Skip to content

Commit

Permalink
Use map::has_nearby_table for eating/butchering
Browse files Browse the repository at this point in the history
Factoring out the similar loops to check for nearby tables,
and using the new `map::has_nearby_table` function instead.
  • Loading branch information
wapcaplet committed Feb 7, 2020
1 parent 73da9d2 commit f4d6648
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 25 deletions.
10 changes: 1 addition & 9 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,6 @@ static void set_up_butchery( player_activity &act, player &u, butcher_type actio
}
}

bool has_table_nearby = false;
for( const tripoint &pt : g->m.points_in_radius( u.pos(), 2 ) ) {
if( g->m.has_flag_furn( flag_FLAT_SURF, pt ) || g->m.has_flag( flag_FLAT_SURF, pt ) ||
( ( g->m.veh_at( pt ) && ( g->m.veh_at( pt )->vehicle().has_part( flag_KITCHEN ) ||
g->m.veh_at( pt )->vehicle().has_part( flag_FLAT_SURF ) ) ) ) ) {
has_table_nearby = true;
}
}
bool has_tree_nearby = false;
for( const tripoint &pt : g->m.points_in_radius( u.pos(), 2 ) ) {
if( g->m.has_flag( flag_TREE, pt ) ) {
Expand Down Expand Up @@ -448,7 +440,7 @@ static void set_up_butchery( player_activity &act, player &u, butcher_type actio
act.targets.pop_back();
return;
}
if( !has_table_nearby ) {
if( !g->m.has_nearby_table( u.pos(), 2 ) ) {
u.add_msg_if_player( m_info,
_( "To perform a full butchery on a corpse this big, you need a table nearby or something else with a flat surface. A leather tarp spread out on the ground could suffice." ) );
act.targets.pop_back();
Expand Down
10 changes: 1 addition & 9 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,14 +1425,6 @@ static activity_reason_info can_do_activity_there( const activity_id &act, playe
corpses.push_back( i );
}
}
bool has_table_nearby = false;
for( const tripoint &pt : g->m.points_in_radius( src_loc, 2 ) ) {
if( g->m.has_flag_furn( flag_FLAT_SURF, pt ) || g->m.has_flag( flag_FLAT_SURF, pt ) ||
( ( g->m.veh_at( pt ) && ( g->m.veh_at( pt )->vehicle().has_part( flag_KITCHEN ) ||
g->m.veh_at( pt )->vehicle().has_part( flag_FLAT_SURF ) ) ) ) ) {
has_table_nearby = true;
}
}
bool b_rack_present = false;
for( const tripoint &pt : g->m.points_in_radius( src_loc, 2 ) ) {
if( g->m.has_flag_furn( flag_BUTCHER_EQ, pt ) ) {
Expand All @@ -1441,7 +1433,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, playe
}
if( !corpses.empty() ) {
if( big_count > 0 && small_count == 0 ) {
if( !has_table_nearby || !b_rack_present ) {
if( !b_rack_present || !g->m.has_nearby_table( src_loc, 2 ) ) {
return activity_reason_info::fail( NO_ZONE );
}
if( p.has_quality( quality_id( qual_BUTCHER ), 1 ) && ( p.has_quality( qual_SAW_W ) ||
Expand Down
8 changes: 1 addition & 7 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,20 +840,14 @@ bool player::eat( item &food, bool force )
add_msg_player_or_npc( _( "You eat your %s." ), _( "<npcname> eats a %s." ),
food.tname() );
if( !spoiled && !food.has_flag( flag_ALLERGEN_JUNK ) ) {
bool has_table_nearby = false;
bool has_chair_nearby = false;
for( const tripoint &pt : g->m.points_in_radius( pos(), 1 ) ) {
if( g->m.has_flag_furn( flag_FLAT_SURF, pt ) || g->m.has_flag( flag_FLAT_SURF, pt ) ||
( g->m.veh_at( pt ) && ( g->m.veh_at( pt )->vehicle().has_part( "KITCHEN" ) ||
g->m.veh_at( pt )->vehicle().has_part( "FLAT_SURF" ) ) ) ) {
has_table_nearby = true;
}
if( g->m.has_flag_furn( flag_CAN_SIT, pt ) || g->m.has_flag( flag_CAN_SIT, pt ) ||
( g->m.veh_at( pt ) && ( g->m.veh_at( pt )->vehicle().has_part( "SEAT" ) ) ) ) {
has_chair_nearby = true;
}
}
if( has_chair_nearby && has_table_nearby ) {
if( has_chair_nearby && g->m.has_nearby_table( pos(), 1 ) ) {
if( has_trait( trait_TABLEMANNERS ) ) {
rem_morale( MORALE_ATE_WITHOUT_TABLE );
add_morale( MORALE_ATE_WITH_TABLE, 3, 3, 3_hours, 2_hours, true );
Expand Down
1 change: 1 addition & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2598,6 +2598,7 @@ bool map::has_nearby_table( const tripoint &p, int radius )
return true;
}
}
return false;
}

bool map::mop_spills( const tripoint &p )
Expand Down

0 comments on commit f4d6648

Please sign in to comment.