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


///////////////////////////////////
//
// Mission 8 -- Silent Destroyer
//
///////////////////////////////////

//
// *** task for Nazi AntiAirGroup 1_234 ***
//

///////////////////////////////////////////////////////////////////////
/// Start of Gun Towers Section
///////////////////////////////////////////////////////////////////////

class C8_NaziGT extends CBaseAITask_BaseTask
{
  int StartTime = 0;
  int TimeContinuous = 5000;
  void OnEnemyTargeted()
  {
    StartTime = GetGameTime();
    Core_BroadcastEvent( "WarningDetected" );
  }
  void OnNoEnemy()
  {
    StartTime = 0;
  }

  void Unit_Destroyed( string ObjectID )
  {
    if ( Core_IsStringStartsWith( ObjectID, "8_NaziGT_A" ))
    {
      Core_BroadcastEvent( "GalderStart" );
    }
  }


  void OnUpdate()
  {
    if ( (StartTime != 0) && ( (GetGameTime() - StartTime) > TimeContinuous ) )
    {
      Core_BroadcastEvent( "GalderStart" );
    }
  }
}


///////////////////////////////////////////////////////////////////////
/// End of Gun Towers Section
///////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////
/// Start of Galder's Section: A - real Galder, B - fake Galder
///////////////////////////////////////////////////////////////////////

class C8_Galder_A extends CBaseAITask_Patrol
{
  void Init()
  {
    DeactivatePatrol();
  }

  array GetPatrolTrip()
  {
    return array (vector(4370,13680,0));
  }

  float GetTripSpeed()
  {
    return 32;
  }

  void GalderStart()
  {
    ActivatePatrol();
  }
}

///--------------------------------------------------------------------

class C8_Galder_B extends CBaseAITask_Patrol
{
  void Init()
  {
    DeactivatePatrol();
  }

  array GetPatrolTrip()
  {
    return array (vector(3250,4050,0));
  }

  float GetTripSpeed()
  {
    return 29;
  }

  void GalderStart()
  {
    ActivatePatrol();
  }
}

///////////////////////////////////////////////////////////////////////
/// End of Galder's Section: A - real Galder, B - fake Galder
///////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////
/// Start of CrossRoads patrol Section
///////////////////////////////////////////////////////////////////////

class C8_NaziCross extends CBaseAITask_BaseTask
{
  int StartTime = 0;
  int TimeContinuous = 5000;
  void OnEnemyTargeted()
  {
    StartTime = GetGameTime();
    Core_BroadcastEvent( "WarningDetected" );
  }
  void OnNoEnemy()
  {
    StartTime = 0;
  }

  void OnUpdate()
  {
    if ( (StartTime != 0) && ( (GetGameTime() - StartTime) > TimeContinuous ) )
    {
      Core_BroadcastEvent( "GalderStart" );
    }
  }

  void Unit_Destroyed( string ObjectID )
  {
    if ( Core_IsStringStartsWith( ObjectID, GetUnitPrefix() ))
    {
      Core_BroadcastEvent( "GalderStart" );
    }
  }
}

class C8_NaziCross_A extends C8_NaziCross
{
  string GetUnitPrefix()
  {
    return "8_NaziCross_A";
  }
}

//----------------------------------------------------------------------------------

class C8_NaziCross_B extends C8_NaziCross
{
  string GetUnitPrefix()
  {
    return "8_NaziCross_B";
  }
}

//----------------------------------------------------------------------------------

class C8_NaziCross_C extends C8_NaziCross
{
  string GetUnitPrefix()
  {
    return "8_NaziCross_C";
  }
}
//----------------------------------------------------------------------------------

class C8_NaziCross_D extends C8_NaziCross
{
  string GetUnitPrefix()
  {
    return "8_NaziCross_D";
  }
}
///////////////////////////////////////////////////////////////////////
/// End of CrossRoads patrol Section
///////////////////////////////////////////////////////////////////////

