Skip to content

Commit

Permalink
new SOURCE_FIREWOOD zone (named "Source: Firewood") + make the old wa…
Browse files Browse the repository at this point in the history
…y of marking firewood source still usable
  • Loading branch information
pierredavidbelanger committed Aug 22, 2019
1 parent 2613243 commit 9b893f1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
43 changes: 34 additions & 9 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ void cancel_aim_processing();
const efftype_id effect_controlled( "controlled" );
const efftype_id effect_pet( "pet" );

const zone_type_id zone_source_firewood( "SOURCE_FIREWOOD" );

const trap_str_id tr_firewood_source( "tr_firewood_source" );
const trap_str_id tr_unfinished_construction( "tr_unfinished_construction" );

Expand Down Expand Up @@ -1392,27 +1394,47 @@ static cata::optional<tripoint> find_best_fire(
return best_fire;
}

static cata::optional<tripoint> find_best_refuel_spot( const tripoint &center )
static inline bool has_clear_path_to_pickup_items( const tripoint &from, const tripoint &to )
{
return g->m.has_items( to ) &&
g->m.accessible_items( to ) &&
g->m.clear_path( from, to, PICKUP_RANGE, 1, 100 );
}

static cata::optional<tripoint> find_refuel_spot_zone( const tripoint &center )
{
const zone_manager &mgr = zone_manager::get_manager();
const zone_type_id zone_loot_wood( "LOOT_WOOD" );
const tripoint center_abs = g->m.getabs( center );

const std::unordered_set<tripoint> &tiles_abs_unordered =
mgr.get_near( zone_loot_wood, center_abs, PICKUP_RANGE );
mgr.get_near( zone_source_firewood, center_abs, PICKUP_RANGE );
const std::vector<tripoint> &tiles_abs =
get_sorted_tiles_by_distance( center_abs, tiles_abs_unordered );

for( const tripoint &tile_abs : tiles_abs ) {
const tripoint tile = g->m.getlocal( tile_abs );
if( g->m.has_items( tile ) &&
g->m.accessible_items( tile ) &&
g->m.clear_path( center, tile, PICKUP_RANGE, 1, 100 ) ) {
if( has_clear_path_to_pickup_items( center, tile ) ) {
return tile;
}
}

return cata::optional<tripoint>();
return {};
}

static cata::optional<tripoint> find_refuel_spot_trap( const std::vector<tripoint> &from,
const tripoint &center )
{
const auto tile = std::find_if( from.begin(), from.end(), [center]( const tripoint & pt ) {
// Hacky - firewood spot is a trap and it's ID-checked
return g->m.tr_at( pt ).id == tr_firewood_source
&& has_clear_path_to_pickup_items( center, pt );
} );

if( tile != from.end() ) {
return *tile;
}

return {};
}

void try_fuel_fire( player_activity &act, player &p, const bool starting_fire )
Expand All @@ -1428,9 +1450,12 @@ void try_fuel_fire( player_activity &act, player &p, const bool starting_fire )
return;
}

const cata::optional<tripoint> refuel_spot = find_best_refuel_spot( pos );
cata::optional<tripoint> refuel_spot = find_refuel_spot_zone( pos );
if( !refuel_spot ) {
return;
refuel_spot = find_refuel_spot_trap( adjacent, pos );
if( !refuel_spot ) {
return;
}
}

// Special case: fire containers allow burning logs, so use them as fuel iif fire is contained
Expand Down
5 changes: 5 additions & 0 deletions src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ zone_manager::zone_manager()
types.emplace( zone_type_id( "LOOT_IGNORE" ),
zone_type( translate_marker( "Loot: Ignore" ),
translate_marker( "Items inside of this zone are ignored by \"sort out loot\" zone-action." ) ) );
types.emplace( zone_type_id( "SOURCE_FIREWOOD" ),
zone_type( translate_marker( "Source: Firewood" ),
translate_marker( "Source for firewood or other flammable materials in this zone may be used to automatically refuel fires. "
"This will be done to maintain light during long-running tasks that require it such as crafting or reading, "
"but not (for example) if you are simply waiting nearby." ) ) );
types.emplace( zone_type_id( "CONSTRUCTION_BLUEPRINT" ),
zone_type( translate_marker( "Construction: Blueprint" ),
translate_marker( "Designate a blueprint zone for construction." ) ) );
Expand Down

0 comments on commit 9b893f1

Please sign in to comment.