------------------------------------------------------------
--     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=190,left=130,allvis=0;
function StartMission()
-- начало действий
  SetNormalTimeMode();
  MothershipFlight:Stop();
  SetQuestState("quest_4_03", QUEST_DONE);
  LineToWldCatBase:Delete();
  nav_WldCatStation:Delete();
  nav_Current:Delete();
  CatsLider:Message("#L_WildCat_01",10);
  Timer_Seq(11, GoTo_NavPoint1);
end;


--info:top=230,left=130,allvis=0;
function GoTo_NavPoint1()
  flight_cats1:Escort(mothership);
  flight_cats2: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));
  nav_WildCat = CreateNavPoint("",xyz_wildcat_station,"nav_void.dds",RGB(255,255,255));
  LineToStartPoint = CreateLine(nav_WildCat, 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=210,allvis=0;
function Dogs_Defends()
  flight_dogs1:Attack(mothership);
  flight_dogs2:Attack(mothership);
  flight_dogs3:Attack(mothership);
end;


--info:top=170,left=210,allvis=0;
function For_Contract()
  SetNormalTimeMode();
  MothershipFlight:Stop();
  NewGreenFlight("MercGroup", "merc4", mothership:GetPosition()+Vector3(-25, 10, 50), 1, 15, Vector3(0.5, 0, -0.5));
  NewGreenFlight("MercGroup", "merc5", mothership:GetPosition()+Vector3(-25, 10, 40), 1, 15, Vector3(0.5, 0, -0.5));
  pilot_merc4_1:Message("#L_merc_01",5);
  SetGroupRelation(MercGroup, Player_Group, RELATION_WAR);
  SetGroupRelation(Player_Group, MercGroup, RELATION_WAR);
end;


--info:top=270,left=130,allvis=0;
function GoTo_NavPoint2()
  trig_Start_point:Activate(FALSE);
  LineToStartPoint:Delete();
  nav_WildCat: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=310,left=130,allvis=0;
function MeetingDogs()
  trig_War_point:Activate(FALSE);
  LineToWarPirates:Delete();
  SetNormalTimeMode();
  MothershipFlight:Stop();
  SetQuestState("quest_4_01", QUEST_DONE);
--  AddPlayerExperience(5);
-- создаем пиратов
  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_2", "dogs1", xys_war_pirates+Vector3(-50, 10, -5), 1, 4, Vector3(1, 0, 0));
  NewPirateFlight("PirateGroup_2", "dogs2", xys_war_pirates+Vector3(-5, -10, -50), 1, 4, Vector3(1, 0, 0));
  NewPirateFlight("PirateGroup_2", "dogs3", xys_war_pirates+Vector3(-30, 0, -30), 1, 5, Vector3(1, 0, 0));
  pilot_dogs3_1:Message("#L_Dogs_01", 4, "BeginFight");
end;


--info:top=350,left=130,allvis=0;
function BeginFight()
  new_SetAllGroupRelations(rep_cats_ws_dogs, groups_for_rel);
-- вторая партия кошек
  NewFlight("PirateGroup_1", "cats3", "Yari_pir2", "PirateTough", xys_war_pirates+Vector3(-70, 10, -5), Vector3(1, 0, 0));
  NewShip("cats3_2", "Yari_pir1", "PirateRookie", xys_war_pirates+Vector3(-70, 10, -10), Vector3(1, 0, 0));
  flight_cats3:AddShip(ship_cats3_2);
  NewFlight("PirateGroup_1", "cats4", "Excalibur_pir1", "PirateTough", xys_war_pirates+Vector3(-5, 10, -70), Vector3(1, 0, 0));
  NewShip("cats4_2", "Yari_pir2", "PirateTough", xys_war_pirates+Vector3(-10, 10, -70), Vector3(1, 0, 0));
  flight_cats4:AddShip(ship_cats4_2);
  CatsLider:Message("#L_WildCat_02",5);
  flight_cats1:Attack(ship_dogs3_1);
  flight_cats2:Attack(ship_dogs3_2);
  flight_cats3:Attack(ship_dogs1_1);
  flight_cats4:Attack(ship_dogs2_1);
  SetAllDied({flight_dogs1,flight_dogs2,flight_dogs3}, Died_Pirates);
end;


--info:top=390,left=130,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);
  HeroSpeaker:Message("#L_Hero_01",5);
  Timer_Seq(6, GoTo_DogsBase);
