Skip to content

Commit

Permalink
Burn just 1 item from a stack when refueling (#34641)
Browse files Browse the repository at this point in the history
* Move items into fire to handle splitting charges
* Fix burning charged items
  • Loading branch information
AlexMooney authored and kevingranade committed Oct 13, 2019
1 parent aa3fc18 commit c266e03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
19 changes: 5 additions & 14 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2822,13 +2822,8 @@ void try_fuel_fire( player_activity &act, player &p, const bool starting_fire )
if( !contained && fire_age < -40_minutes && fd.fuel_produced > 1.0f && !it.made_of( LIQUID ) ) {
// Too much - we don't want a firestorm!
// Move item back to refueling pile
// Note: this handles messages (they're the generic "you drop x")
drop_on_map( p, item_drop_reason::deliberate, { it }, *refuel_spot );

const int distance = std::max( rl_dist( *best_fire, *refuel_spot ), 1 );
p.mod_moves( -Pickup::cost_to_move_item( p, it ) * distance );

g->m.i_rem( *best_fire, &it );
// Note: move_item() handles messages (they're the generic "you drop x")
move_item( p, it, 0, *best_fire, *refuel_spot, nullptr, -1 );
return;
}
}
Expand All @@ -2849,13 +2844,9 @@ void try_fuel_fire( player_activity &act, player &p, const bool starting_fire )
float last_fuel = fd.fuel_produced;
it.simulate_burn( fd );
if( fd.fuel_produced > last_fuel ) {
// Note: this handles messages (they're the generic "you drop x")
drop_on_map( p, item_drop_reason::deliberate, { it }, *best_fire );

const int distance = std::max( rl_dist( *refuel_spot, *best_fire ), 1 );
p.mod_moves( -Pickup::cost_to_move_item( p, it ) * distance );

g->m.i_rem( *refuel_spot, &it );
int quantity = std::max( 1, std::min( it.charges, it.charges_per_volume( 250_ml ) ) );
// Note: move_item() handles messages (they're the generic "you drop x")
move_item( p, it, quantity, *refuel_spot, *best_fire, nullptr, -1 );
return;
}
}
Expand Down
18 changes: 16 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7039,6 +7039,13 @@ float item::simulate_burn( fire_data &frd ) const
burn_added = 1;
}

if( count_by_charges() ) {
int stack_burnt = rng( type->stack_size / 2, type->stack_size );
time_added *= stack_burnt;
smoke_added *= stack_burnt;
burn_added *= stack_burnt;
}

frd.fuel_produced += time_added;
frd.smoke_produced += smoke_added;
return burn_added;
Expand All @@ -7053,10 +7060,17 @@ bool item::burn( fire_data &frd )
}

if( count_by_charges() ) {
burn_added *= rng( type->stack_size / 2, type->stack_size );
charges -= roll_remainder( burn_added );
if( type->volume == 0_ml ) {
charges = 0;
} else {
charges -= roll_remainder( burn_added * units::legacy_volume_factor * type->stack_size /
( 3.0 * type->volume ) );
}

if( charges <= 0 ) {
return true;
} else {
return false;
}
}

Expand Down

0 comments on commit c266e03

Please sign in to comment.