share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert03.lua
branchspacecampaign
changeset 9605 66cd14e5bdad
child 9606 1d088cc31ff8
equal deleted inserted replaced
9604:edc1785487c3 9605:66cd14e5bdad
       
     1 ------------------- ABOUT ----------------------
       
     2 --
       
     3 -- Hero has to use the rc plane end perform some
       
     4 -- flying tasks
       
     5 
       
     6 HedgewarsScriptLoad("/Scripts/Locale.lua")
       
     7 HedgewarsScriptLoad("/Scripts/Animate.lua")
       
     8 HedgewarsScriptLoad("/Missions/Campaign/A_Space_Adventure/global_functions.lua")
       
     9 
       
    10 -- globals
       
    11 local missionName = loc("Precise flying")
       
    12 local challengeObjectives = loc("Use the rc plane and destroy the all the targets").."|"..
       
    13 	loc("Each time you destroy your level targets you'll get teleported to the next level").."|"..
       
    14 	loc("You'll have only one rc plane at the start of the mission").."|"..
       
    15 	loc("During the game you can get new plane by getting the weapon crates")
       
    16 local currentTarget = 1
       
    17 -- hogs
       
    18 local hero = {
       
    19 	name = loc("Hog Solo"),
       
    20 	x = 100,
       
    21 	y = 170
       
    22 }
       
    23 -- teams
       
    24 local teamA = {
       
    25 	name = loc("Hog Solo"),
       
    26 	color = tonumber("38D61C",16) -- green
       
    27 }
       
    28 -- creates & targets
       
    29 local rcCrates = {
       
    30 	{ x = 1680, y = 240},
       
    31 	{ x = 2810, y = 720},
       
    32 }
       
    33 local targets = {
       
    34 	{ x = 2070, y = 410},
       
    35 	{ x = 3880, y = 1430},
       
    36 	{ x = 4030, y = 1430},
       
    37 }
       
    38 
       
    39 -------------- LuaAPI EVENT HANDLERS ------------------
       
    40 
       
    41 function onGameInit()
       
    42 	GameFlags = gfOneClanMode
       
    43 	Seed = 1
       
    44 	TurnTime = -1
       
    45 	CaseFreq = 0
       
    46 	MinesNum = 0
       
    47 	MinesTime = 1
       
    48 	Explosives = 0
       
    49 	Map = "desert03_map"
       
    50 	Theme = "Desert"
       
    51 	
       
    52 	-- Hog Solo
       
    53 	AddTeam(teamA.name, teamA.color, "Bone", "Island", "HillBilly", "cm_birdy")
       
    54 	hero.gear = AddHog(hero.name, 0, 100, "war_desertgrenadier1")
       
    55 	AnimSetGearPosition(hero.gear, hero.x, hero.y)
       
    56 	
       
    57 	initCheckpoint("desert03")
       
    58 	
       
    59 	AnimInit()
       
    60 	--AnimationSetup()
       
    61 end
       
    62 
       
    63 function onGameStart()
       
    64 	AnimWait(hero.gear, 3000)
       
    65 	FollowGear(hero.gear)
       
    66 	ShowMission(missionName, loc("Challenge Objectives"), challengeObjectives, -amSkip, 0)
       
    67 
       
    68 	AddEvent(onHeroDeath, {hero.gear}, heroDeath, {hero.gear}, 0)
       
    69 
       
    70 	-- original crates and targets
       
    71 	SpawnAmmoCrate(rcCrates[1].x, rcCrates[1].y, amRCPlane)
       
    72 	targets[1].gear = AddGear(targets[1].x, targets[1].y, gtTarget, 0, 0, 0, 0)
       
    73 	
       
    74 	-- hero ammo
       
    75 	AddAmmo(hero.gear, amRCPlane, 1)
       
    76 
       
    77 	SendHealthStatsOff()
       
    78 end
       
    79 
       
    80 function onGameTick20()
       
    81 	checkTargetsDestroied()
       
    82 end
       
    83 
       
    84 function onAmmoStoreInit()
       
    85 	if currentTarget == 1 then
       
    86 		SetAmmo(amRCPlane, 0, 0, 0, 1)
       
    87 	end
       
    88 end
       
    89 
       
    90 -------------- EVENTS ------------------
       
    91 
       
    92 function onHeroDeath(gear)
       
    93 	if not GetHealth(hero.gear) then
       
    94 		return true
       
    95 	end
       
    96 	return false
       
    97 end
       
    98 
       
    99 -------------- ACTIONS ------------------
       
   100 
       
   101 function heroDeath(gear)
       
   102 	SendStat('siGameResult', loc("Hog Solo lost, try again!")) --1
       
   103 	SendStat('siCustomAchievement', loc("You have to destroy all the targets")) --11			
       
   104 	SendStat('siCustomAchievement', loc("Read the Challenge Objectives from within the mission for more details")) --11		
       
   105 	SendStat('siPlayerKills','1',teamB.name)
       
   106 	SendStat('siPlayerKills','0',teamA.name)
       
   107 	EndGame()
       
   108 end
       
   109 
       
   110 ----------------- Other Functions -----------------
       
   111 
       
   112 function checkTargetsDestroied()
       
   113 	if currentTarget == 1 then
       
   114 		if not GetHealth(targets[1].gear) then
       
   115 			AddCaption(loc("Level 1 clear!"))
       
   116 			SetGearPosition(hero.gear, 3590, 90)
       
   117 			currentTarget = 2
       
   118 			setTargets(currentTarget)
       
   119 		end
       
   120 	elseif currentTarget == 2 then
       
   121 		
       
   122 	else
       
   123 		win()
       
   124 	end
       
   125 end
       
   126 
       
   127 function setTargets(ct)
       
   128 	if ct == 2 then
       
   129 		SpawnAmmoCrate(rcCrates[2].x, rcCrates[2].y, amRCPlane)
       
   130 		for i=2,3 do
       
   131 			targets[i].gear = AddGear(targets[i].x, targets[i].y, gtTarget, 0, 0, 0, 0)
       
   132 		end
       
   133 	end
       
   134 end
       
   135 
       
   136 function win()
       
   137 	EndGame()
       
   138 end