------------------------------------------------------------
--     2008 Elite Games Team (R) All Rights Reserved      --
--             "STAR WOLVES 2: CIVIL WAR"                 --
------------------------------------------------------------

------------------------------------------------------------
-- Auto-built Quest-Action-file created by "MapBuilder2"  --
------------------------------------------------------------
--      "MapBuilder2" v.2.6 Elite Games Team              --
------------------------------------------------------------


--info:top=120,left=130,allvis=0;
function StartMission()
  SetNormalTimeMode();
--------------------------------------------------------------------------------
  --StartDialog("Dialog1");
  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
      StartDialog("Dialog1");
    end;
  else
    StartDialog("Dialog1");
  end; 
end;

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


--info:top=160,left=130,allvis=0;
function GoTo_Station()
  AddQuest("quest_18a_01", "#L_Quest_18a_01a", "#L_Quest_18a_01b", QUEST_PROCESS);
  nav_current = CreateNavPoint("", mothership:GetPosition(), "nav_void.dds", RGB(255,255,255), mothership);
  LineToStation = CreateLine(nav_current, NP_FIRST, RGB(20,80,220), .3, TRUE, .2, 1);
  NewTrigger("outside", TrueCondition, Lions_Go, mothership, Vector3(-500, 300, -600), 150);
end;


--info:top=190,left=130,allvis=0;
function Lions_Go()
  flight_emp1:Escort(mothership);
  trig_Emp1Near = NewTrigger("f_object_inside", TrueCondition, Dialog_Def, flight_emp1, mothership, 150);
  flight_vks1:Escort(mothership);
  trig_Vks1Near = NewTrigger("f_object_inside", TrueCondition, Dialog_Def, flight_vks1, mothership, 150);
  flight_vks2:Escort(mothership);
  trig_Vks2Near = NewTrigger("f_object_inside", TrueCondition, Dialog_Def, flight_vks2, mothership, 150);
end;


--info:top=220,left=130,allvis=0;
function Dialog_Def()
  lMission = 1;
  SetQuestState("quest_18a_01", QUEST_DONE);
  trig_Emp1Near:Delete();
  trig_Emp1Near = NIL;
  flight_emp1:Stop();
  trig_Vks1Near:Delete();
  trig_Vks1Near = NIL;
  flight_vks1:Stop();
  trig_Vks2Near:Delete();
  trig_Vks2Near = NIL;
  flight_vks2:Stop();
  LineToStation:Delete();
  LineToStation = NIL;
  nav_current:Delete();
  nav_current = NIL;
  SetNormalTimeMode();
  MothershipFlight:Stop();
  if (Player_Group:HavePerk("F_of_Merchant")) then
    StartDialog("Dialog2");
  else
    StartDialog("Dialog3");
  end;
end;


--info:top=370,left=270,allvis=0;
function failedAlarm()
  if (trig_Alarm1) then
    trig_Alarm1:Delete();
    trig_Alarm1 = NIL;
  end;
  if (trig_Alarm2) then
    trig_Alarm2:Delete();
    trig_Alarm2 = NIL;
  end;
  if (trig_Alarm3) then
    trig_Alarm3:Delete();
    trig_Alarm3 = NIL;
  end;
  if (trig_Alarm4) then
    trig_Alarm4:Delete();
    trig_Alarm4 = NIL;
  end;
  if (trig_Alarm5) then
    trig_Alarm5:Delete();
    trig_Alarm5 = NIL;
  end;
  if (trig_EmpDialog) then
    trig_EmpDialog:Delete();
    trig_EmpDialog = NIL;
  end;
  Remove_Pers_FromBase();
-- удаляем базу из группы игрока
  MothershipPilot = mothership:GetPilot(); 
  MothershipFlight = MothershipPilot:GetFlight(); 
  Player_Group:RemoveFlight(MothershipFlight);
  Emperor_Group:AddFlight(MothershipFlight);
-- создаем новое звено для персов игрока 
  local VFlight = ViperSpeaker:GetFlight();
  if (VFlight:GetPilotCount()==1) then
    Player_Group:RemoveFlight(VFlight);
    Emperor_Group:AddFlight(VFlight);
    VFlight:Escort(mothership);
  else
    local ViperShip = ViperSpeaker:GetShip();
    local NewViperFlight = Emperor_Group:CreateFlight("NewViperFlight");
    NewViperFlight:AddShip(ViperShip);
    NewViperFlight:Escort(mothership);
  end;
-- теперь общий стоп и выставляем отношения
  MothershipFlight:Stop();
  Stop_Player_Pilots();
  trig_HeroDied = NewTrigger("died", TrueCondition, Hero_Died, HeroSpeaker:GetShip());
  new_SetAllGroupRelations(rel_PlWar, power_rel_1);
  VksSpeaker:Message("#L_vks_01", 5, "Viper_Damn");
end;


--info:top=460,left=310,allvis=0;
function Viper_Damn()
  ViperSpeaker:Message("#L_Viper_01", 4);
end;


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


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


--info:top=500,left=270,allvis=0;
function Hero_Died()
  ShowMsgBox("#L_sys_01", "#L_sys_02", fin_failed);
end;


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


--info:top=280,left=130,allvis=0;
function If_Spread()
  trig_Alarm1 = NewTrigger("side_inside", TrueCondition, failedAlarm, PLAYER_TEAM, mothership:GetPosition()+Vector3(100, 0, 100), 125);
  trig_Alarm2 = NewTrigger("side_inside", TrueCondition, failedAlarm, PLAYER_TEAM, mothership:GetPosition()+Vector3(100, 0, -100), 125);
  trig_Alarm3 = NewTrigger("side_inside", TrueCondition, failedAlarm, PLAYER_TEAM, mothership:GetPosition()+Vector3(100, 100, 0), 125);
  trig_Alarm4 = NewTrigger("side_inside", TrueCondition, failedAlarm, PLAYER_TEAM, mothership:GetPosition()+Vector3(100, -100, 0), 125);
  trig_Alarm5 = NewTrigger("outside", TrueCondition, failedAlarm, mothership, mothership:GetPosition(), 25);
  Timer_Seq(3, Need_Wait);
