Add team score next to team bars for CTF_Blizard, Control, CTF, Mutant, Space Invasion
authorWuzzy <Wuzzy2@mail.ru>
Fri, 16 Feb 2018 19:16:35 +0100
changeset 13019 880662cf41ee
parent 13018 0248cf0da834
child 13020 d1e7f2420f00
Add team score next to team bars for CTF_Blizard, Control, CTF, Mutant, Space Invasion
share/hedgewars/Data/Maps/CTF_Blizzard/map.lua
share/hedgewars/Data/Maps/Control/map.lua
share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua
share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua
share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua
share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua
--- a/share/hedgewars/Data/Maps/CTF_Blizzard/map.lua	Fri Feb 16 13:57:48 2018 +0100
+++ b/share/hedgewars/Data/Maps/CTF_Blizzard/map.lua	Fri Feb 16 19:16:35 2018 +0100
@@ -1,4 +1,4 @@
---------------------------------
+-------------------------------
 -- CTF_BLIZZARD 0.9
 --------------------------------
 
@@ -119,6 +119,7 @@
 local teamNameArr = {}	-- store the list of teams
 local teamSize = {}	-- store how many hogs per team
 local teamIndex = {} -- at what point in the hhs{} does each team begin
+local clanTeams = {} -- list of teams per clan
 
 -------------------
 -- flag variables
@@ -228,11 +229,9 @@
 
 	if teamID == 0 then
 		alt = 1
-		winner = "Red"
 
 	elseif teamID == 1 then
 		alt = 0
-		winner = "Blue"
 	end
 
 	if fCaptures[teamID] == 3 then
@@ -242,7 +241,6 @@
 				SetHealth(hhs[i],0)
 			end
 		end
-		--ShowMission("GAME OVER!", "Victory for the " .. winner .. " Team!", "Hooray!", 0, 0)
 		ShowMission(loc("GAME OVER!"), loc("Victory for the ") .. GetHogTeamName(CurrentHedgehog), loc("Hooray!"), 0, 0)
 	end
 
@@ -253,7 +251,7 @@
 	for i = 0, 1 do
 
 		if fNeedsRespawn[i] == true then
-			fGear[i] = SpawnAmmoCrate(fSpawnX[i],fSpawnY[i],amSkip)
+			fGear[i] = SpawnFakeAmmoCrate(fSpawnX[i],fSpawnY[i],false,false)
 			--fGear[i] = SpawnHealthCrate(fSpawnX[i],fSpawnY[i])
 			fNeedsRespawn[i] = false
 			fIsMissing[i] = false -- new, this should solve problems of a respawned flag being "returned" when a player tries to score
@@ -266,6 +264,7 @@
 
 function FlagDeleted(gear)
 
+	PlaySound(sndShotgunReload)
 	if (gear == fGear[0]) then
 		wtf = 0
 		bbq = 1
@@ -292,10 +291,12 @@
 				fNeedsRespawn[bbq] = true
 				fCaptures[wtf] = fCaptures[wtf] +1					--fCaptures[wtf]
 
-				--ShowMission(LOC_NOT("You have SCORED!!"), "Red Team: " .. fCaptures[0], "Blue Team: " .. fCaptures[1], -amBazooka, 0)
-				ShowMission(loc("You have SCORED!!"), GetHogTeamName(CurrentHedgehog) .. ": " .. fCaptures[wtf], loc("Opposing Team: ") .. fCaptures[bbq], 0, 0)
+				AddCaption(string.format(loc("%s has scored!"), GetHogTeamName(CurrentHedgehog)), 0xFFFFFFFF, capgrpGameState)
+				for i=1, #clanTeams[wtf] do
+					SetTeamLabel(clanTeams[wtf][i], fCaptures[wtf])
+				end
 
-				PlaySound(sndVictory)
+				PlaySound(sndHomerun)
 				--SetEffect(fThief[bbq], hePoisoned, false)
 				fThief[bbq] = nil -- player no longer has the enemy flag
 				CheckScore(wtf)
