share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit02.lua
branchspacecampaign
changeset 9552 90d69a2c1729
parent 9550 59061246a25c
child 9554 054eede3b718
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit02.lua	Tue Aug 20 06:07:58 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit02.lua	Wed Aug 21 02:06:31 2013 +0300
@@ -27,11 +27,9 @@
 	[dialog04] = {missionName, loc("Return to the Surface"), loc("Go to the surface!").."|"..loc("Attack the assasins before they attack back"), 1, 4000},
 }
 -- crates
-local crates = {
-	{name = amDEagle, x = 1680, y = 1650},
-	{name = amGirder, x = 1680, y = 1160},
-	{name = amRope, x = 1400, y = 1870},
-}
+local eagleCrate = {name = amDEagle, x = 1680, y = 1650}
+local girderCrate =	{name = amGirder, x = 1680, y = 1160}
+local ropeCrate = {name = amRope, x = 1400, y = 1870}
 local weaponCrate = { x = 1360, y = 1870}
 -- hogs
 local hero = {}
@@ -85,21 +83,21 @@
 	
 	WriteLnToConsole("CHECKPOINT IS "..checkPointReached)
 	-- load checkpoints, problem getting the campaign variable
-	--local h = GetCampaignVar("Desert01CheckPoint")
-	--WriteLnToCosnole("HERE "..GetCampaignVar("Fruit02CheckPoint"))
+	local health = 100
 	if tonumber(GetCampaignVar("Fruit02CheckPoint")) then
 		WriteLnToConsole("**TRUE**")
 		checkPointReached = tonumber(GetCampaignVar("Fruit02CheckPoint"))
-		if checkPointReached == 2 or checkPointReached == 3 then
+		if checkPointReached ~= 1 then
 			WriteLnToConsole("++++++++++++++HEEEEEEEREEEEEEEEEEEEE")
 			loadHogsPositions()
+			health = tonumber(GetCampaignVar("HeroHealth"))
 		end
 	end
 	
 	WriteLnToConsole("CHECKPOINT IS "..checkPointReached)
 	-- Hog Solo and Green Bananas
 	AddTeam(teamA.name, teamA.color, "Bone", "Island", "HillBilly", "cm_birdy")
-	hero.gear = AddHog(hero.name, 0, 100, "war_desertgrenadier1")
+	hero.gear = AddHog(hero.name, 0, health, "war_desertgrenadier1")
 	AnimSetGearPosition(hero.gear, hero.x, hero.y)
 	HogTurnLeft(hero.gear, true)	
 	green2.gear = AddHog(green2.name, 0, 100, "war_desertgrenadier1")
@@ -153,16 +151,6 @@
 		HideHog(redHedgehogs[i].gear)
 	end
 	
-	-- place crates
-	for i=1,table.getn(crates) do
-		SpawnAmmoCrate(crates[i].x, crates[i].y, crates[i].name)
-	end
-	if tookPartInBattle then
-		SpawnAmmoCrate(weaponCrate.x, weaponCrate.y, amWatermelon)
-	else
-		SpawnAmmoCrate(weaponCrate.x, weaponCrate.y, amSniperRifle)		
-	end
-	
 	-- explosives
 	-- I wanted to use FindPlace but doesn't accept height values...
 	local x1 = 950
@@ -194,24 +182,56 @@
 	AddGear(3105, 1680, gtMine, 0, 0, 0, 0)
 	AddGear(3095, 1680, gtMine, 0, 0, 0, 0)
 	AddGear(3085, 1680, gtMine, 0, 0, 0, 0)
-	AddGear(3075, 1680, gtMine, 0, 0, 0, 0)
-	
-	if tookPartInBattle then
-		AddAnim(dialog01)
-	else
-		AddAnim(dialog02)
-	end
+	AddGear(3075, 1680, gtMine, 0, 0, 0, 0)	
+
 	WriteLnToConsole("CHECKPOINT IS "..checkPointReached)
 	if checkPointReached == 1 then
 		AddAmmo(hero.gear, amFirePunch, 3)
 		AddEvent(onCheckPoint1, {hero.gear}, checkPoint1, {hero.gear}, 0)
