Skip to content

Commit ac4dab0

Browse files
committed
Present dispersion as MOA in item UI
The game runs all dispersion related attributes as "100th of MOA", and this number is presented as-is on our UI. Presenting actual units is nice, so convert all those numbers to actual decimal MOA and present unit string.
1 parent 967f9b5 commit ac4dab0

File tree

2 files changed

+57
-55
lines changed

2 files changed

+57
-55
lines changed

src/item.cpp

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,18 +3002,17 @@ void item::ammo_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
30023002
iteminfo::is_decimal, ammo.range_multiplier );
30033003
}
30043004
if( parts->test( iteminfo_parts::AMMO_DAMAGE_DISPERSION ) ) {
3005-
info.emplace_back( "AMMO", _( "Dispersion: " ), "",
3006-
iteminfo::lower_is_better, ammo.dispersion );
3005+
info.emplace_back( "AMMO", _( "Dispersion: " ), "<num> MOA",
3006+
iteminfo::is_decimal | iteminfo::lower_is_better, ammo.dispersion / 100.0 );
30073007
}
30083008
if( parts->test( iteminfo_parts::AMMO_DAMAGE_RECOIL ) ) {
3009-
info.emplace_back( "AMMO", _( "Recoil: " ), "",
3010-
iteminfo::lower_is_better | iteminfo::no_newline, ammo.recoil );
3009+
info.emplace_back( "AMMO", _( "Recoil: " ), "<num> MOA",
3010+
iteminfo::is_decimal | iteminfo::lower_is_better | iteminfo::no_newline, ammo.recoil / 100.0 );
30113011
}
30123012
if( parts->test( iteminfo_parts::AMMO_DAMAGE_CRIT_MULTIPLIER ) ) {
30133013
info.emplace_back( "AMMO", space + _( "Critical multiplier: " ), ammo.critical_multiplier );
30143014
}
30153015
if( parts->test( iteminfo_parts::AMMO_BARREL_DETAILS ) ) {
3016-
std::string barrel_details;
30173016
const units::length small = 150_mm;
30183017
const units::length medium = 400_mm;
30193018
const units::length large = 600_mm;
@@ -3032,24 +3031,27 @@ void item::ammo_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
30323031
const std::string small_string = string_format( " <info>%d %s</info>: ",
30333032
convert_length( small ),
30343033
length_units( small ) );
3035-
info.emplace_back( "AMMO", small_string, _( " damage: <num>" ), iteminfo::no_newline,
3034+
info.emplace_back( "AMMO", small_string, _( " damage = <num>" ), iteminfo::no_newline,
30363035
small_damage );
3037-
info.emplace_back( "AMMO", "", _( " dispersion: <num>" ),
3038-
iteminfo::no_name | iteminfo::lower_is_better, small_dispersion );
3036+
info.emplace_back( "AMMO", "", _( " dispersion = <num> MOA" ),
3037+
iteminfo::no_name | iteminfo::is_decimal | iteminfo::lower_is_better,
3038+
small_dispersion / 100.0 );
30393039
const std::string medium_string = string_format( " <info>%d %s</info>: ",
30403040
convert_length( medium ),
30413041
length_units( medium ) );
3042-
info.emplace_back( "AMMO", medium_string, _( " damage: <num>" ), iteminfo::no_newline,
3042+
info.emplace_back( "AMMO", medium_string, _( " damage = <num>" ), iteminfo::no_newline,
30433043
medium_damage );
3044-
info.emplace_back( "AMMO", "", _( " dispersion: <num>" ),
3045-
iteminfo::no_name | iteminfo::lower_is_better, medium_dispersion );
3044+
info.emplace_back( "AMMO", "", _( " dispersion = <num> MOA" ),
3045+
iteminfo::no_name | iteminfo::is_decimal | iteminfo::lower_is_better,
3046+
medium_dispersion / 100.0 );
30463047
const std::string large_string = string_format( " <info>%d %s</info>: ",
30473048
convert_length( large ),
30483049
length_units( large ) );
3049-
info.emplace_back( "AMMO", large_string, _( " damage: <num>" ), iteminfo::no_newline,
3050+
info.emplace_back( "AMMO", large_string, _( " damage = <num>" ), iteminfo::no_newline,
30503051
large_damage );
3051-
info.emplace_back( "AMMO", "", _( " dispersion: <num>" ),
3052-
iteminfo::no_name | iteminfo::lower_is_better, large_dispersion );
3052+
info.emplace_back( "AMMO", "", _( " dispersion = <num> MOA" ),
3053+
iteminfo::no_name | iteminfo::is_decimal | iteminfo::lower_is_better,
3054+
large_dispersion / 100.0 );
30533055
}
30543056
}
30553057
}
@@ -3288,22 +3290,22 @@ void item::gun_info( const item *mod, std::vector<iteminfo> &info, const iteminf
32883290

32893291
if( parts->test( iteminfo_parts::GUN_DISPERSION ) ) {
32903292
info.emplace_back( "GUN", _( "Dispersion: " ), "",
3291-
iteminfo::no_newline | iteminfo::lower_is_better,
3292-
mod->gun_dispersion( false, false ) );
3293+
iteminfo::is_decimal | iteminfo::lower_is_better | iteminfo::no_newline,
3294+
mod->gun_dispersion( false, false ) / 100.0 );
32933295
}
32943296
if( mod->ammo_required() ) {
32953297
int ammo_dispersion = curammo->ammo->dispersion_considering_length( barrel_length() );
32963298
// ammo_dispersion and sum_of_dispersion don't need to translate.
32973299
if( parts->test( iteminfo_parts::GUN_DISPERSION_LOADEDAMMO ) ) {
32983300
info.emplace_back( "GUN", "ammo_dispersion", "",
3299-
iteminfo::no_newline | iteminfo::lower_is_better |
3300-
iteminfo::no_name | iteminfo::show_plus,
3301-
ammo_dispersion );
3301+
iteminfo::is_decimal | iteminfo::lower_is_better | iteminfo::no_name | iteminfo::no_newline |
3302+
iteminfo::show_plus,
3303+
ammo_dispersion / 100.0 );
33023304
}
33033305
if( parts->test( iteminfo_parts::GUN_DISPERSION_TOTAL ) ) {
3304-
info.emplace_back( "GUN", "sum_of_dispersion", _( " = <num>" ),
3305-
iteminfo::lower_is_better | iteminfo::no_name,
3306-
loaded_mod->gun_dispersion( true, false ) );
3306+
info.emplace_back( "GUN", "sum_of_dispersion", _( " = <num> MOA" ),
3307+
iteminfo::is_decimal | iteminfo::lower_is_better | iteminfo::no_name,
3308+
loaded_mod->gun_dispersion( true, false ) / 100.0 );
33073309
}
33083310
}
33093311
info.back().bNewLine = true;
@@ -3318,20 +3320,20 @@ void item::gun_info( const item *mod, std::vector<iteminfo> &info, const iteminf
33183320
if( parts->test( iteminfo_parts::GUN_DISPERSION_SIGHT ) ) {
33193321
if( point_shooting_limit <= eff_disp ) {
33203322
info.emplace_back( "GUN", _( "Sight dispersion (point shooting): " ), "",
3321-
iteminfo::no_newline | iteminfo::lower_is_better,
3322-
point_shooting_limit );
3323+
iteminfo::is_decimal | iteminfo::no_newline | iteminfo::lower_is_better,
3324+
point_shooting_limit / 100.0 );
33233325
} else {
33243326
info.emplace_back( "GUN", _( "Sight dispersion: " ), "",
3325-
iteminfo::no_newline | iteminfo::lower_is_better,
3326-
act_disp );
3327+
iteminfo::is_decimal | iteminfo::no_newline | iteminfo::lower_is_better,
3328+
act_disp / 100.0 );
33273329

33283330
if( adj_disp ) {
33293331
info.emplace_back( "GUN", "sight_adj_disp", "",
3330-
iteminfo::no_newline | iteminfo::lower_is_better |
3331-
iteminfo::no_name | iteminfo::show_plus, adj_disp );
3332-
info.emplace_back( "GUN", "sight_eff_disp", _( " = <num>" ),
3333-
iteminfo::lower_is_better | iteminfo::no_name,
3334-
eff_disp );
3332+
iteminfo::is_decimal | iteminfo::no_newline | iteminfo::lower_is_better |
3333+
iteminfo::no_name | iteminfo::show_plus, adj_disp / 100.0 );
3334+
info.emplace_back( "GUN", "sight_eff_disp", _( " = <num> MOA" ),
3335+
iteminfo::is_decimal | iteminfo::lower_is_better | iteminfo::no_name,
3336+
eff_disp / 100.0 );
33353337
}
33363338
}
33373339
}
@@ -3340,21 +3342,21 @@ void item::gun_info( const item *mod, std::vector<iteminfo> &info, const iteminf
33403342
info.back().bNewLine = true;
33413343
if( loaded_mod->gun_recoil( player_character ) ) {
33423344
if( parts->test( iteminfo_parts::GUN_RECOIL ) ) {
3343-
info.emplace_back( "GUN", _( "Effective recoil: " ), "",
3344-
iteminfo::no_newline | iteminfo::lower_is_better,
3345-
loaded_mod->gun_recoil( player_character ) );
3345+
info.emplace_back( "GUN", _( "Effective recoil: " ), "<num> MOA",
3346+
iteminfo::is_decimal | iteminfo::no_newline | iteminfo::lower_is_better,
3347+
loaded_mod->gun_recoil( player_character ) / 100.0 );
33463348
}
33473349
if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_BIPOD ) ) {
3348-
info.emplace_back( "GUN", "bipod_recoil", _( " (with bipod <num>)" ),
3349-
iteminfo::lower_is_better | iteminfo::no_name,
3350-
loaded_mod->gun_recoil( player_character, true ) );
3350+
info.emplace_back( "GUN", "bipod_recoil", _( " (with bipod <num> MOA)" ),
3351+
iteminfo::is_decimal | iteminfo::lower_is_better | iteminfo::no_name,
3352+
loaded_mod->gun_recoil( player_character, true ) / 100.0 );
33513353
}
33523354

