ASA fruit01: Recognize victory if killing all enemy hogs in "flee" variant
authorWuzzy <Wuzzy2@mail.ru>
Wed, 29 May 2019 01:05:20 +0200
changeset 15082 a2d09a597fbb
parent 15081 527a7414bb44
child 15083 fb7a9b0119d3
ASA fruit01: Recognize victory if killing all enemy hogs in "flee" variant
ChangeLog.txt
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit01.lua
--- a/ChangeLog.txt	Tue May 28 22:07:56 2019 +0200
+++ b/ChangeLog.txt	Wed May 29 01:05:20 2019 +0200
@@ -69,6 +69,7 @@
  * Searching in the dust: Fix a lot of broken/stupid smuggler behaviours
  * Chasing the blue hog: Fix player not losing the race when timing out while still having the rope
  * Chasing the blue hog: Fix player winning if Crazy Runner died
+ * Bad timing: Win mission in "flee" variant if all enemy hogs are dead
  * Getting to the device: Fix clan colors
  * Various minor tweaks and bugfixes
 
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit01.lua	Tue May 28 22:07:56 2019 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit01.lua	Wed May 29 01:05:20 2019 +0200
@@ -315,6 +315,19 @@
 	return win
 end
 
+function onEscapeWinByKill(gear)
+	local win = true
+	for i=1,7 do
+		if GetHealth(yellowArmy[i].gear) or yellowArmy[i].hidden then
+			win = false
+		end
+	end
+	if GetHealth(yellow1.gear) then
+		win = false
+	end
+	return win
+end
+
 function isHeroOnLaunchPad()
 	if not hero.dead and GetX(hero.gear) < 170 and GetY(hero.gear) > 1980 and StoppedGear(hero.gear) then
 		return true
@@ -377,6 +390,15 @@
 	EndGame()
 end
 
+function escapeWinByKill(gear)
+	RemoveEventFunc(heroOnLaunchPadWithEnemies)
+	-- add stats
+	saveVariables()
+	SendStat(siGameResult, string.format(loc("%s won!"), teamB.name))
+	sendSimpleTeamRankings({teamA.name, teamD.name, teamB.name, teamC.name})
+	EndGame()
+end
+
 function heroSelect()
 	awaitingInput = false
 	FollowGear(hero.gear)
@@ -391,6 +413,8 @@
 		AddAmmo(green1.gear, amSwitch, 100)
 		AddEvent(onHeroOnLaunchPadWithEnemies, {hero.gear}, heroOnLaunchPadWithEnemies, {hero.gear}, 0)
 		AddEvent(onEscapeWin, {hero.gear}, escapeWin, {hero.gear}, 0)
+		-- Alternative victory in the "flee" mission: ALL yellow hedgehogs killed
+		AddEvent(onEscapeWinByKill, {hero.gear}, escapeWinByKill, {hero.gear}, 0)
 		local greenTeam = { green2, green3, green4, green5 }
 		for i=1,4 do
 			SetHogLevel(greenTeam[i].gear, 1)