share/hedgewars/Data/Missions/Campaign/A Classic Fairytale/backstab.lua
changeset 7253 86814ed9feab
child 7255 93cf6b3b89be
equal deleted inserted replaced
7251:cba4960b426f 7253:86814ed9feab
       
     1 loadfile(GetDataPath() .. "Scripts/Locale.lua")()
       
     2 loadfile(GetDataPath() .. "Scripts/Animate.lua")()
       
     3 
       
     4 -----------------------------Constants---------------------------------
       
     5 choiceAccepted = 1
       
     6 choiceRefused = 2
       
     7 choiceAttacked = 3
       
     8 
       
     9 choiceEliminate = 1
       
    10 choiceSpare = 2
       
    11 
       
    12 leaksNum = 1
       
    13 denseNum = 2
       
    14 waterNum = 3
       
    15 buffaloNum = 4
       
    16 chiefNum = 5
       
    17 princessNum = 6
       
    18 wiseNum = 7
       
    19 
       
    20 spyKillStage = 1
       
    21 platformStage = 2
       
    22 wave3Stage = 3
       
    23 
       
    24 tmpVar = 0
       
    25 
       
    26 nativeNames = {loc("Leaks A Lot"), loc("Dense Cloud"), loc("Fiery Water"), 
       
    27                loc("Raging Buffalo"), loc("Righteous Beard"), loc("Fell From Heaven"),
       
    28                loc("Wise Oak"), loc("Eagle Eye"), loc("Flaming Worm")}
       
    29 
       
    30 nativeHats = {"Rambo", "RobinHood", "pirate_jack", "zoo_Bunny", "IndianChief",
       
    31               "tiara", "AkuAku", "None", "None"}
       
    32 
       
    33 nativePos = {{887, 329}, {1050, 288}, {1731, 707},
       
    34              {830, 342}, {1001, 290}, {773, 340},
       
    35              {953, 305}, {347, 648}, {314, 647}}
       
    36 
       
    37 nativeDir = {"Right", "Left", "Left", 
       
    38              "Right", "Left", "Right", 
       
    39              "Left", "Right", "Right"}
       
    40 
       
    41 cannibalNames = {loc("Brain Teaser"), loc("Bone Jackson"), loc("Gimme Bones"), 
       
    42                  loc("Hedgibal Letter"), loc("Bloodpie"), loc("Scalp Muncher"),
       
    43                  loc("Back Breaker"), loc("Dahmer"), loc("Meiwes"),
       
    44                  loc("Ear Sniffer"), loc("Regurgitator"), loc("Muriel")}
       
    45 
       
    46 cannibalPos = {{3607, 1472}, {3612, 1487}, {3646, 1502}, 
       
    47                {3694, 1509}, {3746, 1525}, {3704, 1513},
       
    48                {3607, 1472}, {3612, 1487}, {3646, 1502}, 
       
    49                {3694, 1509}, {3746, 1525}, {3704, 1513}}
       
    50 
       
    51 cannibalDir = {"Left", "Left", "Left",
       
    52                "Left", "Left", "Left",
       
    53                "Left", "Left", "Left",
       
    54                "Left", "Left", "Left"}
       
    55 
       
    56 cyborgPos = {1369, 574}
       
    57 cyborgPos2 = {1308, 148}
       
    58 
       
    59 deployedPos = {2522, 1365}
       
    60 -----------------------------Variables---------------------------------
       
    61 natives = {}
       
    62 nativeDead = {}
       
    63 nativeHidden = {}
       
    64 nativeRevived = {}
       
    65 nativesNum = 0
       
    66 
       
    67 cannibals = {}
       
    68 cannibalDead = {}
       
    69 cannibalHidden = {}
       
    70 
       
    71 speakerHog = nil
       
    72 spyHog = nil
       
    73 deployedHog = nil
       
    74 
       
    75 cyborgHidden = false
       
    76 
       
    77 m2Choice = 0
       
    78 m2DenseDead = 0
       
    79 m4DenseDead = 0
       
    80 m4BuffaloDead = 0
       
    81 m4WaterDead = 0
       
    82 m4ChiefDead = 0
       
    83 m4LeaksDead = 0
       
    84 
       
    85 needRevival = false
       
    86 gearr = nil
       
    87 startElimination = 0
       
    88 stage = 0
       
    89 choice = 0
       
    90 highJumped = false
       
    91 TurnsLeft = 0
       
    92 startNativesNum = 0
       
    93 
       
    94 startAnim = {}
       
    95 afterChoiceAnim = {}
       
    96 wave2Anim = {}
       
    97 wave2DeadAnim = {}
       
    98 wave3DeadAnim = {}
       
    99 
       
   100 -----------------------------Animations--------------------------------
       
   101 function Wave2Reaction()
       
   102   local i = 1
       
   103   local gearr = nil
       
   104   while nativeDead[i] == true do
       
   105     i = i + 1
       
   106   end
       
   107   gearr = natives[i]
       
   108   if nativeDead[denseNum] ~= true and band(GetState(natives[denseNum]), gstDrowning) == 0 then
       
   109     AnimInsertStepNext({func = AnimCustomFunction, args = {dense, EmitDenseClouds, {"Left"}}})
       
   110     AnimInsertStepNext({func = AnimTurn, args = {dense, "Left"}})
       
   111   end
       
   112   if nativeDead[buffaloNum] ~= true and band(GetState(natives[buffaloNum]), gstDrowning) == 0 then
       
   113     AnimInsertStepNext({func = AnimSay, args = {natives[buffaloNum], loc("Let them have a taste of my fury!"), SAY_SHOUT, 6000}}) 
       
   114   end
       
   115   AnimInsertStepNext({func = AnimSay, args = {gearr, loc("There's more of them? When did they become so hungry?"), SAY_SHOUT, 8000}}) 
       
   116 end
       
   117 
       
   118 function EmitDenseClouds(dir)
       
   119   local dif
       
   120   if dir == "Left" then
       
   121     dif = 10
       
   122   else
       
   123     dif = -10
       
   124   end
       
   125   AnimInsertStepNext({func = AnimVisualGear, args = {natives[denseNum], GetX(natives[denseNum]) + dif, GetY(natives[denseNum]) + dif, vgtSteam, 0, true}, swh = false})
       
   126   AnimInsertStepNext({func = AnimVisualGear, args = {natives[denseNum], GetX(natives[denseNum]) + dif, GetY(natives[denseNum]) + dif, vgtSteam, 0, true}, swh = false})
       
   127   AnimInsertStepNext({func = AnimVisualGear, args = {natives[denseNum], GetX(natives[denseNum]) + dif, GetY(natives[denseNum]) + dif, vgtSteam, 0, true}, swh = false})
       
   128   AnimInsertStepNext({func = AnimWait, args = {natives[denseNum], 800}})
       
   129   AnimInsertStepNext({func = AnimVisualGear, args = {natives[denseNum], GetX(natives[denseNum]) + dif, GetY(natives[denseNum]) + dif, vgtSteam, 0, true}, swh = false})
       
   130   AnimInsertStepNext({func = AnimVisualGear, args = {natives[denseNum], GetX(natives[denseNum]) + dif, GetY(natives[denseNum]) + dif, vgtSteam, 0, true}, swh = false})
       
   131   AnimInsertStepNext({func = AnimWait, args = {natives[denseNum], 800}})
       
   132   AnimInsertStepNext({func = AnimVisualGear, args = {natives[denseNum], GetX(natives[denseNum]) + dif, GetY(natives[denseNum]) + dif, vgtSteam, 0, true}, swh = false})
       
   133 end
       
   134 
       
   135 function SaySafe()
       
   136   local i = 1
       
   137   while gearr == nil do
       
   138     if nativeDead[i] ~= true and nativeHidden[i] ~= true then
       
   139       gearr = natives[i]
       
   140     end
       
   141     i = i + 1
       
   142   end
       
   143   AnimInsertStepNext({func = AnimSay, args = {natives[wiseNum], "We are indeed.", SAY_SAY, 2500}})
       
   144   AnimInsertStepNext({func = AnimSay, args = {gearr, "I think we are safe here.", SAY_SAY, 4000}})
       
   145 end
       
   146 
       
   147 function ReviveNatives()
       
   148   for i = 1, 7 do
       
   149     if nativeHidden[i] == true and nativeDead[i] ~= true then
       
   150       RestoreHog(natives[i])
       
   151       nativeHidden[i] = false
       
   152       nativeRevived[i] = true
       
   153       AnimInsertStepNext({func = AnimOutOfNowhere, args = {natives[i], unpack(nativePos[i])}})
       
   154     end
       
   155   end
       
   156 end
       
   157 
       
   158 function WonderAlive()
       
   159   if nativeRevived[waterNum] == true then
       
   160     AnimInsertStepNext({func = AnimSay, args = {natives[waterNum], "I'm...alive? How? Why?", SAY_THINK, 3500}})
       
   161     AnimInsertStepNext({func = AnimWait, args = {natives[waterNum], 800}})
       
   162     AnimInsertStepNext({func = AnimTurn, args = {natives[waterNum], "Left"}})
       
   163     AnimInsertStepNext({func = AnimWait, args = {natives[waterNum], 800}})
       
   164     AnimInsertStepNext({func = AnimTurn, args = {natives[waterNum], "Right"}})
       
   165   end
       
   166   if nativeRevived[leaksNum] == true and nativeRevived[denseNum] == true then
       
   167     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "But why would they help us?", SAY_SAY, 4000}})
       
   168     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "It must be the aliens!", SAY_SAY, 3500}})
       
   169     AnimInsertStepNext({func = AnimSay, args = {natives[princessNum], "You just appeared out of thin air!", SAY_SAY, 5000}})
       
   170     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "But...we died!", SAY_SAY, 2500}})
       
   171     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "This must be the caves!", SAY_SAY, 3500}})
       
   172     AnimInsertStepNext({func = AnimSay, args = {natives[denseNum], "Dude, where are we?", SAY_SAY, 3000}})
       
   173     AnimInsertStepNext({func = AnimWait, args = {natives[leaksNum], 800}})
       
   174     AnimInsertStepNext({func = AnimTurn, args = {natives[leaksNum], "Right"}})
       
   175     AnimInsertStepNext({func = AnimTurn, args = {natives[denseNum], "Left"}})
       
   176     AnimInsertStepNext({func = AnimWait, args = {natives[leaksNum], 800}})
       
   177     AnimInsertStepNext({func = AnimTurn, args = {natives[leaksNum], "Left"}})
       
   178     AnimInsertStepNext({func = AnimTurn, args = {natives[denseNum], "Right"}})
       
   179     AnimInsertStepNext({func = AnimWait, args = {natives[leaksNum], 800}})
       
   180     AnimInsertStepNext({func = AnimTurn, args = {natives[leaksNum], "Right"}})
       
   181     AnimInsertStepNext({func = AnimTurn, args = {natives[denseNum], "Left"}})
       
   182     AnimInsertStepNext({func = AnimWait, args = {natives[leaksNum], 800}})
       
   183     AnimInsertStepNext({func = AnimTurn, args = {natives[leaksNum], "Left"}})
       
   184     AnimInsertStepNext({func = AnimTurn, args = {natives[denseNum], "Right"}})
       
   185     AnimInsertStepNext({func = AnimCustomFunction, swh = false, args = {natives[leaksNum], CondNeedToTurn, {natives[leaksNum], natives[princessNum]}}})
       
   186     if nativeDead[chiefNum] ~= true then
       
   187       AnimInsertStepNext({func = AnimTurn, args = {natives[chiefNum], "Right"}})
       
   188     end
       
   189   elseif nativeRevived[leaksNum] == true then
       
   190     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "Why would they do this?", SAY_SAY, 6000}})
       
   191     AnimInsertStepNext({func = AnimSay, args = {natives[wiseNum], "It must be the aliens' deed.", SAY_SAY, 5000}})
       
   192     AnimInsertStepNext({func = AnimSay, args = {natives[wiseNum], "Do not laugh, inexperienced one, for he speaks the truth!", SAY_SAY, 10000}})
       
   193     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "Yeah, sure! I died. Hillarious!", SAY_SAY, 6000}})
       
   194     AnimInsertStepNext({func = AnimSay, args = {gearr, "You're...alive!? But we saw you die!", SAY_SAY, 6000}})
       
   195     AnimInsertStepNext({func = AnimSay, args = {gearr, "???", SAY_SAY, 2000}})
       
   196     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "Wow, what a dream!", SAY_SAY, 3000}})
       
   197     if nativeDead[chiefNum] ~= true then
       
   198       AnimInsertStepNext({func = AnimTurn, args = {natives[chiefNum], "Right"}})
       
   199     end
       
   200     AnimInsertStepNext({func = AnimCustomFunction, swh = false, args = {natives[leaksNum], CondNeedToTurn, {natives[leaksNum], natives[wiseNum]}}})
       
   201     AnimInsertStepNext({func = AnimCustomFunction, swh = false, args = {natives[leaksNum], CondNeedToTurn, {natives[leaksNum], gearr}}})
       
   202   elseif nativeRevived[denseNum] == true then
       
   203     AnimInsertStepNext({func = AnimSay, args = {natives[denseNum], "Dude, that's so cool!", SAY_SAY, 3000}})
       
   204     AnimInsertStepNext({func = AnimSay, args = {natives[wiseNum], "It must be the aliens' deed.", SAY_SAY, 5000}})
       
   205     AnimInsertStepNext({func = AnimSay, args = {natives[denseNum], "But that's impossible!", SAY_SAY, 3000}})
       
   206     AnimInsertStepNext({func = AnimSay, args = {natives[wiseNum], "It was not a dream, unwise one!", SAY_SAY, 5000}})
       
   207     AnimInsertStepNext({func = AnimSay, args = {natives[denseNum], "Exactly, man! That was my dream.", SAY_SAY, 5000}})
       
   208     AnimInsertStepNext({func = AnimSay, args = {gearr, "You're...alive!? But we saw you die!", SAY_SAY,  6000}})
       
   209     AnimInsertStepNext({func = AnimSay, args = {gearr, "???", SAY_SAY, 2000}})
       
   210     AnimInsertStepNext({func = AnimSay, args = {natives[denseNum], "Dude, wow! I just had the weirdest high!", SAY_SAY, 6000}})
       
   211     if nativeDead[chiefNum] ~= true then
       
   212       AnimInsertStepNext({func = AnimTurn, args = {natives[chiefNum], "Right"}})
       
   213     end
       
   214     AnimInsertStepNext({func = AnimCustomFunction, swh = false, args = {natives[denseNum], CondNeedToTurn, {natives[denseNum], natives[wiseNum]}}})
       
   215     AnimInsertStepNext({func = AnimCustomFunction, swh = false, args = {natives[denseNum], CondNeedToTurn, {natives[denseNum], gearr}}})
       
   216   end
       
   217 end
       
   218 
       
   219 function ExplainAlive()
       
   220   if needRevival == true and m4WaterDead == 1 then
       
   221     RestoreCyborg()
       
   222     SetGearPosition(cyborg, unpack(cyborgPos))
       
   223     AnimInsertStepNext({func = AnimCustomFunction, args = {water, HideCyborg, {}}})
       
   224     AnimInsertStepNext({func = AnimSwitchHog, args = {water}})
       
   225     AnimInsertStepNext({func = AnimSay, args = {cyborg, "The answer is...entertaintment. You'll see what I mean.", SAY_SAY, 8000}})
       
   226     AnimInsertStepNext({func = AnimSay, args = {cyborg, "You're probably wondering why I bought you back...", SAY_SAY, 8000}})
       
   227   end
       
   228 end
       
   229 
       
   230 function SpyDebate()
       
   231   if m2Choice == choiceAccepted then
       
   232     spyHog = natives[denseNum]
       
   233     AnimInsertStepNext({func = AnimSay, args = {natives[wiseNum], "What shall we do with the traitor?", SAY_SAY, 6000}})
       
   234     AnimInsertStepNext({func = SetHealth, swh = false, args = {natives[denseNum], 26}})
       
   235     AnimInsertStepNext({func = AnimVisualGear, args = {GetGearPosition(natives[denseNum]), vgtExplosion, 0, true}})
       
   236     AnimInsertStepNext({func = AnimSay, args = {natives[wiseNum], "Here, let me help you!", SAY_SAY, 3000}})
       
   237     if nativeDead[chiefNum] == true then
       
   238       AnimInsertStepNext({func = AnimSay, args = {natives[princessNum], "You killed my father, you monster!", SAY_SAY, 5000}})
       
   239     end
       
   240     AnimInsertStepNext({func = AnimSay, args = {natives[denseNum], "Look, I had no choice!", SAY_SAY, 3000}})
       
   241     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "You have been giving us out to the enemy, haven't you!", SAY_SAY, 7000}})
       
   242     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "You're a pathetic liar!", SAY_SAY, 3000}})
       
   243     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "Interesting! Last time you said you killed a cannibal!", SAY_SAY, 7000}})
       
   244     AnimInsertStepNext({func = AnimSay, args = {natives[denseNum], "I told you, I just found them.", SAY_SAY, 4500}})
       
   245     AnimInsertStepNext({func = AnimCustomFunction, args = {natives[denseNum], EmitDenseClouds, {"Left"}}})
       
   246     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "Where did you get the weapons in the forest, Dense Cloud?", SAY_SAY, 8000}})
       
   247     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "Not now, Fiery Water!", SAY_SAY, 3000}})
       
   248   else
       
   249     spyHog = natives[waterNum]
       
   250     AnimInsertStepNext({func = AnimSay, args = {natives[wiseNum], "What shall we do with the traitor?", SAY_SAY, 5000}})
       
   251     AnimInsertStepNext({func = SetHealth, swh = false, args = {natives[waterNum], 26}})
       
   252     AnimInsertStepNext({func = AnimVisualGear, args = {nativePos[denseNum][1] + 50, nativePos[denseNum][2], vgtExplosion, 0, true}})
       
   253     AnimInsertStepNext({func = AnimSay, args = {natives[princessNum], "I can't believe what I'm hearing!", SAY_SAY, 5500}})
       
   254     AnimInsertStepNext({func = AnimSay, args = {natives[waterNum], "You know what? I don't even regret anything!", SAY_SAY, 7000}})
       
   255     AnimInsertStepNext({func = AnimSay, args = {natives[princessNum], "In fact, you are the only one that's been acting strangely.", SAY_SAY, 8000}})
       
   256     AnimInsertStepNext({func = AnimSay, args = {natives[waterNum], "Are you accusing me of something?", SAY_SAY, 3500}})
       
   257     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "Seems like every time you take a \"walk\", the enemy find us!", SAY_SAY, 8000}})
       
   258     AnimInsertStepNext({func = AnimSay, args = {natives[waterNum], "You know...taking a stroll.", SAY_SAY, 3500}})
       
   259     AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "Where have you been?!", SAY_SAY, 3000}})
       
   260   end
       
   261   if nativeRevived[waterNum] == true then
       
   262     AnimInsertStepNext({func = AnimSay, args = {natives[waterNum], "You won't believe what happened to me!", SAY_SAY, 5500}})
       
   263   end
       
   264   AnimInsertStepNext({func = AnimSay, args = {natives[waterNum], "Hey, guys!", SAY_SAY, 2000}})
       
   265   AnimInsertStepNext({func = AnimMove, args = {natives[waterNum], "Left", nativePos[denseNum][1] + 50, nativePos[denseNum][2]}})
       
   266   AnimInsertStepNext({func = AnimJump, args = {natives[waterNum], "back"}})
       
   267   AnimInsertStepNext({func = AnimTurn, args = {natives[waterNum], "Right"}})
       
   268   AnimInsertStepNext({func = AnimMove, args = {natives[waterNum], "Left", 1228, 412}})
       
   269   AnimInsertStepNext({func = AnimJump, args = {natives[waterNum], "long"}})
       
   270   AnimInsertStepNext({func = AnimJump, args = {natives[waterNum], "long"}})
       
   271   AnimInsertStepNext({func = AnimJump, args = {natives[waterNum], "long"}})
       
   272   AnimInsertStepNext({func = AnimTurn, args = {natives[waterNum], "Left"}})
       
   273   AnimInsertStepNext({func = AnimSay, args = {natives[wiseNum], "There must be a spy among us!", SAY_SAY, 4000}})
       
   274   AnimInsertStepNext({func = AnimSay, args = {natives[princessNum], "We made sure noone followed us!", SAY_SAY, 4000}})
       
   275   AnimInsertStepNext({func = AnimSay, args = {natives[leaksNum], "What? Here? How did they find us?!", SAY_SAY, 5000}})
       
   276 end
       
   277 
       
   278 function AnimationSetup()
       
   279   table.insert(startAnim, {func = AnimWait, args = {natives[leaksNum], 3000}})
       
   280   table.insert(startAnim, {func = AnimCustomFunction, swh = false, args = {natives[leaksNum], SaySafe, {}}})
       
   281   if needRevival == true then
       
   282     table.insert(startAnim, {func = AnimCustomFunction, swh = false, args = {cyborg, ReviveNatives, {}}})
       
   283     table.insert(startAnim, {func = AnimCustomFunction, swh = false, args = {natives[leaksNum], WonderAlive, {}}})
       
   284     table.insert(startAnim, {func = AnimCustomFunction, swh = false, args = {cyborg, ExplainAlive, {}}})
       
   285   end
       
   286   table.insert(startAnim, {func = AnimCustomFunction, swh = false, args = {natives[leaksNum], RestoreWave, {1}}})
       
   287   table.insert(startAnim, {func = AnimOutOfNowhere, args = {cannibals[1], unpack(cannibalPos[1])}})
       
   288   table.insert(startAnim, {func = AnimOutOfNowhere, args = {cannibals[2], unpack(cannibalPos[2])}})
       
   289   table.insert(startAnim, {func = AnimOutOfNowhere, args = {cannibals[3], unpack(cannibalPos[3])}})
       
   290   table.insert(startAnim, {func = AnimWait, args = {natives[leaksNum], 1000}})
       
   291   table.insert(startAnim, {func = AnimCustomFunction, swh = false, args = {natives[leaksNum], SpyDebate, {}}})
       
   292   AddSkipFunction(startAnim, SkipStartAnim, {})
       
   293 end
       
   294 
       
   295 function SetupWave2Anim()
       
   296   for i = 7, 1, -1 do
       
   297     if nativeDead[i] ~= true then
       
   298       speakerHog = natives[i]
       
   299     end
       
   300   end
       
   301   table.insert(wave2Anim, {func = AnimOutOfNowhere, args = {cannibals[4], unpack(cannibalPos[4])}})
       
   302   table.insert(wave2Anim, {func = AnimOutOfNowhere, args = {cannibals[5], unpack(cannibalPos[5])}})
       
   303   table.insert(wave2Anim, {func = AnimOutOfNowhere, args = {cannibals[6], unpack(cannibalPos[6])}})
       
   304   table.insert(wave2Anim, {func = AnimSay, args = {speakerHog, "Look out! There's more of them!", SAY_SHOUT, 5000}})
       
   305   AddSkipFunction(wave2Anim, SkipWave2Anim, {})
       
   306 end
       
   307 
       
   308 function SetupWave2DeadAnim()
       
   309   for i = 7, 1, -1 do
       
   310     if nativeDead[i] ~= true then
       
   311       deployedHog = natives[i]
       
   312     end
       
   313   end
       
   314   if nativeDead[wiseNum] ~= true and band(GetState(natives[wiseNum]), gstDrowning) == 0 then
       
   315     if nativesNum > 1 then
       
   316       table.insert(wave2DeadAnim, {func = AnimWait, args = {natives[wiseNum], 1500}})
       
   317       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "What a strange feeling!", SAY_THINK, 3000}})
       
   318       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "I need to warn the others.", SAY_THINK, 3000}})
       
   319       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "If only I had a way...", SAY_THINK, 3000}})
       
   320       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "Oh, silly me! I forgot that I'm the shaman.", SAY_THINK, 6000}})
       
   321       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {natives[wiseNum], TeleportNatives, {}}})
       
   322       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {natives[wiseNum], TurnNatives, {natives[wiseNum]}}})
       
   323       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {natives[wiseNum], CondNeedToTurn, {natives[wiseNum], deployedHog}}})
       
   324       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "I sense another wave of cannibals heading our way!", SAY_SAY, 6500}})
       
   325       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "We need to prevent their arrival!", SAY_SAY, 4500}})
       
   326       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "Go, quick!", SAY_SAY, 2500}})
       
   327       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {natives[wiseNum], DeployHog, {}}})
       
   328       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {natives[wiseNum], RestoreCyborg, {}}})
       
   329       table.insert(wave2DeadAnim, {func = AnimOutOfNowhere, swh = false, args = {cyborg, cyborgPos2[1], cyborgPos2[2]}})
       
   330       table.insert(wave2DeadAnim, {func = AnimTurn, args = {cyborg, "Left"}})
       
   331       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {cyborg, IsolateNatives, {}}})
       
   332       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {cyborg, PutCGI, {}}})
       
   333       table.insert(wave2DeadAnim, {func = AnimSay, args = {cyborg, "I want to see how it handles this!", SAY_SAY, 6000}})
       
   334       table.insert(wave2DeadAnim, {func = AnimSwitchHog, args = {deployedHog}})
       
   335       table.insert(wave2DeadAnim, {func = AnimDisappear, args = {cyborg, 0, 0}})
       
   336       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {cyborg, DeployHog, {}}})
       
   337       table.insert(wave2DeadAnim, {func = AnimCustomFunction, swh = false, args = {cyborg, HideCyborg, {}}})
       
   338     else
       
   339       table.insert(wave2DeadAnim, {func = AnimWait, args = {natives[wiseNum], 1500}})
       
   340       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "What a strange feeling!", SAY_THINK, 3000}})
       
   341       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "I sense another wave of cannibals heading my way!", SAY_THINK, 6500}})
       
   342       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "I need to prevent their arrival!", SAY_THINK, 4500}})
       
   343       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "If only I had a way...", SAY_THINK, 3000}})
       
   344       table.insert(wave2DeadAnim, {func = AnimSay, args = {natives[wiseNum], "Oh, silly me! I forgot that I'm the shaman.", SAY_THINK, 6000}})
       
   345     end
       
   346   else
       
   347     table.insert(wave2DeadAnim, {func = AnimWait, args = {cyborg, 1500}})
       
   348     table.insert(wave2DeadAnim, {func = AnimCustomFunction, swh = false, args = {cyborg, RestoreCyborg, {}}})
       
   349     table.insert(wave2DeadAnim, {func = AnimOutOfNowhere, args = {cyborg, cyborgPos2[1], cyborgPos2[2]}})
       
   350     table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {cyborg, TeleportNatives, {}}})
       
   351     table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {cyborg, TurnNatives, {cyborg}}})
       
   352     table.insert(wave2DeadAnim, {func = AnimSay, args = {cyborg, "Oh, my! This is even more entertaining than I've expected!", SAY_SAY, 7500}})
       
   353     table.insert(wave2DeadAnim, {func = AnimSay, args = {cyborg, "You might want to find a way to instantly kill arriving cannibals!", SAY_SAY, 8000}})
       
   354     table.insert(wave2DeadAnim, {func = AnimSay, args = {cyborg, "I believe there's more of them.", SAY_SAY, 4000}})
       
   355     if nativesNum > 1 then
       
   356       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {natives[wiseNum], RestoreCyborg, {}}})
       
   357       table.insert(wave2DeadAnim, {func = AnimOutOfNowhere, swh = false, args = {cyborg, cyborgPos2[1], cyborgPos2[2]}})
       
   358       table.insert(wave2DeadAnim, {func = AnimTurn, args = {cyborg, "Left"}})
       
   359       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {cyborg, IsolateNatives, {}}})
       
   360       table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {cyborg, PutCGI, {}}})
       
   361       table.insert(wave2DeadAnim, {func = AnimSay, args = {cyborg, "I want to see how it handles this!", SAY_SAY, 6000}})
       
   362     end
       
   363     table.insert(wave2DeadAnim, {func = AnimSwitchHog, args = {deployedHog}})
       
   364     table.insert(wave2DeadAnim, {func = AnimDisappear, swh = false, args = {cyborg, 0, 0}})
       
   365     table.insert(wave2DeadAnim, {func = AnimCustomFunction, args = {deployedHog, DeployHog, {}}})
       
   366     table.insert(wave2DeadAnim, {func = AnimCustomFunction, swh = false, args = {cyborg, HideCyborg, {}}})
       
   367   end
       
   368   AddSkipFunction(wave2DeadAnim, SkipWave2DeadAnim, {})
       
   369 end
       
   370 
       
   371 function IsolateNatives()
       
   372   PlaceGirder(710, 299, 6)
       
   373   PlaceGirder(690, 299, 6)
       
   374   PlaceGirder(761, 209, 4)
       
   375   PlaceGirder(921, 209, 4)
       
   376   PlaceGirder(1081, 209, 4)
       
   377   PlaceGirder(761, 189, 4)
       
   378   PlaceGirder(921, 189, 4)
       
   379   PlaceGirder(1081, 189, 4)
       
   380   PlaceGirder(761, 169, 4)
       
   381   PlaceGirder(921, 169, 4)
       
   382   PlaceGirder(1081, 169, 4)
       
   383   PlaceGirder(761, 149, 4)
       
   384   PlaceGirder(921, 149, 4)
       
   385   PlaceGirder(1081, 149, 4)
       
   386   PlaceGirder(761, 129, 4)
       
   387   PlaceGirder(921, 129, 4)
       
   388   PlaceGirder(1081, 129, 4)
       
   389   PlaceGirder(1120, 261, 2)
       
   390   PlaceGirder(1140, 261, 2)
       
   391   PlaceGirder(1160, 261, 2)
       
   392   AddAmmo(deployedHog, amDEagle, 0)
       
   393   AddAmmo(deployedHog, amFirePunch, 0)
       
   394 end
       
   395 
       
   396 function PutCGI()
       
   397   AddVisualGear(710, 299, vgtExplosion, 0, true)
       
   398   AddVisualGear(690, 299, vgtExplosion, 0, true)
       
   399   AddVisualGear(761, 209, vgtExplosion, 0, true)
       
   400   AddVisualGear(921, 209, vgtExplosion, 0, true)
       
   401   AddVisualGear(1081, 209, vgtExplosion, 0, true)
       
   402   AddVisualGear(761, 189, vgtExplosion, 0, true)
       
   403   AddVisualGear(921, 189, vgtExplosion, 0, true)
       
   404   AddVisualGear(1081, 189, vgtExplosion, 0, true)
       
   405   AddVisualGear(761, 169, vgtExplosion, 0, true)
       
   406   AddVisualGear(921, 169, vgtExplosion, 0, true)
       
   407   AddVisualGear(1081, 169, vgtExplosion, 0, true)
       
   408   AddVisualGear(761, 149, vgtExplosion, 0, true)
       
   409   AddVisualGear(921, 149, vgtExplosion, 0, true)
       
   410   AddVisualGear(1081, 149, vgtExplosion, 0, true)
       
   411   AddVisualGear(761, 129, vgtExplosion, 0, true)
       
   412   AddVisualGear(921, 129, vgtExplosion, 0, true)
       
   413   AddVisualGear(1081, 129, vgtExplosion, 0, true)
       
   414   AddVisualGear(1120, 261, vgtExplosion, 0, true)
       
   415   AddVisualGear(1140, 261, vgtExplosion, 0, true)
       
   416   AddVisualGear(1160, 261, vgtExplosion, 0, true)
       
   417 end
       
   418 
       
   419 function TeleportNatives()
       
   420   nativePos[waterNum] = {1100, 288}
       
   421   for i = 1, 7 do
       
   422     if nativeDead[i] ~= true then 
       
   423       AnimTeleportGear(natives[i], unpack(nativePos[i]))
       
   424     end
       
   425   end
       
   426 end
       
   427 
       
   428 function TurnNatives(hog)
       
   429   for i = 1, 7 do
       
   430     if nativeDead[i] == false then
       
   431       if GetX(natives[i]) < GetX(hog) then
       
   432         AnimTurn(natives[i], "Right")
       
   433       else
       
   434         AnimTurn(natives[i], "Left")
       
   435       end
       
   436     end
       
   437   end
       
   438 end
       
   439 
       
   440 function DeployHog()
       
   441   AnimSwitchHog(deployedHog)
       
   442   AnimTeleportGear(deployedHog, unpack(deployedPos))
       
   443   if deployedHog ~= natives[wiseNum] then
       
   444     AnimSay(deployedHog, "Why me?!", SAY_THINK, 2000)
       
   445   end
       
   446 end
       
   447 
       
   448 function SetupAfterChoiceAnim()
       
   449   for i = 7, 1, -1 do
       
   450     if nativeDead[i] ~= true then
       
   451       if natives[i] ~= spyHog then
       
   452         speakerHog = natives[i]
       
   453       end
       
   454     end
       
   455   end
       
   456   if choice == choiceEliminate then
       
   457     table.insert(afterChoiceAnim, {func = AnimWait, args = {speakerHog, 1500}})
       
   458     table.insert(afterChoiceAnim, {func = AnimSay, args = {speakerHog, "He won't be selling us out anymore!", SAY_SAY, 6000}})
       
   459     if nativeDead[princessNum] ~= true and m4ChiefDead == 1 then
       
   460       table.insert(afterChoiceAnim, {func = AnimSay, args = {natives[princessNum], "That's for my father!", SAY_SAY, 3500}})
       
   461     end
       
   462     table.insert(afterChoiceAnim, {func = AnimSay, args = {speakerHog, "Let's show those cannibals what we're made of!", SAY_SAY, 7000}})
       
   463   else
       
   464     table.insert(afterChoiceAnim, {func = AnimCustomFunction, swh = false, args = {natives[leaksNum], CondNeedToTurn, {speakerHog, spyHog}}})
       
   465     table.insert(afterChoiceAnim, {func = AnimSay, args = {speakerHog, "We'll spare your life for now!", SAY_SAY, 4500}})
       
   466     table.insert(afterChoiceAnim, {func = AnimSay, args = {spyHog, "May the spirits aid you in all your quests!", SAY_SAY, 7000}})
       
   467     table.insert(afterChoiceAnim, {func = AnimSay, args = {speakerHog, "I just don't want to sink to your level.", SAY_SAY, 6000}})
       
   468     table.insert(afterChoiceAnim, {func = AnimSay, args = {speakerHog, "Let's show those cannibals what we're made of!", SAY_SAY, 7000}})
       
   469   end
       
   470   table.insert(afterChoiceAnim, {func = AnimSay, args = {natives[8], "Let us help, too!", SAY_SAY, 3000}})
       
   471   table.insert(afterChoiceAnim, {func = AnimTurn, args = {speakerHog, "Left", SAY_SAY, 7000}})
       
   472   table.insert(afterChoiceAnim, {func = AnimSay, args = {speakerHog, "No. You and the rest of the tribe are safer there!", SAY_SAY, 7000}})
       
   473   AddSkipFunction(afterChoiceAnim, SkipAfterChoiceAnim, {})
       
   474 end
       
   475 
       
   476 function SetupHogDeadAnim(gear)
       
   477   hogDeadAnim = {}
       
   478   if nativesNum == 0 then
       
   479     return
       
   480   end
       
   481   local hogDeadStrings = {loc("They killed " .. gear .."! You bastards!"), 
       
   482                           loc(gear .. "! Why?!"), 
       
   483                           loc("That was just mean!"), 
       
   484                           loc("Oh no, not " .. gear .. "!"),
       
   485                           loc("Why " .. gear .. "? Why?"),
       
   486                           loc("What has " .. gear .. " ever done to you?!")}
       
   487   table.insert(hogDeadAnim, {func = AnimSay, args = {CurrentHedgehog, hogDeadStrings[7 - nativesNum], SAY_SHOUT, 4000}})
       
   488 end
       
   489 
       
   490 function AfterHogDeadAnim()
       
   491   freshDead = nil
       
   492   TurnTimeLeft = TurnTime
       
   493 end
       
   494 
       
   495 --------------------------Anim skip functions--------------------------
       
   496 
       
   497 function AfterAfterChoiceAnim()
       
   498   stage = 0
       
   499   AddEvent(CheckWaveDead, {1}, DoWaveDead, {1}, 0)
       
   500   AddAmmo(speakerHog, amSwitch, 100)
       
   501   SetGearMessage(speakerHog, 0)
       
   502   SetState(speakerHog, 0)
       
   503   TurnTimeLeft = -1
       
   504   ShowMission("Backstab", "The food bites back", "Defeat the cannibals", 1, 4000)
       
   505   SpawnCrates()
       
   506 end
       
   507 
       
   508 function SkipAfterChoiceAnim()
       
   509   SetGearMessage(CurrentHedgehog, 0)
       
   510   AnimSwitchHog(speakerHog)
       
   511 end
       
   512 
       
   513 function AfterWave2Anim()
       
   514   AddEvent(CheckWaveDead, {2}, DoWaveDead, {2}, 0)
       
   515   SetGearMessage(CurrentHedgehog, 0)
       
   516   SetState(CurrentHedgehog, 0)
       
   517   SpawnCrates()
       
   518   TurnTimeLeft = TurnTime
       
   519 end
       
   520 
       
   521 function SkipWave2DeadAnim()
       
   522   TeleportNatives()
       
   523   DeployHog()
       
   524   HideCyborg()
       
   525 end
       
   526 
       
   527 function SpawnPlatformCrates()
       
   528   SpawnAmmoCrate(2494, 1262, amMine)
       
   529   SpawnAmmoCrate(2574, 1279, amSMine)
       
   530   SpawnAmmoCrate(2575, 1267, amMine)
       
   531   SpawnAmmoCrate(2617, 1259, amSMine)
       
   532   SpawnUtilityCrate(2579, 1254, amMine)
       
   533   SpawnUtilityCrate(2478, 1243, amMine)
       
   534 end
       
   535 
       
   536 function AfterWave2DeadAnim()
       
   537   TurnsLeft = 13
       
   538   stage = platformStage
       
   539   SpawnPlatformCrates()
       
   540   AddEvent(CheckTurnsOver, {}, DoTurnsOver, {3}, 0)
       
   541   AddEvent(CheckWaveDead, {3}, DoWaveDead, {3}, 0)
       
   542   AddEvent(CheckDeployedDead, {}, DoDeployedDead, {}, 0)
       
   543   TurnTimeLeft = 0
       
   544   ShowMission("Backstab", "Drills", "You have 12 turns until the next wave arrives.|Make sure the arriving cannibals are greeted appropriately!|If the hog dies, the cause is lost.|Hint: you might want to use some mines...", 1, 12000)
       
   545 end
       
   546 
       
   547 function DoTurnsOver()
       
   548   stage = wave3Stage
       
   549   RestoreWave(3)
       
   550 end
       
   551 
       
   552 function SkipWave2Anim()
       
   553   AnimSwitchHog(speakerHog)
       
   554 end
       
   555 
       
   556 function SkipStartAnim()
       
   557   SetGearPosition(natives[waterNum], nativePos[denseNum][1] + 50, nativePos[denseNum][2])
       
   558   RestoreWave(1)
       
   559   ReviveNatives()
       
   560   SetGearMessage(CurrentHedgehog, 0)
       
   561   SetState(CurrentHedgehog, 0)
       
   562   if m2Choice == choiceAccepted then
       
   563     spyHog = natives[denseNum]
       
   564   else
       
   565     spyHog = natives[waterNum]
       
   566   end
       
   567   SetHealth(spyHog, 26)
       
   568 end
       
   569 
       
   570 function AfterStartAnim()
       
   571   AnimSwitchHog(natives[leaksNum])
       
   572   TurnTimeLeft = -1
       
   573   stage = spyKillStage
       
   574   AddEvent(CheckChoice, {}, DoChoice, {}, 0)
       
   575   AddEvent(CheckKilledOther, {}, DoKilledOther, {}, 0)
       
   576   AddEvent(CheckChoiceRefuse, {}, DoChoiceRefuse, {}, 0)
       
   577   ShowMission("Backstab", "Judas", "Kill the traitor...or spare his life!|Kill him or press [Precise]!", 1, 8000)
       
   578   ----------------------
       
   579   SetHealth(natives[leaksNum], 1)
       
   580 end
       
   581 
       
   582 -----------------------------Events------------------------------------
       
   583 function CheckTurnsOver()
       
   584   return TurnsLeft == 0
       
   585 end
       
   586 
       
   587 function CheckDeployedDead()
       
   588   return deployedDead
       
   589 end
       
   590 
       
   591 function DoDeployedDead()
       
   592   ShowMission("Backstab", "Brutus", "You have failed to save the tribe!", 0, 6000)
       
   593   ParseCommand("teamgone " .. loc("Natives"))
       
   594   ParseCommand("teamgone " .. loc("Tribe"))
       
   595   TurnTimeLeft = 0
       
   596 end
       
   597 
       
   598 function CheckChoice()
       
   599   return choice ~= 0 and tmpVar == 0
       
   600 end
       
   601 
       
   602 function CheckDeaths()
       
   603   for i = 1, 7 do
       
   604     if natives[i] ~= spyHog and band(GetState(natives[i]), gstAttacked) ~= 0 then
       
   605       return true
       
   606     end
       
   607   end
       
   608   return false
       
   609 end
       
   610 
       
   611 function DoChoice()
       
   612   RemoveEventFunc(CheckChoiceRefuse)
       
   613   SetupAfterChoiceAnim()
       
   614   AddAnim(afterChoiceAnim)
       
   615   AddFunction({func = AfterAfterChoiceAnim, args = {}})
       
   616 end
       
   617 
       
   618 function CheckChoiceRefuse()
       
   619   return highJumped == true and StoppedGear(CurrentHedgehog)
       
   620 end
       
   621 
       
   622 function DoChoiceRefuse()
       
   623   choice = choiceSpare
       
   624 end
       
   625 
       
   626 function CheckKilledOther()
       
   627   if stage ~= spyKillStage then
       
   628     return false
       
   629   end
       
   630   return (nativesNum < startNativesNum and choice ~= choiceEliminate) or
       
   631           (nativesNum < startNativesNum - 1 and choice == choiceEliminate)
       
   632 end
       
   633 
       
   634 function DoKilledOther()
       
   635   ShowMission("Backstab", "Brutus", "You have killed an innocent hedgehog!", 0, 6000)
       
   636   ParseCommand("teamgone " .. loc("Natives"))
       
   637   ParseCommand("teamgone " .. loc("Tribe"))
       
   638   TurnTimeLeft = 0
       
   639 end
       
   640 
       
   641 function CheckWaveDead(index)
       
   642   for i = (index - 1) * 3 + 1, index * 3 do
       
   643     if cannibalDead[i] ~= true or CurrentHedgehog == cannibals[i] then
       
   644       return false
       
   645     end
       
   646   end
       
   647   return true
       
   648 end
       
   649 
       
   650 function DoWaveDead(index)
       
   651   TurnTimeLeft = 0
       
   652   if index == 1 then
       
   653     RestoreWave(2)
       
   654     SetupWave2Anim()
       
   655     AddAnim(wave2Anim)
       
   656     AddFunction({func = AfterWave2Anim, args = {}})
       
   657   elseif index == 2 then
       
   658     SetupWave2DeadAnim()
       
   659     AddAnim(wave2DeadAnim)
       
   660     AddFunction({func = AfterWave2DeadAnim, args = {}})
       
   661   elseif index == 3 then
       
   662     HideNatives()
       
   663     SetupWave3DeadAnim()
       
   664     AddAnim(wave3DeadAnim)
       
   665     AddFunction({func = AfterWave3DeadAnim, args = {}})
       
   666   end
       
   667 end
       
   668 
       
   669 function HideNatives()
       
   670   for i = 1, 9 do
       
   671     if nativeDead[i] ~= true and natives[i] ~= deployedHog then
       
   672       if nativeHidden[i] ~= true then
       
   673         HideHog(natives[i])
       
   674         nativeHidden[i] = true
       
   675       end
       
   676     end
       
   677   end
       
   678 end
       
   679 
       
   680 function SetupWave3DeadAnim()
       
   681   table.insert(wave3DeadAnim, {func = AnimTurn, args = {deployedHog, "Left"}})
       
   682   table.insert(wave3DeadAnim, {func = AnimSay, args = {deployedHog, "That ought to show them!", SAY_SAY, 4000}})
       
   683   table.insert(wave3DeadAnim, {func = AnimSay, args = {deployedHog, "Guys, do you think there's more of them?", SAY_SHOUT, 7000}})
       
   684   table.insert(wave3DeadAnim, {func = AnimVisualGear, args = {deployedHog, unpack(nativePos[wiseNum]), vgtEvilTrace, 0, true}})
       
   685   table.insert(wave3DeadAnim, {func = AnimWait, args = {deployedHog, 1000}})
       
   686   table.insert(wave3DeadAnim, {func = AnimSay, args = {deployedHog, "Where are they?!", SAY_THINK, 3000}})
       
   687   table.insert(wave3DeadAnim, {func = AnimCustomFunction, args = {deployedHog, RestoreCyborg, {}}})
       
   688   table.insert(wave3DeadAnim, {func = AnimOutOfNowhere, args = {cyborg, 4040, 782}})
       
   689   table.insert(wave3DeadAnim, {func = AnimSay, args = {cyborg, "These primitive people are so funny!", SAY_THINK, 6500}})
       
   690   table.insert(wave3DeadAnim, {func = AnimMove, args = {cyborg, "Right", 4060, 0}})
       
   691   table.insert(wave3DeadAnim, {func = AnimCustomFunction, args = {deployedHog, HideCyborg, {}}})
       
   692   table.insert(wave3DeadAnim, {func = AnimSay, args = {deployedHog, "I need to find the others!", SAY_THINK, 4500}})
       
   693   table.insert(wave3DeadAnim, {func = AnimSay, args = {deployedHog, "I have to follow that alien.", SAY_THINK, 4500}})
       
   694 end
       
   695 
       
   696 function SkipWave3DeadAnim()
       
   697   AnimSwitchHog(deployedHog)
       
   698 end
       
   699 
       
   700 function AfterWave3DeadAnim()
       
   701   if nativeDead[leaksNum] == true then
       
   702     SaveCampaignVar("M5LeaksDead", "1")
       
   703   else
       
   704     SaveCampaignVar("M5LeaksDead", "0")
       
   705   end
       
   706   if nativeDead[denseNum] == true then
       
   707     SaveCampaignVar("M5DenseDead", "1")
       
   708   else
       
   709     SaveCampaignVar("M5DenseDead", "0")
       
   710   end
       
   711   if nativeDead[waterNum] == true then
       
   712     SaveCampaignVar("M5WaterDead", "1")
       
   713   else
       
   714     SaveCampaignVar("M5WaterDead", "0")
       
   715   end
       
   716   if nativeDead[buffaloNum] == true then
       
   717     SaveCampaignVar("M5BuffaloDead", "1")
       
   718   else
       
   719     SaveCampaignVar("M5BuffaloDead", "0")
       
   720   end
       
   721   if nativeDead[princessNum] == true then
       
   722     SaveCampaignVar("M5PrincessDead", "1")
       
   723   else
       
   724     SaveCampaignVar("M5PrincessDead", "0")
       
   725   end
       
   726   if nativeDead[wiseNum] == true then
       
   727     SaveCampaignVar("M5WiseDead", "1")
       
   728   else
       
   729     SaveCampaignVar("M5WiseDead", "0")
       
   730   end
       
   731   if nativeDead[chiefNum] == true then
       
   732     SaveCampaignVar("M5ChiefDead", "1")
       
   733   else
       
   734     SaveCampaignVar("M5ChiefDead", "0")
       
   735   end
       
   736   SaveCampaignVar("M5Choice", "" .. choice)
       
   737   SaveCampaignVar("Progress", "5")
       
   738 
       
   739   for i = 1, 7 do 
       
   740     if natives[i] == deployedHog then
       
   741       SaveCampaignVar("M5DeployedNum", "" .. i)
       
   742     end
       
   743   end
       
   744 
       
   745   ParseCommand("teamgone " .. loc("Tribe"))
       
   746   ParseCommand("teamgone " .. loc("Assault Team"))
       
   747   ParseCommand("teamgone " .. loc("Reinforcements"))
       
   748   ParseCommand("teamgone " .. loc("011101001"))
       
   749   TurnTimeLeft = 0
       
   750 end
       
   751 
       
   752 -----------------------------Misc--------------------------------------
       
   753 
       
   754 function SpawnCrates()
       
   755   SpawnAmmoCrate(0, 0, amDrill)
       
   756   SpawnAmmoCrate(0, 0, amGrenade)
       
   757   SpawnAmmoCrate(0, 0, amBazooka)
       
   758   SpawnAmmoCrate(0, 0, amDynamite)
       
   759   SpawnAmmoCrate(0, 0, amGrenade)
       
   760   SpawnAmmoCrate(0, 0, amMine)
       
   761   SpawnAmmoCrate(0, 0, amShotgun)
       
   762   SpawnAmmoCrate(0, 0, amFlamethrower)
       
   763   SpawnAmmoCrate(0, 0, amMolotov)
       
   764   SpawnAmmoCrate(0, 0, amSMine)
       
   765   SpawnAmmoCrate(0, 0, amMortar)
       
   766   SpawnUtilityCrate(0, 0, amRope)
       
   767   SpawnUtilityCrate(0, 0, amRope)
       
   768   SpawnUtilityCrate(0, 0, amParachute)
       
   769   SpawnUtilityCrate(0, 0, amParachute)
       
   770   SetHealth(SpawnHealthCrate(0, 0), 25)
       
   771   SetHealth(SpawnHealthCrate(0, 0), 25)
       
   772   SetHealth(SpawnHealthCrate(0, 0), 25)
       
   773   SetHealth(SpawnHealthCrate(0, 0), 25)
       
   774   SetHealth(SpawnHealthCrate(0, 0), 25)
       
   775   SetHealth(SpawnHealthCrate(0, 0), 25)
       
   776 end
       
   777 
       
   778 
       
   779 function RestoreWave(index)
       
   780   for i = (index - 1) * 3 + 1, index * 3 do
       
   781     if cannibalHidden[i] == true then
       
   782       RestoreHog(cannibals[i])
       
   783       FollowGear(cannibals[i])
       
   784       cannibalHidden[i] = false
       
   785     end
       
   786   end
       
   787 end
       
   788 
       
   789 function GetVariables()
       
   790   m2DenseDead = tonumber(GetCampaignVar("M2DenseDead"))
       
   791   m2Choice = tonumber(GetCampaignVar("M2Choice"))
       
   792   m4DenseDead = tonumber(GetCampaignVar("M4DenseDead"))
       
   793   m4LeaksDead = tonumber(GetCampaignVar("M4LeaksDead"))
       
   794   m4ChiefDead = tonumber(GetCampaignVar("M4ChiefDead"))
       
   795   m4WaterDead = tonumber(GetCampaignVar("M4WaterDead"))
       
   796   m4BuffaloDead = tonumber(GetCampaignVar("M4BuffaloDead"))
       
   797 end
       
   798 
       
   799 function HideCyborg()
       
   800   if cyborgHidden == false then
       
   801     HideHog(cyborg)
       
   802     cyborgHidden = true
       
   803   end
       
   804 end
       
   805 
       
   806 function RestoreCyborg()
       
   807   if cyborgHidden == true then
       
   808     RestoreHog(cyborg)
       
   809     cyborgHidden = false
       
   810   end
       
   811 end
       
   812 
       
   813 function SetupPlace()
       
   814   startElimination = 1
       
   815   HideHog(cyborg)
       
   816   cyborgHidden = true
       
   817   for i = 1, 9 do
       
   818     HideHog(cannibals[i])
       
   819     cannibalHidden[i] = true
       
   820   end
       
   821   if m4LeaksDead == 1 then
       
   822     HideHog(natives[leaksNum])
       
   823     nativeHidden[leaksNum] = true
       
   824     needRevival = true
       
   825   end
       
   826   if m4DenseDead == 1 then
       
   827     if m2Choice ~= choiceAccepted then
       
   828       DeleteGear(natives[denseNum])
       
   829     else
       
   830       HideHog(natives[denseNum])
       
   831       nativeHidden[denseNum] = true
       
   832       needRevival = true
       
   833     end
       
   834   end
       
   835   if m4WaterDead == 1 then
       
   836     HideHog(natives[waterNum])
       
   837     nativeHidden[waterNum] = true
       
   838     needRevival = true
       
   839   end
       
   840   if m4ChiefDead == 1 then
       
   841     DeleteGear(natives[chiefNum])
       
   842     SetGearPosition(natives[princessNum], unpack(nativePos[buffaloNum]))
       
   843     nativePos[princessNum] = nativePos[buffaloNum]
       
   844   end
       
   845   if m4BuffaloDead == 1 then
       
   846     DeleteGear(natives[buffaloNum])
       
   847   end
       
   848   startElimination = 0
       
   849   PlaceGirder(3568, 1461, 1)
       
   850   PlaceGirder(440, 523, 5)
       
   851   PlaceGirder(350, 441, 1)
       
   852   PlaceGirder(405, 553, 5)
       
   853   PlaceGirder(316, 468, 1)
       
   854   PlaceGirder(1319, 168, 0)
       
   855   startNativesNum = nativesNum
       
   856 end
       
   857 
       
   858 function SetupEvents()
       
   859 end
       
   860 
       
   861 function SetupAmmo()
       
   862   AddAmmo(natives[princessNum], amSwitch, 0)
       
   863 end
       
   864 
       
   865 function AddHogs()
       
   866 	AddTeam(loc("Natives"), 29439, "Bone", "Island", "HillBilly", "cm_birdy")
       
   867   for i = 1, 7 do
       
   868     natives[i] = AddHog(nativeNames[i], 0, 100, nativeHats[i])
       
   869   end
       
   870   nativesNum = 7
       
   871 
       
   872   AddTeam(loc("Tribe"), 29438, "Bone", "Island", "HillBilly", "cm_birdy")
       
   873   for i = 8, 9 do
       
   874     natives[i] = AddHog(nativeNames[i], 0, 100, nativeHats[i])
       
   875   end
       
   876 
       
   877 
       
   878   AddTeam(loc("Assault Team"), 14483456, "Skull", "Island", "Pirate", "cm_vampire")
       
   879   for i = 1, 6 do
       
   880     cannibals[i] = AddHog(cannibalNames[i], 1, 50, "vampirichog")
       
   881   end
       
   882 
       
   883   AddTeam(loc("Reinforcements"), 14483456, "Skull", "Island", "Pirate", "cm_vampire")
       
   884   for i = 7, 9 do
       
   885     cannibals[i] = AddHog(cannibalNames[i], 1, 50, "vampirichog")
       
   886   end
       
   887 
       
   888   AddTeam(loc("011101001"), 14483456, "ring", "UFO", "Robot", "cm_star")
       
   889   cyborg = AddHog(loc("Unit 334a$7%;.*"), 0, 200, "cyborg1")
       
   890 
       
   891   for i = 1, 9 do
       
   892     SetGearPosition(natives[i], unpack(nativePos[i]))
       
   893     AnimTurn(natives[i], nativeDir[i])
       
   894   end
       
   895 
       
   896   SetGearPosition(cyborg, 0, 0)
       
   897 
       
   898   for i = 1, 9 do
       
   899     SetGearPosition(cannibals[i], unpack(cannibalPos[i]))
       
   900     AnimTurn(cannibals[i], cannibalDir[i])
       
   901   end
       
   902 end
       
   903 
       
   904 function CondNeedToTurn(hog1, hog2)
       
   905   xl, xd = GetX(hog1), GetX(hog2)
       
   906   if xl > xd then
       
   907     AnimInsertStepNext({func = AnimTurn, args = {hog1, "Left"}})
       
   908     AnimInsertStepNext({func = AnimTurn, args = {hog2, "Right"}})
       
   909   elseif xl < xd then
       
   910     AnimInsertStepNext({func = AnimTurn, args = {hog2, "Left"}})
       
   911     AnimInsertStepNext({func = AnimTurn, args = {hog1, "Right"}})
       
   912   end
       
   913 end
       
   914 
       
   915 -----------------------------Main Functions----------------------------
       
   916 
       
   917 function onGameInit()
       
   918 	Seed = 2
       
   919 	GameFlags = gfSolidLand
       
   920 	TurnTime = 60000 
       
   921 	CaseFreq = 0
       
   922 	MinesNum = 6
       
   923 	MinesTime = 3000
       
   924 	Explosives = 6
       
   925 	Delay = 10 
       
   926   Map = "Cave"
       
   927 	Theme = "Nature"
       
   928   SuddenDeathTurns = 3000
       
   929 
       
   930   AddHogs()
       
   931   AnimInit()
       
   932 end
       
   933 
       
   934 function onGameStart()
       
   935   GetVariables()
       
   936   SetupAmmo()
       
   937   SetupPlace()
       
   938   AnimationSetup()
       
   939   SetupEvents()
       
   940   AddAnim(startAnim)
       
   941   AddFunction({func = AfterStartAnim, args = {}})
       
   942 end
       
   943 
       
   944 function onGameTick()
       
   945   AnimUnWait()
       
   946   if ShowAnimation() == false then
       
   947     return
       
   948   end
       
   949   ExecuteAfterAnimations()
       
   950   CheckEvents()
       
   951 end
       
   952 
       
   953 function onGearDelete(gear)
       
   954   for i = 1, 7 do
       
   955     if gear == natives[i] then
       
   956       nativeDead[i] = true
       
   957       nativesNum = nativesNum - 1
       
   958       if startElimination == 0 then
       
   959         freshDead = nativeNames[i]
       
   960       end
       
   961     end
       
   962   end
       
   963 
       
   964   for i = 1, 9 do
       
   965     if gear == cannibals[i] then
       
   966       cannibalDead[i] = true
       
   967     end
       
   968   end
       
   969 
       
   970   if gear == spyHog and stage == spyKillStage then
       
   971     freshDead = nil
       
   972     choice = choiceEliminate
       
   973     tmpVar = 1
       
   974   end
       
   975 end
       
   976 
       
   977 function onGearAdd(gear)
       
   978 end
       
   979 
       
   980 function onAmmoStoreInit()
       
   981   SetAmmo(amDEagle, 9, 0, 0, 0)
       
   982   SetAmmo(amSniperRifle, 4, 0, 0, 0)
       
   983   SetAmmo(amFirePunch, 9, 0, 0, 0)
       
   984   SetAmmo(amWhip, 9, 0, 0, 0)
       
   985   SetAmmo(amBaseballBat, 9, 0, 0, 0)
       
   986   SetAmmo(amHammer, 9, 0, 0, 0)
       
   987   SetAmmo(amLandGun, 9, 0, 0, 0)
       
   988   SetAmmo(amSnowball, 8, 0, 0, 0)
       
   989   SetAmmo(amGirder, 4, 0, 0, 2)
       
   990   SetAmmo(amParachute, 4, 0, 0, 2)
       
   991   SetAmmo(amSwitch, 8, 0, 0, 2)
       
   992   SetAmmo(amSkip, 8, 0, 0, 0)
       
   993   SetAmmo(amRope, 5, 0, 0, 3)
       
   994   SetAmmo(amBlowTorch, 3, 0, 0, 3)
       
   995   SetAmmo(amPickHammer, 0, 0, 0, 3)
       
   996   SetAmmo(amLowGravity, 0, 0, 0, 2)
       
   997   SetAmmo(amDynamite, 0, 0, 0, 3)
       
   998   SetAmmo(amBazooka, 4, 0, 0, 4)
       
   999   SetAmmo(amGrenade, 4, 0, 0, 4)
       
  1000   SetAmmo(amMine, 2, 0, 0, 2)
       
  1001   SetAmmo(amSMine, 2, 0, 0, 2)
       
  1002   SetAmmo(amMolotov, 2, 0, 0, 3)
       
  1003   SetAmmo(amFlamethrower, 2, 0, 0, 3)
       
  1004   SetAmmo(amShotgun, 4, 0, 0, 4)
       
  1005   SetAmmo(amTeleport, 0, 0, 0, 2)
       
  1006   SetAmmo(amDrill, 0, 0, 0, 4)
       
  1007   SetAmmo(amMortar, 0, 0, 0, 4)
       
  1008 end
       
  1009 
       
  1010 j = 0
       
  1011 
       
  1012 function onNewTurn()
       
  1013   tmpVar = 0
       
  1014   if AnimInProgress() then
       
  1015     TurnTimeLeft = -1
       
  1016     return
       
  1017   end
       
  1018 
       
  1019   if GetHogTeamName(CurrentHedgehog) == loc("Tribe") then
       
  1020     TurnTimeLeft = 0
       
  1021     return
       
  1022   end
       
  1023   TurnsLeft = TurnsLeft - 1
       
  1024 
       
  1025   if stage == spyKillStage then
       
  1026     if CurrentHedgehog == spyHog or GetHogTeamName(CurrentHedgehog) ~= loc("Natives") then
       
  1027       TurnTimeLeft = 0
       
  1028     else
       
  1029       SetGearMessage(CurrentHedgehog, 0)
       
  1030       TurnTimeLeft = -1
       
  1031     end
       
  1032   else
       
  1033     if freshDead ~= nil and GetHogTeamName(CurrentHedgehog) == loc("Natives") then
       
  1034       SetupHogDeadAnim(freshDead)
       
  1035       AddAnim(hogDeadAnim)
       
  1036       AddFunction({func = AfterHogDeadAnim, args = {}})
       
  1037     end
       
  1038   end
       
  1039 end
       
  1040 
       
  1041 function onGearDamage(gear, damage)
       
  1042 end
       
  1043 
       
  1044 function onPrecise()
       
  1045   if GameTime > 2500 then
       
  1046     SetAnimSkip(true)
       
  1047   end
       
  1048   if stage == spyKillStage then
       
  1049     highJumped = true
       
  1050   end
       
  1051 end