finally most of the mission mechanics seems ok spacecampaign
authorPeriklis Ntanasis <pntanasis@gmail.com>
Sat, 03 Aug 2013 03:13:10 +0300
branchspacecampaign
changeset 9457 934f4d8370f1
parent 9455 4bf3fac0e49d
child 9459 8c653c0dd332
finally most of the mission mechanics seems ok
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/cosmos.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/cosmos.lua	Fri Aug 02 22:19:36 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/cosmos.lua	Sat Aug 03 03:13:10 2013 +0300
@@ -355,7 +355,7 @@
 	else
 		AnimCaption(hero.gear,loc("Welcome to the planet of ice!"))
 		SaveCampaignVar("Planet", "icePlanet")
-		SaveCampaignVar("UnlockedMissions", "2")
+		SaveCampaignVar("UnlockedMissions", "3")
 		SaveCampaignVar("Mission1", "5")
 		SaveCampaignVar("Mission2", "6")
 		SaveCampaignVar("Mission3", "1")
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua	Fri Aug 02 22:19:36 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua	Sat Aug 03 03:13:10 2013 +0300
@@ -1,7 +1,7 @@
 ------------------- ABOUT ----------------------
 --
 -- Hero has to pass as fast as possible inside the
--- rings as in the runner mode
+-- rings as in the racer mode
 
 HedgewarsScriptLoad("/Scripts/Locale.lua")
 HedgewarsScriptLoad("/Scripts/Animate.lua")
@@ -10,51 +10,61 @@
 -- globals
 local campaignName = loc("A Space Adventure")
 local missionName = loc("Ice planet, a frozen adventure!")
-local heroAtAntiFlyArea = false
-local heroVisitedAntiFlyArea = false
-local heroAtFinalStep = false
-local iceGunTaken = false
-local checkPointReached = 1 -- 1 is normal spawn
+local currentWaypoint = 1
+local radius = 75
 -- dialogs
 local dialog01 = {}
-local dialog02 = {}
 -- mission objectives
 local goals = {
 	[dialog01] = {missionName, loc("Getting ready"), loc("Collect the icegun and get the device part from Thanta"), 1, 4500},
 }
--- crates
-local icegunY = 1950
-local icegunX = 260
 -- hogs
 local hero = {}
 local ally = {}
 -- teams
 local teamA = {}
 local teamB = {}
-local teamC = {}
 -- hedgehogs values
 hero.name = "Hog Solo"
-hero.x = 450
-hero.y = 200
+hero.x = 750
+hero.y = 130
 hero.dead = false
 ally.name = "Paul McHoggy"
-ally.x = 512
-ally.y = 200
+ally.x = 860
+ally.y = 130
 teamA.name = loc("Hog Solo")
 teamA.color = tonumber("38D61C",16) -- green
 teamB.name = loc("Allies")
 teamB.color = tonumber("FF0000",16) -- red
+-- way points
+local current waypoint = 1
+local waypoints = { 
+	[1] = {x=1450, y=140},
+	[2] = {x=990, y=580},
+	[3] = {x=1650, y=950},
+	[4] = {x=620, y=630},
+	[5] = {x=1470, y=540},
+	[6] = {x=1960, y=60},
+	[7] = {x=1600, y=400},
+	[8] = {x=240, y=940},
+	[9] = {x=200, y=530},
+	[10] = {x=1180, y=120},
+	[11] = {x=1950, y=660},
+	[12] = {x=1280, y=980},
+	[13] = {x=590, y=1100},
+	[14] = {x=20, y=620},
+	[15] = {x=hero.x, y=hero.y}
+}
 
 -------------- LuaAPI EVENT HANDLERS ------------------
 
 function onGameInit()
 	Seed = 1
-	TurnTime = 25000
+	TurnTime = 15000
 	CaseFreq = 0
 	MinesNum = 0
 	MinesTime = 1
 	Explosives = 0
-	Delay = 3
 	Map = "ice02_map"
 	Theme = "Snow"
 	
@@ -62,21 +72,79 @@
 	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)
-	HogTurnLeft(hero.gear, true)
 	-- Ally
 	AddTeam(teamB.name, teamB.color, "Bone", "Island", "HillBilly", "cm_birdy")
 	ally.gear = AddHog(ally.name, 0, 100, "tophats")
 	AnimSetGearPosition(ally.gear, ally.x, ally.y)
+	HogTurnLeft(ally.gear, true)
 	
 	AnimInit()
 	--AnimationSetup()	
 end
-
+local wp = 0
 function onGameStart()
 	AnimWait(hero.gear, 3000)
 	FollowGear(hero.gear)
 	
-	AddAmmo(hero.gear, amJetpack, 99)
+	AddAmmo(hero.gear, amJetpack, 3)
+	
+	-- place a waypoint
+	placeNextWaypoint()
 	
 	SendHealthStatsOff()
 end
+
+function onGameTick20()
+	if checkIfHeroInWaypoint() then
+		if not placeNextWaypoint() then
+			-- GAME OVER, WIN!
+			EndGame()
+		end
+	end
+end
+
+function onGearDelete(gear)
+	if gear == hero.gear then
+		hero.dead = true
+	end
+end
+
+------------------ Other Functions -------------------
+
+function placeNextWaypoint()
+	WriteLnToConsole("IN PLACE NEXT POINT")
+	if currentWaypoint > 1 then
+		local wp = waypoints[currentWaypoint-1]
+		DeleteVisualGear(wp.gear)
+	end
+	if currentWaypoint < 16 then
+		local wp = waypoints[currentWaypoint]
+		wp.gear = AddVisualGear(1,1,vgtCircle,1,true)
+		SetVisualGearValues(wp.gear, wp.x,wp.y, 20, 200, 0, 0, 100, radius, 3, 0xff0000ff)
+		-- add bonus time and "fuel"		
+		WriteLnToConsole("Before "..TurnTimeLeft)
+		if currentWaypoint % 2 == 0 then
+			AddAmmo(hero.gear, amJetpack, GetAmmoCount(hero.gear, amJetpack)+1)
+			TurnTimeLeft = TurnTimeLeft + 10000		
+		else
+			TurnTimeLeft = TurnTimeLeft + 8000
+		end		
+		WriteLnToConsole("After "..TurnTimeLeft)
+		radius = radius - 4
+		currentWaypoint = currentWaypoint + 1
+		return true
+	end
+	return false
+end
+
+function checkIfHeroInWaypoint()
+	if not hero.dead then
+		local wp = waypoints[currentWaypoint-1]
+		local distance = math.sqrt((GetX(hero.gear)-wp.x)^2 + (GetY(hero.gear)-wp.y)^2)
+		if distance <= radius+4 then
+			SetWind(math.random(-100,100))
+			return true
+		end
+	end
+	return false
+end