Rip out stats code from TurnReaction and put it into new function TurnStats. Fixes buggy stats
--- a/hedgewars/uGears.pas Mon Sep 03 21:19:15 2018 +0200
+++ b/hedgewars/uGears.pas Mon Sep 03 22:14:46 2018 +0200
@@ -62,8 +62,8 @@
var delay: LongWord;
delay2: LongWord;
- step: (stInit, stDelay, stChDmg, stSweep, stChWin1, stTurnReact,
- stAfterDelay, stChWin2, stWater, stChWin3, stHealth,
+ step: (stInit, stDelay, stChDmg, stSweep, stTurnStats, stChWin1,
+ stTurnReact, stAfterDelay, stChWin2, stWater, stChWin3, stHealth,
stSpawn, stNTurn);
NewTurnTick: LongWord;
//SDMusic: shortstring;
@@ -289,6 +289,13 @@
else
inc(step);
+ stTurnStats:
+ begin
+ if (not bBetweenTurns) and (not isInMultiShoot) then
+ uStats.TurnStats;
+ inc(step)
+ end;
+
stChWin1:
begin
CheckForWin();
--- a/hedgewars/uStats.pas Mon Sep 03 21:19:15 2018 +0200
+++ b/hedgewars/uStats.pas Mon Sep 03 22:14:46 2018 +0200
@@ -39,6 +39,7 @@
procedure HedgehogDamaged(Gear: PGear; Attacker: PHedgehog; Damage: Longword; killed: boolean);
procedure TargetHit;
procedure Skipped;
+procedure TurnStats;
procedure TurnReaction;
procedure SendStats;
procedure hedgehogFlight(Gear: PGear; time: Longword);
@@ -135,14 +136,56 @@
isTurnSkipped:= true
end;
-procedure TurnReaction;
+procedure TurnStats;
var i, t: LongInt;
- killsCheck: LongInt;
+begin
+inc(FinishedTurnsTotal);
+
+for t:= 0 to Pred(TeamsCount) do // send even on zero turn
+ with TeamsArray[t]^ do
+ for i:= 0 to cMaxHHIndex do
+ with Hedgehogs[i].stats do
+ begin
+ inc(DamageRecv, StepDamageRecv);
+ inc(DamageGiven, StepDamageGiven);
+ if StepDamageRecv > MaxStepDamageRecv then
+ MaxStepDamageRecv:= StepDamageRecv;
+ if StepDamageGiven > MaxStepDamageGiven then
+ MaxStepDamageGiven:= StepDamageGiven;
+ if StepKills > MaxStepKills then
+ MaxStepKills:= StepKills;
+ StepKills:= 0;
+ StepDamageRecv:= 0;
+ StepDamageGiven:= 0;
+ StepPoisoned:= false;
+ StepDied:= false;
+ end;
+
+if SendHealthStatsOn then
+ for t:= 0 to Pred(ClansCount) do
+ with ClansArray[t]^ do
+ begin
+ SendStat(siClanHealth, IntToStr(Color) + ' ' + IntToStr(ClanHealth));
+ end;
+
+Kills:= 0;
+KillsClan:= 0;
+DamageClan:= 0;
+DamageTurn:= 0;
+HitTargets:= 0;
+PoisonClan:= 0;
+PoisonTurn:= 0;
+AmmoUsedCount:= 0;
+AmmoDamagingUsed:= false;
+isTurnSkipped:= false;
+end;
+
+procedure TurnReaction;
+var killsCheck: LongInt;
s: ansistring;
begin
//TryDo(not bBetweenTurns, 'Engine bug: TurnReaction between turns', true);
-inc(FinishedTurnsTotal);
if FinishedTurnsTotal <> 0 then
begin
s:= ansistring(CurrentHedgehog^.Name);
@@ -209,45 +252,6 @@
AddCaption(FormatA(GetEventString(eidTurnSkipped), s), capcolDefault, capgrpMessage);
end
end;
-
-
-for t:= 0 to Pred(TeamsCount) do // send even on zero turn
- with TeamsArray[t]^ do
- for i:= 0 to cMaxHHIndex do
- with Hedgehogs[i].stats do
- begin
- inc(DamageRecv, StepDamageRecv);
- inc(DamageGiven, StepDamageGiven);
- if StepDamageRecv > MaxStepDamageRecv then
- MaxStepDamageRecv:= StepDamageRecv;
- if StepDamageGiven > MaxStepDamageGiven then
- MaxStepDamageGiven:= StepDamageGiven;
- if StepKills > MaxStepKills then
- MaxStepKills:= StepKills;
- StepKills:= 0;
- StepDamageRecv:= 0;
- StepDamageGiven:= 0;
- StepPoisoned:= false;
- StepDied:= false;
- end;
-
-if SendHealthStatsOn then
- for t:= 0 to Pred(ClansCount) do
- with ClansArray[t]^ do
- begin
- SendStat(siClanHealth, IntToStr(Color) + ' ' + IntToStr(ClanHealth));
- end;
-
-Kills:= 0;
-KillsClan:= 0;
-DamageClan:= 0;
-DamageTurn:= 0;
-HitTargets:= 0;
-PoisonClan:= 0;
-PoisonTurn:= 0;
-AmmoUsedCount:= 0;
-AmmoDamagingUsed:= false;
-isTurnSkipped:= false
end;
procedure AmmoUsed(am: TAmmoType);
--- a/hedgewars/uTeams.pas Mon Sep 03 21:19:15 2018 +0200
+++ b/hedgewars/uTeams.pas Mon Sep 03 22:14:46 2018 +0200
@@ -75,9 +75,12 @@
TurnTimeLeft:= 0;
ReadyTimeLeft:= 0;
-// if the game ends during a multishot, do last TurnReaction
+// if the game ends during a multishot, do last TurnStats + TurnReaction
if (not bBetweenTurns) and isInMultiShoot then
+ begin
+ TurnStats();
TurnReaction();
+ end;
if not TeamsGameOver then
begin