1 (* |
1 (* |
2 * Hedgewars, a free turn based strategy game |
2 * Hedgewars, a free turn based strategy game |
3 * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
3 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4 * |
4 * |
5 * This program is free software; you can redistribute it and/or modify |
5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License as published by |
6 * it under the terms of the GNU General Public License as published by |
7 * the Free Software Foundation; version 2 of the License |
7 * the Free Software Foundation; version 2 of the License |
8 * |
8 * |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. |
12 * GNU General Public License for more details. |
13 * |
13 * |
14 * You should have received a copy of the GNU General Public License |
14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software |
15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 *) |
17 *) |
18 |
18 |
19 {$INCLUDE "options.inc"} |
19 {$INCLUDE "options.inc"} |
20 |
20 |
21 unit uStats; |
21 unit uStats; |
23 uses uConsts, uTypes; |
23 uses uConsts, uTypes; |
24 |
24 |
25 var TotalRounds: LongInt; |
25 var TotalRounds: LongInt; |
26 FinishedTurnsTotal: LongInt; |
26 FinishedTurnsTotal: LongInt; |
27 SendHealthStatsOn : boolean = true; |
27 SendHealthStatsOn : boolean = true; |
28 |
28 |
29 procedure initModule; |
29 procedure initModule; |
30 procedure freeModule; |
30 procedure freeModule; |
31 |
31 |
32 procedure AmmoUsed(am: TAmmoType); |
32 procedure AmmoUsed(am: TAmmoType); |
33 procedure HedgehogDamaged(Gear: PGear; Attacker: PHedgehog; Damage: Longword; killed: boolean); |
33 procedure HedgehogDamaged(Gear: PGear; Attacker: PHedgehog; Damage: Longword; killed: boolean); |
95 isTurnSkipped:= true |
95 isTurnSkipped:= true |
96 end; |
96 end; |
97 |
97 |
98 procedure TurnReaction; |
98 procedure TurnReaction; |
99 var i, t: LongInt; |
99 var i, t: LongInt; |
|
100 s: ansistring; |
100 begin |
101 begin |
101 TryDo(not bBetweenTurns, 'Engine bug: TurnReaction between turns', true); |
102 TryDo(not bBetweenTurns, 'Engine bug: TurnReaction between turns', true); |
102 |
103 |
103 inc(FinishedTurnsTotal); |
104 inc(FinishedTurnsTotal); |
104 if FinishedTurnsTotal <> 0 then |
105 if FinishedTurnsTotal <> 0 then |
105 begin |
106 begin |
|
107 s:= ansistring(CurrentHedgehog^.Name); |
106 inc(CurrentHedgehog^.stats.FinishedTurns); |
108 inc(CurrentHedgehog^.stats.FinishedTurns); |
107 |
109 |
108 if (CurrentHedgehog^.stats.DamageGiven = DamageTotal) and (DamageTotal > 0) then |
110 if (CurrentHedgehog^.stats.DamageGiven = DamageTotal) and (DamageTotal > 0) then |
109 AddVoice(sndFirstBlood, CurrentTeam^.voicepack) |
111 AddVoice(sndFirstBlood, CurrentTeam^.voicepack) |
110 |
112 |
111 else if CurrentHedgehog^.stats.StepDamageRecv > 0 then |
113 else if CurrentHedgehog^.stats.StepDamageRecv > 0 then |
112 begin |
114 begin |
113 AddVoice(sndStupid, PreviousTeam^.voicepack); |
115 AddVoice(sndStupid, PreviousTeam^.voicepack); |
114 if CurrentHedgehog^.stats.DamageGiven = CurrentHedgehog^.stats.StepDamageRecv then |
116 if CurrentHedgehog^.stats.DamageGiven = CurrentHedgehog^.stats.StepDamageRecv then |
115 AddCaption(Format(GetEventString(eidHurtSelf), CurrentHedgehog^.Name), cWhiteColor, capgrpMessage); |
117 AddCaption(FormatA(GetEventString(eidHurtSelf), s), cWhiteColor, capgrpMessage); |
116 end |
118 end |
117 |
119 |
118 else if DamageClan <> 0 then |
120 else if DamageClan <> 0 then |
119 if DamageTurn > DamageClan then |
121 if DamageTurn > DamageClan then |
120 if random(2) = 0 then |
122 if random(2) = 0 then |
138 else if (AmmoUsedCount > 0) and (not isTurnSkipped) then |
140 else if (AmmoUsedCount > 0) and (not isTurnSkipped) then |
139 begin end// nothing ? |
141 begin end// nothing ? |
140 else if isTurnSkipped then |
142 else if isTurnSkipped then |
141 begin |
143 begin |
142 AddVoice(sndBoring, PreviousTeam^.voicepack); |
144 AddVoice(sndBoring, PreviousTeam^.voicepack); |
143 AddCaption(Format(GetEventString(eidTurnSkipped), CurrentHedgehog^.Name), cWhiteColor, capgrpMessage); |
145 AddCaption(FormatA(GetEventString(eidTurnSkipped), s), cWhiteColor, capgrpMessage); |
144 end |
146 end |
145 else if not PlacingHogs then |
147 else if not PlacingHogs then |
146 AddVoice(sndCoward, PreviousTeam^.voicepack); |
148 AddVoice(sndCoward, PreviousTeam^.voicepack); |
147 end; |
149 end; |
148 |
150 |
162 MaxStepKills:= StepKills; |
164 MaxStepKills:= StepKills; |
163 StepKills:= 0; |
165 StepKills:= 0; |
164 StepDamageRecv:= 0; |
166 StepDamageRecv:= 0; |
165 StepDamageGiven:= 0 |
167 StepDamageGiven:= 0 |
166 end; |
168 end; |
167 |
169 |
168 if SendHealthStatsOn then |
170 if SendHealthStatsOn then |
169 for t:= 0 to Pred(ClansCount) do |
171 for t:= 0 to Pred(ClansCount) do |
170 with ClansArray[t]^ do |
172 with ClansArray[t]^ do |
171 begin |
173 begin |
172 SendStat(siClanHealth, IntToStr(Color) + ' ' + IntToStr(ClanHealth)); |
174 SendStat(siClanHealth, IntToStr(Color) + ' ' + IntToStr(ClanHealth)); |
296 |
298 |
297 if KilledHHs > 0 then |
299 if KilledHHs > 0 then |
298 SendStat(siKilledHHs, IntToStr(KilledHHs)); |
300 SendStat(siKilledHHs, IntToStr(KilledHHs)); |
299 |
301 |
300 // now to console |
302 // now to console |
301 if winnersClan <> nil then |
303 if winnersClan <> nil then |
302 begin |
304 begin |
303 WriteLnToConsole('WINNERS'); |
305 WriteLnToConsole('WINNERS'); |
304 WriteLnToConsole(inttostr(winnersClan^.TeamsNumber)); |
306 WriteLnToConsole(inttostr(winnersClan^.TeamsNumber)); |
305 for t:= 0 to winnersClan^.TeamsNumber - 1 do |
307 for t:= 0 to winnersClan^.TeamsNumber - 1 do |
306 WriteLnToConsole(winnersClan^.Teams[t]^.TeamName); |
308 WriteLnToConsole(winnersClan^.Teams[t]^.TeamName); |
307 end |
309 end |
308 else |
310 else |
309 WriteLnToConsole('DRAW'); |
311 WriteLnToConsole('DRAW'); |
310 |
312 |
311 ScriptCall('onAchievementsDeclaration'); |
313 ScriptCall('onAchievementsDeclaration'); |
312 end; |
314 end; |
313 |
315 |
314 procedure declareAchievement(id, teamname, location: shortstring; value: LongInt); |
316 procedure declareAchievement(id, teamname, location: shortstring; value: LongInt); |
315 begin |
317 begin |
316 if (length(id) = 0) or (length(teamname) = 0) or (length(location) = 0) then exit; |
318 if (length(id) = 0) or (length(teamname) = 0) or (length(location) = 0) then exit; |
317 WriteLnToConsole('ACHIEVEMENT'); |
319 WriteLnToConsole('ACHIEVEMENT'); |
318 WriteLnToConsole(id); |
320 WriteLnToConsole(id); |
319 WriteLnToConsole(teamname); |
321 WriteLnToConsole(teamname); |
320 WriteLnToConsole(location); |
322 WriteLnToConsole(location); |