end;


--info:top=420,left=180,allvis=0;
function GoTo_DogsBase()
  if (flight_cats1) and (flight_cats1:IsAlive()) then flight_cats1:Escort(mothership); end;
  if (flight_cats2) and (flight_cats2:IsAlive()) then flight_cats2:Escort(mothership); end;
  if (flight_cats3) and (flight_cats3:IsAlive()) then flight_cats3:Escort(mothership); end;
  if (flight_cats4) and (flight_cats4:IsAlive()) then flight_cats4:Escort(mothership); end;
  NewFlight("PirateGroup_1", "cats5", "Yari_pir2", "PirateTough", xys_war_pirates+Vector3(-70, 10, -5), Vector3(1, 0, 0));
  NewShip("cats5_2", "Yari_pir1", "PirateRookie", xys_war_pirates+Vector3(-70, 10, -10), Vector3(1, 0, 0));
  flight_cats5:AddShip(ship_cats5_2);
  flight_cats5:Escort(mothership);
  nav_Start_Point:Delete();
  nav_War_Point:Delete();
  nav_End_Point:Delete();
end;


--info:top=440,left=130,allvis=0;
function Dialog_Lastochka()
  trig_DogsBase:Delete();
  LineToDogsBase:Delete();
  SetNormalTimeMode();
  MothershipFlight:Stop();
  if (flight_cats1) and (flight_cats1:IsAlive()) then flight_cats1:Move(xyz_dogs_base+Vector3(-3, 5, 10)); end;
  if (flight_cats2) and (flight_cats2:IsAlive()) then flight_cats2:Move(xyz_dogs_base+Vector3(15, 10, 0)); end;
  if (flight_cats3) and (flight_cats3:IsAlive()) then flight_cats3:Move(xyz_dogs_base+Vector3(2, -5, -10)); end;
  if (flight_cats4) and (flight_cats4:IsAlive()) then flight_cats4:Move(xyz_dogs_base+Vector3(-3, -15, 0)); end;
  LastochkaSpeaker:Message("#L_Lastochka_01",3, "Dialog_Lastochka2");
end;


--info:top=480,left=130,allvis=0;
function Dialog_Lastochka2()
  HeroSpeaker:Message("#L_Hero_02",2,"Dialog_Lastochka3");
end;


--info:top=520,left=130,allvis=0;
function Dialog_Lastochka3()
  LastochkaSpeaker:Message("#L_Lastochka_02",4,"Treachery_Of_Cats");
end;


--info:top=560,left=130,allvis=0;
function Treachery_Of_Cats()
  CatsLider:Message("#L_WildCat_03",17,"Treachery_Of_Cats2");
end;


--info:top=600,left=130,allvis=0;
function Treachery_Of_Cats2()
  HeroSpeaker:Message("#L_Hero_03",1,"Treachery_Of_Cats3");
end;


--info:top=640,left=130,allvis=0;
function Treachery_Of_Cats3()
  CatsLider:Message("#L_WildCat_04",7,"Defeat_Of_Cats");
end;


--info:top=680,left=130,allvis=0;
function Defeat_Of_Cats()
  LastochkaSpeaker:Message("#L_Lastochka_03",16);
  Timer_Seq(15, Defeat_Of_Cats2);
end;


--info:top=720,left=130,allvis=0;
function Defeat_Of_Cats2()
  FightLastochka = CreatePilot("LastochkaForThird");
  new_mothership:AssignPilot(FightLastochka);
  New_Mothership_Flight = PirateGroup_3:CreateFlight("New_Mothership_Flight");
  New_Mothership_Flight:AddShip(new_mothership);
  new_SetAllGroupRelations(rep_play_ws_cats, groups_for_rel);
  if (flight_cats1) and (flight_cats1:IsAlive()) then flight_cats1:Blow(); end;
  if (flight_cats2) and (flight_cats2:IsAlive()) then flight_cats2:Blow(); end;
  if (flight_cats3) and (flight_cats3:IsAlive()) then flight_cats3:Blow(); end;
  if (flight_cats4) and (flight_cats4:IsAlive()) then flight_cats4:Blow(); end;