end;


--info:top=280,left=220,allvis=0;
function If_Stay()
  local mshippos = mothership:GetPosition();
  local k1 = VectorLength(Vector3(-500, 300, -600), mshippos)/150;
  local tx = mshippos.x - (mshippos.x + 500) / k1;
  local ty = mshippos.y - (mshippos.y - 300) / k1;
  local tz = mshippos.z - (mshippos.z + 600) / k1;
  trig_Alarm1 = NewTrigger("side_outside", TrueCondition, failedAlarm, PLAYER_TEAM, Vector3(tx, ty, tz), 250);
  trig_Alarm5 = NewTrigger("outside", TrueCondition, failedAlarm, mothership, mothership:GetPosition(), 25);
  Timer_Seq(3, Need_Wait);
end;


--info:top=360,left=130,allvis=0;
function Need_Wait()
  if (GetGroupRelation("Emperor_Group", PLAYER_GROUP)==RELATION_NEUTRAL) then
    VksSpeaker:Message("#L_vks_02", 8);
    trig_EmpDialog = NewTrigger("timer", TrueCondition, Emperor_Dialog, 30);
  end;
end;


--info:top=280,left=600,allvis=0;
function If_Go()
  local mshippos = mothership:GetPosition();
  local k1 = VectorLength(Vector3(-500, 300, -600), mshippos)/150;
  local tx = mshippos.x - (mshippos.x + 500) / k1;
  local ty = mshippos.y - (mshippos.y - 300) / k1;
  local tz = mshippos.z - (mshippos.z + 600) / k1;
  trig_Alarm1 = NewTrigger("side_outside", TrueCondition, failedAlarm, PLAYER_TEAM, Vector3(tx, ty, tz), 250);
  trig_Alarm5 = NewTrigger("outside", TrueCondition, failedAlarm, mothership, mothership:GetPosition(), 25);
  Timer_Seq(1, Wait_Hero_and_Viper);
end;


--info:top=320,left=600,allvis=0;
function Wait_Hero_and_Viper()
  if (GetGroupRelation("Emperor_Group", PLAYER_GROUP)==RELATION_NEUTRAL) then
    if (ViperSpeaker:IsInBase())or(ViperSpeaker:IsBasePilot())or(HeroSpeaker:IsInBase())or(HeroSpeaker:IsBasePilot()) then
      OutputToScreenLog("#L_sys_03", 9);
      trig_Hint = NewTrigger("timer", TrueCondition, Wait_Hero_and_Viper, 10);
    else
      Timer_Seq(1, GoTo_Target);
    end;
  end;
end;


--info:top=360,left=600,allvis=0;
function GoTo_Target()
  if (trig_Alarm1) then
    trig_Alarm1:Delete();
    trig_Alarm1 = NIL;
  end;
  if (trig_Alarm5) then
    trig_Alarm5:Delete();
    trig_Alarm5 = NIL;
  end;
  trig_AttackVks:Delete();
  trig_AttackVks = NIL;
  local flightV = ViperSpeaker:GetFlight();
  ViperShip = ViperSpeaker:GetShip();
  if (flightV:GetPilotCount()==1) then
    ViperFlight = ViperSpeaker:GetFlight();
  else
    ViperFlight = Player_Group:CreateFlight("ViperFlight");
    ViperFlight:AddShip(ViperShip);
  end;
  HeroShip = HeroSpeaker:GetShip();
  ViperFlight:AddShip(HeroShip);
-- удаляем базу из группы игрока
  MothershipPilot = mothership:GetPilot(); 
  MothershipFlight = MothershipPilot:GetFlight(); 
  Player_Group:RemoveFlight(MothershipFlight);
  Tmp_Group:AddFlight(MothershipFlight);
-- создаем новое звено для персов игрока 
  if (SedoySpeaker:GetSide()==PLAYER_TEAM) then
    local SFlight = SedoySpeaker:GetFlight();
    Player_Group:RemoveFlight(SFlight);
    Tmp_Group:AddFlight(SFlight);
    SFlight:Escort(mothership);
  end;
  if (ValidolSpeaker:GetSide()==PLAYER_TEAM) then
    local VFlight = ValidolSpeaker:GetFlight();
    Player_Group:RemoveFlight(VFlight);
    Tmp_Group:AddFlight(VFlight);
    VFlight:Escort(mothership);
  end;
  if (KalemSpeaker:GetSide()==PLAYER_TEAM) then
    local KFlight = KalemSpeaker:GetFlight();
    Player_Group:RemoveFlight(KFlight);
    Tmp_Group:AddFlight(KFlight);
    KFlight:Escort(mothership);
  end;
  if (LastochkaSpeaker:GetSide()==PLAYER_TEAM) then
    local LFlight = LastochkaSpeaker:GetFlight();
    Player_Group:RemoveFlight(LFlight);
    Tmp_Group:AddFlight(LFlight);
    LFlight:Escort(mothership);
  end;
  MothershipFlight:Stop();
  Stop_Player_Pilots();
  trig_HeroDied = NewTrigger("died", TrueCondition, Hero_Died, HeroShip);
  NewVksFlight("Emperor_Group", "vks11", FIRST:GetPosition()+Vector3(-50, 20, 50), 1, 20, Vector3(-1, 0, 0));
  nav_target = CreateNavPoint("", FIRST:GetPosition()+Vector3(-50, 20, 50), "nav_default.dds", RGB(255,255,255));
  lMission = 0;
  local pos_ms = HeroShip:GetPosition();
  local pos_tg = FIRST:GetPosition()+Vector3(-50, 20, 50);
  local center = Vector3((pos_ms.x+pos_tg.x)/2,(pos_ms.y+pos_tg.y)/2,(pos_ms.z+pos_tg.z)/2);
  local dist = VectorLength(pos_ms, pos_tg)/2;
  trig_EscapeH = NewTrigger("outside", TrueCondition, Try_Escape, HeroShip, center, dist+25);
  trig_ApproachH = NewTrigger("inside", TrueCondition, Reinit_Approch_H, HeroShip, center, dist-25);
  pos_ms = ViperShip:GetPosition();
  pos_tg = FIRST:GetPosition()+Vector3(-50, 20, 50);
  center = Vector3((pos_ms.x+pos_tg.x)/2,(pos_ms.y+pos_tg.y)/2,(pos_ms.z+pos_tg.z)/2);
  dist = VectorLength(pos_ms, pos_tg)/2;
  trig_EscapeV = NewTrigger("outside", TrueCondition, Try_Escape, ViperShip, center, dist+25);
  trig_ApproachV = NewTrigger("inside", TrueCondition, Reinit_Approch_V, ViperShip, center, dist-25);
  trig_EmpDialog = NewTrigger("inside", TrueCondition, Near_Station, ViperShip, FIRST:GetPosition()+Vector3(-50, 20, 50), 50);
