------------------------------------------------------------
--     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=110,left=130,allvis=0;
function StartMission()
  lWait = 0;
  SetNormalTimeMode();
  trig_HederAttack = NewTrigger("timer", TrueCondition, Heder_Attack, 120);
  StartDialog("Dialog1");
end;


--info:top=150,left=130,allvis=0;
function Tramp_NeedOut()
  if (TrampSpeaker:IsInBase())or(TrampSpeaker:IsBasePilot()) then
    OutputToScreenLog("#L_sys_01", 9);
    trig_Hint = NewTrigger("timer", TrueCondition, Tramp_NeedOut, 10);
  else
    Timer_Seq(1, GoTo_Station);
  end;
end;


--info:top=190,left=330,allvis=0;
function Heder_Attack()
  trig_Hint:Delete();
  mRadar = Player_Group:CreateRadar(PORTAL_U:GetPosition(), 300, 0.1);
  Timer_Seq(1, First_Parti);
  Timer_Seq(8, Straight_Attack);

  Anim_1 = CreateMovie(_TARGETCAM);
  Anim_1:SetLength(8);
  Anim_1:SetInterpolate(_LINEAR);
  Anim_1:SetTarget(PORTAL_U);
  Anim_1:InitMovie(1, TRUE, 3);
  Anim_1:AddPosKey(PORTAL_U:GetPosition()+Vector3(0, 50, -100), 0);
  Anim_1:AttachEscapeScript("End_Attack");
  Anim_1:Play();

  Anim_2 = CreateMovie(_TARGETCAM);
  Anim_2:SetLength(5);
  Anim_2:SetInterpolate(_LINEAR);
  Anim_2:SetTarget(mothership);
  Anim_2:InitMovie(1, TRUE, 2);
  Anim_2:AddPosKey(mothership:GetPosition()+Vector3(50, 30, -10), 0);
  Anim_2:Play();
  Anim_2:AttachEscapeScript("End_Attack");
  Anim_2:AttachAction("End_Attack");

  PlayList({Anim_1,Anim_2});
end;


--info:top=350,left=330,allvis=0;
function Straight_Attack()
  local mshipPos = mothership:GetPosition();
  CreatePortalGlow(mshipPos+Vector3(-100, 0, 10), Vector3(0.9, 0, -0.1), 5);
  NewVksFlight("Heder_Group", "hedA1", mshipPos+Vector3(-90, 0, 10), 1, 20, Vector3(0.9, 0, -0.1));
  NewVksFlight("Heder_Group", "hedA2", mshipPos+Vector3(-99, 0, 21), 2, 20, Vector3(0.9, 0, -0.1));
  NewVksFlight("Heder_Group", "hedA3", mshipPos+Vector3(-101, 0, -1), 2, 20, Vector3(0.9, 0, -0.1));
  new_SetGroupRelations("Heder_Group", PLAYER_GROUP, "W");
end;


--info:top=380,left=350,allvis=0;
function End_Attack()
  Player_Group:DeleteRadar(mRadar);
  mothership:Blow();
end;


--info:top=190,left=130,allvis=0;
function GoTo_Station()
  trig_HederAttack:Delete();
  trig_HederAttack = NIL;
  TrampFlight = TrampSpeaker:GetFlight();
  TrampShip = TrampSpeaker:GetShip();
  if (TrampFlight:GetPilotCount()==1) then
    Player_Group:RemoveFlight(TrampFlight);
    VksGroup_1:AddFlight(TrampFlight);
    TrampFlight:Move(ship_tr2_1:GetPosition()+Vector3(60, 0, 100));
  else
    NewTrampFlight = VksGroup_1:CreateFlight("NewTrampFlight");
    NewTrampFlight:AddShip(TrampShip);
    NewTrampFlight:Move(ship_tr2_1:GetPosition()+Vector3(60, 0, 100));
  end;
  AddQuest("quest_19a_01", "#L_Quest_19a_01a", "#L_Quest_19a_01b", QUEST_PROCESS);
  nav_current = CreateNavPoint("", mothership:GetPosition(), "nav_void.dds", RGB(255,255,255), mothership);
  LineToStation = CreateLine(nav_current, np_control, RGB(20,80,220), .3, TRUE, .2, 1);
  NewTrigger("timer", TrueCondition, Dialog_OnWay, 10);
  NewTrigger("timer", TrueCondition, Heder_ComeOn, 50);
