From 84462ba8b20c28136c6a7923323f7cde28a86d70 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 31 Jul 2014 23:04:00 +0200 Subject: Fixed hunger bugs, Implemented golden apple, added jump statistic, added correct food effects. --- src/Entities/EntityEffect.cpp | 2 +- src/Entities/Player.cpp | 53 +++++++++++++++++++++++++++++-------------- src/Entities/Player.h | 5 +--- 3 files changed, 38 insertions(+), 22 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index fdcbe822e..39314f256 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -309,7 +309,7 @@ void cEntityEffectHunger::OnTick(cPawn & a_Target) if (a_Target.IsPlayer()) { cPlayer & Target = (cPlayer &) a_Target; - Target.SetFoodExhaustionLevel(Target.GetFoodExhaustionLevel() + 0.025); // 0.5 per second = 0.025 per tick + Target.AddFoodExhaustion(0.025 * ((double)GetIntensity() + 1.0)); // 0.5 per second = 0.025 per tick } } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 603fc7937..c9d885b89 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -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, 4.0)); + m_FoodExhaustionLevel = std::max(0.0, std::min(a_FoodExhaustionLevel, 40.0)); } @@ -568,6 +568,18 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) +void cPlayer::AddFoodExhaustion(double a_Exhaustion) +{ + if (!IsGameModeCreative()) + { + m_FoodExhaustionLevel = std::min(m_FoodExhaustionLevel + a_Exhaustion, 40.0); + } +} + + + + + void cPlayer::FoodPoison(int a_NumTicks) { AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0, 1); @@ -1979,19 +1991,34 @@ void cPlayer::HandleFood(void) return; } + // Apply food exhaustion that has accumulated: + if (m_FoodExhaustionLevel > 4.0) + { + m_FoodExhaustionLevel -= 4.0; + + if (m_FoodSaturationLevel > 0.0) + { + m_FoodSaturationLevel = std::max(m_FoodSaturationLevel - 1.0, 0.0); + } + else + { + SetFoodLevel(m_FoodLevel - 1); + } + } + // Heal or damage, based on the food level, using the m_FoodTickTimer: - if ((m_FoodLevel > 17) || (m_FoodLevel <= 0)) + if ((m_FoodLevel >= 18) || (m_FoodLevel <= 0)) { m_FoodTickTimer++; if (m_FoodTickTimer >= 80) { m_FoodTickTimer = 0; - if ((m_FoodLevel > 17) && (GetHealth() < GetMaxHealth())) + if ((m_FoodLevel >= 18) && (GetHealth() < GetMaxHealth())) { // Regenerate health from food, incur 3 pts of food exhaustion: Heal(1); - m_FoodExhaustionLevel += 3.0; + AddFoodExhaustion(3.0); } else if ((m_FoodLevel <= 0) && (m_Health > 1)) { @@ -2000,20 +2027,9 @@ void cPlayer::HandleFood(void) } } } - - // Apply food exhaustion that has accumulated: - if (m_FoodExhaustionLevel >= 4.0) + else { - m_FoodExhaustionLevel -= 4.0; - - if (m_FoodSaturationLevel >= 1.0) - { - m_FoodSaturationLevel -= 1.0; - } - else - { - SetFoodLevel(m_FoodLevel - 1); - } + m_FoodTickTimer = 0; } } @@ -2088,14 +2104,17 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos) else if (IsSubmerged()) { m_Stats.AddValue(statDistDove, Value); + AddFoodExhaustion(0.00015 * (double)Value); } else if (IsSwimming()) { m_Stats.AddValue(statDistSwum, Value); + AddFoodExhaustion(0.00015 * (double)Value); } else if (IsOnGround()) { m_Stats.AddValue(statDistWalked, Value); + AddFoodExhaustion((m_IsSprinting ? 0.001 : 0.0001) * (double)Value); } else { diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 65c1e33a8..f188789b8 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -284,10 +284,7 @@ public: bool Feed(int a_Food, double a_Saturation); /** Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values. */ - void AddFoodExhaustion(double a_Exhaustion) - { - m_FoodExhaustionLevel += a_Exhaustion; - } + void AddFoodExhaustion(double a_Exhaustion); /** Starts the food poisoning for the specified amount of ticks */ void FoodPoison(int a_NumTicks); -- cgit v1.2.3