------------------------------------------------------------
--     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=120,left=130,allvis=0;
function StartMission()
  SetNormalTimeMode();
  StartDialog("Dialog1");
end;


--info:top=160,left=130,allvis=0;
function Aia_GoOut()
  StopHere();
  if (AiaSpeaker:IsInBase()) or (AiaSpeaker:IsBasePilot()) then
    SysSpeaker:Message("#L_sys_02", 10, "Aia_GoOut");
  else
    Timer_Seq(1, Aia_GoTo_Itan);
  end;
end;


--info:top=200,left=130,allvis=0;
function Aia_GoTo_Itan()
  local AiaFlight = AiaSpeaker:GetFlight();
  local AiaShip = AiaSpeaker:GetShip();
  if (AiaFlight:GetPilotCount() > 1) then
    local NewAiaFlight = UssGroup_1:CreateFlight("NewAiaFlight");
    NewAiaFlight:AddShip(AiaShip);
    NewAiaFlight:Move(USS_STATION:GetPosition()+Vector3(-20, 30, 30));
  else
    Player_Group:RemoveFlight(AiaFlight);
    UssGroup_1:AddFlight(AiaFlight);
    AiaFlight:Move(USS_STATION:GetPosition()+Vector3(-20, 30, 30));
  end;
  AddQuest("quest_19b_01", "#L_Quest_19b_01a", "#L_Quest_19b_01b", QUEST_PROCESS);
  trig_AiaComeOn = NewTrigger("timer", TrueCondition, Aia_ComeOn, 180);
  trig_NearPortal = NewTrigger("inside", TrueCondition, Near_Portal, mothership, PORTAL_U:GetPosition()+Vector3(100, 0, -50), 150);
end;


--info:top=230,left=170,allvis=0;
function Aia_ComeOn()
  trig_AiaComeOn:Delete();
  trig_AiaComeOn = NIL;
  local AiaFlight = AiaSpeaker:GetFlight();
  AiaFlight:Escort(mothership);
--------------------------------------------------------------------------------
--  trig_AiaReturn = NewTrigger("f_object_inside", TrueCondition, Aia_Return, AiaFlight, mothership, 150);
  trig_AiaReturn = NewTrigger("f_object_inside", TrueCondition, count_or_go_on, AiaFlight, mothership, 150);
--------------------------------------------------------------------------------
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() >= 6) then
      choose_pilot();
    else
      Aia_Return();
    end;
  else
    Aia_Return();
  end; 
end;

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


--info:top=270,left=170,allvis=0;
function Aia_Return()
  trig_AiaReturn:Delete();
  trig_AiaReturn = NIL;
  trig_NearPortal:Delete();
  trig_NearPortal = NIL;
  SetQuestState("quest_19b_01", QUEST_DONE);
  local AiaFlight = AiaSpeaker:GetFlight();
  UssGroup_1:RemoveFlight(AiaFlight);
  Player_Group:AddFlight(AiaFlight);
  AiaSpeaker:Message("#L_Aia_01", 10);
  trig_NearPortal = NewTrigger("inside", TrueCondition, Near_Portal, mothership, PORTAL_U:GetPosition()+Vector3(0, 0, -75), 150);
end;


--info:top=300,left=130,allvis=0;
function Near_Portal()
  if (trig_AiaComeOn) then
    trig_AiaComeOn:Delete();
    trig_AiaComeOn = NIL;
  end;
  if (trig_AiaReturn) then
    trig_AiaReturn:Delete();
    trig_AiaReturn = NIL;
  end;
  if (trig_NearPortal) then
    trig_NearPortal:Delete();
    trig_NearPortal = NIL;
  end;
  SetNormalTimeMode();
  if (AiaSpeaker:GetSide()==PLAYER_TEAM) then
    StartDialog("Dialog2");
  else
    local AiaShip = AiaSpeaker:GetShip();
    SetPosition(mothership:GetPosition()+Vector3(0, 0, -160));
    local AiaFlight = AiaSpeaker:GetFlight();
    AiaFlight:Escort(mothership);
    StartDialog("Dialog3");
  end;
