SimpleMission: Check regular victory at turn and or start
authorWuzzy <Wuzzy2@mail.ru>
Thu, 22 Feb 2018 01:35:16 +0100
changeset 13060 5ceb8b0632c4
parent 13059 2d0f3e12fcad
child 13061 b1a230d21a48
SimpleMission: Check regular victory at turn and or start
share/hedgewars/Data/Scripts/SimpleMission.lua
--- a/share/hedgewars/Data/Scripts/SimpleMission.lua	Thu Feb 22 01:03:40 2018 +0100
+++ b/share/hedgewars/Data/Scripts/SimpleMission.lua	Thu Feb 22 01:35:16 2018 +0100
@@ -486,6 +486,19 @@
 		for t=0, TeamsCount-1 do
 			local team = GetTeamName(t)
 			local defeat = _G.sm.checkGoal({type="teamDefeat", teamName=team})
+			if not defeat then
+				-- Deep check, also look at damage of all hogs
+				local dead = 0
+				for h=1, #teamHogs[team] do
+					local _,_,_,_,_,_,_,_,_,_,_,Damage = GetGearValues(teamHogs[team][h])
+					if Damage >= GetHealth(teamHogs[team][h]) then
+						dead = dead + 1
+					end
+				end
+				if dead >= #teamHogs[team] then
+					defeat = true
+				end
+			end
 			if (defeat == true) and (GetTeamClan(team) == _G.sm.playerClan) then
 				victory = false
 				break
@@ -504,7 +517,6 @@
 		if errord then
 			return
 		end
-		_G.sm.checkRegularVictory()
 		local nonGoalStatus, nonGoalFailText = _G.sm.checkNonGoals()
 		local goalStatus, goalFailText = _G.sm.checkGoals()
 		if nonGoalStatus == true then
@@ -685,6 +697,7 @@
 		_G.sm.gameStarted = true
 
 		if params.customGoalCheck == "turnStart" then
+			_G.sm.checkRegularVictory()
 			_G.sm.checkWinOrFail()
 		end
 	end
@@ -693,6 +706,7 @@
 		_G.sm.gameTurns = _G.sm.gameTurns + 1
 
 		if params.customGoalCheck == "turnEnd" then
+			_G.sm.checkRegularVictory()
 			_G.sm.checkWinOrFail()
 		end
 	end