//////////////////////////////////////////////////////////////////////////////
//
// AVP_ServerEntity_Vent.h
//
// Copyright (c) 2008 Rebellion. All rights reserved.
//
// Description:
//
//     Vent for getting in to/out of ducts
//
//////////////////////////////////////////////////////////////////////////////

// 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_SERVERENTITY_VENT_H___
#define ___AVP_SERVERENTITY_VENT_H___ 1

#include "Entity/Asura_Entity.h"

#include "Entity/Vent/AVP_Vent_Messages.h"

#define AVP_MAX_VENT_NODES 16
#define AVP_MAX_START_NODES_PER_VENT_NODE 4

class AVP_ServerEntity_PhysicalObject;

class AVP_ServerEntity_Vent : public Asura_Entity_Server
{
private:
	struct ExitPoint
	{
		Asura_Vector_3 m_xPosition;
		Asura_Quat m_xOrientation;
	};

public:
	AVP_ServerEntity_Vent(const Asura_Guid uGUID = ASURA_GUID_UNREGISTERED);

	const Asura_Vector_3& GetPosition() const { return m_xPosition; }
	const Asura_Matrix_3x3& GetOrientation() const { return m_xOrientation; }

	void SetPosition( const Asura_Vector_3& xPos ) { m_xPosition = xPos; }
	void SetOrientation( const Asura_Matrix_3x3& xOri ) { m_xOrientation = xOri; }

	bool IsDamaged() const { return m_bIsDamaged; }
	Asura_Hash_ID GetUndamagedSkinHash() const { return m_uUndamagedSkinHash; }
	Asura_Hash_ID GetDamagedSkinHash() const { return m_uDamagedSkinHash; }
	
	virtual	bool CanBeSavedToChunk(void) const			{ return true; }
	virtual	bool IsFilledFromChunkBuffer(void) const	{ return false; }
	virtual void WriteToChunkStream(Asura_Chunk_Stream& xStream) const;
	virtual void ReadFromChunkStream(Asura_Chunk_Stream& xStream);

	virtual bool GetHasCreateMessage() const { return true; }
	virtual void MakeCreateMessage(Asura_Guid uRequestingClient, bool bSendGuaranteed = false);

#ifdef ASURA_TOOLS
	void CreateDefaultExitPoints();
	void CreateExitPoint(const Asura_Vector_3& xPosition, const Asura_Quat& xOrientation);
	void DeleteExitPoint(u_int uIndex);
	void CopyExitPoints(const u_int uNumPoints, const ExitPoint* pxExitPoints); // For the tools copy functionality.

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

	static AVP_ServerEntity_Vent* Create(Asura_Guid uGuid) { return new AVP_ServerEntity_Vent(uGuid); }

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

protected:
// 	virtual void	InitialiseFromBlueprint( const Asura_Blueprint& xBlueprint );

	static bool AreNodesConnected( const u_int uStartNode, const u_int uEndNode );

	virtual ~AVP_ServerEntity_Vent(void);

private:
	typedef Asura_Entity_Server PARENT;

	friend class ToolsAVP_Entity_Vent;
	friend class AVP_Message_Vent_ClientCreate;

	Asura_Vector_3		m_xPosition;
	Asura_Matrix_3x3	m_xOrientation;

	bool				m_bIsDamaged;

	Asura_Hash_ID		m_uUndamagedSkinHash;
	Asura_Hash_ID		m_uDamagedSkinHash;

	u_int				m_uNumVentNodes;
	Asura_Guid			m_auVentNode[ AVP_MAX_VENT_NODES ];

	u_int m_uNumExitPoints;
	ExitPoint* m_pxExitPoints;

	static Asura_Hashed_List<AVP_ServerEntity_Vent> s_xList;
};

#endif // #ifndef ___AVP_SERVERENTITY_VENT_H___
