less variables used to save the checkpoints - potential breakage xD spacecampaign
authorPeriklis Ntanasis <pntanasis@gmail.com>
Tue, 27 Aug 2013 01:25:46 +0300
branchspacecampaign
changeset 9582 bf314b2258b3
parent 9580 49db7a78c2bd
child 9584 a7bf5464dfb6
less variables used to save the checkpoints - potential breakage xD
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death01.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert01.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit01.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit02.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/global_functions.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice01.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon01.lua
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death01.lua	Mon Aug 26 06:23:19 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/death01.lua	Tue Aug 27 01:25:46 2013 +0300
@@ -125,6 +125,8 @@
 		HogTurnLeft(thugs[i].gear, not thugs[i].turnLeft)
 	end
 	
+	initCheckpoint("death01")
+	
 	AnimInit()
 	AnimationSetup()
 end
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert01.lua	Mon Aug 26 06:23:19 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert01.lua	Tue Aug 27 01:25:46 2013 +0300
@@ -95,9 +95,7 @@
 	Theme = "Desert"
 	
 	-- get the check point
-	if tonumber(GetCampaignVar("Desert01CheckPoint")) then
-		checkPointReached = tonumber(GetCampaignVar("Desert01CheckPoint"))
-	end
+	checkPointReached = initCheckpoint("desert01")
 	-- get hero health
 	local heroHealth = 100
 	if checkPointReached > 1 and tonumber(GetCampaignVar("HeroHealth")) then
@@ -378,17 +376,17 @@
 end
 
 function heroAtCheckpoint2(gear)
-	saveCheckPoint("2")
+	saveCheckPointLocal("2")
 	secondBattle()
 end
 
 function heroAtCheckpoint3(gear)
-	saveCheckPoint("3")
+	saveCheckPointLocal("3")
 	secondBattle()
 end
 
 function heroAtCheckpoint4(gear)
-	saveCheckPoint("4")
+	saveCheckPointLocal("4")
 end
 
 function heroAtThirdBattle(gear)
@@ -407,7 +405,7 @@
 function checkForWin2(gear)
 	-- ok lets place one more checkpoint as next part seems challenging without rope
 	if cratesFound ==  0 then
-		saveCheckPoint("5")
+		saveCheckPointLocal("5")
 	end
 	
 	checkForWin()	
@@ -463,9 +461,9 @@
 	TurnTimeLeft = 0
 end
 
-function saveCheckPoint(cpoint)
+function saveCheckPointLocal(cpoint)
 	-- save checkpoint
