//////////////////////////////////////////////////////////////////////////////
//
// AVP_ServerEntity_PhysicsObject.h
//
// Copyright (c) 2006 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

// 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_PHYSICSOBJECT_H___
#define AVP_SERVERENTITY_PHYSICSOBJECT_H___ 1

// I N C L U D E S ///////////////////////////////////////////////////////////

// Engine independent.
#include "Entity/PhysicalObject/Asura_ServerEntity_PhysicsObject.h"

// Project independent.
#include "Entity/PhysicalObject/AVP_ServerEntity_PhysicalObject.h"

// C L A S S E S /////////////////////////////////////////////////////////////

class AVP_ServerEntity_PhysicsObject : public AVP_ServerEntity_PhysicalObject, public virtual Asura_ServerEntity_PhysicsObject
{

public:

	static AVP_ServerEntity_PhysicsObject* Create( Asura_Guid uGUID)	{ return(new AVP_ServerEntity_PhysicsObject (uGUID)); }

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

    virtual bool HandleMessage(const Asura_Message* pxMessage);
    virtual void Update( void );

    virtual void ReadFromChunkStream( Asura_Chunk_Stream& xStream );
	virtual void WriteToChunkStream( Asura_Chunk_Stream& xStream ) const;
        
    // Legacy chunk handling, to be removed as soon as possible.
	virtual bool IsFilledFromChunkBuffer( void ) const	{ return(false); }
    virtual int GetChunkBufferSize( void );
	virtual void InitialiseFromChunkBuffer( const char*& pcChunkBfr );
	virtual void FillInChunkBuffer( char*& pcChunkBfr );

#ifdef ASURA_TOOLS

    static void CreateFromTools( Asura_Guid uGUID );
    static void SetNewObjectShouldBeStatic( bool bStatic );

    virtual void ApplyChangesForTemplateInstance( Tools_EntityTemplateInstance* pxInstance );
    virtual bool CanBeIncludedInTemplate( void ) const;

#endif // #ifdef ASURA_TOOLS

	virtual bool GetHasCreateMessage() const { return true; }

	// Set this and this object will be cleared up when this actor no longer exists.
	void SetExitenceTiedToActor(Asura_Guid uActor) { m_uExistenceTiedTo = uActor; }

protected:

    AVP_ServerEntity_PhysicsObject( Asura_Guid uGUID = ASURA_GUID_UNREGISTERED, bool bAllocateDynamicsBlock = true );
    virtual ~AVP_ServerEntity_PhysicsObject( void );

    virtual void	MakeClientUpdateMessage(void);
	virtual void	MakeCreateMessage(Asura_Guid uRequestingClient, bool bSendGuaranteed = false);

	// Overridden event functions...
	virtual void	OnDeath(const AVP_EntityDamage_ApplyToEntity& xDamage);


private:

	Asura_Guid m_uExistenceTiedTo;

    typedef AVP_ServerEntity_PhysicalObject PARENT;
    typedef Asura_ServerEntity_PhysicsObject PARENT_ASURA;

#ifdef ASURA_TOOLS
    friend class ToolsAVP_Entity_PhysicsObject;
#endif

    static Asura_Hashed_List<AVP_ServerEntity_PhysicsObject> s_xList;

};

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef AVP_SERVERENTITY_PHYSICSOBJECT_H___
