Display score next to team bar in singleplayer challenges
authorWuzzy <Wuzzy2@mail.ru>
Sat, 24 Feb 2018 14:59:35 +0100
changeset 13065 a297e06d1607
parent 13064 6766b900ab13
child 13066 ad75ed9a1e15
Display score next to team bar in singleplayer challenges
share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua
share/hedgewars/Data/Missions/Challenge/User_Mission_-_RCPlane_Challenge.lua
share/hedgewars/Data/Missions/Challenge/User_Mission_-_Rope_Knock_Challenge.lua
share/hedgewars/Data/Scripts/SpeedShoppa.lua
share/hedgewars/Data/Scripts/TargetPractice.lua
--- a/share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua	Fri Feb 23 22:43:34 2018 +0100
+++ b/share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua	Sat Feb 24 14:59:35 2018 +0100
@@ -51,6 +51,9 @@
 -- Position for delayed targets
 local delayedTargetTargetX, delayedTargetY
 
+-- Team name of the player's team
+local playerTeamName = loc("Sniperz")
+
 -- This is a custom function to make it easier to
 -- spawn more targets with just one line of code
 -- You may define as many custom functions as you
@@ -68,6 +71,12 @@
 function spawnTargetDelayed(x, y)
 	delayedTargetX = x
 	delayedTargetY = y
+	-- The previous target always counts double after destruction
+	score_bonus = score_bonus + 1
+end
+
+function getTargetScore()
+	return score_bonus * 200
 end
 
 -- Cut sequence to blow up land with dynamite
@@ -124,7 +133,7 @@
 	HealthDecrease = 0
 
 	-- Create the player team
-	AddTeam(loc("Sniperz"), 14483456, "Simple", "Island", "Default", "cm_crosshair")
+	AddTeam(playerTeamName, 0xFF0204, "Simple", "Island", "Default", "cm_crosshair")
 	-- And add a hog to it
 	player = AddHog(loc("Hunter"), 0, 1, "Sniper")
 	SetGearPosition(player, 602, 1465)
@@ -146,6 +155,9 @@
 	-- A positive icon paramter (n) represents the (n+1)-th mission icon
 	-- A timeframe of 0 is replaced with the default time to show.
 	ShowMission(loc("Sniper Training"), loc("Aiming Practice"), loc("Eliminate all targets before your time runs out.|You have unlimited ammo for this mission."), -amSniperRifle, 0)
+
+	-- Displayed initial player score
+	SetTeamLabel(playerTeamName, "0")
 end
 
 -- This function is called every game tick.
@@ -245,8 +257,6 @@
 				cinematic = false
 				SetCinematicMode(false)
 			end
-			-- Add bonus score for the previuos target
-			score_bonus = score_bonus + 1
 			-- Now *actually* spawn the delayed target
 			spawnTarget(delayedTargetX, delayedTargetY)
 		end
@@ -390,6 +400,7 @@
 			time_goal = TurnTimeLeft
 			end
 		end
+		SetTeamLabel(playerTeamName, getTargetScore())
 	end
 end
 
@@ -400,12 +411,13 @@
 	if shots > 0 then
 		accuracy = (score/shots)*100
 	end
-	local end_score_targets = (score_bonus * 200)
+	local end_score_targets = getTargetScore()
 	local end_score_overall
 	if not game_lost then
 		local end_score_time = math.ceil(time_goal/5)
 		local end_score_accuracy = math.ceil(accuracy * 100)
 		end_score_overall = end_score_time + end_score_targets + end_score_accuracy
+		SetTeamLabel(playerTeamName, tostring(end_score_overall))
 
 		SendStat(siGameResult, loc("You have successfully finished the sniper rifle training!"))
 		SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets))
@@ -420,6 +432,6 @@
 		end_score_overall = end_score_targets
 	end
 	SendStat(siPointType, loc("points"))
-	SendStat(siPlayerKills, tostring(end_score_overall), loc("Sniperz"))
+	SendStat(siPlayerKills, tostring(end_score_overall), playerTeamName)
 end
 
