mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-23 15:40:42 +00:00
Improve CharacterController const-correctness
C++ Core Guidelines Con. 2
This commit is contained in:
parent
788de7edcb
commit
97d4206a3d
@ -703,7 +703,7 @@ std::string chooseBestAttack(const ESM::Weapon* weapon)
|
|||||||
attackType = "chop";
|
attackType = "chop";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
MWMechanics::CharacterController::setAttackTypeRandomly(attackType);
|
attackType = MWMechanics::CharacterController::getRandomAttackType();
|
||||||
|
|
||||||
return attackType;
|
return attackType;
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ void CharacterController::refreshJumpAnims(const std::string& weapShortGroup, Ju
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CharacterController::onOpen()
|
bool CharacterController::onOpen() const
|
||||||
{
|
{
|
||||||
if (mPtr.getType() == ESM::Container::sRecordId)
|
if (mPtr.getType() == ESM::Container::sRecordId)
|
||||||
{
|
{
|
||||||
@ -406,7 +406,7 @@ bool CharacterController::onOpen()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::onClose()
|
void CharacterController::onClose() const
|
||||||
{
|
{
|
||||||
if (mPtr.getType() == ESM::Container::sRecordId)
|
if (mPtr.getType() == ESM::Container::sRecordId)
|
||||||
{
|
{
|
||||||
@ -445,7 +445,7 @@ std::string CharacterController::getWeaponAnimation(int weaponType) const
|
|||||||
return weaponGroup;
|
return weaponGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CharacterController::fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask)
|
std::string CharacterController::fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask) const
|
||||||
{
|
{
|
||||||
bool isRealWeapon = mWeaponType != ESM::Weapon::HandToHand && mWeaponType != ESM::Weapon::Spell && mWeaponType != ESM::Weapon::None;
|
bool isRealWeapon = mWeaponType != ESM::Weapon::HandToHand && mWeaponType != ESM::Weapon::Spell && mWeaponType != ESM::Weapon::None;
|
||||||
if (!isRealWeapon)
|
if (!isRealWeapon)
|
||||||
@ -1072,7 +1072,7 @@ void CharacterController::updatePtr(const MWWorld::Ptr &ptr)
|
|||||||
mPtr = ptr;
|
mPtr = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::updateIdleStormState(bool inwater)
|
void CharacterController::updateIdleStormState(bool inwater) const
|
||||||
{
|
{
|
||||||
if (!mAnimation->hasAnimation("idlestorm") || mUpperBodyState != UpperCharState_Nothing || inwater)
|
if (!mAnimation->hasAnimation("idlestorm") || mUpperBodyState != UpperCharState_Nothing || inwater)
|
||||||
{
|
{
|
||||||
@ -1527,12 +1527,12 @@ bool CharacterController::updateState(CharacterState idle)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// There is no "best attack" for Hand-to-Hand
|
// There is no "best attack" for Hand-to-Hand
|
||||||
setAttackTypeRandomly(mAttackType);
|
mAttackType = getRandomAttackType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setAttackTypeBasedOnMovement();
|
mAttackType = getMovementBasedAttackType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else if (mPtr != getPlayer()) use mAttackType set by AiCombat
|
// else if (mPtr != getPlayer()) use mAttackType set by AiCombat
|
||||||
@ -2361,7 +2361,7 @@ void CharacterController::update(float duration)
|
|||||||
mAnimation->enableHeadAnimation(cls.isActor() && !cls.getCreatureStats(mPtr).isDead());
|
mAnimation->enableHeadAnimation(cls.isActor() && !cls.getCreatureStats(mPtr).isDead());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::persistAnimationState()
|
void CharacterController::persistAnimationState() const
|
||||||
{
|
{
|
||||||
ESM::AnimationState& state = mPtr.getRefData().getAnimationState();
|
ESM::AnimationState& state = mPtr.getRefData().getAnimationState();
|
||||||
|
|
||||||
@ -2497,18 +2497,18 @@ void CharacterController::skipAnim()
|
|||||||
mSkipAnim = true;
|
mSkipAnim = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CharacterController::isPersistentAnimPlaying()
|
bool CharacterController::isPersistentAnimPlaying() const
|
||||||
{
|
{
|
||||||
if (!mAnimQueue.empty())
|
if (!mAnimQueue.empty())
|
||||||
{
|
{
|
||||||
AnimationQueueEntry& first = mAnimQueue.front();
|
const AnimationQueueEntry& first = mAnimQueue.front();
|
||||||
return first.mPersist && isAnimPlaying(first.mGroup);
|
return first.mPersist && isAnimPlaying(first.mGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CharacterController::isAnimPlaying(const std::string &groupName)
|
bool CharacterController::isAnimPlaying(const std::string &groupName) const
|
||||||
{
|
{
|
||||||
if(mAnimation == nullptr)
|
if(mAnimation == nullptr)
|
||||||
return false;
|
return false;
|
||||||
@ -2589,7 +2589,7 @@ void CharacterController::resurrect()
|
|||||||
mWeaponType = ESM::Weapon::None;
|
mWeaponType = ESM::Weapon::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::updateContinuousVfx()
|
void CharacterController::updateContinuousVfx() const
|
||||||
{
|
{
|
||||||
// Keeping track of when to stop a continuous VFX seems to be very difficult to do inside the spells code,
|
// Keeping track of when to stop a continuous VFX seems to be very difficult to do inside the spells code,
|
||||||
// as it's extremely spread out (ActiveSpells, Spells, InventoryStore effects, etc...) so we do it here.
|
// as it's extremely spread out (ActiveSpells, Spells, InventoryStore effects, etc...) so we do it here.
|
||||||
@ -2606,7 +2606,7 @@ void CharacterController::updateContinuousVfx()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::updateMagicEffects()
|
void CharacterController::updateMagicEffects() const
|
||||||
{
|
{
|
||||||
if (!mPtr.getClass().isActor())
|
if (!mPtr.getClass().isActor())
|
||||||
return;
|
return;
|
||||||
@ -2622,7 +2622,7 @@ void CharacterController::updateMagicEffects()
|
|||||||
mAnimation->setVampire(vampire);
|
mAnimation->setVampire(vampire);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::setVisibility(float visibility)
|
void CharacterController::setVisibility(float visibility) const
|
||||||
{
|
{
|
||||||
// We should take actor's invisibility in account
|
// We should take actor's invisibility in account
|
||||||
if (mPtr.getClass().isActor())
|
if (mPtr.getClass().isActor())
|
||||||
@ -2648,18 +2648,17 @@ void CharacterController::setVisibility(float visibility)
|
|||||||
mAnimation->setAlpha(visibility);
|
mAnimation->setAlpha(visibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::setAttackTypeBasedOnMovement()
|
std::string CharacterController::getMovementBasedAttackType() const
|
||||||
{
|
{
|
||||||
float *move = mPtr.getClass().getMovementSettings(mPtr).mPosition;
|
float *move = mPtr.getClass().getMovementSettings(mPtr).mPosition;
|
||||||
if (std::abs(move[1]) > std::abs(move[0]) + 0.2f) // forward-backward
|
if (std::abs(move[1]) > std::abs(move[0]) + 0.2f) // forward-backward
|
||||||
mAttackType = "thrust";
|
return "thrust";
|
||||||
else if (std::abs(move[0]) > std::abs(move[1]) + 0.2f) // sideway
|
if (std::abs(move[0]) > std::abs(move[1]) + 0.2f) // sideway
|
||||||
mAttackType = "slash";
|
return "slash";
|
||||||
else
|
return "chop";
|
||||||
mAttackType = "chop";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CharacterController::isRandomAttackAnimation(const std::string& group) const
|
bool CharacterController::isRandomAttackAnimation(const std::string& group)
|
||||||
{
|
{
|
||||||
return (group == "attack1" || group == "swimattack1" ||
|
return (group == "attack1" || group == "swimattack1" ||
|
||||||
group == "attack2" || group == "swimattack2" ||
|
group == "attack2" || group == "swimattack2" ||
|
||||||
@ -2753,16 +2752,15 @@ void CharacterController::setAIAttackType(const std::string& attackType)
|
|||||||
mAttackType = attackType;
|
mAttackType = attackType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::setAttackTypeRandomly(std::string& attackType)
|
std::string CharacterController::getRandomAttackType()
|
||||||
{
|
{
|
||||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||||
float random = Misc::Rng::rollProbability(world->getPrng());
|
float random = Misc::Rng::rollProbability(world->getPrng());
|
||||||
if (random >= 2/3.f)
|
if (random >= 2/3.f)
|
||||||
attackType = "thrust";
|
return "thrust";
|
||||||
else if (random >= 1/3.f)
|
if (random >= 1/3.f)
|
||||||
attackType = "slash";
|
return "slash";
|
||||||
else
|
return "chop";
|
||||||
attackType = "chop";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CharacterController::readyToPrepareAttack() const
|
bool CharacterController::readyToPrepareAttack() const
|
||||||
@ -2784,12 +2782,12 @@ float CharacterController::getAttackStrength() const
|
|||||||
return mAttackStrength;
|
return mAttackStrength;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CharacterController::getAttackingOrSpell()
|
bool CharacterController::getAttackingOrSpell() const
|
||||||
{
|
{
|
||||||
return mPtr.getClass().getCreatureStats(mPtr).getAttackingOrSpell();
|
return mPtr.getClass().getCreatureStats(mPtr).getAttackingOrSpell();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::setActive(int active)
|
void CharacterController::setActive(int active) const
|
||||||
{
|
{
|
||||||
mAnimation->setActive(active);
|
mAnimation->setActive(active);
|
||||||
}
|
}
|
||||||
@ -2799,7 +2797,7 @@ void CharacterController::setHeadTrackTarget(const MWWorld::ConstPtr &target)
|
|||||||
mHeadTrackTarget = target;
|
mHeadTrackTarget = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::playSwishSound(float attackStrength)
|
void CharacterController::playSwishSound(float attackStrength) const
|
||||||
{
|
{
|
||||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ class CharacterController : public MWRender::Animation::TextKeyListener
|
|||||||
bool mIsMovingBackward{false};
|
bool mIsMovingBackward{false};
|
||||||
osg::Vec2f mSmoothedSpeed;
|
osg::Vec2f mSmoothedSpeed;
|
||||||
|
|
||||||
void setAttackTypeBasedOnMovement();
|
std::string getMovementBasedAttackType() const;
|
||||||
|
|
||||||
void refreshCurrentAnims(CharacterState idle, CharacterState movement, JumpingState jump, bool force=false);
|
void refreshCurrentAnims(CharacterState idle, CharacterState movement, JumpingState jump, bool force=false);
|
||||||
void refreshHitRecoilAnims(CharacterState& idle);
|
void refreshHitRecoilAnims(CharacterState& idle);
|
||||||
@ -206,18 +206,18 @@ class CharacterController : public MWRender::Animation::TextKeyListener
|
|||||||
void clearAnimQueue(bool clearPersistAnims = false);
|
void clearAnimQueue(bool clearPersistAnims = false);
|
||||||
|
|
||||||
bool updateState(CharacterState idle);
|
bool updateState(CharacterState idle);
|
||||||
void updateIdleStormState(bool inwater);
|
void updateIdleStormState(bool inwater) const;
|
||||||
|
|
||||||
std::string chooseRandomAttackAnimation() const;
|
std::string chooseRandomAttackAnimation() const;
|
||||||
bool isRandomAttackAnimation(const std::string& group) const;
|
static bool isRandomAttackAnimation(const std::string& group);
|
||||||
|
|
||||||
bool isPersistentAnimPlaying();
|
bool isPersistentAnimPlaying() const;
|
||||||
|
|
||||||
void updateAnimQueue();
|
void updateAnimQueue();
|
||||||
|
|
||||||
void updateHeadTracking(float duration);
|
void updateHeadTracking(float duration);
|
||||||
|
|
||||||
void updateMagicEffects();
|
void updateMagicEffects() const;
|
||||||
|
|
||||||
void playDeath(float startpoint, CharacterState death);
|
void playDeath(float startpoint, CharacterState death);
|
||||||
CharacterState chooseRandomDeathState() const;
|
CharacterState chooseRandomDeathState() const;
|
||||||
@ -229,11 +229,11 @@ class CharacterController : public MWRender::Animation::TextKeyListener
|
|||||||
|
|
||||||
bool updateCarriedLeftVisible(int weaptype) const;
|
bool updateCarriedLeftVisible(int weaptype) const;
|
||||||
|
|
||||||
std::string fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask = nullptr);
|
std::string fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask = nullptr) const;
|
||||||
|
|
||||||
std::string getWeaponAnimation(int weaponType) const;
|
std::string getWeaponAnimation(int weaponType) const;
|
||||||
|
|
||||||
bool getAttackingOrSpell();
|
bool getAttackingOrSpell() const;
|
||||||
void setAttackingOrSpell(bool attackingOrSpell);
|
void setAttackingOrSpell(bool attackingOrSpell);
|
||||||
|
|
||||||
|
|
||||||
@ -249,21 +249,21 @@ public:
|
|||||||
void handleTextKey(const std::string &groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map) override;
|
void handleTextKey(const std::string &groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map) override;
|
||||||
|
|
||||||
// Be careful when to call this, see comment in Actors
|
// Be careful when to call this, see comment in Actors
|
||||||
void updateContinuousVfx();
|
void updateContinuousVfx() const;
|
||||||
|
|
||||||
void updatePtr(const MWWorld::Ptr &ptr);
|
void updatePtr(const MWWorld::Ptr &ptr);
|
||||||
|
|
||||||
void update(float duration);
|
void update(float duration);
|
||||||
|
|
||||||
bool onOpen();
|
bool onOpen() const;
|
||||||
void onClose();
|
void onClose() const;
|
||||||
|
|
||||||
void persistAnimationState();
|
void persistAnimationState() const;
|
||||||
void unpersistAnimationState();
|
void unpersistAnimationState();
|
||||||
|
|
||||||
bool playGroup(const std::string &groupname, int mode, int count, bool persist=false);
|
bool playGroup(const std::string &groupname, int mode, int count, bool persist=false);
|
||||||
void skipAnim();
|
void skipAnim();
|
||||||
bool isAnimPlaying(const std::string &groupName);
|
bool isAnimPlaying(const std::string &groupName) const;
|
||||||
|
|
||||||
enum KillResult
|
enum KillResult
|
||||||
{
|
{
|
||||||
@ -291,10 +291,10 @@ public:
|
|||||||
bool isTurning() const;
|
bool isTurning() const;
|
||||||
bool isAttackingOrSpell() const;
|
bool isAttackingOrSpell() const;
|
||||||
|
|
||||||
void setVisibility(float visibility);
|
void setVisibility(float visibility) const;
|
||||||
void castSpell(const std::string& spellId, bool manualSpell=false);
|
void castSpell(const std::string& spellId, bool manualSpell=false);
|
||||||
void setAIAttackType(const std::string& attackType);
|
void setAIAttackType(const std::string& attackType);
|
||||||
static void setAttackTypeRandomly(std::string& attackType);
|
static std::string getRandomAttackType();
|
||||||
|
|
||||||
bool readyToPrepareAttack() const;
|
bool readyToPrepareAttack() const;
|
||||||
bool readyToStartAttack() const;
|
bool readyToStartAttack() const;
|
||||||
@ -302,12 +302,12 @@ public:
|
|||||||
float getAttackStrength() const;
|
float getAttackStrength() const;
|
||||||
|
|
||||||
/// @see Animation::setActive
|
/// @see Animation::setActive
|
||||||
void setActive(int active);
|
void setActive(int active) const;
|
||||||
|
|
||||||
/// Make this character turn its head towards \a target. To turn off head tracking, pass an empty Ptr.
|
/// Make this character turn its head towards \a target. To turn off head tracking, pass an empty Ptr.
|
||||||
void setHeadTrackTarget(const MWWorld::ConstPtr& target);
|
void setHeadTrackTarget(const MWWorld::ConstPtr& target);
|
||||||
|
|
||||||
void playSwishSound(float attackStrength);
|
void playSwishSound(float attackStrength) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user