end;


--info:top=340,left=130,allvis=0;
function Aia_Return_2()
  SetQuestState("quest_19b_01", QUEST_DONE);
  local AiaFlight = AiaSpeaker:GetFlight();
  UssGroup_1:RemoveFlight(AiaFlight);
  Player_Group:AddFlight(AiaFlight);
  Timer_Seq(5, Second_Dialog);
end;


--info:top=380,left=130,allvis=0;
function Second_Dialog()
  SetNormalTimeMode();
  StartDialog("Dialog4");
end;


--info:top=410,left=180,allvis=0;
function First_Wave()
  count = 0;
  PORTAL_U:Start(10, 0);
  for i=1, 20 do
    local posiX = RAND(100)-50;
    local posiY = RAND(100)-50;
    local posiZ = RAND(100);
    local flightType = RAND(2) + 1;
    local flightStrength = RAND(5) + 16;
    local flight = NewBerserkSuperFlight("Berserk_Group", "br"..i, PORTAL_U:GetPosition()+Vector3(posiX, posiY, posiZ), flightType, flightStrength, Vector3(0, 0, -1));
    count = count + 1;
    NewTrigger("f_died", DiedCondition, After_First, flight);
  end;
end;


--info:top=440,left=220,allvis=0;
function DiedCondition()
  count = count - 1;
  if (count==0) then
    return TRUE;
  end;
  return FALSE;
end;


--info:top=460,left=180,allvis=0;
function After_First()
  SetNormalTimeMode();
  StartDialog("Dialog5");
end;


--info:top=500,left=180,allvis=0;
function GoTo_Station()
  oldFun = ChangeFuncDocking("Com_Trade_Dialog", COM_STATION);
  AddQuest("quest_19b_02", "#L_Quest_19b_02a", "#L_Quest_19b_02b", QUEST_PROCESS);
  nav_current = CreateNavPoint("", mothership:GetPosition(), "nav_void.dds", RGB(255,255,255), mothership);
  LineToStation = CreateLine(nav_current, np_com, RGB(20,80,220), .3, TRUE, .2, 1);
  NewTrigger("inside", TrueCondition, Near_Station, mothership, COM_STATION:GetPosition(), 150);
end;


--info:top=520,left=220,allvis=0;
function Com_Trade_Dialog()
  local NShop_USS_sst = {		-- количество каждого предмета в магазине
	{0,0,12,12,0,0,12,9,		-- HC,VC guns
	0,6,6,3,0,6,3,			-- LC,PLC
	0,9,6,6,6,3,			-- PC,RG
	0,0,15,9,0,15,9,6,		-- THC,TVC
	0,9,6,3,9,6,3,			-- TLC,TPLC
	0,9,6,0,6,3,			-- TPC,TRG
	0,9,12,6,0,9,12,6,3,0,0,		-- CG,AC
	0,0,0,9,6,3,0,0,0,0,0,0},	-- GK
	{0,0,9,6,0,0,12,9,0,9,12,9,	-- LRS,ECM,AMS systems
	0,6,3,9,6,0,12,9,6,		-- Stealth,LRRNB
	0,0,18,9,0,6,9,6,		-- RBot
	0,0,12,9,3,0,12,3,9,6,6,6,	-- Sh,Eng,Man
	0,18,12,9,6,0,9,3,		-- Gun,ALS
	0,3,2,2,0,3,3,2,3,1,		-- BS_
	0,3,2,1,0,4,3,2,		-- RBot,Sh
	2,1,2,1,2,2,0,0,2,0},		-- Eng,Gun,ALS
	{0,9,7,4,0,15,10,6,12,12,8,6,	-- SM,SRM,LRM rockets
	0,6,4,10,7,5},			-- T,MIRV
	{0,0,0,0,2,		-- 1
	2,1,2,2,2,		-- 2
	4,3,3,0,0,0,0,		-- 3
	8,6,0,6,6,0,0,0,	-- 4
	0,5,0,0,0,0}};		-- 5 level ships
  CreateShop("comuss");
  AddAllToShops({"comuss"}, NShop_USS_sst, 80, 0.0, 0.0);
  UpdateTradeSystem(TRUE);

  MothershipFlight:Stop();
  SetTraderFlag(TRUE);
  TradeStationDlg("comuss");
  Timer_Seq(1, After_Dock);
