------------------------------------------------------------
--     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()
  StartDialog("Dialog2");
end;


--info:top=160,left=120,allvis=0;
function Josef_Dialog()
  LineToJoe:Delete();
  LineToJoe = NIL;
  LineToTarget:Delete();
  LineToTarget = CreateLine(np_Joe, nav_target, RGB(20,80,220), .3, TRUE, .2, 1);
  SetQuestLabel("Josef", "yes");
  SetNormalTimeMode();
  MothershipFlight:Stop();
--------------------------------------------------------------------------------
--  StartDialog("Dialog3");
  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("Dialog3");
    end;
  else
    StartDialog("Dialog3");
  end; 
end;

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


--info:top=210,left=170,allvis=0;
function Josef_ComeOn()
  SetQuestLabel("QuestPoint", "1");
  trig_Only:Delete();
  trig_Only = NewTrigger("inside", TrueCondition, Start_With_Josef, mothership, Vector3(-100, 50, 200), 70);
  ship1 = CreateCarcass("Stormcrow_mk2_hunt3", JOE:GetPosition()+Vector3(5, 3, 0), Vector3(1,0,0)); 
  ship1:AssignPilot(JosefSpeaker);
  JosefFlight = Player_Group:CreateFlight("JosefFlight");
  JosefFlight:AddShip(ship1);
  JosefFlight:Escort(mothership);
end;


--info:top=210,left=60,allvis=0;
function Josef_No()
  SetQuestLabel("QuestPoint", "2");
  if (GetQuestLabel("Quest3Path")=="Prizrak") then
    LastochkaSpeaker:Message("#L_Lastochka_04", 6);
  else
    LastochkaSpeaker:Message("#L_Lastochka_05", 6);
  end;
end;


--info:top=280,left=220,allvis=0;
function Start_With_Josef()
  LineToTarget:Delete();
  LineToTarget = NIL;
  SetNormalTimeMode();
  MothershipFlight:Stop();
  SetQuestLabel("Block_X213", "no");
  SetQuestState("quest_10_01", QUEST_DONE);
  if (GetQuestLabel("Quest3Path")=="Prizrak") then
    StartDialog("Dialog4");
  else
    StartDialog("Dialog5");
  end;
end;


--info:top=320,left=220,allvis=0;
function GoTo_X220()
  SetQuestLabel("QuestPoint", "3");
  LineToPortal = CreateLine(nav_target, NP_PORTAL_L, RGB(20,80,220), .3, TRUE, .2, 1);
  AddQuest("quest_10_02", "#L_Quest_10_02a", "#L_Quest_10_02b", QUEST_PROCESS);
  if (GetQuestLabel("Quest3Path")=="Prizrak") then
    ship_ph2_1:ComeToPortal(PORTAL_L);
    NewTrigger("f_object_inside", trigger_inside2portal_Condition, Portal_Action, flight_ph2, PORTAL_L, 20);
    AddQuest("quest_10_04", "#L_Quest_10_04a", "#L_Quest_10_04b", QUEST_PROCESS);
  else
    flight_hr1:Escort(mothership);
    AddQuest("quest_10_05", "#L_Quest_10_05a", "#L_Quest_10_05b", QUEST_PROCESS);
  end;
end;


--info:top=370,left=310,allvis=0;
function Portal_Action()
  trig_PhDied:Delete();
  flight_ph1:Delete();
  flight_ph2:Delete();
end;


--info:top=280,left=390,allvis=0;
function Start_Without_Josef()
  if (LineToJoe) then LineToJoe:Delete(); end;
  if (trig_Josef) then trig_Josef:Delete(); end;
  LineToTarget:Delete();
  LineToTarget = NIL;
  SetNormalTimeMode();
  MothershipFlight:Stop();
  SetQuestLabel("Block_X213", "no");
  SetQuestState("quest_10_01", QUEST_DONE);
  if (GetQuestLabel("Quest3Path")=="Prizrak") then
    StartDialog("Dialog6");
  else
    StartDialog("Dialog7");
  end;
end;


--info:top=320,left=390,allvis=0;
function GoTo_X213()
  SetQuestLabel("QuestPoint", "4");
  LineToPortal = CreateLine(nav_target, NP_PORTAL_U, RGB(20,80,220), .3, TRUE, .2, 1);
  AddQuest("quest_10_03", "#L_Quest_10_03a", "#L_Quest_10_03b", QUEST_PROCESS);
  if (GetQuestLabel("Quest3Path")=="Prizrak") then
    ship_ph2_1:ComeToPortal(PORTAL_U);
    NewTrigger("f_object_inside", trigger_inside2portal_Condition, Portal_Action, flight_ph2, PORTAL_U, 20);
    AddQuest("quest_10_04", "#L_Quest_10_04a", "#L_Quest_10_04b", QUEST_PROCESS);
  else
    flight_hr1:Escort(mothership);
    AddQuest("quest_10_05", "#L_Quest_10_05a", "#L_Quest_10_05b", QUEST_PROCESS);
  end;
end;


