From adbc50366b90d17fe79812f09b61ccc17bb3ee05 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 7 Sep 2014 04:46:47 +0200 Subject: [PATCH] Use random attack strength for creatures (Bug #1876) Determining the attack strength from the time the wind-up animation was held will not work properly, as most creatures don't have this animation. This fixes another balancing issue with Rieklings (they were previously using an attack strength of 1 every time). --- apps/openmw/mwclass/creature.cpp | 3 +-- apps/openmw/mwmechanics/character.cpp | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index db6079f185..6aa4d58ed0 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -277,8 +277,7 @@ namespace MWClass break; } - // I think this should be random, since attack1-3 animations don't have an attack strength like NPCs do - float damage = min + (max - min) * ::rand()/(RAND_MAX+1.0); + float damage = min + (max - min) * stats.getAttackStrength(); if (!weapon.isEmpty()) { diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index c2a934d3a1..d856b73898 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -960,6 +960,15 @@ bool CharacterController::updateWeaponState() animPlaying = mAnimation->getInfo(mCurrentWeapon, &complete); if(mUpperBodyState == UpperCharState_MinAttackToMaxAttack && mHitState != CharState_KnockDown) { + float attackStrength = complete; + if (!mPtr.getClass().isNpc()) + { + // most creatures don't actually have an attack wind-up animation, so use a uniform random value + // (even some creatures that can use weapons don't have a wind-up animation either, e.g. Rieklings) + // Note: vanilla MW uses a random value for *all* non-player actors, but we probably don't need to go that far. + attackStrength = std::min(1.f, 0.1f + std::rand() / float(RAND_MAX)); + } + if(mAttackType != "shoot") { MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); @@ -974,15 +983,15 @@ bool CharacterController::updateWeaponState() else { std::string sound = "SwishM"; - if(complete < 0.5f) + if(attackStrength < 0.5f) sndMgr->playSound3D(mPtr, sound, 1.0f, 0.8f); //Weak attack - else if(complete < 1.0f) + else if(attackStrength < 1.0f) sndMgr->playSound3D(mPtr, sound, 1.0f, 1.0f); //Medium attack else sndMgr->playSound3D(mPtr, sound, 1.0f, 1.2f); //Strong attack } } - stats.setAttackStrength(complete); + stats.setAttackStrength(attackStrength); mAnimation->disable(mCurrentWeapon); mAnimation->play(mCurrentWeapon, Priority_Weapon,