1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-09 09:39:53 +00:00

Rename DrawState_ to DrawState and use enum class

This commit is contained in:
ζeh Matt 2022-07-17 19:36:48 +03:00
parent b032a643f9
commit 841fd9618f
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0
27 changed files with 67 additions and 67 deletions

View File

@ -234,7 +234,7 @@ namespace MWClass
const MWWorld::Store<ESM::GameSetting> &gmst = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
MWMechanics::CreatureStats &stats = getCreatureStats(ptr);
if (stats.getDrawState() != MWMechanics::DrawState_Weapon)
if (stats.getDrawState() != MWMechanics::DrawState::Weapon)
return;
// Get the weapon used (if hand-to-hand, weapon = inv.end())

View File

@ -995,7 +995,7 @@ namespace MWClass
else
moveSpeed = getWalkSpeed(ptr);
if(stats.isWerewolf() && running && stats.getDrawState() == MWMechanics::DrawState_Nothing)
if(stats.isWerewolf() && running && stats.getDrawState() == MWMechanics::DrawState::Nothing)
moveSpeed *= gmst.fWereWolfRunMult->mValue.getFloat();
return moveSpeed;

View File

@ -416,7 +416,7 @@ namespace MWGui
// change draw state only if the item is in player's right hand
if (rightHand != store.end() && item == *rightHand)
{
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Weapon);
}
}
else if (key->type == Type_MagicItem)
@ -432,7 +432,7 @@ namespace MWGui
}
store.setSelectedEnchantItem(it);
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Spell);
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Spell);
}
}
else if (key->type == Type_Magic)
@ -452,12 +452,12 @@ namespace MWGui
store.setSelectedEnchantItem(store.end());
MWBase::Environment::get().getWindowManager()
->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player)));
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Spell);
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Spell);
}
else if (key->type == Type_HandToHand)
{
store.unequipSlot(MWWorld::InventoryStore::Slot_CarriedRight, player);
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState::Weapon);
}
}

View File

@ -1376,8 +1376,8 @@ namespace MWGui
mHud->unsetSelectedSpell();
MWWorld::Player* player = &MWBase::Environment::get().getWorld()->getPlayer();
if (player->getDrawState() == MWMechanics::DrawState_Spell)
player->setDrawState(MWMechanics::DrawState_Nothing);
if (player->getDrawState() == MWMechanics::DrawState::Spell)
player->setDrawState(MWMechanics::DrawState::Nothing);
mSpellWindow->setTitle("#{sNone}");
}

View File

@ -355,11 +355,11 @@ namespace MWInput
if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(player.getPlayer()))
return;
MWMechanics::DrawState_ state = player.getDrawState();
if (state == MWMechanics::DrawState_Weapon || state == MWMechanics::DrawState_Nothing)
player.setDrawState(MWMechanics::DrawState_Spell);
MWMechanics::DrawState state = player.getDrawState();
if (state == MWMechanics::DrawState::Weapon || state == MWMechanics::DrawState::Nothing)
player.setDrawState(MWMechanics::DrawState::Spell);
else
player.setDrawState(MWMechanics::DrawState_Nothing);
player.setDrawState(MWMechanics::DrawState::Nothing);
}
void ActionManager::quickLoad()
@ -390,11 +390,11 @@ namespace MWInput
else if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(player.getPlayer()))
return;
MWMechanics::DrawState_ state = player.getDrawState();
if (state == MWMechanics::DrawState_Spell || state == MWMechanics::DrawState_Nothing)
player.setDrawState(MWMechanics::DrawState_Weapon);
MWMechanics::DrawState state = player.getDrawState();
if (state == MWMechanics::DrawState::Spell || state == MWMechanics::DrawState::Nothing)
player.setDrawState(MWMechanics::DrawState::Weapon);
else
player.setDrawState(MWMechanics::DrawState_Nothing);
player.setDrawState(MWMechanics::DrawState::Nothing);
}
void ActionManager::rest()

View File

