------------------------------------------------------------
--     2008 Elite Games Team (R) All Rights Reserved      --
--             "STAR WOLVES 2: CIVIL WAR"                 --
------------------------------------------------------------

------------------------------------------------------------
-- Auto-built Quest-Action-file created by "MapBuilder2"  --
------------------------------------------------------------
--      "MapBuilder2" v.2.6 Elite Games Team              --
------------------------------------------------------------


--info:top=110,left=80,allvis=0;
function StartMission()
  StartDialog("Dialog1");
end;


--info:top=150,left=80,allvis=0;
function GoTo_Station()
  AddQuest("quest_15e_01", "#L_Quest_15e_01a", "#L_Quest_15e_01b", QUEST_PROCESS);
  nav_current = CreateNavPoint("", mothership:GetPosition(), "nav_void.dds", RGB(255,255,255), mothership);
  LineToStation = CreateLine(nav_current, np_UFT, RGB(20,80,220), .3, TRUE, .2, 1);
  flight_alex1:Escort(mothership);
  NewTrigger("f_object_inside", TrueCondition, Alex_Dialog, flight_alex1, mothership, 100);
end;


--info:top=190,left=80,allvis=0;
function Alex_Dialog()
  LineToStation:Delete();
  LineToStation = NIL;
  nav_current:Delete();
  nav_current = NIL;
  SetNormalTimeMode();
  MothershipFlight:Stop();
  StartDialog("Dialog2");
end;


