Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add weapon ammo to the weapon name #36474

Merged
merged 13 commits into from
Dec 30, 2019
19 changes: 17 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = item( ammo_current() ).ammo_type()->name();
Hirmuolio marked this conversation as resolved.
Show resolved Hide resolved
} else {
ammotext = ammotype( *ammo_types( true ).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
Expand Down
4 changes: 4 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,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 weaon and magazine names. For example \"Mosin-Nagant M44 (4/5)\" becomes \"Mosin-Nagant M44 (4/5 7.62x54mm)\"." ),
Hirmuolio marked this conversation as resolved.
Show resolved Hide resolved
true
);

mOptionsSort["interface"]++;

Expand Down