Start implementing better statistics implementation (does nothing yet)
authorunc0rr
Fri, 14 Mar 2008 19:34:05 +0000
changeset 814 7fb4417b7bc1
parent 813 36fffe78ff11
child 815 82ff416301bd
Start implementing better statistics implementation (does nothing yet)
hedgewars/CMakeLists.txt
hedgewars/hwengine.dpr
hedgewars/uGears.pas
hedgewars/uStats.pas
hedgewars/uTeams.pas
--- a/hedgewars/CMakeLists.txt	Fri Mar 14 16:51:24 2008 +0000
+++ b/hedgewars/CMakeLists.txt	Fri Mar 14 19:34:05 2008 +0000
@@ -29,6 +29,7 @@
 	uRandom.pas
 	uSHA.pas
 	uSound.pas
+	uStats.pas
 	uStore.pas
 	uTeams.pas
 	uTriggers.pas
--- a/hedgewars/hwengine.dpr	Fri Mar 14 16:51:24 2008 +0000
+++ b/hedgewars/hwengine.dpr	Fri Mar 14 19:34:05 2008 +0000
@@ -49,7 +49,8 @@
   uLocale in 'uLocale.pas',
   uAmmos in 'uAmmos.pas',
   uSHA in 'uSHA.pas',
-  uFloat in 'uFloat.pas';
+  uFloat in 'uFloat.pas',
+  uStats in 'uStats.pas';
 
 {$INCLUDE options.inc}
 
--- a/hedgewars/uGears.pas	Fri Mar 14 16:51:24 2008 +0000
+++ b/hedgewars/uGears.pas	Fri Mar 14 19:34:05 2008 +0000
@@ -69,7 +69,8 @@
 
 implementation
 uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions,
-     uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos, uTriggers, GL;
+     uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos, uTriggers, GL,
+     uStats;
 
 const MAXROPEPOINTS = 300;
 var RopePoints: record
@@ -81,7 +82,6 @@
                                   b: boolean;
                                   end;
                  end;
-    StepDamage: Longword = 0;
 
 procedure DeleteGear(Gear: PGear); forward;
 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord); forward;
@@ -328,7 +328,7 @@
          begin
          t:= max(Gear^.Damage, Gear^.Health);
          AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtHealthTag, t, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog;
-         inc(StepDamage, t)
+         uStats.HedgehogDamaged(Gear, t)
          end;
       team:= PHedgehog(Gear^.Hedgehog)^.Team;
       if CurrentHedgehog^.Gear = Gear then
@@ -356,7 +356,6 @@
          if Gear^.Damage <> 0 then
             begin
             CheckNoDamage:= false;
-            inc(StepDamage, Gear^.Damage);
             if Gear^.Health < Gear^.Damage then Gear^.Health:= 0
                                            else dec(Gear^.Health, Gear^.Damage);
             AddGear(hwRound(Gear^.X), hwRound(Gear^.Y) - cHHRadius - 12,
@@ -378,7 +377,7 @@
 
 procedure ProcessGears;
 const delay: LongWord = 0;
-      step: (stDelay, stChDmg, stChWin, stSpawn, stNTurn) = stDelay;
+      step: (stDelay, stChDmg, stChWin, stTurnReact, stSpawn, stNTurn) = stDelay;
 var Gear, t: PGear;
 begin
 AllInactive:= true;
@@ -403,6 +402,10 @@
                  end;
         stChDmg: if CheckNoDamage then inc(step) else step:= stDelay;
         stChWin: if not CheckForWin then inc(step) else step:= stDelay;
+    stTurnReact: begin
+                 TurnReaction;
+                 inc(step)
+                 end;
         stSpawn: begin
                  if not isInMultiShoot then SpawnBoxOfSmth;
                  inc(step)
@@ -411,9 +414,6 @@
                  //AwareOfExplosion(0, 0, 0);
                  if isInMultiShoot then isInMultiShoot:= false
                     else begin
-                    with CurrentHedgehog^ do
-                         if MaxStepDamage < StepDamage then MaxStepDamage:= StepDamage;
-                    StepDamage:= 0;
                     ParseCommand('/nextturn', true);
                     end;
                  step:= Low(step)
@@ -683,6 +683,7 @@
                           if (Mask and EXPLNoDamage) = 0 then
                              begin
                              inc(Gear^.Damage, dmg);
+                             uStats.HedgehogDamaged(Gear, dmg);
                              if Gear^.Kind = gtHedgehog then
                                 AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, Gear)
                              end;
@@ -712,10 +713,8 @@
 procedure ShotgunShot(Gear: PGear);
 var t: PGear;
     dmg: integer;
-    hh: PHedgehog;
 begin
 Gear^.Radius:= cShotgunRadius;
-hh:= Gear^.Hedgehog;
 t:= GearsList;
 while t <> nil do
     begin
@@ -730,7 +729,7 @@
                        if t^.Kind = gtHedgehog then
                           begin
                           AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), dmg, t);
