Fix ACF Eplilogue becoming unplayble when all hogs except the traitor have died
authorWuzzy <almikes@aol.com>
Fri, 28 Apr 2017 00:21:16 +0200
changeset 12370 92b4bab79c26
parent 12369 5857936921ec
child 12376 2b1dd699b371
Fix ACF Eplilogue becoming unplayble when all hogs except the traitor have died
share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/epil.lua
--- a/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/epil.lua	Thu Apr 27 23:47:44 2017 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/epil.lua	Fri Apr 28 00:21:16 2017 +0200
@@ -71,6 +71,7 @@
 startAnim = {}
 
 gearDead = {}
+hogDead = {}
 --------------------------Anim skip functions--------------------------
 function SkipStartAnim()
   SetGearMessage(CurrentHedgehog, 0)
@@ -380,8 +381,17 @@
   CheckEvents()
 end
 
+function onGearAdd(gear)
+  if GetGearType(gear) == gtHedgehog then
+    hogDead[gear] = false
+  end
+end
+
 function onGearDelete(gear)
   gearDead[gear] = true
+  if GetGearType(gear) == gtHedgehog then
+    hogDead[gear] = true
+  end
 end
 
 function onAmmoStoreInit()
@@ -421,12 +431,22 @@
   SetAmmo(amWhip, 9, 0, 0, 0)
 end
 
+function IsEveryoneExceptTraitorDead()
+  for id, isDead in pairs(hogDead) do
+    if id ~= traitor and not isDead then
+      return false
+    end
+  end
+  return true
+end
+
 function onNewTurn()
   if AnimInProgress() then
     TurnTimeLeft = -1
     return
   end
-  if CurrentHedgehog == traitor then
+  -- Don't allow player to play with traitor, except when it is the final hog left
+  if CurrentHedgehog == traitor and not IsEveryoneExceptTraitorDead() then
     EndTurn(true)
   else
     TurnTimeLeft = -1