diff options
author | madmaxoft <github@xoft.cz> | 2013-08-22 08:55:58 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-08-22 08:55:58 +0200 |
commit | 73afb1507d2a0defda8a03f60030dc49bb53f94f (patch) | |
tree | b5a14bb289756f734a8cc7e949e660298167627c /source/Entities | |
parent | Another fix for #31. (diff) | |
download | cuberite-73afb1507d2a0defda8a03f60030dc49bb53f94f.tar cuberite-73afb1507d2a0defda8a03f60030dc49bb53f94f.tar.gz cuberite-73afb1507d2a0defda8a03f60030dc49bb53f94f.tar.bz2 cuberite-73afb1507d2a0defda8a03f60030dc49bb53f94f.tar.lz cuberite-73afb1507d2a0defda8a03f60030dc49bb53f94f.tar.xz cuberite-73afb1507d2a0defda8a03f60030dc49bb53f94f.tar.zst cuberite-73afb1507d2a0defda8a03f60030dc49bb53f94f.zip |
Diffstat (limited to 'source/Entities')
-rw-r--r-- | source/Entities/Entity.h | 6 | ||||
-rw-r--r-- | source/Entities/ProjectileEntity.cpp | 79 | ||||
-rw-r--r-- | source/Entities/ProjectileEntity.h | 26 |
3 files changed, 105 insertions, 6 deletions
diff --git a/source/Entities/Entity.h b/source/Entities/Entity.h index 820405cb9..dde3eb8c6 100644 --- a/source/Entities/Entity.h +++ b/source/Entities/Entity.h @@ -90,12 +90,13 @@ public: etPlayer, etPickup, etMonster, - etMob = etMonster, // DEPRECATED, use etMonster instead! etFallingBlock, etMinecart, etTNT, + etProjectile, // DEPRECATED older constants, left over for compatibility reasons (plugins) + etMob = etMonster, // DEPRECATED, use etMonster instead! eEntityType_Entity = etEntity, eEntityType_Player = etPlayer, eEntityType_Pickup = etPickup, @@ -276,9 +277,8 @@ public: /** 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!"); } + virtual void SpawnOn(cClientHandle & a_Client) = 0; // tolua_begin diff --git a/source/Entities/ProjectileEntity.cpp b/source/Entities/ProjectileEntity.cpp new file mode 100644 index 000000000..93508e2f7 --- /dev/null +++ b/source/Entities/ProjectileEntity.cpp @@ -0,0 +1,79 @@ + +// ProjectileEntity.cpp + +// Implements the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types + +#include "Globals.h" +#include "ProjectileEntity.h" + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cProjectileEntity: + +cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, double a_Width, double a_Height) : + super(etProjectile, a_X, a_Y, a_Z, a_Width, a_Height), + m_Creator(a_Creator) +{ +} + + + + + +cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Vector3d & a_Pos, const Vector3d & a_Speed, double a_Width, double a_Height) : + super(etProjectile, a_Pos.x, a_Pos.y, a_Pos.z, a_Width, a_Height), + m_Creator(a_Creator) +{ + SetSpeed(a_Speed); +} + + + + + +cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d * a_Speed) +{ + Vector3d Speed; + if (a_Speed != NULL) + { + Speed = *a_Speed; + } + + switch (a_Kind) + { + case pkArrow: return new cArrowEntity(a_Creator, a_X, a_Y, a_Z, Speed); + // TODO: the rest + } + + LOGWARNING("%s: Unknown kind: %d", __FUNCTION__, a_Kind); + return NULL; +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cArrowEntity: + +cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d a_Speed) : + super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5) +{ + SetSpeed(a_Speed); +} + + + + + +void cArrowEntity::SpawnOn(cClientHandle & a_Client) +{ + // TODO +} + + + + diff --git a/source/Entities/ProjectileEntity.h b/source/Entities/ProjectileEntity.h index 2e050068b..426b2ea84 100644 --- a/source/Entities/ProjectileEntity.h +++ b/source/Entities/ProjectileEntity.h @@ -1,7 +1,7 @@ // ProjectileEntity.h -// Declares the cProjectileEntity class representing the common base class for projectiles +// Declares the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types @@ -38,12 +38,21 @@ public: pkFishingFloat = 90, } ; + // tolua_end + cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, double a_Width, double a_Height); cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Vector3d & a_Pos, const Vector3d & a_Speed, double a_Width, double a_Height); + static cProjectileEntity * Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d * a_Speed = NULL); + /// Called by the physics blocktracer when the entity hits a solid block, the coords and the face hit is given virtual void OnHitSolidBlock(double a_BlockX, double a_BlockY, double a_BlockZ, char a_BlockFace) {}; + // tolua_begin + + /// Returns the entity who created this projectile; may be NULL + cEntity * GetCreator(void) { return m_Creator; } + protected: eKind m_Kind; @@ -58,9 +67,20 @@ protected: class cArrowEntity : public cProjectileEntity { + typedef cProjectileEntity super; + public: - cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, double a_Width, double a_Height); - cArrowEntity(cEntity * a_Creator, const Vector3d & a_Pos, const Vector3d & a_Speed, double a_Width, double a_Height); + + // tolua_end + + cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d a_Speed); + +protected: + + // cEntity overrides: + virtual void SpawnOn(cClientHandle & a_Client) override; + + // tolua_begin } ; // tolua_end |