//////////////////////////////////////////////////////////////////////////////
//
// AVP_ServerEntity_RoomNode.h
//
// Created by AJK 15/01/2009
//
// Copyright (c) 2009 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef AVP_SERVERENTITY_ROOMNODE_H
#define AVP_SERVERENTITY_ROOMNODE_H

// Asura
#include "Core/Asura_LinkList.h"
#include "Entity/Asura_Entity.h"
#include "Volume/Asura_VolumeGroup.h"

class AVP_RoomNode_ExitLink;
class AVP_ServerEntity_Actor;

class AVP_ServerEntity_RoomNode : public Asura_Entity_Server
{
public:
	static AVP_ServerEntity_RoomNode* Create(Asura_Guid uGuid)			 { return new AVP_ServerEntity_RoomNode(uGuid); }
	static AVP_ServerEntity_RoomNode* FindEntity(Asura_Guid uGuid)		 { return s_xList.FindEntity(uGuid); }
	static const Asura_Hashed_List<AVP_ServerEntity_RoomNode>* GetList() { return &s_xList; }    

	virtual bool 	CanBeSavedToChunk( void ) const						 { return ( true );  }
	virtual bool	IsFilledFromChunkBuffer( void ) const				 { return ( false ); }
	virtual void	ReadFromChunkStream(Asura_Chunk_Stream& xStream);
	virtual void	WriteToChunkStream(Asura_Chunk_Stream& xStream) const;
	virtual bool	HasClientEntities() const { return false; }

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

	const Asura_VolumeGroup&	                    GetVolumeGroup()   const { return m_xVolumeGroup;   }
	      Asura_VolumeGroup&	                    GetVolumeGroup() { return m_xVolumeGroup;   }
	const Asura_LinkList< AVP_RoomNode_ExitLink* >& GetLinkList() const { return m_xLinkList; }
	Asura_LinkList< AVP_RoomNode_ExitLink* >&       GetLinkList() { return m_xLinkList; }
	      AVP_RoomNode_ExitLink*                    GetExitLinkTo( Asura_Guid uToRoomNode, u_int uID ) const;
	const AVP_RoomNode_ExitLink*                    GetNearestExitLinkTo( Asura_Guid uToRoomNode, const AVP_ServerEntity_Actor& xActor ) const;
	      bool                                      HasExitLinkForSpecies(const AVP_ServerEntity_Actor& xActor ) const;
	      u_int                                     GetMaxExitLinkID() const;
	bool                                            IsOldVersion() const { return m_bOldVersion; }
	void                  SetPosition ( const Asura_Vector_3& xPos ) { m_xPosition = xPos; }
	const Asura_Vector_3& GetPosition() const { return m_xPosition; }
	u_int GetLinkedExitLinksCount () const;
	void  ConvertOldVersionLinks();

protected:
	AVP_ServerEntity_RoomNode( Asura_Guid uGuid = ASURA_GUID_UNREGISTERED );
	virtual ~AVP_ServerEntity_RoomNode();

private:
	enum { CURRENT_CHUNK_VERSION = 9};

	typedef Asura_Entity_Server PARENT;

	Asura_VolumeGroup						m_xVolumeGroup;
	Asura_LinkList <AVP_RoomNode_ExitLink*> m_xLinkList;
	Asura_Vector_3				            m_xPosition;
	bool                                    m_bOldVersion;

#ifdef ASURA_TOOLS
	friend class ToolsAVP_Entity_RoomNode;
	friend class ToolsAVP_Entity_RoomNode_VolumeEdit_Controller;
#endif

	static Asura_Hashed_List<AVP_ServerEntity_RoomNode> s_xList;
};

#endif // #ifndef AVP_SERVERENTITY_ROOMNODE_H
