------------------------------------------------------------
--     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();
  MothershipFlight:Stop();
  if (flight_cor1:IsAlive()) then
    StartDialog("Dialog1");
  elseif (flight_tr1:IsAlive()) then
    StartDialog("Dialog2");
  elseif (flight_aia1:IsAlive()) then
    StartDialog("Dialog3");
  else
    StartDialog("Dialog4");
  end;
end;


--info:top=240,left=130,allvis=0;
function Against_Uel()
  local NShop_NI = {		-- количество каждого предмета в магазине
	{9,9,0,0,9,12,0,0,		-- HC,VC guns
	6,6,0,0,9,0,0,			-- LC,PLC
	9,6,0,6,3,0,			-- PC,RG
	9,6,0,0,9,9,3,0,		-- THC,TVC
	6,6,0,0,6,0,0,			-- TLC,TPLC
	6,0,0,6,0,0,			-- TPC,TRG
	9,9,0,0,9,9,0,0,0,0,0,		-- CG,AC
	0,0,0,0,0,0,0,0,0,0,0,0},	-- GK
	{9,9,3,0,9,9,3,0,9,6,3,0,	-- LRS,ECM,AMS systems
	6,3,0,3,0,9,6,0,0,		-- Stealth,LRRNB
	24,12,6,0,9,6,3,0,		-- RBot
	12,9,3,0,0,18,9,9,6,0,3,0,	-- Sh,Eng,Man
	27,9,0,6,0,6,0,0,		-- Gun,ALS
	6,6,0,0,6,6,0,0,0,0,		-- BS_
	6,3,0,0,9,6,0,0,		-- RBot,Sh
	3,0,0,0,0,0,0,3,0,0},		-- Eng,Gun,ALS
	{30,21,9,0,36,18,6,0,18,9,0,0,	-- SM,SRM,LRM rockets
	9,3,0,6,0,0},			-- T,MIRV
	{12,9,12,12,9,		-- 1
	9,9,9,6,6,		-- 2
	0,6,0,0,0,0,6,		-- 3
	0,0,0,0,0,3,0,0,	-- 4
	0,0,0,0,0,0}};		-- 5 level ships
  local NShop_NI_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,9,3,0,		-- CG,AC
	0,0,0,0,0,0,0,0,0,9,6,3},	-- 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,0,6,0,		-- 2
	0,9,0,0,0,0,9,		-- 3
	0,0,0,0,0,9,12,9,	-- 4
	3,0,9,0,0,0}};		-- 5 level ships
  CreateShop("nk_20c");
  AddAllToShops({"nk_20c"},NShop_NI,70,0.0,0.0);
  AddAllToBlackShops({"nk_20c"},NShop_NI_sst,90,0.0,0.0);
  UpdateTradeSystem(TRUE);
  ChangeFuncDocking("My_TradeStation_Action", TRADE);
  if (flight_ber1) and (flight_ber1:IsAlive()) then
    flight_ber1:Escort(ship_uel1_1);
  else
    CreatePortalGlow(ship_uel1_1:GetPosition()+Vector3(-200, 20, -60), Vector3(1, 0, 0), 5);
    NewBerserkSuperFlight("Uel_Group", "ber1", ship_uel1_1:GetPosition()+Vector3(-200, 20, -60), 3, 20, Vector3(1, 0, 0));
    flight_ber1:Escort(ship_uel1_1);
  end;
  if (flight_ber2) and (flight_ber2:IsAlive()) then
    flight_ber2:Escort(ship_uel1_1);
  else
    CreatePortalGlow(ship_uel1_1:GetPosition()+Vector3(-150, -20, 60), Vector3(1, 0, 0), 5);
    NewBerserkSuperFlight("Uel_Group", "ber2", ship_uel1_1:GetPosition()+Vector3(-150, -20, 60), 3, 20, Vector3(1, 0, 0));
    flight_ber2:Escort(ship_uel1_1);
  end;
  if (flight_ber3) and (flight_ber3:IsAlive()) then
    flight_ber3:Escort(ship_uel1_1);
  else
    CreatePortalGlow(ship_uel1_1:GetPosition()+Vector3(-100, -70, 20), Vector3(1, 0, 0), 5);
    NewBerserkSuperFlight("Uel_Group", "ber3", ship_uel1_1:GetPosition()+Vector3(-100, -70, 20), 3, 20, Vector3(1, 0, 0));
    flight_ber3:Escort(ship_uel1_1);
  end;
  if (flight_ber4) and (flight_ber4:IsAlive()) then
    flight_ber4:Escort(ship_uel1_1);
  else
    CreatePortalGlow(ship_uel1_1:GetPosition()+Vector3(-100, 70, 40), Vector3(1, 0, 0), 5);
    NewBerserkSuperFlight("Uel_Group", "ber4", ship_uel1_1:GetPosition()+Vector3(-100, 70, 40), 3, 20, Vector3(1, 0, 0));
    flight_ber4:Escort(ship_uel1_1);
  end;
  table_Berserk1 = {{"NewBerserkFlight", "Uel_Group", ship_ber1_1, {"brR11", "brR12", "brR13", "brR14"}, 16, ship_ber1_1, "escort"},
                    {"NewBerserkFlight", "Uel_Group", ship_ber2_1, {"brR21", "brR22", "brR23", "brR24"}, 16, ship_ber2_1, "escort"},
                    {"NewBerserkFlight", "Uel_Group", ship_ber3_1, {"brR31", "brR32", "brR33", "brR34"}, 16, ship_ber3_1, "escort"},
                    {"NewBerserkFlight", "Uel_Group", ship_ber4_1, {"brR41", "brR42", "brR43", "brR44"}, 16, ship_ber4_1, "escort"},
                    {"NewUelCopyFlight", "Uel_Group", ship_uel1_1, {"copy1", "copy2", "copy3", "copy4", "copy5", "copy6"}, 1, ship_uel1_1, "escort"}};
  InitializationRespawn(table_Berserk1);
  StartRespawn();
  ship_uel1_1:ComeToPortal(PORTAL_D);
  NewTrigger("f_object_inside", TrueCondition, Uel_Dialog, flight_uel1, PORTAL_D, 15);
  Stop_Fighting(rel_WarUel);
  SedoySpeaker:Message("#L_Sedoy_01", 4);
  AddQuest("quest_20c_01", "#L_Quest_20c_01a", "#L_Quest_20c_01b", QUEST_PROCESS);
  trig_UelAfraided = NewTrigger("HP", TrueCondition, Uel_Afraided, ship_uel1_1, 15000);
  trig_UelDied = NewTrigger("f_died", TrueCondition, Uel_Died, flight_uel1);
