//-------------------------------------------------------------------
//
//  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.
//
//-------------------------------------------------------------------

///////////////////////////////////
//
// Mission 4. "GuardedTarget"
//
//

class CDestroyGuardedTarget_AIController extends CBaseAIController
{

  void OnObjectEnterArea( int _NavPointIndex, string _NavPointName, string _ObjectID)
  {
    if ( _NavPointName == "WestNP_07"
      && Core_IsStringStartsWith( _ObjectID, "CargoWest"))
    {
      Core_BroadcastEvent("WestCargoArrive");
    }
    if ( _NavPointName == "SudeNP_06"
      && Core_IsStringStartsWith( _ObjectID, "CargoSude"))
    {
      Core_BroadcastEvent("SudeCargoArrive");
    }
    if ( _NavPointName == "NordNP_09"
      && Core_IsStringStartsWith( _ObjectID, "CargoNord"))
    {
      Core_BroadcastEvent("NordCargoArrive");
    }

  }
}

// Defender group

class CMission4_Defender extends CBaseAITask_BaseTask
{
  // do delay before fire
  void OnEnemyTargeted()
  {
    SetFireStyle_SetFireDelay( 5000, 1000);
  }
}


// Patrol group A

class CMission4_BasePatrol_a extends CBaseAITask_Patrol, CNavPointUser
{
  array GetPatrolTrip()
  {
    return array(
      GetNavPoint("NavPoint_1"),
      GetNavPoint("NavPoint_2"),
      GetNavPoint("NavPoint_3"),
      GetNavPoint("NavPoint_4"),
      GetNavPoint("NavPoint_5"));
  }

  float GetTripSpeed()
  {
    return 20;
  }

  void Notify_OnEnemyTargeted()
  {
    SetAttackStyle_DirectMove( true);
    SetFireStyle_SetFireDelay( 5000, 3000);
  };

  void OnNoEnemy() {} // do not stop attack when enemy disappeared
}


// Patrol group B

class CMission4_BasePatrol_b extends CBaseAITask_Patrol, CNavPointUser
{
  array GetPatrolTrip()
  {
    return array(
      GetNavPoint("NavPoint_1"),
      GetNavPoint("NavPoint_2"),
      GetNavPoint("NavPoint_3"),
      GetNavPoint("NavPoint_4"),
      GetNavPoint("NavPoint_5"));
  }

  float GetTripSpeed()
  {
    return 20;
  }

  void Notify_OnEnemyTargeted()
  {
    SetAttackStyle_DirectMove( true);
    SetFireStyle_SetFireDelay( 5000, 3000);
  };

  void OnNoEnemy() {} // do not stop attack when enemy disappeared
}


// Patrol group C

class CMission4_BasePatrol_c extends CBaseAITask_Patrol, CNavPointUser
{
  array GetPatrolTrip()
  {
    return array(
      GetNavPoint("NavPoint_1"),
      GetNavPoint("NavPoint_2"),
      GetNavPoint("NavPoint_3"),
      GetNavPoint("NavPoint_4"),
      GetNavPoint("NavPoint_5"));
  }

  float GetTripSpeed()
  {
    return 20;
  }

  // do not start attack but keep patrolling
  void OnEnemyTargeted()
  {
    SetFireStyle_SetFireDelay( 5000, 3000);
  }
}

class CMission4_WestCargo extends CBaseAITask_Patrol, CNavPointUser
{

  boolean m_Activated = false;
  boolean m_Deactivated = false;
  vector FormationVector = vector(10.0, 10.0, 0.0 );
  int OvertakeSpeed = 26;

  void Init()
    {
      DeactivatePatrol();
    }

  void StartRunFromBase()
    {
      if ( !m_Activated )
       {
         m_Activated = true;
         ActivatePatrol();
       }
    }

