1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-01-26 02:07:26 +00:00

Changed a bunch of enums in Entity.h

This simplifies a few things. First, the values of DamageType are now continous,
with the benefit that they can now be stored in a std::bitset.
Second, this repairs entity_getNearestEntity(..., ET_AVATAR) or DT_ENEMY as param,
because these were 0, but the game expected -1 as universal value.
This way, any entity was returned when querying for ET_AVATAR or DT_ENEMY.
Now, 0 is the universal/NONE value, which should avoid mistakes like this.
This commit is contained in:
fgenesis 2012-12-13 19:48:47 +01:00
parent b242d80c75
commit 8b67ece907
3 changed files with 72 additions and 73 deletions

View file

@ -1690,15 +1690,12 @@ void Entity::moveOutOfWall()
void Entity::clearDamageTargets() void Entity::clearDamageTargets()
{ {
disabledDamageTypes.clear(); disabledDamageTypes.reset();
} }
void Entity::setDamageTarget(DamageType dt, bool v) void Entity::setDamageTarget(DamageType dt, bool v)
{ {
if (v) disabledDamageTypes.set(dt, !v);
disabledDamageTypes.erase(dt);
else
disabledDamageTypes.insert(dt);
} }
void Entity::setEatType(EatType et, const std::string &file) void Entity::setEatType(EatType et, const std::string &file)
@ -1719,17 +1716,17 @@ void Entity::setAllDamageTargets(bool v)
else else
{ {
for (int i = DT_ENEMY; i < DT_ENEMY_REALMAX; i++) for (int i = DT_ENEMY; i < DT_ENEMY_REALMAX; i++)
disabledDamageTypes.insert(DamageType(i)); disabledDamageTypes.set(DamageType(i));
for (int i = DT_AVATAR; i < DT_AVATAR_REALMAX; i++) for (int i = DT_AVATAR; i < DT_AVATAR_REALMAX; i++)
disabledDamageTypes.insert(DamageType(i)); disabledDamageTypes.set(DamageType(i));
for (int i = DT_AVATAR_MAX; i < DT_REALMAX; i++) for (int i = DT_AVATAR_MAX; i < DT_REALMAX; i++)
disabledDamageTypes.insert(DamageType(i)); disabledDamageTypes.set(DamageType(i));
} }
} }
bool Entity::isDamageTarget(DamageType dt) bool Entity::isDamageTarget(DamageType dt)
{ {
return disabledDamageTypes.find(dt) == disabledDamageTypes.end(); return disabledDamageTypes.test(dt);
} }
float Entity::getHealthPerc() float Entity::getHealthPerc()

View file

