hedgewars/uStats.pas
author unc0rr
Fri, 25 Apr 2008 13:12:52 +0000
changeset 870 dd418d9c18c5
parent 869 daddcd31ef34
child 871 f1bf00b7fd5a
permissions -rw-r--r--
Use more sounds
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
     1
(*
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2008 Andrey Korotaev <unC0Rr@gmail.com>
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
     4
 *
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
     8
 *
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    13
 *
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    17
 *)
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    18
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    19
unit uStats;
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    20
interface
829
1209eb768acf Use 'first blood' sound
unc0rr
parents: 815
diff changeset
    21
uses uGears, uConsts;
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    22
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    23
type TStatistics = record
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    24
                   DamageRecv,
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    25
                   DamageGiven: Longword;
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    26
                   StepDamageRecv,
869
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
    27
                   StepDamageGiven,
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
    28
                   StepKills: Longword;
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    29
                   MaxStepDamageRecv,
869
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
    30
                   MaxStepDamageGiven,
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
    31
                   MaxStepKills: Longword;
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
    32
                   FinishedTurns: Longword;
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    33
                   end;
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    34
829
1209eb768acf Use 'first blood' sound
unc0rr
parents: 815
diff changeset
    35
procedure AmmoUsed(am: TAmmoType);
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    36
procedure HedgehogDamaged(Gear: PGear);
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    37
procedure TurnReaction;
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    38
procedure SendStats;
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    39
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    40
implementation
858
5005a485f103 Repair round statistics
unc0rr
parents: 831
diff changeset
    41
uses uTeams, uSound, uMisc;
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
    42
var DamageGiven : Longword = 0;
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
    43
    DamageClan  : Longword = 0;
829
1209eb768acf Use 'first blood' sound
unc0rr
parents: 815
diff changeset
    44
    DamageTotal : Longword = 0;
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    45
    KillsClan   : LongWord = 0;
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    46
    Kills       : LongWord = 0;
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    47
    KillsTotal  : LongWord = 0;
830
f07267032194 - Add statistics info for ammo used in step and whether it is damaging ammo
unc0rr
parents: 829
diff changeset
    48
    AmmoUsedCount : Longword = 0;
f07267032194 - Add statistics info for ammo used in step and whether it is damaging ammo
unc0rr
parents: 829
diff changeset
    49
    AmmoDamagingUsed : boolean = false;
870
dd418d9c18c5 Use more sounds
unc0rr
parents: 869
diff changeset
    50
    FinishedTurnsTotal: LongInt = -1;
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    51
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    52
procedure HedgehogDamaged(Gear: PGear);
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    53
begin
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    54
if Gear <> CurrentHedgehog^.Gear then
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    55
	inc(CurrentHedgehog^.stats.StepDamageGiven, Gear^.Damage);
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
    56
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    57
if CurrentHedgehog^.Team^.Clan = PHedgehog(Gear^.Hedgehog)^.Team^.Clan then inc(DamageClan, Gear^.Damage);
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
    58
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    59
if Gear^.Health <= Gear^.Damage then
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    60
	begin
869
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
    61
	inc(CurrentHedgehog^.stats.StepKills);
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    62
	inc(Kills);
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    63
	inc(KillsTotal);
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    64
	if CurrentHedgehog^.Team^.Clan = PHedgehog(Gear^.Hedgehog)^.Team^.Clan then inc(KillsClan);
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    65
	end;
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
    66
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    67
inc(PHedgehog(Gear^.Hedgehog)^.stats.StepDamageRecv, Gear^.Damage);
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    68
inc(DamageGiven, Gear^.Damage);
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    69
inc(DamageTotal, Gear^.Damage)
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    70
end;
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    71
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    72
procedure TurnReaction;
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
    73
var Gear: PGear;
869
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
    74
    i, t: LongInt;
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
    75
begin
870
dd418d9c18c5 Use more sounds
unc0rr
parents: 869
diff changeset
    76
inc(FinishedTurnsTotal);
dd418d9c18c5 Use more sounds
unc0rr
parents: 869
diff changeset
    77
if FinishedTurnsTotal = 0 then exit;
dd418d9c18c5 Use more sounds
unc0rr
parents: 869
diff changeset
    78
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
    79
inc(CurrentHedgehog^.stats.FinishedTurns);
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
    80
864
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
    81
if (DamageGiven = DamageTotal) and (DamageTotal > 0) then
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
    82
	PlaySound(sndFirstBlood, false)
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
    83
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
    84
else if CurrentHedgehog^.stats.StepDamageRecv > 0 then
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
    85
	PlaySound(sndStupid, false)
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
    86
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
    87
else if DamageClan <> 0 then
864
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
    88
	if DamageTotal > DamageClan then
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
    89
		PlaySound(sndNutter, false)
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
    90
	else
866
ac6f6c95c23f - Some more sounds
unc0rr
parents: 864
diff changeset
    91
		if random(2) = 0 then
ac6f6c95c23f - Some more sounds
unc0rr
parents: 864
diff changeset
    92
			PlaySound(sndSameTeam, false)
ac6f6c95c23f - Some more sounds
unc0rr
parents: 864
diff changeset
    93
		else
ac6f6c95c23f - Some more sounds
unc0rr
parents: 864
diff changeset
    94
			PlaySound(sndTraitor, false)
864
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
    95
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    96
else if DamageGiven <> 0 then
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    97
	if Kills > 0 then
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    98
		PlaySound(sndEnemyDown, false)
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
    99
	else
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
   100
		PlaySound(sndRegret, false)
864
024369e09a53 Use some more sounds
unc0rr
parents: 858
diff changeset
   101
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
   102
