//--------------------------------------------------------------------------------------
//	File	:	AVP_ServerEntity_AlienSpawnPoint.h
//	Created	:	22 / 10 / 07
//	Author	:	Gareth Thomas
//	Copyright (C) 2006 Rebellion, All Rights Reserved.
//--------------------------------------------------------------------------------------
#ifdef ASURA_USE_PRAGMA_ONCE 
#pragma once
#endif   // ifdef ASURA_USE_PRAGMA_ONCE
#ifndef __AVP_SERVERENTITY_ALIENSPAWNPOINT_H__
#define __AVP_SERVERENTITY_ALIENSPAWNPOINT_H__ 1

//--------------------------------------------------------------------------------------
//	INCLUDES
//--------------------------------------------------------------------------------------
#include "Entity/Asura_Entity.h"

#include "Entity/Spawners/AVP_ServerEntity_SpawnPoint.h"

// Forward Declarations

class AVP_ServerActor_Alien;
class Tools_EntityTemplateInstance;

//--------------------------------------------------------------------------------------
//	Class	:	AVP_ServerEntity_AlienSpawnPoint
//	Created	:	22 / 10 / 07
//	Author	:	Gareth Thomas
//--------------------------------------------------------------------------------------
class AVP_ServerEntity_AlienSpawnPoint : public AVP_ServerEntity_SpawnPoint
{
public:
	static const float fALIEN_SPAWNPOINT_DEFAULT_RADIUS;

	void Spawn(Asura_Hash_ID uBlueprintTypeHashID, Asura_Hash_ID uBlueprintHashID);

	bool		IsInUse() const;
	bool		IsInsideRadius( const Asura_Vector_3& xPosition ) const	{ return ( ( xPosition - GetPosition() ).MagnitudeSquared() <= ( m_fRadius * m_fRadius ) ); }
	bool		IsNearExitPoint( const Asura_Vector_3& xPosition ) const;

	float		GetRadius() const { return m_fRadius; }
	u_int		GetNumSpawnPointLinks() const { return m_uNumSpawnPointLinks; }
	Asura_Guid* GetSpawnPointLinks() const { return m_puSpawnPointLinks; }
	const Asura_Vector_3& GetExitPoint() const;

	virtual void PostLoadInitialise( void ) { FindNearestWaypoint(); CalculateRealAgility(); }

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

	u_short		GetCurrentWaypointID( void ) const { return m_usWaypointID; }
	int			GetRealAgilityValue( void ) const { return m_iRealAgilityValue; }
	float		GetIdleTimeLeft( void ) const { return m_fIdleTimeLeft; }

	static AVP_ServerEntity_AlienSpawnPoint*							Create(const Asura_Guid uGuid);
	static AVP_ServerEntity_AlienSpawnPoint*							FindEntity(Asura_Guid uGuid)	{return s_xList.FindEntity(uGuid);}
	static const Asura_Hashed_List<AVP_ServerEntity_AlienSpawnPoint>*	GetList(void)					{return &s_xList;}

#ifdef ASURA_TOOLS
	virtual bool CanBeIncludedInTemplate() const;
	virtual void ApplyChangesForTemplateInstance( Tools_EntityTemplateInstance* pxInstance );
#endif

protected:	
	AVP_ServerEntity_AlienSpawnPoint( const Asura_Guid uGuid );
	virtual ~AVP_ServerEntity_AlienSpawnPoint();

private:
	int			m_iAgilityValue;
	float		m_fRadius;
	u_int		m_uNumSpawnPointLinks;
	Asura_Guid* m_puSpawnPointLinks;
	u_int		m_uGroupID;
	float		m_fIdleTimeLeft;

	u_short		m_usWaypointID;			// Don't save these
	int			m_iRealAgilityValue;	//.

	void FindNearestWaypoint( void );
	void CalculateRealAgility( void );

	//	Friend classes
	friend class ToolsAVP_Entity_AlienSpawnPoint;

	//	Private typedefs
	typedef AVP_ServerEntity_SpawnPoint PARENT;

	// Chunk Version
	enum { CURRENT_CHUNK_VERSION = 5 };

	//	Private statics
	static Asura_Hashed_List< AVP_ServerEntity_AlienSpawnPoint > s_xList;
};
/// End of class 'AVP_ServerEntity_AlienSpawnPoint'. ///

#endif   /// ifndef __AVP_SERVERENTITY_ALIENSPAWNPOINT_H__
