OpenMW
apps/openmw/mwmechanics/character.hpp
Go to the documentation of this file.
00001 #ifndef GAME_MWMECHANICS_CHARACTER_HPP
00002 #define GAME_MWMECHANICS_CHARACTER_HPP
00003 
00004 #include <OgreVector3.h>
00005 
00006 #include <components/esm/loadmgef.hpp>
00007 
00008 #include "../mwworld/ptr.hpp"
00009 
00010 namespace MWWorld
00011 {
00012     class ContainerStoreIterator;
00013     class InventoryStore;
00014 }
00015 
00016 namespace MWRender
00017 {
00018     class Animation;
00019 }
00020 
00021 namespace MWMechanics
00022 {
00023 
00024 class Movement;
00025 class NpcStats;
00026 
00027 enum Priority {
00028     Priority_Default,
00029     Priority_Jump,
00030     Priority_Movement,
00031     Priority_Weapon,
00032     Priority_Torch,
00033 
00034     Priority_Death,
00035 
00036     Num_Priorities
00037 };
00038 
00039 enum CharacterState {
00040     CharState_None,
00041 
00042     CharState_SpecialIdle,
00043     CharState_Idle,
00044     CharState_Idle2,
00045     CharState_Idle3,
00046     CharState_Idle4,
00047     CharState_Idle5,
00048     CharState_Idle6,
00049     CharState_Idle7,
00050     CharState_Idle8,
00051     CharState_Idle9,
00052     CharState_IdleSwim,
00053     CharState_IdleSneak,
00054 
00055     CharState_WalkForward,
00056     CharState_WalkBack,
00057     CharState_WalkLeft,
00058     CharState_WalkRight,
00059 
00060     CharState_SwimWalkForward,
00061     CharState_SwimWalkBack,
00062     CharState_SwimWalkLeft,
00063     CharState_SwimWalkRight,
00064 
00065     CharState_RunForward,
00066     CharState_RunBack,
00067     CharState_RunLeft,
00068     CharState_RunRight,
00069 
00070     CharState_SwimRunForward,
00071     CharState_SwimRunBack,
00072     CharState_SwimRunLeft,
00073     CharState_SwimRunRight,
00074 
00075     CharState_SneakForward,
00076     CharState_SneakBack,
00077     CharState_SneakLeft,
00078     CharState_SneakRight,
00079 
00080     CharState_TurnLeft,
00081     CharState_TurnRight,
00082 
00083     CharState_Jump,
00084 
00085     CharState_Death1,
00086     CharState_Death2,
00087     CharState_Death3,
00088     CharState_Death4,
00089     CharState_Death5,
00090     CharState_SwimDeath
00091 };
00092 
00093 enum WeaponType {
00094     WeapType_None,
00095 
00096     WeapType_HandToHand,
00097     WeapType_OneHand,
00098     WeapType_TwoHand,
00099     WeapType_TwoWide,
00100     WeapType_BowAndArrow,
00101     WeapType_Crossbow,
00102     WeapType_ThowWeapon,
00103     WeapType_PickProbe,
00104 
00105     WeapType_Spell
00106 };
00107 
00108 enum UpperBodyCharacterState {
00109     UpperCharState_Nothing,
00110     UpperCharState_EquipingWeap,
00111     UpperCharState_UnEquipingWeap,
00112     UpperCharState_WeapEquiped,
00113     UpperCharState_StartToMinAttack,
00114     UpperCharState_MinAttackToMaxAttack,
00115     UpperCharState_MaxAttackToMinHit,
00116     UpperCharState_MinHitToHit,
00117     UpperCharState_FollowStartToFollowStop,
00118     UpperCharState_CastingSpell
00119 };
00120 
00121 enum JumpingState {
00122     JumpState_None,
00123     JumpState_Falling,
00124     JumpState_Landing
00125 };
00126 
00127 class CharacterController
00128 {
00129     MWWorld::Ptr mPtr;
00130     MWRender::Animation *mAnimation;
00131 
00132     typedef std::deque<std::pair<std::string,size_t> > AnimationQueue;
00133     AnimationQueue mAnimQueue;
00134 
00135     CharacterState mIdleState;
00136     std::string mCurrentIdle;
00137 
00138     CharacterState mMovementState;
00139     std::string mCurrentMovement;
00140     float mMovementSpeed;
00141 
00142     CharacterState mDeathState;
00143     std::string mCurrentDeath;
00144 
00145     UpperBodyCharacterState mUpperBodyState;
00146 
00147     JumpingState mJumpState;
00148     std::string mCurrentJump;
00149 
00150     WeaponType mWeaponType;
00151     std::string mCurrentWeapon;
00152 
00153     bool mSkipAnim;
00154 
00155     // counted for skill increase
00156     float mSecondsOfSwimming;
00157     float mSecondsOfRunning;
00158 
00159     std::string mAttackType; // slash, chop or thrust
00160 
00161     void refreshCurrentAnims(CharacterState idle, CharacterState movement, bool force=false);
00162 
00163     static void getWeaponGroup(WeaponType weaptype, std::string &group);
00164 
00165     static MWWorld::ContainerStoreIterator getActiveWeapon(NpcStats &stats,
00166                                                            MWWorld::InventoryStore &inv,
00167                                                            WeaponType *weaptype);
00168 
00169     void clearAnimQueue();
00170 
00171     bool updateNpcState(bool onground, bool inwater, bool isrunning, bool sneak);
00172 
00173     void updateVisibility();
00174 
00175 public:
00176     CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim);
00177     virtual ~CharacterController();
00178 
00179     // Be careful when to call this, see comment in Actors
00180     void updateContinuousVfx();
00181 
00182     void updatePtr(const MWWorld::Ptr &ptr);
00183 
00184     void update(float duration);
00185 
00186     void playGroup(const std::string &groupname, int mode, int count);
00187     void skipAnim();
00188     bool isAnimPlaying(const std::string &groupName);
00189 
00190     void kill();
00191     void resurrect();
00192     bool isDead() const
00193     { return mDeathState != CharState_None; }
00194 
00195     void forceStateUpdate();
00196 };
00197 
00198 }
00199 
00200 #endif /* GAME_MWMECHANICS_CHARACTER_HPP */