  void WestCargoArrive()
    {
      if ( !m_Deactivated )
       {
         m_Deactivated = true;
         DeactivatePatrol();

      string Leader = GetCommander("CargoWest_Rank");
      if ( Leader != "" )
        {
        SetOrder_Formation(
          Leader,
          FormationVector,
          10, //#TMP
          15, //#TMP
          OvertakeSpeed/2,
          OvertakeSpeed/2);
        }

       }
    }

  array GetPatrolTrip()
  {
    return array(
      GetNavPoint("WestNP_01"),
      GetNavPoint("WestNP_02"),
      GetNavPoint("WestNP_03"),
      GetNavPoint("WestNP_04"),
      GetNavPoint("WestNP_05"),
      GetNavPoint("WestNP_06"),
      GetNavPoint("WestNP_07"));
  }

  float GetTripSpeed()
  {
    return 28;
  }

  // do not start attack but keep patrolling
  void OnEnemyTargeted()
  {
    SetFireStyle_SetFireDelay( 5000, 3000);
  }

}

class CMission4_SudeCargo extends CBaseAITask_Patrol, CNavPointUser
{

  boolean m_Activated = false;
  boolean m_Deactivated = false;
  vector FormationVector = vector(10.0, 10.0, 0.0 );
  int OvertakeSpeed = 26;

  void Init()
    {
      DeactivatePatrol();
    }

  void StartRunFromBase()
    {
      if ( !m_Activated )
       {
         m_Activated = true;
         ActivatePatrol();
       }
    }

  void SudeCargoArrive()
    {
      if ( !m_Deactivated )
       {
         m_Deactivated = true;
         DeactivatePatrol();

         string Leader = GetCommander("CargoSude_Rank");
         if ( Leader != "" )
          {
            SetOrder_Formation(
              Leader,
              FormationVector,
              10, //#TMP
              15, //#TMP
              OvertakeSpeed/2,
              OvertakeSpeed/2);
          }
       }
    }

  array GetPatrolTrip()
  {
    return array(
      GetNavPoint("SudeNP_01"),
      GetNavPoint("SudeNP_02"),
      GetNavPoint("SudeNP_03"),
      GetNavPoint("SudeNP_04"),
      GetNavPoint("SudeNP_05"),
      GetNavPoint("SudeNP_06")
//      GetNavPoint("SudeNP_07")
      );
  }

  float GetTripSpeed()
  {
    return 28;
  }

  // do not start attack but keep patrolling
  void OnEnemyTargeted()
  {
    SetFireStyle_SetFireDelay( 5000, 3000);
  }
}

class CMission4_NordCargo extends CBaseAITask_Patrol, CNavPointUser
{

  boolean m_Activated = false;
  boolean m_Deactivated = false;
  vector FormationVector = vector(10.0, 10.0, 0.0 );
  int OvertakeSpeed = 26;

  void Init()
    {
      DeactivatePatrol();
    }

  void StartRunFromBase()
    {
      if ( !m_Activated )
       {
         m_Activated = true;
         ActivatePatrol();
       }
    }

  void NordCargoArrive()
    {
      if ( !m_Deactivated )
       {
         m_Deactivated = true;
         DeactivatePatrol();

         string Leader = GetCommander("CargoNord_Rank");
         if ( Leader != "" )
          {
            SetOrder_Formation(
              Leader,
              FormationVector,
              10, //#TMP
              15, //#TMP
              OvertakeSpeed/2,
              OvertakeSpeed/2);
          }
       }
    }

  array GetPatrolTrip()
  {
    return array(
      GetNavPoint("NordNP_01"),
      GetNavPoint("NordNP_02"),
      GetNavPoint("NordNP_03"),
      GetNavPoint("NordNP_04"),
      GetNavPoint("NordNP_05"),
      GetNavPoint("NordNP_06"),
      GetNavPoint("NordNP_07"),
      GetNavPoint("NordNP_08"),
      GetNavPoint("NordNP_09")
      );
  }

  float GetTripSpeed()
  {
    return 28;
  }

  // do not start attack but keep patrolling
  void OnEnemyTargeted()
  {
    SetFireStyle_SetFireDelay( 5000, 3000);
  }
}