2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Vector3d.h"
|
|
|
|
#include "Vector3f.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-27 05:02:06 -05:00
|
|
|
// Place this macro in the public section of each cEntity descendant class and you're done :)
|
2012-12-21 07:21:20 -05:00
|
|
|
#define CLASS_PROTODEF(classname) \
|
|
|
|
virtual bool IsA(const char * a_ClassName) const override\
|
|
|
|
{ \
|
|
|
|
return ((strcmp(a_ClassName, #classname) == 0) || super::IsA(a_ClassName)); \
|
|
|
|
} \
|
|
|
|
virtual const char * GetClass(void) const override \
|
|
|
|
{ \
|
|
|
|
return #classname; \
|
|
|
|
} \
|
2013-02-02 18:55:29 -05:00
|
|
|
static const char * GetClassStatic(void) \
|
|
|
|
{ \
|
|
|
|
return #classname; \
|
|
|
|
} \
|
2012-12-21 07:21:20 -05:00
|
|
|
virtual const char * GetParentClass(void) const override \
|
|
|
|
{ \
|
|
|
|
return super::GetClass(); \
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cWorld;
|
|
|
|
class cReferenceManager;
|
|
|
|
class cClientHandle;
|
2012-12-22 05:15:53 -05:00
|
|
|
class MTRand;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 17:14:45 -04:00
|
|
|
// tolua_begin
|
|
|
|
class cEntity
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ENTITY_STATUS_HURT = 2,
|
|
|
|
ENTITY_STATUS_DEAD = 3,
|
|
|
|
ENTITY_STATUS_WOLF_TAMING = 6,
|
|
|
|
ENTITY_STATUS_WOLF_TAMED = 7,
|
|
|
|
ENTITY_STATUS_WOLF_SHAKING = 8,
|
|
|
|
ENTITY_STATUS_EATING_ACCEPTED = 9,
|
|
|
|
ENTITY_STATUS_SHEEP_EATING = 10,
|
|
|
|
} ;
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
enum eEntityType
|
|
|
|
{
|
|
|
|
etEntity, // For all other types
|
|
|
|
etPlayer,
|
|
|
|
etPickup,
|
|
|
|
etMob,
|
|
|
|
etFallingBlock,
|
2013-02-18 11:48:50 -05:00
|
|
|
etMinecart,
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
// Older constants, left over for compatibility reasons (plugins)
|
|
|
|
eEntityType_Entity = etEntity,
|
|
|
|
eEntityType_Player = etPlayer,
|
|
|
|
eEntityType_Pickup = etPickup,
|
|
|
|
eEntityType_Mob = etMob,
|
|
|
|
} ;
|
2013-02-21 16:55:36 -05:00
|
|
|
|
|
|
|
// tolua_end
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
|
|
cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z);
|
2012-08-19 17:14:45 -04:00
|
|
|
virtual ~cEntity();
|
|
|
|
|
2012-08-24 03:58:26 -04:00
|
|
|
virtual void Initialize(cWorld * a_World);
|
2012-08-19 17:14:45 -04:00
|
|
|
|
2013-02-21 16:55:36 -05:00
|
|
|
// tolua_begin
|
|
|
|
|
2012-12-21 07:52:14 -05:00
|
|
|
eEntityType GetEntityType(void) const { return m_EntityType; }
|
|
|
|
|
2013-02-27 05:02:06 -05:00
|
|
|
bool IsPlayer (void) const { return (m_EntityType == etPlayer); }
|
|
|
|
bool IsPickup (void) const { return (m_EntityType == etPickup); }
|
|
|
|
bool IsMob (void) const { return (m_EntityType == etMob); }
|
|
|
|
bool IsMinecart(void) const { return (m_EntityType == etMinecart); }
|
2012-12-21 07:21:20 -05:00
|
|
|
|
|
|
|
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
|
|
|
|
virtual bool IsA(const char * a_ClassName) const;
|
|
|
|
|
|
|
|
/// Returns the topmost class name for the object
|
|
|
|
virtual const char * GetClass(void) const;
|
2013-02-02 18:55:29 -05:00
|
|
|
|
|
|
|
// Returns the class name of this class
|
|
|
|
static const char * GetClassStatic(void);
|
2012-12-21 07:21:20 -05:00
|
|
|
|
|
|
|
/// Returns the topmost class's parent class name for the object. cEntity returns an empty string (no parent).
|
|
|
|
virtual const char * GetParentClass(void) const;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-12-21 05:59:59 -05:00
|
|
|
cWorld * GetWorld(void) const { return m_World; }
|
|
|
|
|
2013-02-10 08:33:01 -05:00
|
|
|
const Vector3d & GetPosition (void) const {return m_Pos; }
|
|
|
|
double GetPosX (void) const {return m_Pos.x; }
|
|
|
|
double GetPosY (void) const {return m_Pos.y; }
|
|
|
|
double GetPosZ (void) const {return m_Pos.z; }
|
|
|
|
const Vector3f & GetRot (void) const {return m_Rot; }
|
|
|
|
float GetRotation (void) const {return m_Rot.x; }
|
|
|
|
float GetPitch (void) const {return m_Rot.y; }
|
|
|
|
float GetRoll (void) const {return m_Rot.z; }
|
|
|
|
Vector3f GetLookVector(void) const;
|
2013-02-21 16:55:36 -05:00
|
|
|
const Vector3d & GetSpeed (void) const { return m_Speed; }
|
|
|
|
double GetSpeedX (void) const { return m_Speed.x; }
|
|
|
|
double GetSpeedY (void) const { return m_Speed.y; }
|
|
|
|
double GetSpeedZ (void) const { return m_Speed.z; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-12-21 05:59:59 -05:00
|
|
|
int GetChunkX(void) const {return m_ChunkX; }
|
|
|
|
int GetChunkY(void) const {return m_ChunkY; }
|
|
|
|
int GetChunkZ(void) const {return m_ChunkZ; }
|
|
|
|
|
|
|
|
void SetPosX (double a_PosX);
|
|
|
|
void SetPosY (double a_PosY);
|
|
|
|
void SetPosZ (double a_PosZ);
|
|
|
|
void SetPosition(double a_PosX, double a_PosY, double a_PosZ);
|
|
|
|
void SetPosition(const Vector3d & a_Pos);
|
|
|
|
void SetRot (const Vector3f & a_Rot);
|
|
|
|
void SetRotation(float a_Rotation);
|
|
|
|
void SetPitch (float a_Pitch);
|
|
|
|
void SetRoll (float a_Roll);
|
|
|
|
// tolua_end
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
inline int GetUniqueID(void) const { return m_UniqueID; } // tolua_export
|
|
|
|
inline bool IsDestroyed(void) const { return m_bDestroyed; } // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
void Destroy(); // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
void RemoveFromChunk(void); // for internal use in cChunk
|
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
virtual void Tick(float a_Dt, MTRand & a_TickRandom); // tolua_export
|
|
|
|
virtual void HandlePhysics(float a_Dt) {} // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-24 03:58:26 -04:00
|
|
|
/** Descendants override this function to send a command to the specified client to spawn the entity on the client.
|
|
|
|
To spawn on all eligible clients, use cChunkMap::BroadcastSpawnEntity()
|
|
|
|
Needs to have a default implementation due to Lua bindings.
|
|
|
|
*/
|
|
|
|
virtual void SpawnOn(cClientHandle & a_Client) {ASSERT(!"SpawnOn() unimplemented!"); } // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
void WrapRotation();
|
2012-08-28 17:59:49 -04:00
|
|
|
|
|
|
|
// Metadata flags; descendants may override the defaults:
|
|
|
|
virtual bool IsOnFire (void) const {return (m_BurnPeriod > 0); }
|
|
|
|
virtual bool IsCrouched (void) const {return false; }
|
|
|
|
virtual bool IsRiding (void) const {return false; }
|
|
|
|
virtual bool IsSprinting(void) const {return false; }
|
|
|
|
virtual bool IsRclking (void) const {return false; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void Destroyed() {} // Called after the entity has been destroyed
|
|
|
|
|
|
|
|
void SetWorld( cWorld* a_World ) { m_World = a_World; }
|
|
|
|
void MoveToCorrectChunk(bool a_bIgnoreOldChunk = false);
|
|
|
|
|
|
|
|
friend class cReferenceManager;
|
|
|
|
void AddReference( cEntity*& a_EntityPtr );
|
|
|
|
void ReferencedBy( cEntity*& a_EntityPtr );
|
|
|
|
void Dereference( cEntity*& a_EntityPtr );
|
|
|
|
|
|
|
|
static cCriticalSection m_CSCount;
|
|
|
|
static int m_EntityCount;
|
|
|
|
|
|
|
|
int m_UniqueID;
|
|
|
|
|
|
|
|
cReferenceManager* m_Referencers;
|
|
|
|
cReferenceManager* m_References;
|
|
|
|
|
|
|
|
int m_ChunkX, m_ChunkY, m_ChunkZ;
|
|
|
|
Vector3d m_Pos;
|
2013-02-21 16:55:36 -05:00
|
|
|
bool m_bDirtyPosition;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
Vector3f m_Rot;
|
2013-02-21 16:55:36 -05:00
|
|
|
bool m_bDirtyOrientation;
|
|
|
|
|
|
|
|
Vector3d m_Speed;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
bool m_bDestroyed;
|
|
|
|
bool m_bRemovedFromChunk;
|
|
|
|
|
|
|
|
eEntityType m_EntityType;
|
|
|
|
|
|
|
|
cWorld* m_World;
|
2012-08-28 17:59:49 -04:00
|
|
|
|
|
|
|
float m_FireDamageInterval;
|
|
|
|
float m_BurnPeriod;
|
2013-01-11 23:46:01 -05:00
|
|
|
}; // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
typedef std::list<cEntity *> cEntityList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|