From 22d990697871d2aeb82799159ee13b4455573e87 Mon Sep 17 00:00:00 2001 From: Max Yari Date: Thu, 20 Jun 2024 16:58:24 +0200 Subject: [PATCH] An ability to specify attack type in controls.use value --- apps/openmw/mwmechanics/actors.cpp | 18 +++++++++++++++++- apps/openmw/mwmechanics/character.cpp | 12 +++++++++++- apps/openmw/mwmechanics/character.hpp | 2 ++ apps/openmw/mwmechanics/creaturestats.cpp | 1 + apps/openmw/mwmechanics/creaturestats.hpp | 4 ++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 525044d55c..1a6f224c0a 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -239,6 +239,18 @@ namespace MWMechanics namespace { + std::string_view attackTypeName(int attackTypeNum) + { + if (attackTypeNum == 1) + return "chop"; + else if (attackTypeNum == 2) + return "slash"; + else if (attackTypeNum == 3) + return "thrust"; + else + return ""; + } + float getTimeToDestination(const AiPackage& package, const osg::Vec3f& position, float speed, float duration, const osg::Vec3f& halfExtents) { @@ -363,7 +375,11 @@ namespace MWMechanics mov.mSpeedFactor = osg::Vec2(controls.mMovement, controls.mSideMovement).length(); stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Run, controls.mRun); stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Sneak, controls.mSneak); - stats.setAttackingOrSpell((controls.mUse & 1) == 1); + + int attackTypeNum = controls.mUse & 3; + stats.setAttackingOrSpell(attackTypeNum != 0); + stats.setAttackType(attackTypeName(attackTypeNum)); + controls.mChanged = false; } // For the player we don't need to copy these values to Lua because mwinput doesn't change them. diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 287e5d035c..1a396c9ce9 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1674,7 +1674,12 @@ namespace MWMechanics } } else if (aiInactive) - mAttackType = getRandomAttackType(); + { + mAttackType = getDesiredAttackType(); + if (mAttackType == "") + mAttackType = getRandomAttackType(); + } + // else if (mPtr != getPlayer()) use mAttackType set by AiCombat startKey = mAttackType + ' ' + startKey; stopKey = mAttackType + " max attack"; @@ -3002,6 +3007,11 @@ namespace MWMechanics return mPtr.getClass().getCreatureStats(mPtr).getAttackingOrSpell(); } + std::string_view CharacterController::getDesiredAttackType() const + { + return mPtr.getClass().getCreatureStats(mPtr).getAttackType(); + } + void CharacterController::setActive(int active) const { mAnimation->setActive(active); diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 8ead23f659..f043419a81 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -247,6 +247,8 @@ namespace MWMechanics bool getAttackingOrSpell() const; void setAttackingOrSpell(bool attackingOrSpell) const; + std::string_view getDesiredAttackType() const; + void prepareHit(); public: diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 98bfa59c89..e3fed90d58 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -45,6 +45,7 @@ namespace MWMechanics , mSideMovementAngle(0) , mLevel(0) , mAttackingOrSpell(false) + , mAttackType("") { for (const ESM::Attribute& attribute : MWBase::Environment::get().getESMStore()->get()) { diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 7989357634..3f7c57094c 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -97,6 +97,7 @@ namespace MWMechanics protected: int mLevel; bool mAttackingOrSpell; + std::string mAttackType; public: CreatureStats(); @@ -130,6 +131,7 @@ namespace MWMechanics const MagicEffects& getMagicEffects() const; bool getAttackingOrSpell() const { return mAttackingOrSpell; } + std::string_view getAttackType() const { return mAttackType; } int getLevel() const; @@ -156,6 +158,8 @@ namespace MWMechanics void setAttackingOrSpell(bool attackingOrSpell) { mAttackingOrSpell = attackingOrSpell; } + void setAttackType(std::string_view attackType) { mAttackType = attackType; } + void setLevel(int level); void setAiSetting(AiSetting index, Stat value);