------------------------------------------------------------
--     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=170,left=230,allvis=0;
function StartMission()
  SetNormalTimeMode();
  MothershipFlight:Stop();
  LineToStation:Delete();
  Teleporter:Delete();
  Teleporter = CreateTrigger();
  Teleporter:AttachEvent(_EVENT_TIMER); 
  Teleporter:SetTime(3);
  Teleporter:AttachCondition(TrueCondition);
  Teleporter:AttachAction(My_TeleporterAction);
  PortalTrigger_RAND_PORTAL_Activate:Delete();
  PortalTrigger_RAND_PORTAL_Activate = CreateTrigger();
  PortalTrigger_RAND_PORTAL_Activate:AttachEvent(_EVENT_INSIDEVOLUME);
  PortalTrigger_RAND_PORTAL_Activate:SetObject(mothership);
  PortalTrigger_RAND_PORTAL_Activate:SetVolume(RAND_PORTAL:GetPosition(), 150);
  PortalTrigger_RAND_PORTAL_Activate:AttachCondition(TrueCondition);
  PortalTrigger_RAND_PORTAL_Activate:AttachAction(Random_Activate);
  SetQuestState("quest_8e_01", QUEST_DONE);
  RemovePost("mail_008e_1");
  if (GetLevelDifficult()==HARD) then
    StartDialog("Dialog1");
  elseif (GetLevelDifficult()==NORMAL) then
    StartDialog("Dialog11");
  else
    StartDialog("Dialog12");
  end;
end;


--info:top=240,left=370,allvis=0;
function My_TeleporterAction()
  SetInitTeamRelation("Inoco",PLAYER_TEAM,GetGroupRelation(InocoGroup_1,PLAYER_GROUP));
  if (dest_location=="heos") then
    mylast_location = "danstag";
    mydest_location = "moscowia";
    myvideo = "random_jump";
    CustomTeleportate(mylast_location,mydest_location,myvideo);
  else
    TeleportToLocation(dest_location);
  end;
end;


--info:top=270,left=370,allvis=0;
function Random_Activate()
  SetNormalTimeMode();
  dest_location = "xt54";
  RAND_PORTAL:AddMeshFX("PARTICLESYSTEM","portal_vortex.pst");
  PortalTrigger_RAND_PORTAL_Deactivate:Activate();
  StartDialog("Dialog2");
end;


--info:top=280,left=260,allvis=0;
function Dikkens_No()
  flight_ino1:Escort(mothership);
  flight_ino2:Escort(mothership);
  flight_ino3:Escort(mothership);
  LineToPortal = CreateLine(np_war, NP_PORTAL_R, RGB(20,80,220), .3,TRUE,.2, 1);
  local pos_ms = mothership:GetPosition();
  local pos_tg = PORTAL_R:GetPosition();
  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_Escape = NewTrigger("outside", TrueCondition, Try_Escape, mothership, center, dist+25);
  local mindist = dist-25;
  if (mindist<0) then mindist=0; end;
  trig_Approach = NewTrigger("inside", TrueCondition, Reinit_Approch, mothership, center, mindist);
end;


--info:top=360,left=310,allvis=0;
function Try_Escape()
  new_SetGroupRelations("Inoco_Group",Player_Group,"W");
end;


--info:top=320,left=310,allvis=0;
function Reinit_Approch()
  local v_target = PORTAL_R:GetPosition();
  local v_ship = mothership: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_Escape:Delete();
  trig_Approach:Delete();
  if (distance>25) then
    distance = distance/2;
    trig_Escape = NewTrigger("outside", TrueCondition, Try_Escape, mothership, v_center, distance+25);
    local mindistance = distance-25;
    if (mindistance<0) then mindistance=0; end;
    trig_Approach = NewTrigger("inside", TrueCondition, Reinit_Approch, mothership, v_center, mindistance);
  end;
end;


--info:top=280,left=150,allvis=0;
function Dikkens_Yes()
  PortalTrigger_RAND_PORTAL_Activate:Activate();
  PortalTrigger_RAND_PORTAL:Activate();
  if (GetQuestLabel("OnRandomPortal_all")~="yes") then
    SetQuestLabel("OnRandomPortal_3","already");
    SetQuestLabel("OnRandomPortal_all","yes");
    NP_PORTAL_RAND = CreateNavPoint("#M_portal_to_random", RAND_PORTAL:GetPosition(), "nav_rndportal.dds", RGB(255,255,255), RAND_PORTAL);
  else
    if (GetQuestLabel("OnRandomPortal_3")~="already") then
      SetQuestLabel("OnRandomPortal_3","already");
      NP_PORTAL_RAND = CreateNavPoint("#M_portal_to_random", RAND_PORTAL:GetPosition(), "nav_rndportal.dds", RGB(255,255,255), RAND_PORTAL);
    else
      NP_PORTAL_RAND = CreateNavPoint("#M_portal_to_random", RAND_PORTAL:GetPosition(), "nav_void.dds", RGB(255,255,255));
    end;
  end;
  if (GetLevelDifficult()==HARD) then
    AddPlayerCredits(300000);
  elseif (GetLevelDifficult()==NORMAL) then
    AddPlayerCredits(750000);
  else
    AddPlayerCredits(1500000);
  end;
  flight_ino1:Escort(mothership);
  flight_ino2:Escort(mothership);
  flight_ino3:Escort(mothership);
  LineToPortal = CreateLine(np_war, NP_PORTAL_RAND, RGB(20,80,220), .3,TRUE,.2, 1);
  AddQuest("quest_8e_02", "#L_Quest_8e_02a", "#L_Quest_8e_02b", QUEST_PROCESS);
