1
0

Moved Effects.h to EntityEffects.h, added initial impl

This commit is contained in:
archshift 2014-06-06 00:17:49 -07:00
parent c1692a2e3b
commit 87b1bfaf2a
9 changed files with 115 additions and 36 deletions

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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)
{
}

View File

@ -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

View File

@ -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<cEntityEffect::eType, cEntityEffect>())
{
}
@ -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);
}

View File

@ -2,6 +2,7 @@
#pragma once
#include "Entity.h"
#include "EntityEffects.h"
@ -19,8 +20,14 @@ public:
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<cEntityEffect::eType, cEntityEffect> m_EntityEffects;
} ; // tolua_export

View File

@ -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:

View File

@ -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"