--info:top=120,left=310,allvis=0;
function StartInitMission()
  MercTeam = CreateTeam("Merc");
  
  MothershipPilot = mothership:GetPilot();
  MothershipFlight = MothershipPilot:GetFlight();
  
  Player_Group = MothershipPilot:GetGroup();
  Merc_Group = MercTeam:CreateGroup("Merc_Group");
  
  HeroSpeaker = GetPilot("Hero");
  LastochkaSpeaker = GetPilot("Lastochka");
  SedoySpeaker = GetPilot("Sedoy");
  JosefSpeaker = CreatePilot("Josef");
  PhantomSpeaker = CreatePilot("m10_Phantom");
  HereticSpeaker = CreatePilot("m10_Heretic");

  if (lMission=="0") then
    LineToJoe = CreateLine(NP_PORTAL_R, np_Joe, RGB(20,80,220), .3, TRUE, .2, 1);
    trig_Josef = NewTrigger("inside", TrueCondition, Josef_Dialog, mothership, JOE:GetPosition(), 70);
  end;
  if (GetQuestLabel("Quest3Path")=="Prizrak") then
    SetQuestLabel("ShipsCount", "3");
    nav_target = CreateNavPoint("#L_Phantom", Vector3(-100, 50, 200), "nav_default.dds", RGB(255,255,255));
    NewFlight("Merc_Group", "ph1", "Trident_Phantom", "m10_Phantom", Vector3(-100, 50, 200), Vector3(1, 0, 0));
    NewFlight("Merc_Group", "ph2", "Arba", "OthersOfficer", Vector3(-120, 50, 200), Vector3(1, 0, 0));
    NewShip("ph2_2", "Arba", "OthersOfficer", Vector3(-140, 50, 220), Vector3(1, 0, 0));
    flight_ph2:AddShip(ship_ph2_2);
    NewShip("ph2_3", "Arba", "OthersOfficer", Vector3(-140, 50, 180), Vector3(1, 0, 0));
    flight_ph2:AddShip(ship_ph2_3);
    flight_ph1:Escort(ship_ph2_1);
    trig_PhDied = NewTrigger("f_died", TrueCondition, Mass_Attack, flight_ph1);
  else
    nav_target = CreateNavPoint("#L_Heretic", Vector3(-100, 50, 200), "nav_default.dds", RGB(255,255,255));
    NewFlight("Merc_Group", "hr1", "EvilEye_mk2_Heretic", "m10_Heretic", Vector3(-100, 50, 200), Vector3(1, 0, 0));
    NewTrigger("f_died", TrueCondition, Mass_Attack, flight_hr1);
  end;
  NewTrigger("reps", TrueCondition, Failure_Quest, Player_Group, Merc_Group, RELATION_WAR);
  LineToTarget = CreateLine(NP_PORTAL_R, nav_target, RGB(20,80,220), .3, TRUE, .2, 1);
  if (lMission=="1") then
    trig_Only = NewTrigger("inside", TrueCondition, Start_With_Josef, mothership, Vector3(-100, 50, 200), 70);
  else
    trig_Only = NewTrigger("inside", TrueCondition, Start_Without_Josef, mothership, Vector3(-100, 50, 200), 70);
  end;
  SetQuestLabel("Josef", "no");
end;


--info:top=190,left=430,allvis=0;
function Mass_Attack()
  if (GetQuestState("quest_10_4")==QUEST_PROCESS) then SetQuestState("quest_10_4", QUEST_FAILED); end;
  if (GetQuestState("quest_10_5")==QUEST_PROCESS) then SetQuestState("quest_10_5", QUEST_FAILED); end;
  SysSpeaker = CreatePilot("Hint");
  if (GetQuestLabel("Quest3Path")=="Prizrak") then
    SysSpeaker:Message("#L_sys_02", 5, "Fin_Game");
  else
    SysSpeaker:Message("#L_sys_03", 5, "Fin_Game");
  end;
end;


--info:top=190,left=580,allvis=0;
function Failure_Quest()
  SysSpeaker = CreatePilot("Hint");
  SysSpeaker:Message("#L_sys_01", 8, "Fin_Game");
end;


--info:top=230,left=580,allvis=0;
function Fin_Game()
  EndGame("gamefailed");
end;


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

  if (lMission=="0") then
    Timer_Seq(4, StartMission);
  end;
  return TRUE;
end;


--info:top=80,left=570,allvis=0;
function ACTION_LEAVELOCATION()
  if (LineToTarget) then LineToTarget:Delete(); end;
  if (LineToJoe) then LineToJoe:Delete(); end;
  if (LineToPortal) then LineToPortal:Delete(); end;
  nav_target:Delete();
  RemovePost("mail_010_1");
  RemovePost("mail_010_2");
  RemovePost("mail_010_3");
  lMission = GetQuestLabel("QuestPoint");
  if (lMission=="3") then
    SetQuestLabel("QuestPoint", "0");
    QuestActionDone();
    QuestStart("mission_10_2");
  elseif (lMission=="4") then
    SetQuestLabel("QuestPoint", "0");
    QuestActionDone();
    if (GetQuestLabel("Quest3Path")=="Prizrak") then
      QuestStart("mission_10_1");
    elseif (dest_location=="x213") then
      QuestStart("mission_10_1");
    else
      QuestStart("mission_10_2");
    end;
  end;

  return TRUE;
end;


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

  return TRUE;
end;
