Skip to content

Commit

Permalink
Merge pull request #65852 from TimPollard/gun_random_capacity_rework
Browse files Browse the repository at this point in the history
Using default mags to calculate max capacity for guns with random ammo
  • Loading branch information
Rivet-the-Zombie authored May 30, 2023
2 parents 9ffcd2b + 23b3343 commit dc4fd35
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/item_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,22 @@ void Item_modifier::modify( item &new_item, const std::string &context ) const
}

int max_capacity = -1;
if( charges.first != -1 && charges.second == -1 && new_item.is_magazine() ) {
const int max_ammo = new_item.ammo_capacity( item_controller->find_template(
new_item.ammo_default() )->ammo->type );

if( charges.first != -1 && charges.second == -1 && ( new_item.is_magazine() ||
new_item.uses_magazine() ) ) {
int max_ammo = 0;

if( new_item.is_magazine() ) {
// Get the ammo capacity of the new item itself
max_ammo = new_item.ammo_capacity( item_controller->find_template(
new_item.ammo_default() )->ammo->type );
} else if( !new_item.magazine_default().is_null() ) {
// Get the capacity of the item's default magazine
max_ammo = item_controller->find_template( new_item.magazine_default() )->magazine->capacity;
}
// Don't change the ammo capacity from 0 if the item isn't a magazine
// and doesn't have a default magazine with a capacity

if( max_ammo > 0 ) {
max_capacity = max_ammo;
}
Expand Down

0 comments on commit dc4fd35

Please sign in to comment.