/// Start of Nazi Patrol from A to D ==================================
class C8_NaziPatrol extends CBaseAITask_Patrol
{
  int StartTime = 0;
  int TimeContinuous = 5000;

    array GetPatrolTrip()
  {
    return array (vector(6705,6085,0),
	          vector(9550,4570,0));
  }

  float GetTripSpeed()
  {
    return 20;
  }

  void OnEnemyTargeted()
  {
    StartTime = GetGameTime();
  }
  void OnNoEnemy()
  {
    StartTime = 0;
  }

  void OnUpdate()
  {
    if ( (StartTime != 0) && ( (GetGameTime() - StartTime) > TimeContinuous ) )
    {
      Core_BroadcastEvent( "GalderStart" );
    }
  }

  void Unit_Destroyed( string ObjectID )
  {
    if ( Core_IsStringStartsWith( ObjectID, GetUnitPrefix() ))
    {
      Core_BroadcastEvent( "GalderStart" );
    }
  }
}
///--------------------------------------------------------------------------------
class C8_NaziPatrol_AD extends C8_NaziPatrol
{
  array GetPatrolTrip()
  {
    return array (vector(6705,6085,0),
	              vector(9550,4570,0));
  }
  string GetUnitPrefix()
  {
    return "8_NaziPatrol_AD";
  }
}
///--------------------------------------------------------------------------------
class C8_NaziPatrol_BG extends C8_NaziPatrol
{
  array GetPatrolTrip()
  {
    return array (vector(9443,10327,0),
	              vector(7505,10655,0));
  }
  string GetUnitPrefix()
  {
    return "8_NaziPatrol_BG";
  }
}
///--------------------------------------------------------------------------------
class C8_NaziPatrol_BC extends C8_NaziPatrol
{
  array GetPatrolTrip()
  {
    return array (vector(6235,9690,0),
	              vector(7500,10650,0));
  }
  string GetUnitPrefix()
  {
    return "8_NaziPatrol_BC";
  }
}
/// End of Nazi Patrol from A to D ====================================

///////////////////////////////////////////////////////////////////////
/// Start of Campers Section
///////////////////////////////////////////////////////////////////////

class C8_NaziCamp_A extends CBaseAITask_Patrol
{
  int StartTime = 0;
  int TimeContinuous = 5000;

  void Init()
  {
    DeactivatePatrol();
  }

  array GetPatrolTrip()
  {
    return array (vector(13345,4765,0));
  }

  float GetTripSpeed()
  {
    return 23;
  }

  void OnEnemyTargeted()
  {
    StartTime = GetGameTime();
  }
  void OnNoEnemy()
  {
    StartTime = 0;
  }

  void OnUpdate()
  {
    if ( (StartTime != 0) && ( (GetGameTime() - StartTime) > TimeContinuous ) )
    {
      Core_BroadcastEvent( "CampAlarm" );
    }
  }

  void Unit_Destroyed( string ObjectID )
  {
    if ( Core_IsStringStartsWith( ObjectID, "8_NaziCamp_A" ))
    {
      Core_BroadcastEvent( "CampAlarm" );
    }
  }
  void CampAlarm()
  {
    ActivatePatrol();
  }
  void CampA_PointReached()
    {
      DeactivatePatrol();
    }
}
///----------------------------------------------------------------------
class C8_NaziCamp_B extends CBaseAITask_Patrol
{
  int StartTime = 0;
  int TimeContinuous = 5000;

  void Init()
  {
    DeactivatePatrol();
  }
  array GetPatrolTrip()
  {
    return array (vector(9640,4640,0));
  }
  float GetTripSpeed()
  {
    return 24;
  }
  void OnEnemyTargeted()
  {
    StartTime = GetGameTime();
  }
  void OnNoEnemy()
  {
    StartTime = 0;
  }
  void OnUpdate()
  {
    if ( (StartTime != 0) && ( (GetGameTime() - StartTime) > TimeContinuous ) )
    {
      Core_BroadcastEvent( "CampAlarm" );
    }
  }
  void Unit_Destroyed( string ObjectID )
  {
    if ( Core_IsStringStartsWith( ObjectID, "8_NaziCamp_B" ))
    {
      Core_BroadcastEvent( "CampAlarm" );
    }
  }
  void CampAlarm()
  {
    ActivatePatrol();
  }
  void CampB_PointReached()
    {
      DeactivatePatrol();
    }
}

