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

124 lines
3.6 KiB
C++
Raw Normal View History

// ProjectileEntity.h
// Declares the cProjectileEntity class representing the common base class for projectiles
#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 them in the protocol. */
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-10-20 21:55:07 +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 = nullptr);
/** 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);
/** 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
/** Called by Chunk when the projectile is eligible for player collection */
virtual void CollectedBy(cPlayer & a_Dest);
2013-11-12 21:43:20 +00:00
// 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
*/
2015-03-21 15:18:17 +01:00
UInt32 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
2015-03-21 15:18:17 +01:00
Used to migitate invalid pointers caused by the creator being destroyed. */
2014-07-04 16:49:24 +01:00
struct CreatorData
{
2015-03-21 15:18:17 +01:00
CreatorData(UInt32 a_UniqueID, const AString & a_Name, const cEnchantments & a_Enchantments) :
2014-07-04 16:49:24 +01:00
m_UniqueID(a_UniqueID),
2014-08-19 17:57:32 +02:00
m_Name(a_Name),
m_Enchantments(a_Enchantments)
2014-07-04 16:49:24 +01:00
{
}
2015-03-21 15:18:17 +01:00
const UInt32 m_UniqueID;
2014-07-04 16:49:24 +01:00
AString m_Name;
2014-08-19 17:57:32 +02:00
cEnchantments m_Enchantments;
2014-07-04 16:49:24 +01:00
};
/** 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
2015-05-09 09:25:09 +02:00
The ID and / or name may be nullptr (e.g. for dispensers / mobs). */
2014-07-04 16:49:24 +01:00
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:
2015-01-11 21:12:26 +00:00
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void HandlePhysics(std::chrono::milliseconds 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