diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-09-11 23:20:49 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-09-11 23:20:49 +0200 |
commit | e225b7f8262df48ad4d7094bc295add3007b0649 (patch) | |
tree | a42e9afcc88cfe6e9d1258458e3ad42764083d0e /src/Entities/SplashPotionEntity.cpp | |
parent | cBlockArea: change MakeIndex to return size_t (diff) | |
download | cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.gz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.bz2 cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.lz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.xz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.zst cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.zip |
Diffstat (limited to 'src/Entities/SplashPotionEntity.cpp')
-rw-r--r-- | src/Entities/SplashPotionEntity.cpp | 80 |
1 files changed, 24 insertions, 56 deletions
diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index 8356806b3..15be9706e 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -17,60 +17,6 @@ //////////////////////////////////////////////////////////////////////////////// -// cSplashPotionEntityCallback: - -/** Used to distribute the splashed potion effect among nearby entities */ -class cSplashPotionCallback : - public cEntityCallback -{ -public: - /** Creates the callback. - @param a_HitPos The position where the splash potion has splashed - @param a_EntityEffectType The effect type of the potion - @param a_EntityEffect The effect description */ - cSplashPotionCallback(Vector3d a_HitPos, cEntityEffect::eType a_EntityEffectType, const cEntityEffect & a_EntityEffect) : - m_HitPos(a_HitPos), - m_EntityEffectType(a_EntityEffectType), - m_EntityEffect(a_EntityEffect) - { - } - - /** Called by cWorld::ForEachEntity(), adds the stored entity effect to the entity, if it is close enough. */ - virtual bool Item(cEntity * a_Entity) override - { - if (!a_Entity->IsPawn()) - { - // Not an entity that can take effects - return false; - } - - double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length(); - if (SplashDistance >= 20) - { - // Too far away - return false; - } - - // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash. - // TODO: better equation - double Reduction = -0.25 * SplashDistance + 1.0; - Reduction = std::max(Reduction, 0.0); - - static_cast<cPawn *>(a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction); - return false; - } - -private: - Vector3d m_HitPos; - cEntityEffect::eType m_EntityEffectType; - const cEntityEffect & m_EntityEffect; -}; - - - - - -//////////////////////////////////////////////////////////////////////////////// // cSplashPotionEntity: cSplashPotionEntity::cSplashPotionEntity( @@ -119,8 +65,30 @@ void cSplashPotionEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) void cSplashPotionEntity::Splash(Vector3d a_HitPos) { - cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect); - m_World->ForEachEntity(Callback); + m_World->ForEachEntity([=](cEntity & a_Entity) + { + if (!a_Entity.IsPawn()) + { + // Not an entity that can take effects + return false; + } + + double SplashDistance = (a_Entity.GetPosition() - a_HitPos).Length(); + if (SplashDistance >= 20) + { + // Too far away + return false; + } + + // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash. + // TODO: better equation + double Reduction = -0.25 * SplashDistance + 1.0; + Reduction = std::max(Reduction, 0.0); + + static_cast<cPawn &>(a_Entity).AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction); + return false; + } + ); m_World->BroadcastSoundParticleEffect( EffectID::PARTICLE_SPLASH_POTION, |