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

Factor out map::has_nearby_table for eating/butchering checks #37790

Merged
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
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
14 changes: 14 additions & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,20 @@ bool map::has_nearby_fire( const tripoint &p, int radius )
return false;
}

bool map::has_nearby_table( const tripoint &p, int radius )
{
for( const tripoint &pt : points_in_radius( p, radius ) ) {
const optional_vpart_position vp = veh_at( p );
if( has_flag( "FLAT_SURF", pt ) ) {
return true;
}
if( vp && ( vp->vehicle().has_part( "KITCHEN" ) || vp->vehicle().has_part( "FLAT_SURF" ) ) ) {
return true;
}
}
return false;
}

bool map::mop_spills( const tripoint &p )
{
bool retval = false;
Expand Down
5 changes: 5 additions & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,11 @@ class map
// "fire" item to be used for example when crafting or when
// a iuse function needs fire.
bool has_nearby_fire( const tripoint &p, int radius = 1 );
/**
* Check whether a table/workbench/vehicle kitchen or other flat
* surface is nearby that could be used for crafting or eating.
*/
bool has_nearby_table( const tripoint &p, int radius = 1 );
/**
* Check if creature can see some items at p. Includes:
* - check for items at this location (has_items(p))
Expand Down