Fix player rankings on round draw: Clans that die in the same turn now have the same rank
authorWuzzy <Wuzzy2@mail.ru>
Tue, 04 Sep 2018 15:03:35 +0200
changeset 13762 f0cb47f0bfaf
parent 13761 a0d6404a80a2
child 13763 b1177e9c9ee9
Fix player rankings on round draw: Clans that die in the same turn now have the same rank
ChangeLog.txt
QTfrontend/ui/page/pagegamestats.cpp
QTfrontend/ui/page/pagegamestats.h
hedgewars/uIO.pas
hedgewars/uStats.pas
hedgewars/uTypes.pas
--- a/ChangeLog.txt	Tue Sep 04 14:20:15 2018 +0200
+++ b/ChangeLog.txt	Tue Sep 04 15:03:35 2018 +0200
@@ -37,6 +37,8 @@
 
 Frontend:
  + Add setting to disable audio dampening when losing window focus
+ + Rework player rankings: Losing clans are now ranked in the reverse order they died
+ * Fix player rankings on round draw: Clans that died in the same turn now have the same rank
  * Fix rare crash when aborting video encoding in progress
  * Fix critical failure to cleanup teams list after rejoining game under certain conditions
  * Controllers are detected again
@@ -121,6 +123,7 @@
  + Change callback: onGearResurrect: 2nd parameter for visual gear spawned at resurrect position (might be nil)
  + New parameter: SetAmmoTexts: 5th param. showExtra: Set to false to hide texts like “Not yet available”
  + New parameter: ShowMission: 6th param. forceDisplay: Set to true to prevent this particular mission panel to be hidden manually by player
+ + Can set custom team rank: Call SendStat with 1st param siTeamRank and 2nd param to the desired rank, as string. Must be called before siPlayerKills of the team for which this applies
  + New Lua library: Achievements
  + Add sprite tint globals in Utilts library: U_LAND_TINT_NORMAL, U_LAND_TINT_ICE, U_LAND_TINT_INDESTRUCTIBLE and U_LAND_TINT_BOUNCY
  + New globals: Infinite fly time for jetpack/Birdy by setting health to JETPACK_FUEL_INFINITE or BIRDY_ENERGY_INFINITE, respectively
--- a/QTfrontend/ui/page/pagegamestats.cpp	Tue Sep 04 14:20:15 2018 +0200
+++ b/QTfrontend/ui/page/pagegamestats.cpp	Tue Sep 04 15:03:35 2018 +0200
@@ -152,6 +152,7 @@
     labelGameRank->setText("");
     labelGameWin->setText("");
     playerPosition = 0;
+    scriptPlayerPosition = 0;
     lastColor = 0;
 }
 
@@ -326,7 +327,13 @@
             if (lastColor == c) playerPosition--;
             lastColor = c;
 
-            switch (playerPosition)
+            unsigned int realPlayerPosition;
+            if(scriptPlayerPosition == 0)
+                realPlayerPosition = playerPosition;
+            else
+                realPlayerPosition = scriptPlayerPosition;
+
+            switch (realPlayerPosition)
             {
                 case 1:
                     image = "<img src=\":/res/StatsMedal1.png\">";
@@ -353,9 +360,10 @@
                 kindOfPoints = QString("");
             }
 
-            message = QString("<p><h2>%1 %2. <font color=\"%4\">%3</font> ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "</h2></p>";
+            message = QString("<p><h2>%1 %2. <font color=\"%4\">%3</font> ").arg(image, QString::number(realPlayerPosition), playername, clanColor.name()) + killstring + "</h2></p>";
 
             labelGameRank->setText(labelGameRank->text() + message);
+            scriptPlayerPosition = 0;
             break;
         }
         case 's' :
@@ -388,6 +396,10 @@
             AddStatText(message);
             break;
         }
-
+        case 'R' :
+        {
+            scriptPlayerPosition = info.toInt();
+            break;
+        }
     }
 }
--- a/QTfrontend/ui/page/pagegamestats.h	Tue Sep 04 14:20:15 2018 +0200
+++ b/QTfrontend/ui/page/pagegamestats.h	Tue Sep 04 15:03:35 2018 +0200
@@ -68,6 +68,7 @@
 
         QMap<qint32, QVector<qint32> > healthPoints;
         unsigned int playerPosition;
