From 4c0191c22d8ad19493b77a6282ec649f81b1059c Mon Sep 17 00:00:00 2001 From: Matthew Jimenez Date: Tue, 20 Dec 2022 22:41:41 -0600 Subject: [PATCH] ULTIMA8: Fix attacking backwards by turning to direction first --- .../world/actors/avatar_mover_process.cpp | 50 ++++++++++--------- .../world/actors/u8_avatar_mover_process.cpp | 2 +- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/engines/ultima/ultima8/world/actors/avatar_mover_process.cpp b/engines/ultima/ultima8/world/actors/avatar_mover_process.cpp index 0285039471e..5c90621dcab 100644 --- a/engines/ultima/ultima8/world/actors/avatar_mover_process.cpp +++ b/engines/ultima/ultima8/world/actors/avatar_mover_process.cpp @@ -81,34 +81,38 @@ void AvatarMoverProcess::run() { bool AvatarMoverProcess::checkTurn(Direction direction, bool moving) { Actor *avatar = getControlledActor(); Direction curdir = avatar->getDir(); - bool combat = avatar->isInCombat() && !avatar->hasActorFlags(Actor::ACT_COMBATRUN); - - // Note: don't need to turn if moving backward in combat stance - // CHECKME: currently, first turn in the right direction - if (direction != curdir && !(combat && Direction_Invert(direction) == curdir)) { - Animation::Sequence lastanim = avatar->getLastAnim(); - - if (moving && - (lastanim == Animation::walk || lastanim == Animation::run || - lastanim == Animation::combatStand || - (GAME_IS_CRUSADER && (lastanim == Animation::startRunSmallWeapon || - lastanim == Animation::combatRunSmallWeapon))) && - (ABS(direction - curdir) + 2) % 16 <= 4) { - // don't need to explicitly do a turn animation - return false; - } - - if (moving && lastanim == Animation::run) { - // slow down to a walk first - waitFor(avatar->doAnim(Animation::walk, curdir)); - return true; - } + if (direction == curdir) + return false; + if (!moving) { turnToDirection(direction); return true; } - return false; + // Do not turn if moving backward in combat stance + bool combat = avatar->isInCombat() && !avatar->hasActorFlags(Actor::ACT_COMBATRUN); + if (combat && Direction_Invert(direction) == curdir) + return false; + + Animation::Sequence lastanim = avatar->getLastAnim(); + + // Check if we don't need to explicitly do a turn animation + if ((lastanim == Animation::walk || lastanim == Animation::run || + lastanim == Animation::combatStand || + (GAME_IS_CRUSADER && (lastanim == Animation::startRunSmallWeapon || + lastanim == Animation::combatRunSmallWeapon))) && + (ABS(direction - curdir) + 2) % 16 <= 4) { + return false; + } + + if (lastanim == Animation::run) { + // slow down to a walk first + waitFor(avatar->doAnim(Animation::walk, curdir)); + return true; + } + + turnToDirection(direction); + return true; } void AvatarMoverProcess::turnToDirection(Direction direction) { diff --git a/engines/ultima/ultima8/world/actors/u8_avatar_mover_process.cpp b/engines/ultima/ultima8/world/actors/u8_avatar_mover_process.cpp index f2902a62c1e..12ef395bddc 100644 --- a/engines/ultima/ultima8/world/actors/u8_avatar_mover_process.cpp +++ b/engines/ultima/ultima8/world/actors/u8_avatar_mover_process.cpp @@ -150,7 +150,7 @@ void U8AvatarMoverProcess::handleCombatMode() { // double left click = attack // pout << "AvatarMover: combat attack" << Std::endl; - if (checkTurn(mousedir, true)) + if (checkTurn(mousedir, false)) return; waitFor(avatar->doAnim(Animation::attack, mousedir));