------------------------------------------------------------
--     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=160,left=140,allvis=0;
function StartMission()
-- начало действий
  SetNormalTimeMode();
  MothershipFlight:Stop();
  LineToMercBase:Delete();
  nav_Current:Delete();
  SetQuestState("quest_4_04", QUEST_DONE);
  MercCommander:Message("#L_Merc_01",19,"Merc_Meeting1");
end;


--info:top=200,left=140,allvis=0;
function Merc_Meeting1()
  HeroSpeaker:Message("#L_Hero_01",1,"Merc_Meeting2");
end;


--info:top=240,left=140,allvis=0;
function Merc_Meeting2()
  MercCommander:Message("#L_Merc_02",8);
  Timer_Seq(6, GoTo_NavPoint1);
end;


--info:top=280,left=140,allvis=0;
function GoTo_NavPoint1()
  flight_merc1:Escort(mothership);
  flight_merc2:Move(xys_war_pirates+Vector3(0,200,0));
-- создаем точки маршрута
  nav_Start_Point = CreateNavPoint("#L_nav_first",xyz_start_point,"nav_default.dds",RGB(255,255,255));
  LineToStartPoint = CreateLine(nav_MercStation, nav_Start_Point, RGB(20,80,220), .3,TRUE,.2, 1);
  nav_War_Point = CreateNavPoint("#L_nav_second",xys_war_pirates,"nav_default.dds",RGB(255,255,255));
  nav_End_Point = CreateNavPoint("#L_nav_third",xys_end_point,"nav_default.dds",RGB(255,255,255));
  AddQuest("quest_4_01", "#L_Quest_4_01a", "#L_Quest_4_01b", QUEST_PROCESS);
  trig_Start_point = NewTrigger("inside", Trig_Cond, GoTo_NavPoint2, mothership, xyz_start_point, 25);
end;


--info:top=140,left=200,allvis=0;
function Dogs_Defends()
  flight_dogs1:Attack(mothership);
  flight_dogs2:Attack(mothership);
  flight_dogs3:Attack(mothership);
end;


--info:top=320,left=140,allvis=0;
function GoTo_NavPoint2()
  trig_Start_point:Activate(FALSE);
  LineToStartPoint:Delete();
  LineToWarPirates = CreateLine( nav_Start_Point,nav_War_Point, RGB(20,80,220), .3,TRUE,.2, 1);
  trig_War_point = NewTrigger("inside", Trig_Cond, MeetingDogs, mothership, xys_war_pirates, 50);
end;


--info:top=360,left=140,allvis=0;
function MeetingDogs()
  trig_War_point:Activate(FALSE);
  LineToWarPirates:Delete();
  SetNormalTimeMode();
  MothershipFlight:Stop();
  SetQuestState("quest_4_01", QUEST_DONE);
--  AddPlayerExperience(5);
  nav_Start_Point:Delete();
  nav_War_Point:Delete();
  nav_End_Point:Delete();
-- создаем пиратов
  if (flight_dogs1~=NIL) then flight_dogs1:Delete(); end;
  if (flight_dogs2~=NIL) then flight_dogs2:Delete(); end;
  if (flight_dogs3~=NIL) then flight_dogs3:Delete(); end;
  trig_DogsBase:Delete();
  mRadar = Player_Group:CreateRadar(mothership:GetPosition(),250,0.1);
  NewPirateFlight("PirateGroup_1", "dogs1", xys_war_pirates+Vector3(-50, 10, -5), 1, 4, Vector3(1, 0, 0));
  NewPirateFlight("PirateGroup_1", "dogs2", xys_war_pirates+Vector3(-5, -10, -50), 1, 4, Vector3(1, 0, 0));
  NewPirateFlight("PirateGroup_1", "dogs3", xys_war_pirates+Vector3(-30, 0, -30), 1, 5, Vector3(1, 0, 0));
  pilot_dogs3_1:Message("#L_Pir_01",4);
  Timer_Seq(6, BeginFight);
end;


