diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-08-01 19:51:43 +0200 |
---|---|---|
committer | Lukas Pioch <lukas@zgow.de> | 2017-08-03 15:34:38 +0200 |
commit | 79eb4c3aed59edce58d2529bf9c6334f7fe6fbad (patch) | |
tree | 1c572f4c9939968abbcb3ec6b9d6d9630b1f900a /src/Entities/Pawn.cpp | |
parent | Remove double includes part 2 (#3890) (diff) | |
download | cuberite-79eb4c3aed59edce58d2529bf9c6334f7fe6fbad.tar cuberite-79eb4c3aed59edce58d2529bf9c6334f7fe6fbad.tar.gz cuberite-79eb4c3aed59edce58d2529bf9c6334f7fe6fbad.tar.bz2 cuberite-79eb4c3aed59edce58d2529bf9c6334f7fe6fbad.tar.lz cuberite-79eb4c3aed59edce58d2529bf9c6334f7fe6fbad.tar.xz cuberite-79eb4c3aed59edce58d2529bf9c6334f7fe6fbad.tar.zst cuberite-79eb4c3aed59edce58d2529bf9c6334f7fe6fbad.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Entities/Pawn.cpp | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 0a9abcdc1..a0095a8a4 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -55,7 +55,7 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { // Copies values to prevent pesky wrong accesses and erasures cEntityEffect::eType EffectType = iter->first; - cEntityEffect * Effect = iter->second; + cEntityEffect * Effect = iter->second.get(); // Iterates (must be called before any possible erasure) ++iter; @@ -157,6 +157,15 @@ bool cPawn::IsFireproof(void) const +bool cPawn::IsInvisible() const +{ + return HasEntityEffect(cEntityEffect::effInvisibility); +} + + + + + void cPawn::HandleAir(void) { if (IsSubmerged() && HasEntityEffect(cEntityEffect::effWaterBreathing)) @@ -188,9 +197,10 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, s } a_Duration = static_cast<int>(a_Duration * a_DistanceModifier); - m_EntityEffects[a_EffectType] = cEntityEffect::CreateEntityEffect(a_EffectType, a_Duration, a_Intensity, a_DistanceModifier); + auto Res = m_EntityEffects.emplace(a_EffectType, cEntityEffect::CreateEntityEffect(a_EffectType, a_Duration, a_Intensity, a_DistanceModifier)); m_World->BroadcastEntityEffect(*this, a_EffectType, a_Intensity, static_cast<short>(a_Duration)); - m_EntityEffects[a_EffectType]->OnActivate(*this); + cEntityEffect * Effect = Res.first->second.get(); + Effect->OnActivate(*this); } @@ -200,9 +210,14 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, s void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType) { m_World->BroadcastRemoveEntityEffect(*this, a_EffectType); - m_EntityEffects[a_EffectType]->OnDeactivate(*this); - delete m_EntityEffects[a_EffectType]; - m_EntityEffects.erase(a_EffectType); + auto itr = m_EntityEffects.find(a_EffectType); + if (itr != m_EntityEffects.end()) + { + // Erase from effect map before calling OnDeactivate to allow metadata broadcasts (e.g. for invisibility effect) + auto Effect = std::move(itr->second); + m_EntityEffects.erase(itr); + Effect->OnDeactivate(*this); + } } @@ -459,16 +474,22 @@ void cPawn::StopEveryoneFromTargetingMe() std::map<cEntityEffect::eType, cEntityEffect *> cPawn::GetEntityEffects() { - return m_EntityEffects; + std::map<cEntityEffect::eType, cEntityEffect *> Effects; + for (auto & Effect : m_EntityEffects) + { + Effects.insert({ Effect.first, Effect.second.get() }); + } + return Effects; } -cEntityEffect *cPawn::GetEntityEffect(cEntityEffect::eType a_EffectType) +cEntityEffect * cPawn::GetEntityEffect(cEntityEffect::eType a_EffectType) { - return m_EntityEffects.at(a_EffectType); + auto itr = m_EntityEffects.find(a_EffectType); + return (itr != m_EntityEffects.end()) ? itr->second.get() : nullptr; } |