ASA moon02: Fix player not losing if time runs out while still having the rope
authorWuzzy <Wuzzy2@mail.ru>
Mon, 14 Jan 2019 17:04:18 +0100
changeset 14601 1a68c8a07d1f
parent 14600 42f3d6860971
child 14602 72b4bdd5052c
ASA moon02: Fix player not losing if time runs out while still having the rope
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua	Mon Jan 14 16:18:34 2019 +0100
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua	Mon Jan 14 17:04:18 2019 +0100
@@ -13,12 +13,16 @@
 local challengeObjectives = loc("Use the rope in order to catch the blue hedgehog").."|"..
 	loc("You have to stand very close to him")
 local currentPosition = 1
+local raceSectionStarted = false
+local runnerCaught = false
 local previousTimeLeft = 0
 local startChallenge = false
 local winningTime = nil
 local currentTime = 0
 local runnerTime = 0
 local record
+local lostGame = false
+local heroHurt = false
 -- dialogs
 local dialog01 = {}
 local dialog02 = {}
@@ -125,16 +129,29 @@
 			runnerTime = runnerTime + runner.places[currentPosition].turnTime
 			SetTeamLabel(teamB.name, string.format(loc("%.1fs"), runnerTime/1000))
 		else
-			if GetAmmoCount(hero.gear, amRope) == 0  then
-				lose()
-			end
 			SetWeapon(amRope)
 			SetTurnTimeLeft(runner.places[currentPosition].turnTime + previousTimeLeft)
 			previousTimeLeft = 0
+			if currentPosition > 1 then
+				raceSectionStarted = true
+			end
+			runnerCaught = false
 		end
 	end
 end
 
+function onEndTurn()
+	if raceSectionStarted and currentPosition > 1 and currentPosition < 5 then
+		if CurrentHedgehog == hero.gear and (not runnerCaught) and (not heroHurt) then
+			-- sndBoring played manually because lose calls EndGame, which suppresses
+			-- the taunt.
+			PlaySound(sndBoring, hero.gear)
+			lose()
+		end
+	end
+	raceSectionStarted = false
+end
+
 function onGameTick()
 	AnimUnWait()
 	if ShowAnimation() == false then
@@ -162,6 +179,12 @@
 	end
 end
 
+function onGearDamage(gear)
+	if gear == hero.gear then
+		heroHurt = true
+	end
+end
+
 -------------- EVENTS ------------------
 
 function onHeroDeath(gear)
@@ -258,11 +281,11 @@
 		end
 		AddAmmo(hero.gear, amRope, 1)
 		if currentPosition ~= 1 then
-			PlaySound(sndVictory)
 			if currentPosition > 1 and currentPosition < 4 then
 				AnimCaption(hero.gear, loc("Go, get him again!"), 3000)
 				AnimSay(runner.gear, loc("You got me!"), SAY_SAY, 3000)
 			end
+			runnerCaught = true
 			previousTimeLeft = TurnTimeLeft
 		end
 		currentPosition = currentPosition + 1
@@ -273,6 +296,10 @@
 end
 
 function lose()
+	if lostGame then
+		return
+	end
+	lostGame = true
 	SendStat(siGameResult, loc("Too slow! Try again ..."))
 	SendStat(siCustomAchievement, loc("You have to catch the other hog 3 times."))
 	SendStat(siCustomAchievement, loc("The time that you have left when you reach the blue hedgehog will be added to the next turn."))