--- a/share/hedgewars/Data/Missions/Challenge/User_Mission_-_RCPlane_Challenge.lua	Fri Feb 23 22:43:34 2018 +0100
+++ b/share/hedgewars/Data/Missions/Challenge/User_Mission_-_RCPlane_Challenge.lua	Sat Feb 24 14:59:35 2018 +0100
@@ -53,6 +53,7 @@
                                 loc("Compete to use as few planes as possible!") .. "|" ..
 								"", -amRCPlane, 4000
                                 )
+	SetTeamLabel(loc("Wannabe Flyboys"), "0")
 
 	PlaceGirder(2192, 508, 6)
 	PlaceGirder(2192, 670, 6)
@@ -332,6 +333,7 @@
 	if GetGearType(gear) == gtRCPlane then
 		RCGear = gear
 		planesUsed = planesUsed + 1
+		SetTeamLabel(loc("Wannabe Flyboys"), tostring(planesUsed))
 		planeTimer = 0
 		missiles = 0
 	end
@@ -352,7 +354,6 @@
 		RCGear = nil
 		planeUhOh = false
 		missiles = 0
-		AddCaption(string.format(loc("Planes used: %d"), planesUsed))
 
 		if(planeTimer < 2000 and crateStreak == 0) then
 			nextComment = sndStupid
--- a/share/hedgewars/Data/Missions/Challenge/User_Mission_-_Rope_Knock_Challenge.lua	Fri Feb 23 22:43:34 2018 +0100
+++ b/share/hedgewars/Data/Missions/Challenge/User_Mission_-_Rope_Knock_Challenge.lua	Sat Feb 24 14:59:35 2018 +0100
@@ -70,18 +70,24 @@
 
 				}
 
+local playerTeamName = loc("Wannabe Shoppsta")
+
 function GenericEnd()
 	EndGame()
 end
 
+function GetKillScore()
+	return math.ceil((hogsKilled / 16)*6000)
+end
+
 function GameOverMan()
 	missionWon = false
 	ShowMission(loc("Rope-knocking Challenge"), loc("Challenge over!"), loc("Oh no! Just try again!"), -amSkip, 0)
 	SendStat(siGameResult, loc("Challenge over!"))
-	local score = math.ceil((hogsKilled / 16)*6000)
+	local score = GetKillScore()
 	SendStat(siCustomAchievement, string.format(loc("You have killed %d of 16 hedgehogs (+%d points)."), hogsKilled, score))
 	SendStat(siPointType, loc("points"))
-	SendStat(siPlayerKills, tostring(score), loc("Wannabe Shoppsta"))
+	SendStat(siPlayerKills, tostring(score), playerTeamName)
 	PlaySound(sndHellish)
 end
 
@@ -91,13 +97,14 @@
 	ShowMission(loc("Rope-knocking Challenge"), loc("Challenge completed!"), loc("Congratulations!") .. "|" .. string.format(loc("Completion time: %.2fs"), completeTime), 0, 0)
 	PlaySound(sndHomerun)
 	SendStat(siGameResult, loc("Challenge completed!"))
-	local hogScore = math.ceil((hogsKilled / 16)*6000)
+	local hogScore = GetKillScore()
 	local timeScore = math.ceil((finishTime/TurnTime)*6000)
 	local score = hogScore + timeScore
 	SendStat(siCustomAchievement, string.format(loc("You have killed %d of 16 hedgehogs (+%d points)."), hogsKilled, hogScore))
 	SendStat(siCustomAchievement, string.format(loc("You have completed this challenge in %.2f s (+%d points)."), completeTime, timeScore))
 	SendStat(siPointType, loc("points"))
-	SendStat(siPlayerKills, tostring(score), loc("Wannabe Shoppsta"))
+	SendStat(siPlayerKills, tostring(score), playerTeamName)
+	SetTeamLabel(playerTeamName, tostring(score))
 end
 
 function AssignCharacter(p)
@@ -144,7 +151,7 @@
 	MinesNum = 0
 	Explosives = 0
 
-	AddTeam(loc("Wannabe Shoppsta"), 0x11F12B, "money", "Island", "Default", "cm_shoppa")
+	AddTeam(playerTeamName, 0x11F12B, "money", "Island", "Default", "cm_shoppa")
 	hhs[0] = AddHog(loc("Ace"), 0, 1, "Gasmask")
 	SetGearPosition(player, 1380, 1500)
 