--info:top=250,left=80,allvis=0;
function If_Uel()
-- лишние патрули
  flight_merc_1:Delete();
  flight_uft03:Delete();
  flight_uft05:Delete();
  flight_uft06:Delete();
  flight_uft07:Delete();
  flight_uft08:Delete();
  flight_uft09:Delete();
  flight_uft10:Delete();

  Player_Team = CreateTeam(PLAYER_TEAM);
  if (SedoySpeaker:IsInBase()) or (SedoySpeaker:IsBasePilot()) then
    if (SedoySpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    Player_Team:RemovePilot(SedoySpeaker);
    local ship = CreateCarcass("Puma_pl1", mothership:GetPosition()+Vector3(20, -20, 20), Vector3(1, 0, 0));
    ship:AssignPilot(SedoySpeaker);
    SedoyFlight = Grey_Group:CreateFlight("SedoyFlight");
    SedoyFlight:AddShip(ship);
  else
    SedoyShip = SedoySpeaker:GetShip();
    SedoyFlight = SedoySpeaker:GetFlight();
    if (SedoyFlight:GetPilotCount()==1) then
      Player_Group:RemoveFlight(SedoyFlight);
      Grey_Group:AddFlight(SedoyFlight);
    else
      NewSedoyFlight = Grey_Group:CreateFlight("NewSedoyFlight");
      NewSedoyFlight:AddShip(SedoyShip);
    end;
  end;
  if (KalemSpeaker:IsInBase()) or (KalemSpeaker:IsBasePilot()) then
    if (KalemSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    Player_Team:RemovePilot(KalemSpeaker);
    local ship = CreateCarcass("Trident_pl1", mothership:GetPosition()+Vector3(30, -20, 20), Vector3(1, 0, 0));
    ship:AssignPilot(KalemSpeaker);
    KalemFlight = Grey_Group:CreateFlight("KalemFlight");
    KalemFlight:AddShip(ship);
  else
    KalemShip = KalemSpeaker:GetShip();
    KalemFlight = KalemSpeaker:GetFlight();
    if (KalemFlight:GetPilotCount()==1) then
      Player_Group:RemoveFlight(KalemFlight);
      Grey_Group:AddFlight(KalemFlight);
    else
      NewKalemFlight = Grey_Group:CreateFlight("NewKalemFlight");
      NewKalemFlight:AddShip(KalemShip);
    end;
  end;
  flight_alex3 = SedoySpeaker:GetFlight();
  flight_alex4 = KalemSpeaker:GetFlight();
  flight_nm1:Delete();
  flight_om1:Delete();
  YanaSpeaker:Message("#L_Yana_01", 3);
  new_SetGroupRelations("Grey_Group", PLAYER_GROUP, "W");
  new_SetGroupRelations("UftGroup_1", PLAYER_GROUP, "W");
  SetAllDied({flight_alex1, flight_alex2, flight_alex3, flight_alex4}, First_Wave_1);
end;


--info:top=290,left=80,allvis=0;
function First_Wave_1()
  NewGreyFlight("Grey_Group", "gr1", Resp1:GetPosition()+Vector3(-10, 0, 20), 1, 14, Vector3(0, 0, -1));
  flight_gr1:Escort(mothership);
  NewTrigger("f_object_inside", TrueCondition, Near_MotherShip, flight_gr1, mothership, 110);
  NewGreyFlight("Grey_Group", "gr2", Resp2:GetPosition()+Vector3(10, 0, 20), 1, 13, Vector3(0, 0, -1));
  flight_gr2:Escort(mothership);
  NewTrigger("f_object_inside", TrueCondition, Near_MotherShip, flight_gr2, mothership, 110);
  NewGreyFlight("Grey_Group", "gr3", Resp3:GetPosition()+Vector3(-10, 0, 20), 1, 14, Vector3(0, 0, -1));
  flight_gr3:Escort(mothership);
  NewTrigger("f_object_inside", TrueCondition, Near_MotherShip, flight_gr3, mothership, 110);
  SetAllDied({flight_gr1, flight_gr2, flight_gr3}, Yana_Founded_1);
  YanaSpeaker:Message("#L_Yana_02", 4, "First_Wave_2");
end;


--info:top=320,left=40,allvis=0;
function First_Wave_2()
  HeroSpeaker:Message("#L_Hero_01", 4, "First_Wave_3");
end;


--info:top=360,left=40,allvis=0;
function First_Wave_3()
  YanaSpeaker:Message("#L_Yana_03", 4);
end;


--info:top=550,left=260,allvis=0;
function Near_MotherShip()
  local myTriggerContext = GetTriggerContext();
  local flight = myTriggerContext:GetFlight();
  flight:Stop();
end;


--info:top=390,left=80,allvis=0;
function Yana_Founded_1()
  sign = 1;
  Grey_Respawn();
  jammer = RAND(2) + 1;
  trig_Resp1Died = NewTrigger("died", TrueCondition, Resp1_Died, Resp1);
  trig_Resp2Died = NewTrigger("died", TrueCondition, Resp2_Died, Resp2);
  trig_Resp3Died = NewTrigger("died", TrueCondition, Resp3_Died, Resp3);
  trig_UFTDied = NewTrigger("died", TrueCondition, Mission_Done_Uel, UFT);
  YanaSpeaker:Message("#L_Yana_04", 9, "Yana_Founded_2");
end;


--info:top=420,left=40,allvis=0;
function Yana_Founded_2()
  nav_Resp1 = CreateNavPoint("#L_anhar", Resp1:GetPosition(), "nav_target.dds", RGB(255,255,255), Resp1);
  nav_Resp2 = CreateNavPoint("#L_anhar", Resp2:GetPosition(), "nav_target.dds", RGB(255,255,255), Resp2);
  nav_Resp3 = CreateNavPoint("#L_anhar", Resp3:GetPosition(), "nav_target.dds", RGB(255,255,255), Resp3);
  HeroSpeaker:Message("#L_Hero_02", 5, "Yana_Founded_3");
end;


--info:top=460,left=40,allvis=0;
function Yana_Founded_3()
  UelDSpeaker:Message("#L_UelD_01", 6, "Yana_Founded_4");
end;


--info:top=500,left=40,allvis=0;
function Yana_Founded_4()
  YanaSpeaker:Message("#L_Yana_05", 9);
  AddQuest("quest_15e_03", "#L_Quest_15e_03a", "#L_Quest_15e_03b", QUEST_PROCESS);
end;


--info:top=480,left=300,allvis=0;
function Grey_Respawn()
  lRespawn = 0;
  if (Resp1) then
    lRespawn = 1;
    if not(flight_gr1) then
      Respawn_Grey(Resp1, "gr1");
    elseif not(flight_gr1:IsAlive()) then
      Respawn_Grey(Resp1, "gr1");
    end;
  end;
  if (Resp2) then
    lRespawn = 1;
    if not(flight_gr2) then
      Respawn_Grey(Resp2, "gr2");
    elseif not(flight_gr2:IsAlive()) then
      Respawn_Grey(Resp2, "gr2");
    end;
  end;
  if (Resp3) then
    lRespawn = 1;
    if not(flight_gr3) then
      Respawn_Grey(Resp3, "gr3");
    elseif not(flight_gr3:IsAlive()) then
      Respawn_Grey(Resp3, "gr3");
    end;
  end;
  if (lRespawn==1) and (lStopRespawn==0) then
    Timer_Seq(15, Grey_Respawn);
  end;
end;


--info:top=520,left=300,allvis=0;
function Respawn_Grey(stResp, flight)
  if (sign==1) then
    sign = -1;
  else
    sign = 1;
  end;
  local typef = RAND(1) + 1;
  local strength = 12 + RAND(3);
  local fl = NewGreyFlight("Grey_Group", flight, stResp:GetPosition()+Vector3(sign*10, 0, 20), typef, strength, Vector3(0, 0, -1));
  if (GetQuestState("quest_15e_01")==QUEST_PROCESS) then
    fl:Escort(mothership);
    NewTrigger("f_object_inside", TrueCondition, Near_MotherShip, fl, mothership, 110);
  elseif (GetQuestState("quest_15e_02")==QUEST_PROCESS) then
    if (flight_ber1:IsAlive()) then
      fl:Escort(ship_ber1_1);
    elseif (flight_ber2:IsAlive()) then
      fl:Escort(ship_ber2_1);
    elseif (flight_ber3:IsAlive()) then
      fl:Escort(ship_ber3_1);
    elseif (flight_ber4:IsAlive()) then
      fl:Escort(ship_ber4_1);
    end;
  end;
end;


--info:top=590,left=80,allvis=0;
function Resp1_Died()
  Resp1 = NIL;
  nav_Resp1 = NIL;
  trig_Resp1Died:Delete();
  trig_Resp1Died = NIL;
  if (jammer==1) then
    Timer_Seq(1, Jammer_Died_1);
  else
    Timer_Seq(1, Not_Jammer_1);
  end;
end;


--info:top=590,left=180,allvis=0;
function Resp2_Died()
  Resp2 = NIL;
  nav_Resp2 = NIL;
  trig_Resp2Died:Delete();
  trig_Resp2Died = NIL;
  if (jammer==2) then
    Timer_Seq(1, Jammer_Died_1);
  else
    Timer_Seq(1, Not_Jammer_1);
  end;
end;


--info:top=590,left=270,allvis=0;
function Resp3_Died()
  Resp3 = NIL;
  nav_Resp3 = NIL;
  trig_Resp3Died:Delete();
  trig_Resp3Died = NIL;
  if (jammer==3) then
    Timer_Seq(1, Jammer_Died_1);
  else
    Timer_Seq(1, Not_Jammer_1);
  end;
end;


--info:top=670,left=120,allvis=0;
function Not_Jammer_1()
  HeroSpeaker:Message("#L_Hero_03", 4, "Not_Jammer_2");
end;


--info:top=710,left=120,allvis=0;
function Not_Jammer_2()
  UelDSpeaker:Message("#L_UelD_02", 4, "Not_Jammer_3");
end;


--info:top=750,left=120,allvis=0;
function Not_Jammer_3()
  HeroSpeaker:Message("#L_Hero_04", 3);
end;


--info:top=670,left=230,allvis=0;
function Jammer_Died_1()
  HeroSpeaker:Message("#L_Hero_05", 3, "Jammer_Died_2");
end;


--info:top=710,left=230,allvis=0;
function Jammer_Died_2()
  UelDSpeaker:Message("#L_UelD_03", 4, "Jammer_Died_3");
  SetQuestState("quest_15e_03", QUEST_DONE);
  if (trig_Resp1Died) then
    trig_Resp1Died:Delete();
    trig_Resp1Died = NIL;
  end;
  if (trig_Resp2Died) then
    trig_Resp2Died:Delete();
    trig_Resp2Died = NIL;
  end;
  if (trig_Resp3Died) then
    trig_Resp3Died:Delete();
    trig_Resp3Died = NIL;
  end;
  CreatePortalGlow(Vector3(400, 0, 800), Vector3(0, 0, -1), 5);
  NewBerserkSuperFlight("Uel_Group", "ber1", Vector3(400, 0, 800), 3, 20, Vector3(0, 0, -1));
  flight_ber1:Move(UFT:GetPosition());
  NewTrigger("f_inside", TrueCondition, Ber1_Near, flight_ber1, UFT:GetPosition(), 120);
  CreatePortalGlow(Vector3(-800, 0, -400), Vector3(1, 0, 0), 5);
  NewBerserkSuperFlight("Uel_Group", "ber2", Vector3(-800, 0, -400), 3, 20, Vector3(1, 0, 0));
  flight_ber2:Move(UFT:GetPosition());
  NewTrigger("f_inside", TrueCondition, Ber2_Near, flight_ber2, UFT:GetPosition(), 120);
  Berserk_RespawnU();
end;


--info:top=750,left=230,allvis=0;
function Jammer_Died_3()
  HeroSpeaker:Message("#L_Hero_05", 4);
end;


--info:top=790,left=180,allvis=0;
function Berserk_RespawnU()
  lBRespawn = 0;
  if (ship_ber1_1:IsAlive()) then
    lBRespawn = 1;
    if not(flight_br1) then
      Respawn_Berserk(ship_ber1_1, "br1");
    elseif not(flight_br1:IsAlive()) then
      Respawn_Berserk(ship_ber1_1, "br1");
    end;
    if not(flight_br2) then
      Respawn_Berserk(ship_ber1_1, "br2");
    elseif not(flight_br2:IsAlive()) then
      Respawn_Berserk(ship_ber1_1, "br2");
    end;
    if not(flight_br3) then
      Respawn_Berserk(ship_ber1_1, "br3");
    elseif not(flight_br3:IsAlive()) then
      Respawn_Berserk(ship_ber1_1, "br3");
    end;
    if not(flight_br4) then
      Respawn_Berserk(ship_ber1_1, "br4");
    elseif not(flight_br4:IsAlive()) then
      Respawn_Berserk(ship_ber1_1, "br4");
    end;
    if not(flight_br5) then
      Respawn_Berserk(ship_ber1_1, "br5");
    elseif not(flight_br5:IsAlive()) then
      Respawn_Berserk(ship_ber1_1, "br5");
    end;
  end;
  if (ship_ber2_1:IsAlive()) then
    lBRespawn = 1;
    if not(flight_br6) then
      Respawn_Berserk(ship_ber2_1, "br6");
    elseif not(flight_br6:IsAlive()) then
      Respawn_Berserk(ship_ber2_1, "br6");
    end;
    if not(flight_br7) then
      Respawn_Berserk(ship_ber2_1, "br7");
    elseif not(flight_br7:IsAlive()) then
      Respawn_Berserk(ship_ber2_1, "br7");
    end;
    if not(flight_br8) then
      Respawn_Berserk(ship_ber2_1, "br8");
    elseif not(flight_br8:IsAlive()) then
      Respawn_Berserk(ship_ber2_1, "br8");
    end;
    if not(flight_br9) then
      Respawn_Berserk(ship_ber2_1, "br9");
    elseif not(flight_br9:IsAlive()) then
      Respawn_Berserk(ship_ber2_1, "br9");
    end;
    if not(flight_br10) then
      Respawn_Berserk(ship_ber2_1, "br10");
    elseif not(flight_br10:IsAlive()) then
      Respawn_Berserk(ship_ber2_1, "br10");
    end;
  end;
  if (lBRespawn==1) and (lStopRespawn==0) then
    Timer_Seq(15, Berserk_RespawnU);
  end;
end;


--info:top=820,left=20,allvis=0;
function Mission_Done_Uel()
  lStopRespawn = 1;
  if (trig_Resp1Died) then
    trig_Resp1Died:Delete();
    trig_Resp1Died = NIL;
  end;
  if (trig_Resp2Died) then
    trig_Resp2Died:Delete();
    trig_Resp2Died = NIL;
  end;
  if (trig_Resp3Died) then
    trig_Resp3Died:Delete();
    trig_Resp3Died = NIL;
  end;
  SetQuestState("quest_15e_01", QUEST_DONE);
  Timer_Seq(1, Anim_GoTo);
  AutoSave("#AS_mission_15_5");
end;


--info:top=860,left=20,allvis=0;
function Anim_GoTo()
  local pos = mothership:GetPosition();
  local orn = mothership:GetVectorOrientation();
  local glow_orn = mothership:GetVectorOrientation();
  orn.x = orn.x * 25;
  orn.y = orn.y * 25;
  orn.z = orn.z * 25;
  glow_orn.x = -glow_orn.x;
  glow_orn.y = -glow_orn.y;
  glow_orn.z = -glow_orn.z;
  tmpNull = CreateCarcass("NULL", pos+orn, glow_orn); 
  MothershipFlight:Move(pos+orn);
  tmpNull:AddMeshFX("PARTICLESYSTEM", "portal.pst", glow_orn);
  tmpNull:AddMeshFX("PARTICLESYSTEM", "portal_rotate.pst", glow_orn);
  mothership:PlayFX("Portal Out.shfx");
  Anim_1 = CreateMovie(_TARGETCAM);
  Anim_1:SetLength(5);
  Anim_1:SetInterpolate(_LINEAR);
  Anim_1:SetTarget(mothership);
  Anim_1:InitMovie(1, TRUE, 1);
  Anim_1:AddPosKey(mothership:GetPosition()+Vector3(orn.x*(-1.827)+orn.z*0.8134, 10-orn.y, orn.z*(-1.827)-orn.x*0.8134), 5);
  Anim_1:Play();
  Anim_1:AttachEscapeScript("GoTo_Zebos");
  Anim_1:AttachAction("GoTo_Zebos");
  UelDSpeaker:Message("#L_UelD_04", 5);
end;


--info:top=900,left=20,allvis=0;
function GoTo_Zebos()
  EnableRandom();
  AddPost("book015e_2");
  CustomTeleportate("nk", "zebos", "long_jump");
end;


--info:top=260,left=590,allvis=0;
function If_Alex()
-- выгружаем пилотов с базы
  Remove_Pers_FromBase();
-- меняем базу на новую
  local posn = mothership:GetPosition();
  local orn = mothership:GetOrientation();
  local ornv = mothership:GetVectorOrientation();
  mothership_uel = mothership;
  mothership = SetPlayerMotherShip(ship_nm1_1); 
  Stop_Player_Pilots();
  PortalTrigger_PORTAL_D:SetObject(mothership);
  PortalTrigger_PORTAL_L:SetObject(mothership);
  PortalTrigger_PORTAL_U:SetObject(mothership);
  PortalsActivate_Action();
  CreateTradeStationDocking(TRADE, mothership);
  CreateRepairStationDocking(STO_Station, mothership, 110, 1);
-- удаляем новую базу из группы игрока
  MothershipPilot = mothership:GetPilot(); 
  MothershipFlight = MothershipPilot:GetFlight(); 
  Player_Group:RemoveFlight(MothershipFlight);
  Grey_Group:AddFlight(MothershipFlight);
-- создаем новое звено для старого мазершипа и копий Уэла 
  FocusOn({HeroSpeaker:GetShip(), SedoySpeaker:GetShip(), YanaSpeaker:GetShip(), KalemSpeaker:GetShip()}, ornv, 60);
  mothership_uel:SetPosition(Vector3(-3000, 0, 3000));
  ship_om1_1:SetPosition(posn);
  ship_om1_1:SetOrientation(orn);
  local UDFlight = UelDSpeaker:GetFlight();
  if (UDFlight:GetPilotCount()==1) then
    Player_Group:RemoveFlight(UDFlight);
    Uel_Group:AddFlight(UDFlight);
    UDFlight:Escort(ship_om1_1);
  else
    local UelDFlight = Uel_Group:CreateFlight("UelDFlight");
    UelDFlight:AddShip(UelDSpeaker:GetShip());
    UelDFlight:Escort(ship_om1_1);
  end;
  local UTFlight = UelTSpeaker:GetFlight();
  if (UTFlight:GetPilotCount()==1) then
    Player_Group:RemoveFlight(UTFlight);
    Uel_Group:AddFlight(UTFlight);
    UTFlight:Escort(ship_om1_1);
  else
    local UelTFlight = Uel_Group:CreateFlight("UelTFlight");
    UelTFlight:AddShip(UelTSpeaker:GetShip());
    UelTFlight:Escort(ship_om1_1);
  end;
-- выставляем отношения
  SetQuestState("quest_15e_01", QUEST_FAILED);
  new_SetGroupRelations("Uel_Group", PLAYER_GROUP, "W");
  new_SetGroupRelations("Grey_Group", PLAYER_GROUP, "F");
  SetQuestLabel("ZebosPermit","no");
  SetQuestLabel("InocoPermit","no");
  HeroShip = HeroSpeaker:GetShip();
  flight_alex1:Escort(HeroShip);
  flight_alex2:Escort(HeroShip);
  trig_HeroDied = NewTrigger("died", TrueCondition, Hero_Died, HeroShip);
  SedoySpeaker:Message("#L_Sedoy_01", 4, "Alex_Retirement");
end;


--info:top=290,left=630,allvis=0;
function Remove_Pers_FromBase()
  if (HeroSpeaker:IsInBase()) or (HeroSpeaker:IsBasePilot()) then
    if (HeroSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(20, -20, -20), Vector3(1, 0, 0));
    ship:AssignPilot(HeroSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightH");
    flight:AddShip(ship);
  end;
  if (SedoySpeaker:IsInBase()) or (SedoySpeaker:IsBasePilot()) then
    if (SedoySpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(20, -20, 20), Vector3(1, 0, 0));
    ship:AssignPilot(SedoySpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightS");
    flight:AddShip(ship);
  end;
  if (YanaSpeaker:IsInBase()) or (YanaSpeaker:IsBasePilot()) then
    if (YanaSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(30, -20, -20), Vector3(1, 0, 0));
    ship:AssignPilot(YanaSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightY");
    flight:AddShip(ship);
  end;
  if (KalemSpeaker:IsInBase()) or (KalemSpeaker:IsBasePilot()) then
    if (KalemSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(30, -20, 20), Vector3(1, 0, 0));
    ship:AssignPilot(KalemSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightK");
    flight:AddShip(ship);
  end;
  if (UelDSpeaker:IsInBase()) or (UelDSpeaker:IsBasePilot()) then
    if (UelDSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_ino2", mothership:GetPosition()+Vector3(40, -20, -20), Vector3(1, 0, 0));
    ship:AssignPilot(UelDSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightUD");
    flight:AddShip(ship);
  end;
  if (UelTSpeaker:IsInBase()) or (UelTSpeaker:IsBasePilot()) then
    if (UelTSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_ino2", mothership:GetPosition()+Vector3(40, -20, -20), Vector3(1, 0, 0));
    ship:AssignPilot(UelTSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightUT");
    flight:AddShip(ship);
  end;
end;


--info:top=320,left=630,allvis=0;
function Stop_Player_Pilots()
  local flight = HeroSpeaker:GetFlight();
  flight:Stop();
  flight = SedoySpeaker:GetFlight();
  flight:Stop();
  flight = YanaSpeaker:GetFlight();
  flight:Stop();
  flight = KalemSpeaker:GetFlight();
  flight:Stop();
  flight = UelDSpeaker:GetFlight();
  flight:Stop();
  flight = UelTSpeaker:GetFlight();
  flight:Stop();
end;


--info:top=460,left=880,allvis=0;
function Hero_Died()
  ShowMsgBox("#L_sys_01", "#L_sys_02", finFailed);
end;


--info:top=900,left=880,allvis=0;
function finFailed()
  EndGame("gamefailed");
end;


--info:top=340,left=590,allvis=0;
function Alex_Retirement()
  AlexSpeaker:Message("#L_Alex_01", 4);
  NewTrigger("inside", TrueCondition, Near_Station, HeroShip, UFT:GetPosition(), 150);
  Timer_Seq(120, Berserk_ComeOn);
end;


--info:top=370,left=630,allvis=0;
function Near_Station()
  SetNormalTimeMode();
  SetStopESC(TRUE);
  Anim_1 = CreateMovie(_ASIMUTHCAM);
  Anim_1:SetLength(12);
  Anim_1:SetInterpolate(_LINEAR);
  Anim_1:SetTarget(ship_nm1_1);
  Anim_1:InitMovie(1, TRUE, 5);
  Anim_1:AddKeys(224.3069, 95.4849, 48.18, 0);
  Anim_1:AddKeys(67.3815, 59.1708, 48.18, 12);
  Anim_1:Play();
  Remove_Pers_Flights();
  Grey_Group:RemoveFlight(MothershipFlight);
  Player_Group:AddFlight(MothershipFlight);
  GetShipName(mothership);
  Add_Pers_Flights();
  trig_HeroDied:Delete();
  if (flight_alex1:IsAlive()) then flight_alex1:Escort(mothership); end;
  if (flight_alex2:IsAlive()) then flight_alex2:Escort(mothership); end;
  AlexSpeaker:Message("#L_Alex_03", 7);
end;


function Remove_Pers_Flights()
  if (HeroSpeaker:IsCanSayReplica()) then
    HeroFlight = HeroSpeaker:GetFlight();
    Player_Group:RemoveFlight(HeroFlight);
  end;
  if (SedoySpeaker:IsCanSayReplica()) and (SedoySpeaker:GetSide()==PLAYER_TEAM) then
    SedoyFlight = SedoySpeaker:GetFlight();
    Player_Group:RemoveFlight(SedoyFlight);
  end;
  if (YanaSpeaker:IsCanSayReplica()) and (YanaSpeaker:GetSide()==PLAYER_TEAM) then
    YanaFlight = YanaSpeaker:GetFlight();
    Player_Group:RemoveFlight(YanaFlight);
  end;
  if (KalemSpeaker:IsCanSayReplica()) and (KalemSpeaker:GetSide()==PLAYER_TEAM) then
    KalemFlight = KalemSpeaker:GetFlight();
    Player_Group:RemoveFlight(KalemFlight);
  end;
end;


--info:top=580,left=120,allvis=0;
function Add_Pers_Flights()
  if (HeroSpeaker:IsCanSayReplica()) then
    HeroFlight = HeroSpeaker:GetFlight();
    Player_Group:AddFlight(HeroFlight);
  end;
  if (SedoySpeaker:IsCanSayReplica()) and (SedoySpeaker:GetSide()~=PLAYER_TEAM) then
    SedoyFlight = SedoySpeaker:GetFlight();
    Player_Group:AddFlight(SedoyFlight);
  end;
  if (YanaSpeaker:IsCanSayReplica()) and (YanaSpeaker:GetSide()~=PLAYER_TEAM) then
    YanaFlight = YanaSpeaker:GetFlight();
    Player_Group:AddFlight(YanaFlight);
  end;
  if (KalemSpeaker:IsCanSayReplica()) and (KalemSpeaker:GetSide()~=PLAYER_TEAM) then
    KalemFlight = KalemSpeaker:GetFlight();
    Player_Group:AddFlight(KalemFlight);
  end;
end;


--info:top=390,left=590,allvis=0;
function Berserk_ComeOn()
  CreatePortalGlow(Vector3(400, 0, 800), Vector3(0, 0, -1), 5);
  NewBerserkSuperFlight("Uel_Group", "ber1", Vector3(400, 0, 800), 3, 20, Vector3(0, 0, -1));
  flight_ber1:Move(Resp2:GetPosition());
  NewTrigger("f_inside", TrueCondition, Ber1_NearR, flight_ber1, Resp2:GetPosition(), 100);
  CreatePortalGlow(Vector3(-800, 0, -400), Vector3(1, 0, 0), 5);
  NewBerserkSuperFlight("Uel_Group", "ber2", Vector3(-800, 0, -400), 3, 20, Vector3(1, 0, 0));
  flight_ber2:Move(Resp1:GetPosition());
  NewTrigger("f_inside", TrueCondition, Ber2_NearR, flight_ber2, Resp1:GetPosition(), 100);
  CreatePortalGlow(Vector3(-300, 0, -900), Vector3(1, 0, 0), 5);
  NewBerserkSuperFlight("Uel_Group", "ber3", Vector3(-300, 0, -900), 3, 20, Vector3(1, 0, 0));
  flight_ber3:Move(Resp3:GetPosition());
  NewTrigger("f_inside", TrueCondition, Ber3_NearR, flight_ber3, Resp3:GetPosition(), 100);
  CreatePortalGlow(Vector3(900, 0, 400), Vector3(-1, 0, 0), 5);
  NewBerserkSuperFlight("Uel_Group", "ber4", Vector3(900, 0, 400), 3, 20, Vector3(-1, 0, 0));
  flight_ber4:Move(UFT:GetPosition());
  NewTrigger("f_inside", TrueCondition, Ber4_Near, flight_ber4, UFT:GetPosition(), 120);
  SetAllDied({flight_ber1,flight_ber2,flight_ber3,flight_ber4}, Mission_Done_Alex);
  signB = 1;
  Berserk_Respawn();
  countResp = 3;
  trig_Resp1Died = NewTrigger("died", TrueCondition, Resp1_Died2, Resp1);
  trig_Resp2Died = NewTrigger("died", TrueCondition, Resp2_Died2, Resp2);
  trig_Resp3Died = NewTrigger("died", TrueCondition, Resp3_Died2, Resp3);
  nav_Resp1 = CreateNavPoint("#L_anhar", Resp1:GetPosition(), "nav_target.dds", RGB(255,255,255), Resp1);
  nav_Resp2 = CreateNavPoint("#L_anhar", Resp2:GetPosition(), "nav_target.dds", RGB(255,255,255), Resp2);
  nav_Resp3 = CreateNavPoint("#L_anhar", Resp3:GetPosition(), "nav_target.dds", RGB(255,255,255), Resp3);
  trig_UFTDied = NewTrigger("died", TrueCondition, Mission_Failed, UFT);
  sign = 1;
  Grey_Respawn();
  AlexSpeaker:Message("#L_Alex_02", 4);
  AddQuest("quest_15e_02", "#L_Quest_15e_02a", "#L_Quest_15e_02b", QUEST_PROCESS);
end;


--info:top=420,left=630,allvis=0;
function Ber1_NearR()
  flight_ber1:Attack(Resp2);
end;


--info:top=450,left=630,allvis=0;
function Ber2_NearR()
  flight_ber2:Attack(Resp1);
end;


--info:top=480,left=630,allvis=0;
function Ber3_NearR()
  flight_ber3:Attack(Resp3);
end;


--info:top=800,left=590,allvis=0;
function Ber1_Near()
  flight_ber1:Attack(UFT);
end;


--info:top=800,left=490,allvis=0;
function Ber2_Near()
  flight_ber2:Attack(UFT);
end;


--info:top=800,left=690,allvis=0;
function Ber3_Near()
  flight_ber3:Attack(UFT);
end;


--info:top=800,left=770,allvis=0;
function Ber4_Near()
  flight_ber4:Attack(UFT);
end;


--info:top=680,left=460,allvis=0;
function Berserk_Respawn()
  lBRespawn = 0;
  if (ship_ber1_1:IsAlive()) then
    lBRespawn = 1;
    if not(flight_br1) then
      Respawn_Berserk(ship_ber1_1, "br1");
    elseif not(flight_br1:IsAlive()) then
      Respawn_Berserk(ship_ber1_1, "br1");
    end;
    if not(flight_br2) then
      Respawn_Berserk(ship_ber1_1, "br2");
    elseif not(flight_br2:IsAlive()) then
      Respawn_Berserk(ship_ber1_1, "br2");
    end;
    if not(flight_br3) then
      Respawn_Berserk(ship_ber1_1, "br3");
    elseif not(flight_br3:IsAlive()) then
      Respawn_Berserk(ship_ber1_1, "br3");
    end;
    if not(flight_br4) then
      Respawn_Berserk(ship_ber1_1, "br4");
    elseif not(flight_br4:IsAlive()) then
      Respawn_Berserk(ship_ber1_1, "br4");
    end;
    if not(flight_br5) then
      Respawn_Berserk(ship_ber1_1, "br5");
    elseif not(flight_br5:IsAlive()) then
      Respawn_Berserk(ship_ber1_1, "br5");
    end;
  end;
  if (ship_ber2_1:IsAlive()) then
    lBRespawn = 1;
    if not(flight_br6) then
      Respawn_Berserk(ship_ber2_1, "br6");
    elseif not(flight_br6:IsAlive()) then
      Respawn_Berserk(ship_ber2_1, "br6");
    end;
    if not(flight_br7) then
      Respawn_Berserk(ship_ber2_1, "br7");
    elseif not(flight_br7:IsAlive()) then
      Respawn_Berserk(ship_ber2_1, "br7");
    end;
    if not(flight_br8) then
      Respawn_Berserk(ship_ber2_1, "br8");
    elseif not(flight_br8:IsAlive()) then
      Respawn_Berserk(ship_ber2_1, "br8");
    end;
    if not(flight_br9) then
      Respawn_Berserk(ship_ber2_1, "br9");
    elseif not(flight_br9:IsAlive()) then
      Respawn_Berserk(ship_ber2_1, "br9");
    end;
    if not(flight_br10) then
      Respawn_Berserk(ship_ber2_1, "br10");
    elseif not(flight_br10:IsAlive()) then
      Respawn_Berserk(ship_ber2_1, "br10");
    end;
  end;
  if (ship_ber3_1:IsAlive()) then
    lBRespawn = 1;
    if not(flight_br11) then
      Respawn_Berserk(ship_ber3_1, "br11");
    elseif not(flight_br11:IsAlive()) then
      Respawn_Berserk(ship_ber3_1, "br11");
    end;
    if not(flight_br12) then
      Respawn_Berserk(ship_ber3_1, "br12");
    elseif not(flight_br12:IsAlive()) then
      Respawn_Berserk(ship_ber3_1, "br12");
    end;
    if not(flight_br13) then
      Respawn_Berserk(ship_ber3_1, "br13");
    elseif not(flight_br13:IsAlive()) then
      Respawn_Berserk(ship_ber3_1, "br13");
    end;
    if not(flight_br14) then
      Respawn_Berserk(ship_ber3_1, "br14");
    elseif not(flight_br14:IsAlive()) then
      Respawn_Berserk(ship_ber3_1, "br14");
    end;
    if not(flight_br15) then
      Respawn_Berserk(ship_ber3_1, "br15");
    elseif not(flight_br15:IsAlive()) then
      Respawn_Berserk(ship_ber3_1, "br15");
    end;
  end;
  if (ship_ber4_1:IsAlive()) then
    lBRespawn = 1;
    if not(flight_br16) then
      Respawn_Berserk(ship_ber4_1, "br16");
    elseif not(flight_br16:IsAlive()) then
      Respawn_Berserk(ship_ber4_1, "br16");
    end;
    if not(flight_br17) then
      Respawn_Berserk(ship_ber4_1, "br17");
    elseif not(flight_br17:IsAlive()) then
      Respawn_Berserk(ship_ber4_1, "br17");
    end;
    if not(flight_br18) then
      Respawn_Berserk(ship_ber4_1, "br18");
    elseif not(flight_br18:IsAlive()) then
      Respawn_Berserk(ship_ber4_1, "br18");
    end;
    if not(flight_br19) then
      Respawn_Berserk(ship_ber4_1, "br19");
    elseif not(flight_br19:IsAlive()) then
      Respawn_Berserk(ship_ber4_1, "br19");
    end;
    if not(flight_br20) then
      Respawn_Berserk(ship_ber4_1, "br20");
    elseif not(flight_br20:IsAlive()) then
      Respawn_Berserk(ship_ber4_1, "br20");
    end;
  end;
  if (lBRespawn==1) and (lStopRespawn==0) then
    Timer_Seq(15, Berserk_Respawn);
  end;
end;


--info:top=840,left=320,allvis=0;
function Respawn_Berserk(stResp, flight)
  if (signB==1) then
    signB = -1;
  else
    signB = 1;
  end;
  local typef = RAND(1) + 1;
  local strength = 17 + RAND(3);
  local fl = NewBerserkSuperFlight("Uel_Group", flight, stResp:GetPosition()+Vector3(signB*10, 0, 20), typef, strength, Vector3(0, 0, -1));
  fl:Escort(stResp);
end;


--info:top=550,left=490,allvis=0;
function Resp1_Died2()
  Resp1 = NIL;
  nav_Resp1 = NIL;
  trig_Resp1Died:Delete();
  trig_Resp1Died = NIL;
  if (flight_ber2:IsAlive()) then
    flight_ber2:Move(UFT:GetPosition());
    NewTrigger("f_inside", TrueCondition, Ber2_Near, flight_ber2, UFT:GetPosition(), 120);
  end;
  countResp = countResp - 1;
  Timer_Seq(1, Alex_Replic);
end;


--info:top=550,left=590,allvis=0;
function Resp2_Died2()
  Resp2 = NIL;
  nav_Resp2 = NIL;
  trig_Resp2Died:Delete();
  trig_Resp2Died = NIL;
  if (flight_ber1:IsAlive()) then
    flight_ber1:Move(UFT:GetPosition());
    NewTrigger("f_inside", TrueCondition, Ber1_Near, flight_ber1, UFT:GetPosition(), 120);
  end;
  countResp = countResp - 1;
  Timer_Seq(1, Alex_Replic);
end;


--info:top=550,left=690,allvis=0;
function Resp3_Died2()
  Resp3 = NIL;
  nav_Resp3 = NIL;
  trig_Resp3Died:Delete();
  trig_Resp3Died = NIL;
  if (flight_ber3:IsAlive()) then
    flight_ber3:Move(UFT:GetPosition());
    NewTrigger("f_inside", TrueCondition, Ber3_Near, flight_ber3, UFT:GetPosition(), 120);
  end;
  countResp = countResp - 1;
  Timer_Seq(1, Alex_Replic);
end;


--info:top=620,left=620,allvis=0;
function Alex_Replic()
  if (countResp==2) then
    AlexSpeaker:Message("#L_Alex_04", 6);
  elseif (countResp==1) then
    AlexSpeaker:Message("#L_Alex_05", 4);
  else
    AlexSpeaker:Message("#L_Alex_06", 4);
  end;
end;


--info:top=850,left=620,allvis=0;
function Mission_Done_Alex()
  EnableRandom();
  lStopRespawn = 1;
  SetQuestState("quest_15e_02", QUEST_DONE);
  SetNormalTimeMode();
--------------------------------------------------------------------------------
--  StartDialog("Dialog3");
  count_or_go_on();
--------------------------------------------------------------------------------
end;


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function count_or_go_on()
  if (pilot_El) or (pilot_Ace) or (pilot_Astra) or (pilot_Bavard) or (pilot_Joker) then
    if (count_pilots() >= 4) then
      choose_pilot();
    else
      StartDialog("Dialog3");
    end;
  else
    StartDialog("Dialog3");
  end; 
end;

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


--info:top=880,left=640,allvis=0;
function Yana_GoOut()
  if (YanaSpeaker:IsInBase()) or (YanaSpeaker:IsBasePilot()) then
    if (YanaSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local Player_Team = CreateTeam(PLAYER_TEAM);
    Player_Team:RemovePilot(YanaSpeaker);
    local ship = CreateCarcass("Puma_pl1", mothership:GetPosition()+Vector3(20, -20, 20), Vector3(1, 0, 0));
    ship:AssignPilot(YanaSpeaker);
    YanaFlight = Grey_Group:CreateFlight("YanaFlight");
    YanaFlight:AddShip(ship);
    YanaFlight:Move(Vector3(-3000, 500, 3000));
  elseif (YanaSpeaker:IsCanSayReplica()) then
    YanaShip = YanaSpeaker:GetShip();
    YanaFlight = YanaSpeaker:GetFlight();
    if (YanaFlight:GetPilotCount()==1) then
      Player_Group:RemoveFlight(YanaFlight);
      Grey_Group:AddFlight(YanaFlight);
    else
      NewYanaFlight = Grey_Group:CreateFlight("NewYanaFlight");
      NewYanaFlight:AddShip(YanaShip);
    end;
    flight_Yana = YanaSpeaker:GetFlight();
    flight_Yana:Move(Vector3(-3000, 500, 3000));
  else
    local Player_Team = CreateTeam(PLAYER_TEAM);
    Player_Team:RemovePilot(YanaSpeaker);
    YanaSpeaker:Kill();
    YanaSpeaker = NIL;
  end;
end;


--info:top=900,left=620,allvis=0;
function finMission()
  if (flight_alex1) and (flight_alex1:IsAlive()) then
    AddPilotToPlayer(pilot_alex1_1);
  else
    AddPilotToPlayer(AlexSpeaker);
  end;
  if (flight_alex2) and (flight_alex2:IsAlive()) then
    AddPilotToPlayer(pilot_alex2_1);
  else
    AddPilotToPlayer(NataliSpeaker);
  end;
  AddPilotToPlayer(ClericSpeaker);
  AddQuest("quest_15eA_01", "#L_Quest_15eA_01a", "#L_Quest_15eA_01b", QUEST_PROCESS);
  CreateRoute("nk", "torr", "endoria1", "kruger", "shula", "eridan");
  AddPost("book015e_1");
  AutoSave("#AS_mission_15_6");
end;


--info:top=900,left=490,allvis=0;
function Mission_Failed()
  SetQuestState("quest_15e_02", QUEST_FAILED);
  mothership:Blow();
end;


--info:top=110,left=330,allvis=0;
function StartInitMission()
  GreyTeam = CreateTeam("Grey");
  UelTeam = CreateTeam("Berserk");

  MothershipPilot = mothership:GetPilot();
  MothershipFlight = MothershipPilot:GetFlight();

  Player_Group = MothershipPilot:GetGroup();
  Grey_Group = GreyTeam:CreateGroup("Grey_Group");
  Uel_Group = UelTeam:CreateGroup("Uel_Group");
  new_SetGroupRelations("Grey_Group", PLAYER_GROUP, "N");
  new_SetGroupRelations("UftGroup_1", PLAYER_GROUP, "N");
  new_SetGroupRelations("Uel_Group", PLAYER_GROUP, "F");
  new_SetGroupRelations("Grey_Group", "UftGroup_1", "F");
  new_SetGroupRelations("Grey_Group", "Uel_Group", "W");
  new_SetGroupRelations("UftGroup_1", "Uel_Group", "W");

  HeroSpeaker = GetPilot("Hero");
  SedoySpeaker = GetPilot("Sedoy");
  YanaSpeaker = GetPilot("Yana");
  UelDSpeaker = GetPilot("Uel2");
  KalemSpeaker = GetPilot("Kalem");
  UelTSpeaker = GetPilot("Uel3");
  AlexSpeaker = CreatePilot("Alex");
  Correct_Alex(AlexSpeaker);
  ClericSpeaker = CreatePilot("Cleric");
  ClericSpeaker:SetPerk("Gunnery_3");
  ClericSpeaker:SetPerk("Learner");
  ClericSpeaker:SetPerk("Missiles_3");
  ClericSpeaker:SetPerk("F_Weapon_Laser");
  ClericSpeaker:SetPerk("Systems_4");
  ClericSpeaker:SetPerk("Countermeasures_Exp");
  ClericSpeaker:SetPerk("Shields_Exp");
  ClericSpeaker:SetPerk("Piloting_3");
  NataliSpeaker = CreatePilot("Natali");

  NewFlight("Grey_Group", "alex1", "Gunslinger_gr2", "Alex", UFT:GetPosition()+Vector3(-160, 0, -60), Vector3(-0.5, 0, -0.5));
  Correct_Alex(pilot_alex1_1);
  NewFlight("Grey_Group", "alex2", "Gunslinger_gr2", "Natali", UFT:GetPosition()+Vector3(-150, 10, -50), Vector3(-0.5, 0, -0.5));
  flight_alex2:Escort(ship_alex1_1);
-- станции респавна
  Resp1 = CreateStation("OBSERVATORY_ASTEROID2_Universal", Vector3(-250, 50, -100), Vector3(1, 0, 0), TRUE);
  Resp2 = CreateStation("OBSERVATORY_ASTEROID2_Universal", Vector3(150, 50, -250), Vector3(1, 0, 0), TRUE);
  Resp3 = CreateStation("OBSERVATORY_ASTEROID2_Universal", Vector3(400, 50, -650), Vector3(1, 0, 0), TRUE);
  local xyz_UFT = UFT:GetPosition();
  np_UFT:Delete();
  UFT:Delete();
  UFT = CreateStation("Station_uft_stabM", xyz_UFT, Vector3(-1, 0, 0));
  np_UFT = CreateNavPoint("#M_Name_Station_uft_stab", xyz_UFT, "nav_modulestation_02.dds", RGB(255,255,255), UFT);
  SetNavPointLabel(np_UFT, "xyz_UFT");
  SetObjectLabel(UFT, "UFT");
-- серые
  NewGreyFlight("Grey_Group", "grey1", UFT:GetPosition()+Vector3(-100, 50, 200), 1, 18, Vector3(0, 0, 1));
  flight_grey1:Patrol({UFT:GetPosition()+Vector3(-150, 50, 150), UFT:GetPosition()+Vector3(-50, 50, 250)}, TRUE);
  NewGreyFlight("Grey_Group", "grey2", UFT:GetPosition()+Vector3(-100, 50, -200), 1, 18, Vector3(0, 0, 1));
  flight_grey2:Patrol({UFT:GetPosition()+Vector3(-150, 50, -150), UFT:GetPosition()+Vector3(-50, 50, -250)}, TRUE);
  NewGreyFlight("Grey_Group", "grey3", UFT:GetPosition()+Vector3(100, -50, 200), 1, 18, Vector3(0, 0, 1));
  flight_grey3:Patrol({UFT:GetPosition()+Vector3(50, 50, 250), UFT:GetPosition()+Vector3(150, 50, 150)}, TRUE);
  NewGreyFlight("Grey_Group", "grey4", UFT:GetPosition()+Vector3(100, -50, -200), 1, 18, Vector3(0, 0, 1));
  flight_grey4:Patrol({UFT:GetPosition()+Vector3(-50, 50, -250), UFT:GetPosition()+Vector3(-150, 50, -150)}, TRUE);
  NewFlight("Grey_Group", "nm1", "Mothership_Lion_mk2a_grey", "BasePilot", UFT:GetPosition()+Vector3(-60, 10, -60), Vector3(-1, 0, 0));
  NewFlight("Grey_Group", "grey6", "Lion_gr2", "GreySuperAce", UFT:GetPosition()+Vector3(-60, 10, 60), Vector3(-1, 0, 0));
  NewFlight("Grey_Group", "grey7", "Lion_gr2", "GreySuperAce", UFT:GetPosition()+Vector3(100, 30, 0), Vector3(1, 0, 0));
-- запаска
  NewFlight("Uel_Group", "om1", "Manticore_ino1_1", "Uel4", Vector3(3000, 0, 3000), Vector3(1, 0, 0));
-- вылет мазершипа
  CreatePortalGlow(Vector3(-900, 300, -850), Vector3(0.5, 0, 0.5), 7);
  mothership:SetPosition(Vector3(-900, 300, -850));
  mothership:SetOrientation(CreateQuaternionFromVector3(Vector3(0.5, 0, 0.5)));
  mothership:PlayFX("Portal Out.shfx");
  mothership:ApplyImpulse(15, Vector3(0.5, 0, 0.5));
  FocusOn({mothership}, Vector3(-0.2534,0.4,-0.6601), 60);

  lStopRespawn = 0;

  DisableRandom();

  Teleporter:Delete();
  Teleporter = CreateTrigger();
  Teleporter:AttachEvent(_EVENT_TIMER); 
  Teleporter:SetTime(3);
  Teleporter:AttachCondition(TrueCondition);
  Teleporter:AttachAction(My_TeleporterAction);
end;


--info:top=150,left=440,allvis=0;
function My_TeleporterAction()
  if (GetQuestState("quest_15e_01")==QUEST_PROCESS) or (GetQuestState("quest_15e_02")==QUEST_PROCESS) then
    OutputToScreenLog("#L_sys_03", 7);
    Timer_Seq(7, fin_failed);
  else
    Timer_Seq(1, TeleporterAction);
  end;
end;


--info:top=190,left=440,allvis=0;
function fin_failed()
  EndGame("gamefailed");
end;


--info:top=150,left=330,allvis=0;
function Correct_Alex(pilot)
  pilot:SetPerk("Pilot_3");
  pilot:SetPerk("Pilot_4");
  pilot:SetPerk("Piloting_3");
  pilot:SetPerk("Gunnery_2");
  pilot:SetPerk("F_Weapon_AC");
  pilot:SetPerk("Missiles_3");
  pilot:SetPerk("Missiles_4");
  pilot:SetPerk("missile_salvo_2");
  pilot:SetPerk("missile_salvo_3");
  pilot:SetPerk("weak_spot_1");
  pilot:SetPerk("weak_spot_2");
  pilot:SetPerk("polarization_2");
  pilot:SetPerk("polarization_3");
  pilot:SetPerk("depolarization_1");
  pilot:SetPerk("depolarization_2");
  pilot:SetPerk("Systems_2");
  pilot:SetPerk("Systems_3");
  pilot:SetPerk("Countermeasures");
  pilot:SetPerk("Repairman");
  pilot:SetPerk("Shields_Op");
  pilot:SetPerk("Engine_Op");
end;


--info:top=70,left=80,allvis=0;
function ACTION_INIT()
  SetQuestLabel("CurrentQuest","15e");
  StartInitMission();

  Timer_Seq(5, StartMission);
  return TRUE;
end;


--info:top=70,left=570,allvis=0;
function ACTION_LEAVELOCATION()
  if (Resp1) then
    if (Resp1:IsAlive()) then
      if (nav_Resp1) then nav_Resp1:Delete(); end;
      Resp1:Delete();
    end;
  end;
  if (Resp2) then
    if (Resp2:IsAlive()) then
      if (nav_Resp2) then nav_Resp2:Delete(); end;
      Resp2:Delete();
    end;
  end;
  if (Resp3) then
    if (Resp3:IsAlive()) then
      if (nav_Resp3) then nav_Resp3:Delete(); end;
      Resp3:Delete();
    end;
  end;
  if (tmpNull) then tmpNull:Delete(); end;
  if (GetQuestState("quest_15e_01")==QUEST_PROCESS) or (GetQuestState("quest_15e_02")==QUEST_PROCESS) then
    Terminate();
  elseif (GetGroupRelation(Uel_Group, PLAYER_GROUP)==RELATION_FRIEND) then
    SetQuestLabel("Transfer_To_NI", "step3")
    AddPost("news015_1");
    AddPost("news015_6");
    AddPost("news015_2");
    AddPost("news015_7");
    AddPost("news015_4");
    AddPost("news015_8");
    AddPost("news015_5");
    QuestActionDone();
    QuestStart("mission_16e");
  else
    SetQuestLabel("EridanPermit", "yes");
    SetQuestLabel("Transfer_To_NI", "step3")
    AddPost("news015_1");
    AddPost("news015_6");
    AddPost("news015_2");
    AddPost("news015_7");
    AddPost("news015_4");
    AddPost("news015_8");
    AddPost("news015_5");
    QuestActionDone();
    QuestStart("mission_17d");
  end;

  return TRUE;
end;


--info:top=70,left=470,allvis=0;
function ACTION_FINI()

  return TRUE;
end;
