1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 23:49:55 +00:00
openmw-tes3mp/apps/openmw/mwmechanics/character.hpp

311 lines
7.7 KiB
C++
Raw Normal View History

#ifndef GAME_MWMECHANICS_CHARACTER_HPP
#define GAME_MWMECHANICS_CHARACTER_HPP
2015-06-03 21:04:35 +00:00
#include <deque>
#include <components/esm/loadmgef.hpp>
#include "../mwworld/ptr.hpp"
#include "../mwworld/containerstore.hpp"
2015-05-21 22:55:43 +00: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 07:54:44 +00:00
enum Priority {
Priority_Default,
2015-07-25 23:35:36 +00:00
Priority_WeaponLowerBody,
Priority_SneakIdleLowerBody,
Priority_SwimIdle,
Priority_Jump,
Priority_Movement,
2013-12-31 11:24:20 +00:00
Priority_Hit,
Priority_Weapon,
Priority_Block,
2014-01-08 14:05:14 +00:00
Priority_Knockdown,
Priority_Torch,
Priority_Storm,
2013-05-13 07:54:44 +00:00
Priority_Death,
Priority_Persistent,
2013-05-13 07:54:44 +00:00
Num_Priorities
};
enum CharacterState {
CharState_None,
CharState_SpecialIdle,
CharState_Idle,
2013-02-03 08:19:22 +00:00
CharState_Idle2,
CharState_Idle3,
CharState_Idle4,
CharState_Idle5,
CharState_Idle6,
CharState_Idle7,
CharState_Idle8,
CharState_Idle9,
2013-02-06 03:05:07 +00:00
CharState_IdleSwim,
2013-03-06 15:58:56 +00:00
CharState_IdleSneak,
CharState_WalkForward,
CharState_WalkBack,
CharState_WalkLeft,
CharState_WalkRight,
2013-02-06 03:05:07 +00:00
CharState_SwimWalkForward,
CharState_SwimWalkBack,
CharState_SwimWalkLeft,
CharState_SwimWalkRight,
2013-02-07 00:53:52 +00:00
CharState_RunForward,
CharState_RunBack,
CharState_RunLeft,
CharState_RunRight,
CharState_SwimRunForward,
CharState_SwimRunBack,
CharState_SwimRunLeft,
CharState_SwimRunRight,
2013-03-06 15:58:56 +00:00
CharState_SneakForward,
CharState_SneakBack,
CharState_SneakLeft,
CharState_SneakRight,
2013-03-31 10:50:20 +00:00
CharState_TurnLeft,
CharState_TurnRight,
CharState_SwimTurnLeft,
CharState_SwimTurnRight,
2013-03-31 10:50:20 +00:00
2013-02-15 12:45:28 +00:00
CharState_Jump,
2013-02-03 08:19:22 +00:00
CharState_Death1,
CharState_Death2,
CharState_Death3,
CharState_Death4,
CharState_Death5,
2013-12-31 11:24:20 +00:00
CharState_SwimDeath,
CharState_SwimDeathKnockDown,
CharState_SwimDeathKnockOut,
CharState_DeathKnockDown,
CharState_DeathKnockOut,
2013-12-31 11:24:20 +00:00
2014-01-02 19:54:41 +00:00
CharState_Hit,
2017-09-22 11:49:42 +00:00
CharState_SwimHit,
CharState_KnockDown,
CharState_KnockOut,
2017-09-22 11:26:35 +00:00
CharState_SwimKnockDown,
CharState_SwimKnockOut,
CharState_Block
};
2013-07-13 21:24:52 +00:00
enum UpperBodyCharacterState {
UpperCharState_Nothing,
UpperCharState_EquipingWeap,
UpperCharState_UnEquipingWeap,
UpperCharState_WeapEquiped,
2013-07-16 21:38:55 +00:00
UpperCharState_StartToMinAttack,
UpperCharState_MinAttackToMaxAttack,
UpperCharState_MaxAttackToMinHit,
UpperCharState_MinHitToHit,
UpperCharState_FollowStartToFollowStop,
UpperCharState_CastingSpell
2013-07-13 21:24:52 +00:00
};
2013-08-19 06:42:56 +00:00
enum JumpingState {
JumpState_None,
JumpState_InAir,
2013-08-19 06:42:56 +00:00
JumpState_Landing
};
struct WeaponInfo;
2015-05-21 22:55:43 +00: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;
std::string mCurrentIdle;
CharacterState mMovementState;
std::string mCurrentMovement;
float mMovementAnimSpeed;
bool mAdjustMovementAnimSpeed;
bool mHasMovedInXY;
bool mMovementAnimationControlled;
CharacterState mDeathState;
std::string mCurrentDeath;
bool mFloatToSurface;
2013-12-31 11:24:20 +00:00
CharacterState mHitState;
std::string mCurrentHit;
2013-07-13 21:24:52 +00:00
UpperBodyCharacterState mUpperBodyState;
2013-08-19 06:42:56 +00:00
JumpingState mJumpState;
2013-08-19 15:10:18 +00:00
std::string mCurrentJump;
2013-08-19 06:42:56 +00:00
int mWeaponType;
2013-07-23 09:50:52 +00:00
std::string mCurrentWeapon;
float mAttackStrength;
bool mSkipAnim;
2013-04-28 05:53:04 +00:00
// counted for skill increase
float mSecondsOfSwimming;
float mSecondsOfRunning;
MWWorld::ConstPtr mHeadTrackTarget;
float mTurnAnimationThreshold; // how long to continue playing turning animation after actor stopped turning
std::string mAttackType; // slash, chop or thrust
bool mAttackingOrSpell;
bool mCastingManualSpell;
2017-11-15 15:43:36 +00:00
float mTimeUntilWake;
bool mIsMovingBackward;
2020-09-04 13:03:33 +00:00
osg::Vec2f mSmoothedSpeed;
void setAttackTypeBasedOnMovement();
void refreshCurrentAnims(CharacterState idle, CharacterState movement, JumpingState jump, bool force=false);
2018-08-20 18:04:02 +00:00
void refreshHitRecoilAnims(CharacterState& idle);
void refreshJumpAnims(const std::string& weapShortGroup, JumpingState jump, CharacterState& idle, bool force=false);
void refreshMovementAnims(const std::string& weapShortGroup, CharacterState movement, CharacterState& idle, bool force=false);
void refreshIdleAnims(const std::string& weapShortGroup, CharacterState idle, bool force=false);
void clearAnimQueue(bool clearPersistAnims = false);
2018-08-20 18:04:02 +00:00
bool updateWeaponState(CharacterState& idle);
bool updateCreatureState();
void updateIdleStormState(bool inwater);
std::string chooseRandomAttackAnimation() const;
bool isRandomAttackAnimation(const std::string& group) const;
bool isPersistentAnimPlaying();
2016-08-22 21:02:57 +00:00
void updateAnimQueue();
void updateHeadTracking(float duration);
void updateMagicEffects();
void playDeath(float startpoint, CharacterState death);
2016-05-19 20:30:14 +00:00
CharacterState chooseRandomDeathState() const;
2014-01-02 19:54:41 +00:00
void playRandomDeath(float startpoint = 0.0f);
2013-12-31 11:24:20 +00:00
/// choose a random animation group with \a prefix and numeric suffix
2018-10-09 06:21:12 +00: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;
2019-08-09 08:10:28 +00:00
std::string fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask = nullptr);
2019-08-09 08:58:20 +00:00
std::string getWeaponAnimation(int weaponType) const;
public:
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim);
virtual ~CharacterController();
void handleTextKey(const std::string &groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map) override;
2015-05-21 22:55:43 +00:00
// Be careful when to call this, see comment in Actors
void updateContinuousVfx();
void updatePtr(const MWWorld::Ptr &ptr);
void update(float duration);
bool onOpen();
void onClose();
void persistAnimationState();
void unpersistAnimationState();
bool playGroup(const std::string &groupname, int mode, int count, bool persist=false);
void skipAnim();
bool isAnimPlaying(const std::string &groupName);
enum KillResult
{
Result_DeathAnimStarted,
Result_DeathAnimPlaying,
Result_DeathAnimJustFinished,
Result_DeathAnimFinished
};
KillResult kill();
2014-05-14 05:14:08 +00:00
void resurrect();
bool isDead() const
{ return mDeathState != CharState_None; }
void forceStateUpdate();
bool isAttackPreparing() const;
bool isCastingSpell() const;
bool isReadyToBlock() const;
2017-09-22 11:26:35 +00:00
bool isKnockedDown() const;
bool isKnockedOut() const;
2017-09-22 11:49:42 +00:00
bool isRecovery() const;
bool isSneaking() const;
bool isRunning() const;
bool isTurning() const;
bool isAttackingOrSpell() const;
void setVisibility(float visibility);
void setAttackingOrSpell(bool attackingOrSpell);
void castSpell(const std::string spellId, bool manualSpell=false);
2017-04-20 11:36:14 +00:00
void setAIAttackType(const std::string& attackType);
static void setAttackTypeRandomly(std::string& attackType);
bool readyToPrepareAttack() const;
2015-07-03 03:58:12 +00:00
bool readyToStartAttack() const;
float getAttackStrength() const;
/// @see Animation::setActive
void setActive(int active);
/// 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(float attackStrength);
};
}
#endif /* GAME_MWMECHANICS_CHARACTER_HPP */