Files
cuberite-2a/src/Entities/ProjectileEntity.h
T

124 lines
3.5 KiB
C++
Raw Normal View History

// ProjectileEntity.h
// Declares the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types
#pragma once
#include "Entity.h"
// tolua_begin
class cProjectileEntity :
public cEntity
{
typedef cEntity super;
public:
/// The kind of the projectile. The numbers correspond to the network type ID used for spawning via the 0x17 packet.
enum eKind
{
pkArrow = 60,
pkSnowball = 61,
pkEgg = 62,
pkGhastFireball = 63,
pkFireCharge = 64,
pkEnderPearl = 65,
pkExpBottle = 75,
pkSplashPotion = 73,
2013-11-16 20:58:17 +00:00
pkFirework = 76,
pkWitherSkull = 66,
pkFishingFloat = 90,
} ;
// tolua_end
CLASS_PROTODEF(cProjectileEntity)
2013-08-25 21:31:35 +02:00
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);
2014-07-13 14:09:08 +01:00
static cProjectileEntity * Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem * a_Item, const Vector3d * a_Speed = NULL);
2013-09-03 09:41:31 +02:00
/// Called by the physics blocktracer when the entity hits a solid block, the hit position and the face hit (BLOCK_FACE_) is given
2014-02-04 10:59:05 -08:00
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace);
2013-09-01 22:40:35 +02:00
/// Called by the physics blocktracer when the entity hits another entity
2014-07-17 22:50:58 +02:00
virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
{
UNUSED(a_EntityHit);
UNUSED(a_HitPos);
}
2013-09-01 22:40:35 +02:00
2013-11-12 21:43:20 +00:00
/// Called by Chunk when the projectile is eligible for player collection
virtual void CollectedBy(cPlayer * a_Dest);
// tolua_begin
/// Returns the kind of the projectile (fast class identification)
eKind GetProjectileKind(void) const { return m_ProjectileKind; }
2014-07-05 22:59:22 +01:00
/** Returns the unique ID of the entity who created this projectile
May return an ID <0
2014-07-04 16:49:24 +01:00
*/
2014-07-05 22:59:22 +01:00
int GetCreatorUniqueID(void) { return m_CreatorData.m_UniqueID; }
2014-07-04 16:49:24 +01:00
/** Returns the name of the player that created the projectile
Will be empty for non-player creators
*/
AString GetCreatorName(void) const { return m_CreatorData.m_Name; }
/// Returns the string that is used as the entity type (class name) in MCA files
AString GetMCAClassName(void) const;
/// Returns true if the projectile has hit the ground and is stuck there
bool IsInGround(void) const { return m_IsInGround; }
// tolua_end
/// Sets the internal InGround flag. To be used by MCA loader only!
void SetIsInGround(bool a_IsInGround) { m_IsInGround = a_IsInGround; }
protected:
2014-07-04 16:49:24 +01:00
2014-07-17 22:50:58 +02:00
/** A structure that stores the Entity ID and Playername of the projectile's creator
2014-07-04 16:49:24 +01:00
Used to migitate invalid pointers caused by the creator being destroyed
*/
struct CreatorData
{
2014-07-04 22:07:26 +01:00
CreatorData(int a_UniqueID, const AString & a_Name) :
2014-07-04 16:49:24 +01:00
m_UniqueID(a_UniqueID),
m_Name(a_Name)
{
}
const int m_UniqueID;
AString m_Name;
};
/** The type of projectile I am */
eKind m_ProjectileKind;
2014-07-04 16:49:24 +01:00
/** The structure for containing the entity ID and name who has created this projectile
The ID and/or name may be NULL (e.g. for dispensers/mobs)
*/
CreatorData m_CreatorData;
/// True if the projectile has hit the ground and is stuck there
bool m_IsInGround;
2013-11-14 22:39:14 +00:00
2013-08-27 19:57:37 +02:00
// cEntity overrides:
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override;
virtual void SpawnOn(cClientHandle & a_Client) override;
2013-08-30 14:32:07 +02:00
2014-07-17 22:15:34 +02:00
} ; // tolua_export