hedgewars/uTeams.pas
changeset 5021 ca09bfa0414c
parent 5016 9347d82a26cc
child 5022 d2a2f6c9b236
equal deleted inserted replaced
5020:14b2915a1404 5021:ca09bfa0414c
    55 
    55 
    56 if (AliveCount > 1)
    56 if (AliveCount > 1)
    57 or ((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false);
    57 or ((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false);
    58 CheckForWin:= true;
    58 CheckForWin:= true;
    59 
    59 
    60 if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft;
       
    61 TurnTimeLeft:= 0;
    60 TurnTimeLeft:= 0;
    62 ReadyTimeLeft:= 0;
    61 ReadyTimeLeft:= 0;
    63 if not GameOver then
    62 if not GameOver then
    64     begin
    63     begin
    65     if AliveCount = 0 then
    64     if AliveCount = 0 then
    95 GameOver:= true
    94 GameOver:= true
    96 end;
    95 end;
    97 
    96 
    98 procedure SwitchHedgehog;
    97 procedure SwitchHedgehog;
    99 var c: LongWord;
    98 var c: LongWord;
   100     PrevHH, PrevTeam: LongWord;
    99     PrevHH, PrevTeam, PrevClan: LongWord;
   101 begin
   100 begin
   102 TargetPoint.X:= NoPointX;
   101 TargetPoint.X:= NoPointX;
   103 TryDo(CurrentTeam <> nil, 'nil Team', true);
   102 TryDo(CurrentTeam <> nil, 'nil Team', true);
   104 with CurrentHedgehog^ do
   103 with CurrentHedgehog^ do
   105     if (PreviousTeam <> nil) and PlacingHogs and Unplaced then
   104     if (PreviousTeam <> nil) and PlacingHogs and Unplaced then
   140         LocalAmmo:= Hedgehogs[c].AmmoStore
   139         LocalAmmo:= Hedgehogs[c].AmmoStore
   141         end;
   140         end;
   142 
   141 
   143 c:= CurrentTeam^.Clan^.ClanIndex;
   142 c:= CurrentTeam^.Clan^.ClanIndex;
   144 repeat
   143 repeat
   145     if (GameFlags And gfTagTeam) = 0 then inc(c);
       
   146 
       
   147     if (c = ClansCount) and ((GameFlags And gfTagTeam) = 0) then
       
   148         begin
       
   149         if not PlacingHogs then inc(TotalRounds);
       
   150         c:= 0
       
   151         end;
       
   152 
       
   153     with ClansArray[c]^ do
   144     with ClansArray[c]^ do
   154         if (CurrTeam = TagTeamIndex) and ((GameFlags And gfTagTeam) <> 0) then
   145         if (CurrTeam = TagTeamIndex) and ((GameFlags And gfTagTeam) <> 0) then
   155             begin
   146             begin
   156             TagTeamIndex:= Succ(TagTeamIndex) mod TeamsNumber;
   147             TagTeamIndex:= Pred(TagTeamIndex) mod TeamsNumber;
   157             CurrTeam:= Succ(CurrTeam) mod TeamsNumber;
   148             CurrTeam:= Pred(CurrTeam) mod TeamsNumber;
   158             c:= Succ(c) mod ClansCount;
   149             inc(c);
   159             NextClan:= true;
   150             NextClan:= true;
   160             end;
   151             end;
       
   152 
       
   153     if (GameFlags And gfTagTeam) = 0 then inc(c);
       
   154 
       
   155     if c = ClansCount then
       
   156         begin
       
   157         if not PlacingHogs then inc(TotalRounds);
       
   158         c:= 0
       
   159         end;
   161 
   160 
   162     with ClansArray[c]^ do
   161     with ClansArray[c]^ do
   163         begin
   162         begin
   164         PrevTeam:= CurrTeam;
   163         PrevTeam:= CurrTeam;
   165         repeat
   164         repeat
   170                 PrevHH:= CurrHedgehog mod HedgehogsNumber; // prevent infinite loop when CurrHedgehog = 7, but HedgehogsNumber < 8 (team is destroyed before its first turn)
   169                 PrevHH:= CurrHedgehog mod HedgehogsNumber; // prevent infinite loop when CurrHedgehog = 7, but HedgehogsNumber < 8 (team is destroyed before its first turn)
   171                 repeat
   170                 repeat
   172                     CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber;
   171                     CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber;
   173                 until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH)
   172                 until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH)
   174                 end
   173                 end
   175         until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (PrevTeam = CurrTeam);
   174         until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (PrevTeam = CurrTeam) or ((CurrTeam = TagTeamIndex) and ((GameFlags And gfTagTeam) <> 0));
   176         end
   175         end
   177 until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil);
   176 until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil);
   178 
   177 
   179 CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]);
   178 CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]);
   180 end;
   179 end;