CTF_Blizzard: Display scores in stats screen
authorWuzzy <Wuzzy2@mail.ru>
Thu, 16 May 2019 21:49:33 +0200
changeset 14999 fe8b4f2da9aa
parent 14998 1e21dfd7f9b5
child 15000 4406994969c3
CTF_Blizzard: Display scores in stats screen
share/hedgewars/Data/Maps/CTF_Blizzard/map.lua
--- a/share/hedgewars/Data/Maps/CTF_Blizzard/map.lua	Thu May 16 21:15:07 2019 +0200
+++ b/share/hedgewars/Data/Maps/CTF_Blizzard/map.lua	Thu May 16 21:49:33 2019 +0200
@@ -105,6 +105,7 @@
 						-- currently every 6 TURNS, should this work
 						-- on ROUNDS instead?
 local effectTimer = 0
+local gameEnded = false
 
 local ropeGear = nil
 
@@ -120,6 +121,11 @@
 local teamIndex = {} -- at what point in the hhs{} does each team begin
 local clanTeams = {} -- list of teams per clan
 
+local mostCapturesHogName = nil -- name of hog who holds the record of most flags captured
+local mostCapturesHogTeam = nil -- name of team who holds the record of most flags captured
+local mostCaptures = 0 -- number of most per-hog captures
+local capturesPerHog = {}
+
 -------------------
 -- flag variables
 -------------------
@@ -230,7 +236,8 @@
 		alt = 0
 	end
 
-	if fCaptures[teamID] == 3 then
+	if fCaptures[teamID] == 3 and not gameEnded then
+		gameEnded = true
 		for i = 0, (numhhs-1) do
 			if GetHogClan(hhs[i]) == alt then
 				SetEffect(hhs[i], heResurrectable, 0)
@@ -239,6 +246,28 @@
 		end
 		local victoryMsg = string.format(loc("Victory for %s!"), GetHogTeamName(CurrentHedgehog))
 		AddCaption(victoryMsg, capcolDefault, capgrpGameState)
+
+		-- Calculate team rankings
+		local teamList = {}
+		for i=0, TeamsCount-1 do
+			local name = GetTeamName(i)
+			local clan = GetTeamClan(name)
+			if fCaptures[clan] ~= nil then
+				table.insert(teamList, { score = fCaptures[clan], name = name, clan = clan })
+			end
+		end
+		local teamRank = function(a, b)
+			return a.score > b.score
+		end
+		table.sort(teamList, teamRank)
+
+		for i=1, #teamList do
+			SendStat(siPointType, "!POINTS")
+			SendStat(siPlayerKills, tostring(teamList[i].score), teamList[i].name)
+		end
+		if mostCaptures >= 2 then
+			SendStat(siCustomAchievement, string.format(loc("%s (%s) has captured the flag %d times."), mostCapturesHogName, mostCapturesHogTeam, mostCaptures))
+		end
 	end
 
 end
@@ -290,6 +319,13 @@
 					SetTeamLabel(clanTeams[wtf][i], fCaptures[wtf])
 				end
 
+				capturesPerHog[CurrentHedgehog] = capturesPerHog[CurrentHedgehog] + 1
+				if capturesPerHog[CurrentHedgehog] > mostCaptures then
+					mostCaptures = capturesPerHog[CurrentHedgehog]
+					mostCapturesHogName = GetHogName(CurrentHedgehog)
+					mostCapturesHogTeam = GetHogTeamName(CurrentHedgehog)
+				end
+
 				PlaySound(sndHomerun)
 				fThief[bbq] = nil -- player no longer has the enemy flag
 				CheckScore(wtf)
@@ -527,6 +563,9 @@
 	Map = "Blizzard" -- The map to be played
 	Theme = "Snow" -- The theme to be used
 
+	SendHealthStatsOff()
+	SendRankingStatsOff()
+
 end
 
 
@@ -713,6 +752,7 @@
 
 	if GetGearType(gear) == gtHedgehog then
 
+		capturesPerHog[gear] = 0
 		if GetHogClan(gear) > 1 then
 			DeleteGear(gear)
 			if not excessHogsWarning then