--info:top=400,left=140,allvis=0;
function BeginFight()
  new_SetAllGroupRelations(rep_merc_ws_pir, groups_for_rel);
-- вторая партия наемников
  NewFlight("MercGroup", "merc3", "Stormcrow_merc2", "RecruitPilot", xys_war_pirates+Vector3(-70, 10, -5), Vector3(1, 0, 0));
  NewShip("merc3_2", "Stormcrow_merc1", "RecruitPilot", xys_war_pirates+Vector3(-70, 10, -10), Vector3(1, 0, 0));
  flight_merc3:AddShip(ship_merc3_2);
  NewFlight("MercGroup", "merc4", "Excalibur_merc2", "RecruitOfficer", xys_war_pirates+Vector3(-5, 10, -70), Vector3(1, 0, 0));
  NewShip("merc4_2", "Excalibur_merc2", "RecruitPilot", xys_war_pirates+Vector3(-10, 10, -70), Vector3(1, 0, 0));
  flight_merc4:AddShip(ship_merc4_2);
  flight_merc1:Attack(ship_dogs3_1);
  flight_merc2:Attack(ship_dogs3_2);
  flight_merc3:Attack(ship_dogs1_1);
  flight_merc4:Attack(ship_dogs2_1);
  SetAllDied({flight_dogs1,flight_dogs2,flight_dogs3}, Died_Pirates);
end;


--info:top=440,left=140,allvis=0;
function Died_Pirates()
  Player_Group:DeleteRadar(mRadar);
  nav_BasePirates = CreateNavPoint("#L_nav_DogsBase", xyz_dogs_base,"nav_arba_pir.dds", RGB(255,255,255));
  nav_WarPirates = CreateNavPoint("#L_nav_War",xys_war_pirates,"nav_pir1.dds",RGB(255,255,255));
  LineToDogsBase = CreateLine( nav_WarPirates,nav_BasePirates, RGB(20,80,220), .3,TRUE,.2, 1);
  trig_DogsBase = NewTrigger("inside", Trig_Cond, Dialog_Lastochka, mothership, xyz_dogs_base, 50);
  MercCommander:Message("#L_Merc_03",3,"Died_Pirates2");
end;


--info:top=490,left=40,allvis=0;
function Died_Pirates2()
  HeroSpeaker:Message("#L_Hero_02",3,"GoTo_DogsBase");
end;


--info:top=530,left=40,allvis=0;
function GoTo_DogsBase()
  if (flight_merc1~=NIL) then flight_merc1:Escort(mothership); end;
  if (flight_merc2~=NIL) then flight_merc2:Escort(mothership); end;
  if (flight_merc3~=NIL) then flight_merc3:Escort(mothership); end;
  if (flight_merc4~=NIL) then flight_merc4:Escort(mothership); end;
end;


--info:top=560,left=140,allvis=0;
function Dialog_Lastochka()
  trig_DogsBase:Activate(FALSE);
  LineToDogsBase:Delete();
  SetNormalTimeMode();
  MothershipFlight:Stop();
  if (flight_merc2) and (flight_merc2:IsAlive()) then flight_merc2:Move(xyz_dogs_base+Vector3(0, -6, 0)); end;
  if (flight_merc4) and (flight_merc4:IsAlive()) then flight_merc4:Move(xyz_dogs_base+Vector3(0, -6, -6)); end;
  Anim_1 = CreateMovie(_ASIMUTHCAM);
  Anim_1:SetLength(11);
  Anim_1:SetInterpolate(_LINEAR);
  Anim_1:SetTarget(new_mothership);
  Anim_1:InitMovie(1, TRUE, 2);
  Anim_1:AddKeys(147.8268, 62.9834, 40, 0);
  Anim_1:AddKeys(93.1433, 156.9258, 30, 5);
  Anim_1:AddKeys(93.1433, 156.9258, 12, 11);
