Skip to content

Commit

Permalink
Merge pull request #32164 from davidpwbrown/npc_running_off_fix
Browse files Browse the repository at this point in the history
NPC running off fix
  • Loading branch information
ZhilkinSerg authored Jul 6, 2019
2 parents a44b11a + e180a47 commit 5101125
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,10 @@ void npc::revert_after_activity()
{
mission = previous_mission;
attitude = previous_attitude;
activity = player_activity();
current_activity.clear();
clear_destination();
backlog.clear();
}

npc_mission npc::get_previous_mission()
Expand Down Expand Up @@ -1688,7 +1692,7 @@ bool npc::is_patrolling() const

bool npc::has_player_activity() const
{
return activity && mission == NPC_MISSION_ACTIVITY;
return activity && mission == NPC_MISSION_ACTIVITY && attitude == NPCATT_ACTIVITY;
}

bool npc::is_travelling() const
Expand Down Expand Up @@ -2654,7 +2658,7 @@ void npc::set_mission( npc_mission new_mission )

bool npc::has_activity() const
{
return mission == NPC_MISSION_ACTIVITY;
return mission == NPC_MISSION_ACTIVITY && attitude == NPCATT_ACTIVITY;
}

npc_attitude npc::get_attitude() const
Expand Down
19 changes: 18 additions & 1 deletion src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,12 @@ void npc::move()
if( action == npc_undecided && attitude == NPCATT_ACTIVITY ) {
std::vector<tripoint> activity_route = get_auto_move_route();
if( !activity_route.empty() && !has_destination_activity() ) {
const tripoint final_destination = activity_route.back();
tripoint final_destination;
if( destination_point ) {
final_destination = g->m.getlocal( *destination_point );
} else {
final_destination = activity_route.back();
}
update_path( final_destination );
if( !path.empty() ) {
move_to_next();
Expand All @@ -780,6 +785,14 @@ void npc::move()
}

if( action == npc_undecided ) {
// an interrupted activity can cause this situation. stops allied NPCs zooming off like random NPCs
if( attitude == NPCATT_ACTIVITY && !activity ) {
revert_after_activity();
if( is_ally( g->u ) ) {
attitude = NPCATT_FOLLOW;
mission = NPC_MISSION_NULL;
}
}
if( is_stationary( true ) ) {
// if we're in a vehicle, stay in the vehicle
if( in_vehicle ) {
Expand Down Expand Up @@ -2989,7 +3002,9 @@ bool npc::do_player_activity()
if( !backlog.empty() ) {
activity = backlog.front();
backlog.pop_front();
current_activity = activity.get_verb();
} else {
current_activity.clear();
revert_after_activity();
// if we loaded after being out of the bubble for a while, we might have more
// moves than we need, so clear them
Expand Down Expand Up @@ -3841,6 +3856,8 @@ std::string npc_action_name( npc_action action )
return "Avoid friendly fire";
case npc_escape_explosion:
return "Escape explosion";
case npc_player_activity:
return "Performing activity";
default:
return "Unnamed action";
}
Expand Down
4 changes: 4 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10487,6 +10487,10 @@ void player::assign_activity( const player_activity &act, bool allow_resume )
if( activity.rooted() ) {
rooted_message();
}
if( is_npc() ) {
npc *guy = dynamic_cast<npc *>( this );
guy->current_activity = activity.get_verb();
}
}

bool player::has_activity( const activity_id &type ) const
Expand Down
2 changes: 1 addition & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,7 @@ class player : public Character
player_activity activity;
std::list<player_activity> backlog;
int volume;
cata::optional<tripoint> destination_point;
const profession *prof;

start_location_id start_location;
Expand Down Expand Up @@ -1828,7 +1829,6 @@ class player : public Character

std::vector<tripoint> auto_move_route;
player_activity destination_activity;
cata::optional<tripoint> destination_point;
// Used to make sure auto move is canceled if we stumble off course
cata::optional<tripoint> next_expected_position;
/** warnings from a faction about bad behaviour */
Expand Down

0 comments on commit 5101125

Please sign in to comment.