@@ -171,6 +178,7 @@
                         loc("Use the rope to knock your enemies to their doom.") .. "|" ..
                         loc("Finish this challenge as fast as possible to earn bonus points."),
                         -amRope, 4000)
+	SetTeamLabel(playerTeamName, "0")
 
 	PlaceGirder(46,1783, 0)
 
@@ -235,6 +243,8 @@
 		AddCaption(string.format(knockTaunt(), GetHogName(gear)), 0xFFFFFFFF, capgrpMessage)
 
 		hogsKilled = hogsKilled +1
+		SetTeamLabel(playerTeamName, tostring(GetKillScore()))
+
 		if hogsKilled == 15 then
 			PlaySound(sndRideOfTheValkyries)
 		elseif hogsKilled == 16 then
--- a/share/hedgewars/Data/Scripts/SpeedShoppa.lua	Fri Feb 23 22:43:34 2018 +0100
+++ b/share/hedgewars/Data/Scripts/SpeedShoppa.lua	Sat Feb 24 14:59:35 2018 +0100
@@ -117,6 +117,8 @@
 	_G.onGameStart = function()
 		SendHealthStatsOff()
 		ShowMission(params.missionTitle, loc("Challenge"), params.goalText, -amRope, 5000) 
+		-- <crates collected>/<total number of crates>
+		SetTeamLabel(params.teamName, string.format(loc("%d/%d"), cratesCollected, #crates))
 		for i=1,#crates do
 			spawnCrate(crates[i].x, crates[i].y)
 		end
@@ -130,6 +132,8 @@
 	_G.onGearDelete = function(gear)
 		if GetGearType(gear) == gtCase and not hogHurt and not timeOut then
 			cratesCollected = cratesCollected + 1
+			-- <crates collected>/<total number of crates>
+			SetTeamLabel(params.teamName, string.format(loc("%d/%d"), cratesCollected, #crates))
 			PlaySound(sndShotgunReload)
 			if cratesCollected == #crates then
 				endTime = TurnTimeLeft
--- a/share/hedgewars/Data/Scripts/TargetPractice.lua	Fri Feb 23 22:43:34 2018 +0100
+++ b/share/hedgewars/Data/Scripts/TargetPractice.lua	Sat Feb 24 14:59:35 2018 +0100
@@ -103,6 +103,12 @@
 	- shootText:	A string which says how many times the player shot, ā€œ%dā€ is replaced
 			by the number of shots. (default: "You have shot %d times.")
 ]]
+
+
+local getTargetsScore = function()
+	return scored * math.ceil(6000/#targets)
+end
+
 function TargetPracticeMission(params)
 	if params.hogHat == nil then params.hogHat = "NoHat" end
 	if params.hogName == nil then params.hogName = loc("Trainee") end
@@ -151,6 +157,7 @@
 	_G.onGameStart = function()
 		SendHealthStatsOff()
 		ShowMission(params.missionTitle, loc("Aiming practice"), params.goalText, -params.ammoType, 5000)
+		SetTeamLabel(params.teamName, "0")
 		spawnTarget()
 	end
 
@@ -205,6 +212,7 @@
 	_G.onGearDamage = function(gear, damage)
 		if GetGearType(gear) == gtTarget then
 			scored = scored + 1
+			SetTeamLabel(params.teamName, tostring(getTargetsScore()))
 			if scored < total_targets then
 				AddCaption(string.format(loc("Targets left: %d"), (total_targets-scored)), 0xFFFFFFFF, capgrpMessage)
 				spawnTarget()
@@ -249,12 +257,13 @@
 
 	_G.generateStats = function()
 		local accuracy = (scored/shots)*100
-		local end_score_targets = scored * math.ceil(6000/#targets)
+		local end_score_targets = getTargetsScore()
 		local end_score_overall
 		if not game_lost then
 			local end_score_time = math.ceil(time_goal/(params.time/6000))
 			local end_score_accuracy = math.ceil(accuracy * 60)
 			end_score_overall = end_score_time + end_score_targets + end_score_accuracy
+			SetTeamLabel(params.teamName, tostring(end_score_overall))
 
 			SendStat(siGameResult, loc("You have finished the target practice!"))