Skip to content

Commit

Permalink
Handle default magazines properly for items with magazine_adaptor mods (
Browse files Browse the repository at this point in the history
CleverRaven#35278)

* Handle magazine_adaptor mods in magazine_default

* Fix ar15_retool_300blk ammotypes
  • Loading branch information
Matthew Taylor authored and ZhilkinSerg committed Nov 3, 2019
1 parent ffa0b28 commit 26ddfe9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
19 changes: 2 additions & 17 deletions data/json/items/gun/300BLK.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,9 @@
},
{
"id": "ar15_retool_300blk",
"copy-from": "rifle_semi",
"copy-from": "ar15",
"type": "GUN",
"name": "AR-15",
"//": "This is assumed to be the standard model matching the (currently not in-game) M16.",
"description": "This ubiquitous rifle is the forefather of M16 rifle series. It is lightweight and accurate, but will malfunction if not properly maintained. This one is a semi automatic civilian version.",
"weight": "2815 g",
"volume": "2 L",
"price": 125000,
"to_hit": -1,
"bashing": 12,
"material": [ "steel", "plastic" ],
"symbol": "(",
"color": "dark_gray",
"ammo": "300blk",
"dispersion": 150,
"durability": 7,
"min_cycle_recoil": 1350,
"default_mods": [ "retool_ar15_300blk" ],
"magazines": [ [ "300blk", [ "stanag30", "stanag50", "survivor223mag" ] ] ]
"default_mods": [ "retool_ar15_300blk" ]
}
]
10 changes: 10 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6662,6 +6662,16 @@ bool item::magazine_integral() const
itype_id item::magazine_default( bool conversion ) const
{
if( !ammo_types( conversion ).empty() ) {
if( conversion ) {
for( const item *m : is_gun() ? gunmods() : toolmods() ) {
if( !m->type->mod->magazine_adaptor.empty() ) {
auto mags = m->type->mod->magazine_adaptor.find( ammotype( *ammo_types( conversion ).begin() ) );
if( mags != m->type->mod->magazine_adaptor.end() ) {
return *( mags->second.begin() );
}
}
}
}
auto mag = type->magazine_default.find( ammotype( *ammo_types( conversion ).begin() ) );
if( mag != type->magazine_default.end() ) {
return mag->second;
Expand Down

0 comments on commit 26ddfe9

Please sign in to comment.