share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua
changeset 14575 28d00ceb8b54
parent 14488 7bb7e5e54f70
child 14898 4596357d002d
equal deleted inserted replaced
14574:6e5cda26f676 14575:28d00ceb8b54
    20 }
    20 }
    21 -- For an achievement/award (see below)
    21 -- For an achievement/award (see below)
    22 local cratesCollected = 0
    22 local cratesCollected = 0
    23 local totalCrates = 0
    23 local totalCrates = 0
    24 local damageTaken = false
    24 local damageTaken = false
       
    25 local record
    25 -- health crates
    26 -- health crates
    26 healthX = 565
    27 healthX = 565
    27 health1Y = 1400
    28 health1Y = 1400
    28 health2Y = 850
    29 health2Y = 850
    29 -- hogs
    30 -- hogs
    80 	hero.gear = AddMissionHog(100)
    81 	hero.gear = AddMissionHog(100)
    81 	hero.name = GetHogName(hero.gear)
    82 	hero.name = GetHogName(hero.gear)
    82 	AnimSetGearPosition(hero.gear, hero.x, hero.y)
    83 	AnimSetGearPosition(hero.gear, hero.x, hero.y)
    83 	HogTurnLeft(hero.gear, true)
    84 	HogTurnLeft(hero.gear, true)
    84 
    85 
       
    86  	record = tonumber(GetCampaignVar("FastestMineEscape"))
    85 	initCheckpoint("desert02")
    87 	initCheckpoint("desert02")
    86 
    88 
    87 	AnimInit(true)
    89 	AnimInit(true)
    88 	AnimationSetup()
    90 	AnimationSetup()
    89 end
    91 end
    95 
    97 
    96 function onGameStart()
    98 function onGameStart()
    97 	AnimWait(hero.gear, 3000)
    99 	AnimWait(hero.gear, 3000)
    98 	FollowGear(hero.gear)
   100 	FollowGear(hero.gear)
    99 
   101 
       
   102 	if record ~= nil then
       
   103 		goals[dialog01][3] = goals[dialog01][3] .. "|" .. string.format(loc("Fastest escape: %d turns"), record)
       
   104 	end
   100 	ShowMission(unpack(goals[dialog01]))
   105 	ShowMission(unpack(goals[dialog01]))
   101 	HideMission()
   106 	HideMission()
   102 
   107 
   103 	AddEvent(onHeroDeath, {hero.gear}, heroDeath, {hero.gear}, 0)
   108 	AddEvent(onHeroDeath, {hero.gear}, heroDeath, {hero.gear}, 0)
   104 	AddEvent(onHeroSafe, {hero.gear}, heroSafe, {hero.gear}, 0)
   109 	AddEvent(onHeroSafe, {hero.gear}, heroSafe, {hero.gear}, 0)
   110 	AddAnim(dialog01)
   115 	AddAnim(dialog01)
   111 end
   116 end
   112 
   117 
   113 function onNewTurn()
   118 function onNewTurn()
   114 	SetWeapon(amRope)
   119 	SetWeapon(amRope)
       
   120 	if TotalRounds >= 0 and record ~= nil then
       
   121 		SetTeamLabel(teamA.name, tostring(TotalRounds))
       
   122 	end
   115 end
   123 end
   116 
   124 
   117 function onGameTick()
   125 function onGameTick()
   118 	AnimUnWait()
   126 	AnimUnWait()
   119 	if ShowAnimation() == false then
   127 	if ShowAnimation() == false then
   183 
   191 
   184 function heroSafe(gear)
   192 function heroSafe(gear)
   185 	SendStat(siGameResult, loc("Congratulations, you won!"))
   193 	SendStat(siGameResult, loc("Congratulations, you won!"))
   186 	SendStat(siCustomAchievement, loc("You have escaped successfully."))
   194 	SendStat(siCustomAchievement, loc("You have escaped successfully."))
   187 	SendStat(siCustomAchievement, string.format(loc("Your escape took you %d turns."), TotalRounds))
   195 	SendStat(siCustomAchievement, string.format(loc("Your escape took you %d turns."), TotalRounds))
   188 	local record = tonumber(GetCampaignVar("FastestMineEscape"))
       
   189 	if record ~= nil and TotalRounds >= record then
   196 	if record ~= nil and TotalRounds >= record then
   190 		SendStat(siCustomAchievement, string.format(loc("Your fastest escape so far: %d turns"), record))
   197 		SendStat(siCustomAchievement, string.format(loc("Your fastest escape so far: %d turns"), record))
   191 	end
   198 	end
   192 	if record == nil or TotalRounds < record then
   199 	if record == nil or TotalRounds < record then
   193 		SaveCampaignVar("FastestMineEscape", tostring(TotalRounds))
   200 		SaveCampaignVar("FastestMineEscape", tostring(TotalRounds))
   229 ------------------ Other Functions -------------------
   236 ------------------ Other Functions -------------------
   230 
   237 
   231 function challengeStart()
   238 function challengeStart()
   232 	startChallenge = true
   239 	startChallenge = true
   233 	EndTurn(true)
   240 	EndTurn(true)
   234 end
   241 	if record ~= nil then
       
   242 		SetTeamLabel(teamA.name, "0")
       
   243 	end
       
   244 end