@ -709,8 +709,8 @@ namespace MWInput
else
{
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
MWMechanics::DrawState_ state = player.getDrawState();
player.setAttackingOrSpell(currentValue != 0 && state != MWMechanics::DrawState_Nothing);
MWMechanics::DrawState state = player.getDrawState();
player.setAttackingOrSpell(currentValue != 0 && state != MWMechanics::DrawState::Nothing);
}
}
else if (action == A_Jump)

View File

@ -114,10 +114,10 @@ namespace MWLua
void addActorBindings(sol::table actor, const Context& context)
{
actor["STANCE"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, int>({
{"Nothing", MWMechanics::DrawState_Nothing},
{"Weapon", MWMechanics::DrawState_Weapon},
{"Spell", MWMechanics::DrawState_Spell},
actor["STANCE"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, MWMechanics::DrawState>({
{"Nothing", MWMechanics::DrawState::Nothing},
{"Weapon", MWMechanics::DrawState::Weapon},
{"Spell", MWMechanics::DrawState::Spell},
}));
actor["EQUIPMENT_SLOT"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, int>({
{"Helmet", MWWorld::InventoryStore::Slot_Helmet},

View File

@ -22,7 +22,7 @@ namespace MWMechanics
{
const MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(mObjectId, false); //The target to follow
actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Nothing);
actor.getClass().getCreatureStats(actor).setDrawState(DrawState::Nothing);
// Stop if the target doesn't exist
// Really we should be checking whether the target is currently registered with the MechanicsManager

View File

@ -40,7 +40,7 @@ namespace MWMechanics
void ActionSpell::prepare(const MWWorld::Ptr &actor)
{
actor.getClass().getCreatureStats(actor).getSpells().setSelectedSpell(mSpellId);
actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Spell);
actor.getClass().getCreatureStats(actor).setDrawState(DrawState::Spell);
if (actor.getClass().hasInventoryStore(actor))
{
MWWorld::InventoryStore& inv = actor.getClass().getInventoryStore(actor);
@ -64,7 +64,7 @@ namespace MWMechanics
{
actor.getClass().getCreatureStats(actor).getSpells().setSelectedSpell(std::string());
actor.getClass().getInventoryStore(actor).setSelectedEnchantItem(mItem);
actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Spell);
actor.getClass().getCreatureStats(actor).setDrawState(DrawState::Spell);
}
float ActionEnchantedItem::getCombatRange(bool& isRanged) const
@ -106,7 +106,7 @@ namespace MWMechanics
equip.execute(actor);
}
}
actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Weapon);
actor.getClass().getCreatureStats(actor).setDrawState(DrawState::Weapon);
}
float ActionWeapon::getCombatRange(bool& isRanged) const
@ -324,7 +324,7 @@ namespace MWMechanics
static const float fHandToHandReach = gmst.find("fHandToHandReach")->mValue.getFloat();
dist = fHandToHandReach;
}
else if (stats.getDrawState() == MWMechanics::DrawState_Spell)
else if (stats.getDrawState() == MWMechanics::DrawState::Spell)
{
dist = 1.0f;
if (!selectedSpellId.empty())

View File

@ -64,7 +64,7 @@ namespace MWMechanics
if (!mCellId.empty() && mCellId != actor.getCell()->getCell()->getCellId().mWorldspace)
return false; // Not in the correct cell, pause and rely on the player to go back through a teleport door
actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Nothing);
actor.getClass().getCreatureStats(actor).setDrawState(DrawState::Nothing);
actor.getClass().getCreatureStats(actor).setMovementFlag(CreatureStats::Flag_Run, false);
const MWWorld::Ptr follower = MWBase::Environment::get().getWorld()->getPtr(mTargetActorRefId, false);

View File

@ -72,7 +72,7 @@ bool AiFollow::execute (const MWWorld::Ptr& actor, CharacterController& characte
if (target == MWWorld::Ptr() || !target.getRefData().getCount() || !target.getRefData().isEnabled())
return false;
actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Nothing);
actor.getClass().getCreatureStats(actor).setDrawState(DrawState::Nothing);
AiFollowStorage& storage = state.get<AiFollowStorage>();

View File

@ -44,7 +44,7 @@ bool AiPursue::execute (const MWWorld::Ptr& actor, CharacterController& characte
if (target.getClass().getCreatureStats(target).isDead())
return true;
actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Nothing);
actor.getClass().getCreatureStats(actor).setDrawState(DrawState::Nothing);
//Set the target destination
const osg::Vec3f dest = target.getRefData().getPosition().asVec3();

View File

@ -68,7 +68,7 @@ namespace MWMechanics
const osg::Vec3f targetPos(mX, mY, mZ);
stats.setMovementFlag(CreatureStats::Flag_Run, false);
stats.setDrawState(DrawState_Nothing);
stats.setDrawState(DrawState::Nothing);
// Note: we should cancel internal "return after combat" package, if original location is too far away
if (!isWithinMaxRange(targetPos, actorPos))

View File

@ -196,7 +196,7 @@ namespace MWMechanics
mRemainingDuration -= ((duration*MWBase::Environment::get().getWorld()->getTimeScaleFactor()) / 3600);
cStats.setDrawState(DrawState_Nothing);
cStats.setDrawState(DrawState::Nothing);
cStats.setMovementFlag(CreatureStats::Flag_Run, false);
ESM::Position pos = actor.getRefData().getPosition();

View File

@ -1104,9 +1104,9 @@ bool CharacterController::updateState(CharacterState idle)
const MWWorld::Class &cls = mPtr.getClass();
CreatureStats &stats = cls.getCreatureStats(mPtr);
int weaptype = ESM::Weapon::None;
if(stats.getDrawState() == DrawState_Weapon)
if(stats.getDrawState() == DrawState::Weapon)
weaptype = ESM::Weapon::HandToHand;
else if (stats.getDrawState() == DrawState_Spell)
else if (stats.getDrawState() == DrawState::Spell)
weaptype = ESM::Weapon::Spell;
const bool isWerewolf = cls.isNpc() && cls.getNpcStats(mPtr).isWerewolf();
@ -1118,7 +1118,7 @@ bool CharacterController::updateState(CharacterState idle)
{
MWWorld::InventoryStore &inv = cls.getInventoryStore(mPtr);
MWWorld::ContainerStoreIterator weapon = getActiveWeapon(mPtr, &weaptype);
if(stats.getDrawState() == DrawState_Spell)
if(stats.getDrawState() == DrawState::Spell)
weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if(weapon != inv.end() && mWeaponType != ESM::Weapon::HandToHand && weaptype != ESM::Weapon::HandToHand && weaptype != ESM::Weapon::Spell && weaptype != ESM::Weapon::None)
@ -1910,7 +1910,7 @@ void CharacterController::update(float duration)
else if (canMove)
{
float targetMovementAngle = vec.y() >= 0 ? std::atan2(-vec.x(), vec.y()) : std::atan2(vec.x(), -vec.y());
movementSettings.mIsStrafing = (stats.getDrawState() != MWMechanics::DrawState_Nothing || inwater)
movementSettings.mIsStrafing = (stats.getDrawState() != MWMechanics::DrawState::Nothing || inwater)
&& std::abs(targetMovementAngle) > osg::DegreesToRadians(60.0f);
if (movementSettings.mIsStrafing)
targetMovementAngle = 0;
@ -1929,7 +1929,7 @@ void CharacterController::update(float duration)
}
mAnimation->setLegsYawRadians(stats.getSideMovementAngle());
if (stats.getDrawState() == MWMechanics::DrawState_Nothing || inwater)
if (stats.getDrawState() == MWMechanics::DrawState::Nothing || inwater)
mAnimation->setUpperBodyYawRadians(stats.getSideMovementAngle() / 2);
else
mAnimation->setUpperBodyYawRadians(stats.getSideMovementAngle() / 4);

View File

@ -19,7 +19,7 @@ namespace MWMechanics
int CreatureStats::sActorId = 0;
CreatureStats::CreatureStats()
: mDrawState (DrawState_Nothing), mDead (false), mDeathAnimationFinished(false), mDied (false), mMurdered(false), mFriendlyHits (0),
: mDrawState (DrawState::Nothing), mDead (false), mDeathAnimationFinished(false), mDied (false), mMurdered(false), mFriendlyHits (0),
mTalkedTo (false), mAlarmed (false), mAttacked (false),
mKnockdown(false), mKnockdownOneFrame(false), mKnockdownOverOneFrame(false),
mHitRecovery(false), mBlock(false), mMovementFlags(0),
@ -499,12 +499,12 @@ namespace MWMechanics
}
}
DrawState_ CreatureStats::getDrawState() const
DrawState CreatureStats::getDrawState() const
{
return mDrawState;
}
void CreatureStats::setDrawState(DrawState_ state)
void CreatureStats::setDrawState(DrawState state)
{
mDrawState = state;
}
@ -542,7 +542,7 @@ namespace MWMechanics
state.mLastHitObject = mLastHitObject;
state.mLastHitAttemptObject = mLastHitAttemptObject;
state.mRecalcDynamicStats = false;
state.mDrawState = mDrawState;
state.mDrawState = static_cast<int>(mDrawState);
state.mLevel = mLevel;
state.mActorId = mActorId;
state.mDeathAnimation = mDeathAnimation;
@ -596,7 +596,7 @@ namespace MWMechanics
mFallHeight = state.mFallHeight;
mLastHitObject = state.mLastHitObject;
mLastHitAttemptObject = state.mLastHitAttemptObject;
mDrawState = DrawState_(state.mDrawState);
mDrawState = DrawState(state.mDrawState);
mLevel = state.mLevel;
mActorId = state.mActorId;
mDeathAnimation = state.mDeathAnimation;

View File

@ -38,7 +38,7 @@ namespace MWMechanics
class CreatureStats
{
static int sActorId;
DrawState_ mDrawState;
DrawState mDrawState;
AttributeValue mAttributes[ESM::Attribute::Length];
DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
Spells mSpells;
@ -98,8 +98,8 @@ namespace MWMechanics
public:
CreatureStats();
DrawState_ getDrawState() const;
void setDrawState(DrawState_ state);
DrawState getDrawState() const;
void setDrawState(DrawState state);
void recalculateMagicka();

View File

@ -3,12 +3,12 @@
namespace MWMechanics
{
/// \note The _ suffix is required to avoid a collision with a Windoze macro. Die, Microsoft! Die!
enum DrawState_
enum class DrawState
{
DrawState_Nothing = 0,
DrawState_Weapon = 1,
DrawState_Spell = 2
Nothing = 0,
Weapon = 1,
Spell = 2
};
}

View File

@ -571,7 +571,7 @@ namespace MWMechanics
x += fDispDiseaseMod;
static const float fDispWeaponDrawn = gmst.find("fDispWeaponDrawn")->mValue.getFloat();
if (playerStats.getDrawState() == MWMechanics::DrawState_Weapon)
if (playerStats.getDrawState() == MWMechanics::DrawState::Weapon)
x += fDispWeaponDrawn;
x += ptr.getClass().getCreatureStats(ptr).getMagicEffects().get(ESM::MagicEffect::Charm).getMagnitude();
@ -1789,8 +1789,8 @@ namespace MWMechanics
MWWorld::Player* player = &MWBase::Environment::get().getWorld()->getPlayer();
// Werewolfs can not cast spells, so we need to unset the prepared spell if there is one.
if (npcStats.getDrawState() == MWMechanics::DrawState_Spell)
npcStats.setDrawState(MWMechanics::DrawState_Nothing);
if (npcStats.getDrawState() == MWMechanics::DrawState::Spell)
npcStats.setDrawState(MWMechanics::DrawState::Nothing);
npcStats.setWerewolf(werewolf);

View File

@ -190,7 +190,7 @@ namespace
// change draw state only if the item is in player's right hand
if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
player.setDrawState(MWMechanics::DrawState_Weapon);
player.setDrawState(MWMechanics::DrawState::Weapon);
if (prevItem != store.end())
player.setPreviousItem(itemId, prevItem->getCellRef().getRefId());

View File

@ -249,7 +249,7 @@ namespace MWMechanics
return 0.f;
// Enemy doesn't attack
if (stats.getDrawState() != MWMechanics::DrawState_Weapon)
if (stats.getDrawState() != MWMechanics::DrawState::Weapon)
return 0.f;
break;
@ -270,7 +270,7 @@ namespace MWMechanics
return 0.f;
// Enemy doesn't cast spells
if (stats.getDrawState() != MWMechanics::DrawState_Spell)
if (stats.getDrawState() != MWMechanics::DrawState::Spell)
return 0.f;
break;
@ -288,7 +288,7 @@ namespace MWMechanics
return 0.f;
// Enemy doesn't cast spells
if (stats.getDrawState() != MWMechanics::DrawState_Spell)
if (stats.getDrawState() != MWMechanics::DrawState::Spell)
return 0.f;
break;
}

View File

@ -11,13 +11,13 @@ namespace MWMechanics
{
MWWorld::InventoryStore &inv = actor.getClass().getInventoryStore(actor);
CreatureStats &stats = actor.getClass().getCreatureStats(actor);
if(stats.getDrawState() == MWMechanics::DrawState_Spell)
if(stats.getDrawState() == MWMechanics::DrawState::Spell)
{
*weaptype = ESM::Weapon::Spell;
return inv.end();
}
if(stats.getDrawState() == MWMechanics::DrawState_Weapon)
if(stats.getDrawState() == MWMechanics::DrawState::Weapon)
{
MWWorld::ContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if(weapon == inv.end())

View File

@ -178,7 +178,7 @@ bool ActorAnimation::updateCarriedLeftVisible(const int weaptype) const
const MWWorld::ConstContainerStoreIterator shield = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
if (shield != inv.end() && shield->getType() == ESM::Armor::sRecordId && !getSheathedShieldMesh(*shield).empty())
{
if(stats.getDrawState() != MWMechanics::DrawState_Weapon)
if(stats.getDrawState() != MWMechanics::DrawState::Weapon)
return false;
if (weapon != inv.end())

View File

@ -783,7 +783,7 @@ namespace MWScript
MWWorld::Ptr ptr = R()(runtime);
runtime.push((ptr.getClass().hasInventoryStore(ptr) || ptr.getClass().isBipedal(ptr)) &&
ptr.getClass().getCreatureStats (ptr).getDrawState () == MWMechanics::DrawState_Weapon);
ptr.getClass().getCreatureStats (ptr).getDrawState () == MWMechanics::DrawState::Weapon);
}
};
@ -796,7 +796,7 @@ namespace MWScript
{
MWWorld::Ptr ptr = R()(runtime);
runtime.push(ptr.getClass().getCreatureStats (ptr).getDrawState () == MWMechanics::DrawState_Spell);
runtime.push(ptr.getClass().getCreatureStats (ptr).getDrawState () == MWMechanics::DrawState::Spell);
}
};

