Skip to content

Commit

Permalink
Migrate magazine compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund committed Feb 6, 2020
1 parent 20fefc0 commit 77006ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,27 @@ void Item_factory::finalize_pre( itype &obj )
}
}

// Migrate compataible magazines
for( auto kv : obj.magazines ) {
for( auto mag_it = kv.second.begin(); mag_it != kv.second.end(); ) {
auto maybe_migrated = migrated_magazines.find( *mag_it );
if( maybe_migrated != migrated_magazines.end() ) {
mag_it = kv.second.erase( mag_it );
kv.second.insert( kv.second.begin(), maybe_migrated->second );
} else {
++mag_it;
}
}
}

// Migrate default magazines
for( auto kv : obj.magazine_default ) {
auto maybe_migrated = migrated_magazines.find( kv.second );
if( maybe_migrated != migrated_magazines.end() ) {
kv.second = maybe_migrated->second;
}
}

if( obj.mod ) {
// Migrate acceptable ammo and ammo modifiers
migrate_ammo_set( obj.mod->acceptable_ammo );
Expand Down Expand Up @@ -598,6 +619,18 @@ void Item_factory::finalize_item_blacklist()
migrate.first );
}
}

// migrate magazines as well
auto maybe_mag = m_templates.find( migrate.first );
if( maybe_mag != m_templates.end() && maybe_mag->second.magazine ) {
auto replacement = m_templates.find( migrate.second.replace );
if( replacement->second.magazine ) {
migrated_magazines.emplace( std::make_pair( migrate.first, migrate.second.replace ) );
} else {
debugmsg( "Replacement item %s for migrated magazine %s is not a magazine.", migrate.second.replace,
migrate.first );
}
}
}
for( vproto_id &vid : vehicle_prototype::get_all() ) {
vehicle_prototype &prototype = const_cast<vehicle_prototype &>( vid.obj() );
Expand Down
1 change: 1 addition & 0 deletions src/item_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class Item_factory
GroupMap m_template_groups;

std::unordered_map<itype_id, ammotype> migrated_ammo;
std::unordered_map<itype_id, itype_id> migrated_magazines;

/** Checks that ammo is listed in ammunition_type::name().
* At least one instance of this ammo type should be defined.
Expand Down

0 comments on commit 77006ce

Please sign in to comment.