------------------------------------------------------------
--     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=100,left=320,allvis=0;
function StartMission()
  SetQuestLabel("USSAgent", "ambush");
  trig_AttackConvoy = NewTrigger("reps", TrueCondition, Attack_Convoy, Player_Group, Uft_Group_1, RELATION_WAR);
  trig_ConvoyDied = NewTrigger("f_died", TrueCondition, failedMission, flight_uft1);
  lMission = 0;
  StartDialog("Dialog2");
end;


--info:top=180,left=30,allvis=0;
function Attack_Convoy()
  trig_AttackConvoy:Delete();
  trig_ConvoyDied:Delete();
  if (ConvoyOffTrigger) then ConvoyOffTrigger:Delete(); end;
  if (ConvoyOffTrigger2) then ConvoyOffTrigger2:Delete(); end;
  if (ConvoyOffTrigger3) then ConvoyOffTrigger3:Delete(); end;
  if (ConvoyOffTrigger4) then ConvoyOffTrigger4:Delete(); end;
  if (trig_Trap) then trig_Trap:Delete(); end;
  if (LineToPortal) then LineToPortal:Delete(); end;
  if (LineToNJ3) then LineToNJ3:Delete(); end;
  if (nav_Convoy) then nav_Convoy:Delete(); end;
  _FTrader_exclude();
  LastochkaSpeaker:Message("#L_Lastochka_03",5,"Kill_Convoy2");
end;


--info:top=220,left=30,allvis=0;
function Kill_Convoy2()
  HeroSpeaker:Message("#L_Hero_02",5,"Kill_Convoy3");
end;


--info:top=260,left=30,allvis=0;
function Kill_Convoy3()
  LastochkaSpeaker:Message("#L_Lastochka_04",6,"Kill_Convoy4");
end;


--info:top=300,left=30,allvis=0;
function Kill_Convoy4()
  HeroSpeaker:Message("#L_Hero_03",5,"failedMission");
end;


--info:top=450,left=30,allvis=0;
function failedMission()
  _FTrader_include();
  StopHere();
-- выключаем триггера
  if (trig_AttackConvoy) then trig_AttackConvoy:Delete(); end;
  if (trig_ConvoyDied) then trig_ConvoyDied:Delete(); end;
  if (ConvoyOffTrigger) then ConvoyOffTrigger:Delete(); end;
  if (ConvoyOffTrigger2) then ConvoyOffTrigger2:Delete(); end;
  if (ConvoyOffTrigger3) then ConvoyOffTrigger3:Delete(); end;
  if (ConvoyOffTrigger4) then ConvoyOffTrigger4:Delete(); end;
  if (trig_Trap) then trig_Trap:Delete(); end;
-- удаляем маршруты
  if (LineToPortal) then LineToPortal:Delete(); end;
  if (LineToNJ3) then LineToNJ3:Delete(); end;
  if (nav_Convoy) then nav_Convoy:Delete(); end;
-- Провал миссии
  SetQuestState("quest_6K", QUEST_FAILED);
  SetInitTeamRelation("Uss", PLAYER_TEAM, RELATION_WAR);
  ClearRoute();
  CreateRoute("nj1", "nj3", "b_leftera1");
end;


--info:top=180,left=170,allvis=0;
function GoTo_NJ2()
  SetQuestLabel("USSAgent", "nothing");
-- Предупредить караван
  flight_uss2:Move(PORTAL_D:GetPosition() + Vector3(0,1600,0));
  flight_uss1:Delete();
  LineToPortal = CreateLine(NP_PORTAL_L, NP_PORTAL_U, RGB(20,80,220), .3,TRUE,.2, 1);
  trig_PortalL = NewTrigger("outside", Trig_Cond, Activate_Fall, mothership, PORTAL_L:GetPosition(), 100);
end;


--info:top=220,left=170,allvis=0;
function Activate_Fall()
  lMission = 1;
  ConvoyOffTrigger=NewTrigger("inside", TrueCondition, Mission_fall, mothership, PORTAL_L:GetPosition(), 40);
  ConvoyOffTrigger2=NewTrigger("inside", TrueCondition, Mission_fall, mothership, PORTAL_D:GetPosition(), 40);
  ConvoyOffTrigger3=NewTrigger("inside", TrueCondition, Mission_fall, mothership, PORTAL_R:GetPosition(), 40);
end;


--info:top=270,left=240,allvis=0;
function Mission_fall()
-- тупой провал миссии сопровождения
  lMission = 0;
  trig_AttackConvoy:Delete();
  trig_ConvoyDied:Delete();
  if (ConvoyOffTrigger) then ConvoyOffTrigger:Delete(); end;
  if (ConvoyOffTrigger2) then ConvoyOffTrigger2:Delete(); end;
  if (ConvoyOffTrigger3) then ConvoyOffTrigger3:Delete(); end;
  if (ConvoyOffTrigger4) then ConvoyOffTrigger4:Delete(); end;
  if (LineToPortal) then LineToPortal:Delete(); end;
  if (LineToNJ3) then LineToNJ3:Delete(); end;
  if (nav_Convoy) then nav_Convoy:Delete(); end;
  _FTrader_exclude();
  SpeakUSS:Message("#L_USS_01",5,"Mission_fall2");
