--------------------------------------------------------------------------------
---- Check 6 and remove  -------------------------------------------------------
--------------------------------------------------------------------------------

SpeakerGW = CreatePilot("GoblinWizard");

function count_pilots()
  local q_pilots = 0;
  if (pilot_Hero) then q_pilots = q_pilots + 1; end;
  if (pilot_Lastochka) then q_pilots = q_pilots + 1; end;
  if (pilot_Lastochka2) then q_pilots = q_pilots + 1; end;
  if (pilot_Sedoy) then q_pilots = q_pilots + 1; end;
  if (pilot_Alex) then q_pilots = q_pilots + 1; end;
  if (pilot_Validol) then q_pilots = q_pilots + 1; end;
  if (pilot_Yana) then q_pilots = q_pilots + 1; end;
  if (pilot_Viper) then q_pilots = q_pilots + 1; end;
  if (pilot_Kalem) then q_pilots = q_pilots + 1; end;
  if (pilot_Aia) then q_pilots = q_pilots + 1; end;
  if (pilot_Alexandra) then q_pilots = q_pilots + 1; end;
  if (pilot_Cleric) then q_pilots = q_pilots + 1; end;
  if (pilot_Uel) then q_pilots = q_pilots + 1; end;
  if (pilot_Uel2) then q_pilots = q_pilots + 1; end;
  if (pilot_Uel3) then q_pilots = q_pilots + 1; end;
  if (pilot_Uel4) then q_pilots = q_pilots + 1; end;
  if (pilot_Tramp) then q_pilots = q_pilots + 1; end;
  if (pilot_Natali) then q_pilots = q_pilots + 1; end;
  if (pilot_Blade) then q_pilots = q_pilots + 1; end;
  if (pilot_alex1_1) then q_pilots = q_pilots + 1; end;
  if (pilot_alex2_1) then q_pilots = q_pilots + 1; end;
  if (pilot_Alisa) then q_pilots = q_pilots + 1; end;
  if (pilot_Che) then q_pilots = q_pilots + 1; end;
  if (pilot_Josef) then q_pilots = q_pilots + 1; end;
  if (pilot_Corsair) then q_pilots = q_pilots + 1; end;
  if (pilot_Heretic) then q_pilots = q_pilots + 1; end;
  if (pilot_m10_Heretic) then q_pilots = q_pilots + 1; end;
  if (pilot_Phantom) then q_pilots = q_pilots + 1; end;
  if (pilot_m10_Phantom) then q_pilots = q_pilots + 1; end;
  if (pilot_El) then q_pilots = q_pilots + 1; end;
  if (pilot_Ace) then q_pilots = q_pilots + 1; end;
  if (pilot_Astra) then q_pilots = q_pilots + 1; end;
  if (pilot_Bavard) then q_pilots = q_pilots + 1; end;
  if (pilot_Joker) then q_pilots = q_pilots + 1; end;
  return q_pilots
end;

function choose_pilot()
  StartTradeDialog("Dialog_choose_any_pilot","Dialog_choose_any_pilot_Init");
end;

function Dialog_choose_any_pilot_Init()
local tab_pilots_dialog = {
	{pilot_El,"ans01"},
	{pilot_Ace,"ans02"},
	{pilot_Astra,"ans03"},
	{pilot_Bavard,"ans04"},
	{pilot_Joker,"ans05"}};

  for k, x in tab_pilots_dialog do
    if (not(x[1])) then
		  HideAnswer(x[2]);
	  end;
  end;
end;

--("Dialog_choose_any_pilot") 1. El -> pick_El(), 2. Ace -> pick_Ace(), ...

function GW_Message()
  SpeakerGW:Message("#L_sys_have_to_dock", 2);
  trig_NoDock:Activate();
end;

function pick_El()
  pick_pilot(pilot_El);
end;

function pick_Ace()
  pick_pilot(pilot_Ace);
end;

function pick_Astra()
  pick_pilot(pilot_Astra);
end;

function pick_Bavard()
  pick_pilot(pilot_Bavard);
end;

function pick_Joker()
  pick_pilot(pilot_Joker);
end;

function pick_pilot(pilot_name)
local tab_pilots_remove = {
	{pilot_El,"remove_El"},
	{pilot_Ace,"remove_Ace"},
	{pilot_Astra,"remove_Astra"},
	{pilot_Bavard,"remove_Bavard"},
	{pilot_Joker,"remove_Joker"}};

  for k, x in tab_pilots_remove do
    if (x[1] == pilot_name) then
		  r_pilot = x[2];
	  end;
  end;
  
  SetNormalTimeMode();
  if (pilot_name:IsBasePilot()) then
    RemoveBaseDriver();
  end;
  trig_NoDock = NewTrigger("timer", TrueCondition, GW_Message, 1);
  trig_PilotInBase = NewTrigger("base", TrueCondition, r_pilot, pilot_name);
end;

function remove_El()
  remove_pilot(pilot_El);
end;

function remove_Ace()
  remove_pilot(pilot_Ace);
end;

function remove_Astra()
  remove_pilot(pilot_Astra);
end;

function remove_Bavard()
  remove_pilot(pilot_Bavard);
end;

function remove_Joker()
  remove_pilot(pilot_Joker);
end;

function remove_pilot(pilot_name)
local tab_save_perks = {
	{pilot_El,"perks_El"},
	{pilot_Ace,"perks_Ace"},
	{pilot_Astra,"perks_Astra"},
	{pilot_Bavard,"perks_Bavard"},
	{pilot_Joker,"perks_Joker"}};

  for k, x in tab_save_perks do
    if (x[1] == pilot_name) then
		  perks_pilot = x[2];
	  end;
  end;

  SetNormalTimeMode();
  trig_NoDock:Activate(FALSE);
  SavePerks(pilot_name, perks_pilot);
  local Player_Team = CreateTeam(PLAYER_TEAM);
  Player_Team:RemovePilot(pilot_name);
  pilot_name:Kill();
  if (pilot_name == pilot_El) then pilot_El = NIL;
    elseif (pilot_name == pilot_Ace) then pilot_Ace = NIL;
    elseif (pilot_name == pilot_Astra) then pilot_Astra = NIL;
    elseif (pilot_name == pilot_Bavard) then pilot_Bavard = NIL;
    elseif (pilot_name == pilot_Joker) then pilot_Joker = NIL;
  end;
  SpeakerGW:Message("#L_pilot_dismissed", 5);
  Timer_Seq(5, count_or_go_on);