33533355
if( parts->test( iteminfo_parts::GUN_RECOIL_THEORETICAL_MINIMUM ) ) {
33543356
info.back().bNewLine = true;
3355-
info.emplace_back( "GUN", _( "Theoretical minimum recoil: " ), "",
3356-
iteminfo::no_newline | iteminfo::lower_is_better, loaded_mod->gun_recoil( player_character, true,
3357-
true ) );
3357+
info.emplace_back( "GUN", _( "Theoretical minimum recoil: " ), "<num> MOA",
3358+
iteminfo::is_decimal | iteminfo::no_newline | iteminfo::lower_is_better,
3359+
loaded_mod->gun_recoil( player_character, true, true ) / 100.0 );
33583360
}
33593361
if( parts->test( iteminfo_parts:: GUN_IDEAL_STRENGTH ) ) {
33603362
info.emplace_back( "GUN", "ideal_strength", _( " (when strength reaches: <num>)" ),
@@ -3576,13 +3578,13 @@ void item::gunmod_info( std::vector<iteminfo> &info, const iteminfo_query *parts
35763578
}
35773579

35783580
if( mod.dispersion != 0 && parts->test( iteminfo_parts::GUNMOD_DISPERSION ) ) {
3579-
info.emplace_back( "GUNMOD", _( "Dispersion modifier: " ), "",
3580-
iteminfo::lower_is_better | iteminfo::show_plus,
3581-
mod.dispersion );
3581+
info.emplace_back( "GUNMOD", _( "Dispersion modifier: " ), "<num> MOA",
3582+
iteminfo::is_decimal | iteminfo::lower_is_better | iteminfo::show_plus,
3583+
mod.dispersion / 100.0 );
35823584
}
35833585
if( mod.sight_dispersion != -1 && parts->test( iteminfo_parts::GUNMOD_DISPERSION_SIGHT ) ) {
3584-
info.emplace_back( "GUNMOD", _( "Sight dispersion: " ), "",
3585-
iteminfo::lower_is_better, mod.sight_dispersion );
3586+
info.emplace_back( "GUNMOD", _( "Sight dispersion: " ), "<num> MOA",
3587+
iteminfo::is_decimal | iteminfo::lower_is_better, mod.sight_dispersion / 100.0 );
35863588
}
35873589
if( mod.field_of_view > 0 && parts->test( iteminfo_parts::GUNMOD_FIELD_OF_VIEW ) ) {
35883590
if( mod.field_of_view >= MAX_RECOIL ) {

tests/iteminfo_test.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ TEST_CASE( "gun_or_other_ranged_weapon_attributes", "[iteminfo][weapon][gun]" )
18161816

18171817
CHECK( item_info_str( glock, recoil ) ==
18181818
"--\n"
1819-
"Effective recoil: <color_c_yellow>312</color>\n" );
1819+
"Effective recoil: <color_c_yellow>3.12</color> MOA\n" );
18201820
}
18211821

18221822
SECTION( "gun type and current magazine" ) {
@@ -1907,7 +1907,7 @@ TEST_CASE( "gun_or_other_ranged_weapon_attributes", "[iteminfo][weapon][gun]" )
19071907
SECTION( "weapon dispersion" ) {
19081908
CHECK( item_info_str( compbow, { iteminfo_parts::GUN_DISPERSION } ) ==
19091909
"--\n"
1910-
"Dispersion: <color_c_yellow>850</color>\n" );
1910+
"Dispersion: <color_c_yellow>8.50</color>\n" );
19111911
}
19121912

19131913
SECTION( "needing two hands to fire" ) {
@@ -1949,15 +1949,15 @@ TEST_CASE( "gun_armor_piercing_dispersion_and_other_stats", "[iteminfo][gun][mis
19491949
"--\n = <color_c_yellow>0</color>\n" );
19501950

19511951
CHECK( item_info_str( glock, disp_loaded ) ==
1952-
"--\n<color_c_yellow>+60</color>\n" );
1952+
"--\n<color_c_yellow>+0.60</color>\n" );
19531953
CHECK( item_info_str( glock, disp_total ) ==
1954-
"--\n = <color_c_yellow>540</color>\n" );
1954+
"--\n = <color_c_yellow>5.40</color> MOA\n" );
19551955

19561956
CHECK( item_info_str( glock, disp_sight ) ==
19571957
"--\n"
1958-
"Sight dispersion: <color_c_yellow>30</color>"
1959-
"<color_c_yellow>+14</color>"
1960-
" = <color_c_yellow>44</color>\n" );
1958+
"Sight dispersion: <color_c_yellow>0.30</color>"
1959+
"<color_c_yellow>+0.14</color>"
1960+
" = <color_c_yellow>0.44</color> MOA\n" );
19611961

