From 8b67ece9075a0135b8e2a63b976609ee6249b3b7 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 13 Dec 2012 19:48:47 +0100 Subject: [PATCH] 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. --- Aquaria/Entity.cpp | 15 ++--- Aquaria/Entity.h | 124 ++++++++++++++++++------------------ Aquaria/ScriptInterface.cpp | 4 +- 3 files changed, 71 insertions(+), 72 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 4dd5c95..02e83a7 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -1690,15 +1690,12 @@ void Entity::moveOutOfWall() void Entity::clearDamageTargets() { - disabledDamageTypes.clear(); + disabledDamageTypes.reset(); } void Entity::setDamageTarget(DamageType dt, bool v) { - if (v) - disabledDamageTypes.erase(dt); - else - disabledDamageTypes.insert(dt); + disabledDamageTypes.set(dt, !v); } void Entity::setEatType(EatType et, const std::string &file) @@ -1719,17 +1716,17 @@ void Entity::setAllDamageTargets(bool v) else { 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++) - disabledDamageTypes.insert(DamageType(i)); + disabledDamageTypes.set(DamageType(i)); for (int i = DT_AVATAR_MAX; i < DT_REALMAX; i++) - disabledDamageTypes.insert(DamageType(i)); + disabledDamageTypes.set(DamageType(i)); } } bool Entity::isDamageTarget(DamageType dt) { - return disabledDamageTypes.find(dt) == disabledDamageTypes.end(); + return disabledDamageTypes.test(dt); } float Entity::getHealthPerc() diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 646cb6d..5794c97 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef ENTITY_H #define ENTITY_H +#include + #include "../BBGE/StateMachine.h" #include "../ExternalLibs/tinyxml.h" #include "../BBGE/SkeletalSprite.h" @@ -75,70 +77,70 @@ enum EV enum DamageType { - DT_NONE = -1, - DT_ENEMY = 0, - DT_ENEMY_ENERGYBLAST = 1, - DT_ENEMY_SHOCK = 2, - DT_ENEMY_BITE = 3, - DT_ENEMY_TRAP = 4, - DT_ENEMY_WEB = 5, - DT_ENEMY_BEAM = 6, - DT_ENEMY_GAS = 7, - DT_ENEMY_INK = 8, - DT_ENEMY_POISON = 9, - DT_ENEMY_ACTIVEPOISON = 10, - DT_ENEMY_CREATOR = 11, - DT_ENEMY_MANTISBOMB = 12, - DT_ENEMY_REALMAX , - DT_ENEMY_MAX = 13, + DT_NONE, + DT_ENEMY, + DT_ENEMY_ENERGYBLAST, + DT_ENEMY_SHOCK, + DT_ENEMY_BITE, + DT_ENEMY_TRAP, + DT_ENEMY_WEB, + DT_ENEMY_BEAM, + DT_ENEMY_GAS, + DT_ENEMY_INK, + DT_ENEMY_POISON, + DT_ENEMY_ACTIVEPOISON, + DT_ENEMY_CREATOR, + DT_ENEMY_MANTISBOMB, + DT_ENEMY_REALMAX, + DT_ENEMY_MAX, - DT_AVATAR = 1000, - DT_AVATAR_ENERGYBLAST = 1001, - DT_AVATAR_SHOCK = 1002, - DT_AVATAR_BITE = 1003, - DT_AVATAR_VOMIT = 1004, - DT_AVATAR_ACID = 1005, - DT_AVATAR_SPORECHILD = 1006, - DT_AVATAR_LIZAP = 1007, - DT_AVATAR_NATURE = 1008, - DT_AVATAR_ENERGYROLL = 1009, - DT_AVATAR_VINE = 1010, - DT_AVATAR_EAT = 1011, - DT_AVATAR_EAT_BASICSHOT = 1011, - DT_AVATAR_EAT_MAX = 1012, - DT_AVATAR_LANCEATTACH = 1013, - DT_AVATAR_LANCE = 1014, - DT_AVATAR_CREATORSHOT = 1015, - DT_AVATAR_DUALFORMLI = 1016, - DT_AVATAR_DUALFORMNAIJA = 1017, - DT_AVATAR_BUBBLE = 1018, - DT_AVATAR_SEED = 1019, - DT_AVATAR_PET = 1020, - DT_AVATAR_PETNAUTILUS = 1021, - DT_AVATAR_PETBITE = 1022, - DT_AVATAR_REALMAX , - DT_AVATAR_MAX = 1030, - DT_TOUCH = 1031, - DT_CRUSH = 1032, - DT_SPIKES = 1033, - DT_STEAM = 1034, + DT_AVATAR, + DT_AVATAR_ENERGYBLAST, + DT_AVATAR_SHOCK, + DT_AVATAR_BITE, + DT_AVATAR_VOMIT, + DT_AVATAR_ACID, + DT_AVATAR_SPORECHILD, + DT_AVATAR_LIZAP, + DT_AVATAR_NATURE, + DT_AVATAR_ENERGYROLL, + DT_AVATAR_VINE, + DT_AVATAR_EAT, + DT_AVATAR_EAT_BASICSHOT, + DT_AVATAR_EAT_MAX, + DT_AVATAR_LANCEATTACH, + DT_AVATAR_LANCE, + DT_AVATAR_CREATORSHOT, + DT_AVATAR_DUALFORMLI, + DT_AVATAR_DUALFORMNAIJA, + DT_AVATAR_BUBBLE, + DT_AVATAR_SEED, + DT_AVATAR_PET, + DT_AVATAR_PETNAUTILUS, + DT_AVATAR_PETBITE, + DT_AVATAR_REALMAX, + DT_AVATAR_MAX, + DT_TOUCH, + DT_CRUSH, + DT_SPIKES, + DT_STEAM, DT_REALMAX }; enum EatType { - EAT_NONE = -1, - EAT_DEFAULT = 0, - EAT_FILE = 1, + EAT_NONE, + EAT_DEFAULT, + EAT_FILE, EAT_MAX }; enum ObsCheck { - OBSCHECK_RANGE = 0, - OBSCHECK_4DIR = 1, - OBSCHECK_DOWN = 2, - OBSCHECK_8DIR = 3 + OBSCHECK_RANGE, + OBSCHECK_4DIR, + OBSCHECK_DOWN, + OBSCHECK_8DIR, }; class Shot; @@ -169,13 +171,13 @@ struct DamageData enum EntityType { - ET_NOTYPE =-1, - ET_AVATAR =0, - ET_ENEMY =1, - ET_PET =2, - ET_FLOCK =3, - ET_NEUTRAL =4, - ET_INGREDIENT =5 + ET_NOTYPE, + ET_AVATAR, + ET_ENEMY, + ET_PET, + ET_FLOCK, + ET_NEUTRAL, + ET_INGREDIENT, }; enum EntityProperty @@ -406,7 +408,7 @@ public: void setDamageTarget(DamageType dt, bool v); bool isDamageTarget(DamageType dt); - typedef std::set DisabledDamageTypes; + typedef std::bitset DisabledDamageTypes; int targetRange; int getTargetRange() { return targetRange; } diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 43bbd08..54aa8a6 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -6315,9 +6315,9 @@ luaFunc(entity_getNearestEntity) Entity *e = *i; 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)) {