summaryrefslogtreecommitdiffstats
path: root/src/Entities/Pawn.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-06-13 11:04:16 +0200
committerarchshift <admin@archshift.com>2014-06-17 20:39:21 +0200
commite289fe4dd7372a029ba85722e3ce99991e9d1d6b (patch)
tree1bc8ad0d0aa8a7e8685a53bddb0730c4a82122a4 /src/Entities/Pawn.cpp
parentEntity Effect: Separates total duration and ticks of activity (diff)
downloadcuberite-e289fe4dd7372a029ba85722e3ce99991e9d1d6b.tar
cuberite-e289fe4dd7372a029ba85722e3ce99991e9d1d6b.tar.gz
cuberite-e289fe4dd7372a029ba85722e3ce99991e9d1d6b.tar.bz2
cuberite-e289fe4dd7372a029ba85722e3ce99991e9d1d6b.tar.lz
cuberite-e289fe4dd7372a029ba85722e3ce99991e9d1d6b.tar.xz
cuberite-e289fe4dd7372a029ba85722e3ce99991e9d1d6b.tar.zst
cuberite-e289fe4dd7372a029ba85722e3ce99991e9d1d6b.zip
Diffstat (limited to 'src/Entities/Pawn.cpp')
-rw-r--r--src/Entities/Pawn.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp
index 0273981f9..ec829f6f8 100644
--- a/src/Entities/Pawn.cpp
+++ b/src/Entities/Pawn.cpp
@@ -8,9 +8,9 @@
-cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height)
- : cEntity(a_EntityType, 0, 0, 0, a_Width, a_Height)
- , m_EntityEffects(tEffectMap())
+cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height):
+ super(a_EntityType, 0, 0, 0, a_Width, a_Height),
+ m_EntityEffects(tEffectMap())
{
}
@@ -24,22 +24,22 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk)
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;
+ cEntityEffect::eType EffectType = iter->first;
+ cEntityEffect & EffectValues = iter->second;
// Apply entity effect
- HandleEntityEffect(effect_type, effect_values);
+ HandleEntityEffect(EffectType, EffectValues);
- // Increase the effect's tick counter
- effect_values.m_Ticks++;
+ // Reduce the effect's duration
+ EffectValues.m_Ticks++;
// Iterates (must be called before any possible erasure)
++iter;
// Remove effect if duration has elapsed
- if (effect_values.GetDuration() - effect_values.m_Ticks <= 0)
+ if (EffectValues.GetDuration() - EffectValues.m_Ticks <= 0)
{
- RemoveEntityEffect(effect_type);
+ RemoveEntityEffect(EffectType);
}
// TODO: Check for discrepancies between client and server effect values
@@ -52,7 +52,7 @@ void cPawn::Tick(float a_Dt, cChunk & a_Chunk)
-void cPawn::KilledBy(cEntity *a_Killer)
+void cPawn::KilledBy(cEntity * a_Killer)
{
ClearEntityEffects();
}
@@ -61,16 +61,15 @@ void cPawn::KilledBy(cEntity *a_Killer)
-void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect)
+void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier)
{
if (a_EffectType == cEntityEffect::effNoEffect)
{
return;
}
- a_Effect.SetDuration(a_Effect.GetDuration() * a_Effect.GetDistanceModifier());
- m_EntityEffects[a_EffectType] = a_Effect;
- m_World->BroadcastEntityEffect(*this, a_EffectType, a_Effect.GetIntensity(), a_Effect.GetDuration());
+ m_EntityEffects[a_EffectType] = cEntityEffect(a_EffectDurationTicks, a_EffectIntensity, this, a_DistanceModifier);
+ m_World->BroadcastEntityEffect(*this, a_EffectType, a_EffectIntensity, (short)(a_EffectDurationTicks * a_DistanceModifier));
}
@@ -93,13 +92,13 @@ void cPawn::ClearEntityEffects()
for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
{
// Copy values to prevent pesky wrong erasures
- cEntityEffect::eType effect_type = iter->first;
+ cEntityEffect::eType EffectType = iter->first;
// Iterates (must be called before any possible erasure)
++iter;
// Remove effect
- RemoveEntityEffect(effect_type);
+ RemoveEntityEffect(EffectType);
}
}