diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-07-20 13:02:23 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-07-20 13:02:23 +0200 |
commit | d0e7b2f18b15afbc78adfdcf7d1b7b3511a0a6ab (patch) | |
tree | 4f283dd99354a72bb8ba30da637b38adb5521b76 /src/Entities | |
parent | Proper comment for DropBlock() (diff) | |
parent | NBTChunkSerializer.cpp: Added break after serializing the splash potion (diff) | |
download | cuberite-d0e7b2f18b15afbc78adfdcf7d1b7b3511a0a6ab.tar cuberite-d0e7b2f18b15afbc78adfdcf7d1b7b3511a0a6ab.tar.gz cuberite-d0e7b2f18b15afbc78adfdcf7d1b7b3511a0a6ab.tar.bz2 cuberite-d0e7b2f18b15afbc78adfdcf7d1b7b3511a0a6ab.tar.lz cuberite-d0e7b2f18b15afbc78adfdcf7d1b7b3511a0a6ab.tar.xz cuberite-d0e7b2f18b15afbc78adfdcf7d1b7b3511a0a6ab.tar.zst cuberite-d0e7b2f18b15afbc78adfdcf7d1b7b3511a0a6ab.zip |
Diffstat (limited to 'src/Entities')
33 files changed, 341 insertions, 262 deletions
diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index a3a1667e4..913519c4c 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -72,15 +72,15 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) -{ +{ if (GetSpeed().EqualsEps(Vector3d(0, 0, 0), 0.0000001)) { - SetSpeed(GetLookVector().NormalizeCopy() * 0.1); // Ensure that no division by zero happens later + SetSpeed(GetLookVector().NormalizeCopy() * 0.1); // Ensure that no division by zero happens later } Vector3d Hit = a_HitPos; Vector3d SinkMovement = (GetSpeed() / 1000); - Hit += SinkMovement * (0.0005 / SinkMovement.Length()); // Make arrow sink into block a centimetre so it lodges (but not to far so it goes black clientside) + Hit += SinkMovement * (0.0005 / SinkMovement.Length()); // Make arrow sink into block a centimetre so it lodges (but not to far so it goes black clientside) super::OnHitSolidBlock(Hit, a_HitFace); Vector3i BlockHit = Hit.Floor(); @@ -97,7 +97,7 @@ void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFa void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) -{ +{ int Damage = (int)(GetSpeed().Length() / 20 * m_DamageCoeff + 0.5); if (m_IsCritical) { @@ -166,9 +166,9 @@ void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) // We can afford to do this because xoft's algorithm for trajectory is near perfect, so things are pretty close anyway without sync // Besides, this seems to be what the vanilla server does, note how arrows teleport half a second after they hit to the server position - if (!m_HasTeleported) // Sent a teleport already, don't do again + if (!m_HasTeleported) // Sent a teleport already, don't do again { - if (m_HitGroundTimer > 500.f) // Send after half a second, could be less, but just in case + if (m_HitGroundTimer > 500.f) // Send after half a second, could be less, but just in case { m_World->BroadcastTeleportEntity(*this); m_HasTeleported = true; @@ -189,9 +189,9 @@ void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk) return; } - if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? + if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? { - m_IsInGround = false; // Yes, begin simulating physics again + m_IsInGround = false; // Yes, begin simulating physics again } } } diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h index 76cb24449..ad93dba6c 100644 --- a/src/Entities/ArrowEntity.h +++ b/src/Entities/ArrowEntity.h @@ -99,4 +99,4 @@ protected: virtual void CollectedBy(cPlayer * a_Player) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; -}; // tolua_export +}; // tolua_export diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 31bfe3dc3..8ff8866a1 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -94,7 +94,7 @@ void cBoat::Tick(float a_Dt, cChunk & a_Chunk) super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); - SetSpeed(GetSpeed() * 0.97); // Slowly decrease the speed + SetSpeed(GetSpeed() * 0.97); // Slowly decrease the speed if ((POSY_TOINT < 0) || (POSY_TOINT > cChunkDef::Height)) { @@ -104,7 +104,7 @@ void cBoat::Tick(float a_Dt, cChunk & a_Chunk) if (IsBlockWater(m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT))) { if (GetSpeedY() < 2) - { + { AddSpeedY(0.2); } } diff --git a/src/Entities/CMakeLists.txt b/src/Entities/CMakeLists.txt index 205cb2cca..5d10e1680 100644 --- a/src/Entities/CMakeLists.txt +++ b/src/Entities/CMakeLists.txt @@ -4,11 +4,64 @@ project (MCServer) include_directories ("${PROJECT_SOURCE_DIR}/../") -file(GLOB SOURCE - "*.cpp" - "*.h" -) +SET (SRCS + ArrowEntity.cpp + Boat.cpp + EnderCrystal.cpp + Entity.cpp + EntityEffect.cpp + ExpBottleEntity.cpp + ExpOrb.cpp + FallingBlock.cpp + FireChargeEntity.cpp + FireworkEntity.cpp + Floater.cpp + GhastFireballEntity.cpp + HangingEntity.cpp + ItemFrame.cpp + Minecart.cpp + Painting.cpp + Pawn.cpp + Pickup.cpp + Player.cpp + ProjectileEntity.cpp + SplashPotionEntity.cpp + TNTEntity.cpp + ThrownEggEntity.cpp + ThrownEnderPearlEntity.cpp + ThrownSnowballEntity.cpp + WitherSkullEntity.cpp) -add_library(Entities ${SOURCE}) +SET (HDRS + ArrowEntity.h + Boat.h + EnderCrystal.h + Entity.h + EntityEffect.h + ExpBottleEntity.h + ExpOrb.h + FallingBlock.h + FireChargeEntity.h + FireworkEntity.h + Floater.h + GhastFireballEntity.h + HangingEntity.h + ItemFrame.h + Minecart.h + Painting.h + Pawn.h + Pickup.h + Player.h + ProjectileEntity.h + SplashPotionEntity.h + TNTEntity.h + ThrownEggEntity.h + ThrownEnderPearlEntity.h + ThrownSnowballEntity.h + WitherSkullEntity.h) -target_link_libraries(Entities WorldStorage) +if(NOT MSVC) + add_library(Entities ${SRCS} ${HDRS}) + + target_link_libraries(Entities WorldStorage) +endif() diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 4a6de25b7..5a3bbcdc4 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -49,6 +49,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_IsSubmerged(false) , m_AirLevel(0) , m_AirTickTimer(0) + , m_TicksAlive(0) , m_HeadYaw(0.0) , m_Rot(0.0, 0.0, 0.0) , m_Pos(a_X, a_Y, a_Z) @@ -74,7 +75,7 @@ cEntity::~cEntity() /* // DEBUG: - LOGD("Deleting entity %d at pos {%.2f, %.2f, %.2f} ~ [%d, %d]; ptr %p", + LOGD("Deleting entity %d at pos {%.2f, %.2f, %.2f} ~ [%d, %d]; ptr %p", m_UniqueID, m_Pos.x, m_Pos.y, m_Pos.z, (int)(m_Pos.x / cChunkDef::Width), (int)(m_Pos.z / cChunkDef::Width), @@ -272,7 +273,7 @@ void cEntity::SetYawFromSpeed(void) void cEntity::SetPitchFromSpeed(void) { const double EPS = 0.0000001; - double xz = sqrt(m_Speed.x * m_Speed.x + m_Speed.z * m_Speed.z); // Speed XZ-plane component + double xz = sqrt(m_Speed.x * m_Speed.x + m_Speed.z * m_Speed.z); // Speed XZ-plane component if ((abs(xz) < EPS) && (abs(m_Speed.y) < EPS)) { // atan2() may overflow or is undefined, pick any number @@ -316,7 +317,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) if ((a_TDI.DamageType == dtAttack) || (a_TDI.DamageType == dtArrowAttack)) { a_TDI.FinalDamage += 2; - m_World->BroadcastEntityAnimation(*this, 4); // Critical hit + m_World->BroadcastEntityAnimation(*this, 4); // Critical hit } } @@ -327,14 +328,11 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) // TODO: Apply damage to armor - if (m_Health < 0) - { - m_Health = 0; - } + m_Health = std::max(m_Health, 0); - if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != NULL)) // Knockback for only players and mobs + if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != NULL)) // Knockback for only players and mobs { - int KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchKnockback); // More common enchantment + int KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchKnockback); // More common enchantment if (KnockbackLevel < 1) { // We support punch on swords and vice versa! :) @@ -345,7 +343,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) switch (KnockbackLevel) { case 1: AdditionalSpeed.Set(5, 0.3, 5); break; - case 2: AdditionalSpeed.Set(8, 0.3, 8); break; + case 2: AdditionalSpeed.Set(8, 0.3, 8); break; default: break; } AddSpeed(a_TDI.Knockback + AdditionalSpeed); @@ -562,6 +560,8 @@ void cEntity::SetHealth(int a_Health) void cEntity::Tick(float a_Dt, cChunk & a_Chunk) { + m_TicksAlive++; + if (m_InvulnerableTicks > 0) { m_InvulnerableTicks--; @@ -640,7 +640,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) { - // Outside of the world + // Outside of the world AddSpeedY(m_Gravity * a_Dt); AddPosition(GetSpeed() * a_Dt); return; @@ -752,11 +752,11 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) NextSpeed.x *= 0.25; NextSpeed.z *= 0.25; } - - //Get water direction + + // Get water direction Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ); - m_WaterSpeed *= 0.9f; //Reduce speed each tick + m_WaterSpeed *= 0.9f; // Reduce speed each tick switch(WaterDir) { @@ -813,7 +813,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) if (Tracer.HitNormal.y != 0.f) NextSpeed.y = 0.f; if (Tracer.HitNormal.z != 0.f) NextSpeed.z = 0.f; - if (Tracer.HitNormal.y == 1) // Hit BLOCK_FACE_YP, we are on the ground + if (Tracer.HitNormal.y == 1) // Hit BLOCK_FACE_YP, we are on the ground { m_bOnGround = true; } @@ -858,7 +858,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) if (POSY_TOINT > m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) { m_TicksLeftBurning = 0; - } + } } // Do the burning damage: @@ -1080,9 +1080,9 @@ void cEntity::HandleAir(void) if (IsSubmerged()) { - if (!IsPlayer()) // Players control themselves + if (!IsPlayer()) // Players control themselves { - SetSpeedY(1); // Float in the water + SetSpeedY(1); // Float in the water } // Either reduce air level or damage player @@ -1090,7 +1090,7 @@ void cEntity::HandleAir(void) { if (m_AirTickTimer < 1) { - // Damage player + // Damage player TakeDamage(dtDrowning, NULL, 1, 1, 0); // Reset timer m_AirTickTimer = DROWNING_TICKS; @@ -1146,10 +1146,7 @@ void cEntity::SetMaxHealth(int a_MaxHealth) m_MaxHealth = a_MaxHealth; // Reset health, if too high: - if (m_Health > a_MaxHealth) - { - m_Health = a_MaxHealth; - } + m_Health = std::min(m_Health, a_MaxHealth); } @@ -1251,9 +1248,9 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude) int DiffY = (int)(floor(GetPosY() * 32.0) - floor(m_LastPos.y * 32.0)); int DiffZ = (int)(floor(GetPosZ() * 32.0) - floor(m_LastPos.z * 32.0)); - if ((DiffX != 0) || (DiffY != 0) || (DiffZ != 0)) // Have we moved? + if ((DiffX != 0) || (DiffY != 0) || (DiffZ != 0)) // Have we moved? { - if ((abs(DiffX) <= 127) && (abs(DiffY) <= 127) && (abs(DiffZ) <= 127)) // Limitations of a Byte + if ((abs(DiffX) <= 127) && (abs(DiffY) <= 127) && (abs(DiffZ) <= 127)) // Limitations of a Byte { // Difference within Byte limitations, use a relative move packet if (m_bDirtyOrientation) @@ -1273,7 +1270,7 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude) { // Too big a movement, do a teleport m_World->BroadcastTeleportEntity(*this, a_Exclude); - m_LastPos = GetPosition(); // See above + m_LastPos = GetPosition(); // See above m_bDirtyOrientation = false; } } @@ -1382,8 +1379,8 @@ void cEntity::SetMass(double a_Mass) } else { - // Make sure that mass is not zero. 1g is the default because we - // have to choose a number. It's perfectly legal to have a mass + // Make sure that mass is not zero. 1g is the default because we + // have to choose a number. It's perfectly legal to have a mass // less than 1g as long as is NOT equal or less than zero. m_Mass = 0.001; } @@ -1469,7 +1466,7 @@ void cEntity::SetWidth(double a_Width) void cEntity::AddPosX(double a_AddPosX) { - m_Pos.x += a_AddPosX; + m_Pos.x += a_AddPosX; } @@ -1477,7 +1474,7 @@ void cEntity::AddPosX(double a_AddPosX) void cEntity::AddPosY(double a_AddPosY) { - m_Pos.y += a_AddPosY; + m_Pos.y += a_AddPosY; } @@ -1485,7 +1482,7 @@ void cEntity::AddPosY(double a_AddPosY) void cEntity::AddPosZ(double a_AddPosZ) { - m_Pos.z += a_AddPosZ; + m_Pos.z += a_AddPosZ; } @@ -1495,7 +1492,7 @@ void cEntity::AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ) { m_Pos.x += a_AddPosX; m_Pos.y += a_AddPosY; - m_Pos.z += a_AddPosZ; + m_Pos.z += a_AddPosZ; } @@ -1505,7 +1502,7 @@ void cEntity::AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeed { m_Speed.x += a_AddSpeedX; m_Speed.y += a_AddSpeedY; - m_Speed.z += a_AddSpeedZ; + m_Speed.z += a_AddSpeedZ; WrapSpeed(); } @@ -1515,7 +1512,7 @@ void cEntity::AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeed void cEntity::AddSpeedX(double a_AddSpeedX) { - m_Speed.x += a_AddSpeedX; + m_Speed.x += a_AddSpeedX; WrapSpeed(); } @@ -1525,7 +1522,7 @@ void cEntity::AddSpeedX(double a_AddSpeedX) void cEntity::AddSpeedY(double a_AddSpeedY) { - m_Speed.y += a_AddSpeedY; + m_Speed.y += a_AddSpeedY; WrapSpeed(); } @@ -1535,7 +1532,7 @@ void cEntity::AddSpeedY(double a_AddSpeedY) void cEntity::AddSpeedZ(double a_AddSpeedZ) { - m_Speed.z += a_AddSpeedZ; + m_Speed.z += a_AddSpeedZ; WrapSpeed(); } @@ -1572,7 +1569,7 @@ void cEntity::SteerVehicle(float a_Forward, float a_Sideways) -////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // Get look vector (this is NOT a rotation!) Vector3d cEntity::GetLookVector(void) const { @@ -1586,11 +1583,11 @@ Vector3d cEntity::GetLookVector(void) const -////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // Set position void cEntity::SetPosition(double a_PosX, double a_PosY, double a_PosZ) { - m_Pos.Set(a_PosX, a_PosY, a_PosZ); + m_Pos.Set(a_PosX, a_PosY, a_PosZ); } @@ -1599,7 +1596,7 @@ void cEntity::SetPosition(double a_PosX, double a_PosY, double a_PosZ) void cEntity::SetPosX(double a_PosX) { - m_Pos.x = a_PosX; + m_Pos.x = a_PosX; } @@ -1608,7 +1605,7 @@ void cEntity::SetPosX(double a_PosX) void cEntity::SetPosY(double a_PosY) { - m_Pos.y = a_PosY; + m_Pos.y = a_PosY; } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index ea44c2722..83fe76e7e 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -416,6 +416,9 @@ public: /** Gets remaining air of a monster */ int GetAirLevel(void) const { return m_AirLevel; } + /** 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; } @@ -428,7 +431,7 @@ public: virtual void OnRightClicked(cPlayer &) {}; /// 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 = NULL) { UNUSED(a_Drops); UNUSED(a_Killer); @@ -485,7 +488,7 @@ protected: /// 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; @@ -506,7 +509,7 @@ protected: 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 + virtual void Destroyed(void) {} // Called after the entity has been destroyed /** Called in each tick to handle air-related processing i.e. drowning */ virtual void HandleAir(void); @@ -521,6 +524,9 @@ protected: int m_AirLevel; int m_AirTickTimer; + /** The number of ticks this entity has been alive for */ + long int m_TicksAlive; + private: /** Measured in degrees, [-180, +180) */ double m_HeadYaw; diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index 4da7cac85..6c4b13a58 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -108,7 +108,7 @@ void cEntityEffect::OnTick(cPawn & a_Target) -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cEntityEffectInstantHealth: void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) @@ -128,7 +128,7 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cEntityEffectInstantDamage: void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) @@ -148,7 +148,7 @@ void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cEntityEffectRegeneration: void cEntityEffectRegeneration::OnTick(cPawn & a_Target) @@ -175,7 +175,7 @@ void cEntityEffectRegeneration::OnTick(cPawn & a_Target) -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cEntityEffectHunger: void cEntityEffectHunger::OnTick(cPawn & a_Target) @@ -193,7 +193,7 @@ void cEntityEffectHunger::OnTick(cPawn & a_Target) -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cEntityEffectWeakness: void cEntityEffectWeakness::OnTick(cPawn & a_Target) @@ -211,7 +211,7 @@ void cEntityEffectWeakness::OnTick(cPawn & a_Target) -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cEntityEffectPoison: void cEntityEffectPoison::OnTick(cPawn & a_Target) @@ -250,7 +250,7 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cEntityEffectWither: void cEntityEffectWither::OnTick(cPawn & a_Target) @@ -270,7 +270,7 @@ void cEntityEffectWither::OnTick(cPawn & a_Target) -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cEntityEffectSaturation: void cEntityEffectSaturation::OnTick(cPawn & a_Target) diff --git a/src/Entities/ExpBottleEntity.h b/src/Entities/ExpBottleEntity.h index b2043d8f1..e9536452c 100644 --- a/src/Entities/ExpBottleEntity.h +++ b/src/Entities/ExpBottleEntity.h @@ -30,4 +30,4 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; -}; // tolua_export +}; // tolua_export diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index e437c24ef..ed225b8e6 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -6,7 +6,7 @@ cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) - : cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98) + : cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98) , m_Reward(a_Reward) , m_Timer(0.f) { @@ -19,7 +19,7 @@ cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward) - : cEntity(etExpOrb, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98) + : cEntity(etExpOrb, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98) , m_Reward(a_Reward) , m_Timer(0.f) { diff --git a/src/Entities/FireChargeEntity.h b/src/Entities/FireChargeEntity.h index 3924c337c..42ecc7d74 100644 --- a/src/Entities/FireChargeEntity.h +++ b/src/Entities/FireChargeEntity.h @@ -33,4 +33,4 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override; -} ; // tolua_export +} ; // tolua_export diff --git a/src/Entities/FireworkEntity.h b/src/Entities/FireworkEntity.h index c62ca9402..7dbdc49e1 100644 --- a/src/Entities/FireworkEntity.h +++ b/src/Entities/FireworkEntity.h @@ -37,4 +37,4 @@ private: int m_ExplodeTimer; cItem m_FireworkItem; -}; // tolua_export +}; // tolua_export diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index d49893020..159429147 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -11,7 +11,7 @@ -/////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cFloaterEntityCollisionCallback class cFloaterEntityCollisionCallback : public cEntityCallback @@ -75,7 +75,7 @@ protected: -/////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cFloaterCheckEntityExist class cFloaterCheckEntityExist : public cEntityCallback @@ -130,7 +130,7 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) HandlePhysics(a_Dt, a_Chunk); if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ())) && m_World->GetBlockMeta((int) GetPosX(), (int) GetPosY(), (int) GetPosZ()) == 0) { - if ((!m_CanPickupItem) && (m_AttachedMobID == -1)) // Check if you can't already pickup a fish and if the floater isn't attached to a mob. + if ((!m_CanPickupItem) && (m_AttachedMobID == -1)) // Check if you can't already pickup a fish and if the floater isn't attached to a mob. { if (m_CountDownTime <= 0) { @@ -141,7 +141,7 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) m_CountDownTime = 100 + m_World->GetTickRandomNumber(800); LOGD("Floater %i can be picked up", GetUniqueID()); } - else if (m_CountDownTime == 20) // Calculate the position where the particles should spawn and start producing them. + else if (m_CountDownTime == 20) // Calculate the position where the particles should spawn and start producing them. { LOGD("Started producing particles for floater %i", GetUniqueID()); m_ParticlePos.Set(GetPosX() + (-4 + m_World->GetTickRandomNumber(8)), GetPosY(), GetPosZ() + (-4 + m_World->GetTickRandomNumber(8))); @@ -156,12 +156,12 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) m_CountDownTime--; if (m_World->GetHeight((int) GetPosX(), (int) GetPosZ()) == (int) GetPosY()) { - if (m_World->IsWeatherWet() && m_World->GetTickRandomNumber(3) == 0) // 25% chance of an extra countdown when being rained on. + if (m_World->IsWeatherWet() && m_World->GetTickRandomNumber(3) == 0) // 25% chance of an extra countdown when being rained on. { m_CountDownTime--; } } - else // if the floater is underground it has a 50% chance of not decreasing the countdown. + else // if the floater is underground it has a 50% chance of not decreasing the countdown. { if (m_World->GetTickRandomNumber(1) == 0) { @@ -190,21 +190,21 @@ void cFloater::Tick(float a_Dt, cChunk & a_Chunk) if (Callback.HasHit()) { AttachTo(Callback.GetHitEntity()); - Callback.GetHitEntity()->TakeDamage(*this); // TODO: the player attacked the mob not the floater. + Callback.GetHitEntity()->TakeDamage(*this); // TODO: the player attacked the mob not the floater. m_AttachedMobID = Callback.GetHitEntity()->GetUniqueID(); } } cFloaterCheckEntityExist EntityCallback; m_World->DoWithEntityByID(m_PlayerID, EntityCallback); - if (!EntityCallback.DoesExist()) // The owner doesn't exist anymore. Destroy the floater entity. + if (!EntityCallback.DoesExist()) // The owner doesn't exist anymore. Destroy the floater entity. { Destroy(true); } if (m_AttachedMobID != -1) { - m_World->DoWithEntityByID(m_AttachedMobID, EntityCallback); // The mob the floater was attached to doesn't exist anymore. + m_World->DoWithEntityByID(m_AttachedMobID, EntityCallback); // The mob the floater was attached to doesn't exist anymore. if (!EntityCallback.DoesExist()) { m_AttachedMobID = -1; diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h index 547d503f1..5d2720b6a 100644 --- a/src/Entities/Floater.h +++ b/src/Entities/Floater.h @@ -14,7 +14,7 @@ class cFloater : typedef cEntity super; public: - //tolua_end + // tolua_end CLASS_PROTODEF(cFloater); @@ -43,4 +43,4 @@ protected: // Entity IDs int m_PlayerID; int m_AttachedMobID; -} ; // tolua_export +} ; // tolua_export diff --git a/src/Entities/GhastFireballEntity.h b/src/Entities/GhastFireballEntity.h index 9e4572c78..fa59fa642 100644 --- a/src/Entities/GhastFireballEntity.h +++ b/src/Entities/GhastFireballEntity.h @@ -35,4 +35,4 @@ protected: // TODO: Deflecting the fireballs by arrow- or sword- hits -} ; // tolua_export +} ; // tolua_export diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp index 41ac86268..32d2b226d 100644 --- a/src/Entities/HangingEntity.cpp +++ b/src/Entities/HangingEntity.cpp @@ -10,7 +10,7 @@ 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) + : cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8) , m_BlockFace(a_BlockFace) { SetMaxHealth(1); @@ -28,14 +28,14 @@ void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle) // 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) { - case BLOCK_FACE_ZP: break; // Initialised to zero + case BLOCK_FACE_ZP: break; // Initialised to zero case BLOCK_FACE_ZM: Dir = 2; break; case BLOCK_FACE_XM: Dir = 1; break; case BLOCK_FACE_XP: Dir = 3; break; default: ASSERT(!"Unhandled block face when trying to spawn item frame!"); return; } - if ((Dir == 0) || (Dir == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180 + if ((Dir == 0) || (Dir == 2)) // Probably a client bug, but two directions are flipped and contrary to the norm, so we do -180 { SetYaw((Dir * 90) - 180); } diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index 4cd707faa..f0b0c8c65 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -10,7 +10,7 @@ cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) - : cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z) + : cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z) , m_Item(E_BLOCK_AIR) , m_Rotation(0) { @@ -43,7 +43,7 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player) } } - GetWorld()->BroadcastEntityMetadata(*this); // Update clients + GetWorld()->BroadcastEntityMetadata(*this); // Update clients } diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 7bd440d6d..d4eadc5d5 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -103,21 +103,7 @@ cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) : void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) { - char SubType = 0; - switch (m_Payload) - { - case mpNone: SubType = 0; break; - case mpChest: SubType = 1; break; - case mpFurnace: SubType = 2; break; - case mpTNT: SubType = 3; break; - case mpHopper: SubType = 5; break; - default: - { - ASSERT(!"Unknown payload, cannot spawn on client"); - return; - } - } - a_ClientHandle.SendSpawnVehicle(*this, 10, SubType); // 10 = Minecarts, SubType = What type of Minecart + a_ClientHandle.SendSpawnVehicle(*this, 10, (char)m_Payload); // 10 = Minecarts a_ClientHandle.SendEntityMetadata(*this); } @@ -127,7 +113,7 @@ void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) { - if (IsDestroyed()) // Mainly to stop detector rails triggering again after minecart is dead + if (IsDestroyed()) // Mainly to stop detector rails triggering again after minecart is dead { return; } @@ -156,8 +142,8 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) if (!IsBlockRail(InsideType)) { - Chunk->GetBlockTypeMeta(RelPosX, PosY + 1, RelPosZ, InsideType, InsideMeta); // When an descending minecart hits a flat rail, it goes through the ground; check for this - if (IsBlockRail(InsideType)) AddPosY(1); // Push cart upwards + Chunk->GetBlockTypeMeta(RelPosX, PosY + 1, RelPosZ, InsideType, InsideMeta); // When an descending minecart hits a flat rail, it goes through the ground; check for this + if (IsBlockRail(InsideType)) AddPosY(1); // Push cart upwards } bool WasDetectorRail = false; @@ -186,12 +172,12 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) default: VERIFY(!"Unhandled rail type despite checking if block was rail!"); break; } - AddPosition(GetSpeed() * (a_Dt / 1000)); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in Entity.cpp + AddPosition(GetSpeed() * (a_Dt / 1000)); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in Entity.cpp } else { // Not on rail, default physics - SetPosY(floor(GetPosY()) + 0.35); // HandlePhysics overrides this if minecart can fall, else, it is to stop ground clipping minecart bottom when off-rail + SetPosY(floor(GetPosY()) + 0.35); // HandlePhysics overrides this if minecart can fall, else, it is to stop ground clipping minecart bottom when off-rail super::HandlePhysics(a_Dt, *Chunk); } @@ -223,18 +209,18 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) switch (a_RailMeta) { - case E_META_RAIL_ZM_ZP: // NORTHSOUTH + case E_META_RAIL_ZM_ZP: // NORTHSOUTH { SetYaw(270); SetPosY(floor(GetPosY()) + 0.55); - SetSpeedY(0); // Don't move vertically as on ground - SetSpeedX(0); // Correct diagonal movement from curved rails + SetSpeedY(0); // Don't move vertically as on ground + SetSpeedX(0); // Correct diagonal movement from curved rails // Execute both the entity and block collision checks bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedZ() != 0) // Don't do anything if cart is stationary + if (GetSpeedZ() != 0) // Don't do anything if cart is stationary { if (GetSpeedZ() > 0) { @@ -249,7 +235,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } break; } - case E_META_RAIL_XM_XP: // EASTWEST + case E_META_RAIL_XM_XP: // EASTWEST { SetYaw(180); SetPosY(floor(GetPosY()) + 0.55); @@ -272,7 +258,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } break; } - case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH + case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH { SetYaw(270); SetSpeedX(0); @@ -280,21 +266,21 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) if (GetSpeedZ() >= 0) { // SpeedZ POSITIVE, going SOUTH - if (GetSpeedZ() <= MAX_SPEED) // Speed limit + if (GetSpeedZ() <= MAX_SPEED) // Speed limit { - AddSpeedZ(0.5); // Speed up - SetSpeedY(-GetSpeedZ()); // Downward movement is negative (0 minus positive numbers is negative) + AddSpeedZ(0.5); // Speed up + SetSpeedY(-GetSpeedZ()); // Downward movement is negative (0 minus positive numbers is negative) } } else { // SpeedZ NEGATIVE, going NORTH - AddSpeedZ(1); // Slow down - SetSpeedY(-GetSpeedZ()); // Upward movement is positive (0 minus negative number is positive number) + AddSpeedZ(1); // Slow down + SetSpeedY(-GetSpeedZ()); // Upward movement is positive (0 minus negative number is positive number) } break; } - case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH + case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH { SetYaw(270); SetSpeedX(0); @@ -302,21 +288,21 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) if (GetSpeedZ() > 0) { // SpeedZ POSITIVE, going SOUTH - AddSpeedZ(-1); // Slow down - SetSpeedY(GetSpeedZ()); // Upward movement positive + AddSpeedZ(-1); // Slow down + SetSpeedY(GetSpeedZ()); // Upward movement positive } else { - if (GetSpeedZ() >= MAX_SPEED_NEGATIVE) // Speed limit + if (GetSpeedZ() >= MAX_SPEED_NEGATIVE) // Speed limit { // SpeedZ NEGATIVE, going NORTH - AddSpeedZ(-0.5); // Speed up - SetSpeedY(GetSpeedZ()); // Downward movement negative + AddSpeedZ(-0.5); // Speed up + SetSpeedY(GetSpeedZ()); // Downward movement negative } } break; } - case E_META_RAIL_ASCEND_XM: // ASCEND EAST + case E_META_RAIL_ASCEND_XM: // ASCEND EAST { SetYaw(180); SetSpeedZ(0); @@ -336,7 +322,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } break; } - case E_META_RAIL_ASCEND_XP: // ASCEND WEST + case E_META_RAIL_ASCEND_XP: // ASCEND WEST { SetYaw(180); SetSpeedZ(0); @@ -356,10 +342,10 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } break; } - case E_META_RAIL_CURVED_ZM_XM: // Ends pointing NORTH and WEST + case E_META_RAIL_CURVED_ZM_XM: // Ends pointing NORTH and WEST { - SetYaw(315); // Set correct rotation server side - SetPosY(floor(GetPosY()) + 0.55); // Levitate dat cart + SetYaw(315); // Set correct rotation server side + SetPosY(floor(GetPosY()) + 0.55); // Levitate dat cart SetSpeedY(0); TestBlockCollision(a_RailMeta); @@ -369,7 +355,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) break; } - case E_META_RAIL_CURVED_ZM_XP: // Curved NORTH EAST + case E_META_RAIL_CURVED_ZM_XP: // Curved NORTH EAST { SetYaw(225); SetPosY(floor(GetPosY()) + 0.55); @@ -380,7 +366,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) break; } - case E_META_RAIL_CURVED_ZP_XM: // Curved SOUTH WEST + case E_META_RAIL_CURVED_ZP_XM: // Curved SOUTH WEST { SetYaw(135); SetPosY(floor(GetPosY()) + 0.55); @@ -391,7 +377,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) break; } - case E_META_RAIL_CURVED_ZP_XP: // Curved SOUTH EAST + case E_META_RAIL_CURVED_ZP_XP: // Curved SOUTH EAST { SetYaw(45); SetPosY(floor(GetPosY()) + 0.55); @@ -404,7 +390,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } default: { - ASSERT(!"Unhandled rail meta!"); // Dun dun DUN! + ASSERT(!"Unhandled rail meta!"); // Dun dun DUN! break; } } @@ -428,7 +414,7 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) switch (a_RailMeta & 0x07) { - case E_META_RAIL_ZM_ZP: // NORTHSOUTH + case E_META_RAIL_ZM_ZP: // NORTHSOUTH { SetYaw(270); SetPosY(floor(GetPosY()) + 0.55); @@ -451,7 +437,7 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) } break; } - case E_META_RAIL_XM_XP: // EASTWEST + case E_META_RAIL_XM_XP: // EASTWEST { SetYaw(180); SetPosY(floor(GetPosY()) + 0.55); @@ -474,7 +460,7 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) } break; } - case E_META_RAIL_ASCEND_XM: // ASCEND EAST + case E_META_RAIL_ASCEND_XM: // ASCEND EAST { SetYaw(180); SetSpeedZ(0); @@ -493,8 +479,8 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) SetSpeedY(-GetSpeedX()); } break; - } - case E_META_RAIL_ASCEND_XP: // ASCEND WEST + } + case E_META_RAIL_ASCEND_XP: // ASCEND WEST { SetYaw(180); SetSpeedZ(0); @@ -513,8 +499,8 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) } } break; - } - case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH + } + case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH { SetYaw(270); SetSpeedX(0); @@ -534,7 +520,7 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) } break; } - case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH + case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH { SetYaw(270); SetSpeedX(0); @@ -787,7 +773,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) } } break; - } + } case E_META_RAIL_CURVED_ZM_XM: case E_META_RAIL_CURVED_ZM_XP: case E_META_RAIL_CURVED_ZP_XM: @@ -883,7 +869,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) } } return true; - } + } case E_META_RAIL_CURVED_ZM_XM: case E_META_RAIL_CURVED_ZM_XP: case E_META_RAIL_CURVED_ZP_XM: @@ -907,7 +893,7 @@ bool cMinecart::DoTakeDamage(TakeDamageInfo & TDI) if ((TDI.Attacker != NULL) && TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative()) { Destroy(); - TDI.FinalDamage = GetMaxHealth(); // Instant hit for creative + TDI.FinalDamage = GetMaxHealth(); // Instant hit for creative SetInvulnerableTicks(0); return super::DoTakeDamage(TDI); // No drops for creative } @@ -980,7 +966,7 @@ void cMinecart::Destroyed() -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cRideableMinecart: cRideableMinecart::cRideableMinecart(double a_X, double a_Y, double a_Z, const cItem & a_Content, int a_Height) : @@ -1023,7 +1009,7 @@ void cRideableMinecart::OnRightClicked(cPlayer & a_Player) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cMinecartWithChest: cMinecartWithChest::cMinecartWithChest(double a_X, double a_Y, double a_Z) : @@ -1056,7 +1042,7 @@ void cMinecartWithChest::OnRightClicked(cPlayer & a_Player) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cMinecartWithFurnace: cMinecartWithFurnace::cMinecartWithFurnace(double a_X, double a_Y, double a_Z) : @@ -1078,12 +1064,12 @@ void cMinecartWithFurnace::OnRightClicked(cPlayer & a_Player) { a_Player.GetInventory().RemoveOneEquippedItem(); } - if (!m_IsFueled) // We don't want to change the direction by right clicking it. + if (!m_IsFueled) // We don't want to change the direction by right clicking it. { AddSpeed(a_Player.GetLookVector().x, 0, a_Player.GetLookVector().z); } m_IsFueled = true; - m_FueledTimeLeft = m_FueledTimeLeft + 600; // The minecart will be active 600 more ticks. + m_FueledTimeLeft = m_FueledTimeLeft + 600; // The minecart will be active 600 more ticks. m_World->BroadcastEntityMetadata(*this); } } @@ -1118,7 +1104,7 @@ void cMinecartWithFurnace::Tick(float a_Dt, cChunk & a_Chunk) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cMinecartWithTNT: cMinecartWithTNT::cMinecartWithTNT(double a_X, double a_Y, double a_Z) : @@ -1132,7 +1118,7 @@ cMinecartWithTNT::cMinecartWithTNT(double a_X, double a_Y, double a_Z) : -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cMinecartWithHopper: cMinecartWithHopper::cMinecartWithHopper(double a_X, double a_Y, double a_Z) : diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index 1e60f091c..c585cfab0 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -23,13 +23,14 @@ class cMinecart : public: CLASS_PROTODEF(cMinecart); + /** Minecart payload, values correspond to packet subtype */ enum ePayload { - mpNone, // Empty minecart, ridable by player or mobs - mpChest, // Minecart-with-chest, can store a grid of 3*8 items - mpFurnace, // Minecart-with-furnace, can be powered - mpTNT, // Minecart-with-TNT, can be blown up with activator rail - mpHopper, // Minecart-with-hopper, can be hopper + mpNone = 0, // Empty minecart, ridable by player or mobs + mpChest = 1, // Minecart-with-chest, can store a grid of 3*8 items + mpFurnace = 2, // Minecart-with-furnace, can be powered + mpTNT = 3, // Minecart-with-TNT, can be blown up with activator rail + mpHopper = 5, // Minecart-with-hopper, can be hopper // TODO: Spawner minecarts, (and possibly any block in a minecart with NBT editing) } ; @@ -99,7 +100,7 @@ public: protected: cItem m_Content; - int m_Height; + int m_Height; } ; diff --git a/src/Entities/Painting.h b/src/Entities/Painting.h index 30af6d412..ce7c6f3de 100644 --- a/src/Entities/Painting.h +++ b/src/Entities/Painting.h @@ -18,8 +18,8 @@ public: 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 + const AString & GetName(void) const { return m_Name; } // tolua_export + int GetDirection(void) const { return m_Direction; } // tolua_export private: diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index bae1485d4..aab534f41 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -85,7 +85,7 @@ protected: cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) - : cEntity(etPickup, a_PosX, a_PosY, a_PosZ, 0.2, 0.2) + : cEntity(etPickup, a_PosX, a_PosY, a_PosZ, 0.2, 0.2) , m_Timer(0.f) , m_Item(a_Item) , m_bCollected(false) @@ -113,7 +113,7 @@ void cPickup::SpawnOn(cClientHandle & a_Client) void cPickup::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - BroadcastMovementUpdate(); //Notify clients of position + BroadcastMovementUpdate(); // Notify clients of position m_Timer += a_Dt; @@ -143,17 +143,17 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk) m_bCollected = true; m_Timer = 0; // We have to reset the timer. m_Timer += a_Dt; // In case we have to destroy the pickup in the same tick. - if (m_Timer > 500.f) + if (m_Timer > 500.f) { Destroy(true); return; } } - if (!IsDestroyed() && (m_Item.m_ItemCount < m_Item.GetMaxStackSize())) // Don't combine into an already full pickup + if (!IsDestroyed() && (m_Item.m_ItemCount < m_Item.GetMaxStackSize())) // Don't combine into an already full pickup { cPickupCombiningCallback PickupCombiningCallback(GetPosition(), this); - m_World->ForEachEntity(PickupCombiningCallback); // Not ForEachEntityInChunk, otherwise pickups don't combine across chunk boundaries + m_World->ForEachEntity(PickupCombiningCallback); // Not ForEachEntityInChunk, otherwise pickups don't combine across chunk boundaries if (PickupCombiningCallback.FoundMatchingPickup()) { m_World->BroadcastEntityMetadata(*this); @@ -176,7 +176,7 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk) return; } - if (GetPosY() < VOID_BOUNDARY) // Out of this world and no more visible! + if (GetPosY() < VOID_BOUNDARY) // Out of this world and no more visible! { Destroy(true); return; @@ -194,14 +194,14 @@ bool cPickup::CollectedBy(cPlayer * a_Dest) if (m_bCollected) { // LOG("Pickup %d cannot be collected by \"%s\", because it has already been collected.", m_UniqueID, a_Dest->GetName().c_str()); - return false; // It's already collected! + return false; // It's already collected! } // Two seconds if player created the pickup (vomiting), half a second if anything else if (m_Timer < (m_bIsPlayerCreated ? 2000.f : 500.f)) { // LOG("Pickup %d cannot be collected by \"%s\", because it is not old enough.", m_UniqueID, a_Dest->GetName().c_str()); - return false; // Not old enough + return false; // Not old enough } if (cRoot::Get()->GetPluginManager()->CallHookCollectingPickup(a_Dest, *this)) diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h index 2dcbecaaf..d7c5d2b26 100644 --- a/src/Entities/Pickup.h +++ b/src/Entities/Pickup.h @@ -27,12 +27,12 @@ public: cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); - cItem & GetItem(void) {return m_Item; } // tolua_export + cItem & GetItem(void) {return m_Item; } // tolua_export const cItem & GetItem(void) const {return m_Item; } virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - bool CollectedBy(cPlayer * a_Dest); // tolua_export + bool CollectedBy(cPlayer * a_Dest); // tolua_export virtual void Tick(float a_Dt, cChunk & a_Chunk) override; @@ -46,7 +46,7 @@ public: bool IsCollected(void) const { return m_bCollected; } // tolua_export /** Returns true if created by player (i.e. vomiting), used for determining picking-up delay time */ - bool IsPlayerCreated(void) const { return m_bIsPlayerCreated; } // tolua_export + bool IsPlayerCreated(void) const { return m_bIsPlayerCreated; } // tolua_export private: diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index da50843b6..698f77bf6 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Player.h" +#include "../ChatColor.h" #include "../Server.h" #include "../UI/Window.h" #include "../UI/WindowOwner.h" @@ -223,7 +224,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) SendExperience(); } - if (!GetPosition().EqualsEps(m_LastPos, 0.01)) // Non negligible change in position from last tick? + if (!GetPosition().EqualsEps(m_LastPos, 0.01)) // Non negligible change in position from last tick? { // Apply food exhaustion from movement: ApplyFoodExhaustionFromMovement(); @@ -284,19 +285,19 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) short cPlayer::CalcLevelFromXp(short a_XpTotal) { - //level 0 to 15 + // level 0 to 15 if(a_XpTotal <= XP_TO_LEVEL15) { return a_XpTotal / XP_PER_LEVEL_TO15; } - //level 30+ + // level 30+ if(a_XpTotal > XP_TO_LEVEL30) { return (short) (151.5 + sqrt( 22952.25 - (14 * (2220 - a_XpTotal)))) / 7; } - //level 16 to 30 + // level 16 to 30 return (short) ( 29.5 + sqrt( 870.25 - (6 * ( 360 - a_XpTotal )))) / 3; } @@ -306,19 +307,19 @@ short cPlayer::CalcLevelFromXp(short a_XpTotal) short cPlayer::XpForLevel(short a_Level) { - //level 0 to 15 + // level 0 to 15 if(a_Level <= 15) { return a_Level * XP_PER_LEVEL_TO15; } - //level 30+ + // level 30+ if(a_Level >= 31) { return (short) ( (3.5 * a_Level * a_Level) - (151.5 * a_Level) + 2220 ); } - //level 16 to 30 + // level 16 to 30 return (short) ( (1.5 * a_Level * a_Level) - (29.5 * a_Level) + 360 ); } @@ -340,7 +341,7 @@ float cPlayer::GetXpPercentage() short int currentLevel = CalcLevelFromXp(m_CurrentXp); short int currentLevel_XpBase = XpForLevel(currentLevel); - return (float)(m_CurrentXp - currentLevel_XpBase) / + return (float)(m_CurrentXp - currentLevel_XpBase) / (float)(XpForLevel(1+currentLevel) - currentLevel_XpBase); } @@ -353,7 +354,7 @@ bool cPlayer::SetCurrentExperience(short int a_CurrentXp) if(!(a_CurrentXp >= 0) || (a_CurrentXp > (SHRT_MAX - m_LifetimeTotalXp))) { LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_CurrentXp); - return false; //oops, they gave us a dodgey number + return false; // oops, they gave us a dodgey number } m_CurrentXp = a_CurrentXp; @@ -375,16 +376,13 @@ short cPlayer::DeltaExperience(short a_Xp_delta) // Value was bad, abort and report LOGWARNING("Attempt was made to increment Xp by %d, which overflowed the short datatype. Ignoring.", a_Xp_delta); - return -1; // Should we instead just return the current Xp? + return -1; // Should we instead just return the current Xp? } m_CurrentXp += a_Xp_delta; // Make sure they didn't subtract too much - if (m_CurrentXp < 0) - { - m_CurrentXp = 0; - } + m_CurrentXp = std::max<short int>(m_CurrentXp, 0); // Update total for score calculation if (a_Xp_delta > 0) @@ -392,7 +390,7 @@ short cPlayer::DeltaExperience(short a_Xp_delta) m_LifetimeTotalXp += a_Xp_delta; } - LOGD("Player \"%s\" gained/lost %d experience, total is now: %d", + LOGD("Player \"%s\" gained/lost %d experience, total is now: %d", GetName().c_str(), a_Xp_delta, m_CurrentXp); // Set experience to be updated @@ -477,7 +475,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) { float Dist = (float)(m_LastGroundHeight - floor(GetPosY())); - if (Dist >= 2.0) // At least two blocks - TODO: Use m_LastJumpHeight instead of m_LastGroundHeight above + if (Dist >= 2.0) // At least two blocks - TODO: Use m_LastJumpHeight instead of m_LastGroundHeight above { // Increment statistic m_Stats.AddValue(statDistFallen, (StatValue)floor(Dist * 100 + 0.5)); @@ -497,7 +495,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) // Fall particles GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, (int)GetPosY() - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */); - } + } m_LastGroundHeight = (float)GetPosY(); } @@ -580,7 +578,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) void cPlayer::FoodPoison(int a_NumTicks) { - AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0, NULL); + AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0, 1); } @@ -623,8 +621,9 @@ void cPlayer::FinishEating(void) GetInventory().RemoveOneEquippedItem(); - //if the food is mushroom soup, return a bowl to the inventory - if( Item.m_ItemType == E_ITEM_MUSHROOM_SOUP ) { + // if the food is mushroom soup, return a bowl to the inventory + if (Item.m_ItemType == E_ITEM_MUSHROOM_SOUP) + { cItem emptyBowl(E_ITEM_BOWL, 1, 0, ""); GetInventory().AddItem(emptyBowl, true, true); } @@ -871,10 +870,10 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI) if (m_Health > 0) { - return; // not dead yet =] + return; // not dead yet =] } - m_bVisible = false; // So new clients don't see the player + m_bVisible = false; // So new clients don't see the player // Puke out all the items cItems Pickups; @@ -905,6 +904,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI) case dtCactusContact: DamageText = "was impaled on a cactus"; break; case dtLavaContact: DamageText = "was melted by lava"; break; case dtPoisoning: DamageText = "died from septicaemia"; break; + case dtWithering: DamageText = "is a husk of their former selves"; break; case dtOnFire: DamageText = "forgot to stop, drop, and roll"; break; case dtFireContact: DamageText = "burnt themselves to death"; break; case dtInVoid: DamageText = "somehow fell out of the world"; break; @@ -925,7 +925,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI) else { AString KillerClass = a_TDI.Attacker->GetClass(); - KillerClass.erase(KillerClass.begin()); // Erase the 'c' of the class (e.g. "cWitch" -> "Witch") + KillerClass.erase(KillerClass.begin()); // Erase the 'c' of the class (e.g. "cWitch" -> "Witch") GetWorld()->BroadcastChatDeath(Printf("%s was killed by a %s", GetName().c_str(), KillerClass.c_str())); } @@ -1278,7 +1278,7 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const // TODO: Add a slight random change (+-0.0075 in each direction) return res * a_SpeedCoeff; -} +} @@ -1311,7 +1311,7 @@ void cPlayer::MoveTo( const Vector3d & a_NewPos ) { // When attached to an entity, the client sends position packets with weird coords: // 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 + // 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) { @@ -1338,7 +1338,7 @@ void cPlayer::MoveTo( const Vector3d & a_NewPos ) void cPlayer::SetVisible(bool a_bVisible) { - if (a_bVisible && !m_bVisible) // Make visible + if (a_bVisible && !m_bVisible) // Make visible { m_bVisible = true; m_World->BroadcastSpawnEntity(*this); @@ -1346,7 +1346,7 @@ void cPlayer::SetVisible(bool a_bVisible) if (!a_bVisible && m_bVisible) { m_bVisible = false; - m_World->BroadcastDestroyEntity(*this, m_ClientHandle); // Destroy on all clients + m_World->BroadcastDestroyEntity(*this, m_ClientHandle); // Destroy on all clients } } @@ -1420,7 +1420,7 @@ bool cPlayer::HasPermission(const AString & a_Permission) { if( OtherSplit[i].compare( Split[i] ) != 0 ) { - if( OtherSplit[i].compare("*") == 0 ) return true; // WildCard man!! WildCard! + if( OtherSplit[i].compare("*") == 0 ) return true; // WildCard man!! WildCard! break; } } @@ -1454,7 +1454,7 @@ bool cPlayer::IsInGroup( const AString & a_Group ) void cPlayer::ResolvePermissions() { - m_ResolvedPermissions.clear(); // Start with an empty map yo~ + m_ResolvedPermissions.clear(); // Start with an empty map // Copy all player specific permissions into the resolved permissions map for( PermissionMap::iterator itr = m_Permissions.begin(); itr != m_Permissions.end(); ++itr ) @@ -1482,7 +1482,7 @@ void cPlayer::ResolveGroups() m_ResolvedGroups.clear(); // Get a complete resolved list of all groups the player is in - std::map< cGroup*, bool > AllGroups; // Use a map, because it's faster than iterating through a list to find duplicates + std::map< cGroup*, bool > AllGroups; // Use a map, because it's faster than iterating through a list to find duplicates GroupList ToIterate; for( GroupList::iterator GroupItr = m_Groups.begin(); GroupItr != m_Groups.end(); ++GroupItr ) { @@ -1500,7 +1500,7 @@ void cPlayer::ResolveGroups() else { AllGroups[ CurrentGroup ] = true; - m_ResolvedGroups.push_back( CurrentGroup ); // Add group to resolved list + m_ResolvedGroups.push_back( CurrentGroup ); // Add group to resolved list const cGroup::GroupList & Inherits = CurrentGroup->GetInherits(); for( cGroup::GroupList::const_iterator itr = Inherits.begin(); itr != Inherits.end(); ++itr ) { @@ -1548,7 +1548,7 @@ void cPlayer::TossEquippedItem(char a_Amount) char NewAmount = a_Amount; if (NewAmount > GetInventory().GetEquippedItem().m_ItemCount) { - NewAmount = GetInventory().GetEquippedItem().m_ItemCount; // Drop only what's there + NewAmount = GetInventory().GetEquippedItem().m_ItemCount; // Drop only what's there } GetInventory().GetHotbarGrid().ChangeSlotCount(GetInventory().GetEquippedSlotNum() /* Returns hotbar subslot, which HotbarGrid takes */, -a_Amount); @@ -1610,7 +1610,7 @@ void cPlayer::TossItems(const cItems & a_Items) double vX = 0, vY = 0, vZ = 0; EulerToVector(-GetYaw(), GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; - m_World->SpawnItemPickups(a_Items, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player + m_World->SpawnItemPickups(a_Items, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player } @@ -1889,7 +1889,7 @@ bool cPlayer::SaveToDisk() { LOGWARNING("Error writing player \"%s\" to file \"%s\" - cannot save data. Player will lose their progress. ", GetName().c_str(), SourceFile.c_str() - ); + ); return false; } @@ -1931,7 +1931,7 @@ cPlayer::StringList cPlayer::GetResolvedPermissions() void cPlayer::UseEquippedItem(void) { - if (IsGameModeCreative()) // No damage in creative + if (IsGameModeCreative()) // No damage in creative { return; } @@ -2074,7 +2074,7 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos) { if (IsClimbing()) { - if (a_DeltaPos.y > 0.0) // Going up + if (a_DeltaPos.y > 0.0) // Going up { m_Stats.AddValue(statDistClimbed, (StatValue)floor(a_DeltaPos.y * 100 + 0.5)); } @@ -2093,7 +2093,7 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos) } else { - if (Value >= 25) // Ignore small/slow movement + if (Value >= 25) // Ignore small/slow movement { m_Stats.AddValue(statDistFlown, Value); } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 793f11e57..7c287d41b 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -119,11 +119,11 @@ public: void SetTouchGround( bool a_bTouchGround ); inline void SetStance( const double a_Stance ) { m_Stance = a_Stance; } - double GetEyeHeight(void) const; // tolua_export - Vector3d GetEyePosition(void) const; // tolua_export + double GetEyeHeight(void) const; // tolua_export + Vector3d GetEyePosition(void) const; // tolua_export inline bool IsOnGround(void) const {return m_bTouchGround; } // tolua_export inline double GetStance(void) const { return GetPosY() + 1.62; } // tolua_export // TODO: Proper stance when crouching etc. - inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export + inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export inline const cInventory & GetInventory(void) const { return m_Inventory; } /** Gets the contents of the player's associated enderchest */ @@ -174,7 +174,7 @@ public: AString GetIP(void) const { return m_IP; } // tolua_export /** Returns the associated team, NULL if none */ - cTeam * GetTeam(void) { return m_Team; } // tolua_export + cTeam * GetTeam(void) { return m_Team; } // tolua_export /** Sets the player team, NULL if none */ void SetTeam(cTeam * a_Team); @@ -198,9 +198,9 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); - /** Forces the player to move in the given direction. + /** Forces the player to move in the given direction. @deprecated Use SetSpeed instead. */ - void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export + void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export /** Tries to move to a new position, with attachment-related checks (y == -999) */ void MoveTo(const Vector3d & a_NewPos); // tolua_export @@ -239,15 +239,15 @@ public: typedef std::list< std::string > StringList; /** Adds a player to existing group or creates a new group when it doesn't exist */ - void AddToGroup( const AString & a_GroupName ); // tolua_export + void AddToGroup( const AString & a_GroupName ); // tolua_export /** Removes a player from the group, resolves permissions and group inheritance (case sensitive) */ - void RemoveFromGroup( const AString & a_GroupName ); // tolua_export + void RemoveFromGroup( const AString & a_GroupName ); // tolua_export - bool HasPermission( const AString & a_Permission ); // tolua_export - const GroupList & GetGroups() { return m_Groups; } // >> EXPORTED IN MANUALBINDINGS << - StringList GetResolvedPermissions(); // >> EXPORTED IN MANUALBINDINGS << - bool IsInGroup( const AString & a_Group ); // tolua_export + bool HasPermission( const AString & a_Permission ); // tolua_export + const GroupList & GetGroups() { return m_Groups; } // >> EXPORTED IN MANUALBINDINGS << + StringList GetResolvedPermissions(); // >> EXPORTED IN MANUALBINDINGS << + bool IsInGroup( const AString & a_Group ); // tolua_export // tolua_begin @@ -326,10 +326,10 @@ public: virtual void Killed(cEntity * a_Victim) override; - void Respawn(void); // tolua_export + void Respawn(void); // tolua_export - void SetVisible( bool a_bVisible ); // tolua_export - bool IsVisible(void) const { return m_bVisible; } // tolua_export + void SetVisible( bool a_bVisible ); // tolua_export + bool IsVisible(void) const { return m_bVisible; } // tolua_export /** Moves the player to the specified world. Returns true if successful, false on failure (world not found). */ @@ -345,7 +345,7 @@ public: Returns true on success, false on failure. */ bool LoadFromFile(const AString & a_FileName); - void LoadPermissionsFromDisk(void); // tolua_export + void LoadPermissionsFromDisk(void); // tolua_export const AString & GetLoadedWorldName() { return m_LoadedWorldName; } @@ -430,7 +430,7 @@ protected: AString m_LoadedWorldName; /** Xp Level stuff */ - enum + enum { XP_TO_LEVEL15 = 255, XP_PER_LEVEL_TO15 = 17, @@ -570,7 +570,7 @@ protected: /** Returns the filename for the player data based on the UUID given. This can be used both for online and offline UUIDs. */ AString GetUUIDFileName(const AString & a_UUID); -} ; // tolua_export +} ; // tolua_export diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 019ebeaa5..b5e81bc0c 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -35,7 +35,7 @@ -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cProjectileTracerCallback: class cProjectileTracerCallback : @@ -122,7 +122,7 @@ protected: -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cProjectileEntityCollisionCallback: class cProjectileEntityCollisionCallback : @@ -146,9 +146,11 @@ public: (a_Entity->GetUniqueID() == m_Projectile->GetCreatorUniqueID()) // Do not check whoever shot the projectile ) { - // TODO: Don't check creator only for the first 5 ticks - // so that arrows stuck in ground and dug up can hurt the player - return false; + // Don't check creator only for the first 5 ticks so that projectiles can collide with the creator + if (m_Projectile->GetTicksAlive() <= 5) + { + return false; + } } cBoundingBox EntBox(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight()); @@ -211,7 +213,7 @@ protected: -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cProjectileEntity: cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, double a_Width, double a_Height) : diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 14cee1272..e6b05714e 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -52,7 +52,7 @@ public: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace); /// Called by the physics blocktracer when the entity hits another entity - virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) + virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { UNUSED(a_EntityHit); UNUSED(a_HitPos); @@ -89,7 +89,7 @@ public: protected: - /** A structure that stores the Entity ID and Playername of the projectile's creator + /** A structure that stores the Entity ID and Playername of the projectile's creator Used to migitate invalid pointers caused by the creator being destroyed */ struct CreatorData @@ -120,4 +120,4 @@ protected: virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; virtual void SpawnOn(cClientHandle & a_Client) override; -} ; // tolua_export +} ; // tolua_export diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index ed5afaf11..c1623845f 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -2,12 +2,16 @@ #include "SplashPotionEntity.h" #include "Pawn.h" +#include "../ClientHandle.h" -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/// Converts an angle in radians into a byte representation used by the network protocol +#define ANGLE_TO_PROTO(X) (Byte)(X * 255 / 360) + +//////////////////////////////////////////////////////////////////////////////// // cSplashPotionEntityCallback: /** Used to distribute the splashed potion effect among nearby entities */ @@ -44,10 +48,7 @@ public: // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash. // TODO: better equation double Reduction = -0.25 * SplashDistance + 1.0; - if (Reduction < 0) - { - Reduction = 0; - } + Reduction = std::max(Reduction, 0.0); ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction); return false; @@ -63,7 +64,7 @@ private: -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cSplashPotionEntity: cSplashPotionEntity::cSplashPotionEntity( @@ -72,12 +73,13 @@ cSplashPotionEntity::cSplashPotionEntity( const Vector3d & a_Speed, cEntityEffect::eType a_EntityEffectType, cEntityEffect a_EntityEffect, - int a_PotionParticleType + int a_PotionColor ) : super(pkSplashPotion, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), m_EntityEffectType(a_EntityEffectType), m_EntityEffect(a_EntityEffect), - m_PotionParticleType(a_PotionParticleType) + m_PotionColor(a_PotionColor), + m_DestroyTimer(-1) { SetSpeed(a_Speed); } @@ -89,7 +91,7 @@ cSplashPotionEntity::cSplashPotionEntity( void cSplashPotionEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { Splash(a_HitPos); - Destroy(); + m_DestroyTimer = 2; } @@ -100,7 +102,7 @@ void cSplashPotionEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_ { a_EntityHit.TakeDamage(dtRangedAttack, this, 0, 1); Splash(a_HitPos); - Destroy(true); + m_DestroyTimer = 5; } @@ -112,7 +114,17 @@ void cSplashPotionEntity::Splash(const Vector3d & a_HitPos) cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect); m_World->ForEachEntity(Callback); - m_World->BroadcastSoundParticleEffect(2002, (int)a_HitPos.x, (int)a_HitPos.y, (int)a_HitPos.z, m_PotionParticleType); + m_World->BroadcastSoundParticleEffect(2002, (int)a_HitPos.x, (int)a_HitPos.y, (int)a_HitPos.z, m_PotionColor); +} + + + + + +void cSplashPotionEntity::SpawnOn(cClientHandle & a_Client) +{ + a_Client.SendSpawnObject(*this, 73, m_PotionColor, ANGLE_TO_PROTO(GetYaw()), ANGLE_TO_PROTO(GetPitch())); + a_Client.SendEntityMetadata(*this); } diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h index 076e477da..290dd81d4 100644 --- a/src/Entities/SplashPotionEntity.h +++ b/src/Entities/SplashPotionEntity.h @@ -31,29 +31,51 @@ public: const Vector3d & a_Speed, cEntityEffect::eType a_EntityEffectType, cEntityEffect a_EntityEffect, - int a_PotionParticleType + int a_PotionColor ); - cEntityEffect::eType GetEntityEffectType (void) const { return m_EntityEffectType; } - cEntityEffect GetEntityEffect (void) const { return m_EntityEffect; } - int GetPotionParticleType(void) const { return m_PotionParticleType; } + cEntityEffect::eType GetEntityEffectType(void) const { return m_EntityEffectType; } + cEntityEffect GetEntityEffect(void) const { return m_EntityEffect; } + int GetPotionColor(void) const { return m_PotionColor; } void SetEntityEffectType(cEntityEffect::eType a_EntityEffectType) { m_EntityEffectType = a_EntityEffectType; } void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; } - void SetPotionParticleType(int a_PotionParticleType) { m_PotionParticleType = a_PotionParticleType; } + void SetPotionColor(int a_PotionColor) { m_PotionColor = a_PotionColor; } protected: cEntityEffect::eType m_EntityEffectType; cEntityEffect m_EntityEffect; - int m_PotionParticleType; + int m_PotionColor; // 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); + } + } /** Splashes the potion, fires its particle effects and sounds @param a_HitPos The position where the potion will splash */ void Splash(const Vector3d & a_HitPos); -} ; // tolua_export + + virtual void SpawnOn(cClientHandle & a_Client) override; + +private: + /** Time in ticks to wait for the hit animation to begin before destroying */ + int m_DestroyTimer; +} ; // tolua_export diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp index fd9a4e7ac..53af446cc 100644 --- a/src/Entities/TNTEntity.cpp +++ b/src/Entities/TNTEntity.cpp @@ -42,7 +42,7 @@ void cTNTEntity::Explode(void) { m_FuseTicks = 0; Destroy(true); - LOGD("BOOM at {%f,%f,%f}", GetPosX(), GetPosY(), GetPosZ()); + LOGD("BOOM at {%f, %f, %f}", GetPosX(), GetPosY(), GetPosZ()); m_World->DoExplosionAt(4.0, GetPosX() + 0.49, GetPosY() + 0.49, GetPosZ() + 0.49, true, esPrimedTNT, this); } diff --git a/src/Entities/TNTEntity.h b/src/Entities/TNTEntity.h index 116f5a8cb..df61b14f5 100644 --- a/src/Entities/TNTEntity.h +++ b/src/Entities/TNTEntity.h @@ -38,7 +38,7 @@ public: protected: int m_FuseTicks; ///< How much ticks is left, while the tnt will explode -}; // tolua_export +}; // tolua_export diff --git a/src/Entities/ThrownEggEntity.h b/src/Entities/ThrownEggEntity.h index dc72c279f..f93731256 100644 --- a/src/Entities/ThrownEggEntity.h +++ b/src/Entities/ThrownEggEntity.h @@ -55,4 +55,4 @@ private: /** Time in ticks to wait for the hit animation to begin before destroying */ int m_DestroyTimer; -} ; // tolua_export +} ; // tolua_export diff --git a/src/Entities/ThrownEnderPearlEntity.h b/src/Entities/ThrownEnderPearlEntity.h index 1cea5f7d9..549d8a3eb 100644 --- a/src/Entities/ThrownEnderPearlEntity.h +++ b/src/Entities/ThrownEnderPearlEntity.h @@ -55,4 +55,4 @@ private: /** Time in ticks to wait for the hit animation to begin before destroying */ int m_DestroyTimer; -} ; // tolua_export +} ; // tolua_export diff --git a/src/Entities/ThrownSnowballEntity.h b/src/Entities/ThrownSnowballEntity.h index 9a8770379..6f3efdd7e 100644 --- a/src/Entities/ThrownSnowballEntity.h +++ b/src/Entities/ThrownSnowballEntity.h @@ -52,4 +52,4 @@ private: /** Time in ticks to wait for the hit animation to begin before destroying */ int m_DestroyTimer; -} ; // tolua_export +} ; // tolua_export diff --git a/src/Entities/WitherSkullEntity.h b/src/Entities/WitherSkullEntity.h index 8b3639802..ebc1550e3 100644 --- a/src/Entities/WitherSkullEntity.h +++ b/src/Entities/WitherSkullEntity.h @@ -32,4 +32,4 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; -} ; // tolua_export +} ; // tolua_export |