Skip to content

Commit

Permalink
Add new map::has_nearby_table function
Browse files Browse the repository at this point in the history
The algorithm for nearby table location is done in at least 3 places:

- src/activity_handlers.cpp:L412-419
- src/activity_item_handling.cpp:L1428-1435
- src/consumption.cpp:L845-850

Moving `has_nearby_table` as a new function it into map.cpp made it
obvious that this is where it actually belongs; there it can fit neatly
alongside its brethren like `has_nearby_fire`.

This commit only adds the new function; refactoring will come next.
  • Loading branch information
wapcaplet committed Feb 7, 2020
1 parent 40c494c commit 73da9d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,19 @@ 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;
}
}
}

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

0 comments on commit 73da9d2

Please sign in to comment.