------------------------------------------------------------
--     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 Alexandra_ComeOn()
  NewFlight("Kfni_Group", "al1", "Mothership_KFNI_pl1", "Alexandra", mothership:GetPosition()+Vector3(50, 10, -50), Vector3(-1, 0, 0));
  ship_al1_1:PlayFX("Cloak Out.shfx");
  Timer_Seq(3, Alexandra_Dialog);
end;


--info:top=200,left=130,allvis=0;
function Alexandra_Dialog()
  SetNormalTimeMode();
  StartDialog("Dialog2");
end;


--info:top=240,left=130,allvis=0;
function Alexandra_GoOut()
  local pos = ship_al1_1:GetPosition();
  local orn = ship_al1_1:GetVectorOrientation();
  local glow_orn = ship_al1_1:GetVectorOrientation();
  orn.x = orn.x * 25;
  orn.y = orn.y * 25;
  orn.z = orn.z * 25;
  glow_orn.x = -glow_orn.x;
  glow_orn.y = -glow_orn.y;
  glow_orn.z = -glow_orn.z;
  CreatePortalGlow(pos+orn, glow_orn, 5);
  flight_al1:Move(pos+orn);
  ship_al1_1:PlayFX("Portal Out.shfx");
  Timer_Seq(5, Alexandra_Out);
end;


--info:top=280,left=130,allvis=0;
function Alexandra_Out()
  flight_al1:Delete();
  SetNormalTimeMode();
  StartDialog("Dialog3");
end;


--info:top=340,left=50,allvis=0;
function For_Viper()
  trig_KishimovCome = NewTrigger("timer", TrueCondition, Kishimov_ComeOn, 10);
  count = 1;
  NewTrigger("f_died", DiedCondition, Tramp_Died, flight_tr1);
  if (flight_tr2) then
    if (flight_tr2:IsAlive()) then
      NewTrigger("f_died", DiedCondition, Tramp_Died, flight_tr2);
      count = count + 1;
    end;
  end;
  if (flight_tr3) then
    if (flight_tr3:IsAlive()) then
      NewTrigger("f_died", DiedCondition, Tramp_Died, flight_tr3);
      count = count + 1;
    end;
  end;
  new_SetAllGroupRelations(rel_TrampWar, power_rel_1);
  AddQuest("quest_15a_01", "#L_Quest_15a_01a", "#L_Quest_15a_01b", QUEST_PROCESS);
end;


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


--info:top=370,left=100,allvis=0;
function Kishimov_ComeOn()
  trig_KishimovCome:Delete();
  trig_KishimovCome = NIL;
  mshipPos = mothership:GetPosition();
  CreatePortalGlow(mshipPos+Vector3(70, 20, 30), Vector3(-1, 0, 0), 6);
  NewVksFlight("Vks_Group", "ki1", mshipPos+Vector3(60, 20, 30), 1, 18, Vector3(-1, 0, 0));
  ship_ki1_1:Delete();
  NewShip("ki1_1", "Wyvern_nav1", "m12a_Kishimov", mshipPos+Vector3(55, 20, 30), Vector3(-1, 0, 0));
  flight_ki1:AddShip(ship_ki1_1);
  ship_ki1_1:SetRole(ROLE_LEADER);
  NewVksFlight("Vks_Group", "ki2", mshipPos+Vector3(70, 20, 40), 1, 17, Vector3(-1, 0, 0));
  flight_ki2:Escort(ship_ki1_1);
  NewVksFlight("Vks_Group", "ki3", mshipPos+Vector3(70, 20, 20), 1, 17, Vector3(-1, 0, 0));
  flight_ki3:Escort(ship_ki1_1);
  count = count + 3;
  NewTrigger("f_died", DiedCondition, Tramp_Died, flight_ki1);
  NewTrigger("f_died", DiedCondition, Tramp_Died, flight_ki2);
  NewTrigger("f_died", DiedCondition, Tramp_Died, flight_ki3);
  pilot_ki1_1:Message("#L_Kishimov_01", 4, "Tramp_Attack");
end;


--info:top=440,left=100,allvis=0;
function Tramp_Attack()
  TrampSpeaker:Message("#L_Tramp_01", 4, "Kishimov_Ok");
end;


--info:top=480,left=100,allvis=0;
function Kishimov_Ok()
  pilot_ki1_1:Message("#L_Kishimov_02", 2);
end;


--info:top=500,left=50,allvis=0;
function Tramp_Died()
  if (trig_KishimovCome) then
    trig_KishimovCome:Delete();
    trig_KishimovCome = NIL;
  end;
  lMission = 0;
  SetNormalTimeMode();
  SetQuestState("quest_15a_01", QUEST_DONE);
  StartDialog("Dialog4");
