Report mission victory for most missions
authorWuzzy <Wuzzy2@mail.ru>
Tue, 18 Dec 2018 18:16:31 +0100
changeset 14485 ead8928a59f8
parent 14484 bd1db668b7c0
child 14486 ca851d0957cf
Report mission victory for most missions
share/hedgewars/Data/Maps/ClimbHome/map.lua
share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua
share/hedgewars/Data/Missions/Challenge/User_Mission_-_RCPlane_Challenge.lua
share/hedgewars/Data/Missions/Challenge/User_Mission_-_Rope_Knock_Challenge.lua
share/hedgewars/Data/Missions/Challenge/User_Mission_-_That_Sinking_Feeling.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Bamboo_Thicket.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Dangerous_Ducklings.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Diver.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Spooky_Tree.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork_2.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Flying_Saucer.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Movement.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Rope.lua
share/hedgewars/Data/Scripts/SimpleMission.lua
share/hedgewars/Data/Scripts/SpeedShoppa.lua
share/hedgewars/Data/Scripts/TargetPractice.lua
--- a/share/hedgewars/Data/Maps/ClimbHome/map.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Maps/ClimbHome/map.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -428,6 +428,7 @@
             end
             -- FIXME: Hog is also in winning box if it just walks into the chair from the left, touching it. Intentional?
             if not YouWon and not YouLost and gearIsInBox(CurrentHedgehog, 1920, 252, 50, 50) then