end;


--------------------------------------------------------------------------------
---- Buy MOTHERSHIP section ----------------------------------------------------
--------------------------------------------------------------------------------

function DialogR_buy_GW_Alien_Dreadnought_0()
	_buy_ms_GW("Alien_Dreadnought_0");
end;

function DialogR_buy_GW_Alien_Frigate_0()
	_buy_ms_GW("Alien_Frigate_0");
end;

function DialogR_buy_GW_Chimera()
	_buy_ms_GW("Chimera");
end;

function DialogR_buy_GW_Mega_Chimera()
  _buy_ms_GW("Mega_Chimera");
end;

function DialogR_buy_GW_BattleshipImp_GK0()
  _buy_ms_GW("BattleshipImp_GK0");
end;

function DialogR_buy_GW_Liner()
  _buy_ms_GW("Liner_gw");
end;

function DialogR_buy_GW_Mothership()
  _buy_ms_GW("Mothership");
end;

function DialogR_buy_GW_Mothership_corporate()
  _buy_ms_GW("Mothership_corporate");
end;

function DialogR_buy_GW_Mothership_empire()
  _buy_ms_GW("Mothership_empire");
end;

function DialogR_buy_GW_Mothership_KFNI()
  _buy_ms_GW("Mothership_KFNI");
end;

function DialogR_buy_GW_Mothership_Invincible_1()
  _buy_ms_GW("Invincible_1");
end;

function DialogR_buy_GW_Mothership_Lion()
  _buy_ms_GW("Mothership_Lion");
end;

function DialogR_buy_GW_Mothership_old()
  _buy_ms_GW("Mothership_old");
end;

function DialogR_buy_GW_Mothership_uel()
  _buy_ms_GW("Mothership_uel");
end;

function DialogR_buy_GW_P_transport()
  _buy_ms_GW("P_transport");
end;

function DialogR_buy_GW_Starhammer_0()
  _buy_ms_GW("Starhammer_0");
end;

function DialogR_buy_GW_StoneArrow0()
  _buy_ms_GW("StoneArrow0");
end;

function DialogR_buy_GW_AngorFrigate()
  _buy_ms_GW("AngorFrigate");
end;

function DialogR_fin()
end;

function _buy_ms_GW(nameMS)
  local tab_MS = {
	{"Alien_Dreadnought_0",100},
  {"Alien_Frigate_0",100},
	{"Mega_Chimera",100},
	{"BattleshipImp_GK0",100},
	{"Chimera",100},
	{"Liner_gw",600000},
	{"Mothership",200000},
	{"Mothership_corporate",1000000},
	{"Mothership_empire",1000000},
	{"Mothership_KFNI",200000},
	{"Invincible_1",1200000},
	{"Mothership_Lion",1200000},
	{"Mothership_old",100000},
	{"Mothership_uel",1200000},
	{"P_transport",100},
	{"Starhammer_0",1500000},
	{"StoneArrow0",100},
	{"AngorFrigate",100}
	};
	
	local costMS = 0;
	for k, x in tab_MS do
		if (x[1] == nameMS) then
      costMS = x[2];
		end;
	end;
  if (costMS == 0) then return FALSE;
  end;
  
  local cash = GetPlayerCredits();
  if (cash >= costMS) then
  
    new_mothership = CreateCarcass(nameMS, mothership:GetPosition() + Vector3(0, 30, 0), mothership:GetVectorOrientation());
    mothership_old = mothership;
    mothership = SetPlayerMotherShip(new_mothership);
 
    if (GetCurrentLocation() == "el_ariash") then
      PortalTrigger_PORTAL_L:SetObject(mothership);
      PortalTrigger_PORTAL_U:SetObject(mothership);
      PortalTrigger_PORTAL_D:SetObject(mothership);
    else
      if (PORTAL_R) then PortalTrigger_PORTAL_R:SetObject(mothership); end;
      if (PORTAL_L) then PortalTrigger_PORTAL_L:SetObject(mothership); end;
      if (PORTAL_U) then PortalTrigger_PORTAL_U:SetObject(mothership); end;
      if (PORTAL_D) then PortalTrigger_PORTAL_D:SetObject(mothership); end;
    end;
    
    if (TRADE_STATION) then CreateTradeStationDocking(TRADE_STATION,mothership); end;
    if (TRADE) then CreateTradeStationDocking(TRADE,mothership); end;
    
    CreateRepairStationDocking(STO_Station, mothership, tonumber(GetQuestLabel("m_st_radius")), tonumber(GetQuestLabel("m_st_type")));
--    trig_m_st_activate = NewTrigger("inside", TrueCondition, m_st_activate, mothership, STO_Station:GetPosition(), tonumber(GetQuestLabel("m_st_radius")));

    PortalsActivate_Action();
    GetShipName(mothership);
    SubPlayerCredits(costMS);
    FocusOn({mothership_old, mothership}, mothership:GetVectorOrientation() + Vector3(0, 0.9, 0), 60); 
    OutputToScreenLog("#UI_MS_buy_ok",7);
  else	
    OutputToScreenLog("#UI_MS_buy_fail",7);
  end;
end;

--function m_st_activate()
--  CreateRepairStationDocking(STO_Station, mothership, tonumber(GetQuestLabel("m_st_radius")), tonumber(GetQuestLabel("m_st_type")));
--  OutputToScreenLog("Maintenance Station activated!",10);
--end;

--------------------------------------------------------------------------------
---- Buy FIGHTER section ---------------------------------------------------
--------------------------------------------------------------------------------