end;


--info:top=310,left=240,allvis=0;
function Mission_fall2()
  flight_uft1:Move(PORTAL_L:GetPosition());
  LastochkaSpeaker:Message("#L_Lastochka_01",10,"Mission_fall4");
  Timer_Seq(2, failedMission);
end;


--info:top=350,left=240,allvis=0;
function Mission_fall4()
  StopHere();
  flight_uft1:Delete();
end;


--info:top=170,left=660,allvis=0;
function GoTo_NJ3()
-- не предупреждать караван
  flight_uss2:Escort(mothership);
  LineToNJ3 = CreateLine(NP_PORTAL_L, NP_PORTAL_R, RGB(20,80,220), .3,TRUE,.2, 1);
  trig_PortalL = NewTrigger("outside", Trig_Cond, Activate_Fall_2, mothership, PORTAL_L:GetPosition(), 100);
  trig_Trap = NewTrigger("outside", Trig_Cond, Deception, mothership, PORTAL_L:GetPosition(), 600);
end;


--info:top=220,left=310,allvis=0;
function Activate_Fall_2()
  lMission = 2;
  ConvoyOffTrigger=NewTrigger("inside", TrueCondition, Mission_fall, mothership, PORTAL_L:GetPosition(), 40);
  ConvoyOffTrigger2=NewTrigger("inside", TrueCondition, Mission_fall, mothership, PORTAL_D:GetPosition(), 40);
  ConvoyOffTrigger3=NewTrigger("inside", TrueCondition, Mission_fall, mothership, PORTAL_R:GetPosition(), 40);
  ConvoyOffTrigger4=NewTrigger("inside", TrueCondition, Mission_fall, mothership, PORTAL_U:GetPosition(), 40);
end;


--info:top=210,left=660,allvis=0;
function Deception()
  SetNormalTimeMode();
  MothershipFlight:Stop();
  LineToNJ3:Delete();
  StartDialog("Dialog3");
end;


--info:top=270,left=390,allvis=0;
function Attack_Ambush()
-- атаковать засаду
  AddQuest("quest_6c_01", "#L_Quest_6c_01a", "#L_Quest_6c_01b", QUEST_PROCESS);
  flight_uft1:Stop();
  flight_uss2:Stop();
  xyz_Convoy = mothership:GetPosition();
  nav_Convoy = CreateNavPoint("#L_nav_convoy",xyz_Convoy,"nav_arba.dds",RGB(255,255,255));
  trig_Outside = NewTrigger("side_outside", TrueCondition, Help_Convoy, PLAYER_TEAM, xyz_Convoy, 950);
  NewTrigger("side_inside", Trig_Cond, Near_Ambush, PLAYER_TEAM, xyz_ambush, 200);
  lMission = 0;
end;


--info:top=310,left=390,allvis=0;
function Near_Ambush()
  LastochkaSpeaker:Message("#L_Lastochka_05",5,"False_Ambush");
  NewPirateFlight("Pirate_Group_1", "piram", xyz_ambush, 1, 4, Vector3(-1, 0, 0));
end;


--info:top=350,left=390,allvis=0;
function False_Ambush()
  SetQuestState("quest_6c_01", QUEST_FAILED);
  if (trig_Outside) then
    trig_Outside:Delete();
    trig_Outside = NIL;
    LastochkaSpeaker:Message("#L_Lastochka_06",5,"Help_Convoy");
  else
    LastochkaSpeaker:Message("#L_Lastochka_06",5);
  end;
end;


--info:top=380,left=360,allvis=0;
function Help_Convoy()
  if (trig_Outside) then
    trig_Outside:Delete();
    trig_Outside = NIL;
  end;
  if (not(LastochkaSpeaker:IsInBase())) and (not(LastochkaSpeaker:IsBasePilot())) and (LastochkaSpeaker:IsCanSayReplica()) then
    LastochkaShip = LastochkaSpeaker:GetShip();
  end;
  if (not(HeroSpeaker:IsInBase())) and (not(HeroSpeaker:IsBasePilot())) and (HeroSpeaker:IsCanSayReplica()) then
    HeroShip = HeroSpeaker:GetShip();
  end;
  if (VectorLength(mothership:GetPosition(), xyz_Convoy)<400) then
    mothership:Blow();
  else
    if (LastochkaShip) then
      if (VectorLength(LastochkaShip:GetPosition(), xyz_Convoy)<400) then
        LastochkaShip:Blow();
      end;
    end;
    if (HeroShip) then
      if (VectorLength(HeroShip:GetPosition(), xyz_Convoy)<400) then
        HeroShip:Blow();
      end;
    end;
    Timer_Seq(1, Convoy_Message);
  end;
end;


