Skip to content

Commit

Permalink
fix NPC pulping
Browse files Browse the repository at this point in the history
  • Loading branch information
SurFlurer committed Mar 15, 2024
1 parent 84b2f37 commit 43def57
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,7 @@ void activity_handlers::pulp_finish( player_activity *act, Character *you )
if( you->is_npc() ) {
npc *guy = dynamic_cast<npc *>( you );
guy->revert_after_activity();
guy->pulp_location.reset();
} else {
act->set_to_null();
}
Expand Down
4 changes: 2 additions & 2 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
19 changes: 9 additions & 10 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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()
Expand Down

0 comments on commit 43def57

Please sign in to comment.