end;


--info:top=400,left=600,allvis=0;
function Reinit_Approch_H()
  local v_target = FIRST:GetPosition()+Vector3(-50, 20, 50);
  local v_ship = HeroShip:GetPosition();
  local v_center = Vector3((v_target.x+v_ship.x)/2,(v_target.y+v_ship.y)/2,(v_target.z+v_ship.z)/2);
  local distance = VectorLength(v_target,v_ship);
  trig_EscapeH:Delete();
  trig_EscapeH = NIL;
  trig_ApproachH:Delete();
  trig_ApproachH = NIL;
  if (distance>25) then
    distance = distance/2;
    trig_EscapeH = NewTrigger("outside", TrueCondition, Try_Escape, HeroShip, v_center, distance+25);
    trig_ApproachH = NewTrigger("inside", TrueCondition, Reinit_Approch_H, HeroShip, v_center, distance-25);
  end;
end;


--info:top=380,left=750,allvis=0;
function Reinit_Approch_V()
  local v_target = FIRST:GetPosition()+Vector3(-50, 20, 50);
  local v_ship = ViperShip:GetPosition();
  local v_center = Vector3((v_target.x+v_ship.x)/2,(v_target.y+v_ship.y)/2,(v_target.z+v_ship.z)/2);
  local distance = VectorLength(v_target,v_ship);
  trig_EscapeV:Delete();
  trig_EscapeV = NIL;
  trig_ApproachV:Delete();
  trig_ApproachV = NIL;
  if (distance>25) then
    distance = distance/2;
    trig_EscapeV = NewTrigger("outside", TrueCondition, Try_Escape, ViperShip, v_center, distance+25);
    trig_ApproachV = NewTrigger("inside", TrueCondition, Reinit_Approch_V, ViperShip, v_center, distance-25);
  end;
end;


--info:top=560,left=650,allvis=0;
function Try_Escape()
  if (trig_EscapeH) then
    trig_EscapeH:Delete();
    trig_EscapeH = NIL;
  end;
  if (trig_ApproachH) then
    trig_ApproachH:Delete();
    trig_ApproachH = NIL;
  end;
  if (trig_EscapeV) then
    trig_EscapeV:Delete();
    trig_EscapeV = NIL;
  end;
  if (trig_ApproachV) then
    trig_ApproachV:Delete();
    trig_ApproachV = NIL;
  end;
  if (trig_EmpDialog) then
    trig_EmpDialog:Delete();
    trig_EmpDialog = NIL;
  end;
  if (LineTo) then
    LineTo:Delete();
    LineTo = NIL;
  end;
  if (nav_target) then
    nav_target:Delete();
    nav_target = NIL;
  end;
  if (nav_target2) then
    nav_target2:Delete();
    nav_target2 = NIL;
  end;
  MothershipPilot = mothership:GetPilot(); 
  MothershipFlight = MothershipPilot:GetFlight(); 
  Tmp_Group:RemoveFlight(MothershipFlight);
  Emperor_Group:AddFlight(MothershipFlight);
  local VFlight = ViperSpeaker:GetFlight();
  if (VFlight:GetPilotCount()==1) then
    Player_Group:RemoveFlight(VFlight);
    Emperor_Group:AddFlight(VFlight);
    VFlight:Escort(mothership);
  else
    local VShip = ViperSpeaker:GetShip();
    local NewViperFlight = Emperor_Group:CreateFlight("NewViperFlight");
    NewViperFlight:AddShip(VShip);
  end;
  ViperSpeaker:Message("#L_Viper_01", 4);
  new_SetAllGroupRelations(rel_PlWar, power_rel_1);
end;


--info:top=430,left=530,allvis=0;
function Near_Station()
  if (trig_EscapeH) then
    trig_EscapeH:Delete();
    trig_EscapeH = NIL;
  end;
  if (trig_ApproachH) then
    trig_ApproachH:Delete();
    trig_ApproachH = NIL;
  end;
  if (trig_EscapeV) then
    trig_EscapeV:Delete();
    trig_EscapeV = NIL;
  end;
  if (trig_ApproachV) then
    trig_ApproachV:Delete();
    trig_ApproachV = NIL;
  end;
  local VFlight = ViperSpeaker:GetFlight();
  VFlight:Stop();
  flight_vks11:Escort(ViperShip);
  nav_target2 = CreateNavPoint("", FIRST:GetPosition()+Vector3(100, 50, 200), "nav_default.dds", RGB(255,255,255));
  LineTo = CreateLine(nav_target, nav_target2, RGB(20,80,220), .3, TRUE, .2, 1);
  local pos_ms = HeroShip:GetPosition();
  local pos_tg = FIRST:GetPosition()+Vector3(100, 50, 200);
  local center = Vector3((pos_ms.x+pos_tg.x)/2,(pos_ms.y+pos_tg.y)/2,(pos_ms.z+pos_tg.z)/2);
  local dist = VectorLength(pos_ms, pos_tg)/2;
  trig_EscapeH = NewTrigger("outside", TrueCondition, Try_Escape, HeroShip, center, dist+25);
  trig_ApproachH = NewTrigger("inside", TrueCondition, Reinit_Approch_H2, HeroShip, center, dist-25);
  pos_ms = ViperShip:GetPosition();
  pos_tg = FIRST:GetPosition()+Vector3(100, 50, 200);
  center = Vector3((pos_ms.x+pos_tg.x)/2,(pos_ms.y+pos_tg.y)/2,(pos_ms.z+pos_tg.z)/2);
  dist = VectorLength(pos_ms, pos_tg)/2;
  trig_EscapeV = NewTrigger("outside", TrueCondition, Try_Escape, ViperShip, center, dist+25);
  trig_ApproachV = NewTrigger("inside", TrueCondition, Reinit_Approch_V2, ViperShip, center, dist-25);
  trig_EmpDialog = NewTrigger("inside", TrueCondition, Emperor_Dialog, ViperShip, FIRST:GetPosition()+Vector3(100, 50, 200), 30);
  VksSpeaker:Message("#L_vks_03", 10, "Viper_OK");
