diff options
author | madmaxoft <github@xoft.cz> | 2014-06-13 11:04:16 +0200 |
---|---|---|
committer | archshift <admin@archshift.com> | 2014-06-17 20:39:21 +0200 |
commit | e289fe4dd7372a029ba85722e3ce99991e9d1d6b (patch) | |
tree | 1bc8ad0d0aa8a7e8685a53bddb0730c4a82122a4 | |
parent | Entity Effect: Separates total duration and ticks of activity (diff) | |
download | cuberite-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 '')
-rw-r--r-- | src/Entities/EntityEffects.h | 27 | ||||
-rw-r--r-- | src/Entities/Pawn.cpp | 33 | ||||
-rw-r--r-- | src/Entities/Pawn.h | 16 | ||||
-rw-r--r-- | src/Entities/Player.cpp | 2 | ||||
-rw-r--r-- | src/Entities/SplashPotionEntity.cpp | 19 | ||||
-rw-r--r-- | src/Items/ItemPotion.h | 3 | ||||
-rw-r--r-- | src/Mobs/CaveSpider.cpp | 2 |
7 files changed, 52 insertions, 50 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; } + + + + diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h index 200c13cab..70a926cad 100644 --- a/src/Items/ItemPotion.h +++ b/src/Items/ItemPotion.h @@ -146,8 +146,7 @@ public: virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override { // Called when potion is a drinkable potion - short potion_damage = a_Item->m_ItemDamage; - a_Player->AddEntityEffect(GetEntityEffectType(potion_damage), cEntityEffect(GetEntityEffectDuration(potion_damage), GetEntityEffectIntensity(potion_damage), a_Player)); + a_Player->AddEntityEffect(GetEntityEffectType(a_Item->m_ItemDamage), GetEntityEffectDuration(a_Item->m_ItemDamage), GetEntityEffectIntensity(a_Item->m_ItemDamage)); a_Player->GetInventory().RemoveOneEquippedItem(); a_Player->GetInventory().AddItem(E_ITEM_GLASS_BOTTLE); return true; diff --git a/src/Mobs/CaveSpider.cpp b/src/Mobs/CaveSpider.cpp index fe0f2ac73..118a6e93b 100644 --- a/src/Mobs/CaveSpider.cpp +++ b/src/Mobs/CaveSpider.cpp @@ -34,7 +34,7 @@ void cCaveSpider::Attack(float a_Dt) if (m_Target->IsPawn()) { // TODO: Easy = no poison, Medium = 7 seconds, Hard = 15 seconds - ((cPawn *) m_Target)->AddEntityEffect(cEntityEffect::effPoison, cEntityEffect(140, 0, this)); + ((cPawn *) m_Target)->AddEntityEffect(cEntityEffect::effPoison, 7 * 20, 0); } } |