Add real-time combat: connecting attacks always hit

With the new [Game] 'real time combat' setting (on by default), melee
and ranged attacks that physically connect always hit. The classic hit
chance becomes a damage multiplier clamped to [0.25, 1], so weapon
skill, agility, luck, fatigue and the target's evasion still matter and
average damage stays near classic balance. Applies to NPCs, creatures
and projectiles. Set it to false for Morrowind's hit and miss rolls.

Refs #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 14:42:58 -05:00
co-authored by Claude Opus 5.5
parent 9d846231bc
commit 27e35b3ac8
9 changed files with 87 additions and 1 deletions
+6
View File
@@ -251,6 +251,10 @@ namespace MWClass
victim = result.first;
hitPosition = result.second;
// Ashlar: a swing that connects always hits; hit chance scales damage in hit() instead.
if (Settings::game().mRealTimeCombat)
return true;
float hitchance = MWMechanics::getHitChance(ptr, victim, ptr.get<ESM::Creature>()->mBase->mData.mCombat);
return Misc::Rng::roll0to99(world->getPrng()) < hitchance;
}
@@ -339,6 +343,8 @@ namespace MWClass
MWMechanics::getHandToHandDamage(ptr, victim, damage, healthdmg, attackStrength);
}
damage *= MWMechanics::getRealTimeDamageScale(ptr, victim, ref->mBase->mData.mCombat);
MWMechanics::applyElementalShields(ptr, victim);
if (MWMechanics::blockMeleeAttack(ptr, victim, weapon, damage, attackStrength))
+11
View File
@@ -561,6 +561,10 @@ namespace MWClass
victim = result.first;
hitPosition = result.second;
// Ashlar: a swing that connects always hits; hit chance scales damage in hit() instead.
if (Settings::game().mRealTimeCombat)
return true;
ESM::RefId weapskill = ESM::Skill::HandToHand;
if (!weapon.isEmpty())
weapskill = weapon.getClass().getEquipmentSkill(weapon);
@@ -630,6 +634,13 @@ namespace MWClass
MWMechanics::getHandToHandDamage(ptr, victim, damage, healthdmg, attackStrength);
}
{
ESM::RefId skill = ESM::Skill::HandToHand;
if (!weapon.isEmpty())
skill = weapon.getClass().getEquipmentSkill(weapon);
damage *= MWMechanics::getRealTimeDamageScale(ptr, victim, static_cast<int>(getSkill(ptr, skill)));
}
MWBase::World* world = MWBase::Environment::get().getWorld();
const MWWorld::Store<ESM::GameSetting>& store = world->getStore().get<ESM::GameSetting>();
+16 -1
View File
@@ -1,6 +1,7 @@
#include "combat.hpp"
#include <algorithm>
#include <array>
#include <components/misc/rng.hpp>
@@ -241,7 +242,8 @@ namespace MWMechanics
int skillValue = static_cast<int>(attacker.getClass().getSkill(attacker, weaponSkill));
if (Misc::Rng::roll0to99(world->getPrng()) >= getHitChance(attacker, victim, skillValue))
if (!Settings::game().mRealTimeCombat
&& Misc::Rng::roll0to99(world->getPrng()) >= getHitChance(attacker, victim, skillValue))
{
MWBase::Environment::get().getLuaManager()->onHit(attacker, victim, weapon, projectile, 0,
attackStrength, attackWindUp, damage, false, hitPosition, false,
@@ -261,6 +263,7 @@ namespace MWMechanics
damage += attack[0] + ((attack[1] - attack[0]) * attackStrength);
}
adjustWeaponDamage(damage, weapon, attacker);
damage *= getRealTimeDamageScale(attacker, victim, skillValue);
}
reduceWeaponCondition(damage, validVictim, weapon, attacker);
@@ -349,6 +352,18 @@ namespace MWMechanics
return round(attackTerm - defenseTerm);
}
float hitChanceToDamageScale(float hitChance)
{
return std::clamp(hitChance / 100.f, 0.25f, 1.f);
}
float getRealTimeDamageScale(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, int skillValue)
{
if (!Settings::game().mRealTimeCombat)
return 1.f;
return hitChanceToDamageScale(getHitChance(attacker, victim, skillValue));
}
void applyElementalShields(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim)
{
// Don't let elemental shields harm the player in god mode.
+7
View File
@@ -39,6 +39,13 @@ namespace MWMechanics
/// Get the chance (in percent) for \a attacker to successfully hit \a victim with a given weapon skill value
float getHitChance(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, int skillValue);
/// Ashlar real-time combat: converts a classic hit chance (in percent) into a damage multiplier.
/// It keeps average damage close to classic combat, with a floor so weak hits still count.
float hitChanceToDamageScale(float hitChance);
/// Ashlar real-time combat: damage multiplier for a hit that connected, or 1 when the setting is off.
float getRealTimeDamageScale(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, int skillValue);
/// Applies damage to attacker based on the victim's elemental shields.
void applyElementalShields(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim);
+2
View File
@@ -22,6 +22,8 @@ file(GLOB UNITTEST_SRC_FILES
mwlua/testobjectcache.cpp
mwlua/testmwscriptbindings.cpp
mwmechanics/testcombat.cpp
mwscript/testscripts.cpp
mwsound/testheadcache.cpp
@@ -0,0 +1,27 @@
#include <apps/openmw/mwmechanics/combat.hpp>
#include <gtest/gtest.h>
namespace
{
using MWMechanics::hitChanceToDamageScale;
TEST(MWMechanicsCombatTest, hitChanceToDamageScaleKeepsAverageDamageInRange)
{
EXPECT_FLOAT_EQ(hitChanceToDamageScale(50.f), 0.5f);
EXPECT_FLOAT_EQ(hitChanceToDamageScale(80.f), 0.8f);
}
TEST(MWMechanicsCombatTest, hitChanceToDamageScaleIsFullDamageForCertainHits)
{
EXPECT_FLOAT_EQ(hitChanceToDamageScale(100.f), 1.f);
EXPECT_FLOAT_EQ(hitChanceToDamageScale(180.f), 1.f);
}
TEST(MWMechanicsCombatTest, hitChanceToDamageScaleHasFloorForUnlikelyHits)
{
EXPECT_FLOAT_EQ(hitChanceToDamageScale(10.f), 0.25f);
EXPECT_FLOAT_EQ(hitChanceToDamageScale(0.f), 0.25f);
EXPECT_FLOAT_EQ(hitChanceToDamageScale(-40.f), 0.25f);
}
}
+2
View File
@@ -75,6 +75,8 @@ namespace Settings
"actor collision shape type" };
SettingValue<bool> mPlayerMovementIgnoresAnimation{ mIndex, "Game", "player movement ignores animation" };
SettingValue<bool> mTerrainObstructsFocus{ mIndex, "Game", "terrain obstructs focus" };
// Ashlar
SettingValue<bool> mRealTimeCombat{ mIndex, "Game", "real time combat" };
};
}
@@ -511,3 +511,14 @@ Game Settings
If enabled, focused object selection will account for terrain.
The default behavior matches Morrowind, allowing objects partially or totally submerged in terrain to gain focus.
.. omw-setting::
:title: real time combat
:type: boolean
:range: true, false
:default: true
Ashlar setting. If enabled, melee and ranged attacks that physically connect always hit.
The classic hit chance instead scales their damage, between 25% and 100%,
so weapon skill, agility, luck, fatigue and the target's evasion still matter.
Disable for Morrowind's hit and miss rolls.
+5
View File
@@ -393,6 +393,11 @@ player movement ignores animation = false
# Makes focused object selection account for terrain.
terrain obstructs focus = false
# Ashlar: attacks that physically connect always hit. The classic hit
# chance scales their damage instead, so skill and evasion still matter.
# Set to false for classic hit and miss rolls.
real time combat = true
[General]
# Anisotropy reduces distortion in textures at low angles (e.g. 0 to 16).