end;


--info:top=560,left=220,allvis=0;
function After_Dock()
  ChangeFuncDocking(oldFun, COM_STATION);
end;


--info:top=580,left=180,allvis=0;
function Near_Station()
  LineToStation:Delete();
  LineToStation = NIL;
  nav_current:Delete();
  nav_current = NIL;
  SetNormalTimeMode();
  MothershipFlight:Stop();
  StartDialog("Dialog6");
end;


--info:top=620,left=180,allvis=0;
function GoTo_Portal()
  SetQuestState("quest_19b_02", QUEST_DONE);
  AddQuest("quest_19b_03", "#L_Quest_19b_03a", "#L_Quest_19b_03b", QUEST_PROCESS);
  ship_ussD_1:ComeToPortal(PORTAL_D);
  trig_LeadDied = NewTrigger("died", TrueCondition, Leader_Died, ship_ussD_1);
  NewTrigger("f_object_inside", trigger_inside2portal_Condition, Transports_GoOut, flight_ussD, PORTAL_D, 20);
  NewUSSFlight("UssGroup_1", "uss5", USS_STATION:GetPosition()+Vector3(-100, 0, -100), 3, 20, Vector3(0, 0, 1));
  NewUSSFlight("UssGroup_1", "uss6", USS_STATION:GetPosition()+Vector3(-120, 0, -100), 1, 20, Vector3(0, 0, 1));
  NewUSSFlight("UssGroup_1", "uss7", USS_STATION:GetPosition()+Vector3(-100, 0, -120), 1, 20, Vector3(0, 0, 1));
  NewUSSFlight("UssGroup_1", "uss8", USS_STATION:GetPosition()+Vector3(-110, -20, -110), 2, 20, Vector3(0, 0, 1));
  NewUSSFlight("UssGroup_1", "uss9", USS_STATION:GetPosition()+Vector3(-110, -20, -110), 2, 20, Vector3(0, 0, 1));
  flight_uss6:Escort(ship_uss5_1);
  flight_uss7:Escort(ship_uss5_1);
  flight_uss8:Escort(ship_uss5_1);
  flight_uss9:Escort(ship_uss5_1);
  flight_uss5:Move(PORTAL_U:GetPosition()+Vector3(0, 0, -100));
  NewTrigger("inside", TrueCondition, Last_Defenders, ship_uss5_1, PORTAL_U:GetPosition()+Vector3(0, 0, -100), 25);
  NewTrigger("f_object_inside", TrueCondition, USS_Died, flight_ussD, TRADE_STATION, 200);
  Timer_Seq(30, Second_Wave);
end;


--info:top=690,left=30,allvis=0;
function Leader_Died()
  trig_LeadDied:Delete();
  trig_LeadDied = NIL;
  if (ship_ussD_2:IsAlive()) then
    ship_ussD_2:ComeToPortal(PORTAL_D);
    trig_LeadDied = NewTrigger("died", TrueCondition, Leader_Died, ship_ussD_2);
  elseif (ship_ussD_3:IsAlive()) then
    ship_ussD_3:ComeToPortal(PORTAL_D);
    trig_LeadDied = NewTrigger("died", TrueCondition, Leader_Died, ship_ussD_3);
  else
    Timer_Seq(1, All_Transports_Died);
  end;
end;


--info:top=730,left=30,allvis=0;
function All_Transports_Died()
  SetQuestState("quest_19b_03", QUEST_FAILED);
  StartDialog("Dialog7");
end;