end;


--info:top=340,left=160,allvis=0;
function My_TradeStation_Action()
  ShowMsgBox("#UI_TradeStationWndCaption", "#UI_TradeStationDockRequest", My_TradeStationDock_Ok, My_TradeStationDock_Cancel);
end;


--info:top=370,left=190,allvis=0;
function My_TradeStationDock_Ok()
  MothershipFlight:Stop();
  TradeStationDlg("nk_20c");
end;


--info:top=390,left=160,allvis=0;
function My_TradeStationDock_Cancel()
end;


--info:top=320,left=40,allvis=0;
function Uel_Dialog()
  ship_uel1_1:SetHP(30000);
  ship_uel1_1:SetShield(18000);
  SetNormalTimeMode();
  StartDialog("Dialog5");
end;


--info:top=360,left=40,allvis=0;
function Uel_GoOut()
  PORTAL_D:Start(5, 0);
  Timer_Seq(2, Uel_Out);
end;


--info:top=400,left=40,allvis=0;
function Uel_Out()
  SetQuestState("quest_20c_01", QUEST_FAILED);
  if (trig_UelAfraided) then
    trig_UelAfraided:Delete();
    trig_UelAfraided = NIL;
  end;
  trig_UelDied:Delete();
  trig_UelDied = NIL;
  flight_uel1:Delete();
  for i=1, 20 do
    local flight = getglobal("flight_br"..i);
    if not(flight) or not(flight:IsAlive()) then
      local posiX = RAND(2000)-1000;
      local posiY = RAND(200)-100;
      local posiZ = RAND(2000)-1000;
      local flightType = RAND(2) + 1;
      local flightStrength = RAND(5) + 16;
      CreatePortalGlow(Vector3(posiX, posiY, posiZ), Vector3(0, 0, -1), 5);
      flight = NewBerserkSuperFlight("Uel_Group", "br"..i, Vector3(posiX, posiY, posiZ), flightType, flightStrength, Vector3(0, 0, -1));
      flight:SetChaseDistance(2000);
    end;
    flight:Attack(mothership);
  end;
  SedoySpeaker:Message("#L_Sedoy_02", 3, "failedMission");
end;


--info:top=440,left=40,allvis=0;
function failedMission()
  EndGame("NewEmpWithoutGrey_PartWin");
end;


--info:top=280,left=390,allvis=0;
function Uel_Afraided()
  trig_UelAfraided:Delete();
  trig_UelAfraided = NIL;
  SetNormalTimeMode();
  StartDialog("Dialog6");
end;


