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

Using zone as firewood source while handling item activity #33372

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
59 changes: 50 additions & 9 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ 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 zone_type_id z_loot_unsorted( "LOOT_UNSORTED" );

const trap_str_id tr_firewood_source( "tr_firewood_source" );
Expand Down Expand Up @@ -2060,6 +2061,49 @@ static cata::optional<tripoint> find_best_fire(
return best_fire;
}

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 tripoint center_abs = g->m.getabs( center );

const std::unordered_set<tripoint> &tiles_abs_unordered =
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( has_clear_path_to_pickup_items( center, tile ) ) {
return tile;
}
}

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 )
{
const tripoint pos = p.pos();
Expand All @@ -2073,15 +2117,12 @@ void try_fuel_fire( player_activity &act, player &p, const bool starting_fire )
return;
}

const auto refuel_spot = std::find_if( adjacent.begin(), adjacent.end(),
[pos]( const tripoint & pt ) {
// Hacky - firewood spot is a trap and it's ID-checked
// TODO: Something cleaner than ID-checking a trap
return g->m.tr_at( pt ).id == tr_firewood_source && g->m.has_items( pt ) &&
g->m.accessible_items( pt ) && g->m.clear_path( pos, pt, PICKUP_RANGE, 1, 100 );
} );
if( refuel_spot == adjacent.end() ) {
return;
cata::optional<tripoint> refuel_spot = find_refuel_spot_zone( pos );
if( !refuel_spot ) {
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
4 changes: 4 additions & 0 deletions src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ 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 such as crafting, reading or waiting." ) ) );
types.emplace( zone_type_id( "CONSTRUCTION_BLUEPRINT" ),
zone_type( translate_marker( "Construction: Blueprint" ),
translate_marker( "Designate a blueprint zone for construction." ) ) );
Expand Down