@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef ENTITY_H #ifndef ENTITY_H
#define ENTITY_H #define ENTITY_H
#include <bitset>
#include "../BBGE/StateMachine.h" #include "../BBGE/StateMachine.h"
#include "../ExternalLibs/tinyxml.h" #include "../ExternalLibs/tinyxml.h"
#include "../BBGE/SkeletalSprite.h" #include "../BBGE/SkeletalSprite.h"
@ -75,70 +77,70 @@ enum EV
enum DamageType enum DamageType
{ {
DT_NONE = -1, DT_NONE,
DT_ENEMY = 0, DT_ENEMY,
DT_ENEMY_ENERGYBLAST = 1, DT_ENEMY_ENERGYBLAST,
DT_ENEMY_SHOCK = 2, DT_ENEMY_SHOCK,
DT_ENEMY_BITE = 3, DT_ENEMY_BITE,
DT_ENEMY_TRAP = 4, DT_ENEMY_TRAP,
DT_ENEMY_WEB = 5, DT_ENEMY_WEB,
DT_ENEMY_BEAM = 6, DT_ENEMY_BEAM,
DT_ENEMY_GAS = 7, DT_ENEMY_GAS,
DT_ENEMY_INK = 8, DT_ENEMY_INK,
DT_ENEMY_POISON = 9, DT_ENEMY_POISON,
DT_ENEMY_ACTIVEPOISON = 10, DT_ENEMY_ACTIVEPOISON,
DT_ENEMY_CREATOR = 11, DT_ENEMY_CREATOR,
DT_ENEMY_MANTISBOMB = 12, DT_ENEMY_MANTISBOMB,
DT_ENEMY_REALMAX , DT_ENEMY_REALMAX,
DT_ENEMY_MAX = 13, DT_ENEMY_MAX,
DT_AVATAR = 1000, DT_AVATAR,
DT_AVATAR_ENERGYBLAST = 1001, DT_AVATAR_ENERGYBLAST,
DT_AVATAR_SHOCK = 1002, DT_AVATAR_SHOCK,
DT_AVATAR_BITE = 1003, DT_AVATAR_BITE,
DT_AVATAR_VOMIT = 1004, DT_AVATAR_VOMIT,
DT_AVATAR_ACID = 1005, DT_AVATAR_ACID,
DT_AVATAR_SPORECHILD = 1006, DT_AVATAR_SPORECHILD,
DT_AVATAR_LIZAP = 1007, DT_AVATAR_LIZAP,
DT_AVATAR_NATURE = 1008, DT_AVATAR_NATURE,
DT_AVATAR_ENERGYROLL = 1009, DT_AVATAR_ENERGYROLL,
DT_AVATAR_VINE = 1010, DT_AVATAR_VINE,
DT_AVATAR_EAT = 1011, DT_AVATAR_EAT,
DT_AVATAR_EAT_BASICSHOT = 1011, DT_AVATAR_EAT_BASICSHOT,
DT_AVATAR_EAT_MAX = 1012, DT_AVATAR_EAT_MAX,
DT_AVATAR_LANCEATTACH = 1013, DT_AVATAR_LANCEATTACH,
DT_AVATAR_LANCE = 1014, DT_AVATAR_LANCE,
DT_AVATAR_CREATORSHOT = 1015, DT_AVATAR_CREATORSHOT,
DT_AVATAR_DUALFORMLI = 1016, DT_AVATAR_DUALFORMLI,
DT_AVATAR_DUALFORMNAIJA = 1017, DT_AVATAR_DUALFORMNAIJA,
DT_AVATAR_BUBBLE = 1018, DT_AVATAR_BUBBLE,
DT_AVATAR_SEED = 1019, DT_AVATAR_SEED,
DT_AVATAR_PET = 1020, DT_AVATAR_PET,
DT_AVATAR_PETNAUTILUS = 1021, DT_AVATAR_PETNAUTILUS,
DT_AVATAR_PETBITE = 1022, DT_AVATAR_PETBITE,
DT_AVATAR_REALMAX , DT_AVATAR_REALMAX,
DT_AVATAR_MAX = 1030, DT_AVATAR_MAX,
DT_TOUCH = 1031, DT_TOUCH,
DT_CRUSH = 1032, DT_CRUSH,
DT_SPIKES = 1033, DT_SPIKES,
DT_STEAM = 1034, DT_STEAM,
DT_REALMAX DT_REALMAX
}; };
enum EatType enum EatType
{ {
EAT_NONE = -1, EAT_NONE,
EAT_DEFAULT = 0, EAT_DEFAULT,
EAT_FILE = 1, EAT_FILE,
EAT_MAX EAT_MAX
}; };
enum ObsCheck enum ObsCheck
{ {
OBSCHECK_RANGE = 0, OBSCHECK_RANGE,
OBSCHECK_4DIR = 1, OBSCHECK_4DIR,
OBSCHECK_DOWN = 2, OBSCHECK_DOWN,
OBSCHECK_8DIR = 3 OBSCHECK_8DIR,
}; };
class Shot; class Shot;
@ -169,13 +171,13 @@ struct DamageData
enum EntityType enum EntityType
{ {
ET_NOTYPE =-1, ET_NOTYPE,
ET_AVATAR =0, ET_AVATAR,
ET_ENEMY =1, ET_ENEMY,
ET_PET =2, ET_PET,
ET_FLOCK =3, ET_FLOCK,
ET_NEUTRAL =4, ET_NEUTRAL,
ET_INGREDIENT =5 ET_INGREDIENT,
}; };
enum EntityProperty enum EntityProperty
@ -406,7 +408,7 @@ public:
void setDamageTarget(DamageType dt, bool v); void setDamageTarget(DamageType dt, bool v);
bool isDamageTarget(DamageType dt); bool isDamageTarget(DamageType dt);
typedef std::set<DamageType> DisabledDamageTypes; typedef std::bitset<DT_REALMAX> DisabledDamageTypes;
int targetRange; int targetRange;
int getTargetRange() { return targetRange; } int getTargetRange() { return targetRange; }

View file

@ -6315,9 +6315,9 @@ luaFunc(entity_getNearestEntity)
Entity *e = *i; Entity *e = *i;
if (e != me && e != ignore && e->isPresent() && e->isNormalLayer()) if (e != me && e != ignore && e->isPresent() && e->isNormalLayer())
{ {
if (type == 0 || e->getEntityType() == type) if (type == ET_NOTYPE || e->getEntityType() == type)
{ {
if (damageTarget == 0 || e->isDamageTarget((DamageType)damageTarget)) if (damageTarget == DT_NONE || e->isDamageTarget((DamageType)damageTarget))
{ {
if (!name || ((nocasecmp(e->name, name)==0) == nameCheck)) if (!name || ((nocasecmp(e->name, name)==0) == nameCheck))
{ {