Add more support for handling disconnects while playing (not fully tested)
authorunc0rr
Tue, 14 Oct 2008 14:33:54 +0000
changeset 1352 405ad07cf875
parent 1351 aa7aefec5c1b
child 1353 c72d37d4eb4e
Add more support for handling disconnects while playing (not fully tested)
hedgewars/uAIMisc.pas
hedgewars/uGears.pas
hedgewars/uIO.pas
hedgewars/uTeams.pas
--- a/hedgewars/uAIMisc.pas	Mon Oct 13 19:04:27 2008 +0000
+++ b/hedgewars/uAIMisc.pas	Tue Oct 14 14:33:54 2008 +0000
@@ -78,28 +78,29 @@
 e:= 0;
 for t:= 0 to Pred(TeamsCount) do
 	with TeamsArray[t]^ do
-	begin
-	for i:= 0 to cMaxHHIndex do
-		if (Hedgehogs[i].Gear <> nil)
-			and (Hedgehogs[i].Gear <> ThinkingHH) then
+		if not hasGone then
 			begin
-			with Targets.ar[Targets.Count], Hedgehogs[i] do
-				begin
-				Point.X:= hwRound(Gear^.X);
-				Point.Y:= hwRound(Gear^.Y);
-				if Clan <> CurrentTeam^.Clan then
+			for i:= 0 to cMaxHHIndex do
+				if (Hedgehogs[i].Gear <> nil)
+				and (Hedgehogs[i].Gear <> ThinkingHH) then
 					begin
-					Score:=  Gear^.Health;
-					inc(e)
-					end else
-					begin
-					Score:= -Gear^.Health;
-					inc(f)
-					end
-				end;
-			inc(Targets.Count)
+					with Targets.ar[Targets.Count], Hedgehogs[i] do
+						begin
+						Point.X:= hwRound(Gear^.X);
+						Point.Y:= hwRound(Gear^.Y);
+						if Clan <> CurrentTeam^.Clan then
+							begin
+							Score:=  Gear^.Health;
+							inc(e)
+							end else
+							begin
+							Score:= -Gear^.Health;
+							inc(f)
+							end
+						end;
+					inc(Targets.Count)
+					end;
 			end;
-	end;
 
 if e > f then friendlyfactor:= 300 + (e - f) * 30
 else friendlyfactor:= max(30, 300 - f * 80 div e)
@@ -124,21 +125,27 @@
 MyClan:= PHedgehog(ThinkingHH^.Hedgehog)^.Team^.Clan;
 Gear:= GearsList;
 while Gear <> nil do
-      begin
-      case Gear^.Kind of
-           gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25);
-           gtMine: if (Gear^.State and gstAttacking) = 0 then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50)
-                                                        else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
-           gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75);
-           gtHedgehog: begin
-                       if Gear^.Damage >= Gear^.Health then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25) else
-                          if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then
-                             if (MyClan = PHedgehog(Gear^.Hedgehog)^.Team^.Clan) then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend
-                                                                                 else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3)
-                       end;
-           end;
-      Gear:= Gear^.NextGear
-      end;
+	begin
+	case Gear^.Kind of
+		gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25);
+		gtMine: if (Gear^.State and gstAttacking) = 0 then
+				AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50)
+			else
+				AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
+		gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75);
+		gtHedgehog: begin
+					if Gear^.Damage >= Gear^.Health then
+						AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25)
+					else
+						if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then
+							if (MyClan = PHedgehog(Gear^.Hedgehog)^.Team^.Clan) then
+								AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend
+							else
+								AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3)
+					end;
+		end;
+	Gear:= Gear^.NextGear
+	end;
 if isAfterAttack and (KnownExplosion.Radius > 0) then
    with KnownExplosion do
         AddBonus(X, Y, Radius + 10, -Radius);
@@ -157,13 +164,13 @@
 begin
 Result:= 0;
 for i:= 0 to Pred(bonuses.Count) do
-    with bonuses.ar[i] do
-         begin
-         r:= hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y)));
-         if r < Radius then
-            inc(Result, Score * (Radius - r))
-         end;
-    RatePlace:= Result
+	with bonuses.ar[i] do
+		begin
+		r:= hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y)));
+		if r < Radius then
+			inc(Result, Score * (Radius - r))
+		end;
+	RatePlace:= Result
 end;
 
 function TestColl(x, y, r: LongInt): boolean;
--- a/hedgewars/uGears.pas	Mon Oct 13 19:04:27 2008 +0000
+++ b/hedgewars/uGears.pas	Tue Oct 14 14:33:54 2008 +0000
@@ -446,11 +446,11 @@
 AllInactive:= true;
 t:= GearsList;
 while t <> nil do
-      begin
-      Gear:= t;
-      t:= Gear^.NextGear;
-      if Gear^.Active then Gear^.doStep(Gear);
-      end;
+	begin
+	Gear:= t;
+	t:= Gear^.NextGear;
+	if Gear^.Active then Gear^.doStep(Gear);
+	end;
 
 if AllInactive then
 case step of
--- a/hedgewars/uIO.pas	Mon Oct 13 19:04:27 2008 +0000
+++ b/hedgewars/uIO.pas	Tue Oct 14 14:33:54 2008 +0000
@@ -273,7 +273,7 @@
 			inttostr(headcmd^.Time) + ')',
 			true);
 
-isInLag:= (headcmd = nil) and tmpflag
+isInLag:= (headcmd = nil) and tmpflag and not CurrentTeam^.hasGone
 end;
 
 end.
--- a/hedgewars/uTeams.pas	Mon Oct 13 19:04:27 2008 +0000
+++ b/hedgewars/uTeams.pas	Tue Oct 14 14:33:54 2008 +0000
@@ -329,18 +329,21 @@
 var i: LongInt;
 begin
 with team^ do
-     begin
-     NewTeamHealthBarWidth:= 0;
-     for i:= 0 to cMaxHHIndex do
-         if Hedgehogs[i].Gear <> nil then
-            inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health);
-     TeamHealth:= NewTeamHealthBarWidth;
-     if NewTeamHealthBarWidth > MaxTeamHealth then
-        begin
-        MaxTeamHealth:= NewTeamHealthBarWidth;
-        RecountAllTeamsHealth;
-        end else NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth
-     end;
+	begin
+	NewTeamHealthBarWidth:= 0;
+	
+	if not hasGone then
+		for i:= 0 to cMaxHHIndex do
+			if Hedgehogs[i].Gear <> nil then
+				inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health);
+
+	TeamHealth:= NewTeamHealthBarWidth;
+	if NewTeamHealthBarWidth > MaxTeamHealth then
+		begin
+		MaxTeamHealth:= NewTeamHealthBarWidth;
+		RecountAllTeamsHealth;
+		end else NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth
+	end;
 
 RecountClanHealth(team^.Clan);