//-------------------------------------------------------------------
//
//  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 CDestroyMission extends
  CBaseMission, CDestroyMissionObjectList, CDestroyMission_Strings, CNavPointUser
{
  int GetAutoGeneratedUnitsQty()
  {
    return 6;
  }

  void CDestroyMission()
  {
    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", "CDestroyMission_Atmosphere");

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

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

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

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

    BaseMission_CreateObjects();

    //
    //  Mission specific
    //

    // count how many 1st and 2nd objectives' objects are in the mission
    array m_Objects = GetObjectsIDs();

    m_Village1Count    = 0;
    m_Village2Count    = 0;
    m_Village3Count    = 0;
    m_Village4Count    = 0;
    m_TanksCount       = 0;
    m_BonusCount       = 0;
    m_EnemiesDestroyed = 0;

    for (int i = 0; i < m_Objects.size(); i = i + 1)
    {
      if (Core_IsStringStartsWith(m_Objects[i], "AntiAirObj1"))
        m_Village1Count = m_Village1Count + 1;

      if (Core_IsStringStartsWith(m_Objects[i], "AntiAirObj2"))
        m_Village2Count = m_Village2Count + 1;

      if (Core_IsStringStartsWith(m_Objects[i], "AntiAirObj3"))
        m_Village3Count = m_Village3Count + 1;

      if (Core_IsStringStartsWith(m_Objects[i], "AntiAirObj4"))
        m_Village4Count = m_Village4Count + 1;

      if (Core_IsStringStartsWith(m_Objects[i], "TankObj6"))
        m_TanksCount = m_TanksCount + 1;

      if (Core_IsStringStartsWith(m_Objects[i], "AntiAirObj5"))
        m_BonusCount = m_BonusCount + 1;
    }
  }

  //
  //  Mission specific variables
  //

  int  m_Village1Count;
  int  m_Village2Count;
  int  m_Village3Count;
  int  m_Village4Count;
  int  m_TanksCount;
  int  m_BonusCount;
  int  m_EnemiesDestroyed;

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

  array m_BonusMissionObjectivesStatuses =
          array(
            str_ObjectiveInProgress
          );

  //
  //  virtual methods
  //

  //
  //  Mission statistics

  string GetMissionStatistics()
  {
    return str_StatisticsTitle + m_EnemiesDestroyed;
  }

  //
  //  Mission navpoints

  array GetNavPoints()
  {
    array navpoints =
      array(
          GetNavPoint("NavPoint_Suglobovka"),
          GetNavPoint("NavPoint_Tabunovka"),
          GetNavPoint("NavPoint_Rymino"),
          GetNavPoint("NavPoint_Koloskovo"),
          GetNavPoint("NavPoint_Schultz"),
          GetNavPoint("NavPoint_Gadyukino")
//        vector(9731.0,  3326.0,  1000.0),
//        vector(8127.0,  1203.0,  1000.0),
//        vector(7453.0,  5589.0,  1000.0),
//        vector(5132.0,  4513.0,  1000.0),
//        vector(4457.0,  10883.0, 1000.0),
//        vector(11923.0, 2204.0,  1000.0)
      );
    return navpoints;
  }

  //
  //  Mission map skin file

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

  //
  //  Mission specific event handlers
  //

  //
  //  Object destroyed event handler
  //

  void OnGameObjectDestroyed(string _id)
  {
    BaseMission_OnGameObjectDestroyed(_id);

    if (Core_IsStringStartsWith(_id, "AntiAirObj1"))
    {
      m_Village1Count = m_Village1Count - 1;
      m_EnemiesDestroyed = m_EnemiesDestroyed + 1;
    }

    if (Core_IsStringStartsWith(_id, "AntiAirObj2"))
    {
      m_Village2Count = m_Village2Count - 1;
      m_EnemiesDestroyed = m_EnemiesDestroyed + 1;
    }

    if (Core_IsStringStartsWith(_id, "AntiAirObj3"))
    {
      m_Village3Count = m_Village3Count - 1;
      m_EnemiesDestroyed = m_EnemiesDestroyed + 1;
    }

    if (Core_IsStringStartsWith(_id, "AntiAirObj4"))
    {
      m_Village4Count = m_Village4Count - 1;
      m_EnemiesDestroyed = m_EnemiesDestroyed + 1;
    }

    if (Core_IsStringStartsWith(_id, "AntiAirObj5"))
    {
      m_BonusCount = m_BonusCount - 1;
      m_EnemiesDestroyed = m_EnemiesDestroyed + 1;
    }

    if (Core_IsStringStartsWith(_id, "TankObj6"))
    {
      m_TanksCount = m_TanksCount - 1;
    }

    if (m_Village1Count == 0)
     BaseMission_CompleteObjective(0);

    if (m_Village2Count == 0)
      BaseMission_CompleteObjective(1);

    if (m_Village3Count == 0)
      BaseMission_CompleteObjective(2);

    if (m_Village4Count == 0)
      BaseMission_CompleteObjective(3);

    if (m_TanksCount == 0)
      BaseMission_CompleteObjective(4);

    if (m_BonusCount == 0)
      BaseMission_CompleteBonusObjective(0);
  }

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

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