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