Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop NPCs getting confused by stashed outbounds activities #36316

Merged
merged 1 commit into from Dec 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2773,13 +2773,11 @@ void generic_multi_activity_handler( player_activity &act, player &p )
const tripoint abspos = g->m.getabs( p.pos() );
// NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
activity_id activity_to_restore = act.id();

// Nuke the current activity, leaving the backlog alone
p.activity = player_activity();
// now we setup the target spots based on whch activity is occuring
// the set of target work spots - potentally after we have fetched required tools.
std::unordered_set<tripoint> src_set = generic_multi_activity_locations( p, activity_to_restore );

// now we have our final set of points
std::vector<tripoint> src_sorted = get_sorted_tiles_by_distance( abspos, src_set );
// now loop through the work-spot tiles and judge whether its worth travelling to it yet
Expand Down Expand Up @@ -2866,13 +2864,6 @@ void generic_multi_activity_handler( player_activity &act, player &p )
// tidy up leftover moved parts and tools left lying near the work spots.
if( player_activity( activity_to_restore ).is_multi_type() ) {
p.assign_activity( activity_id( "ACT_TIDY_UP" ) );
if( p.is_npc() ) {
npc *guy = dynamic_cast<npc *>( &p );
if( guy ) {
guy->set_attitude( NPCATT_ACTIVITY );
guy->set_mission( NPC_MISSION_ACTIVITY );
}
}
}
}
p.activity_vehicle_part_index = -1;
Expand Down
18 changes: 2 additions & 16 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,14 +1674,7 @@ bool player::uninstall_bionic( const bionic_id &b_id, player &installer, bool au
}

int success = chance_of_success - rng( 1, 100 );

if( is_npc() ) {
static_cast<npc *>( this )->set_attitude( NPCATT_ACTIVITY );
assign_activity( activity_id( "ACT_OPERATION" ), to_moves<int>( difficulty * 20_minutes ) );
static_cast<npc *>( this )->set_mission( NPC_MISSION_ACTIVITY );
} else {
assign_activity( activity_id( "ACT_OPERATION" ), to_moves<int>( difficulty * 20_minutes ) );
}
assign_activity( activity_id( "ACT_OPERATION" ), to_moves<int>( difficulty * 20_minutes ) );

activity.values.push_back( difficulty );
activity.values.push_back( success );
Expand Down Expand Up @@ -1922,14 +1915,7 @@ bool player::install_bionics( const itype &type, player &installer, bool autodoc
}

int success = chance_of_success - rng( 0, 99 );
if( is_npc() ) {
static_cast<npc *>( this )->set_attitude( NPCATT_ACTIVITY );
assign_activity( activity_id( "ACT_OPERATION" ), to_moves<int>( difficulty * 20_minutes ) );
static_cast<npc *>( this )->set_mission( NPC_MISSION_ACTIVITY );
} else {
assign_activity( activity_id( "ACT_OPERATION" ), to_moves<int>( difficulty * 20_minutes ) );
}

assign_activity( activity_id( "ACT_OPERATION" ), to_moves<int>( difficulty * 20_minutes ) );
activity.values.push_back( difficulty );
activity.values.push_back( success );
activity.values.push_back( units::to_millijoule( bionics[bioid].capacity ) );
Expand Down
1 change: 1 addition & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6757,6 +6757,7 @@ void Character::assign_activity( const player_activity &act, bool allow_resume )
rooted_message();
}
if( is_npc() ) {
cancel_stashed_activity();
npc *guy = dynamic_cast<npc *>( this );
guy->set_attitude( NPCATT_ACTIVITY );
guy->set_mission( NPC_MISSION_ACTIVITY );
Expand Down
2 changes: 0 additions & 2 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1670,9 +1670,7 @@ void basecamp::start_menial_labor()
}
validate_sort_points();

comp->set_attitude( NPCATT_ACTIVITY );
comp->assign_activity( activity_id( "ACT_MOVE_LOOT" ) );
comp->set_mission( NPC_MISSION_ACTIVITY );
popup( _( "%s goes off to clean toilets and sort loot." ), comp->disp_name() );
}

Expand Down
2 changes: 0 additions & 2 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,6 @@ void npc::start_read( item &chosen, player *pl )
act.str_values.emplace_back( "martial_art" );
}
assign_activity( act );
set_attitude( NPCATT_ACTIVITY );
set_mission( NPC_MISSION_ACTIVITY );
}

void npc::do_npc_read()
Expand Down
3 changes: 0 additions & 3 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ void npc::move()
}
regen_ai_cache();
adjust_power_cbms();

if( activity.id() == "ACT_OPERATION" ) {
execute_action( npc_player_activity );
return;// NPCs under operation should just stay still
Expand Down Expand Up @@ -849,8 +848,6 @@ void npc::move()
const std::vector<activity_id> jobs_to_rotate = job_duties[job];
if( !jobs_to_rotate.empty() ) {
assign_activity( random_entry( jobs_to_rotate ) );
set_mission( NPC_MISSION_ACTIVITY );
set_attitude( NPCATT_ACTIVITY );
action = npc_player_activity;
found_job = true;
} else {
Expand Down
20 changes: 0 additions & 20 deletions src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,12 @@ void talk_function::start_trade( npc &p )

void talk_function::sort_loot( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
p.assign_activity( activity_id( "ACT_MOVE_LOOT" ) );
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::do_construction( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
p.assign_activity( activity_id( "ACT_MULTIPLE_CONSTRUCTION" ) );
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::do_read( npc &p )
Expand All @@ -220,9 +216,7 @@ void talk_function::find_mount( npc &p )
// first find one nearby
for( monster &critter : g->all_monsters() ) {
if( p.can_mount( critter ) ) {
p.set_attitude( NPCATT_ACTIVITY );
// keep the horse still for some time, so that NPC can catch up to it nad mount it.
p.set_mission( NPC_MISSION_ACTIVITY );
p.assign_activity( activity_id( "ACT_FIND_MOUNT" ) );
p.chosen_mount = g->shared_from( critter );
// we found one, thats all we need.
Expand All @@ -237,51 +231,37 @@ void talk_function::find_mount( npc &p )

void talk_function::do_butcher( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
p.assign_activity( activity_id( "ACT_MULTIPLE_BUTCHER" ) );
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::do_chop_plank( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
p.assign_activity( activity_id( "ACT_MULTIPLE_CHOP_PLANKS" ) );
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::do_vehicle_deconstruct( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
p.assign_activity( activity_id( "ACT_VEHICLE_DECONSTRUCTION" ) );
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::do_vehicle_repair( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
p.assign_activity( activity_id( "ACT_VEHICLE_REPAIR" ) );
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::do_chop_trees( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
p.assign_activity( activity_id( "ACT_MULTIPLE_CHOP_TREES" ) );
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::do_farming( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
p.assign_activity( activity_id( "ACT_MULTIPLE_FARM" ) );
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::do_fishing( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
p.assign_activity( activity_id( "ACT_MULTIPLE_FISH" ) );
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::revert_activity( npc &p )
Expand Down