Fix rope detection in ASA desert01
authorWuzzy <almikes@aol.com>
Fri, 29 Sep 2017 18:27:44 +0200
changeset 12588 2b9f658cba90
parent 12587 0b27d8b4f8e7
child 12589 fa837afff629
Fix rope detection in ASA desert01
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert01.lua
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert01.lua	Fri Sep 29 18:00:43 2017 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert01.lua	Fri Sep 29 18:27:44 2017 +0200
@@ -20,6 +20,7 @@
 local heroIsInBattle = false
 local ongoingBattle = 0
 local cratesFound = 0
+local ropeGear = nil
 -- dialogs
 local dialog01 = {}
 -- mission objectives
@@ -236,7 +237,16 @@
 	SetAmmo(amSkip, 9, 0, 0, 1)
 end
 
+function onGearAdd(gear)
+	if GetGearType(gear) == gtRope then
+		ropeGear = gear
+	end
+end
+
 function onGearDelete(gear)
+	if GetGearType(gear) == gtRope then
+		ropeGear = nil
+	end
 	local foundDeviceCrateCandidate = function(candidate_crate_table, other_crate_table)
 		candidate_crate_table.deleted = true
 		-- Evaluates to false if crate has been collected
@@ -360,12 +370,15 @@
 
 function heroAtFirstBattle(gear)
 	AnimCaption(hero.gear, loc("A smuggler! Prepare for battle"), 5000)
-	-- Hog gets scared if on rope
-	if GetGearElasticity(hero.gear) ~= 0 then
-		HogSay(hero.gear, loc("Gasp! A smuggler!"), SAY_SHOUT)
-	end
 	-- Remember velocity to restore it later
 	local dx, dy = GetGearVelocity(hero.gear)
+	-- Hog gets scared if on rope
+	if isOnRope() then
+		PlaySound(sndRopeRelease)
+		HogSay(hero.gear, loc("Gasp! A smuggler!"), SAY_SHOUT)
+		dx = div(dx, 3)
+		dy = div(dy, 3)
+	end
 	EndTurn(true)
 	heroIsInBattle = true
 	ongoingBattle = 1
@@ -393,11 +406,14 @@
 	heroIsInBattle = true
 	ongoingBattle = 3
 	AnimSay(smuggler3.gear, loc("Who's there?! I'll get you!"), SAY_SHOUT, 5000)
+	local dx, dy = GetGearVelocity(hero.gear)
 	-- Hog gets scared and falls from rope
-	if GetGearElasticity(hero.gear) ~= 0 then
+	if isOnRope() then
+		PlaySound(sndRopeRelease)
 		HogSay(hero.gear, loc("Yikes!"), SAY_SHOUT)
+		dx = div(dx, 3)
+		dy = div(dy, 3)
 	end
-	local dx, dy = GetGearVelocity(hero.gear)
 	AnimSwitchHog(smuggler3.gear)
 	EndTurn(true)
 	SetGearVelocity(hero.gear, dx, dy)
@@ -456,6 +472,13 @@
 
 --------------- OTHER FUNCTIONS ------------------
 
+function isOnRope()
+	if ropeGear then
+		return true
+	end
+	return false
+end
+
 function startMission()
 	AnimSwitchHog(ally.gear)
 	EndTurn(true)
@@ -466,11 +489,14 @@
 	if heroIsInBattle and ongoingBattle == 1 then
 		AnimSay(smuggler1.gear, loc("Get him, Spike!"), SAY_SHOUT, 4000)
 	end
+	local dx, dy = GetGearVelocity(hero.gear)
 	-- Hog gets scared if on rope
-	if GetGearElasticity(hero.gear) ~= 0 then
+	if isOnRope() then
+		PlaySound(sndRopeRelease)
 		HogSay(hero.gear, loc("Gasp!"), SAY_SHOUT)
+		dx = div(dx, 3)
+		dy = div(dy, 3)
 	end
-	local dx, dy = GetGearVelocity(hero.gear)
 	heroIsInBattle = true
 	ongoingBattle = 2
 	AnimSay(smuggler2.gear, loc("This is seems like a wealthy hedgehog, nice ..."), SAY_THINK, 5000)