--info:top=690,left=140,allvis=0;
function Transports_GoOut()
  SetQuestState("quest_19b_03", QUEST_DONE);
  trig_LeadDied:Delete();
  trig_LeadDied = NIL;
  flight_ussD:Delete();
  AiaSpeaker:Message("#L_Aia_06", 5);
  Timer_Seq(1, Need_GoOut);
end;


--info:top=690,left=280,allvis=0;
function Second_Wave()
  for i=1, 20 do
    local posiX = RAND(2000)-1000;
    local posiY = RAND(200)-100;
    local posiZ = RAND(2000)-1000;
    local flightType = RAND(2) + 1;
    local flightStrength = RAND(5) + 16;
    --CreatePortalGlow(Vector3(posiX, posiY, posiZ), Vector3(0, 0, -1), 5);
    local flight = NewBerserkSuperFlight("Berserk_Group", "br"..i, Vector3(posiX, posiY, posiZ), flightType, flightStrength, Vector3(0, 0, -1));
    flight:SetChaseDistance(2000);
  end;
  UssSpeaker:Message("#L_uss_01", 4, "Kalem_That");
end;


--info:top=730,left=280,allvis=0;
function Kalem_That()
  KalemSpeaker:Message("#L_Kalem_01", 5, "Aia_Defend");
end;


--info:top=770,left=280,allvis=0;
function Aia_Defend()
  AiaSpeaker:Message("#L_Aia_02", 4);
end;


--info:top=690,left=380,allvis=0;
function Last_Defenders()
  mRadar = Player_Group:CreateRadar(PORTAL_U:GetPosition(), 300, 0.1);
  Anim_1 = CreateMovie(_TARGETCAM);
  Anim_1:SetLength(12);
  Anim_1:SetInterpolate(_LINEAR);
  Anim_1:SetTarget(PORTAL_U);
  Anim_1:InitMovie(1, TRUE, 3);
  Anim_1:AddPosKey(PORTAL_U:GetPosition()+Vector3(0, 50, -150), 0);
  Anim_1:AddScriptKey("Last_Parti", 1);
  Anim_1:Play();
  Anim_1:AttachEscapeScript("Fin_Anim");
  Anim_1:AttachAction("Fin_Anim");
  AiaSpeaker:Message("#L_Aia_03", 6, "USS_No");
end;


--info:top=720,left=480,allvis=0;
function Last_Parti()
  PORTAL_U:Start(5, 0);
  NewBerserkSuperFlight("Berserk_Group", "ber1", PORTAL_U:GetPosition()+Vector3(10, 0, -10), 3, 20, Vector3(0, 0, -1));
  flight_ber1:SetChaseDistance(2000);
  NewTrigger("f_died", TrueCondition, Chimera_Died, flight_ber1);
  NewBerserkSuperFlight("Berserk_Group", "ber2", PORTAL_U:GetPosition()+Vector3(-10, 0, -10), 3, 20, Vector3(0, 0, -1));
  flight_ber2:SetChaseDistance(2000);
  NewTrigger("f_died", TrueCondition, Chimera_Died, flight_ber2);
  NewBerserkSuperFlight("Berserk_Group", "ber3", PORTAL_U:GetPosition()+Vector3(0, -10, -10), 3, 20, Vector3(0, 0, -1));
  flight_ber3:SetChaseDistance(2000);
  NewTrigger("f_died", TrueCondition, Chimera_Died, flight_ber3);
  NewBerserkSuperFlight("Berserk_Group", "ber4", PORTAL_U:GetPosition()+Vector3(0, 10, -10), 3, 20, Vector3(0, 0, -1));
  flight_ber4:SetChaseDistance(2000);
  NewTrigger("f_died", TrueCondition, Chimera_Died, flight_ber4);
  table_Berserk1 = {{"NewBerserkSuperFlight", "Berserk_Group", ship_ber1_1, {"brR11", "brR12", "brR13", "brR14", "brR15", "brR16"}, 16, ship_ber1_1, "escort"},
                    {"NewBerserkSuperFlight", "Berserk_Group", ship_ber2_1, {"brR21", "brR22", "brR23", "brR24", "brR25", "brR26"}, 16, ship_ber2_1, "escort"},
                    {"NewBerserkSuperFlight", "Berserk_Group", ship_ber3_1, {"brR31", "brR32", "brR33", "brR34", "brR35", "brR36"}, 16, ship_ber3_1, "escort"},
                    {"NewBerserkSuperFlight", "Berserk_Group", ship_ber4_1, {"brR41", "brR42", "brR43", "brR44", "brR45", "brR46"}, 16, ship_ber4_1, "escort"}};
  InitializationRespawn(table_Berserk1);
  StartRespawn();
