--- a/hedgewars/uStats.pas Fri Oct 11 11:55:31 2013 +0200
+++ b/hedgewars/uStats.pas Fri Oct 11 17:43:13 2013 +0200
@@ -35,9 +35,10 @@
procedure TurnReaction;
procedure SendStats;
procedure hedgehogFlight(Gear: PGear; time: Longword);
+procedure declareAchievement(id, teamname, location: shortstring; value: LongInt);
implementation
-uses uSound, uLocale, uVariables, uUtils, uIO, uCaptions, uDebug, uMisc, uConsole;
+uses uSound, uLocale, uVariables, uUtils, uIO, uCaptions, uDebug, uMisc, uConsole, uScript;
var DamageClan : Longword = 0;
DamageTotal : Longword = 0;
@@ -165,11 +166,11 @@
end;
if SendHealthStatsOn then
- for t:= 0 to Pred(ClansCount) do
- with ClansArray[t]^ do
- begin
- SendStat(siClanHealth, IntToStr(Color) + ' ' + IntToStr(ClanHealth));
- end;
+ for t:= 0 to Pred(ClansCount) do
+ with ClansArray[t]^ do
+ begin
+ SendStat(siClanHealth, IntToStr(Color) + ' ' + IntToStr(ClanHealth));
+ end;
Kills:= 0;
KillsClan:= 0;
@@ -210,103 +211,114 @@
winnersClan : PClan;
begin
if SendHealthStatsOn then
- msd:= 0; msdhh:= nil;
- msk:= 0; mskhh:= nil;
- mskcnt:= 0;
- maxTeamKills := 0;
- maxTurnSkips := 0;
- maxTeamDamage := 0;
- winnersClan:= nil;
+ msd:= 0; msdhh:= nil;
+ msk:= 0; mskhh:= nil;
+ mskcnt:= 0;
+ maxTeamKills := 0;
+ maxTurnSkips := 0;
+ maxTeamDamage := 0;
+ winnersClan:= nil;
- for t:= 0 to Pred(TeamsCount) do
- with TeamsArray[t]^ do
- begin
- if not ExtDriven then
- SendStat(siTeamStats, GetTeamStatString(TeamsArray[t]));
- for i:= 0 to cMaxHHIndex do
- begin
- if Hedgehogs[i].stats.MaxStepDamageGiven > msd then
- begin
- msdhh:= @Hedgehogs[i];
- msd:= Hedgehogs[i].stats.MaxStepDamageGiven
- end;
- if Hedgehogs[i].stats.MaxStepKills >= msk then
- if Hedgehogs[i].stats.MaxStepKills = msk then
- inc(mskcnt)
- else
- begin
- mskcnt:= 1;
- mskhh:= @Hedgehogs[i];
- msk:= Hedgehogs[i].stats.MaxStepKills
- end;
- end;
+ for t:= 0 to Pred(TeamsCount) do
+ with TeamsArray[t]^ do
+ begin
+ if not ExtDriven then
+ SendStat(siTeamStats, GetTeamStatString(TeamsArray[t]));
+ for i:= 0 to cMaxHHIndex do
+ begin
+ if Hedgehogs[i].stats.MaxStepDamageGiven > msd then
+ begin
+ msdhh:= @Hedgehogs[i];
+ msd:= Hedgehogs[i].stats.MaxStepDamageGiven
+ end;
+ if Hedgehogs[i].stats.MaxStepKills >= msk then
+ if Hedgehogs[i].stats.MaxStepKills = msk then
+ inc(mskcnt)
+ else
+ begin
+ mskcnt:= 1;
+ mskhh:= @Hedgehogs[i];
+ msk:= Hedgehogs[i].stats.MaxStepKills
+ end;
+ end;
- { send player stats for winner teams }
- if Clan^.ClanHealth > 0 then
- begin
- winnersClan:= Clan;
- SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
- IntToStr(stats.Kills) + ' ' + TeamName);
- end;
+ { send player stats for winner teams }
+ if Clan^.ClanHealth > 0 then
+ begin
+ winnersClan:= Clan;
+ SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
+ IntToStr(stats.Kills) + ' ' + TeamName);
+ end;
- { determine maximum values of TeamKills, TurnSkips, TeamDamage }
- if stats.TeamKills > maxTeamKills then
- begin
- maxTeamKills := stats.TeamKills;
- maxTeamKillsName := TeamName;
- end;
- if stats.TurnSkips > maxTurnSkips then
- begin
- maxTurnSkips := stats.TurnSkips;
- maxTurnSkipsName := TeamName;
- end;
- if stats.TeamDamage > maxTeamDamage then
- begin
- maxTeamDamage := stats.TeamDamage;
- maxTeamDamageName := TeamName;
- end;
+ { determine maximum values of TeamKills, TurnSkips, TeamDamage }
+ if stats.TeamKills > maxTeamKills then
+ begin
+ maxTeamKills := stats.TeamKills;
+ maxTeamKillsName := TeamName;
+ end;
+ if stats.TurnSkips > maxTurnSkips then
+ begin
+ maxTurnSkips := stats.TurnSkips;
+ maxTurnSkipsName := TeamName;
+ end;
+ if stats.TeamDamage > maxTeamDamage then
+ begin
+ maxTeamDamage := stats.TeamDamage;
+ maxTeamDamageName := TeamName;
+ end;
- end;
+ end;
+
+ { now send player stats for loser teams }
+ for t:= 0 to Pred(TeamsCount) do
+ begin
+ with TeamsArray[t]^ do
+ begin
+ if Clan^.ClanHealth = 0 then
+ begin
+ SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
+ IntToStr(stats.Kills) + ' ' + TeamName);
+ end;
+ end;
+ end;
- { now send player stats for loser teams }
- for t:= 0 to Pred(TeamsCount) do
- begin
- with TeamsArray[t]^ do
- begin
- if Clan^.ClanHealth = 0 then
- begin
- SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
- IntToStr(stats.Kills) + ' ' + TeamName);
- end;
- end;
- end;
+ if msdhh <> nil then
+ SendStat(siMaxStepDamage, IntToStr(msd) + ' ' + msdhh^.Name + ' (' + msdhh^.Team^.TeamName + ')');
+ if mskcnt = 1 then
+ SendStat(siMaxStepKills, IntToStr(msk) + ' ' + mskhh^.Name + ' (' + mskhh^.Team^.TeamName + ')');
- if msdhh <> nil then
- SendStat(siMaxStepDamage, IntToStr(msd) + ' ' + msdhh^.Name + ' (' + msdhh^.Team^.TeamName + ')');
- if mskcnt = 1 then
- SendStat(siMaxStepKills, IntToStr(msk) + ' ' + mskhh^.Name + ' (' + mskhh^.Team^.TeamName + ')');
+ if maxTeamKills > 1 then
+ SendStat(siMaxTeamKills, IntToStr(maxTeamKills) + ' ' + maxTeamKillsName);
+ if maxTurnSkips > 2 then
+ SendStat(siMaxTurnSkips, IntToStr(maxTurnSkips) + ' ' + maxTurnSkipsName);
+ if maxTeamDamage > 30 then
+ SendStat(siMaxTeamDamage, IntToStr(maxTeamDamage) + ' ' + maxTeamDamageName);
+
+ if KilledHHs > 0 then
+ SendStat(siKilledHHs, IntToStr(KilledHHs));
- if maxTeamKills > 1 then
- SendStat(siMaxTeamKills, IntToStr(maxTeamKills) + ' ' + maxTeamKillsName);
- if maxTurnSkips > 2 then
- SendStat(siMaxTurnSkips, IntToStr(maxTurnSkips) + ' ' + maxTurnSkipsName);
- if maxTeamDamage > 30 then
- SendStat(siMaxTeamDamage, IntToStr(maxTeamDamage) + ' ' + maxTeamDamageName);
-
- if KilledHHs > 0 then
- SendStat(siKilledHHs, IntToStr(KilledHHs));
+ // now to console
+ if winnersClan <> nil then
+ begin
+ WriteLnToConsole('WINNERS');
+ WriteLnToConsole(inttostr(winnersClan^.TeamsNumber));
+ for t:= 0 to winnersClan^.TeamsNumber - 1 do
+ WriteLnToConsole(winnersClan^.Teams[t]^.TeamName);
+ end
+ else
+ WriteLnToConsole('DRAW');
+
+ ScriptCall('onAchievementsDeclaration');
+end;
- // now to console
- if winnersClan <> nil then
- begin
- WriteLnToConsole('WINNERS');
- for t:= 0 to winnersClan^.TeamsNumber - 1 do
- WriteLnToConsole(winnersClan^.Teams[t]^.TeamName);
- end
- else
- WriteLnToConsole('DRAW');
-
- WriteLnToConsole('');
+procedure declareAchievement(id, teamname, location: shortstring; value: LongInt);
+begin
+if (length(id) = 0) or (length(teamname) = 0) or (length(location) = 0) then exit;
+ WriteLnToConsole('ACHIEVEMENT');
+ WriteLnToConsole(id);
+ WriteLnToConsole(teamname);
+ WriteLnToConsole(location);
+ WriteLnToConsole(inttostr(value));
end;
procedure initModule;