//-------------------------------------------------------------------
//
//  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 CInterceptConvoyMission extends
  CBaseMission,
  CInterceptConvoyMissionObjectList,
  CInterceptConvoyMission_Strings,
  CNavPointUser
{
  int GetAutoGeneratedUnitsQty()
  {
    return 6;
  }

  void CInterceptConvoyMission()
  {
    BaseMission_InitMission();

    BaseMission_UpdateLoadProgress();
    CreateComponent("DebugCamera", "GameObject", "CDebugCamera");
    SetComponentPosition("DebugCamera",
      matrix(
        1.0, 0.0, 0.0, 3120.0,
        0.0, 1.0, 0.0, 4670.0,
        0.0, 0.0, 1.0,  500.0,
        0.0, 0.0, 0.0,    1.0
      ));

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

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

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

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

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

    BaseMission_CreateObjects();

   // A Convoy direction
   SetBehaviorGroupRank( "10_NaziConv_A_01", "ConvA_Rank", 1);
   SetBehaviorGroupRank( "10_NaziConv_A_02", "ConvA_Rank", 2);
   SetBehaviorGroupRank( "10_NaziConv_A_03", "ConvA_Rank", 3);
   SetBehaviorGroupRank( "10_NaziConv_A_04", "ConvA_Rank", 4);
   SetBehaviorGroupRank( "10_NaziConv_A_05", "ConvA_Rank", 5);
   SetBehaviorGroupRank( "10_NaziConv_A_06", "ConvA_Rank", 6);
   SetBehaviorGroupRank( "10_NaziConv_A_07", "ConvA_Rank", 7);
   SetBehaviorGroupRank( "10_NaziConv_A_08", "ConvA_Rank", 8);
   SetBehaviorGroupRank( "10_NaziConv_A_09", "ConvA_Rank", 9);
   SetBehaviorGroupRank( "10_NaziConv_A_11", "ConvA_Rank", 11);
   SetBehaviorGroupRank( "10_NaziConv_A_12", "ConvA_Rank", 12);
   SetBehaviorGroupRank( "10_NaziConv_A_13", "ConvA_Rank", 13);
   SetBehaviorGroupRank( "10_NaziConv_A_14", "ConvA_Rank", 14);
   SetBehaviorGroupRank( "10_NaziConv_A_15", "ConvA_Rank", 15);

   // B Convoy direction
   SetBehaviorGroupRank( "10_NaziConv_B_01", "ConvB_Rank", 1);
   SetBehaviorGroupRank( "10_NaziConv_B_02", "ConvB_Rank", 2);
   SetBehaviorGroupRank( "10_NaziConv_B_03", "ConvB_Rank", 3);
   SetBehaviorGroupRank( "10_NaziConv_B_04", "ConvB_Rank", 4);
   SetBehaviorGroupRank( "10_NaziConv_B_05", "ConvB_Rank", 5);
   SetBehaviorGroupRank( "10_NaziConv_B_06", "ConvB_Rank", 6);
   SetBehaviorGroupRank( "10_NaziConv_B_07", "ConvB_Rank", 7);
   SetBehaviorGroupRank( "10_NaziConv_B_08", "ConvB_Rank", 8);
   SetBehaviorGroupRank( "10_NaziConv_B_09", "ConvB_Rank", 9);
   SetBehaviorGroupRank( "10_NaziConv_B_10", "ConvB_Rank", 10);
   SetBehaviorGroupRank( "10_NaziConv_B_11", "ConvB_Rank", 11);
   SetBehaviorGroupRank( "10_NaziConv_B_12", "ConvB_Rank", 12);
   SetBehaviorGroupRank( "10_NaziConv_B_13", "ConvB_Rank", 13);
   SetBehaviorGroupRank( "10_NaziConv_B_14", "ConvB_Rank", 14);
   SetBehaviorGroupRank( "10_NaziConv_B_15", "ConvB_Rank", 15);
   SetBehaviorGroupRank( "10_NaziConv_B_16", "ConvB_Rank", 16);

   //  Rank_PatrolA
   SetBehaviorGroupRank( "10_NaziPatrol_A_01", "Rank_PatrolA", 1);
   SetBehaviorGroupRank( "10_NaziPatrol_A_02", "Rank_PatrolA", 2);
   SetBehaviorGroupRank( "10_NaziPatrol_A_03", "Rank_PatrolA", 3);
   SetBehaviorGroupRank( "10_NaziPatrol_A_04", "Rank_PatrolA", 4);

   // Rank_PatrolCrossA
   SetBehaviorGroupRank( "10_NaziCrossA_Patrol_01", "Rank_PatrolCrossA", 1);
   SetBehaviorGroupRank( "10_NaziCrossA_Patrol_02", "Rank_PatrolCrossA", 2);
   SetBehaviorGroupRank( "10_NaziCrossA_Patrol_03", "Rank_PatrolCrossA", 3);

   // Rank_SharkPatrol
   SetBehaviorGroupRank( "10_SharkPatrol_01", "Rank_SharkPatrol", 1);
   SetBehaviorGroupRank( "10_SharkPatrol_02", "Rank_SharkPatrol", 2);
   SetBehaviorGroupRank( "10_SharkPatrol_03", "Rank_SharkPatrol", 3);
   SetBehaviorGroupRank( "10_SharkPatrol_04", "Rank_SharkPatrol", 4);

  }


  array m_MissionObjectivesStatuses =
          array(
            str_ObjectiveInProgress,
            str_ObjectiveInProgress
          );

  array m_BonusMissionObjectivesStatuses =
          array(
            str_ObjectiveInProgress
                  );

  //
  //  'virtual' methods
  //

  //
  //  Mission statistics

  string GetMissionStatistics()
  {
    return str_StatisticsTitle;
  }

  //
  //  Mission navpoints

  array GetNavPoints()
  {
    array navpoints =
      array(
        GetNavPoint("NavPointA"),
        GetNavPoint("NavPointB"),
        GetNavPoint("NavPoint_Austerlitz")
      );
    return navpoints;
  }

  // the 1st navpoint in the array is a default one
  array GetNavPointsDescriptions()
  {
    return m_NavigationPoints;
  }

  //
  //  Mission map skin file

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

  void WarningDetected()
  {
    Core_BroadcastEvent(
      "OnDisplayMessage",
      str_WarningMessage,
      m_BadNewsColor);
  }

  void NeedToQuit()
  {
    BaseMission_DelayedQuit();
  }
  // Objective of convoys
  boolean ConvA_Killed = false;
  boolean ConvB_Killed = false;
  int m_ConvA_Killed = 0;
  final int ConvA_KilledToWin = 14;
  int m_ConvB_Killed = 0;
  final int ConvB_KilledToWin = 16;
  int m_Titovo_Killed = 0;
  final int Titovo_KilledToWin = 7;

  boolean ConvoyASatrtMessage = false;
  boolean ConvoyBSatrtMessage = false;
  boolean ConvoyAStopMessage  = false;
  boolean ConvoyBStopMessage  = false;

  void OnConvoyAStart()
  {
    if ( !ConvoyASatrtMessage )
     {
       ConvoyASatrtMessage = true;
//        Core_LogMessage("Camera shows: Convoy A after moving start. Unit 02");
//        Core_SendEventTo(
//          "Helicopter",
//          "ShowEventObject",
//          "10_NaziConv_A_02",       //     - id of object to show
//          70.0                      //     - distance from camera to object
//          );
     }
  }

  void OnConvoyBStart()
  {
    if ( !ConvoyBSatrtMessage )
     {
        ConvoyBSatrtMessage = true;
        Core_LogMessage("Camera shows: Convoy B after moving start. Unit 02");
        Core_SendEventTo(
          "Helicopter",
          "ShowEventObject",
          "10_NaziConv_B_02",       //     - id of object to show
          70.0                      //     - distance from camera to object
          );
     }
  }

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

    if ( Core_IsStringStartsWith( _id, "10_NaziConv_A") )
    {
      m_ConvA_Killed = m_ConvA_Killed + 1;
      if ( m_ConvA_Killed >= ConvA_KilledToWin )
      {
        ConvA_Killed = true;
        BaseMission_CompleteObjective(0);
      }
    }
    if ( Core_IsStringStartsWith( _id, "10_NaziConv_B") )
    {
      m_ConvB_Killed = m_ConvB_Killed + 1;
      if ( m_ConvB_Killed >= ConvB_KilledToWin )
      {
        ConvB_Killed = true;
        BaseMission_CompleteObjective(1);
      }
    }

    if ( Core_IsStringStartsWith( _id, "10_NaziTitovo") )
    {
      m_Titovo_Killed = m_Titovo_Killed + 1;
      if ( m_Titovo_Killed >= Titovo_KilledToWin )
      {
        BaseMission_CompleteBonusObjective(0);
        m_Titovo_Killed = m_Titovo_Killed + 1;
      }
    }

  }
  void OnConvoyAStop()
  {
    Core_BroadcastEvent(
        "OnDisplayMessage",
        str_ConvoyAEscaped,
        m_BadNewsColor
      );
    if ( !ConvoyAStopMessage )
     {
      ConvoyAStopMessage = true;
      Core_SendEventTo(
            "Helicopter",
            "ShowEventPoint",
            vector(3390, 13365, 0), //        - point to show
            80.0                    //        - distance from camera to point
        );
     }
    BaseMission_DelayedQuit();
  }
  void OnConvoyBStop()
  {
    Core_BroadcastEvent(
        "OnDisplayMessage",
        str_ConvoyBEscaped,
        m_BadNewsColor
      );
    if ( !ConvoyBStopMessage )
     {
      ConvoyBStopMessage = true;
      Core_SendEventTo(
            "Helicopter",
            "ShowEventPoint",
            vector(9030, 3925, 0), //        - point to show
            80.0                   //        - distance from camera to point
        );
     }
    BaseMission_DelayedQuit();
  }

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

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