mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 06:53:52 +00:00
Issue #777: Handle creatures with weapons in CharacterController. Move attack strength to CreatureStats.
This commit is contained in:
parent
198bb0de60
commit
13646a651b
8 changed files with 35 additions and 33 deletions
|
@ -42,13 +42,14 @@ namespace MWMechanics
|
|||
|
||||
actor.getClass().getCreatureStats(actor).setMovementFlag(CreatureStats::Flag_Run, true);
|
||||
|
||||
if(actor.getTypeName() == typeid(ESM::NPC).name())
|
||||
if (actor.getClass().hasInventoryStore(actor))
|
||||
{
|
||||
MWMechanics::DrawState_ state = actor.getClass().getNpcStats(actor).getDrawState();
|
||||
MWMechanics::DrawState_ state = actor.getClass().getCreatureStats(actor).getDrawState();
|
||||
if (state == MWMechanics::DrawState_Spell || state == MWMechanics::DrawState_Nothing)
|
||||
actor.getClass().getNpcStats(actor).setDrawState(MWMechanics::DrawState_Weapon);
|
||||
actor.getClass().getCreatureStats(actor).setDrawState(MWMechanics::DrawState_Weapon);
|
||||
//MWWorld::Class::get(actor).getCreatureStats(actor).setAttackingOrSpell(true);
|
||||
}
|
||||
|
||||
ESM::Position pos = actor.getRefData().getPosition();
|
||||
const ESM::Pathgrid *pathgrid =
|
||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::Pathgrid>().search(*actor.getCell()->mCell);
|
||||
|
|
|
@ -323,7 +323,7 @@ void CharacterController::getWeaponGroup(WeaponType weaptype, std::string &group
|
|||
}
|
||||
|
||||
|
||||
MWWorld::ContainerStoreIterator CharacterController::getActiveWeapon(NpcStats &stats, MWWorld::InventoryStore &inv, WeaponType *weaptype)
|
||||
MWWorld::ContainerStoreIterator CharacterController::getActiveWeapon(CreatureStats &stats, MWWorld::InventoryStore &inv, WeaponType *weaptype)
|
||||
{
|
||||
if(stats.getDrawState() == DrawState_Spell)
|
||||
{
|
||||
|
@ -434,15 +434,16 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
|
|||
* handle knockout and death which moves the character down. */
|
||||
mAnimation->setAccumulation(Ogre::Vector3(1.0f, 1.0f, 0.0f));
|
||||
|
||||
if(mPtr.getTypeName() == typeid(ESM::NPC).name())
|
||||
if (cls.hasInventoryStore(mPtr))
|
||||
{
|
||||
getActiveWeapon(cls.getNpcStats(mPtr), cls.getInventoryStore(mPtr), &mWeaponType);
|
||||
getActiveWeapon(cls.getCreatureStats(mPtr), cls.getInventoryStore(mPtr), &mWeaponType);
|
||||
if(mWeaponType != WeapType_None)
|
||||
{
|
||||
getWeaponGroup(mWeaponType, mCurrentWeapon);
|
||||
mUpperBodyState = UpperCharState_WeapEquiped;
|
||||
mAnimation->showWeapons(true);
|
||||
}
|
||||
mAnimation->showCarriedLeft(mWeaponType != WeapType_Spell && mWeaponType != WeapType_HandToHand);
|
||||
}
|
||||
|
||||
if(!cls.getCreatureStats(mPtr).isDead())
|
||||
|
@ -517,14 +518,14 @@ bool CharacterController::updateCreatureState()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CharacterController::updateNpcState(bool inwater, bool isrunning)
|
||||
bool CharacterController::updateWeaponState(bool inwater, bool isrunning)
|
||||
{
|
||||
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
|
||||
NpcStats &stats = cls.getNpcStats(mPtr);
|
||||
CreatureStats &stats = cls.getCreatureStats(mPtr);
|
||||
WeaponType weaptype = WeapType_None;
|
||||
MWWorld::InventoryStore &inv = cls.getInventoryStore(mPtr);
|
||||
MWWorld::ContainerStoreIterator weapon = getActiveWeapon(stats, inv, &weaptype);
|
||||
const bool isWerewolf = stats.isWerewolf();
|
||||
const bool isWerewolf = cls.isNpc() && cls.getNpcStats(mPtr).isWerewolf();
|
||||
|
||||
bool forcestateupdate = false;
|
||||
if(weaptype != mWeaponType && mHitState != CharState_KnockDown)
|
||||
|
@ -613,7 +614,7 @@ bool CharacterController::updateNpcState(bool inwater, bool isrunning)
|
|||
{
|
||||
// Unset casting flag, otherwise pressing the mouse button down would
|
||||
// continue casting every frame if there is no animation
|
||||
mPtr.getClass().getCreatureStats(mPtr).setAttackingOrSpell(false);
|
||||
stats.setAttackingOrSpell(false);
|
||||
|
||||
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||
|
||||
|
@ -1128,8 +1129,8 @@ void CharacterController::update(float duration)
|
|||
}
|
||||
}
|
||||
|
||||
if(cls.isNpc())
|
||||
forcestateupdate = updateNpcState(inwater, isrunning) || forcestateupdate;
|
||||
if(cls.hasInventoryStore(mPtr))
|
||||
forcestateupdate = updateWeaponState(inwater, isrunning) || forcestateupdate;
|
||||
else
|
||||
forcestateupdate = updateCreatureState() || forcestateupdate;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace MWMechanics
|
|||
{
|
||||
|
||||
class Movement;
|
||||
class NpcStats;
|
||||
class CreatureStats;
|
||||
|
||||
enum Priority {
|
||||
Priority_Default,
|
||||
|
@ -170,13 +170,13 @@ class CharacterController
|
|||
|
||||
static void getWeaponGroup(WeaponType weaptype, std::string &group);
|
||||
|
||||
static MWWorld::ContainerStoreIterator getActiveWeapon(NpcStats &stats,
|
||||
static MWWorld::ContainerStoreIterator getActiveWeapon(CreatureStats &stats,
|
||||
MWWorld::InventoryStore &inv,
|
||||
WeaponType *weaptype);
|
||||
|
||||
void clearAnimQueue();
|
||||
|
||||
bool updateNpcState(bool inwater, bool isrunning);
|
||||
bool updateWeaponState(bool inwater, bool isrunning);
|
||||
bool updateCreatureState();
|
||||
|
||||
void updateVisibility();
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace MWMechanics
|
|||
mAttackingOrSpell(false), mAttackType(AT_Chop),
|
||||
mIsWerewolf(false),
|
||||
mFallHeight(0), mRecalcDynamicStats(false), mKnockdown(false), mHitRecovery(false),
|
||||
mMovementFlags(0), mDrawState (DrawState_Nothing)
|
||||
mMovementFlags(0), mDrawState (DrawState_Nothing), mAttackStrength(0.f)
|
||||
{
|
||||
for (int i=0; i<4; ++i)
|
||||
mAiSettings[i] = 0;
|
||||
|
@ -462,4 +462,14 @@ namespace MWMechanics
|
|||
mDrawState = state;
|
||||
}
|
||||
|
||||
float CreatureStats::getAttackStrength() const
|
||||
{
|
||||
return mAttackStrength;
|
||||
}
|
||||
|
||||
void CreatureStats::setAttackStrength(float value)
|
||||
{
|
||||
mAttackStrength = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace MWMechanics
|
|||
bool mKnockdown;
|
||||
bool mHitRecovery;
|
||||
unsigned int mMovementFlags;
|
||||
float mAttackStrength; // Note only some creatures attack with weapons
|
||||
|
||||
float mFallHeight;
|
||||
|
||||
|
@ -62,6 +63,10 @@ namespace MWMechanics
|
|||
DrawState_ getDrawState() const;
|
||||
void setDrawState(DrawState_ state);
|
||||
|
||||
/// When attacking, stores how strong the attack should be (0 = weakest, 1 = strongest)
|
||||
float getAttackStrength() const;
|
||||
void setAttackStrength(float value);
|
||||
|
||||
bool needToRecalcDynamicStats();
|
||||
|
||||
void addToFallHeight(float height);
|
||||
|
|
|
@ -28,23 +28,12 @@ MWMechanics::NpcStats::NpcStats()
|
|||
, mReputation(0)
|
||||
, mWerewolfKills (0)
|
||||
, mProfit(0)
|
||||
, mAttackStrength(0.0f)
|
||||
, mTimeToStartDrowning(20.0)
|
||||
, mLastDrowningHit(0)
|
||||
{
|
||||
mSkillIncreases.resize (ESM::Attribute::Length, 0);
|
||||
}
|
||||
|
||||
float MWMechanics::NpcStats::getAttackStrength() const
|
||||
{
|
||||
return mAttackStrength;
|
||||
}
|
||||
|
||||
void MWMechanics::NpcStats::setAttackStrength(float value)
|
||||
{
|
||||
mAttackStrength = value;
|
||||
}
|
||||
|
||||
int MWMechanics::NpcStats::getBaseDisposition() const
|
||||
{
|
||||
return mDisposition;
|
||||
|
|
|
@ -59,10 +59,6 @@ namespace MWMechanics
|
|||
int getProfit() const;
|
||||
void modifyProfit(int diff);
|
||||
|
||||
/// When attacking, stores how strong the attack should be (0 = weakest, 1 = strongest)
|
||||
float getAttackStrength() const;
|
||||
void setAttackStrength(float value);
|
||||
|
||||
int getBaseDisposition() const;
|
||||
|
||||
void setBaseDisposition(int disposition);
|
||||
|
|
|
@ -34,8 +34,8 @@ CreatureAnimation::CreatureAnimation(const MWWorld::Ptr &ptr)
|
|||
|
||||
CreatureWeaponAnimation::CreatureWeaponAnimation(const MWWorld::Ptr &ptr)
|
||||
: Animation(ptr, ptr.getRefData().getBaseNode())
|
||||
, mShowWeapons(true) // TODO: change to false, once charactercontroller handles creature weapons
|
||||
, mShowCarriedLeft(true) // TODO: change to false, once charactercontroller handles creature weapons
|
||||
, mShowWeapons(false)
|
||||
, mShowCarriedLeft(false)
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::Creature> *ref = mPtr.get<ESM::Creature>();
|
||||
|
||||
|
|
Loading…
Reference in a new issue