added death planet side mission spacecampaign
authorPeriklis Ntanasis <pntanasis@gmail.com>
Tue, 03 Sep 2013 04:01:19 +0300
branchspacecampaign
changeset 9601 6af4ca27421a
parent 9600 7daf157d8b52
child 9602 a8ed4853963e
added death planet side mission
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/campaign.ini
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/cosmos.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death02.hwp
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death02.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit03.lua
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/campaign.ini	Mon Sep 02 18:57:30 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/campaign.ini	Tue Sep 03 04:01:19 2013 +0300
@@ -40,3 +40,7 @@
 [Mission 10]
 Name=Side Mission: Precise shooting
 Script=fruit03.lua
+
+[Mission 11]
+Name=Side Mission: Killing the specialists
+Script=death02.lua
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/cosmos.lua	Mon Sep 02 18:57:30 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/cosmos.lua	Tue Sep 03 04:01:19 2013 +0300
@@ -414,9 +414,10 @@
 	else
 		AnimCaption(hero.gear,loc("Welcome to the Death Planet!"))
 		SaveCampaignVar("Planet", "deathPlanet")
-		SaveCampaignVar("UnlockedMissions", "2")
+		SaveCampaignVar("UnlockedMissions", "3")
 		SaveCampaignVar("Mission1", "9")
-		SaveCampaignVar("Mission2", "1")
+		SaveCampaignVar("Mission2", "11")
+		SaveCampaignVar("Mission3", "1")
 		sendStats(loc("the Planet of Death"))
 	end
 end