--info:top=320,left=390,allvis=0;
function Uel_Died()
  SetQuestState("quest_20c_01", QUEST_DONE);
  StopRespawn();
  for i=1, 20 do
    local flight = getglobal("flight_br"..i);
    if (flight) and (flight:IsAlive()) then
      flight:Blow();
    end;
  end;
  for i=1, 4 do
    local flight = getglobal("flight_ber"..i);
    if (flight) and (flight:IsAlive()) then
      flight:Blow();
    end;
  end;
  for i=1, 4 do
    for j=1, 6 do
      local flight = getglobal("flight_brR"..i..j);
      if (flight) and (flight:IsAlive()) then
        flight:Blow();
      end;
    end;
  end;
  for i=1, 6 do
    local flight = getglobal("flight_copy"..i);
    if (flight) and (flight:IsAlive()) then
      flight:Blow();
    end;
  end;
  SedoySpeaker:Message("#L_Sedoy_03", 6, "All_Done");
end;


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


--info:top=370,left=390,allvis=0;
function All_Done()
  StopHere();
  SetNormalTimeMode();
  MothershipFlight:Stop();
  StartDialog("Dialog7");
end;


--info:top=440,left=390,allvis=0;
function finMission()
  EndGame("NewEmpWithoutGrey");
end;


--info:top=240,left=530,allvis=0;
function For_Uel()
-- выгружаем пилотов с базы
  Remove_Pers_FromBase();
-- меняем базу на новую
  local posn = ship_uel1_1:GetPosition();
  local orn = ship_uel1_1:GetOrientation();
  local ornv = ship_uel1_1:GetVectorOrientation();
  mothership_old = mothership;
  ship_uel1_1:SetPosition(Vector3(-3000, 0, 3000));
  ship_nm1_1:SetPosition(posn);
  ship_nm1_1:SetOrientation(orn);
  mothership = SetPlayerMotherShip(ship_nm1_1); 
  TempPilot = CreatePilot("BasePilot");
  mothership_old:AssignPilot(TempPilot);
  Old_Mothership_Flight = Allies_Group:CreateFlight("Old_Mothership_Flight");
  Old_Mothership_Flight:AddShip(mothership_old);
  Stop_Player_Pilots();
  PortalTrigger_PORTAL_D:SetObject(mothership);
  PortalTrigger_PORTAL_L:SetObject(mothership);
  PortalTrigger_PORTAL_U:SetObject(mothership);
  PortalsActivate_Action();
  CreateTradeStationDocking(TRADE, mothership);
  CreateRepairStationDocking(STO_Station, mothership, 110, 1);
-- удаляем новую базу из группы игрока
  MothershipPilot = mothership:GetPilot(); 
  MothershipFlight = MothershipPilot:GetFlight(); 
  Player_Group:RemoveFlight(MothershipFlight);
  Uel_Group:AddFlight(MothershipFlight);
-- создаем новое звено для старого мазершипа и команды игрока 
  FocusOn({HeroSpeaker:GetShip(), SedoySpeaker:GetShip(), LastochkaSpeaker:GetShip(), KalemSpeaker:GetShip(), CheSpeaker:GetShip(), AlexandraSpeaker:GetShip()}, ornv, 60);
  
  local HFlight = HeroSpeaker:GetFlight();
  if (HFlight:GetPilotCount()>1) then
    local NewHFlight = Uel_Group:CreateFlight("NewHFlight");
    NewHFlight:AddShip(HeroSpeaker:GetShip());
  end;
  local AFlight = AlexandraSpeaker:GetFlight();
  if (AFlight:GetPilotCount()==1) then
    Player_Group:RemoveFlight(AFlight);
    Allies_Group:AddFlight(AFlight);
    AFlight:Escort(mothership_old);
  else
    local NewAFlight = Allies_Group:CreateFlight("NewAFlight");
    NewAFlight:AddShip(AlexandraSpeaker:GetShip());
    NewAFlight:Escort(mothership_old);
  end;
  local SFlight = SedoySpeaker:GetFlight();
  if (SFlight:GetPilotCount()==1) then
    Player_Group:RemoveFlight(SFlight);
    Allies_Group:AddFlight(SFlight);
    SFlight:Escort(mothership_old);
  else
    local NewSFlight = Allies_Group:CreateFlight("NewSFlight");
    NewSFlight:AddShip(SedoySpeaker:GetShip());
    NewSFlight:Escort(mothership_old);
  end;
  local LFlight = LastochkaSpeaker:GetFlight();
  if (LFlight:GetPilotCount()==1) then
    Player_Group:RemoveFlight(LFlight);
    Allies_Group:AddFlight(LFlight);
    LFlight:Escort(mothership_old);
  else
    local NewLFlight = Allies_Group:CreateFlight("NewLFlight");
    NewLFlight:AddShip(LastochkaSpeaker:GetShip());
    NewLFlight:Escort(mothership_old);
  end;
  local KFlight = KalemSpeaker:GetFlight();
  if (KFlight:GetPilotCount()==1) then
    Player_Group:RemoveFlight(KFlight);
    Allies_Group:AddFlight(KFlight);
    KFlight:Escort(mothership_old);
  else
    local NewKFlight = Allies_Group:CreateFlight("NewKFlight");
    NewKFlight:AddShip(KalemSpeaker:GetShip());
    NewKFlight:Escort(mothership_old);
  end;
  local CFlight = CheSpeaker:GetFlight();
  if (CFlight:GetPilotCount()==1) then
    Player_Group:RemoveFlight(CFlight);
    Allies_Group:AddFlight(CFlight);
    CFlight:Escort(mothership_old);
  else
    local NewCFlight = Allies_Group:CreateFlight("NewCFlight");
    NewCFlight:AddShip(CheSpeaker:GetShip());
    NewCFlight:Escort(mothership_old);
  end;
