share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/family.lua
changeset 13135 824a75401a61
parent 13134 d204ed947785
child 13138 52d7672363c1
equal deleted inserted replaced
13134:d204ed947785 13135:824a75401a61
   128 freshDead = nil
   128 freshDead = nil
   129 crates = {}
   129 crates = {}
   130 cratesNum = 0
   130 cratesNum = 0
   131 
   131 
   132 princessFreed = false
   132 princessFreed = false
       
   133 closeToPrincess = false
       
   134 friendsEscaped = false
   133 -----------------------------Animations--------------------------------
   135 -----------------------------Animations--------------------------------
   134 function EmitDenseClouds(dir)
   136 function EmitDenseClouds(dir)
   135   local dif
   137   local dif
   136   if dir == "Left" then
   138   if dir == "Left" then
   137     dif = 10
   139     dif = 10
   217 function AfterMidAnim()
   219 function AfterMidAnim()
   218   HideHedge(cyborg)
   220   HideHedge(cyborg)
   219   SetupPlace3()
   221   SetupPlace3()
   220   SetGearMessage(natives[1], 0)
   222   SetGearMessage(natives[1], 0)
   221   AddNewEvent(CheckPrincessFreed, {}, DoPrincessFreed, {}, 0)
   223   AddNewEvent(CheckPrincessFreed, {}, DoPrincessFreed, {}, 0)
       
   224   AddNewEvent(CheckCloseToPrincess, {}, DoCloseToPrincess, {}, 0)
       
   225   AddNewEvent(CheckFriendsEscaped, {}, DoFriendsEscaped, {}, 0)
   222   EndTurn(true)
   226   EndTurn(true)
   223   ShowMission(loc("Family Reunion"), loc("Salvation"),
   227   ShowMission(loc("Family Reunion"), loc("Salvation"),
   224      loc("Get your teammates out of their natural prison and save the princess!") .."|"..
   228      loc("Get your teammates out of their natural prison and save the princess!") .."|"..
   225      loc("All your hedgehogs must be above the marked height!") .."|"..
   229      loc("All your hedgehogs must be above the marked height!") .."|"..
   226      loc("Hint: Drilling holes should solve everything.").."|"..
   230      loc("Hint: Drilling holes should solve everything.").."|"..
   235   Victory()
   239   Victory()
   236 end
   240 end
   237 
   241 
   238 function SkipMidAnim()
   242 function SkipMidAnim()
   239   AnimTeleportGear(natives[1], unpack(nativeMidPos2))
   243   AnimTeleportGear(natives[1], unpack(nativeMidPos2))
   240   SkipStartAnim()
   244   AnimSwitchHog(natives[1])
       
   245   AnimWait(natives[1], 1)
   241 end
   246 end
   242 
   247 
   243 function SetupPlace3()
   248 function SetupPlace3()
   244   SpawnSupplyCrate(2086, 1887, amRope, 1)
   249   SpawnSupplyCrate(2086, 1887, amRope, 1)
   245   SpawnSupplyCrate(2147, 728, amBlowTorch, 2)
   250   SpawnSupplyCrate(2147, 728, amBlowTorch, 2)
   317 	SpawnSupplyCrate(1809, 1880, amGirder, 1)
   322 	SpawnSupplyCrate(1809, 1880, amGirder, 1)
   318 	SpawnSupplyCrate(530, 1747, amPortalGun, 1)
   323 	SpawnSupplyCrate(530, 1747, amPortalGun, 1)
   319 end
   324 end
   320 
   325 
   321 -----------------------------Events------------------------------------
   326 -----------------------------Events------------------------------------
       
   327 function CheckCloseToPrincess()
       
   328   if GetX(natives[1]) == nil or GetX(princess) == nil then
       
   329     return false
       
   330   end
       
   331   return math.abs(GetX(natives[1]) - GetX(princess)) <= 20 and math.abs(GetY(natives[1]) - GetY(princess)) <= 17 and StoppedGear(natives[1])
       
   332 end
       
   333 
       
   334 function CheckFriendsEscaped()
       
   335   if GetX(natives[2]) == nil or GetX(natives[3]) == nil then
       
   336     return false
       
   337   end
       
   338   return GetY(natives[2]) < 1500 and GetY(natives[3]) < 1500 and StoppedGear(natives[2]) and StoppedGear(natives[3])
       
   339 end
       
   340 
   322 function CheckPrincessFreed()
   341 function CheckPrincessFreed()
   323   if GetX(natives[1]) == nil or GetX(natives[2]) == nil or GetX(natives[3]) == nil or GetX(princess) == nil then
   342   return CheckCloseToPrincess() and CheckFriendsEscaped()
   324     return false
       
   325   end
       
   326   return math.abs(GetX(natives[1]) - GetX(princess)) <= 15 and math.abs(GetY(natives[1]) - GetY(princess)) <= 15 and StoppedGear(natives[1]) 
       
   327         and GetY(natives[2]) < 1500 and GetY(natives[3]) < 1500 and StoppedGear(natives[2]) and StoppedGear(natives[3])
       
   328 end
   343 end
   329 
   344 
   330 function DoPrincessFreed()
   345 function DoPrincessFreed()
   331   AddAnim(princessFreedAnim)
   346   AddAnim(princessFreedAnim)
       
   347 end
       
   348 
       
   349 function DoFriendsEscaped()
       
   350   if friendsEscaped then
       
   351     return
       
   352   end
       
   353   if not CheckCloseToPrincess() then
       
   354     if GetX(natives[2]) == nil and GetX(natives[1]) == nil then
       
   355       return
       
   356     end
       
   357     HogSay(natives[2], string.format(loc("Finally! We're out of this hellhole. Now go save the princess, %s!"), nativeNames[natives[m5DeployedNum]]), SAY_SAY)
       
   358   end
       
   359   friendsEscaped = true
       
   360 end
       
   361 
       
   362 function DoCloseToPrincess()
       
   363   if closeToPrincess then
       
   364     return
       
   365   end
       
   366   if not CheckFriendsEscaped() then
       
   367     if GetX(natives[2]) == nil then
       
   368       return
       
   369     end
       
   370     HogSay(natives[2], loc("Hey, don't forget us! We still need to climb up!"), SAY_SHOUT)
       
   371     FollowGear(natives[2])
       
   372   end
       
   373   closeToPrincess = true
   332 end
   374 end
   333 
   375 
   334 function Victory()
   376 function Victory()
   335   if not princessFreed then
   377   if not princessFreed then
   336     if progress and progress<7 then
   378     if progress and progress<7 then
   387   return gearDead[gear]
   429   return gearDead[gear]
   388 end
   430 end
   389 
   431 
   390 function EndMission()
   432 function EndMission()
   391   if not princessFreed then
   433   if not princessFreed then
       
   434     RemoveEventFunc(CheckFriendsEscaped)
       
   435     RemoveEventFunc(CheckCloseToPrincess)
   392     RemoveEventFunc(CheckPrincessFreed)
   436     RemoveEventFunc(CheckPrincessFreed)
   393     AddCaption(loc("So the princess was never heard of again ..."))
   437     AddCaption(loc("So the princess was never heard of again ..."))
   394     DismissTeam(loc("Natives"))
   438     DismissTeam(loc("Natives"))
   395     DismissTeam(loc("011101001"))
   439     DismissTeam(loc("011101001"))
   396     EndTurn(true)
   440     EndTurn(true)