--------------------------------------------------------------------------------
--  SetAllDied({flight_cats5}, Dogs_Base_Occupy);
  SetAllDied({flight_cats5}, 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
      Dogs_Base_Occupy();
    end;
  else
    Dogs_Base_Occupy();
  end; 
end;

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

--info:top=760,left=130,allvis=0;
function Dogs_Base_Occupy()
  StartDialog("Dialog1");
end;


--info:top=800,left=130,allvis=0;
function Bilateral_Treaty()
  Change_Mathership();
  SetQuestLabel("ReadyStoryDlg","FALSE");

  Anim_1 = CreateMovie(_ASIMUTHCAM);
  Anim_1:SetLength(11);
  Anim_1:SetInterpolate(_LINEAR);
  Anim_1:SetTarget(old_arba);
  Anim_1:InitMovie(1, TRUE, 0);
  Anim_1:AddKeys(154.0171, 62.6476, 60.00, 0);
  Anim_1:AddKeys(230.4165, 56.3927, 39.03, 11);
  Anim_1:AttachEscapeScript("Bilateral_Treaty2");

  Anim_2 = CreateMovie(_ASIMUTHCAM);
  Anim_2:SetLength(15);
  Anim_2:SetInterpolate(_LINEAR);
  Anim_2:SetTarget(new_mothership);
  Anim_2:InitMovie(1, TRUE, 3);
  Anim_2:AddKeys(230.4165, 56.3927, 39.03, 0);
  Anim_2:AddKeys(284.5037, 74.9616, 39.03, 8);
  Anim_2:AddKeys(316.2579, 57.4963, 28.06, 15);
  Anim_2:AttachEscapeScript("Bilateral_Treaty2");
  Anim_2:AttachAction("Bilateral_Treaty2");

  PlayList({Anim_1,Anim_2});
end;


--info:top=830,left=190,allvis=0;
function Change_Mathership()
  old_arba = mothership;
  mothership = SetPlayerMotherShip(new_mothership);
  TempPilot = CreatePilot("PirateRookie");
  old_arba:AssignPilot(TempPilot);
  Old_Mothership_Flight = PirateGroup_3: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);
  mothership:AddShipToInventory("Excalibur_pl1", 1);
  AddPilotToPlayer(LastochkaSpeaker);
  mothership:AddModuleToInventory("BS_LRS2",1);
  mothership:AddModuleToInventory("BS_EngAmp1",1);
end;


--info:top=850,left=130,allvis=0;
function Bilateral_Treaty2()
-- нужен ролик: корабли сближаются, некоторое время висят рядом и расходятся; можно изобразить передачу спаскапсул(-ы) и протчего барахла
  lPoint = 0;
  FocusOn(mothership,Vector3(-1,0.4,0.5),30);
  Old_Mothership_Flight:Stop();
--  AddPlayerExperience(20);
  NewTrigger("f_object_inside", trigger_inside2portal_Condition, trigger_inside2portal_Action, Old_Mothership_Flight, PORTAL_D, 25);
  StartDialog("Dialog2");
end;


--info:top=890,left=130,allvis=0;
function GoTo_Portal()
-- ВКС
  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);
  trig_ForContract:Delete();

  old_arba:ComeToPortal(PORTAL_D);
  mothership:ComeToPortal(PORTAL_U);
  Anim_3 = CreateMovie(_TARGETCAM);
  Anim_3:SetLength(30);
  Anim_3:SetInterpolate(_LINEAR);
  Anim_3:SetTarget(old_arba);
  Anim_3:InitMovie(1, TRUE, 3);
  Anim_3:AddPosKey(old_arba:GetPosition()+Vector3(-50, 10, -50), 0);
  Anim_3:Play();
  Anim_3:AttachEscapeScript("Fin_Action");
  Anim_3:AttachAction("Fin_Action");
end;


--info:top=930,left=130,allvis=0;
function Fin_Action()
  Old_Mothership_Flight:Delete();
  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);
  CreateRoute("ahilles", "argon", "gefest", "elio");
