//---------------------------------------------------------------------------
// File			: AVP_Behaviour_Marine_TestBehaviour.cpp
// Created		: 
// Created By	: Gareth Thomas
// Copyright (C) 2007 Rebellion. All Rights Reserved.
//---------------------------------------------------------------------------

// INCLUDES ///////////////////////////////////////////////////////////

// core
#include "Core/Asura.h"
// header
#include "Behaviour/BehaviourTypes/Human/Marine/AVP_Behaviour_Marine_TestBehaviour.h"
// asura
#include "Interface/Asura_CommandConsole.h"
#ifndef ASURA_NO_DEBUG_OUTPUT
#include "Rendering/Asura_Font_System.h"
#endif

// AVP
#include "Actor/Vertebrates/AVP_Vertebrate_MeleeCounter_System.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/Human/AVP_ServerActor_Human.h"
#include "Entity/PhysicalObject/Actor/Vertebrates/AVP_Vertebrate_Messages.h"
#include "Inventory/AVP_Inventory_System.h"
#include "Inventory/Items/Weapons/AVP_InventoryWeapon_RangedWeapon.h"

// AVP axon
#include "Behaviour/BehaviourTypes/AVP_Behaviour_Types.h"
#include "Core/BrainTypes/AVP_Brain_Actor_Marine.h"
#include "Tactical/AVP_Tactical_System.h"

//---------------------------------------------------------------------------------
//*********************************************************************************
//---------------------------------------------------------------------------------
// Class		: AVP_Behaviour_Marine_TestBehaviour
// Description	: 
//---------------------------------------------------------------------------------
//*********************************************************************************
//---------------------------------------------------------------------------------


//---------------------------------------------------------------------------
// AVP_Behaviour_Marine_TestBehaviour :: Constructor
//---------------------------------------------------------------------------
AVP_Behaviour_Marine_TestBehaviour::AVP_Behaviour_Marine_TestBehaviour(AVP_Brain_Actor_Marine* pxBrain)
: PARENT( pxBrain, AVP_BEHAVIOUR_TYPE_MARINE_TESTBEHAVIOUR )
, m_pxMarineBrain( pxBrain )
, m_eUpdateState( CHOOSE )
{

}

//---------------------------------------------------------------------------
// AVP_Behaviour_Marine_TestBehaviour :: Decnstructor
//---------------------------------------------------------------------------
AVP_Behaviour_Marine_TestBehaviour::~AVP_Behaviour_Marine_TestBehaviour()
{

}

//---------------------------------------------------------------------------
// AVP_Behaviour_Marine_TestBehaviour :: Activate
//---------------------------------------------------------------------------
bool AVP_Behaviour_Marine_TestBehaviour::Activate(void)
{
	return PARENT::Activate();
}

//---------------------------------------------------------------------------
// AVP_Behaviour_Marine_TestBehaviour :: Deactivate
//---------------------------------------------------------------------------
void AVP_Behaviour_Marine_TestBehaviour::Deactivate(void)
{
	// Destroys any child behaviours created by this behaviour
	DestroyAllChildren();

	PARENT::Deactivate();
}

//---------------------------------------------------------------------------
// AVP_Behaviour_Marine_TestBehaviour :: PerFrameUpdate
//---------------------------------------------------------------------------
void AVP_Behaviour_Marine_TestBehaviour::PerFrameUpdate(const float fTimeslice)
{
	switch ( m_eUpdateState )
	{
		case CHOOSE:
		{
			
			u_int uNumWaypoints = Asura_AI_Navigation_System::GetNumberOfWaypoints();
			u_int uWaypointID = Asura_Random::GetIntU( 0, uNumWaypoints - 1 );
			Asura_AI_NavVertex* pxWaypoint = Asura_AI_Navigation_System::GetWaypoint( uWaypointID );

			if ( pxWaypoint )
			{
				float fDistanceSq = ( pxWaypoint->GetPosition() - GetMarineBrain()->GetHumanActor()->GetPosition() ).MagnitudeSquared();

				if ( fDistanceSq > 36.0f )
				{
					GetMarineBrain()->GetTacticalSystem()->SetDestination( pxWaypoint->GetPosition() );
					GetMarineBrain()->GetTacticalSystem()->OverrideStartMovementDelay();
					GetMarineBrain()->GetTacticalSystem()->SetMovementSpeed( AVP_Navigation::MM_SLOW );
					GetMarineBrain()->GetTacticalSystem()->SetShouldStopAtDestination( false );
					GetMarineBrain()->GetTacticalSystem()->SetAtDestinationRange( 0.9f );
					GetMarineBrain()->GetTacticalSystem()->SetIsPerformingAction( true );
					m_eUpdateState = MOVE;
				}
			}
			
		}break;

		case MOVE:
		{
			if ( GetMarineBrain()->GetTacticalSystem()->HasArrivedAtDestination() )
			{
				m_eUpdateState = CHOOSE;
			}

		}break;

		default:
		{

		}break;
	}
}

//---------------------------------------------------------------------------
// AVP_Behaviour_Marine_TestBehaviour :: RenderDebugInfo
//---------------------------------------------------------------------------
// Debug output is rendered by turning on the console var AVP.AI.RenderDebugInfo
#ifndef ASURA_NO_DEBUG_OUTPUT
void AVP_Behaviour_Marine_TestBehaviour::RenderDebugInfo()
{
	PARENT::RenderDebugInfo();
}
#endif

/// End Of File 'AVP_behaviour_Marine_TestBehaviour.cpp'
