Fix victory check of a few scenarios
authorWuzzy <Wuzzy2@mail.ru>
Tue, 18 Dec 2018 18:37:58 +0100
changeset 14471 734a7af2dfc2
parent 14470 ca851d0957cf
child 14472 4edcb655dc5a
Fix victory check of a few scenarios
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork_2.lua
share/hedgewars/Data/Missions/Scenario/portal.lua
share/hedgewars/Data/Scripts/SimpleMission.lua
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork.lua	Tue Dec 18 18:26:13 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork.lua	Tue Dec 18 18:37:58 2018 +0100
@@ -4,6 +4,7 @@
 local p2 = nil
 local enemy = nil
 local bCrate = nil
+local playerTeamName = loc("Feeble Resistance")
 
 local GameOver = false
 
@@ -23,7 +24,7 @@
 	HealthDecrease = 0
 	WaterRise = 0
 
-	AddTeam(loc("Feeble Resistance"), -1, "Statue", "Island", "Default", "cm_kiwi")
+	AddTeam(playerTeamName, -1, "Statue", "Island", "Default", "cm_kiwi")
 	player = AddHog(loc("Greg"), 0, 50, "NoHat")
 	p2 = AddHog(loc("Mark"), 0, 20, "NoHat")
 
@@ -98,10 +99,11 @@
 		SetHealth(p2,0)
 		SetHealth(player,0)
 	end
-	if (gear == enemy) and not (GameOver) then
-		SaveMissionVar("Won", "true")
-		GameOver = true
-	end
 
 end
 
+function onGameResult(winningClan)
+	if winningClan == GetTeamClan(playerTeamName) then
+		SaveMissionVar("Won", "true")
+	end
+end
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork_2.lua	Tue Dec 18 18:26:13 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork_2.lua	Tue Dec 18 18:37:58 2018 +0100
@@ -9,7 +9,7 @@
 local Pack = nil
 local help = false
 local GameOver = false
-local missionWon = false
+local playerTeamName = loc("Feeble Resistance")
 
 function onGameInit()
 	Seed = 0
@@ -26,7 +26,7 @@
 	Map = "CrazyMission"
 	Theme = "CrazyMission"
 
-	AddTeam(loc("Feeble Resistance"), -1, "Statue", "Island", "Default", "cm_kiwi")
+	AddTeam(playerTeamName, -1, "Statue", "Island", "Default", "cm_kiwi")
 	player = AddHog(loc("Greg"), 0, 30, "NoHat")
 	hlayer = AddHog(loc("Mark"), 0, 40, "NoHat")
 
@@ -106,9 +106,10 @@
 		SetHealth(hlayer, 0)
 		SetHealth(player, 0)
 	end
-	if (gear == enemy) and (not GameOver) then
-		GameOver = true
+end
+
+function onGameResult(winningClan)
+	if winningClan == GetTeamClan(playerTeamName) then
 		SaveMissionVar("Won", "true")
 	end
 end
-
--- a/share/hedgewars/Data/Missions/Scenario/portal.lua	Tue Dec 18 18:26:13 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/portal.lua	Tue Dec 18 18:37:58 2018 +0100
@@ -202,3 +202,8 @@
 	end
 end
 
+function onGameResult(winningClan)
+	if winningClan == GetHogClan(player) then
+		SaveMissionVar("Won", "true")
+	end
+end
--- a/share/hedgewars/Data/Scripts/SimpleMission.lua	Tue Dec 18 18:26:13 2018 +0100
+++ b/share/hedgewars/Data/Scripts/SimpleMission.lua	Tue Dec 18 18:37:58 2018 +0100
@@ -504,10 +504,6 @@
 		end
 		if victory then
 			_G.sm.gameEnded = true
-			if not _G.sm.wonVarWritten then
-				SaveMissionVar("Won", "true")
-				_G.sm.wonVarWritten = true
-			end
 		end
 	end
 
@@ -703,9 +699,7 @@
 	_G.onNewTurn = function()
 		_G.sm.gameStarted = true
 
-		if params.customGoals == nil then
-			_G.sm.checkRegularVictory()
-		elseif params.customGoalCheck == "turnStart" then
+		if params.customGoalCheck == "turnStart" then
 			_G.sm.checkRegularVictory()
 			_G.sm.checkWinOrFail()
 		end
@@ -714,14 +708,19 @@
 	_G.onEndTurn = function()
 		_G.sm.gameTurns = _G.sm.gameTurns + 1
 
-		if params.customGoals == nil then
-			_G.sm.checkRegularVictory()
-		elseif params.customGoalCheck == "turnEnd" then
+		if params.customGoalCheck == "turnEnd" then
 			_G.sm.checkRegularVictory()
 			_G.sm.checkWinOrFail()
 		end
 	end
 
+	_G.onGameResult = function(winningClan)
+		if (params.customGoals == nil) and (not _G.sm.wonVarWritten) and (winningClan == _G.sm.playerClan) then
+			SaveMissionVar("Won", "true")
+			_G.sm.wonVarWritten = true
+		end
+	end
+
 	_G.onAmmoStoreInit = function()
 		local ammoTypesDone = {}
 		-- Read script's stated ammo wishes