From 382b68a081e449dd8f229f438e3947ac0a5c91c3 Mon Sep 17 00:00:00 2001 From: Capostrophic <21265616+Capostrophic@users.noreply.github.com> Date: Wed, 1 Aug 2018 19:27:19 +0300 Subject: [PATCH 1/6] Combat AI: take the actual hit chance in account when rating weapon --- apps/openmw/mwmechanics/weaponpriority.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/weaponpriority.cpp b/apps/openmw/mwmechanics/weaponpriority.cpp index 5a0bd9c154..f3d00c606e 100644 --- a/apps/openmw/mwmechanics/weaponpriority.cpp +++ b/apps/openmw/mwmechanics/weaponpriority.cpp @@ -103,7 +103,10 @@ namespace MWMechanics int skill = item.getClass().getEquipmentSkill(item); if (skill != -1) - rating *= actor.getClass().getSkill(actor, skill) / 100.f; + { + MWMechanics::SkillValue& value = actor.getClass().getSkill(actor, skill); + rating *= MWMechanics::getHitChance(actor, enemy, value) / 100.f; + } // There is no need to apply bonus if weapon rating == 0 if (rating == 0.f) From bec47dfb7c63e369bad925fa666705be59f5442a Mon Sep 17 00:00:00 2001 From: Capostrophic <21265616+Capostrophic@users.noreply.github.com> Date: Wed, 1 Aug 2018 19:41:49 +0300 Subject: [PATCH 2/6] Make ranged weapon bonus a distance-dependent multiplier --- apps/openmw/mwmechanics/weaponpriority.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwmechanics/weaponpriority.cpp b/apps/openmw/mwmechanics/weaponpriority.cpp index f3d00c606e..e1c2eaa344 100644 --- a/apps/openmw/mwmechanics/weaponpriority.cpp +++ b/apps/openmw/mwmechanics/weaponpriority.cpp @@ -30,7 +30,7 @@ namespace MWMechanics return 0.f; float rating=0.f; - float bonus=0.f; + float rangedMult=1.f; if (weapon->mData.mType >= ESM::Weapon::MarksmanBow && weapon->mData.mType <= ESM::Weapon::MarksmanThrown) { @@ -44,7 +44,8 @@ namespace MWMechanics if (MWBase::Environment::get().getWorld()->isUnderwater(MWWorld::ConstPtr(enemy), 0.75f)) return 0.f; - bonus+=1.5f; + if (getDistanceMinusHalfExtents(actor, enemy) >= getMaxAttackDistance(enemy)) + rangedMult = 1.5f; } if (weapon->mData.mType >= ESM::Weapon::MarksmanBow) @@ -104,15 +105,11 @@ namespace MWMechanics int skill = item.getClass().getEquipmentSkill(item); if (skill != -1) { - MWMechanics::SkillValue& value = actor.getClass().getSkill(actor, skill); + int value = actor.getClass().getSkill(actor, skill); rating *= MWMechanics::getHitChance(actor, enemy, value) / 100.f; } - // There is no need to apply bonus if weapon rating == 0 - if (rating == 0.f) - return 0.f; - - return rating + bonus; + return rating * rangedMult; } float rateAmmo(const MWWorld::Ptr &actor, const MWWorld::Ptr &enemy, MWWorld::Ptr &bestAmmo, ESM::Weapon::Type ammoType) From 9d85b7c2d3bdea59933b9f89d4da61aaf8a4d4dd Mon Sep 17 00:00:00 2001 From: Capostrophic <21265616+Capostrophic@users.noreply.github.com> Date: Thu, 2 Aug 2018 15:20:07 +0300 Subject: [PATCH 3/6] Use the actual damage for deducting weapon rating --- apps/openmw/mwmechanics/weaponpriority.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmechanics/weaponpriority.cpp b/apps/openmw/mwmechanics/weaponpriority.cpp index e1c2eaa344..6d7cbf07d8 100644 --- a/apps/openmw/mwmechanics/weaponpriority.cpp +++ b/apps/openmw/mwmechanics/weaponpriority.cpp @@ -50,20 +50,27 @@ namespace MWMechanics if (weapon->mData.mType >= ESM::Weapon::MarksmanBow) { - rating = (weapon->mData.mChop[0] + weapon->mData.mChop[1]) / 2.f; + float rangedDamage = weapon->mData.mChop[0] + weapon->mData.mChop[1]; + MWMechanics::adjustWeaponDamage(rangedDamage, item, actor); + + rating = rangedDamage / 2.f; if (weapon->mData.mType >= ESM::Weapon::MarksmanThrown) MWMechanics::resistNormalWeapon(enemy, actor, item, rating); } else { + float meleeDamage = 0.f; + for (int i=0; i<2; ++i) { - rating += weapon->mData.mSlash[i]; - rating += weapon->mData.mThrust[i]; - rating += weapon->mData.mChop[i]; + meleeDamage += weapon->mData.mSlash[i]; + meleeDamage += weapon->mData.mThrust[i]; + meleeDamage += weapon->mData.mChop[i]; } - rating /= 6.f; + + MWMechanics::adjustWeaponDamage(meleeDamage, item, actor); + rating = meleeDamage / 6.f; MWMechanics::resistNormalWeapon(enemy, actor, item, rating); } From 433c24562e573044fbb7aa46d9e470c4eca7445a Mon Sep 17 00:00:00 2001 From: Capostrophic <21265616+Capostrophic@users.noreply.github.com> Date: Fri, 3 Aug 2018 14:06:09 +0300 Subject: [PATCH 4/6] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1923e52377..930e828bb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,9 @@ Bug #4510: Division by zero in MWMechanics::CreatureStats::setAttribute Bug #4519: Knockdown does not discard movement in the 1st-person mode Bug #4539: Paper Doll is affected by GUI scaling + Bug #4548: Weapon priority: use the actual chance to hit the target instead of weapon skill + Bug #4549: Weapon priority: use the actual damage in weapon rating calculations + Bug #4550: Weapon priority: make ranged weapon bonus more sensible Feature #2606: Editor: Implemented (optional) case sensitive global search Feature #3083: Play animation when NPC is casting spell via script Feature #3276: Editor: Search- Show number of (remaining) search results and indicate a search without any results From 2f44acafe2b761347ac632113a98dc703d07f4ae Mon Sep 17 00:00:00 2001 From: Capostrophic <21265616+Capostrophic@users.noreply.github.com> Date: Fri, 3 Aug 2018 14:15:03 +0300 Subject: [PATCH 5/6] Fix changelog --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c06a15549..c741c02545 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,15 +76,13 @@ Bug #4519: Knockdown does not discard movement in the 1st-person mode Bug #4539: Paper Doll is affected by GUI scaling Bug #4545: Creatures flee from werewolves - Bug #4548: Weapon priority: use the actual chance to hit the target instead of weapon skill - Bug #4549: Weapon priority: use the actual damage in weapon rating calculations - Bug #4550: Weapon priority: make ranged weapon bonus more sensible Feature #2606: Editor: Implemented (optional) case sensitive global search Feature #3083: Play animation when NPC is casting spell via script Feature #3103: Provide option for disposition to get increased by successful trade Feature #3276: Editor: Search- Show number of (remaining) search results and indicate a search without any results Feature #3641: Editor: Limit FPS in 3d preview window Feature #3703: Ranged sneak attack criticals + Feature #4012: Editor: Write a log file if OpenCS crashes Feature #4222: 360° screenshots Feature #4256: Implement ToggleBorders (TB) console command Feature #4324: Add CFBundleIdentifier in Info.plist to allow for macOS function key shortcuts @@ -93,9 +91,11 @@ Feature #4444: Per-group KF-animation files support Feature #4466: Editor: Add option to ignore "Base" records when running verifier Feature #4488: Make water shader rougher during rain - Feature #4012: Editor: Write a log file if OpenCS crashes Feature #4509: Show count of enchanted items in stack in the spells list Feature #4512: Editor: Use markers for lights and creatures levelled lists + Feature #4548: Weapon priority: use the actual chance to hit the target instead of weapon skill + Feature #4549: Weapon priority: use the actual damage in weapon rating calculations + Feature #4550: Weapon priority: make ranged weapon bonus more sensible Task #2490: Don't open command prompt window on Release-mode builds automatically Task #4545: Enable is_pod string test From d15dcaff68fcf085ba56d4bf6bfa08b881b581ba Mon Sep 17 00:00:00 2001 From: Capostrophic <21265616+Capostrophic@users.noreply.github.com> Date: Fri, 3 Aug 2018 19:22:58 +0300 Subject: [PATCH 6/6] Don't adjust weapon rating according to weapon condition twice --- apps/openmw/mwmechanics/weaponpriority.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/openmw/mwmechanics/weaponpriority.cpp b/apps/openmw/mwmechanics/weaponpriority.cpp index 6d7cbf07d8..26c784c4d3 100644 --- a/apps/openmw/mwmechanics/weaponpriority.cpp +++ b/apps/openmw/mwmechanics/weaponpriority.cpp @@ -79,7 +79,6 @@ namespace MWMechanics { if (item.getClass().getItemHealth(item) == 0) return 0.f; - rating *= item.getClass().getItemHealth(item) / float(item.getClass().getItemMaxHealth(item)); } if (weapon->mData.mType == ESM::Weapon::MarksmanBow)