share/hedgewars/Data/Missions/Training/Basic_Training_-_Rope.lua
changeset 14668 38836d6c5c8a
parent 14492 6c62f7ebea45
child 14928 4c5fb1ee75b7
equal deleted inserted replaced
14667:6b70c109389f 14668:38836d6c5c8a
    39 local target1Reached = false	-- hog near 1st first target
    39 local target1Reached = false	-- hog near 1st first target
    40 local barrelsBoom = false	-- barrels exploded
    40 local barrelsBoom = false	-- barrels exploded
    41 local wasFirstTurn = false	-- first turn msg was displayed
    41 local wasFirstTurn = false	-- first turn msg was displayed
    42 local gameOver = false		-- game over (only victory possible)
    42 local gameOver = false		-- game over (only victory possible)
    43 local currentTarget = 0		-- current target ID. First target = 1
    43 local currentTarget = 0		-- current target ID. First target = 1
       
    44 local flawless = true		-- flawless if no damage taken and no mistake made
    44 
    45 
    45 local cpX, cpY = 208, 1384	-- hog checkpoint, initialized with start coords
    46 local cpX, cpY = 208, 1384	-- hog checkpoint, initialized with start coords
    46 
    47 
    47 -- "Constants"
    48 -- "Constants"
    48 local initHogHealth = 50
    49 local initHogHealth = 50
   231 		local x, y = GetGearPosition(CurrentHedgehog)
   232 		local x, y = GetGearPosition(CurrentHedgehog)
   232 		if band(GetState(CurrentHedgehog), gstHHDriven) ~= 0 and GetAmmoCount(CurrentHedgehog, amRope) == 0 and
   233 		if band(GetState(CurrentHedgehog), gstHHDriven) ~= 0 and GetAmmoCount(CurrentHedgehog, amRope) == 0 and
   233 				GetFlightTime(CurrentHedgehog) == 0 and (not ropeGear) and
   234 				GetFlightTime(CurrentHedgehog) == 0 and (not ropeGear) and
   234 				math.abs(dX) < 5 and math.abs(dY) < 5 and
   235 				math.abs(dX) < 5 and math.abs(dY) < 5 and
   235 				(x < 3417 or y > 471) then
   236 				(x < 3417 or y > 471) then
       
   237 			flawless = false
   236 			AddCaption(loc("Your rope is gone! Try again!"))
   238 			AddCaption(loc("Your rope is gone! Try again!"))
   237 			resetFinalChallenge()
   239 			resetFinalChallenge()
   238 			PlaySound(sndWarp)
   240 			PlaySound(sndWarp)
   239 		end
   241 		end
   240 	end
   242 	end
   260 end
   262 end
   261 
   263 
   262 function onGearResurrect(gear, vGear)
   264 function onGearResurrect(gear, vGear)
   263 	-- Teleport hog to previous checkpoint
   265 	-- Teleport hog to previous checkpoint
   264 	if gear == hog then
   266 	if gear == hog then
       
   267 		flawless = false
   265 		SetGearPosition(hog, cpX, cpY)
   268 		SetGearPosition(hog, cpX, cpY)
   266 		if vGear then
   269 		if vGear then
   267 			SetVisualGearValues(vGear, GetX(hog), GetY(hog))
   270 			SetVisualGearValues(vGear, GetX(hog), GetY(hog))
   268 		end
   271 		end
   269 		FollowGear(hog)
   272 		FollowGear(hog)
   270 		AddCaption(loc("Your hedgehog has been revived!"))
   273 		AddCaption(loc("Your hedgehog has been revived!"))
   271 		if isInFinalChallenge then
   274 		if isInFinalChallenge then
   272 			resetFinalChallenge(false)
   275 			resetFinalChallenge(false)
   273 		end
   276 		end
       
   277 	end
       
   278 end
       
   279 
       
   280 function onGearDamage(gear)
       
   281 	if gear == hog then
       
   282 		flawless = false
   274 	end
   283 	end
   275 end
   284 end
   276 
   285 
   277 function onGearDelete(gear)
   286 function onGearDelete(gear)
   278 	if GetGearType(gear) == gtTarget then
   287 	if GetGearType(gear) == gtTarget then
   329 			isInFinalChallenge = true
   338 			isInFinalChallenge = true
   330 		elseif currentTarget == 7 then
   339 		elseif currentTarget == 7 then
   331 			SaveMissionVar("Won", "true")
   340 			SaveMissionVar("Won", "true")
   332 			ShowMission(loc("Basic Rope Training"), loc("Training complete!"),
   341 			ShowMission(loc("Basic Rope Training"), loc("Training complete!"),
   333 			loc("Congratulations!"), 0, 0)
   342 			loc("Congratulations!"), 0, 0)
   334 			PlaySound(sndVictory, hog)
   343 			if flawless then
       
   344 				PlaySound(sndFlawless, hog)
       
   345 			else
       
   346 				PlaySound(sndVictory, hog)
       
   347 			end
   335 			AddAmmo(hog, amBaseballBat, 0)
   348 			AddAmmo(hog, amBaseballBat, 0)
   336 			AddAmmo(hog, amGrenade, 0)
   349 			AddAmmo(hog, amGrenade, 0)
   337 			AddAmmo(hog, amRope, 0)
   350 			AddAmmo(hog, amRope, 0)
   338 			SendStat(siCustomAchievement, loc("Oh yeah! You sure know how to rope!"))
   351 			SendStat(siCustomAchievement, loc("Oh yeah! You sure know how to rope!"))
   339 			SendStat(siGameResult, loc("You have finished the Basic Rope Training!"))
   352 			SendStat(siGameResult, loc("You have finished the Basic Rope Training!"))