Binary file share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death02.hwp has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death02.lua	Tue Sep 03 04:01:19 2013 +0300
@@ -0,0 +1,252 @@
+------------------- ABOUT ----------------------
+--
+-- Hero has been surrounded my some space villains
+-- He has to defeat them in order to escape
+
+HedgewarsScriptLoad("/Scripts/Locale.lua")
+HedgewarsScriptLoad("/Scripts/Animate.lua")
+HedgewarsScriptLoad("/Missions/Campaign/A_Space_Adventure/global_functions.lua")
+
+----------------- VARIABLES --------------------
+-- globals
+local missionName = loc("Killing the specialists")
+local challengeObjectives = loc("Use your available weapons in order to eliminate the enemies").."|"..
+	loc("Each time you play this missions enemy hogs will have a random playing order").."|"..
+	loc("Each enemy hog can use only the weapon that he is named of").."|"..
+	loc("If you kill a hog with the weapon that he uses your hp will be 100").."|"..
+	loc("If you kill a hog with another weapon you'll get 35% of the damaged dealt").."|"..
+	loc("Every time you kill an enemy hog your ammo will get reseted").."|"..
+	loc("Rope won't get reseted")
+-- hogs
+local hero = {
+	name = loc("Hog Solo"),
+	x = 850,
+	y = 460,
+	mortarAmmo = 2,
+	firepunchAmmo = 1,
+	deagleAmmo = 4,
+	bazookaAmmo = 2,
+	grenadeAmmo = 4,
+}
+local enemies = {
+	{ name = loc("Mortar"), x = 1890, y = 520, weapon = amMortar, additionalWeapons = {}},
+	{ name = loc("Desert Eagle"), x = 1390, y = 790, weapon = amDEagle, additionalWeapons = {}},
+	{ name = loc("Grenade"), x = 186, y = 48, weapon = amGrenade, additionalWeapons = {}},
+	{ name = loc("Shyryuken"), x = 330, y = 270, weapon = amFirePunch, additionalWeapons = {}},
+	{ name = loc("Bazooka"), x = 1950, y = 150, weapon = amBazooka, additionalWeapons = {}},
+}
+-- teams
+local teamA = {
+	name = loc("Hog Solo"),
+	color = tonumber("38D61C",16) -- green
+}
+local teamB = {
+	name = loc("5 deadly hogs"),
+	color = tonumber("FF0000",16) -- red
+}
+
+-------------- LuaAPI EVENT HANDLERS ------------------
+
+function onGameInit()
+	Seed = 1
+	TurnTime = 25000
+	CaseFreq = 0
+	MinesNum = 0
+	MinesTime = 1
+	Explosives = 0
+	Map = "death02_map"
+	Theme = "Hell"
+	
+	-- Hog Solo
+	AddTeam(teamA.name, teamA.color, "Bone", "Island", "HillBilly", "cm_birdy")
+	hero.gear = AddHog(hero.name, 0, 100, "war_desertgrenadier1")
+	AnimSetGearPosition(hero.gear, hero.x, hero.y)
+	-- enemies
+	shuffleHogs(enemies)
+	AddTeam(teamB.name, teamB.color, "Bone", "Island", "HillBilly", "cm_birdy")
+	for i=1,table.getn(enemies) do
+		enemies[i].gear = AddHog(enemies[i].name, 1, 100, "war_desertgrenadier1")
+		AnimSetGearPosition(enemies[i].gear, enemies[i].x, enemies[i].y)
+	end
+	
+	initCheckpoint("death02")
+	
+	AnimInit()
+	--AnimationSetup()
+end
+
+function onGameStart()
+	AnimWait(hero.gear, 3000)
+	FollowGear(hero.gear)
+	ShowMission(missionName, loc("Challenge Objectives"), challengeObjectives, -amSkip, 0)
+	
+	AddEvent(onHeroDeath, {hero.gear}, heroDeath, {hero.gear}, 0)
+	AddEvent(onHeroWin, {hero.gear}, heroWin, {hero.gear}, 0)
+
+	--hero ammo
+	AddAmmo(hero.gear, amSkip, 100)
+	AddAmmo(hero.gear, amRope, 2)
+	refreshHeroAmmo()
+
+	SendHealthStatsOff()
+end
+
+function onNewTurn()
+	if CurrentHedgehog ~= hero.gear then
+		enemyWeapons()
+	end
+end
+
+function onGearDelete(gear)
+	if isHog(gear) then
+		SetHealth(hero.gear, 100)
+		local deadHog = getHog(gear)
+		if deadHog.weapon == amDynamite then
+			hero.dynamiteAmmo = 0
+		elseif deadHog.weapon == amFirePunch then
+			hero.firepunchAmmo = 0
+		elseif deadHog.weapon == amDEagle then
+			hero.deagleAmmo = 0
+		elseif deadHog.weapon == amBazooka then
+			hero.bazookaAmmo = 0
+		elseif deadHog.weapon == amGrenade then
+			hero.grenadeAmmo = 0
+		end		
+		local randomHog = math.random(1,table.getn(enemies))
+		while not GetHealth(enemies[randomHog].gear) do
+			randomHog = math.random(1,table.getn(enemies))
+		end
+		table.insert(enemies[randomHog].additionalWeapons, deadHog.weapon)
+		for i=1,table.getn(deadHog.additionalWeapons) do
+			table.insert(enemies[randomHog].additionalWeapons, deadHog.additionalWeapons[i])
+		end
+		refreshHeroAmmo()
+	end
+end
+
+function onGearDamage(gear, damage)
+	if isHog(gear) and GetHealth(hero.gear) then
+		SetHealth(hero.gear, GetHealth(hero.gear) + damage/3)
+	end
+end
+
+function onGameTick()
+	AnimUnWait()
+	if ShowAnimation() == false then
+		return
+	end
+	ExecuteAfterAnimations()
+	CheckEvents()
+end
+
+function onPrecise()
+	if GameTime > 3000 then
+		SetAnimSkip(true)   
+	end
+end
+
+-------------- EVENTS ------------------
+
+function onHeroDeath(gear)
+	if not GetHealth(hero.gear) then
+		return true
+	end
+	return false
+end
+
+function onHeroWin(gear)
+	local allDead = true
+	for i=1,table.getn(enemies) do
+		if GetHealth(enemies[i].gear) then
+			allDead = false
+			break
+		end
+	end
+	return allDead
+end
+
+-------------- ACTIONS ------------------
+
+function heroDeath(gear)
+	SendStat('siGameResult', loc("Hog Solo lost, try again!")) --1
+	SendStat('siCustomAchievement', loc("You have to eliminate all the enemies")) --11			
+	SendStat('siCustomAchievement', loc("Read the Challenge Objectives from within the mission for more details")) --11		
+	SendStat('siPlayerKills','1',teamB.name)
+	SendStat('siPlayerKills','0',teamA.name)
+	EndGame()
+end
+
+function heroWin(gear)
+	SendStat('siGameResult', loc("Congratulations, you won!")) --1
+	SendStat('siCustomAchievement', loc("You complete the mission in "..TotalRounds.." rounds")) --11			
+	-- TODO SendStat('siCustomAchievement', loc("You have gained some extra life")) --11		
+	SendStat('siPlayerKills','1',teamA.name)
+	EndGame()
+end
+
+------------ Other Functions -------------------
+
+function shuffleHogs(hogs)
+    local hogsNumber = table.getn(hogs)
+    for i=1,hogsNumber do
+		local randomHog = math.random(hogsNumber)
+		hogs[i], hogs[randomHog] = hogs[randomHog], hogs[i]
+    end
+end
+
+function refreshHeroAmmo()
+	local extraAmmo = 0
+	if getAliveEnemiesCount() == 1 then
+		extraAmmo = 2
+	end
+	AddAmmo(hero.gear, amMortar, hero.mortarAmmo + extraAmmo)
+	AddAmmo(hero.gear, amFirePunch, hero.firepunchAmmo + extraAmmo)
+	AddAmmo(hero.gear, amDEagle, hero.deagleAmmo + extraAmmo)
+	AddAmmo(hero.gear, amBazooka, hero.bazookaAmmo + extraAmmo)
+	AddAmmo(hero.gear, amGrenade, hero.grenadeAmmo + extraAmmo)
+end
+
+function enemyWeapons()
+	for i=1,table.getn(enemies) do
+		if GetHealth(enemies[i].gear) and enemies[i].gear == CurrentHedgehog then
+			AddAmmo(enemies[i].gear, amMortar, 0)
+			AddAmmo(enemies[i].gear, amFirePunch, 0)
+			AddAmmo(enemies[i].gear, amDEagle, 0)
+			AddAmmo(enemies[i].gear, amBazooka, 0)
+			AddAmmo(enemies[i].gear, amGrenade, 0)
+			AddAmmo(enemies[i].gear, enemies[i].weapon, 1)
+			for w=1,table.getn(enemies[i].additionalWeapons) do
+				AddAmmo(enemies[i].gear, enemies[i].additionalWeapons[w], 1)
+			end
+		end
+	end
+end
+
+function isHog(gear)
+	local hog = false
+	for i=1,table.getn(enemies) do
+		if gear == enemies[i].gear then
+			hog = true
+			break
+		end
+	end
+	return hog
+end
+
+function getHog(gear)
+	for i=1,table.getn(enemies) do
+		if gear == enemies[i].gear then
+			return enemies[i]
+		end
+	end
+end
+
+function getAliveEnemiesCount()
+	local count = 0
+	for i=1,table.getn(enemies) do
+		if GetHealth(enemies[i].gear) then
+			count = count + 1
+		end
+	end
+	return count
+end
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit03.lua	Mon Sep 02 18:57:30 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit03.lua	Tue Sep 03 04:01:19 2013 +0300
@@ -34,24 +34,24 @@
 	y = 560
 }
 local enemiesOdd = {
-	{name = "Hog 1", x = 2000 , y = 175},
-	{name = "Hog III", x = 1950 , y = 1110},
-	{name = "Hog 100", x = 1270 , y = 1480},
-	{name = "Hog Saturn", x = 240 , y = 790},
-	{name = "Hog nueve", x = 620 , y = 1950},
-	{name = "Hog onze", x = 720 , y = 1950},
-	{name = "Hog dertien", x = 1620 , y = 1950},
-	{name = "Hog 3x5", x = 1720 , y = 1950},
+	{name = loc("Hog 1"), x = 2000 , y = 175},
+	{name = loc("Hog III"), x = 1950 , y = 1110},
+	{name = loc("Hog 100"), x = 1270 , y = 1480},
+	{name = loc("Hog Saturn"), x = 240 , y = 790},
+	{name = loc("Hog nueve"), x = 620 , y = 1950},
+	{name = loc("Hog onze"), x = 720 , y = 1950},
+	{name = loc("Hog dertien"), x = 1620 , y = 1950},
+	{name = loc("Hog 3x5"), x = 1720 , y = 1950},
 }
 local enemiesEven = {
-	{name = "Hog two", x = 660, y = 140},
-	{name = "Hog D", x = 1120, y = 1250},
-	{name = "Hog exi", x = 1290, y = 1250},
-	{name = "Hog octo", x = 820, y = 1950},
-	{name = "Hog decar", x = 920, y = 1950},
-	{name = "Hog Hephaestus", x = 1820, y = 1950},
-	{name = "Hog 7+7", x = 1920, y = 1950},
-	{name = "Hog EOF", x = 1200, y = 560},
+	{name = loc("Hog two"), x = 660, y = 140},
+	{name = loc("Hog D"), x = 1120, y = 1250},
+	{name = loc("Hog exi"), x = 1290, y = 1250},
+	{name = loc("Hog octo"), x = 820, y = 1950},
+	{name = loc("Hog decar"), x = 920, y = 1950},
+	{name = loc("Hog Hephaestus"), x = 1820, y = 1950},
+	{name = loc("Hog 7+7"), x = 1920, y = 1950},
+	{name = loc("Hog EOF"), x = 1200, y = 560},
 }
 -- teams
 local teamA = {
@@ -201,7 +201,6 @@
 
 -------------- ACTIONS ------------------
 
--- game ends anyway but I want to sent custom stats probably...
 function heroDeath(gear)
 	SendStat('siGameResult', loc("Hog Solo lost, try again!")) --1
 	SendStat('siCustomAchievement', loc("You have to eliminate all the enemies")) --11