end;


--info:top=790,left=510,allvis=0;
function Resp_Berserk(postfix)
  PORTAL_U:Start(5, 0);
  local flight = NewBerserkSuperFlight("Berserk_Group", postfix, PORTAL_U:GetPosition(), 3, 20, Vector3(0, 0, -1));
  flight:SetChaseDistance(2000);
  flight:Attack(mothership);
  NewTrigger("f_died", TrueCondition, Chimera_Died, flight);
end;


--info:top=760,left=480,allvis=0;
function Chimera_Died()
  if not(flight_ber1:IsAlive()) then
    Resp_Berserk("ber1");
    ship_ber1_1 = getglobal("ship_ber1_1");
    ChangeObject(table_ber1, ship_ber1_1);
    ChangeRespObject(table_ber1, ship_ber1_1)
  end;
  if not(flight_ber2:IsAlive()) then
    Resp_Berserk("ber2");
    ship_ber2_1 = getglobal("ship_ber2_1");
    ChangeObject(table_ber2, ship_ber2_1);
    ChangeRespObject(table_ber2, ship_ber2_1)
  end;
  if not(flight_ber3:IsAlive()) then
    Resp_Berserk("ber3");
    ship_ber3_1 = getglobal("ship_ber3_1");
    ChangeObject(table_ber3, ship_ber3_1);
    ChangeRespObject(table_ber3, ship_ber3_1)
  end;
  if not(flight_ber4:IsAlive()) then
    Resp_Berserk("ber4");
    ship_ber4_1 = getglobal("ship_ber4_1");
    ChangeObject(table_ber4, ship_ber4_1);
    ChangeRespObject(table_ber4, ship_ber4_1)
  end;
end;


--info:top=770,left=380,allvis=0;
function USS_No()
  UssSpeaker:Message("#L_uss_02", 3, "Aia_GoGo");
end;


--info:top=810,left=380,allvis=0;
function Aia_GoGo()
  AiaSpeaker:Message("#L_Aia_04", 3);
end;


--info:top=750,left=400,allvis=0;
function Fin_Anim()
  Player_Group:DeleteRadar(mRadar);
end;


--info:top=690,left=620,allvis=0;
function USS_Died()
  mRadar = Player_Group:CreateRadar(USS_STATION:GetPosition(), 300, 0.1);
  USS_STATION:SetGodMode(FALSE);
  Timer_Seq(8, USS_Blow);
  Anim_2 = CreateMovie(_TARGETCAM);
  Anim_2:SetLength(10);
  Anim_2:SetInterpolate(_LINEAR);
  Anim_2:SetTarget(USS_STATION);
  Anim_2:InitMovie(1, TRUE, 3);
  Anim_2:AddPosKey(USS_STATION:GetPosition()+Vector3(200, 25, 100), 0);
  Anim_2:AddPosKey(USS_STATION:GetPosition()+Vector3(-100, 75, -50), 10);
  Anim_2:AddScriptKey("Uel_ComeOn", 1);
  Anim_2:Play();
  Anim_2:AttachEscapeScript("Lastochka_Damn");
  Anim_2:AttachAction("Lastochka_Damn");
end;


