diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index 92631d1f333d4..99829781b0eb0 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -3473,9 +3473,6 @@ void vehicle::deserialize( const JsonObject &data ) auto it = vp.part().items.begin(); auto end = vp.part().items.end(); for( ; it != end; ++it ) { - if( it->needs_processing() ) { - active_items.add( *it, vp.mount() ); - } // remove after 0.F if( savegame_loading_version < 33 ) { migrate_item_charges( *it ); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index eb51c7fa5bbed..ac704ba92488b 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -5778,6 +5778,20 @@ void vehicle::enable_refresh() refresh(); } +void vehicle::refresh_active_item_cache() +{ + // Need to manually backfill the active item cache since the part loader can't call its vehicle. + for( const vpart_reference &vp : get_any_parts( VPFLAG_CARGO ) ) { + auto it = vp.part().items.begin(); + auto end = vp.part().items.end(); + for( ; it != end; ++it ) { + if( it->needs_processing() ) { + active_items.add( *it, vp.mount() ); + } + } + } +} + /** * Refreshes all caches and refinds all parts. Used after the vehicle has had a part added or removed. * Makes indices of different part types so they're easy to find. Also calculates power drain. @@ -6064,6 +6078,7 @@ void vehicle::refresh( const bool remove_fakes ) zones_dirty = true; invalidate_mass(); occupied_cache_pos = { -1, -1, -1 }; + refresh_active_item_cache(); } vpart_edge_info vehicle::get_edge_info( const point &mount ) const diff --git a/src/vehicle.h b/src/vehicle.h index a05ed1f3ef6dc..60a169a8b83b7 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -837,6 +837,9 @@ class vehicle //Refresh all caches and re-locate all parts void refresh( bool remove_fakes = true ); + // Refresh active_item cache for vehicle parts + void refresh_active_item_cache(); + /** * Set stat for part constrained by range [0,durability] * @note does not invoke base @ref item::on_damage callback