Fix engine crash in ACF mission 5 when skipping animation after killing wave 2 while the cyborg is talking
authorWuzzy <almikes@aol.com>
Thu, 27 Apr 2017 21:00:28 +0200
changeset 12361 05fe955e2763
parent 12360 a775a61e02ab
child 12362 f57053c4551d
Fix engine crash in ACF mission 5 when skipping animation after killing wave 2 while the cyborg is talking Also harden the code against double function calls
share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/backstab.lua
--- a/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/backstab.lua	Thu Apr 27 19:09:01 2017 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/backstab.lua	Thu Apr 27 21:00:28 2017 +0200
@@ -70,6 +70,9 @@
 spyHog = nil
 deployedHog = nil
 deployedDead = false
+nativesTeleported = false
+nativesIsolated = false
+hogDeployed = false
 
 cyborgHidden = false
 needToAct = 0
@@ -395,28 +398,31 @@
 end
 
 function IsolateNatives()
-  PlaceGirder(710, 299, 6)
-  PlaceGirder(690, 299, 6)
-  PlaceGirder(761, 209, 4)
-  PlaceGirder(921, 209, 4)
-  PlaceGirder(1081, 209, 4)
-  PlaceGirder(761, 189, 4)
-  PlaceGirder(921, 189, 4)
-  PlaceGirder(1081, 189, 4)
-  PlaceGirder(761, 169, 4)
-  PlaceGirder(921, 169, 4)
-  PlaceGirder(1081, 169, 4)
-  PlaceGirder(761, 149, 4)
-  PlaceGirder(921, 149, 4)
-  PlaceGirder(1081, 149, 4)
-  PlaceGirder(761, 129, 4)
-  PlaceGirder(921, 129, 4)
-  PlaceGirder(1081, 129, 4)
-  PlaceGirder(1120, 261, 2)
-  PlaceGirder(1140, 261, 2)
-  PlaceGirder(1160, 261, 2)
-  AddAmmo(deployedHog, amDEagle, 0)
-  AddAmmo(deployedHog, amFirePunch, 0)
+  if not nativesIsolated then
+    PlaceGirder(710, 299, 6)
+    PlaceGirder(690, 299, 6)
+    PlaceGirder(761, 209, 4)
+    PlaceGirder(921, 209, 4)
+    PlaceGirder(1081, 209, 4)
+    PlaceGirder(761, 189, 4)
+    PlaceGirder(921, 189, 4)
+    PlaceGirder(1081, 189, 4)
+    PlaceGirder(761, 169, 4)
+    PlaceGirder(921, 169, 4)
+    PlaceGirder(1081, 169, 4)
+    PlaceGirder(761, 149, 4)
+    PlaceGirder(921, 149, 4)
+    PlaceGirder(1081, 149, 4)
+    PlaceGirder(761, 129, 4)
+    PlaceGirder(921, 129, 4)
+    PlaceGirder(1081, 129, 4)
+    PlaceGirder(1120, 261, 2)
+    PlaceGirder(1140, 261, 2)
+    PlaceGirder(1160, 261, 2)
+    AddAmmo(deployedHog, amDEagle, 0)
+    AddAmmo(deployedHog, amFirePunch, 0)
+    nativesIsolated = true
+  end
 end
 
 function PutCGI()
@@ -443,11 +449,14 @@
 end
 
 function TeleportNatives()
-  nativePos[waterNum] = {1100, 288}
-  for i = 1, 7 do
-    if nativeDead[i] ~= true then 
-      AnimTeleportGear(natives[i], unpack(nativePos[i]))
-    end
+  if not nativesTeleported then
+     nativePos[waterNum] = {1100, 288}
+     for i = 1, 7 do
+       if nativeDead[i] ~= true then 
+         AnimTeleportGear(natives[i], unpack(nativePos[i]))
+       end
+     end
+     nativesTeleported = true
   end
 end
 
@@ -464,10 +473,13 @@
 end
 
 function DeployHog()
-  AnimSwitchHog(deployedHog)
-  AnimTeleportGear(deployedHog, unpack(deployedPos))
-  if deployedHog ~= natives[wiseNum] then
-    AnimSay(deployedHog, loc("Why me?!"), SAY_THINK, 2000)
+  if not hogDeployed then
+     AnimSwitchHog(deployedHog)
+     AnimTeleportGear(deployedHog, unpack(deployedPos))
+     if deployedHog ~= natives[wiseNum] then
+        AnimSay(deployedHog, loc("Why me?!"), SAY_THINK, 2000)
+     end
+     hogDeployed = true
   end
 end
 
@@ -546,10 +558,10 @@
 
 function SkipWave2DeadAnim()
   TeleportNatives()
-  IsolateNatives()
+  PutCircles()
   DeployHog()
+  IsolateNatives()
   HideCyborg()
-  PutCircles()
 end
 
 function SpawnPlatformCrates()
@@ -842,8 +854,7 @@
 
 function SetupPlace()
   startNativesNum = nativesNum
-  HideHog(cyborg)
-  cyborgHidden = true
+  HideCyborg()
   for i = 1, 9 do
     HideHog(cannibals[i])
     cannibalHidden[i] = true