+                SaveMissionVar("Won", "true")
                 AddCaption(loc("Victory!"), capcolDefault, capgrpGameState)
                 ShowMission(loc("Climb Home"),
                             loc("Made it!"),
--- a/share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -384,6 +384,7 @@
 		else
 			if not game_lost then
 			-- Victory!
+			SaveMissionVar("Won", "true")
 			AddCaption(loc("Victory!"), capcolDefault, capgrpGameState)
 			ShowMission(loc("Sniper Training"), loc("Aiming Practice"), loc("Congratulations! You've eliminated all targets|within the allowed time frame."), 0, 0)
 			-- Also let the hogs shout "victory!"
--- a/share/hedgewars/Data/Missions/Challenge/User_Mission_-_RCPlane_Challenge.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Challenge/User_Mission_-_RCPlane_Challenge.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -407,6 +407,7 @@
 				SendStat(siGameResult, loc("You have finished the challenge!"))
 				SendStat(siCustomAchievement, string.format(loc("You have used %d RC planes."), planesUsed))
 			end
+			SaveMissionVar("Won", "true")
 		
 			if(totalMissiles > 1) then
 				SendStat(siCustomAchievement, string.format(loc("You have dropped %d missiles."), totalMissiles))
--- a/share/hedgewars/Data/Missions/Challenge/User_Mission_-_Rope_Knock_Challenge.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Challenge/User_Mission_-_Rope_Knock_Challenge.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -2,6 +2,7 @@
 
 local hhs = {}
 local missionWon = nil
+local missionEndHandled = false
 local endTimer = 1000
 local hogsKilled = 0
 local finishTime
@@ -234,10 +235,14 @@
 			EndGame()
 		end
 
-		if missionWon == true then
-			AddCaption(loc("Victory!"), capcolDefault, capgrpGameState)
-		else
-			AddCaption(loc("Challenge over!"), capcolDefault, capgrpGameState)
+		if not missionEndHandled then
+			if missionWon == true then
+				SaveMissionVar("Won", "true")
+				AddCaption(loc("Victory!"), capcolDefault, capgrpGameState)
+			else
+				AddCaption(loc("Challenge over!"), capcolDefault, capgrpGameState)
+			end
+			missionEndHandled = true
 		end
 
 	end
--- a/share/hedgewars/Data/Missions/Challenge/User_Mission_-_That_Sinking_Feeling.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Challenge/User_Mission_-_That_Sinking_Feeling.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -242,6 +242,7 @@
 				SendStat(siCustomAchievement, string.format(loc("You saved %d of 8 Hapless Hogs."), hhLeft))
 
 				if hhLeft == 8 then
+					SaveMissionVar("Won", "true")
 					awardAchievement(loc("Lively Lifeguard"))
 				end
 				EndGame()
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Bamboo_Thicket.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Bamboo_Thicket.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -79,6 +79,7 @@
 
 	if (gear == enemy) then
 		
+		SaveMissionVar("Won", "true")
 		ShowMission(loc("Bamboo Thicket"), loc("MISSION SUCCESSFUL"), loc("Congratulations!"), 0, 0)
 		
 		if (turnNumber < 6) and (firedShell == false) then
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Dangerous_Ducklings.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Dangerous_Ducklings.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -139,9 +139,11 @@
 			awardAchievement(loc("Naughty Ninja"))
 			DismissTeam(loc("Blue Team"))
 			gameWon = true
+			SaveMissionVar("Won", "true")
 		elseif gear == enemy then
 			HogSay(player, loc("Enjoy the swim..."), SAY_THINK)
 			gameWon = true
+			SaveMissionVar("Won", "true")
 			Retreat(3000)
 		end
 
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Diver.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Diver.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -98,6 +98,7 @@
 
 	if (gear == enemy) and (GameOver == false) then
 		ShowMission(loc("Diver"), loc("MISSION SUCCESSFUL"), loc("Congratulations!"), 0, 0)
+		SaveMissionVar("Won", "true")
 	elseif gear == player then
 		ShowMission(loc("Diver"), loc("MISSION FAILED"), loc("Oh no! Just try again!"), -amSkip, 0)		
 		GameOver = true
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Spooky_Tree.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Spooky_Tree.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -148,6 +148,7 @@
 
 	if (gear == enemy) and (GameOver == false) then
 		ShowMission(loc("Spooky Tree"), loc("MISSION SUCCESSFUL"), loc("Congratulations!"), 0, 0);
+		SaveMissionVar("Won", "true")
 	elseif gear == player then
 		ShowMission(loc("Spooky Tree"), loc("MISSION FAILED"), loc("Oh no! Just try again!"), -amSkip, 0)
 		GameOver = true
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -98,5 +98,10 @@
 		SetHealth(p2,0)
 		SetHealth(player,0)
 	end
+	if (gear == enemy) and not (GameOver) then
+		SaveMissionVar("Won", "true")
+		GameOver = true
+	end
 
 end
+
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork_2.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Teamwork_2.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -9,6 +9,7 @@
 local Pack = nil
 local help = false
 local GameOver = false
+local missionWon = false
 
 function onGameInit()
 	Seed = 0
@@ -105,4 +106,9 @@
 		SetHealth(hlayer, 0)
 		SetHealth(player, 0)
 	end
+	if (gear == enemy) and (not GameOver) then
+		GameOver = true
+		SaveMissionVar("Won", "true")
+	end
 end
+
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -211,6 +211,7 @@
 		SetWind(75)
 		spawnTargets()
 	elseif gamePhase == 7 then
+		SaveMissionVar("Won", "true")
 		ShowMission(loc("Basic Bazooka Training"), loc("Training complete!"), loc("Congratulations!"), 0, 0)
 		SetInputMask(0)
 		AddAmmo(CurrentHedgehog, amBazooka, 0)
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Flying_Saucer.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Flying_Saucer.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -205,6 +205,7 @@
 	SetState(Player, band(GetState(Player), bnot(gstHHDriven)))
 	SetState(Player, bor(GetState(Player), gstWinner))
 	PlaySound(sndVictory, Player)
+	SaveMissionVar("Won", "true")
 
 	SendStat(siGameResult, loc("You have finished the Flying Saucer Training!"))
 	SendStat(siCustomAchievement, loc("Good job!"))
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -189,6 +189,7 @@
 		2, 7000)
 		spawnTargets()
 	elseif gamePhase == 6 then
+		SaveMissionVar("Won", "true")
 		ShowMission(loc("Basic Grenade Training"), loc("Training complete!"), loc("Congratulations!"), 0, 0)
 		SetInputMask(0)
 		AddAmmo(CurrentHedgehog, amGrenade, 0)
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Movement.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Movement.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -249,6 +249,7 @@
 end
 
 local function victory()
