//-------------------------------------------------------------------
//
//  This code is copyright 2001 by G5 Software.
//  Any unauthorized usage, either in part or in whole of this code
//  is strictly prohibited. Violators WILL be prosecuted to the
//  maximum extent allowed by law.
//
//-------------------------------------------------------------------

class CEliminateDescentMission extends
  CBaseMission, CEliminateDescentMissionObjectList, CEliminateDescentMission_Strings,
  CNavPointUser, CGermanParatrooperGenerator

{
  int GetAutoGeneratedUnitsQty()
  {
    return 6;
  }

  void CEliminateDescentMission()
  {
    BaseMission_InitMission();

    BaseMission_UpdateLoadProgress();
    CreateComponent("DebugCamera", "GameObject", "CDebugCamera");
    SetComponentPosition("DebugCamera",
      matrix(
        1.0, 0.0, 0.0, 8000.0,
        0.0, 1.0, 0.0, 8000.0,
        0.0, 0.0, 1.0,  600.0,
        0.0, 0.0, 0.0,    1.0
      ));

    // CreateComponent(IDToRegister, ComponentID, ScriptName | FileName | "")
    BaseMission_UpdateLoadProgress();
    CreateComponent("Atmosphere", "Atmosphere", "CEliminateDescentMission_Atmosphere");

    BaseMission_UpdateLoadProgress();
    CreateComponent("Sky", "SkyObject", "CEliminateDescentMission_Sky");

    BaseMission_UpdateLoadProgress();
    CreateComponent("Terrain", "ProgressiveTerrainObject", "CEliminateDescentMission_Terrain");

    BaseMission_UpdateLoadProgress();
    CreateComponent("Forest", "Forest", "CEliminateDescentMission_Forest");

    BaseMission_UpdateLoadProgress();
    CreateComponent( "AIController", "AIController", "CMission14_AIController");

    BaseMission_CreateObjects();
  }

  //
  //  'virtual' methods
  //

  //
  //  Objectives

  array m_MissionObjectivesStatuses =
          array(
            str_ObjectiveInProgress,
            str_ObjectiveInProgress,
            str_ObjectiveInProgress,
            str_ObjectiveInProgress
          );

  array m_BonusMissionObjectivesStatuses =
          array(
            str_ObjectiveInProgress
                  );

  //
  //  Mission statistics

  string GetMissionStatistics()
  {
    return str_StatisticsTitle;
  }

  //
  //  Mission navpoints

  array GetNavPoints()
  {
    array navpoints =
      array(
        GetNavPoint("NavPoint_01"),     // Crossroad position
        GetNavPoint("NavPoint_02"),     // Benghazi position
        GetNavPoint("NavPoint_03"),     // Al-Bwairat position
        GetNavPoint("NavPoint_04")      // Zillah position
      );
    return navpoints;
  }

  //
  //  Mission map skin file

  string GetMapSkinFileName()
  {
    return "Missions/Mission_14/Map.skin";
  }

  int m_ZillahToLanding   = 11;
  int m_BenghaziToLanding = 11;
  int m_BwairatToLanding  = 8;
  int m_RoadFlakLost      = 8;
  int m_CrossRoadLost     = 15;

  int m_ZillahDropped   = 0;
  int m_BenghaziDropped = 0;
  int m_BwairatDropped  = 0;

  int m_ZillahLanded   = 0;
  int m_BenghaziLanded = 0;
  int m_BwairatLanded  = 0;

  int m_ZillahKilled    = 0;
  int m_BenghaziKilled  = 0;
  int m_BwairatKilled   = 0;
  int m_RoadFlakKilled  = 0;
  int m_CrossRoadKilled = 0;

  boolean m_IsZillahLanded   = false;
  boolean m_IsBenghaziLanded = false;
  boolean m_IsBwairatLanded  = false;

  boolean Objective1      = false;
  boolean Objective2      = false;
  boolean Objective3      = false;
  boolean Objective4      = false;
  boolean BonusObjective1 = false;

  string m_ZillahScript   = "C14_ZillahDescent";
  string m_BenghaziScript = "C14_BenghaziDescent";
  string m_BwairatScript  = "C14_BwairatDescent";

  void ZillahDescentArrival()
    {
      BaseMission_DelayedQuit();
    }
  void BenghaziDescentArrival()
    {
      BaseMission_DelayedQuit();
    }
  void BwairatDescentArrival()
    {
      BaseMission_DelayedQuit();
    }

  void OnGameObjectDestroyed(string _id)
   {
     BaseMission_OnGameObjectDestroyed(_id);
     Core_BroadcastEvent( "Unit_Destroyed", _id);

     if ( Core_IsStringStartsWith( _id, "14_Zillah" ) )
      {
  //     if ( m_IsZillahLanded )
//        {
            m_ZillahKilled = m_ZillahKilled + 1;
            if ( (m_ZillahKilled >= m_ZillahLanded) && m_IsZillahLanded && (!Objective1) )
             {
               Objective1 = true;
               BaseMission_CompleteObjective(0);
             }
//        }
      }
     if ( Core_IsStringStartsWith( _id, "14_Benghazi" ) )
      {
//       if ( m_IsBenghaziLanded )
//        {
         m_BenghaziKilled = m_BenghaziKilled + 1;
//        Core_LogMessage("Benghazi troopers has killed. Amount "+m_ZillahKilled);
         if ( (m_BenghaziKilled >= m_BenghaziLanded) && m_IsBenghaziLanded && (!Objective2) )
          {
             Objective2 = true;
             BaseMission_CompleteObjective(1);
//             Core_LogMessage("Benghazi troopers has killed: "+m_ZillahKilled);
          }
//        }
      }
     if ( Core_IsStringStartsWith( _id, "14_Bwairat" ) )
      {
//       if ( m_IsBwairatLanded )
//        {
         m_BwairatKilled = m_BwairatKilled + 1;
//        Core_LogMessage("Benghazi troopers has killed. Amount "+m_ZillahKilled);
         if ( (m_BwairatKilled >= m_BwairatLanded) && m_IsBwairatLanded && (!Objective3) )
          {
             Objective3 = true;
             BaseMission_CompleteObjective(2);
//             Core_LogMessage("Benghazi troopers has killed: "+m_ZillahKilled);
          }
//        }
      }
     if ( Core_IsStringStartsWith( _id, "14_CrossRoad" ) )
      {
        m_CrossRoadKilled = m_CrossRoadKilled + 1;
//        Core_LogMessage("Crossroad guard has killed. Amount "+m_CrossRoadKilled);
        if ( (m_CrossRoadKilled >= m_CrossRoadLost) && (!Objective4) )
          {
//             Core_LogMessage("Crossroad guard has killed all with "+m_CrossRoadKilled+" units");
             BaseMission_CompleteObjective(3);
          }
      }
     if ( Core_IsStringStartsWith( _id, "14_RoadFlak" ) )
      {
        m_RoadFlakKilled = m_RoadFlakKilled + 1;
        if ( (m_RoadFlakKilled >= m_RoadFlakLost) && (!BonusObjective1) )
          {
             BonusObjective1 = true;
             BaseMission_CompleteBonusObjective(0);
          }
      }
   }
   //--------------------------------------------------------------------------//
 void OnParatrooperGroupLanded( boolean _IsLanded, string _LandedID )
  {
//     Core_LogMessage("Group was landed with name - "+_LandedID+" and with alive - "+_IsLanded);
     if ( Core_IsStringStartsWith( _LandedID, "14_Zillah" ) )
      {
        if ( _IsLanded)
         {
           SetBehaviorTask(_LandedID, m_ZillahScript);
           Core_SendEventTo(_LandedID, "OnStartBehavior");
           m_ZillahLanded = m_ZillahLanded + 1;
         }

        m_ZillahDropped = m_ZillahDropped + 1;
        if ( m_ZillahDropped >= m_ZillahToLanding )
         {
          m_IsZillahLanded = true;
          if ( m_ZillahLanded == 0 )
            {
              Objective1 = true;
              BaseMission_CompleteObjective(0);
//              Core_LogMessage("Zillah dropped with: "+m_ZillahDropped+" paratroopers");
//              Core_LogMessage("Zillah landed with: "+m_ZillahLanded+" paratroopers");
            }
//          Core_LogMessage("Zillah dropped with: "+m_ZillahDropped+" paratroopers");
//          Core_LogMessage("Zillah landed with: "+m_ZillahLanded+" paratroopers");
         }
      }
     if ( Core_IsStringStartsWith( _LandedID, "14_Benghazi" ) )
      {
        if ( _IsLanded)
         {
           SetBehaviorTask(_LandedID, m_BenghaziScript);
           Core_SendEventTo(_LandedID, "OnStartBehavior");
           m_BenghaziLanded = m_BenghaziLanded + 1;
         }

        m_BenghaziDropped = m_BenghaziDropped + 1;
        if ( m_BenghaziDropped >= m_BenghaziToLanding )
         {
          m_IsBenghaziLanded = true;
          if ( m_BenghaziLanded == 0 )
            {
              Objective2 = true;
              BaseMission_CompleteObjective(1);
            }
         }
      }
     if ( Core_IsStringStartsWith( _LandedID, "14_Bwairat" ) )
      {
        if ( _IsLanded)
         {
           SetBehaviorTask(_LandedID, m_BwairatScript);
           Core_SendEventTo(_LandedID, "OnStartBehavior");
           m_BwairatLanded = m_BwairatLanded + 1;
         }

        m_BwairatDropped = m_BwairatDropped + 1;
        if ( m_BwairatDropped >= m_BwairatToLanding )
         {
          m_IsBwairatLanded = true;
          if ( m_BenghaziLanded == 0 )
            {
              Objective3 = true;
              BaseMission_CompleteObjective(2);
            }
         }
      }
  }

  void OnMissionLoaded()
  {
    Core_SendEventTo("Helicopter", "OnInitiallyEnableTargetScreen", false);

    // Start mission music playing
    Core_SendEventTo(SOID_MusicController, "PlayMissionMusic", 14);
  }
}
