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