@@ -376,9 +377,9 @@
 	if fThief[wtf] ~= nil then
 		
 		if fThiefY[wtf] > 2040 then
-			fGear[wtf] = SpawnAmmoCrate(fThiefX[wtf],(fThiefY[wtf]+10),amSkip)
+			fGear[wtf] = SpawnFakeAmmoCrate(fThiefX[wtf],(fThiefY[wtf]+10),false,false)
 		else
-			fGear[wtf] = SpawnAmmoCrate(fThiefX[wtf],(fThiefY[wtf]-50),amSkip)
+			fGear[wtf] = SpawnFakeAmmoCrate(fThiefX[wtf],(fThiefY[wtf]-50),false,false)
 		end
 
 		AddVisualGear(fThiefX[wtf], fThiefY[wtf], vgtBigExplosion, 0, false)
@@ -477,39 +478,12 @@
 
 	-- make a list of individual team names
 	for i = 0, (TeamsCount-1) do
-		teamNameArr[i] = i
+		teamNameArr[i] = GetTeamName(i)
 		teamSize[i] = 0
 		teamIndex[i] = 0
+		SetTeamLabel(teamNameArr[i], "0")
 	end
-	numTeams = 0
-
-	for i = 0, (numhhs-1) do
-
-		z = 0
-		unfinished = true
-		while(unfinished == true) do
-
-			newTeam = true
-			tempHogTeamName = GetHogTeamName(hhs[i]) -- this is the new name
-
-			if tempHogTeamName == teamNameArr[z] then
-				newTeam = false
-				unfinished = false
-			end
-
-			z = z + 1
-
-			if z == TeamsCount then
-				unfinished = false
-				if newTeam == true then
-					teamNameArr[numTeams] = tempHogTeamName
-					numTeams = numTeams + 1
-				end
-			end
-
-		end
-
-	end
+	numTeams = TeamsCount
 
 	-- find out how many hogs per team, and the index of the first hog in hhs
 	for i = 0, numTeams-1 do
@@ -520,10 +494,17 @@
 					teamIndex[i] = z -- should give starting index
 				end
 				teamSize[i] = teamSize[i] + 1
-				--add a pointer so this hog appears at i in hhs
+
+				local clan = GetHogClan(hhs[z])
+				-- Also remember the clan to which the team belongs to
+				if not clanTeams[clan] then
+					clanTeams[clan] = {}
+				end
+				table.insert(clanTeams[clan], teamNameArr[i])
 			end
 		end
 
+
 	end
 
 end
@@ -628,7 +609,7 @@
 	fSpawnY[1] = 1747
 
 	for i = 0, 1 do
-		fGear[i] = SpawnAmmoCrate(fSpawnX[i],fSpawnY[i],amSkip)
+		fGear[i] = SpawnFakeAmmoCrate(fSpawnX[i],fSpawnY[i],false,false)
 		fCirc[i] = AddVisualGear(fSpawnX[i],fSpawnY[i],vgtCircle,0,true)
 		fCol[i] = GetClanColor(i)
 
--- a/share/hedgewars/Data/Maps/Control/map.lua	Fri Feb 16 13:57:48 2018 +0100
+++ b/share/hedgewars/Data/Maps/Control/map.lua	Fri Feb 16 19:16:35 2018 +0100
@@ -225,6 +225,13 @@
 		end
 	end
 
+	-- Update team labels
+	for i = 0,(TeamsCount-1) do
+		if teamNameArr[i] ~= " " then
+			SetTeamLabel(teamNameArr[i], teamScore[teamClan[i]])
+		end
+	end
+
 end
 
 -----------------
@@ -273,6 +280,7 @@
 
 	-- find out how many hogs per team, and the index of the first hog in hhs
 	for i = 0, (numTeams-1) do
+		SetTeamLabel(GetTeamName(i), "0")
 		for z = 0, (numhhs-1) do
 			if GetHogTeamName(hhs[z]) == teamNameArr[i] then
 				teamClan[i] = GetHogClan(hhs[z])				