--info:top=720,left=750,allvis=0;
function Uel_ComeOn()
  CreatePortalGlow(USS_STATION:GetPosition()+Vector3(0, 0, 90), Vector3(0, 0, -1), 5);
  NewFlight("Berserk_Group", "uel1", "Manticore_ino2", "Uel", USS_STATION:GetPosition()+Vector3(0, 0, 90), Vector3(0, 0, -1));
  Correct_Uel(pilot_uel1_1);
  ship_uel1_1:SetGodMode();
  flight_uel1:Attack(USS_STATION);
  CreatePortalGlow(USS_STATION:GetPosition()+Vector3(-20, 0, 95), Vector3(0, 0, -1), 5);
  NewBerserkSuperFlight("Berserk_Group", "uel2", USS_STATION:GetPosition()+Vector3(-20, 0, 95), 3, 20, Vector3(0, 0, -1));
  flight_uel2:Attack(USS_STATION);
  CreatePortalGlow(USS_STATION:GetPosition()+Vector3(20, 0, 95), Vector3(0, 0, -1), 5);
  NewBerserkSuperFlight("Berserk_Group", "uel3", USS_STATION:GetPosition()+Vector3(20, 0, 95), 3, 20, Vector3(0, 0, -1));
  flight_uel3:Attack(USS_STATION);
  table_Berserk2 = {{"NewBerserkSuperFlight", "Berserk_Group", ship_uel2_1, {"uel21", "uel22", "uel23", "uel24", "uel25", "uel26"}, 16, ship_uel2_1, "escort"},
                    {"NewBerserkSuperFlight", "Berserk_Group", ship_uel3_1, {"uel31", "uel32", "uel33", "uel34", "uel35", "uel36"}, 16, ship_uel3_1, "escort"}};
  AddRespawn(table_Berserk2);
end;


--info:top=760,left=750,allvis=0;
function Correct_Uel(pilot)
  pilot:SetPerk("Piloting_3");
  pilot:SetPerk("Pilot_4");
  pilot:SetPerk("Gunnery_3");
  pilot:SetPerk("F_Weapon_AC");
  pilot:SetPerk("Missiles_3");
  pilot:SetPerk("Elite");
  pilot:SetPerk("jinxed_2");
  pilot:SetPerk("polarization_1");
  pilot:SetPerk("polarization_2");
  pilot:SetPerk("summon_berserk_2");
  pilot:SetPerk("summon_berserk_3");
  pilot:SetPerk("summon_berserk_4");
  pilot:SetPerk("Systems_3");
  pilot:SetPerk("Systems_4");
  pilot:SetPerk("Countermeasures_Exp");
  pilot:SetPerk("Shields_Exp");
  pilot:SetPerk("Repairman_Exp");
  pilot:SetPerk("Engine_Exp");
end;


--info:top=750,left=640,allvis=0;
function USS_Blow()
  USS_STATION:Blow();
  Player_Group:DeleteRadar(mRadar);
  flight_uel2:Escort(ship_uel1_1);
  flight_uel3:Escort(ship_uel1_1);
  flight_uel1:Move(PORTAL_D:GetPosition()+Vector3(0, 0, 75));
end;


--info:top=770,left=620,allvis=0;
function Lastochka_Damn()
  LastochkaSpeaker:Message("#L_Lastochka_01", 3, "Blade_IDo");
end;


--info:top=810,left=620,allvis=0;
function Blade_IDo()
  BladeSpeaker:Message("#L_Blade_01", 3, "Aia_Stop");
end;


--info:top=850,left=620,allvis=0;
function Aia_Stop()
  AiaSpeaker:Message("#L_Aia_05", 6);
end;


--info:top=790,left=80,allvis=0;
function Need_GoOut()
  lMission = 0;
  AddQuest("quest_19b_04", "#L_Quest_19b_04a", "#L_Quest_19b_04b", QUEST_PROCESS);
end;


