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 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