From 1497dae4fa8d040bdebd7a0fbc090677e4aae738 Mon Sep 17 00:00:00 2001 From: Max Yari Date: Fri, 28 Jun 2024 10:00:04 +0200 Subject: [PATCH] Better mUse out-of-range handling --- apps/openmw/mwmechanics/actors.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index e10de7122f..191ad86733 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -242,14 +242,19 @@ namespace MWMechanics { std::string_view attackTypeName(AttackType attackType) { - if (attackType == AttackType::Chop) - return "chop"; - else if (attackType == AttackType::Slash) - return "slash"; - else if (attackType == AttackType::Thrust) - return "thrust"; - else - return ""; + switch (attackType) + { + case AttackType::NoAttack: + case AttackType::Any: + return {}; + case AttackType::Chop: + return "chop"; + case AttackType::Slash: + return "slash"; + case AttackType::Thrust: + return "thrust"; + } + throw std::logic_error("Invalid attack type value: " + std::to_string(static_cast(attackType))); } float getTimeToDestination(const AiPackage& package, const osg::Vec3f& position, float speed, float duration, @@ -377,10 +382,7 @@ namespace MWMechanics stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Run, controls.mRun); stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Sneak, controls.mSneak); - // Same as mUse % max AttackType int value - AttackType attackType - = static_cast(controls.mUse % (static_cast(AttackType::Thrust) + 1)); - + AttackType attackType = static_cast(controls.mUse); stats.setAttackingOrSpell(attackType != AttackType::NoAttack); stats.setAttackType(attackTypeName(attackType));