local LD = require("design.LevelDesignLibrary")
local EC = require("design.Encounter")
local timer = require("level.timer")
local checkpoint = require("level.checkpoint")
local player, Encounter01, thisLevel, son
local crashFloor = false
local startCollapseCine = false
local firstPathBreak = false
local firstPathFall = false
local secondPathFall = false
local secondPathBuckle = false
local thirdPathBuckle = false
local fourthPathBuckle = false
local distractionPos, distractionFace, pad, Area_1_Encounter_1, Area_1_Encounter_3, Area_1_Encounter_4
function OnScriptLoaded(level)
  thisLevel = level
  EndlessAbove()
  EndlessFlyFromBelow()
  SoundInit()
  player = game.Player.FindPlayer()
  pad = player.Pad
end
function OnFirstStart(level)
  GameObjects.DEAD_ONES:Hide()
  GameObjects.DEAD_ONES_EXTRA:Hide()
  GameObjects.DespawnAll:HideEntityVolume()
  GameObjects.Hive_Path_A.Child:PauseAnim()
  GameObjects.Hive_Path_C:Hide()
  GameObjects.Tendril02ICPost:HideCollision()
  GameObjects.SlideDownIC:HideCollision()
  GameObjects.HivePathFall02:Hide()
  GameObjects.CineZone_TendrilCut02:HideEntityVolume()
  GameObjects.HIVE_INTERIOR:HideEntityVolume()
  GameObjects.RampSheet:HideCollision()
  Area_1_Encounter_1:DisableSpawners({name = "Loc_A4_*"})
  Area_1_Encounter_3:DisableSpawners({name = "Loc_C4_*"})
  Area_1_Encounter_1:DisableSpawners({name = "Loc_A5_*"})
  Area_1_Encounter_3:DisableSpawners({name = "Loc_C5_*"})
  Area_1_Encounter_1:DisableSpawners({name = "Loc_A6_*"})
  Area_1_Encounter_3:DisableSpawners({name = "Loc_C6_*"})
  timer.StartLevelTimer(0.1, function()
    GameObjects.ClonePoseController1_1_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController1_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_1_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_1_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController6_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_1_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController8_1_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController8_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController9_1.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(0.5, function()
    GameObjects.ClonePoseController1_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController1_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController6_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController6_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController8_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController8_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController9_2.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(1, function()
    GameObjects.ClonePoseController1_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController1_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController6_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController6_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController8_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController9_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController9_3.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(1.3, function()
    GameObjects.ClonePoseController1_4_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController1_4.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_4_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_4.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_4_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_4.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_4.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_4.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(1.5, function()
    GameObjects.ClonePoseController1_5.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_5.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_5.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_5_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_5.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_5_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_5.LuaObjectScript.Enable()
  end)
end
function OnUpdate(level)
  if son == nil then
    son = game.AI.FindSon()
    print("spam check")
  end
  if game.Player.FindPlayer():IsInsideEntityZone("CineZone_CrashThruFloor") == true and crashFloor == false then
    crashFloor = true
    timer.StartLevelTimer(11, function()
      GameObjects.SlideDownIC:ShowCollision()
    end)
  end
  if game.Player.FindPlayer():IsInsideEntityZone("CineZone_EnterLightStart") == true and startCollapseCine == false then
    startCollapseCine = true
    game.Level.SetVariable("ALF_NAR_HiveCollapse", true)
    GameObjects.HIVE_INTERIOR:HideCollision()
    GameObjects.IC_Sheet:Hide()
    GameObjects.IC_Sheet:HideCollision()
    GameObjects.TendrilCDHulls:PlayAnimToEnd()
  end
  if game.Player.FindPlayer():IsInsideEntityZone("HiveFirstPathBreak") == true and firstPathBreak == false then
    firstPathBreak = true
    GameObjects.HiveFirstPathBreak:PlayAnimToEnd()
  end
  if game.Player.FindPlayer():IsInsideEntityZone("HivePathFall01") == true and firstPathFall == false then
    firstPathFall = true
    GameObjects.HivePathFall01:PlayAnimToEnd()
  end
  if game.Player.FindPlayer():IsInsideEntityZone("HivePathFall02") == true and secondPathFall == false then
    secondPathFall = true
    GameObjects.HivePathFall02:PlayAnimToEnd()
  end
  if game.Player.FindPlayer():IsInsideEntityZone("HivePathBuckle02") == true and secondPathBuckle == false then
    secondPathBuckle = true
    GameObjects.HivePathBuckle02:PlayAnimToEnd()
    GameObjects.HivePathFall02:Show()
  end
  if game.Player.FindPlayer():IsInsideEntityZone("HivePathFall03") == true and thirdPathBuckle == false then
    thirdPathBuckle = true
    GameObjects.HivePathFall03:PlayAnimToEnd()
  end
  if game.Player.FindPlayer():IsInsideEntityZone("HivePathBuckle04") == true and fourthPathBuckle == false then
    fourthPathBuckle = true
    GameObjects.HivePathBuckle04:PlayAnimToEnd()
  end
  if LD.GetEntityVariable("CompletedCineNumber") >= 236 then
    UpdateHiveBrawlCamera()
  end
end
function UpdateHiveBrawlCamera()
  if game.World.IsInsideCameraZone(player.WorldPosition, "CamGroup_HiveBrawl_Section_10") == true then
    game.Camera.SubmitCameraByName("CBT_Nav_HiveBrawl_010")
  end
  if game.World.IsInsideCameraZone(player.WorldPosition, "CamGroup_HiveBrawl_Section_20") == true then
    game.Camera.SubmitCameraByName("CBT_Nav_HiveBrawl_010")
    game.Camera.SubmitCameraByName("CBT_Nav_HiveBrawl_020")
  end
  if game.World.IsInsideCameraZone(player.WorldPosition, "CamGroup_HiveBrawl_Section_30") == true then
    game.Camera.SubmitCameraByName("CBT_Nav_HiveBrawl_020")
    game.Camera.SubmitCameraByName("CBT_Nav_HiveBrawl_030")
  end
  if game.World.IsInsideCameraZone(player.WorldPosition, "CamGroup_HiveBrawl_Section_40") == true then
    game.Camera.SubmitCameraByName("CBT_Nav_HiveBrawl_030")
    game.Camera.SubmitCameraByName("CBT_Nav_HiveBrawl_040")
  end
end
function OnStartGameFromThisLevel(level)
end
function OnStart(level)
  GameObjects.HiveFirstPathBreak:PlayAnimToFrame(1)
  GameObjects.HiveFirstPathBreak:JumpAnimToFrame(0)
  timer.StartLevelTimer(0.1, function()
    GameObjects.ClonePoseController1_1_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController1_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_1_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_1_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController6_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_1_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController8_1_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController8_1.LuaObjectScript.Enable()
    GameObjects.ClonePoseController9_1.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(0.5, function()
    GameObjects.ClonePoseController1_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController1_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController6_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController6_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController8_2_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController8_2.LuaObjectScript.Enable()
    GameObjects.ClonePoseController9_2.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(1, function()
    GameObjects.ClonePoseController1_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController1_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController6_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController6_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController7_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController8_3.LuaObjectScript.Enable()
    GameObjects.ClonePoseController9_3_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController9_3.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(1.3, function()
    GameObjects.ClonePoseController1_4_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController1_4.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_4_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_4.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_4_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_4.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_4.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_4.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(1.5, function()
    GameObjects.ClonePoseController1_5.LuaObjectScript.Enable()
    GameObjects.ClonePoseController2_5.LuaObjectScript.Enable()
    GameObjects.ClonePoseController3_5.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_5_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController4_5.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_5_HIDE.LuaObjectScript.Enable()
    GameObjects.ClonePoseController5_5.LuaObjectScript.Enable()
  end)
  if LD.GetEntityVariable("CompletedCineNumber") <= 235 then
    GameObjects.PieceOfGeo:Hide()
  end
  if LD.GetEntityVariable("CompletedCineNumber") >= 236 then
    GameObjects.PieceOfGeo:Show()
  end
end
function ShowPieceOfGeo()
  GameObjects.PieceOfGeo:Show()
end
function Tendril02Chopped()
  pad:ClearAllDisabledGameButtons()
  LD.SetEntityVariable("ALF_InputMaskStage", 0)
  GameObjects.CineZone_TendrilCut02:ShowEntityVolume()
  GameObjects.Hive_Path_C:Show()
  timer.StartLevelTimer(10, function()
    GameObjects.Hive_Path_A.Child:PlayAnimToEnd()
  end)
  timer.StartLevelTimer(10, function()
    GameObjects.Tendril02ICPost:ShowCollision()
  end)
  GameObjects.ClonePoseController1_1_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController1_2_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController1_3_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController1_4_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController2_2_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController2_3_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController2_4_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController3_1_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController3_2_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController3_4_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController4_1_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController4_3_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController4_5_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController5_2_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController5_3_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController5_5_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController6_2_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController6_3_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController7_1_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController7_2_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController7_3_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController8_1_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController8_2_HIDE.LuaObjectScript.Disable()
  GameObjects.ClonePoseController9_3_HIDE.LuaObjectScript.Disable()
  timer.StartLevelTimer(0.1, function()
    GameObjects.FlyController1_11.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(0.7, function()
    GameObjects.FlyController1_12.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(1.6, function()
    GameObjects.FlyController1_13.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(0.1, function()
    GameObjects.FlyController2_11.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(0.7, function()
    GameObjects.FlyController2_12.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(1.6, function()
    GameObjects.FlyController2_13.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(0.1, function()
    GameObjects.FlyController3_11.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(0.7, function()
    GameObjects.FlyController3_12.LuaObjectScript.Enable()
  end)
  timer.StartLevelTimer(1.6, function()
    GameObjects.FlyController3_13.LuaObjectScript.Enable()
  end)
  son:CallScript("LuaHook_DisableAutonomousSon")
  player:CallScript("LuaHook_DisableRevive", true)
  local alf500 = game.FindLevel("Alf500_HiveInt")
  if alf500 ~= nil then
    local cineObj = alf500:FindSingleGameObject("Cine_AlfheimLight_Group")
    cineObj:CallScript("TendrilCut02Cine")
  end
  local alf050 = game.FindLevel("Alf050_Sound")
  if alf050 ~= nil then
    alf050:CallScript("Hide490Zones")
  end
end
function Tendril03StartChop()
  musicLastTendril()
  GameObjects.DespawnAll:ShowEntityVolume()
end
function Tendril03Chopped()
  pad:ClearAllDisabledGameButtons()
  game.Compass.SetDesignerForcedHide(true)
  GameObjects.HIVE_INTERIOR:ShowEntityVolume()
  timer.StartLevelTimer(3.5, function()
    GameObjects.HiveTendonFreeze_Final:FindSingleGOByName("lowerHiveTendril00"):Hide()
  end)
  local availabilityState = {
    AvailableForSync = true,
    AvailableForBanter = false,
    AvailableInLevel = true,
    AvailableForCombat = false
  }
  game.AI.FindSon():SetNewAvailabilityRequest("LevelDesignScript", availabilityState)
  local alf510 = game.FindLevel("Alf510_HiveIntCine")
  if alf510 ~= nil then
    alf510:CallScript("AnimateLightsGeo")
    local cineObj2 = alf510:FindSingleGameObject("Cine_IntoTheLight_Group")
    cineObj2:CallScript("IntoTheLightSequence")
  end
  local alf050 = game.FindLevel("Alf050_Sound")
  if alf050 ~= nil then
    alf050:CallScript("HideHiveZones")
    alf050:CallScript("ShowTempleZones")
    alf050:CallScript("PlayLightLoop2")
  end
  son:CallScript("LuaHook_EnableAutonomousSon")
  player:CallScript("LuaHook_DisableRevive", false)
end
function Hive_Path_B_Break()
end
function FirePulse()
end
function EndlessAbove()
  Area_1_Encounter_1 = EC.NewEncounter(thisLevel, "[TB]EC:Hive Fight Above", {
    CheckpointOnComplete = false,
    LeashZone = "LeashZone500"
  })
  Area_1_Encounter_1:AddWave({
    requireOnScreenSpawners = true,
    requireSpawnersInRange = {12, 30},
    infiniteSpawning = true,
    {
      spawners = "DarkOne_SFA",
      spawnLocators = "Loc_A*",
      useSpawnLocatorsOnly = true,
      initialSpawnAmount = 4,
      initialSpawnCooldown = {0, 1.5},
      maxActive = 4,
      totalSpawns = 4,
      spawnCooldown = {0.1, 0.3}
    }
  })
  Area_1_Encounter_1:SetStartZone(thisLevel:GetGameObject("Start_Zone"))
  Area_1_Encounter_1:StartInfiniteSpawning()
end
function EndlessFlyFromBelow()
  Area_1_Encounter_3 = EC.NewEncounter(thisLevel, "[TB]EC:Hive Fight Below", {
    CheckpointOnComplete = false,
    LeashZone = "LeashZone500"
  })
  Area_1_Encounter_3:AddWave({
    requireSpawnersInRange = {13, 30},
    infiniteSpawning = true,
    {
      spawners = "DarkOne_SFBF",
      spawnLocators = "Loc_C*",
      useSpawnLocatorsOnly = true,
      initialSpawnAmount = 3,
      initialSpawnCooldown = {0, 1.5},
      maxActive = 3,
      totalSpawns = 3,
      spawnCooldown = {0.1, 0.3}
    }
  })
  Area_1_Encounter_3:SetStartZone(thisLevel:GetGameObject("Start_Zone"))
  Area_1_Encounter_3:StartInfiniteSpawning()
end
function EnableSegment01()
  Area_1_Encounter_1:EnableSpawners({name = "Loc_A1_*"})
  Area_1_Encounter_3:EnableSpawners({name = "Loc_C1_*"})
  Area_1_Encounter_1:EnableSpawners({name = "Loc_A2_*"})
  Area_1_Encounter_3:EnableSpawners({name = "Loc_C2_*"})
end
function DisableSegment01()
  Area_1_Encounter_1:DisableSpawners({name = "Loc_A1_*"})
  Area_1_Encounter_3:DisableSpawners({name = "Loc_C1_*"})
end
function EnableSegment02()
  Area_1_Encounter_1:EnableSpawners({name = "Loc_A2_*"})
  Area_1_Encounter_3:EnableSpawners({name = "Loc_C2_*"})
  Area_1_Encounter_1:EnableSpawners({name = "Loc_A3_*"})
  Area_1_Encounter_3:EnableSpawners({name = "Loc_C3_*"})
end
function DisableSegment02()
  Area_1_Encounter_1:DisableSpawners({name = "Loc_A2*"})
  Area_1_Encounter_3:DisableSpawners({name = "Loc_C2*"})
end
function EnableSegment03()
  Area_1_Encounter_1:EnableSpawners({name = "Loc_A3_*"})
  Area_1_Encounter_3:EnableSpawners({name = "Loc_C3_*"})
  Area_1_Encounter_1:EnableSpawners({name = "Loc_A4_*"})
  Area_1_Encounter_3:EnableSpawners({name = "Loc_C4_*"})
end
function DisableSegment03()
  Area_1_Encounter_1:DisableSpawners({name = "Loc_A3_*"})
  Area_1_Encounter_3:DisableSpawners({name = "Loc_C3_*"})
end
function EnableSegment04()
  Area_1_Encounter_1:EnableSpawners({name = "Loc_A5_*"})
  Area_1_Encounter_3:EnableSpawners({name = "Loc_C5_*"})
  Area_1_Encounter_1:EnableSpawners({name = "Loc_A6_*"})
  Area_1_Encounter_3:EnableSpawners({name = "Loc_C6_*"})
end
function DisableSegment04()
  Area_1_Encounter_1:DisableSpawners({name = "Loc_A4_*"})
  Area_1_Encounter_3:DisableSpawners({name = "Loc_C4_*"})
end
function EnableSegment05()
  Area_1_Encounter_1:EnableSpawners({name = "Loc_A5_*"})
  Area_1_Encounter_3:EnableSpawners({name = "Loc_C5_*"})
  Area_1_Encounter_1:EnableSpawners({name = "Loc_A6_*"})
  Area_1_Encounter_3:EnableSpawners({name = "Loc_C6_*"})
end
function DisableSegment05()
  Area_1_Encounter_1:DisableSpawners({name = "Loc_A5_*"})
  Area_1_Encounter_3:DisableSpawners({name = "Loc_C5_*"})
end
function Stop_Area_1_Encounter_1()
  Area_1_Encounter_1:StopInfiniteSpawning()
  Area_1_Encounter_3:StopInfiniteSpawning()
end
function Start_Area_1_Encounter_1()
end
function DespawnAllEnemies()
  Area_1_Encounter_1:DespawnEnemies()
  Area_1_Encounter_3:DespawnEnemies()
  Area_1_Encounter_1:SetComplete()
  Area_1_Encounter_3:SetComplete()
  local nearbyEnemies = game.Player.FindPlayer():FindEnemies(50)
  for _, enemy in ipairs(nearbyEnemies) do
    enemy:Destroy()
  end
end
function GetHiveFighterWeakConfig()
  local random = math.random(1, 2)
  if random == 1 then
    return "Light01"
  else
    return "Light02"
  end
end
function SpawnDistraction_FromBelow_DiveBombStart()
  distractionPos = LD.GetWorldJointPosition("SpawnDistraction_Below_DiveBombStart", "SpawnDistractionLoc")
  distractionFace = LD.GetWorldJointForward("SpawnDistraction_Below_DiveBombStart", "SpawnDistractionLoc")
  local charConfig = GetHiveFighterWeakConfig()
  game.AI.Spawn(thisLevel, distractionPos, distractionFace, "CRT_DarkOne00", "BRA_SpawnDistraction_Bomber", {
    PowerLevel = "1",
    Variant = "HiveFighterWeak"
  }, charConfig)
  timer.StartLevelTimer(3, function()
    GameObjects.Hive_Path_B.Child:PlayAnimToEnd()
  end)
end
function SpawnDistraction_FromAbove_DashStrike()
  distractionPos = LD.GetWorldJointPosition("SpawnDistraction_Above_DashStrike", "SpawnDistractionLoc")
  distractionFace = LD.GetWorldJointForward("SpawnDistraction_Above_DashStrike", "SpawnDistractionLoc")
  local charConfig = GetHiveFighterWeakConfig()
  game.AI.Spawn(thisLevel, distractionPos, distractionFace, "CRT_DarkOne00", "BRA_SpawnDistraction_WeaponClash", {
    PowerLevel = "1",
    Variant = "HiveFighterWeak"
  }, charConfig)
end
function SpawnDistraction_FromBelow_ShooterFirst()
  distractionPos = LD.GetWorldJointPosition("SpawnDistraction_Below_Shooter", "SpawnDistractionLocFirst")
  distractionFace = LD.GetWorldJointForward("SpawnDistraction_Below_Shooter", "SpawnDistractionLocFirst")
  local charConfig = GetHiveFighterWeakConfig()
  timer.StartLevelTimer(3, function()
    game.AI.Spawn(thisLevel, distractionPos, distractionFace, "CRT_DarkOne00", "BRA_SpawnDistraction_Shooter", {
      PowerLevel = "1",
      Variant = "HiveFighterWeak"
    }, charConfig)
  end)
end
function SpawnDistraction_FromBelow_DiveBomb_1()
  distractionPos = LD.GetWorldJointPosition("SpawnDistraction_Below_DiveBomb_1", "SpawnDistractionLoc")
  distractionFace = LD.GetWorldJointForward("SpawnDistraction_Below_DiveBomb_1", "SpawnDistractionLoc")
  local charConfig = GetHiveFighterWeakConfig()
  game.AI.Spawn(thisLevel, distractionPos, distractionFace, "CRT_DarkOne00", "BRA_SpawnDistraction_Bomber", {
    PowerLevel = "1",
    Variant = "HiveFighterWeak"
  }, charConfig)
  timer.StartLevelTimer(3, function()
    GameObjects.Hive_Path_C.Child:PlayAnimToEnd()
  end)
end
function SpawnDistraction_FromBelow_AxeLift_1()
  distractionPos = LD.GetWorldJointPosition("SpawnDistraction_Below_AxeLift_1", "SpawnDistractionLoc")
  distractionFace = LD.GetWorldJointForward("SpawnDistraction_Below_AxeLift_1", "SpawnDistractionLoc")
  local charConfig = GetHiveFighterWeakConfig()
  game.AI.Spawn(thisLevel, distractionPos, distractionFace, "CRT_DarkOne00", "BRA_SpawnDistraction_AxeLift", {
    PowerLevel = "1",
    Variant = "HiveFighterWeak"
  }, charConfig)
end
function SpawnDistraction_FromBelow_Shooter_1()
  distractionPos = LD.GetWorldJointPosition("SpawnDistraction_Below_Shooter_1", "SpawnDistractionLoc")
  distractionFace = LD.GetWorldJointForward("SpawnDistraction_Below_Shooter_1", "SpawnDistractionLoc")
  local charConfig = GetHiveFighterWeakConfig()
  game.AI.Spawn(thisLevel, distractionPos, distractionFace, "CRT_DarkOne00", "BRA_SpawnDistraction_Shooter", {
    PowerLevel = "1",
    Variant = "HiveFighterWeak"
  }, charConfig)
end
function SpawnDistraction_FromAbove_DashStrike_1()
  distractionPos = LD.GetWorldJointPosition("SpawnDistraction_Above_DashStrike_1", "SpawnDistractionLoc")
  distractionFace = LD.GetWorldJointForward("SpawnDistraction_Above_DashStrike_1", "SpawnDistractionLoc")
  local charConfig = GetHiveFighterWeakConfig()
  game.AI.Spawn(thisLevel, distractionPos, distractionFace, "CRT_DarkOne00", "BRA_SpawnDistraction_WeaponClash", {
    PowerLevel = "1",
    Variant = "HiveFighterWeak"
  }, charConfig)
end
function SpawnDistraction_FromBelow_Shooter_2()
  distractionPos = LD.GetWorldJointPosition("SpawnDistraction_Below_Shooter_2", "SpawnDistractionLoc")
  distractionFace = LD.GetWorldJointForward("SpawnDistraction_Below_Shooter_2", "SpawnDistractionLoc")
  local charConfig = GetHiveFighterWeakConfig()
  game.AI.Spawn(thisLevel, distractionPos, distractionFace, "CRT_DarkOne00", "BRA_SpawnDistraction_Shooter", {
    PowerLevel = "1",
    Variant = "HiveFighterWeak"
  }, charConfig)
end
function SpawnDistraction_FromBelow_AxeLift_2()
  distractionPos = LD.GetWorldJointPosition("SpawnDistraction_Below_AxeLift_2", "SpawnDistractionLoc")
  distractionFace = LD.GetWorldJointForward("SpawnDistraction_Below_AxeLift_2", "SpawnDistractionLoc")
  local charConfig = GetHiveFighterWeakConfig()
  game.AI.Spawn(thisLevel, distractionPos, distractionFace, "CRT_DarkOne00", "BRA_SpawnDistraction_AxeLift", {
    PowerLevel = "1",
    Variant = "HiveFighterWeak"
  }, charConfig)
end
function OnSaveCheckpoint(level)
  return {
    levelstate = checkpoint.Save()
  }
end
function OnRestoreCheckpoint(level, savedInfo)
  checkpoint.Restore(savedInfo.levelstate)
end
local soundEmitter
function SoundInit()
  soundEmitter = GameObjects.LightRumbleSoundGroup:FindSingleSoundEmitterByName("SNDLightRumble")
  PlayRumbleSound()
end
function PlayRumbleSound()
  if soundEmitter ~= nil then
    soundEmitter:Start("SND_AMB_EMIT_Alfheim_Light_Swam_Rumble_LP")
  end
  print("Sound Emitter: " .. tostring(soundEmitter) .. " Sound: " .. "SND_AMB_EMIT_Alfheim_Light_Swam_Rumble_LP")
end
function musicLastTendril()
  game.Audio.StartMusic("SND_MX_ALF_hive_last_tendril")
end
function musicLastTendrilFail()
  game.Audio.StartMusic("SND_MX_ALF_hive_last_tendril_fail")
end