end;


--info:top=460,left=560,allvis=0;
function Viper_OK()
  ViperSpeaker:Message("#L_Viper_02", 6);
end;


--info:top=490,left=460,allvis=0;
function Reinit_Approch_H2()
  local v_target = FIRST:GetPosition()+Vector3(100, 50, 200);
  local v_ship = HeroShip:GetPosition();
  local v_center = Vector3((v_target.x+v_ship.x)/2,(v_target.y+v_ship.y)/2,(v_target.z+v_ship.z)/2);
  local distance = VectorLength(v_target,v_ship);
  trig_EscapeH:Delete();
  trig_EscapeH = NIL;
  trig_ApproachH:Delete();
  trig_ApproachH = NIL;
  if (distance>25) then
    distance = distance/2;
    trig_EscapeH = NewTrigger("outside", TrueCondition, Try_Escape, HeroShip, v_center, distance+25);
    trig_ApproachH = NewTrigger("inside", TrueCondition, Reinit_Approch_H2, HeroShip, v_center, distance-25);
  end;
end;


--info:top=490,left=610,allvis=0;
function Reinit_Approch_V2()
  local v_target = FIRST:GetPosition()+Vector3(100, 50, 200);
  local v_ship = ViperShip:GetPosition();
  local v_center = Vector3((v_target.x+v_ship.x)/2,(v_target.y+v_ship.y)/2,(v_target.z+v_ship.z)/2);
  local distance = VectorLength(v_target,v_ship);
  trig_EscapeV:Delete();
  trig_EscapeV = NIL;
  trig_ApproachV:Delete();
  trig_ApproachV = NIL;
  if (distance>25) then
    distance = distance/2;
    trig_EscapeV = NewTrigger("outside", TrueCondition, Try_Escape, ViperShip, v_center, distance+25);
    trig_ApproachV = NewTrigger("inside", TrueCondition, Reinit_Approch_V2, ViperShip, v_center, distance-25);
  end;
end;


--info:top=630,left=130,allvis=0;
function Emperor_Dialog()
  if (trig_HeroDied) then
    trig_HeroDied:Delete();
    trig_HeroDied = NIL;
  end;
  if (trig_EscapeH) then
    trig_EscapeH:Delete();
    trig_EscapeH = NIL;
  end;
  if (trig_ApproachH) then
    trig_ApproachH:Delete();
    trig_ApproachH = NIL;
  end;
  if (trig_EscapeV) then
    trig_EscapeV:Delete();
    trig_EscapeV = NIL;
  end;
  if (trig_ApproachV) then
    trig_ApproachV:Delete();
    trig_ApproachV = NIL;
  end;
  if (LineTo) then
    LineTo:Delete();
    LineTo = NIL;
  end;
  if (nav_target) then
    nav_target:Delete();
    nav_target = NIL;
  end;
  if (nav_target2) then
    nav_target2:Delete();
    nav_target2 = NIL;
  end;
  if (trig_AttackVks) then
    trig_AttackVks:Delete();
    trig_AttackVks = NIL;
  end;
  if (GetGroupRelation("Emperor_Group", PLAYER_GROUP)==RELATION_NEUTRAL) then
    trig_EmpDialog:Delete();
    trig_EmpDialog = NIL;
    if (GetQuestLabel("Heder")=="alive") then
      StartDialog("Dialog4");
    else
      StartDialog("Dialog9");
    end;
  end;
end;


--info:top=670,left=130,allvis=0;
function Vks_Attack()
  if (trig_Alarm1) then
    trig_Alarm1:Delete();
    trig_Alarm1 = NIL;
  end;
  if (trig_Alarm2) then
    trig_Alarm2:Delete();
    trig_Alarm2 = NIL;
  end;
  if (trig_Alarm3) then
    trig_Alarm3:Delete();
    trig_Alarm3 = NIL;
  end;
  if (trig_Alarm4) then
    trig_Alarm4:Delete();
    trig_Alarm4 = NIL;
  end;
  if (trig_Alarm5) then
    trig_Alarm5:Delete();
    trig_Alarm5 = NIL;
  end;
  if (LineTo) then
    LineTo:Delete();
    LineTo = NIL;
  end;
  if (nav_target) then
    nav_target:Delete();
    nav_target = NIL;
  end;
  if (nav_target2) then
    nav_target2:Delete();
    nav_target2 = NIL;
  end;
  if (trig_EmpDialog) then
    trig_EmpDialog:Delete();
    trig_EmpDialog = NIL;
  end;
  if (MothershipPilot:GetSide()~=PLAYER_TEAM) then
    if (HeroSpeaker:IsCanSayReplica()) then
      HeroFlight = HeroSpeaker:GetFlight();
      Player_Group:RemoveFlight(HeroFlight);
    end;
    if (ViperSpeaker:IsCanSayReplica()) and (ViperSpeaker:GetSide()==PLAYER_TEAM) then
      ViperFlight = ViperSpeaker:GetFlight();
      Player_Group:RemoveFlight(ViperFlight);
    end;
    Tmp_Group:RemoveFlight(MothershipFlight);
    Player_Group:AddFlight(MothershipFlight);
    if (HeroSpeaker:IsCanSayReplica()) then
      HeroFlight = HeroSpeaker:GetFlight();
      Player_Group:AddFlight(HeroFlight);
    end;
    if (ViperSpeaker:IsCanSayReplica()) and (ViperSpeaker:GetSide()~=PLAYER_TEAM) then
      ViperFlight = ViperSpeaker:GetFlight();
      Player_Group:AddFlight(ViperFlight);
    end;
    if (SedoySpeaker:GetSide()~=PLAYER_TEAM) then
      local SFlight = SedoySpeaker:GetFlight();
      Tmp_Group:RemoveFlight(SFlight);
      Player_Group:AddFlight(SFlight);
      SFlight:Escort(mothership);
    end;
    if (ValidolSpeaker:GetSide()~=PLAYER_TEAM) then
      local VFlight = ValidolSpeaker:GetFlight();
      Tmp_Group:RemoveFlight(VFlight);
      Player_Group:AddFlight(VFlight);
      VFlight:Escort(mothership);
    end;
    if (KalemSpeaker:GetSide()~=PLAYER_TEAM) then
      local KFlight = KalemSpeaker:GetFlight();
      Tmp_Group:RemoveFlight(KFlight);
      Player_Group:AddFlight(KFlight);
      KFlight:Escort(mothership);
    end;
    if (LastochkaSpeaker:GetSide()~=PLAYER_TEAM) then
      local LFlight = LastochkaSpeaker:GetFlight();
      Tmp_Group:RemoveFlight(LFlight);
      Player_Group:AddFlight(LFlight);
      LFlight:Escort(mothership);
    end;
    ViperSpeaker:Message("#L_Viper_03", 6);
  end;
  Timer_Seq(1, Kill_Emperor);