end;


--info:top=970,left=130,allvis=0;
function Save_Game()
  AddPost("news004_1");
  AddPost("news004_2");
  AddPost("news004_3");
  AddPost("news004_5");
  AddPost("book004_3");
  AutoSave("#AS_mission_4");
end;


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

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

  Player_Group = MothershipPilot:GetGroup();
  PirateGroup_1 = PirateTeam:CreateGroup("PirateGroup_1");
  PirateGroup_2 = PirateTeam:CreateGroup("PirateGroup_2");
  PirateGroup_3 = PirateTeam:CreateGroup("PirateGroup_3");
  MercGroup = MercTeam:CreateGroup("MercGroup");
  groups_for_rel = {PirateGroup_1,PirateGroup_2,PirateGroup_3,Player_Group};
  rep_neutral = {{"N"},
                 {"N","N"},
                 {"N","N","N"}};
  rep_cats_ws_dogs = {{"W"},
                      {"X","X"},
                      {"X","W","X"}};
  rep_play_ws_cats = {{"X"},
                      {"W","X"},
                      {"W","X","X"}};
  new_SetAllGroupRelations(rep_neutral, groups_for_rel);

  trig_ForContract = NewTrigger("inside", Trig_Cond, For_Contract, mothership, TRADE_STATION:GetDockingPosition(), 250);

-- создаем базу пиратов
  xyz_dogs_base = Vector3(-900,0,-300);
  new_mothership = CreateCarcass("Arba_pl1",xyz_dogs_base,Vector3(1,0,0));
  NewPirateFlight("PirateGroup_2", "dogs1", xyz_dogs_base+Vector3(-50, 10, -5), 1, 4, Vector3(1, 0, 0));
  NewPirateFlight("PirateGroup_2", "dogs2", xyz_dogs_base+Vector3(-5, -10, -50), 1, 4, Vector3(1, 0, 0));
  NewPirateFlight("PirateGroup_2", "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_wildcat_station = WILDCAT_STATION:GetPosition();
  xyz_start_point = Vector3(500,0,-300);
  xys_war_pirates = Vector3(-150,0,-600);
  xys_end_point = Vector3(-750,0,300);

-- ГГ и Ласточка
  HeroSpeaker = GetPilot("Hero");
  LastochkaSpeaker = CreatePilot("Lastochka");
  CatsLider = CreatePilot("m3_WildKats");

-- первая партия кошек
  nav_WldCatStation = CreateNavPoint("", xyz_wildcat_station, "nav_void.dds");
  nav_Current = CreateNavPoint("", mothership:GetPosition(),"nav_void.dds");
  LineToWldCatBase = CreateLine(nav_Current, nav_WldCatStation, RGB(20,80,220), .3,TRUE,.2, 1);
  NewFlight("PirateGroup_1", "cats1", "Yari_pir2", "PirateTough", xyz_wildcat_station+Vector3(-50, 10, -5), Vector3(1, 0, 0));
  NewShip("cats1_2", "Yari_pir1", "PirateTough", xyz_wildcat_station+Vector3(-50, 10, -10), Vector3(1, 0, 0));
  flight_cats1:AddShip(ship_cats1_2);
  NewFlight("PirateGroup_1", "cats2", "Excalibur_pir2", "PirateCaptain", xyz_wildcat_station+Vector3(-30, 10, -5), Vector3(1, 0, 0));
  NewShip("cats2_2", "Excalibur_pir1", "PirateTough", xyz_wildcat_station+Vector3(-30, 10, -10), Vector3(1, 0, 0));
  flight_cats2:AddShip(ship_cats2_2);
  lPoint = 1;

  AddQuest("quest_4_03", "#L_Quest_4_03a", "#L_Quest_4_03b", QUEST_PROCESS);
  AddPost("mail_004");
  NewTrigger("inside", Trig_Cond, StartMission, mothership, xyz_wildcat_station, 100);
end;


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


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

  return TRUE;
end;


--info:top=70,left=550,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);
--    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=410,allvis=0;
function ACTION_FINI()
  _FTrader_include();
  EndMission();

  return TRUE;
end;