-                          inc(hh^.DamageGiven, dmg)
+                          uStats.HedgehogDamaged(Gear, dmg)
                           end;
                        DeleteCI(t);
                        t^.dX:= t^.dX + SignAs(Gear^.dX * dmg * _0_01 + cHHKick, t^.X - Gear^.X);
@@ -770,7 +769,7 @@
                        if t^.ar[i]^.Kind = gtHedgehog then
                           begin
                           AddDamageTag(hwRound(t^.ar[i]^.X), hwRound(t^.ar[i]^.Y), Damage, t^.ar[i]);
-                          inc(hh^.DamageGiven, Damage)
+                          uStats.HedgehogDamaged(t^.ar[i], Damage)
                           end;
                        DeleteCI(t^.ar[i]);
                        t^.ar[i]^.dX:= Ammo^.dX * Power * _0_01;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/uStats.pas	Fri Mar 14 19:34:05 2008 +0000
@@ -0,0 +1,71 @@
+(*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2008 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *)
+
+unit uStats;
+interface
+uses uGears;
+
+type TStatistics = record
+                   DamageRecv,
+                   DamageGiven: Longword;
+                   StepDamageRecv,
+                   StepDamageGiven: Longword;
+                   MaxStepDamageRecv,
+                   MaxStepDamageGiven: Longword;
+                   Turns: Longword;
+                   end;
+
+procedure HedgehogDamaged(Gear: PGear; Damage: Longword);
+procedure TurnReaction;
+procedure SendStats;
+
+implementation
+uses uTeams, uSound, uConsts;
+
+procedure HedgehogDamaged(Gear: PGear; Damage: Longword);
+begin
+if Gear <> CurrentHedgehog^.Gear then
+   inc(CurrentHedgehog^.stats.StepDamageGiven, Damage);
+inc(PHedgehog(Gear^.Hedgehog)^.stats.StepDamageRecv, Damage)
+end;
+
+procedure TurnReaction;
+begin
+end;
+
+procedure SendStats;
+//var i, t: LongInt;
+//    msd: Longword; msdhh: PHedgehog;
+begin
+(*msd:= 0; msdhh:= nil;
+for t:= 0 to Pred(TeamsCount) do
+   with TeamsArray[t]^ do
+      begin
+      for i:= 0 to cMaxHHIndex do
+          if Hedgehogs[i].MaxStepDamage > msd then
+             begin
+             msdhh:= @Hedgehogs[i];
+             msd:= Hedgehogs[i].MaxStepDamage
+             end;
+      end;
+if msdhh <> nil then SendStat(siMaxStepDamage, inttostr(msdhh^.MaxStepDamage) + ' ' +
+                                               msdhh^.Name + ' (' + msdhh^.Team^.TeamName + ')');
+if KilledHHs > 0 then SendStat(siKilledHHs, inttostr(KilledHHs));*)
+end;
+
+end.
\ No newline at end of file
--- a/hedgewars/uTeams.pas	Fri Mar 14 16:51:24 2008 +0000
+++ b/hedgewars/uTeams.pas	Fri Mar 14 19:34:05 2008 +0000
@@ -18,7 +18,7 @@
 
 unit uTeams;
 interface
-uses SDLh, uConsts, uKeys, uGears, uRandom, uFloat;
+uses SDLh, uConsts, uKeys, uGears, uRandom, uFloat, uStats;
 {$INCLUDE options.inc}
 
 type PHHAmmo = ^THHAmmo;
@@ -40,8 +40,7 @@
                  AttacksNum: Longword;
                  visStepPos: LongWord;
                  BotLevel  : LongWord; // 0 - Human player
-                 DamageGiven: Longword;
-                 MaxStepDamage: Longword;
+                 stats: TStatistics;
                  end;
      TTeam = record
              Clan: PClan;
@@ -87,7 +86,6 @@
 procedure RecountTeamHealth(team: PTeam);
 procedure RestoreTeamsFromSave;
 function CheckForWin: boolean;
-procedure SendStats;
 
 implementation
 uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uSound;
@@ -325,26 +323,6 @@
    TeamsArray[t]^.ExtDriven:= false
 end;
 
-procedure SendStats;
-var i, t: LongInt;
-    msd: Longword; msdhh: PHedgehog;
-begin
-msd:= 0; msdhh:= nil;
-for t:= 0 to Pred(TeamsCount) do
-   with TeamsArray[t]^ do
-      begin
-      for i:= 0 to cMaxHHIndex do
-          if Hedgehogs[i].MaxStepDamage > msd then
-             begin
-             msdhh:= @Hedgehogs[i];
-             msd:= Hedgehogs[i].MaxStepDamage
-             end;
-      end;
-if msdhh <> nil then SendStat(siMaxStepDamage, inttostr(msdhh^.MaxStepDamage) + ' ' +
-                                               msdhh^.Name + ' (' + msdhh^.Team^.TeamName + ')');
-if KilledHHs > 0 then SendStat(siKilledHHs, inttostr(KilledHHs));
-end;
-
 initialization
 
 finalization