end;


--info:top=1120,left=50,allvis=0;
function finMission_Viper()
  Timer_Seq(1, autosaveMission_Viper);
end;


--info:top=1160,left=50,allvis=0;
function autosaveMission_Viper()
  Timer_Seq(1, Anim_GoTo);
  AutoSave("#AS_mission_15_1");
end;


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


--info:top=1240,left=50,allvis=0;
function GoTo_NJ2()
  AddPost("book015a_2");
  dest_location = "nj2";
  CustomTeleportate("xt23", "nj2", "long_jump");
end;


--info:top=340,left=270,allvis=0;
function For_Tramp()
-- выгружаем пилотов с базы
  Remove_Pers_FromBase();
-- меняем базу на новую
  local posn = mothership:GetPosition();
  local orn = mothership:GetOrientation();
  local ornv = mothership:GetVectorOrientation();
  mothership_viper = mothership;
  mothership = SetPlayerMotherShip(ship_tr1_1); 
  Stop_Player_Pilots();
  PortalTrigger_PORTAL_L:SetObject(mothership);
  PortalTrigger_PORTAL_R:SetObject(mothership);
  PortalTrigger_PORTAL_U:SetObject(mothership);
  PortalsActivate_Action();
  GetShipName(mothership);
  CreateRepairStationDocking(STO_STATION, mothership, 110, 1);
  CreateTradeStationDocking(TRADE_STATION, mothership);
  CreateNoneStationDocking(PIR, mothership, 120, "pirate");
  CreateNoneStationDocking(MINE, mothership, 100, "5"); 
-- удаляем новую базу из группы игрока
  MothershipPilot = mothership:GetPilot(); 
  MothershipFlight = MothershipPilot:GetFlight(); 
  Player_Group:RemoveFlight(MothershipFlight);
  Vks_Group:AddFlight(MothershipFlight);
-- создаем новое звено для старого мазершипа и Гюрзы
  local plship = {};
  local posnum = 1;
  if (HeroSpeaker:IsCanSayReplica()) then
    plship[posnum] = HeroSpeaker:GetShip();
    posnum = posnum + 1;
  end;
  if (SedoySpeaker:IsCanSayReplica()) then
    plship[posnum] = SedoySpeaker:GetShip();
    posnum = posnum + 1;
  end;
  if (ValidolSpeaker:IsCanSayReplica()) then
    plship[posnum] = ValidolSpeaker:GetShip();
    posnum = posnum + 1;
  end;
  if (KalemSpeaker:IsCanSayReplica()) then
    plship[posnum] = KalemSpeaker:GetShip();
    posnum = posnum + 1;
  end;
  if (LastochkaSpeaker:IsCanSayReplica()) then
    plship[posnum] = LastochkaSpeaker:GetShip();
    posnum = posnum + 1;
  end;
  FocusOn(plship, ornv, 60);
  mothership_viper:SetPosition(Vector3(-3000, 0, 3000));
  ship_om_1:SetPosition(posn);
  ship_om_1:SetOrientation(orn);
  if (ViperSpeaker:IsCanSayReplica()) then
    local VFlight = ViperSpeaker:GetFlight();
    if (VFlight:GetPilotCount()==1) then
      Player_Group:RemoveFlight(VFlight);
      Viper_Group:AddFlight(VFlight);
      VFlight:Escort(ship_om_1);
    else
      local NewVFlight = Viper_Group:CreateFlight("NewVFlight");
      NewVFlight:AddShip(ViperSpeaker:GetShip());
      NewVFlight:Escort(ship_om_1);
    end;
  else
    local Player_Team = CreateTeam(PLAYER_TEAM);
    Player_Team = CreateTeam(PLAYER_TEAM);
    Player_Team:RemovePilot(ViperSpeaker);
  end;
  LastochkaSpeaker:Message("#L_Lastochka_01", 3, "Viper_Gloatingly");
end;