-- выставляем отношения
  Stop_Fighting(rel_ForUel);
  Timer_Seq(1, New_Path);
end;


--info:top=270,left=560,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 (AlexandraSpeaker:IsInBase()) or (AlexandraSpeaker:IsBasePilot()) then
    if (AlexandraSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(40, -20, 20), Vector3(1, 0, 0));
    ship:AssignPilot(AlexandraSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightA");
    flight:AddShip(ship);
  end;
  if (CheSpeaker:IsInBase()) or (CheSpeaker:IsBasePilot()) then
    if (CheSpeaker:IsBasePilot()) then RemoveBaseDriver(); end;
    local ship = CreateCarcass("EvilEye_pl1", mothership:GetPosition()+Vector3(40, -20, -20), Vector3(1, 0, 0));
    ship:AssignPilot(CheSpeaker);
    local flight = Player_Group:CreateFlight("tmpFlightC");
    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;
end;


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


--info:top=320,left=530,allvis=0;
function New_Path()
--------------------------------------------------------------------------------
--  StartDialog("Dialog8");
  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() >= 2) then
      choose_pilot();
    else
      StartDialog("Dialog8");
    end;
  else
    StartDialog("Dialog8");
  end; 
end;

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



--info:top=360,left=530,allvis=0;
function GoTo_Portal()
  if (HeroSpeaker:IsCanSayReplica()) then
    HeroFlight = HeroSpeaker:GetFlight();
    Player_Group:RemoveFlight(HeroFlight);
  end;
  Uel_Group:RemoveFlight(MothershipFlight);
  Player_Group:AddFlight(MothershipFlight);
  GetShipName(mothership);
  if (HeroSpeaker:IsCanSayReplica()) then
    HeroFlight = HeroSpeaker:GetFlight();
    Player_Group:AddFlight(HeroFlight);
  end;
  Add_Uel2();
  Add_Uel2();
  Add_Uel3();
  Add_Uel3();
  Add_Uel4();
  AddQuest("quest_20c_03", "#L_Quest_20c_03a", "#L_Quest_20c_03b", QUEST_PROCESS);
  NewTrigger("inside", TrueCondition, Uel_AllGood, mothership, PORTAL_D:GetPosition(), 60);
  NewTrigger("inside", TrueCondition, Uel_AllGood, mothership, PORTAL_L:GetPosition(), 60);
  NewTrigger("inside", TrueCondition, Uel_AllGood, mothership, PORTAL_U:GetPosition(), 60);
end;


--info:top=390,left=590,allvis=0;
function Add_Uel2()
  local pilot = CreatePilot("Uel2");
  Uel2_To_Uber(pilot);
  AddPilotToPlayer(pilot);
end;


--info:top=430,left=590,allvis=0;
function Add_Uel3()
  local pilot = CreatePilot("Uel3");
  Uel3_To_Uber(pilot);
  AddPilotToPlayer(pilot);
end;


--info:top=470,left=590,allvis=0;
function Add_Uel4()
  local pilot = CreatePilot("Uel4");
  Uel4_To_Uber(pilot);
  AddPilotToPlayer(pilot);
end;


--info:top=500,left=530,allvis=0;
function Uel_AllGood()
  SetNormalTimeMode();
  SetQuestState("quest_20c_03", QUEST_DONE);
  UelSpeaker:Message("#L_Uel_01", 6, "finForUel");
end;


--info:top=540,left=530,allvis=0;
function finForUel()
  EndGame("NewKiotoCrash");
end;


