//---------------------------------
//  Mission script
//
//  (c) 2001 G5 Software:
//      Sergey Shoolts
//      Vlad Suglobov
//      Max Ryumin
//      Alex Tabunov
//      Alex Koloskov
//---------------------------------

class CInterceptJeepMission extends
        CBaseMission,
        CNavPointUser,
        CInterceptJeepMissionObjectList,
        CInterceptJeepMission_Strings
{
  int GetAutoGeneratedUnitsQty()
  {
    return 6;
  }

  void CInterceptJeepMission()
  {
    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", "CInterceptJeepMission_Atmosphere");

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

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

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

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

    BaseMission_CreateObjects();
  }

  array m_MissionObjectivesStatuses =
          array(
            str_ObjectiveInProgress,
            str_ObjectiveInProgress
          );

  array m_BonusMissionObjectivesStatuses =
          array(
            str_ObjectiveInProgress
                  );

  //
  //  'virtual' methods
  //

  //
  //  Mission statistics

  string GetMissionStatistics()
  {
    return "";
  }

  //
  //  Mission navpoints

  // the 1st navpoint in the array is a default one
  array GetNavPoints()
  {
    array navpoints =
      array(
        GetNavPoint("NavPoint_Camp"),
        GetNavPoint("NavPoint_Galder"),
        GetNavPoint("NavPointFuel")
      );
    return navpoints;
  }

  //
  //  Mission map skin file

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

  void OnGalderWon()
  {
    Core_BroadcastEvent(
          "OnDisplayMessage",
          str_GalderWonMessage,
          m_BadNewsColor
         );
    BaseMission_DelayedQuit();
  }

//#TMP:
  boolean GalderStarted = false;
  void GalderStart()
  {
    if ( !GalderStarted )
    {
      Core_BroadcastEvent(
        "OnDisplayMessage",
        str_GalderStartedMessage,
        m_BadNewsColor
      );
      Core_SendEventTo(
        "Helicopter",
        "ShowEventObject",
        "8_Galder_A_02",          //     - id of object to show
        80.0                      //     - distance from camera to object
        );
      GalderStarted = true;
    }
  }
  boolean CampAlarmed = false;
  void CampAlarm()
  {
    if ( !CampAlarmed )
    {
      Core_BroadcastEvent(
        "OnDisplayMessage",
        str_CampAlarmMessage,
        m_BadNewsColor
      );
      CampAlarmed = true;
    }
  }

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

  final int GalderKilledToWin = 3;
  final int NaziCampToWin = 15;
  final int NaziFuelToWin = 4;
  int m_GalderKilled = 0;
  int m_NaziCampKilled = 0;
  int m_NaziFuelKilled = 0;
  bool GalderKilled = false;
  bool CampKilled = false;
  color StructureDestroyedColor = color(1.0, 0.0, 0.0);

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

    Core_BroadcastEvent( "Unit_Destroyed", _id);

    if ( Core_IsStringStartsWith( _id, "8_Galder_A") )
    {
      m_GalderKilled = m_GalderKilled + 1;
      if ( m_GalderKilled >= GalderKilledToWin )
      {
        BaseMission_CompleteObjective(0);
        GalderKilled = true;
      }
    }
    if ( Core_IsStringStartsWith( _id, "8_NaziCamp") )
    {
      m_NaziCampKilled = m_NaziCampKilled + 1;
      if ( m_NaziCampKilled >= NaziCampToWin )
      {
        BaseMission_CompleteObjective(1);
        CampKilled = true;
      }
    }
    if ( Core_IsStringStartsWith( _id, "8_NaziFuel_B") )
    {
      m_NaziFuelKilled = m_NaziFuelKilled + 1;
      if ( m_NaziFuelKilled >= NaziFuelToWin )
      {
        BaseMission_CompleteBonusObjective(0);
      }
    }

  }

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

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