--info:top=370,left=300,allvis=0;
function Remove_Pers_FromBase()
  if (HeroSpeaker:IsInBase()) or (HeroSpeaker:IsBasePilot()) then
    if (HeroSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(20, -20, -20), Vector3(1, 0, 0));
    ship:AssignPilot(HeroSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightH");
    flight:AddShip(ship);
  end;
  if (SedoySpeaker:IsInBase()) or (SedoySpeaker:IsBasePilot()) then
    if (SedoySpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(20, -20, 20), Vector3(1, 0, 0));
    ship:AssignPilot(SedoySpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightS");
    flight:AddShip(ship);
  end;
  if (ValidolSpeaker:IsInBase()) or (ValidolSpeaker:IsBasePilot()) then
    if (ValidolSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(30, -20, -20), Vector3(1, 0, 0));
    ship:AssignPilot(ValidolSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightV");
    flight:AddShip(ship);
  end;
  if (KalemSpeaker:IsInBase()) or (KalemSpeaker:IsBasePilot()) then
    if (KalemSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(30, -20, 20), Vector3(1, 0, 0));
    ship:AssignPilot(KalemSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightK");
    flight:AddShip(ship);
  end;
  if (LastochkaSpeaker:IsInBase()) or (LastochkaSpeaker:IsBasePilot()) then
    if (LastochkaSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(30, -20, 20), Vector3(1, 0, 0));
    ship:AssignPilot(LastochkaSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightL");
    flight:AddShip(ship);
  end;
  if (ViperSpeaker:IsInBase()) or (ViperSpeaker:IsBasePilot()) then
    if (ViperSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("Panthera_nav2", mothership:GetPosition()+Vector3(40, -20, -20), Vector3(1, 0, 0));
    ship:AssignPilot(ViperSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightVi");
    flight:AddShip(ship);
  end;
end;


--info:top=400,left=300,allvis=0;
function Stop_Player_Pilots()
  local flight = HeroSpeaker:GetFlight();
  flight:Stop();
  local flight = SedoySpeaker:GetFlight();
  flight:Stop();
  local flight = ValidolSpeaker:GetFlight();
  flight:Stop();
  local flight = KalemSpeaker:GetFlight();
  flight:Stop();
  local flight = LastochkaSpeaker:GetFlight();
  flight:Stop();
  local flight = ViperSpeaker:GetFlight();
  flight:Stop();
end;


--info:top=420,left=270,allvis=0;
function Viper_Gloatingly()
  if not(ViperSpeaker:IsAlive()) then
    ViperSpeaker = CreatePilot("Viper");
  end;
  ViperSpeaker:Message("#L_Viper_01", 7, "Viper_Command");
  Timer_Seq(3, SB_ComeOn);
end;


--info:top=450,left=310,allvis=0;
function SB_ComeOn()
  mshipPos = mothership:GetPosition();
  CreatePortalGlow(mshipPos+Vector3(70, 20, 30), Vector3(-1, 0, 0), 5);
  NewVksFlight("Viper_Group", "sb1", mshipPos+Vector3(60, 20, 30), 1, 18, Vector3(-1, 0, 0));
  NewVksFlight("Viper_Group", "sb2", mshipPos+Vector3(70, 20, 40), 1, 17, Vector3(-1, 0, 0));
  flight_sb2:Escort(ship_sb1_1);
  NewVksFlight("Viper_Group", "sb3", mshipPos+Vector3(70, 20, 20), 1, 17, Vector3(-1, 0, 0));
  flight_sb3:Escort(ship_sb1_1);
end;


--info:top=470,left=270,allvis=0;
function Viper_Command()
  if not(ViperSpeaker:IsAlive()) then
    ViperSpeaker = CreatePilot("Viper");
  end;
--------------------------------------------------------------------------------
--  ViperSpeaker:Message("#L_Viper_02", 6, "Tramp_Come");
  ViperSpeaker:Message("#L_Viper_02", 6, "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
      Tramp_Come();
    end;
  else
    Tramp_Come();
  end; 
end;

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



--info:top=510,left=270,allvis=0;
function Tramp_Come()
  TrampSpeaker:Message("#L_Tramp_02", 6);
  Remove_Pers_Flights();
  Vks_Group:RemoveFlight(MothershipFlight);
  Player_Group:AddFlight(MothershipFlight);
  GetShipName(mothership);
  Add_Pers_Flights();
  AddPilotToPlayer(TrampSpeaker);
  mothership:AddShipToInventory("Panthera_nav2", 1);
  mothership:AddShipToInventory("Wyvern_nav1", 1);
  mothership:AddShipToInventory("Wyvern_nav1", 1);
  AddQuest("quest_15a_02", "#L_Quest_15a_02a", "#L_Quest_15a_02b", QUEST_PROCESS);
  new_SetAllGroupRelations(rel_ViperWar, power_rel_1);
  if (ViperSpeaker:IsCanSayReplica()) then
    local VFlight = ViperSpeaker:GetFlight();
    if (flight_om:IsAlive()) then
      SetAllDied({flight_om, VFlight}, Viper_Died);
    else
      NewTrigger("f_died", TrueCondition, Viper_Died, VFlight);
    end;
  elseif (flight_om:IsAlive()) then
    NewTrigger("f_died", TrueCondition, Viper_Died, flight_om);
  else
    Timer_Seq(8, Viper_Died);
  end;
  trig_NewSB = NewTrigger("timer", TrueCondition, SB_ComeOn_2, 20);
  trig_NearPortalR = NewTrigger("inside", TrueCondition, Kishimov_ComeFromPortal, mothership, PORTAL_R:GetPosition(), 100);
  trig_NearPortalU = NewTrigger("inside", TrueCondition, Kishimov_ComeFromPortal, mothership, PORTAL_U:GetPosition(), 100);
  trig_NearPortalL = NewTrigger("inside", TrueCondition, Kishimov_ComeFromPortal, mothership, PORTAL_L:GetPosition(), 100);
end;


--info:top=550,left=120,allvis=0;
function Remove_Pers_Flights()
  if (HeroSpeaker:IsCanSayReplica()) then
    HeroFlight = HeroSpeaker:GetFlight();
    Player_Group:RemoveFlight(HeroFlight);
  end;
  if (SedoySpeaker:IsCanSayReplica()) and (SedoySpeaker:GetSide()==PLAYER_TEAM) then
    SedoyFlight = SedoySpeaker:GetFlight();
    Player_Group:RemoveFlight(SedoyFlight);
  end;
  if (ValidolSpeaker:IsCanSayReplica()) and (ValidolSpeaker:GetSide()==PLAYER_TEAM) then
    ValidolFlight = ValidolSpeaker:GetFlight();
    Player_Group:RemoveFlight(ValidolFlight);
  end;
  if (KalemSpeaker:IsCanSayReplica()) and (KalemSpeaker:GetSide()==PLAYER_TEAM) then
    KalemFlight = KalemSpeaker:GetFlight();
    Player_Group:RemoveFlight(KalemFlight);
  end;
  if (LastochkaSpeaker:IsCanSayReplica()) and (LastochkaSpeaker:GetSide()==PLAYER_TEAM) then
    LastochkaFlight = LastochkaSpeaker:GetFlight();
    Player_Group:RemoveFlight(LastochkaFlight);
  end;
end;


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


--info:top=620,left=320,allvis=0;
function Kishimov_ComeFromPortal()
  trig_NearPortalR:Delete();
  trig_NearPortalR = NIL;
  trig_NearPortalU:Delete();
  trig_NearPortalU = NIL;
  trig_NearPortalL:Delete();
  trig_NearPortalL = NIL;
  mshipPos = mothership:GetPosition();
  if (VectorLength(mshipPos, PORTAL_R:GetPosition())<110) then
    PORTAL_R:Start(5, 0);
    NewVksFlight("Vks_Group", "ki1", PORTAL_R:GetPosition()+Vector3(-8, -2, 5), 1, 18, Vector3(-1, -0.2, 0.5));
    ship_ki1_1:Delete();
    NewShip("ki1_1", "Wyvern_nav1", "m12a_Kishimov", mshipPos+Vector3(-8, -2, 5), Vector3(-1, -0.2, 0.5));
    flight_ki1:AddShip(ship_ki1_1);
    ship_ki1_1:SetRole(ROLE_LEADER);
    NewVksFlight("Vks_Group", "ki2", mshipPos+Vector3(5, 0, 8), 1, 17, Vector3(-1, -0.2, 0.5));
    flight_ki2:Escort(ship_ki1_1);
    NewVksFlight("Vks_Group", "ki3", mshipPos+Vector3(-5, 0, -8), 1, 17, Vector3(-1, -0.2, 0.5));
    flight_ki3:Escort(ship_ki1_1);
  elseif (VectorLength(mshipPos, PORTAL_U:GetPosition())<110) then
    PORTAL_U:Start(5, 0);
    NewVksFlight("Vks_Group", "ki1", PORTAL_R:GetPosition()+Vector3(7, 0, -7), 1, 18, Vector3(0.5, 0, -0.5));
    ship_ki1_1:Delete();
    NewShip("ki1_1", "Wyvern_nav1", "m12a_Kishimov", mshipPos+Vector3(7, 0, -7), Vector3(0.5, 0, -0.5));
    flight_ki1:AddShip(ship_ki1_1);
    ship_ki1_1:SetRole(ROLE_LEADER);
    NewVksFlight("Vks_Group", "ki2", mshipPos+Vector3(7, 0, 7), 1, 17, Vector3(0.5, 0, -0.5));
    flight_ki2:Escort(ship_ki1_1);
    NewVksFlight("Vks_Group", "ki3", mshipPos+Vector3(-7, 0, -7), 1, 17, Vector3(0.5, 0, -0.5));
    flight_ki3:Escort(ship_ki1_1);
  else
    PORTAL_L:Start(5, 0);
    NewVksFlight("Vks_Group", "ki1", PORTAL_R:GetPosition()+Vector3(3, 7, 0), 1, 18, Vector3(1, 0.7, 0));
    ship_ki1_1:Delete();
    NewShip("ki1_1", "Wyvern_nav1", "m12a_Kishimov", mshipPos+Vector3(3, 7, 0), Vector3(1, 0.7, 0));
    flight_ki1:AddShip(ship_ki1_1);
    ship_ki1_1:SetRole(ROLE_LEADER);
    NewVksFlight("Vks_Group", "ki2", mshipPos+Vector3(0, 0, -10), 1, 17, Vector3(1, 0.7, 0));
    flight_ki2:Escort(ship_ki1_1);
    NewVksFlight("Vks_Group", "ki3", mshipPos+Vector3(0, 0, 10), 1, 17, Vector3(1, 0.7, 0));
    flight_ki3:Escort(ship_ki1_1);
  end;
  pilot_ki1_1:Message("#L_Kishimov_01", 4, "Tramp_Attack_2");
end;


--info:top=660,left=320,allvis=0;
function Tramp_Attack_2()
  TrampSpeaker:Message("#L_Tramp_01", 4, "Kishimov_Ok_2");
end;


--info:top=700,left=320,allvis=0;
function Kishimov_Ok_2()
  pilot_ki1_1:Message("#L_Kishimov_02", 2);
  flight_ki1:Escort(mothership);
end;


--info:top=540,left=320,allvis=0;
function SB_ComeOn_2()
  trig_NewSB:Delete();
  trig_NewSB = NIL;
  mshipPos = mothership:GetPosition();
  CreatePortalGlow(mshipPos+Vector3(30, -20, -70), Vector3(0, 0, 1), 5);
  NewVksFlight("Viper_Group", "sb4", mshipPos+Vector3(30, -20, -60), 1, 19, Vector3(0, 0, 1));
  NewVksFlight("Viper_Group", "sb5", mshipPos+Vector3(40, -20, -70), 1, 18, Vector3(0, 0, 1));
  flight_sb5:Escort(ship_sb4_1);
  NewVksFlight("Viper_Group", "sb6", mshipPos+Vector3(20, -20, -70), 1, 18, Vector3(0, 0, 1));
  flight_sb6:Escort(ship_sb4_1);
  if (ViperSpeaker:IsAlive()) then
    ViperSpeaker:Message("#L_Viper_03", 4, "Tramp_NeedGo");
  else
    local tmpViperSpeaker = CreatePilot("Viper");
    tmpViperSpeaker:Message("#L_Viper_03", 4, "Tramp_NeedGo");
  end;
end;


--info:top=580,left=320,allvis=0;
function Tramp_NeedGo()
  TrampSpeaker:Message("#L_Tramp_03", 7);
end;


--info:top=720,left=270,allvis=0;
function Viper_Died()
  SetQuestState("quest_15a_02", QUEST_DONE);
  if (trig_NewSB) then
    trig_NewSB:Delete();
    trig_NewSB = NIL;
  end;
  if (trig_NearPortalR) then
    trig_NearPortalR:Delete();
    trig_NearPortalR = NIL;
  end;
  if (trig_NearPortalU) then
    trig_NearPortalU:Delete();
    trig_NearPortalU = NIL;
  end;
  if (trig_NearPortalL) then
    trig_NearPortalL:Delete();
    trig_NearPortalL = NIL;
  end;
  Stop_Fight();
  ornflight = NIL;
  if (flight_sb1) then
    if (flight_sb1:IsAlive()) then
      ornflight = flight_sb1;
    end;
  elseif (flight_sb2) then
    if (flight_sb2:IsAlive()) then
      ornflight = flight_sb2;
    end;
  elseif (flight_sb3) then
    if (flight_sb3:IsAlive()) then
      ornflight = flight_sb3;
    end;
  elseif (flight_sb4) then
    if (flight_sb4:IsAlive()) then
      ornflight = flight_sb4;
    end;
  elseif (flight_sb5) then
    if (flight_sb5:IsAlive()) then
      ornflight = flight_sb5;
    end;
  elseif (flight_sb6:IsAlive()) then
    if (flight_sb6:IsAlive()) then
      ornflight = flight_sb6;
    end;
  end;
  SetNormalTimeMode();
  if (ornflight~=NIL) then
    StartDialog("Dialog5");
  elseif (flight_ki1) then
    Timer_Seq(1, Kishimov_Dialog);
  else
    Timer_Seq(1, Kishimov_ComeFromHyper);
  end;
end;


--info:top=750,left=300,allvis=0;
function Stop_Fight()
-- прекращение боя с ВКС
  new_SetAllGroupRelations(rel_StopFight, power_rel_1);
  local PlTeam = CreateTeam(PLAYER_TEAM);
  PlTeam:CheckAllegiance();
  VksTeam:CheckAllegiance();
  MothershipFlight:Stop();
  if (not(SedoySpeaker:IsInBase())) and (not(SedoySpeaker:IsBasePilot()) and (SedoySpeaker:IsCanSayReplica())) then
    SedoyFlight = SedoySpeaker:GetFlight();
    SedoyFlight:Stop();
  end;
  if (not(LastochkaSpeaker:IsInBase())) and (not(LastochkaSpeaker:IsBasePilot()) and (LastochkaSpeaker:IsCanSayReplica())) then
    LastochkaFlight = LastochkaSpeaker:GetFlight();
    LastochkaFlight:Stop();
  end;
  if (not(HeroSpeaker:IsInBase())) and (not(HeroSpeaker:IsBasePilot()) and (HeroSpeaker:IsCanSayReplica())) then
    HeroFlight = HeroSpeaker:GetFlight();
    HeroFlight:Stop();
  end;
  if (not(ValidolSpeaker:IsInBase())) and (not(ValidolSpeaker:IsBasePilot()) and (ValidolSpeaker:IsCanSayReplica())) then
    ValidolFlight = ValidolSpeaker:GetFlight();
    ValidolFlight:Stop();
  end;
  if (not(KalemSpeaker:IsInBase())) and (not(KalemSpeaker:IsBasePilot()) and (KalemSpeaker:IsCanSayReplica())) then
    KalemFlight = KalemSpeaker:GetFlight();
    KalemFlight:Stop();
  end;
  if (not(TrampSpeaker:IsInBase())) and (not(TrampSpeaker:IsBasePilot()) and (TrampSpeaker:IsCanSayReplica())) then
    TrampFlight = TrampSpeaker:GetFlight();
    TrampFlight:Stop();
  end;
  if (flight_sb1) then
    if (flight_sb1:IsAlive()) then
      flight_sb1:Stop();
    end;
  end;
  if (flight_sb2) then
    if (flight_sb2:IsAlive()) then
      flight_sb2:Stop();
    end;
  end;
  if (flight_sb3) then
    if (flight_sb3:IsAlive()) then
      flight_sb3:Stop();
    end;
  end;
  if (flight_tr2) then
    if (flight_tr2:IsAlive()) then
      flight_tr2:Stop();
    end;
  end;
  if (flight_tr3) then
    if (flight_tr3:IsAlive()) then
      flight_tr3:Stop();
    end;
  end;
  if (flight_sb4) then
    if (flight_sb4:IsAlive()) then
      flight_sb4:Stop();
    end;
  end;
  if (flight_sb5) then
    if (flight_sb5:IsAlive()) then
      flight_sb5:Stop();
    end;
  end;
  if (flight_sb6) then
    if (flight_sb6:IsAlive()) then
      flight_sb6:Stop();
    end;
  end;
  if (flight_ki1) then
    if (flight_ki1:IsAlive()) then
      flight_ki1:Stop();
    end;
  end;
  if (flight_ki2) then
    if (flight_ki2:IsAlive()) then
      flight_ki2:Stop();
    end;
  end;
  if (flight_ki3) then
    if (flight_ki3:IsAlive()) then
      flight_ki3:Stop();
    end;
  end;
end;


--info:top=790,left=170,allvis=0;
function SB_GoOut()
  local ornpilot = ornflight:GetLeader();
  local ornship = ornpilot:GetShip();
  local pos = ornship:GetPosition();
  local orn = ornship:GetVectorOrientation();
  local glow_orn = ornship:GetVectorOrientation();
  orn.x = orn.x * 25;
  orn.y = orn.y * 25;
  orn.z = orn.z * 25;
  glow_orn.x = -glow_orn.x;
  glow_orn.y = -glow_orn.y;
  glow_orn.z = -glow_orn.z;
  CreatePortalGlow(pos+orn, glow_orn, 5);
  if (flight_sb1) then
    if (flight_sb1:IsAlive()) then
      flight_sb1:Move(pos+orn);
    end;
  end;
  if (flight_sb2) then
    if (flight_sb2:IsAlive()) then
      flight_sb2:Move(pos+orn);
    end;
  end;
  if (flight_sb3) then
    if (flight_sb3:IsAlive()) then
      flight_sb3:Move(pos+orn);
    end;
  end;
  if (flight_sb4) then
    if (flight_sb4:IsAlive()) then
      flight_sb4:Move(pos+orn);
    end;
  end;
  if (flight_sb5) then
    if (flight_sb5:IsAlive()) then
      flight_sb5:Move(pos+orn);
    end;
  end;
  if (flight_sb6) then
    if (flight_sb6:IsAlive()) then
      flight_sb6:Move(pos+orn);
    end;
  end;
  Timer_Seq(5, SB_Out);
end;


--info:top=830,left=170,allvis=0;
function SB_Out()
  if (flight_sb1) then
    if (flight_sb1:IsAlive()) then
      flight_sb1:Delete();
    end;
  end;
  if (flight_sb2) then
    if (flight_sb2:IsAlive()) then
      flight_sb2:Delete();
    end;
  end;
  if (flight_sb3) then
    if (flight_sb3:IsAlive()) then
      flight_sb3:Delete();
    end;
  end;
  if (flight_sb4) then
    if (flight_sb4:IsAlive()) then
      flight_sb4:Delete();
    end;
  end;
  if (flight_sb5) then
    if (flight_sb5:IsAlive()) then
      flight_sb5:Delete();
    end;
  end;
  if (flight_sb6) then
    if (flight_sb6:IsAlive()) then
      flight_sb6:Delete();
    end;
  end;
  if (flight_ki1) then
    Timer_Seq(1, Kishimov_Dialog);
  else
    Timer_Seq(1, Kishimov_ComeFromHyper);
  end;
end;


--info:top=890,left=270,allvis=0;
function Kishimov_ComeFromHyper()
  mshipPos = mothership:GetPosition();
  CreatePortalGlow(mshipPos+Vector3(70, 20, 30), Vector3(-1, 0, 0), 6);
  NewVksFlight("Vks_Group", "ki1", mshipPos+Vector3(60, 20, 30), 1, 18, Vector3(-1, 0, 0));
  ship_ki1_1:Delete();
  NewShip("ki1_1", "Wyvern_nav1", "m12a_Kishimov", mshipPos+Vector3(55, 20, 30), Vector3(-1, 0, 0));
  flight_ki1:AddShip(ship_ki1_1);
  ship_ki1_1:SetRole(ROLE_LEADER);
  NewVksFlight("Vks_Group", "ki2", mshipPos+Vector3(70, 20, 40), 1, 17, Vector3(-1, 0, 0));
  flight_ki2:Escort(ship_ki1_1);
  NewVksFlight("Vks_Group", "ki3", mshipPos+Vector3(70, 20, 20), 1, 17, Vector3(-1, 0, 0));
  flight_ki3:Escort(ship_ki1_1);
  pilot_ki1_1:Message("#L_Kishimov_01", 4, "Tramp_LongTime");
end;


--info:top=930,left=270,allvis=0;
function Tramp_LongTime()
  TrampSpeaker:Message("#L_Tramp_04", 3, "Kishimov_Yes");
end;


--info:top=970,left=270,allvis=0;
function Kishimov_Yes()
  pilot_ki1_1:Message("#L_Kishimov_03", 4, "Kishimov_Dialog");
end;


--info:top=1020,left=170,allvis=0;
function Kishimov_Dialog()
  StopHere();
  lMission = 0;
  ornflight = NIL;
  if (flight_ki1:IsAlive()) then
    ornflight = flight_ki1;
  elseif (flight_ki2:IsAlive()) then
    ornflight = flight_ki2;
  elseif (flight_ki3:IsAlive()) then
    ornflight = flight_ki3;
  end;
  SetNormalTimeMode();
  StartDialog("Dialog6");
end;


--info:top=1060,left=170,allvis=0;
function Kishimov_GoOut()
  if (ornflight~=NIL) then
    local ornpilot = ornflight:GetLeader();
    local ornship = ornpilot:GetShip();
    local pos = ornship:GetPosition();
    local orn = ornship:GetVectorOrientation();
    local glow_orn = ornship:GetVectorOrientation();
    orn.x = orn.x * 25;
    orn.y = orn.y * 25;
    orn.z = orn.z * 25;
    glow_orn.x = -glow_orn.x;
    glow_orn.y = -glow_orn.y;
    glow_orn.z = -glow_orn.z;
    CreatePortalGlow(pos+orn, glow_orn, 5);
    if (flight_ki1:IsAlive()) then
      flight_ki1:Move(pos+orn);
    end;
    if (flight_ki2:IsAlive()) then
      flight_ki2:Move(pos+orn);
    end;
    if (flight_ki3:IsAlive()) then
      flight_ki3:Move(pos+orn);
    end;
    Timer_Seq(5, Kishimov_Out);
  end;
end;


--info:top=1100,left=170,allvis=0;
function Kishimov_Out()
  if (flight_ki1:IsAlive()) then
    flight_ki1:Delete();
  end;
  if (flight_ki2:IsAlive()) then
    flight_ki2:Delete();
  end;
  if (flight_ki3:IsAlive()) then
    flight_ki3:Delete();
  end;
end;


--info:top=1120,left=310,allvis=0;
function finMission_Tramp()
  AddPost("book015a_1");
  Timer_Seq(1, autosaveMission_Tramp);
end;


--info:top=1160,left=310,allvis=0;
function autosaveMission_Tramp()
  AddQuest("quest_15a_03", "#L_Quest_15a_03a", "#L_Quest_15a_03b", QUEST_PROCESS);
  Teleporter:Delete();
  Teleporter = CreateTrigger();
  Teleporter:AttachEvent(_EVENT_TIMER); 
  Teleporter:SetTime(3);
  Teleporter:AttachCondition(TrueCondition);
  Teleporter:AttachAction(My_TeleporterAction);
  AutoSave("#AS_mission_15_1");
end;


--info:top=1200,left=310,allvis=0;
function My_TeleporterAction()
  SetQuestLabel("XT86permit","yes");
  dest_location = "xt86";
  CustomTeleportate("xt23", "xt86", "long_jump");
end;


--info:top=120,left=390,allvis=0;
function StartInitMission()
  KfniTeam = CreateTeam("Kfni");
  VksTeam = CreateTeam("Vks");

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

  Player_Group = MothershipPilot:GetGroup();
  Viper_Group = VksTeam:CreateGroup("Viper_Group");
  Kfni_Group = KfniTeam:CreateGroup("Kfni_Group");
  Vks_Group = pilot_tr1_1:GetGroup();
  power_rel_1 = {Player_Group,Viper_Group,Vks_Group,Kfni_Group};
  rel_Neutral = {{"N"},
                 {"N","N"},
                 {"N","N","N"}};
  rel_TrampWar = {{"F"},
                  {"W","W"},
                  {"X","X","X"}};
  rel_ViperWar = {{"W"},
                  {"F","W"},
                  {"X","X","X"}};
  rel_StopFight = {{"N"},
                   {"X","N"},
                   {"X","X","X"}};
  new_SetAllGroupRelations(rel_Neutral, power_rel_1);

  HeroSpeaker = GetPilot("Hero");
  SedoySpeaker = GetPilot("Sedoy");
  ValidolSpeaker = GetPilot("Validol");
  ViperSpeaker = GetPilot("Viper");
  KalemSpeaker = GetPilot("Kalem");
  LastochkaSpeaker = GetPilot("Lastochka2");
  TrampSpeaker = CreatePilot("Tramp");

  NewFlight("Viper_Group", "om", "Mothership_Lion_pl1", "BasePilot", Vector3(3000, 0, 3000), Vector3(1, 0, 0));
  lMission = 1;

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


--info:top=160,left=390,allvis=0;
function My_TeleporterAction_Start()
  if (lMission==1) then
    OutputToScreenLog("#L_sys_01", 7);
    Timer_Seq(7, fin_failed);
  else
    Timer_Seq(1, TeleporterAction);
  end;
end;


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


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

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


--info:top=80,left=570,allvis=0;
function ACTION_LEAVELOCATION()
  if (lMission==1) then
    Terminate();
  else
    if (tmpNull) then tmpNull:Delete(); end;
    if (GetQuestState("quest_15a_03")==QUEST_PROCESS) then SetQuestState("quest_15a_03", QUEST_DONE); end;
    SetQuestLabel("Transfer_To_NI", "step3")
    AddPost("news015_1");
    AddPost("news015_6");
    AddPost("news015_3");
    AddPost("news015_7");
    AddPost("news015_4");
    AddPost("news015_8");
    AddPost("news015_5");
    QuestActionDone();
    if (dest_location=="nj2") then
      QuestStart("mission_16a");
    else
      QuestStart("mission_19a");
    end;
  end;

  return TRUE;
end;


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

  return TRUE;
end;