@@ -412,22 +420,6 @@
 			TurnTimeLeft = 1
 		end
 
-		totalComment = ""		
-		for i = 0,(TeamsCount-1) do
-				if teamNameArr[i] ~= " " then
-					-- Team scores (“<team name>: <score>”)
-					teamComment[i] = string.format(loc("%s: %d"), teamNameArr[i], teamScore[teamClan[i]]) .. "|"
-					totalComment = totalComment .. teamComment[i]			
-				elseif teamNameArr[i] == " " then
-					teamComment[i] = "|"
-				end
-			end
-			
-			ShowMission(missionName, missionCaption,
-			missionHelp .. "|" ..
-			loc("Team Scores:") .. "|" ..
-			totalComment, 0, 1600)
-	
 	end
 
 end
--- a/share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua	Fri Feb 16 13:57:48 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua	Fri Feb 16 19:16:35 2018 +0100
@@ -156,7 +156,7 @@
 		end
 		if CurrentHedgehog ~= nil then
 			AddCaption(string.format(loc("Victory for %s!"), GetHogTeamName(CurrentHedgehog)))
-			showMissionAndScorebar()
+			updateScores()
 		end
 	end
 
@@ -184,7 +184,7 @@
 		fNeedsRespawn[bbq] = true
 		fCaptures[wtf] = fCaptures[wtf] +1
 		AddCaption(string.format(loc("%s has scored!"), GetHogName(CurrentHedgehog)))
-		showMissionAndScorebar()
+		updateScores()
 		PlaySound(sndHomerun)
 		fThief[bbq] = nil -- player no longer has the enemy flag
 		CheckScore(wtf)
@@ -472,7 +472,7 @@
 
 end
 
-function showMissionAndScorebar(instaHide)
+function showCTFMission()
 	local captures
 	if captureLimit == 1 then
 		captures = string.format(loc("- First team to capture the flag wins"), captureLimit)
@@ -489,26 +489,18 @@
 		loc("- Dropped flags may be returned or recaptured").."|"..
 		loc("- Hogs will be revived")
 
-	local scoreboard = ""
+	ShowMission(loc("Capture The Flag"), loc("A Hedgewars minigame"), rules, 0, 0)
+end
 
-	if gameStarted then
-		scoreboard = "|" .. loc("Scores: ") .. "|"
-		for i=0, 1 do
-			scoreboard = scoreboard .. string.format(loc("%s: %d"), teamNameArr[i], fCaptures[i])
-			if i~=1 then scoreboard = scoreboard .. "|" end
-		end
-	end
-	local mission = rules .. scoreboard
-
-	ShowMission(loc("Capture The Flag"), loc("A Hedgewars minigame"), mission, 0, 0)
-	if instaHide then
-		HideMission()
+function updateScores()
+	for i=0, 1 do
+		SetTeamLabel(teamNameArr[i], tostring(fCaptures[i]))
 	end
 end
 
 function onGameStart()
 
-	showMissionAndScorebar()
+	showCTFMission()
 
 	RebuildTeamInfo()
 
@@ -547,7 +539,7 @@
 		HandleRespawns()
 	--new method of placing starting flags
 	elseif gameTurns == 1 then
-		showMissionAndScorebar()
+		showCTFMission()
 	elseif gameTurns == 2 then
 		fPlaced[0] = true
 	elseif gameTurns == 3 then
