//////////////////////////////////////////////////////////////////////////////
//
// AVP_Behaviour_Sentrygun_PointAndShoot.h
//
// Copyright (C) 2008 Rebellion. All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __AVP_BEHAVIOUR_SENTRYGUN_POINTANDSHOOT_H__
#define __AVP_BEHAVIOUR_SENTRYGUN_POINTANDSHOOT_H__ 1

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

// I N C L U D E S ///////////////////////////////////////////////////////////

// asura
#include "Network/Asura_Guid.h"

// avp axon
#include "Behaviour/Axon_Project_Behaviour.h"

// F O R W A R D   D E C L A R A T I O N S ///////////////////////////////////

class AVP_Brain_Actor_Sentrygun;

//////////////////////////////////////////////////////////////////////////////
//
// AVP_Behaviour_Sentrygun_PointAndShoot
//
//////////////////////////////////////////////////////////////////////////////

class AVP_Behaviour_Sentrygun_PointAndShoot : public Axon_Project_Behaviour
{
	typedef Axon_Project_Behaviour PARENT;

public:
	enum State
	{
		UNSET,
		SWEEPING,
		TARGETTING,
		LOST_TARGET,
		DISABLED,
		NUM_STATES
	};

	enum FiringState
	{
		FIRINGSTATE_UNSET,
		FIRINGSTATE_INVESTIGATING,
		FIRINGSTATE_FIRING,
		FIRINGSTATE_WAITING,
		FIRINGSTATE_DISABLED,
		NUM_FIRING_STATES
	};

	AVP_Behaviour_Sentrygun_PointAndShoot( AVP_Brain_Actor_Sentrygun* pxBrain );
	void SwitchToState( const State eNextState );

protected:

	virtual bool Activate();
	virtual void Deactivate();
	virtual void Update( const float fTimeslice );
	virtual void PerFrameUpdate( const float fTimeslice );

#ifndef ASURA_NO_DEBUG_OUTPUT
	virtual void RenderDebugInfo();
#endif

	AVP_Brain_Actor_Sentrygun* GetSentrygunBrain() const;

private:
	FiringState GetCurrentFiringState() const { return m_eFiringState; }
	void SwitchToFiringState( const FiringState eNextFiringState );

	void UpdateTargetDetails();
	bool HaveTarget() const;
	void TurnTowardsTarget();

	bool IsAbleToFire() const;

private:
	Asura_Guid		m_uTargetGuid;
	FiringState		m_eFiringState;
	float			m_fShootTimer;
	float			m_fInvestigateTime;
	float			m_fFireTime;
	float			m_fWaitTime;
	float			m_fLostTime;
	Asura_Vector_3	m_xTargetPosition;
	bool			m_bInvItemEndUsagePending;
};

#endif //__AVP_BEHAVIOUR_SENTRYGUN_POINTANDSHOOT_H__
