2013-08-20 16:47:40 +02:00
|
|
|
|
|
|
|
// ProjectileEntity.h
|
|
|
|
|
2014-10-21 21:25:52 +02:00
|
|
|
// Declares the cProjectileEntity class representing the common base class for projectiles
|
2013-08-20 16:47:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Entity.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// tolua_begin
|
|
|
|
|
|
|
|
class cProjectileEntity :
|
|
|
|
public cEntity
|
|
|
|
{
|
|
|
|
typedef cEntity super;
|
|
|
|
|
|
|
|
public:
|
2014-10-21 21:25:52 +02:00
|
|
|
/** The kind of the projectile. The numbers correspond to the network type ID used for spawning them in the protocol. */
|
2013-08-20 16:47:40 +02:00
|
|
|
enum eKind
|
|
|
|
{
|
|
|
|
pkArrow = 60,
|
|
|
|
pkSnowball = 61,
|
|
|
|
pkEgg = 62,
|
2013-08-22 22:31:15 +02:00
|
|
|
pkGhastFireball = 63,
|
|
|
|
pkFireCharge = 64,
|
2013-08-20 16:47:40 +02:00
|
|
|
pkEnderPearl = 65,
|
|
|
|
pkExpBottle = 75,
|
|
|
|
pkSplashPotion = 73,
|
2013-11-16 20:58:17 +00:00
|
|
|
pkFirework = 76,
|
2013-08-20 16:47:40 +02:00
|
|
|
pkWitherSkull = 66,
|
|
|
|
pkFishingFloat = 90,
|
|
|
|
} ;
|
|
|
|
|
2013-08-22 08:55:58 +02:00
|
|
|
// tolua_end
|
|
|
|
|
2014-07-22 15:36:13 -07:00
|
|
|
CLASS_PROTODEF(cProjectileEntity)
|
2013-08-25 21:31:35 +02:00
|
|
|
|
2013-08-20 16:47:40 +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);
|
2013-08-22 08:55:58 +02:00
|
|
|
|
2014-10-21 21:25:52 +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-08-20 16:47:40 +02:00
|
|
|
|
2014-10-21 21:25:52 +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)
|
2013-12-22 13:46:55 +00:00
|
|
|
{
|
|
|
|
UNUSED(a_EntityHit);
|
|
|
|
UNUSED(a_HitPos);
|
|
|
|
}
|
2013-09-01 22:40:35 +02:00
|
|
|
|
2014-10-21 21:25:52 +02:00
|
|
|
/** Called by Chunk when the projectile is eligible for player collection */
|
2014-10-15 19:01:55 +02:00
|
|
|
virtual void CollectedBy(cPlayer & a_Dest);
|
2013-11-12 21:43:20 +00:00
|
|
|
|
2013-08-22 08:55:58 +02:00
|
|
|
// tolua_begin
|
|
|
|
|
2014-10-21 21:25:52 +02:00
|
|
|
/** Returns the kind of the projectile (fast class identification) */
|
2013-08-22 22:31:15 +02:00
|
|
|
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; }
|
2013-08-22 08:55:58 +02:00
|
|
|
|
2014-10-21 21:25:52 +02:00
|
|
|
/** Returns the string that is used as the entity type (class name) in MCA files */
|
2013-08-22 22:31:15 +02:00
|
|
|
AString GetMCAClassName(void) const;
|
|
|
|
|
2014-10-21 21:25:52 +02:00
|
|
|
/** Returns true if the projectile has hit the ground and is stuck there */
|
2013-08-22 22:31:15 +02:00
|
|
|
bool IsInGround(void) const { return m_IsInGround; }
|
2013-08-20 16:47:40 +02:00
|
|
|
|
2013-09-07 21:26:17 +02:00
|
|
|
// tolua_end
|
|
|
|
|
2014-10-21 21:25:52 +02:00
|
|
|
/** Sets the internal InGround flag. To be used by MCA loader only! */
|
2013-09-07 21:26:17 +02:00
|
|
|
void SetIsInGround(bool a_IsInGround) { m_IsInGround = a_IsInGround; }
|
|
|
|
|
2013-08-20 16:47:40 +02:00
|
|
|
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 */
|
2013-08-22 22:31:15 +02:00
|
|
|
eKind m_ProjectileKind;
|
2013-08-20 16:47:40 +02:00
|
|
|
|
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;
|
2013-08-22 22:31:15 +02:00
|
|
|
|
2014-10-21 21:25:52 +02:00
|
|
|
/** True if the projectile has hit the ground and is stuck there */
|
2013-08-22 22:31:15 +02:00
|
|
|
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;
|
2013-08-30 18:10:58 +02:00
|
|
|
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
|