diff options
author | archshift <admin@archshift.com> | 2014-06-07 11:02:20 +0200 |
---|---|---|
committer | archshift <admin@archshift.com> | 2014-06-17 20:39:19 +0200 |
commit | 615152eb8c6c88083f7b9eac57ec07147f34a6d6 (patch) | |
tree | 84b9ef883dfa0a814fbcfd0246613b9ce5f5674e | |
parent | Pawn: Enabled entity effect broadcast, added typedef (diff) | |
download | cuberite-615152eb8c6c88083f7b9eac57ec07147f34a6d6.tar cuberite-615152eb8c6c88083f7b9eac57ec07147f34a6d6.tar.gz cuberite-615152eb8c6c88083f7b9eac57ec07147f34a6d6.tar.bz2 cuberite-615152eb8c6c88083f7b9eac57ec07147f34a6d6.tar.lz cuberite-615152eb8c6c88083f7b9eac57ec07147f34a6d6.tar.xz cuberite-615152eb8c6c88083f7b9eac57ec07147f34a6d6.tar.zst cuberite-615152eb8c6c88083f7b9eac57ec07147f34a6d6.zip |
-rw-r--r-- | src/Entities/Pawn.cpp | 21 | ||||
-rw-r--r-- | src/Entities/Player.cpp | 2 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 1f93e59fa..93f6a69bc 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -10,7 +10,7 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) : cEntity(a_EntityType, 0, 0, 0, a_Width, a_Height) - , m_EntityEffects(std::map<cEntityEffect::eType, cEntityEffect>()) + , m_EntityEffects(tEffectMap()) { } @@ -21,20 +21,25 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) void cPawn::Tick(float a_Dt, cChunk & a_Chunk) { // Iterate through this entity's applied effects - for (tEffectMap::iterator iter = m_EntityEffects.begin(); - iter != m_EntityEffects.end(); - ++iter) + for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();) { + // Copies values to prevent pesky wrong accesses and erasures + cEntityEffect::eType effect_type = iter->first; + cEntityEffect &effect_values = iter->second; + // Apply entity effect - HandleEntityEffects(iter->first, iter->second); + HandleEntityEffects(effect_type, effect_values); // Reduce the effect's duration - iter->second.m_Ticks--; + effect_values.m_Ticks--; + + // Iterates (must be called before any possible erasure) + ++iter; // Remove effect if duration has elapsed - if (iter->second.m_Ticks <= 0) + if (effect_values.m_Ticks <= 0) { - RemoveEntityEffect(iter->first); + RemoveEntityEffect(effect_type); } // TODO: Check for discrepancies between client and server effect values diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index d075957fe..67449f800 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -570,7 +570,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) void cPlayer::FoodPoison(int a_NumTicks) { - AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(0, a_NumTicks, NULL)); + AddEntityEffect(cEntityEffect::efHunger, cEntityEffect(a_NumTicks, 0, NULL)); } |