function DialogR_buy_Gunslinger_mk2_black0()
  buy_fig("Gunslinger_mk2_black0");
end;

function DialogR_buy_Hrimturs_mk2_black0()
  buy_fig("Hrimturs_mk2_black0");
end;

function DialogR_buy_Trident_mk2_black0()
  buy_fig("Trident_mk2_black0");
end;

function DialogR_buy_Raptor_mk2_black0()
  buy_fig("Raptor_mk2_black0");
end;

function DialogR_buy_Wyvern_pl0()
  buy_fig("Wyvern_pl0");
end;

function DialogR_buy_Wyvern_mk2_pl0()
  buy_fig("Wyvern_mk2_pl0");
end;

function DialogR_buy_Dragon_pl0()
  buy_fig("Dragon_pl0");
end;

function DialogR_buy_Bastard_0()
  buy_fig("Bastard_0");
end;

function DialogR_buy_Mataris_0()
  buy_fig("Mataris_0");
end;

function DialogR_buy_Raven_0()
  buy_fig("Raven_0");
end;

function DialogR_buy_Scolm_0()
  buy_fig("Scolm_0");
end;

function DialogR_buy_AngorFighter()
  buy_fig("AngorFighter");
end;

function DialogR_buy_AngorFighter1()
  buy_fig("AngorFighter1");
end;

function DialogR_buy_AngorFighter2()
  buy_fig("AngorFighter2");
end;

function DialogR_buy_EvilEye_mk2_pl0()
  buy_fig("EvilEye_mk2_pl0");
end;

function DialogR_buy_Butcher_pl0_gw()
  buy_fig("Butcher_pl0_gw");
end;

function DialogR_buy_Cavalier_0_gw()
  buy_fig("Cavalier_0_gw");
end;

function buy_fig(nameFIG)
  local tab_FIG = {
	{"Gunslinger_mk2_black0",280000},
  {"Hrimturs_mk2_black0",240000},
	{"Trident_mk2_black0",250000},
	{"Raptor_mk2_black0",54000},
	{"Wyvern_pl0",280000},
	{"Wyvern_mk2_pl0",310000},
	{"Dragon_pl0",250000},
	{"Bastard_0",300000},
	{"Mataris_0",300000},
	{"Raven_0",280000},
	{"Scolm_0",290000},
	{"AngorFighter2",50000},
	{"AngorFighter1",50000},
	{"AngorFighter",50000},
	{"EvilEye_mk2_pl0",110000},
	{"Butcher_pl0_gw",300000},
	{"Cavalier_0_gw",190000}
	};
	
	local costFIG = 0;
	for k, x in tab_FIG do
		if (x[1] == nameFIG) then
      costFIG = x[2];
		end;
	end;
  if (costFIG == 0) then return FALSE;
  end;
  
  local cash = GetPlayerCredits();
  if (cash >= costFIG) then
  	mothership:AddShipToInventory(nameFIG, 1);
    SubPlayerCredits(costFIG);
    OutputToScreenLog("#UI_FIG_buy_ok",7);
  else	
    OutputToScreenLog("#UI_buy_fail",7);
  end;
end;


--------------------------------------------------------------------------------
---- Buy MS EQUIPMENT section --------------------------------------------------
--------------------------------------------------------------------------------

function buy_THGK3()
  buy_ms_eq("THGK3");
end;

function buy_TLGK3()
  buy_ms_eq("TLGK3");
end;

function buy_TPGK3()
  buy_ms_eq("TPGK3");
end;

function buy_TRGK3()
  buy_ms_eq("TRGK3");
end;


function buy_ms_eq(eq_name)
  local tab_ms_eq = {
	{"THGK3",350000},
  {"TLGK3",350000},
  {"TPGK3",350000},
  {"TRGK3",350000}
	};
	
	local cost = 0;
	for k, x in tab_ms_eq do
		if (x[1] == eq_name) then
      cost = x[2];
		end;
	end;
  if (cost == 0) then return FALSE;
  end;
  
  local cash = GetPlayerCredits();
  if (cash >= cost) then
  	mothership:AddModuleToInventory(eq_name, 1);
    SubPlayerCredits(cost);
    OutputToScreenLog("#UI_item_buy_ok",7);
  else	
    OutputToScreenLog("#UI_buy_fail",7);
  end;
end;


--------------------------------------------------------------------------------
---- Buy/Dismiss PILOT section -------------------------------------------------
--------------------------------------------------------------------------------

function OnStationStartGW()
  Timer_Seq(0.1, OnStationStartGW_1);
end;

function OnStationStartGW_1()
  StartTradeDialog("DialogGW","OnStationStartGW_Init");
end;

function OnStationStartGW_Init()
local tab_pilots_dialog = {
	{pilot_El,"ans_CANTEEN_01","ans_CANTEEN_06"},
	{pilot_Ace,"ans_CANTEEN_03","ans_CANTEEN_08"},
	{pilot_Astra,"ans_CANTEEN_02","ans_CANTEEN_07"},
	{pilot_Bavard,"ans_CANTEEN_05","ans_CANTEEN_10"},
	{pilot_Joker,"ans_CANTEEN_04","ans_CANTEEN_09"}};

  for k, x in tab_pilots_dialog do
    if (x[1]) then
		  HideAnswer(x[2]);
	  else
		  HideAnswer(x[3]);
	  end;
  end;
  
  if (tonumber(GetQuestLabel("BasePilot_BKT")) == 1) then
    HideAnswer("ans_BKT");
  else
    HideAnswer("ans_teach_BKT");
  end;
end;

function dismiss_El()
  dismiss_pilot(pilot_El);
end;

function dismiss_Ace()
  dismiss_pilot(pilot_Ace);
end;

function dismiss_Astra()
  dismiss_pilot(pilot_Astra);
end;

function dismiss_Bavard()
  dismiss_pilot(pilot_Bavard);
end;

function dismiss_Joker()
  dismiss_pilot(pilot_Joker);
end;