end;


--info:top=710,left=130,allvis=0;
function Kill_Emperor()
  new_SetGroupRelations("Emperor_Group", PLAYER_GROUP, "W");
  new_SetGroupRelations("VksGroup_1", PLAYER_GROUP, "W");
  flight_emp1:Move(MAIN:GetPosition());
  trig_EmperorNearMain = NewTrigger("f_inside", TrueCondition, Emperor_NearStation, flight_emp1, MAIN:GetPosition(), 100);
  trig_EmperorDied = NewTrigger("f_died", TrueCondition, Emperor_Died, flight_emp1);
  empHP = GetCurHP(ship_emp1_1);
  trig_EmperorAfraided = NewTrigger("HP", TrueCondition, Emperor_Afraided, ship_emp1_1, empHP/2);
  MAIN:AddToGroup("VksGroup_1");
  trig_MainAttacked = NewTrigger("attack", TrueCondition, Main_Attacked, PLAYER_GROUP, MAIN);
  AddQuest("quest_18a_02", "#L_Quest_18a_02a", "#L_Quest_18a_02b", QUEST_PROCESS);
  Timer_Seq(6, Emperor_NeedHyper);
end;


--info:top=770,left=60,allvis=0;
function Emperor_NeedHyper()
  if (flight_emp1) and (flight_emp1:IsAlive()) then
    EmperorSpeaker:Message("#L_emperor_01", 4, "Viper_NeedKill");
  end;
end;


--info:top=810,left=60,allvis=0;
function Viper_NeedKill()
  ViperSpeaker:Message("#L_Viper_04", 3);
end;


--info:top=770,left=210,allvis=0;
function Emperor_NearStation()
  trig_MainAttacked:Delete();
  trig_MainAttacked = NIL;
  trig_EmperorNearMain:Delete();
  trig_EmperorNearMain = NIL;
  trig_MainDied = NewTrigger("side_inside", TrueCondition, Main_Died, PLAYER_TEAM, MAIN:GetPosition(), 150);
  trig_EmperorGoHyper = NewTrigger("timer", TrueCondition, Emperor_ToHyper, 90);
  SetNormalTimeMode();
  StartDialog("Dialog5");
end;


--info:top=810,left=210,allvis=0;
function Emperor_ToHyper()
  trig_EmperorGoHyper:Delete();
  trig_EmperorGoHyper = NIL;
  DispetcherSpeaker:Message("#L_disp_02", 4, "Emperor_Activate");
end;


--info:top=850,left=210,allvis=0;
function Emperor_Activate()
  if (flight_emp1) and (flight_emp1:IsAlive()) then
    EmperorSpeaker:Message("#L_emperor_04", 5);
    local pos = ship_emp1_1:GetPosition();
    local orn = ship_emp1_1:GetVectorOrientation();
    local glow_orn = ship_emp1_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_emp1:Move(pos+orn);
    ship_emp1_1:PlayFX("Portal Out.shfx");
    Timer_Seq(5, Emperor_ToPortal);
  end;
end;


--info:top=770,left=380,allvis=0;
function Emperor_Afraided()
  trig_EmperorAfraided:Delete();
  trig_EmperorAfraided = NIL
  EmperorSpeaker:Message("#L_emperor_02", 7, "Viper_Know");
end;


--info:top=810,left=380,allvis=0;
function Viper_Know()
  ViperSpeaker:Message("#L_Viper_05", 7);
end;


--info:top=770,left=520,allvis=0;
function Main_Attacked()
  trig_MainAttacked:Delete();
  trig_MainAttacked = NIL;
  if (trig_EmperorNearMain) then
    trig_EmperorNearMain:Delete();
    trig_EmperorNearMain = NIL;
  end;
  Timer_Seq(1, Emperor_GoPortal);
  DispetcherSpeaker:Message("#L_disp_01", 3, "Emperor_GoToPortal");
end;


--info:top=810,left=520,allvis=0;
function Emperor_GoToPortal()
  EmperorSpeaker:Message("#L_emperor_03", 4, "Viper_NeedFast");
end;


--info:top=850,left=520,allvis=0;
function Viper_NeedFast()
  ViperSpeaker:Message("#L_Viper_06", 4);
end;


--info:top=900,left=350,allvis=0;
function Emperor_GoPortal()
  ship_emp1_1:ComeToPortal(PORTAL_R);
  trig_EmperorGoOut = NewTrigger("f_object_inside", trigger_inside2portal_Condition, Emperor_ToPortal, flight_emp1, PORTAL_R, 20);
end;


--info:top=940,left=350,allvis=0;
function Emperor_ToPortal()
  if (flight_emp1) and (flight_emp1:IsAlive()) then
    SetQuestState("quest_18a_02", QUEST_FAILED);
    new_SetAllGroupRelations(rel_EndWar, power_rel_1);
    if (trig_EmperorAfraided) then
      trig_EmperorAfraided:Delete();
    end;
    trig_EmperorDied:Delete();
    flight_emp1:Delete();
    Timer_Seq(1, Vks_Normal);
  end;
