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