From 0c0c762412922b784aaf154b51a8d5d547d3f86f Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 21 Oct 2014 21:25:52 +0200 Subject: Exported individual projectile classes to Lua API. They used to be exported, but then they were moved to separate files and those werent' added to the ToLua processing list. --- src/Entities/ArrowEntity.h | 45 ++++++++++++++++++--------------- src/Entities/ExpBottleEntity.h | 17 ++++++++++--- src/Entities/FireChargeEntity.h | 15 ++++++++--- src/Entities/FireworkEntity.cpp | 13 ++++++---- src/Entities/FireworkEntity.h | 32 ++++++++++++++++++++--- src/Entities/GhastFireballEntity.h | 15 ++++++++--- src/Entities/Painting.h | 13 +++++++--- src/Entities/ProjectileEntity.h | 20 +++++++-------- src/Entities/SplashPotionEntity.h | 18 ++++++++++--- src/Entities/ThrownEggEntity.cpp | 21 +++++++++++++++ src/Entities/ThrownEggEntity.h | 34 ++++++++++--------------- src/Entities/ThrownEnderPearlEntity.cpp | 22 ++++++++++++++++ src/Entities/ThrownEnderPearlEntity.h | 34 ++++++++++--------------- src/Entities/ThrownSnowballEntity.cpp | 25 ++++++++++++++++++ src/Entities/ThrownSnowballEntity.h | 34 ++++++++++--------------- src/Entities/WitherSkullEntity.h | 12 +++++++-- 16 files changed, 253 insertions(+), 117 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h index 1e4d8eebb..436ec0293 100644 --- a/src/Entities/ArrowEntity.h +++ b/src/Entities/ArrowEntity.h @@ -1,6 +1,11 @@ -// -// ArrowEntity.h -// + +// ArrowEntity.h + +// Declares the cArrowEntity representing the arrow that has been shot by the player or by a skeleton + + + + #pragma once @@ -19,7 +24,7 @@ class cArrowEntity : typedef cProjectileEntity super; public: - /// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field + /** Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field */ enum ePickupState { psNoPickup = 0, @@ -31,33 +36,33 @@ public: CLASS_PROTODEF(cArrowEntity) - /// Creates a new arrow with psNoPickup state and default damage modifier coeff + /** Creates a new arrow with psNoPickup state and default damage modifier coeff */ cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); - /// Creates a new arrow as shot by a player, initializes it from the player object + /** Creates a new arrow as shot by a player, initializes it from the player object */ cArrowEntity(cPlayer & a_Player, double a_Force); // tolua_begin - /// Returns whether the arrow can be picked up by players + /** Returns whether the arrow can be picked up by players */ ePickupState GetPickupState(void) const { return m_PickupState; } - /// Sets a new pickup state + /** Sets a new pickup state */ void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; } - /// Returns the damage modifier coeff. + /** Returns the damage modifier coeff. */ double GetDamageCoeff(void) const { return m_DamageCoeff; } - /// Sets the damage modifier coeff + /** Sets the damage modifier coeff */ void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; } - /// Returns true if the specified player can pick the arrow up + /** Returns true if the specified player can pick the arrow up */ bool CanPickup(const cPlayer & a_Player) const; - /// Returns true if the arrow is set as critical + /** Returns true if the arrow is set as critical */ bool IsCritical(void) const { return m_IsCritical; } - /// Sets the IsCritical flag + /** Sets the IsCritical flag */ void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; } /** Gets the block arrow is in */ @@ -70,28 +75,28 @@ public: protected: - /// Determines when the arrow can be picked up by players + /** Determines when the arrow can be picked up by players */ ePickupState m_PickupState; - /// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow + /** The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow */ double m_DamageCoeff; - /// If true, the arrow deals more damage + /** If true, the arrow deals more damage */ bool m_IsCritical; - /// Timer for pickup collection animation or five minute timeout + /** Timer for pickup collection animation or five minute timeout */ float m_Timer; - /// Timer for client arrow position confirmation via TeleportEntity + /** Timer for client arrow position confirmation via TeleportEntity */ float m_HitGroundTimer; // Whether the arrow has already been teleported into the proper position in the ground. bool m_HasTeleported; - /// If true, the arrow is in the process of being collected - don't go to anyone else + /** If true, the arrow is in the process of being collected - don't go to anyone else */ bool m_bIsCollected; - /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air + /** Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air */ Vector3i m_HitBlockPos; // cProjectileEntity overrides: diff --git a/src/Entities/ExpBottleEntity.h b/src/Entities/ExpBottleEntity.h index d36110f97..715b9947e 100644 --- a/src/Entities/ExpBottleEntity.h +++ b/src/Entities/ExpBottleEntity.h @@ -1,6 +1,11 @@ -// -// ExpBottleEntity.h -// + +// ExpBottleEntity.h + +// Declares the cExpBottleEntity class representing the thrown exp bottle + + + + #pragma once @@ -33,6 +38,10 @@ protected: /** Breaks the bottle, fires its particle effects and sounds @param a_HitPos The position where the bottle will break */ - void Break(const Vector3d &a_HitPos); + void Break(const Vector3d & a_HitPos); }; // tolua_export + + + + diff --git a/src/Entities/FireChargeEntity.h b/src/Entities/FireChargeEntity.h index 5df55bec4..eb08f5324 100644 --- a/src/Entities/FireChargeEntity.h +++ b/src/Entities/FireChargeEntity.h @@ -1,6 +1,11 @@ -// -// FireChargeEntity.h -// + +// FireChargeEntity.h + +// Declares the cFireChargeEntity representing the fire charge shot by the blaze + + + + #pragma once @@ -34,3 +39,7 @@ protected: virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; } ; // tolua_export + + + + diff --git a/src/Entities/FireworkEntity.cpp b/src/Entities/FireworkEntity.cpp index 403a53c84..68d02640a 100644 --- a/src/Entities/FireworkEntity.cpp +++ b/src/Entities/FireworkEntity.cpp @@ -10,7 +10,7 @@ cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) : super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), - m_ExplodeTimer(0), + m_TicksToExplosion(a_Item.m_FireworkItem.m_FlightTimeInTicks), m_FireworkItem(a_Item) { } @@ -27,7 +27,9 @@ void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) if ((PosY < 0) || (PosY >= cChunkDef::Height)) { - goto setspeed; + AddSpeedY(1); + AddPosition(GetSpeed() * (a_Dt / 1000)); + return; } if (m_IsInGround) @@ -50,7 +52,6 @@ void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } } -setspeed: AddSpeedY(1); AddPosition(GetSpeed() * (a_Dt / 1000)); } @@ -63,11 +64,13 @@ void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) + if (m_TicksToExplosion <= 0) { + // TODO: Notify the plugins m_World->BroadcastEntityStatus(*this, esFireworkExploding); Destroy(); + return; } - m_ExplodeTimer++; + m_TicksToExplosion -= 1; } diff --git a/src/Entities/FireworkEntity.h b/src/Entities/FireworkEntity.h index 20f18b6dc..300ec571e 100644 --- a/src/Entities/FireworkEntity.h +++ b/src/Entities/FireworkEntity.h @@ -1,6 +1,11 @@ -// -// FireworkEntity.h -// + +// FireworkEntity.h + +// Declares the cFireworkEntity class representing the flying firework rocket + + + + #pragma once @@ -24,7 +29,22 @@ public: CLASS_PROTODEF(cFireworkEntity) cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item); + + // tolua_begin + + /** Returns the item used to create the rocket (has all the firework effects on it) */ const cItem & GetItem(void) const { return m_FireworkItem; } + + /** Sets the item that is used to create the rocket (has all the firework effects on it) */ + void SetItem(const cItem & a_Item) { m_FireworkItem = a_Item; } + + /** Returns the number of ticks left until the firework explosion. */ + int GetTicksToExplosion(void) const { return m_TicksToExplosion; } + + /** Sets the number of ticks left until the firework explosion. */ + void SetTicksToExplosion(int a_TicksToExplosion) { m_TicksToExplosion = a_TicksToExplosion; } + + // tolua_end protected: @@ -34,7 +54,11 @@ protected: private: - int m_ExplodeTimer; + int m_TicksToExplosion; cItem m_FireworkItem; }; // tolua_export + + + + diff --git a/src/Entities/GhastFireballEntity.h b/src/Entities/GhastFireballEntity.h index 3ed72d9ef..bbce89d31 100644 --- a/src/Entities/GhastFireballEntity.h +++ b/src/Entities/GhastFireballEntity.h @@ -1,6 +1,11 @@ -// -// GhastFireballEntity.h -// + +// GhastFireballEntity.h + +// Declares the cGhastFireballEntity class representing the ghast fireball in flight. + + + + #pragma once @@ -36,3 +41,7 @@ protected: // TODO: Deflecting the fireballs by arrow- or sword- hits } ; // tolua_export + + + + diff --git a/src/Entities/Painting.h b/src/Entities/Painting.h index 9877c95c5..078270b42 100644 --- a/src/Entities/Painting.h +++ b/src/Entities/Painting.h @@ -11,15 +11,22 @@ class cPainting : public cEntity { - // tolua_end typedef cEntity super; public: + + // tolua_end + CLASS_PROTODEF(cPainting) cPainting(const AString & a_Name, int a_Direction, double a_X, double a_Y, double a_Z); - const AString & GetName(void) const { return m_Name; } // tolua_export - int GetDirection(void) const { return m_Direction; } // tolua_export + + // tolua_begin + + const AString & GetName(void) const { return m_Name; } + int GetDirection(void) const { return m_Direction; } + + // tolua_end private: diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 03eda9739..b9d2dfa63 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -1,7 +1,7 @@ // ProjectileEntity.h -// Declares the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types +// Declares the cProjectileEntity class representing the common base class for projectiles @@ -23,7 +23,7 @@ class cProjectileEntity : typedef cEntity super; public: - /// The kind of the projectile. The numbers correspond to the network type ID used for spawning via the 0x17 packet. + /** The kind of the projectile. The numbers correspond to the network type ID used for spawning them in the protocol. */ enum eKind { pkArrow = 60, @@ -48,22 +48,22 @@ public: 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); - /// Called by the physics blocktracer when the entity hits a solid block, the hit position and the face hit (BLOCK_FACE_) is given + /** Called by the physics blocktracer when the entity hits a solid block, the hit position and the face hit (BLOCK_FACE_) is given */ virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace); - /// Called by the physics blocktracer when the entity hits another entity + /** Called by the physics blocktracer when the entity hits another entity */ virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { UNUSED(a_EntityHit); UNUSED(a_HitPos); } - /// Called by Chunk when the projectile is eligible for player collection + /** 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) + /** Returns the kind of the projectile (fast class identification) */ eKind GetProjectileKind(void) const { return m_ProjectileKind; } /** Returns the unique ID of the entity who created this projectile @@ -76,15 +76,15 @@ public: */ AString GetCreatorName(void) const { return m_CreatorData.m_Name; } - /// Returns the string that is used as the entity type (class name) in MCA files + /** 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 + /** 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! + /** Sets the internal InGround flag. To be used by MCA loader only! */ void SetIsInGround(bool a_IsInGround) { m_IsInGround = a_IsInGround; } protected: @@ -114,7 +114,7 @@ protected: */ CreatorData m_CreatorData; - /// True if the projectile has hit the ground and is stuck there + /** True if the projectile has hit the ground and is stuck there */ bool m_IsInGround; // cEntity overrides: diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index 4afc5f204..9302d8292 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -1,6 +1,11 @@ -// -// SplashPotionEntity.h -// + +// SplashPotionEntity.h + +// Declares the cSplashPotionEntity class representing a splash potion that has been thrown + + + + #pragma once @@ -32,6 +37,7 @@ public: const cItem & a_Item ); + // tolua_begin cEntityEffect::eType GetEntityEffectType(void) const { return m_EntityEffectType; } cEntityEffect GetEntityEffect(void) const { return m_EntityEffect; } int GetPotionColor(void) const { return m_PotionColor; } @@ -39,6 +45,8 @@ public: void SetEntityEffectType(cEntityEffect::eType a_EntityEffectType) { m_EntityEffectType = a_EntityEffectType; } void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; } void SetPotionColor(int a_PotionColor) { m_PotionColor = a_PotionColor; } + + // tolua_end protected: @@ -77,3 +85,7 @@ private: /** Time in ticks to wait for the hit animation to begin before destroying */ int m_DestroyTimer; } ; // tolua_export + + + + diff --git a/src/Entities/ThrownEggEntity.cpp b/src/Entities/ThrownEggEntity.cpp index 5ae85bee8..24c946a9c 100644 --- a/src/Entities/ThrownEggEntity.cpp +++ b/src/Entities/ThrownEggEntity.cpp @@ -44,6 +44,27 @@ void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hit +void cThrownEggEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + if (m_DestroyTimer > 0) + { + m_DestroyTimer--; + if (m_DestroyTimer == 0) + { + Destroy(); + return; + } + } + else + { + super::Tick(a_Dt, a_Chunk); + } +} + + + + + void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) { if (m_World->GetTickRandomNumber(7) == 1) diff --git a/src/Entities/ThrownEggEntity.h b/src/Entities/ThrownEggEntity.h index a0b7d5340..6ffedf5b5 100644 --- a/src/Entities/ThrownEggEntity.h +++ b/src/Entities/ThrownEggEntity.h @@ -1,6 +1,11 @@ -// -// ThrownEggEntity.h -// + +// ThrownEggEntity.h + +// Declares the cThrownEggEntity class representing a regular thrown egg + + + + #pragma once @@ -29,23 +34,8 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void Tick (float a_Dt, cChunk & a_Chunk) override - { - if (m_DestroyTimer > 0) - { - m_DestroyTimer--; - if (m_DestroyTimer == 0) - { - Destroy(); - return; - } - } - else - { - super::Tick(a_Dt, a_Chunk); - } - } + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; // Randomly decides whether to spawn a chicken where the egg lands. void TrySpawnChicken(const Vector3d & a_HitPos); @@ -56,3 +46,7 @@ private: int m_DestroyTimer; } ; // tolua_export + + + + diff --git a/src/Entities/ThrownEnderPearlEntity.cpp b/src/Entities/ThrownEnderPearlEntity.cpp index c7407e6ae..8f1b62934 100644 --- a/src/Entities/ThrownEnderPearlEntity.cpp +++ b/src/Entities/ThrownEnderPearlEntity.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "ThrownEnderPearlEntity.h" @@ -45,6 +46,27 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d +void cThrownEnderPearlEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + if (m_DestroyTimer > 0) + { + m_DestroyTimer--; + if (m_DestroyTimer == 0) + { + Destroy(); + return; + } + } + else + { + super::Tick(a_Dt, a_Chunk); + } +} + + + + + void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) { if (m_CreatorData.m_Name.empty()) diff --git a/src/Entities/ThrownEnderPearlEntity.h b/src/Entities/ThrownEnderPearlEntity.h index 436450013..475ebde87 100644 --- a/src/Entities/ThrownEnderPearlEntity.h +++ b/src/Entities/ThrownEnderPearlEntity.h @@ -1,6 +1,11 @@ -// -// ThrownEnderPearlEntity.h -// + +// ThrownEnderPearlEntity.h + +// Declares the cThrownEnderPeralEntity class representing an ender pearl being thrown + + + + #pragma once @@ -29,23 +34,8 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void Tick (float a_Dt, cChunk & a_Chunk) override - { - if (m_DestroyTimer > 0) - { - m_DestroyTimer--; - if (m_DestroyTimer == 0) - { - Destroy(); - return; - } - } - else - { - super::Tick(a_Dt, a_Chunk); - } - } + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; /** Teleports the creator where the ender pearl lands */ void TeleportCreator(const Vector3d & a_HitPos); @@ -56,3 +46,7 @@ private: int m_DestroyTimer; } ; // tolua_export + + + + diff --git a/src/Entities/ThrownSnowballEntity.cpp b/src/Entities/ThrownSnowballEntity.cpp index 496397100..88e39d22e 100644 --- a/src/Entities/ThrownSnowballEntity.cpp +++ b/src/Entities/ThrownSnowballEntity.cpp @@ -43,3 +43,28 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & m_DestroyTimer = 5; } + + + + + +void cThrownSnowballEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + if (m_DestroyTimer > 0) + { + m_DestroyTimer--; + if (m_DestroyTimer == 0) + { + Destroy(); + return; + } + } + else + { + super::Tick(a_Dt, a_Chunk); + } +} + + + + diff --git a/src/Entities/ThrownSnowballEntity.h b/src/Entities/ThrownSnowballEntity.h index 8d195ced1..f806996cc 100644 --- a/src/Entities/ThrownSnowballEntity.h +++ b/src/Entities/ThrownSnowballEntity.h @@ -1,6 +1,11 @@ -// -// ThrownSnowballEntity.h -// + +// ThrownSnowballEntity.h + +// Declares the cThrownSnowballEntity representing a snowball that has been thrown + + + + #pragma once @@ -29,23 +34,8 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - virtual void Tick (float a_Dt, cChunk & a_Chunk) override - { - if (m_DestroyTimer > 0) - { - m_DestroyTimer--; - if (m_DestroyTimer == 0) - { - Destroy(); - return; - } - } - else - { - super::Tick(a_Dt, a_Chunk); - } - } + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; private: @@ -53,3 +43,7 @@ private: int m_DestroyTimer; } ; // tolua_export + + + + diff --git a/src/Entities/WitherSkullEntity.h b/src/Entities/WitherSkullEntity.h index c59acd807..43a520388 100644 --- a/src/Entities/WitherSkullEntity.h +++ b/src/Entities/WitherSkullEntity.h @@ -1,8 +1,12 @@ -// WitherSkullEntity.h +// WitherSkullEntity.h // Declares the cWitherSkullEntity class representing the entity used by both blue and black wither skulls + + + + #pragma once #include "ProjectileEntity.h" @@ -30,6 +34,10 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; - virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; } ; // tolua_export + + + + -- cgit v1.2.3 From a42fa071bc3ac1615e7c9b9d59fb4c882cc6097d Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 21 Oct 2014 22:02:30 +0200 Subject: Properly exported cItemFrame and cHangingEntity to Lua. --- src/Entities/HangingEntity.cpp | 30 +++++++++++++++++++----------- src/Entities/HangingEntity.h | 29 +++++++++++++++++------------ src/Entities/ItemFrame.cpp | 16 ++++++++-------- src/Entities/ItemFrame.h | 17 +++++++++++------ 4 files changed, 55 insertions(+), 37 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp index 3276bc4a0..a6b9c40c8 100644 --- a/src/Entities/HangingEntity.cpp +++ b/src/Entities/HangingEntity.cpp @@ -9,9 +9,9 @@ -cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) - : cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8) - , m_BlockFace(a_BlockFace) +cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_Facing, double a_X, double a_Y, double a_Z) : + cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8), + m_Facing(a_Facing) { SetMaxHealth(1); SetHealth(1); @@ -21,15 +21,23 @@ cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, -void cHangingEntity::SetDirection(eBlockFace a_BlockFace) +void cHangingEntity::SetFacing(eBlockFace a_Facing) { - if ((a_BlockFace < 2) || (a_BlockFace > 5)) + // Y-based faces are not allowed: + switch (a_Facing) { - ASSERT(!"Tried to set a bad direction!"); - return; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + { + LOGWARNING("%s: Invalid facing: %d. Ignoring.", __FUNCTION__, a_Facing); + ASSERT(!"Tried to set a bad facing!"); + return; + } + default: break; } - m_BlockFace = a_BlockFace; + m_Facing = a_Facing; } @@ -41,7 +49,7 @@ void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle) int Dir = 0; // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces - switch (m_BlockFace) + switch (m_Facing) { case BLOCK_FACE_ZP: Dir = 0; break; case BLOCK_FACE_ZM: Dir = 2; break; @@ -49,8 +57,8 @@ void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle) case BLOCK_FACE_XP: Dir = 3; break; default: { - LOGINFO("Invalid face (%d) in a cHangingEntity at {%d, %d, %d}, adjusting to BLOCK_FACE_XP.", - m_BlockFace, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ() + LOGINFO("Invalid facing (%d) in a cHangingEntity at {%d, %d, %d}, adjusting to BLOCK_FACE_XP.", + m_Facing, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ() ); Dir = 3; } diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h index 1cc0034e1..67146a20b 100644 --- a/src/Entities/HangingEntity.h +++ b/src/Entities/HangingEntity.h @@ -11,36 +11,41 @@ class cHangingEntity : public cEntity { - // tolua_end typedef cEntity super; public: + // tolua_end + CLASS_PROTODEF(cHangingEntity) cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z); - /** Returns the orientation from the hanging entity */ - eBlockFace GetDirection() const { return m_BlockFace; } // tolua_export + // tolua_begin + + /** Returns the direction in which the entity is facing. */ + eBlockFace GetFacing() const { return m_Facing; } - /** Set the orientation from the hanging entity */ - void SetDirection(eBlockFace a_BlockFace); // tolua_export + /** Set the direction in which the entity is facing. */ + void SetFacing(eBlockFace a_Facing); - /** Returns the X coord. */ - int GetTileX() const { return POSX_TOINT; } // tolua_export + /** Returns the X coord of the block in which the entity resides. */ + int GetBlockX() const { return POSX_TOINT; } - /** Returns the Y coord. */ - int GetTileY() const { return POSY_TOINT; } // tolua_export + /** Returns the Y coord of the block in which the entity resides. */ + int GetBlockY() const { return POSY_TOINT; } - /** Returns the Z coord. */ - int GetTileZ() const { return POSZ_TOINT; } // tolua_export + /** Returns the Z coord of the block in which the entity resides. */ + int GetBlockZ() const { return POSZ_TOINT; } + + // tolua_end private: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override {} - eBlockFace m_BlockFace; + eBlockFace m_Facing; }; // tolua_export diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index f512324eb..6704c05b4 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -9,10 +9,10 @@ -cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) - : cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z) - , m_Item(E_BLOCK_AIR) - , m_Rotation(0) +cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) : + cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z), + m_Item(E_BLOCK_AIR), + m_ItemRotation(0) { } @@ -27,10 +27,10 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player) if (!m_Item.IsEmpty()) { // Item not empty, rotate, clipping values to zero to three inclusive - m_Rotation++; - if (m_Rotation >= 8) + m_ItemRotation++; + if (m_ItemRotation >= 8) { - m_Rotation = 0; + m_ItemRotation = 0; } } else if (!a_Player.GetEquippedItem().IsEmpty()) @@ -72,7 +72,7 @@ void cItemFrame::KilledBy(TakeDamageInfo & a_TDI) SetHealth(GetMaxHealth()); m_Item.Empty(); - m_Rotation = 0; + m_ItemRotation = 0; SetInvulnerableTicks(0); GetWorld()->BroadcastEntityMetadata(*this); } diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h index a63b78b70..3642662f9 100644 --- a/src/Entities/ItemFrame.h +++ b/src/Entities/ItemFrame.h @@ -11,26 +11,31 @@ class cItemFrame : public cHangingEntity { - // tolua_end typedef cHangingEntity super; public: + // tolua_end + CLASS_PROTODEF(cItemFrame) cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z); + // tolua_begin + /** Returns the item in the frame */ - const cItem & GetItem(void) { return m_Item; } // tolua_export + const cItem & GetItem(void) { return m_Item; } /** Set the item in the frame */ - void SetItem(cItem & a_Item) { m_Item = a_Item; } // tolua_export + void SetItem(cItem & a_Item) { m_Item = a_Item; } /** Returns the rotation from the item in the frame */ - Byte GetRotation(void) const { return m_Rotation; } // tolua_export + Byte GetItemRotation(void) const { return m_ItemRotation; } /** Set the rotation from the item in the frame */ - void SetRotation(Byte a_Rotation) { m_Rotation = a_Rotation; } // tolua_export + void SetRotation(Byte a_ItemRotation) { m_ItemRotation = a_ItemRotation; } + + // tolua_end private: @@ -39,7 +44,7 @@ private: virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override; cItem m_Item; - Byte m_Rotation; + Byte m_ItemRotation; }; // tolua_export -- cgit v1.2.3 From b979cad8931e6d107e18d424274aee4bd2e59b41 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 21 Oct 2014 22:32:17 +0200 Subject: cItemFrame: Fixed a forgotten rename. --- src/Entities/ItemFrame.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h index 3642662f9..ced8c37af 100644 --- a/src/Entities/ItemFrame.h +++ b/src/Entities/ItemFrame.h @@ -33,7 +33,7 @@ public: Byte GetItemRotation(void) const { return m_ItemRotation; } /** Set the rotation from the item in the frame */ - void SetRotation(Byte a_ItemRotation) { m_ItemRotation = a_ItemRotation; } + void SetItemRotation(Byte a_ItemRotation) { m_ItemRotation = a_ItemRotation; } // tolua_end -- cgit v1.2.3 From a26541a7c3ced0569098edd0aae61c097c2912f4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 20 Oct 2014 21:55:07 +0100 Subject: En masse NULL -> nullptr replace --- src/Entities/ArrowEntity.cpp | 2 +- src/Entities/Boat.cpp | 4 +- src/Entities/Entity.cpp | 56 +++++------ src/Entities/Entity.h | 196 +++++++++++++++++++------------------- src/Entities/EntityEffect.cpp | 10 +- src/Entities/ExpOrb.cpp | 2 +- src/Entities/Floater.cpp | 2 +- src/Entities/ItemFrame.cpp | 4 +- src/Entities/Minecart.cpp | 14 +-- src/Entities/Minecart.h | 4 +- src/Entities/Painting.cpp | 2 +- src/Entities/Player.cpp | 60 ++++++------ src/Entities/Player.h | 4 +- src/Entities/ProjectileEntity.cpp | 16 ++-- src/Entities/ProjectileEntity.h | 4 +- 15 files changed, 192 insertions(+), 188 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 7e429c62e..30f18f677 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -217,7 +217,7 @@ void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); - if (Chunk == NULL) + if (Chunk == nullptr) { // Inside an unloaded chunk, abort return; diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 328a70846..953213bca 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -42,7 +42,7 @@ bool cBoat::DoTakeDamage(TakeDamageInfo & TDI) if (GetHealth() == 0) { - if (TDI.Attacker != NULL) + if (TDI.Attacker != nullptr) { if (TDI.Attacker->IsPlayer()) { @@ -64,7 +64,7 @@ void cBoat::OnRightClicked(cPlayer & a_Player) { super::OnRightClicked(a_Player); - if (m_Attachee != NULL) + if (m_Attachee != nullptr) { if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID()) { diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index da85dec50..afc61c73f 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -29,8 +29,8 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d : m_UniqueID(0) , m_Health(1) , m_MaxHealth(1) - , m_AttachedTo(NULL) - , m_Attachee(NULL) + , m_AttachedTo(nullptr) + , m_Attachee(nullptr) , m_bDirtyHead(true) , m_bDirtyOrientation(true) , m_bHasSentNoSpeed(true) @@ -38,9 +38,9 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_Gravity(-9.81f) , m_LastPos(a_X, a_Y, a_Z) , m_IsInitialized(false) - , m_WorldTravellingFrom(NULL) + , m_WorldTravellingFrom(nullptr) , m_EntityType(a_EntityType) - , m_World(NULL) + , m_World(nullptr) , m_IsFireproof(false) , m_TicksSinceLastBurnDamage(0) , m_TicksSinceLastLavaDamage(0) @@ -73,7 +73,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d cEntity::~cEntity() { // Before deleting, the entity needs to have been removed from the world, if ever added - ASSERT((m_World == NULL) || !m_World->HasEntity(m_UniqueID)); + ASSERT((m_World == nullptr) || !m_World->HasEntity(m_UniqueID)); /* // DEBUG: @@ -85,11 +85,11 @@ cEntity::~cEntity() ); */ - if (m_AttachedTo != NULL) + if (m_AttachedTo != nullptr) { Detach(); } - if (m_Attachee != NULL) + if (m_Attachee != nullptr) { m_Attachee->Detach(); } @@ -242,7 +242,7 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R TDI.FinalDamage = a_FinalDamage; Vector3d Heading(0, 0, 0); - if (a_Attacker != NULL) + if (a_Attacker != nullptr) { Heading = a_Attacker->GetLookVector() * (a_Attacker->IsSprinting() ? 16 : 11); Heading.y = 1.6; @@ -265,7 +265,7 @@ void cEntity::SetYawFromSpeed(void) SetYaw(0); return; } - SetYaw(atan2(m_Speed.x, m_Speed.z) * 180 / PI); + SetYaw(atan2(m_Speed.x, m_Speed.z) * 180 / M_PI); } @@ -282,7 +282,7 @@ void cEntity::SetPitchFromSpeed(void) SetPitch(0); return; } - SetPitch(atan2(m_Speed.y, xz) * 180 / PI); + SetPitch(atan2(m_Speed.y, xz) * 180 / M_PI); } @@ -308,7 +308,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) return false; } - if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) + if ((a_TDI.Attacker != nullptr) && (a_TDI.Attacker->IsPlayer())) { cPlayer * Player = (cPlayer *)a_TDI.Attacker; @@ -544,7 +544,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_Health = std::max(m_Health, 0); // Add knockback: - if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != NULL)) + if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != nullptr)) { int KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchKnockback); // More common enchantment if (KnockbackLevel < 1) @@ -571,7 +571,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) { KilledBy(a_TDI); - if (a_TDI.Attacker != NULL) + if (a_TDI.Attacker != nullptr) { a_TDI.Attacker->Killed(this); } @@ -778,7 +778,7 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) m_InvulnerableTicks--; } - if (m_AttachedTo != NULL) + if (m_AttachedTo != nullptr) { Vector3d DeltaPos = m_Pos - m_AttachedTo->GetPosition(); if (DeltaPos.Length() > 0.5) @@ -1092,7 +1092,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) { if (!m_IsFireproof) { - TakeDamage(dtOnFire, NULL, BURN_DAMAGE, 0); + TakeDamage(dtOnFire, nullptr, BURN_DAMAGE, 0); } m_TicksSinceLastBurnDamage = 0; } @@ -1163,7 +1163,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) { if (!m_IsFireproof) { - TakeDamage(dtLavaContact, NULL, LAVA_DAMAGE, 0); + TakeDamage(dtLavaContact, nullptr, LAVA_DAMAGE, 0); } m_TicksSinceLastLavaDamage = 0; } @@ -1184,7 +1184,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) { if (!m_IsFireproof) { - TakeDamage(dtFireContact, NULL, FIRE_DAMAGE, 0); + TakeDamage(dtFireContact, nullptr, FIRE_DAMAGE, 0); } m_TicksSinceLastFireDamage = 0; } @@ -1213,7 +1213,7 @@ void cEntity::TickInVoid(cChunk & a_Chunk) { if (m_TicksSinceLastVoidDamage == 20) { - TakeDamage(dtInVoid, NULL, 2, 0); + TakeDamage(dtInVoid, nullptr, 2, 0); m_TicksSinceLastVoidDamage = 0; } else @@ -1239,7 +1239,7 @@ void cEntity::DetectCacti(void) (((GetPosY() - Y < 1) && (GetWorld()->GetBlock(X, Y, Z) == E_BLOCK_CACTUS)))) ) { - TakeDamage(dtCactusContact, NULL, 1, 0); + TakeDamage(dtCactusContact, nullptr, 1, 0); } } @@ -1380,7 +1380,7 @@ bool cEntity::DetectPortal() bool cEntity::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn) { UNUSED(a_ShouldSendRespawn); - ASSERT(a_World != NULL); + ASSERT(a_World != nullptr); if (GetWorld() == a_World) { @@ -1406,7 +1406,7 @@ bool cEntity::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn) bool cEntity::MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn) { cWorld * World = cRoot::Get()->GetWorld(a_WorldName); - if (World == NULL) + if (World == nullptr) { LOG("%s: Couldn't find world \"%s\".", __FUNCTION__, a_WorldName.c_str()); return false; @@ -1493,7 +1493,7 @@ void cEntity::HandleAir(void) if (m_AirTickTimer <= 0) { // Damage player - TakeDamage(dtDrowning, NULL, 1, 1, 0); + TakeDamage(dtDrowning, nullptr, 1, 1, 0); // Reset timer m_AirTickTimer = DROWNING_TICKS; } @@ -1708,7 +1708,7 @@ void cEntity::AttachTo(cEntity * a_AttachTo) // Already attached to that entity, nothing to do here return; } - if (m_AttachedTo != NULL) + if (m_AttachedTo != nullptr) { // Detach from any previous entity: Detach(); @@ -1726,14 +1726,14 @@ void cEntity::AttachTo(cEntity * a_AttachTo) void cEntity::Detach(void) { - if (m_AttachedTo == NULL) + if (m_AttachedTo == nullptr) { // Attached to no entity, our work is done return; } - m_AttachedTo->m_Attachee = NULL; - m_AttachedTo = NULL; - m_World->BroadcastAttachEntity(*this, NULL); + m_AttachedTo->m_Attachee = nullptr; + m_AttachedTo = nullptr; + m_World->BroadcastAttachEntity(*this, nullptr); } @@ -1956,7 +1956,7 @@ void cEntity::HandleSpeedFromAttachee(float a_Forward, float a_Sideways) void cEntity::SteerVehicle(float a_Forward, float a_Sideways) { - if (m_AttachedTo == NULL) + if (m_AttachedTo == nullptr) { return; } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 451ac3711..af545fe4a 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -32,7 +32,7 @@ #define POSZ_TOINT FloorC(GetPosZ()) #define POS_TOINT Vector3i(POSXTOINT, POSYTOINT, POSZTOINT) -#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); if ((ChunkVarName == NULL) || !ChunkVarName->IsValid()) { return; } +#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); if ((ChunkVarName == nullptr) || !ChunkVarName->IsValid()) { return; } @@ -84,13 +84,13 @@ public: etFloater, etItemFrame, etPainting, - + // Common variations etMob = etMonster, // DEPRECATED, use etMonster instead! } ; - + // tolua_end - + enum eEntityStatus { // TODO: Investiagate 0, 1, and 5 as Wiki.vg is not certain @@ -127,22 +127,22 @@ public: // Informs client to explode a firework based on its metadata esFireworkExploding = 17, } ; - + static const int FIRE_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in fire static const int FIRE_DAMAGE = 1; ///< Damage to deal when standing in fire static const int LAVA_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in lava static const int LAVA_DAMAGE = 5; ///< Damage to deal when standing in lava static const int BURN_TICKS_PER_DAMAGE = 20; ///< Ticks to wait between damaging an entity when it is burning static const int BURN_DAMAGE = 1; ///< Damage to deal when the entity is burning - + static const int BURN_TICKS = 200; ///< Ticks to keep an entity burning after it has stood in lava / fire - + static const int MAX_AIR_LEVEL = 300; ///< Maximum air an entity can have static const int DROWNING_TICKS = 20; ///< Number of ticks per heart of damage - + static const int VOID_BOUNDARY = -46; ///< Y position to begin applying void damage static const int FALL_DAMAGE_HEIGHT = 4; ///< Y difference after which fall damage is applied - + cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height); virtual ~cEntity(); @@ -151,9 +151,9 @@ public: virtual bool Initialize(cWorld & a_World); // tolua_begin - + eEntityType GetEntityType(void) const { return m_EntityType; } - + bool IsEnderCrystal(void) const { return (m_EntityType == etEnderCrystal); } bool IsPlayer (void) const { return (m_EntityType == etPlayer); } bool IsPickup (void) const { return (m_EntityType == etPickup); } @@ -168,16 +168,16 @@ public: bool IsFloater (void) const { return (m_EntityType == etFloater); } bool IsItemFrame (void) const { return (m_EntityType == etItemFrame); } bool IsPainting (void) const { return (m_EntityType == etPainting); } - + /// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true) virtual bool IsA(const char * a_ClassName) const; - + /** Returns the class name of this class */ static const char * GetClassStatic(void); /** Returns the topmost class name for the object */ virtual const char * GetClass(void) const; - + /** Returns the topmost class's parent class name for the object. cEntity returns an empty string (no parent). */ virtual const char * GetParentClass(void) const; @@ -200,9 +200,9 @@ public: double GetSpeedY (void) const { return m_Speed.y; } double GetSpeedZ (void) const { return m_Speed.z; } double GetWidth (void) const { return m_Width; } - - int GetChunkX(void) const {return static_cast(floor(m_Pos.x / cChunkDef::Width)); } - int GetChunkZ(void) const {return static_cast(floor(m_Pos.z / cChunkDef::Width)); } + + int GetChunkX(void) const {return (int)floor(m_Pos.x / cChunkDef::Width); } + int GetChunkZ(void) const {return (int)floor(m_Pos.z / cChunkDef::Width); } void SetHeadYaw (double a_HeadYaw); void SetHeight (double a_Height); @@ -219,21 +219,21 @@ public: /** Sets the speed of the entity, measured in m / sec */ void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ); - + /** Sets the speed of the entity, measured in m / sec */ void SetSpeed(const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } - + /** Sets the speed in the X axis, leaving the other speed components intact. Measured in m / sec. */ void SetSpeedX(double a_SpeedX); - + /** Sets the speed in the Y axis, leaving the other speed components intact. Measured in m / sec. */ void SetSpeedY(double a_SpeedY); - + /** Sets the speed in the Z axis, leaving the other speed components intact. Measured in m / sec. */ void SetSpeedZ(double a_SpeedZ); - + void SetWidth (double a_Width); - + void AddPosX (double a_AddPosX); void AddPosY (double a_AddPosY); void AddPosZ (double a_AddPosZ); @@ -244,7 +244,7 @@ public: void AddSpeedX (double a_AddSpeedX); void AddSpeedY (double a_AddSpeedY); void AddSpeedZ (double a_AddSpeedZ); - + virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways); void SteerVehicle(float a_Forward, float a_Sideways); @@ -256,60 +256,60 @@ public: /// Makes this pawn take damage from an attack by a_Attacker. Damage values are calculated automatically and DoTakeDamage() called void TakeDamage(cEntity & a_Attacker); - + /// Makes this entity take the specified damage. The final damage is calculated using current armor, then DoTakeDamage() called void TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, double a_KnockbackAmount); /// Makes this entity take the specified damage. The values are packed into a TDI, knockback calculated, then sent through DoTakeDamage() void TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, int a_FinalDamage, double a_KnockbackAmount); - + float GetGravity(void) const { return m_Gravity; } - + void SetGravity(float a_Gravity) { m_Gravity = a_Gravity; } - + /// Sets the rotation to match the speed vector (entity goes "face-forward") void SetYawFromSpeed(void); - + /// Sets the pitch to match the speed vector (entity gies "face-forward") void SetPitchFromSpeed(void); - + // tolua_end - + /** Makes this entity take damage specified in the a_TDI. The TDI is sent through plugins first, then applied. If it returns false, the entity hasn't receive any damage. */ virtual bool DoTakeDamage(TakeDamageInfo & a_TDI); - + // tolua_begin /// Returns the hitpoints that this pawn can deal to a_Receiver using its equipped items virtual int GetRawDamageAgainst(const cEntity & a_Receiver); - + /** Returns whether armor will protect against the passed damage type **/ virtual bool ArmorCoversAgainst(eDamageType a_DamageType); - + /// Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover virtual int GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_RawDamage); - + /// Returns the knockback amount that the currently equipped items would cause to a_Receiver on a hit virtual double GetKnockbackAmountAgainst(const cEntity & a_Receiver); - + /// Returns the curently equipped weapon; empty item if none virtual cItem GetEquippedWeapon(void) const { return cItem(); } - + /// Returns the currently equipped helmet; empty item if none virtual cItem GetEquippedHelmet(void) const { return cItem(); } - + /// Returns the currently equipped chestplate; empty item if none virtual cItem GetEquippedChestplate(void) const { return cItem(); } /// Returns the currently equipped leggings; empty item if none virtual cItem GetEquippedLeggings(void) const { return cItem(); } - + /// Returns the currently equipped boots; empty item if none virtual cItem GetEquippedBoots(void) const { return cItem(); } - /// Called when the health drops below zero. a_Killer may be NULL (environmental damage) + /// Called when the health drops below zero. a_Killer may be nullptr (environmental damage) virtual void KilledBy(TakeDamageInfo & a_TDI); /// Called when the entity kills another entity @@ -317,20 +317,20 @@ public: /// Heals the specified amount of HPs virtual void Heal(int a_HitPoints); - + /// Returns the health of this entity int GetHealth(void) const { return m_Health; } - + /// Sets the health of this entity; doesn't broadcast any hurt animation void SetHealth(int a_Health); - + // tolua_end virtual void Tick(float a_Dt, cChunk & a_Chunk); - + /// Handles the physics of the entity - updates position based on speed, updates speed based on environment virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk); - + /// Updates the state related to this entity being on fire virtual void TickBurning(cChunk & a_Chunk); @@ -341,34 +341,34 @@ public: Returns true if MoveToWorld() was called, false if not */ virtual bool DetectPortal(void); - + /// Handles when the entity is in the void virtual void TickInVoid(cChunk & a_Chunk); /// Called when the entity starts burning virtual void OnStartedBurning(void); - + /// Called when the entity finishes burning virtual void OnFinishedBurning(void); - + // tolua_begin - + /// Sets the maximum value for the health void SetMaxHealth(int a_MaxHealth); int GetMaxHealth(void) const { return m_MaxHealth; } - + /// Sets whether the entity is fireproof void SetIsFireproof(bool a_IsFireproof); - + bool IsFireproof(void) const { return m_IsFireproof; } - + /// Puts the entity on fire for the specified amount of ticks void StartBurning(int a_TicksLeftBurning); - + /// Stops the entity from burning, resets all burning timers void StopBurning(void); - + // tolua_end /** Descendants override this function to send a command to the specified client to spawn the entity on the client. @@ -377,10 +377,10 @@ public: virtual void SpawnOn(cClientHandle & a_Client) = 0; // tolua_begin - + /// Teleports to the entity specified virtual void TeleportToEntity(cEntity & a_Entity); - + /// Teleports to the coordinates specified virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ); @@ -389,7 +389,7 @@ public: /** Moves entity to specified world, taking a world name */ bool MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn = true); - + // tolua_end virtual bool DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn); @@ -399,16 +399,16 @@ public: /** Sets the world the entity will be leaving */ void SetWorldTravellingFrom(cWorld * a_World) { m_WorldTravellingFrom = a_World; } - + /// Updates clients of changes in the entity. - virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = NULL); - + virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = nullptr); + /// Attaches to the specified entity; detaches from any previous one first void AttachTo(cEntity * a_AttachTo); - + /// Detaches from the currently attached entity, if any virtual void Detach(void); - + /// Makes sure head yaw is not over the specified range. void WrapHeadYaw(); @@ -417,9 +417,9 @@ public: /// Makes speed is not over 20. Max speed is 20 blocks / second void WrapSpeed(); - + // tolua_begin - + // COMMON metadata flags; descendants may override the defaults: virtual bool IsOnFire (void) const {return (m_TicksLeftBurning > 0); } virtual bool IsCrouched (void) const {return false; } @@ -437,20 +437,20 @@ public: /** Gets number of ticks this entity has existed for */ long int GetTicksAlive(void) const { return m_TicksAlive; } - + /** Gets the invulnerable ticks from the entity */ int GetInvulnerableTicks(void) const { return m_InvulnerableTicks; } /** Set the invulnerable ticks from the entity */ void SetInvulnerableTicks(int a_InvulnerableTicks) { m_InvulnerableTicks = a_InvulnerableTicks; } - + // tolua_end - + /// Called when the specified player right-clicks this entity virtual void OnRightClicked(cPlayer & a_Player) {} /// Returns the list of drops for this pawn when it is killed. May check a_Killer for special handling (sword of looting etc.). Called from KilledBy(). - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) { UNUSED(a_Drops); UNUSED(a_Killer); @@ -462,38 +462,38 @@ public: protected: static cCriticalSection m_CSCount; static int m_EntityCount; - + /** Measured in meter/second (m/s) */ Vector3d m_Speed; int m_UniqueID; - + int m_Health; int m_MaxHealth; - - /// The entity to which this entity is attached (vehicle), NULL if none + + /// The entity to which this entity is attached (vehicle), nullptr if none cEntity * m_AttachedTo; - - /// The entity which is attached to this entity (rider), NULL if none + + /// The entity which is attached to this entity (rider), nullptr if none cEntity * m_Attachee; /** Stores whether head yaw has been set manually */ bool m_bDirtyHead; - + /** Stores whether our yaw/pitch/roll (body orientation) has been set manually */ bool m_bDirtyOrientation; - + /** Stores whether we have sent a Velocity packet with a speed of zero (no speed) to the client Ensures that said packet is sent only once */ bool m_bHasSentNoSpeed; /** Stores if the entity is on the ground */ bool m_bOnGround; - + /** Stores gravity that is applied to an entity every tick For realistic effects, this should be negative. For spaaaaaaace, this can be zero or even positive */ float m_Gravity; - + /** Last position sent to client via the Relative Move or Teleport packets (not Velocity) Only updated if cEntity::BroadcastMovementUpdate() is called! */ Vector3d m_LastPos; @@ -502,37 +502,37 @@ protected: bool m_IsInitialized; /** World entity is travelling from - Set to a valid world pointer by MoveToWorld; reset to NULL when the entity is removed from the old world + Set to a valid world pointer by MoveToWorld; reset to nullptr when the entity is removed from the old world Can't be a simple boolean as context switches between worlds may leave the new chunk processing (and therefore immediately removing) the entity before the old chunk could remove it */ cWorld * m_WorldTravellingFrom; eEntityType m_EntityType; - + cWorld * m_World; - + /// Whether the entity is capable of taking fire or lava damage. bool m_IsFireproof; /// Time, in ticks, since the last damage dealt by being on fire. Valid only if on fire (IsOnFire()) int m_TicksSinceLastBurnDamage; - + /// Time, in ticks, since the last damage dealt by standing in lava. Reset to zero when moving out of lava. int m_TicksSinceLastLavaDamage; - + /// Time, in ticks, since the last damage dealt by standing in fire. Reset to zero when moving out of fire. int m_TicksSinceLastFireDamage; - + /// Time, in ticks, until the entity extinguishes its fire int m_TicksLeftBurning; - + /// Time, in ticks, since the last damage dealt by the void. Reset to zero when moving out of the void. int m_TicksSinceLastVoidDamage; - + /** Does the actual speed-setting. The default implementation just sets the member variable value; overrides can provide further processing, such as forcing players to move at the given speed. */ virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ); - + virtual void Destroyed(void) {} // Called after the entity has been destroyed /** Applies friction to an entity @@ -543,7 +543,7 @@ protected: /** Called in each tick to handle air-related processing i.e. drowning */ virtual void HandleAir(void); - + /** Called once per tick to set IsSwimming and IsSubmerged */ virtual void SetSwimState(cChunk & a_Chunk); @@ -568,29 +568,29 @@ protected: /** Portal delay timer and cooldown boolean data */ sPortalCooldownData m_PortalCooldownData; - + /** The number of ticks this entity has been alive for */ long int m_TicksAlive; - + private: /** Measured in degrees, [-180, +180) */ double m_HeadYaw; - + /** Measured in degrees, [-180, +180) */ Vector3d m_Rot; - + /** Position of the entity's XZ center and Y bottom */ Vector3d m_Pos; - + /** Measured in meter / second */ Vector3d m_WaterSpeed; - + /** Measured in Kilograms (Kg) */ double m_Mass; - + /** Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. */ double m_Width; - + /** Height of the entity (Y axis) */ double m_Height; @@ -600,3 +600,7 @@ private: } ; // tolua_export typedef std::list cEntityList; + + + + diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index b1ddaa30e..bae686b77 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -216,7 +216,7 @@ cEntityEffect * cEntityEffect::CreateEntityEffect(cEntityEffect::eType a_EffectT } ASSERT(!"Unhandled entity effect type!"); - return NULL; + return nullptr; } @@ -329,7 +329,7 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead()) { - a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage + a_Target.TakeDamage(dtPotionOfHarming, nullptr, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage return; } a_Target.Heal(amount); @@ -352,7 +352,7 @@ void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) a_Target.Heal(amount); return; } - a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage + a_Target.TakeDamage(dtPotionOfHarming, nullptr, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage } @@ -452,7 +452,7 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) // Cannot take poison damage when health is at 1 if (a_Target.GetHealth() > 1) { - a_Target.TakeDamage(dtPoisoning, NULL, 1, 0); + a_Target.TakeDamage(dtPoisoning, nullptr, 1, 0); } } } @@ -473,7 +473,7 @@ void cEntityEffectWither::OnTick(cPawn & a_Target) if ((m_Ticks % frequency) == 0) { - a_Target.TakeDamage(dtWither, NULL, 1, 0); + a_Target.TakeDamage(dtWither, nullptr, 1, 0); } } diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 73d5cbfed..751308661 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -45,7 +45,7 @@ void cExpOrb::SpawnOn(cClientHandle & a_Client) void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk) { cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 5)); - if (a_ClosestPlayer != NULL) + if (a_ClosestPlayer != nullptr) { Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition()); a_PlayerPos.y++; diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index 159429147..5fe6a1238 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -22,7 +22,7 @@ public: m_Pos(a_Pos), m_NextPos(a_NextPos), m_MinCoeff(1), - m_HitEntity(NULL) + m_HitEntity(nullptr) { } virtual bool Item(cEntity * a_Entity) override diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index 6704c05b4..dfffcd3ed 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -62,7 +62,7 @@ void cItemFrame::KilledBy(TakeDamageInfo & a_TDI) return; } - if ((a_TDI.Attacker != NULL) && a_TDI.Attacker->IsPlayer() && !((cPlayer *)a_TDI.Attacker)->IsGameModeCreative()) + if ((a_TDI.Attacker != nullptr) && a_TDI.Attacker->IsPlayer() && !((cPlayer *)a_TDI.Attacker)->IsGameModeCreative()) { cItems Item; Item.push_back(m_Item); @@ -83,7 +83,7 @@ void cItemFrame::KilledBy(TakeDamageInfo & a_TDI) void cItemFrame::GetDrops(cItems & a_Items, cEntity * a_Killer) { - if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative()) + if ((a_Killer != nullptr) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative()) { a_Items.push_back(cItem(E_ITEM_ITEM_FRAME)); } diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index f45e7bb69..22e046800 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -36,7 +36,7 @@ public: virtual bool Item(cEntity * a_Entity) override { - ASSERT(a_Entity != NULL); + ASSERT(a_Entity != nullptr); if (!a_Entity->IsPlayer() && !a_Entity->IsMob() && !a_Entity->IsMinecart() && !a_Entity->IsBoat()) { @@ -130,7 +130,7 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) int RelPosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; int RelPosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); - if (Chunk == NULL) + if (Chunk == nullptr) { // Inside an unloaded chunk, bail out all processing return; @@ -806,7 +806,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) { - cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == NULL) ? -1 : m_Attachee->GetUniqueID())); + cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == nullptr) ? -1 : m_Attachee->GetUniqueID())); int ChunkX, ChunkZ; cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ); m_World->ForEachEntityInChunk(ChunkX, ChunkZ, MinecartCollisionCallback); @@ -980,7 +980,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) bool cMinecart::DoTakeDamage(TakeDamageInfo & TDI) { - if ((TDI.Attacker != NULL) && TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative()) + if ((TDI.Attacker != nullptr) && TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative()) { Destroy(); TDI.FinalDamage = GetMaxHealth(); // Instant hit for creative @@ -1074,7 +1074,7 @@ void cRideableMinecart::OnRightClicked(cPlayer & a_Player) { super::OnRightClicked(a_Player); - if (m_Attachee != NULL) + if (m_Attachee != nullptr) { if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID()) { @@ -1120,14 +1120,14 @@ void cMinecartWithChest::OnRightClicked(cPlayer & a_Player) { // If the window is not created, open it anew: cWindow * Window = GetWindow(); - if (Window == NULL) + if (Window == nullptr) { OpenNewWindow(); Window = GetWindow(); } // Open the window for the player: - if (Window != NULL) + if (Window != nullptr) { if (a_Player.GetWindow() != Window) { diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index ab906fd06..40e22c641 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -140,9 +140,9 @@ protected: { UNUSED(a_SlotNum); ASSERT(a_Grid == &m_Contents); - if (m_World != NULL) + if (m_World != nullptr) { - if (GetWindow() != NULL) + if (GetWindow() != nullptr) { GetWindow()->BroadcastWholeWindow(); } diff --git a/src/Entities/Painting.cpp b/src/Entities/Painting.cpp index e217556c7..1aa6da0a1 100644 --- a/src/Entities/Painting.cpp +++ b/src/Entities/Painting.cpp @@ -43,7 +43,7 @@ void cPainting::Tick(float a_Dt, cChunk & a_Chunk) void cPainting::GetDrops(cItems & a_Items, cEntity * a_Killer) { - if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative()) + if ((a_Killer != nullptr) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative()) { a_Items.push_back(cItem(E_ITEM_PAINTING)); } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 6bd0a3d20..790147fd3 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -56,8 +56,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) : m_Stance(0.0), m_Inventory(*this), m_EnderChestContents(9, 3), - m_CurrentWindow(NULL), - m_InventoryWindow(NULL), + m_CurrentWindow(nullptr), + m_InventoryWindow(nullptr), m_GameMode(eGameMode_NotSet), m_IP(""), m_ClientHandle(a_Client), @@ -78,10 +78,10 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) : m_IsChargingBow(false), m_BowCharge(0), m_FloaterID(-1), - m_Team(NULL), + m_Team(nullptr), m_TicksUntilNextSave(PLAYER_INVENTORY_SAVE_INTERVAL), m_bIsTeleporting(false), - m_UUID((a_Client != NULL) ? a_Client->GetUUID() : ""), + m_UUID((a_Client != nullptr) ? a_Client->GetUUID() : ""), m_CustomName("") { m_InventoryWindow = new cInventoryWindow(*this); @@ -96,7 +96,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) : m_PlayerName = a_PlayerName; - cWorld * World = NULL; + cWorld * World = nullptr; if (!LoadFromDisk(World)) { m_Inventory.Clear(); @@ -144,10 +144,10 @@ cPlayer::~cPlayer(void) SaveToDisk(); - m_ClientHandle = NULL; + m_ClientHandle = nullptr; delete m_InventoryWindow; - m_InventoryWindow = NULL; + m_InventoryWindow = nullptr; LOGD("Player %p deleted", this); } @@ -186,12 +186,12 @@ void cPlayer::SpawnOn(cClientHandle & a_Client) void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) { - if (m_ClientHandle != NULL) + if (m_ClientHandle != nullptr) { if (m_ClientHandle->IsDestroyed()) { // This should not happen, because destroying a client will remove it from the world, but just in case - m_ClientHandle = NULL; + m_ClientHandle = nullptr; return; } @@ -504,7 +504,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) if (Damage > 0) { // cPlayer makes sure damage isn't applied in creative, no need to check here - TakeDamage(dtFalling, NULL, Damage, Damage, 0); + TakeDamage(dtFalling, nullptr, Damage, Damage, 0); // Fall particles GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, (int)GetPosY() - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */); @@ -651,7 +651,7 @@ void cPlayer::AbortEating(void) void cPlayer::SendHealth(void) { - if (m_ClientHandle != NULL) + if (m_ClientHandle != nullptr) { m_ClientHandle->SendHealth(); } @@ -663,7 +663,7 @@ void cPlayer::SendHealth(void) void cPlayer::SendExperience(void) { - if (m_ClientHandle != NULL) + if (m_ClientHandle != nullptr) { m_ClientHandle->SendExperience(); m_bDirtyExperience = false; @@ -859,11 +859,11 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) } } - if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer())) + if ((a_TDI.Attacker != nullptr) && (a_TDI.Attacker->IsPlayer())) { cPlayer * Attacker = (cPlayer *)a_TDI.Attacker; - if ((m_Team != NULL) && (m_Team == Attacker->m_Team)) + if ((m_Team != nullptr) && (m_Team == Attacker->m_Team)) { if (!m_Team->AllowsFriendlyFire()) { @@ -915,7 +915,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI) m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10); SaveToDisk(); // Save it, yeah the world is a tough place ! - if ((a_TDI.Attacker == NULL) && m_World->ShouldBroadcastDeathMessages()) + if ((a_TDI.Attacker == nullptr) && m_World->ShouldBroadcastDeathMessages()) { AString DamageText; switch (a_TDI.DamageType) @@ -941,7 +941,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI) } GetWorld()->BroadcastChatDeath(Printf("%s %s", GetName().c_str(), DamageText.c_str())); } - else if (a_TDI.Attacker == NULL) // && !m_World->ShouldBroadcastDeathMessages() by fallthrough + else if (a_TDI.Attacker == nullptr) // && !m_World->ShouldBroadcastDeathMessages() by fallthrough { // no-op } @@ -997,7 +997,7 @@ void cPlayer::Killed(cEntity * a_Victim) void cPlayer::Respawn(void) { - ASSERT(m_World != NULL); + ASSERT(m_World != nullptr); m_Health = GetMaxHealth(); SetInvulnerableTicks(20); @@ -1107,9 +1107,9 @@ void cPlayer::SetTeam(cTeam * a_Team) cTeam * cPlayer::UpdateTeam(void) { - if (m_World == NULL) + if (m_World == nullptr) { - SetTeam(NULL); + SetTeam(nullptr); } else { @@ -1142,7 +1142,7 @@ void cPlayer::OpenWindow(cWindow * a_Window) void cPlayer::CloseWindow(bool a_CanRefuse) { - if (m_CurrentWindow == NULL) + if (m_CurrentWindow == nullptr) { m_CurrentWindow = m_InventoryWindow; return; @@ -1167,7 +1167,7 @@ void cPlayer::CloseWindow(bool a_CanRefuse) void cPlayer::CloseWindowIfID(char a_WindowID, bool a_CanRefuse) { - if ((m_CurrentWindow == NULL) || (m_CurrentWindow->GetWindowID() != a_WindowID)) + if ((m_CurrentWindow == nullptr) || (m_CurrentWindow->GetWindowID() != a_WindowID)) { return; } @@ -1354,7 +1354,7 @@ void cPlayer::MoveTo( const Vector3d & a_NewPos) // Y = -999 and X, Z = attempting to create speed, usually up to 0.03 // We cannot test m_AttachedTo, because when deattaching, the server thinks the client is already deattached while // the client may still send more of these nonsensical packets. - if (m_AttachedTo != NULL) + if (m_AttachedTo != nullptr) { Vector3d AddSpeed(a_NewPos); AddSpeed.y = 0; @@ -1581,7 +1581,7 @@ void cPlayer::TossItems(const cItems & a_Items) bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn) { - ASSERT(a_World != NULL); + ASSERT(a_World != nullptr); if (GetWorld() == a_World) { @@ -1590,7 +1590,7 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn) } // Send the respawn packet: - if (a_ShouldSendRespawn && (m_ClientHandle != NULL)) + if (a_ShouldSendRespawn && (m_ClientHandle != nullptr)) { m_ClientHandle->SendRespawn(a_World->GetDimension()); } @@ -1652,7 +1652,7 @@ bool cPlayer::LoadFromDisk(cWorldPtr & a_World) GetName().c_str(), m_UUID.c_str(), OfflineUUID.c_str(), OfflineUsage ); - if (a_World == NULL) + if (a_World == nullptr) { a_World = cRoot::Get()->GetDefaultWorld(); } @@ -1729,7 +1729,7 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World) m_LoadedWorldName = root.get("world", "world").asString(); a_World = cRoot::Get()->GetWorld(GetLoadedWorldName(), false); - if (a_World == NULL) + if (a_World == nullptr) { a_World = cRoot::Get()->GetDefaultWorld(); } @@ -1795,7 +1795,7 @@ bool cPlayer::SaveToDisk() root["SpawnY"] = GetLastBedPos().y; root["SpawnZ"] = GetLastBedPos().z; - if (m_World != NULL) + if (m_World != nullptr) { root["world"] = m_World->GetName(); if (m_GameMode == m_World->GetGameMode()) @@ -1949,7 +1949,7 @@ void cPlayer::HandleFood(void) else if ((m_FoodLevel <= 0) && (m_Health > 1)) { // Damage from starving - TakeDamage(dtStarving, NULL, 1, 1, 0); + TakeDamage(dtStarving, nullptr, 1, 1, 0); } } } @@ -2018,7 +2018,7 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos) { StatValue Value = (StatValue)floor(a_DeltaPos.Length() * 100 + 0.5); - if (m_AttachedTo == NULL) + if (m_AttachedTo == nullptr) { if (IsClimbing()) { @@ -2091,7 +2091,7 @@ void cPlayer::ApplyFoodExhaustionFromMovement() } // If riding anything, apply no food exhaustion - if (m_AttachedTo != NULL) + if (m_AttachedTo != nullptr) { return; } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 22d6a2ae2..4bb51b556 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -176,10 +176,10 @@ public: AString GetIP(void) const { return m_IP; } // tolua_export - /** Returns the associated team, NULL if none */ + /** Returns the associated team, nullptr if none */ cTeam * GetTeam(void) { return m_Team; } // tolua_export - /** Sets the player team, NULL if none */ + /** Sets the player team, nullptr if none */ void SetTeam(cTeam * a_Team); // tolua_end diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index ab25ac30c..1768714f8 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -135,7 +135,7 @@ public: m_Pos(a_Pos), m_NextPos(a_NextPos), m_MinCoeff(1), - m_HitEntity(NULL) + m_HitEntity(nullptr) { } @@ -221,9 +221,9 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a super(etProjectile, a_X, a_Y, a_Z, a_Width, a_Height), m_ProjectileKind(a_Kind), m_CreatorData( - ((a_Creator != NULL) ? a_Creator->GetUniqueID() : -1), - ((a_Creator != NULL) ? (a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "") : ""), - ((a_Creator != NULL) ? a_Creator->GetEquippedWeapon().m_Enchantments : cEnchantments()) + ((a_Creator != nullptr) ? a_Creator->GetUniqueID() : -1), + ((a_Creator != nullptr) ? (a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "") : ""), + ((a_Creator != nullptr) ? a_Creator->GetEquippedWeapon().m_Enchantments : cEnchantments()) ), m_IsInGround(false) { @@ -251,7 +251,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Ve cProjectileEntity * 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) { Vector3d Speed; - if (a_Speed != NULL) + if (a_Speed != nullptr) { Speed = *a_Speed; } @@ -269,10 +269,10 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, case pkWitherSkull: return new cWitherSkullEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkFirework: { - ASSERT(a_Item != NULL); + ASSERT(a_Item != nullptr); if (a_Item->m_FireworkItem.m_Colours.empty()) { - return NULL; + return nullptr; } return new cFireworkEntity(a_Creator, a_X, a_Y, a_Z, *a_Item); @@ -280,7 +280,7 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, } LOGWARNING("%s: Unknown projectile kind: %d", __FUNCTION__, a_Kind); - return NULL; + return nullptr; } diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index b9d2dfa63..2a98e31c7 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -46,7 +46,7 @@ public: 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 cItem * a_Item, const Vector3d * a_Speed = NULL); + 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 */ virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace); @@ -110,7 +110,7 @@ protected: eKind m_ProjectileKind; /** 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) + The ID and/or name may be nullptr (e.g. for dispensers/mobs) */ CreatorData m_CreatorData; -- cgit v1.2.3