//-----------------------------------------
// Jeeps runaway
//-----------------------------------------

class C8_NaziAlert_A extends CBaseAITask_Patrol
{
  void Init()
  {
    DeactivatePatrol();
  }
  array GetPatrolTrip()
  {
    return array (vector(13345,4765,0));
  }
  float GetTripSpeed()
  {
    return 27;
  }
  void CampAlarm()
  {
    ActivatePatrol();
  }
  void AlertAStop()
  {
    DeactivatePatrol();
  }
}
///----------------------------------------------------------------------
class C8_NaziAlert_B extends CBaseAITask_Patrol
{
  void Init()
  {
    DeactivatePatrol();
  }
  array GetPatrolTrip()
  {
    return array (vector(9640,4640,0));
  }
  float GetTripSpeed()
  {
    return 27;
  }
  void CampAlarm()
  {
    ActivatePatrol();
  }
  void AlertBStop()
  {
    DeactivatePatrol();
  }
}
///////////////////////////////////////////////////////////////////////
/// End of Campers Section
///////////////////////////////////////////////////////////////////////

/// Start of Refueller Section ========================================

class C8_NaziFuel_A extends CBaseAITask_Patrol
{
  void Init()
  {
    DeactivatePatrol();
  }
}
//--------------------------------------------------
class C8_NaziFuel_B extends CBaseAITask_Patrol
{
  void Init()
  {
    DeactivatePatrol();
  }
}
/// End of Refueller Section ==========================================

///////////////////////////////////////////////////////////////////////
/// Start of check for mission failed
///////////////////////////////////////////////////////////////////////

class CMission8_AIController extends CBaseAIController
{
  array  ActivatePointCenterList = array(
    vector( 4370, 13680, 0),    // Right-Up Village
    vector( 3250, 4050, 0),     // Left-Up Village
    vector( 13345, 4765, 0),
    vector( 9640, 4640, 0));

  array  ActivatePointRadiusList = array(
    50.0,                       // radius of camp
    50.0,
    50.0,
    50.0);

  array ActivatePointNameList = array(
    "Right-Up Village",
    "Left-Up Village",
    "",
    "");


  void OnObjectEnterArea( int _AreaIndex, string _NavPointName, string _ObjectID )
  {
  ///--- If Galder get the point----------------------------------------
    if ( (_AreaIndex == 0 ) && Core_IsStringStartsWith( _ObjectID, "8_Galder"))
    {
      Core_BroadcastEvent("OnGalderWon");
      Core_LogMessage("Galder in a left-up village now");
    }
  ///--- If AlarmJeep got the point ------------------------------------
	if ( ( _AreaIndex == 2 )
      && Core_IsStringStartsWith( _ObjectID, "8_NaziAlert_A"))
    {
      Core_BroadcastEvent("GalderStart");
      Core_BroadcastEvent("AlertAStop");
    }
	if ( ( _AreaIndex == 3 )
      && Core_IsStringStartsWith( _ObjectID, "8_NaziAlert_B"))
    {
      Core_BroadcastEvent("GalderStart");
	  Core_BroadcastEvent("AlertBStop");
    }
  if ( ( _AreaIndex == 2 ) && Core_IsStringStartsWith( _ObjectID, "8_NaziCamp"))
    {
      Core_BroadcastEvent("CampA_PointReached");
    }
  if ( ( _AreaIndex == 3 ) && Core_IsStringStartsWith( _ObjectID, "8_NaziCamp"))
    {
      Core_BroadcastEvent("CampB_PointReached");
    }
  }
}

///////////////////////////////////////////////////////////////////////
/// End of check for mission failed
///////////////////////////////////////////////////////////////////////