+        unsigned int scriptPlayerPosition;
         quint32 lastColor;
         bool defaultGraphTitle;
         QScopedPointer<QGraphicsScene> m_scene;
--- a/hedgewars/uIO.pas	Tue Sep 04 14:20:15 2018 +0200
+++ b/hedgewars/uIO.pas	Tue Sep 04 15:03:35 2018 +0200
@@ -254,7 +254,7 @@
 end;
 
 procedure SendStat(sit: TStatInfoType; s: shortstring);
-const stc: array [TStatInfoType] of char = ('r', 'D', 'k', 'K', 'H', 'T', 'P', 's', 'S', 'B', 'c', 'g', 'p');
+const stc: array [TStatInfoType] of char = ('r', 'D', 'k', 'K', 'H', 'T', 'P', 's', 'S', 'B', 'c', 'g', 'p', 'R');
 var buf: shortstring;
 begin
 buf:= 'i' + stc[sit] + s;
--- a/hedgewars/uStats.pas	Tue Sep 04 14:20:15 2018 +0200
+++ b/hedgewars/uStats.pas	Tue Sep 04 15:03:35 2018 +0200
@@ -312,6 +312,7 @@
     maxTeamDamageName : shortstring;
     winnersClan : PClan;
     deathEntry : PClanDeathLogEntry;
+    currentRank: Longword;
 begin
 if SendHealthStatsOn then
     msd:= 0; msdhh:= nil;
@@ -321,6 +322,7 @@
     maxTurnSkips := 0;
     maxTeamDamage := 0;
     winnersClan:= nil;
+    currentRank:= 0;
 
     for t:= 0 to Pred(TeamsCount) do
         with TeamsArray[t]^ do
@@ -351,8 +353,12 @@
                 begin
                 winnersClan:= Clan;
                 if SendRankingStatsOn then
+                    begin
+                    currentRank:= 1;
+                    SendStat(siTeamRank, '1');
                     SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
                         IntToStr(stats.Kills) + ' ' + TeamName);
+                    end;
             end;
 
             { determine maximum values of TeamKills, TurnSkips, TeamDamage }
@@ -374,12 +380,15 @@
 
         end;
 
+    inc(currentRank);
+
     { Now send player stats for loser teams/clans.
     The losing clans are ranked in the reverse order they died.
     The clan that died last is ranked 2nd,
     the clan that died second to last is ranked 3rd,
     and so on. }
     deathEntry := ClanDeathLog;
+    i:= 0;
     if SendRankingStatsOn then
         while (deathEntry <> nil) do
             begin
@@ -389,11 +398,16 @@
                     for t:= 0 to Pred(TeamsCount) do
                         if TeamsArray[t]^.Clan^.ClanIndex = deathEntry^.KilledClans[c]^.ClanIndex then
                             begin
+                            inc(i);
+                            SendStat(siTeamRank, IntToStr(currentRank));
                             SendStat(siPlayerKills, IntToStr(deathEntry^.killedClans[c]^.Color) + ' ' +
                                 IntToStr(TeamsArray[t]^.stats.Kills) + ' ' + TeamsArray[t]^.TeamName);
                             end;
                     deathEntry^.KilledClans[c]^.StatsHandled:= true;
                     end;
+            if i > 0 then
+                inc(currentRank, i);
+            i:= 0;
             deathEntry:= deathEntry^.NextEntry;
             end;
 
--- a/hedgewars/uTypes.pas	Tue Sep 04 14:20:15 2018 +0200
+++ b/hedgewars/uTypes.pas	Tue Sep 04 15:03:35 2018 +0200
@@ -176,7 +176,7 @@
     TStatInfoType = (siGameResult, siMaxStepDamage, siMaxStepKills, siKilledHHs,
             siClanHealth, siTeamStats, siPlayerKills, siMaxTeamDamage,
             siMaxTeamKills, siMaxTurnSkips, siCustomAchievement, siGraphTitle,
-            siPointType);
+            siPointType, siTeamRank);
 
     // Various 'emote' animations a hedgehog can do
     TWave = (waveRollup, waveSad, waveWave, waveHurrah, waveLemonade, waveShrug, waveJuggle);