diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 4fe86e1c5..4a6eb7535 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -40,7 +40,7 @@ $cfile "../Entities/Painting.h" $cfile "../Entities/Pickup.h" $cfile "../Entities/ProjectileEntity.h" $cfile "../Entities/TNTEntity.h" -$cfile "../Entities/Effects.h" +$cfile "../Entities/EntityEffects.h" $cfile "../Server.h" $cfile "../World.h" $cfile "../Inventory.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 335ce8315..3d5a0e396 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,7 +42,7 @@ set(BINDING_DEPENDECIES Cuboid.h Defines.h Enchantments.h - Entities/Effects.h + Entities/EntityEffects.h Entities/Entity.h Entities/Floater.h Entities/Pawn.h diff --git a/src/Entities/Effects.h b/src/Entities/Effects.h deleted file mode 100644 index baf3302fb..000000000 --- a/src/Entities/Effects.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -// tolua_begin -enum ENUM_ENTITY_EFFECT -{ - E_EFFECT_SPEED = 1, - E_EFFECT_SLOWNESS = 2, - E_EFFECT_HASTE = 3, - E_EFFECT_MINING_FATIGUE = 4, - E_EFFECT_STENGTH = 5, - E_EFFECT_INSTANT_HEALTH = 6, - E_EFFECT_INSTANT_DAMAGE = 7, - E_EFFECT_JUMP_BOOST = 8, - E_EFFECT_NAUSEA = 9, - E_EFFECT_REGENERATION = 10, - E_EFFECT_RESISTANCE = 11, - E_EFFECT_FIRE_RESISTANCE = 12, - E_EFFECT_WATER_BREATHING = 13, - E_EFFECT_INVISIBILITY = 14, - E_EFFECT_BLINDNESS = 15, - E_EFFECT_NIGHT_VISION = 16, - E_EFFECT_HUNGER = 17, - E_EFFECT_WEAKNESS = 18, - E_EFFECT_POISON = 19, - E_EFFECT_WITHER = 20, - E_EFFECT_HEALTH_BOOST = 21, - E_EFFECT_ABSORPTION = 22, - E_EFFECT_SATURATION = 23, -} ; -// tolua_end diff --git a/src/Entities/EntityEffects.cpp b/src/Entities/EntityEffects.cpp new file mode 100644 index 000000000..3aa3fd1ed --- /dev/null +++ b/src/Entities/EntityEffects.cpp @@ -0,0 +1,25 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "EntityEffects.h" + + + + + +cEntityEffect::cEntityEffect(): + m_Ticks(0), + m_Intensity(0) +{ + +} + + + + + +cEntityEffect::cEntityEffect(int a_Ticks, short a_Intensity): + m_Ticks(a_Ticks), + m_Intensity(a_Intensity) +{ + +} diff --git a/src/Entities/EntityEffects.h b/src/Entities/EntityEffects.h new file mode 100644 index 000000000..6ddd86b01 --- /dev/null +++ b/src/Entities/EntityEffects.h @@ -0,0 +1,53 @@ +#pragma once + +// tolua_begin +class cEntityEffect { +public: + + /** All types of entity effects (numbers correspond to IDs) */ + enum eType + { + efSpeed = 1, + efSlowness = 2, + efHaste = 3, + efMiningFatigue = 4, + efStrength = 5, + efInstantHealth = 6, + efInstantDamage = 7, + efJumpBoost = 8, + efNausia = 9, + efRegeneration = 10, + efResistance = 11, + efFireResistance = 12, + efWaterBreathing = 13, + efInvisibility = 14, + efBlindness = 15, + efNightVision = 16, + efHunger = 17, + efWeakness = 18, + efPoison = 19, + efWither = 20, + efHealthBoost = 21, + efAbsorption = 22, + efSaturation = 23, + } ; + + /** The duration of the effect */ + int m_Ticks; + + /** How strong the effect will be applied */ + short m_Intensity; + + /** + * An empty entity effect + */ + cEntityEffect(); + + /** + * An entity effect + * @param a_Ticks The duration of the effect + * @param a_Intensity How strong the effect will be applied + */ + cEntityEffect(int a_Ticks, short a_Intensity); +}; +// tolua_end diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index fffefd538..e1ddca27e 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -10,6 +10,7 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) : cEntity(a_EntityType, 0, 0, 0, a_Width, a_Height) , m_bBurnable(true) + , m_EntityEffects(std::map()) { } @@ -17,3 +18,27 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) +void cPawn::Tick(float a_Dt, cChunk & a_Chunk) +{ + + + super::Tick(a_Dt, a_Chunk); +} + + + + + +void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect) +{ + m_EntityEffects[a_EffectType] = a_Effect; +} + + + + + +void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType) +{ + m_EntityEffects.erase(a_EffectType); +} diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h index e76337d86..7824a06f8 100644 --- a/src/Entities/Pawn.h +++ b/src/Entities/Pawn.h @@ -2,6 +2,7 @@ #pragma once #include "Entity.h" +#include "EntityEffects.h" @@ -18,9 +19,15 @@ public: CLASS_PROTODEF(cPawn); cPawn(eEntityType a_EntityType, double a_Width, double a_Height); + + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + + void AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect); + void RemoveEntityEffect(cEntityEffect::eType a_EffectType); protected: bool m_bBurnable; + std::map m_EntityEffects; } ; // tolua_export diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index fdc0bb390..035973a16 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -584,12 +584,12 @@ void cPlayer::FoodPoison(int a_NumTicks) m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { - m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); + m_World->BroadcastRemoveEntityEffect(*this, cEntityEffect::efHunger); SendHealth(); } else { - m_World->BroadcastEntityEffect(*this, E_EFFECT_HUNGER, 0, 400); // Give the player the "Hunger" effect for 20 seconds. + m_World->BroadcastEntityEffect(*this, cEntityEffect::efHunger, 0, 400); // Give the player the "Hunger" effect for 20 seconds. } } @@ -1930,7 +1930,7 @@ void cPlayer::HandleFood(void) } else { - m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); // Remove the "Hunger" effect. + m_World->BroadcastRemoveEntityEffect(*this, cEntityEffect::efHunger); // Remove the "Hunger" effect. } // Apply food exhaustion that has accumulated: diff --git a/src/Globals.h b/src/Globals.h index c5768facf..e99333693 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -368,6 +368,5 @@ T Clamp(T a_Value, T a_Min, T a_Max) #include "BiomeDef.h" #include "BlockID.h" #include "BlockInfo.h" -#include "Entities/Effects.h"