Some improvements on stats subsystem
authorunc0rr
Thu, 05 May 2011 17:08:29 +0400
changeset 5202 45a16280d68d
parent 5201 7b9aa7aac336
child 5203 b77f28facca6
Some improvements on stats subsystem
hedgewars/uGears.pas
hedgewars/uStats.pas
hedgewars/uTypes.pas
--- a/hedgewars/uGears.pas	Wed May 04 01:19:39 2011 +0200
+++ b/hedgewars/uGears.pas	Thu May 05 17:08:29 2011 +0400
@@ -593,13 +593,6 @@
             Gear^.Damage:= t;
             if ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cWaterOpacity < $FF))) and (hwRound(Gear^.Y) < cWaterLine + 256) then
                 spawnHealthTagForHH(Gear, t);
-
-            // should be not CurrentHedgehog, but hedgehog of the last gear which caused damage to this hog
-            // same stand for CheckHHDamage
-            if (Gear^.LastDamage <> nil) then
-                uStats.HedgehogDamaged(Gear, Gear^.LastDamage)
-            else
-                uStats.HedgehogDamaged(Gear, CurrentHedgehog)
             end;
 
         team:= Gear^.Hedgehog^.Team;
@@ -623,6 +616,14 @@
                     TeamGoneEffect(team^.Clan^.Teams[i]^)
                     end
             end;
+
+        // should be not CurrentHedgehog, but hedgehog of the last gear which caused damage to this hog
+        // same stand for CheckHHDamage
+        if (Gear^.LastDamage <> nil) then
+            uStats.HedgehogDamaged(Gear, Gear^.LastDamage, 0, true)
+        else
+            uStats.HedgehogDamaged(Gear, CurrentHedgehog, 0, true);
+
         inc(KilledHHs);
         RecountTeamHealth(team);
         if (CurrentHedgehog <> nil) and CurrentHedgehog^.Effects[heResurrectable] and not Gear^.Hedgehog^.Effects[heResurrectable] then
@@ -1078,6 +1079,7 @@
            CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog;
            spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg);
            end;
+        uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);    
         end;
     end else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure
         begin
@@ -1085,7 +1087,6 @@
         end;
     inc(Gear^.Damage, Damage);
     
-    uStats.HedgehogDamaged(Gear, AttackerHog);    
     ScriptCall('onGearDamage', Gear^.UID, Damage);
 end;
 
--- a/hedgewars/uStats.pas	Wed May 04 01:19:39 2011 +0200
+++ b/hedgewars/uStats.pas	Thu May 05 17:08:29 2011 +0400
@@ -29,7 +29,7 @@
 procedure freeModule;
 
 procedure AmmoUsed(am: TAmmoType);
-procedure HedgehogDamaged(Gear: PGear; Attacker: PHedgehog);
+procedure HedgehogDamaged(Gear: PGear; Attacker: PHedgehog; Damage: Longword; killed: boolean);
 procedure Skipped;
 procedure TurnReaction;
 procedure SendStats;
@@ -50,7 +50,7 @@
     vpHurtSameClan: PVoicepack = nil;
     vpHurtEnemy: PVoicepack = nil;
 
-procedure HedgehogDamaged(Gear: PGear; Attacker: PHedgehog);
+procedure HedgehogDamaged(Gear: PGear; Attacker: PHedgehog; Damage: Longword; killed: boolean);
 begin
 if Attacker^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then
     vpHurtSameClan:= CurrentHedgehog^.Team^.voicepack
@@ -60,11 +60,11 @@
 //////////////////////////
 
 if Gear <> Attacker^.Gear then
-    inc(Attacker^.stats.StepDamageGiven, Gear^.Damage);
+    inc(Attacker^.stats.StepDamageGiven, Damage);
 
-if CurrentHedgehog^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then inc(DamageClan, Gear^.Damage);
+if CurrentHedgehog^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then inc(DamageClan, Damage);
 
-if Gear^.Health <= Gear^.Damage then
+if killed then
     begin
     inc(Attacker^.stats.StepKills);
     inc(Kills);
@@ -75,12 +75,13 @@
         inc(Attacker^.Team^.stats.TeamKills);
         inc(Attacker^.Team^.stats.TeamDamage, Gear^.Damage);
     end;
+    if Gear = Attacker^.Gear then inc(Attacker^.Team^.stats.Suicides);
     if Attacker^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then inc(KillsClan);
     end;
 
-inc(Gear^.Hedgehog^.stats.StepDamageRecv, Gear^.Damage);
-inc(DamageGiven, Gear^.Damage);
-inc(DamageTotal, Gear^.Damage)
+inc(Gear^.Hedgehog^.stats.StepDamageRecv, Damage);
+inc(DamageGiven, Damage);
+inc(DamageTotal, Damage)
 end;
 
 procedure Skipped;
--- a/hedgewars/uTypes.pas	Wed May 04 01:19:39 2011 +0200
+++ b/hedgewars/uTypes.pas	Thu May 05 17:08:29 2011 +0400
@@ -292,6 +292,7 @@
 
     TTeamStats = record
         Kills : Longword;
+        Suicides: Longword;
         AIKills : Longword;
         TeamKills : Longword;
         TurnSkips : Longword;