... or. just move the king check to after the gear nil
authornemo
Fri, 05 Feb 2010 13:32:57 +0000
changeset 2760 420fe0344e5f
parent 2759 03988f64e146
child 2761 1467c7298b10
... or. just move the king check to after the gear nil
hedgewars/uGears.pas
--- a/hedgewars/uGears.pas	Fri Feb 05 13:30:47 2010 +0000
+++ b/hedgewars/uGears.pas	Fri Feb 05 13:32:57 2010 +0000
@@ -426,7 +426,8 @@
 
 procedure DeleteGear(Gear: PGear);
 var team: PTeam;
-	t,i,k: Longword;
+	t,i: Longword;
+    k: boolean;
 begin
 DeleteCI(Gear);
 
@@ -457,18 +458,17 @@
 		if CurrentHedgehog^.Gear = Gear then
 			FreeActionsList; // to avoid ThinkThread on drawned gear
 
+		PHedgehog(Gear^.Hedgehog)^.Gear:= nil;
         if PHedgehog(Gear^.Hedgehog)^.King then
             begin
             // are there any other kings left? Just doing nil check.  Presumably a mortally wounded king will get reaped soon enough
-            k:= 0;
+            k:= false;
             for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
-                if (team^.Clan^.Teams[i]^.Hedgehogs[0].Gear <> nil) then inc(k);
-            if k < 2 then // current dying king is count of 1
+                if (team^.Clan^.Teams[i]^.Hedgehogs[0].Gear <> nil) then k:= true;
+            if not k then
                 for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
                     TeamGoneEffect(team^.Clan^.Teams[i]^)
             end;
-
-		PHedgehog(Gear^.Hedgehog)^.Gear:= nil;
 		inc(KilledHHs);
 		RecountTeamHealth(team)
 		end;