------------------------------------------------------------
--     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=80,allvis=0;
function StartMission()
  LastochkaSpeaker:Message("#L_Lastochka_01", 9, "Hero_Where");
end;


--info:top=160,left=80,allvis=0;
function Hero_Where()
  HeroSpeaker:Message("#L_Hero_01", 13);
  nav_target = CreateNavPoint("", Vector3(-500, 0, -400), "nav_default.dds", RGB(255,255,255));
  nav_current = CreateNavPoint("", mothership:GetPosition(), "nav_void.dds", RGB(255,255,255), mothership);
  LineToTarget = CreateLine(nav_current, nav_target, RGB(20,80,220), .3, TRUE, .2, 1);
  AddQuest("quest_15b_01", "#L_Quest_15b_01a", "#L_Quest_15b_01b", QUEST_PROCESS);
  NewTrigger("inside", TrueCondition, Meet_Grey, mothership, Vector3(-500, 0, -400), 75);
end;


--info:top=200,left=80,allvis=0;
function Meet_Grey()
  LineToTarget:Delete();
  nav_target:Delete();
  nav_current:Delete();
  SetNormalTimeMode();
  MothershipFlight:Stop();
  SetQuestState("quest_15b_01", QUEST_DONE);
  StartDialog("Dialog6");
end;


--info:top=240,left=80,allvis=0;
function Alex_To_Player()
--------------------------------------------------------------------------------
--  Timer_Seq(1, Anim_NewMothership);
  Timer_Seq(1, 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() >= 5) then
      choose_pilot();
    else
      Anim_NewMothership();
    end;
  else
    Anim_NewMothership();
  end; 
end;

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


--info:top=280,left=80,allvis=0;
function Anim_NewMothership()
  Change_Mathership();
  Anim_1 = CreateMovie(_ASIMUTHCAM);
  Anim_1:SetLength(8);
  Anim_1:SetInterpolate(_LINEAR);
  Anim_1:SetTarget(ship_nm1_1);
  Anim_1:InitMovie(1, TRUE, 3);
  Anim_1:AddKeys(245.0840, 71.4361, 38.48, 0);
  Anim_1:AddKeys(116.7007, 69.8231, 38.48, 8);
  Anim_1:Play();
  Anim_1:AttachEscapeScript("Alex_Done");
  Anim_1:AttachAction("Alex_Done");
end;


--info:top=310,left=120,allvis=0;
function Change_Mathership()
  mothership_old = mothership;
  mothership = SetPlayerMotherShip(ship_nm1_1);
  GetShipName(mothership);

  PortalTrigger_PORTAL_L:SetObject(mothership);
  PortalTrigger_PORTAL_R:SetObject(mothership);
  PortalTrigger_PORTAL_U:SetObject(mothership);
  PortalsActivate_Action();
  CreatePirateStationDocking(station_K,mothership,40,"pirate3",TRUE);

  AddPilotToPlayer(AlexSpeaker);
  AddPilotToPlayer(ClericSpeaker);
end;


--info:top=330,left=80,allvis=0;
function Alex_Done()
  AlexSpeaker:Message("#L_Alex_01", 4);
  Timer_Seq(3, Templars_ComeOn);
end;


--info:top=370,left=80,allvis=0;
function Templars_ComeOn()
  CreatePortalGlow(Vector3(-400, 0, -500), Vector3(-0.5, 0, 0.5), 5);
  NewTemplFlight("Templar_Group", "temp1", Vector3(-410, 0, -490), 3, 18, Vector3(-0.5, 0, 0.5));
  NewTemplFlight("Templar_Group", "temp2", Vector3(-400, 0, -510), 1, 20, Vector3(-0.5, 0, 0.5));
  NewTemplFlight("Templar_Group", "temp3", Vector3(-390, 0, -490), 1, 20, Vector3(-0.5, 0, 0.5));
  NewTemplFlight("Templar_Group", "temp4", Vector3(-400, -10, -500), 2, 20, Vector3(-0.5, 0, 0.5));
  flight_temp2:Escort(ship_temp1_1);
  flight_temp3:Escort(ship_temp1_1);
  flight_temp4:Escort(ship_temp1_1);
  ship_temp1_1:ApplyImpulse(10, Vector3(-0.5, 0, 0.5));
  Timer_Seq(5, finDialog);
end;


--info:top=410,left=80,allvis=0;
function finDialog()
  SetNormalTimeMode();
  StartDialog("Dialog7");
end;


--info:top=450,left=80,allvis=0;
function finMission()
  Timer_Seq(1, autosaveMission);
end;


--info:top=490,left=80,allvis=0;
function autosaveMission()
  Timer_Seq(1, Anim_GoTo);
  AutoSave("#AS_mission_15_4");
end;


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


--info:top=570,left=80,allvis=0;
function GoTo_Vulcan()
  lMission = 0;
  dest_location = "vulcan";
  CustomTeleportate("argon", "vulcan", "long_jump");