end;


--info:top=860,left=350,allvis=0;
function Main_Died()
  SetNormalTimeMode();
  StartDialog("Dialog6");
end;


--info:top=940,left=130,allvis=0;
function Emperor_Died()
  if (trig_EmperorNearMain) then
    trig_EmperorNearMain:Delete();
    trig_EmperorNearMain = NIL;
  end;
  if (trig_EmperorAfraided) then
    trig_EmperorAfraided:Delete();
    trig_EmperorAfraided = NIL;
  end;
  if (trig_MainAttacked) then
    trig_MainAttacked:Delete();
    trig_MainAttacked = NIL;
  end;
  if (trig_MainDied) then
    trig_MainDied:Delete();
    trig_MainDied = NIL;
  end;
  if (trig_EmperorGoHyper) then
    trig_EmperorGoHyper:Delete();
    trig_EmperorGoHyper = NIL;
  end;
  SetQuestState("quest_18a_02", QUEST_DONE);
  new_SetAllGroupRelations(rel_EndWar, power_rel_1);
  Timer_Seq(1, Vks_Stop);
  VksSpeaker:Message("#L_vks_04", 4, "Leut_Panic");
end;


--info:top=990,left=130,allvis=0;
function Leut_Panic()
  LeutSpeaker:Message("#L_vks_05", 2, "Vks_Panic");
end;


--info:top=1030,left=130,allvis=0;
function Vks_Panic()
  VksSpeaker:Message("#L_vks_06", 4);
  Timer_Seq(1, Vks_OutGoing);
  Timer_Seq(7, finMission);
end;


--info:top=980,left=350,allvis=0;
function Vks_Normal()
  VksSpeaker:Message("#L_vks_07", 5);
  Timer_Seq(2, Vks_OutGoing);
  Timer_Seq(7, failedMission);
end;


--info:top=970,left=160,allvis=0;
function Vks_Stop()
  if (flight_emp2:IsAlive()) then
    flight_emp2:Stop();
  end;
  if (flight_emp3:IsAlive()) then
    flight_emp3:Stop();
  end;
  if (flight_emp4:IsAlive()) then
    flight_emp4:Stop();
  end;
  if (flight_vks1:IsAlive()) then
    flight_vks1:Stop();
  end;
  if (flight_vks2:IsAlive()) then
    flight_vks2:Stop();
  end;
  if (flight_bigdef1:IsAlive()) then
    flight_bigdef1:Stop();
  end;
  if (flight_vks3:IsAlive()) then
    flight_vks3:Stop();
  end;
  if (flight_vks4:IsAlive()) then
    flight_vks4:Stop();
  end;
  if (flight_vks5:IsAlive()) then
    flight_vks5:Stop();
  end;
  if (flight_vks6:IsAlive()) then
    flight_vks6:Stop();
  end;
  if (flight_vks7:IsAlive()) then
    flight_vks7:Stop();
  end;
  if (flight_vks8:IsAlive()) then
    flight_vks8:Stop();
  end;
  if (flight_vks9:IsAlive()) then
    flight_vks9:Stop();
  end;
  if (flight_vks10:IsAlive()) then
    flight_vks10:Stop();
  end;
  if (flight_pat1:IsAlive()) then
    flight_pat1:Stop();
  end;
  if (flight_pat2:IsAlive()) then
    flight_pat2:Stop();
  end;
  if (flight_pat3:IsAlive()) then
    flight_pat3:Stop();
  end;
  if (flight_pat4:IsAlive()) then
    flight_pat4:Stop();
  end;
  if (flight_pat5:IsAlive()) then
    flight_pat5:Stop();
  end;
end;


--info:top=1060,left=210,allvis=0;
function Vks_OutGoing()
  if (flight_vks1:IsAlive()) then
    local pos = ship_vks1_1:GetPosition();
    local orn = ship_vks1_1:GetVectorOrientation();
    local glow_orn = ship_vks1_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_vks1:Move(pos+orn);
    ship_vks1_1:PlayFX("Portal Out.shfx");
    Timer_Seq(5, Vks1_Out);
  end;
  if (flight_vks2:IsAlive()) then
    local pos = ship_vks2_1:GetPosition();
    local orn = ship_vks2_1:GetVectorOrientation();
    local glow_orn = ship_vks2_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_vks2:Move(pos+orn);
    ship_vks2_1:PlayFX("Portal Out.shfx");
    Timer_Seq(5, Vks2_Out);
  end;
  if (flight_bigdef1:IsAlive()) then
    local pos = ship_bigdef1_1:GetPosition();
    local orn = ship_bigdef1_1:GetVectorOrientation();
    local glow_orn = ship_bigdef1_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_bigdef1:Move(pos+orn);
    ship_bigdef1_1:PlayFX("Portal Out.shfx");
    Timer_Seq(5, Bigdef1_Out);
  end;
  if (flight_vks3:IsAlive()) then
    flight_vks3:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_vks4:IsAlive()) then
    flight_vks4:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_vks5:IsAlive()) then
    flight_vks5:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_vks6:IsAlive()) then
    flight_vks6:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_vks7:IsAlive()) then
    flight_vks7:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_vks8:IsAlive()) then
    flight_vks8:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_vks9:IsAlive()) then
    flight_vks9:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_vks10:IsAlive()) then
    flight_vks10:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_pat1:IsAlive()) then
    flight_pat1:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_pat2:IsAlive()) then
    flight_pat2:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_pat3:IsAlive()) then
    flight_pat3:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_pat4:IsAlive()) then
    flight_pat4:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
  if (flight_pat5:IsAlive()) then
    flight_pat5:Move(Vector3(3000, 500, RAND(6000)-3000));
  end;
end;


--info:top=1090,left=240,allvis=0;
function Vks1_Out()
  flight_vks1:Delete();
end;


--info:top=1120,left=240,allvis=0;
function Vks2_Out()
  flight_vks2:Delete();
end;


