1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 21:32:42 +00:00
OpenMW/apps/openmw/mwmechanics/character.hpp

314 lines
7.8 KiB
C++
Raw Normal View History

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