Avoid doing this stuff twice, even if CheckForWin is called twice
authornemo
Fri, 29 Oct 2010 13:19:33 -0400
changeset 4014 e9baae83370b
parent 4013 c9b20ed3566f
child 4015 2897cf5730e7
Avoid doing this stuff twice, even if CheckForWin is called twice
hedgewars/uTeams.pas
--- a/hedgewars/uTeams.pas	Fri Oct 29 11:19:21 2010 -0400
+++ b/hedgewars/uTeams.pas	Fri Oct 29 13:19:33 2010 -0400
@@ -101,6 +101,7 @@
     LocalClan: LongInt;  // last non-bot, non-extdriven clan
     LocalAmmo: LongInt;  // last non-bot, non-extdriven clan's first team's ammo index
     CurMinAngle, CurMaxAngle: Longword;
+    GameOver: boolean;
 
 procedure initModule;
 procedure freeModule;
@@ -139,31 +140,35 @@
 
 TurnTimeLeft:= 0;
 ReadyTimeLeft:= 0;
-if AliveCount = 0 then
-    begin // draw
-    AddCaption(trmsg[sidDraw], cWhiteColor, capgrpGameState);
-    SendStat(siGameResult, trmsg[sidDraw]);
-    AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000)
-    end else // win
-    with AliveClan^ do
-        begin
-        if TeamsNumber = 1 then
-            s:= Format(shortstring(trmsg[sidWinner]), Teams[0]^.TeamName)  // team wins
-        else
-            s:= Format(shortstring(trmsg[sidWinner]), Teams[0]^.TeamName); // clan wins
+if not GameOver then
+    begin
+    if AliveCount = 0 then
+        begin // draw
+        AddCaption(trmsg[sidDraw], cWhiteColor, capgrpGameState);
+        SendStat(siGameResult, trmsg[sidDraw]);
+        AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000)
+        end else // win
+        with AliveClan^ do
+            begin
+            if TeamsNumber = 1 then
+                s:= Format(shortstring(trmsg[sidWinner]), Teams[0]^.TeamName)  // team wins
+            else
+                s:= Format(shortstring(trmsg[sidWinner]), Teams[0]^.TeamName); // clan wins
 
-        for j:= 0 to Pred(TeamsNumber) do
-            with Teams[j]^ do
-                for i:= 0 to cMaxHHIndex do
-                    with Hedgehogs[i] do
-                        if (Gear <> nil) then
-                            Gear^.State:= gstWinner;
+            for j:= 0 to Pred(TeamsNumber) do
+                with Teams[j]^ do
+                    for i:= 0 to cMaxHHIndex do
+                        with Hedgehogs[i] do
+                            if (Gear <> nil) then
+                                Gear^.State:= gstWinner;
 
-        AddCaption(s, cWhiteColor, capgrpGameState);
-        SendStat(siGameResult, s);
-        AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000)
-        end;
-SendStats
+            AddCaption(s, cWhiteColor, capgrpGameState);
+            SendStat(siGameResult, s);
+            AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000)
+            end;
+    SendStats;
+    end;
+GameOver:= true
 end;
 
 procedure SwitchHedgehog;
@@ -497,6 +502,7 @@
     ClansCount:= 0;
     LocalClan:= -1;
     LocalAmmo:= -1;
+    GameOver:= false
 end;
 
 procedure freeModule;