Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
authorWuzzy <almikes@aol.com>
Wed, 26 Apr 2017 01:51:51 +0200
changeset 12332 657a8d63c99d
parent 12331 6707ee1d2430
child 12333 6bdabf67a012
Lua API: SendAchevementsStatsOff, SendGameResultOff, SendRankingStatsOff
ChangeLog.txt
hedgewars/uScript.pas
hedgewars/uStats.pas
hedgewars/uTeams.pas
--- a/ChangeLog.txt	Wed Apr 26 01:46:38 2017 +0200
+++ b/ChangeLog.txt	Wed Apr 26 01:51:51 2017 +0200
@@ -237,6 +237,9 @@
  + New call: SetAmmoDescriptionAppendix(ammoType, descAppend) -- Append a custom text to the description of an ammo type without overwriting it
  + New call: GetHogFort(gearUid) -- Returns the name of the fort of the hog's team
  + New call: PlaceRubber(x, y, frameIdx) -- Places a rubber
+ + New call: SendGameResultOff() -- Disable the game automatically setting a game result in the stats screen
+ + New call: SendRankingStatsOff() -- Disable the game automatically filling the team rankings in the stats screen
+ + New call: SendAchievementsStatsOff() -- Disable the game automatically populating the bullet point list in the “Details” section on the stats screen
  + New call: EndTurn([noTaunts]) -- Ends the current turn
  + New hook: onVisualGearAdd(vgUid) -- called when a visual gear is added
  + New hook: onVisualGearDelete(vgUid) -- called when a visual gear is deleted
--- a/hedgewars/uScript.pas	Wed Apr 26 01:46:38 2017 +0200
+++ b/hedgewars/uScript.pas	Wed Apr 26 01:51:51 2017 +0200
@@ -1937,6 +1937,27 @@
     lc_sendstat:= 0
 end;
 
+function lc_sendgameresultoff(L : Plua_State) : LongInt; Cdecl;
+begin
+    L:= L; // avoid compiler hint
+    uStats.SendGameResultOn := false;
+    lc_sendgameresultoff:= 0
+end;
+
+function lc_sendrankingstatsoff(L : Plua_State) : LongInt; Cdecl;
+begin
+    L:= L; // avoid compiler hint
+    uStats.SendRankingStatsOn := false;
+    lc_sendrankingstatsoff:= 0
+end;
+
+function lc_sendachievementsstatsoff(L : Plua_State) : LongInt; Cdecl;
+begin
+    L:= L; // avoid compiler hint
+    uStats.SendAchievementsStatsOn := false;
+    lc_sendachievementsstatsoff:= 0
+end;
+
 function lc_sendhealthstatsoff(L : Plua_State) : LongInt; Cdecl;
 begin
     L:= L; // avoid compiler hint
@@ -3409,6 +3430,9 @@
 lua_register(luaState, _P'EndGame', @lc_endgame);
 lua_register(luaState, _P'EndTurn', @lc_endturn);
 lua_register(luaState, _P'SendStat', @lc_sendstat);
+lua_register(luaState, _P'SendGameResultOff', @lc_sendgameresultoff);
+lua_register(luaState, _P'SendRankingStatsOff', @lc_sendrankingstatsoff);
+lua_register(luaState, _P'SendAchievementsStatsOff', @lc_sendachievementsstatsoff);
 lua_register(luaState, _P'SendHealthStatsOff', @lc_sendhealthstatsoff);
 lua_register(luaState, _P'FindPlace', @lc_findplace);
 lua_register(luaState, _P'SetGearPosition', @lc_setgearposition);
--- a/hedgewars/uStats.pas	Wed Apr 26 01:46:38 2017 +0200
+++ b/hedgewars/uStats.pas	Wed Apr 26 01:51:51 2017 +0200
@@ -24,6 +24,9 @@
 
 var TotalRounds: LongInt;
     FinishedTurnsTotal: LongInt;
+    SendGameResultOn : boolean = true;
+    SendRankingStatsOn : boolean = true;
+    SendAchievementsStatsOn : boolean = true;
     SendHealthStatsOn : boolean = true;
 
 procedure initModule;
@@ -276,7 +279,7 @@
     for t:= 0 to Pred(TeamsCount) do
         with TeamsArray[t]^ do
         begin
-            if not ExtDriven then
+            if (not ExtDriven) and SendRankingStatsOn then
                 SendStat(siTeamStats, GetTeamStatString(TeamsArray[t]));
             for i:= 0 to cMaxHHIndex do
                 begin
@@ -300,8 +303,9 @@
             if Clan^.ClanHealth > 0 then
                 begin
                 winnersClan:= Clan;
-                SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
-                    IntToStr(stats.Kills) + ' ' + TeamName);
+                if SendRankingStatsOn then
+                    SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
+                        IntToStr(stats.Kills) + ' ' + TeamName);
             end;
 
             { determine maximum values of TeamKills, TurnSkips, TeamDamage }
@@ -324,32 +328,37 @@
         end;
 
     { now send player stats for loser teams }
-    for t:= 0 to Pred(TeamsCount) do
-        begin
-        with TeamsArray[t]^ do
+    if SendRankingStatsOn then
+        for t:= 0 to Pred(TeamsCount) do
             begin
-            if Clan^.ClanHealth = 0 then
+            with TeamsArray[t]^ do
                 begin
-                SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
-                    IntToStr(stats.Kills) + ' ' + TeamName);
+                if Clan^.ClanHealth = 0 then
+                    begin
+                    SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
+                        IntToStr(stats.Kills) + ' ' + TeamName);
+                end;
             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 + ')');
+    // “Achievements” / Details part of stats screen
+    if SendAchievementsStatsOn then
+        begin
+        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 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 KilledHHs > 0 then
+            SendStat(siKilledHHs, IntToStr(KilledHHs));
+        end;
 
     // now to console
     if winnersClan <> nil then
--- a/hedgewars/uTeams.pas	Wed Apr 26 01:46:38 2017 +0200
+++ b/hedgewars/uTeams.pas	Wed Apr 26 01:51:51 2017 +0200
@@ -82,7 +82,8 @@
     if AliveCount = 0 then
         begin // draw
         AddCaption(GetEventString(eidRoundDraw), cWhiteColor, capgrpGameState);
-        SendStat(siGameResult, shortstring(trmsg[sidDraw]));
+        if SendGameResultOn then
+            SendStat(siGameResult, shortstring(trmsg[sidDraw]));
         AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000);
         end
     else // win
@@ -113,7 +114,8 @@
                 AddVoice(sndVictory, Teams[0]^.voicepack);
 
             AddCaption(cap, cWhiteColor, capgrpGameState);
-            SendStat(siGameResult, shortstring(s));
+            if SendGameResultOn then
+                SendStat(siGameResult, shortstring(s));
             AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000)
             end;
     SendStats;