--  Anim_1:AddKeys(136.1402, 62.1494, 40, 20);
  Anim_1:AddScriptKey("Dialog_Lastochka1", 1);
  Anim_1:AddScriptKey("Dialog_Lastochka2", 4);
  Anim_1:AddScriptKey("Dialog_Lastochka3", 6);
  Anim_1:AttachEscapeScript("Dogs_Base_Occupy");
  Anim_1:AttachAction("Dogs_Base_Occupy");
  Anim_1:Play();
end;


--info:top=590,left=190,allvis=0;
function Dialog_Lastochka1()
  LastochkaSpeaker:Message("#L_Lastochka_01",2);
end;


--info:top=620,left=190,allvis=0;
function Dialog_Lastochka2()
  HeroSpeaker:Message("#L_Hero_03",1);
end;


--info:top=650,left=190,allvis=0;
function Dialog_Lastochka3()
  LastochkaSpeaker:Message("#L_Lastochka_02",3);
end;


--info:top=670,left=140,allvis=0;
function Dogs_Base_Occupy()
  FightSpeakers = CreatePilot("MercBasePilot");
  FightSpeakers:Message("#L_Fight_01",20,"Fin_Dogs_Base_Occupy");

end;


--info:top=710,left=140,allvis=0;
function Fin_Dogs_Base_Occupy()
  lPay = GetQuestLabel("Pay");
  ClearQuestLabel("Pay");
  if (lPay=="Yes") then
    MercCommander:Message("#L_Merc_04",5,"By_Merc1");
    mothership:AddShipToInventory("Excalibur_pl1", 1);
  else
    MercCommander:Message("#L_Merc_06",10,"Another_By_Merc1");
  end;
end;


--info:top=770,left=30,allvis=0;
function By_Merc1()
  HeroSpeaker:Message("#L_Hero_04",1,"By_Merc2");
end;


--info:top=770,left=240,allvis=0;
function Another_By_Merc1()
  HeroSpeaker:Message("#L_Hero_05",1,"Another_By_Merc2");
end;


--info:top=810,left=240,allvis=0;
function Another_By_Merc2()
  MercCommander:Message("#L_Merc_07",6,"Another_By_Merc3");
end;


--info:top=850,left=240,allvis=0;
function Another_By_Merc3()
  HeroSpeaker:Message("#L_Hero_06",2,"By_Merc2");
end;