-		AddEvent(onCheckPoint2, {hero.gear}, checkPoint2, {hero.gear}, 0)	
+		AddEvent(onCheckPoint2, {hero.gear}, checkPoint2, {hero.gear}, 0)
+		AddEvent(onCheckPoint3, {hero.gear}, checkPoint3, {hero.gear}, 0)
+		AddEvent(onCheckPoint4, {hero.gear}, checkPoint4, {hero.gear}, 0)
+		if tookPartInBattle then
+			AddAnim(dialog01)
+		else
+			AddAnim(dialog02)
+		end
 	elseif checkPointReached == 2 then
-		loadWeapons()
 		AddEvent(onCheckPoint2, {hero.gear}, checkPoint2, {hero.gear}, 0)
+		AddEvent(onCheckPoint3, {hero.gear}, checkPoint3, {hero.gear}, 0)
+		AddEvent(onCheckPoint4, {hero.gear}, checkPoint4, {hero.gear}, 0)
 	elseif checkPointReached == 3 then
+		AddEvent(onCheckPoint1, {hero.gear}, checkPoint1, {hero.gear}, 0)
+		AddEvent(onCheckPoint3, {hero.gear}, checkPoint3, {hero.gear}, 0)
+		AddEvent(onCheckPoint4, {hero.gear}, checkPoint4, {hero.gear}, 0)
+	elseif checkPointReached == 4 then
+		AddEvent(onCheckPoint4, {hero.gear}, checkPoint4, {hero.gear}, 0)		
+	elseif checkPointReached == 5 then
+		-- EMPTY
+	end
+	if checkPointReached ~= 1 then
 		loadWeapons()
-		AddEvent(onCheckPoint1, {hero.gear}, checkPoint1, {hero.gear}, 0)
+	end
+	
+	-- girders
+	if checkPointReached > 1 then
+		PlaceGirder(1580, 875, 4)
+		PlaceGirder(1800, 875, 4)
+	end
+	
+	-- place crates
+	if checkPointReached < 2 then
+		SpawnAmmoCrate(girderCrate.x, girderCrate.y, girderCrate.name)
+	end
+	if checkPointReached < 5 then
+		SpawnAmmoCrate(eagleCrate.x, eagleCrate.y, eagleCrate.name)
+	end
+	SpawnAmmoCrate(ropeCrate.x, ropeCrate.y, ropeCrate.name)
+
+	if tookPartInBattle then
+		SpawnAmmoCrate(weaponCrate.x, weaponCrate.y, amWatermelon)
+	else
+		SpawnAmmoCrate(weaponCrate.x, weaponCrate.y, amSniperRifle)		
 	end
 	
 	SendHealthStatsOff()
@@ -285,7 +305,7 @@
 end
 
 function onDeviceCrates(gear)
-	if not hero.dead and GetY(hero.gear)>1850 and GetX(hero.gear)>1340 then
+	if not hero.dead and GetY(hero.gear)>1850 and GetX(hero.gear)>1340 and GetX(hero.gear)<1640 then
 		return true
 	end
 	return false
@@ -318,8 +338,8 @@
 
 function onCheckPoint1(gear)
 	-- before barrel jump
-	if GetX(hero.gear) > 2850 and GetX(hero.gear) < 2945 and GetY(hero.gear) > 808 and GetY(hero.gear) < 852
-			and	not isHeroAtWrongPlace() then
+	if not hero.dead and GetX(hero.gear) > 2850 and GetX(hero.gear) < 2945 
+			and GetY(hero.gear) > 808 and GetY(hero.gear) < 852 and	not isHeroAtWrongPlace() then
 		return true
 	end
 	return false
@@ -327,14 +347,33 @@
 
 function onCheckPoint2(gear)
 	-- before barrel jump
-	if ((GetX(green2.gear) > 2850 and GetX(green2.gear) < 2945 and GetY(green2.gear) > 808 and GetY(green2.gear) < 852)
-			or (GetX(green3.gear) > 2850 and GetX(green3.gear) < 2945 and GetY(green3.gear) > 808 and GetY(green3.gear) < 852))
+	if ((GetHealth(green2.gear) and GetX(green2.gear) > 2850 and GetX(green2.gear) < 2945 and GetY(green2.gear) > 808 and GetY(green2.gear) < 852)
+			or (GetHealth(green3.gear) and GetX(green3.gear) > 2850 and GetX(green3.gear) < 2945 and GetY(green3.gear) > 808 and GetY(green3.gear) < 852))
 			and not isHeroAtWrongPlace() then
 		return true
 	end
 	return false
 end
 
