diff --git a/src/map.cpp b/src/map.cpp index 15164651c649e..508f2c5a9d90a 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -7974,6 +7974,15 @@ void map::actualize( const tripoint &grid ) return; } + for( const std::unique_ptr &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( 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; diff --git a/src/vehicle_part.cpp b/src/vehicle_part.cpp index a5fdd44a9b100..57e2197625f3e 100644 --- a/src/vehicle_part.cpp +++ b/src/vehicle_part.cpp @@ -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( 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;