Skip to content

Commit

Permalink
Refactor item blacklist application code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade committed Jan 13, 2020
1 parent 9ec036f commit 42bc661
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,33 +457,28 @@ 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( auto &e : m_templates ) {
if( !item_is_blacklisted( e.first ) ) {
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( e.first );

for( std::pair<const Group_tag, std::unique_ptr<Item_spawn_data>> &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( e.first );
for( const std::pair<const requirement_id, requirement_data> &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( [&]( const recipe & r ) {
return r.result() == e.first;
recipe_dictionary::delete_if( [&candidate]( const recipe & r ) {
return r.result() == candidate->first;
} );
}

for( auto &vid : vehicle_prototype::get_all() ) {
for( vproto_id &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;
Expand Down

0 comments on commit 42bc661

Please sign in to comment.