From 154dcc942c6c6306aa7fcd7d7e3fcf2d025cf158 Mon Sep 17 00:00:00 2001 From: Allofich Date: Thu, 1 Sep 2016 22:43:33 +0900 Subject: [PATCH 1/4] Let NPCs use attack type regardless of movement --- apps/openmw/mwmechanics/aicombat.cpp | 20 ++++++++++---------- apps/openmw/mwmechanics/character.cpp | 21 ++++++++++++++------- apps/openmw/mwmechanics/character.hpp | 1 + 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index ce66b045a..380c9acf0 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -23,7 +23,7 @@ namespace { //chooses an attack depending on probability to avoid uniformity - ESM::Weapon::AttackType chooseBestAttack(const ESM::Weapon* weapon, MWMechanics::Movement &movement); + std::string chooseBestAttack(const ESM::Weapon* weapon, MWMechanics::Movement &movement); osg::Vec3f AimDirToMovingTarget(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, const osg::Vec3f& vLastTargetPos, float duration, int weapType, float strength); @@ -630,7 +630,7 @@ namespace MWMechanics characterController.setAttackingOrSpell(true); if (!distantCombat) - chooseBestAttack(weapon, mMovement); + characterController.setAIAttackType(chooseBestAttack(weapon, mMovement)); mStrength = Misc::Rng::rollClosedProbability(); @@ -678,9 +678,9 @@ namespace MWMechanics namespace { -ESM::Weapon::AttackType chooseBestAttack(const ESM::Weapon* weapon, MWMechanics::Movement &movement) +std::string chooseBestAttack(const ESM::Weapon* weapon, MWMechanics::Movement &movement) { - ESM::Weapon::AttackType attackType; + std::string attackType; if (weapon == NULL) { @@ -690,17 +690,17 @@ ESM::Weapon::AttackType chooseBestAttack(const ESM::Weapon* weapon, MWMechanics: { movement.mPosition[0] = (Misc::Rng::rollClosedProbability() < 0.5f) ? 1.0f : -1.0f; movement.mPosition[1] = 0; - attackType = ESM::Weapon::AT_Slash; + attackType = "slash"; } else if(roll <= 0.666f) //forward punch { movement.mPosition[1] = 1; - attackType = ESM::Weapon::AT_Thrust; + attackType = "thrust"; } else { movement.mPosition[1] = movement.mPosition[0] = 0; - attackType = ESM::Weapon::AT_Chop; + attackType = "chop"; } } else @@ -715,17 +715,17 @@ ESM::Weapon::AttackType chooseBestAttack(const ESM::Weapon* weapon, MWMechanics: { movement.mPosition[0] = (Misc::Rng::rollClosedProbability() < 0.5f) ? 1.0f : -1.0f; movement.mPosition[1] = 0; - attackType = ESM::Weapon::AT_Slash; + attackType = "slash"; } else if(roll <= (slash + thrust)) { movement.mPosition[1] = 1; - attackType = ESM::Weapon::AT_Thrust; + attackType = "thrust"; } else { movement.mPosition[1] = movement.mPosition[0] = 0; - attackType = ESM::Weapon::AT_Chop; + attackType = "chop"; } } diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 38fec4e4f..93f553f19 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1208,7 +1208,6 @@ bool CharacterController::updateWeaponState() if(mUpperBodyState == UpperCharState_WeapEquiped && (mHitState == CharState_None || mHitState == CharState_Block)) { MWBase::Environment::get().getWorld()->breakInvisibility(mPtr); - mAttackType.clear(); if(mWeaponType == WeapType_Spell) { // Unset casting flag, otherwise pressing the mouse button down would @@ -1309,14 +1308,17 @@ bool CharacterController::updateWeaponState() { if (isWeapon) { - if(mPtr == getPlayer() && - Settings::Manager::getBool("best attack", "Game")) + if(mPtr == getPlayer()) { - MWWorld::ContainerStoreIterator weapon = mPtr.getClass().getInventoryStore(mPtr).getSlot(MWWorld::InventoryStore::Slot_CarriedRight); - mAttackType = getBestAttack(weapon->get()->mBase); + if (Settings::Manager::getBool("best attack", "Game")) + { + MWWorld::ContainerStoreIterator weapon = mPtr.getClass().getInventoryStore(mPtr).getSlot(MWWorld::InventoryStore::Slot_CarriedRight); + mAttackType = getBestAttack(weapon->get()->mBase); + } + else + setAttackTypeBasedOnMovement(); } - else - setAttackTypeBasedOnMovement(); + // else if (mPtr != getPlayer()) use mAttackType already set by AiCombat } else setAttackTypeRandomly(); @@ -2227,6 +2229,11 @@ void CharacterController::setAttackingOrSpell(bool attackingOrSpell) mAttackingOrSpell = attackingOrSpell; } +void CharacterController::setAIAttackType(std::string attackType) +{ + mAttackType = attackType; +} + bool CharacterController::readyToPrepareAttack() const { return (mHitState == CharState_None || mHitState == CharState_Block) diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 4661d6983..deaf63539 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -269,6 +269,7 @@ public: bool isSneaking() const; void setAttackingOrSpell(bool attackingOrSpell); + void setAIAttackType(std::string attackType); // set and used by AiCombat bool readyToPrepareAttack() const; bool readyToStartAttack() const; From 286e4bb98f6fda7187e2fc2bf322adb0ef2ef4ef Mon Sep 17 00:00:00 2001 From: Allofich Date: Thu, 1 Sep 2016 23:12:10 +0900 Subject: [PATCH 2/4] Remove attacktype movement --- apps/openmw/mwmechanics/aicombat.cpp | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 380c9acf0..0d2499e7a 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -687,21 +687,11 @@ std::string chooseBestAttack(const ESM::Weapon* weapon, MWMechanics::Movement &m //hand-to-hand deal equal damage for each type float roll = Misc::Rng::rollClosedProbability(); if(roll <= 0.333f) //side punch - { - movement.mPosition[0] = (Misc::Rng::rollClosedProbability() < 0.5f) ? 1.0f : -1.0f; - movement.mPosition[1] = 0; attackType = "slash"; - } else if(roll <= 0.666f) //forward punch - { - movement.mPosition[1] = 1; attackType = "thrust"; - } else - { - movement.mPosition[1] = movement.mPosition[0] = 0; attackType = "chop"; - } } else { @@ -712,21 +702,11 @@ std::string chooseBestAttack(const ESM::Weapon* weapon, MWMechanics::Movement &m float roll = Misc::Rng::rollClosedProbability() * (slash + chop + thrust); if(roll <= slash) - { - movement.mPosition[0] = (Misc::Rng::rollClosedProbability() < 0.5f) ? 1.0f : -1.0f; - movement.mPosition[1] = 0; attackType = "slash"; - } else if(roll <= (slash + thrust)) - { - movement.mPosition[1] = 1; attackType = "thrust"; - } else - { - movement.mPosition[1] = movement.mPosition[0] = 0; attackType = "chop"; - } } return attackType; From 0d63d75bb0faac2895273ace55f9458347e5e47b Mon Sep 17 00:00:00 2001 From: Allofich Date: Sat, 3 Sep 2016 22:40:24 +0900 Subject: [PATCH 3/4] Remove no longer used parameter --- apps/openmw/mwmechanics/aicombat.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 0d2499e7a..2926bcb95 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -23,7 +23,7 @@ namespace { //chooses an attack depending on probability to avoid uniformity - std::string chooseBestAttack(const ESM::Weapon* weapon, MWMechanics::Movement &movement); + std::string chooseBestAttack(const ESM::Weapon* weapon); osg::Vec3f AimDirToMovingTarget(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, const osg::Vec3f& vLastTargetPos, float duration, int weapType, float strength); @@ -630,7 +630,7 @@ namespace MWMechanics characterController.setAttackingOrSpell(true); if (!distantCombat) - characterController.setAIAttackType(chooseBestAttack(weapon, mMovement)); + characterController.setAIAttackType(chooseBestAttack(weapon)); mStrength = Misc::Rng::rollClosedProbability(); @@ -678,7 +678,7 @@ namespace MWMechanics namespace { -std::string chooseBestAttack(const ESM::Weapon* weapon, MWMechanics::Movement &movement) +std::string chooseBestAttack(const ESM::Weapon* weapon) { std::string attackType; From 5c2bc515fefe103d894283a8420d630ef3580ce3 Mon Sep 17 00:00:00 2001 From: Allofich Date: Sun, 4 Sep 2016 01:57:38 +0900 Subject: [PATCH 4/4] Remove overridden code in aicombat --- apps/openmw/mwmechanics/aicombat.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 2926bcb95..aa6bcdef0 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -682,18 +682,7 @@ std::string chooseBestAttack(const ESM::Weapon* weapon) { std::string attackType; - if (weapon == NULL) - { - //hand-to-hand deal equal damage for each type - float roll = Misc::Rng::rollClosedProbability(); - if(roll <= 0.333f) //side punch - attackType = "slash"; - else if(roll <= 0.666f) //forward punch - attackType = "thrust"; - else - attackType = "chop"; - } - else + if (weapon != NULL) { //the more damage attackType deals the more probability it has int slash = (weapon->mData.mSlash[0] + weapon->mData.mSlash[1])/2;