//-------------------------------------------------------------------
//
//  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 CDrawAttentionMission extends
  CBaseMission, CDrawAttentionMissionObjectList, CDrawAttentionMission_Strings, CNavPointUser
{
  int GetAutoGeneratedUnitsQty()
  {
    return 6;
  }

  void CDrawAttentionMission()
  {
    BaseMission_InitMission();

    BaseMission_UpdateLoadProgress();
    CreateComponent("DebugCamera", "GameObject", "CDebugCamera");
    SetComponentPosition("DebugCamera",
      matrix(
        1.0, 0.0, 0.0, 6090.0,
        0.0, 1.0, 0.0, 5800.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", "CDrawAttentionMission_Atmosphere");

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

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

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

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

    BaseMission_CreateObjects();

   // Platoon ranking
   SetBehaviorGroupRank( "11_Platoon_01", "Platoon_Rank", 1);
   SetBehaviorGroupRank( "11_Platoon_02", "Platoon_Rank", 2);
   SetBehaviorGroupRank( "11_Platoon_03", "Platoon_Rank", 3);
   SetBehaviorGroupRank( "11_Platoon_04", "Platoon_Rank", 4);
   SetBehaviorGroupRank( "11_Platoon_05", "Platoon_Rank", 5);
   SetBehaviorGroupRank( "11_Platoon_06", "Platoon_Rank", 6);
   SetBehaviorGroupRank( "11_Platoon_07", "Platoon_Rank", 7);
   SetBehaviorGroupRank( "11_Platoon_08", "Platoon_Rank", 8);

   // Soviet Tank ranking
   SetBehaviorGroupRank( "11_Soviet_Tank_01", "SovietTank_Rank", 1);
   SetBehaviorGroupRank( "11_Soviet_Tank_02", "SovietTank_Rank", 2);
   SetBehaviorGroupRank( "11_Soviet_Tank_03", "SovietTank_Rank", 3);
   SetBehaviorGroupRank( "11_Soviet_Tank_04", "SovietTank_Rank", 4);

   // Soviet Katusha ranking
   SetBehaviorGroupRank( "11_Katusha_01", "SovietKatusha_Rank", 1);
   SetBehaviorGroupRank( "11_Katusha_02", "SovietKatusha_Rank", 2);
   SetBehaviorGroupRank( "11_Katusha_03", "SovietKatusha_Rank", 3);
   SetBehaviorGroupRank( "11_Katusha_04", "SovietKatusha_Rank", 4);
   SetBehaviorGroupRank( "11_Katusha_05", "SovietKatusha_Rank", 5);
   // Soviet Strike ranking
   SetBehaviorGroupRank( "11_Soviet_Strike_01", "SovietStrike_Rank", 1);
   SetBehaviorGroupRank( "11_Soviet_Strike_02", "SovietStrike_Rank", 2);
   SetBehaviorGroupRank( "11_Soviet_Strike_03", "SovietStrike_Rank", 3);
   SetBehaviorGroupRank( "11_Soviet_Strike_04", "SovietStrike_Rank", 4);
   SetBehaviorGroupRank( "11_Soviet_Strike_05", "SovietStrike_Rank", 5);
   SetBehaviorGroupRank( "11_Soviet_Strike_06", "SovietStrike_Rank", 6);
   SetBehaviorGroupRank( "11_Soviet_Strike_07", "SovietStrike_Rank", 7);
   SetBehaviorGroupRank( "11_Soviet_Strike_08", "SovietStrike_Rank", 8);
   SetBehaviorGroupRank( "11_Soviet_Strike_09", "SovietStrike_Rank", 9);
   SetBehaviorGroupRank( "11_Soviet_Strike_10", "SovietStrike_Rank", 10);
// Nazi AntiAir Reserve ranking
   SetBehaviorGroupRank( "11_Nazi_AA_Reserve_01", "NaziAAReserve_Rank", 1);
   SetBehaviorGroupRank( "11_Nazi_AA_Reserve_02", "NaziAAReserve_Rank", 2);
   SetBehaviorGroupRank( "11_Nazi_AA_Reserve_03", "NaziAAReserve_Rank", 3);
   SetBehaviorGroupRank( "11_Nazi_AA_Reserve_04", "NaziAAReserve_Rank", 4);
   SetBehaviorGroupRank( "11_Nazi_AA_Reserve_05", "NaziAAReserve_Rank", 5);
   SetBehaviorGroupRank( "11_Nazi_AA_Reserve_06", "NaziAAReserve_Rank", 6);
   SetBehaviorGroupRank( "11_Nazi_AA_Reserve_07", "NaziAAReserve_Rank", 7);
   // Nazi Reserve ranking
   SetBehaviorGroupRank( "11_Nazi_Reserve_01", "NaziReserve_Rank", 1);
   SetBehaviorGroupRank( "11_Nazi_Reserve_02", "NaziReserve_Rank", 2);
   SetBehaviorGroupRank( "11_Nazi_Reserve_03", "NaziReserve_Rank", 3);
   SetBehaviorGroupRank( "11_Nazi_Reserve_04", "NaziReserve_Rank", 4);
   SetBehaviorGroupRank( "11_Nazi_Reserve_05", "NaziReserve_Rank", 5);
   SetBehaviorGroupRank( "11_Nazi_Reserve_06", "NaziReserve_Rank", 6);
   SetBehaviorGroupRank( "11_Nazi_Reserve_07", "NaziReserve_Rank", 7);
   SetBehaviorGroupRank( "11_Nazi_Reserve_08", "NaziReserve_Rank", 8);
   SetBehaviorGroupRank( "11_Nazi_Reserve_09", "NaziReserve_Rank", 9);
   SetBehaviorGroupRank( "11_Nazi_Reserve_10", "NaziReserve_Rank", 10);
   // GB10 Defender ranking
   SetBehaviorGroupRank( "11_GB10Defend_01", "GB10Defend_Rank", 1);
   SetBehaviorGroupRank( "11_GB10Defend_02", "GB10Defend_Rank", 2);
   SetBehaviorGroupRank( "11_GB10Defend_03", "GB10Defend_Rank", 3);
   SetBehaviorGroupRank( "11_GB10Defend_04", "GB10Defend_Rank", 4);
  }

  //
  //  'virtual' methods
  //

  //
  //  Objectives

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

  array m_BonusMissionObjectivesStatuses =
          array(
            str_ObjectiveInProgress
                  );

  //
  //  Mission statistics

  string GetMissionStatistics()
  {
    return str_StatisticsTitle+German_Killed;
  }

  //
  //  Mission navpoints

  array GetNavPoints()
  {
    array navpoints =
      array(
        GetNavPoint("NavPoint_01"),
        GetNavPoint("NavPoint_05"),
        GetNavPoint("NavPoint_02"),
        GetNavPoint("NavPoint_03")
      );
    return navpoints;
  }

  //
  //  Mission map skin file

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

  int Soviet_Killed            = 0;
  int German_Killed            = 0;
  int PlatoonKilled            = 0;
  final int PlatoonKilledToWin = 8;
  int CrossKilled              = 0;
  final int CrossKilledToWin   = 12;
  int SovietStrikeKilled       = 0;
  final int SovietStrikeAmount = 10;
  int NaziReserveKilled        = 0;
  int NaziAAReserveKilled      = 0;
  final int NaziReserveLost    = 10;
  final int NaziAAReserveLost  = 7;
  int SovietKatushasLeft       = 5;
  boolean m_Objective1           = false;
  boolean m_Objective2           = false;
  boolean m_Objective3           = false;

  void OnSovietSrikeStop()
  {
    //
    //  Soviet attack succeeded
    //
    m_Objective3 = true;
    BaseMission_CompleteObjective(2);
//    Core_LogMessage("Call CheckObjectives with Obj_3 is "+m_Objective3);
    Core_BroadcastEvent("CheckObjectives");
  }

  void OnConvoyKatushaStop()
  {
    //
    //  Katushas arrived at their disposition
    //

    Core_BroadcastEvent(
        "OnDisplayMessage",
        str_KatushasArrived,
        m_GoodNewsColor
      );
  }

  void OnKatushaStartFire()
  {
    //
    //  Katushas started an attack on the base
    //

    Core_BroadcastEvent(
        "OnDisplayMessage",
        str_KatushasStartedFire,
        m_GoodNewsColor
      );
  }

  void OnNaziReserveStart()
  {
    //
    //  Nazi reserve departed from its location
    //

    Core_BroadcastEvent(
        "OnDisplayMessage",
        str_ReserveMovedOut,
        m_BadNewsColor
      );
  }
  void OnGameObjectDestroyed(string _id)
  {
    BaseMission_OnGameObjectDestroyed(_id);
    Core_BroadcastEvent( "Unit_Destroyed", _id);

    if ( Core_IsStringStartsWith( _id, "11_Soviet" ) )
    {
      Soviet_Killed = Soviet_Killed + 1;
    }
    else
    {
      German_Killed = German_Killed + 1;
    }

    if ( Core_IsStringStartsWith( _id, "11_Platoon" ) )
    {
      PlatoonKilled =  PlatoonKilled + 1;
      if ( PlatoonKilled >= PlatoonKilledToWin )
      {
        BaseMission_CompleteBonusObjective(0);
      }
    }
    if ( Core_IsStringStartsWith( _id, "11_Cross" ))
    {
      Core_BroadcastEvent( "CrossRoadUnderAttack" );
      CrossKilled = CrossKilled + 1;
      if ( CrossKilled >= CrossKilledToWin )
      {
        m_Objective1 = true;
        BaseMission_CompleteObjective(0);
      }
    }
    if ( Core_IsStringStartsWith( _id, "11_Nazi_Reserve" ))
    {
      NaziReserveKilled = NaziReserveKilled + 1;
    }
    if ( Core_IsStringStartsWith( _id, "11_Nazi_AA_Reserve" ))
    {
      NaziAAReserveKilled = NaziAAReserveKilled + 1;
    }

    if ( (NaziReserveKilled >= NaziReserveLost) && (NaziAAReserveKilled >= NaziAAReserveLost) && !m_Objective2 )
    {
      m_Objective2 = true;
      BaseMission_CompleteObjective(1);
    }

    if ( Core_IsStringStartsWith( _id, "11_Katusha" ))
    {
      //
      //  Katusha killed
      //
      Core_BroadcastEvent(
          "OnDisplayMessage",
          str_KatushaDestroyed,
          m_BadNewsColor
        );
      Core_SendEventTo(
          "Helicopter",
          "ShowEventObject",
          _id,                      //     - id of object to show
          70.0                      //     - distance from camera to object
        );
      SovietKatushasLeft = SovietKatushasLeft - 1;
    }

    if ( Core_IsStringStartsWith( _id, "11_Soviet_Strike" ))
    {
      //
      //  Soviet tank killed
      //

      Core_BroadcastEvent(
          "OnDisplayMessage",
          str_TankDestroyed,
          m_BadNewsColor
        );
      Core_SendEventTo(
          "Helicopter",
          "ShowEventObject",
          _id,                      //     - id of object to show
          70.0                      //     - distance from camera to object
        );
      SovietStrikeKilled = SovietStrikeKilled + 1;

      if ( SovietStrikeKilled >= SovietStrikeAmount )
      {
        //
        //  All soviet units killed, mission failed?
        //

        Core_BroadcastEvent(
            "OnDisplayMessage",
            str_AllTanksDestroyed,
            m_BadNewsColor
          );

        BaseMission_DelayedQuit();
      }
    }
    if ( Core_IsStringStartsWith( _id, "11_Nazi_GB10_" ))
    {
      Core_BroadcastEvent( "Base10UnderAttack" );
    }
  }

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

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