end;


--info:top=220,left=150,allvis=0;
function Dialog_OnWay()
  SetNormalTimeMode();
  StartDialog("Dialog2");
end;


--info:top=240,left=130,allvis=0;
function Heder_ComeOn()
  if (nav_current) then
    nav_current:Delete();
    nav_current = NIL;
  end;
  if (LineToStation) then
    LineToStation:Delete();
    LineToStation = NIL;
  end;
  mRadar = Player_Group:CreateRadar(PORTAL_U:GetPosition(), 300, 0.1);
  Timer_Seq(1, First_Parti);
  Anim_3 = CreateMovie(_TARGETCAM);
  Anim_3:SetLength(15);
  Anim_3:SetInterpolate(_LINEAR);
  Anim_3:SetTarget(PORTAL_U);
  Anim_3:InitMovie(1, TRUE, 1);
  Anim_3:AddPosKey(PORTAL_U:GetPosition()+Vector3(0, 50, -100), 0);
  Anim_3:Play();
  Anim_3:AttachEscapeScript("Heder_Dialog");
  Anim_3:AttachAction("Heder_Dialog");
end;


--info:top=280,left=230,allvis=0;
function First_Parti()
  PORTAL_U:Start(5, 0);
  NewFlight("Heder_Group", "hed1", "Heder_Lion", "VksSuperAce", PORTAL_U:GetPosition()+Vector3(0, -3, -10), Vector3(0, -0.3, -1));
  NewVksFlight("Heder_Group", "hed2", PORTAL_U:GetPosition()+Vector3(-10, 0, 0), 1, 20, Vector3(0, -0.3, -1));
  NewVksFlight("Heder_Group", "hed3", PORTAL_U:GetPosition()+Vector3(10, 0, 0), 1, 20, Vector3(0, -0.3, -1));
  NewVksFlight("Heder_Group", "hed4", PORTAL_U:GetPosition()+Vector3(0, -10, 0), 2, 20, Vector3(0, -0.3, -1));
  flight_hed2:Escort(ship_hed1_1);
  flight_hed3:Escort(ship_hed1_1);
  flight_hed4:Escort(ship_hed1_1);
  ship_hed1_1:ApplyImpulse(15, Vector3(0, -0.3, -1));
  flight_hed1:Move(PORTAL_U:GetPosition()+Vector3(-30, 0, -150));
  Timer_Seq(7, Second_Parti);
end;


--info:top=320,left=230,allvis=0;
function Second_Parti()
  PORTAL_U:Start(5, 0);
  NewVksFlight("Heder_Group_2", "hed5", PORTAL_U:GetPosition()+Vector3(-5, 0, 0), 3, 8, Vector3(0, -0.3, -1));
  NewVksFlight("Heder_Group_2", "hed6", PORTAL_U:GetPosition()+Vector3(5, 0, 0), 3, 8, Vector3(0, -0.3, -1));
  NewVksFlight("Heder_Group", "hed7", PORTAL_U:GetPosition()+Vector3(0, -10, 3), 1, 19, Vector3(0, -0.3, -1));
  NewVksFlight("Heder_Group", "hed8", PORTAL_U:GetPosition()+Vector3(0, 10, -3), 1, 19, Vector3(0, -0.3, -1));
  flight_hed7:Escort(ship_hed5_1);
  flight_hed8:Escort(ship_hed6_1);
  ship_hed5_1:ApplyImpulse(15, Vector3(0, -0.3, -1));
  ship_hed6_1:ApplyImpulse(15, Vector3(0, -0.3, -1));
  flight_hed5:Move(Vector3(-100, 0, -100));
  flight_hed6:Move(CONTROL:GetPosition());