--info:top=900,left=130,allvis=0;
function By_Merc2()
--------------------------------------------------------------------------------
--  MercCommander:Message("#L_Merc_05",2,"New_Mothership");
  MercCommander:Message("#L_Merc_05",2,"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() >= 6) then
      choose_pilot();
    else
      New_Mothership();
    end;
  else
    New_Mothership();
  end; 
end;

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



--info:top=940,left=130,allvis=0;
function New_Mothership()
  StopHere();
  if (flight_merc1~=NIL) then
    flight_merc1:Move(xyz_MercStation+Vector3(-50, 10, 5));
    NewTrigger("f_inside", TrueCondition, Delete_Mercs, flight_merc1, xyz_MercStation, 75);
  end;
  if (flight_merc2~=NIL) then
    flight_merc2:Move(xyz_MercStation+Vector3(-40, 10, 5));
    NewTrigger("f_inside", TrueCondition, Delete_Mercs, flight_merc2, xyz_MercStation, 75);
  end;
  if (flight_merc3~=NIL) then
    flight_merc3:Move(xyz_MercStation+Vector3(-30, 10, 15));
    NewTrigger("f_inside", TrueCondition, Delete_Mercs, flight_merc3, xyz_MercStation, 75);
  end;
  if (flight_merc4~=NIL) then
    flight_merc4:Move(xyz_MercStation+Vector3(-20, 10, 25));
    NewTrigger("f_inside", TrueCondition, Delete_Mercs, flight_merc4, xyz_MercStation, 75);
  end;
  nav_MercStation:Delete();
  Change_Mathership();
  SetQuestLabel("ReadyStoryDlg","FALSE");

  Anim_2 = CreateMovie(_ASIMUTHCAM);
  Anim_2:SetLength(11);
  Anim_2:SetInterpolate(_LINEAR);
  Anim_2:SetTarget(old_arba);
  Anim_2:InitMovie(1, TRUE, 0);
  Anim_2:AddKeys(145.0171, 62.6476, 60.00, 0);
  Anim_2:AddKeys(175.4165, 56.3927, 39.03, 11);
  Anim_2:AttachEscapeScript("Transfer_End");

  Anim_3 = CreateMovie(_ASIMUTHCAM);
  Anim_3:SetLength(15);
  Anim_3:SetInterpolate(_LINEAR);
  Anim_3:SetTarget(new_mothership);
  Anim_3:InitMovie(1, TRUE, 3);
  Anim_3:AddKeys(147.8268, 62.9834, 39.03, 0);
  Anim_3:AddKeys(230.4165, 56.3927, 39.03, 8);
  Anim_3:AddKeys(316.2579, 57.4963, 28.06, 15);
  Anim_3:AttachEscapeScript("Transfer_End");
  Anim_3:AttachAction("Transfer_End");

  PlayList({Anim_2,Anim_3});
end;


--info:top=970,left=180,allvis=0;
function Delete_Mercs()
  if (flight_merc1~=NIL) then flight_merc1:Delete(); end;
  if (flight_merc2~=NIL) then flight_merc2:Delete(); end;
  if (flight_merc3~=NIL) then flight_merc3:Delete(); end;
  if (flight_merc4~=NIL) then flight_merc4:Delete(); end;
  if (flight_mercB~=NIL) then flight_mercB:Delete(); end;
end;


--info:top=1020,left=130,allvis=0;
function Transfer_End()
  lPoint = 0;
  SetQuestLabel("Phantom","MeetNo");
  FocusOn(mothership,Vector3(-1,0.4,0.5),30);
--  AddPlayerExperience(20);
  Old_Mothership_Flight:Escort(mothership);
  RemovePost("mail_004");
  AddPost("mail_0045");
  AddQuest("quest_4_02", "#L_Quest_4_02a", "#L_Quest_4_02b", QUEST_PROCESS);
  LineToPortal = CreateLine(nav_BasePirates, NP_PORTAL_U, RGB(20,80,220), .3,TRUE,.2, 1);
  NewTrigger("inside", Trig_Cond, Save_Game, mothership, PORTAL_U:GetPosition(), 40);
  trig_NearPortal = NewTrigger("inside", Trig_Cond, Drop_Transport, mothership, PORTAL_U:GetPosition(), 150);
  trig_SOS = NewTrigger("outside", Trig_Cond, SOS_Message, mothership, xyz_dogs_base, 250);
  trig_AttackArba = NewTrigger("reps", Trig_Cond, Arba_Attack, Player_Group, PhantomGroup_2, RELATION_WAR);
  CreateRoute("ahilles", "argon", "gefest", "elio");
  StartDialog("Dialog3");
end;


--info:top=1240,left=330,allvis=0;
function Drop_Transport()
  SetNormalTimeMode();
  StartDialog("Dialog6");
end;


--info:top=1280,left=330,allvis=0;
function Transport_ToStation()
  Old_Mothership_Flight:Move(TRADE_STATION:GetPosition());
end;


--info:top=1060,left=320,allvis=0;
function Arba_Attack()
  trig_DiedArba = NewTrigger("died", Trig_Cond, Arba_Died, old_arba);
  LastochkaSpeaker:Message("#L_Lastochka_03",1,"Arba_Attack_2");
end;


--info:top=1090,left=400,allvis=0;
function Arba_Attack_2()
  HeroSpeaker:Message("#L_Hero_07",3);
end;


--info:top=1100,left=320,allvis=0;
function Arba_Died()
  tRel = GetGroupRelation(Player_Group,PhantomGroup_2);
  if (tRel==RELATION_WAR) then
    StartDialog("Dialog5");
  end;
end;


--info:top=1140,left=320,allvis=0;
function Debil_Died()
  mothership:Blow();
end;


--info:top=1050,left=20,allvis=0;
function Set_New_Reputation()
-- ВКС
  SetInitTeamRelation("Vks", PLAYER_TEAM, RELATION_WAR);
  SetInitTeamRelation(PLAYER_TEAM, "Vks", RELATION_WAR);
-- КФНИ
  SetInitTeamRelation("Kfni", PLAYER_TEAM, RELATION_WAR);
  SetInitTeamRelation(PLAYER_TEAM, "Kfni", RELATION_WAR);
-- Патруль
  SetInitTeamRelation("Patrol", PLAYER_TEAM, RELATION_WAR);
  SetInitTeamRelation(PLAYER_TEAM, "Patrol", RELATION_WAR);
-- Пираты
  SetInitTeamRelation("Pirates", PLAYER_TEAM, RELATION_NEUTRAL);
  SetInitTeamRelation(PLAYER_TEAM, "Pirates", RELATION_NEUTRAL);
  SetGroupRelation(Pirate_Group_1_1, PLAYER_GROUP, RELATION_NEUTRAL);
  SetGroupRelation(PLAYER_GROUP, Pirate_Group_1_1, RELATION_NEUTRAL);
end;


--info:top=1000,left=180,allvis=0;
function Change_Mathership()
  old_arba = mothership;
  mothership = SetPlayerMotherShip(new_mothership);
  TempPilot = CreatePilot("Autopilot");
  old_arba:AssignPilot(TempPilot);
  Old_Mothership_Flight = PhantomGroup_2:CreateFlight("Old_Mothership_Flight");
  Old_Mothership_Flight:AddShip(old_arba);

  PortalTrigger_PORTAL_U:SetObject(mothership);
  PortalTrigger_PORTAL_D:SetObject(mothership);
  CreateTradeStationDocking(TRADE_STATION,mothership);
  GetShipName(mothership);
  mothership:AddShipToInventory("Excalibur_pir1", 1);
  AddPilotToPlayer(LastochkaSpeaker);
end;


--info:top=1080,left=130,allvis=0;
function SOS_Message()
  MothershipPilot = mothership:GetPilot();
  MothershipFlight = MothershipPilot:GetFlight();
  Player_Group = MothershipPilot:GetGroup();
  StartDialog("Dialog1");
end;


--info:top=1120,left=130,allvis=0;
function GoTo_Phantom()
  LineToPortal:Delete();
  nav_Current = CreateNavPoint("", mothership:GetPosition(),"nav_void.dds");
  nav_Phantom = CreateNavPoint("#L_nav_Phantom",xys_Phantom,"nav_pir1.dds",RGB(255,255,255));
  LineToPhantom = CreateLine(nav_Current, nav_Phantom, RGB(20,80,220), .3,TRUE,.2, 1);
  AddQuest("quest_4_03", "#L_Quest_4_03a", "#L_Quest_4_03b", QUEST_PROCESS);
  trig_Phantom = NewTrigger("inside", Trig_Cond, Help_Phantom, mothership, xys_Phantom, 150);
  dist = VectorLength(mothership:GetPosition(), xys_Phantom) + 75;
  trig_NoHelp = NewTrigger("outside", TrueCondition, No_Help, mothership, xys_Phantom, dist);
  trig_Timer = NewTrigger("timer", TrueCondition, No_Help, 600);
end;


--info:top=1160,left=230,allvis=0;
function No_Help()
  trig_Phantom:Delete();
  trig_Phantom = NIL;
  trig_NoHelp:Delete();
  trig_NoHelp = NIL;
  trig_Timer:Delete();
  trig_Timer = NIL;
  NewFlight("PhantomGroup_1", "ph1", "Arba", "UFTTrader", xys_Phantom+Vector3(-10, 5, -5), Vector3(-1, 0, 0));
  NewFlight("PhantomGroup_2", "ph2", "Walrus_pl", "UFTTrader", xys_Phantom+Vector3(-5, 5, -50), Vector3(0, 0, 1));
  NewShip("ph2_2", "Walrus_pl", "UFTTrader", xys_Phantom+Vector3(-15, 5, -65), Vector3(0, 0, 1));
  ship_ph1_1:Blow();
  ship_ph2_1:Blow();
  ship_ph2_2:Blow();
  NewTrigger("inside", TrueCondition, Near_SOS_Point, mothership, xys_Phantom, 75);
end;


--info:top=1200,left=230,allvis=0;
function Near_SOS_Point()
  SetNormalTimeMode();
  MothershipFlight:Stop();
  SetQuestState("quest_4_03", QUEST_FAILED);
  LastochkaSpeaker:Message("#L_Lastochka_04", 13);
end;


--info:top=1160,left=40,allvis=0;
function Help_Phantom()
  trig_Phantom:Delete();
  LineToPhantom:Delete();
  trig_NearPortal:Delete();
  trig_NearPortal = NIL;
  trig_NoHelp:Delete();
  trig_NoHelp = NIL;
  trig_Timer:Delete();
  trig_Timer = NIL;
  SetNormalTimeMode();
  NewPirateFlight("PirateGroup_2", "pir2", xys_Phantom+Vector3(-50, 10, -5), 1, 4, Vector3(1, 0, 0));
  ship_pir2_1:SetPosition(xys_Phantom+Vector3(-50, 10, -5));
  if (ship_pir2_2) and (ship_pir2_2:IsAlive()) then
    ship_pir2_2:SetPosition(xys_Phantom+Vector3(50, 10, -10));
  end;
  if (ship_pir2_3) and (ship_pir2_3:IsAlive()) then
    ship_pir2_3:SetPosition(xys_Phantom+Vector3(-50, -30, 0));
  end;
  NewFlight("PhantomGroup_1", "ph1", "Arba", "UFTTrader", xys_Phantom+Vector3(-10, 5, -5), Vector3(-1, 0, 0));
  NewFlight("PhantomGroup_2", "ph2", "Walrus_pl", "UFTTrader", xys_Phantom+Vector3(-5, 5, -50), Vector3(0, 0, 1));
  NewShip("ph2_2", "Walrus_pl", "UFTTrader", xys_Phantom+Vector3(-15, 5, -65), Vector3(0, 0, 1));
  flight_ph2:AddShip(ship_ph2_2);
  new_SetAllGroupRelations(rep_phan_ws_pir, groups_for_rel);
  SetAllDied({flight_pir2}, Help_Phantom_Done);
  ship_ph1_1:SetHP(30);
  flight_pir2:Attack(ship_ph1_1);
  trig_Phantom = NewTrigger("inside", Trig_Cond, Phantom_ARBA_Blow, mothership, xys_Phantom, 75);
end;


--info:top=1190,left=70,allvis=0;
function Phantom_ARBA_Blow()
  MothershipPilot = mothership:GetPilot();
  MothershipFlight = MothershipPilot:GetFlight();
  Player_Group = MothershipPilot:GetGroup();
  if (flight_ph1) and (flight_ph1:IsAlive()) then ship_ph1_1:Blow(); end;
end;


--info:top=1210,left=40,allvis=0;
function Help_Phantom_Done()
  SetQuestState("quest_4_03", QUEST_DONE);
--  AddPlayerExperience(5);
  StartDialog("Dialog2");
end;


--info:top=1250,left=40,allvis=0;
function All_Did()
  SetQuestLabel("Phantom","Friend");
  flight_ph2:Escort(old_arba);
  Old_Mothership_Flight:Move(TRADE_STATION:GetPosition());
  mothership:AddModuleToInventory("BS_LRS2",1);
  mothership:AddModuleToInventory("BS_EngAmp1",1);
  LineToPortal = CreateLine(nav_Phantom,NP_PORTAL_U, RGB(20,80,220), .3,TRUE,.2, 1);
  Anim_4 = CreateMovie(_TARGETCAM);
  Anim_4:SetLength(15);
  Anim_4:SetInterpolate(_LINEAR);
  Anim_4:SetTarget(ship_ph2_1);
  Anim_4:InitMovie(1, TRUE, 3);
  Anim_4:AddPosKey(xys_Phantom, 0);
  Anim_4:AttachEscapeScript("Fin_Dialog");

  Anim_5 = CreateMovie(_TARGETCAM);
  Anim_5:SetLength(15);
  Anim_5:SetInterpolate(_LINEAR);
  Anim_5:SetTarget(old_arba);
  Anim_5:InitMovie(1, TRUE, 3);
  Anim_5:AddPosKey(old_arba:GetPosition()+Vector3(20, 5, -10), 0);
  Anim_5:AttachEscapeScript("Fin_Dialog");
  Anim_5:AttachAction("Fin_Dialog");

  PlayList({Anim_4,Anim_5});
end;


--info:top=1290,left=40,allvis=0;
function Fin_Dialog()
  if (trig_AttackArba) then trig_AttackArba:Delete(); end;
  Old_Mothership_Flight:Delete();
  flight_ph2:Delete();
  StartDialog("Dialog4");
end;


--info:top=1330,left=230,allvis=0;
function Save_Game()
  AddPost("news004_1");
  AddPost("news004_2");
  AddPost("news004_3");
  AddPost("news004_4");
  if (GetQuestLabel("Phantom")=="Friend") then
    AddPost("book004_1");
  else
    AddPost("book004_2");
  end;
  if (GetQuestState("quest_4_03")==QUEST_PROCESS) then SetQuestState("quest_4_03", QUEST_FAILED); end;
  AutoSave("#AS_mission_4");
end;


--info:top=110,left=140,allvis=0;
function StartInitMis()
  UftTeam = CreateTeam("Uft");
  PirateTeam = CreateTeam("Pirates");
  MercTeam = CreateTeam("Recruits");
  PatrolTeam = CreateTeam("Patrol");

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

  Player_Group = MothershipPilot:GetGroup();
  MercGroup = MercTeam:CreateGroup("MercGroup");
  PirateGroup_1 = PirateTeam:CreateGroup("PirateGroup_1");
  PirateGroup_2 = PirateTeam:CreateGroup("PirateGroup_2");
  PhantomGroup_1 = UftTeam:CreateGroup("PhantomGroup_1");
  PhantomGroup_2 = UftTeam:CreateGroup("PhantomGroup_2");
  groups_for_rel = {MercGroup,PirateGroup_1,PirateGroup_2,PhantomGroup_1,PhantomGroup_2,Player_Group};
  rep_neutral = {{"N"},
                 {"N","N"},
                 {"N","N","N"},
                 {"N","N","N","N"},
                 {"F","N","N","N","N"}};
  rep_merc_ws_pir = {{"W"},
                     {"X","X"},
                     {"X","X","X"},
                     {"X","X","X","X"},
                     {"X","W","X","X","X"}};
  rep_phan_ws_pir = {{"X"},
                     {"X","X"},
                     {"X","X","W"},
                     {"X","X","X","X"},
                     {"X","X","W","X","X"}};
  new_SetAllGroupRelations(rep_neutral, groups_for_rel);

-- создаем базу пиратов
  xyz_dogs_base = Vector3(-900,0,-300);
  new_mothership = CreateCarcass("Arba_pl1",xyz_dogs_base,Vector3(1,0,0));
  NewPirateFlight("PirateGroup_1", "dogs1", xyz_dogs_base+Vector3(50, 10, -5), 1, 4, Vector3(1, 0, 0));
  NewPirateFlight("PirateGroup_1", "dogs2", xyz_dogs_base+Vector3(-5, -10, 50), 1, 4, Vector3(1, 0, 0));
  NewPirateFlight("PirateGroup_1", "dogs3", xyz_dogs_base+Vector3(30, 0, 30), 1, 5, Vector3(1, 0, 0));
  trig_DogsBase = NewTrigger("inside", Trig_Cond, Dogs_Defends, mothership, xyz_dogs_base, 150);

-- вспомогательные точки
  xyz_portal_to_argon = PORTAL_U:GetPosition();
  xyz_start_point = Vector3(100,0,300);
  xys_war_pirates = Vector3(-150,0,-600);
  xys_end_point = Vector3(-750,0,300);
  xys_Phantom = Vector3(100,0,-450);
  xyz_MercStation = Vector3(-900, 0, 450);

-- ГГ и Ласточка
  HeroSpeaker = GetPilot("Hero");
  LastochkaSpeaker = CreatePilot("Lastochka");
  MercCommander = CreatePilot("m3_Recruit");
  PhantomSpeaker = CreatePilot("Phantom");

-- первая партия наемников
  nav_MercStation = CreateNavPoint("#L_nav_merc", xyz_MercStation, "nav_arba.dds", RGB(255,255,255));
  nav_Current = CreateNavPoint("", mothership:GetPosition(),"nav_void.dds");
  LineToMercBase = CreateLine(nav_Current, nav_MercStation, RGB(20,80,220), .3,TRUE,.2, 1);
  NewFlight("MercGroup", "mercB", "Base_mercenary_1", "GreenRecruitOfficer", xyz_MercStation, Vector3(1, 0, 0));
  NewFlight("MercGroup", "merc1", "Stormcrow_merc3", "RecruitPilot", xyz_MercStation+Vector3(50, 10, 5), Vector3(-1, 0, 0));
  NewShip("merc1_2", "Stormcrow_merc1", "RecruitPilot", xyz_MercStation+Vector3(50, 10, 10), Vector3(-1, 0, 0));
  flight_merc1:AddShip(ship_merc1_2);
  NewFlight("MercGroup", "merc2", "Excalibur_merc2", "RecruitOfficer", xyz_MercStation+Vector3(30, 10, 5), Vector3(-1, 0, 0));
  NewShip("merc2_2", "Excalibur_merc2", "RecruitPilot", xyz_MercStation+Vector3(30, 10, 10), Vector3(-1, 0, 0));
  flight_merc2:AddShip(ship_merc2_2);
  lPoint = 1;

  AddQuest("quest_4_04", "#L_Quest_4_04a", "#L_Quest_4_04b", QUEST_PROCESS);
  AddPost("mail_004");
  NewTrigger("inside", Trig_Cond, StartMission, mothership, xyz_MercStation, 75);
end;


--info:top=120,left=510,allvis=0;
function EndMission()
-- удаляем лишние навигационные точки и линии
  if (LineToPortal) then LineToPortal:Delete(); end;
  if (nav_WarPirates) then nav_WarPirates:Delete(); end;
  if (nav_Current) then nav_Current:Delete(); end;
  if (nav_Phantom) then nav_Phantom:Delete(); end;
  if (nav_BasePirates) then nav_BasePirates:Delete(); end;
end;


--info:top=70,left=140,allvis=0;
function ACTION_INIT()
  _FTrader_exclude();
  SetQuestLabel("CurrentQuest","4_1");
  StartInitMis();

  return TRUE;
end;


--info:top=70,left=570,allvis=0;
function ACTION_LEAVELOCATION()
  EndMission();
  if (dest_location == "pegas") then
    QuestActionDone();
    QuestStart("mission_3_04");
  elseif (lPoint == 1) then
    QuestActionDone();
    QuestStart("mission_3_03");
  else
    SetQuestState("quest_4_02", QUEST_DONE);
    if (GetQuestState("quest_4_03")==QUEST_PROCESS) then SetQuestState("quest_4_03", QUEST_FAILED); end;
--    AddPlayerExperience(5);
    QuestActionDone();
-- запускаем следующую миссию
    SetInitTeamRelation("Kfni", PLAYER_TEAM, RELATION_WAR);
    SetInitTeamRelation(PLAYER_TEAM, "Kfni", RELATION_WAR);
    QuestStart("mission_4_5");
    AddQuest("quest_4_5_01", "#L_Quest_4_5_01a", "#L_Quest_4_5_01b", QUEST_PROCESS);
  end;

  return TRUE;
end;


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