end;


--info:top=120,left=330,allvis=0;
function StartInitMission()
  GreyTeam = CreateTeam("Grey");
  TemplarTeam = CreateTeam("Templar");
  SetInitTeamRelation("Grey", PLAYER_TEAM, RELATION_FRIEND);

  MothershipPilot = mothership:GetPilot();
  MothershipFlight = MothershipPilot:GetFlight();
  
  Player_Group = MothershipPilot:GetGroup();
  Grey_Group = GreyTeam:CreateGroup("Grey_Group");
  Templar_Group = TemplarTeam:CreateGroup("Templar_Group");
  new_SetGroupRelations("Templar_Group", PLAYER_GROUP, "F");
  new_SetGroupRelations("Templar_Group", "Grey_Group", "F");
  
  HeroSpeaker = GetPilot("Hero");
  SedoySpeaker = GetPilot("Sedoy");
  KalemSpeaker = GetPilot("Kalem");
  LastochkaSpeaker = GetPilot("Lastochka2");
  AlexSpeaker = CreatePilot("Alex");
  Correct_Alex(AlexSpeaker);
  ClericSpeaker = CreatePilot("Cleric");
  ClericSpeaker:SetPerk("Gunnery_3");
  ClericSpeaker:SetPerk("Learner");
  ClericSpeaker:SetPerk("Missiles_3");
  ClericSpeaker:SetPerk("F_Weapon_Laser");
  ClericSpeaker:SetPerk("Systems_4");
  ClericSpeaker:SetPerk("Countermeasures_Exp");
  ClericSpeaker:SetPerk("Shields_Exp");
  ClericSpeaker:SetPerk("Piloting_3");

-- вылет мазершипа
  CreatePortalGlow(Vector3(500, 50, -400), Vector3(-1, 0, 0), 7);
  mothership:SetPosition(Vector3(500, 50, -400));
  mothership:SetOrientation(CreateQuaternionFromVector3(Vector3(-1, 0, 0)));
  mothership:PlayFX("Portal Out.shfx");
  mothership:ApplyImpulse(15, Vector3(-1, 0, 0));
  FocusOn({mothership}, Vector3(0.9135, 0.4, 0.4067), 60);
-- серые
  NewFlight("Grey_Group", "nm1", "Mothership_LionG_pl1", "GreyMaster", Vector3(-500, 35, -400), Vector3(0, 0, -1));
  NewGreyFlight("Grey_Group", "grey1", Vector3(-480, 55, -400), 1, 20, Vector3(0, 0, -1));
  ship_grey1_1:Delete();
  NewShip("grey1_1", "Gunslinger_gr3", "Natali", Vector3(-480, 55, -400), Vector3(0, 0, -1));
  flight_grey1:AddShip(ship_grey1_1);
  ship_grey1_1:SetRole(ROLE_LEADER);
  NewGreyFlight("Grey_Group", "grey2", Vector3(-480, 35, -380), 1, 20, Vector3(0, 0, -1));
  NewGreyFlight("Grey_Group", "grey3", Vector3(-520, 35, -380), 1, 19, Vector3(0, 0, -1));
  NewGreyFlight("Grey_Group", "grey4", Vector3(-500, 15, -380), 2, 19, Vector3(0, 0, -1));

  lMission = 1;

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


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


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


--info:top=160,left=330,allvis=0;
function Correct_Alex(pilot)
  pilot:SetPerk("Pilot_3");
  pilot:SetPerk("Pilot_4");
  pilot:SetPerk("Piloting_3");
  pilot:SetPerk("Gunnery_2");
  pilot:SetPerk("F_Weapon_AC");
  pilot:SetPerk("Missiles_3");
  pilot:SetPerk("Missiles_4");
  pilot:SetPerk("missile_salvo_2");
  pilot:SetPerk("missile_salvo_3");
  pilot:SetPerk("weak_spot_1");
  pilot:SetPerk("weak_spot_2");
  pilot:SetPerk("polarization_2");
  pilot:SetPerk("polarization_3");
  pilot:SetPerk("depolarization_1");
  pilot:SetPerk("depolarization_2");
  pilot:SetPerk("Systems_2");
  pilot:SetPerk("Systems_3");
  pilot:SetPerk("Countermeasures");
  pilot:SetPerk("Repairman");
  pilot:SetPerk("Shields_Op");
  pilot:SetPerk("Engine_Op");
end;


--info:top=80,left=80,allvis=0;
function ACTION_INIT()
  StartInitMission();

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


--info:top=80,left=570,allvis=0;
function ACTION_LEAVELOCATION()
  if (lMission==1) then
    Terminate();
  elseif (dest_location=="vulcan") then
    tmpNull:Delete();
    SetQuestLabel("VulcanPermit", "yes");
    QuestActionDone();
    QuestStart("mission_16d");
  else
    Terminate();
  end;

  return TRUE;
end;


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

  return TRUE;
end;
