share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/enemy.lua
changeset 14876 543729d313f5
parent 14661 0bba06a05d52
child 14898 4596357d002d
equal deleted inserted replaced
14875:12ffbbf81ee1 14876:543729d313f5
    19 
    19 
    20 ]]
    20 ]]
    21 
    21 
    22 HedgewarsScriptLoad("/Scripts/Locale.lua")
    22 HedgewarsScriptLoad("/Scripts/Locale.lua")
    23 HedgewarsScriptLoad("/Scripts/Animate.lua")
    23 HedgewarsScriptLoad("/Scripts/Animate.lua")
       
    24 HedgewarsScriptLoad("/Scripts/Utils.lua")
    24 
    25 
    25 
    26 
    26 --------------------------------------------Constants------------------------------------
    27 --------------------------------------------Constants------------------------------------
    27 choiceAccepted = 1
    28 choiceAccepted = 1
    28 choiceRefused = 2
    29 choiceRefused = 2
    95 players = {}
    96 players = {}
    96 leader = nil
    97 leader = nil
    97 
    98 
    98 gearDead = {}
    99 gearDead = {}
    99 hedgeHidden = {}
   100 hedgeHidden = {}
       
   101 trackedMines = {}
   100 
   102 
   101 startAnim = {}
   103 startAnim = {}
   102 finalAnim = {}
   104 finalAnim = {}
   103 -----------------------------Animations--------------------------------
   105 -----------------------------Animations--------------------------------
   104 function CondNeedToTurn(hog1, hog2)
   106 function CondNeedToTurn(hog1, hog2)
   408 end
   410 end
   409 
   411 
   410 function FailedMission()
   412 function FailedMission()
   411   RestoreHedge(cyborg)
   413   RestoreHedge(cyborg)
   412   AnimOutOfNowhere(cyborg, unpack(cyborgPos[1]))
   414   AnimOutOfNowhere(cyborg, unpack(cyborgPos[1]))
       
   415   ClearMinesAroundCyborg()
   413   if CheckCyborgsDead() then
   416   if CheckCyborgsDead() then
   414     AnimSay(cyborg, loc("Hmmm...it's a draw. How unfortunate!"), SAY_THINK, 6000)
   417     AnimSay(cyborg, loc("Hmmm...it's a draw. How unfortunate!"), SAY_THINK, 6000)
   415   elseif leader ~= nil then
   418   elseif leader ~= nil then
   416     CondNeedToTurn2(cyborg, leader)
   419     CondNeedToTurn2(cyborg, leader)
   417     AddAnim({{func = AnimSay, args = {leader, loc("Yay, we won!"), SAY_SAY, 2000}},
   420     AddAnim({{func = AnimSay, args = {leader, loc("Yay, we won!"), SAY_SAY, 2000}},
   433 
   436 
   434 function WonMission()
   437 function WonMission()
   435   RestoreHedge(cyborg)
   438   RestoreHedge(cyborg)
   436   CondNeedToTurn2(cyborg, players[1])
   439   CondNeedToTurn2(cyborg, players[1])
   437   SetupFinalAnim()
   440   SetupFinalAnim()
       
   441   ClearMinesAroundCyborg()
   438   AddAnim(finalAnim)
   442   AddAnim(finalAnim)
   439   AddFunction({func = WinMission, args = {}})
   443   AddFunction({func = WinMission, args = {}})
   440 end
   444 end
   441 
   445 
   442 function WinMission()
   446 function WinMission()
   456 
   460 
   457 function RestoreHedge(hedge)
   461 function RestoreHedge(hedge)
   458   if hedgeHidden[hedge] == true then
   462   if hedgeHidden[hedge] == true then
   459     RestoreHog(hedge)
   463     RestoreHog(hedge)
   460     hedgeHidden[hedge] = false
   464     hedgeHidden[hedge] = false
       
   465   end
       
   466 end
       
   467 
       
   468 function ClearMinesAroundCyborg()
       
   469   if GetHealth(cyborg) then
       
   470     local vaporized = 0
       
   471     for mine, _ in pairs(trackedMines) do
       
   472        if GetHealth(mine) and GetHealth(cyborg) and gearIsInBox(mine, GetX(cyborg) - 50, GetY(cyborg) - 50, 100, 100) == true then
       
   473           AddVisualGear(GetX(mine), GetY(mine), vgtSmoke, 0, false)
       
   474           DeleteGear(mine)
       
   475           vaporized = vaporized + 1
       
   476        end
       
   477     end
       
   478     if vaporized > 0 then
       
   479        PlaySound(sndVaporize)
       
   480     end
   461   end
   481   end
   462 end
   482 end
   463 
   483 
   464 function GetVariables()
   484 function GetVariables()
   465   progress = tonumber(GetCampaignVar("Progress"))
   485   progress = tonumber(GetCampaignVar("Progress"))
   613   end
   633   end
   614   ExecuteAfterAnimations()
   634   ExecuteAfterAnimations()
   615   CheckEvents()
   635   CheckEvents()
   616 end
   636 end
   617 
   637 
       
   638 function onGearAdd(gear)
       
   639   local gt = GetGearType(gear)
       
   640   if gt == gtMine or gt == gtSMine or gt == gtAirMine then
       
   641     trackedMines[gear] = true
       
   642   end
       
   643 end
       
   644 
   618 function onGearDelete(gear)
   645 function onGearDelete(gear)
       
   646   local gt = GetGearType(gear)
       
   647   if gt == gtMine or gt == gtSMine or gt == gtAirMine then
       
   648     trackedMines[gear] = nil
       
   649   end
   619   gearDead[gear] = true
   650   gearDead[gear] = true
   620   if GetGearType(gear) == gtHedgehog then
   651   if gt == gtHedgehog then
   621     if GetHogTeamName(gear) == nativesTeamName then
   652     if GetHogTeamName(gear) == nativesTeamName then
   622       for i = 1, nativesLeft do
   653       for i = 1, nativesLeft do
   623         if natives[i] == gear then
   654         if natives[i] == gear then
   624           table.remove(natives, i)
   655           table.remove(natives, i)
   625           table.remove(players, i)
   656           table.remove(players, i)