share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/shadow.lua
branchspacecampaign
changeset 9308 4bddcc1a1450
parent 9306 c9978ada9a3d
child 10290 42efccba0711
equal deleted inserted replaced
9296:5cc010e79431 9308:4bddcc1a1450
       
     1 HedgewarsScriptLoad("/Scripts/Locale.lua")
       
     2 HedgewarsScriptLoad("/Scripts/Animate.lua")
       
     3 
       
     4 -----------------------------Constants---------------------------------
       
     5 startStage = 0
       
     6 spyStage = 1
       
     7 wave1Stage = 2
       
     8 wave2Stage = 3
       
     9 cyborgStage = 4
       
    10 ramonStage = 5
       
    11 aloneStage = 6
       
    12 duoStage = 7
       
    13 interSpyStage = 8
       
    14 interWeakStage = 9
       
    15 acceptedReturnStage = 10
       
    16 refusedReturnStage = 11
       
    17 attackedReturnStage = 12
       
    18 loseStage = 13
       
    19 
       
    20 ourTeam = 0
       
    21 weakTeam = 1
       
    22 strongTeam = 2
       
    23 cyborgTeam = 3
       
    24 
       
    25 leaksNr = 0
       
    26 denseNr = 1
       
    27 
       
    28 choiceAccept = 1
       
    29 choiceRefuse = 2
       
    30 choiceAttack = 3
       
    31 
       
    32 HogNames = {loc("Brainiac"), loc("Corpsemonger"), loc("Femur Lover"), loc("Glark"), loc("Bonely"), loc("Rot Molester"), loc("Bloodrocutor"), loc("Muscle Dissolver"), loc("Bloodsucker")}
       
    33 
       
    34 ---POSITIONS---
       
    35 
       
    36 cannibalPos = {{3108, 1127}, 
       
    37                {2559, 1080}, {3598, 1270}, {3293, 1177}, {2623, 1336}, 
       
    38                {3418, 1336}, {3447, 1335}, {3481, 1340}, {3507, 1324}} 
       
    39 densePos = {2776, 1177}
       
    40 leaksPos = {2941, 1172}
       
    41 cyborgPos = {1113, 1818}
       
    42 
       
    43 ---Animations
       
    44 
       
    45 startDialogue = {}
       
    46 weaklingsAnim = {}
       
    47 stronglingsAnim = {}
       
    48 acceptedAnim = {}
       
    49 acceptedSurvivedFinalAnim = {}
       
    50 acceptedDiedFinalAnim = {}
       
    51 refusedAnim = {}
       
    52 refusedFinalAnim = {}
       
    53 attackedAnim = {}
       
    54 attackedFinalAnim = {}
       
    55 
       
    56 -----------------------------Variables---------------------------------
       
    57 lastHogTeam = ourTeam
       
    58 lastOurHog = leaksNr
       
    59 lastEnemyHog = 0
       
    60 stage = 0
       
    61 choice = 0
       
    62 
       
    63 brainiacDead = false
       
    64 cyborgHidden = false
       
    65 leaksHidden = false
       
    66 denseHidden = false
       
    67 cyborgAttacked = false
       
    68 retryReturn = false
       
    69 shotgunTaken = false
       
    70 grenadeTaken = false
       
    71 spikyDead = false
       
    72 ramonDead = false
       
    73 denseDead = false
       
    74 leaksDead = false
       
    75 ramonHidden = false
       
    76 spikyHidden = false
       
    77 grenadeUsed = false
       
    78 shotgunUsed = false
       
    79 
       
    80 
       
    81 hogNr = {}
       
    82 cannibalDead = {}
       
    83 isHidden = {}
       
    84 
       
    85 
       
    86 --------------------------Anim skip functions--------------------------
       
    87 function AfterRefusedAnim()
       
    88   SpawnUtilityCrate(2045, 1575, amSwitch)
       
    89   SpawnUtilityCrate(2365, 1495, amShotgun)
       
    90   SpawnUtilityCrate(2495, 1519, amGrenade)
       
    91   SpawnUtilityCrate(2620, 1524, amRope)
       
    92   ShowMission(loc("The Shadow Falls"), loc("The Showdown"), loc("Save Leaks A Lot!|Hint: The Switch utility might be of help to you."), 1, 6000)
       
    93   RemoveEventFunc(CheckDenseDead)
       
    94   AddEvent(CheckStronglingsDead, {}, DoStronglingsDeadRefused, {}, 0)
       
    95   AddAmmo(cannibals[6], amGrenade, 1)
       
    96   AddAmmo(cannibals[7], amGrenade, 1)
       
    97   AddAmmo(cannibals[8], amGrenade, 1)
       
    98   AddAmmo(cannibals[9], amGrenade, 1)
       
    99   stage = ramonStage
       
   100   SwitchHog(cannibals[9])
       
   101   FollowGear(ramon)
       
   102   TurnTimeLeft = 0
       
   103   SetGearMessage(ramon, 0)
       
   104   SetGearMessage(leaks, 0)
       
   105   AnimWait(ramon, 1)
       
   106   AddFunction({func = HideHog, args = {cyborg}})
       
   107 end
       
   108 
       
   109 function SkipRefusedAnim()
       
   110   RefusedStart()
       
   111   AnimSetGearPosition(dense, 2645, 1146)
       
   112   AnimSetGearPosition(ramon, 2218, 1675)
       
   113   AnimSetGearPosition(spiky, 2400, 1675)
       
   114 end
       
   115 
       
   116 function AfterStartDialogue()
       
   117   stage = spyStage
       
   118   ShowMission(loc("The Shadow Falls"), loc("Play with me!"), loc("Defend yourself!|Hint: You can get tips on using weapons by moving your mouse over them in the weapon selection menu"), 1, 6000)
       
   119   TurnTimeLeft = TurnTime
       
   120 end
       
   121 
       
   122 
       
   123 function StartSkipFunc()
       
   124   SetState(cannibals[1], 0)
       
   125   AnimTurn(leaks, "Right")
       
   126   AnimSwitchHog(leaks)
       
   127   SetInputMask(0xFFFFFFFF)
       
   128 end
       
   129 
       
   130 function AfterWeaklingsAnim()
       
   131   AddAmmo(cannibals[2], amShotgun, 1)
       
   132   AddAmmo(cannibals[2], amGrenade, 1)
       
   133   AddAmmo(cannibals[3], amShotgun, 1)
       
   134   AddAmmo(cannibals[3], amGrenade, 1)
       
   135   AddAmmo(cannibals[4], amShotgun, 1)
       
   136   AddAmmo(cannibals[4], amGrenade, 1)
       
   137   AddAmmo(cannibals[5], amShotgun, 1)
       
   138   AddAmmo(cannibals[5], amGrenade, 1)
       
   139   AddAmmo(leaks, amSkip, 4)
       
   140   AddAmmo(dense, amSkip, 4)
       
   141   AddEvent(CheckWeaklingsKilled, {}, DoWeaklingsKilled, {}, 0)
       
   142   SetHealth(SpawnHealthCrate(2757, 1030), 50)
       
   143   SetHealth(SpawnHealthCrate(2899, 1009), 50)
       
   144   stage = wave1Stage
       
   145   SwitchHog(dense)
       
   146   SetGearMessage(dense, 0)
       
   147   SetGearMessage(leaks, 0)
       
   148   TurnTimeLeft = TurnTime
       
   149   ShowMission(loc("The Shadow Falls"), loc("Why do you not like me?"), loc("Obliterate them!|Hint: You might want to take cover..."), 1, 6000)
       
   150 end
       
   151 
       
   152 function SkipWeaklingsAnim()
       
   153   for i = 2, 5 do
       
   154     if isHidden[cannibals[i]] == true then
       
   155       RestoreHog(cannibals[i])
       
   156       isHidden[cannibals[i]] = false
       
   157     end
       
   158     AnimSetGearPosition(cannibals[i], unpack(cannibalPos[i]))
       
   159     SetState(cannibals[i], 0)
       
   160   end
       
   161   SetInputMask(0xFFFFFFFF)
       
   162 end
       
   163 
       
   164 function AfterStronglingsAnim()
       
   165   stage = cyborgStage
       
   166   ShowMission(loc("The Shadow Falls"), loc("The Dilemma"), loc("Choose your side! If you want to join the strange man, walk up to him.|Otherwise, walk away from him. If you decide to att...nevermind..."), 1, 8000)
       
   167   AddEvent(CheckChoice, {}, DoChoice, {}, 0)
       
   168   AddEvent(CheckRefuse, {}, DoRefuse, {}, 0)
       
   169   AddEvent(CheckAccept, {}, DoAccept, {}, 0)
       
   170   AddEvent(CheckConfront, {}, DoConfront, {}, 0)
       
   171   AddAmmo(dense, amSwitch, 0)
       
   172   AddAmmo(dense, amSkip, 0)
       
   173   AddAmmo(leaks, amSwitch, 0)
       
   174   AddAmmo(leaks, amSkip, 0)
       
   175   SetHealth(SpawnHealthCrate(2557, 1030), 50)
       
   176   SetHealth(SpawnHealthCrate(3599, 1009), 50)
       
   177   TurnTimeLeft = 0
       
   178 end
       
   179 
       
   180 function SkipStronglingsAnim()
       
   181   for i = 6, 9 do
       
   182     if isHidden[cannibals[i]] == true then
       
   183       RestoreHog(cannibals[i])
       
   184       isHidden[cannibals[i]] = false
       
   185     end
       
   186     AnimSetGearPosition(cannibals[i], unpack(cannibalPos[i]))
       
   187     SetState(cannibals[i], 0)
       
   188   end
       
   189   if cyborgHidden == true then
       
   190     RestoreHog(cyborg)
       
   191     cyborgHidden = false
       
   192   end
       
   193   SetState(cyborg, 0)
       
   194   SetState(dense, 0)
       
   195   AnimSetGearPosition(dense, 1350, 1315)
       
   196   FollowGear(dense)
       
   197   HogTurnLeft(dense, true)
       
   198   AnimSetGearPosition(cyborg, 1250, 1315)
       
   199   SwitchHog(dense)
       
   200   SetInputMask(0xFFFFFFFF)
       
   201 end
       
   202 
       
   203 function RestartReturnAccepted()
       
   204   retryReturn = false
       
   205   AnimSetGearPosition(dense, 1350, 1310)
       
   206   AddAmmo(dense, amGirder, 2)
       
   207   AddAmmo(dense, amParachute, 2)
       
   208   ShowMission(loc("The Shadow Falls"), loc("The walk of Fame"), loc("Return to Leaks A Lot! If you get stuck, press [Precise] to try again!"), 1, 6000)
       
   209   RemoveEventFunc(CheckNeedGirder)
       
   210   RemoveEventFunc(CheckNeedWeapons)
       
   211   AddEvent(CheckNeedGirder, {}, DoNeedGirder, {}, 0)
       
   212   AddEvent(CheckNeedWeapons, {}, DoNeedWeapons, {}, 0)
       
   213 end
       
   214 
       
   215 
       
   216 function AfterAcceptedAnim()
       
   217   stage = acceptedReturnStage
       
   218   SpawnAmmoCrate(1370, 810, amGirder)
       
   219   SpawnAmmoCrate(1300, 810, amParachute)
       
   220   ShowMission(loc("The Shadow Falls"), loc("The walk of Fame"), loc("Return to Leaks A Lot! If you get stuck, press [Precise] to try again!"), 1, 6000)
       
   221   AddEvent(CheckTookWeapons, {}, DoTookWeapons, {}, 0)
       
   222   AddEvent(CheckNeedGirder, {}, DoNeedGirder, {}, 0)
       
   223   AddEvent(CheckNeedWeapons, {}, DoNeedWeapons, {}, 0)
       
   224   AddEvent(CheckRestartReturnAccepted, {}, RestartReturnAccepted, {}, 1)
       
   225   RemoveEventFunc(CheckDenseDead)
       
   226   SwitchHog(dense)
       
   227   AnimWait(dense, 1)
       
   228   AddFunction({func = HideHog, args = {cyborg}})
       
   229 end
       
   230 
       
   231 function SkipAcceptedAnim()
       
   232   AnimSetGearPosition(cyborg, unpack(cyborgPos))
       
   233   SetState(cyborg, gstInvisible)
       
   234   AnimSwitchHog(dense)
       
   235   SetInputMask(0xFFFFFFFF)
       
   236 end
       
   237 
       
   238 function AfterAttackedAnim()
       
   239   stage = aloneStage
       
   240   ShowMission(loc("The Shadow Falls"), loc("The Individualist"), loc("Defeat the cannibals!|Grenade hint: set the timer with [1-5], aim with [Up]/[Down] and hold [Space] to set power"), 1, 8000)
       
   241   AddAmmo(cannibals[6], amGrenade, 1)
       
   242   AddAmmo(cannibals[6], amFirePunch, 0)
       
   243   AddAmmo(cannibals[6], amBaseballBat, 0)
       
   244   AddAmmo(cannibals[7], amGrenade, 1)
       
   245   AddAmmo(cannibals[7], amFirePunch, 0)
       
   246   AddAmmo(cannibals[7], amBaseballBat, 0)
       
   247   AddAmmo(cannibals[8], amGrenade, 1)
       
   248   AddAmmo(cannibals[8], amFirePunch, 0)
       
   249   AddAmmo(cannibals[8], amBaseballBat, 0)
       
   250   AddAmmo(cannibals[9], amGrenade, 1)
       
   251   AddAmmo(cannibals[9], amFirePunch, 0)
       
   252   AddAmmo(cannibals[9], amBaseballBat, 0)
       
   253   SetGearMessage(leaks, 0)
       
   254   TurnTimeLeft = TurnTime
       
   255   AddEvent(CheckStronglingsDead, {}, DoStronglingsDeadAttacked, {}, 0)
       
   256   SwitchHog(leaks)
       
   257   AnimWait(dense, 1)
       
   258   AddFunction({func = HideHog, args = {cyborg}})
       
   259 end
       
   260 
       
   261 function SkipAttackedAnim()
       
   262   if denseDead == false then
       
   263     DeleteGear(dense)
       
   264   end
       
   265   SpawnAmmoCrate(2551, 994, amGrenade)
       
   266   SpawnAmmoCrate(3551, 994, amGrenade)
       
   267   SpawnAmmoCrate(3392, 1101, amShotgun)
       
   268   SpawnAmmoCrate(3192, 1101, amShotgun)
       
   269   AnimSetGearPosition(cyborg, unpack(cyborgPos))
       
   270   SetState(cyborg, gstInvisible)
       
   271   AnimSwitchHog(leaks)
       
   272   SetInputMask(0xFFFFFFFF)
       
   273 end
       
   274 
       
   275   
       
   276 -----------------------------Animations--------------------------------
       
   277 
       
   278 function SpawnCrates()
       
   279   SpawnAmmoCrate(2551, 994, amGrenade)
       
   280   SpawnAmmoCrate(3551, 994, amGrenade)
       
   281   SpawnAmmoCrate(3392, 1101, amShotgun)
       
   282   SpawnAmmoCrate(3192, 1101, amShotgun)
       
   283   return true
       
   284 end
       
   285 
       
   286 function EmitDenseClouds(anim, dir)
       
   287   local dif
       
   288   if dir == "Left" then 
       
   289     dif = 10
       
   290   else
       
   291     dif = -10
       
   292   end
       
   293   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense) + dif, GetY(dense) + dif, vgtSteam, 0, true}, swh = false})
       
   294   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense) + dif, GetY(dense) + dif, vgtSteam, 0, true}, swh = false})
       
   295   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense) + dif, GetY(dense) + dif, vgtSteam, 0, true}, swh = false})
       
   296   AnimInsertStepNext({func = AnimWait, args = {dense, 800}})
       
   297   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense) + dif, GetY(dense) + dif, vgtSteam, 0, true}, swh = false})
       
   298   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense) + dif, GetY(dense) + dif, vgtSteam, 0, true}, swh = false})
       
   299   AnimInsertStepNext({func = AnimWait, args = {dense, 800}})
       
   300   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense) + dif, GetY(dense) + dif, vgtSteam, 0, true}, swh = false})
       
   301 end
       
   302 
       
   303 function BlowDenseCloud()
       
   304   AnimInsertStepNext({func = DeleteGear, args = {dense}, swh = false}) 
       
   305   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense), GetY(dense), vgtBigExplosion, 0, true}, swh = false})
       
   306   AnimInsertStepNext({func = AnimWait, args = {dense, 1200}})
       
   307   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense) + 20, GetY(dense), vgtExplosion, 0, true}, swh = false})
       
   308   AnimInsertStepNext({func = AnimWait, args = {dense, 100}})
       
   309   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense) + 10, GetY(dense), vgtExplosion, 0, true}, swh = false})
       
   310   AnimInsertStepNext({func = AnimWait, args = {dense, 100}})
       
   311   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense) - 10, GetY(dense), vgtExplosion, 0, true}, swh = false})
       
   312   AnimInsertStepNext({func = AnimWait, args = {dense, 100}})
       
   313   AnimInsertStepNext({func = AnimVisualGear, args = {dense, GetX(dense) - 20, GetY(dense), vgtExplosion, 0, true}, swh = false})
       
   314 end
       
   315 
       
   316 function SetupAcceptedSurvivedFinalAnim()
       
   317   table.insert(acceptedSurvivedFinalAnim, {func = AnimCustomFunction, args = {dense, CondNeedToTurn, {leaks, dense}}})
       
   318   table.insert(acceptedSurvivedFinalAnim, {func = AnimSay, args = {leaks, loc("Pfew! That was close!"), SAY_SAY, 3000}})
       
   319   if grenadeUsed and shotgunUsed then
       
   320     table.insert(acceptedSurvivedFinalAnim, {func = AnimSay, args = {leaks, loc("Where did you get the exploding apples and the magic bow that shoots many arrows?"), SAY_SAY, 9000}})
       
   321   elseif grenadeUsed then
       
   322     table.insert(acceptedSurvivedFinalAnim, {func = AnimSay, args = {leaks, loc("Where did you get the exploding apples?"), SAY_SAY, 6000}})
       
   323   elseif shotgunUsed then
       
   324     table.insert(acceptedSurvivedFinalAnim, {func = AnimSay, args = {leaks, loc("Where did you get the magic bow that shoots many arrows?"), SAY_SAY, 8000}})
       
   325   else
       
   326     table.insert(acceptedSurvivedFinalAnim, {func = AnimSay, args = {leaks, loc("Did you warn the village?"), SAY_SAY, 4000}})
       
   327     table.insert(acceptedSurvivedFinalAnim, {func = AnimSay, args = {dense, loc("No, I came back to help you out..."), SAY_SAY, 5000}})
       
   328   end
       
   329   if grenadeUsed or shotgunUsed then
       
   330     table.insert(acceptedSurvivedFinalAnim, {func = AnimSay, args = {dense, loc("Uhm...I met one of them and took his weapons."), SAY_SAY, 5000}})
       
   331   end
       
   332   table.insert(acceptedSurvivedFinalAnim, {func = AnimSay, args = {dense, loc("We should head back to the village now."), SAY_SAY, 5000}})
       
   333 end
       
   334 
       
   335 function AnimationSetup()
       
   336   table.insert(startDialogue, {func = AnimWait, args = {dense, 4000}})
       
   337   table.insert(startDialogue, {func = AnimCaption, args = {leaks, loc("After the shock caused by the enemy spy, Leaks A Lot and Dense Cloud went hunting to relax."), 6000}})
       
   338   table.insert(startDialogue, {func = AnimCaption, args = {leaks, loc("Little did they know that this hunt will mark them forever..."), 4000}})
       
   339   table.insert(startDialogue, {func = AnimSay, args = {leaks, loc("I have no idea where that mole disappeared...Can you see it?"), SAY_SAY, 9000}})
       
   340   table.insert(startDialogue, {func = AnimSay, args = {dense, loc("Nope. It was one fast mole, that's for sure."), SAY_SAY, 5000}}) 
       
   341   table.insert(startDialogue, {func = AnimCustomFunction, args = {dense, EmitDenseClouds, {startDialogue, "Right"}}})
       
   342   table.insert(startDialogue, {func = AnimWait, args = {dense, 2000}})
       
   343   table.insert(startDialogue, {func = AnimSay, args = {leaks, loc("Please, stop releasing your \"smoke signals\"!"), SAY_SAY, 5000}})
       
   344   table.insert(startDialogue, {func = AnimSay, args = {leaks, loc("You're terrorizing the forest...We won't catch anything like this!"), SAY_SAY, 6000}})
       
   345   table.insert(startDialogue, {func = AnimSay, args = {leaks, loc("..."), SAY_THINK, 1000}})
       
   346   table.insert(startDialogue, {func = AnimGiveState, args = {cannibals[1], 0}, swh = false})
       
   347   table.insert(startDialogue, {func = AnimOutOfNowhere, args = {cannibals[1], unpack(cannibalPos[1])}, swh = false})
       
   348   table.insert(startDialogue, {func = AnimTurn, args = {leaks, "Right"}})
       
   349   table.insert(startDialogue, {func = AnimTurn, args = {cannibals[1], "Right"}})
       
   350   table.insert(startDialogue, {func = AnimWait, args = {cannibals[1], 1000}})
       
   351   table.insert(startDialogue, {func = AnimTurn, args = {cannibals[1], "Left"}})
       
   352   table.insert(startDialogue, {func = AnimWait, args = {cannibals[1], 1000}})
       
   353   table.insert(startDialogue, {func = AnimTurn, args = {cannibals[1], "Right"}})
       
   354   table.insert(startDialogue, {func = AnimSay, args = {cannibals[1], loc("I can't believe it worked!"), SAY_THINK, 3500}})
       
   355   table.insert(startDialogue, {func = AnimSay, args = {cannibals[1], loc("That shaman sure knows what he's doing!"), SAY_THINK, 6000}})
       
   356   table.insert(startDialogue, {func = AnimSay, args = {cannibals[1], loc("Yeah...I think it's a 'he', lol."), SAY_THINK, 5000}})
       
   357   table.insert(startDialogue, {func = AnimSay, args = {leaks, loc("It wants our brains!"), SAY_SHOUT, 3000}})
       
   358   table.insert(startDialogue, {func = AnimTurn, args = {cannibals[1], "Left"}})
       
   359   table.insert(startDialogue, {func = AnimSay, args = {cannibals[1], loc("Not you again! My head still hurts from last time!"), SAY_SHOUT, 6000}})
       
   360   table.insert(startDialogue, {func = AnimSwitchHog, args = {leaks}})
       
   361   AddSkipFunction(startDialogue, StartSkipFunc, {})
       
   362 
       
   363   table.insert(weaklingsAnim, {func = AnimGearWait, args = {leaks, 1000}})
       
   364   table.insert(weaklingsAnim, {func = AnimCustomFunction, args = {leaks, CondNeedToTurn, {leaks, dense}}})
       
   365   table.insert(weaklingsAnim, {func = AnimSay, args = {leaks, loc("Did you see him coming?"), SAY_SAY, 3500}})
       
   366   table.insert(weaklingsAnim, {func = AnimSay, args = {dense, loc("No. Where did he come from?"), SAY_SAY, 3500}})
       
   367   table.insert(weaklingsAnim, {func = AnimCustomFunction, args = {leaks, UnHideWeaklings, {}}})
       
   368   table.insert(weaklingsAnim, {func = AnimOutOfNowhere, args = {cannibals[2], unpack(cannibalPos[2])}})
       
   369   table.insert(weaklingsAnim, {func = AnimGiveState, args = {cannibals[2], 0}})
       
   370   table.insert(weaklingsAnim, {func = AnimWait, args = {leaks, 400}})
       
   371   table.insert(weaklingsAnim, {func = AnimGiveState, args = {cannibals[3], 0}})
       
   372   table.insert(weaklingsAnim, {func = AnimOutOfNowhere, args = {cannibals[3], unpack(cannibalPos[3])}})
       
   373   table.insert(weaklingsAnim, {func = AnimWait, args = {leaks, 400}})
       
   374   table.insert(weaklingsAnim, {func = AnimGiveState, args = {cannibals[4], 0}})
       
   375   table.insert(weaklingsAnim, {func = AnimOutOfNowhere, args = {cannibals[4], unpack(cannibalPos[4])}})
       
   376   table.insert(weaklingsAnim, {func = AnimWait, args = {leaks, 400}})
       
   377   table.insert(weaklingsAnim, {func = AnimGiveState, args = {cannibals[5], 0}})
       
   378   table.insert(weaklingsAnim, {func = AnimOutOfNowhere, args = {cannibals[5], unpack(cannibalPos[5])}})
       
   379   table.insert(weaklingsAnim, {func = AnimWait, args = {leaks, 400}})
       
   380   table.insert(weaklingsAnim, {func = AnimSay, args = {cannibals[3], loc("Are we there yet?"), SAY_SAY, 4000}}) 
       
   381   table.insert(weaklingsAnim, {func = AnimSay, args = {dense, loc("This must be some kind of sorcery!"), SAY_SHOUT, 3500}})
       
   382   table.insert(weaklingsAnim, {func = AnimSwitchHog, args = {leaks}})
       
   383   AddSkipFunction(weaklingsAnim, SkipWeaklingsAnim, {})
       
   384 
       
   385   table.insert(stronglingsAnim, {func = AnimGearWait, args = {leaks, 1000}})
       
   386   table.insert(stronglingsAnim, {func = AnimCustomFunction, args = {leaks, UnHideStronglings, {}}})
       
   387   table.insert(stronglingsAnim, {func = AnimCustomFunction, args = {leaks, CondNeedToTurn, {leaks, dense}}})
       
   388   table.insert(stronglingsAnim, {func = AnimGiveState, args = {leaks, 0}})
       
   389   table.insert(stronglingsAnim, {func = AnimGiveState, args = {dense, 0}})
       
   390   table.insert(stronglingsAnim, {func = AnimSay, args = {leaks, loc("I thought their shaman died when he tried our medicine!"), SAY_SAY, 7000}})
       
   391   table.insert(stronglingsAnim, {func = AnimSay, args = {dense, loc("I saw it with my own eyes!"), SAY_SAY, 4000}})
       
   392   table.insert(stronglingsAnim, {func = AnimSay, args = {leaks, loc("Then how do they keep appearing?"), SAY_SAY, 4000}})
       
   393   table.insert(stronglingsAnim, {func = AnimSay, args = {leaks, loc("It's impossible to communicate with the spirits without a shaman."), SAY_SAY, 7000}})
       
   394   table.insert(stronglingsAnim, {func = AnimSay, args = {dense, loc("We need to warn the village."), SAY_SAY, 3500}})
       
   395   table.insert(stronglingsAnim, {func = AnimGiveState, args = {cannibals[6], 0}})
       
   396   table.insert(stronglingsAnim, {func = AnimOutOfNowhere, args = {cannibals[6], unpack(cannibalPos[6])}})
       
   397   table.insert(stronglingsAnim, {func = AnimWait, args = {leaks, 400}})
       
   398   table.insert(stronglingsAnim, {func = AnimGiveState, args = {cannibals[7], 0}})
       
   399   table.insert(stronglingsAnim, {func = AnimOutOfNowhere, args = {cannibals[7], unpack(cannibalPos[7])}})
       
   400   table.insert(stronglingsAnim, {func = AnimWait, args = {leaks, 400}})
       
   401   table.insert(stronglingsAnim, {func = AnimGiveState, args = {cannibals[8], 0}})
       
   402   table.insert(stronglingsAnim, {func = AnimOutOfNowhere, args = {cannibals[8], unpack(cannibalPos[8])}})
       
   403   table.insert(stronglingsAnim, {func = AnimWait, args = {leaks, 400}})
       
   404   table.insert(stronglingsAnim, {func = AnimGiveState, args = {cannibals[9], 0}})
       
   405   table.insert(stronglingsAnim, {func = AnimOutOfNowhere, args = {cannibals[9], unpack(cannibalPos[9])}})
       
   406   table.insert(stronglingsAnim, {func = AnimWait, args = {leaks, 400}})
       
   407   table.insert(stronglingsAnim, {func = AnimSay, args = {cannibals[7], loc("What a ride!"), SAY_SHOUT, 2000}})
       
   408   table.insert(stronglingsAnim, {func = AnimTurn, args = {leaks, "Right"}})
       
   409   table.insert(stronglingsAnim, {func = AnimWait, args = {leaks, 700}})
       
   410   table.insert(stronglingsAnim, {func = AnimTurn, args = {leaks, "Left"}})
       
   411   table.insert(stronglingsAnim, {func = AnimSay, args = {leaks, loc("We can't defeat them!"), SAY_THINK, 3000}})
       
   412   table.insert(stronglingsAnim, {func = AnimSay, args = {leaks, loc("I'll hold them off while you return to the village!"), SAY_SAY, 6000}})
       
   413   table.insert(stronglingsAnim, {func = AnimFollowGear, args = {cyborg}, swh = false})
       
   414   table.insert(stronglingsAnim, {func = AnimCaption, args = {cyborg, loc("30 minutes later...")}, swh = false})
       
   415   table.insert(stronglingsAnim, {func = AnimWait, args = {cyborg, 2000}})
       
   416   table.insert(stronglingsAnim, {func = AnimSetGearPosition, args = {dense, 1420, 1315}})
       
   417   table.insert(stronglingsAnim, {func = AnimMove, args = {dense, "Left", 1400, 0}})
       
   418   table.insert(stronglingsAnim, {func = AnimCustomFunction, args = {dense, EmitDenseClouds, {stronglingsAnim, "Left"}}})
       
   419   table.insert(stronglingsAnim, {func = AnimMove, args = {dense, "Left", 1350, 0}})
       
   420   table.insert(stronglingsAnim, {func = AnimOutOfNowhere, args = {cyborg, 1250, 1320}})
       
   421   table.insert(stronglingsAnim, {func = AnimRemoveState, args = {cyborg, gstInvisible}})
       
   422   table.insert(stronglingsAnim, {func = AnimGearWait, args = {cyborg, 2000}})
       
   423   table.insert(stronglingsAnim, {func = AnimSay, args = {cyborg, loc("Greetings, cloudy one!"), SAY_SAY, 3000}})
       
   424   table.insert(stronglingsAnim, {func = AnimSay, args = {cyborg, loc("I have come to make you an offering..."), SAY_SAY, 6000}})
       
   425   table.insert(stronglingsAnim, {func = AnimSay, args = {cyborg, loc("You are given the chance to turn your life around..."), SAY_SAY, 6000}})
       
   426   table.insert(stronglingsAnim, {func = AnimSay, args = {cyborg, loc("If you agree to provide the information we need, you will be spared!"), SAY_SAY, 7000}})
       
   427   table.insert(stronglingsAnim, {func = AnimSay, args = {cyborg, loc("Have no illusions, your tribe is dead, indifferent of your choice."), SAY_SAY, 7000}})
       
   428   table.insert(stronglingsAnim, {func = AnimSay, args = {cyborg, loc("If you decide to help us, though, we will no longer need to find a new governor for the island."), SAY_SAY, 8000}})
       
   429   table.insert(stronglingsAnim, {func = AnimSay, args = {cyborg, loc("If you know what I mean..."), SAY_SAY, 3000}})
       
   430   table.insert(stronglingsAnim, {func = AnimSay, args = {cyborg, loc("So? What will it be?"), SAY_SAY, 3000}})
       
   431   table.insert(stronglingsAnim, {func = AnimSwitchHog, args = {dense}})
       
   432   AddSkipFunction(stronglingsAnim, SkipStronglingsAnim, {})
       
   433 
       
   434   table.insert(acceptedAnim, {func = AnimSay, args = {cyborg, loc("Great choice, Steve! Mind if I call you that?"), SAY_SAY, 7000}})
       
   435   table.insert(acceptedAnim, {func = AnimSay, args = {dense, loc("Whatever floats your boat..."), SAY_SAY, 4500}})
       
   436   table.insert(acceptedAnim, {func = AnimSay, args = {cyborg, loc("Great! You will be contacted soon for assistance."), SAY_SAY, 6000}})
       
   437   table.insert(acceptedAnim, {func = AnimSay, args = {cyborg, loc("In the meantime, take these and return to your \"friend\"!"), SAY_SAY, 6000}})
       
   438   table.insert(acceptedAnim, {func = AnimGiveState, args = {cyborg, gstInvisible}})
       
   439   table.insert(acceptedAnim, {func = AnimDisappear, args = {cyborg, unpack(cyborgPos)}})
       
   440   table.insert(acceptedAnim, {func = AnimSwitchHog, args = {dense}})
       
   441   AddSkipFunction(acceptedAnim, SkipAcceptedAnim, {}) 
       
   442 
       
   443   table.insert(acceptedDiedFinalAnim, {func = AnimSay, args = {leaks, loc("Pfew! That was close!"), SAY_THINK, 3000}})
       
   444   table.insert(acceptedDiedFinalAnim, {func = AnimSay, args = {leaks, loc("Your death will not be in vain, Dense Cloud!"), SAY_THINK, 5000}})
       
   445   table.insert(acceptedDiedFinalAnim, {func = AnimSay, args = {dense, loc("You will be avenged!"), SAY_SAY, 3000}})
       
   446 
       
   447   table.insert(refusedAnim, {func = AnimSay, args = {cyborg, loc("I see..."), SAY_SAY, 2000}})
       
   448   table.insert(refusedAnim, {func = AnimSay, args = {cyborg, loc("Remember this, pathetic animal: when the day comes, you will regret your blind loyalty!"), SAY_SAY, 8000}})
       
   449   table.insert(refusedAnim, {func = AnimSay, args = {cyborg, loc("You just committed suicide..."), SAY_SAY, 5000}})
       
   450   table.insert(refusedAnim, {func = AnimDisappear, args = {cyborg, unpack(cyborgPos)}})
       
   451   table.insert(refusedAnim, {func = AnimGiveState, args = {cyborg, gstInvisible}})
       
   452   table.insert(refusedAnim, {func = AnimSay, args = {dense, loc("If you say so..."), SAY_THINK, 3000}})
       
   453   table.insert(refusedAnim, {func = AnimFollowGear, args = {cyborg}, swh = false})
       
   454   table.insert(refusedAnim, {func = AnimWait, args = {cyborg, 700}})
       
   455   table.insert(refusedAnim, {func = AnimCustomFunction, args = {dense, RefusedStart, {}}})
       
   456   table.insert(refusedAnim, {func = AnimOutOfNowhere, args = {dense, 2645, 1146}})
       
   457   table.insert(refusedAnim, {func = AnimOutOfNowhere, args = {ramon, 2218, 1675}})
       
   458   table.insert(refusedAnim, {func = AnimOutOfNowhere, args = {spiky, 2400, 1675}})
       
   459   table.insert(refusedAnim, {func = AnimTurn, args = {spiky, "Left"}})
       
   460   table.insert(refusedAnim, {func = AnimWait, args = {cyborg, 1700}})
       
   461   table.insert(refusedAnim, {func = AnimTurn, args = {spiky, "Right"}})
       
   462   table.insert(refusedAnim, {func = AnimWait, args = {cyborg, 1700}})
       
   463   table.insert(refusedAnim, {func = AnimTurn, args = {spiky, "Left"}})
       
   464   table.insert(refusedAnim, {func = AnimSay, args = {spiky, loc("Dude, we really need a new shaman..."), SAY_SAY, 4000}})
       
   465   AddSkipFunction(refusedAnim, SkipRefusedAnim, {})
       
   466 
       
   467   table.insert(refusedFinalAnim, {func = AnimSay, args = {leaks, loc("It's over..."), SAY_SAY, 2000}})
       
   468   table.insert(refusedFinalAnim, {func = AnimSay, args = {leaks, loc("Let's head back to the village!"), SAY_SAY, 4000}})
       
   469 
       
   470   table.insert(attackedAnim, {func = AnimCustomFunction, args = {dense, CondNeedToTurn, {cyborg, dense}}})
       
   471   table.insert(attackedAnim, {func = AnimCustomFunction, args = {cyborg, SetHealth, {cyborg, 200}}})
       
   472   table.insert(attackedAnim, {func = AnimWait, args = {cyborg, 2000}})
       
   473   table.insert(attackedAnim, {func = AnimSay, args = {cyborg, loc("Really?! You thought you could harm me with your little toys?"), SAY_SAY, 7000}})
       
   474   table.insert(attackedAnim, {func = AnimSay, args = {cyborg, loc("You're pathetic! You are not worthy of my attention..."), SAY_SAY, 6000}})
       
   475   table.insert(attackedAnim, {func = AnimSay, args = {cyborg, loc("Actually, you aren't worthy of life! Take this..."), SAY_SAY, 5000}})
       
   476   table.insert(attackedAnim, {func = AnimCustomFunction, args = {dense, BlowDenseCloud, {}}, swh = false})
       
   477   table.insert(attackedAnim, {func = AnimWait, args = {cyborg, 2000}})
       
   478   table.insert(attackedAnim, {func = AnimSay, args = {cyborg, loc("Incredible..."), SAY_SAY, 3000}})
       
   479   table.insert(attackedAnim, {func = AnimDisappear, args = {cyborg, unpack(cyborgPos)}})
       
   480   table.insert(attackedAnim, {func = AnimGiveState, args = {cyborg, gstInvisible}})
       
   481   table.insert(attackedAnim, {func = AnimSwitchHog, args = {leaks}})
       
   482   table.insert(attackedAnim, {func = AnimSay, args = {leaks, loc("I wonder where Dense Cloud is..."), SAY_THINK, 4000}})
       
   483   table.insert(attackedAnim, {func = AnimSay, args = {leaks, loc("I can't wait any more, I have to save myself!"), SAY_THINK, 5000}})
       
   484   table.insert(attackedAnim, {func = AnimCustomFunction, args = {leaks, SpawnCrates, {}}})
       
   485   table.insert(attackedAnim, {func = AnimWait, args = {leaks, 1500}})
       
   486   table.insert(attackedAnim, {func = AnimSay, args = {leaks, loc("Where are all these crates coming from?!"), SAY_THINK, 5500}})
       
   487   AddSkipFunction(attackedAnim, SkipAttackedAnim, {})
       
   488   
       
   489   table.insert(attackedFinalAnim, {func = AnimWait, args = {leaks, 2000}})
       
   490   table.insert(attackedFinalAnim, {func = AnimSay, args = {leaks, loc("I have to get back to the village!"), SAY_THINK, 5000}})
       
   491   table.insert(attackedFinalAnim, {func = AnimSay, args = {leaks, loc("Dense Cloud must have already told them everything..."), SAY_THINK, 7000}})
       
   492 
       
   493 end
       
   494 
       
   495 
       
   496 -----------------------------Misc--------------------------------------
       
   497 
       
   498 
       
   499 function RefusedStart()
       
   500   if ramonHidden == true then
       
   501     RestoreHog(ramon)
       
   502     ramonHidden = false
       
   503   end
       
   504   if spikyHidden == true then
       
   505     RestoreHog(spiky)
       
   506     spikyHidden = false
       
   507   end
       
   508   SetState(ramon, 0)
       
   509   SetState(spiky, 0)
       
   510   SetGearMessage(dense, 0)
       
   511   SetGearMessage(ramon, 0)
       
   512   SetGearMessage(spiky, 0)
       
   513 end
       
   514 
       
   515 function AddHogs()
       
   516 	AddTeam(loc("Natives"), 29439, "Bone", "Island", "HillBilly", "cm_birdy")
       
   517   ramon = AddHog(loc("Ramon"), 0, 100, "rasta")
       
   518 	leaks = AddHog(loc("Leaks A Lot"), 0, 100, "Rambo")
       
   519   dense = AddHog(loc("Dense Cloud"), 0, 100, "RobinHood")
       
   520   spiky = AddHog(loc("Spiky Cheese"), 0, 100, "hair_yellow")
       
   521 
       
   522   AddTeam(loc("Weaklings"), 14483456, "Skull", "Island", "Pirate","cm_vampire")
       
   523   cannibals = {}
       
   524   cannibals[1] = AddHog(loc("Brainiac"), 5, 20, "Zombi")
       
   525 
       
   526   for i = 2, 5 do
       
   527     cannibals[i] = AddHog(HogNames[i], 1, 20, "Zombi")
       
   528     hogNr[cannibals[i]] = i - 2
       
   529   end
       
   530 
       
   531   AddTeam(loc("Stronglings"), 14483456, "Skull", "Island", "Pirate","cm_vampire")
       
   532 
       
   533   for i = 6, 9 do
       
   534     cannibals[i] = AddHog(HogNames[i], 2, 30, "vampirichog")
       
   535     hogNr[cannibals[i]] = i - 2
       
   536   end
       
   537 
       
   538   AddTeam(loc("011101001"), 14483456, "ring", "UFO", "Robot", "cm_star")
       
   539   cyborg = AddHog(loc("Y3K1337"), 0, 200, "cyborg1")
       
   540 end
       
   541 
       
   542 function PlaceHogs()
       
   543   HogTurnLeft(leaks, true)
       
   544 
       
   545   for i = 2, 9 do
       
   546     AnimSetGearPosition(cannibals[i], unpack(cyborgPos))
       
   547     AnimTurn(cannibals[i], "Left")
       
   548     cannibalDead[i] = false
       
   549   end
       
   550 
       
   551   AnimSetGearPosition(cannibals[1], cannibalPos[1][1], cannibalPos[1][2])
       
   552   AnimTurn(cannibals[1], "Left")
       
   553 
       
   554   AnimSetGearPosition(cyborg, cyborgPos[1], cyborgPos[2])
       
   555   AnimSetGearPosition(ramon, 2218, 1675)
       
   556   AnimSetGearPosition(skiky, 2400, 1675)
       
   557   AnimSetGearPosition(dense, densePos[1], densePos[2])
       
   558   AnimSetGearPosition(leaks, leaksPos[1], leaksPos[2]) 
       
   559 end
       
   560 
       
   561 function VisiblizeHogs()
       
   562   for i = 1, 9 do
       
   563     SetState(cannibals[i], gstInvisible)
       
   564   end
       
   565   SetState(cyborg, gstInvisible)
       
   566   SetState(ramon, gstInvisible)
       
   567   SetState(spiky, gstInvisible)
       
   568 end
       
   569 
       
   570 function CondNeedToTurn(hog1, hog2)
       
   571   xl, xd = GetX(hog1), GetX(hog2)
       
   572   if xl > xd then
       
   573     AnimInsertStepNext({func = AnimTurn, args = {hog1, "Left"}})
       
   574     AnimInsertStepNext({func = AnimTurn, args = {hog2, "Right"}})
       
   575   elseif xl < xd then
       
   576     AnimInsertStepNext({func = AnimTurn, args = {hog2, "Left"}})
       
   577     AnimInsertStepNext({func = AnimTurn, args = {hog1, "Right"}})
       
   578   end
       
   579 end
       
   580 
       
   581 function HideHogs()
       
   582   for i = 2, 9 do
       
   583     HideHog(cannibals[i])
       
   584     isHidden[cannibals[i]] = true
       
   585   end
       
   586   HideHog(cyborg)
       
   587   cyborgHidden = true
       
   588   HideHog(ramon)
       
   589   HideHog(spiky)
       
   590   ramonHidden = true
       
   591   spikyHidden = true
       
   592 end
       
   593 
       
   594 function HideStronglings()
       
   595   for i = 6, 9 do
       
   596     HideHog(cannibals[i])
       
   597     isHidden[cannibals[i]] = true
       
   598   end
       
   599 end
       
   600 
       
   601 function UnHideWeaklings()
       
   602   for i = 2, 5 do
       
   603     RestoreHog(cannibals[i])
       
   604     isHidden[cannibals[i]] = false
       
   605     SetState(cannibals[i], gstInvisible)
       
   606   end
       
   607 end
       
   608 
       
   609 function UnHideStronglings()
       
   610   for i = 6, 9 do
       
   611     RestoreHog(cannibals[i])
       
   612     isHidden[cannibals[i]] = false
       
   613     SetState(cannibals[i], gstInvisible)
       
   614   end
       
   615   RestoreHog(cyborg)
       
   616   cyborgHidden = false
       
   617   SetState(cyborg, gstInvisible)
       
   618 end
       
   619 
       
   620 function ChoiceTaken()
       
   621   SetGearMessage(CurrentHedgehog, 0)
       
   622   if choice == choiceAccept then
       
   623     AddAnim(acceptedAnim)
       
   624     AddFunction({func = AfterAcceptedAnim, args = {}})
       
   625   elseif choice == choiceRefuse then
       
   626     AddAnim(refusedAnim)
       
   627     AddFunction({func = AfterRefusedAnim, args = {}})
       
   628   else
       
   629     AddAnim(attackedAnim)
       
   630     AddFunction({func = AfterAttackedAnim, args = {}})
       
   631   end
       
   632 end
       
   633 
       
   634 function KillCyborg()
       
   635   RestoreHog(cyborg)
       
   636   DeleteGear(cyborg)
       
   637   TurnTimeLeft = 0
       
   638 end
       
   639 -----------------------------Events------------------------------------
       
   640 
       
   641 function CheckBrainiacDead()
       
   642   return brainiacDead
       
   643 end
       
   644 
       
   645 function DoBrainiacDead()
       
   646   TurnTimeLeft = 0
       
   647   SetGearMessage(CurrentHedgehog, 0)
       
   648   AddAnim(weaklingsAnim)
       
   649   AddFunction({func = AfterWeaklingsAnim, args = {}})
       
   650   stage = interSpyStage
       
   651 end
       
   652   
       
   653 function CheckWeaklingsKilled()
       
   654   for i = 2, 5 do
       
   655     if cannibalDead[i] == false then
       
   656       return false
       
   657     end
       
   658   end
       
   659   return true
       
   660 end
       
   661 
       
   662 function DoWeaklingsKilled()
       
   663   SetGearMessage(CurrentHedgehog, 0)
       
   664   AddAnim(stronglingsAnim)
       
   665   AddFunction({func = AfterStronglingsAnim, args = {}})
       
   666   stage = interWeakStage
       
   667   ParseCommand("teamgone " .. loc("Weaklings"))
       
   668 end
       
   669 
       
   670 function CheckRefuse()
       
   671   return GetX(dense) > 1400 and StoppedGear(dense)
       
   672 end
       
   673 
       
   674 function DoRefuse()
       
   675   choice = choiceRefuse
       
   676 end
       
   677 
       
   678 function CheckAccept()
       
   679   return GetX(dense) < 1300 and StoppedGear(dense)
       
   680 end
       
   681 
       
   682 function DoAccept()
       
   683   choice = choiceAccept
       
   684 end
       
   685 
       
   686 function CheckConfront()
       
   687   return cyborgAttacked and StoppedGear(dense)
       
   688 end
       
   689 
       
   690 function DoConfront()
       
   691   choice = choiceAttack
       
   692 end
       
   693 
       
   694 function CheckChoice()
       
   695   return choice ~= 0
       
   696 end
       
   697 
       
   698 function DoChoice()
       
   699   RemoveEventFunc(CheckConfront)
       
   700   RemoveEventFunc(CheckAccept)
       
   701   RemoveEventFunc(CheckRefuse)
       
   702   ChoiceTaken()
       
   703 end
       
   704 
       
   705 function CheckNeedGirder()
       
   706   return GetX(dense) > 1640 and StoppedGear(dense)
       
   707 end
       
   708 
       
   709 function DoNeedGirder()
       
   710   ShowMission(loc("The Shadow Falls"), loc("Under Construction"), loc("To place a girder, select it, use [Left] and [Right] to select angle and length, place with [Left Click]"), 1, 6000)
       
   711 end
       
   712 
       
   713 function CheckNeedWeapons()
       
   714   return GetX(dense) > 2522 and StoppedGear(dense)
       
   715 end
       
   716 
       
   717 function DoNeedWeapons()
       
   718   grenadeCrate = SpawnAmmoCrate(2550, 800, amGrenade)
       
   719   shotgunCrate = SpawnAmmoCrate(2610, 850, amShotgun)
       
   720   AddCaption(loc("A little gift from the cyborgs"))
       
   721 end
       
   722 
       
   723 function CheckTookWeapons()
       
   724   return shotgunTaken and grenadeTaken
       
   725 end
       
   726 
       
   727 function DoTookWeapons()
       
   728   ShowMission(loc("The Shadow Falls"), loc("The guardian"), loc("Protect yourselves!|Grenade hint: set the timer with [1-5], aim with [Up]/[Down] and hold [Space] to set power"), 1, 8000)
       
   729   AddAmmo(dense, amSkip, 100)
       
   730   AddAmmo(dense, amSwitch, 100)
       
   731   AddAmmo(leaks, amSkip, 100)
       
   732   AddAmmo(leaks, amSwitch, 100)
       
   733   stage = duoStage
       
   734   RemoveEventFunc(CheckNeedGirder)
       
   735   RemoveEventFunc(CheckNeedWeapons)
       
   736   RemoveEventFunc(CheckRestartReturnAccepted)
       
   737   AddEvent(CheckStronglingsDead, {}, DoStronglingsDead, {}, 0)
       
   738   AddAmmo(cannibals[6], amGrenade, 2)
       
   739   AddAmmo(cannibals[6], amShotgun, 2)
       
   740   AddAmmo(cannibals[7], amGrenade, 2)
       
   741   AddAmmo(cannibals[7], amShotgun, 2)
       
   742   AddAmmo(cannibals[8], amGrenade, 2)
       
   743   AddAmmo(cannibals[8], amShotgun, 2)
       
   744   AddAmmo(cannibals[9], amGrenade, 2)
       
   745   AddAmmo(cannibals[9], amShotgun, 2)
       
   746   SetGearMessage(leaks, 0)
       
   747   SetGearMessage(dense, 0)
       
   748   TurnTimeLeft = TurnTime
       
   749 end
       
   750 
       
   751 function DoStronglingsDead()
       
   752   SetGearMessage(CurrentHedgehog, 0)
       
   753   if denseDead == true then
       
   754     AddAnim(acceptedDiedFinalAnim)
       
   755     SaveCampaignVar("M2DenseDead", "1")
       
   756   else
       
   757     SetupAcceptedSurvivedFinalAnim()
       
   758     AddAnim(acceptedSurvivedFinalAnim)
       
   759     SaveCampaignVar("M2DenseDead", "0")
       
   760   end
       
   761   SaveCampaignVar("M2RamonDead", "0")
       
   762   SaveCampaignVar("M2SpikyDead", "0")
       
   763   AddFunction({func = KillCyborg, args = {}})
       
   764   if progress and progress<2 then
       
   765     SaveCampaignVar("Progress", "2")
       
   766   end
       
   767   SaveCampaignVar("M2Choice", "" .. choice)
       
   768 end
       
   769 
       
   770 function DoStronglingsDeadRefused()
       
   771   if denseDead == true then
       
   772     SaveCampaignVar("M2DenseDead", "1")
       
   773   else
       
   774     SaveCampaignVar("M2DenseDead", "0")
       
   775   end
       
   776   if ramonDead == true then
       
   777     SaveCampaignVar("M2RamonDead", "1")
       
   778   else
       
   779     SaveCampaignVar("M2RamonDead", "0")
       
   780   end
       
   781   if spikyDead == true then
       
   782     SaveCampaignVar("M2SpikyDead", "1")
       
   783   else
       
   784     SaveCampaignVar("M2SpikyDead", "0")
       
   785   end
       
   786   AddAnim(refusedFinalAnim)
       
   787   AddFunction({func = KillCyborg, args = {}})
       
   788   if progress and progress<2 then
       
   789     SaveCampaignVar("Progress", "2")
       
   790   end
       
   791   SaveCampaignVar("M2Choice", "" .. choice)
       
   792 end
       
   793 
       
   794 function DoStronglingsDeadAttacked()
       
   795   SaveCampaignVar("M2DenseDead", "1")
       
   796   SaveCampaignVar("M2RamonDead", "0")
       
   797   SaveCampaignVar("M2SpikyDead", "0")
       
   798   if progress and progress<2 then
       
   799     SaveCampaignVar("Progress", "2")
       
   800   end
       
   801   SaveCampaignVar("M2Choice", "" .. choice)
       
   802   AddAnim(attackedFinalAnim)
       
   803   AddFunction({func = KillCyborg, args = {}})
       
   804 end
       
   805 
       
   806 function CheckStronglingsDead()
       
   807   if leaksDead == true then
       
   808     return false
       
   809   end
       
   810   for i = 6, 9 do
       
   811     if cannibalDead[i] == false then
       
   812       return false
       
   813     end
       
   814   end
       
   815   return true
       
   816 end
       
   817 
       
   818 function CheckLeaksDead()
       
   819   return leaksDead
       
   820 end
       
   821 
       
   822 function DoDead()
       
   823   AddCaption(loc("...and so the cyborgs took over the world..."))
       
   824   stage = loseStage
       
   825   TurnTimeLeft = 0
       
   826   ParseCommand("teamgone " .. loc("Natives"))
       
   827 end
       
   828 
       
   829 function CheckDenseDead()
       
   830   return denseDead and choice ~= choiceAttack 
       
   831 end
       
   832 
       
   833 function CheckRestartReturnAccepted()
       
   834   return retryReturn
       
   835 end
       
   836 
       
   837 -----------------------------Main Functions----------------------------
       
   838 
       
   839 function onGameInit()
       
   840 	Seed = 334 
       
   841 	GameFlags = gfSolidLand + gfDisableWind + gfPerHogAmmo
       
   842 	TurnTime = 50000 
       
   843 	CaseFreq = 0
       
   844 	MinesNum = 0
       
   845 	MinesTime = 3000
       
   846 	Explosives = 0
       
   847 	Delay = 10 
       
   848 	Map = "A_Classic_Fairytale_shadow"
       
   849 	Theme = "Nature"
       
   850     SuddenDeathTurns = 3000
       
   851 
       
   852   AddHogs()
       
   853   PlaceHogs()
       
   854   VisiblizeHogs()
       
   855   
       
   856   AnimInit()
       
   857   AnimationSetup()
       
   858 end
       
   859 
       
   860 function onGameStart()
       
   861   progress = tonumber(GetCampaignVar("Progress"))
       
   862   HideHogs()
       
   863   AddAmmo(leaks, amSwitch, 100)
       
   864   AddAmmo(dense, amSwitch, 100)
       
   865   AddEvent(CheckLeaksDead, {}, DoDead, {}, 0)
       
   866   AddEvent(CheckDenseDead, {}, DoDead, {}, 0)
       
   867   AddAnim(startDialogue)
       
   868   AddFunction({func = AfterStartDialogue, args = {}})
       
   869   AddEvent(CheckBrainiacDead, {}, DoBrainiacDead, {}, 0)
       
   870   ShowMission(loc("The Shadow Falls"), loc("The First Encounter"), loc("Survive!|Hint: Cinematics can be skipped with the [Precise] key."), 1, 0)
       
   871 end
       
   872 
       
   873 function onGameTick()
       
   874   AnimUnWait()
       
   875   if ShowAnimation() == false then
       
   876     return
       
   877   end
       
   878   ExecuteAfterAnimations()
       
   879   CheckEvents()
       
   880 end
       
   881 
       
   882 function onGearDelete(gear)
       
   883   if gear == cannibals[1] then
       
   884     brainiacDead = true
       
   885   elseif gear == grenadeCrate then
       
   886     grenadeTaken = true
       
   887   elseif gear == shotgunCrate then
       
   888     shotgunTaken = true
       
   889   elseif gear == dense then
       
   890     denseDead = true
       
   891   elseif gear == leaks then
       
   892     leaksDead = true
       
   893   elseif gear == ramon then
       
   894     ramonDead = true
       
   895   elseif gear == spiky then
       
   896     spikyDead = true
       
   897   else
       
   898     for i = 2, 9 do
       
   899       if gear == cannibals[i] then
       
   900         cannibalDead[i] = true
       
   901       end
       
   902     end
       
   903   end
       
   904 end
       
   905 
       
   906 function onGearAdd(gear)
       
   907   if GetGearType(gear) == gtGrenade and GetHogTeamName(CurrentHedgehog) == loc("Natives") then
       
   908     grenadeUsed = true
       
   909   elseif GetGearType(gear) == gtShotgunShot and GetHogTeamName(CurrentHedgehog) == loc("Natives") then
       
   910     shotgunUsed = true
       
   911   end
       
   912 end
       
   913 
       
   914 function onAmmoStoreInit()
       
   915   SetAmmo(amDEagle, 9, 0, 0, 0)
       
   916   SetAmmo(amSniperRifle, 6, 0, 0, 0)
       
   917   SetAmmo(amFirePunch, 3, 0, 0, 0)
       
   918   SetAmmo(amWhip, 4, 0, 0, 0)
       
   919   SetAmmo(amBaseballBat, 4, 0, 0, 0)
       
   920   SetAmmo(amHammer, 2, 0, 0, 0)
       
   921   SetAmmo(amLandGun, 1, 0, 0, 0)
       
   922   SetAmmo(amSnowball, 7, 0, 0, 0)
       
   923   SetAmmo(amGirder, 0, 0, 0, 2)
       
   924   SetAmmo(amParachute, 0, 0, 0, 2)
       
   925   SetAmmo(amGrenade, 0, 0, 0, 3)
       
   926   SetAmmo(amShotgun, 0, 0, 0, 3)
       
   927   SetAmmo(amSwitch, 0, 0, 0, 8)
       
   928   SetAmmo(amRope, 0, 0, 0, 6)
       
   929 end
       
   930 
       
   931 function onNewTurn()
       
   932   if AnimInProgress() then
       
   933     TurnTimeLeft = -1
       
   934 --  elseif stage == interSpyStage and GetHogTeamName(CurrentHedgehog) ~= loc("Natives") then
       
   935 --    TurnTimeLeft = 0
       
   936 --    SetState(CurrentHedgehog, gstInvisible)
       
   937   elseif stage == cyborgStage then
       
   938     if CurrentHedgehog ~= dense then
       
   939       TurnTimeLeft = 0
       
   940     else
       
   941       TurnTimeLeft = -1
       
   942     end
       
   943   elseif stage == acceptedReturnStage then
       
   944     SwitchHog(dense)
       
   945     FollowGear(dense)
       
   946     TurnTimeLeft = -1
       
   947   end
       
   948 end
       
   949 
       
   950 function onGearDamage(gear, damage)
       
   951   if gear == cyborg and stage == cyborgStage then
       
   952     cyborgAttacked = true
       
   953   end
       
   954 end
       
   955 
       
   956 function onPrecise()
       
   957   if GameTime > 2500 and AnimInProgress() then
       
   958     SetAnimSkip(true)
       
   959     return
       
   960   end
       
   961   if stage == acceptedReturnStage then
       
   962     retryReturn = true
       
   963 --  else
       
   964 --    for i = 1, 9 do
       
   965 --      DeleteGear(cannibals[i])
       
   966 --    end
       
   967   end
       
   968 end
       
   969