diff --git a/src/item_factory.cpp b/src/item_factory.cpp index ba103114d5c39..bef3e6f74f98a 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -486,6 +486,41 @@ void Item_factory::finalize_item_blacklist() vec.erase( iter, vec.end() ); } } + + for( const std::pair &migrate : migrations ) { + if( m_templates.find( migrate.second.replace ) == m_templates.end() ) { + debugmsg( "Replacement item for migration %s does not exist", migrate.first.c_str() ); + continue; + } + + for( std::pair> &g : m_template_groups ) { + g.second->replace_item( migrate.first, migrate.second.replace ); + } + + // replace migrated items in requirements + for( const std::pair &r : requirement_data::all() ) { + const_cast( r.second ).replace_item( migrate.first, + migrate.second.replace ); + } + + // remove any recipes used to craft the migrated item + // if there's a valid recipe, it will be for the replacement + recipe_dictionary::delete_if( [&migrate]( const recipe & r ) { + return r.result() == migrate.first; + } ); + } + for( vproto_id &vid : vehicle_prototype::get_all() ) { + vehicle_prototype &prototype = const_cast( vid.obj() ); + for( vehicle_item_spawn &vis : prototype.item_spawns ) { + for( itype_id &type_to_spawn : vis.item_ids ) { + std::map::iterator replacement = + migrations.find( type_to_spawn ); + if( replacement != migrations.end() ) { + type_to_spawn = replacement->second.replace; + } + } + } + } } void Item_factory::load_item_blacklist( const JsonObject &json )