ULTIMA8: Refactor Item getFlags -> hasFlags

This commit is contained in:
Matthew Duggan 2020-04-24 09:51:18 +09:00
parent e0398b15ec
commit 7c85b1838d
14 changed files with 42 additions and 32 deletions

View File

@ -285,7 +285,7 @@ Container *ContainerGump::getTargetContainer(Item *item, int mx, int my) {
ShapeInfo *targetinfo = targetcontainer->getShapeInfo();
if ((targetcontainer->getObjId() == item->getObjId()) ||
targetinfo->is_land() ||
(targetcontainer->getFlags() & Item::FLG_IN_NPC_LIST)) {
targetcontainer->hasFlags(Item::FLG_IN_NPC_LIST)) {
targetcontainer = nullptr;
}
}

View File

@ -150,13 +150,13 @@ void GameMapGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scaled)
continue;
if (!paintEditorItems && item->getShapeInfo()->is_editor())
continue;
if (item->getFlags() & Item::FLG_INVISIBLE) {
if (item->hasFlags(Item::FLG_INVISIBLE)) {
// special case: invisible avatar _is_ drawn
// HACK: unless EXT_TRANSPARENT is also set.
// (Used for hiding the avatar when drawing a full area map)
if (item->getObjId() == 1) {
if (item->getExtFlags() & Item::EXT_TRANSPARENT)
if (item->hasExtFlags(Item::EXT_TRANSPARENT))
continue;
int32 x_, y_, z_;

View File

@ -390,7 +390,7 @@ uint16 Actor::getEquip(uint32 type) const {
uint32 cet = (*iter)->getShapeInfo()->_equipType;
bool cbackpack = ((*iter)->getShape() == backpack_shape);
if (((*iter)->getFlags() & FLG_EQUIPPED) &&
if ((*iter)->hasFlags(FLG_EQUIPPED) &&
(cet == type || (cbackpack && type == 7))) { // !! constant
return (*iter)->getObjId();
}

View File

@ -89,7 +89,7 @@ bool ActorAnimProcess::init() {
return false;
}
if (!(actor->getFlags() & Item::FLG_FASTAREA)) {
if (!actor->hasFlags(Item::FLG_FASTAREA)) {
// not in the fast area? Can't play an animation then.
// (If we do, the actor will likely fall because the floor is gone.)
return false;
@ -162,7 +162,7 @@ void ActorAnimProcess::run() {
_firstFrame = false;
if (!(a->getFlags() & Item::FLG_FASTAREA)) {
if (!a->hasFlags(Item::FLG_FASTAREA)) {
// not in the fast area? Kill the animation then.
//! TODO: Decide if this is the right move.
// Animation could do one of three things: pause, move
@ -298,7 +298,7 @@ void ActorAnimProcess::run() {
}
// Did we just leave the fast area?
if (!(a->getFlags() & Item::FLG_FASTAREA)) {
if (!a->hasFlags(Item::FLG_FASTAREA)) {
#ifdef WATCHACTOR
if (_itemNum == watchactor)
pout << "Animation ["

View File

@ -64,7 +64,7 @@ bool AnimationTracker::init(Actor *actor_, Animation::Sequence action_,
if (state_ == 0) {
_animAction->getAnimRange(actor_, _dir, _startFrame, _endFrame);
actor_->getLocation(_x, _y, _z);
_flipped = (actor_->getFlags() & Item::FLG_FLIPPED) != 0;
_flipped = actor_->hasFlags(Item::FLG_FLIPPED);
_firstStep = actor_->hasActorFlags(Actor::ACT_FIRSTSTEP);
} else {
_animAction->getAnimRange(state_->_lastAnim, state_->_direction,
@ -212,7 +212,7 @@ bool AnimationTracker::step() {
}
// determine footpad
bool actorflipped = (a->getFlags() & Item::FLG_FLIPPED) != 0;
bool actorflipped = a->hasFlags(Item::FLG_FLIPPED);
int32 xd, yd, zd;
a->getFootpadWorld(xd, yd, zd);
if (actorflipped != _flipped) {
@ -312,13 +312,13 @@ bool AnimationTracker::step() {
descentdelta = -20; // Descend
if (descentdelta) {
if (dy == 0 && dx != 0 && !(support->getFlags() & Item::FLG_FLIPPED)) {
if (dy == 0 && dx != 0 && !support->hasFlags(Item::FLG_FLIPPED)) {
// Moving left or right on horizontal bridge
// descentdelta = 60*dy/dx
// 60*dy = descentdelta * dx
// dy = descentdelta * dx / 60;
ty += descentdelta * dx / 60;
} else if (dx == 0 && dy != 0 && (support->getFlags() & Item::FLG_FLIPPED)) {
} else if (dx == 0 && dy != 0 && support->hasFlags(Item::FLG_FLIPPED)) {
// Moving up or down on vertical bridge
tx += descentdelta * dy / 60;
}

View File

@ -73,7 +73,7 @@ void CombatProcess::run() {
// They should not try to approach.
Actor *a = getActor(_itemNum);
if (!(a->getFlags() & Item::FLG_FASTAREA))
if (!a->hasFlags(Item::FLG_FASTAREA))
return;
Actor *t = getActor(_target);
@ -184,7 +184,7 @@ bool CombatProcess::isValidTarget(Actor *target_) {
if (target_ == a) return false;
// not in the fastarea
if (!(target_->getFlags() & Item::FLG_FASTAREA)) return false;
if (!target_->hasFlags(Item::FLG_FASTAREA)) return false;
// dead actors don't make good targets
if (target_->isDead()) return false;

View File

@ -53,7 +53,7 @@ void PathfindingState::load(const Actor *_actor) {
_lastAnim = _actor->getLastAnim();
_direction = _actor->getDir();
_firstStep = _actor->hasActorFlags(Actor::ACT_FIRSTSTEP);
_flipped = (_actor->getFlags() & Item::FLG_FLIPPED) != 0;
_flipped = _actor->hasFlags(Item::FLG_FLIPPED);
_combat = _actor->isInCombat();
}

View File

@ -128,7 +128,7 @@ void PathfinderProcess::run() {
Actor *actor = getActor(_itemNum);
assert(actor);
// if not in the fastarea, do nothing
if (!(actor->getFlags() & Item::FLG_FASTAREA)) return;
if (!actor->hasFlags(Item::FLG_FASTAREA)) return;
bool ok = true;

View File

@ -57,7 +57,7 @@ void ResurrectionProcess::run() {
return;
}
if (a->getFlags() & Item::FLG_GUMP_OPEN) {
if (a->hasFlags(Item::FLG_GUMP_OPEN)) {
// first close gump in case player is still rummaging through us
a->closeGump();
}

View File

@ -163,7 +163,7 @@ void CameraProcess::ItemMoved() {
Item *item = getItem(_itemNum);
// We only update for now if lerping has been disabled
if (item && (item->getExtFlags() & Item::EXT_LERP_NOPREV)) {
if (item && item->hasExtFlags(Item::EXT_LERP_NOPREV)) {
item->getLocation(_ex, _ey, _ez);
_sx = _ex;
_sy = _ey;

View File

@ -132,8 +132,7 @@ void CurrentMap::writeback() {
item->clearExtFlag(Item::EXT_INCURMAP);
// delete all _fast only and disposable _items
if ((item->getFlags() & Item::FLG_FAST_ONLY) ||
(item->getFlags() & Item::FLG_DISPOSABLE)) {
if (item->hasFlags(Item::FLG_FAST_ONLY | Item::FLG_DISPOSABLE)) {
delete item;
continue;
}
@ -145,11 +144,11 @@ void CurrentMap::writeback() {
}
// this item isn't from the Map. (like NPCs)
if (item->getFlags() & Item::FLG_IN_NPC_LIST)
if (item->hasFlags(Item::FLG_IN_NPC_LIST))
continue;
item->clearObjId();
if (item->getExtFlags() & Item::EXT_FIXED) {
if (item->hasExtFlags(Item::EXT_FIXED)) {
// item came from fixed
_currentMap->_fixedItems.push_back(item);
} else {
@ -488,7 +487,7 @@ void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript,
const Item *item = *iter;
if (item->getExtFlags() & Item::EXT_SPRITE)
if (item->hasExtFlags(Item::EXT_SPRITE))
continue;
// check if item is in range?
@ -499,7 +498,7 @@ void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript,
int32 ixd, iyd;
//!! constants
if (item->getFlags() & Item::FLG_FLIPPED) {
if (item->hasFlags(Item::FLG_FLIPPED)) {
ixd = 32 * info->_y;
iyd = 32 * info->_x;
} else {
@ -577,7 +576,7 @@ void CurrentMap::surfaceSearch(UCList *itemlist, const uint8 *loopscript,
if (item->getObjId() == check)
continue;
if (item->getExtFlags() & Item::EXT_SPRITE)
if (item->hasExtFlags(Item::EXT_SPRITE))
continue;
// check if item is in range?
@ -716,7 +715,7 @@ bool CurrentMap::isValidPosition(int32 x, int32 y, int32 z,
const Item *item = *iter;
if (item->getObjId() == item_)
continue;
if (item->getExtFlags() & Item::EXT_SPRITE)
if (item->hasExtFlags(Item::EXT_SPRITE))
continue;
ShapeInfo *si = item->getShapeInfo();
@ -840,7 +839,7 @@ bool CurrentMap::scanForValidPosition(int32 x, int32 y, int32 z, Item *item,
Item *citem = *iter;
if (citem->getObjId() == item->getObjId())
continue;
if (citem->getExtFlags() & Item::EXT_SPRITE)
if (citem->hasExtFlags(Item::EXT_SPRITE))
continue;
ShapeInfo *si = citem->getShapeInfo();
@ -1027,7 +1026,7 @@ bool CurrentMap::sweepTest(const int32 start[3], const int32 end[3],
Item *other_item = *iter;
if (other_item->getObjId() == item)
continue;
if (other_item->getExtFlags() & Item::EXT_SPRITE)
if (other_item->hasExtFlags(Item::EXT_SPRITE))
continue;
uint32 othershapeflags = other_item->getShapeInfo()->_flags;
@ -1225,7 +1224,7 @@ Item *CurrentMap::traceTopItem(int32 x, int32 y, int32 ztop, int32 zbot, ObjId i
Item *item = *iter;
if (item->getObjId() == ignore)
continue;
if (item->getExtFlags() & Item::EXT_SPRITE)
if (item->hasExtFlags(Item::EXT_SPRITE))
continue;
ShapeInfo *si = item->getShapeInfo();

View File

@ -62,7 +62,7 @@ void DestroyItemProcess::run() {
// FIXME: should probably prevent player from opening gump in the
// first place...
if (it->getFlags() & Item::FLG_GUMP_OPEN) {
if (it->hasFlags(Item::FLG_GUMP_OPEN)) {
// first close gump in case player is still rummaging through us
it->closeGump();
}

View File

@ -600,7 +600,8 @@ uint32 Item::getTotalWeight() const {
uint32 Item::getVolume() const {
// invisible items (trap markers and such) don't take up volume
if (getFlags() & FLG_INVISIBLE) return 0;
if (hasFlags(FLG_INVISIBLE))
return 0;
uint32 volume = getShapeInfo()->_volume;
@ -1135,7 +1136,7 @@ uint32 Item::use() {
if (actor) {
if (actor->isDead()) {
// dead actor, so open/close the dead-body-_gump
if (getFlags() & FLG_GUMP_OPEN) {
if (hasFlags(FLG_GUMP_OPEN)) {
closeGump();
} else {
openGump(12); // CONSTANT!!

View File

@ -131,11 +131,16 @@ public:
//! Get the Box this item occupies in the world. Undef if item is contained
Box getWorldBox() const;
//! Get flags
//! Get all flags
inline uint16 getFlags() const {
return _flags;
}
//! Does this item have any of the given flags mask set
inline bool hasFlags(uint16 flags) const {
return (_flags & flags) != 0;
}
//! Set the flags set in the given mask.
void setFlag(uint32 mask) {
_flags |= mask;
@ -160,6 +165,11 @@ public:
return _extendedFlags;
}
//! Does item have any of the given extended flags
inline bool hasExtFlags(uint32 flags) const {
return (_extendedFlags & flags) != 0;
}
//! Set the _extendedFlags set in the given mask.
void setExtFlag(uint32 mask) {
_extendedFlags |= mask;