Fix Killing the Specialists recording the turn count way too low
authorWuzzy <Wuzzy2@mail.ru>
Sun, 11 Feb 2018 02:03:09 +0100
changeset 12975 dc35a79c6ef9
parent 12974 2fee2ee717eb
child 12976 f306a0c2899c
Fix Killing the Specialists recording the turn count way too low
ChangeLog.txt
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death02.lua
--- a/ChangeLog.txt	Sun Feb 11 01:15:23 2018 +0100
+++ b/ChangeLog.txt	Sun Feb 11 02:03:09 2018 +0100
@@ -32,6 +32,7 @@
  + Hard Flying: Display personal best at mission start
  + Killing the Specialists: Add event messages and graphical effects
  * Killing the Specialists: Fix very misleading hints in mission panel
+ * Killing the Specialists: Fix number of rounds measured being way too low
 
 A Classic Fairytale:
  + Mission 3: Display number of turns left at timed parcours
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death02.lua	Sun Feb 11 01:15:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death02.lua	Sun Feb 11 02:03:09 2018 +0100
@@ -33,6 +33,7 @@
 	bazookaAmmo = 2,
 	grenadeAmmo = 4,
 }
+local heroTurns = 0
 local enemies = {
 	{ name = GetAmmoName(amMortar), x = 1890, y = 520, weapon = amMortar, additionalWeapons = {}},
 	{ name = GetAmmoName(amDEagle), x = 1390, y = 790, weapon = amDEagle, additionalWeapons = {}},
@@ -111,6 +112,8 @@
 	end
 	if CurrentHedgehog ~= hero.gear then
 		enemyWeapons()
+	else
+		heroTurns = heroTurns + 1
 	end
 end
 
@@ -215,17 +218,20 @@
 function heroWin(gear)
 	saveBonus(3, 4)
 	SendStat(siGameResult, loc("Congratulations, you won!"))
-	SendStat(siCustomAchievement, string.format(loc("You completed the mission in %d rounds."), TotalRounds))
-	local record = tonumber(GetCampaignVar("FastestSpecialistsKill"))
-	if record ~= nil and TotalRounds >= record then
+	SendStat(siCustomAchievement, string.format(loc("You completed the mission in %d rounds."), heroTurns))
+	local record = tonumber(GetCampaignVar("FastestSpecialistsWin"))
+	if record ~= nil and heroTurns >= record then
 		SendStat(siCustomAchievement, string.format(loc("Your fastest victory so far: %d rounds"), record))
 	end
-	if record == nil or TotalRounds < record then
-		SaveCampaignVar("FastestSpecialistsKill", tostring(TotalRounds))
+	if record == nil or heroTurns < record then
+		SaveCampaignVar("FastestSpecialistsWin", tostring(heroTurns))
 		if record ~= nil then
 			SendStat(siCustomAchievement, loc("This is a new personal best, congratulations!"))
 		end
 	end
+	-- An old version of this mission was buggy and stored a turn record WAY too low.
+	-- Let's clear the broken variable (FastestSpecialistsKill) here.
+	SaveCampaignVar("FastestSpecialistsKill", "")
 	SendStat(siCustomAchievement, loc("The next 4 times you play the \"The last encounter\" mission you'll get 20 more hit points and a laser sight."))
 	sendSimpleTeamRankings({teamA.name, teamB.name})
 	SaveCampaignVar("Mission11Won", "true")