//////////////////////////////////////////////////////////////////////////////
//
// Asura_ServerEntity_ForceField_Conveyor.h
//
// Copyright (c) 2007 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
	#pragma once
#endif

#ifndef __ASURA_SERVERENTITY_FORCEFIELD_CONVEYOR_H__
#define __ASURA_SERVERENTITY_FORCEFIELD_CONVEYOR_H__

#include "Core/Asura_OrientedVolume.h"
#include "Entity/Asura_Entity.h"
#include "Entity/Triggers/Asura_ServerEntity_Activatable.h"
#include "Network/Asura_Guid.h"

#ifdef ASURA_TOOLS
#include "Entity/Asura_Entity_Classification.h"
#endif

class Asura_Physics_ForceField_Conveyor;

class Asura_ServerEntity_ForceField_Conveyor : public Asura_ServerEntity_ActivatableWithPosition
{
	friend class Asura_Message_ForceField_ClientUpdate;
	friend class Tools_Entity_ForceField_Conveyor;

public:

	//Constructors / Destructors
	Asura_ServerEntity_ForceField_Conveyor(bool bInitiallyActive = true);
	Asura_ServerEntity_ForceField_Conveyor(const Asura_Guid uGuid);

	virtual ~Asura_ServerEntity_ForceField_Conveyor();

	#ifdef ASURA_TOOLS
	virtual void ApplyChangesForTemplateInstance(class Tools_EntityTemplateInstance* pxInstance);
	virtual bool CanBeIncludedInTemplate() const {return Classification == AsuraEntityClass_ForceField_Conveyor;}

	virtual void AddVolume();
	virtual void RemoveVolume(u_int uIndex);
	virtual void UpdatePhysicsFields();
	#endif //ASURA_TOOLS

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

	// Public functions...
	static Asura_ServerEntity_ForceField_Conveyor*	Create(const Asura_Guid uGuid );
	static Asura_ServerEntity_ForceField_Conveyor*	Create(const Asura_Guid uGuid, Asura_Chunk_Stream& xStream);
	
	static Asura_ServerEntity_ForceField_Conveyor*							FindEntity(const Asura_Guid uGuid)	{ return(s_xList.FindEntity(uGuid)); }
	static const Asura_Hashed_List<Asura_ServerEntity_ForceField_Conveyor>*	GetList(void)						{ return(&s_xList); }

	u_int GetNumberOfVolumes() { return m_uNumVolumes;}
	Asura_Bounding_Box* GetVolumeBox(u_int uIndex) { return &m_pxVolumes[uIndex].m_xBox;}
	Asura_Quat* GetVolumeOrient(u_int uIndex) { return &m_pxVolumes[uIndex].m_xOrient;}

	void SetForce(Asura_Vector_3 xForce) { m_xForce = xForce; }
	const Asura_Vector_3 GetForce() const { return m_xForce; }

	void SetForceEuler(Asura_Euler_3 xForceEuler) { m_xForceEuler = xForceEuler; }
	const Asura_Euler_3 GetForceEuler() const { return m_xForceEuler; }

	virtual	bool IsFilledFromChunkBuffer() const { return false; }

	virtual void CreatePhysicsFields();
	virtual void DestroyPhysicsFields();
	
	virtual void OnActivation();
	virtual void OnDeactivation();
	virtual void SetFieldsActive(bool bActive);

protected:

	enum { CURRENT_CHUNK_VERSION = 1 };

	Asura_Vector_3		m_xForce;
	Asura_Euler_3		m_xForceEuler;
	u_int m_uNumVolumes;
	Asura_OrientedVolume* m_pxVolumes;


	Asura_Physics_ForceField_Conveyor** m_ppxConveyor;

private:
	typedef Asura_ServerEntity_ActivatableWithPosition PARENT;

	// Static list of teleporters...
	static Asura_Hashed_List<Asura_ServerEntity_ForceField_Conveyor>	s_xList;


//Static methods
public:

#ifdef ASURA_TOOLS
	static Asura_ServerEntity_ForceField_Conveyor* CreateFromTools();
#endif //ASURA_TOOLS


protected:
};


#endif//__ASURA_SERVERENTITY_FORCEFIELD_CONVEYOR_H__