function dismiss_pilot(pilot_name)
local tab_save_perks = {
	{pilot_El,"perks_El"},
	{pilot_Ace,"perks_Ace"},
	{pilot_Astra,"perks_Astra"},
	{pilot_Bavard,"perks_Bavard"},
	{pilot_Joker,"perks_Joker"}};

  for k, x in tab_save_perks do
    if (x[1] == pilot_name) then
		  perks_pilot = x[2];
	  end;
  end;

  SavePerks(pilot_name, perks_pilot);
  local Player_Team = CreateTeam(PLAYER_TEAM);
  Player_Team:RemovePilot(pilot_name);
  pilot_name:Kill();
  if (pilot_name == pilot_El) then pilot_El = NIL;
    elseif (pilot_name == pilot_Ace) then pilot_Ace = NIL;
    elseif (pilot_name == pilot_Astra) then pilot_Astra = NIL;
    elseif (pilot_name == pilot_Bavard) then pilot_Bavard = NIL;
    elseif (pilot_name == pilot_Joker) then pilot_Joker = NIL;
  end;
  OutputToScreenLog("Pilot dismissed!",7);
end;


function hire_El()
  local cost_El = 50000;
  local cash = GetPlayerCredits();
  if (pilot_El) then
    OutputToScreenLog("Al is already in your team!",10);
  elseif (count_pilots() >= 6) then
    OutputToScreenLog("Al can't join you. You already have 6 pilots!",10);
  elseif (cash >= cost_El) then
    pilot_El = CreatePilot("El");
    RestorePerks(pilot_El, "perks_El");
    AddPilotToPlayer(pilot_El);
    SubPlayerCredits(cost_El);
    OutputToScreenLog("#UI_hire_El_ok",7);
  else	
    OutputToScreenLog("#UI_buy_fail",7);
  end;
end;

function hire_Astra()
  if (pilot_Astra) then
    OutputToScreenLog("Astra is already in your team!",10);
  elseif (count_pilots() >= 6) then
    OutputToScreenLog("Astra can't join you. You already have 6 pilots!",10);
  else
    local cost_Astra = 50000;
    local cash = GetPlayerCredits();
    if (cash >= cost_Astra) then
      pilot_Astra = CreatePilot("Astra");
      RestorePerks(pilot_Astra, "perks_Astra");
      AddPilotToPlayer(pilot_Astra);
      SubPlayerCredits(cost_Astra);
      OutputToScreenLog("#UI_hire_Astra_ok",7);
    else	
      OutputToScreenLog("#UI_buy_fail",7);
    end;
  end;
end;

function hire_Ace()
  if (pilot_Ace) then
    OutputToScreenLog("Ace is already in your team!",10);
  elseif (count_pilots() >= 6) then
    OutputToScreenLog("Ace can't join you. You already have 6 pilots!",10);
  else
    local cost_Ace = 50000;
    local cash = GetPlayerCredits();
    if (cash >= cost_Ace) then
      pilot_Ace = CreatePilot("Ace");
      RestorePerks(pilot_Ace, "perks_Ace");
      AddPilotToPlayer(pilot_Ace);
      SubPlayerCredits(cost_Ace);
      OutputToScreenLog("#UI_hire_Ace_ok",7);
    else	
      OutputToScreenLog("#UI_buy_fail",7);
    end;
  end;
end;

function hire_Joker()
  if (pilot_Joker) then
    OutputToScreenLog("Joker is already in your team!",10);
  elseif (count_pilots() >= 6) then
    OutputToScreenLog("Joker can't join you. You already have 6 pilots!",10);
  else
    local cost_Joker = 50000;
    local cash = GetPlayerCredits();
    if (cash >= cost_Joker) then
      pilot_Joker = CreatePilot("Joker");
      RestorePerks(pilot_Joker, "perks_Joker");
      AddPilotToPlayer(pilot_Joker);
      SubPlayerCredits(cost_Joker);
      OutputToScreenLog("#UI_hire_Joker_ok",7);
    else	
      OutputToScreenLog("#UI_buy_fail",7);
    end;
  end;
end;

function hire_Bavard()
  if (pilot_Bavard) then
    OutputToScreenLog("Baward is already in your team!",10);
  elseif (count_pilots() >= 6) then
    OutputToScreenLog("Baward can't join you. You already have 6 pilots!",10);
  else
    local cost_Bavard = 50000;
    local cash = GetPlayerCredits();
    if (cash >= cost_Bavard) then
      pilot_Bavard = CreatePilot("Bavard");
      RestorePerks(pilot_Bavard, "perks_Bavard");
      AddPilotToPlayer(pilot_Bavard);
      SubPlayerCredits(cost_Bavard);
      OutputToScreenLog("#UI_hire_Bavard_ok",7);
    else	
      OutputToScreenLog("#UI_buy_fail",7);
    end;
  end;
end;

--function hire_Bavard()
--  Hire_Pilot("Bavard");
--end;
--
--function hire_Joker()
--  Hire_Pilot("Joker");
--end;
--
--function hire_Ace()
--  Hire_Pilot("Ace");
--end;
--
--function hire_Astra()
--  Hire_Pilot("Astra");
--end;
--
--function hire_El()
--  Hire_Pilot("El");
--end;
--
--function Hire_Pilot(name_pilot)
--  local tab_pilots = {
--    {"El",100,"perks_El",El},
--    {"Ace",100,"perks_Ace",Ace},
--    {"Joker",100,"perks_Joker",Joker},
--    {"Bavard",100,"perks_Bavard",Bavard},
--    {"Astra",100,"perks_Astra",Astra}
--    };
--	
--	local cost_pilot = 0;
--	for i, sh in tab_pilots do
--		if (sh[1] == name_pilot) then
--      cost_pilot = sh[2];
--      perk_pilot = sh[3];
--      id_pilot = sh[4];
--		end;
--	end;
--  if (cost_pilot == 0) then return FALSE;
--  end;
--  
--  local cash = GetPlayerCredits();
--  if (cash >= cost_pilot) then
--    pilot = CreatePilot(name_pilot);
--    RestorePerks(pilot, perk_pilot);
--    AddPilotToPlayer(pilot);
--    SubPlayerCredits(cost_pilot);
--    OutputToScreenLog("#UI_hire_ok",7);
--  else	
--    OutputToScreenLog("#UI_buy_fail",7);
--  end;
--end;

