summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarchshift <admin@archshift.com>2014-08-03 07:35:29 +0200
committerarchshift <admin@archshift.com>2014-08-03 07:35:29 +0200
commit9ecce2366e81ae66c77312220e378ff2f1b02a24 (patch)
tree49d909ee4e16da9cc8c146aa968052c2480c16a7
parentRemoved unused cPlayer::FoodPoison function (diff)
downloadcuberite-9ecce2366e81ae66c77312220e378ff2f1b02a24.tar
cuberite-9ecce2366e81ae66c77312220e378ff2f1b02a24.tar.gz
cuberite-9ecce2366e81ae66c77312220e378ff2f1b02a24.tar.bz2
cuberite-9ecce2366e81ae66c77312220e378ff2f1b02a24.tar.lz
cuberite-9ecce2366e81ae66c77312220e378ff2f1b02a24.tar.xz
cuberite-9ecce2366e81ae66c77312220e378ff2f1b02a24.tar.zst
cuberite-9ecce2366e81ae66c77312220e378ff2f1b02a24.zip
-rw-r--r--src/Entities/Entity.cpp28
-rw-r--r--src/Entities/Player.cpp17
2 files changed, 16 insertions, 29 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index c2727e6a1..042e3b868 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -543,10 +543,7 @@ void cEntity::KilledBy(TakeDamageInfo & a_TDI)
void cEntity::Heal(int a_HitPoints)
{
m_Health += a_HitPoints;
- if (m_Health > m_MaxHealth)
- {
- m_Health = m_MaxHealth;
- }
+ m_Health = std::min(m_Health, m_MaxHealth);
}
@@ -555,7 +552,7 @@ void cEntity::Heal(int a_HitPoints)
void cEntity::SetHealth(int a_Health)
{
- m_Health = std::max(0, std::min(m_MaxHealth, a_Health));
+ m_Health = Clamp(a_Health, 0, m_MaxHealth);
}
@@ -1264,10 +1261,10 @@ void cEntity::HandleAir(void)
SetSpeedY(1); // Float in the water
}
- // Either reduce air level or damage player
- if (m_AirLevel < 1)
+ if (m_AirLevel <= 0)
{
- if (m_AirTickTimer < 1)
+ // Either reduce air level or damage player
+ if (m_AirTickTimer <= 0)
{
// Damage player
TakeDamage(dtDrowning, NULL, 1, 1, 0);
@@ -1552,17 +1549,10 @@ void cEntity::SetHeight(double a_Height)
void cEntity::SetMass(double a_Mass)
{
- if (a_Mass > 0)
- {
- m_Mass = 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
- // less than 1g as long as is NOT equal or less than zero.
- m_Mass = 0.001;
- }
+ // 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 = std::max(a_Mass, 0.001);
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index d3d5a61d4..d1d7349a6 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -527,7 +527,7 @@ void cPlayer::SetFoodLevel(int a_FoodLevel)
void cPlayer::SetFoodSaturationLevel(double a_FoodSaturationLevel)
{
- m_FoodSaturationLevel = std::max(0.0, std::min(a_FoodSaturationLevel, (double)m_FoodLevel));
+ m_FoodSaturationLevel = Clamp(a_FoodSaturationLevel, 0.0, (double) m_FoodLevel);
}
@@ -545,7 +545,7 @@ void cPlayer::SetFoodTickTimer(int a_FoodTickTimer)
void cPlayer::SetFoodExhaustionLevel(double a_FoodExhaustionLevel)
{
- m_FoodExhaustionLevel = std::max(0.0, std::min(a_FoodExhaustionLevel, 40.0));
+ m_FoodExhaustionLevel = Clamp(a_FoodExhaustionLevel, 0.0, 40.0);
}
@@ -700,16 +700,13 @@ double cPlayer::GetMaxSpeed(void) const
{
return m_FlyingMaxSpeed;
}
+ else if (m_IsSprinting)
+ {
+ return m_SprintingMaxSpeed;
+ }
else
{
- if (m_IsSprinting)
- {
- return m_SprintingMaxSpeed;
- }
- else
- {
- return m_NormalMaxSpeed;
- }
+ return m_NormalMaxSpeed;
}
}