From 258df8bfdc69c85fa80d7213e0f76f45cb061971 Mon Sep 17 00:00:00 2001 From: Heiko Stuebner Date: Wed, 29 Jan 2025 11:28:06 +0100 Subject: [PATCH] Move turn-preparation to a separate function There are multiple turning variants (regular, whirl, away) that all will need the same preparation steps, so move them to a separate function for re-use. --- game/world/objects/npc.cpp | 23 +++++++++++++++-------- game/world/objects/npc.h | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/game/world/objects/npc.cpp b/game/world/objects/npc.cpp index 38e358979..3ee6ed53a 100644 --- a/game/world/objects/npc.cpp +++ b/game/world/objects/npc.cpp @@ -2172,6 +2172,20 @@ void Npc::tick(uint64_t dt) { implAiTick(dt); } +bool Npc::prepareTurn() { + const auto st = bodyStateMasked(); + if(interactive()==nullptr && (st==BS_WALK || st==BS_SNEAK)) { + visual.stopWalkAnim(*this); + setAnimRotate(0); + return false; + } + if(interactive()==nullptr) { + visual.stopWalkAnim(*this); + visual.stopDlgAnim(*this); + } + return true; +} + void Npc::nextAiAction(AiQueue& queue, uint64_t dt) { if(isInAir()) return; @@ -2191,17 +2205,10 @@ void Npc::nextAiAction(AiQueue& queue, uint64_t dt) { break; } case AI_TurnToNpc: { - const auto st = bodyStateMasked(); - if(interactive()==nullptr && (st==BS_WALK || st==BS_SNEAK)) { - visual.stopWalkAnim(*this); - setAnimRotate(0); + if(!prepareTurn()) { queue.pushFront(std::move(act)); break; } - if(interactive()==nullptr) { - visual.stopWalkAnim(*this); - visual.stopDlgAnim(*this); - } if(act.target!=nullptr && implTurnTo(*act.target,dt)) { queue.pushFront(std::move(act)); break; diff --git a/game/world/objects/npc.h b/game/world/objects/npc.h index 026e9506d..15dc548ab 100644 --- a/game/world/objects/npc.h +++ b/game/world/objects/npc.h @@ -495,6 +495,7 @@ class Npc final { bool checkHealth(bool onChange, bool forceKill); void onNoHealth(bool death, HitSound sndMask); bool hasAutoroll() const; + bool prepareTurn(); void stopWalkAnimation(); void takeDamage(Npc& other, const Bullet* b, const CollideMask bMask, int32_t splId, bool isSpell); void takeFallDamage(const Tempest::Vec3& fallSpeed);