--------------------------------------------------------------------------------
---- Bryna & KT ----------------------------------------------------------------
--------------------------------------------------------------------------------

function OnStationStartBKT_perks()
  Timer_Seq(0.1, OnStationStartBKT_perks_1);
end;

function OnStationStartBKT_perks_1()
  StartTradeDialog("DialogBKT_perks","OnStationStartBKT_perks_Init");
end;

function OnStationStartBKT_perks_Init()
  local tab_BKT_perks_dialog = {
  	{"Piloting_1",5,"Piloting_1","Piloting_1","Piloting_1","ans_Piloting_1"},
  	{"Piloting_2",15,"Piloting_1","Piloting_1","Piloting_1","ans_Piloting_2"},
  	{"Piloting_3",35,"Piloting_2","Piloting_2","Piloting_2","ans_Piloting_3"},
  	{"Piloting_4",75,"Piloting_3","Piloting_3","Piloting_3","ans_Piloting_4"},
  	{"Piloting_5",150,"Piloting_4","Piloting_4","Piloting_4","ans_Piloting_5"},
  	{"Gunnery_1",5,"Piloting_1","Piloting_1","Piloting_1","ans_Gunnery_1"},
  	{"Gunnery_2",15,"Gunnery_1","Gunnery_1","Gunnery_1","ans_Gunnery_2"},
  	{"Gunnery_3",35,"Gunnery_2","Gunnery_2","Gunnery_2","ans_Gunnery_3"},
  	{"Gunnery_4",70,"Gunnery_3","Gunnery_3","Gunnery_3","ans_Gunnery_4"},
  	{"Gunnery_5",150,"Gunnery_4","Gunnery_4","Gunnery_4","ans_Gunnery_5"},
  	{"Criticals_1",50,"Gunnery_3","Gunnery_3","Gunnery_3","ans_Criticals_1"},
  	{"Criticals_2",100,"Criticals_1","Criticals_1","Criticals_1","ans_Criticals_2"},
  	{"Criticals_3",200,"Criticals_2","Criticals_2","Criticals_2","ans_Criticals_3"},
  	{"Hard_to_Kill",100,"Piloting_4","Piloting_4","Piloting_4","ans_Hard_to_Kill"},
    {"Elite",250,"Piloting_5","Gunnery_5","Criticals_3","ans_Elite"},
  	{"Systems_1",15,"Piloting_1","Piloting_1","Piloting_1","ans_Systems_1"},
  	{"Systems_2",50,"Learner_Exp","Learner_Exp","Learner_Exp","ans_Systems_2"},
  	{"Systems_3",100,"Systems_2","Systems_2","Systems_2","ans_Systems_3"},
  	{"Systems_4",150,"Systems_3","Systems_3","Systems_3","ans_Systems_4"},
  	{"Learner",35,"Systems_1","Systems_1","Systems_1","ans_Learner"},
  	{"Learner_Exp",75,"Learner","Learner","Learner","ans_Learner_Exp"},
  	{"Countermeasures",35,"Systems_1","Systems_1","Systems_1","ans_Countermeasures"},
  	{"Countermeasures_Exp",75,"Countermeasures","Countermeasures","Countermeasures","ans_Countermeasures_Exp"},
  	{"Shields_Op",35,"Systems_1","Systems_1","Systems_1","ans_Shields_Op"},
  	{"Shields_Exp",75,"Shields_Op","Shields_Op","Shields_Op","ans_Shields_Exp"},
  	{"Engine_Op",35,"Systems_1","Systems_1","Systems_1","ans_Engine_Op"},
  	{"Engine_Exp",75,"Engine_Op","Engine_Op","Engine_Op","ans_Engine_Exp"},
    {"Repairman",30,"Systems_1","Systems_1","Systems_1","ans_Repairman"},
    {"Repairman_Exp",70,"Repairman","Repairman","Repairman","ans_Repairman_Exp"},
    {"Tech_Adaptation",100,"Learner_Exp","Learner_Exp","Learner_Exp","ans_Tech_Adaptation"},
    {"Tech_Adaptation_Alien",150,"Tech_Adaptation","Tech_Adaptation","Tech_Adaptation","ans_Tech_Adaptation_Alien"},
    {"Tech_Adaptation_Prec",200,"Tech_Adaptation_Alien","Tech_Adaptation_Alien","Tech_Adaptation_Alien","ans_Tech_Adaptation_Prec"},
  	{"Gun_Range",100,"Learner_Exp","Learner_Exp","Learner_Exp","ans_Gun_Range"}};
  	
  pilot_BasePilot_BKT = GetPilot("BasePilot_BKT");

  for k, x in tab_BKT_perks_dialog do
    if (pilot_BasePilot_BKT:HasProperty(x[1])) or not (pilot_BasePilot_BKT:HasProperty(x[3])) or not (pilot_BasePilot_BKT:HasProperty(x[4])) or not (pilot_BasePilot_BKT:HasProperty(x[5])) then
		  HideAnswer(x[6]);
	  end;
  end;
end;

function buy_Piloting_2()
  buy_perk("Piloting_2");
end;

function buy_Piloting_3()
  buy_perk("Piloting_3");
end;

function buy_Piloting_4()
  buy_perk("Piloting_4");
end;

function buy_Piloting_5()
  buy_perk("Piloting_5");
end;

function buy_Gunnery_1()
  buy_perk("Gunnery_1");
end;

function buy_Gunnery_2()
  buy_perk("Gunnery_2");
end;

function buy_Gunnery_3()
  buy_perk("Gunnery_3");
end;

function buy_Gunnery_4()
  buy_perk("Gunnery_4");