--info:top=1150,left=240,allvis=0;
function Bigdef1_Out()
  flight_bigdef1:Delete();
end;


--info:top=1170,left=130,allvis=0;
function finMission()
  SetNormalTimeMode();
  StartDialog("Dialog7");
end;


--info:top=1210,left=130,allvis=0;
function doneMission()
  EndGame("ViperDone");
end;


--info:top=1170,left=350,allvis=0;
function failedMission()
  SetNormalTimeMode();
  StartDialog("Dialog8");
end;


--info:top=1210,left=350,allvis=0;
function failMission()
  EndGame("ViperFailed");
end;


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

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

  Player_Group = MothershipPilot:GetGroup();
  Emperor_Group = VksTeam:CreateGroup("Emperor_Group");
  Tmp_Group = MercTeam:CreateGroup("Tmp_Group");
  power_rel_1 = {Player_Group, Tmp_Group, Emperor_Group, VksGroup_1};
  rel_Neutral = {{"F"},
                 {"N","N"},
                 {"N","N","F"}};
  rel_PlWar = {{"X"},
               {"W","W"},
               {"W","W","X"}};
  rel_EndWar = {{"X"},
                {"CN","CN"},
                {"CN","CN","X"}};
  new_SetAllGroupRelations(rel_Neutral, power_rel_1);

  HeroSpeaker = GetPilot("Hero");
  SedoySpeaker = GetPilot("Sedoy");
  ValidolSpeaker = GetPilot("Validol");
  ViperSpeaker = GetPilot("Viper");
  KalemSpeaker = GetPilot("Kalem");
  LastochkaSpeaker = GetPilot("Lastochka2");
  VksSpeaker = CreatePilot("VksAce");
  LeutSpeaker = CreatePilot("VksOfficer");
  EmperorSpeaker = CreatePilot("Emperor");
  DispetcherSpeaker = CreatePilot("DispetcherVKS");

  NewFlight("Emperor_Group", "emp1", "Lion_Tramp", "VksSuperAce", FIRST:GetPosition()+Vector3(-100, 30, -150), Vector3(-1, 0, 0));
  NewFlight("Emperor_Group", "vks1", "Lion_Tramp", "VksSuperAce", FIRST:GetPosition()+Vector3(-100, -30, -250), Vector3(-1, 0, 0));
  NewFlight("Emperor_Group", "vks2", "Lion_Tramp", "VksSuperAce", SECOND:GetPosition()+Vector3(-200, 10, -50), Vector3(-1, 0, 0));
  NewVksFlight("VksGroup_1", "bigdef1", MAIN:GetPosition()+Vector3(0, 100, 0), 3, 20, Vector3(0, 0, -1));
  NewVksFlight("VksGroup_1", "pat1", MAIN:GetPosition()+Vector3(-80, 50, 150), 1, 20, Vector3(-1, 0, 0));
  flight_pat1:Patrol({Vector3(200, 0, 600), Vector3(-100, 0, 450), Vector3(200, 100, 600), MAIN:GetPosition()+Vector3(-80, 50, 150)}, TRUE);
  NewVksFlight("VksGroup_1", "pat2", MAIN:GetPosition()+Vector3(80, 50, 150), 1, 20, Vector3(-1, 0, 0));
  flight_pat2:Patrol({MAIN:GetPosition()+Vector3(80, 50, -150), Vector3(750, 0, 100), MAIN:GetPosition()+Vector3(-100, -50, -150), MAIN:GetPosition()+Vector3(-80, 0, 120), MAIN:GetPosition()+Vector3(80, 50, 150)}, TRUE);
  NewVksFlight("VksGroup_1", "pat3", SECOND:GetPosition()+Vector3(80, 0, -100), 1, 20, Vector3(-1, 0, 0));
  flight_pat3:Patrol({Vector3(700, 50, -400), Vector3(750, 0, 100), Vector3(400, -50, -100), Vector3(450, 50, -300), Vector3(550, 100, -350)}, TRUE);
  NewVksFlight("VksGroup_1", "pat4", SECOND:GetPosition()+Vector3(-80, 50, 0), 1, 20, Vector3(-1, 0, 0));
  flight_pat4:Patrol({FIRST:GetPosition()+Vector3(100, -50, -100), MAIN:GetPosition()+Vector3(0, 0, -200), SECOND:GetPosition()+Vector3(-80, 50, 0)}, TRUE);
  NewVksFlight("VksGroup_1", "pat5", FIRST:GetPosition()+Vector3(50, -50, -100), 1, 20, Vector3(-1, 0, 0));
  flight_pat5:Patrol({FIRST:GetPosition()+Vector3(100, -50, -100), SECOND:GetPosition()+Vector3(-80, 50, 0), MAIN:GetPosition()+Vector3(0, 0, -200)}, TRUE);
  NewVksFlight("Emperor_Group", "emp2", FIRST:GetPosition()+Vector3(110, 30, 90), 1, 20, Vector3(-1, 0, 0));
  NewVksFlight("Emperor_Group", "emp3", FIRST:GetPosition()+Vector3(110, 30, 110), 1, 20, Vector3(-1, 0, 0));
  NewVksFlight("Emperor_Group", "emp4", FIRST:GetPosition()+Vector3(110, 20, 100), 2, 20, Vector3(-1, 0, 0));
  flight_emp2:Escort(ship_emp1_1);
  flight_emp3:Escort(ship_emp1_1);
  flight_emp4:Escort(ship_emp1_1);
  NewVksFlight("Emperor_Group", "vks3", FIRST:GetPosition()+Vector3(-90, -30, -260), 1, 20, Vector3(-1, 0, 0));
  NewVksFlight("Emperor_Group", "vks4", FIRST:GetPosition()+Vector3(-90, -30, -240), 1, 19, Vector3(-1, 0, 0));
  NewVksFlight("Emperor_Group", "vks5", FIRST:GetPosition()+Vector3(-90, -40, -250), 2, 20, Vector3(-1, 0, 0));
  NewVksFlight("Emperor_Group", "vks6", FIRST:GetPosition()+Vector3(-90, -20, -250), 2, 19, Vector3(-1, 0, 0));
  flight_vks3:Escort(ship_vks1_1);
  flight_vks4:Escort(ship_vks1_1);
  flight_vks5:Escort(ship_vks1_1);
  flight_vks6:Escort(ship_vks1_1);
  NewVksFlight("Emperor_Group", "vks7", SECOND:GetPosition()+Vector3(-190, 10, -60), 1, 20, Vector3(-1, 0, 0));
  NewVksFlight("Emperor_Group", "vks8", SECOND:GetPosition()+Vector3(-190, 10, -40), 1, 19, Vector3(-1, 0, 0));
  NewVksFlight("Emperor_Group", "vks9", SECOND:GetPosition()+Vector3(-190, 0, -50), 2, 20, Vector3(-1, 0, 0));
  NewVksFlight("Emperor_Group", "vks10", SECOND:GetPosition()+Vector3(-190, 20, -50), 2, 19, Vector3(-1, 0, 0));
  flight_vks7:Escort(ship_vks2_1);
  flight_vks8:Escort(ship_vks2_1);
  flight_vks9:Escort(ship_vks2_1);
  flight_vks10:Escort(ship_vks2_1);