--------------------------------------------------------------------------------
--  Timer_Seq(2, Heder_Operate);
  Timer_Seq(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
      Heder_Operate();
    end;
  else
    Heder_Operate();
  end; 
end;

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



--info:top=350,left=130,allvis=0;
function Heder_Dialog()
  Player_Group:DeleteRadar(mRadar);
  SetNormalTimeMode();
  StartDialog("Dialog3");
end;


--info:top=390,left=230,allvis=0;
function Heder_Operate()
  lAfraid = 0;
  trig_ShipyardBlow = NewTrigger("f_inside", TrueCondition, ShipYard_Blow, flight_hed5, Vector3(-100, 0, -100), 200);
  trig_ControlBlow = NewTrigger("f_inside", TrueCondition, Living_Blow, flight_hed6, CONTROL:GetPosition(), 60);
  count2 = 2;
  trig_H5Died = NewTrigger("f_died", Died2Condition, Heder_Nothing, flight_hed5);
  trig_H6Died = NewTrigger("f_died", Died2Condition, Heder_Nothing, flight_hed6);
  local flight = TrampSpeaker:GetFlight();
  trig_TrampDied = NewTrigger("f_died", TrueCondition, finFailed, flight);
  new_SetAllGroupRelations(rel_PvsH, power_rel_1);
  count = 0;
  if (flight_hed1:IsAlive()) then
    count = count +1;
    trig_Hd1Died = NewTrigger("f_died", DiedCondition, Heder_Died, flight_hed1);
    trig_HederAfraided = NewTrigger("HP", TrueCondition, Heder_Afraided, ship_hed1_1, 5000);
  end;
  if (flight_hed2:IsAlive()) then
    count = count +1;
    trig_Hd2Died = NewTrigger("f_died", DiedCondition, Heder_Died, flight_hed2);
  end;
  if (flight_hed3:IsAlive()) then
    count = count +1;
    trig_Hd3Died = NewTrigger("f_died", DiedCondition, Heder_Died, flight_hed3);
  end;
  if (flight_hed4:IsAlive()) then
    count = count +1;
    trig_Hd4Died = NewTrigger("f_died", DiedCondition, Heder_Died, flight_hed4);
  end;
  if (flight_hed5:IsAlive()) then
    count = count +1;
    trig_Hd5Died = NewTrigger("f_died", DiedCondition, Heder_Died, flight_hed5);
  end;
  if (flight_hed6:IsAlive()) then
    count = count +1;
    trig_Hd6Died = NewTrigger("f_died", DiedCondition, Heder_Died, flight_hed6);
  end;
  if (flight_hed7:IsAlive()) then
    count = count +1;
    trig_Hd7Died = NewTrigger("f_died", DiedCondition, Heder_Died, flight_hed7);
  end;
  if (flight_hed8:IsAlive()) then
    count = count +1;
    trig_Hd8Died = NewTrigger("f_died", DiedCondition, Heder_Died, flight_hed8);
  end;
  AddQuest("quest_19a_02", "#L_Quest_19a_02a", "#L_Quest_19a_02b", QUEST_PROCESS);
  Timer_Seq(20, Kfni_Phantom);
end;


--info:top=440,left=160,allvis=0;
function Died2Condition()
  count2 = count2 - 1;
  if (count2==0) then
    return TRUE;
  end;
  return FALSE;
end;


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


--info:top=450,left=30,allvis=0;
function Kfni_Phantom()
  local flight = TrampSpeaker:GetFlight();
  if (flight:IsAlive()) then
    DispetcherSpeaker:Message("#L_disp_01", 4, "Tramp_Who");
  end;
end;


--info:top=490,left=30,allvis=0;
function Tramp_Who()
  TrampSpeaker:Message("#L_Tramp_01", 3, "Dispetcher_No");
end;


--info:top=530,left=30,allvis=0;
function Dispetcher_No()
  DispetcherSpeaker:Message("#L_disp_02", 10, "Tramp_Wanders");
end;


--info:top=570,left=30,allvis=0;
function Tramp_Wanders()
  TrampSpeaker:Message("#L_Tramp_02", 4);
end;


--info:top=610,left=130,allvis=0;
function ShipYard_Blow()
  ship_001:Blow();
  ship_002:Blow();
  ship_003:Blow();
  ship_004:Blow();
  ship_005:Blow();
  ship_006:Blow();
  ship_007:Blow();
  ship_008:Blow();
  ship_tr2_1:Blow();
  DOCK1:Blow();
  DOCK2:Blow();
  DOCK3:Blow();
  DOCK4:Blow();
  trig_H5Died:Delete();
  if (flight_hed1:IsAlive()) then
    if (flight_hed7) then flight_hed7:Escort(ship_hed1_1); end;
    if not(CONTROL:IsAlive()) then
      HederSpeaker:Message("#L_Heder_02", 5, "Heder_GoOut");
    elseif not(flight_hed6:IsAlive()) then
      HederSpeaker:Message("#L_Heder_01", 5, "Heder_GoOut");
    else
      NewTrigger("f_died", TrueCondition, Only_Shipyard, flight_hed6);
    end;
  end;
  if (GetQuestState("quest_19a_02")==QUEST_PROCESS) then SetQuestState("quest_19a_02", QUEST_FAILED); end;
end;


--info:top=610,left=250,allvis=0;
function Living_Blow()
  CONTROL:Blow();
  trig_H6Died:Delete();
  if (flight_hed1:IsAlive()) then
    if (flight_hed8) then flight_hed8:Escort(ship_hed1_1); end;
    if not(DOCK1:IsAlive()) then
      HederSpeaker:Message("#L_Heder_02", 5, "Heder_GoOut");
    elseif not(flight_hed5:IsAlive()) then
      HederSpeaker:Message("#L_Heder_03", 7, "Heder_GoOut");
    else
      NewTrigger("f_died", TrueCondition, Only_Living, flight_hed5);
    end;
  end;
  if (GetQuestState("quest_19a_01")==QUEST_PROCESS) then SetQuestState("quest_19a_01", QUEST_FAILED); end;
  if (GetQuestState("quest_19a_02")==QUEST_PROCESS) then SetQuestState("quest_19a_02", QUEST_FAILED); end;
end;


--info:top=650,left=130,allvis=0;
function Only_Shipyard()
  if (flight_hed1:IsAlive()) then
    HederSpeaker:Message("#L_Heder_01", 5, "Heder_GoOut");
  end;
end;


--info:top=650,left=250,allvis=0;
function Only_Living()
  if (flight_hed1:IsAlive()) then
    HederSpeaker:Message("#L_Heder_03", 7, "Heder_GoOut");
  end;
end;


--info:top=610,left=370,allvis=0;
function Heder_Nothing()
  if (flight_hed1:IsAlive()) then
    HederSpeaker:Message("#L_Heder_04", 9, "Heder_GoOut");
  end;
end;


--info:top=610,left=490,allvis=0;
function Heder_Afraided()
  if (flight_hed1:IsAlive()) then
    HederSpeaker:Message("#L_Heder_05", 4, "HVks_But");
  end;
end;


--info:top=650,left=490,allvis=0;
function HVks_But()
  VksSpeaker:Message("#L_vks_01", 3, "Heder_Damn");
end;


--info:top=690,left=490,allvis=0;
function Heder_Damn()
  if (flight_hed1:IsAlive()) then
    lAfraid = 1;
    HederSpeaker:Message("#L_Heder_06", 4, "Heder_Out");
    if (flight_hed5:IsAlive()) then flight_hed5:Move(ship_hed1_1:GetPosition()); end;
    if (flight_hed6:IsAlive()) then flight_hed6:Move(ship_hed1_1:GetPosition()); end;
  else
    StopHere();
  end;
end;


--info:top=740,left=370,allvis=0;
function Heder_GoOut()
  StopHere();
  if (flight_hed1:IsAlive()) then
    local pos = ship_hed1_1:GetPosition();
    local orn = ship_hed1_1:GetVectorOrientation();
    local glow_orn = ship_hed1_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_hed1:Move(pos+orn);
    ship_hed1_1:PlayFX("Portal Out.shfx");
    Timer_Seq(5, Heder_Out);
  end;
end;


--info:top=780,left=370,allvis=0;
function Heder_Out()
  if (flight_hed1:IsAlive()) then
    flight_hed1:Delete();
    if not(CONTROL:IsAlive()) or not(DOCK1:IsAlive()) then
      if (flight_hed2:IsAlive()) then flight_hed2:Delete(); end;
      if (flight_hed3:IsAlive()) then flight_hed3:Delete(); end;
      if (flight_hed4:IsAlive()) then flight_hed4:Delete(); end;
      if (flight_hed7:IsAlive()) then flight_hed7:Delete(); end;
      if (flight_hed8:IsAlive()) then flight_hed8:Delete(); end;
    elseif (lAfraid==1) then
      if (flight_hed2:IsAlive()) then flight_hed2:Delete(); end;
      if (flight_hed3:IsAlive()) then flight_hed3:Delete(); end;
      if (flight_hed4:IsAlive()) then flight_hed4:Delete(); end;
      if (flight_hed5:IsAlive()) then flight_hed5:Delete(); end;
      if (flight_hed6:IsAlive()) then flight_hed6:Delete(); end;
      if (flight_hed7:IsAlive()) then flight_hed7:Delete(); end;
      if (flight_hed8:IsAlive()) then flight_hed8:Delete(); end;
    end;
  end;
end;


--info:top=610,left=620,allvis=0;
function Heder_Died()
  if (TrampSpeaker:IsAlive()) then
    if (GetQuestState("quest_19a_02")==QUEST_PROCESS) then SetQuestState("quest_19a_02", QUEST_DONE); end;
    lWait = 1;
    local flight = TrampSpeaker:GetFlight();
    if (CONTROL:IsAlive()) then
      if (DOCK1:IsAlive()) then
        TrampSpeaker:Message("#L_Tramp_03", 6);
        flight:Move(DOCK3:GetPosition()+Vector3(-20, 30, 35));
        NewTrigger("f_inside", TrueCondition, Tramp_Change_Ship, flight, DOCK3:GetPosition()+Vector3(-20, 30, 35), 5);
      else
        TrampSpeaker:Message("#L_Tramp_04", 8, "Hero_WhatNow");
        flight:Escort(mothership);
        NewTrigger("f_object_inside", TrueCondition, Tramp_Return, flight, mothership, 150);
      end;
      nav_current = CreateNavPoint("", mothership:GetPosition(), "nav_void.dds", RGB(255,255,255), mothership);
      LineToStation = CreateLine(nav_current, np_control, RGB(20,80,220), .3, TRUE, .2, 1);
    else
      if (GetQuestState("quest_19a_01")==QUEST_PROCESS) then SetQuestState("quest_19a_01", QUEST_FAILED); end;
      AddQuest("quest_19a_03", "#L_Quest_19a_03a", "#L_Quest_19a_03b", QUEST_PROCESS);
      if (DOCK1:IsAlive()) then
        TrampSpeaker:Message("#L_Tramp_06", 10);
        flight:Move(DOCK3:GetPosition()+Vector3(-20, 30, 35));
        NewTrigger("f_inside", TrueCondition, Tramp_Change_Ship, flight, DOCK3:GetPosition()+Vector3(-20, 30, 35), 5);
      else
        NewTrigger("f_object_inside", TrueCondition, Tramp_Return, flight, mothership, 150);
        SetNormalTimeMode();
        StartDialog("Dialog4");
      end;
    end;
  end;
end;


--info:top=650,left=620,allvis=0;
function Hero_WhatNow()
  HeroSpeaker:Message("#L_Hero_01", 3, "Tramp_GoToStation");
end;


--info:top=690,left=620,allvis=0;
function Tramp_GoToStation()
  TrampSpeaker:Message("#L_Tramp_05", 10);
end;


--info:top=800,left=730,allvis=0;
function Tramp_Change_Ship()
  trig_TrampDied:Delete();
  local flight = VksGroup_1:CreateFlight("flight_tr2");
  ship_tr2_1:AssignPilot(TrampSpeaker);
  flight:AddShip(ship_tr2_1);
  flight:Escort(mothership);
  NewTrigger("f_object_inside", TrueCondition, Tramp_Return_OnNew, flight, mothership, 150);
end;


--info:top=800,left=530,allvis=0;
function Tramp_Return()
  lWait = 2;
  local flight = TrampSpeaker:GetFlight();
  VksGroup_1:RemoveFlight(flight);
  Player_Group:AddFlight(flight);
  flight:Escort(mothership);
  if (CONTROL:IsAlive()) then
    if (GetQuestState("quest_19a_03")==QUEST_PROCESS) then
      SetQuestState("quest_19a_03", QUEST_DONE);
      SetNormalTimeMode();
      StartDialog("Dialog5");
    else
      RemoveQuest("quest_19a_01");
      AddQuest("quest_19a_04", "#L_Quest_19a_04a", "#L_Quest_19a_04b", QUEST_PROCESS);
    end;
  else
    if (GetQuestState("quest_19a_03")==QUEST_PROCESS) then
      SetQuestState("quest_19a_03", QUEST_DONE);
    end;
    Timer_Seq(1, To_Altrabon);
  end;
end;


--info:top=1030,left=730,allvis=0;
function To_Altrabon()
  lMission = 0;
  AddQuest("quest_19aO_01", "#L_Quest_19aO_01a", "#L_Quest_19aO_01b", QUEST_PROCESS);
  AddQuest("quest_19aO_02", "#L_Quest_19aO_02a", "#L_Quest_19aO_02b", QUEST_PROCESS);
  AutoSave("#AS_mission_19_1");
end;


--info:top=840,left=730,allvis=0;
function Tramp_Return_OnNew()
  lWait = 2;
  local flight = TrampSpeaker:GetFlight();
  flight:Stop();
  Change_Mathership();
  Anim_4 = CreateMovie(_ASIMUTHCAM);
  Anim_4:SetLength(12);
  Anim_4:SetInterpolate(_LINEAR);
  Anim_4:SetTarget(ship_tr2_1);
  Anim_4:InitMovie(1, TRUE, 5);
  Anim_4:AddKeys(167.1156, 78.3496, 37.32, 0);
  Anim_4:AddKeys(270.3316, 59.7303, 37.32, 12);
  Anim_4:Play();
  Anim_4:AttachEscapeScript("fin_Dialog");
  Anim_4:AttachAction("fin_Dialog");
end;


--info:top=870,left=780,allvis=0;
function Change_Mathership()
  mothership_old = mothership;
  mothership = SetPlayerMotherShip(ship_tr2_1);
  GetShipName(mothership);

  PortalTrigger_PORTAL_U:SetObject(mothership);
  PortalsActivate_Action();
  CreateDocking("Control_Dialog",CONTROL:GetPosition(),mothership,150,"",CONTROL);
  AddPilotToPlayer(TrampSpeaker);
end;


--info:top=890,left=730,allvis=0;
function fin_Dialog()
  SetNormalTimeMode();
  if (CONTROL:IsAlive()) then
    if (GetQuestState("quest_19a_03")==QUEST_PROCESS) then
      SetQuestState("quest_19a_03", QUEST_DONE);
      StartDialog("Dialog6");
    else
      RemoveQuest("quest_19a_01");
      AddQuest("quest_19a_04", "#L_Quest_19a_04a", "#L_Quest_19a_04b", QUEST_PROCESS);
    end;
  else
    if (GetQuestState("quest_19a_03")==QUEST_PROCESS) then
      SetQuestState("quest_19a_03", QUEST_DONE);
    end;
    StartDialog("Dialog7");
  end;
end;


--info:top=890,left=440,allvis=0;
function fin_Dialog_Near_Control()
  if (nav_current) then
    nav_current:Delete();
    nav_current = NIL;
  end;
  if (LineToStation) then
    LineToStation:Delete();
    LineToStation = NIL;
  end;
  SetNormalTimeMode();
  if (mothership:GetName()=="mothership_lion_mk2a_vks") then
    StartDialog("Dialog6");
  else
    StartDialog("Dialog5");
  end;
end;


--info:top=950,left=530,allvis=0;
function pause_AfterDialog()
  if (mothership:GetName()=="mothership_lion_mk2a_vks") then
    AddPost("book019a_1");
  else
    AddPost("book019a_2");
  end;
  Timer_Seq(1, Jamp_To);
  AutoSave("#AS_mission_19_1");
end;


--info:top=990,left=530,allvis=0;
function Jamp_To()
  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_5 = CreateMovie(_TARGETCAM);
  Anim_5:SetLength(5);
  Anim_5:SetInterpolate(_LINEAR);
  Anim_5:SetTarget(mothership);
  Anim_5:InitMovie(1, TRUE, 1);
  Anim_5: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_5:Play();
  Anim_5:AttachEscapeScript("Teleport_To");
  Anim_5:AttachAction("Teleport_To");
end;


--info:top=1030,left=530,allvis=0;
function Teleport_To()
  lMission = 0;
  dest_location = "torr";
  CustomTeleportate("xt86", dest_location, "long_jump");
end;


--info:top=480,left=910,allvis=0;
function finFailed()
  if (GetQuestState("quest_19a_02")==QUEST_PROCESS) then SetQuestState("quest_19a_02", QUEST_FAILED); end;
  if (flight_hed1:IsAlive()) then
    HederSpeaker:Message("#L_Heder_07", 9, "Both_Blow");
  else
    Timer_Seq(1, Sedoy_EndGame);
  end;
end;


--info:top=520,left=910,allvis=0;
function Both_Blow()
  StopHere();
  if (flight_hed5:IsAlive()) then
    if (DOCK1:IsAlive()) then
      trig_ShipyardBlow:Delete();
      Timer_Seq(1, ShipYard_Blow);
    end;
  end;
  if (flight_hed6:IsAlive()) then
    if (CONTROL:IsAlive()) then
      trig_ControlBlow:Delete();
      Timer_Seq(1, Living_Blow);
    end;
  end;
  Timer_Seq(6, Sedoy_EndGame);
end;


--info:top=990,left=910,allvis=0;
function Sedoy_EndGame()
  SedoySpeaker:Message("#L_Sedoy_01", 5, "failedMission");
end;


--info:top=1030,left=910,allvis=0;
function failedMission()
  StopHere();
  EndGame("gamefailed");
end;


--info:top=110,left=410,allvis=0;
function StartInitMission()
  VksTeam = CreateTeam("Vks");

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

  Player_Group = MothershipPilot:GetGroup();
  Heder_Group = VksTeam:CreateGroup("Heder_Group");
  Heder_Group_2 = VksTeam:CreateGroup("Heder_Group_2");
  Tramp_Group = VksTeam:CreateGroup("Tramp_Group");
  power_rel_1 = {Player_Group, Heder_Group, Heder_Group_2, VksGroup_1};
  rel_Neutral = {{"N"},
                 {"N","N"},
                 {"F","N","N"}};
  rel_HvsT = {{"X"},
              {"X","X"},
              {"X","W","X"}};
  rel_PvsH = {{"W"},
              {"X","X"},
              {"X","X","X"}};
  rel_PvsT = {{"X"},
              {"X","X"},
              {"W","X","X"}};
  new_SetAllGroupRelations(rel_Neutral, power_rel_1);

  HeroSpeaker = GetPilot("Hero");
  SedoySpeaker = GetPilot("Sedoy");
  ValidolSpeaker = GetPilot("Validol");
  TrampSpeaker = GetPilot("Tramp");
  KalemSpeaker = GetPilot("Kalem");
  LastochkaSpeaker = GetPilot("Lastochka2");
  VksSpeaker = CreatePilot("VksAce");
  DispetcherSpeaker = CreatePilot("DispetcherVKS");
  HederSpeaker = CreatePilot("AdmiralVKS_Heder");

  flight_vks03:Move(PORTAL_U:GetPosition()+Vector3(-50, 0, -200));
-- готовый Лев
  ship_tr2_1 = CreateCarcass("Mothership_Lion_mk2a_vks", DOCK3:GetPosition()+Vector3(0, 50, 35), Vector3(0, 0, 1));

  AddPost("news016_1");
  AddPost("news016_5");
  AddPost("news016_2");
  AddPost("news016_6");
  AddPost("news016_3");
  AddPost("news016_7");
  AddPost("news016_4");

  lMission = 1;
  local NShop_Vks_sst = {		-- количество каждого предмета в магазине
	{0,0,12,6,0,0,12,9,		-- HC,VC guns
	0,12,9,3,0,12,6,			-- LC,PLC
	0,9,6,12,9,6,			-- PC,RG
	0,0,15,9,0,18,12,6,		-- THC,TVC
	0,9,9,3,12,9,6,			-- TLC,TPLC
	0,9,6,0,9,3,			-- TPC,TRG
	0,9,12,6,0,9,12,6,3,0,0,		-- CG,AC
	9,6,3,0,0,0,0,0,0,0,0,0},	-- GK
	{0,0,9,6,0,0,12,9,0,9,12,9,	-- LRS,ECM,AMS systems
	0,6,3,9,6,0,12,9,6,		-- Stealth,LRRNB
	0,0,18,9,0,6,9,6,		-- RBot
	0,0,12,9,3,0,12,3,9,6,6,6,	-- Sh,Eng,Man
	0,18,12,9,6,0,12,6,		-- Gun,ALS
	0,9,6,6,0,9,9,6,9,3,		-- BS_
	0,9,6,3,0,12,9,6,		-- RBot,Sh
	6,3,6,6,3,6,0,0,6,3},		-- Eng,Gun,ALS
	{0,27,21,12,0,45,30,18,36,36,24,18,	-- SM,SRM,LRM rockets
	0,18,12,30,21,15},			-- T,MIRV
	{0,0,0,0,6,		-- 1
	6,0,6,6,6,		-- 2
	12,9,0,0,0,0,0,		-- 3
	12,9,6,9,0,0,0,0,	-- 4
	6,0,0,0,0,0}};		-- 5 level ships
  CreateShop("control");
  AddAllToShops({"control"}, NShop_Vks_sst, 80, 0.0, 0.0);
  UpdateTradeSystem(TRUE);
  CreateDocking("Control_Dialog",CONTROL:GetPosition(),mothership,150,"",CONTROL);
  DOCK1:SetGodMode(FALSE);
  DOCK2:SetGodMode(FALSE);
  DOCK3:SetGodMode(FALSE);
  DOCK4:SetGodMode(FALSE);
  LINK:SetGodMode(FALSE);
  CONTROL:SetGodMode(FALSE);

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

-- вылет мазершипа, если требуется
  last_loc = GetLastLocation();
  if (last_loc=="xt23") then
    CreatePortalGlow(Vector3(600, 300, -150), Vector3(-1, 0, 0), 7);
    mothership:SetPosition(Vector3(600, 300, -150));
    mothership:SetOrientation(CreateQuaternionFromVector3(Vector3(-1, 0, 0)));
    mothership:PlayFX("Portal Out.shfx");
    mothership:ApplyImpulse(15, Vector3(-1, 0, 0));
    FocusOn({mothership}, Vector3(-0.2534,0.4,-0.6601), 60);
  end;
end;


--info:top=190,left=460,allvis=0;
function My_TeleporterAction()
  if (lMission==1) then
    OutputToScreenLog("#L_sys_02", 7);
    Timer_Seq(7, fin_failed);
  else
    Timer_Seq(1, TeleporterAction);
  end;
end;


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


--info:top=130,left=440,allvis=0;
function Control_Dialog()
  if (nav_current) then
    nav_current:Delete();
    nav_current = NIL;
  end;
  if (LineToStation) then
    LineToStation:Delete();
    LineToStation = NIL;
  end;
  MothershipFlight:Stop();
  if (GetQuestState("quest_19a_01")==QUEST_PROCESS) then
    SetQuestState("quest_19a_01", QUEST_DONE);
    if (lWait==1) then
      AddQuest("quest_19a_03", "#L_Quest_19a_03a", "#L_Quest_19a_03b", QUEST_PROCESS);
    elseif (lWait==2) then
      Timer_Seq(2, fin_Dialog_Near_Control);
    end;
  end;
  if (GetQuestState("quest_19a_04")==QUEST_PROCESS) then
    SetQuestState("quest_19a_04", QUEST_DONE);
    Timer_Seq(2, fin_Dialog_Near_Control);
  end;
  SetTraderFlag(TRUE);
  TradeStationDlg("control");
end;


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

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


--info:top=70,left=570,allvis=0;
function ACTION_LEAVELOCATION()
  if (tmpNull) then tmpNull:Delete(); end;
  if (lMission==1) then
    Terminate();
  else
    SetInitTeamRelation("Vks", PLAYER_TEAM, RELATION_NEUTRAL);
    SetInitTeamRelation("Kfni", PLAYER_TEAM, RELATION_NEUTRAL);
    if (GetQuestState("quest_19a_01")~=QUEST_NOINIT) then RemoveQuest("quest_19a_01"); end;
    if (GetQuestState("quest_19a_02")~=QUEST_NOINIT) then RemoveQuest("quest_19a_02"); end;
    if (GetQuestState("quest_19a_03")~=QUEST_NOINIT) then RemoveQuest("quest_19a_03"); end;
    if (GetQuestState("quest_19a_04")~=QUEST_NOINIT) then RemoveQuest("quest_19a_04"); end;
    QuestActionDone();
    if (destlocation=="torr") then
      QuestStart("mission_20a");
    else
      QuestChoice("mission_19a_1","altrabon");
      QuestChoice("mission_19a_2","corrino");
      QuestChoice("mission_19a_3","taira");
      QuestChoice("mission_19a_4","shula");
      QuestChoice("mission_20a","nk");
    end;
  end;

  return TRUE;
end;


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

  return TRUE;
end;