+	SaveMissionVar("Won", "true")
 	ShowMission(loc("Basic Movement Training"), loc("Training complete!"),loc("Congratulations! You have completed the obstacle course!"), 0, 0)
 	SendStat(siGameResult, loc("You have completed the Basic Movement Training!"))
 	SendStat(siCustomAchievement, loc("Congratulations!"))
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Rope.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Rope.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -328,6 +328,7 @@
 			SetHealth(hog, initHogHealthFinal)
 			isInFinalChallenge = true
 		elseif currentTarget == 7 then
+			SaveMissionVar("Won", "true")
 			ShowMission(loc("Basic Rope Training"), loc("Training complete!"),
 			loc("Congratulations!"), 0, 0)
 			PlaySound(sndVictory, hog)
--- a/share/hedgewars/Data/Scripts/SimpleMission.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Scripts/SimpleMission.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -264,6 +264,8 @@
 
 	_G.sm.playerClan = 0
 
+	_G.sm.wonVarWritten = false
+
 	_G.sm.makeStats = function(winningClan, customAchievements)
 		for t=0, TeamsCount-1 do
 			local team = GetTeamName(t)
@@ -502,6 +504,10 @@
 		end
 		if victory then
 			_G.sm.gameEnded = true
+			if not _G.sm.wonVarWritten then
+				SaveMissionVar("Won", "true")
+				_G.sm.wonVarWritten = true
+			end
 		end
 	end
 
@@ -524,6 +530,10 @@
 	_G.sm.win = function()
 		if not _G.sm.gameEnded then
 			_G.sm.gameEnded = true
+			if not _G.sm.wonVarWritten then
+				SaveMissionVar("Won", "true")
+				_G.sm.wonVarWritten = true
+			end
 			AddCaption(loc("Victory!"), capcolDefault, capgrpGameState)
 			SendStat(siGameResult, loc("You win!"))
 			if GetHogLevel(CurrentHedgehog) == 0 then
@@ -693,7 +703,9 @@
 	_G.onNewTurn = function()
 		_G.sm.gameStarted = true
 
-		if params.customGoalCheck == "turnStart" then
+		if params.customGoals == nil then
+			_G.sm.checkRegularVictory()
+		elseif params.customGoalCheck == "turnStart" then
 			_G.sm.checkRegularVictory()
 			_G.sm.checkWinOrFail()
 		end
@@ -702,7 +714,9 @@
 	_G.onEndTurn = function()
 		_G.sm.gameTurns = _G.sm.gameTurns + 1
 
-		if params.customGoalCheck == "turnEnd" then
+		if params.customGoals == nil then
+			_G.sm.checkRegularVictory()
+		elseif params.customGoalCheck == "turnEnd" then
 			_G.sm.checkRegularVictory()
 			_G.sm.checkWinOrFail()
 		end
--- a/share/hedgewars/Data/Scripts/SpeedShoppa.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Scripts/SpeedShoppa.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -164,6 +164,7 @@
 	_G.finalize = function()
 		if not gameEnded then
 			if cratesCollected == #crates then
+				SaveMissionVar("Won", "true")
 				PlaySound(sndVictory, playerHog)
 				SetEffect(playerHog, heInvulnerable, 1)
 				SetState(playerHog, bor(GetState(playerHog), gstWinner))
--- a/share/hedgewars/Data/Scripts/TargetPractice.lua	Tue Dec 18 15:21:23 2018 +0100
+++ b/share/hedgewars/Data/Scripts/TargetPractice.lua	Tue Dec 18 18:16:31 2018 +0100
@@ -244,6 +244,7 @@
 				spawnTarget()
 			else
 				if not game_lost then
+					SaveMissionVar("Won", "true")
 					AddCaption(loc("You have destroyed all targets!"), capcolDefault, capgrpGameState)
 					ShowMission(params.missionTitle, loc("Aiming practice"), loc("Congratulations! You have destroyed all targets within the time."), 0, 0)
 					PlaySound(sndVictory, player)