--- a/share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua	Fri Feb 16 13:57:48 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua	Fri Feb 16 19:16:35 2018 +0100
@@ -1689,7 +1689,7 @@
 
 	ShowMission	(
 				loc("CONSTRUCTION MODE"),
-				loc("a Hedgewars mini-game"),
+				loc("A Hedgewars mini-game"),
 				loc("Build a fortress and destroy your enemy.") .. "|" ..
 				loc("There are a variety of structures available to aid you.") .. "|" ..
 				loc("Use the structure placer to place structures.")
--- a/share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua	Fri Feb 16 13:57:48 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua	Fri Feb 16 19:16:35 2018 +0100
@@ -119,8 +119,7 @@
 	loc("+2 for becoming the Mutant") .. "|" ..
 	loc("+1 to the Mutant for killing anyone") .. "|" ..
 	loc("+1 to the Bottom Feeder for killing anyone") .. "|" ..
-	loc("-1 to anyone for a suicide") .. "|" ..
-	loc("Other kills don't give you points.")
+	loc("-1 to anyone for a suicide")
 
 	return ruleSet
 
@@ -369,25 +368,12 @@
     SetHealth(gear, 0)
 end
 
-function updateScore()
-
-    local showScore = ""
-
+function renderScores()
     for i=0, TeamsCount-1 do
         if teams[i]~= nil then
-
-            local curr_score = getTeamValue(teams[i], "Score")
-            showScore = showScore .. string.format(loc("%s: %d (deaths: %d)"), teams[i], curr_score, getTeamValue(teams[i], "DeadHogs")) .. "|"
-
+            SetTeamLabel(teams[i], string.format(loc("Score: %d | Deaths: %d"), getTeamValue(teams[i], "Score"), getTeamValue(teams[i], "DeadHogs")))
         end
     end
-
-    ShowMission(loc("Mutant"),
-                loc("Scores"),
-                showScore, 4, 1)
-
-    HideMission()
-
 end
 
 function checkScore()
@@ -507,11 +493,6 @@
 
     if meh == false then
 		meh = true
-	else
-		ShowMission(    loc("Mutant"),
-                    loc("Scores"),
-                    showScore, 4, 1)
-		HideMission()
 	end
 
     end
@@ -603,6 +584,8 @@
             end
         end
 
+        renderScores()
+
         ---***---
 end
 
@@ -700,7 +683,7 @@
         end
         AddVisualGear(GetX(gear), GetY(gear), vgtSmokeRing, 0, false)
         PlaySound(sndWhack)
-        updateScore()
+        renderScores()
     end
 end
 end
--- a/share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua	Fri Feb 16 13:57:48 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua	Fri Feb 16 19:16:35 2018 +0100
@@ -575,7 +575,6 @@
 
 	-- make a list of individual team names
 	for i = 0, (TeamsCount-1) do
-		teamNameArr[i] = " " -- = i
 		teamSize[i] = 0
 		teamIndex[i] = 0
 		teamScore[i] = 0
@@ -628,6 +627,10 @@
 
 	end
 
+	for i=0, TeamsCount-1 do
+		SetTeamLabel(teamNameArr[i], teamScore[i])
+	end
+
 end
 
 -- control
@@ -638,6 +641,7 @@
 	for i = 0,(TeamsCount-1) do
 		if teamClan[i] == GetHogClan(CurrentHedgehog) then
 			teamScore[i] = teamScore[i] + p
+			SetTeamLabel(teamNameArr[i], teamScore[i])
 		end
 	end
 
@@ -729,16 +733,11 @@
 	end
 	local statusText, scoreText
 	if roundNumber >= roundLimit then
-		if teamStats[1].score == teamStats[2].score then
-			statusText = loc("Status Update")
-			scoreText = loc("Team scores:")
-		else
-			statusText = loc("Game over!")
-			scoreText = loc("Final team scores:")
-		end
+		statusText = loc("Game over!")
+		scoreText = loc("Final team scores:")
 	else
-		statusText = loc("Status Update")
-		scoreText = loc("Team scores:")
+		AddCaption(string.format(loc("Rounds complete: %d/%d"), roundNumber, roundLimit, 0xFFFFFFFF))
+		return
 	end
 	local displayTime
 	if roundNumber >= roundLimit then
@@ -1256,7 +1255,6 @@
 				" " .. "|" ..
 
 				string.format(loc("Round Limit: %d"), roundLimit) .. "|" ..
-				string.format(loc("Turn Time: %dsec"), (TurnTime/1000)) .. "|" ..
 				" " .. "|" ..
 
 				loc("Movement: [Up], [Down], [Left], [Right]") .. "|" ..