Save some records in campaign vars: Hard flying, Running for survival
authorWuzzy <almikes@aol.com>
Wed, 16 Nov 2016 16:34:33 +0100
changeset 11895 712e20a3d895
parent 11894 c8979eeb73fa
child 11896 d79621bcb709
Save some records in campaign vars: Hard flying, Running for survival
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua	Wed Nov 16 16:32:44 2016 +0100
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua	Wed Nov 16 16:34:33 2016 +0100
@@ -155,7 +155,17 @@
 	SendStat(siGameResult, loc("Congratulations, you won!"))
 	SendStat(siCustomAchievement, loc("You have escaped successfully."))
 	SendStat(siCustomAchievement, string.format(loc("Your escape took you %d turns."), TotalRounds))
-	SendStat(siPlayerKills,'1',teamA.name)
+	local record = tonumber(GetCampaignVar("FastestMineEscape"))
+	if record ~= nil and TotalRounds >= record then
+		SendStat(siCustomAchievement, string.format(loc("Your fastest escape so far: %d turns"), record))
+	end
+	if record == nil or TotalRounds < record then
+		SaveCampaignVar("FastestMineEscape", tostring(TotalRounds))
+		if record ~= nil then
+			SendStat(siCustomAchievement, loc("This is a new personal best, congratulations!"))
+		end
+	end
+	SendStat(siPlayerKills,'0',teamA.name)
 	EndGame()
 end
 
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua	Wed Nov 16 16:32:44 2016 +0100
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua	Wed Nov 16 16:34:33 2016 +0100
@@ -135,14 +135,30 @@
 			gameEnded = true
 			-- GAME OVER, WIN!
 			totalTime = totalTime - TurnTimeLeft
-			totalTime = totalTime / 1000
+			local totalTimePrinted  = totalTime / 1000
 			local saucersLeft = GetAmmoCount(hero.gear, amJetpack)
 			local saucersUsed = totalSaucers - saucersLeft
 			SendStat(siGameResult, loc("Hooray! You are a champion!"))
-			SendStat(siCustomAchievement, string.format(loc("You completed the mission in %.3f seconds.", totalTime)))
-			SendStat(siCustomAchievement, string.format(loc("You have used %d flying saucers.", saucersUsed)))
-			SendStat(siCustomAchievement, string.format(loc("You had %d additional flying saucers left"), saucersLeft))
-			SendStat(siPlayerKills,'1',teamA.name)
+			SendStat(siCustomAchievement, string.format(loc("You completed the mission in %.3f seconds."), totalTimePrinted))
+			local record = tonumber(GetCampaignVar("IceStadiumBestTime"))
+			if record ~= nil and totalTime >= record then
+				SendStat(siCustomAchievement, string.format(loc("Your personal best time so far: %.3f seconds"), record/1000))
+			end
+			if record == nil or totalTime < record then
+				SaveCampaignVar("IceStadiumBestTime", tostring(totalTime))
+				if record ~= nil then
+					SendStat(siCustomAchievement, loc("This is a new personal best time, congratulations!"))
+				end
+			end
+			SendStat(siCustomAchievement, string.format(loc("You have used %d flying saucers."), saucersUsed))
+			SendStat(siCustomAchievement, string.format(loc("You had %d additional flying saucers left."), saucersLeft))
+
+			record = tonumber(GetCampaignVar("IceStadiumLeastSaucersUsed"))
+			if record == nil or saucersUsed < record then
+				SaveCampaignVar("IceStadiumLeastSaucersUsed", tostring(saucersUsed))
+			end
+
+			SendStat(siPlayerKills,'0',teamA.name)
 			EndGame()
 		end
 	end