--info:top=120,left=410,allvis=0;
function StartInitMission()
  BerserkTeam = CreateTeam("Berserk");

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

  Player_Group = MothershipPilot:GetGroup();
  Berserk_Group = BerserkTeam:CreateGroup("Berserk_Group");
  new_SetGroupRelations("UssGroup_1", PLAYER_GROUP, "F");

  HeroSpeaker = GetPilot("Hero");
  SedoySpeaker = GetPilot("Sedoy");
  BladeSpeaker = GetPilot("Blade");
  KalemSpeaker = GetPilot("Kalem");
  LastochkaSpeaker = GetPilot("Lastochka2");
  AiaSpeaker = GetPilot("Aia");
  UssSpeaker = CreatePilot("USSOfficer");
  SysSpeaker = CreatePilot("Hint");

-- лететь отсюда можно только в пограничные системы
  Teleporter:Delete();
  Teleporter = CreateTrigger();
  Teleporter:AttachEvent(_EVENT_TIMER); 
  Teleporter:SetTime(3);
  Teleporter:AttachCondition(TrueCondition);
  Teleporter:AttachAction(My_TeleporterAction);
-- местное население
-- пиратеги разбежались
  flight_Pir01:Delete();
  flight_Pir02:Delete();
  flight_Pir03:Delete();
  flight_Pir04:Delete();
  flight_Pir05:Delete();
  flight_Pir06:Delete();
-- транспорты эвакуации
  NewUSSFlight("UssGroup_1", "ussE1", FACTORY:GetPosition()+Vector3(-50, 0, 0), 3, 3, Vector3(-0.5, 0, -0.5));
  flight_ussE1:Patrol({STO_Station:GetPosition()+Vector3(0, 60, 0), TRADE_STATION:GetPosition()+Vector3(0, 60, 0), PORTAL_D:GetPosition()+Vector3(0, 0, 30), PORTAL_D:GetPosition()}, TRUE);
  NewTrigger("f_object_inside", trigger_inside2portal_Condition, trigger_inside2portal_Action, flight_ussE1, PORTAL_D, 20);
  NewUSSFlight("UssGroup_1", "ussE2", TRADE_STATION:GetPosition()+Vector3(0, 60, 0), 3, 3, Vector3(1, 0, 0));
  flight_ussE2:Patrol({STO_Station:GetPosition()+Vector3(0, 60, 0), FACTORY:GetPosition()+Vector3(-50, 0, 0), PORTAL_D:GetPosition()+Vector3(0, 0, 30), PORTAL_D:GetPosition()}, TRUE);
  NewTrigger("f_object_inside", trigger_inside2portal_Condition, trigger_inside2portal_Action, flight_ussE2, PORTAL_D, 20);
  NewUSSFlight("UssGroup_1", "ussE3", STO_Station:GetPosition()+Vector3(0, 60, 0), 3, 7, Vector3(0.5, 0, 0.5));
  flight_ussE3:Patrol({STO_Station:GetPosition()+Vector3(0, 60, 0), FACTORY:GetPosition()+Vector3(-50, 0, 0), TRADE_STATION:GetPosition()+Vector3(0, 60, 0)}, TRUE);
  NewUSSFlight("UssGroup_1", "ussE4", USS_STATION:GetPosition()+Vector3(0, 30, 50), 3, 7, Vector3(0.5, 0, 0.5));
  flight_ussE4:Patrol({COM_STATION:GetPosition()+Vector3(-50, 60, 0), USS_STATION:GetPosition()+Vector3(0, 30, 50)}, TRUE);
  NewUSSFlight("UssGroup_1", "ussE5", PORTAL_L:GetPosition()+Vector3(10, 0, 0), 3, 10, Vector3(1, 0, 0));
  flight_ussE5:Patrol({COM_STATION:GetPosition()+Vector3(-50, 60, 0), TRADE_STATION:GetPosition()+Vector3(0, 60, 0), USS_STATION:GetPosition()+Vector3(0, 30, 50), PORTAL_D:GetPosition()+Vector3(0, 0, 30), PORTAL_D:GetPosition()}, TRUE);
  NewTrigger("f_object_inside", trigger_inside2portal_Condition, trigger_inside2portal_Action, flight_ussE5, PORTAL_D, 20);
  NewFlight("UssGroup_1", "ussD", "Arba_uss2", "USSOfficer", COM_STATION:GetPosition()+Vector3(-60, 30, 30), Vector3(-0.5, 0, -0.5), "shipFormationColumn");
  NewShip("ussD_2", "HMQueen_uss3", "USSOfficer", COM_STATION:GetPosition()+Vector3(-40, 30, 50), Vector3(-0.5, 0, -0.5));
  flight_ussD:AddShip(ship_ussD_2);
  NewShip("ussD_3", "HMQueen_uss3", "USSOfficer", COM_STATION:GetPosition()+Vector3(-20, 30, 70), Vector3(-0.5, 0, -0.5));
  flight_ussD:AddShip(ship_ussD_3);
