hedgewars/uStats.pas
changeset 12384 1adc078355d1
parent 12359 81ab841a0da5
child 12568 494d3e1c4810
equal deleted inserted replaced
12383:e3d9abcc427a 12384:1adc078355d1
    22 interface
    22 interface
    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     SendGameResultOn : boolean = true;
       
    28     SendRankingStatsOn : boolean = true;
       
    29     SendAchievementsStatsOn : boolean = true;
    27     SendHealthStatsOn : boolean = true;
    30     SendHealthStatsOn : boolean = true;
    28 
    31 
    29 procedure initModule;
    32 procedure initModule;
    30 procedure freeModule;
    33 procedure freeModule;
    31 
    34 
    96 
    99 
    97 if CurrentHedgehog^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then inc(DamageClan, Damage);
   100 if CurrentHedgehog^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then inc(DamageClan, Damage);
    98 
   101 
    99 if killed then
   102 if killed then
   100     begin
   103     begin
       
   104     Gear^.Hedgehog^.stats.StepDied:= true;
   101     inc(Attacker^.stats.StepKills);
   105     inc(Attacker^.stats.StepKills);
   102     inc(Kills);
   106     inc(Kills);
   103     inc(KillsTotal);
   107     inc(KillsTotal);
   104     inc(Attacker^.Team^.stats.Kills);
   108     inc(Attacker^.Team^.stats.Kills);
   105     if (Attacker^.Team^.TeamName = Gear^.Hedgehog^.Team^.TeamName) then
   109     if (Attacker^.Team^.TeamName = Gear^.Hedgehog^.Team^.TeamName) then
   144     // First blood (first damage, poison or kill)
   148     // First blood (first damage, poison or kill)
   145     if ((DamageTotal > 0) or (KillsTotal > 0) or (PoisonTotal > 0)) and ((CurrentHedgehog^.stats.DamageGiven = DamageTotal) and (CurrentHedgehog^.stats.StepKills = KillsTotal) and (PoisonTotal = PoisonTurn + PoisonClan)) then
   149     if ((DamageTotal > 0) or (KillsTotal > 0) or (PoisonTotal > 0)) and ((CurrentHedgehog^.stats.DamageGiven = DamageTotal) and (CurrentHedgehog^.stats.StepKills = KillsTotal) and (PoisonTotal = PoisonTurn + PoisonClan)) then
   146         AddVoice(sndFirstBlood, CurrentTeam^.voicepack)
   150         AddVoice(sndFirstBlood, CurrentTeam^.voicepack)
   147 
   151 
   148     // Hog hurts, poisons or kills itself (except sacrifice)
   152     // Hog hurts, poisons or kills itself (except sacrifice)
   149     else if (CurrentHedgehog^.stats.Sacrificed = false) and ((CurrentHedgehog^.stats.StepDamageRecv > 0) or (CurrentHedgehog^.stats.StepPoisoned) or (CurrentHedgehog^.Gear = nil)) then
   153     else if (CurrentHedgehog^.stats.Sacrificed = false) and ((CurrentHedgehog^.stats.StepDamageRecv > 0) or (CurrentHedgehog^.stats.StepPoisoned) or (CurrentHedgehog^.stats.StepDied)) then
   150         begin
   154         begin
   151         AddVoice(sndStupid, PreviousTeam^.voicepack);
   155         AddVoice(sndStupid, PreviousTeam^.voicepack);
   152         // Message for hurting itself only (not drowning)
   156         // Message for hurting itself only (not drowning)
   153         if (CurrentHedgehog^.stats.DamageGiven = CurrentHedgehog^.stats.StepDamageRecv) and (CurrentHedgehog^.stats.StepDamageRecv >= 1) then
   157         if (CurrentHedgehog^.stats.DamageGiven = CurrentHedgehog^.stats.StepDamageRecv) and (CurrentHedgehog^.stats.StepDamageRecv >= 1) then
   154             AddCaption(FormatA(GetEventString(eidHurtSelf), s), cWhiteColor, capgrpMessage);
   158             AddCaption(FormatA(GetEventString(eidHurtSelf), s), cWhiteColor, capgrpMessage);
   213                     MaxStepKills:= StepKills;
   217                     MaxStepKills:= StepKills;
   214                 StepKills:= 0;
   218                 StepKills:= 0;
   215                 StepDamageRecv:= 0;
   219                 StepDamageRecv:= 0;
   216                 StepDamageGiven:= 0;
   220                 StepDamageGiven:= 0;
   217                 StepPoisoned:= false;
   221                 StepPoisoned:= false;
       
   222                 StepDied:= false;
   218                 end;
   223                 end;
   219 
   224 
   220 if SendHealthStatsOn then
   225 if SendHealthStatsOn then
   221     for t:= 0 to Pred(ClansCount) do
   226     for t:= 0 to Pred(ClansCount) do
   222         with ClansArray[t]^ do
   227         with ClansArray[t]^ do
   274     winnersClan:= nil;
   279     winnersClan:= nil;
   275 
   280 
   276     for t:= 0 to Pred(TeamsCount) do
   281     for t:= 0 to Pred(TeamsCount) do
   277         with TeamsArray[t]^ do
   282         with TeamsArray[t]^ do
   278         begin
   283         begin
   279             if not ExtDriven then
   284             if (not ExtDriven) and SendRankingStatsOn then
   280                 SendStat(siTeamStats, GetTeamStatString(TeamsArray[t]));
   285                 SendStat(siTeamStats, GetTeamStatString(TeamsArray[t]));
   281             for i:= 0 to cMaxHHIndex do
   286             for i:= 0 to cMaxHHIndex do
   282                 begin
   287                 begin
   283                 if Hedgehogs[i].stats.MaxStepDamageGiven > msd then
   288                 if Hedgehogs[i].stats.MaxStepDamageGiven > msd then
   284                     begin
   289                     begin
   298 
   303 
   299             { send player stats for winner teams }
   304             { send player stats for winner teams }
   300             if Clan^.ClanHealth > 0 then
   305             if Clan^.ClanHealth > 0 then
   301                 begin
   306                 begin
   302                 winnersClan:= Clan;
   307                 winnersClan:= Clan;
   303                 SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
   308                 if SendRankingStatsOn then
   304                     IntToStr(stats.Kills) + ' ' + TeamName);
   309                     SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
       
   310                         IntToStr(stats.Kills) + ' ' + TeamName);
   305             end;
   311             end;
   306 
   312 
   307             { determine maximum values of TeamKills, TurnSkips, TeamDamage }
   313             { determine maximum values of TeamKills, TurnSkips, TeamDamage }
   308             if stats.TeamKills > maxTeamKills then
   314             if stats.TeamKills > maxTeamKills then
   309                 begin
   315                 begin
   322             end;
   328             end;
   323 
   329 
   324         end;
   330         end;
   325 
   331 
   326     { now send player stats for loser teams }
   332     { now send player stats for loser teams }
   327     for t:= 0 to Pred(TeamsCount) do
   333     if SendRankingStatsOn then
   328         begin
   334         for t:= 0 to Pred(TeamsCount) do
   329         with TeamsArray[t]^ do
       
   330             begin
   335             begin
   331             if Clan^.ClanHealth = 0 then
   336             with TeamsArray[t]^ do
   332                 begin
   337                 begin
   333                 SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
   338                 if Clan^.ClanHealth = 0 then
   334                     IntToStr(stats.Kills) + ' ' + TeamName);
   339                     begin
       
   340                     SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
       
   341                         IntToStr(stats.Kills) + ' ' + TeamName);
       
   342                 end;
   335             end;
   343             end;
   336         end;
   344         end;
   337     end;
   345 
   338 
   346     // “Achievements” / Details part of stats screen
   339     if msdhh <> nil then
   347     if SendAchievementsStatsOn then
   340         SendStat(siMaxStepDamage, IntToStr(msd) + ' ' + msdhh^.Name + ' (' + msdhh^.Team^.TeamName + ')');
   348         begin
   341     if mskcnt = 1 then
   349         if msdhh <> nil then
   342         SendStat(siMaxStepKills, IntToStr(msk) + ' ' + mskhh^.Name + ' (' + mskhh^.Team^.TeamName + ')');
   350             SendStat(siMaxStepDamage, IntToStr(msd) + ' ' + msdhh^.Name + ' (' + msdhh^.Team^.TeamName + ')');
   343 
   351         if mskcnt = 1 then
   344     if maxTeamKills > 1 then
   352             SendStat(siMaxStepKills, IntToStr(msk) + ' ' + mskhh^.Name + ' (' + mskhh^.Team^.TeamName + ')');
   345         SendStat(siMaxTeamKills, IntToStr(maxTeamKills) + ' ' + maxTeamKillsName);
   353 
   346     if maxTurnSkips > 2 then
   354         if maxTeamKills > 1 then
   347         SendStat(siMaxTurnSkips, IntToStr(maxTurnSkips) + ' ' + maxTurnSkipsName);
   355             SendStat(siMaxTeamKills, IntToStr(maxTeamKills) + ' ' + maxTeamKillsName);
   348     if maxTeamDamage > 30 then
   356         if maxTurnSkips > 2 then
   349         SendStat(siMaxTeamDamage, IntToStr(maxTeamDamage) + ' ' + maxTeamDamageName);
   357             SendStat(siMaxTurnSkips, IntToStr(maxTurnSkips) + ' ' + maxTurnSkipsName);
   350 
   358         if maxTeamDamage > 30 then
   351     if KilledHHs > 0 then
   359             SendStat(siMaxTeamDamage, IntToStr(maxTeamDamage) + ' ' + maxTeamDamageName);
   352         SendStat(siKilledHHs, IntToStr(KilledHHs));
   360 
       
   361         if KilledHHs > 0 then
       
   362             SendStat(siKilledHHs, IntToStr(KilledHHs));
       
   363         end;
   353 
   364 
   354     // now to console
   365     // now to console
   355     if winnersClan <> nil then
   366     if winnersClan <> nil then
   356         begin
   367         begin
   357         WriteLnToConsole('WINNERS');
   368         WriteLnToConsole('WINNERS');