From 061010288a99fd11f91bf713ac68068c57f79be7 Mon Sep 17 00:00:00 2001 From: archshift Date: Mon, 14 Jul 2014 13:46:15 -0700 Subject: Readability and clarity changes --- src/Entities/Entity.cpp | 9 ++++++--- src/Entities/EntityEffect.cpp | 41 ++++++++++++++++------------------------- src/Entities/EntityEffect.h | 2 +- 3 files changed, 23 insertions(+), 29 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 042c4b4c3..670e8420a 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -311,10 +311,13 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) // IsOnGround() only is false if the player is moving downwards // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain) - if (!Player->IsOnGround() && (a_TDI.DamageType == dtAttack || a_TDI.DamageType == dtArrowAttack)) + if (!Player->IsOnGround()) { - a_TDI.FinalDamage += 2; - m_World->BroadcastEntityAnimation(*this, 4); // Critical hit + if ((a_TDI.DamageType == dtAttack) || (a_TDI.DamageType == dtArrowAttack)) + { + a_TDI.FinalDamage += 2; + m_World->BroadcastEntityAnimation(*this, 4); // Critical hit + } } Player->GetStatManager().AddValue(statDamageDealt, (StatValue)floor(a_TDI.FinalDamage * 10 + 0.5)); diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index 852099b79..12dd17d72 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -113,15 +113,12 @@ void cEntityEffect::OnTick(cPawn & a_Target) void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) { // Base amount = 6, doubles for every increase in intensity - int amount = (int)(6 * std::pow(2.0, m_Intensity) * m_DistanceModifier); + int amount = (int)(6 * (1 << m_Intensity) * m_DistanceModifier); - if (a_Target.IsMob()) + if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead()) { - if (((cMonster &) a_Target).IsUndead()) - { - a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage - return; - } + a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage + return; } a_Target.Heal(amount); } @@ -136,15 +133,12 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target) void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target) { // Base amount = 6, doubles for every increase in intensity - int amount = (int)(6 * std::pow(2.0, m_Intensity) * m_DistanceModifier); + int amount = (int)(6 * (1 << m_Intensity) * m_DistanceModifier); - if (a_Target.IsMob()) + if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead()) { - if (((cMonster &) a_Target).IsUndead()) - { - a_Target.Heal(amount); - return; - } + a_Target.Heal(amount); + return; } a_Target.TakeDamage(dtPotionOfHarming, NULL, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage } @@ -160,18 +154,15 @@ void cEntityEffectRegeneration::OnTick(cPawn & a_Target) { super::OnTick(a_Target); - if (a_Target.IsMob()) + if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead()) { - if (((cMonster &) a_Target).IsUndead()) - { - return; - } + return; } // Regen frequency = 50 ticks, divided by potion level (Regen II = 25 ticks) int frequency = (int) std::floor(50.0 / (double)(m_Intensity + 1)); - if (m_Ticks % frequency != 0) + if ((m_Ticks % frequency) != 0) { return; } @@ -231,9 +222,9 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) cMonster & Target = (cMonster &) a_Target; // Doesn't effect undead mobs, spiders - if (Target.IsUndead() - || Target.GetMobType() == cMonster::mtSpider - || Target.GetMobType() == cMonster::mtCaveSpider) + if ((Target.IsUndead()) + || (Target.GetMobType() == cMonster::mtSpider) + || (Target.GetMobType() == cMonster::mtCaveSpider)) { return; } @@ -242,7 +233,7 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target) // Poison frequency = 25 ticks, divided by potion level (Poison II = 12 ticks) int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1)); - if (m_Ticks % frequency == 0) + if ((m_Ticks % frequency) == 0) { // Cannot take poison damage when health is at 1 if (a_Target.GetHealth() > 1) @@ -266,7 +257,7 @@ void cEntityEffectWither::OnTick(cPawn & a_Target) // Poison frequency = 40 ticks, divided by effect level (Wither II = 20 ticks) int frequency = (int) std::floor(25.0 / (double)(m_Intensity + 1)); - if (m_Ticks % frequency == 0) + if ((m_Ticks % frequency) == 0) { a_Target.TakeDamage(dtWither, NULL, 1, 0); } diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h index c6532a9bd..ea0716d59 100644 --- a/src/Entities/EntityEffect.h +++ b/src/Entities/EntityEffect.h @@ -220,7 +220,7 @@ class cEntityEffectNausea: typedef cEntityEffect super; public: cEntityEffectNausea(int a_Duration, short a_Intensity, double a_DistanceModifier = 1): - super(a_Duration, a_Intensity, a_DistanceModifier) + super(a_Duration, a_Intensity, a_DistanceModifier) { } }; -- cgit v1.2.3