Skip to content

Commit

Permalink
Move turn-preparation to a separate function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mmind committed Feb 8, 2025
1 parent 7a0745c commit 258df8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 15 additions & 8 deletions game/world/objects/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions game/world/objects/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 258df8b

Please sign in to comment.