Skip to content

Commit

Permalink
Apply migrations to item groups and requirements and vehicle spawns
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade committed Jan 6, 2020
1 parent 83f1a6d commit 51020d6
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<itype_id, itype>::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<requirement_data &>( 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<vehicle_prototype &>( 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<itype_id, migration> &migrate : migrations ) {
std::unordered_map<itype_id, itype>::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<requirement_data &>( r.second ).blacklist_item( e.first );
const_cast<requirement_data &>( 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<vehicle_prototype &>( vid.obj() );
for( vehicle_item_spawn &vis : prototype.item_spawns ) {
Expand Down

0 comments on commit 51020d6

Please sign in to comment.