share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert01.lua
changeset 14614 efa2bdeadd79
parent 14613 3d4044b4aa3e
child 14898 4596357d002d
equal deleted inserted replaced
14613:3d4044b4aa3e 14614:efa2bdeadd79
   132 	AnimWait(hero.gear, 3000)
   132 	AnimWait(hero.gear, 3000)
   133 	FollowGear(hero.gear)
   133 	FollowGear(hero.gear)
   134 
   134 
   135 	AddEvent(onHeroDeath, {hero.gear}, heroDeath, {hero.gear}, 0)
   135 	AddEvent(onHeroDeath, {hero.gear}, heroDeath, {hero.gear}, 0)
   136 	AddEvent(onHeroAtFirstBattle, {hero.gear}, heroAtFirstBattle, {hero.gear}, 1)
   136 	AddEvent(onHeroAtFirstBattle, {hero.gear}, heroAtFirstBattle, {hero.gear}, 1)
   137 	AddEvent(onHeroAtThirdBattle, {hero.gear}, heroAtThirdBattle, {hero.gear}, 0)
   137 	AddEvent(onHeroAtThirdBattle, {hero.gear}, heroAtThirdBattle, {hero.gear}, 1)
   138 	AddEvent(onCheckForWin1, {hero.gear}, checkForWin1, {hero.gear}, 0)
   138 	AddEvent(onCheckForWin1, {hero.gear}, checkForWin1, {hero.gear}, 0)
   139 	AddEvent(onCheckForWin2, {hero.gear}, checkForWin2, {hero.gear}, 0)
   139 	AddEvent(onCheckForWin2, {hero.gear}, checkForWin2, {hero.gear}, 0)
   140 	AddEvent(onCrateDestroyed, {hero.gear}, crateDestroyed, {hero.gear}, 0)
   140 	AddEvent(onCrateDestroyed, {hero.gear}, crateDestroyed, {hero.gear}, 0)
   141 
   141 
   142 	-- smugglers ammo
   142 	-- smugglers ammo
   185 		AddGear(x, 470, gtMine, 0, 0, 0, 0)
   185 		AddGear(x, 470, gtMine, 0, 0, 0, 0)
   186 		x = x + GetRandom(13)+8
   186 		x = x + GetRandom(13)+8
   187 	end
   187 	end
   188 
   188 
   189 	AddEvent(onHeroFleeFirstBattle, {hero.gear}, heroFleeFirstBattle, {hero.gear}, 1)
   189 	AddEvent(onHeroFleeFirstBattle, {hero.gear}, heroFleeFirstBattle, {hero.gear}, 1)
   190 	AddEvent(onHeroAtBattlePoint1, {hero.gear}, heroAtBattlePoint1, {hero.gear}, 0)
   190 	AddEvent(onHeroAtBattlePoint1, {hero.gear}, heroAtBattlePoint1, {hero.gear}, 1)
   191 	AddEvent(onHeroAtBattlePoint2, {hero.gear}, heroAtBattlePoint2, {hero.gear}, 0)
   191 	AddEvent(onHeroAtBattlePoint2, {hero.gear}, heroAtBattlePoint2, {hero.gear}, 1)
   192 	-- crates
   192 	-- crates
   193 	SpawnSupplyCrate(btorch1X, btorch1Y, amBlowTorch)
   193 	SpawnSupplyCrate(btorch1X, btorch1Y, amBlowTorch)
   194 	SpawnHealthCrate(680, 460)
   194 	SpawnHealthCrate(680, 460)
   195 	-- hero ammo
   195 	-- hero ammo
   196 	AddAmmo(hero.gear, amRope, 2)
   196 	AddAmmo(hero.gear, amRope, 2)
   274 	elseif gear == btorch2.gear then
   274 	elseif gear == btorch2.gear then
   275 		foundDeviceCrateCandidate(btorch2, girder)
   275 		foundDeviceCrateCandidate(btorch2, girder)
   276 	end
   276 	end
   277 	if gear == hero.gear then
   277 	if gear == hero.gear then
   278 		hero.dead = true
   278 		hero.dead = true
   279 	elseif (gear == smuggler1.gear or gear == smuggler2.gear or gear == smuggler3.gear) and heroIsInBattle then
   279 	elseif heroIsInBattle then
   280 		heroIsInBattle = false
   280 		if ((ongoingBattle == 1 and gear == smuggler1.gear) or
   281 		SetTeamPassive(teamB.name, true)
   281 		(ongoingBattle == 2 and gear == smuggler2.gear) or
   282 		ongoingBattle = 0
   282 		(ongoingBattle == 3 and gear == smuggler3.gear)) then
       
   283 			heroIsInBattle = false
       
   284 			SetTeamPassive(teamB.name, true)
       
   285 			ongoingBattle = 0
       
   286 			if gear == smuggler1.gear then
       
   287 				RemoveEventFunc(onHeroAtFirstBattle)
       
   288 				RemoveEventFunc(onHeroFleeFirstBattle)
       
   289 			elseif gear == smuggler2.gear then
       
   290 				RemoveEventFunc(onHeroAtBattlePoint1)
       
   291 				RemoveEventFunc(onHeroAtBattlePoint2)
       
   292 			elseif gear == smuggler3.gear then
       
   293 				RemoveEventFunc(onHeroAtThirdBattle)
       
   294 			end
       
   295 		end
   283 	end
   296 	end
   284 end
   297 end
   285 
   298 
   286 function onPrecise()
   299 function onPrecise()
   287 	if GameTime > 3000 then
   300 	if GameTime > 3000 then
   297 	end
   310 	end
   298 	return false
   311 	return false
   299 end
   312 end
   300 
   313 
   301 function onHeroAtFirstBattle(gear)
   314 function onHeroAtFirstBattle(gear)
   302 	if not hero.dead and not heroIsInBattle and GetHealth(smuggler1.gear) and GetX(hero.gear) <= 1233 and GetX(hero.gear) > 80
   315 	if not hero.dead and (not (heroIsInBattle and ongoingBattle == 1)) and ((not heroIsInBattle) or (heroIsInBattle and ongoingBattle == 3)) and GetHealth(smuggler1.gear) and GetX(hero.gear) <= 1233 and GetX(hero.gear) > 80
   303 			and GetY(hero.gear) <= GetY(smuggler1.gear)+5 and GetY(hero.gear) >= GetY(smuggler1.gear)-40 and
   316 			and GetY(hero.gear) <= GetY(smuggler1.gear)+5 and GetY(hero.gear) >= GetY(smuggler1.gear)-40 and
   304 			-- If hero is standing or at a rope
   317 			-- If hero is standing or at a rope
   305 			(StoppedGear(hero.gear) or GetGearElasticity(hero.gear) ~= 0) then
   318 			(StoppedGear(hero.gear) or GetGearElasticity(hero.gear) ~= 0) then
   306 		return true
   319 		return true
   307 	end
   320 	end
   318 	return false
   331 	return false
   319 end
   332 end
   320 
   333 
   321 -- saves the location of the hero and prompts him for the second battle
   334 -- saves the location of the hero and prompts him for the second battle
   322 function onHeroAtBattlePoint1(gear)
   335 function onHeroAtBattlePoint1(gear)
   323 	if not hero.dead and GetX(hero.gear) > 1000 and GetX(hero.gear) < 1100
   336 	if not hero.dead and (not (heroIsInBattle and ongoingBattle == 2))
       
   337 			and GetX(hero.gear) > 1000 and GetX(hero.gear) < 1100
   324 			and GetY(hero.gear) > 590 and GetY(hero.gear) < 700 and StoppedGear(hero.gear)
   338 			and GetY(hero.gear) > 590 and GetY(hero.gear) < 700 and StoppedGear(hero.gear)
   325 			and (StoppedGear(hero.gear) or GetGearElasticity(hero.gear) ~= 0) then
   339 			and (StoppedGear(hero.gear) or GetGearElasticity(hero.gear) ~= 0) then
   326 		return true
   340 		return true
   327 	end
   341 	end
   328 	return false
   342 	return false
   329 end
   343 end
   330 
   344 
   331 function onHeroAtBattlePoint2(gear)
   345 function onHeroAtBattlePoint2(gear)
   332 	if not hero.dead and GetX(hero.gear) > 1610 and GetX(hero.gear) < 1680
   346 	if not hero.dead and (not (heroIsInBattle and ongoingBattle == 2))
       
   347 			and GetX(hero.gear) > 1610 and GetX(hero.gear) < 1680
   333 			and GetY(hero.gear) > 850 and GetY(hero.gear) < 1000
   348 			and GetY(hero.gear) > 850 and GetY(hero.gear) < 1000
   334 			and (StoppedGear(hero.gear) or GetGearElasticity(hero.gear) ~= 0) then
   349 			and (StoppedGear(hero.gear) or GetGearElasticity(hero.gear) ~= 0) then
   335 		return true
   350 		return true
   336 	end
   351 	end
   337 	return false
   352 	return false
   338 end
   353 end
   339 
   354 
   340 function onHeroAtThirdBattle(gear)
   355 function onHeroAtThirdBattle(gear)
   341 	if not hero.dead and GetX(hero.gear) > 2000 and GetX(hero.gear) < 2200
   356 	if not hero.dead and (not (heroIsInBattle and ongoingBattle == 3))
       
   357 			and GetX(hero.gear) > 2000 and GetX(hero.gear) < 2200
   342 			and GetY(hero.gear) > 1430 and GetY(hero.gear) < 1670 then
   358 			and GetY(hero.gear) > 1430 and GetY(hero.gear) < 1670 then
   343 		return true
   359 		return true
   344 	end
   360 	end
   345 	return false
   361 	return false
   346 end
   362 end
   372 	lose()
   388 	lose()
   373 end
   389 end
   374 
   390 
   375 function heroAtFirstBattle(gear)
   391 function heroAtFirstBattle(gear)
   376 	AnimCaption(hero.gear, loc("A smuggler! Prepare for battle"), 5000)
   392 	AnimCaption(hero.gear, loc("A smuggler! Prepare for battle"), 5000)
   377 	-- Remember velocity to restore it later
       
   378 	local dx, dy = GetGearVelocity(hero.gear)
       
   379 	-- Hog gets scared if on rope
       
   380 	if isOnRope() then
       
   381 		PlaySound(sndRopeRelease)
       
   382 		HogSay(hero.gear, loc("Gasp! A smuggler!"), SAY_SHOUT)
       
   383 		dx = div(dx, 3)
       
   384 		dy = div(dy, 3)
       
   385 	end
       
   386 	SetGearMessage(hero.gear, 0)
       
   387 	SetTeamPassive(teamB.name, false)
       
   388 	heroIsInBattle = true
       
   389 	EndTurn(true)
       
   390 	ongoingBattle = 1
   393 	ongoingBattle = 1
   391 	AnimSwitchHog(smuggler1.gear)
   394 	if not heroIsInBattle then
   392 	EndTurn(true)
   395 		-- Remember velocity to restore it later
   393 	SetGearVelocity(hero.gear, dx, dy)
   396 		local dx, dy = GetGearVelocity(hero.gear)
       
   397 		-- Hog gets scared if on rope
       
   398 		if isOnRope() then
       
   399 			PlaySound(sndRopeRelease)
       
   400 			HogSay(hero.gear, loc("Gasp! A smuggler!"), SAY_SHOUT)
       
   401 			dx = div(dx, 3)
       
   402 			dy = div(dy, 3)
       
   403 		end
       
   404 		SetGearMessage(hero.gear, 0)
       
   405 		SetTeamPassive(teamB.name, false)
       
   406 		heroIsInBattle = true
       
   407 		--EndTurn(true)
       
   408 		AnimSwitchHog(smuggler1.gear)
       
   409 		EndTurn(true)
       
   410 		SetGearVelocity(hero.gear, dx, dy)
       
   411 	end
   394 end
   412 end
   395 
   413 
   396 function heroFleeFirstBattle(gear)
   414 function heroFleeFirstBattle(gear)
   397 	AnimSay(smuggler1.gear, loc("Run away, you coward!"), SAY_SHOUT, 4000)
   415 	AnimSay(smuggler1.gear, loc("Run away, you coward!"), SAY_SHOUT, 4000)
   398 	SetTeamPassive(teamB.name, true)
   416 	SetTeamPassive(teamB.name, true)
   408 function heroAtBattlePoint2(gear)
   426 function heroAtBattlePoint2(gear)
   409 	secondBattle()
   427 	secondBattle()
   410 end
   428 end
   411 
   429 
   412 function heroAtThirdBattle(gear)
   430 function heroAtThirdBattle(gear)
   413 	heroIsInBattle = true
   431 	-- third battle
   414 	SetTeamPassive(teamB.name, false)
       
   415 	ongoingBattle = 3
   432 	ongoingBattle = 3
   416 	AnimSay(smuggler3.gear, loc("Who's there?! I'll get you!"), SAY_SHOUT, 5000)
   433 	AnimSay(smuggler3.gear, loc("Who's there?! I'll get you!"), SAY_SHOUT, 5000)
   417 	local dx, dy = GetGearVelocity(hero.gear)
   434 	if not heroIsInBattle then
   418 	-- Hog gets scared and falls from rope
   435 		heroIsInBattle = true
   419 	if isOnRope() then
   436 		SetTeamPassive(teamB.name, false)
   420 		PlaySound(sndRopeRelease)
   437 		ongoingBattle = 3
   421 		HogSay(hero.gear, loc("Yikes!"), SAY_SHOUT)
   438 		local dx, dy = GetGearVelocity(hero.gear)
   422 		dx = div(dx, 3)
   439 		-- Hog gets scared and falls from rope
   423 		dy = div(dy, 3)
   440 		if isOnRope() then
   424 	end
   441 			PlaySound(sndRopeRelease)
   425 	SetGearMessage(hero.gear, 0)
   442 			HogSay(hero.gear, loc("Yikes!"), SAY_SHOUT)
   426 	AnimSwitchHog(smuggler3.gear)
   443 			dx = div(dx, 3)
   427 	EndTurn(true)
   444 			dy = div(dy, 3)
   428 	SetGearVelocity(hero.gear, dx, dy)
   445 		end
       
   446 		SetGearMessage(hero.gear, 0)
       
   447 		AnimSwitchHog(smuggler3.gear)
       
   448 		EndTurn(true)
       
   449 		SetGearVelocity(hero.gear, dx, dy)
       
   450 	end
   429 end
   451 end
   430 
   452 
   431 function crateDestroyed(gear)
   453 function crateDestroyed(gear)
   432 	lose()
   454 	lose()
   433 end
   455 end
   492 	AnimSwitchHog(ally.gear)
   514 	AnimSwitchHog(ally.gear)
   493 	EndTurn(true)
   515 	EndTurn(true)
   494 end
   516 end
   495 
   517 
   496 function secondBattle()
   518 function secondBattle()
       
   519 	local smugglerMsg = function()
       
   520 		AnimSay(smuggler2.gear, loc("This seems like a wealthy hedgehog, nice ..."), SAY_THINK, 5000)
       
   521 	end
   497 	-- second battle
   522 	-- second battle
   498 	if heroIsInBattle and ongoingBattle == 1 then
   523 	if heroIsInBattle then
   499 		AnimSay(smuggler1.gear, loc("Get him, Spike!"), SAY_SHOUT, 4000)
   524 		if ongoingBattle == 1 then
   500 	end
   525 			AnimSay(smuggler1.gear, loc("Get him, Spike!"), SAY_SHOUT, 4000)
   501 	local dx, dy = GetGearVelocity(hero.gear)
   526 		else
   502 	-- Hog gets scared if on rope
   527 			smugglerMsg()
   503 	if isOnRope() then
   528 		end
   504 		PlaySound(sndRopeRelease)
   529 		ongoingBattle = 2
   505 		HogSay(hero.gear, loc("Gasp!"), SAY_SHOUT)
   530 	else
   506 		dx = div(dx, 3)
   531 		smugglerMsg()
   507 		dy = div(dy, 3)
   532 		local dx, dy = GetGearVelocity(hero.gear)
   508 	end
   533 		-- Hog gets scared if on rope
   509 	SetGearMessage(hero.gear, 0)
   534 		if isOnRope() then
   510 	heroIsInBattle = true
   535 			PlaySound(sndRopeRelease)
   511 	SetTeamPassive(teamB.name, false)
   536 			HogSay(hero.gear, loc("Gasp!"), SAY_SHOUT)
   512 	ongoingBattle = 2
   537 			dx = div(dx, 3)
   513 	AnimSay(smuggler2.gear, loc("This seems like a wealthy hedgehog, nice ..."), SAY_THINK, 5000)
   538 			dy = div(dy, 3)
   514 	AnimSwitchHog(smuggler2.gear)
   539 		end
   515 	EndTurn(true)
   540 		SetGearMessage(hero.gear, 0)
       
   541 		heroIsInBattle = true
       
   542 		SetTeamPassive(teamB.name, false)
       
   543 		ongoingBattle = 2
       
   544 		AnimSwitchHog(smuggler2.gear)
       
   545 		EndTurn(true)
       
   546 	end
   516 	SetGearVelocity(hero.gear, dx, dy)
   547 	SetGearVelocity(hero.gear, dx, dy)
   517 end
   548 end
   518 
   549 
   519 function checkForWin()
   550 function checkForWin()
   520 	if cratesFound ==  0 then
   551 	if cratesFound ==  0 then