- Fix for desyncs when player exits
authorunc0rr
Sat, 09 May 2009 11:56:46 +0000
changeset 2040 7c366fc3c099
parent 2039 3001445b4500
child 2041 9e0b5a6bcecf
- Fix for desyncs when player exits - Effect for gone team: all hedgehogs assume damage == health, then die not tested
hedgewars/HHHandlers.inc
hedgewars/uTeams.pas
--- a/hedgewars/HHHandlers.inc	Fri May 08 18:20:06 2009 +0000
+++ b/hedgewars/HHHandlers.inc	Sat May 09 11:56:46 2009 +0000
@@ -712,6 +712,11 @@
 	exit
 	end;
 
-if (Gear^.State and gstHHDriven) = 0 then doStepHedgehogFree(Gear)
-                                     else doStepHedgehogDriven(Gear)
+if (Gear^.State and gstHHDriven) = 0 then
+	doStepHedgehogFree(Gear)
+else
+	begin
+	TeamGoneEffect(PHedgehog(Gear^.Hedgehog)^.Team^);
+	doStepHedgehogDriven(Gear)
+	end
 end;
--- a/hedgewars/uTeams.pas	Fri May 08 18:20:06 2009 +0000
+++ b/hedgewars/uTeams.pas	Sat May 09 11:56:46 2009 +0000
@@ -104,6 +104,7 @@
 procedure RestoreTeamsFromSave;
 function  CheckForWin: boolean;
 procedure TeamGone(s: shortstring);
+procedure TeamGoneEffect(var Team: TTeam);
 
 implementation
 uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uChat, uVisualGears;
@@ -197,9 +198,9 @@
 					CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber;
 				until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH)
 				end
-		until ((CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) and (not CurrentTeam^.hasGone)) or (PrevTeam = CurrTeam);
+		until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (PrevTeam = CurrTeam);
 		end
-until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) and (not CurrentTeam^.hasGone);
+until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil);
 
 CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog])
 end;
@@ -368,7 +369,7 @@
 end;
 
 procedure TeamGone(s: shortstring);
-var i, t: LongInt;
+var t: LongInt;
 begin
 t:= 0;
 while (t < cMaxTeams)
@@ -379,22 +380,22 @@
 with TeamsArray[t]^ do
 	begin
 	AddChatString('** '+ TeamName + ' is gone');
-	for i:= 0 to cMaxHHIndex do
-		with Hedgehogs[i] do
-			if Gear <> nil then
-				begin
-				if Gear^.State and gstAttacking <> 0 then
-					AttackBar:= 0;
-					
-				Gear^.State:= Gear^.State and not gstHHDriven
-				end;
-
 	hasGone:= true
 	end;
 	
 RecountTeamHealth(TeamsArray[t])
 end;
 
+procedure TeamGoneEffect(var Team: TTeam);
+var i: LongInt;
+begin
+with Team do
+	for i:= 0 to cMaxHHIndex do
+		with Hedgehogs[i] do
+			if Gear <> nil then
+				Gear^.Damage:= Gear^.Health
+end;
+
 initialization
 
 finalization