share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death02.lua
branchspacecampaign
changeset 9601 6af4ca27421a
child 9602 a8ed4853963e
equal deleted inserted replaced
9600:7daf157d8b52 9601:6af4ca27421a
       
     1 ------------------- ABOUT ----------------------
       
     2 --
       
     3 -- Hero has been surrounded my some space villains
       
     4 -- He has to defeat them in order to escape
       
     5 
       
     6 HedgewarsScriptLoad("/Scripts/Locale.lua")
       
     7 HedgewarsScriptLoad("/Scripts/Animate.lua")
       
     8 HedgewarsScriptLoad("/Missions/Campaign/A_Space_Adventure/global_functions.lua")
       
     9 
       
    10 ----------------- VARIABLES --------------------
       
    11 -- globals
       
    12 local missionName = loc("Killing the specialists")
       
    13 local challengeObjectives = loc("Use your available weapons in order to eliminate the enemies").."|"..
       
    14 	loc("Each time you play this missions enemy hogs will have a random playing order").."|"..
       
    15 	loc("Each enemy hog can use only the weapon that he is named of").."|"..
       
    16 	loc("If you kill a hog with the weapon that he uses your hp will be 100").."|"..
       
    17 	loc("If you kill a hog with another weapon you'll get 35% of the damaged dealt").."|"..
       
    18 	loc("Every time you kill an enemy hog your ammo will get reseted").."|"..
       
    19 	loc("Rope won't get reseted")
       
    20 -- hogs
       
    21 local hero = {
       
    22 	name = loc("Hog Solo"),
       
    23 	x = 850,
       
    24 	y = 460,
       
    25 	mortarAmmo = 2,
       
    26 	firepunchAmmo = 1,
       
    27 	deagleAmmo = 4,
       
    28 	bazookaAmmo = 2,
       
    29 	grenadeAmmo = 4,
       
    30 }
       
    31 local enemies = {
       
    32 	{ name = loc("Mortar"), x = 1890, y = 520, weapon = amMortar, additionalWeapons = {}},
       
    33 	{ name = loc("Desert Eagle"), x = 1390, y = 790, weapon = amDEagle, additionalWeapons = {}},
       
    34 	{ name = loc("Grenade"), x = 186, y = 48, weapon = amGrenade, additionalWeapons = {}},
       
    35 	{ name = loc("Shyryuken"), x = 330, y = 270, weapon = amFirePunch, additionalWeapons = {}},
       
    36 	{ name = loc("Bazooka"), x = 1950, y = 150, weapon = amBazooka, additionalWeapons = {}},
       
    37 }
       
    38 -- teams
       
    39 local teamA = {
       
    40 	name = loc("Hog Solo"),
       
    41 	color = tonumber("38D61C",16) -- green
       
    42 }
       
    43 local teamB = {
       
    44 	name = loc("5 deadly hogs"),
       
    45 	color = tonumber("FF0000",16) -- red
       
    46 }
       
    47 
       
    48 -------------- LuaAPI EVENT HANDLERS ------------------
       
    49 
       
    50 function onGameInit()
       
    51 	Seed = 1
       
    52 	TurnTime = 25000
       
    53 	CaseFreq = 0
       
    54 	MinesNum = 0
       
    55 	MinesTime = 1
       
    56 	Explosives = 0
       
    57 	Map = "death02_map"
       
    58 	Theme = "Hell"
       
    59 	
       
    60 	-- Hog Solo
       
    61 	AddTeam(teamA.name, teamA.color, "Bone", "Island", "HillBilly", "cm_birdy")
       
    62 	hero.gear = AddHog(hero.name, 0, 100, "war_desertgrenadier1")
       
    63 	AnimSetGearPosition(hero.gear, hero.x, hero.y)
       
    64 	-- enemies
       
    65 	shuffleHogs(enemies)
       
    66 	AddTeam(teamB.name, teamB.color, "Bone", "Island", "HillBilly", "cm_birdy")
       
    67 	for i=1,table.getn(enemies) do
       
    68 		enemies[i].gear = AddHog(enemies[i].name, 1, 100, "war_desertgrenadier1")
       
    69 		AnimSetGearPosition(enemies[i].gear, enemies[i].x, enemies[i].y)
       
    70 	end
       
    71 	
       
    72 	initCheckpoint("death02")
       
    73 	
       
    74 	AnimInit()
       
    75 	--AnimationSetup()
       
    76 end
       
    77 
       
    78 function onGameStart()
       
    79 	AnimWait(hero.gear, 3000)
       
    80 	FollowGear(hero.gear)
       
    81 	ShowMission(missionName, loc("Challenge Objectives"), challengeObjectives, -amSkip, 0)
       
    82 	
       
    83 	AddEvent(onHeroDeath, {hero.gear}, heroDeath, {hero.gear}, 0)
       
    84 	AddEvent(onHeroWin, {hero.gear}, heroWin, {hero.gear}, 0)
       
    85 
       
    86 	--hero ammo
       
    87 	AddAmmo(hero.gear, amSkip, 100)
       
    88 	AddAmmo(hero.gear, amRope, 2)
       
    89 	refreshHeroAmmo()
       
    90 
       
    91 	SendHealthStatsOff()
       
    92 end
       
    93 
       
    94 function onNewTurn()
       
    95 	if CurrentHedgehog ~= hero.gear then
       
    96 		enemyWeapons()
       
    97 	end
       
    98 end
       
    99 
       
   100 function onGearDelete(gear)
       
   101 	if isHog(gear) then
       
   102 		SetHealth(hero.gear, 100)
       
   103 		local deadHog = getHog(gear)
       
   104 		if deadHog.weapon == amDynamite then
       
   105 			hero.dynamiteAmmo = 0
       
   106 		elseif deadHog.weapon == amFirePunch then
       
   107 			hero.firepunchAmmo = 0
       
   108 		elseif deadHog.weapon == amDEagle then
       
   109 			hero.deagleAmmo = 0
       
   110 		elseif deadHog.weapon == amBazooka then
       
   111 			hero.bazookaAmmo = 0
       
   112 		elseif deadHog.weapon == amGrenade then
       
   113 			hero.grenadeAmmo = 0
       
   114 		end		
       
   115 		local randomHog = math.random(1,table.getn(enemies))
       
   116 		while not GetHealth(enemies[randomHog].gear) do
       
   117 			randomHog = math.random(1,table.getn(enemies))
       
   118 		end
       
   119 		table.insert(enemies[randomHog].additionalWeapons, deadHog.weapon)
       
   120 		for i=1,table.getn(deadHog.additionalWeapons) do
       
   121 			table.insert(enemies[randomHog].additionalWeapons, deadHog.additionalWeapons[i])
       
   122 		end
       
   123 		refreshHeroAmmo()
       
   124 	end
       
   125 end
       
   126 
       
   127 function onGearDamage(gear, damage)
       
   128 	if isHog(gear) and GetHealth(hero.gear) then
       
   129 		SetHealth(hero.gear, GetHealth(hero.gear) + damage/3)
       
   130 	end
       
   131 end
       
   132 
       
   133 function onGameTick()
       
   134 	AnimUnWait()
       
   135 	if ShowAnimation() == false then
       
   136 		return
       
   137 	end
       
   138 	ExecuteAfterAnimations()
       
   139 	CheckEvents()
       
   140 end
       
   141 
       
   142 function onPrecise()
       
   143 	if GameTime > 3000 then
       
   144 		SetAnimSkip(true)   
       
   145 	end
       
   146 end
       
   147 
       
   148 -------------- EVENTS ------------------
       
   149 
       
   150 function onHeroDeath(gear)
       
   151 	if not GetHealth(hero.gear) then
       
   152 		return true
       
   153 	end
       
   154 	return false
       
   155 end
       
   156 
       
   157 function onHeroWin(gear)
       
   158 	local allDead = true
       
   159 	for i=1,table.getn(enemies) do
       
   160 		if GetHealth(enemies[i].gear) then
       
   161 			allDead = false
       
   162 			break
       
   163 		end
       
   164 	end
       
   165 	return allDead
       
   166 end
       
   167 
       
   168 -------------- ACTIONS ------------------
       
   169 
       
   170 function heroDeath(gear)
       
   171 	SendStat('siGameResult', loc("Hog Solo lost, try again!")) --1
       
   172 	SendStat('siCustomAchievement', loc("You have to eliminate all the enemies")) --11			
       
   173 	SendStat('siCustomAchievement', loc("Read the Challenge Objectives from within the mission for more details")) --11		
       
   174 	SendStat('siPlayerKills','1',teamB.name)
       
   175 	SendStat('siPlayerKills','0',teamA.name)
       
   176 	EndGame()
       
   177 end
       
   178 
       
   179 function heroWin(gear)
       
   180 	SendStat('siGameResult', loc("Congratulations, you won!")) --1
       
   181 	SendStat('siCustomAchievement', loc("You complete the mission in "..TotalRounds.." rounds")) --11			
       
   182 	-- TODO SendStat('siCustomAchievement', loc("You have gained some extra life")) --11		
       
   183 	SendStat('siPlayerKills','1',teamA.name)
       
   184 	EndGame()
       
   185 end
       
   186 
       
   187 ------------ Other Functions -------------------
       
   188 
       
   189 function shuffleHogs(hogs)
       
   190     local hogsNumber = table.getn(hogs)
       
   191     for i=1,hogsNumber do
       
   192 		local randomHog = math.random(hogsNumber)
       
   193 		hogs[i], hogs[randomHog] = hogs[randomHog], hogs[i]
       
   194     end
       
   195 end
       
   196 
       
   197 function refreshHeroAmmo()
       
   198 	local extraAmmo = 0
       
   199 	if getAliveEnemiesCount() == 1 then
       
   200 		extraAmmo = 2
       
   201 	end
       
   202 	AddAmmo(hero.gear, amMortar, hero.mortarAmmo + extraAmmo)
       
   203 	AddAmmo(hero.gear, amFirePunch, hero.firepunchAmmo + extraAmmo)
       
   204 	AddAmmo(hero.gear, amDEagle, hero.deagleAmmo + extraAmmo)
       
   205 	AddAmmo(hero.gear, amBazooka, hero.bazookaAmmo + extraAmmo)
       
   206 	AddAmmo(hero.gear, amGrenade, hero.grenadeAmmo + extraAmmo)
       
   207 end
       
   208 
       
   209 function enemyWeapons()
       
   210 	for i=1,table.getn(enemies) do
       
   211 		if GetHealth(enemies[i].gear) and enemies[i].gear == CurrentHedgehog then
       
   212 			AddAmmo(enemies[i].gear, amMortar, 0)
       
   213 			AddAmmo(enemies[i].gear, amFirePunch, 0)
       
   214 			AddAmmo(enemies[i].gear, amDEagle, 0)
       
   215 			AddAmmo(enemies[i].gear, amBazooka, 0)
       
   216 			AddAmmo(enemies[i].gear, amGrenade, 0)
       
   217 			AddAmmo(enemies[i].gear, enemies[i].weapon, 1)
       
   218 			for w=1,table.getn(enemies[i].additionalWeapons) do
       
   219 				AddAmmo(enemies[i].gear, enemies[i].additionalWeapons[w], 1)
       
   220 			end
       
   221 		end
       
   222 	end
       
   223 end
       
   224 
       
   225 function isHog(gear)
       
   226 	local hog = false
       
   227 	for i=1,table.getn(enemies) do
       
   228 		if gear == enemies[i].gear then
       
   229 			hog = true
       
   230 			break
       
   231 		end
       
   232 	end
       
   233 	return hog
       
   234 end
       
   235 
       
   236 function getHog(gear)
       
   237 	for i=1,table.getn(enemies) do
       
   238 		if gear == enemies[i].gear then
       
   239 			return enemies[i]
       
   240 		end
       
   241 	end
       
   242 end
       
   243 
       
   244 function getAliveEnemiesCount()
       
   245 	local count = 0
       
   246 	for i=1,table.getn(enemies) do
       
   247 		if GetHealth(enemies[i].gear) then
       
   248 			count = count + 1
       
   249 		end
       
   250 	end
       
   251 	return count
       
   252 end