+function onCheckPoint3(gear)
+	-- after barrel jump
+	if ((GetHealth(green2.gear) and GetY(green2.gear) > 1550 and GetX(green2.gear) < 3000 and StoppedGear(green2.gear)) 
+			or (GetHealth(green3.gear) and GetY(green3.gear) > 1550 and GetX(green3.gear) < 3000 and StoppedGear(green2.gear)))
+			and not isHeroAtWrongPlace() then
+		return true
+	end
+	return false
+end
+
+function onCheckPoint4(gear)
+	-- hero at crates
+	if not hero.dead and GetX(hero.gear) > 1288 and GetX(hero.gear) < 1420 
+			and GetY(hero.gear) > 1840 and	not isHeroAtWrongPlace() then
+		return true
+	end
+	return false
+end
+
 -------------- ACTIONS ------------------
 
 function heroDeath(gear)
@@ -407,17 +446,19 @@
 end
 
 function checkPoint1(gear)
-	AnimCaption(hero.gear, loc("Checkpoint reached!"), 3000)
-	SaveCampaignVar("Fruit02CheckPoint", 2)
-	saveHogsPositions()
-	saveWeapons()
+	saveCheckPoint(2)
 end
 
 function checkPoint2(gear)
-	AnimCaption(hero.gear, loc("Checkpoint reached!"), 3000)
-	SaveCampaignVar("Fruit02CheckPoint", 3)
-	saveHogsPositions()
-	saveWeapons()
+	saveCheckPoint(3)
+end
+
+function checkPoint3(gear)
+	saveCheckPoint(4)
+end
+
+function checkPoint4(gear)
+	saveCheckPoint(5)
 end
 
 -------------- ANIMATIONS ------------------
@@ -521,6 +562,7 @@
 	if positions[5] then
 		green3.x = tonumber(positions[5])
 		green3.y = tonumber(positions[6])
+		WriteLnToConsole("---------"..green3.y)
 	end
 end
 
@@ -528,16 +570,15 @@
 	-- firepunch - gilder - deagle - watermelon - sniper
 	WriteLnToConsole("SAVE WEAPONS TRIGGERED: "..GetAmmoCount(hero.gear, amFirePunch)..GetAmmoCount(hero.gear, amGilder)..
 			GetAmmoCount(hero.gear, amDEagle)..GetAmmoCount(hero.gear, amWatermelon)..GetAmmoCount(hero.gear, amSniperRifle))
-	SaveCampaignVar("HeroAmmo", GetAmmoCount(hero.gear, amFirePunch)..GetAmmoCount(hero.gear, amGilder)..
+	SaveCampaignVar("HeroAmmo", GetAmmoCount(hero.gear, amFirePunch)..GetAmmoCount(hero.gear, amGirder)..
 			GetAmmoCount(hero.gear, amDEagle)..GetAmmoCount(hero.gear, amWatermelon)..GetAmmoCount(hero.gear, amSniperRifle))
 end
 
 function loadWeapons()
 	local ammo = GetCampaignVar("HeroAmmo")
-	WriteLnToConsole("LOAD WEAPONS "..ammo)
-	WriteLnToConsole("LOAD WEAPONS "..ammo:sub(1,1))
+	WriteLnToConsole("GILDER "..tonumber(ammo:sub(2,2)))
 	AddAmmo(hero.gear, amFirePunch, tonumber(ammo:sub(1,1)))
-	AddAmmo(hero.gear, amGilder, tonumber(ammo:sub(2,2)))
+	AddAmmo(hero.gear, amGirder, tonumber(ammo:sub(2,2)))
 	AddAmmo(hero.gear, amDEagle, tonumber(ammo:sub(3,3)))
 	AddAmmo(hero.gear, amWatermelon, tonumber(ammo:sub(4,4)))
 	AddAmmo(hero.gear, amSniperRifle, tonumber(ammo:sub(5,5)))
@@ -563,5 +604,16 @@
 		end
 		s = s:sub(2)
 	end
+	if first:len() > 0 then
+		table.insert(res, tonumber(first))
+	end
 	return res
 end
+
+function saveCheckPoint(cpoint)
+	AnimCaption(hero.gear, loc("Checkpoint reached!"), 3000)
+	SaveCampaignVar("Fruit02CheckPoint", cpoint)
+	SaveCampaignVar("HeroHealth", GetHealth(hero.gear))
+	saveHogsPositions()
+	saveWeapons()
+end