1
0
This commit is contained in:
STRWarrior 2014-08-03 15:32:45 +02:00
commit a24e960a89
3 changed files with 74 additions and 105 deletions

View File

@ -543,10 +543,7 @@ void cEntity::KilledBy(TakeDamageInfo & a_TDI)
void cEntity::Heal(int a_HitPoints) void cEntity::Heal(int a_HitPoints)
{ {
m_Health += a_HitPoints; m_Health += a_HitPoints;
if (m_Health > m_MaxHealth) m_Health = std::min(m_Health, m_MaxHealth);
{
m_Health = m_MaxHealth;
}
} }
@ -555,7 +552,7 @@ void cEntity::Heal(int a_HitPoints)
void cEntity::SetHealth(int a_Health) 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);
} }
@ -1068,9 +1065,7 @@ bool cEntity::DetectPortal()
} }
m_PortalCooldownData.m_TicksDelayed = 0; m_PortalCooldownData.m_TicksDelayed = 0;
switch (GetWorld()->GetDimension()) if (GetWorld()->GetDimension() == dimNether)
{
case dimNether:
{ {
if (GetWorld()->GetLinkedOverworldName().empty()) if (GetWorld()->GetLinkedOverworldName().empty())
{ {
@ -1086,7 +1081,7 @@ bool cEntity::DetectPortal()
return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false); return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
} }
case dimOverworld: else
{ {
if (GetWorld()->GetNetherWorldName().empty()) if (GetWorld()->GetNetherWorldName().empty())
{ {
@ -1103,8 +1098,6 @@ bool cEntity::DetectPortal()
return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetNetherWorldName(), dimNether, GetWorld()->GetName()), false); return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetNetherWorldName(), dimNether, GetWorld()->GetName()), false);
} }
default: return false;
}
} }
case E_BLOCK_END_PORTAL: case E_BLOCK_END_PORTAL:
{ {
@ -1113,10 +1106,9 @@ bool cEntity::DetectPortal()
return false; return false;
} }
switch (GetWorld()->GetDimension()) if (GetWorld()->GetDimension() == dimEnd)
{
case dimEnd:
{ {
if (GetWorld()->GetLinkedOverworldName().empty()) if (GetWorld()->GetLinkedOverworldName().empty())
{ {
return false; return false;
@ -1133,7 +1125,7 @@ bool cEntity::DetectPortal()
return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false); return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
} }
case dimOverworld: else
{ {
if (GetWorld()->GetEndWorldName().empty()) if (GetWorld()->GetEndWorldName().empty())
{ {
@ -1150,8 +1142,7 @@ bool cEntity::DetectPortal()
return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetEndWorldName(), dimEnd, GetWorld()->GetName()), false); return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetEndWorldName(), dimEnd, GetWorld()->GetName()), false);
} }
default: return false;
}
} }
default: break; default: break;
} }
@ -1270,10 +1261,10 @@ void cEntity::HandleAir(void)
SetSpeedY(1); // Float in the water SetSpeedY(1); // Float in the water
} }
// Either reduce air level or damage player if (m_AirLevel <= 0)
if (m_AirLevel < 1)
{ {
if (m_AirTickTimer < 1) // Runs the air tick timer to check whether the player should be damaged
if (m_AirTickTimer <= 0)
{ {
// Damage player // Damage player
TakeDamage(dtDrowning, NULL, 1, 1, 0); TakeDamage(dtDrowning, NULL, 1, 1, 0);
@ -1557,18 +1548,11 @@ void cEntity::SetHeight(double a_Height)
void cEntity::SetMass(double a_Mass) 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 // 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 // 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. // less than 1g as long as is NOT equal or less than zero.
m_Mass = 0.001; m_Mass = std::max(a_Mass, 0.001);
}
} }

View File

@ -527,7 +527,7 @@ void cPlayer::SetFoodLevel(int a_FoodLevel)
void cPlayer::SetFoodSaturationLevel(double a_FoodSaturationLevel) 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) 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);
} }
@ -580,15 +580,6 @@ void cPlayer::AddFoodExhaustion(double a_Exhaustion)
void cPlayer::FoodPoison(int a_NumTicks)
{
AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0, 1);
}
void cPlayer::StartEating(void) void cPlayer::StartEating(void)
{ {
// Set the timer: // Set the timer:
@ -709,9 +700,7 @@ double cPlayer::GetMaxSpeed(void) const
{ {
return m_FlyingMaxSpeed; return m_FlyingMaxSpeed;
} }
else else if (m_IsSprinting)
{
if (m_IsSprinting)
{ {
return m_SprintingMaxSpeed; return m_SprintingMaxSpeed;
} }
@ -720,7 +709,6 @@ double cPlayer::GetMaxSpeed(void) const
return m_NormalMaxSpeed; return m_NormalMaxSpeed;
} }
} }
}

View File

@ -286,9 +286,6 @@ public:
/** Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values. */ /** Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values. */
void AddFoodExhaustion(double a_Exhaustion); void AddFoodExhaustion(double a_Exhaustion);
/** Starts the food poisoning for the specified amount of ticks */
void FoodPoison(int a_NumTicks);
/** Returns true if the player is currently in the process of eating the currently equipped item */ /** Returns true if the player is currently in the process of eating the currently equipped item */
bool IsEating(void) const { return (m_EatingFinishTick >= 0); } bool IsEating(void) const { return (m_EatingFinishTick >= 0); }