//
// AVP_ClientEntity_CommandPost.h
//
// Created by RDM - 21 November 2006
//
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __AVP_CLIENTENTITY_COMMANDPOST_H__
#define __AVP_CLIENTENTITY_COMMANDPOST_H__

/************/
/* Includes */
/************/

// asura
#include "Rendering/Asura_Colour.h"
#include "SpecialFX/Asura_Beam_System.h"

// BF3
#include "Core/AVP_Settings.h"
#include "Entity/PhysicalObject/PhysicsObject/AVP_ClientEntity_PhysicsObject.h"

// Forward declarations
class Asura_PFX_Effect_Template;
class AVP_Message_CommandPost_ClientCreate;

/***********/
/* Classes */
/***********/

/*************************************************************
 *
 * Class Name    : AVP_ClientEntity_CommandPost
 *
 * Author        : Richard May
 *
 * Description   : Client entity for the BF3 command posts.
 *
 *************************************************************/
class AVP_ClientEntity_CommandPost : public AVP_ClientEntity_PhysicsObject
{
	friend class ToolsAVP_Entity_CommandPost;

private:
	typedef AVP_ClientEntity_PhysicsObject PARENT;

public:
	/* Public interface functions. */
	virtual void Update( void );																	
	virtual void Render( void );
	virtual bool HandleMessage( const Asura_Message* pxMsg );

	// accessors
	bool  IsContested( void ) const												{ return m_bContested; }
	bool  IsCaptureDisabled( void ) const										{ return m_bCaptureDisabled; }
	bool  IsDefaultSpawnPoint( void ) const										{ return m_bDefaultSpawnPoint; }
	bool  IsMobileCommandPost( void ) const										{ return m_bMobileCommandPost; } 

	float GetCaptureTime( void ) const											{ return m_fCaptureTime; }
	float GetCaptureTimer( void ) const											{ return m_fCaptureTimer; }
	int GetCurrentFaction( void ) const											{ return m_iCurrentFaction; }
	int GetFaction( void ) const												{ return m_iCurrentFaction; }
	int GetCapturingFaction( void ) const										{ return m_iCapturingFaction; }
	u_int GetCapturingGuid(void) const											{ return m_uCapturingGuid; }
	Asura_Hash_ID GetNameHashID(void) const										{ return m_uNameHashID; }						

	void  SetMobileCommandPost( bool bMobile )									{ m_bMobileCommandPost = bMobile; }
	void  SetCaptureTime( float fTime )											{ m_fCaptureTime = fTime; }
	void  SetCaptureTimer( float fTimer )										{ m_fCaptureTimer = fTimer; }
	void  SetCurrentFaction( int iFaction );
	void  SetCapturingGuid(u_int uGuid)											{ m_uCapturingGuid = uGuid;}
	void  SetCapturingFaction( int iFaction)									{ m_iCapturingFaction = iFaction; }
	void  SetContested( bool bContested )										{ m_bContested = bContested; }
	void  SetCaptureDisabled( bool bCaptureDisabled )							{ m_bCaptureDisabled = bCaptureDisabled; }
	void  SetDefaultSpawnPoint( bool bDefault )									{ m_bDefaultSpawnPoint = bDefault; }
	void  SetNameHashID( Asura_Hash_ID uNameHashID )							{ m_uNameHashID = uNameHashID; }
	
	void KillHumSound();

	/* Static functions. */
	static AVP_ClientEntity_CommandPost* FindEntity( Asura_Guid uGUID )			{ return s_xList.FindEntity( uGUID ); }
	static Asura_Hashed_List<AVP_ClientEntity_CommandPost>* GetList( void )		{ return &s_xList; }
	static Asura_Entity* Create( const Asura_Message* pxMessage );

	static u_int GetInstanceCount() { return s_uInstanceCount; }
	static u_int GetNumberOwnedByTeam( const AVP_Settings::Team eTeam );

	static void KillAllHumSounds();
	static void Pause();
	static void Unpause();

protected:
	/* Constructors/destructor. */
	AVP_ClientEntity_CommandPost();
	virtual ~AVP_ClientEntity_CommandPost();

	// Initialisation after client creation
	virtual void PostCreateInitialise();

	// Messages
	void	ProcessClientCreate(const AVP_Message_CommandPost_ClientCreate* pxData, float fServerTime, bool bProcessPosAndOri = true);

	/* Helper functions. */		
	void UpdatePFX();
	void UpdateSound();
	void UpdateAnims();
	void UpdateBeam();

	virtual void OnEntityActivate( void );
	virtual void OnEntityDeactivate( void );

	void DecrementNumberOwnedByTeam( const u_int uTeam );
	void IncrementNumberOwnedByTeam( const u_int uTeam );
	
	Asura_PFX_Effect_Template* CreateColourisedPFXEffectTemplate( Asura_Hash_ID uSourceEffectTempID, Asura_Hash_ID uNewEffectTempID, const Asura_RGBA& xColour );
	
		/* Data. */		
	int m_iCurrentFaction;
	int m_iCapturingFaction;
	u_int m_uCapturingGuid;
	float m_fCaptureTime;
	float m_fCaptureTimer;
	float m_fBeamLength;
	float m_fPulseTimer;
	Asura_Handle m_iHumSoundHandle;
	u_int* m_puPulsePFXHandles;
	u_int* m_puBeamPFXHandles;
	u_int* m_puBeamIDs;
	Asura_Animation** m_pxIconAnims;
	Asura_Hash_ID	m_uNameHashID; 

	union
	{
		struct
		{
			u_int m_bCaptureDisabled : 1,
				  m_bContested : 1,
				  m_bMobileCommandPost	  : 1,
				  m_bDefaultSpawnPoint : 1,
				  _CMD_POST_UNUSED : 28;
		};

		u_int m_uCommandPostFlags;
	};

	/* Static Data. */
	static u_int s_uInstanceCount;								   // number of existing command post entities
	static u_int s_auNumberOwnedByTeam[AVP_Settings::AVP_NUM_TEAMS]; // number of command post entities owned by evil team
	
	static Asura_Hashed_List<AVP_ClientEntity_CommandPost> s_xList;
	static const Asura_Hash_ID s_auPulsePFX[AVP_Settings::AVP_NUM_TEAMS];
	static const Asura_Hash_ID s_auBeamPFXCaptured[AVP_Settings::AVP_NUM_TEAMS];
	static const Asura_Hash_ID s_auBeamPFXNeutral[AVP_Settings::AVP_NUM_TEAMS];
	static const Asura_Hash_ID s_auIconSkinIDs[AVP_Settings::AVP_NUM_TEAMS];
	static Asura_Beam_Template s_axBeamTemplates[AVP_Settings::AVP_NUM_TEAMS];
	static const Asura_Hash_ID s_uIconAnimID;
	static const Asura_Hash_ID s_uOpenAnimID;	

	static bool s_bIsPaused;
};
/* end of class AVP_ClientEntity_CommandPost */


/***************/
/* End of File */
/***************/

#endif//__AVP_CLIENTENTITY_COMMANDPOST_H__
