//-------------------------------------------------------------------
//
//  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 CSupportAerialAttackMission extends
  CBaseMission, CSupportAerialAttackMissionObjectList, CSupportAerialAttackMission_Strings, CNavPointUser
{
  int GetAutoGeneratedUnitsQty()
  {
    return 6;
  }

  void CSupportAerialAttackMission()
  {
    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", "CSupportAerialAttackMission_Atmosphere");

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

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

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

    BaseMission_UpdateLoadProgress();
    CreateComponent( "AIController", "AIController", "CMission13_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+GermanKilled;
  }

  //
  //  Mission navpoints

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

  //
  //  Mission map skin file

  string GetMapSkinFileName()
  {
    return "Missions/Mission_13/Map.skin";
  }
// TMP variables
  int GermanKilled        =0;
  int TobruqKilled        = 0;
  final int TobruqLost    = 39;
  int AlAqaliaKilled      = 0;
  final int AlAqaliaLost  = 29;
  int RefuellerKilled     = 0;
  final int RefuellerLost = 12;
  boolean Objective1      = false;
  boolean Objective2      = false;
  boolean BonusObjective1 = false;

  void OnTobruqTumeUp()
    {
//    Core_LogMessage("In Tobruq killet about: "+TobruqKilled);
//    Core_LogMessage("Need to kill In: "+TobruqLost+" and procentel is: "+(TobruqLost*0.7));
      if ( TobruqKilled < TobruqLost*0.7 )
       {
        if ( !Objective1)
         {
          BaseMission_DelayedQuit();
         }
       }
    }

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

    if ( Core_IsStringStartsWith( _id, "13_Tobruq" ) )
    {
      TobruqKilled = TobruqKilled + 1;
      if ( !Objective1 )
        {
          Core_SendEventTo(
            "Helicopter",
            "OnDisplayMessage",
            (TobruqKilled*100/TobruqLost)+str_TobruqProcentel,
            m_GoodNewsColor,
            240000, 1);
//          Core_LogMessage("Tobruq defender eliminating"+(TobruqKilled*100/TobruqLost));
        }
      if ( TobruqKilled >= TobruqLost*0.7)
       {
        if ( !Objective1 )
          {
            Core_BroadcastEvent("Objective1_Complete");
            Core_SendEventTo(
              "Helicopter",
              "OnDisplayMessage",
              "",
              m_GoodNewsColor,
              1, 1);
//            Core_LogMessage("Tobruq has a zero string");
            Objective1 = true;
            Core_ScheduleTask("Bullets",
                              OT_SendEventTo,
                              10.0,
                              "StartSovietAirBombing",
                              200, 30.0,
                              vector(8790.0, 6650.0, 305.0),
                              250.0
                            );
            Core_ScheduleTask("Bullets",
                              OT_SendEventTo,
                              15.0,
                              "StartSovietAirBombing",
                              100, 20.0,
                              vector(9242.0, 6642.0, 35.0),
                              150.0
                            );
            Core_SendEventTo(
                 "Helicopter",
                 "ShowEventPoint",
                 vector(8790.0, 6650.0, 305.0), //     - id of object to show
                 150.0                          //     - distance from camera to object
              );
            BaseMission_CompleteObjective(0);
          }
       }
    }
    if ( Core_IsStringStartsWith( _id, "13_Al" ) )
    {
      AlAqaliaKilled = AlAqaliaKilled + 1;
      if ( !Objective2 )
        {
          Core_SendEventTo(
            "Helicopter",
            "OnDisplayMessage",
            (AlAqaliaKilled*100/AlAqaliaLost)+str_AqaliaProcentel,
            m_GoodNewsColor,
            240000, 1);
        }
      if ( AlAqaliaKilled >= AlAqaliaLost*0.7)
       {
        if ( !Objective2 )
          {
            Core_BroadcastEvent("Objective2_Complete");
//            Core_LogMessage("Aqalia send Objective 2 complete.");
            Core_SendEventTo(
              "Helicopter",
              "OnDisplayMessage",
              "",
              m_GoodNewsColor,
              1, 1);
            Objective2 = true;
            // BaseMission_CompleteObjective(1);
            Core_ScheduleTask(
                SOID_MissionController,
                OT_SendEventTo,
                10.0,
                "BaseMission_CompleteObjective",
                1
              );
//            Core_LogMessage("Objective Complete after 10 sec.");
            Core_ScheduleTask("Bullets",
                              OT_SendEventTo,
                              5.0,
                              "StartSovietAirBombing",
                              500, 50.0,
                              vector(5345.0, 3600.0, 32.0),
                              400.0
                  );
//            Core_LogMessage("AlAqalia bombardment after 5 sec.");
            Core_SendEventTo(
                 "Helicopter",
                 "ShowEventPoint",
                 vector(5345.0, 3600.0, 150.0),  //     - id of object to show
                 150.0                           //     - distance from camera to object
              );
//            Core_LogMessage("Camera Upon point of bombardment immidiately after 0 sec.");
          }
       }
    }
    if ( Core_IsStringStartsWith( _id, "13_Refueller" ) )
    {
      RefuellerKilled = RefuellerKilled + 1;
      if ( RefuellerKilled >= RefuellerLost )
       {
        if ( !BonusObjective1)
          {
            BonusObjective1 = true;
            BaseMission_CompleteBonusObjective(0);
          }
       }
    }
    if ( Core_IsStringStartsWith( _id, "13" ) )
    {
      GermanKilled = GermanKilled + 1;
    }
  }

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

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