share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua
changeset 14576 2087e50e03e2
parent 14488 7bb7e5e54f70
child 14577 221380cdee7e
equal deleted inserted replaced
14575:28d00ceb8b54 14576:2087e50e03e2
    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 local winningTime = nil
       
    19 local currentTime = 0
       
    20 local runnerTime = 0
       
    21 local record
    19 -- dialogs
    22 -- dialogs
    20 local dialog01 = {}
    23 local dialog01 = {}
    21 local dialog02 = {}
    24 local dialog02 = {}
    22 -- mission objectives
    25 -- mission objectives
    23 local goals = {
    26 local goals = {
    72 	teamB.name = AddTeam(teamB.name, teamB.color, "ring", "Island", "Default", "cm_sonic")
    75 	teamB.name = AddTeam(teamB.name, teamB.color, "ring", "Island", "Default", "cm_sonic")
    73 	runner.gear = AddHog(runner.name, 0, 100, "sth_Sonic")
    76 	runner.gear = AddHog(runner.name, 0, 100, "sth_Sonic")
    74 	AnimSetGearPosition(runner.gear, runner.places[1].x, runner.places[1].y)
    77 	AnimSetGearPosition(runner.gear, runner.places[1].x, runner.places[1].y)
    75 	HogTurnLeft(runner.gear, true)
    78 	HogTurnLeft(runner.gear, true)
    76 
    79 
       
    80 	record = tonumber(GetCampaignVar("FastestBlueHogCatch"))
    77 	initCheckpoint("moon02")
    81 	initCheckpoint("moon02")
    78 
    82 
    79 	AnimInit(true)
    83 	AnimInit(true)
    80 	AnimationSetup()
    84 	AnimationSetup()
    81 end
    85 end
    84 	AnimWait(hero.gear, 3000)
    88 	AnimWait(hero.gear, 3000)
    85 	FollowGear(hero.gear)
    89 	FollowGear(hero.gear)
    86 
    90 
    87 	AddEvent(onHeroDeath, {hero.gear}, heroDeath, {hero.gear}, 0)
    91 	AddEvent(onHeroDeath, {hero.gear}, heroDeath, {hero.gear}, 0)
    88 
    92 
       
    93 	if record ~= nil then
       
    94 		goals[dialog01][3] = goals[dialog01][3] .. "|" .. string.format(loc("Personal best: %.3f seconds"), record/1000)
       
    95 	end
    89 	AddAmmo(hero.gear, amRope, 1)
    96 	AddAmmo(hero.gear, amRope, 1)
    90 
    97 
    91 	SendHealthStatsOff()
    98 	SendHealthStatsOff()
    92 	hogTurn = runner.gear
    99 	hogTurn = runner.gear
    93 	AddAnim(dialog01)
   100 	AddAnim(dialog01)
   109 
   116 
   110 function onNewTurn()
   117 function onNewTurn()
   111 	if startChallenge and currentPosition < 5 then
   118 	if startChallenge and currentPosition < 5 then
   112 		if CurrentHedgehog ~= hero.gear then
   119 		if CurrentHedgehog ~= hero.gear then
   113 			EndTurn(true)
   120 			EndTurn(true)
       
   121 			runnerTime = runnerTime + runner.places[currentPosition].turnTime
       
   122 			SetTeamLabel(teamB.name, string.format(loc("%.1fs"), runnerTime/1000))
   114 		else
   123 		else
   115 			if GetAmmoCount(hero.gear, amRope) == 0  then
   124 			if GetAmmoCount(hero.gear, amRope) == 0  then
   116 				lose()
   125 				lose()
   117 			end
   126 			end
   118 			SetWeapon(amRope)
   127 			SetWeapon(amRope)
   127 	if ShowAnimation() == false then
   136 	if ShowAnimation() == false then
   128 		return
   137 		return
   129 	end
   138 	end
   130 	ExecuteAfterAnimations()
   139 	ExecuteAfterAnimations()
   131 	CheckEvents()
   140 	CheckEvents()
       
   141 	if GetHealth(hero.gear) and CurrentHedgehog == hero.gear and startChallenge and currentPosition < 5 and currentPosition > 1 and ReadyTimeLeft == 0 and band(GetState(CurrentHedgehog), gstHHDriven) ~= 0 then
       
   142 		currentTime = currentTime + 1
       
   143 	end
   132 end
   144 end
   133 
   145 
   134 function onGameTick20()
   146 function onGameTick20()
       
   147 	if startChallenge and currentPosition < 5 and currentPosition > 1 and CurrentHedgehog == hero.gear and ReadyTimeLeft == 0 and band(GetState(CurrentHedgehog), gstHHDriven) ~= 0 then
       
   148 		SetTeamLabel(teamA.name, string.format(loc("%.1fs"), currentTime/1000))
       
   149 	end
   135 	if GetHealth(hero.gear) and startChallenge and isHeroNextToRunner() and currentPosition < 5 then
   150 	if GetHealth(hero.gear) and startChallenge and isHeroNextToRunner() and currentPosition < 5 then
   136 		moveRunner()
   151 		moveRunner()
   137 	end
   152 	end
   138 end
   153 end
   139 
   154 
   222 		local baseTime = 0
   237 		local baseTime = 0
   223 		for i=1, #runner.places do
   238 		for i=1, #runner.places do
   224 			baseTime = baseTime + runner.places[i].turnTime
   239 			baseTime = baseTime + runner.places[i].turnTime
   225 		end
   240 		end
   226 		winningTime = baseTime - TurnTimeLeft
   241 		winningTime = baseTime - TurnTimeLeft
       
   242 		SetTeamLabel(teamA.name, string.format(loc("%.3fs"), winningTime/1000))
   227 		SendStat(siCustomAchievement, string.format(loc("You have managed to catch the blue hedgehog in %.3f seconds."), winningTime/1000))
   243 		SendStat(siCustomAchievement, string.format(loc("You have managed to catch the blue hedgehog in %.3f seconds."), winningTime/1000))
   228 		local record = tonumber(GetCampaignVar("FastestBlueHogCatch"))
       
   229 		if record ~= nil and winningTime >= record then
   244 		if record ~= nil and winningTime >= record then
   230 			SendStat(siCustomAchievement, string.format(loc("Your personal best time so far: %.3f seconds"), record/1000))
   245 			SendStat(siCustomAchievement, string.format(loc("Your personal best time so far: %.3f seconds"), record/1000))
   231 		end
   246 		end
   232 		if record == nil or winningTime < record then
   247 		if record == nil or winningTime < record then
   233 			SaveCampaignVar("FastestBlueHogCatch", tostring(winningTime))
   248 			SaveCampaignVar("FastestBlueHogCatch", tostring(winningTime))