share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua
changeset 11891 d79621bcb709
parent 11692 68eddcdc9f26
child 11952 63988f36debf
equal deleted inserted replaced
11890:712e20a3d895 11891:d79621bcb709
    13 local challengeObjectives = loc("Use the rope in order to catch the blue hedgehog").."|"..
    13 local challengeObjectives = loc("Use the rope in order to catch the blue hedgehog").."|"..
    14 	loc("You have to stand very close to him")
    14 	loc("You have to stand very close to him")
    15 local currentPosition = 1
    15 local currentPosition = 1
    16 local previousTimeLeft = 0
    16 local previousTimeLeft = 0
    17 local startChallenge = false
    17 local startChallenge = false
       
    18 local winningTime = nil
    18 -- dialogs
    19 -- dialogs
    19 local dialog01 = {}
    20 local dialog01 = {}
    20 local dialog02 = {}
    21 local dialog02 = {}
    21 -- mission objectives
    22 -- mission objectives
    22 local goals = {
    23 local goals = {
   197 		currentPosition = currentPosition + 1
   198 		currentPosition = currentPosition + 1
   198 		if GetX(hero.gear) > GetX(runner.gear) then
   199 		if GetX(hero.gear) > GetX(runner.gear) then
   199 			HogTurnLeft(runner.gear, false)
   200 			HogTurnLeft(runner.gear, false)
   200 		end
   201 		end
   201 		AddAnim(dialog02)
   202 		AddAnim(dialog02)
       
   203 
       
   204 		-- Update time record
       
   205 		local baseTime = 0
       
   206 		for i=1, #runner.places do
       
   207 			baseTime = baseTime + runner.places[i].turnTime
       
   208 		end
       
   209 		winningTime = baseTime - TurnTimeLeft
       
   210 		SendStat(siCustomAchievement, string.format(loc("You have managed to catch the blue hedgehog in %.3f seconds."), winningTime/1000))
       
   211 		local record = tonumber(GetCampaignVar("FastestBlueHogCatch"))
       
   212 		if record ~= nil and winningTime >= record then
       
   213 			SendStat(siCustomAchievement, string.format(loc("Your personal best time so far: %.3f seconds"), record/1000))
       
   214 		end
       
   215 		if record == nil or winningTime < record then
       
   216 			SaveCampaignVar("FastestBlueHogCatch", tostring(winningTime))
       
   217 			if record ~= nil then
       
   218 				SendStat(siCustomAchievement, loc("This is a new personal best time, congratulations!"))
       
   219 			end
       
   220 		end
       
   221 
   202 		TurnTimeLeft = 0
   222 		TurnTimeLeft = 0
   203 	elseif currentPosition < 4 then
   223 	elseif currentPosition < 4 then
   204 		if not startChallenge then
   224 		if not startChallenge then
   205 			startChallenge = true
   225 			startChallenge = true
   206 		end
   226 		end
   230 	EndGame()
   250 	EndGame()
   231 end
   251 end
   232 
   252 
   233 function win()
   253 function win()
   234 	SendStat(siGameResult, loc("Congratulations, you are the fastest!"))
   254 	SendStat(siGameResult, loc("Congratulations, you are the fastest!"))
   235 	SendStat(siCustomAchievement, loc("You have managed to catch the blue hedgehog in time."))
   255 	-- siCustomAchievements were added earlier
   236 	SendStat(siPlayerKills,'1',teamA.name)
   256 	SendStat(siPlayerKills,'0',teamA.name)
   237 	EndGame()
   257 	EndGame()
   238 end
   258 end