end;

function buy_Gunnery_5()
  buy_perk("Gunnery_5");
end;

function buy_Criticals_1()
  buy_perk("Criticals_1");
end;

function buy_Criticals_2()
  buy_perk("Criticals_2");
end;

function buy_Criticals_3()
  buy_perk("Criticals_3");
end;

function buy_Hard_to_Kill()
  buy_perk("Hard_to_Kill");
end;

function buy_Elite()
  buy_perk("Elite");
end;

function buy_Systems_1()
  buy_perk("Systems_1");
end;

function buy_Systems_2()
  buy_perk("Systems_2");
end;

function buy_Systems_3()
  buy_perk("Systems_3");
end;

function buy_Systems_4()
  buy_perk("Systems_4");
end;

function buy_Learner()
  buy_perk("Learner");
end;

function buy_Learner_Exp()
  buy_perk("Learner_Exp");
end;

function buy_Countermeasures()
  buy_perk("Countermeasures");
end;

function buy_Countermeasures_Exp()
  buy_perk("Countermeasures_Exp");
end;

function buy_Shields_Op()
  buy_perk("Shields_Op");
end;

function buy_Shields_Exp()
  buy_perk("Shields_Exp");
end;

function buy_Engine_Op()
  buy_perk("Engine_Op");
end;

function buy_Engine_Exp()
  buy_perk("Engine_Exp");
end;

function buy_Repairman()
  buy_perk("Repairman");
end;

function buy_Repairman_Exp()
  buy_perk("Repairman_Exp");
end;

function buy_Tech_Adaptation()
  buy_perk("Tech_Adaptation");
end;

function buy_Tech_Adaptation_Alien()
  buy_perk("Tech_Adaptation_Alien");
end;

function buy_Tech_Adaptation_Prec()
  buy_perk("Tech_Adaptation_Prec");
end;

function buy_Gun_Range()
  buy_perk("Gun_Range");
end;

function buy_perk(perk)
  local tab_BKT_perks_cost = {
  	{"Piloting_1",5},
  	{"Piloting_2",15},
  	{"Piloting_3",35},
  	{"Piloting_4",75},
  	{"Piloting_5",150},
  	{"Gunnery_1",5},
  	{"Gunnery_2",15},
  	{"Gunnery_3",35},
  	{"Gunnery_4",70},
  	{"Gunnery_5",150},
  	{"Criticals_1",50},
  	{"Criticals_2",100},
  	{"Criticals_3",200},
  	{"Hard_to_Kill",100},
    {"Elite",250},
  	{"Systems_1",15},
  	{"Systems_2",50},
  	{"Systems_3",100},
  	{"Systems_4",150},
  	{"Learner",35},
  	{"Learner_Exp",75},
  	{"Countermeasures",35},
  	{"Countermeasures_Exp",75},
  	{"Shields_Op",35},
  	{"Shields_Exp",75},
  	{"Engine_Op",35},
  	{"Engine_Exp",75},
    {"Repairman",30},
    {"Repairman_Exp",70},
    {"Tech_Adaptation",100},
    {"Tech_Adaptation_Alien",150},
    {"Tech_Adaptation_Prec",200},
  	{"Gun_Range",100}};

  local cost_perk = 0;
	for i, x in tab_BKT_perks_cost do
		if (x[1] == perk) then
      cost_perk = x[2];
		end;
	end;
  if (cost_perk == 0) then
    return FALSE;
  end;

  pilot_BasePilot_BKT = GetPilot("BasePilot_BKT");
  local points_BKT = pilot_BasePilot_BKT:GetPoints();
  if (points_BKT >= cost_perk) then
    pilot_BasePilot_BKT:SetPerk(perk);
    OutputToScreenLog("Perk added!",7);
    pilot_BasePilot_BKT:SetPoints(points_BKT - cost_perk);
    OutputToScreenLog("Bryna&KT "..pilot_BasePilot_BKT:GetPoints().." skill points now.",7);
  else	
    OutputToScreenLog("Error "..pilot_BasePilot_BKT:GetPoints().." Bryna&KT skill points left!",7);
  end;
end;



function OnStationStartBKT_pilots()
  Timer_Seq(0.1, OnStationStartBKT_pilots_1);
end;

function OnStationStartBKT_pilots_1()
  StartTradeDialog("DialogBKT_pilots","OnStationStartBKT_pilots_Init");
end;

function OnStationStartBKT_pilots_Init()
  local tab_BKT_suck_dialog = {
  	{pilot_Hero,"ans_Hero_1","ans_Hero_10"},
    {pilot_Lastochka,"ans_Lastochka_1","ans_Lastochka_10"},
    {pilot_Lastochka2,"ans_Lastochka2_1","ans_Lastochka2_10"},
    {pilot_Sedoy,"ans_Sedoy_1","ans_Sedoy_10"},
    {pilot_Alex,"ans_Alex_1","ans_Alex_10"},
    {pilot_Validol,"ans_Validol_1","ans_Validol_10"},
    {pilot_Yana,"ans_Yana_1","ans_Yana_10"},
    {pilot_Viper,"ans_Viper_1","ans_Viper_10"},
    {pilot_Kalem,"ans_Kalem_1","ans_Kalem_10"},
    {pilot_Aia,"ans_Aia_1","ans_Aia_10"},
    {pilot_Alexandra,"ans_Alexandra_1","ans_Alexandra_10"},
    {pilot_Cleric,"ans_Cleric_1","ans_Cleric_10"},
    {pilot_Uel,"ans_Uel_1","ans_Uel_10"},
    {pilot_Uel2,"ans_Uel2_1","ans_Uel2_10"},
    {pilot_Uel3,"ans_Uel3_1","ans_Uel3_10"},
    {pilot_Uel4,"ans_Uel4_1","ans_Uel4_10"},
    {pilot_Tramp,"ans_Tramp_1","ans_Tramp_10"},
    {pilot_Natali,"ans_Natali_1","ans_Natali_10"},
    {pilot_Blade,"ans_Blade_1","ans_Blade_10"},
    {pilot_alex1_1,"ans_alex1_1_1","ans_alex1_1_10"},
    {pilot_alex2_1,"ans_alex2_1_1","ans_alex2_1_10"},
    {pilot_El,"ans_El_1","ans_El_10"},
    {pilot_Ace,"ans_Ace_1","ans_Ace_10"},
    {pilot_Astra,"ans_Astra_1","ans_Astra_10"},
    {pilot_Bavard,"ans_Bavard_1","ans_Bavard_10"},
    {pilot_Joker,"ans_Joker_1","ans_Joker_10"},
    
    {pilot_Alisa,"ans_Alisa_1","ans_Alisa_10"},
    {pilot_Che,"ans_Che_1","ans_Che_10"},
    {pilot_Josef,"ans_Josef_1","ans_Josef_10"},
    {pilot_Corsair,"ans_Corsair_1","ans_Corsair_10"},
    {pilot_Heretic,"ans_Heretic_1","ans_Heretic_10"},
    {pilot_m10_Heretic,"ans_m10_Heretic_1","ans_m10_Heretic_10"},
    {pilot_Phantom,"ans_Phantom_1","ans_Phantom_10"},
    {pilot_m10_Phantom,"ans_m10_Phantom_1","ans_m10_Phantom_10"}};
    
    for k, x in tab_BKT_suck_dialog do
      if (not(x[1])) then
        HideAnswer(x[2]);
        HideAnswer(x[3]);
      end;
    end;
