//-------------------------------------------------------------------
//
//  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 CSurvivalMission extends
  CBaseMission, CSurvivalMissionObjectList, CSurvivalMission_Strings,
  CNavPointUser, CGermanParatrooperGenerator
{
  int GetAutoGeneratedUnitsQty()
  {
    return 6;
  }

  void CSurvivalMission()
  {
    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", "CSurvivalMission_Atmosphere");

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

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

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

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

    BaseMission_CreateObjects();
  }

  //
  //  'virtual' methods
  //

  //
  //  Objectives

  array m_MissionObjectivesStatuses =
          array(
            str_ObjectiveInProgress,
            str_ObjectiveInProgress
          );

  array m_BonusMissionObjectivesStatuses =
          array(
            str_ObjectiveInProgress
                  );


  //
  //  Mission statistics

  string GetMissionStatistics()
  {
    return str_StatisticsTitle+m_GermanKilled;
  }

  //
  //  Mission navpoints

  array GetNavPoints()
  {
    array navpoints =
      array(
        GetNavPoint("NavPoint_01"),     // Benghazi Crossroad position
        GetNavPoint("NavPoint_02"),     // Al-Bwairat Crossroad position
        GetNavPoint("NavPoint_03"),     // Zillah position
        GetNavPoint("NavPoint_04")      // Tobruq position
      );
    return navpoints;
  }

  //
  //  Mission map skin file

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

  final int m_TobruqConvoyLost       = 18;
  final int m_BenghaziConvoyLost     = 8;
  final int m_BenghaziTankConvoyLost = 8;
  final int m_AqaliaConvoyLost       = 10;
//  final int m_TobruqConvoyLost       = 4;
//  final int m_BenghaziConvoyLost     = 2;
//  final int m_BenghaziTankConvoyLost = 2;
//  final int m_AqaliaConvoyLost       = 4;

  final int m_RoadFlakLost           = 10;

  int m_GermanKilled = 0;
  int m_TobruqConvoyKilled = 0;
  int m_AqaliaConvoyKilled = 0;
  int m_BenghaziConvoyKilled = 0;
  int m_RoadFlakKilled = 0;

  boolean m_TobruqStopped   = false;
  boolean m_BenghaziStopped = false;
//  boolean m_BenghaziStopped = false;
  boolean m_AqaliaStopped   = false;

  boolean Objective1      = false;
  boolean Objective2      = false;
  boolean Objective3      = false;
  boolean BonusObjective1 = false;

  void ConvoyGetNavPoint_02()
    {
      BaseMission_DelayedQuit();
    }

  void Wave1MemberStopped( string _idConvoy )
    {
      if ( m_TobruqStopped && m_BenghaziStopped && m_AqaliaStopped && !Objective1 )
       {
         Core_LogMessage("Wave 1 was stopped wit your help");
         Objective1 = true;
         BaseMission_CompleteObjective(0);
       }
    }
  void OnGameObjectDestroyed(string _id)
   {
     BaseMission_OnGameObjectDestroyed(_id);

     if ( Core_IsStringStartsWith( _id, "15_G" ) )
      {
         m_GermanKilled = m_GermanKilled + 1;
      }
     if ( Core_IsStringStartsWith( _id, "15_GTobruq" ) )
      {
         m_TobruqConvoyKilled = m_TobruqConvoyKilled + 1;
         if ( (m_TobruqConvoyKilled >= m_TobruqConvoyLost*0.7) && ( !m_TobruqStopped ) )
          {
             m_TobruqStopped = true;
             Core_BroadcastEvent("Wave1MemberStopped", "Tobruq");
             Core_LogMessage("Tobruq convoy has stopped. With "+m_TobruqConvoyKilled+" killed units");
          }
      }
     if ( Core_IsStringStartsWith( _id, "15_GAqalia" ) )
      {
         m_AqaliaConvoyKilled = m_AqaliaConvoyKilled + 1;
         if ( (m_AqaliaConvoyKilled >= m_AqaliaConvoyLost*0.7) && ( !m_AqaliaStopped ) )
          {
             m_AqaliaStopped = true;
             Core_BroadcastEvent("Wave1MemberStopped", "Aqalia");
             Core_LogMessage(" Al-Aqalia convoy has stopped. With "+m_AqaliaConvoyKilled+" killed units");
          }
      }
     if ( Core_IsStringStartsWith( _id, "15_GBenghazi" ) )
      {
         m_BenghaziConvoyKilled = m_BenghaziConvoyKilled + 1;
         if ( (m_BenghaziConvoyKilled >= (m_BenghaziConvoyLost+m_BenghaziTankConvoyLost)*0.7) && ( !m_BenghaziStopped ) )
          {
             m_BenghaziStopped = true;
             Core_BroadcastEvent("Wave1MemberStopped", "Benghazi");
             Core_LogMessage(" Benghazi convoy has stopped. With "+m_BenghaziConvoyKilled+" killed units");
          }
      }
     if ( Core_IsStringStartsWith( _id, "15_AmmoBox" ) && !Objective2 )
      {
         Objective2 = true;
         BaseMission_CompleteObjective(1);
         Core_ScheduleTask("Bullets",
                           OT_SendEventTo,
                           10.0,
                           "StartSovietAirBombing",
                           300, 30.0,
                           GetNavPoint("NavPoint_03"),
                           300.0
                            );
      }

  // Check BonusObjective
     if ( Core_IsStringStartsWith( _id, "15_GRoad_Flak" ) )
      {
         m_RoadFlakKilled = m_RoadFlakKilled + 1;
         if ( (m_RoadFlakKilled >= m_RoadFlakLost) && ( !BonusObjective1 ) )
          {
            BonusObjective1 = true;
            BaseMission_CompleteBonusObjective(0);
          }
      }

   }

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

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