-	SaveCampaignVar("Desert01CheckPoint", cpoint)	
+	saveCheckpoint(cpoint)	
 	SaveCampaignVar("HeroHealth", GetHealth(hero.gear))
 	-- bazooka - grenade - rope - parachute - deagle - btorch - construct - portal
 	SaveCampaignVar("HeroAmmo", GetAmmoCount(hero.gear, amBazooka)..GetAmmoCount(hero.gear, amGrenade)..
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua	Mon Aug 26 06:23:19 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua	Tue Aug 27 01:25:46 2013 +0300
@@ -5,6 +5,7 @@
 
 HedgewarsScriptLoad("/Scripts/Locale.lua")
 HedgewarsScriptLoad("/Scripts/Animate.lua")
+HedgewarsScriptLoad("/Missions/Campaign/A_Space_Adventure/global_functions.lua")
 
 ----------------- VARIABLES --------------------
 -- globals
@@ -76,6 +77,8 @@
 	AnimSetGearPosition(hero.gear, hero.x, hero.y)
 	HogTurnLeft(hero.gear, true)
 	
+	initCheckpoint("desert02")
+	
 	AnimInit()
 	AnimationSetup()
 end
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit01.lua	Mon Aug 26 06:23:19 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit01.lua	Tue Aug 27 01:25:46 2013 +0300
@@ -146,6 +146,8 @@
 		yellowArmy[i].gear = AddHog(yellowArmy[i].name, 1, yellowArmy[i].health, "war_desertgrenadier1")
 		AnimSetGearPosition(yellowArmy[i].gear, yellowArmy[i].x, yellowArmy[i].y)
 	end
+	
+	initCheckpoint("fruit01")
 
 	AnimInit()
 	AnimationSetup()	
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit02.lua	Mon Aug 26 06:23:19 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit02.lua	Tue Aug 27 01:25:46 2013 +0300
@@ -83,12 +83,10 @@
 	
 	-- load checkpoints, problem getting the campaign variable
 	local health = 100
-	if tonumber(GetCampaignVar("Fruit02CheckPoint")) then
-		checkPointReached = tonumber(GetCampaignVar("Fruit02CheckPoint"))
-		if checkPointReached ~= 1 then
-			loadHogsPositions()
-			health = tonumber(GetCampaignVar("HeroHealth"))
-		end
+	checkPointReached = initCheckpoint("fruit02")
+	if checkPointReached ~= 1 then
+		loadHogsPositions()
+		health = tonumber(GetCampaignVar("HeroHealth"))
 	end
 	
 	-- Hog Solo and Green Bananas
@@ -442,19 +440,19 @@
 end
 
 function checkPoint1(gear)
-	saveCheckPoint(2)
+	saveCheckPointLocal(2)
 end
 
 function checkPoint2(gear)
-	saveCheckPoint(3)
+	saveCheckPointLocal(3)
 end
 
 function checkPoint3(gear)
-	saveCheckPoint(4)
+	saveCheckPointLocal(4)
 end
 
 function checkPoint4(gear)
-	saveCheckPoint(5)
+	saveCheckPointLocal(5)
 end
 
 -------------- ANIMATIONS ------------------
@@ -599,9 +597,9 @@
 	return res
 end
 
-function saveCheckPoint(cpoint)
+function saveCheckPointLocal(cpoint)
 	AnimCaption(hero.gear, loc("Checkpoint reached!"), 3000)
-	SaveCampaignVar("Fruit02CheckPoint", cpoint)
+	saveCheckpoint(cpoint)
 	SaveCampaignVar("HeroHealth", GetHealth(hero.gear))
 	saveHogsPositions()
 	saveWeapons()
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/global_functions.lua	Mon Aug 26 06:23:19 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/global_functions.lua	Tue Aug 27 01:25:46 2013 +0300
@@ -50,3 +50,18 @@
 	end
 	return status
 end
+
+function initCheckpoint(mission)
+	local checkPoint = 1
+	if GetCampaignVar("CurrentMission") ~= mission then
+		SaveCampaignVar("CurrentMission", mission)
+		SaveCampaignVar("CurrentMissionCheckpoint", 1)
+	else
+		checkPoint = tonumber(GetCampaignVar("currentMissionCheckpoint"))
+	end
+	return checkPoint
+end
+
+function saveCheckpoint(cp)
+	SaveCampaignVar("CurrentMissionCheckpoint", cp)
+end
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice01.lua	Mon Aug 26 06:23:19 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice01.lua	Tue Aug 27 01:25:46 2013 +0300
@@ -94,9 +94,7 @@
 	Theme = "Snow"
 	
 	-- get the check point
-	if tonumber(GetCampaignVar("Ice01CheckPoint")) then
-		checkPointReached = tonumber(GetCampaignVar("Ice01CheckPoint"))
-	end
+	checkPointReached = initCheckpoint("ice01")
 	-- get hero health
 	local heroHealth = 100
 	if tonumber(GetCampaignVar("HeroHealth")) then
@@ -422,12 +420,12 @@
 
 function heroFinalStep(gear)
 	heroAtFinalStep = true
-	SaveCampaignVar("Ice01CheckPoint", "3")
+	saveCheckpoint("3")
 	SaveCampaignVar("HeroHealth", GetHealth(hero.gear))
 end
 
 function columnCheckPoint(gear)
-	SaveCampaignVar("Ice01CheckPoint", "2")	
+	saveCheckpoint("2")
 	SaveCampaignVar("HeroHealth", GetHealth(hero.gear))
 	AnimCaption(hero.gear, loc("Checkpoint reached!"), 5000)
 end
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua	Mon Aug 26 06:23:19 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua	Tue Aug 27 01:25:46 2013 +0300
@@ -5,6 +5,7 @@
 
 HedgewarsScriptLoad("/Scripts/Locale.lua")
 HedgewarsScriptLoad("/Scripts/Animate.lua")
+HedgewarsScriptLoad("/Missions/Campaign/A_Space_Adventure/global_functions.lua")
 
 ----------------- VARIABLES --------------------
 -- globals
@@ -88,6 +89,8 @@
 	AnimSetGearPosition(ally.gear, ally.x, ally.y)
 	HogTurnLeft(ally.gear, true)
 	
+	initCheckpoint("ice02")
+	
 	AnimInit()
 	AnimationSetup()	
 end
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon01.lua	Mon Aug 26 06:23:19 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon01.lua	Tue Aug 27 01:25:46 2013 +0300
@@ -153,10 +153,7 @@
 	HogTurnLeft(minion3.gear, true)
 	
 	-- get the check point
-	if tonumber(GetCampaignVar("Moon01CheckPoint")) then
-		checkPointReached = tonumber(GetCampaignVar("Moon01CheckPoint"))
-	end
-	
+	checkPointReached = initCheckpoint("moon01")
 	if checkPointReached == 1 then
 		-- Start of the game
 	elseif checkPointReached == 2 then
@@ -319,8 +316,8 @@
 
 -------------- OUTCOMES ------------------
 
-function weaponsPlatform(gear)	
-	SaveCampaignVar("Moon01CheckPoint", "2")	
+function weaponsPlatform(gear)
+	saveCheckpoint("2")
 	SaveCampaignVar("HeroHealth",GetHealth(hero.gear))
 	TurnTimeLeft = 0
 	weaponsAqcuired = true