--info:top=120,left=450,allvis=0;
function StartInitMission()
  KfniTeam = CreateTeam("Kfni");
  InocoTeam = CreateTeam("Inoco");

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

  Player_Group = MothershipPilot:GetGroup();
  Allies_Group = KfniTeam:CreateGroup("Allies_Group");
  Uel_Group = InocoTeam:CreateGroup("Uel_Group");
  power_rel_1 = {Player_Group,Allies_Group,Uel_Group,UftGroup_1};
  rel_Neutral = {{"F"},
                 {"N","N"},
                 {"N","N","W"}};
  rel_WarUel = {{"X"},
                {"W","W"},
                {"X","X","W"}};
  rel_ForUel = {{"W"},
                {"F","W"},
                {"W","X","W"}};

  HeroSpeaker = GetPilot("Hero");
  SedoySpeaker = GetPilot("Sedoy");
  CheSpeaker = GetPilot("Che");
  AlexandraSpeaker = GetPilot("Alexandra");
  KalemSpeaker = GetPilot("Kalem");
  LastochkaSpeaker = GetPilot("Lastochka2");
  CorsairSpeaker = CreatePilot("Corsair");
  TrampSpeaker = CreatePilot("Tramp");
  AiaSpeaker = CreatePilot("Aia");
  AlexSpeaker = CreatePilot("Alex");
  ClericSpeaker = CreatePilot("Cleric");
  UelSpeaker = CreatePilot("Uel");

  StopRespawn();
  Stop_Fighting(rel_Neutral);
  DisableRandom();
-- назад дороги нет
  Teleporter:Delete();
  Teleporter = CreateTrigger();
  Teleporter:AttachEvent(_EVENT_TIMER); 
  Teleporter:SetTime(3);
  Teleporter:AttachCondition(TrueCondition);
  Teleporter:AttachAction(My_TeleporterAction);

  NewFlight("Uel_Group", "nm1", "Mothership_uel_pl2", "BasePilot", Vector3(3000, 0, 3000), Vector3(-1, 0, 0));
end;


function Stop_Fighting(rel_table)
  if (not(SedoySpeaker:IsInBase())) and (not(SedoySpeaker:IsBasePilot())) and (SedoySpeaker:IsCanSayReplica()) then
    SedoyFlight = SedoySpeaker:GetFlight();
  end;
  if (not(LastochkaSpeaker:IsInBase())) and (not(LastochkaSpeaker:IsBasePilot())) and (LastochkaSpeaker:IsCanSayReplica()) then
    LastochkaFlight = LastochkaSpeaker:GetFlight();
  end;
  if (not(HeroSpeaker:IsInBase())) and (not(HeroSpeaker:IsBasePilot())) and (HeroSpeaker:IsCanSayReplica()) then
    HeroFlight = HeroSpeaker:GetFlight();
  end;
  if (not(CheSpeaker:IsInBase())) and (not(CheSpeaker:IsBasePilot())) and (CheSpeaker:IsCanSayReplica()) then
    CheFlight = CheSpeaker:GetFlight();
  end;
  if (not(AlexandraSpeaker:IsInBase())) and (not(AlexandraSpeaker:IsBasePilot())) and (AlexandraSpeaker:IsCanSayReplica()) then
    AlexandraFlight = AlexandraSpeaker:GetFlight();
  end;
  if (not(KalemSpeaker:IsInBase())) and (not(KalemSpeaker:IsBasePilot())) and (KalemSpeaker:IsCanSayReplica()) then
    KalemFlight = KalemSpeaker:GetFlight();
  end;
  new_SetAllGroupRelations(rel_table, power_rel_1);
  local PlTeam = CreateTeam(PLAYER_TEAM);
  PlTeam:CheckAllegiance();
  KfniTeam:CheckAllegiance();
  InocoTeam:CheckAllegiance();
  Uft_Team:CheckAllegiance();
  MothershipFlight:Stop();
  if (SedoyFlight) then SedoyFlight:Stop(); end;
  if (LastochkaFlight) then LastochkaFlight:Stop(); end;
  if (HeroFlight) then HeroFlight:Stop(); end;
  if (CheFlight) then CheFlight:Stop(); end;
  if (AlexandraFlight) then AlexandraFlight:Stop(); end;
  if (KalemFlight) then KalemFlight:Stop(); end;
end;


--info:top=160,left=450,allvis=0;
function My_TeleporterAction()
  if (GetGroupRelation("Uel_Group", PLAYER_GROUP)==RELATION_WAR) then
    OutputToScreenLog("#L_sys_01", 5);
    Timer_Seq(5, fin_failed);
  end;
end;


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