19621962
// TODO: Add a test gun with thest attributes
19631963
//CHECK( item_info_str( glock, recoil_bipod ).empty() );
@@ -2031,7 +2031,7 @@ TEST_CASE( "gunmod_info", "[iteminfo][gunmod]" )
20312031

20322032
CHECK( item_info_str( supp, disp_sight ) ==
20332033
"--\n"
2034-
"Sight dispersion: <color_c_yellow>11</color>\n" );
2034+
"Sight dispersion: <color_c_yellow>0.11</color> MOA\n" );
20352035

20362036
CHECK( item_info_str( supp, field_of_view ) ==
20372037
"--\n"
@@ -2086,8 +2086,8 @@ TEST_CASE( "ammunition", "[iteminfo][ammo]" )
20862086
"--\n"
20872087
"<color_c_white>Ammunition type</color>: rocks\n"
20882088
"Damage: <color_c_yellow>7</color> Armor-pierce: <color_c_yellow>0</color>\n"
2089-
"Range: <color_c_yellow>10</color> Dispersion: <color_c_yellow>14</color>\n"
2090-
"Recoil: <color_c_yellow>0</color> Critical multiplier: <color_c_yellow>2</color>\n" );
2089+
"Range: <color_c_yellow>10</color> Dispersion: <color_c_yellow>0.14</color> MOA\n"
2090+
"Recoil: <color_c_yellow>0.00</color> MOA Critical multiplier: <color_c_yellow>2</color>\n" );
20912091
}
20922092

20932093
SECTION( "batteries" ) {

0 commit comments

Comments
 (0)