From 51020d66a000d0d6eaf12b7c7cd8346820a90235 Mon Sep 17 00:00:00 2001 From: Kevin Granade Date: Mon, 6 Jan 2020 06:21:01 +0000 Subject: [PATCH] Apply migrations to item groups and requirements and vehicle spawns --- src/item_factory.cpp | 52 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/src/item_factory.cpp b/src/item_factory.cpp index b1f25b35fc2ae..c2fa86548bbe3 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -457,32 +457,62 @@ void Item_factory::finalize() void Item_factory::finalize_item_blacklist() { - for( t_string_set::const_iterator a = item_blacklist.begin(); a != item_blacklist.end(); ++a ) { - if( !has_template( *a ) ) { - debugmsg( "item on blacklist %s does not exist", a->c_str() ); + for( const std::string &blackout : item_blacklist ) { + std::unordered_map::iterator candidate = m_templates.find( blackout ); + if( candidate == m_templates.end() ) { + debugmsg( "item on blacklist %s does not exist", blackout.c_str() ); + continue; + } + + for( auto &g : m_template_groups ) { + g.second->remove_item( candidate->first ); + } + + // remove any blacklisted items from requirements + for( auto &r : requirement_data::all() ) { + const_cast( r.second ).blacklist_item( candidate->first ); } + // remove any recipes used to craft the blacklisted item + recipe_dictionary::delete_if( [&candidate]( const recipe & r ) { + return r.result() == candidate->first; + } ); } - for( auto &e : m_templates ) { - if( !item_is_blacklisted( e.first ) ) { + for( auto &vid : vehicle_prototype::get_all() ) { + vehicle_prototype &prototype = const_cast( vid.obj() ); + for( vehicle_item_spawn &vis : prototype.item_spawns ) { + auto &vec = vis.item_ids; + const auto iter = std::remove_if( vec.begin(), vec.end(), item_is_blacklisted ); + vec.erase( iter, vec.end() ); + } + } + + for( const std::pair &migrate : migrations ) { + std::unordered_map::iterator candidate = m_templates.find( migrate.first ); + if( candidate == m_templates.end() ) { + debugmsg( "item configured for migration %s does not exist", migrate.first.c_str() ); continue; } + for( auto &g : m_template_groups ) { - g.second->remove_item( e.first ); + g.second->replace_item( candidate->first, migrate.second.replace ); } - // remove any blacklisted items from requirements + // replace migrated items in requirements for( auto &r : requirement_data::all() ) { - const_cast( r.second ).blacklist_item( e.first ); + const_cast( r.second ).replace_item( candidate->first, + migrate.second.replace ); } - // remove any recipes used to craft the blacklisted item - recipe_dictionary::delete_if( [&]( const recipe & r ) { - return r.result() == e.first; + // 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( [&candidate]( const recipe & r ) { + return r.result() == candidate->first; } ); } + // TODO: Still need to do something about this. for( auto &vid : vehicle_prototype::get_all() ) { vehicle_prototype &prototype = const_cast( vid.obj() ); for( vehicle_item_spawn &vis : prototype.item_spawns ) {