--info:top=420,left=360,allvis=0;
function Convoy_Message()
  SpeakUSS:Message("#L_USS_02",7);
  NewTrigger("side_inside", Trig_Cond, Attack_Convoy_Another, PLAYER_TEAM, xyz_Convoy, 150);
  flight_uss1:Delete();
  flight_uss2:Delete();
  AddQuest("quest_6c_02", "#L_Quest_6c_02a", "#L_Quest_6c_02b", QUEST_PROCESS);
end;


--info:top=460,left=360,allvis=0;
function Attack_Convoy_Another()
  SetNormalTimeMode();
  trig_ConvoyDied:Delete();
  ship_uft1_2:Blow();
  ship_uft1_1:SetHP(150);
  NewPirateFlight("Pirate_Group_1", "pir1", xyz_Convoy + Vector3(-10, -10, -40), 1, 8, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pir2", xyz_Convoy + Vector3(-60, 0, -40), 1, 9, Vector3(-1, 0, 0));
  new_SetAllGroupRelations(rep_warpirate, groups_for_rel);
  flight_pir1:Attack(ship_uft1_1);
  flight_pir2:Attack(ship_uft1_1);
  trig_ConvoyDied = NewTrigger("died", TrueCondition, Attack_Pirates, ship_uft1_1);
  HeroSpeaker:Message("#L_Hero_04",4);
  SetAllDied({flight_pir1,flight_pir2}, Died_Pirates);
end;


--info:top=500,left=360,allvis=0;
function Attack_Pirates()
  nav_Convoy:Delete();
  trig_AttackConvoy:Delete();
  SetQuestState("quest_6c_02", QUEST_FAILED);
  SetQuestState("quest_6K", QUEST_FAILED);
  LastochkaSpeaker:Message("#L_Lastochka_07",5);
end;


--info:top=940,left=250,allvis=0;
function Died_Pirates()
  if (ConvoyOffTrigger) then ConvoyOffTrigger:Delete(); end;
  if (ConvoyOffTrigger2) then ConvoyOffTrigger2:Delete(); end;
  if (ConvoyOffTrigger3) then ConvoyOffTrigger3:Delete(); end;
  if (ConvoyOffTrigger4) then ConvoyOffTrigger4:Delete(); end;
  LastochkaSpeaker:Message("#L_Lastochka_08",4,"GoTo_NJ3_Failure");
end;


--info:top=980,left=250,allvis=0;
function GoTo_NJ3_Failure()
  HeroSpeaker:Message("#L_Hero_05",6,"GoTo_NJ3_End");
end;


--info:top=1020,left=250,allvis=0;
function GoTo_NJ3_End()
  LastochkaSpeaker:Message("#L_Lastochka_09",6);
end;


--info:top=270,left=600,allvis=0;
function Lastochka_Scout()
-- послать Ласточку на разведку
  LineToNJ3:Delete();
  trig_KillPlayer = NewTrigger("side_outside", Trig_Cond, Attack_Player, PLAYER_TEAM, mothership:GetPosition(), 150);
  Timer_Seq(1, Lastochka_Scout_2);
end;


--info:top=340,left=600,allvis=0;
function Lastochka_Scout_2()
  if (LastochkaSpeaker:IsInBase())or(LastochkaSpeaker:IsBasePilot()) then
    SysSpeaker:Message("#L_sysmsg_01",10,"Lastochka_Scout_2");
  else
    GoTo_Scout();
  end;
end;


--info:top=310,left=500,allvis=0;
function Attack_Player()
  trig_Warning:Activate(FALSE);
  NewPirateFlight("Pirate_Group_1", "pirK1", mothership:GetPosition() + Vector3(-100, -10, -40), 1, 9, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pirK2", mothership:GetPosition() + Vector3(-80, 0, -40), 1, 8, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pirK3", mothership:GetPosition() + Vector3(100, -10, -40), 1, 11, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pirK4", mothership:GetPosition() + Vector3(80, 0, -40), 1, 8, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pirK5", mothership:GetPosition() + Vector3(-10, -10, -100), 1, 11, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pirK6", mothership:GetPosition() + Vector3(-30, 0, -80), 1, 9, Vector3(-1, 0, 0));
  flight_pirK1:Attack(mothership);
  flight_pirK2:Attack(mothership);
  flight_pirK3:Attack(mothership);
  flight_pirK4:Attack(mothership);
  flight_pirK5:Attack(mothership);
  flight_pirK6:Attack(mothership);
  Anim_D = CreateMovie(_TARGETCAM);
  Anim_D:SetLength(12);
  Anim_D:SetInterpolate(_LINEAR);
  Anim_D:SetTarget(mothership);
  Anim_D:InitMovie(1, TRUE, 1);
  Anim_D:AddPosKey(mothership:GetPosition()+Vector3(100, 30, 30), 0);
  Anim_D:AddScriptKey("MShip_Blow", 8);
  Anim_D:Play();
  Anim_D:AttachEscapeScript("MShip_Blow");
  Anim_D:AttachAction("MShip_Blow");
end;


--info:top=350,left=500,allvis=0;
function MShip_Blow()
  if (mothership:IsAlive()) then
    mothership:Blow();
  end;
end;


--info:top=380,left=630,allvis=0;
function GoTo_Scout()
  LastochkaFlight = LastochkaSpeaker:GetFlight();
  if (LastochkaFlight:GetPilotCount() > 1) then
    SysSpeaker:Message("#L_sysmsg_01",10,"Lastochka_Scout_2");
  else
    Player_Group:RemoveFlight(LastochkaFlight);
    LastochkaFlight:Move(xyz_ambush);
--------------------------------------------------------------------------------
--    trig_Warning = NewTrigger("f_outside", Trig_Cond, Lastochka_Warning, LastochkaFlight, mothership:GetPosition(), 350);
    trig_Warning = NewTrigger("f_outside", Trig_Cond, count_or_go_on, LastochkaFlight, mothership:GetPosition(), 350);
--------------------------------------------------------------------------------
  end;
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
      Lastochka_Warning();
    end;
  else
    Lastochka_Warning();
  end; 
end;

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



--info:top=420,left=600,allvis=0;
function Lastochka_Warning()
  pos = ship_uss2_1:GetPosition();
  flight_uss2:Delete();
  ship_uss1_1:SetPosition(pos);
  trig_KillPlayer:Activate(FALSE);
  trig_UssAttack = NewTrigger("reps", TrueCondition, Attack_USS, Player_Group, USS_Group_2, RELATION_WAR);
  LastochkaSpeaker:Message("#L_Lastochka_10",8,"Hero_Select");
end;


--info:top=500,left=640,allvis=0;
function Hero_Select()
  StopHere();
  trig_PirAttack = NewTrigger("timer", Trig_Cond, IfNotAttack, 15);
end;


--info:top=500,left=520,allvis=0;
function Attack_USS()
-- атаковал самостоятельно
  HeroSpeaker:Message("#L_Hero_06",4);
  if (trig_PirAttack) then trig_PirAttack:Delete(); end;
  shipLastochka = LastochkaSpeaker:GetShip();
  shipLastochka:SetPosition(mothership:GetPosition() + Vector3(150, 0, -50));
  LastochkaFlight:Escort(mothership);
  Player_Group:AddFlight(LastochkaFlight);
  if (flight_uss1:IsAlive()) then
    NewTrigger("died", Trig_Cond, Died_Ambush, ship_uss1_1);
  else
    Timer_Seq(1, Died_Ambush);
  end;
end;


--info:top=540,left=640,allvis=0;
function IfNotAttack()
  SetNormalTimeMode();
  trig_UssAttack:Delete();
  StartDialog("Dialog4");
end;


--info:top=580,left=640,allvis=0;
function Real_Ambush()
-- дождался атаки
  NewPirateFlight("Pirate_Group_1", "pir1", mothership:GetPosition() + Vector3(-100, -10, -40), 1, 8, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pir2", mothership:GetPosition() + Vector3(-80, 0, -40), 1, 9, Vector3(-1, 0, 0));
  new_SetAllGroupRelations(rep_warall, groups_for_rel);
  SetAllDied({flight_pir1,flight_pir2,flight_uss1}, Died_Ambush);
  Timer_Seq(5, Lastochka_Return);
end;


--info:top=620,left=640,allvis=0;
function Lastochka_Return()
  LastochkaFlight:Move(mothership:GetPosition() + Vector3(40, 0, -10));
  Player_Group:AddFlight(LastochkaFlight);
  NewTrigger("f_inside", Trig_Cond, Lastochka_Near, LastochkaFlight, mothership:GetPosition(), 150);
end;


--info:top=660,left=640,allvis=0;
function Lastochka_Near()
  LastochkaSpeaker:Message("#L_Lastochka_14",5);
  LastochkaFlight:Escort(mothership);
end;


--info:top=670,left=520,allvis=0;
function Died_Ambush()
  if (flight_uft1:IsAlive()) then
    capsule = CreateCarcass("Escape_Pod_R", mothership:GetPosition() + Vector3(40, 10, -10), Vector3(0,5, 0, 1));
    FocusOn({capsule}, Vector3(0,0.3,1), 2);
    SetNormalTimeMode();
    StartDialog("Dialog5");
  else
    Timer_Seq(1, Died_Pirates);
  end;
end;


--info:top=710,left=570,allvis=0;
function Bribe_No()
  NewPirateFlight("Pirate_Group_1", "pir1", mothership:GetPosition() + Vector3(-100, -10, -40), 1, 8, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pir2", mothership:GetPosition() + Vector3(-80, 0, -40), 1, 9, Vector3(-1, 0, 0));
  new_SetAllGroupRelations(rep_warall, groups_for_rel);
  SetAllDied({flight_pir1,flight_pir2}, Died_Support);
end;


--info:top=710,left=440,allvis=0;
function Bribe_Ok()
  lMission = 3;
  new_SetAllGroupRelations(rep_neutral, groups_for_rel);
  new_SetGroupRelations("VksGroup_1", "Pirate_Group_1", "N");
  new_SetGroupRelations("PatrolGroup_1", "Pirate_Group_1", "N");
  new_SetGroupRelations("Trade_Group_1", "Pirate_Group_1", "N");
  NewPirateFlight("Pirate_Group_1", "pir1", mothership:GetPosition() + Vector3(-100, -10, -40), 1, 8, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pir2", mothership:GetPosition() + Vector3(-80, 0, -40), 1, 9, Vector3(-1, 0, 0));
  capsule:Delete();
  flight_pir1:Escort(mothership);
  flight_pir2:Escort(mothership);
  SpeakAgentUSS:Message("#L_USS_03",5);
  xyz_Convoy = mothership:GetPosition();
  nav_Convoy = CreateNavPoint("",xyz_Convoy,"nav_void.dds",RGB(255,255,255));
  LineToPortal = CreateLine(nav_Convoy, NP_PORTAL_D, RGB(20,80,220), .3,TRUE,.2, 1);
  NewTrigger("inside", Trig_Cond, Near_AlTrabon, mothership, PORTAL_D:GetPosition(), 75);
  trig_NoPortalL = NewTrigger("inside", Trig_Cond, Attack_Transports, mothership, PORTAL_L:GetPosition(), 75);
  trig_NoPortalR = NewTrigger("inside", Trig_Cond, Attack_Transports, mothership, PORTAL_R:GetPosition(), 75);
  trig_NoPortalU = NewTrigger("inside", Trig_Cond, Attack_Transports, mothership, PORTAL_U:GetPosition(), 75);
  trig_PirateAttack = NewTrigger("reps", TrueCondition, Attack_Transports, Player_Group, Pirate_Group_1, RELATION_WAR);
end;


--info:top=740,left=350,allvis=0;
function Attack_Transports()
  trig_NoPortalL:Delete();
  trig_NoPortalR:Delete();
  trig_NoPortalU:Delete();
  trig_PirateAttack:Delete();
  SetNormalTimeMode();
  if (ship_uft1_1:IsAlive()) then
    flight_pir1:Attack(ship_uft1_1);
  else
    flight_pir1:Attack(ship_uft1_2);
  end;
  if (ship_uft2_1:IsAlive()) then
    flight_pir2:Attack(ship_uft1_2);
  else
    flight_pir2:Attack(ship_uft1_1);
  end;
  SetAllDied({flight_pir1,flight_pir2}, Died_Support);
end;


--info:top=770,left=440,allvis=0;
function Near_AlTrabon()
  SetNormalTimeMode();
  MothershipFlight:Stop();
  nav_Convoy:Delete();
  LineToPortal:Delete();
  trig_NoPortalL:Delete();
  trig_NoPortalR:Delete();
  trig_NoPortalU:Delete();
  trig_PirateAttack:Delete();
  StartDialog("Dialog6");
end;


--info:top=820,left=480,allvis=0;
function Sucker()
  lMission = 3;
  trig_ConvoyDied:Delete();
  if (ConvoyOffTrigger) then ConvoyOffTrigger:Delete(); end;
  if (ConvoyOffTrigger2) then ConvoyOffTrigger2:Delete(); end;
  if (ConvoyOffTrigger3) then ConvoyOffTrigger3:Delete(); end;
  if (ConvoyOffTrigger4) then ConvoyOffTrigger4:Delete(); end;
  flight_uft1:Move(PORTAL_D:GetPosition());
  NewTrigger("f_object_inside", trigger_inside2portal_Condition, Transports_To_AlTrabon, flight_uft1, PORTAL_D, 25);
end;


function Transports_To_AlTrabon()
  flight_uft1:Delete();
  flight_pir1:Move(PORTAL_D:GetPosition());
  NewTrigger("f_object_inside", trigger_inside2portal_Condition, trigger_inside2portal_Action, flight_pir1, PORTAL_D, 25);
  flight_pir2:Move(PORTAL_D:GetPosition());
  NewTrigger("f_object_inside", trigger_inside2portal_Condition, trigger_inside2portal_Action, flight_pir2, PORTAL_D, 25);
end;


--info:top=820,left=360,allvis=0;
function Insight()
  new_SetAllGroupRelations(rep_warall, groups_for_rel);
  SetAllDied({flight_pir1,flight_pir2}, Died_Support);
end;


--info:top=880,left=510,allvis=0;
function Died_Support()
  if (flight_uft1:IsAlive()) then
    if (capsule) then capsule:Delete(); end;
    PlaceModule("Escape_PodAUSS",mothership:GetPosition() + Vector3(40, 10, -10), Vector3(0,5, 0, 1));
    nav_Convoy = CreateNavPoint("",mothership:GetPosition(),"nav_void.dds",RGB(255,255,255));
    if (GetQuestState("quest_6c_03")==QUEST_PROCESS) then SetQuestState("quest_6c_03", QUEST_DONE); end;
    StartDialog("Dialog7");
  else
    Timer_Seq(1, Died_Pirates);
  end;
end;


--info:top=940,left=420,allvis=0;
function Select_NJ2()
  lMission = 1;
  LineToPortal = CreateLine(nav_Convoy, NP_PORTAL_U, RGB(20,80,220), .3,TRUE,.2, 1);
  if (ConvoyOffTrigger4) then ConvoyOffTrigger4:Delete(); end;
end;


--info:top=940,left=550,allvis=0;
function Select_EA()
  lMission = 2;
  LineToPortal = CreateLine(nav_Convoy, NP_PORTAL_R, RGB(20,80,220), .3,TRUE,.2, 1);
  if (ConvoyOffTrigger3) then ConvoyOffTrigger3:Delete(); end;
end;


--info:top=270,left=870,allvis=0;
function GoTo_All()
-- идти всем конвоем вперед
  NewTrigger("outside", Trig_Cond, Traitor, mothership, mothership:GetPosition(), 300);
end;


--info:top=310,left=870,allvis=0;
function Traitor()
  SetNormalTimeMode();
  pos = ship_uss2_1:GetPosition();
  flight_uss2:Delete();
  ship_uss1_1:SetPosition(pos);
  StartDialog("Dialog8");
end;


--info:top=350,left=870,allvis=0;
function Traitor_Attack()
  NewPirateFlight("Pirate_Group_1", "pir1", mothership:GetPosition() + Vector3(-100, -10, -40), 1, 8, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pir2", mothership:GetPosition() + Vector3(-80, 0, -40), 1, 6, Vector3(-1, 0, 0));
  NewPirateFlight("Pirate_Group_1", "pir3", mothership:GetPosition() + Vector3(80, 0, 40), 1, 6, Vector3(-1, 0, 0));
  new_SetAllGroupRelations(rep_warall, groups_for_rel);
  trig_UssDied = NewTrigger("died", Trig_Cond, USS_Died, ship_uss1_1);
  piratesCount = 3;
  trig_Pir1Died = NewTrigger("f_died", Died_Cond, Traitor_Escape, flight_pir1);
  trig_Pir2Died = NewTrigger("f_died", Died_Cond, Traitor_Escape, flight_pir2);
  trig_Pir3Died = NewTrigger("f_died", Died_Cond, Traitor_Escape, flight_pir3);
  flight_uss1:Attack(mothership);
end;


--info:top=380,left=940,allvis=0;
function Died_Cond()
  piratesCount = piratesCount - 1;
  if (piratesCount == 1) then
    return TRUE;
  else
    return FALSE;
  end;
end;


--info:top=420,left=930,allvis=0;
function USS_Died()
  HeroSpeaker:Message("#L_Hero_07",4);
  if (flight_pir1:IsAlive()) then
    trig_Pir1Died:Delete();
    trig_Pir1Died2 = NewTrigger("f_died", Died_Cond_All, Died_Support, flight_pir1);
  end;
  if (flight_pir2:IsAlive()) then
    trig_Pir2Died:Delete();
    trig_Pir2Died2 = NewTrigger("f_died", Died_Cond_All, Died_Support, flight_pir2);
  end;
  if (flight_pir3:IsAlive()) then
    trig_Pir3Died:Delete();
    trig_Pir3Died2 = NewTrigger("f_died", Died_Cond_All, Died_Support, flight_pir3);
  end;
end;


--info:top=450,left=870,allvis=0;
function Died_Cond_All()
  piratesCount = piratesCount - 1;
  if (piratesCount == 0) then
    return TRUE;
  else
    return FALSE;
  end;
end;


--info:top=420,left=770,allvis=0;
function Traitor_Escape()
  flight_uss1:Move(PORTAL_D:GetPosition()+Vector3(-200,600,150));
  NewTrigger("outside", Trig_Cond, Escaped, mothership, mothership:GetPosition(), 300);
  if (flight_pir1:IsAlive()) then
    trig_Pir1Died:Delete();
    trig_Pir1Died2 = NewTrigger("f_died", Died_Cond_All, Pursuit, flight_pir1);
  end;
  if (flight_pir2:IsAlive()) then
    trig_Pir2Died:Delete();
    trig_Pir2Died2 = NewTrigger("f_died", Died_Cond_All, Pursuit, flight_pir2);
  end;
  if (flight_pir3:IsAlive()) then
    trig_Pir3Died:Delete();
    trig_Pir3Died2 = NewTrigger("f_died", Died_Cond_All, Pursuit, flight_pir3);
  end;
  MothershipFlight:Stop();
  if not(LastochkaSpeaker:IsInBase()) then
    LastochkaFlight = LastochkaSpeaker:GetFlight();
    LastochkaFlight:Stop();
  end;
  if not(HeroSpeaker:IsInBase()) then
    HeroFlight = HeroSpeaker:GetFlight();
    HeroFlight:Stop();
  end;
  SpeakAgentUSS:Message("#L_USS_04",5,"Escape_USS1");
end;


--info:top=460,left=770,allvis=0;
function Escape_USS1()
  MothershipFlight:Stop();
  if not(LastochkaSpeaker:IsInBase()) then
    LastochkaFlight = LastochkaSpeaker:GetFlight();
    LastochkaFlight:Stop();
  end;
  if not(HeroSpeaker:IsInBase()) then
    HeroFlight = HeroSpeaker:GetFlight();
    HeroFlight:Stop();
  end;
  LastochkaSpeaker:Message("#L_Lastochka_11",3,"Escape_USS2");
  AddQuest("quest_6c_03", "#L_Quest_6c_03a", "#L_Quest_6c_03b", QUEST_PROCESS);
end;


--info:top=500,left=770,allvis=0;
function Escape_USS2()
  StopHere();
  MothershipFlight:Stop();
  if not(LastochkaSpeaker:IsInBase()) then
    LastochkaFlight = LastochkaSpeaker:GetFlight();
    LastochkaFlight:Stop();
  end;
  if not(HeroSpeaker:IsInBase()) then
    HeroFlight = HeroSpeaker:GetFlight();
    HeroFlight:Stop();
  end;
end;


--info:top=530,left=790,allvis=0;
function Escaped()
  ship_uss1_1:SetPosition(PORTAL_D:GetPosition()+Vector3(-200,600,150));
  trig_UssDied:Delete();
end;


--info:top=580,left=850,allvis=0;
function Pursuit()
  nav_Convoy = CreateNavPoint("",mothership:GetPosition(),"nav_void.dds",RGB(255,255,255));
  StartDialog("Dialog9");
end;


--info:top=710,left=860,allvis=0;
function Pursuit_ToTaira()
  LineToPortal = CreateLine(nav_Convoy, NP_PORTAL_L, RGB(20,80,220), .3,TRUE,.2, 1);
  NewTrigger("inside", Trig_Cond, Not_Pursuited, mothership, PORTAL_L:GetPosition(), 125);
end;


--info:top=710,left=990,allvis=0;
function Pursuit_ToNJ2()
  LineToPortal = CreateLine(nav_Convoy, NP_PORTAL_U, RGB(20,80,220), .3,TRUE,.2, 1);
  NewTrigger("inside", Trig_Cond, Not_Pursuited, mothership, PORTAL_U:GetPosition(), 125);
end;


--info:top=710,left=1100,allvis=0;
function Pursuit_ToNJ3()
  LineToPortal = CreateLine(nav_Convoy, NP_PORTAL_R, RGB(20,80,220), .3,TRUE,.2, 1);
  NewTrigger("inside", Trig_Cond, Not_Pursuited, mothership, PORTAL_R:GetPosition(), 125);
end;


--info:top=760,left=990,allvis=0;
function Not_Pursuited()
  SetNormalTimeMode();
  MothershipFlight:Stop();
  nav_Convoy:Delete();
  LineToPortal:Delete();
  SysSpeaker:Message("#L_sysmsg_02",6);
  nav_Convoy = CreateNavPoint("",mothership:GetPosition(),"nav_void.dds",RGB(255,255,255));
  Timer_Seq(60, Not_Wait_Till);
end;


--info:top=800,left=990,allvis=0;
function Not_Wait_Till()
  LastochkaSpeaker:Message("#L_Lastochka_12",4,"GoTo_ElArriash");
end;


--info:top=840,left=990,allvis=0;
function GoTo_ElArriash()
  SetQuestState("quest_6c_03", QUEST_FAILED);
  HeroSpeaker:Message("#L_Hero_08",6);
  LineToPortal = CreateLine(nav_Convoy, NP_PORTAL_R, RGB(20,80,220), .3,TRUE,.2, 1);
  lMission = 2;
  if (ConvoyOffTrigger3) then ConvoyOffTrigger3:Delete(); end;
end;


--info:top=710,left=710,allvis=0;
function Pursuit_ToAlTrabon()
  LineToPortal = CreateLine(nav_Convoy, NP_PORTAL_D, RGB(20,80,220), .3,TRUE,.2, 1);
  NewTrigger("inside", Trig_Cond, Pursuited, mothership, PORTAL_D:GetPosition(), 300);
end;


--info:top=750,left=710,allvis=0;
function Pursuited()
  SetNormalTimeMode();
  MothershipFlight:Stop();
  nav_Convoy:Delete();
  LineToPortal:Delete();
  ship_uss1_1:SetPosition(mothership:GetPosition()+Vector3(-20,0,-100));
  trig_UssDied2 = NewTrigger("died", Trig_Cond, Died_Support, ship_uss1_1);
  SpeakAgentUSS:Message("#L_USS_05",5,"Final_Kill");
end;


--info:top=790,left=710,allvis=0;
function Final_Kill()
  LastochkaSpeaker:Message("#L_Lastochka_13",5);
end;


--info:top=100,left=30,allvis=0;
function StartInitMis()
  UftTeam = CreateTeam("Uft");
  USSTeam = CreateTeam("Uss");
  PirateTeam = CreateTeam("Pirates");

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

  Player_Group = MothershipPilot:GetGroup();
  Uft_Group_1 = UftTeam:CreateGroup("Uft_Group_1");
  USS_Group_1 = USSTeam:CreateGroup("USS_Group_1");
  USS_Group_2 = USSTeam:CreateGroup("USS_Group_2");
  Pirate_Group_1 = PirateTeam:CreateGroup("Pirate_Group_1");
  groups_for_rel = {Uft_Group_1,USS_Group_1,USS_Group_2,Pirate_Group_1,Player_Group};
  rep_neutral = {{"F"},
                 {"N","N"},
                 {"N","N","N"},
                 {"F","N","N","N"}};
  rep_warpirate = {{"X"},
                 {"X","X"},
                 {"W","X","X"},
                 {"X","X","X","W"}};
  rep_warall = {{"X"},
                 {"X","X"},
                 {"X","X","X"},
                 {"X","X","W","W"}};
  new_SetAllGroupRelations(rep_neutral, groups_for_rel);

  NewFlight("Uft_Group_1", "uft1", "Walrus_pl1", "UFTTrader", mothership:GetPosition()+Vector3(0, 10, -20), Vector3(1, 0, 0));
  NewShip("uft1_2", "Walrus_pl1", "UFTTrader", mothership:GetPosition()+Vector3(0, 20, -30), Vector3(1, 0, 0));
  flight_uft1:AddShip(ship_uft1_2);
  NewTrigger("outside", Trig_Cond, Activate_Escort, mothership, PORTAL_L:GetPosition(), 40);
  ship_uft1_1:ApplyImpulse(15, Vector3(1, 0, 0));
  ship_uft1_2:ApplyImpulse(15, Vector3(1, 0, 0));
  NewFlight("USS_Group_1", "uss2", "Hammerhead_uss1", "USSAgent", mothership:GetPosition()+Vector3(45, 10, 40), Vector3(0.5, 0, 0.5));
  NewFlight("USS_Group_2", "uss1", "Hammerhead_uss1", "USSAgent", Vector3(1000, 700, 1000), Vector3(0.5, 0, 0.5));
  HeroSpeaker = GetPilot("Hero");
  LastochkaSpeaker = GetPilot("Lastochka");
  SpeakUSS = CreatePilot("UFTTrader");
  SpeakAgentUSS = CreatePilot("m6c_USSAgent");
  SysSpeaker = CreatePilot("Hint");

  xyz_ambush = Vector3(600, 0, -400);
end;


--info:top=140,left=30,allvis=0;
function Activate_Escort()
  flight_uft1:Escort(mothership);
end;


--info:top=70,left=170,allvis=0;
function ACTION_INIT()
  _FTrader_exclude();
  StartInitMis();
  Timer_Seq(2, StartMission);
  return TRUE;
end;


--info:top=70,left=440,allvis=0;
function ACTION_LEAVELOCATION()
  if (LineToPortal) then LineToPortal:Delete(); end;
  if (LineToNJ3) then LineToNJ3:Delete(); end;
  if (nav_Convoy) then nav_Convoy:Delete(); end;
  if (GetQuestState("quest_6c_01")==QUEST_PROCESS) then SetQuestState("quest_6c_01", QUEST_FAILED); end;
  if (GetQuestState("quest_6c_02")==QUEST_PROCESS) then SetQuestState("quest_6c_02", QUEST_FAILED); end;
  if (GetQuestState("quest_6c_03")==QUEST_PROCESS) then SetQuestState("quest_6c_03", QUEST_FAILED); end;
  QuestActionDone();
  if (lMission==0) then
    if (GetQuestState("quest_6K")==QUEST_PROCESS) then SetQuestState("quest_6K", QUEST_FAILED); end;
    RemovePost("mail_006");
    RemovePost("mail_0061");
    AddPost("mail_0062");
    AddPost("book006_9");
    QuestStart("mission_6");
  elseif (lMission==1) then
    if (dest_location=="nj2") then
      QuestStart("mission_6c_1");
    else
      if (GetQuestState("quest_6K")==QUEST_PROCESS) then SetQuestState("quest_6K", QUEST_FAILED); end;
      RemovePost("mail_006");
      RemovePost("mail_0061");
      AddPost("mail_0062");
      AddPost("book006_10");
      QuestStart("mission_6");
    end;
  elseif (lMission==2) then
    if (dest_location=="nj3") then
      QuestStart("mission_6c_2");
    else
      if (GetQuestState("quest_6K")==QUEST_PROCESS) then SetQuestState("quest_6K", QUEST_FAILED); end;
      RemovePost("mail_006");
      RemovePost("mail_0061");
      AddPost("mail_0062");
      AddPost("book006_10");
      QuestStart("mission_6");
    end;
  elseif (lMission==3) then
    if (dest_location=="altrabon") then
      QuestStart("mission_6c_3");
    else
      if (GetQuestState("quest_6K")==QUEST_PROCESS) then SetQuestState("quest_6K", QUEST_FAILED); end;
      RemovePost("mail_006");
      RemovePost("mail_0061");
      AddPost("mail_0062");
      AddPost("book006_10");
      QuestStart("mission_6");
    end;
  end;

  return TRUE;
end;


--info:top=70,left=680,allvis=0;
function ACTION_FINI()
  _FTrader_include();
  return TRUE;
end;