end;

function suck_Hero_by_1()
  suck_pilot(pilot_Hero,1);
end;

function suck_Hero_by_10()
  suck_pilot(pilot_Hero,10);
end;

function suck_Lastochka_by_1()
  suck_pilot(pilot_Lastochka,1);
end;

function suck_Lastochka_by_10()
  suck_pilot(pilot_Lastochka,10);
end;

function suck_Lastochka2_by_1()
  suck_pilot(pilot_Lastochka2,1);
end;

function suck_Lastochka2_by_10()
  suck_pilot(pilot_Lastochka2,10);
end;

function suck_Sedoy_by_1()
  suck_pilot(pilot_Sedoy,1);
end;

function suck_Sedoy_by_10()
  suck_pilot(pilot_Sedoy,10);
end;

function suck_Alex_by_1()
  suck_pilot(pilot_Alex,1);
end;

function suck_Alex_by_10()
  suck_pilot(pilot_Alex,10);
end;

function suck_Validol_by_1()
  suck_pilot(pilot_Validol,1);
end;

function suck_Validol_by_10()
  suck_pilot(pilot_Validol,10);
end;

function suck_Yana_by_1()
  suck_pilot(pilot_Yana,1);
end;

function suck_Yana_by_10()
  suck_pilot(pilot_Yana,10);
end;

function suck_Viper_by_1()
  suck_pilot(pilot_Viper,1);
end;

function suck_Viper_by_10()
  suck_pilot(pilot_Lastochka,10);
end;

function suck_Kalem_by_1()
  suck_pilot(pilot_Kalem,1);
end;

function suck_Kalem_by_10()
  suck_pilot(pilot_Kalem,10);
end;

function suck_Aia_by_1()
  suck_pilot(pilot_Aia,1);
end;

function suck_Aia_by_10()
  suck_pilot(pilot_Aia,10);
end;

function suck_Alexandra_by_1()
  suck_pilot(pilot_Alexandra,1);
end;

function suck_Alexandra_by_10()
  suck_pilot(pilot_Alexandra,10);
end;

function suck_Cleric_by_1()
  suck_pilot(pilot_Cleric,1);
end;

function suck_Cleric_by_10()
  suck_pilot(pilot_Cleric,10);
end;

function suck_Uel_by_1()
  suck_pilot(pilot_Uel,1);
end;

function suck_Uel_by_10()
  suck_pilot(pilot_Uel,10);
end;

function suck_Uel2_by_1()
  suck_pilot(pilot_Uel2,1);
end;

function suck_Uel2_by_10()
  suck_pilot(pilot_Uel2,10);
end;

function suck_Uel3_by_1()
  suck_pilot(pilot_Uel3,1);
end;

function suck_Uel3_by_10()
  suck_pilot(pilot_Uel3,10);
end;

function suck_Uel4_by_1()
  suck_pilot(pilot_Uel4,1);
end;

function suck_Uel4_by_10()
  suck_pilot(pilot_Uel4,10);
end;

function suck_Tramp_by_1()
  suck_pilot(pilot_Tramp,1);
end;

function suck_Tramp_by_10()
  suck_pilot(pilot_Tramp,10);
end;

function suck_Natali_by_1()
  suck_pilot(pilot_Natali,1);
end;

function suck_Natali_by_10()
  suck_pilot(pilot_Natali,10);
end;

function suck_Blade_by_1()
  suck_pilot(pilot_Blade,1);
end;

function suck_Blade_by_10()
  suck_pilot(pilot_Blade,10);
end;

function suck_alex1_1_by_1()
  suck_pilot(pilot_alex1_1,1);
end;

function suck_alex1_1_by_10()
  suck_pilot(pilot_alex1_1,10);
end;

function suck_alex2_1_by_1()
  suck_pilot(pilot_alex2_1,1);
end;

function suck_alex2_1_by_10()
  suck_pilot(pilot_alex2_1,10);
end;

function suck_El_by_1()
  suck_pilot(pilot_El,1);
end;

function suck_El_by_10()
  suck_pilot(pilot_El,10);
end;

function suck_Ace_by_1()
  suck_pilot(pilot_Ace,1);
end;

function suck_Ace_by_10()
  suck_pilot(pilot_Ace,10);
end;

function suck_Astra_by_1()
  suck_pilot(pilot_Astra,1);
end;

function suck_Astra_by_10()
  suck_pilot(pilot_Astra,10);
end;

function suck_Bavard_by_1()
  suck_pilot(pilot_Bavard,1);
