share/hedgewars/Data/Missions/Campaign/A Classic Fairytale/first_blood.lua
changeset 7203 37661b2a7b64
child 7209 f1976889e1a7
equal deleted inserted replaced
7201:dc17ffdf0702 7203:37661b2a7b64
       
     1 loadfile(GetDataPath() .. "Scripts/Animate.lua")()
       
     2 
       
     3 -----------------------------Variables---------------------------------
       
     4 startDialogue = {}
       
     5 damageAnim = {}
       
     6 onShroomAnim = {}
       
     7 onFlowerAnim = {}
       
     8 tookParaAnim = {}
       
     9 tookPunchAnim = {}
       
    10 onMoleHeadAnim = {}
       
    11 tookRope2Anim = {}
       
    12 challengeAnim = {}
       
    13 challengeFailedAnim = {}
       
    14 challengeCompletedAnim = {}
       
    15 beforeKillAnim = {}
       
    16 closeCannim = {}
       
    17 cannKilledAnim = {}
       
    18 cannKilledEarlyAnim = {}
       
    19 princessDamagedAnim = {}
       
    20 elderDamagedAnim = {}
       
    21 pastMoleHeadAnim = {}
       
    22 
       
    23 
       
    24 targets = {}
       
    25 crates = {}
       
    26 targXdif2 = {2755, 2638, 2921, 2664, 2973, 3162, 3268, 3067, 3588, 3759, 3062, 1300}
       
    27 targYdif2 = {1197, 1537, 1646, 1852, 1857, 1804, 1538, 1173, 984, 1290, 1167, 1183}
       
    28 targXdif1 = {2749, 2909, 2770, 2892, 2836, 3296, 3567, 3066, 1558, 1305}
       
    29 targYdif1 = {1179, 1313, 1734, 1603, 1441, 1522, 982, 1190, 1152, 1259}
       
    30 targetPosX = {{821, 866, 789}, {614, 656, 638}, {1238, 1237, 1200}, {1558, 1596, 1631}, {2190, 2396, 2457}}
       
    31 targetPosY = {{1342, 1347, 1326}, {1112, 1121, 1061}, {1152, 1111, 1111}, {1132, 1136, 1280}, {1291, 1379, 1317}}
       
    32 crateNum = {10, 12}
       
    33 
       
    34 
       
    35 stage = 1
       
    36 cratesCollected = 0
       
    37 chalTries = 0
       
    38 targetsDestroyed = 0
       
    39 targsWave = 1
       
    40 tTime = -1
       
    41 difficulty = 0
       
    42 
       
    43 cannibalVisible = false
       
    44 cannibalKilles = false
       
    45 youngdamaged = false
       
    46 youngKilled = false
       
    47 elderDamaged = false
       
    48 princessDamaged = false
       
    49 elderKilled = false
       
    50 princessKilled = false
       
    51 rope1Taken = false
       
    52 paraTaken = false
       
    53 rope2Taken = false
       
    54 punchTaken = false
       
    55 canKilled = false
       
    56 desertTaken = false
       
    57 challengeFailed = false
       
    58 difficultyChoice = false
       
    59 
       
    60 goals = {
       
    61   [startDialogue] = {"First Blood", "First Steps", "Press [Left] or [Right] to move around, [Enter] to jump", 1, 4000},
       
    62   [onShroomAnim] = {"First Blood", "A leap in a leap", "Go on top of the flower", 1, 4000},
       
    63   [onFlowerAnim] = {"First Blood", "Hightime", "Collect the crate on the right.|Hint: Select the rope, [Up] or [Down] to aim, [Space] to fire, directional keys to move.|Ropes can be fired again in the air!", 1, 7000},
       
    64   [tookParaAnim] = {"First Blood", "Omnivore", "Get on the head of the mole", 1, 4000},
       
    65   [onMoleHeadAnim] = {"First Blood", "The Leap of Faith", "Use the parachute ([Space] while in air) to get the next crate", 1, 4000},
       
    66   [tookRope2Anim] = {"First Blood", "The Rising", "Do the deed", 1, 4000},
       
    67   [tookPunchAnim] = {"First Blood", "The Slaughter", "Destroy the targets!|Hint: Select the Shoryuken and hit [Space]|P.S. You can use it mid-air.", 1, 5000},
       
    68   [challengeAnim] = {"First Blood", "The Crate Frenzy", "Collect the crates within the time limit!|If you fail, you'll have to try again.", 1, 5000},
       
    69   [challengeFailedAnim] = {"First Blood", "The Crate Frenzy", "Collect the crates within the time limit!|If you fail, you'll have to try again.", 1, 5000},
       
    70   [challengeCompletedAnim] = {"First Blood", "The Ultimate Weapon", "Destroy the targets!|Hint: [Up], [Down] to aim, [Space] to shoot", 1, 5000},
       
    71   [beforeKillAnim] = {"First Blood", "The First Blood", "Kill the cannibal!", 1, 5000},
       
    72   [closeCannim] = {"First Blood", "The First Blood", "KILL IT!", 1, 5000}
       
    73 }
       
    74 -----------------------------Animations--------------------------------
       
    75 function Skipanim(anim)
       
    76   AnimSwitchHog(youngh)
       
    77   if goals[anim] ~= nil then
       
    78     ShowMission(unpack(goals[anim]))
       
    79   end
       
    80 end
       
    81 
       
    82 function SkipDamageAnim(anim)
       
    83   SwitchHog(youngh)
       
    84   SetInputMask(0xFFFFFFFF)
       
    85 end
       
    86 
       
    87 function SkipOnShroom()
       
    88   Skipanim(onShroomAnim)
       
    89   SetGearPosition(elderh, 2700, 1278)
       
    90 end
       
    91 
       
    92 function AnimationSetup()
       
    93   AddSkipFunction(damageAnim, SkipDamageAnim, {damageAnim})
       
    94   table.insert(damageAnim, {func = AnimWait, args = {youngh, 500}, skipFunc = Skipanim, skipArgs = damageAnim})
       
    95   table.insert(damageAnim, {func = AnimSay, args = {elderh, "Watch your steps, young one!", SAY_SAY, 2000}})
       
    96   table.insert(damageAnim, {func = AnimGearWait, args = {youngh, 500}})
       
    97 
       
    98   AddSkipFunction(princessDamagedAnim, SkipDamageAnim, {princessDamagedAnim})
       
    99   table.insert(princessDamagedAnim, {func = AnimWait, args = {princess, 500}, skipFunc = Skipanim, skipArgs = princessDamagedAnim})
       
   100   table.insert(princessDamagedAnim, {func = AnimSay, args = {princess, "Why do men keep hurting me?", SAY_THINK, 3000}})
       
   101   table.insert(princessDamagedAnim, {func = AnimGearWait, args = {youngh, 500}})
       
   102 
       
   103   AddSkipFunction(elderDamagedAnim, SkipDamageAnim, {elderDamagedAnim})
       
   104   table.insert(elderDamagedAnim, {func = AnimWait, args = {elderh, 500}, skipFunc = Skipanim, skipArgs = elderDamagedAnim})
       
   105   table.insert(elderDamagedAnim, {func = AnimSay, args = {elderh, "Violence is not the answer to your problems!", SAY_SAY, 3000}})
       
   106   table.insert(elderDamagedAnim, {func = AnimGearWait, args = {youngh, 500}})
       
   107   
       
   108   AddSkipFunction(startDialogue, Skipanim, {startDialogue})
       
   109   table.insert(startDialogue, {func = AnimWait, args = {youngh, 3500}, skipFunc = Skipanim, skipArgs = startDialogue})
       
   110   table.insert(startDialogue, {func = AnimCaption, args = {youngh, "Once upon a time, on an island with great natural resources, lived two tribes in heated conflict...",  5000}})
       
   111   table.insert(startDialogue, {func = AnimCaption, args = {youngh, "One tribe was peaceful, spending their time hunting and training, enjoying the small pleasures of life...", 5000}})
       
   112   table.insert(startDialogue, {func = AnimCaption, args = {youngh, "The other one were all cannibals, spending their time eating the organs of fellow hedgehogs...", 5000}})
       
   113   table.insert(startDialogue, {func = AnimCaption, args = {youngh, "And so it began...", 1000}})
       
   114   table.insert(startDialogue, {func = AnimSay, args = {elderh, "What are you doing at a distance so great, young one?", SAY_SHOUT, 4000}})
       
   115   table.insert(startDialogue, {func = AnimSay, args = {elderh, "Come closer, so that your training may continue!", SAY_SHOUT, 6000}})
       
   116   table.insert(startDialogue, {func = AnimSay, args = {youngh, "This is it! It's time to make Fell From Heaven fall for me...", SAY_THINK, 6000}})
       
   117   table.insert(startDialogue, {func = AnimJump, args = {youngh, "long"}})
       
   118   table.insert(startDialogue, {func = AnimTurn, args = {princess, "Right"}})
       
   119   table.insert(startDialogue, {func = AnimSwitchHog, args = {youngh}})
       
   120   table.insert(startDialogue, {func = AnimShowMission, args = {youngh, "First Blood", "First Steps", "Press [Left] or [Right] to move around, [Enter] to jump", 1, 4000}}) 
       
   121 
       
   122   AddSkipFunction(onShroomAnim, SkipOnShroom, {onShroomAnim})
       
   123   table.insert(onShroomAnim, {func = AnimSay, args = {elderh, "I can see you have been training diligently.", SAY_SAY, 4000}, skipFunc = Skipanim, skipArgs = onShroomAnim})
       
   124   table.insert(onShroomAnim, {func = AnimSay, args = {elderh, "The wind whispers that you are ready to become familiar with tools, now...", SAY_SAY, 4000}})
       
   125   table.insert(onShroomAnim, {func = AnimSay, args = {elderh, "Open that crate and we will continue!", SAY_SAY, 5000}})
       
   126   table.insert(onShroomAnim, {func = AnimMove, args = {elderh, "right", 2700, 0}})
       
   127   table.insert(onShroomAnim, {func = AnimTurn, args = {elderh, "Left"}})
       
   128   table.insert(onShroomAnim, {func = AnimSay, args = {princess, "He moves like an eagle in the sky.", SAY_THINK, 4000}})
       
   129   table.insert(onShroomAnim, {func = AnimSwitchHog, args = {youngh}})
       
   130   table.insert(onShroomAnim, {func = AnimShowMission, args = {youngh, "First Blood", "A leap in a leap", "Go on top of the flower", 1, 4000}}) 
       
   131 
       
   132   AddSkipFunction(onFlowerAnim, Skipanim, {onFlowerAnim})
       
   133   table.insert(onFlowerAnim, {func = AnimTurn, args = {elderh, "Right"}, skipFunc = Skipanim, skipArgs = onFlowerAnim})
       
   134   table.insert(onFlowerAnim, {func = AnimSay, args = {elderh, "See that crate farther on the right?", SAY_SAY, 4000}})
       
   135   table.insert(onFlowerAnim, {func = AnimSay, args = {elderh, "Swing, Leaks A Lot, on the wings of the wind!", SAY_SAY, 6000}})
       
   136   table.insert(onFlowerAnim, {func = AnimSay, args = {princess, "His arms are so strong!", SAY_THINK, 4000}})
       
   137   table.insert(onFlowerAnim, {func = AnimSwitchHog, args = {youngh}})
       
   138   table.insert(onFlowerAnim, {func = AnimShowMission, args = {youngh, "First Blood", "Hightime", "Collect the crate on the right.|Hint: Select the rope, [Up] or [Down] to aim, [Space] to fire, directional keys to move.|Ropes can be fired again in the air!", 1, 7000}}) 
       
   139   
       
   140   AddSkipFunction(tookParaAnim, Skipanim, {tookParaAnim})
       
   141   table.insert(tookParaAnim, {func = AnimGearWait, args = {youngh, 1000}, skipFunc = Skipanim, skipArgs = tookParaAnim})
       
   142   table.insert(tookParaAnim, {func = AnimSay, args = {elderh, "Use the rope to get on the head of the mole, young one!", SAY_SHOUT, 4000}})
       
   143   table.insert(tookParaAnim, {func = AnimSay, args = {elderh, "Worry not, for it is a peaceful animal! There is no reason to be afraid...", SAY_SHOUT, 5000}})
       
   144   table.insert(tookParaAnim, {func = AnimSay, args = {elderh, "We all know what happens when you get frightened...", SAY_SAY, 4000}})
       
   145   table.insert(tookParaAnim, {func = AnimSay, args = {youngh, "So humiliating...", SAY_SAY, 4000}})
       
   146   table.insert(tookParaAnim, {func = AnimShowMission, args = {youngh, "First Blood", "Omnivore", "Get on the head of the mole", 1, 4000}}) 
       
   147   table.insert(tookParaAnim, {func = AnimSwitchHog, args = {youngh}})
       
   148 
       
   149   AddSkipFunction(onMoleHeadAnim, Skipanim, {onMoleHeadAnim})
       
   150   table.insert(onMoleHeadAnim, {func = AnimSay, args = {elderh, "Perfect! Now try to get the next crate without hurting yourself!", SAY_SAY, 4000}, skipFunc = Skipanim, skipArgs = onMoleHeadAnim})
       
   151   table.insert(onMoleHeadAnim, {func = AnimSay, args = {elderh, "The giant umbrella from the last crate should help break the fall.", SAY_SAY, 4000}})
       
   152   table.insert(onMoleHeadAnim, {func = AnimSay, args = {princess, "He's so brave...", SAY_THINK, 4000}})
       
   153   table.insert(onMoleHeadAnim, {func = AnimShowMission, args = {youngh, "First Blood", "The Leap of Faith", "Use the parachute ([Space] while in air) to get the next crate", 1, 4000}}) 
       
   154   table.insert(onMoleHeadAnim, {func = AnimSwitchHog, args = {youngh}})
       
   155 
       
   156   AddSkipFunction(pastMoleHeadAnim, Skipanim, {pastMoleHeadAnim})
       
   157   table.insert(pastMoleHeadAnim, {func = AnimSay, args = {elderh, "I see you have already taken the leap of faith.", SAY_SAY, 4000}, skipFunc = Skipanim, skipArgs = pastMoleHeadAnim})
       
   158   table.insert(pastMoleHeadAnim, {func = AnimSay, args = {elderh, "Get that crate!", SAY_SAY, 4000}})
       
   159   table.insert(pastMoleHeadAnim, {func = AnimSwitchHog, args = {youngh}})
       
   160 
       
   161   AddSkipFunction(tookRope2Anim, Skipanim, {tookRope2Anim})
       
   162   table.insert(tookRope2Anim, {func = AnimSay, args = {elderh, "Impressive...you are still dry as the corpse of a hawk after a week in the desert...", SAY_SAY, 5000}, skipFunc = Skipanim, skipArgs = tookRope2Anim})
       
   163   table.insert(tookRope2Anim, {func = AnimSay, args = {elderh, "You probably know what to do next...", SAY_SAY, 4000}})
       
   164   table.insert(tookRope2Anim, {func = AnimShowMission, args = {youngh, "First Blood", "The Rising", "Do the deed", 1, 4000}}) 
       
   165   table.insert(tookRope2Anim, {func = AnimSwitchHog, args = {youngh}})
       
   166 
       
   167   AddSkipFunction(tookPunchAnim, Skipanim, {tookPunchAnim})
       
   168   table.insert(tookPunchAnim, {func = AnimTurn, args = {elderh, "Left"}, skipFunc = Skipanim, skipArgs = tookPunchAnim})
       
   169   table.insert(tookPunchAnim, {func = AnimSay, args = {elderh, "It is time to practice your fighting skills.", SAY_SAY, 4000}})
       
   170   table.insert(tookPunchAnim, {func = AnimSay, args = {elderh, "Imagine those targets are the wolves that killed your parents! Take your anger out on them!", SAY_SAY, 5000}})
       
   171   table.insert(tookPunchAnim, {func = AnimShowMission, args = {youngh, "First Blood", "The Slaughter", "Destroy the targets!|Hint: Select the Shoryuken and hit [Space]|P.S. You can use it mid-air.", 1, 5000}}) 
       
   172   table.insert(tookPunchAnim, {func = AnimSwitchHog, args = {youngh}})
       
   173 
       
   174   AddSkipFunction(challengeAnim, Skipanim, {challengeAnim})
       
   175   table.insert(challengeAnim, {func = AnimSay, args = {elderh, "I hope you are prepared for a small challenge, young one.", SAY_SAY, 4000}, skipFunc = Skipanim, skipArgs = challengeAnim})
       
   176   table.insert(challengeAnim, {func = AnimSay, args = {elderh, "Your movement skills will be evaluated now.", SAY_SAY, 4000}})
       
   177   table.insert(challengeAnim, {func = AnimSay, args = {elderh, "Collect all the crates, but remember, our time in this life is limited!", SAY_SAY, 4000}})
       
   178   table.insert(challengeAnim, {func = AnimSay, args = {elderh, "How difficult would you like it to be?"}})
       
   179   table.insert(challengeAnim, {func = AnimSwitchHog, args = {youngh}})
       
   180   table.insert(challengeAnim, {func = AnimWait, args = {youngh, 500}})
       
   181 
       
   182   AddSkipFunction(challengeFailedAnim, Skipanim, {challengeFailedAnim})
       
   183   table.insert(challengeFailedAnim, {func = AnimSay, args = {elderh, "Hmmm...perhaps a little more time will help.", SAY_SAY, 4000}, skipFunc = Skipanim, skipArgs = challengeFailedAnim})
       
   184   table.insert(challengeFailedAnim, {func = AnimShowMission, args = {youngh, "First Blood", "The Crate Frenzy", "Collect the crates within the time limit!|If you fail, you'll have to try again.", 1, 5000}}) 
       
   185   table.insert(challengeFailedAnim, {func = AnimSwitchHog, args = {youngh}})
       
   186 
       
   187   AddSkipFunction(challengeCompletedAnim, Skipanim, {challengeCompletedAnim})
       
   188   table.insert(challengeCompletedAnim, {func = AnimSay, args = {elderh, "The spirits of the ancerstors are surely pleased, Leaks A Lot.", SAY_SAY, 4000}, skipFunc = Skipanim, skipArgs = challengeCompletedAnim})
       
   189   table.insert(challengeCompletedAnim, {func = AnimSay, args = {elderh, "You have proven yourself worthy to see our most ancient secret!", SAY_SAY, 4000}})
       
   190   table.insert(challengeCompletedAnim, {func = AnimSay, args = {elderh, "The weapon in that last crate was bestowed upon us by the ancients!", SAY_SAY, 4000}})
       
   191   table.insert(challengeCompletedAnim, {func = AnimSay, args = {elderh, "Use it with precaution!", SAY_SAY, 4000}})
       
   192   table.insert(challengeCompletedAnim, {func = AnimShowMission, args = {youngh, "First Blood", "The Ultimate Weapon", "Destroy the targets!|Hint: [Up], [Down] to aim, [Space] to shoot", 1, 5000}}) 
       
   193   table.insert(challengeCompletedAnim, {func = AnimSwitchHog, args = {youngh}})
       
   194 
       
   195   AddSkipFunction(beforeKillAnim, Skipanim, {beforeKillAnim})
       
   196   table.insert(beforeKillAnim, {func = AnimSay, args = {elderh, "What do my faulty eyes observe? A spy!", SAY_SHOUT, 4000}, skipFunc = Skipanim, skipArgs = beforeKillAnim})
       
   197   table.insert(beforeKillAnim, {func = AnimFollowGear, args = {cannibal}})
       
   198   table.insert(beforeKillAnim, {func = AnimWait, args = {cannibal, 1000}})
       
   199   table.insert(beforeKillAnim, {func = AnimSay, args = {elderh, "Destroy him, Leaks A Lot! He is responsible for the deaths of many of us!", SAY_SHOUT, 4000}})
       
   200   table.insert(beforeKillAnim, {func = AnimSay, args = {cannibal, "Oh, my!", SAY_THINK, 4000}})
       
   201   table.insert(beforeKillAnim, {func = AnimShowMission, args = {youngh, "First Blood", "The First Blood", "Kill the cannibal!", 1, 5000}}) 
       
   202   table.insert(beforeKillAnim, {func = AnimSwitchHog, args = {youngh}})
       
   203   
       
   204   AddSkipFunction(closeCannim, Skipanim, {closeCannim})
       
   205   table.insert(closeCannim, {func = AnimSay, args = {elderh, "I see you would like his punishment to be more...personal...", SAY_SAY, 4000}, skipFunc = Skipanim, skipArgs = closeCannim})
       
   206   table.insert(closeCannim, {func = AnimSay, args = {cannibal, "I'm certain that this is a misunderstanding, fellow hedgehogs!", SAY_SAY, 4000}})
       
   207   table.insert(closeCannim, {func = AnimSay, args = {cannibal, "If only I were given a chance to explain my being here...", SAY_SAY, 4000}})
       
   208   table.insert(closeCannim, {func = AnimSay, args = {elderh, "Do not let his words fool you, young one! He will stab you in the back as soon as you turn away!", SAY_SAY, 6000}})
       
   209   table.insert(closeCannim, {func = AnimSay, args = {elderh, "Here...pick your weapon!", SAY_SAY, 5000}})
       
   210   table.insert(closeCannim, {func = AnimShowMission, args = {youngh, "First Blood", "The First Blood", "KILL IT!", 1, 5000}}) 
       
   211   table.insert(closeCannim, {func = AnimSwitchHog, args = {youngh}})
       
   212 
       
   213   table.insert(cannKilledAnim, {func = AnimSay, args = {elderh, "Yes, yeees! You are now ready to enter the real world!", SAY_SHOUT, 6000}})
       
   214 
       
   215   table.insert(cannKilledEarlyAnim, {func = AnimSay, args = {elderh, "What?! A cannibal? Here? There is no time to waste! Come, you are prepared.", SAY_SHOUT, 4000}})
       
   216 end
       
   217 -----------------------------Events------------------------------------
       
   218 
       
   219 function CheckDamage()
       
   220   return youngdamaged and StoppedGear(youngh) 
       
   221 end
       
   222 
       
   223 function DoOnDamage()
       
   224   AddAnim(damageAnim)
       
   225   youngdamaged = false
       
   226   AddFunction({func = ResetTurnTime, args = {}})
       
   227 end
       
   228 
       
   229 function CheckDeath()
       
   230   return youngKilled
       
   231 end
       
   232 
       
   233 function DoDeath()
       
   234   RemoveEventFunc(CheckKilledOthers)
       
   235   RemoveEventFunc(CheckDamage)
       
   236   RemoveEventFunc(CheckDamagedOthers)
       
   237   FinishThem()
       
   238   ShowMission("First Blood", "The wasted youth", "Leaks A Lot gave his life for his tribe! He should have survived!", 2, 4000)
       
   239 end
       
   240 
       
   241 function CheckDamagedOthers()
       
   242   return (princessDamaged and StoppedGear(princess)) or (elderDamaged and StoppedGear(elderh))
       
   243 end
       
   244 
       
   245 function CheckKilledOthers()
       
   246   return princessKilled or elderKilled
       
   247 end
       
   248 
       
   249 function DoOnDamagedOthers()
       
   250   if princessDamaged then
       
   251     AddAnim(princessDamagedAnim)
       
   252   end
       
   253   if elderDamaged then
       
   254     AddAnim(elderDamagedAnim)
       
   255   end
       
   256   elderDamaged = false
       
   257   princessDamaged = false
       
   258   AddFunction({func = ResetTurnTime, args = {}})
       
   259 end
       
   260 
       
   261 function DoKilledOthers()
       
   262   AddCaption("After Leaks A Lot betrayed his tribe, he joined the cannibals...")
       
   263   FinishThem()
       
   264 end
       
   265 
       
   266 function CheckMovedUntilJump()
       
   267    return GetX(youngh) >= 2343
       
   268 end
       
   269 
       
   270 function DoMovedUntilJump()
       
   271   ShowMission("First Blood", "Step By Step", "Hint: Double Jump - Press [Backspace] twice", -amSkip, 0)
       
   272   AddEvent(CheckOnShroom, {}, DoOnShroom, {}, 0)
       
   273 end
       
   274 
       
   275 function CheckOnShroom()
       
   276   return GetX(youngh) >= 2461
       
   277 end
       
   278 
       
   279 function DoOnShroom()
       
   280   ropeCrate1 = SpawnUtilityCrate(2751, 1194, amRope)
       
   281   AddAnim(onShroomAnim)
       
   282   AddEvent(CheckOnFlower, {}, DoOnFlower, {}, 0)
       
   283 end
       
   284 
       
   285 function CheckOnFlower()
       
   286   return rope1Taken
       
   287 end
       
   288 
       
   289 function DoOnFlower()
       
   290   AddAmmo(youngh, amRope, 100)
       
   291   paraCrate = SpawnUtilityCrate(3245, 1758, amParachute)
       
   292   AddAnim(onFlowerAnim)
       
   293   AddEvent(CheckTookParaCrate, {}, DoTookParaCrate, {}, 0)
       
   294 end
       
   295 
       
   296 function CheckTookParaCrate()
       
   297   return paraTaken and StoppedGear(youngh)
       
   298 end
       
   299 
       
   300 function DoTookParaCrate()
       
   301   AddAmmo(youngh, amParachute, 100)
       
   302   AddAnim(tookParaAnim)
       
   303   AddEvent(CheckOnMoleHead, {}, DoOnMoleHead, {}, 0)
       
   304   AddEvent(CheckPastMoleHead, {}, DoPastMoleHead, {}, 0)
       
   305 end
       
   306 
       
   307 function CheckOnMoleHead()
       
   308   x = GetX(youngh)
       
   309   return x >= 3005 and x <= 3126 and StoppedGear(youngh)
       
   310 end
       
   311 
       
   312 function CheckPastMoleHead()
       
   313   x = GetX(youngh)
       
   314   y = GetY(youngh)
       
   315   return x < 3005 and y > StoppedGear(youngh) 
       
   316 end
       
   317 
       
   318 function DoPastMoleHead()
       
   319   RemoveEventFunc(CheckOnMoleHead)
       
   320   ropeCrate2 = SpawnUtilityCrate(2782, 1720, amRope)
       
   321   AddAmmo(youngh, amRope, 0)
       
   322   AddAnim(pastMoleHeadAnim)
       
   323   AddEvent(CheckTookRope2, {}, DoTookRope2, {}, 0)
       
   324 end
       
   325 
       
   326 function DoOnMoleHead()
       
   327   RemoveEventFunc(CheckPastMoleHead)
       
   328   ropeCrate2 = SpawnUtilityCrate(2782, 1720, amRope)
       
   329   AddAmmo(youngh, amRope, 0)
       
   330   AddAnim(onMoleHeadAnim)
       
   331   AddEvent(CheckTookRope2, {}, DoTookRope2, {}, 0)
       
   332 end
       
   333 
       
   334 function CheckTookRope2()
       
   335   return rope2Taken and StoppedGear(youngh)
       
   336 end
       
   337 
       
   338 function DoTookRope2()
       
   339   AddAmmo(youngh, amRope, 100)
       
   340   AddAnim(tookRope2Anim)
       
   341   punchCrate = SpawnAmmoCrate(2460, 1321, amFirePunch)
       
   342   AddEvent(CheckTookPunch, {}, DoTookPunch, {})
       
   343 end
       
   344 
       
   345 function CheckTookPunch()
       
   346   return punchTaken and StoppedGear(youngh)
       
   347 end
       
   348 
       
   349 function DoTookPunch()
       
   350   AddAmmo(youngh, amFirePunch, 100)
       
   351   AddAmmo(youngh, amRope, 0)
       
   352   AddAnim(tookPunchAnim)
       
   353   targets[1] = AddGear(1594, 1185, gtTarget, 0, 0, 0, 0)
       
   354   targets[2] = AddGear(2188, 1314, gtTarget, 0, 0, 0, 0)
       
   355   targets[3] = AddGear(1961, 1318, gtTarget, 0, 0, 0, 0)
       
   356   targets[4] = AddGear(1961, 1200, gtTarget, 0, 0, 0, 0)
       
   357   targets[5] = AddGear(1961, 1100, gtTarget, 0, 0, 0, 0)
       
   358   AddEvent(CheckTargDestroyed, {}, DoTargDestroyed, {}, 0)
       
   359 end
       
   360 
       
   361 function CheckTargDestroyed()
       
   362   return targetsDestroyed == 5 and StoppedGear(youngh)
       
   363 end
       
   364 
       
   365 function DoTargDestroyed()
       
   366   AddAnim(challengeAnim)
       
   367   targetsDestroyed = 0
       
   368   AddFunction({func = SetChoice, args = {}})
       
   369   ropeCrate3 = SpawnAmmoCrate(2000, 1200, amRope)
       
   370   AddEvent(CheckTookRope3, {}, AddAmmo, {youngh, amRope, 100}, 0)
       
   371   AddEvent(CheckCratesColled, {}, DoCratesColled, {}, 0)
       
   372   AddEvent(CheckChallengeWon, {}, DoChallengeWon, {}, 0)
       
   373   AddEvent(CheckTimesUp, {}, DoTimesUp, {}, 1)
       
   374 end
       
   375 
       
   376 function CheckChoice()
       
   377   return difficulty ~= 0
       
   378 end
       
   379 
       
   380 function DoChoice()
       
   381   difficultyChoice = false
       
   382   SetInputMask(0xFFFFFFFF)
       
   383   StartChallenge(120000 + chalTries * 20000)
       
   384 end
       
   385 
       
   386 function CheckCratesColled()
       
   387   return cratesCollected == crateNum[difficulty]
       
   388 end
       
   389 
       
   390 function DoCratesColled()
       
   391   RemoveEventFunc(CheckTimesUp)
       
   392   TurnTimeLeft = -1
       
   393   AddCaption("As the challenge was completed, Leaks A Lot set foot on the ground...")
       
   394 end
       
   395 
       
   396 function CheckChallengeWon()
       
   397   return cratesCollected == crateNum[difficulty] and StoppedGear(youngh)
       
   398 end
       
   399 
       
   400 function DoChallengeWon()
       
   401   desertCrate = SpawnAmmoCrate(1240, 1212, amDEagle)
       
   402   AddAnim(challengeCompletedAnim)
       
   403   AddEvent(CheckDesertColled, {}, DoDesertColled, {}, 0)
       
   404 end
       
   405 
       
   406 function CheckTookRope3()
       
   407   return rope3Taken
       
   408 end
       
   409 
       
   410 function CheckTimesUp()
       
   411   return TurnTimeLeft == 100
       
   412 end
       
   413 
       
   414 function DoTimesUp()
       
   415   challengeFailed = true
       
   416   DeleteGear(crates[1])
       
   417   TurnTimeLeft = -1
       
   418   AddCaption("And so happenned that Leaks A Lot failed to complete the challenge! He landed, pressured by shame...")
       
   419   AddEvent(CheckChallengeFailed, {}, DoChallengeFailed, {}, 0)
       
   420 end
       
   421 
       
   422 function CheckChallengeFailed()
       
   423   return challengeFailed and StoppedGear(youngh)
       
   424 end
       
   425 
       
   426 function DoChallengeFailed()
       
   427   challengeFailed = false
       
   428   AddAnim(challengeFailedAnim)
       
   429   chalTries = chalTries + 1
       
   430   difficulty = 0
       
   431   AddFunction({func = SetChoice, args = {}})
       
   432 end
       
   433 
       
   434 function CheckDesertColled()
       
   435   return desertTaken and StoppedGear(youngh)
       
   436 end
       
   437 
       
   438 function DoDesertColled()
       
   439   AddAmmo(youngh, amDEagle, 100)
       
   440   PutTargets(1)
       
   441   AddEvent(CheckTargetsKilled, {}, DoTargetsKilled, {}, 1)
       
   442   AddEvent(CheckCannibalKilled, {}, DoCannibalKilledEarly, {}, 0)
       
   443   ShowMission("First Blood", "The Bull's Eye", "[Up], [Down] to aim, [Space] to shoot!", 1, 5000)
       
   444 end
       
   445 
       
   446 function CheckTargetsKilled()
       
   447   return targetsDestroyed == 3 and StoppedGear(youngh)
       
   448 end
       
   449 
       
   450 function DoTargetsKilled()
       
   451   targetsDestroyed = 0
       
   452   targsWave = targsWave + 1
       
   453   if targsWave > 5 then
       
   454     RemoveEventFunc(CheckTargetsKilled)
       
   455     SetState(cannibal, gstVisible)
       
   456     cannibalVisible = true
       
   457     AddAnim(beforeKillAnim)
       
   458     AddEvent(CheckCloseToCannibal, {}, DoCloseToCannibal, {}, 0)
       
   459     AddEvent(CheckCannibalKilled, {}, DoCannibalKilled, {}, 0)
       
   460   else
       
   461     PutTargets(targsWave)
       
   462   end
       
   463 end
       
   464 
       
   465 function CheckCloseToCannibal()
       
   466   if CheckCannibalKilled() then
       
   467     return false
       
   468   end
       
   469   return math.abs(GetX(cannibal) - GetX(youngh)) <= 400 and StoppedGear(youngh)
       
   470 end
       
   471 
       
   472 function DoCloseToCannibal()
       
   473   AddAnim(closeCannim)
       
   474   AddFunction({func = SpawnAmmoCrate, args = {targetPosX[1][1], targetPosY[1][1], amWhip}})
       
   475   AddFunction({func = SpawnAmmoCrate, args = {targetPosX[1][2], targetPosY[1][2], amBaseballBat}})
       
   476   AddFunction({func = SpawnAmmoCrate, args = {targetPosX[1][3], targetPosY[1][3], amHammer}})
       
   477 end
       
   478 
       
   479 function CheckCannibalKilled()
       
   480   return cannibalKilled and StoppedGear(youngh)
       
   481 end
       
   482 
       
   483 function DoCannibalKilled()
       
   484   AddAnim(cannKilledAnim)
       
   485   SaveCampaignVar("Progress", "1")
       
   486 end
       
   487 
       
   488 function DoCannibalKilledEarly()
       
   489   AddAnim(cannKilledEarlyAnim)
       
   490   DoCannibalKilled()
       
   491 end
       
   492 
       
   493 -----------------------------Misc--------------------------------------
       
   494 function StartChallenge(time)
       
   495   cratesCollected = 0
       
   496   PutCrate(1)
       
   497   TurnTimeLeft = time
       
   498   ShowMission("First Blood", "The Crate Frenzy", "Collect the crates within the time limit!|If you fail, you'll have to try again.", 1, 5000) 
       
   499 end
       
   500 
       
   501 function SetChoice()
       
   502   SetInputMask(band(0xFFFFFFFF, bnot(gmAnimate+gmAttack+gmDown+gmHJump+gmLJump+gmSlot+gmSwitch+gmTimer+gmUp+gmWeapon)))
       
   503   difficultyChoice = true
       
   504   ShowMission("First Blood", "The Torment", "Select difficulty: [Left] - easier or [Right] - harder", 0, 4000)
       
   505   AddEvent(CheckChoice, {}, DoChoice, {}, 0) 
       
   506 end
       
   507 
       
   508 function SetTime(time)
       
   509   TurnTimeLeft = time
       
   510 end
       
   511 
       
   512 function ResetTurnTime()
       
   513   TurnTimeLeft = tTime
       
   514   tTime = -1
       
   515 end
       
   516 
       
   517 function PutCrate(i)
       
   518   if i > crateNum[difficulty] then
       
   519     return
       
   520   end
       
   521   if difficulty == 1 then
       
   522     crates[1] = SpawnAmmoCrate(targXdif1[i], targYdif1[i], amRope)
       
   523   else
       
   524     crates[1] = SpawnAmmoCrate(targXdif2[i], targYdif2[i], amRope)
       
   525   end
       
   526 end
       
   527 
       
   528 function PutTargets(i)
       
   529   targets[1] = AddGear(targetPosX[i][1], targetPosY[i][1], gtTarget, 0, 0, 0, 0)
       
   530   targets[2] = AddGear(targetPosX[i][2], targetPosY[i][2], gtTarget, 0, 0, 0, 0)
       
   531   targets[3] = AddGear(targetPosX[i][3], targetPosY[i][3], gtTarget, 0, 0, 0, 0)
       
   532 end
       
   533 
       
   534 function FinishThem()
       
   535   SetHealth(elderh, 0)
       
   536   SetHealth(youngh, 0)
       
   537   SetHealth(princess, 0)
       
   538 end
       
   539 -----------------------------Main Functions----------------------------
       
   540 
       
   541 function onGameInit()
       
   542 	Seed = 69 
       
   543 	GameFlags = gfInfAttack + gfSolidLand + gfDisableWind 
       
   544 	TurnTime = 100000 
       
   545 	CaseFreq = 0
       
   546 	MinesNum = 0
       
   547 	MinesTime = 3000
       
   548 	Explosives = 0
       
   549 	Delay = 10 
       
   550 	MapGen = 0
       
   551 	Theme = "Nature"
       
   552 
       
   553 
       
   554 	AddTeam("Natives", 1117585, "Bone", "Island", "HillBilly", "cm_birdy")
       
   555 	youngh = AddHog("Leaks A Lot", 0, 100, "Rambo")
       
   556   elderh = AddHog("White Raven", 0, 99, "IndianChief")
       
   557   princess = AddHog("Fell From Heaven", 0, 300, "tiara")
       
   558   SetGearPosition(princess, 1911, 1361)
       
   559   HogTurnLeft(princess, true)
       
   560   SetGearPosition(elderh, 2667, 1208)
       
   561   HogTurnLeft(elderh, true)
       
   562   SetGearPosition(youngh, 1862, 1362)
       
   563   HogTurnLeft(youngh, false)
       
   564 
       
   565   AddTeam("Cannibals", 14483456, "Skull", "Island", "Pirate","cm_vampire")
       
   566   cannibal = AddHog("Brainiac", 0, 5, "Zombi")
       
   567   SetGearPosition(cannibal, 525, 1256)
       
   568   HogTurnLeft(cannibal, false)
       
   569   
       
   570   AnimInit()
       
   571   AnimationSetup()
       
   572 end
       
   573 
       
   574 function onGameStart()
       
   575   TurnTimeLeft = -1
       
   576   FollowGear(youngh)
       
   577 	ShowMission("A Classic Fairytale", "First Blood", "Finish your training|Hint: Animations can be skipped with the [Precise] key.", -amSkip, 0)
       
   578   SetState(cannibal, gstInvisible)
       
   579 
       
   580   AddAnim(startDialogue)
       
   581   AddEvent(CheckDamage, {}, DoOnDamage, {}, 1)
       
   582   AddEvent(CheckDeath, {}, DoDeath, {}, 0)
       
   583   AddEvent(CheckDamagedOthers, {}, DoOnDamagedOthers, {}, 1)
       
   584   AddEvent(CheckKilledOthers, {}, DoKilledOthers, {}, 0)
       
   585   AddEvent(CheckMovedUntilJump, {}, DoMovedUntilJump, {}, 0)
       
   586 end
       
   587 
       
   588 function onGameTick()
       
   589   AnimUnWait()
       
   590   if ShowAnimation() == false then
       
   591     return
       
   592   end
       
   593   ExecuteAfterAnimations()
       
   594   CheckEvents()
       
   595 end
       
   596 
       
   597 function onGearDelete(gear)
       
   598   if gear == ropeCrate1 then
       
   599     rope1Taken = true
       
   600   elseif gear == paraCrate then
       
   601     paraTaken = true
       
   602   elseif gear == ropeCrate2 then
       
   603     rope2Taken = true
       
   604   elseif gear == ropeCrate3 then
       
   605     rope3Taken = true
       
   606   elseif gear == crates[1] and challengeFailed == false then
       
   607     crates[1] = nil
       
   608     cratesCollected = cratesCollected + 1
       
   609     PutCrate(cratesCollected + 1)
       
   610   elseif gear == punchCrate then
       
   611     punchTaken = true
       
   612   elseif gear == desertCrate then
       
   613     desertTaken = true
       
   614   elseif GetGearType(gear) == gtTarget then
       
   615     i = 1
       
   616     while targets[i] ~= gear do
       
   617       i = i + 1
       
   618     end
       
   619     targets[i] = nil
       
   620     targetsDestroyed = targetsDestroyed + 1 
       
   621   elseif gear == cannibal then
       
   622     cannibalKilled = true
       
   623   elseif gear == princess then
       
   624     princessKilled = true
       
   625   elseif gear == elderh then
       
   626     elderKilled = true
       
   627   elseif gear == youngh then
       
   628     youngKilled = true
       
   629   end
       
   630 end
       
   631 
       
   632 function onGearAdd(gear)
       
   633 end
       
   634 
       
   635 function onAmmoStoreInit()
       
   636   SetAmmo(amWhip, 0, 0, 0, 8)
       
   637   SetAmmo(amBaseballBat, 0, 0, 0, 8)
       
   638   SetAmmo(amHammer, 0, 0, 0, 8)
       
   639 end
       
   640 
       
   641 function onNewTurn()
       
   642   if CurrentHedgehog == cannibal and cannibalVisible == false then
       
   643     SetState(cannibal, gstInvisible)
       
   644   end
       
   645   SwitchHog(youngh)
       
   646   FollowGear(youngh)
       
   647   TurnTimeLeft = -1
       
   648 end
       
   649 
       
   650 function onGearDamage(gear, damage)
       
   651   if gear == youngh then
       
   652     youngdamaged = true
       
   653     tTime = TurnTimeLeft
       
   654   elseif gear == princess then
       
   655     princessDamaged = true
       
   656     tTime = TurnTimeLeft
       
   657   elseif gear == elderh then
       
   658     elderDamaged = true
       
   659     tTime = TurnTimeLeft
       
   660   elseif gear == cannibal then
       
   661     cannibalVisible = true
       
   662     cannibalDamaged = true
       
   663     SetState(cannibal, 0)
       
   664   end
       
   665 end
       
   666 
       
   667 function onPrecise()
       
   668   if GameTime > 2000 then
       
   669     SetAnimSkip(true)
       
   670   end
       
   671 end
       
   672 
       
   673 function onLeft()
       
   674   if difficultyChoice == true then
       
   675     difficulty = 1
       
   676   end
       
   677 end
       
   678 
       
   679 function onRight()
       
   680   if difficultyChoice == true then
       
   681     difficulty = 2
       
   682   end
       
   683 end
       
   684