From 0db02af80731fddd2e58bd5de470110304606bd5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 24 Jul 2013 21:08:16 -0700 Subject: [PATCH] Set up the weapon state in the CharacterController constructor --- apps/openmw/mwmechanics/character.cpp | 138 ++++++++++++++------------ apps/openmw/mwmechanics/character.hpp | 14 ++- 2 files changed, 86 insertions(+), 66 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 71be10fac..f07e07482 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -232,6 +232,67 @@ void CharacterController::getWeaponGroup(WeaponType weaptype, std::string &group } +MWWorld::ContainerStoreIterator CharacterController::getActiveWeapon(NpcStats &stats, MWWorld::InventoryStore &inv, WeaponType *weaptype) +{ + if(stats.getDrawState() == DrawState_Spell) + { + *weaptype = WeapType_Spell; + return inv.end(); + } + + if(stats.getDrawState() == MWMechanics::DrawState_Weapon) + { + MWWorld::ContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); + if(weapon == inv.end()) + *weaptype = WeapType_HandToHand; + else + { + const std::string &type = weapon->getTypeName(); + if(type == typeid(ESM::Lockpick).name() || type == typeid(ESM::Probe).name()) + *weaptype = WeapType_PickProbe; + else if(type == typeid(ESM::Weapon).name()) + { + MWWorld::LiveCellRef *ref = weapon->get(); + ESM::Weapon::Type type = (ESM::Weapon::Type)ref->mBase->mData.mType; + switch(type) + { + case ESM::Weapon::ShortBladeOneHand: + case ESM::Weapon::LongBladeOneHand: + case ESM::Weapon::BluntOneHand: + case ESM::Weapon::AxeOneHand: + case ESM::Weapon::Arrow: + case ESM::Weapon::Bolt: + *weaptype = WeapType_OneHand; + break; + case ESM::Weapon::LongBladeTwoHand: + case ESM::Weapon::BluntTwoClose: + case ESM::Weapon::AxeTwoHand: + *weaptype = WeapType_TwoHand; + break; + case ESM::Weapon::BluntTwoWide: + case ESM::Weapon::SpearTwoWide: + *weaptype = WeapType_TwoWide; + break; + case ESM::Weapon::MarksmanBow: + *weaptype = WeapType_BowAndArrow; + break; + case ESM::Weapon::MarksmanCrossbow: + *weaptype = WeapType_Crossbow; + break; + case ESM::Weapon::MarksmanThrown: + *weaptype = WeapType_ThowWeapon; + break; + } + } + } + + return weapon; + } + + return inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); +} + + CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim) : mPtr(ptr) , mAnimation(anim) @@ -244,18 +305,28 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim , mSkipAnim(false) , mSecondsOfRunning(0) , mSecondsOfSwimming(0) - , mUpdateWeapon(true) { if(!mAnimation) return; - if(MWWorld::Class::get(mPtr).isActor()) + const MWWorld::Class &cls = MWWorld::Class::get(mPtr); + if(cls.isActor()) { /* Accumulate along X/Y only for now, until we can figure out how we should * handle knockout and death which moves the character down. */ mAnimation->setAccumulation(Ogre::Vector3(1.0f, 1.0f, 0.0f)); - if(!MWWorld::Class::get(mPtr).getCreatureStats(mPtr).isDead()) + if(mPtr.getTypeName() == typeid(ESM::NPC).name()) + { + getActiveWeapon(cls.getNpcStats(mPtr), cls.getInventoryStore(mPtr), &mWeaponType); + if(mWeaponType != WeapType_None) + { + getWeaponGroup(mWeaponType, mCurrentWeapon); + mUpperBodyState = UpperCharState_WeapEquiped; + } + } + + if(!cls.getCreatureStats(mPtr).isDead()) mIdleState = CharState_Idle; else { @@ -302,68 +373,9 @@ bool CharacterController::updateNpcState() NpcStats &stats = cls.getNpcStats(mPtr); WeaponType weaptype = WeapType_None; MWWorld::InventoryStore &inv = cls.getInventoryStore(mPtr); - MWWorld::ContainerStoreIterator weapon = inv.end(); - - if(stats.getDrawState() == DrawState_Spell) - weaptype = WeapType_Spell; - else if(stats.getDrawState() == MWMechanics::DrawState_Weapon) - { - weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); - if(weapon == inv.end()) - weaptype = WeapType_HandToHand; - else - { - const std::string &type = weapon->getTypeName(); - if(type == typeid(ESM::Lockpick).name() || type == typeid(ESM::Probe).name()) - weaptype = WeapType_PickProbe; - else if(type == typeid(ESM::Weapon).name()) - { - MWWorld::LiveCellRef *ref = weapon->get(); - ESM::Weapon::Type type = (ESM::Weapon::Type)ref->mBase->mData.mType; - switch(type) - { - case ESM::Weapon::ShortBladeOneHand: - case ESM::Weapon::LongBladeOneHand: - case ESM::Weapon::BluntOneHand: - case ESM::Weapon::AxeOneHand: - case ESM::Weapon::Arrow: - case ESM::Weapon::Bolt: - weaptype = WeapType_OneHand; - break; - case ESM::Weapon::LongBladeTwoHand: - case ESM::Weapon::BluntTwoClose: - case ESM::Weapon::AxeTwoHand: - weaptype = WeapType_TwoHand; - break; - case ESM::Weapon::BluntTwoWide: - case ESM::Weapon::SpearTwoWide: - weaptype = WeapType_TwoWide; - break; - case ESM::Weapon::MarksmanBow: - weaptype = WeapType_BowAndArrow; - break; - case ESM::Weapon::MarksmanCrossbow: - weaptype = WeapType_Crossbow; - break; - case ESM::Weapon::MarksmanThrown: - weaptype = WeapType_ThowWeapon; - break; - } - } - } - } - else - weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); + MWWorld::ContainerStoreIterator weapon = getActiveWeapon(stats, inv, &weaptype); bool forcestateupdate = false; - if(mUpdateWeapon) - { - forcestateupdate = (mWeaponType != weaptype); - mWeaponType = weaptype; - getWeaponGroup(mWeaponType, mCurrentWeapon); - mUpdateWeapon = false; - } - if(weaptype != mWeaponType) { forcestateupdate = true; diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 9b5178b58..3cd23b57b 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -5,6 +5,12 @@ #include "../mwworld/ptr.hpp" +namespace MWWorld +{ + class ContainerStoreIterator; + class InventoryStore; +} + namespace MWRender { class Animation; @@ -14,6 +20,7 @@ namespace MWMechanics { class Movement; +class NpcStats; enum Priority { Priority_Default, @@ -133,9 +140,6 @@ class CharacterController bool mSkipAnim; - // Workaround for playing weapon draw animation and sound when going to new cell - bool mUpdateWeapon; - // counted for skill increase float mSecondsOfSwimming; float mSecondsOfRunning; @@ -146,6 +150,10 @@ class CharacterController static void getWeaponGroup(WeaponType weaptype, std::string &group); + static MWWorld::ContainerStoreIterator getActiveWeapon(NpcStats &stats, + MWWorld::InventoryStore &inv, + WeaponType *weaptype); + void clearAnimQueue(); bool updateNpcState();