From e304bd08a2363f43bf845b2b370c18a60d1b66d1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 3 Apr 2014 21:44:03 +0200 Subject: Documented the units and range for entity rotations. --- src/Entities/Entity.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index e41f74b09..6e3f8292b 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -159,7 +159,7 @@ public: cWorld * GetWorld(void) const { return m_World; } - double GetHeadYaw (void) const { return m_HeadYaw; } + double GetHeadYaw (void) const { return m_HeadYaw; } // In degrees double GetHeight (void) const { return m_Height; } double GetMass (void) const { return m_Mass; } const Vector3d & GetPosition (void) const { return m_Pos; } @@ -167,9 +167,9 @@ public: double GetPosY (void) const { return m_Pos.y; } double GetPosZ (void) const { return m_Pos.z; } const Vector3d & GetRot (void) const { return m_Rot; } // OBSOLETE, use individual GetYaw(), GetPitch, GetRoll() components - double GetYaw (void) const { return m_Rot.x; } - double GetPitch (void) const { return m_Rot.y; } - double GetRoll (void) const { return m_Rot.z; } + double GetYaw (void) const { return m_Rot.x; } // In degrees, [-180, +180) + double GetPitch (void) const { return m_Rot.y; } // In degrees, [-180, +180), but normal client clips to [-90, +90] + double GetRoll (void) const { return m_Rot.z; } // In degrees, unused in current client Vector3d GetLookVector(void) const; const Vector3d & GetSpeed (void) const { return m_Speed; } double GetSpeedX (void) const { return m_Speed.x; } @@ -189,9 +189,9 @@ public: void SetPosition(double a_PosX, double a_PosY, double a_PosZ); void SetPosition(const Vector3d & a_Pos) { SetPosition(a_Pos.x, a_Pos.y, a_Pos.z); } void SetRot (const Vector3f & a_Rot); // OBSOLETE, use individual SetYaw(), SetPitch(), SetRoll() components - void SetYaw (double a_Yaw); - void SetPitch (double a_Pitch); - void SetRoll (double a_Roll); + void SetYaw (double a_Yaw); // In degrees, normalizes to [-180, +180) + void SetPitch (double a_Pitch); // In degrees, normalizes to [-180, +180) + void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180) void SetSpeed (double a_SpeedX, double a_SpeedY, double a_SpeedZ); void SetSpeed (const Vector3d & a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); } void SetSpeedX (double a_SpeedX); -- cgit v1.2.3 From 1cab52f86799b98940da910e84e207b6037a5cd2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 23:06:47 +0200 Subject: Added cPlayer:SendRotation() API function. --- src/Entities/Player.cpp | 11 +++++++++++ src/Entities/Player.h | 6 ++++++ 2 files changed, 17 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 646aad50f..7f2e5b4c2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1124,6 +1124,17 @@ void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) +void cPlayer::SendRotation(double a_YawDegrees, double a_PitchDegrees) +{ + SetYaw(a_YawDegrees); + SetPitch(a_PitchDegrees); + m_ClientHandle->SendPlayerMoveLook(); +} + + + + + Vector3d cPlayer::GetThrowStartPos(void) const { Vector3d res = GetEyePosition(); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index ea32dbfb9..05377a117 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -129,6 +129,12 @@ public: // tolua_begin + /** Sends the "look" packet to the player, forcing them to set their rotation to the specified values. + a_YawDegrees is clipped to range [-180, +180), + a_PitchDegrees is clipped to range [-180, +180) but the client only uses [-90, +90] + */ + void SendRotation(double a_YawDegrees, double a_PitchDegrees); + /** Returns the position where projectiles thrown by this player should start, player eye position + adjustment */ Vector3d GetThrowStartPos(void) const; -- cgit v1.2.3 From d43c5a9c474bd6e4fbd74f09cca9b9bdbbd88b71 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 5 Apr 2014 22:25:40 +0200 Subject: Removed debugging log from entity physics handling. --- src/Entities/ProjectileEntity.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index a9735a53c..e86bb48bd 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -371,13 +371,14 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) SetYawFromSpeed(); SetPitchFromSpeed(); - // DEBUG: + /* LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}, rot {%.02f, %.02f}", m_UniqueID, GetPosX(), GetPosY(), GetPosZ(), GetSpeedX(), GetSpeedY(), GetSpeedZ(), GetYaw(), GetPitch() ); + */ } -- cgit v1.2.3 From 143a5e61fc8e704f3df776d089217f031bc47779 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 5 Apr 2014 22:34:05 +0200 Subject: Fixed Endiannes conversion routines for floats and doubles. This bug has been introduced in 8825d30aabbee8cb2e452dc5a17deb6f9b6892a7. This change fixes #854. --- src/Entities/Entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 221cbbea7..8ef45f1a5 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1469,7 +1469,7 @@ void cEntity::SteerVehicle(float a_Forward, float a_Sideways) Vector3d cEntity::GetLookVector(void) const { Matrix4d m; - m.Init(Vector3f(), 0, m_Rot.x, -m_Rot.y); + m.Init(Vector3d(), 0, m_Rot.x, -m_Rot.y); Vector3d Look = m.Transform(Vector3d(0, 0, 1)); return Look; } -- cgit v1.2.3 From c0c47d33c571bde4cfb45043b645b3d45c3223e6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 12 Apr 2014 13:16:48 +0100 Subject: Entities handle chunks properly again * Entities properly handle chunks * Changed EntityStatus enums to be less shouty --- src/Entities/Entity.cpp | 115 ++++++++++++++++---------------------- src/Entities/Entity.h | 51 ++++++++++++----- src/Entities/Pickup.cpp | 63 ++++++++++----------- src/Entities/Pickup.h | 3 - src/Entities/Player.cpp | 2 +- src/Entities/ProjectileEntity.cpp | 2 +- 6 files changed, 118 insertions(+), 118 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 8ef45f1a5..aa07527d0 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -330,7 +330,7 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) AddSpeed(a_TDI.Knockback * 2); } - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT); + m_World->BroadcastEntityStatus(*this, esGenericHurt); if (m_Health <= 0) { @@ -479,7 +479,7 @@ void cEntity::KilledBy(cEntity * a_Killer) GetDrops(Drops, a_Killer); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ()); - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_DEAD); + m_World->BroadcastEntityStatus(*this, esGenericDead); } @@ -519,37 +519,36 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) } else { - if (a_Chunk.IsValid()) + if (!a_Chunk.IsValid()) { - cChunk * NextChunk = a_Chunk.GetNeighborChunk(POSX_TOINT, POSZ_TOINT); + return; + } - if ((NextChunk == NULL) || !NextChunk->IsValid()) - { - return; - } + // Position changed -> super::Tick() called + GET_AND_VERIFY_CURRENT_CHUNK(NextChunk, POSX_TOINT, POSZ_TOINT) - TickBurning(*NextChunk); + TickBurning(*NextChunk); - if (GetPosY() < VOID_BOUNDARY) - { - TickInVoid(*NextChunk); - } - else - { - m_TicksSinceLastVoidDamage = 0; - } - - if (IsMob() || IsPlayer()) - { - // Set swimming state - SetSwimState(*NextChunk); + if (GetPosY() < VOID_BOUNDARY) + { + TickInVoid(*NextChunk); + } + else + { + m_TicksSinceLastVoidDamage = 0; + } - // Handle drowning - HandleAir(); - } + if (IsMob() || IsPlayer()) + { + // Set swimming state + SetSwimState(*NextChunk); - HandlePhysics(a_Dt, *NextChunk); + // Handle drowning + HandleAir(); } + + // None of the above functions change position, we remain in the chunk of NextChunk + HandlePhysics(a_Dt, *NextChunk); } } @@ -559,34 +558,30 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { + int BlockX = POSX_TOINT; + int BlockY = POSY_TOINT; + int BlockZ = POSZ_TOINT; + + // Position changed -> super::HandlePhysics() called + GET_AND_VERIFY_CURRENT_CHUNK(NextChunk, BlockX, BlockZ) + // TODO Add collision detection with entities. a_Dt /= 1000; // Convert from msec to sec - Vector3d NextPos = Vector3d(GetPosX(),GetPosY(),GetPosZ()); - Vector3d NextSpeed = Vector3d(GetSpeedX(),GetSpeedY(),GetSpeedZ()); - int BlockX = (int) floor(NextPos.x); - int BlockY = (int) floor(NextPos.y); - int BlockZ = (int) floor(NextPos.z); + Vector3d NextPos = Vector3d(GetPosX(), GetPosY(), GetPosZ()); + Vector3d NextSpeed = Vector3d(GetSpeedX(), GetSpeedY(), GetSpeedZ()); if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) { - // Outside of the world - - cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); - // See if we can commit our changes. If not, we will discard them. - if (NextChunk != NULL) - { - SetSpeed(NextSpeed); - NextPos += (NextSpeed * a_Dt); - SetPosition(NextPos); - } - + // Outside of the world + AddSpeedY(m_Gravity * a_Dt); + AddPosition(GetSpeed() * a_Dt); return; } - int RelBlockX = BlockX - (a_Chunk.GetPosX() * cChunkDef::Width); - int RelBlockZ = BlockZ - (a_Chunk.GetPosZ() * cChunkDef::Width); - BLOCKTYPE BlockIn = a_Chunk.GetBlock( RelBlockX, BlockY, RelBlockZ ); - BLOCKTYPE BlockBelow = (BlockY > 0) ? a_Chunk.GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; + int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width); + int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); + BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ ); + BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block { if (m_bOnGround) // check if it's still on the ground @@ -616,7 +611,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) bool IsNoAirSurrounding = true; for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) { - if (!a_Chunk.UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock)) + if (!NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock)) { // The pickup is too close to an unloaded chunk, bail out of any physics handling return; @@ -764,20 +759,8 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } } - BlockX = (int) floor(NextPos.x); - BlockZ = (int) floor(NextPos.z); - - cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); - // See if we can commit our changes. If not, we will discard them. - if (NextChunk != NULL) - { - if (NextPos.x != GetPosX()) SetPosX(NextPos.x); - if (NextPos.y != GetPosY()) SetPosY(NextPos.y); - if (NextPos.z != GetPosZ()) SetPosZ(NextPos.z); - if (NextSpeed.x != GetSpeedX()) SetSpeedX(NextSpeed.x); - if (NextSpeed.y != GetSpeedY()) SetSpeedY(NextSpeed.y); - if (NextSpeed.z != GetSpeedZ()) SetSpeedZ(NextSpeed.z); - } + SetPosition(NextPos); + SetSpeed(NextSpeed); } @@ -981,13 +964,13 @@ void cEntity::HandleAir(void) } else { - m_AirTickTimer -= 1; + m_AirTickTimer--; } } else { // Reduce air supply - m_AirLevel -= 1; + m_AirLevel--; } } else @@ -1099,15 +1082,15 @@ void cEntity::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude) { - //We need to keep updating the clients when there is movement or if there was a change in speed and after 2 ticks - if( (m_Speed.SqrLength() > 0.0004f || m_bDirtySpeed) && (m_World->GetWorldAge() - m_TimeLastSpeedPacket >= 2)) + // Send velocity packet every two ticks if: speed is not negligible or speed was set (as indicated by the DirtySpeed flag) + if (((m_Speed.SqrLength() > 0.0004f) || m_bDirtySpeed) && ((m_World->GetWorldAge() - m_TimeLastSpeedPacket) >= 2)) { m_World->BroadcastEntityVelocity(*this,a_Exclude); m_bDirtySpeed = false; m_TimeLastSpeedPacket = m_World->GetWorldAge(); } - //Have to process position related packets this every two ticks + // Have to process position related packets this every two ticks if (m_World->GetWorldAge() % 2 == 0) { int DiffX = (int) (floor(GetPosX() * 32.0) - floor(m_LastPosX * 32.0)); diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 6e3f8292b..c2137039a 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -32,6 +32,8 @@ #define POSZ_TOINT (int)floor(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; } + @@ -88,23 +90,42 @@ public: } ; // tolua_end - - enum + + enum eEntityStatus { - ENTITY_STATUS_HURT = 2, - ENTITY_STATUS_DEAD = 3, - ENTITY_STATUS_WOLF_TAMING = 6, - ENTITY_STATUS_WOLF_TAMED = 7, - ENTITY_STATUS_WOLF_SHAKING = 8, - ENTITY_STATUS_EATING_ACCEPTED = 9, - ENTITY_STATUS_SHEEP_EATING = 10, - ENTITY_STATUS_GOLEM_ROSING = 11, - ENTITY_STATUS_VILLAGER_HEARTS = 12, - ENTITY_STATUS_VILLAGER_ANGRY = 13, - ENTITY_STATUS_VILLAGER_HAPPY = 14, - ENTITY_STATUS_WITCH_MAGICKING = 15, + // TODO: Investiagate 0, 1, and 5 as Wiki.vg is not certain + + // Entity becomes coloured red + esGenericHurt = 2, + // Entity plays death animation (entity falls to ground) + esGenericDead = 3, + // Iron Golem plays attack animation (arms lift and fall) + esIronGolemAttacking = 4, + // Wolf taming particles spawn (smoke) + esWolfTaming = 6, + // Wolf tamed particles spawn (hearts) + esWolfTamed = 7, + // Wolf plays water removal animation (shaking and water particles) + esWolfDryingWater = 8, + // Informs client that eating was accepted + esPlayerEatingAccepted = 9, + // Sheep plays eating animation (head lowers to ground) + esSheepEating = 10, + // Iron Golem holds gift to villager children + esIronGolemGivingPlant = 11, + // Villager spawns heart particles + esVillagerBreeding = 12, + // Villager spawns thunderclound particles + esVillagerAngry = 13, + // Villager spawns green crosses + esVillagerHappy = 14, + // Witch spawns magic particle (TODO: investigation into what this is) + esWitchMagicking = 15, + // It seems 16 (zombie conversion) is now done with metadata - ENTITY_STATUS_FIREWORK_EXPLODE= 17, + + // Informs client to explode a firework based on its metadata + esFireworkExploding = 17, } ; enum diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index 7fc89b62b..497b41683 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -98,45 +98,44 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk) if (!m_bCollected) { - int BlockY = (int) floor(GetPosY()); + int BlockY = POSY_TOINT; + int BlockX = POSX_TOINT; + int BlockZ = POSZ_TOINT; + if ((BlockY >= 0) && (BlockY < cChunkDef::Height)) // Don't do anything except for falling when outside the world { - int BlockX = (int) floor(GetPosX()); - int BlockZ = (int) floor(GetPosZ()); // Position might have changed due to physics. So we have to make sure we have the correct chunk. - cChunk * CurrentChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); - if (CurrentChunk != NULL) // Make sure the chunk is loaded - { - int RelBlockX = BlockX - (CurrentChunk->GetPosX() * cChunkDef::Width); - int RelBlockZ = BlockZ - (CurrentChunk->GetPosZ() * cChunkDef::Width); + GET_AND_VERIFY_CURRENT_CHUNK(CurrentChunk, BlockX, BlockZ) + + int RelBlockX = BlockX - (CurrentChunk->GetPosX() * cChunkDef::Width); + int RelBlockZ = BlockZ - (CurrentChunk->GetPosZ() * cChunkDef::Width); - // If the pickup is on the bottommost block position, make it think the void is made of air: (#131) - BLOCKTYPE BlockBelow = (BlockY > 0) ? CurrentChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; - BLOCKTYPE BlockIn = CurrentChunk->GetBlock(RelBlockX, BlockY, RelBlockZ); - - if ( - IsBlockLava(BlockBelow) || (BlockBelow == E_BLOCK_FIRE) || - IsBlockLava(BlockIn) || (BlockIn == E_BLOCK_FIRE) - ) + // If the pickup is on the bottommost block position, make it think the void is made of air: (#131) + BLOCKTYPE BlockBelow = (BlockY > 0) ? CurrentChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; + BLOCKTYPE BlockIn = CurrentChunk->GetBlock(RelBlockX, BlockY, RelBlockZ); + + if ( + IsBlockLava(BlockBelow) || (BlockBelow == E_BLOCK_FIRE) || + IsBlockLava(BlockIn) || (BlockIn == E_BLOCK_FIRE) + ) + { + 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) { - 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) - { - Destroy(true); - return; - } + Destroy(true); + return; } + } - if (!IsDestroyed()) // Don't try to combine if someone has tried to combine me + if (!IsDestroyed()) // Don't try to combine if someone has tried to combine me + { + cPickupCombiningCallback PickupCombiningCallback(GetPosition(), this); + m_World->ForEachEntity(PickupCombiningCallback); // Not ForEachEntityInChunk, otherwise pickups don't combine across chunk boundaries + if (PickupCombiningCallback.FoundMatchingPickup()) { - cPickupCombiningCallback PickupCombiningCallback(GetPosition(), this); - m_World->ForEachEntity(PickupCombiningCallback); // Not ForEachEntityInChunk, otherwise pickups don't combine across chunk boundaries - if (PickupCombiningCallback.FoundMatchingPickup()) - { - m_World->BroadcastEntityMetadata(*this); - } + m_World->BroadcastEntityMetadata(*this); } } } @@ -156,7 +155,7 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk) return; } - if (GetPosY() < -8) // Out of this world and no more visible! + if (GetPosY() < VOID_BOUNDARY) // Out of this world and no more visible! { Destroy(true); return; diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h index 74b917bce..2dcbecaaf 100644 --- a/src/Entities/Pickup.h +++ b/src/Entities/Pickup.h @@ -49,9 +49,6 @@ public: bool IsPlayerCreated(void) const { return m_bIsPlayerCreated; } // tolua_export private: - Vector3d m_ResultingSpeed; //Can be used to modify the resulting speed for the current tick ;) - - Vector3d m_WaterSpeed; /** The number of ticks that the entity has existed / timer between collect and destroy; in msec */ float m_Timer; diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 7f2e5b4c2..2b9533623 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -590,7 +590,7 @@ void cPlayer::FinishEating(void) m_EatingFinishTick = -1; // Send the packets: - m_ClientHandle->SendEntityStatus(*this, ENTITY_STATUS_EATING_ACCEPTED); + m_ClientHandle->SendEntityStatus(*this, esPlayerEatingAccepted); m_World->BroadcastEntityAnimation(*this, 0); m_World->BroadcastEntityMetadata(*this); diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index e86bb48bd..96db17ffd 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -791,7 +791,7 @@ void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk) if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks) { - m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_FIREWORK_EXPLODE); + m_World->BroadcastEntityStatus(*this, esFireworkExploding); Destroy(); } -- cgit v1.2.3 From bdea8706d8050ba3ea00b580bba795bc468cfdbd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 17 Apr 2014 18:50:25 +0100 Subject: Added new AI rules + Added new AI rules handling cacti and large heights * Fixed cIniFile not recognising comments in cIniFile::ReadFile() * Fixed users.ini not being properly generated * Changed all instances of (int)floor(GetPosXXX()) to POSXXX_TOINT --- src/Entities/Entity.cpp | 2 +- src/Entities/Entity.h | 3 ++- src/Entities/Minecart.cpp | 38 +++++++++++++++++++------------------- src/Entities/Player.cpp | 32 ++++++++++++++------------------ 4 files changed, 36 insertions(+), 39 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 8ef45f1a5..7d9039479 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -806,7 +806,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) int MaxRelX = (int)floor(GetPosX() + m_Width / 2) - a_Chunk.GetPosX() * cChunkDef::Width; int MinRelZ = (int)floor(GetPosZ() - m_Width / 2) - a_Chunk.GetPosZ() * cChunkDef::Width; int MaxRelZ = (int)floor(GetPosZ() + m_Width / 2) - a_Chunk.GetPosZ() * cChunkDef::Width; - int MinY = std::max(0, std::min(cChunkDef::Height - 1, (int)floor(GetPosY()))); + int MinY = std::max(0, std::min(cChunkDef::Height - 1, POSY_TOINT)); int MaxY = std::max(0, std::min(cChunkDef::Height - 1, (int)ceil (GetPosY() + m_Height))); bool HasWater = false; bool HasLava = false; diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 6e3f8292b..8fa5a2e42 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -118,7 +118,8 @@ public: BURN_TICKS = 200, ///< How long to keep an entity burning after it has stood in lava / fire MAX_AIR_LEVEL = 300, ///< Maximum air an entity can have DROWNING_TICKS = 20, ///< Number of ticks per heart of damage - VOID_BOUNDARY = -46 ///< At what position Y to begin applying void damage + VOID_BOUNDARY = -46, ///< At what position Y to begin applying void damage + FALL_DAMAGE_HEIGHT = 4 ///< At what position Y fall damage is applied } ; cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 7f38aa35a..6db13231d 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -132,7 +132,7 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) return; } - int PosY = (int)floor(GetPosY()); + int PosY = POSY_TOINT; if ((PosY <= 0) || (PosY >= cChunkDef::Height)) { // Outside the world, just process normal falling physics @@ -141,8 +141,8 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) return; } - int RelPosX = (int)floor(GetPosX()) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelPosZ = (int)floor(GetPosZ()) - a_Chunk.GetPosZ() * cChunkDef::Width; + 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) { @@ -195,7 +195,7 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) super::HandlePhysics(a_Dt, *Chunk); } - if (m_bIsOnDetectorRail && !Vector3i((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())).Equals(m_DetectorRailPosition)) + if (m_bIsOnDetectorRail && !Vector3i(POSX_TOINT, POSY_TOINT, POSZ_TOINT).Equals(m_DetectorRailPosition)) { m_World->SetBlock(m_DetectorRailPosition.x, m_DetectorRailPosition.y, m_DetectorRailPosition.z, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07); m_bIsOnDetectorRail = false; @@ -203,7 +203,7 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) else if (WasDetectorRail) { m_bIsOnDetectorRail = true; - m_DetectorRailPosition = Vector3i((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); + m_DetectorRailPosition = Vector3i(POSX_TOINT, POSY_TOINT, POSZ_TOINT); } // Broadcast positioning changes to client @@ -719,11 +719,11 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) { if (GetSpeedZ() > 0) { - BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())); + BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, (int)ceil(GetPosZ())); if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { // We could try to detect a block in front based purely on coordinates, but xoft made a bounding box system - why not use? :P - cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())), 0.5, 1); + cBoundingBox bbBlock(Vector3d(POSX_TOINT, POSY_TOINT, (int)ceil(GetPosZ())), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); if (bbBlock.DoesIntersect(bbMinecart)) @@ -736,10 +736,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) } else if (GetSpeedZ() < 0) { - BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1); + BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1); if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { - cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1), 0.5, 1); + cBoundingBox bbBlock(Vector3d(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ() - 1), GetWidth() / 2, GetHeight()); if (bbBlock.DoesIntersect(bbMinecart)) @@ -756,10 +756,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) { if (GetSpeedX() > 0) { - BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); + BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), POSY_TOINT, POSZ_TOINT); if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { - cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1); + cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), POSY_TOINT, POSZ_TOINT), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); if (bbBlock.DoesIntersect(bbMinecart)) @@ -772,10 +772,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) } else if (GetSpeedX() < 0) { - BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); + BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT); if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { - cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1); + cBoundingBox bbBlock(Vector3d(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX() - 1, floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); if (bbBlock.DoesIntersect(bbMinecart)) @@ -793,10 +793,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) case E_META_RAIL_CURVED_ZP_XM: case E_META_RAIL_CURVED_ZP_XP: { - BLOCKTYPE BlockXM = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); - BLOCKTYPE BlockXP = m_World->GetBlock((int)floor(GetPosX()) + 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); - BLOCKTYPE BlockZM = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); - BLOCKTYPE BlockZP = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); + BLOCKTYPE BlockXM = m_World->GetBlock(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT); + BLOCKTYPE BlockXP = m_World->GetBlock(POSX_TOINT + 1, POSY_TOINT, POSZ_TOINT); + BLOCKTYPE BlockZM = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT + 1); + BLOCKTYPE BlockZP = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT + 1); if ( (!IsBlockRail(BlockXM) && cBlockInfo::IsSolid(BlockXM)) || (!IsBlockRail(BlockXP) && cBlockInfo::IsSolid(BlockXP)) || @@ -805,7 +805,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) ) { SetSpeed(0, 0, 0); - SetPosition((int)floor(GetPosX()) + 0.5, GetPosY(), (int)floor(GetPosZ()) + 0.5); + SetPosition(POSX_TOINT + 0.5, GetPosY(), POSZ_TOINT + 0.5); return true; } break; @@ -822,7 +822,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) { cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == NULL) ? -1 : m_Attachee->GetUniqueID())); int ChunkX, ChunkZ; - cChunkDef::BlockToChunk((int)floor(GetPosX()), (int)floor(GetPosZ()), ChunkX, ChunkZ); + cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ); m_World->ForEachEntityInChunk(ChunkX, ChunkZ, MinecartCollisionCallback); if (!MinecartCollisionCallback.FoundIntersection()) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 7f2e5b4c2..7cea46e03 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -437,7 +437,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) cWorld * World = GetWorld(); if ((GetPosY() >= 0) && (GetPosY() < cChunkDef::Height)) { - BLOCKTYPE BlockType = World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); + BLOCKTYPE BlockType = World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT); if (BlockType != E_BLOCK_AIR) { m_bTouchGround = true; @@ -466,7 +466,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) TakeDamage(dtFalling, NULL, Damage, Damage, 0); // Fall particles - GetWorld()->BroadcastSoundParticleEffect(2006, (int)floor(GetPosX()), (int)GetPosY() - 1, (int)floor(GetPosZ()), Damage /* Used as particle effect speed modifier */); + GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, (int)GetPosY() - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */); } m_LastGroundHeight = (float)GetPosY(); @@ -1519,22 +1519,16 @@ void cPlayer::LoadPermissionsFromDisk() cIniFile IniFile; if (IniFile.ReadFile("users.ini")) { - std::string Groups = IniFile.GetValue(m_PlayerName, "Groups", ""); - if (!Groups.empty()) + AString Groups = IniFile.GetValueSet(m_PlayerName, "Groups", "Default"); + AStringVector Split = StringSplitAndTrim(Groups, ","); + + for (AStringVector::const_iterator itr = Split.begin(), end = Split.end(); itr != end; ++itr) { - AStringVector Split = StringSplitAndTrim(Groups, ","); - for (AStringVector::const_iterator itr = Split.begin(), end = Split.end(); itr != end; ++itr) + if (!cRoot::Get()->GetGroupManager()->ExistsGroup(*itr)) { - if (!cRoot::Get()->GetGroupManager()->ExistsGroup(*itr)) - { - LOGWARNING("The group %s for player %s was not found!", itr->c_str(), m_PlayerName.c_str()); - } - AddToGroup(*itr); + LOGWARNING("The group %s for player %s was not found!", itr->c_str(), m_PlayerName.c_str()); } - } - else - { - AddToGroup("Default"); + AddToGroup(*itr); } AString Color = IniFile.GetValue(m_PlayerName, "Color", "-"); @@ -1546,8 +1540,10 @@ void cPlayer::LoadPermissionsFromDisk() else { cGroupManager::GenerateDefaultUsersIni(IniFile); + IniFile.AddValue("Groups", m_PlayerName, "Default"); AddToGroup("Default"); } + IniFile.WriteFile("users.ini"); ResolvePermissions(); } @@ -1899,9 +1895,9 @@ void cPlayer::ApplyFoodExhaustionFromMovement() void cPlayer::Detach() { super::Detach(); - int PosX = (int)floor(GetPosX()); - int PosY = (int)floor(GetPosY()); - int PosZ = (int)floor(GetPosZ()); + int PosX = POSX_TOINT; + int PosY = POSY_TOINT; + int PosZ = POSZ_TOINT; // Search for a position within an area to teleport player after detachment // Position must be solid land, and occupied by a nonsolid block -- cgit v1.2.3 From 6cb63a768dd2356d0e41aef1ef086ae972449bdd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 18 Apr 2014 12:59:14 +0100 Subject: Fixed #906 --- src/Entities/Entity.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 86aee4c6f..56ef36ef8 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -771,6 +771,16 @@ void cEntity::TickBurning(cChunk & a_Chunk) { // Remember the current burning state: bool HasBeenBurning = (m_TicksLeftBurning > 0); + + if (GetWorld()->GetWeather() == eWeather_Rain) + { + if (HasBeenBurning) + { + m_TicksLeftBurning = 0; + OnFinishedBurning(); + } + return; + } // Do the burning damage: if (m_TicksLeftBurning > 0) -- cgit v1.2.3 From 013da806ec20b62a742aded9a9d2b8131193f30d Mon Sep 17 00:00:00 2001 From: jfhumann Date: Fri, 18 Apr 2014 21:09:44 +0200 Subject: Did some static analysis, fixed some bugs and optimized a lot of code --- src/Entities/Minecart.cpp | 2 +- src/Entities/Player.cpp | 9 +++++---- src/Entities/Player.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 7f38aa35a..2814ce33c 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -795,7 +795,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) { BLOCKTYPE BlockXM = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); BLOCKTYPE BlockXP = m_World->GetBlock((int)floor(GetPosX()) + 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); - BLOCKTYPE BlockZM = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); + BLOCKTYPE BlockZM = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1); BLOCKTYPE BlockZP = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); if ( (!IsBlockRail(BlockXM) && cBlockInfo::IsSolid(BlockXM)) || diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 7f2e5b4c2..df656ffa1 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -85,9 +85,10 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) if (!LoadFromDisk()) { m_Inventory.Clear(); - SetPosX(cRoot::Get()->GetDefaultWorld()->GetSpawnX()); - SetPosY(cRoot::Get()->GetDefaultWorld()->GetSpawnY()); - SetPosZ(cRoot::Get()->GetDefaultWorld()->GetSpawnZ()); + cWorld * DefaultWorld = cRoot::Get()->GetDefaultWorld(); + SetPosX(DefaultWorld->GetSpawnX()); + SetPosY(DefaultWorld->GetSpawnY()); + SetPosZ(DefaultWorld->GetSpawnZ()); LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}", a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ() @@ -1165,7 +1166,7 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const -void cPlayer::ForceSetSpeed(Vector3d a_Direction) +void cPlayer::ForceSetSpeed(const Vector3d & a_Direction) { SetSpeed(a_Direction); m_ClientHandle->SendEntityVelocity(*this); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 05377a117..74da409cf 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -181,7 +181,7 @@ public: void LoginSetGameMode(eGameMode a_GameMode); /** Forces the player to move in the given direction. */ - void ForceSetSpeed(Vector3d a_Direction); // tolua_export + void ForceSetSpeed(const Vector3d & a_Direction); // tolua_export /** Tries to move to a new position, with attachment-related checks (y == -999) */ void MoveTo(const Vector3d & a_NewPos); // tolua_export -- cgit v1.2.3 From f48d43f050683488b4cdbddcc92cfc7804112c11 Mon Sep 17 00:00:00 2001 From: jfhumann Date: Sat, 19 Apr 2014 20:51:52 +0200 Subject: Fixed Flint and Steel, reverted Minecart change, renamed a parameter name --- src/Entities/Minecart.cpp | 3 ++- src/Entities/Player.cpp | 4 ++-- src/Entities/Player.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index db55eb058..7fe0b3cb1 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -796,7 +796,8 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) BLOCKTYPE BlockXM = m_World->GetBlock(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT); BLOCKTYPE BlockXP = m_World->GetBlock(POSX_TOINT + 1, POSY_TOINT, POSZ_TOINT); BLOCKTYPE BlockZM = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1); - BLOCKTYPE BlockZP = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT + 1); + // FIXME: Should the next line be POSZ_TOINT + 1? Else add some documenttation why - 1 + BLOCKTYPE BlockZP = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1); if ( (!IsBlockRail(BlockXM) && cBlockInfo::IsSolid(BlockXM)) || (!IsBlockRail(BlockXP) && cBlockInfo::IsSolid(BlockXP)) || diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 46edb7199..fedb62527 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1166,9 +1166,9 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const -void cPlayer::ForceSetSpeed(const Vector3d & a_Direction) +void cPlayer::ForceSetSpeed(const Vector3d & a_Speed) { - SetSpeed(a_Direction); + SetSpeed(a_Speed); m_ClientHandle->SendEntityVelocity(*this); } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 74da409cf..78d661015 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -181,7 +181,7 @@ public: void LoginSetGameMode(eGameMode a_GameMode); /** Forces the player to move in the given direction. */ - void ForceSetSpeed(const Vector3d & a_Direction); // 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 -- cgit v1.2.3 From a967313839bab2a5f43befabe689801b949b274e Mon Sep 17 00:00:00 2001 From: "r.ramazanov" Date: Mon, 21 Apr 2014 13:13:25 +0400 Subject: Mobs shouldn't burn when it's Raining #906 --- src/Entities/Entity.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 56ef36ef8..c1926dafc 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -774,12 +774,19 @@ void cEntity::TickBurning(cChunk & a_Chunk) if (GetWorld()->GetWeather() == eWeather_Rain) { - if (HasBeenBurning) + + int PosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width, + PosY = POSY_TOINT, + PosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; + + if ((PosY > 0) || (PosY <= cChunkDef::Height)) { - m_TicksLeftBurning = 0; - OnFinishedBurning(); - } - return; + // Inside the world + if (a_Chunk.GetSkyLight(PosX, PosY, PosZ) == 15) + { + m_TicksLeftBurning = 0; + } + } } // Do the burning damage: -- cgit v1.2.3 From 865e8e22e54340606d8008e13172cb61d326d009 Mon Sep 17 00:00:00 2001 From: jfhumann Date: Mon, 21 Apr 2014 14:04:36 +0200 Subject: reverted the revert of the minecart collision detection fix. --- src/Entities/Minecart.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 7fe0b3cb1..db55eb058 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -796,8 +796,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) BLOCKTYPE BlockXM = m_World->GetBlock(POSX_TOINT - 1, POSY_TOINT, POSZ_TOINT); BLOCKTYPE BlockXP = m_World->GetBlock(POSX_TOINT + 1, POSY_TOINT, POSZ_TOINT); BLOCKTYPE BlockZM = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1); - // FIXME: Should the next line be POSZ_TOINT + 1? Else add some documenttation why - 1 - BLOCKTYPE BlockZP = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT - 1); + BLOCKTYPE BlockZP = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT + 1); if ( (!IsBlockRail(BlockXM) && cBlockInfo::IsSolid(BlockXM)) || (!IsBlockRail(BlockXP) && cBlockInfo::IsSolid(BlockXP)) || -- cgit v1.2.3 From bca7f2949032ab90ee03988f560bce157a25b683 Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 22 Apr 2014 01:59:34 -1000 Subject: Lay foundation for fireproof entities. Prevent any entities with the m_Fireproof flag from taking fire or lava damage. --- src/Entities/Entity.cpp | 15 ++++++++++++--- src/Entities/Entity.h | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 56ef36ef8..345e0054b 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -788,7 +788,10 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastBurnDamage++; if (m_TicksSinceLastBurnDamage >= BURN_TICKS_PER_DAMAGE) { - TakeDamage(dtOnFire, NULL, BURN_DAMAGE, 0); + if (!m_Fireproof) + { + TakeDamage(dtOnFire, NULL, BURN_DAMAGE, 0); + } m_TicksSinceLastBurnDamage = 0; } m_TicksLeftBurning--; @@ -856,7 +859,10 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastLavaDamage++; if (m_TicksSinceLastLavaDamage >= LAVA_TICKS_PER_DAMAGE) { - TakeDamage(dtLavaContact, NULL, LAVA_DAMAGE, 0); + if (!m_Fireproof) + { + TakeDamage(dtLavaContact, NULL, LAVA_DAMAGE, 0); + } m_TicksSinceLastLavaDamage = 0; } } @@ -874,7 +880,10 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastFireDamage++; if (m_TicksSinceLastFireDamage >= FIRE_TICKS_PER_DAMAGE) { - TakeDamage(dtFireContact, NULL, FIRE_DAMAGE, 0); + if (!m_Fireproof) + { + TakeDamage(dtFireContact, NULL, FIRE_DAMAGE, 0); + } m_TicksSinceLastFireDamage = 0; } } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 8f3899e2f..ea85ac683 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -435,6 +435,9 @@ protected: cWorld * m_World; + /// Whether the entity is capable of taking fire or lava damage. + bool m_Fireproof; + /// Time, in ticks, since the last damage dealt by being on fire. Valid only if on fire (IsOnFire()) int m_TicksSinceLastBurnDamage; -- cgit v1.2.3 From 06f41699afe27a6be1de357466f9185403baa550 Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 22 Apr 2014 02:36:39 -1000 Subject: Fixed indentation and changed m_Fireproof to m_IsFireproof. --- src/Entities/Entity.cpp | 24 ++++++++++++------------ src/Entities/Entity.h | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 345e0054b..9a80d3e80 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -788,10 +788,10 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastBurnDamage++; if (m_TicksSinceLastBurnDamage >= BURN_TICKS_PER_DAMAGE) { - if (!m_Fireproof) - { - TakeDamage(dtOnFire, NULL, BURN_DAMAGE, 0); - } + if (!m_IsFireproof) + { + TakeDamage(dtOnFire, NULL, BURN_DAMAGE, 0); + } m_TicksSinceLastBurnDamage = 0; } m_TicksLeftBurning--; @@ -859,10 +859,10 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastLavaDamage++; if (m_TicksSinceLastLavaDamage >= LAVA_TICKS_PER_DAMAGE) { - if (!m_Fireproof) - { - TakeDamage(dtLavaContact, NULL, LAVA_DAMAGE, 0); - } + if (!m_IsFireproof) + { + TakeDamage(dtLavaContact, NULL, LAVA_DAMAGE, 0); + } m_TicksSinceLastLavaDamage = 0; } } @@ -880,10 +880,10 @@ void cEntity::TickBurning(cChunk & a_Chunk) m_TicksSinceLastFireDamage++; if (m_TicksSinceLastFireDamage >= FIRE_TICKS_PER_DAMAGE) { - if (!m_Fireproof) - { - TakeDamage(dtFireContact, NULL, FIRE_DAMAGE, 0); - } + if (!m_IsFireproof) + { + TakeDamage(dtFireContact, NULL, FIRE_DAMAGE, 0); + } m_TicksSinceLastFireDamage = 0; } } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index ea85ac683..84a2003d4 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -435,8 +435,8 @@ protected: cWorld * m_World; - /// Whether the entity is capable of taking fire or lava damage. - bool m_Fireproof; + /// 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; -- cgit v1.2.3 From a37b36adab85206e025d4ca97f6e64dc7a6974b8 Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 22 Apr 2014 12:59:31 -1000 Subject: Fireproof status getter and setter. --- src/Entities/Entity.cpp | 11 +++++++++++ src/Entities/Entity.h | 5 +++++ 2 files changed, 16 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 9a80d3e80..82900ff91 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -45,6 +45,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_IsInitialized(false) , m_EntityType(a_EntityType) , m_World(NULL) + , m_IsFireproof(false) , m_TicksSinceLastBurnDamage(0) , m_TicksSinceLastLavaDamage(0) , m_TicksSinceLastFireDamage(0) @@ -1042,6 +1043,16 @@ void cEntity::SetMaxHealth(int a_MaxHealth) +/// Sets whether the entity is fireproof +void cEntity::SetFireproofStatus(bool a_IsFireproof) +{ + m_IsFireproof = a_IsFireproof; +} + + + + + /// Puts the entity on fire for the specified amount of ticks void cEntity::StartBurning(int a_TicksLeftBurning) { diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 84a2003d4..4267ed0f6 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -329,6 +329,11 @@ public: int GetMaxHealth(void) const { return m_MaxHealth; } + /// Sets whether the entity is fireproof + void SetFireproofStatus(bool a_IsFireproof); + + bool GetFireproofStatus(void) const { return m_IsFireproof; } + /// Puts the entity on fire for the specified amount of ticks void StartBurning(int a_TicksLeftBurning); -- cgit v1.2.3 From 876866942807f823d5d7553538f562a6b081093b Mon Sep 17 00:00:00 2001 From: archshift Date: Wed, 23 Apr 2014 00:12:37 -0700 Subject: Renamed getter and setter for IsFireproof. --- src/Entities/Entity.cpp | 2 +- src/Entities/Entity.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 82900ff91..6da6da54e 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1044,7 +1044,7 @@ void cEntity::SetMaxHealth(int a_MaxHealth) /// Sets whether the entity is fireproof -void cEntity::SetFireproofStatus(bool a_IsFireproof) +void cEntity::SetIsFireproof(bool a_IsFireproof) { m_IsFireproof = a_IsFireproof; } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 4267ed0f6..86efc5a98 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -330,9 +330,9 @@ public: int GetMaxHealth(void) const { return m_MaxHealth; } /// Sets whether the entity is fireproof - void SetFireproofStatus(bool a_IsFireproof); + void SetIsFireproof(bool a_IsFireproof); - bool GetFireproofStatus(void) const { return m_IsFireproof; } + bool IsFireproof(void) const { return m_IsFireproof; } /// Puts the entity on fire for the specified amount of ticks void StartBurning(int a_TicksLeftBurning); -- cgit v1.2.3 From 5deb35c5cfc97fc07601fb64ce9631c794237680 Mon Sep 17 00:00:00 2001 From: "r.ramazanov" Date: Wed, 23 Apr 2014 18:15:04 +0400 Subject: Mobs shouldn't burn when it's Raining #906 Mob Knockback is far too much #776 --- src/Entities/Entity.cpp | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c1926dafc..46bb499b4 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -325,9 +325,32 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_Health = 0; } - if (IsMob() || IsPlayer()) // Knockback for only players and mobs + if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != NULL)) // Knockback for only players and mobs { - AddSpeed(a_TDI.Knockback * 2); + int KnockbackLevel = 0; + if (a_TDI.Attacker->GetEquippedWeapon().m_ItemType == E_ITEM_BOW) + { + KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchPunch); + } + else + { + KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchKnockback); + } + + Vector3d additionalSpeed(0, 0, 0); + switch (KnockbackLevel) + { + case 1: + additionalSpeed.Set(5, .2, 5); + break; + case 2: + additionalSpeed.Set(8, .2, 8); + break; + default: + additionalSpeed.Set(2, .2, 2); + break; + } + AddSpeed(a_TDI.Knockback * additionalSpeed); } m_World->BroadcastEntityStatus(*this, esGenericHurt); @@ -772,16 +795,14 @@ void cEntity::TickBurning(cChunk & a_Chunk) // Remember the current burning state: bool HasBeenBurning = (m_TicksLeftBurning > 0); - if (GetWorld()->GetWeather() == eWeather_Rain) + if (m_World->IsWeatherWet()) { + int PosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; + int PosY = POSY_TOINT; + int PosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - int PosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width, - PosY = POSY_TOINT, - PosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - - if ((PosY > 0) || (PosY <= cChunkDef::Height)) + if((POSY_TOINT - 1) == m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) { - // Inside the world if (a_Chunk.GetSkyLight(PosX, PosY, PosZ) == 15) { m_TicksLeftBurning = 0; -- cgit v1.2.3 From ec9787bae21f92251a38338ae5823aa851c5efea Mon Sep 17 00:00:00 2001 From: archshift Date: Thu, 24 Apr 2014 19:16:16 -0700 Subject: Chicken eggs and ender pearls can hit entities. Fixed warning by adding dedicated m_HasTeleported for fired arrows. --- src/Entities/ProjectileEntity.cpp | 62 +++++++++++++++++++++++++++++++++++---- src/Entities/ProjectileEntity.h | 11 ++++++- 2 files changed, 66 insertions(+), 7 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 96db17ffd..2725822f3 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -562,12 +562,12 @@ 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_HitGroundTimer != -1) // Sent a teleport already, don't do again + if (!m_HasTeleported) // Sent a teleport already, don't do again { if (m_HitGroundTimer > 1000.f) // Send after a second, could be less, but just in case { m_World->BroadcastTeleportEntity(*this); - m_HitGroundTimer = -1; + m_HasTeleported = true; } else { @@ -610,6 +610,32 @@ cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + TryForChicken(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TryForChicken(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEggEntity::TryForChicken(const Vector3d & a_HitPos) { if (m_World->GetTickRandomNumber(7) == 1) { @@ -622,7 +648,6 @@ void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_H m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); m_World->SpawnMob(a_HitPos.x, a_HitPos.y, a_HitPos.z, cMonster::mtChicken); } - Destroy(); } @@ -643,16 +668,40 @@ cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + // TODO: Tweak a_HitPos based on block face. + TeleportUser(a_HitPos); + + Destroy(); +} + + + + + +void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + int TotalDamage = 0; + // TODO: If entity is Ender Crystal, destroy it + + TeleportUser(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + + Destroy(true); +} + + + + + +void cThrownEnderPearlEntity::TeleportUser(const Vector3d & a_HitPos) { // Teleport the creator here, make them take 5 damage: if (m_Creator != NULL) { - // TODO: The coords might need some tweaking based on the block face m_Creator->TeleportToCoords(a_HitPos.x + 0.5, a_HitPos.y + 1.7, a_HitPos.z + 0.5); m_Creator->TakeDamage(dtEnderPearl, this, 5, 0); } - - Destroy(); } @@ -696,6 +745,7 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & TotalDamage = 1; } } + // TODO: If entity is Ender Crystal, destroy it a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index efb7ae783..002aa09a1 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -166,6 +166,9 @@ protected: /// 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 bool m_bIsCollected; @@ -205,7 +208,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; + + void TryForChicken(const Vector3d & a_HitPos); + // tolua_begin } ; @@ -233,6 +239,9 @@ 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; + + void TeleportUser(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From a72744f5c33ec11f33637839e4d6206c4aa2fa2a Mon Sep 17 00:00:00 2001 From: "r.ramazanov" Date: Fri, 25 Apr 2014 10:08:36 +0400 Subject: Mobs shouldn't burn when it's Raining & Mob Knockback is far too much --- src/Entities/Entity.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c09317298..89275a418 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -342,13 +342,13 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) switch (KnockbackLevel) { case 1: - additionalSpeed.Set(5, .2, 5); + additionalSpeed.Set(5, .3, 5); break; case 2: - additionalSpeed.Set(8, .2, 8); + additionalSpeed.Set(8, .3, 8); break; default: - additionalSpeed.Set(2, .2, 2); + additionalSpeed.Set(2, .3, 2); break; } AddSpeed(a_TDI.Knockback * additionalSpeed); @@ -802,12 +802,9 @@ void cEntity::TickBurning(cChunk & a_Chunk) int PosY = POSY_TOINT; int PosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - if((POSY_TOINT - 1) == m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) + if (PosY > m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) { - if (a_Chunk.GetSkyLight(PosX, PosY, PosZ) == 15) - { - m_TicksLeftBurning = 0; - } + m_TicksLeftBurning = 0; } } -- cgit v1.2.3 From 827c3760db5da766a99c42312aa95b43dded9436 Mon Sep 17 00:00:00 2001 From: "r.ramazanov" Date: Fri, 25 Apr 2014 10:58:48 +0400 Subject: Fix for clang --- src/Entities/Entity.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 89275a418..402f94d08 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -798,11 +798,7 @@ void cEntity::TickBurning(cChunk & a_Chunk) if (m_World->IsWeatherWet()) { - int PosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width; - int PosY = POSY_TOINT; - int PosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; - - if (PosY > m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) + if (POSY_TOINT > m_World->GetHeight(POSX_TOINT, POSZ_TOINT)) { m_TicksLeftBurning = 0; } -- cgit v1.2.3 From 4cd2d57c643ec2c7dab7a664248dbf65254c1b1d Mon Sep 17 00:00:00 2001 From: "r.ramazanov" Date: Fri, 25 Apr 2014 12:06:22 +0400 Subject: Fix formatting --- src/Entities/Entity.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 402f94d08..d0dd6fb50 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -341,15 +341,21 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) Vector3d additionalSpeed(0, 0, 0); switch (KnockbackLevel) { - case 1: - additionalSpeed.Set(5, .3, 5); - break; - case 2: - additionalSpeed.Set(8, .3, 8); - break; - default: - additionalSpeed.Set(2, .3, 2); - break; + case 1: + { + additionalSpeed.Set(5, .3, 5); + break; + } + case 2: + { + additionalSpeed.Set(8, .3, 8); + break; + } + default: + { + additionalSpeed.Set(2, .3, 2); + break; + } } AddSpeed(a_TDI.Knockback * additionalSpeed); } -- cgit v1.2.3 From cb7f1ee4bbf726b5b57fe8d1960bb7d03dc1e87a Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 05:39:35 -0700 Subject: Rename spawn chicken method, Initialize m_HasTeleported. --- src/Entities/ProjectileEntity.cpp | 7 ++++--- src/Entities/ProjectileEntity.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 2725822f3..89b833abf 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -440,6 +440,7 @@ cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : m_IsCritical((a_Force >= 1)), m_Timer(0), m_HitGroundTimer(0), + m_HasTeleported(false), m_bIsCollected(false), m_HitBlockPos(0, 0, 0) { @@ -611,7 +612,7 @@ cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, void cThrownEggEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { - TryForChicken(a_HitPos); + TrySpawnChicken(a_HitPos); Destroy(); } @@ -625,7 +626,7 @@ void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hit int TotalDamage = 0; // TODO: If entity is Ender Crystal, destroy it - TryForChicken(a_HitPos); + TrySpawnChicken(a_HitPos); a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); @@ -635,7 +636,7 @@ void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hit -void cThrownEggEntity::TryForChicken(const Vector3d & a_HitPos) +void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos) { if (m_World->GetTickRandomNumber(7) == 1) { diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 002aa09a1..90d44ed91 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -210,7 +210,7 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - void TryForChicken(const Vector3d & a_HitPos); + void TrySpawnChicken(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From 256691461bd9c4719e94d17942372ef8302a3607 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 05:49:18 -0700 Subject: Comments for TrySpawnChicken() and TeleportUser(). --- src/Entities/ProjectileEntity.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 90d44ed91..5aa489ff8 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -210,6 +210,7 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + // Randomly decides whether to spawn a chicken where the egg lands. void TrySpawnChicken(const Vector3d & a_HitPos); // tolua_begin @@ -241,6 +242,7 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + // Teleports the user where the ender pearl lands. void TeleportUser(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From 8aa82d048d4506c963846d5c02650e1037e92992 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 06:26:08 -0700 Subject: Creator not user. --- src/Entities/ProjectileEntity.cpp | 6 +++--- src/Entities/ProjectileEntity.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 89b833abf..fd3e80e5f 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -671,7 +671,7 @@ cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X void cThrownEnderPearlEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { // TODO: Tweak a_HitPos based on block face. - TeleportUser(a_HitPos); + TeleportCreator(a_HitPos); Destroy(); } @@ -685,7 +685,7 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d int TotalDamage = 0; // TODO: If entity is Ender Crystal, destroy it - TeleportUser(a_HitPos); + TeleportCreator(a_HitPos); a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); Destroy(true); @@ -695,7 +695,7 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d -void cThrownEnderPearlEntity::TeleportUser(const Vector3d & a_HitPos) +void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) { // Teleport the creator here, make them take 5 damage: if (m_Creator != NULL) diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index 5aa489ff8..731dd060e 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -242,8 +242,8 @@ protected: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; - // Teleports the user where the ender pearl lands. - void TeleportUser(const Vector3d & a_HitPos); + // Teleports the creator where the ender pearl lands. + void TeleportCreator(const Vector3d & a_HitPos); // tolua_begin -- cgit v1.2.3 From e47dab84f3f6606d6d6e95774b16d7d4e8d7daa6 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 09:56:15 -0700 Subject: Cmake generated projects for IDEs include headers in project files. --- src/Entities/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Entities') diff --git a/src/Entities/CMakeLists.txt b/src/Entities/CMakeLists.txt index 85cc45494..c9ca44d38 100644 --- a/src/Entities/CMakeLists.txt +++ b/src/Entities/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../") file(GLOB SOURCE "*.cpp" + "*.h" ) add_library(Entities ${SOURCE}) -- cgit v1.2.3