--info:top=430,left=720,allvis=0;
function Uel2_To_Uber(pilot)
  if not(pilot:HasProperty("Piloting_1")) then
    pilot:SetPerk("Piloting_1");
  end;
  if not(pilot:HasProperty("Piloting_2")) then
    pilot:SetPerk("Piloting_2");
  end;
  if not(pilot:HasProperty("Piloting_3")) then
    pilot:SetPerk("Piloting_3");
  end;
  if not(pilot:HasProperty("Piloting_4")) then
    pilot:SetPerk("Piloting_4");
  end;
  if not(pilot:HasProperty("Hard_to_Kill")) then
    pilot:SetPerk("Hard_to_Kill");
  end;
  if not(pilot:HasProperty("Pilot_1")) then
    pilot:SetPerk("Pilot_1");
  end;
  if not(pilot:HasProperty("Pilot_2")) then
    pilot:SetPerk("Pilot_2");
  end;
  if not(pilot:HasProperty("Pilot_3")) then
    pilot:SetPerk("Pilot_3");
  end;
  if not(pilot:HasProperty("Pilot_4")) then
    pilot:SetPerk("Pilot_4");
  end;
  if not(pilot:HasProperty("Missiles_Rockets")) then
    pilot:SetPerk("Missiles_Rockets");
  end;
  if not(pilot:HasProperty("Missiles_2")) then
    pilot:SetPerk("Missiles_2");
  end;
  if not(pilot:HasProperty("Missiles_3")) then
    pilot:SetPerk("Missiles_3");
  end;
  if not(pilot:HasProperty("Gunnery_1")) then
    pilot:SetPerk("Gunnery_1");
  end;
  if not(pilot:HasProperty("Gunnery_2")) then
    pilot:SetPerk("Gunnery_2");
  end;
  if not(pilot:HasProperty("Gunnery_3")) then
    pilot:SetPerk("Gunnery_3");
  end;
  if not(pilot:HasProperty("Gunnery_4")) then
    pilot:SetPerk("Gunnery_4");
  end;
  if not(pilot:HasProperty("Gunnery_5")) then
    pilot:SetPerk("Gunnery_5");
  end;
  if not(pilot:HasProperty("Elite")) then
    pilot:SetPerk("Elite");
  end;
  if not(pilot:HasProperty("F_Weapon_HC")) and not(pilot:HasProperty("F_Weapon_Laser")) then
    pilot:SetPerk("F_Weapon_HC");
  end;
  if not(pilot:HasProperty("finesse_1")) then
    pilot:SetPerk("finesse_1");
  end;
  if not(pilot:HasProperty("finesse_2")) then
    pilot:SetPerk("finesse_2");
  end;
  if not(pilot:HasProperty("finesse_3")) then
    pilot:SetPerk("finesse_3");
  end;
  if not(pilot:HasProperty("burst_1")) then
    pilot:SetPerk("burst_1");
  end;
  if not(pilot:HasProperty("burst_2")) then
    pilot:SetPerk("burst_2");
  end;
  if not(pilot:HasProperty("burst_3")) then
    pilot:SetPerk("burst_3");
  end;
  if not(pilot:HasProperty("burst_4")) then
    pilot:SetPerk("burst_4");
  end;
  if not(pilot:HasProperty("Systems_1")) then
    pilot:SetPerk("Systems_1");
  end;
  if not(pilot:HasProperty("Systems_2")) then
    pilot:SetPerk("Systems_2");
  end;
  if not(pilot:HasProperty("Systems_3")) then
    pilot:SetPerk("Systems_3");
  end;
  if not(pilot:HasProperty("Gun_Dispersion")) then
    pilot:SetPerk("Gun_Dispersion");
  end;
  if not(pilot:HasProperty("Countermeasures")) then
    pilot:SetPerk("Countermeasures");
  end;
  if not(pilot:HasProperty("Shields_Op")) then
    pilot:SetPerk("Shields_Op");
  end;
  if not(pilot:HasProperty("Repairman")) then
    pilot:SetPerk("Repairman");
  end;
  if not(pilot:HasProperty("Engine_Op")) then
    pilot:SetPerk("Engine_Op");
  end;
  if not(pilot:HasProperty("Fearless")) then
    pilot:SetPerk("Fearless");
  end;
end;


