Skip to content

Commit

Permalink
Add weapon ammo to the weapon name (#36474)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hirmuolio authored and kevingranade committed Dec 30, 2019
1 parent 73660c1 commit e4f70f4
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
@@ -4024,16 +4024,31 @@ std::string item::display_name( unsigned int quantity ) const
max_amount = to_joule( type->battery->max_capacity );
}

std::string ammotext;
if( ( ( is_gun() && ammo_required() ) || is_magazine() ) && get_option<bool>( "AMMO_IN_NAMES" ) ) {
if( ammo_current() != "null" ) {
ammotext = find_type( ammo_current() )->ammo->type->name();
} else {
ammotext = ammotype( *ammo_types().begin() )->name();
}
}

if( amount || show_amt ) {
if( is_money() ) {
amt = string_format( " $%.2f", amount / 100.0 );
} else {
if( ammotext != "" ) {
ammotext = " " + ammotext;
}

if( max_amount != 0 ) {
amt = string_format( " (%i/%i)", amount, max_amount );
amt = string_format( " (%i/%i%s)", amount, max_amount, ammotext );
} else {
amt = string_format( " (%i)", amount );
amt = string_format( " (%i%s)", amount, ammotext );
}
}
} else if( ammotext != "" ) {
amt = " (" + ammotext + ")";
}

// This is a hack to prevent possible crashing when displaying maps as items during character creation
4 changes: 4 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
@@ -1544,6 +1544,10 @@ void options_manager::add_options_interface()
translate_marker( "If true, show item symbols in inventory and pick up menu." ),
false
);
add( "AMMO_IN_NAMES", "interface", translate_marker( "Add ammo to weapon/magazine names" ),
translate_marker( "If true, the default ammo is added to weapon and magazine names. For example \"Mosin-Nagant M44 (4/5)\" becomes \"Mosin-Nagant M44 (4/5 7.62x54mm)\"." ),
true
);

mOptionsSort["interface"]++;

0 comments on commit e4f70f4

Please sign in to comment.