end;

function suck_Bavard_by_10()
  suck_pilot(pilot_Bavard,10);
end;

function suck_Joker_by_1()
  suck_pilot(pilot_Joker,1);
end;

function suck_Joker_by_10()
  suck_pilot(pilot_Joker,10);
end;

function suck_Alisa_by_1()
  suck_pilot(pilot_Alisa,1);
end;

function suck_Alisa_by_10()
  suck_pilot(pilot_Alisa,10);
end;

function suck_Che_by_1()
  suck_pilot(pilot_Che,1);
end;

function suck_Che_by_10()
  suck_pilot(pilot_Che,10);
end;

function suck_Josef_by_1()
  suck_pilot(pilot_Josef,1);
end;

function suck_Josef_by_10()
  suck_pilot(pilot_Josef,10);
end;

function suck_Corsair_by_1()
  suck_pilot(pilot_Corsair,1);
end;

function suck_Corsair_by_10()
  suck_pilot(pilot_Corsair,10);
end;

function suck_Heretic_by_1()
  suck_pilot(pilot_Heretic,1);
end;

function suck_Heretic_by_10()
  suck_pilot(pilot_Heretic,10);
end;

function suck_m10_Heretic_by_1()
  suck_pilot(pilot_m10_Heretic,1);
end;

function suck_m10_Heretic_by_10()
  suck_pilot(pilot_m10_Heretic,10);
end;

function suck_Phantom_by_1()
  suck_pilot(pilot_Phantom,1);
end;

function suck_Phantom_by_10()
  suck_pilot(pilot_Phantom,10);
end;

function suck_m10_Phantom_by_1()
  suck_pilot(pilot_m10_Phantom,1);
end;

function suck_m10_Phantom_by_10()
  suck_pilot(pilot_m10_Phantom,10);
end;

function suck_pilot(name_pilot,amount)
local tab_BKT_output_names = {
  	{pilot_Hero,"Hero"},
    {pilot_Lastochka,"Ternie"},
    {pilot_Lastochka2,"Ternie"},
    {pilot_Sedoy,"Greyhair"},
    {pilot_Alex,"Alex"},
    {pilot_Validol,"Validol"},
    {pilot_Yana,"Jana"},
    {pilot_Viper,"Viper"},
    {pilot_Kalem,"Kalem"},
    {pilot_Aia,"Aja"},
    {pilot_Alexandra,"Alexandra"},
    {pilot_Cleric,"Cleric"},
    {pilot_Uel,"SAM"},
    {pilot_Uel2,"SAM copy"},
    {pilot_Uel3,"SAM copy"},
    {pilot_Uel4,"SAM copy"},
    {pilot_Tramp,"Adm.Trump"},
    {pilot_Natali,"Nataly"},
    {pilot_Blade,"Blade"},
    {pilot_alex1_1,"Alex1"},
    {pilot_alex2_1,"Alex2"},
    {pilot_El,"Al"},
    {pilot_Ace,"Ace"},
    {pilot_Astra,"Astra"},
    {pilot_Bavard,"Baward"},
    {pilot_Joker,"Joker"},
    
    {pilot_Alisa,"Alice"},
    {pilot_Che,"Che"},
    {pilot_Josef,"Josef"},
    {pilot_Corsair,"Corsair"},
    {pilot_Heretic,"Heretic"},
    {pilot_m10_Heretic,"Heretic"},
    {pilot_Phantom,"Phantom"},
    {pilot_m10_Phantom,"Phantom"}};
    
    for k, x in tab_BKT_output_names do
      if (x[1] == name_pilot) then
        true_name = x[2];
      end;
    end;

  pilot_BasePilot_BKT = GetPilot("BasePilot_BKT");
  local points_BKT = pilot_BasePilot_BKT:GetPoints();
  local points = name_pilot:GetPoints();
  if (points >= amount) then
    name_pilot:SetPoints(points - amount);
    OutputToScreenLog(true_name.." "..name_pilot:GetPoints().." skill points now.",10);
    if (pilot_BasePilot_BKT:HasProperty("Learner_Exp")) then      
      pilot_BasePilot_BKT:SetPoints(points_BKT + amount * 1.25);          
    elseif (pilot_BasePilot_BKT:HasProperty("Learner")) then
      pilot_BasePilot_BKT:SetPoints(points_BKT + amount * 1.1);    
    else
      pilot_BasePilot_BKT:SetPoints(points_BKT + amount);    
    end;
    OutputToScreenLog("Bryna&KT "..pilot_BasePilot_BKT:GetPoints().." skill points now.",10);
  else	
    OutputToScreenLog(true_name.." is dry!",7);
  end;
end;



function check_BKT_skill_points()
  OutputToScreenLog("Bryna&KT "..pilot_BasePilot_BKT:GetPoints().." skill points now.",10);
end;


function OnStationStartBKT_opt()
  Timer_Seq(0.1, OnStationStartBKT_opt_1);
end;

function OnStationStartBKT_opt_1()
  StartTradeDialog("DialogBKT_opt");
end;
  
  


function MSHIPDISPATCHER_RAMA()
    return "mshipDockingQueueDispatcher_rama", "mshipGetNextOneDistance", "mashipUnDockingQueueDispatcher";
end;

function mshipDockingQueueDispatcher_rama(flightIndex)
	if ( flightIndex < 2 ) then
		flightIndex=flightIndex * 0.8;
	end;
      return Vector3(5 + flightIndex, -4.0 - (flightIndex*2), 5 - flightIndex * 15);
end;

function MSHIPDISPATCHER_SILVER()
    return "mshipDockingQueueDispatcher_silver", "mshipGetNextOneDistance", "mashipUnDockingQueueDispatcher";
end;

function mshipDockingQueueDispatcher_silver(flightIndex)
	if ( flightIndex < 2 ) then
		flightIndex=flightIndex * 0.8;
	end;
      return Vector3(0 + flightIndex, -2 - (flightIndex*2), -8 - flightIndex * 7);
end;