end;


--info:top=120,left=80,allvis=0;
function StartInitMis()
  InocoTeam = CreateTeam("Inoco");

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

  Player_Group = MothershipPilot:GetGroup();
  Inoco_Group = InocoTeam:CreateGroup("Inoco_Group");
  new_SetGroupRelations("Inoco_Group",PLAYER_GROUP,"N");

  HeroSpeaker = GetPilot("Hero");
  LastochkaSpeaker = GetPilot("Lastochka");
  SedoySpeaker = GetPilot("Sedoy");

  NewInocoFlight("Inoco_Group", "ino1", WAR:GetPosition()+Vector3(40,-10,-70), 1, 14, Vector3(-0.5,0,-0.5));
  NewInocoFlight("Inoco_Group", "ino2", WAR:GetPosition()+Vector3(40,-10,-80), 1, 13, Vector3(-0.5,0,-0.5));
  NewInocoFlight("Inoco_Group", "ino3", WAR:GetPosition()+Vector3(40,-10,-60), 1, 13, Vector3(-0.5,0,-0.5));

  LineToStation = CreateLine(NP_PORTAL_R, np_war, RGB(20,80,220), .3,TRUE,.2, 1);
  NewTrigger("inside", TrueCondition, StartMission, mothership, WAR:GetPosition(), 140);
  NewTrigger("reps", TrueCondition, If_Attack_InoCo, Player_Group, Inoco_Group, RELATION_WAR);
end;


--info:top=350,left=80,allvis=0;
function If_Attack_InoCo()
  NewInocoFlight("Inoco_Group", "ino10", mothership:GetPosition()+Vector3(60,10,60), 1, 17, Vector3(-0.5,0,-0.5));
  count = flight_ino10:GetPilotCount();
  for i=0,count,1 do
    pilot_tmp = flight_ino10:GetPilotByNumber(i);
    ship_tmp = pilot_tmp:GetShip();
    ship_tmp:PlayFX("Cloak Out.shfx");
  end;
  NewInocoFlight("Inoco_Group", "ino11", mothership:GetPosition()+Vector3(-60,10,60), 1, 17, Vector3(0.5,0,-0.5));
  count = flight_ino11:GetPilotCount();
  for i=0,count,1 do
    pilot_tmp = flight_ino11:GetPilotByNumber(i);
    ship_tmp = pilot_tmp:GetShip();
    ship_tmp:PlayFX("Cloak Out.shfx");
  end;
  Anim_D = CreateMovie(_TARGETCAM);
  Anim_D:SetLength(6);
  Anim_D:SetInterpolate(_LINEAR);
  Anim_D:SetTarget(mothership);
  Anim_D:InitMovie(1, TRUE, 1);
  Anim_D:AddPosKey(mothership:GetPosition()+Vector3(60, 30, -30), 0);
  Anim_D:AddScriptKey("MShip_Blow", 4);
  Anim_D:Play();
  Anim_D:AttachEscapeScript("MShip_Blow");
  Anim_D:AttachAction("MShip_Blow");
end;


--info:top=390,left=80,allvis=0;
function MShip_Blow()
  if (mothership:IsAlive()) then
    mothership:Blow();
  end;
end;


--info:top=80,left=80,allvis=0;
function ACTION_INIT()
  StartInitMis();
  SetQuestLabel("CurrentQuest","8e");

  return TRUE;
end;


--info:top=80,left=570,allvis=0;
function ACTION_LEAVELOCATION()
  if (GetQuestState("quest_8e_01")==QUEST_PROCESS) then
    LineToStation:Delete();
  elseif (dest_location=="xt54") then
    LineToPortal:Delete();
    AddPost("book008e_2");
    QuestActionDone();
  else
    if (GetQuestState("quest_8e_02")==QUEST_PROCESS) then SetQuestState("quest_8e_02", QUEST_FAILED); end;
    AddPost("book008e_1");
    QuestActionDone();
    ClearQuests();
    QuestStart("mission_8e_03");
  end;

  return TRUE;
end;


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

  return TRUE;
end;
