summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/EntityEffects.h27
-rw-r--r--src/Entities/Pawn.cpp33
-rw-r--r--src/Entities/Pawn.h16
-rw-r--r--src/Entities/Player.cpp2
-rw-r--r--src/Entities/SplashPotionEntity.cpp19
5 files changed, 50 insertions, 47 deletions
diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h
index 6b2532aae..c0e8abd28 100644
--- a/src/Entities/EntityEffects.h
+++ b/src/Entities/EntityEffects.h
@@ -3,7 +3,8 @@
class cPawn;
// tolua_begin
-class cEntityEffect {
+class cEntityEffect
+{
public:
/** All types of entity effects (numbers correspond to IDs) */
@@ -52,25 +53,21 @@ public:
void SetDuration(int a_Duration) { m_Duration = a_Duration; }
void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; }
- void SetUser(cPawn *a_User) { m_User = a_User; }
+ void SetUser(cPawn * a_User) { m_User = a_User; }
void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; }
- /**
- * An empty entity effect
- */
- cEntityEffect();
+ /** Creates an empty entity effect */
+ cEntityEffect(void);
- /**
- * An entity effect
- * @param a_Duration How long this effect will last
- * @param a_Intensity How strong the effect will be applied
- * @param a_User The pawn that used this entity effect
- * @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1
- */
- cEntityEffect(int a_Duration, short a_Intensity, cPawn *a_User, double a_DistanceModifier = 1);
+ /** Creates an entity effect of the specified type
+ @param a_Duration How long this effect will last, in ticks
+ @param a_Intensity How strong the effect will be applied
+ @param a_User The pawn that used this entity effect
+ @param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */
+ cEntityEffect(int a_Duration, short a_Intensity, cPawn * a_User, double a_DistanceModifier = 1);
private:
- /** How long this effect will last */
+ /** How long this effect will last, in ticks */
int m_Duration;
/** How strong the effect will be applied */
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);
}
}
diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h
index 2ffdd9fbb..399e02e64 100644
--- a/src/Entities/Pawn.h
+++ b/src/Entities/Pawn.h
@@ -24,19 +24,21 @@ public:
virtual void KilledBy(cEntity * a_Killer) override;
// tolua_begin
+
/** Applies an entity effect
- * @param a_EffectType The entity effect to apply
- * @param a_Effect The parameters of the effect
- */
- void AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect);
+ @param a_EffectType The entity effect to apply
+ @param a_Effect The parameters of the effect
+ */
+ void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier = 1);
/** Removes a currently applied entity effect
- * @param a_EffectType The entity effect to remove
- */
+ @param a_EffectType The entity effect to remove
+ */
void RemoveEntityEffect(cEntityEffect::eType a_EffectType);
/** Removes all currently applied entity effects (used when drinking milk) */
- void ClearEntityEffects();
+ void ClearEntityEffects(void);
+
// tolua_end
protected:
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 5d8c3479b..f2ec81957 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::effHunger, cEntityEffect(a_NumTicks, 0, NULL));
+ AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0);
}
diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp
index 5574ea53c..4035b4794 100644
--- a/src/Entities/SplashPotionEntity.cpp
+++ b/src/Entities/SplashPotionEntity.cpp
@@ -67,20 +67,25 @@ cSplashPotionEntity::cSplashPotionCallback::cSplashPotionCallback(const Vector3d
bool cSplashPotionEntity::cSplashPotionCallback::Item(cEntity * a_Entity)
{
- double distance_splash = (a_Entity->GetPosition() - m_HitPos).Length();
- if (distance_splash < 20)
+ double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length();
+ if (SplashDistance < 20)
{
// y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash.
// TODO: better equation
- double reduction = -0.25 * distance_splash + 1.0;
- if (reduction < 0) reduction = 0;
-
- m_EntityEffect.SetDistanceModifier(reduction);
+ double Reduction = -0.25 * SplashDistance + 1.0;
+ if (Reduction < 0)
+ {
+ Reduction = 0;
+ }
if (a_Entity->IsPawn())
{
- ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect);
+ ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.m_Ticks, m_EntityEffect.GetIntensity(), Reduction);
}
}
return false;
}
+
+
+
+