//-------------------------------------------------------------------
//
//  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 CEliminatePartisansMission extends
  CBaseMission, CEliminatePartisansMissionObjectList, CEliminatePartisansMission_Strings,
  CNavPointUser
{
  int GetAutoGeneratedUnitsQty()
  {
    return 6;
  }

  void CEliminatePartisansMission()
  {
    BaseMission_InitMission();

    BaseMission_UpdateLoadProgress();
    CreateComponent("DebugCamera", "GameObject", "CDebugCamera");
    SetComponentPosition("DebugCamera",
      matrix(
        1.0, 0.0, 0.0, 3802.0,
        0.0, 1.0, 0.0, 6865.0,
        0.0, 0.0, 1.0,  300.0,
        0.0, 0.0, 0.0,    1.0
      ));

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

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

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

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

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

    BaseMission_CreateObjects();

   // Soviet Offensive ranking
   SetBehaviorGroupRank( "12_SovietTank_01", "SovietOffensive_Rank", 1);
   SetBehaviorGroupRank( "12_SovietTank_02", "SovietOffensive_Rank", 2);
   SetBehaviorGroupRank( "12_SovietTank_03", "SovietOffensive_Rank", 3);
   SetBehaviorGroupRank( "12_SovietTank_04", "SovietOffensive_Rank", 4);
   SetBehaviorGroupRank( "12_SovietTank_05", "SovietOffensive_Rank", 5);
   SetBehaviorGroupRank( "12_SovietTank_06", "SovietOffensive_Rank", 6);
   SetBehaviorGroupRank( "12_SovietKatusha_01", "SovietOffensive_Rank", 7);
   SetBehaviorGroupRank( "12_SovietKatusha_02", "SovietOffensive_Rank", 8);
   SetBehaviorGroupRank( "12_SovietKatusha_03", "SovietOffensive_Rank", 9);
   SetBehaviorGroupRank( "12_SovietKatusha_04", "SovietOffensive_Rank", 10);
   SetBehaviorGroupRank( "12_SovietTank_07", "SovietOffensive_Rank", 11);
   SetBehaviorGroupRank( "12_SovietTank_08", "SovietOffensive_Rank", 12);
   // Soviet Offensive ranking
   SetBehaviorGroupRank( "12_SovietAmmo_01", "SovietAmmo_Rank", 1);
   SetBehaviorGroupRank( "12_SovietAmmo_02", "SovietAmmo_Rank", 2);
   SetBehaviorGroupRank( "12_SovietAmmo_03", "SovietAmmo_Rank", 3);
   SetBehaviorGroupRank( "12_SovietAmmo_04", "SovietAmmo_Rank", 4);
   SetBehaviorGroupRank( "12_SovietAmmo_05", "SovietAmmo_Rank", 5);
   SetBehaviorGroupRank( "12_SovietAmmo_06", "SovietAmmo_Rank", 6);
   SetBehaviorGroupRank( "12_SovietAmmo_07", "SovietAmmo_Rank", 7);
   SetBehaviorGroupRank( "12_SovietAmmo_08", "SovietAmmo_Rank", 8);
   SetBehaviorGroupRank( "12_SovietAmmo_09", "SovietAmmo_Rank", 9);
   SetBehaviorGroupRank( "12_SovietAmmo_10", "SovietAmmo_Rank", 10);
   // AA01_Rank ranking
   SetBehaviorGroupRank( "12_GermanAA01_01", "AA01_Rank", 1);
   SetBehaviorGroupRank( "12_GermanAA01_02", "AA01_Rank", 2);
   SetBehaviorGroupRank( "12_GermanAA01_03", "AA01_Rank", 3);
   SetBehaviorGroupRank( "12_GermanAA01_04", "AA01_Rank", 4);
   // AA02_Rank ranking
   SetBehaviorGroupRank( "12_GermanAA02_01", "AA02_Rank", 1);
   SetBehaviorGroupRank( "12_GermanAA02_02", "AA02_Rank", 2);
   SetBehaviorGroupRank( "12_GermanAA02_03", "AA02_Rank", 3);
   SetBehaviorGroupRank( "12_GermanAA02_04", "AA02_Rank", 4);
  }

  //  'virtual' methods

  //  Objectives

  array m_MissionObjectivesStatuses =
          array(
            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_02"),
        GetNavPoint("NavPoint_03")
      );
    return navpoints;
  }
  //  Mission map skin file
  string GetMapSkinFileName()
  {
    return "Missions/Mission_12/Map.skin";
  }

  int Soviet_Killed            = 0;
  int German_Killed            = 0;
  int Soviet_TankKilled        = 0;
  final int Soviet_TankLost    = 8;
  int Soviet_KatushaKilled     = 0;
  final int Soviet_KatushaLost = 4;
  int TraitorKilled            = 0;
  final int TraitorLost        = 31;
  int SupportKilled_1          = 0;
  int SupportKilled_2          = 0;
  final int SupportLost        = 4;

  boolean BObjective1          = false;
  boolean BObjective2          = false;
  boolean m_MessageOnScreen    = false;

  void OnSovietOffensiveStop()
  {
    BaseMission_CompleteObjective(1);
    if ( !m_MessageOnScreen )
     {
        m_MessageOnScreen = true;
        Core_SendEventTo(
          "Helicopter",
          "ShowEventPoint",
          vector(8721.0, 7935.0, 1450), //     - id of object to show
          70.0                          //     - distance from camera to object
        );
     }
  }

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

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

      // Sofiet Offensive under attack message
      Core_BroadcastEvent(
        "OnDisplayMessage",
        str_AttackForcesUnderAttack,
        m_BadNewsColor
      );
      Core_SendEventTo(
          "Helicopter",
          "ShowEventObject",
          _id,                      //     - id of object to show
          50.0                      //     - distance from camera to object
        );
      if ( Soviet_TankKilled >= Soviet_TankLost)
      {
        BaseMission_DelayedQuit();
      }
    }
    if ( Core_IsStringStartsWith( _id, "12_GermanAA01_" ) )
    {
      SupportKilled_1 = SupportKilled_1 + 1;
      if ( SupportKilled_1 >= SupportLost)
      {
        BObjective1 = true;
        if ( BObjective1 && BObjective2)
        {
          BaseMission_CompleteBonusObjective(0);
        }
      }
    }
    if ( Core_IsStringStartsWith( _id, "12_GermanAA02_" ) )
    {
      SupportKilled_2 = SupportKilled_2 + 1;
      if ( SupportKilled_2 >= SupportLost)
      {
        BObjective2 = true;
        if ( BObjective1 && BObjective2)
        {
          BaseMission_CompleteBonusObjective(0);
        }
      }
    }

    if ( Core_IsStringStartsWith( _id, "12_SovietKatusha_" ) )
    {
      Soviet_KatushaKilled = Soviet_KatushaKilled + 1;
      // Soviet Offensive under attack message
      Core_BroadcastEvent(
        "OnDisplayMessage",
        str_AttackForcesUnderAttack,
        m_BadNewsColor
      );
      Core_SendEventTo(
          "Helicopter",
          "ShowEventObject",
          _id,                      //     - id of object to show
          50.0                      //     - distance from camera to object
        );
      if ( Soviet_KatushaKilled >= Soviet_KatushaLost)
      {
        BaseMission_DelayedQuit();
      }
    }
    if ( Core_IsStringStartsWith( _id, "12_Traitor_" ) )
    {
      TraitorKilled = TraitorKilled + 1;
      if ( TraitorKilled >= TraitorLost)
      {
        BaseMission_CompleteObjective(0);
      }
    }
  }

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

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