View File

@ -152,7 +152,7 @@ namespace MWWorld
return mSign;
}
void Player::setDrawState (MWMechanics::DrawState_ state)
void Player::setDrawState (MWMechanics::DrawState state)
{
MWWorld::Ptr ptr = getPlayer();
ptr.getClass().getNpcStats(ptr).setDrawState (state);
@ -229,7 +229,7 @@ namespace MWWorld
ptr.getClass().getMovementSettings(ptr).mRotation[1] += roll;
}
MWMechanics::DrawState_ Player::getDrawState()
MWMechanics::DrawState Player::getDrawState()
{
MWWorld::Ptr ptr = getPlayer();
return ptr.getClass().getNpcStats(ptr).getDrawState();

View File

@ -86,8 +86,8 @@ namespace MWWorld
void setBirthSign(const std::string &sign);
const std::string &getBirthSign() const;
void setDrawState (MWMechanics::DrawState_ state);
MWMechanics::DrawState_ getDrawState(); /// \todo constness
void setDrawState (MWMechanics::DrawState state);
MWMechanics::DrawState getDrawState(); /// \todo constness
/// Activate the object under the crosshair, if any
void activate();

View File

@ -3619,7 +3619,7 @@ namespace MWWorld
mPlayer->setAttackingOrSpell(false);
}
mPlayer->setDrawState(MWMechanics::DrawState_Nothing);
mPlayer->setDrawState(MWMechanics::DrawState::Nothing);
mGoToJail = false;
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Dialogue);