--info:top=470,left=720,allvis=0;
function Uel3_To_Uber(pilot)
  if not(pilot:HasProperty("Piloting_1")) then
    pilot:SetPerk("Piloting_1");
  end;
  if not(pilot:HasProperty("Piloting_2")) then
    pilot:SetPerk("Piloting_2");
  end;
  if not(pilot:HasProperty("Piloting_3")) then
    pilot:SetPerk("Piloting_3");
  end;
  if not(pilot:HasProperty("Hard_to_Kill")) then
    pilot:SetPerk("Hard_to_Kill");
  end;
  if not(pilot:HasProperty("Pilot_1")) then
    pilot:SetPerk("Pilot_1");
  end;
  if not(pilot:HasProperty("Pilot_2")) then
    pilot:SetPerk("Pilot_2");
  end;
  if not(pilot:HasProperty("Pilot_3")) then
    pilot:SetPerk("Pilot_3");
  end;
  if not(pilot:HasProperty("Pilot_4")) then
    pilot:SetPerk("Pilot_4");
  end;
  if not(pilot:HasProperty("Gunnery_1")) then
    pilot:SetPerk("Gunnery_1");
  end;
  if not(pilot:HasProperty("Gunnery_2")) then
    pilot:SetPerk("Gunnery_2");
  end;
  if not(pilot:HasProperty("Gunnery_3")) then
    pilot:SetPerk("Gunnery_3");
  end;
  if not(pilot:HasProperty("Criticals_1")) then
    pilot:SetPerk("Criticals_1");
  end;
  if not(pilot:HasProperty("Missiles_Rockets")) then
    pilot:SetPerk("Missiles_Rockets");
  end;
  if not(pilot:HasProperty("Missiles_2")) then
    pilot:SetPerk("Missiles_2");
  end;
  if not(pilot:HasProperty("Missiles_3")) then
    pilot:SetPerk("Missiles_3");
  end;
  if not(pilot:HasProperty("Missiles_4")) then
    pilot:SetPerk("Missiles_4");
  end;
  if not(pilot:HasProperty("Rockets_1")) then
    pilot:SetPerk("Rockets_1");
  end;
  if not(pilot:HasProperty("Rockets_2")) then
    pilot:SetPerk("Rockets_2");
  end;
  if not(pilot:HasProperty("missile_salvo_1")) then
    pilot:SetPerk("missile_salvo_1");
  end;
  if not(pilot:HasProperty("missile_salvo_2")) then
    pilot:SetPerk("missile_salvo_2");
  end;
  if not(pilot:HasProperty("missile_salvo_3")) then
    pilot:SetPerk("missile_salvo_3");
  end;
  if not(pilot:HasProperty("missile_salvo_4")) then
    pilot:SetPerk("missile_salvo_4");
  end;
  if not(pilot:HasProperty("weak_spot_1")) then
    pilot:SetPerk("weak_spot_1");
  end;
  if not(pilot:HasProperty("weak_spot_2")) then
    pilot:SetPerk("weak_spot_2");
  end;
  if not(pilot:HasProperty("weak_spot_3")) then
    pilot:SetPerk("weak_spot_3");
  end;
  if not(pilot:HasProperty("Elite")) then
    pilot:SetPerk("Elite");
  end;
  if not(pilot:HasProperty("Systems_1")) then
    pilot:SetPerk("Systems_1");
  end;
  if not(pilot:HasProperty("Systems_2")) then
    pilot:SetPerk("Systems_2");
  end;
  if not(pilot:HasProperty("Systems_3")) then
    pilot:SetPerk("Systems_3");
  end;
  if not(pilot:HasProperty("Missile_Range")) then
    pilot:SetPerk("Missile_Range");
  end;
  if not(pilot:HasProperty("Countermeasures")) then
    pilot:SetPerk("Countermeasures");
  end;
  if not(pilot:HasProperty("Shields_Op")) then
    pilot:SetPerk("Shields_Op");
  end;
  if not(pilot:HasProperty("Repairman")) then
    pilot:SetPerk("Repairman");
  end;
  if not(pilot:HasProperty("Engine_Op")) then
    pilot:SetPerk("Engine_Op");
  end;
  if not(pilot:HasProperty("Fearless")) then
    pilot:SetPerk("Fearless");
  end;
end;