-- защита от преждевременной атаки
  trig_AttackVks = NewTrigger("reps", TrueCondition, failedAlarm, Player_Group, Emperor_Group, RELATION_WAR);

  MineField01_Trigger:Delete();
  MineField01_Trigger = NewTrigger("side_inside",TrueCondition,My_MineField1_Action,PLAYER_TEAM,Vector3(300,75,125), 175);
  MineField02_Trigger:Delete();
  MineField02_Trigger = NewTrigger("side_inside",TrueCondition,My_MineField2_Action,PLAYER_TEAM,Vector3(825,75,250), 175);
  MineField03_Trigger:Delete();
  MineField03_Trigger = NewTrigger("side_inside",TrueCondition,My_MineField3_Action,PLAYER_TEAM,Vector3(300,75,800), 175);
  MineField04_Trigger:Delete();
  MineField04_Trigger = NewTrigger("side_inside",TrueCondition,My_MineField4_Action,PLAYER_TEAM,Vector3(425,-25,275), 175);
  MineField05_Trigger:Delete();
  MineField05_Trigger = NewTrigger("side_inside",TrueCondition,My_MineField5_Action,PLAYER_TEAM,Vector3(425,175,275), 175);
  MineField06_Trigger:Delete();
  MineField06_Trigger = NewTrigger("side_inside",TrueCondition,My_MineField6_Action,PLAYER_TEAM,Vector3(850,250,600), 175);

-- вылет мазершипа
  CreatePortalGlow(Vector3(-500, 300, -600), Vector3(0.5, 0, 0.5), 7);
  mothership:SetPosition(Vector3(-500, 300, -600));
  mothership:SetOrientation(CreateQuaternionFromVector3(Vector3(0.5, 0, 0.5)));
  mothership:PlayFX("Portal Out.shfx");
  mothership:ApplyImpulse(15, Vector3(0.5, 0, 0.5));
  FocusOn({mothership}, Vector3(-0.2534,0.4,-0.6601), 60);
end;


--info:top=160,left=270,allvis=0;
function My_MineField1_Action()
  local MFTriggerContext = GetTriggerContext();
  local pilot = MFTriggerContext:GetPilot();
  mfa_ship = pilot:GetShip();
  MineKill(minefield_1, mfa_ship);
  if (lMission==1) then
    lMission = 0;
    Timer_Seq(1, failedAlarm);
  end;
  Timer_Seq(5, MineField_Activate);
end;


--info:top=190,left=290,allvis=0;
function My_MineField2_Action()
  local MFTriggerContext = GetTriggerContext();
  local pilot = MFTriggerContext:GetPilot();
  mfa_ship = pilot:GetShip();
  MineKill(minefield_2, mfa_ship);
  if (lMission==1) then
    lMission = 0;
    Timer_Seq(1, failedAlarm);
  end;
  Timer_Seq(5, MineField_Activate);
end;


--info:top=220,left=310,allvis=0;
function My_MineField3_Action()
  local MFTriggerContext = GetTriggerContext();
  local pilot = MFTriggerContext:GetPilot();
  mfa_ship = pilot:GetShip();
  MineKill(minefield_3, mfa_ship);
  if (lMission==1) then
    lMission = 0;
    Timer_Seq(1, failedAlarm);
  end;
  Timer_Seq(5, MineField_Activate);
end;


--info:top=190,left=490,allvis=0;
function My_MineField4_Action()
  local MFTriggerContext = GetTriggerContext();
  local pilot = MFTriggerContext:GetPilot();
  mfa_ship = pilot:GetShip();
  MineKill(minefield_4, mfa_ship);
  if (lMission==1) then
    lMission = 0;
    Timer_Seq(1, failedAlarm);
  end;
  Timer_Seq(5, MineField_Activate);
end;


--info:top=220,left=520,allvis=0;
function My_MineField5_Action()
  local MFTriggerContext = GetTriggerContext();
  local pilot = MFTriggerContext:GetPilot();
  mfa_ship = pilot:GetShip();
  MineKill(minefield_5, mfa_ship);
  if (lMission==1) then
    lMission = 0;
    Timer_Seq(1, failedAlarm);
  end;
  Timer_Seq(5, MineField_Activate);
end;


--info:top=160,left=460,allvis=0;
function My_MineField6_Action()
  local MFTriggerContext = GetTriggerContext();
  local pilot = MFTriggerContext:GetPilot();
  mfa_ship = pilot:GetShip();
  MineKill(minefield_6, mfa_ship);
  if (lMission==1) then
    lMission = 0;
    Timer_Seq(1, failedAlarm);
  end;
  Timer_Seq(5, MineField_Activate);
end;


--info:top=2770,left=70,allvis=0;
function My_MineField_Activate()
  MineField01_Trigger:Activate();
  MineField02_Trigger:Activate();
  MineField03_Trigger:Activate();
  MineField04_Trigger:Activate();
  MineField05_Trigger:Activate();
  MineField06_Trigger:Activate();
end;


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

  Timer_Seq(5, 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()

  return TRUE;
end;
