CTF: Show team scores and score graph in stats screen
authorWuzzy <Wuzzy2@mail.ru>
Thu, 08 Mar 2018 14:47:47 +0100
changeset 13113 75afd374b764
parent 13112 714f6e5b89fd
child 13114 c3fc9157f740
CTF: Show team scores and score graph in stats screen
ChangeLog.txt
share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua
--- a/ChangeLog.txt	Thu Mar 08 13:42:36 2018 +0100
+++ b/ChangeLog.txt	Thu Mar 08 14:47:47 2018 +0100
@@ -49,6 +49,7 @@
  + Battalion (King Mode): If the king dies, the hogs die normally instead of disappearing
  + Space Invasion: Add a default Space Invasion game scheme
  + Capture the Flag: Can now be played with more than 2 clans
+ + Capture the Flag: Show team scores and score graphi in stats screen
  + HedgeEditor: Show cursor coordinates in top left corner
  + Control: Always remove TimeBox and Resurrector
  * Battalion: Some texts in the mission panel were wrong and misleading
--- a/share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua	Thu Mar 08 13:42:36 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua	Thu Mar 08 14:47:47 2018 +0100
@@ -151,6 +151,24 @@
 			AddCaption(string.format(loc("Victory for %s!"), GetHogTeamName(CurrentHedgehog)), 0xFFFFFFFF, capgrpGameState)
 			updateScores()
 		end
+
+		-- Calculate team rankings
+
+		local teamList = {}
+		for i=0, TeamsCount-1 do
+			local name = GetTeamName(i)
+			local clan = GetTeamClan(name)
+			table.insert(teamList, { score = fCaptures[clan], name = name, clan = clan })
+		end
+		local teamRank = function(a, b)
+			return a.score > b.score
+		end
+		table.sort(teamList, teamRank)
+
+		for i=1, #teamList do
+			SendStat(siPointType, loc("point(s)"))
+			SendStat(siPlayerKills, tostring(teamList[i].score), teamList[i].name)
+		end
 	end
 
 end
@@ -254,6 +272,19 @@
 
 end
 
+-- Advance the clan score graph by one step
+function DrawScores()
+	local clansUsed = {}
+	for i=0, TeamsCount-1 do
+		local team = GetTeamName(i)
+		local clan = GetTeamClan(team)
+		if not clansUsed[clan] then
+			local captures = fCaptures[clan]
+			SendStat(siClanHealth, captures, team)
+			clansUsed[clan] = true
+		end
+	end
+end
 
 function FlagThiefDead(gear)
 
@@ -408,7 +439,6 @@
 	-- Disable Sudden Death
 	WaterRise = 0
 	HealthDecrease = 0
-
 end
 
 function showCTFMission()
@@ -456,12 +486,16 @@
 
 	updateScores()
 
+	SendStat(siGraphTitle, loc("Score graph"))
+	SendHealthStatsOff()
+	SendRankingStatsOff()
+
 end
 
 
 function onNewTurn()
 
-	if gameStarted == true then
+	if gameStarted == true and not gameOver then
 		HandleRespawns()
 	end
 
@@ -474,7 +508,6 @@
 	if not gameStarted and flagsPlaced == ClansCount then
 		StartTheGame()
 	end
-
 end
 
 function onEndTurn()
@@ -487,6 +520,10 @@
 			fSpawnY[clan] = GetY(CurrentHedgehog)
 		end
 	end
+
+	if gameStarted == true then
+		DrawScores()
+	end
 end
 
 function onGameTick()