2013-01-10 08:35:24 -08:00
|
|
|
#ifndef GAME_MWMECHANICS_CHARACTER_HPP
|
|
|
|
#define GAME_MWMECHANICS_CHARACTER_HPP
|
|
|
|
|
2015-06-03 23:04:35 +02:00
|
|
|
#include <deque>
|
2013-01-18 16:00:51 -08:00
|
|
|
|
2022-08-17 19:16:01 +02:00
|
|
|
#include <components/esm3/loadweap.hpp>
|
|
|
|
|
2013-01-12 08:49:08 -08:00
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
|
2015-05-22 00:55:43 +02:00
|
|
|
#include "../mwrender/animation.hpp"
|
|
|
|
|
2013-07-24 21:08:16 -07:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class InventoryStore;
|
|
|
|
}
|
|
|
|
|
2013-01-16 10:16:37 -08:00
|
|
|
namespace MWRender
|
|
|
|
{
|
|
|
|
class Animation;
|
|
|
|
}
|
|
|
|
|
2013-01-10 08:35:24 -08:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
struct Movement;
|
|
|
|
class CreatureStats;
|
|
|
|
|
|
|
|
enum Priority
|
|
|
|
{
|
|
|
|
Priority_Default,
|
|
|
|
Priority_WeaponLowerBody,
|
|
|
|
Priority_SneakIdleLowerBody,
|
|
|
|
Priority_SwimIdle,
|
|
|
|
Priority_Jump,
|
|
|
|
Priority_Movement,
|
|
|
|
Priority_Hit,
|
|
|
|
Priority_Weapon,
|
|
|
|
Priority_Block,
|
|
|
|
Priority_Knockdown,
|
|
|
|
Priority_Torch,
|
|
|
|
Priority_Storm,
|
|
|
|
Priority_Death,
|
2023-10-25 19:53:34 +02:00
|
|
|
Priority_Scripted,
|
2022-09-22 21:26:05 +03:00
|
|
|
|
|
|
|
Num_Priorities
|
|
|
|
};
|
|
|
|
|
|
|
|
enum CharacterState
|
|
|
|
{
|
|
|
|
CharState_None,
|
|
|
|
|
|
|
|
CharState_SpecialIdle,
|
|
|
|
CharState_Idle,
|
|
|
|
CharState_IdleSwim,
|
|
|
|
CharState_IdleSneak,
|
|
|
|
|
|
|
|
CharState_WalkForward,
|
|
|
|
CharState_WalkBack,
|
|
|
|
CharState_WalkLeft,
|
|
|
|
CharState_WalkRight,
|
|
|
|
|
|
|
|
CharState_SwimWalkForward,
|
|
|
|
CharState_SwimWalkBack,
|
|
|
|
CharState_SwimWalkLeft,
|
|
|
|
CharState_SwimWalkRight,
|
|
|
|
|
|
|
|
CharState_RunForward,
|
|
|
|
CharState_RunBack,
|
|
|
|
CharState_RunLeft,
|
|
|
|
CharState_RunRight,
|
|
|
|
|
|
|
|
CharState_SwimRunForward,
|
|
|
|
CharState_SwimRunBack,
|
|
|
|
CharState_SwimRunLeft,
|
|
|
|
CharState_SwimRunRight,
|
|
|
|
|
|
|
|
CharState_SneakForward,
|
|
|
|
CharState_SneakBack,
|
|
|
|
CharState_SneakLeft,
|
|
|
|
CharState_SneakRight,
|
|
|
|
|
|
|
|
CharState_TurnLeft,
|
|
|
|
CharState_TurnRight,
|
|
|
|
CharState_SwimTurnLeft,
|
|
|
|
CharState_SwimTurnRight,
|
|
|
|
|
|
|
|
CharState_Death1,
|
|
|
|
CharState_Death2,
|
|
|
|
CharState_Death3,
|
|
|
|
CharState_Death4,
|
|
|
|
CharState_Death5,
|
|
|
|
CharState_SwimDeath,
|
|
|
|
CharState_SwimDeathKnockDown,
|
|
|
|
CharState_SwimDeathKnockOut,
|
|
|
|
CharState_DeathKnockDown,
|
|
|
|
CharState_DeathKnockOut,
|
|
|
|
|
|
|
|
CharState_Hit,
|
|
|
|
CharState_SwimHit,
|
|
|
|
CharState_KnockDown,
|
|
|
|
CharState_KnockOut,
|
|
|
|
CharState_SwimKnockDown,
|
|
|
|
CharState_SwimKnockOut,
|
|
|
|
CharState_Block
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class UpperBodyState
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Equipping,
|
|
|
|
Unequipping,
|
|
|
|
WeaponEquipped,
|
|
|
|
AttackWindUp,
|
|
|
|
AttackRelease,
|
|
|
|
AttackEnd,
|
|
|
|
Casting
|
|
|
|
};
|
|
|
|
|
|
|
|
enum JumpingState
|
2016-07-30 19:24:03 +02:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
JumpState_None,
|
|
|
|
JumpState_InAir,
|
|
|
|
JumpState_Landing
|
2016-07-30 19:24:03 +02:00
|
|
|
};
|
2013-01-17 13:18:40 -08:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
struct WeaponInfo;
|
2013-07-16 01:30:03 -07:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
class CharacterController : public MWRender::Animation::TextKeyListener
|
|
|
|
{
|
|
|
|
MWWorld::Ptr mPtr;
|
|
|
|
MWWorld::Ptr mWeapon;
|
|
|
|
MWRender::Animation* mAnimation;
|
2013-07-15 22:56:23 -07:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
struct AnimationQueueEntry
|
|
|
|
{
|
|
|
|
std::string mGroup;
|
2024-01-27 18:57:51 +01:00
|
|
|
uint32_t mLoopCount;
|
2023-12-05 14:13:35 +00:00
|
|
|
float mTime;
|
|
|
|
bool mLooping;
|
2023-10-25 19:53:34 +02:00
|
|
|
bool mScripted;
|
2024-01-26 21:39:33 +00:00
|
|
|
std::string mStartKey;
|
|
|
|
std::string mStopKey;
|
|
|
|
float mSpeed;
|
2022-09-22 21:26:05 +03:00
|
|
|
};
|
|
|
|
typedef std::deque<AnimationQueueEntry> AnimationQueue;
|
|
|
|
AnimationQueue mAnimQueue;
|
2024-01-26 21:39:33 +00:00
|
|
|
bool mLuaAnimations{ false };
|
2013-07-15 23:43:33 -07:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
CharacterState mIdleState{ CharState_None };
|
|
|
|
std::string mCurrentIdle;
|
2013-12-31 13:24:20 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
CharacterState mMovementState{ CharState_None };
|
|
|
|
std::string mCurrentMovement;
|
|
|
|
float mMovementAnimSpeed{ 0.f };
|
|
|
|
bool mAdjustMovementAnimSpeed{ false };
|
2023-10-11 11:50:06 +02:00
|
|
|
bool mMovementAnimationHasMovement{ false };
|
2013-07-16 11:40:19 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
CharacterState mDeathState{ CharState_None };
|
|
|
|
std::string mCurrentDeath;
|
|
|
|
bool mFloatToSurface{ true };
|
2013-08-18 23:42:56 -07:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
CharacterState mHitState{ CharState_None };
|
|
|
|
std::string mCurrentHit;
|
2013-07-23 02:50:52 -07:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
UpperBodyState mUpperBodyState{ UpperBodyState::None };
|
2015-06-26 05:15:07 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
JumpingState mJumpState{ JumpState_None };
|
|
|
|
std::string mCurrentJump;
|
2022-11-07 19:06:01 +03:00
|
|
|
bool mInJump{ false };
|
2013-01-12 10:10:27 -08:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
int mWeaponType{ ESM::Weapon::None };
|
|
|
|
std::string mCurrentWeapon;
|
2013-04-28 07:53:04 +02:00
|
|
|
|
2022-10-12 23:53:44 +03:00
|
|
|
float mAttackStrength{ -1.f };
|
2022-09-22 21:26:05 +03:00
|
|
|
MWWorld::Ptr mAttackVictim;
|
|
|
|
osg::Vec3f mAttackHitPos;
|
|
|
|
bool mAttackSuccess{ false };
|
2014-12-16 20:47:45 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool mSkipAnim{ false };
|
2014-09-17 05:20:10 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
// counted for skill increase
|
|
|
|
float mSecondsOfSwimming{ 0.f };
|
|
|
|
float mSecondsOfRunning{ 0.f };
|
2015-07-02 19:14:28 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
MWWorld::ConstPtr mHeadTrackTarget;
|
2022-07-29 16:00:25 +03:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
float mTurnAnimationThreshold{
|
|
|
|
0.f
|
|
|
|
}; // how long to continue playing turning animation after actor stopped turning
|
2015-07-02 19:14:28 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
std::string mAttackType; // slash, chop or thrust
|
2020-06-26 20:04:02 +00:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool mCanCast{ false };
|
2013-07-16 23:32:41 +02:00
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
bool mCastingScriptedSpell{ false };
|
2022-06-13 16:14:19 +03:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool mIsMovingBackward{ false };
|
|
|
|
osg::Vec2f mSmoothedSpeed;
|
2013-04-30 19:26:41 -07:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
std::string_view getMovementBasedAttackType() const;
|
2013-05-16 06:59:41 -07:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void clearStateAnimation(std::string& anim) const;
|
|
|
|
void resetCurrentJumpState();
|
|
|
|
void resetCurrentMovementState();
|
|
|
|
void resetCurrentIdleState();
|
|
|
|
void resetCurrentHitState();
|
|
|
|
void resetCurrentWeaponState();
|
|
|
|
void resetCurrentDeathState();
|
2013-07-23 03:26:24 -07:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void refreshCurrentAnims(CharacterState idle, CharacterState movement, JumpingState jump, bool force = false);
|
|
|
|
void refreshHitRecoilAnims();
|
|
|
|
void refreshJumpAnims(JumpingState jump, bool force = false);
|
|
|
|
void refreshMovementAnims(CharacterState movement, bool force = false);
|
|
|
|
void refreshIdleAnims(CharacterState idle, bool force = false);
|
2018-07-19 16:38:32 +04:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool updateWeaponState();
|
|
|
|
void updateIdleStormState(bool inwater) const;
|
2016-08-22 23:02:57 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
std::string chooseRandomAttackAnimation() const;
|
|
|
|
static bool isRandomAttackAnimation(std::string_view group);
|
2014-12-16 20:47:45 +01:00
|
|
|
|
2023-10-14 13:57:29 +02:00
|
|
|
bool isMovementAnimationControlled() const;
|
2013-12-08 23:05:21 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void updateAnimQueue();
|
2023-12-05 14:13:35 +00:00
|
|
|
void playAnimQueue(bool useLoopStart = false);
|
2013-12-31 13:24:20 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void updateHeadTracking(float duration);
|
2014-01-19 21:11:48 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void updateMagicEffects() const;
|
2014-12-12 16:49:22 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void playDeath(float startpoint, CharacterState death);
|
|
|
|
CharacterState chooseRandomDeathState() const;
|
|
|
|
void playRandomDeath(float startpoint = 0.0f);
|
2019-08-09 12:10:28 +04:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
/// choose a random animation group with \a prefix and numeric suffix
|
|
|
|
/// @param num if non-nullptr, the chosen animation number will be written here
|
|
|
|
std::string chooseRandomGroup(const std::string& prefix, int* num = nullptr) const;
|
2019-08-09 12:58:20 +04:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool updateCarriedLeftVisible(int weaptype) const;
|
2022-02-01 18:47:20 +00:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
std::string fallbackShortWeaponGroup(
|
|
|
|
const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask = nullptr) const;
|
2013-01-12 10:10:27 -08:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
std::string_view getWeaponAnimation(int weaponType) const;
|
|
|
|
std::string_view getWeaponShortGroup(int weaponType) const;
|
2022-05-18 19:55:13 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool getAttackingOrSpell() const;
|
|
|
|
void setAttackingOrSpell(bool attackingOrSpell) const;
|
2022-05-18 19:40:54 +02:00
|
|
|
|
2023-08-11 01:26:34 +03:00
|
|
|
void prepareHit();
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
|
|
|
CharacterController(const MWWorld::Ptr& ptr, MWRender::Animation* anim);
|
|
|
|
virtual ~CharacterController();
|
2015-05-22 00:55:43 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
CharacterController(const CharacterController&) = delete;
|
|
|
|
CharacterController(CharacterController&&) = delete;
|
2013-11-14 13:30:48 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
const MWWorld::Ptr& getPtr() const { return mPtr; }
|
2013-02-25 09:57:34 -08:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void handleTextKey(std::string_view groupname, SceneUtil::TextKeyMap::ConstIterator key,
|
|
|
|
const SceneUtil::TextKeyMap& map) override;
|
2013-01-16 16:31:09 -08:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
// Be careful when to call this, see comment in Actors
|
|
|
|
void updateContinuousVfx() const;
|
2018-09-22 12:57:50 +04:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void updatePtr(const MWWorld::Ptr& ptr);
|
2016-07-30 19:24:03 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void update(float duration);
|
2013-01-16 17:53:18 -08:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool onOpen() const;
|
|
|
|
void onClose() const;
|
2014-05-14 07:14:08 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void persistAnimationState() const;
|
|
|
|
void unpersistAnimationState();
|
2013-04-25 07:08:11 -07:00
|
|
|
|
2024-01-26 21:39:33 +00:00
|
|
|
void playBlendedAnimation(const std::string& groupname, const MWRender::AnimPriority& priority, int blendMask,
|
|
|
|
bool autodisable, float speedmult, std::string_view start, std::string_view stop, float startpoint,
|
2024-01-28 16:34:44 +01:00
|
|
|
uint32_t loops, bool loopfallback = false) const;
|
2024-01-27 18:57:51 +01:00
|
|
|
bool playGroup(std::string_view groupname, int mode, uint32_t count, bool scripted = false);
|
2024-01-26 21:39:33 +00:00
|
|
|
bool playGroupLua(std::string_view groupname, float speed, std::string_view startKey, std::string_view stopKey,
|
2024-01-27 18:57:51 +01:00
|
|
|
uint32_t loops, bool forceLoop);
|
2024-01-26 21:39:33 +00:00
|
|
|
void enableLuaAnimations(bool enable);
|
2022-09-22 21:26:05 +03:00
|
|
|
void skipAnim();
|
|
|
|
bool isAnimPlaying(std::string_view groupName) const;
|
2024-01-01 17:21:00 +03:00
|
|
|
bool isScriptedAnimPlaying() const;
|
2024-01-26 21:39:33 +00:00
|
|
|
void clearAnimQueue(bool clearScriptedAnims = false);
|
2014-12-16 20:47:45 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
enum KillResult
|
|
|
|
{
|
|
|
|
Result_DeathAnimStarted,
|
|
|
|
Result_DeathAnimPlaying,
|
|
|
|
Result_DeathAnimJustFinished,
|
|
|
|
Result_DeathAnimFinished
|
|
|
|
};
|
|
|
|
KillResult kill();
|
2015-07-02 19:14:28 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void resurrect();
|
|
|
|
bool isDead() const { return mDeathState != CharState_None; }
|
2015-07-03 05:58:12 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void forceStateUpdate();
|
2022-07-31 14:41:05 +03:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool isAttackPreparing() const;
|
|
|
|
bool isCastingSpell() const;
|
|
|
|
bool isReadyToBlock() const;
|
|
|
|
bool isKnockedDown() const;
|
|
|
|
bool isKnockedOut() const;
|
|
|
|
bool isRecovery() const;
|
|
|
|
bool isSneaking() const;
|
|
|
|
bool isRunning() const;
|
|
|
|
bool isTurning() const;
|
|
|
|
bool isAttackingOrSpell() const;
|
2015-07-02 22:25:19 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void setVisibility(float visibility) const;
|
2024-03-25 13:50:23 +00:00
|
|
|
void castSpell(const ESM::RefId& spellId, bool scriptedSpell = false);
|
2022-09-22 21:26:05 +03:00
|
|
|
void setAIAttackType(std::string_view attackType);
|
|
|
|
static std::string_view getRandomAttackType();
|
2015-04-29 23:48:08 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool readyToPrepareAttack() const;
|
|
|
|
bool readyToStartAttack() const;
|
2016-12-11 19:35:53 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
float calculateWindUp() const;
|
|
|
|
|
|
|
|
float getAttackStrength() const;
|
|
|
|
|
|
|
|
/// @see Animation::setActive
|
|
|
|
void setActive(int active) const;
|
|
|
|
|
|
|
|
/// 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 playSwishSound() const;
|
2023-07-05 23:58:04 +02:00
|
|
|
|
2023-11-04 16:18:36 +01:00
|
|
|
float getAnimationMovementDirection() const;
|
2023-11-04 14:34:41 +01:00
|
|
|
|
2023-07-05 23:58:04 +02:00
|
|
|
MWWorld::MovementDirectionFlags getSupportedMovementDirections() const;
|
2022-09-22 21:26:05 +03:00
|
|
|
};
|
2013-01-10 08:35:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* GAME_MWMECHANICS_CHARACTER_HPP */
|