else if AmmoDamagingUsed then
870
dd418d9c18c5 Use more sounds
unc0rr
parents: 869
diff changeset
   103
	PlaySound(sndMissed, false)
dd418d9c18c5 Use more sounds
unc0rr
parents: 869
diff changeset
   104
else if AmmoUsedCount > 0 then
dd418d9c18c5 Use more sounds
unc0rr
parents: 869
diff changeset
   105
	// nothing ?
dd418d9c18c5 Use more sounds
unc0rr
parents: 869
diff changeset
   106
else
dd418d9c18c5 Use more sounds
unc0rr
parents: 869
diff changeset
   107
	PlaySound(sndCoward, false);
dd418d9c18c5 Use more sounds
unc0rr
parents: 869
diff changeset
   108
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
   109
869
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   110
for t:= 0 to Pred(TeamsCount) do
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   111
	with TeamsArray[t]^ do
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   112
		for i:= 0 to cMaxHHIndex do
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   113
			with Hedgehogs[i].stats do
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   114
				begin
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   115
				inc(DamageRecv, StepDamageRecv);
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   116
				inc(DamageGiven, StepDamageGiven);
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   117
				if StepDamageRecv > MaxStepDamageRecv then MaxStepDamageRecv:= StepDamageRecv;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   118
				if StepDamageGiven > MaxStepDamageGiven then MaxStepDamageGiven:= StepDamageGiven;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   119
				if StepKills > MaxStepKills then MaxStepKills:= StepKills;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   120
				StepDamageRecv:= 0;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   121
				StepDamageGiven:= 0
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   122
				end;
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
   123
867
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
   124
Kills:= 0;
dc7901b1120e - Use more sounds
unc0rr
parents: 866
diff changeset
   125
KillsClan:= 0;
815
82ff416301bd Use sounds 'stupid' and 'missed'
unc0rr
parents: 814
diff changeset
   126
DamageGiven:= 0;
830
f07267032194 - Add statistics info for ammo used in step and whether it is damaging ammo
unc0rr
parents: 829
diff changeset
   127
DamageClan:= 0;
f07267032194 - Add statistics info for ammo used in step and whether it is damaging ammo
unc0rr
parents: 829
diff changeset
   128
AmmoUsedCount:= 0;
f07267032194 - Add statistics info for ammo used in step and whether it is damaging ammo
unc0rr
parents: 829
diff changeset
   129
AmmoDamagingUsed:= false
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
   130
end;
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
   131
829
1209eb768acf Use 'first blood' sound
unc0rr
parents: 815
diff changeset
   132
procedure AmmoUsed(am: TAmmoType);
1209eb768acf Use 'first blood' sound
unc0rr
parents: 815
diff changeset
   133
begin
830
f07267032194 - Add statistics info for ammo used in step and whether it is damaging ammo
unc0rr
parents: 829
diff changeset
   134
inc(AmmoUsedCount);
f07267032194 - Add statistics info for ammo used in step and whether it is damaging ammo
unc0rr
parents: 829
diff changeset
   135
AmmoDamagingUsed:= AmmoDamagingUsed or Ammoz[am].isDamaging
829
1209eb768acf Use 'first blood' sound
unc0rr
parents: 815
diff changeset
   136
end;
1209eb768acf Use 'first blood' sound
unc0rr
parents: 815
diff changeset
   137
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
   138
procedure SendStats;
858
5005a485f103 Repair round statistics
unc0rr
parents: 831
diff changeset
   139
var i, t: LongInt;
869
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   140
    msd, msk: Longword; msdhh, mskhh: PHedgehog;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   141
    mskcnt: Longword;
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
   142
begin
858
5005a485f103 Repair round statistics
unc0rr
parents: 831
diff changeset
   143
msd:= 0; msdhh:= nil;
869
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   144
msk:= 0; mskhh:= nil;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   145
mskcnt:= 0;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   146
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
   147
for t:= 0 to Pred(TeamsCount) do
869
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   148
	with TeamsArray[t]^ do
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   149
		begin
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   150
		for i:= 0 to cMaxHHIndex do
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   151
			begin
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   152
			if Hedgehogs[i].stats.MaxStepDamageGiven > msd then
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   153
				begin
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   154
				msdhh:= @Hedgehogs[i];
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   155
				msd:= Hedgehogs[i].stats.MaxStepDamageGiven
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   156
				end;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   157
			if Hedgehogs[i].stats.MaxStepKills >= msk then
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   158
				if Hedgehogs[i].stats.MaxStepKills = msk then
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   159
					inc(mskcnt)
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   160
				else
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   161
					begin
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   162
					mskcnt:= 1;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   163
					mskhh:= @Hedgehogs[i];
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   164
					msk:= Hedgehogs[i].stats.MaxStepKills
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   165
					end;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   166
			end
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   167
		end;
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   168
if msdhh <> nil then
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   169
	SendStat(siMaxStepDamage, inttostr(msd) + ' ' + msdhh^.Name + ' (' + msdhh^.Team^.TeamName + ')');
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   170
if mskcnt = 1 then
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   171
	SendStat(siMaxStepKills, inttostr(msk) + ' ' + mskhh^.Name + ' (' + mskhh^.Team^.TeamName + ')');
daddcd31ef34 - New statistics
unc0rr
parents: 867
diff changeset
   172
858
5005a485f103 Repair round statistics
unc0rr
parents: 831
diff changeset
   173
if KilledHHs > 0 then SendStat(siKilledHHs, inttostr(KilledHHs));
814
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
   174
end;
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
   175
7fb4417b7bc1 Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
diff changeset
   176
end.