made lua scripts able to turn off automatic game stats
authorPeriklis Ntanasis <pntanasis@gmail.com>
Thu, 06 Jun 2013 03:52:32 +0300
changeset 9174 d328fe17b195
parent 9173 575dd8fe4a55
child 9175 dc3c0e44f7f3
made lua scripts able to turn off automatic game stats
hedgewars/uScript.pas
hedgewars/uStats.pas
--- a/hedgewars/uScript.pas	Thu Jun 06 03:35:59 2013 +0300
+++ b/hedgewars/uScript.pas	Thu Jun 06 03:52:32 2013 +0300
@@ -1323,6 +1323,13 @@
     lc_sendstat:= 0
 end;
 
+function lc_sendstatsoff(L : Plua_State) : LongInt; Cdecl;
+begin
+    L:= L; // avoid compiler hint
+    uStats.SendStatsOn := false;
+    lc_sendstatsoff:= 0
+end;
+
 function lc_sendstats(L : Plua_State) : LongInt; Cdecl;
 begin
     L:= L; // avoid compiler hint
@@ -2428,6 +2435,7 @@
 lua_register(luaState, _P'GetGearType', @lc_getgeartype);
 lua_register(luaState, _P'EndGame', @lc_endgame);
 lua_register(luaState, _P'SendStat', @lc_sendstat);
+lua_register(luaState, _P'SendStatsOff', @lc_sendstatsoff);
 lua_register(luaState, _P'SendStats', @lc_sendstats);
 lua_register(luaState, _P'FindPlace', @lc_findplace);
 lua_register(luaState, _P'SetGearPosition', @lc_setgearposition);
--- a/hedgewars/uStats.pas	Thu Jun 06 03:35:59 2013 +0300
+++ b/hedgewars/uStats.pas	Thu Jun 06 03:52:32 2013 +0300
@@ -24,7 +24,8 @@
 
 var TotalRounds: LongInt;
     FinishedTurnsTotal: LongInt;
-
+    SendStatsOn : boolean = true;
+    
 procedure initModule;
 procedure freeModule;
 
@@ -162,12 +163,13 @@
                 StepDamageRecv:= 0;
                 StepDamageGiven:= 0
                 end;
-
-for t:= 0 to Pred(ClansCount) do
-    with ClansArray[t]^ do
-        begin
-        SendStat(siClanHealth, IntToStr(Color) + ' ' + IntToStr(ClanHealth));
-        end;
+                
+if SendStatsOn then
+	for t:= 0 to Pred(ClansCount) do
+		with ClansArray[t]^ do
+			begin
+			SendStat(siClanHealth, IntToStr(Color) + ' ' + IntToStr(ClanHealth));
+			end;
 
 Kills:= 0;
 KillsClan:= 0;
@@ -207,103 +209,104 @@
     maxTeamDamageName : shortstring;
     winnersClan : PClan;
 begin
-msd:= 0; msdhh:= nil;
-msk:= 0; mskhh:= nil;
-mskcnt:= 0;
-maxTeamKills := 0;
-maxTurnSkips := 0;
-maxTeamDamage := 0;
-winnersClan:= nil;
+if SendStatsOn then
+	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 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));
 
-// 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');
+	// 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('');
+	WriteLnToConsole('');
 end;
 
 procedure initModule;