--info:top=510,left=720,allvis=0;
function Uel4_To_Uber(pilot)
  if not(pilot:HasProperty("Piloting_1")) then
    pilot:SetPerk("Piloting_1");
  end;
  if not(pilot:HasProperty("Piloting_2")) then
    pilot:SetPerk("Piloting_2");
  end;
  if not(pilot:HasProperty("Piloting_3")) then
    pilot:SetPerk("Piloting_3");
  end;
  if not(pilot:HasProperty("Pilot_1")) then
    pilot:SetPerk("Pilot_1");
  end;
  if not(pilot:HasProperty("Pilot_2")) then
    pilot:SetPerk("Pilot_2");
  end;
  if not(pilot:HasProperty("Pilot_3")) then
    pilot:SetPerk("Pilot_3");
  end;
  if not(pilot:HasProperty("Pilot_4")) then
    pilot:SetPerk("Pilot_4");
  end;
  if not(pilot:HasProperty("Gunnery_1")) then
    pilot:SetPerk("Gunnery_1");
  end;
  if not(pilot:HasProperty("Gunnery_2")) then
    pilot:SetPerk("Gunnery_2");
  end;
  if not(pilot:HasProperty("Gunnery_3")) then
    pilot:SetPerk("Gunnery_3");
  end;
  if not(pilot:HasProperty("Missiles_Rockets")) then
    pilot:SetPerk("Missiles_Rockets");
  end;
  if not(pilot:HasProperty("Missiles_2")) then
    pilot:SetPerk("Missiles_2");
  end;
  if not(pilot:HasProperty("Missiles_3")) then
    pilot:SetPerk("Missiles_3");
  end;
  if not(pilot:HasProperty("Elite")) then
    pilot:SetPerk("Elite");
  end;
  if not(pilot:HasProperty("hack_ship_1")) then
    pilot:SetPerk("hack_ship_1");
  end;
  if not(pilot:HasProperty("hack_ship_2")) then
    pilot:SetPerk("hack_ship_2");
  end;
  if not(pilot:HasProperty("hack_ship_3")) then
    pilot:SetPerk("hack_ship_3");
  end;
  if not(pilot:HasProperty("Systems_1")) then
    pilot:SetPerk("Systems_1");
  end;
  if not(pilot:HasProperty("Systems_2")) then
    pilot:SetPerk("Systems_2");
  end;
  if not(pilot:HasProperty("Systems_3")) then
    pilot:SetPerk("Systems_3");
  end;
  if not(pilot:HasProperty("Systems_4")) then
    pilot:SetPerk("Systems_4");
  end;
  if not(pilot:HasProperty("polarization_1")) then
    pilot:SetPerk("polarization_1");
  end;
  if not(pilot:HasProperty("polarization_2")) then
    pilot:SetPerk("polarization_2");
  end;
  if not(pilot:HasProperty("polarization_3")) then
    pilot:SetPerk("polarization_3");
  end;
  if not(pilot:HasProperty("polarization_4")) then
    pilot:SetPerk("polarization_4");
  end;
  if not(pilot:HasProperty("Countermeasures")) then
    pilot:SetPerk("Countermeasures");
  end;
  if not(pilot:HasProperty("Countermeasures_Exp")) then
    pilot:SetPerk("Countermeasures_Exp");
  end;
  if not(pilot:HasProperty("Shields_Op")) then
    pilot:SetPerk("Shields_Op");
  end;
  if not(pilot:HasProperty("Shields_Exp")) then
    pilot:SetPerk("Shields_Exp");
  end;
  if not(pilot:HasProperty("Repairman")) then
    pilot:SetPerk("Repairman");
  end;
  if not(pilot:HasProperty("Repairman_Exp")) then
    pilot:SetPerk("Repairman_Exp");
  end;
  if not(pilot:HasProperty("Engine_Op")) then
    pilot:SetPerk("Engine_Op");
  end;
  if not(pilot:HasProperty("Engine_Exp")) then
    pilot:SetPerk("Engine_Exp");
  end;
  if not(pilot:HasProperty("Fearless")) then
    pilot:SetPerk("Fearless");
  end;
end;


--info:top=160,left=820,allvis=0;
function NewUelCopyFlight(group, sign, location, type, power, orient)
  local pilotTable = {"Uel2", "Uel3", "Uel4"};
  local shipTable = {{"Wyvern_ino2", "Dragon_ino1", "Gunslinger_ino1"},
                     {"Hrimturs_ino2", "Hrimturs_ino2", "Hrimturs_ino1"},
                     {"Trident_ino3", "Trident_ino2", "Trident_ino1"}};
  local num1 = RAND(3) + 1;
  local num2 = RAND(3) + 1;
  local pname = pilotTable[num1];
  local sname = shipTable[num1][num2];
  local flight = NewFlight(group, sign, sname, pname, location, orient);
  local ship = NewShip(sign.."_2", sname, pname, location+Vector3(5, 5, 0), orient);
  flight:AddShip(ship);
  local pilot = getglobal("pilot_"..sign.."_1");
  if (num1==1) then
    Uel2_To_Uber(pilot);
  elseif (num1==2) then
    Uel3_To_Uber(pilot);
  else
    Uel4_To_Uber(pilot);
  end;
  pilot = getglobal("pilot_"..sign.."_2");
  if (num1==1) then
    Uel2_To_Uber(pilot);
  elseif (num1==2) then
    Uel3_To_Uber(pilot);
  else
    Uel4_To_Uber(pilot);
  end;
  return flight;
end;


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

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


--info:top=80,left=570,allvis=0;
function ACTION_LEAVELOCATION()

  return TRUE;
end;


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

  return TRUE;
end;
