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;
|
2013-03-03 14:05:11 -05:00
|
|
|
|
class cPlayer;
|
2013-04-13 17:02:10 -04:00
|
|
|
|
class cChunk;
|
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,
|
2013-03-09 09:35:43 -05:00
|
|
|
|
etMonster,
|
|
|
|
|
etMob = etMonster, // DEPRECATED, use etMonster instead!
|
2012-12-21 07:52:14 -05:00
|
|
|
|
etFallingBlock,
|
2013-02-18 11:48:50 -05:00
|
|
|
|
etMinecart,
|
2013-04-17 22:42:45 -04:00
|
|
|
|
etTNT,
|
2012-12-21 07:52:14 -05:00
|
|
|
|
|
2013-03-09 09:35:43 -05:00
|
|
|
|
// DEPRECATED older constants, left over for compatibility reasons (plugins)
|
2012-12-21 07:52:14 -05:00
|
|
|
|
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); }
|
2013-06-15 14:11:27 -04:00
|
|
|
|
bool IsTNT (void) const { return (m_EntityType == etTNT); }
|
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-03-01 14:33:41 -05:00
|
|
|
|
|
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-05-21 01:49:56 -04:00
|
|
|
|
double GetHeadYaw (void) const { return m_HeadYaw; }
|
|
|
|
|
double GetHeight (void) const { return m_Height; }
|
|
|
|
|
double GetMass (void) const { return m_Mass; }
|
|
|
|
|
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 Vector3d & GetRot (void) const { return m_Rot; }
|
|
|
|
|
double GetRotation (void) const { return m_Rot.x; }
|
|
|
|
|
double GetPitch (void) const { return m_Rot.y; }
|
|
|
|
|
double GetRoll (void) const { return m_Rot.z; }
|
2013-03-09 09:35:43 -05:00
|
|
|
|
Vector3d GetLookVector(void) const;
|
2013-05-21 01:49:56 -04:00
|
|
|
|
const Vector3d & GetSpeed (void) const { return m_Speed; }
|
2013-02-21 16:55:36 -05:00
|
|
|
|
double GetSpeedX (void) const { return m_Speed.x; }
|
|
|
|
|
double GetSpeedY (void) const { return m_Speed.y; }
|
|
|
|
|
double GetSpeedZ (void) const { return m_Speed.z; }
|
2013-05-21 01:49:56 -04:00
|
|
|
|
double GetWidth (void) const { return m_Width; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-05-19 07:49:01 -04:00
|
|
|
|
int GetChunkX(void) const {return (int)floor(m_Pos.x / cChunkDef::Width); }
|
|
|
|
|
int GetChunkZ(void) const {return (int)floor(m_Pos.z / cChunkDef::Width); }
|
2012-12-21 05:59:59 -05:00
|
|
|
|
|
2013-04-02 02:48:31 -04:00
|
|
|
|
void SetHeadYaw (double a_HeadYaw);
|
2013-05-21 01:49:56 -04:00
|
|
|
|
void SetHeight (double a_Height);
|
2013-04-28 14:54:43 -04:00
|
|
|
|
void SetMass (double a_Mass);
|
2012-12-21 05:59:59 -05:00
|
|
|
|
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);
|
2013-03-22 02:33:10 -04:00
|
|
|
|
void SetPosition(const Vector3d & a_Pos) { SetPosition(a_Pos.x,a_Pos.y,a_Pos.z);}
|
2012-12-21 05:59:59 -05:00
|
|
|
|
void SetRot (const Vector3f & a_Rot);
|
2013-03-09 09:35:43 -05:00
|
|
|
|
void SetRotation(double a_Rotation);
|
|
|
|
|
void SetPitch (double a_Pitch);
|
|
|
|
|
void SetRoll (double a_Roll);
|
|
|
|
|
void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ);
|
2013-04-13 17:02:10 -04:00
|
|
|
|
void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); }
|
2013-03-22 02:33:10 -04:00
|
|
|
|
void SetSpeedX (double a_SpeedX);
|
|
|
|
|
void SetSpeedY (double a_SpeedY);
|
|
|
|
|
void SetSpeedZ (double a_SpeedZ);
|
2013-05-21 01:49:56 -04:00
|
|
|
|
void SetWidth (double a_Width);
|
2013-03-03 14:05:11 -05:00
|
|
|
|
|
2013-03-23 00:33:47 -04:00
|
|
|
|
void AddPosX (double a_AddPosX);
|
|
|
|
|
void AddPosY (double a_AddPosY);
|
|
|
|
|
void AddPosZ (double a_AddPosZ);
|
|
|
|
|
void AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ);
|
|
|
|
|
void AddPosition(const Vector3d & a_AddPos) { AddPosition(a_AddPos.x,a_AddPos.y,a_AddPos.z);}
|
|
|
|
|
void AddSpeed (double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ);
|
|
|
|
|
void AddSpeed (const Vector3d & a_AddSpeed) { AddSpeed(a_AddSpeed.x,a_AddSpeed.y,a_AddSpeed.z);}
|
|
|
|
|
void AddSpeedX (double a_AddSpeedX);
|
|
|
|
|
void AddSpeedY (double a_AddSpeedY);
|
|
|
|
|
void AddSpeedZ (double a_AddSpeedZ);
|
2013-03-09 09:35:43 -05:00
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
|
inline int GetUniqueID(void) const { return m_UniqueID; }
|
|
|
|
|
inline bool IsDestroyed(void) const { return !m_IsInitialized; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
|
void Destroy(void);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
|
// tolua_end
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
|
virtual void Tick(float a_Dt, cChunk & a_Chunk);
|
2013-04-22 03:18:03 -04:00
|
|
|
|
virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk);
|
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.
|
|
|
|
|
*/
|
2013-03-01 14:33:41 -05:00
|
|
|
|
virtual void SpawnOn(cClientHandle & a_Client) {ASSERT(!"SpawnOn() unimplemented!"); }
|
2013-03-22 02:33:10 -04:00
|
|
|
|
|
2013-06-04 08:55:41 -04:00
|
|
|
|
/// Updates clients of changes in the entity.
|
2013-03-22 02:33:10 -04:00
|
|
|
|
virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = NULL);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-03-03 14:05:11 -05:00
|
|
|
|
/// Attaches to the specified entity; detaches from any previous one first
|
|
|
|
|
void AttachTo(cEntity * a_AttachTo);
|
|
|
|
|
|
|
|
|
|
/// Detaches from the currently attached entity, if any
|
|
|
|
|
void Detach(void);
|
|
|
|
|
|
2013-06-04 08:55:41 -04:00
|
|
|
|
/// Makes sure head yaw is not over the specified range.
|
2013-04-02 02:48:31 -04:00
|
|
|
|
void WrapHeadYaw();
|
|
|
|
|
|
2013-06-04 08:55:41 -04:00
|
|
|
|
/// Makes sure rotation is not over the specified range.
|
2012-06-14 09:06:06 -04:00
|
|
|
|
void WrapRotation();
|
2013-03-22 02:33:10 -04:00
|
|
|
|
|
2013-06-04 08:55:41 -04:00
|
|
|
|
/// Makes speed is not over 20. Max speed is 20 blocks / second
|
2013-03-22 02:33:10 -04:00
|
|
|
|
void WrapSpeed();
|
2012-08-28 17:59:49 -04:00
|
|
|
|
|
2013-03-01 14:33:41 -05:00
|
|
|
|
// tolua_begin
|
|
|
|
|
|
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; }
|
2013-03-01 14:33:41 -05:00
|
|
|
|
|
|
|
|
|
// tolua_end
|
2013-03-03 14:05:11 -05:00
|
|
|
|
|
|
|
|
|
/// Called when the specified player right-clicks this entity
|
|
|
|
|
virtual void OnRightClicked(cPlayer & a_Player) {};
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
static cCriticalSection m_CSCount;
|
|
|
|
|
static int m_EntityCount;
|
|
|
|
|
|
|
|
|
|
int m_UniqueID;
|
2013-03-03 14:05:11 -05:00
|
|
|
|
|
|
|
|
|
/// The entity to which this entity is attached (vehicle), NULL if none
|
|
|
|
|
cEntity * m_AttachedTo;
|
|
|
|
|
|
|
|
|
|
/// The entity which is attached to this entity (rider), NULL if none
|
|
|
|
|
cEntity * m_Attachee;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
cReferenceManager* m_Referencers;
|
|
|
|
|
cReferenceManager* m_References;
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
|
// Flags that signal that we haven't updated the clients with the latest.
|
2013-04-02 02:48:31 -04:00
|
|
|
|
bool m_bDirtyHead;
|
2013-03-22 02:33:10 -04:00
|
|
|
|
bool m_bDirtyOrientation;
|
2013-02-21 16:55:36 -05:00
|
|
|
|
bool m_bDirtyPosition;
|
2013-03-22 02:33:10 -04:00
|
|
|
|
bool m_bDirtySpeed;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-04-22 03:18:03 -04:00
|
|
|
|
bool m_bOnGround;
|
|
|
|
|
float m_Gravity;
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
|
// Last Position.
|
2013-03-22 02:33:10 -04:00
|
|
|
|
double m_LastPosX, m_LastPosY, m_LastPosZ;
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
|
// This variables keep track of the last time a packet was sent
|
2013-03-22 02:33:10 -04:00
|
|
|
|
Int64 m_TimeLastTeleportPacket,m_TimeLastMoveReltPacket,m_TimeLastSpeedPacket; // In ticks
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
|
bool m_IsInitialized; // Is set to true when it's initialized, until it's destroyed (Initialize() till Destroy() )
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
eEntityType m_EntityType;
|
|
|
|
|
|
2013-03-09 09:35:43 -05:00
|
|
|
|
cWorld * m_World;
|
2012-08-28 17:59:49 -04:00
|
|
|
|
|
|
|
|
|
float m_FireDamageInterval;
|
|
|
|
|
float m_BurnPeriod;
|
2013-03-09 09:35:43 -05:00
|
|
|
|
|
|
|
|
|
virtual void Destroyed(void) {} // Called after the entity has been destroyed
|
|
|
|
|
|
|
|
|
|
void SetWorld(cWorld * a_World) { m_World = a_World; }
|
2013-04-13 17:02:10 -04:00
|
|
|
|
|
2013-03-09 09:35:43 -05:00
|
|
|
|
friend class cReferenceManager;
|
|
|
|
|
void AddReference( cEntity*& a_EntityPtr );
|
|
|
|
|
void ReferencedBy( cEntity*& a_EntityPtr );
|
|
|
|
|
void Dereference( cEntity*& a_EntityPtr );
|
2013-03-22 02:33:10 -04:00
|
|
|
|
private:
|
2013-04-28 14:54:43 -04:00
|
|
|
|
//Measured in degrees (MAX 360<36>)
|
2013-04-02 02:48:31 -04:00
|
|
|
|
double m_HeadYaw;
|
2013-04-28 14:54:43 -04:00
|
|
|
|
//Measured in meter/second (m/s)
|
2013-03-22 02:33:10 -04:00
|
|
|
|
Vector3d m_Speed;
|
2013-04-28 14:54:43 -04:00
|
|
|
|
//Measured in degrees (MAX 360<36>)
|
2013-03-22 02:33:10 -04:00
|
|
|
|
Vector3d m_Rot;
|
2013-04-28 14:54:43 -04:00
|
|
|
|
//Measured in meters (1 meter = 1 block) (m)
|
2013-03-22 02:33:10 -04:00
|
|
|
|
Vector3d m_Pos;
|
2013-04-28 14:54:43 -04:00
|
|
|
|
//Measured in meter/second
|
2013-04-22 03:18:03 -04:00
|
|
|
|
Vector3d m_WaterSpeed;
|
2013-04-28 14:54:43 -04:00
|
|
|
|
//Measured in Kilograms (Kg)
|
2013-04-28 15:01:46 -04:00
|
|
|
|
double m_Mass;
|
2013-05-21 01:49:56 -04:00
|
|
|
|
//It's Width.
|
|
|
|
|
double m_Width;
|
|
|
|
|
//It's height
|
|
|
|
|
double m_Height;
|
2013-03-09 09:35:43 -05:00
|
|
|
|
} ; // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
typedef std::list<cEntity *> cEntityList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|