//---------------------------------------------------------------------------
// File			: AVP_Behaviour_Sentrygun.h
// Created		: 12 / 02 / 2008
// Created By	: Gareth Thomas
// Copyright (C) 2007 Rebellion. All Rights Reserved.
//---------------------------------------------------------------------------

// BEGIN FILE WRAPPER ///////////////////////////////////////
#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif
#ifndef __AVP_BEHAVIOUR_SENTRYGUN_H__
#define __AVP_BEHAVIOUR_SENTRYGUN_H__ 1
// END FILE WRAPPER ///////////////////////////////////////////

// INCLUDES ///////////////////////////////////////////////////////////
#include "Behaviour/Axon_Project_Behaviour.h"

// FORWARD DECLARATIONS ///////////////////////////////////
class AVP_Brain_Actor_Sentrygun;
class AVP_ServerEntity_GamePlayVolume;

//---------------------------------------------------------------------------
// Class		: AVP_Behaviour_Sentrygun
// Description	: 
//---------------------------------------------------------------------------
class AVP_Behaviour_Sentrygun : public Axon_Project_Behaviour
{
	typedef Axon_Project_Behaviour PARENT;

public:

	// Sentrygun Update State Enum
	enum UpdateState
	{
		UNSET,
		DISABLED,
		SWEEPING,
		ATTACK,
		DESTROYED,
		MAX_STATES
	};

	enum FiringState
	{
		FIRING_STATE_WAIT,
		FIRING_STATE_SHOOT,
		MAX_FIRING_STATES
	};

	// Construction / Deconstruction
	AVP_Behaviour_Sentrygun( AVP_Brain_Actor_Sentrygun* pxBrain );
	virtual ~AVP_Behaviour_Sentrygun() {}

	virtual void ReadFromChunkStream( Asura_Chunk_Stream& xStream );
	virtual void WriteToChunkStream( Asura_Chunk_Stream& xStream ) const;
	virtual void PostLoadInitialise();

	// Public Member Virtual Functions...
	virtual bool Activate();
	virtual bool HandleMessage( const Asura_Message* pxMessage );
	virtual void Deactivate();
	virtual void PerFrameUpdate( const float fTimeslice );

#ifndef ASURA_NO_DEBUG_OUTPUT
	virtual void RenderDebugInfo( void );
#endif


protected:
	
	void							SwitchToState( UpdateState eState );
	void							TurnTowardsTarget( void );
	AVP_Brain_Actor_Sentrygun*		GetSentrygunBrain( void )	{ return m_pxSentrygunBrain; }
	void							FiringUpdate( const float fTimeslice );
	void							StopShooting( void );
	void							StartShooting( void );
	bool							IsAbleToFire( void );
	void							DoSweep( const float fTimeslice );
	void							SendAttackInfo( void );

private:

#ifndef ASURA_NO_DEBUG_OUTPUT
	void							AddNonSymetricalFrustumToRenderList(  u_int uMarkerPoint, float fVisionRange, float fTanHorHalfFOV, u_int uColour );
#endif

	// Private Member Variables...
	UpdateState						m_eCurrentState;		// used for update routeins. 
	FiringState						m_eFiringState;			// used to control burst fire
	AVP_Brain_Actor_Sentrygun*		m_pxSentrygunBrain;
	float							m_fFiringTimer;
	float							m_fFireTime;
	float							m_fWaitTime;
	Asura_Angle						m_xSweepAngle;
	bool							m_bSweepDirection;
	float							m_fSweepTimer;
	float							m_fFoundTargetPause;
	float							m_fLostTargetPause;
	float							m_fPauseTimer;
	u_int							m_uLastTargetGuid;
	u_int							m_iDryFireCount;
};

#endif //__AVP_BEHAVIOUR_SENTRYGUN_H__

/// End Of File 'AVP_Behaviour_Sentrygun.h'