-- охрана у портала
  NewHunterFlight("UssGroup_1", "hun1", PORTAL_U:GetPosition()+Vector3(200, 0, -100), 1, 19, Vector3(-1, 0, 0));
  flight_hun1:Patrol({PORTAL_U:GetPosition()+Vector3(0, 50, -200), PORTAL_U:GetPosition()+Vector3(-200, 0, -100), PORTAL_U:GetPosition()+Vector3(200, 0, -100)}, TRUE);
  NewHunterFlight("UssGroup_1", "hun2", PORTAL_U:GetPosition()+Vector3(-200, 0, -100), 1, 20, Vector3(-1, 0, 0));
  flight_hun1:Patrol({PORTAL_U:GetPosition()+Vector3(200, 0, -100), PORTAL_U:GetPosition()+Vector3(0, 50, -200), PORTAL_U:GetPosition()+Vector3(-200, 0, -100)}, TRUE);
  NewHunterFlight("UssGroup_1", "hun3", PORTAL_U:GetPosition()+Vector3(100, 0, -50), 1, 20, Vector3(-0.67, 0, 0.33));
  NewHunterFlight("UssGroup_1", "hun4", PORTAL_U:GetPosition()+Vector3(120, 0, -50), 1, 19, Vector3(-0.67, 0, 0.33));
  NewHunterFlight("UssGroup_1", "hun5", PORTAL_U:GetPosition()+Vector3(100, 0, -70), 2, 20, Vector3(-0.67, 0, 0.33));
  NewUSSFlight("UssGroup_1", "uss1", PORTAL_U:GetPosition()+Vector3(-100, 0, -100), 1, 20, Vector3(0.5, 0, -0.5));
  NewUSSFlight("UssGroup_1", "uss2", PORTAL_U:GetPosition()+Vector3(-120, 0, -100), 1, 19, Vector3(0.5, 0, -0.5));
  NewUSSFlight("UssGroup_1", "uss3", PORTAL_U:GetPosition()+Vector3(-100, 0, -120), 1, 19, Vector3(0.5, 0, -0.5));
  NewUSSFlight("UssGroup_1", "uss4", PORTAL_U:GetPosition()+Vector3(-110, -20, -110), 2, 20, Vector3(0.5, 0, -0.5));
-- вылет мазершипа
  CreatePortalGlow(Vector3(50, 200, -100), Vector3(-0.5, 0, 0.5), 7);
  mothership:SetPosition(Vector3(50, 200, -100));
  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.6601, 0.4, 0.2534), 60);

  lMission = 1;
end;


--info:top=160,left=410,allvis=0;
function My_TeleporterAction()
  if (dest_location=="x297") then
    TeleportToLocation("x297");
  elseif (lMission==1) then
    failedMission();
  else
    EndGame("TriadaCrash");
  end;
end;


--info:top=200,left=410,allvis=0;
function failedMission()
  OutputToScreenLog("#L_sys_01", 5);
  Timer_Seq(5, fin_failed);
end;


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


--info:top=80,left=130,allvis=0;
function ACTION_INIT()
  StartInitMission();

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


--info:top=80,left=570,allvis=0;
function ACTION_LEAVELOCATION()
  QuestActionDone();
  QuestStart("mission_19b_1");

  return TRUE;
end;


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

  return TRUE;
end;
