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

Spill overflow/MIGRATION pockets from vehicle parts #60963

Merged
merged 2 commits into from
Sep 14, 2022
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
9 changes: 9 additions & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7974,6 +7974,15 @@ void map::actualize( const tripoint &grid )
return;
}

for( const std::unique_ptr<vehicle> &veh : tmpsub->vehicles ) {
// spill out items too large, MIGRATION pockets etc from vehicle parts
for( const vpart_reference &vp : veh->get_all_parts() ) {
const item &base_const = vp.part().get_base();
const_cast<item &>( base_const ).overflow( vp.pos() );
}
veh->refresh();
}

const time_duration time_since_last_actualize = calendar::turn - tmpsub->last_touched;
const bool do_funnels = grid.z >= 0;

Expand Down
24 changes: 10 additions & 14 deletions src/vehicle_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,24 +339,20 @@ int vehicle_part::ammo_consume( int qty, const tripoint &pos )

units::energy vehicle_part::consume_energy( const itype_id &ftype, units::energy wanted_energy )
{
if( base.empty() || !is_fuel_store() ) {
if( !is_fuel_store() ) {
return 0_J;
}

item &fuel = base.legacy_front();
if( fuel.typeId() == ftype ) {
cata_assert( fuel.is_fuel() );

units::energy energy_per_charge = fuel.fuel_energy() / fuel.charges;
int charges_to_use = wanted_energy / energy_per_charge;
if( !charges_to_use ) {
return 0_J;
for( item *const fuel : base.all_items_top() ) {
if( fuel->typeId() != ftype || !fuel->is_fuel() ) {
continue;
}
if( charges_to_use >= fuel.charges ) {
charges_to_use = fuel.charges;
base.clear_items();
} else {
fuel.charges -= charges_to_use;
const units::energy energy_per_charge = fuel->fuel_energy() / fuel->charges;
const int charges_wanted = static_cast<int>( wanted_energy / energy_per_charge );
const int charges_to_use = std::min( charges_wanted, fuel->charges );
fuel->charges -= charges_to_use;
if( fuel->charges == 0 ) {
base.remove_item( *fuel );
}

return charges_to_use * energy_per_charge;
Expand Down