From 43def57f98119f89c00604d2db3bc92fa0587a2d Mon Sep 17 00:00:00 2001 From: Surflurer <22912139+Surflurer@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:26:36 +0800 Subject: [PATCH] fix NPC pulping --- src/activity_handlers.cpp | 1 + src/npc.h | 4 ++-- src/npcmove.cpp | 19 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp index 0b0e99e297d68..95468e62a1321 100644 --- a/src/activity_handlers.cpp +++ b/src/activity_handlers.cpp @@ -1865,6 +1865,7 @@ void activity_handlers::pulp_finish( player_activity *act, Character *you ) if( you->is_npc() ) { npc *guy = dynamic_cast( you ); guy->revert_after_activity(); + guy->pulp_location.reset(); } else { act->set_to_null(); } diff --git a/src/npc.h b/src/npc.h index c8eecbb7bee09..89d3234008413 100644 --- a/src/npc.h +++ b/src/npc.h @@ -1237,8 +1237,8 @@ class npc : public Character /** Returns true if it finds one. */ bool find_corpse_to_pulp(); - /** Returns true if it handles the turn. */ - bool do_pulp(); + /** Returns true if NPC can do pulp in this turn. */ + bool can_do_pulp(); /** perform a player activity, returning true if it took up the turn */ bool do_player_activity(); diff --git a/src/npcmove.cpp b/src/npcmove.cpp index 81dec3c7d1ae3..2e2094f8da68d 100644 --- a/src/npcmove.cpp +++ b/src/npcmove.cpp @@ -2515,10 +2515,14 @@ npc_action npc::address_needs( float danger ) return npc_noop; } - if( one_in( 3 ) && find_corpse_to_pulp() ) { - if( !do_pulp() ) { - move_to_next(); + if( can_do_pulp() ) { + if( !activity ) { + assign_activity( ACT_PULP, calendar::INDEFINITELY_LONG, 0 ); + activity.placement = *pulp_location; } + return npc_player_activity; + } else if( find_corpse_to_pulp() ) { + move_to_next(); return npc_noop; } @@ -3965,7 +3969,7 @@ bool npc::find_corpse_to_pulp() return corpse != nullptr; } -bool npc::do_pulp() +bool npc::can_do_pulp() { if( !pulp_location ) { return false; @@ -3974,12 +3978,7 @@ bool npc::do_pulp() if( rl_dist( *pulp_location, get_location() ) > 1 || pulp_location->z() != posz() ) { return false; } - // TODO: Don't recreate the activity every time - int old_moves = moves; - assign_activity( ACT_PULP, calendar::INDEFINITELY_LONG, 0 ); - activity.placement = *pulp_location; - activity.do_turn( *this ); - return moves != old_moves; + return true; } bool npc::do_player_activity()