share/hedgewars/Data/Missions/Campaign/A Space Adventure/cosmos.lua
branchspacecampaign
changeset 9308 4bddcc1a1450
parent 9296 5cc010e79431
parent 9306 c9978ada9a3d
child 9310 1469147c110f
equal deleted inserted replaced
9296:5cc010e79431 9308:4bddcc1a1450
     1 ------------------- ABOUT ----------------------
       
     2 --
       
     3 -- This map works as a menu for the hero hog to
       
     4 -- navigate through planets. It portrays the hogs
       
     5 -- planet and above the planets that he'll later
       
     6 -- visit.
       
     7 
       
     8 -- TODO
       
     9 -- Save and Load All Check Points
       
    10 -- Save hero health
       
    11 -- Decide and implement if hero will use gas bombs...
       
    12 -- ofc add custom stats page
       
    13 -- PROBLEM : What if one makes a bad choice and wants to replay it map, how to reset?
       
    14 -- POSSIBLE SOLUTIONS: In game function keys, frontend button...
       
    15 
       
    16 HedgewarsScriptLoad("/Scripts/Locale.lua")
       
    17 HedgewarsScriptLoad("/Scripts/Animate.lua")
       
    18 
       
    19 ----------------- VARIABLES --------------------
       
    20 -- globals
       
    21 local campaignName = loc("A Space Adventure")
       
    22 local missionName = loc("Cosmos")
       
    23 local timeForGuard1ToTurn = 1000 * 5 -- 5 sec
       
    24 local timeForGuard1ToTurnLeft = timeForGuard1ToTurn
       
    25 local saucerAcquired = false
       
    26 local checkPointReached = 1 -- 1 is start of the game
       
    27 -- dialogs
       
    28 local dialog01 = {}
       
    29 local dialog02 = {}
       
    30 local dialog03 = {}
       
    31 local dialog04 = {}
       
    32 local dialog05 = {}
       
    33 local dialog06 = {}
       
    34 -- mission objectives
       
    35 local goals = {
       
    36 	[dialog01] = {missionName, loc("Getting ready"), loc("Go and collect the crate on top of the column").."|"..loc("Use the sleep gas bomb if the guards spot you!"), 1, 4500},
       
    37 	[dialog02] = {missionName, loc("The adventure begins!"), loc("Use the saucer and fly to the moon").."|"..loc("Drive carefully as your fuels are limited"), 1, 4500},
       
    38 	[dialog03] = {missionName, loc("An unexpected event!"), loc("Use the saucer and fly away or use the gas bomb to neutralize the guards").."|"..loc("Beware, any damage taken will stay until you take some medicine or visit moon"), 1, 7000}
       
    39 }
       
    40 -- crates
       
    41 local saucerX = 3270
       
    42 local saucerY = 1500
       
    43 -- hogs
       
    44 local hero = {}
       
    45 local director = {}
       
    46 local doctor = {}
       
    47 local guard1 = {}
       
    48 local guard2 = {}
       
    49 -- teams
       
    50 local teamA = {}
       
    51 local teamB = {}
       
    52 local teamC = {}
       
    53 -- hedgehogs values
       
    54 hero.name = loc("Hog Solo")
       
    55 hero.x = 1450
       
    56 hero.y = 1550
       
    57 director.name = loc("H")
       
    58 director.x = 1350
       
    59 director.y = 1550
       
    60 doctor.name = loc("Dr.Cornelius")
       
    61 doctor.x = 1300
       
    62 doctor.y = 1550
       
    63 guard1.name = loc("Bob")
       
    64 guard1.x = 3350
       
    65 guard1.y = 1800
       
    66 guard1.turn = false
       
    67 guard1.keepTurning = true
       
    68 guard2.name = loc("Sam")
       
    69 guard2.x = 3400
       
    70 guard2.y = 1800
       
    71 teamA.name = loc("PAoTH")
       
    72 teamA.color = tonumber("FF0000",16) -- red
       
    73 teamB.name = loc("Guards")
       
    74 teamB.color = tonumber("0033FF",16) -- blue
       
    75 teamC.name = loc("Hog Solo")
       
    76 teamC.color = tonumber("38D61C",16) -- green
       
    77 
       
    78 -------------- LuaAPI EVENT HANDLERS ------------------
       
    79 function onGameInit()
       
    80 	Seed = 35
       
    81 	GameFlags = gfSolidLand + gfDisableWind
       
    82 	TurnTime = 40000
       
    83 	CaseFreq = 0
       
    84 	MinesNum = 0
       
    85 	Explosives = 0
       
    86 	Delay = 5
       
    87 	Map = "cosmos_map" -- custom map included in file
       
    88 	Theme = "Nature"
       
    89 	-- I had originally hero in PAoTH team and changed it, may reconsider though
       
    90 	-- PAoTH
       
    91 	AddTeam(teamC.name, teamC.color, "Bone", "Island", "HillBilly", "cm_birdy")	
       
    92 	hero.gear = AddHog(hero.name, 0, 100, "war_desertgrenadier1")
       
    93 	AnimSetGearPosition(hero.gear, hero.x, hero.y)	
       
    94 	HogTurnLeft(hero.gear, true)
       
    95 	AddTeam(teamA.name, teamA.color, "Bone", "Island", "HillBilly", "cm_birdy")	
       
    96 	director.gear = AddHog(director.name, 0, 100, "hair_yellow")
       
    97 	AnimSetGearPosition(director.gear, director.x, director.y)
       
    98 	doctor.gear = AddHog(doctor.name, 0, 100, "Glasses")
       
    99 	AnimSetGearPosition(doctor.gear, doctor.x, doctor.y)
       
   100 	-- Guards
       
   101 	AddTeam(teamB.name, teamB.color, "Bone", "Island", "HillBilly", "cm_birdy")
       
   102 	guard1.gear = AddHog(guard1.name, 1, 100, "policecap")
       
   103 	AnimSetGearPosition(guard1.gear, guard1.x, guard1.y)
       
   104 	guard2.gear = AddHog(guard2.name, 1, 100, "policecap")
       
   105 	AnimSetGearPosition(guard2.gear, guard2.x, guard2.y)
       
   106 	
       
   107 	-- get the check point
       
   108 	if tonumber(GetCampaignVar("CosmosCheckPoint")) then
       
   109 		checkPointReached = tonumber(GetCampaignVar("CosmosCheckPoint"))
       
   110 	end
       
   111 	-- do checkpoint stuff needed before game starts
       
   112 	if checkPointReached == 1 then
       
   113 		-- Start of the game
       
   114 	elseif checkPointReached == 2 then
       
   115 		-- Hero on the column, just took space ship unnoticed
       
   116 		AnimSetGearPosition(hero.gear, saucerX, saucerY)
       
   117 	elseif checkPointReached == 3 then
       
   118 		-- Hero near column, without space ship unnoticed
       
   119 	elseif checkPointReached == 4 then
       
   120 		-- Hero visited moon for fuels
       
   121 		AnimSetGearPosition(hero.gear, 1110, 850)
       
   122 	elseif checkPointReached == 5 then
       
   123 		-- Hero has visited a planet, he has plenty of fuels and can change planet
       
   124 	end
       
   125 	
       
   126 	AnimInit()
       
   127 	AnimationSetup()
       
   128 end
       
   129 
       
   130 function onGameStart()
       
   131 	-- wait for the first turn to start
       
   132 	AnimWait(hero.gear, 3000)
       
   133 
       
   134 	FollowGear(hero.gear)
       
   135 	ShowMission(loc("A Space Adventure"), loc("Cosmos"), loc("Help Hog Solo to find all the parts of the anti-gravity device.")..
       
   136 	"|"..loc("Travel to all the neighbor planets and collect all the pieces"), -amSkip, 0)
       
   137 	
       
   138 	-- do checkpoint stuff needed after game starts
       
   139 	if checkPointReached == 1 then	
       
   140 		AddAnim(dialog01)
       
   141 		AddAmmo(hero.gear, amGasBomb, 5)
       
   142 		AddAmmo(hero.gear, amRope, 2)
       
   143 		-- Added for dev/debug purposes, remove before release
       
   144 		AddAmmo(hero.gear, amJetpack, 2)
       
   145 		AddAmmo(guard1.gear, amDEagle, 2)
       
   146 		AddAmmo(guard2.gear, amDEagle, 2)
       
   147 		SpawnAmmoCrate(saucerX, saucerY, amJetpack)	
       
   148 		-- EVENT HANDLERS
       
   149 		AddEvent(onHeroBeforeTreePosition, {hero.gear}, heroBeforeTreePosition, {hero.gear}, 0)
       
   150 		AddEvent(onHeroAtSaucerPosition, {hero.gear}, heroAtSaucerPosition, {hero.gear}, 0)
       
   151 		AddEvent(onHeroOutOfGuardSight, {hero.gear}, heroOutOfGuardSight, {hero.gear}, 0)
       
   152 	elseif checkPointReached == 2 then
       
   153 		AddAmmo(hero.gear, amJetpack, 1)
       
   154 		AddAnim(dialog02)
       
   155 	elseif checkPointReached == 3 then
       
   156 		-- Hero near column, without space ship unnoticed
       
   157 	elseif checkPointReached == 4 then
       
   158 		-- Hero visited moon for fuels
       
   159 		AddAnim(dialog05)
       
   160 	elseif checkPointReached == 5 then
       
   161 		-- Hero has visited a planet, he has plenty of fuels and can change planet
       
   162 	end
       
   163 	-- always check for landings
       
   164 	if GetCampaignVar("Planet") ~= "moon" then
       
   165 		AddEvent(onMoonLanding, {hero.gear}, moonLanding, {hero.gear}, 0)
       
   166 	end
       
   167 	if GetCampaignVar("Planet") ~= "desertPlanet" then
       
   168 		AddEvent(onDesertPlanetLanding, {hero.gear}, desertPlanetLanding, {hero.gear}, 0)
       
   169 	end	
       
   170 	if GetCampaignVar("Planet") ~= "fruitPlanet" then
       
   171 		AddEvent(onFruitPlanetLanding, {hero.gear}, fruitPlanetLanding, {hero.gear}, 0)
       
   172 	end
       
   173 	if GetCampaignVar("Planet") ~= "icePlanet" then
       
   174 		AddEvent(onIcePlanetLanding, {hero.gear}, icePlanetLanding, {hero.gear}, 0)
       
   175 	end
       
   176 end
       
   177 
       
   178 function onGameTick()
       
   179 	-- maybe alert this to avoid timeForGuard1ToTurnLeft overflow
       
   180 	if timeForGuard1ToTurnLeft == 0 and guard1.keepTurning then
       
   181 		guard1.turn = not guard1.turn
       
   182 		HogTurnLeft(guard1.gear, guard1.turn)
       
   183 		timeForGuard1ToTurnLeft = timeForGuard1ToTurn
       
   184 	end
       
   185 	timeForGuard1ToTurnLeft = timeForGuard1ToTurnLeft - 1
       
   186 	AnimUnWait()
       
   187 	if ShowAnimation() == false then
       
   188 		return
       
   189 	end
       
   190 	ExecuteAfterAnimations()
       
   191 	CheckEvents()
       
   192 end
       
   193 
       
   194 function onPrecise()
       
   195 	if GameTime > 3000 then
       
   196 		SetAnimSkip(true)   
       
   197 	end
       
   198 end
       
   199 
       
   200 function onAmmoStoreInit()
       
   201 	SetAmmo(amJetpack, 0, 0, 0, 1)
       
   202 end
       
   203 
       
   204 function onNewTurn()
       
   205 	if CurrentHedgehog == director.gear or CurrentHedgehog == doctor.gear then
       
   206 		TurnTimeLeft = 0
       
   207 	end
       
   208 	if guard1.keepTurning then
       
   209 		AnimSwitchHog(hero.gear)
       
   210 		TurnTimeLeft = -1
       
   211 	end
       
   212 end
       
   213 
       
   214 -------------- EVENTS ------------------
       
   215 
       
   216 function onHeroBeforeTreePosition(gear)
       
   217 	if GetX(gear) > 2444 then
       
   218 		return true
       
   219 	end
       
   220 	return false
       
   221 end
       
   222 
       
   223 function onHeroAtSaucerPosition(gear)
       
   224 	if GetX(gear) >= saucerX-32 and GetX(gear) <= saucerX+32 and GetY(gear) >= saucerY-32 and GetY(gear) <= saucerY+32 then
       
   225 		saucerAcquired = true
       
   226 	end
       
   227 	if saucerAcquired and StoppedGear(gear) then
       
   228 		return true
       
   229 	end
       
   230 	return false
       
   231 end
       
   232 
       
   233 function onHeroOutOfGuardSight(gear)
       
   234 	if GetX(gear) < 3100 and GetY(gear) > saucerY-25 and StoppedGear(gear) and not guard1.keepTurning then
       
   235 		return true
       
   236 	end
       
   237 	return false
       
   238 end
       
   239 --
       
   240 function onMoonLanding(gear)
       
   241 	if GetX(gear) > 1010 and GetX(gear) < 1220  and GetY(gear) < 1300 and StoppedGear(gear) then
       
   242 		return true
       
   243 	end
       
   244 	return false
       
   245 end
       
   246 
       
   247 function onFruitPlanetLanding(gear)
       
   248 	if GetX(gear) > 2240 and GetX(gear) < 2540  and GetY(gear) < 1100 and StoppedGear(gear) then
       
   249 		return true
       
   250 	end
       
   251 	return false
       
   252 end
       
   253 
       
   254 function onDesertPlanetLanding(gear)
       
   255 	if GetX(gear) > 3568 and GetX(gear) < 4052  and GetY(gear) < 500 and StoppedGear(gear) then
       
   256 		return true
       
   257 	end
       
   258 	return false
       
   259 end
       
   260 
       
   261 function onIcePlanetLanding(gear)
       
   262 	if GetX(gear) > 1330 and GetX(gear) < 1650  and GetY(gear) < 500 and StoppedGear(gear) then
       
   263 		return true
       
   264 	end
       
   265 	return false
       
   266 end
       
   267 
       
   268 -------------- OUTCOMES ------------------
       
   269 
       
   270 function heroBeforeTreePosition(gear)
       
   271 	AnimSay(gear,loc("Now I have to climb the trees"), SAY_SAY, 4000)
       
   272 	AnimCaption(hero.gear, loc("Use the rope to get to the crate"),  4000)
       
   273 end
       
   274 
       
   275 function heroAtSaucerPosition(gear)
       
   276 	TurnTimeLeft = 0
       
   277 	-- save check point	
       
   278 	SaveCampaignVar("CosmosCheckPoint", "2")
       
   279 	AddAnim(dialog02)
       
   280 	-- check if he was spotted by the guard
       
   281 	if guard1.turn then
       
   282 		guard1.keepTurning = false
       
   283 		AddAnim(dialog03)
       
   284 	end	
       
   285 end
       
   286 
       
   287 function heroOutOfGuardSight(gear)
       
   288 	guard1.keepTurning = true
       
   289 	AddAnim(dialog04)
       
   290 end
       
   291 
       
   292 function moonLanding(gear)
       
   293 	WriteLnToConsole("MOON LANDING, HOORAY!")
       
   294 	AnimCaption(hero.gear,loc("Welcome to the moon!"))
       
   295 	SaveCampaignVar("CosmosCheckPoint", "4")
       
   296 	SaveCampaignVar("Planet", "moon")
       
   297 	EndGame()
       
   298 end
       
   299 
       
   300 function fruitPlanetLanding(gear)
       
   301 	if checkPointReached < 5 then
       
   302 		AddAnim(dialog06)
       
   303 	end
       
   304 end
       
   305 
       
   306 function desertPlanetLanding(gear)
       
   307 	if checkPointReached < 5 then
       
   308 		AddAnim(dialog06)
       
   309 	end
       
   310 end
       
   311 
       
   312 function icePlanetLanding(gear)
       
   313 	if checkPointReached < 5 then
       
   314 		AddAnim(dialog06)
       
   315 	end
       
   316 end
       
   317 
       
   318 -------------- ANIMATIONS ------------------
       
   319 
       
   320 function Skipanim(anim)
       
   321 	if goals[anim] ~= nil then
       
   322 		ShowMission(unpack(goals[anim]))
       
   323     end
       
   324     if CurrentHedgehog ~= hero.gear and anim ~= dialog03 then
       
   325 		AnimSwitchHog(hero.gear)
       
   326 	elseif anim == dialog03 then
       
   327 		startCombat()
       
   328 	elseif anim == dialog05 or anim == dialog06 then
       
   329 		EndGame()
       
   330 	end
       
   331 end
       
   332 
       
   333 function AnimationSetup()
       
   334 	-- DIALOG 01 - Start
       
   335 	AddSkipFunction(dialog01, Skipanim, {dialog01})
       
   336 	table.insert(dialog01, {func = AnimWait, args = {doctor.gear, 3000}})
       
   337 	--table.insert(dialog01, {func = AnimWait, args = {hero.gear, 2500}, skipFunc = Skipanim, skipArgs = dialog01})
       
   338 	table.insert(dialog01, {func = AnimCaption, args = {hero.gear, loc("Near secret base 17 of PAoTH in the rural Hogland..."),  4000}})
       
   339 	table.insert(dialog01, {func = AnimSay, args = {director.gear, loc("So Hog Solo, here we are..."), SAY_SAY, 2000}})
       
   340 	table.insert(dialog01, {func = AnimSay, args = {director.gear, loc("Behind these trees on the East there is secret base 17"), SAY_SAY, 4000}})
       
   341 	table.insert(dialog01, {func = AnimSay, args = {director.gear, loc("You have to continue alone from now on."), SAY_SAY, 3000}})
       
   342 	table.insert(dialog01, {func = AnimSay, args = {director.gear, loc("Be careful, the future of Hogera is in your hands!"), SAY_SAY, 7200}})
       
   343 	table.insert(dialog01, {func = AnimSay, args = {doctor.gear, loc("We'll use our communicators to contact you"), SAY_SAY, 2600}})
       
   344 	table.insert(dialog01, {func = AnimSay, args = {doctor.gear, loc("In am also entrusting you with a rope and a sleep gas bomb"), SAY_SAY, 5000}})
       
   345 	table.insert(dialog01, {func = AnimSay, args = {doctor.gear, loc("You may find them handy"), SAY_SAY, 2300}})
       
   346 	table.insert(dialog01, {func = AnimSay, args = {hero.gear, loc("Thank you Dr.Cornelius"), SAY_SAY, 1600}})
       
   347 	table.insert(dialog01, {func = AnimSay, args = {hero.gear, loc("I'll make good use of them"), SAY_SAY, 4500}})
       
   348 	table.insert(dialog01, {func = AnimSay, args = {director.gear, loc("It would be wiser to steal the space ship while PAoTH guards are taking a brake!"), SAY_SAY, 7000}})
       
   349 	table.insert(dialog01, {func = AnimSay, args = {director.gear, loc("Remember! Many will seek the anti-gravity device! Now go, hurry up!"), SAY_SAY, 4000}})
       
   350 	table.insert(dialog01, {func = AnimSwitchHog, args = {hero.gear}})
       
   351 	-- DIALOG 02 - Hero got the saucer
       
   352 	AddSkipFunction(dialog02, Skipanim, {dialog02})
       
   353 	table.insert(dialog02, {func = AnimWait, args = {hero.gear, 500}})
       
   354 	table.insert(dialog02, {func = AnimCaption, args = {hero.gear, loc("CheckPoint reached!"),  4000}})
       
   355 	table.insert(dialog02, {func = AnimSay, args = {hero.gear, loc("Got the saucer!"), SAY_SHOUT, 2000}})
       
   356 	table.insert(dialog02, {func = AnimSay, args = {director.gear, loc("Nice!"), SAY_SHOUT, 1000}})
       
   357 	table.insert(dialog02, {func = AnimSay, args = {director.gear, loc("Now use it and go to the moon PAoTH station to get more fuels!"), SAY_SHOUT, 5000}})
       
   358     table.insert(dialog02, {func = AnimGearWait, args = {hero.gear, 500}})
       
   359     -- DIALOG 03 - Hero got spotted by guard
       
   360 	AddSkipFunction(dialog03, Skipanim, {dialog03})
       
   361 	table.insert(dialog03, {func = AnimWait, args = {guard1.gear, 4000}})
       
   362 	table.insert(dialog03, {func = AnimCaption, args = {guard1.gear, loc("Prepare to battle or flee!"),  4000}})	
       
   363 	table.insert(dialog03, {func = AnimSay, args = {guard1.gear, loc("Hey").." "..guard2.name.."! "..loc("Look, someone is stealing the saucer!"), SAY_SHOUT, 4000}})
       
   364 	table.insert(dialog03, {func = AnimSay, args = {guard2.gear, loc("I'll get him!"), SAY_SAY, 4000}})
       
   365 	table.insert(dialog03, {func = startCombat, args = {guard1.gear}})
       
   366 	-- DIALOG 04 - Hero out of sight
       
   367 	AddSkipFunction(dialog04, Skipanim, {dialog04})
       
   368 	table.insert(dialog04, {func = AnimCaption, args = {guard1.gear, loc("You are out of danger, time to go to the moon!"),  4000}})
       
   369 	table.insert(dialog04, {func = AnimSay, args = {guard1.gear, loc("I guess we lost him!"), SAY_SAY, 3000}})
       
   370 	table.insert(dialog04, {func = AnimSay, args = {guard2.gear, loc("We should better report this and continue our watch!"), SAY_SAY, 5000}})
       
   371 	table.insert(dialog04, {func = AnimSwitchHog, args = {hero.gear}})
       
   372 	-- DIALOG 05 - Hero returned from moon without fuels
       
   373 	AddSkipFunction(dialog05, Skipanim, {dialog05})
       
   374 	table.insert(dialog05, {func = AnimSay, args = {hero.gear, loc("I guess I can't go far without fuels!"), SAY_THINK, 6000}})
       
   375 	table.insert(dialog05, {func = AnimSay, args = {hero.gear, loc("Go to go back"), SAY_THINK, 2000}})
       
   376 	table.insert(dialog05, {func = EndGame, args = {hero.gear}})
       
   377 	-- DIALOG 06 - Landing on wrong planet or on earth if not enough fuels
       
   378 	AddSkipFunction(dialog06, Skipanim, {dialog06})
       
   379 	table.insert(dialog06, {func = AnimCaption, args = {hero.gear, loc("You have to try again!"),  5000}})
       
   380 	table.insert(dialog06, {func = AnimSay, args = {hero.gear, loc("Hm... Now I run out of fuels..."), SAY_THINK, 3000}})
       
   381 	table.insert(dialog06, {func = EndGame, args = {hero.gear}})
       
   382 end
       
   383 
       
   384 ------------------- custom "animation" functions --------------------------
       
   385 
       
   386 function startCombat()
       
   387 	-- use this so guard2 will gain control
       
   388 	AnimSwitchHog(hero.gear)
       
   389 	TurnTimeLeft = 0
       
   390 end