Skip to content

Commit

Permalink
Hide negligable armor info (CleverRaven#53888)
Browse files Browse the repository at this point in the history
  • Loading branch information
bombasticSlacks authored Dec 31, 2021
1 parent b3e5c7a commit 524a7db
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 94 deletions.
73 changes: 52 additions & 21 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3108,15 +3108,21 @@ static void armor_encumb_bp_info( const item &it, std::vector<iteminfo> &info,
//~ Regular/Default coverage
info.emplace_back( bp_cat, string_format( "%s%s%s", space, _( "Default:" ), space ), "",
iteminfo::no_flags, it.get_coverage( bp ) );
//~ Melee coverage
info.emplace_back( bp_cat, string_format( "%s%s%s", space, _( "Melee:" ), space ), "",
iteminfo::no_flags, it.get_coverage( bp, item::cover_type::COVER_MELEE ) );
//~ Ranged coverage
info.emplace_back( bp_cat, string_format( "%s%s%s", space, _( "Ranged:" ), space ), "",
iteminfo::no_flags, it.get_coverage( bp, item::cover_type::COVER_RANGED ) );
//~ Vitals coverage
info.emplace_back( bp_cat, string_format( "%s%s%s", space, _( "Vitals:" ), space ), "",
iteminfo::no_flags, it.get_coverage( bp, item::cover_type::COVER_VITALS ) );
if( it.get_coverage( bp ) != it.get_coverage( bp, item::cover_type::COVER_MELEE ) ) {
//~ Melee coverage
info.emplace_back( bp_cat, string_format( "%s%s%s", space, _( "Melee:" ), space ), "",
iteminfo::no_flags, it.get_coverage( bp, item::cover_type::COVER_MELEE ) );
}
if( it.get_coverage( bp ) != it.get_coverage( bp, item::cover_type::COVER_RANGED ) ) {
//~ Ranged coverage
info.emplace_back( bp_cat, string_format( "%s%s%s", space, _( "Ranged:" ), space ), "",
iteminfo::no_flags, it.get_coverage( bp, item::cover_type::COVER_RANGED ) );
}
if( it.get_coverage( bp, item::cover_type::COVER_VITALS ) > 0 ) {
//~ Vitals coverage
info.emplace_back( bp_cat, string_format( "%s%s%s", space, _( "Vitals:" ), space ), "",
iteminfo::no_flags, it.get_coverage( bp, item::cover_type::COVER_VITALS ) );
}
}

static bool armor_encumb_header_info( const item &it, std::vector<iteminfo> &info )
Expand Down Expand Up @@ -3268,20 +3274,45 @@ void item::armor_protection_info( std::vector<iteminfo> &info, const iteminfo_qu
const std::string space = " ";
// NOLINTNEXTLINE(cata-translate-string-literal)
std::string bp_cat = string_format( "{%s}ARMOR", bp_name );

bool printed_any = false;

info.emplace_back( "DESCRIPTION", string_format( "<bold>%s%s</bold>:", bp_desc,
_( "Protection" ) ) );
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Bash: " ) ), "",
iteminfo::is_decimal, bash_resist( false, bp ) );
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Cut: " ) ), "",
iteminfo::is_decimal, cut_resist( false, bp ) );
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Ballistic: " ) ), "",
iteminfo::is_decimal, bullet_resist( false, bp ) );
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Acid: " ) ), "",
iteminfo::is_decimal, acid_resist( false, 0, bp ) );
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Fire: " ) ), "",
iteminfo::is_decimal, fire_resist( false, 0, bp ) );
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Environmental: " ) ),
get_base_env_resist( *this ) );
if( bash_resist( false, bp ) >= 1 ) {
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Bash: " ) ), "",
iteminfo::is_decimal, bash_resist( false, bp ) );
printed_any = true;
}
if( cut_resist( false, bp ) >= 1 ) {
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Cut: " ) ), "",
iteminfo::is_decimal, cut_resist( false, bp ) );
printed_any = true;
}
if( bullet_resist( false, bp ) >= 1 ) {
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Ballistic: " ) ), "",
iteminfo::is_decimal, bullet_resist( false, bp ) );
printed_any = true;
}
if( acid_resist( false, 0, bp ) >= 1 ) {
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Acid: " ) ), "",
iteminfo::is_decimal, acid_resist( false, 0, bp ) );
printed_any = true;
}
if( fire_resist( false, 0, bp ) >= 1 ) {
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Fire: " ) ), "",
iteminfo::is_decimal, fire_resist( false, 0, bp ) );
printed_any = true;
}
if( get_base_env_resist( *this ) >= 1 ) {
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Environmental: " ) ),
get_base_env_resist( *this ) );
printed_any = true;
}
// if we haven't printed any armor data acknowlege that
if( !printed_any ) {
info.emplace_back( bp_cat, string_format( "%s%s", space, _( "Negligible Protection" ) ) );
}
if( type->can_use( "GASMASK" ) || type->can_use( "DIVE_TANK" ) ) {
info.emplace_back( "ARMOR", string_format( "<bold>%s%s</bold>:", bp_desc,
_( "Protection when active" ) ) );
Expand Down
81 changes: 8 additions & 73 deletions tests/iteminfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,30 +404,18 @@ TEST_CASE( "item rigidity", "[iteminfo][rigidity]" )
"<color_c_white>L. Arm Encumbrance</color>: <color_c_yellow>30</color>\n"
"<color_c_white>L. Arm Coverage</color>:\n"
" Default: <color_c_yellow>10</color>\n"
" Melee: <color_c_yellow>10</color>\n"
" Ranged: <color_c_yellow>10</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>R. Arm Encumbrance</color>: <color_c_yellow>30</color>\n"
"<color_c_white>R. Arm Coverage</color>:\n"
" Default: <color_c_yellow>10</color>\n"
" Melee: <color_c_yellow>10</color>\n"
" Ranged: <color_c_yellow>10</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>L. Hand Encumbrance</color>: <color_c_yellow>30</color>\n"
"<color_c_white>L. Hand Coverage</color>:\n"
" Default: <color_c_yellow>10</color>\n"
" Melee: <color_c_yellow>10</color>\n"
" Ranged: <color_c_yellow>10</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>R. Hand Encumbrance</color>: <color_c_yellow>30</color>\n"
"<color_c_white>R. Hand Coverage</color>:\n"
" Default: <color_c_yellow>10</color>\n"
" Melee: <color_c_yellow>10</color>\n"
" Ranged: <color_c_yellow>10</color>\n"
" Vitals: <color_c_yellow>0</color>\n" );
" Default: <color_c_yellow>10</color>\n" );
}

SECTION( "non-rigid items indicate their flexible volume/encumbrance" ) {
Expand Down Expand Up @@ -466,28 +454,19 @@ TEST_CASE( "item rigidity", "[iteminfo][rigidity]" )
"When full: <color_c_yellow>6</color>\n"
"<color_c_white>L. Leg Coverage</color>:\n"
" Default: <color_c_yellow>5</color>\n"
" Melee: <color_c_yellow>5</color>\n"
" Ranged: <color_c_yellow>5</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>R. Leg Encumbrance</color>: <color_c_yellow>0</color> "
"When full: <color_c_yellow>6</color>\n"
"<color_c_white>R. Leg Coverage</color>:\n"
" Default: <color_c_yellow>5</color>\n"
" Melee: <color_c_yellow>5</color>\n"
" Ranged: <color_c_yellow>5</color>\n"
" Vitals: <color_c_yellow>0</color>\n" );
" Default: <color_c_yellow>5</color>\n" );

// test_backpack has an explicit "encumbrance" and "max_encumbrance"
CHECK( item_info_str( backpack, encumbrance ) ==
"--\n"
"<color_c_white>Torso Encumbrance</color>: <color_c_yellow>2</color> "
"When full: <color_c_yellow>15</color>\n"
"<color_c_white>Torso Coverage</color>:\n"
" Default: <color_c_yellow>30</color>\n"
" Melee: <color_c_yellow>30</color>\n"
" Ranged: <color_c_yellow>30</color>\n"
" Vitals: <color_c_yellow>0</color>\n" );
" Default: <color_c_yellow>30</color>\n" );

// quiver has no volume, only an implicit volume via ammo
CHECK( item_info_str( quiver, encumbrance ) ==
Expand All @@ -496,17 +475,11 @@ TEST_CASE( "item rigidity", "[iteminfo][rigidity]" )
"When full: <color_c_yellow>11</color>\n"
"<color_c_white>L. Leg Coverage</color>:\n"
" Default: <color_c_yellow>10</color>\n"
" Melee: <color_c_yellow>10</color>\n"
" Ranged: <color_c_yellow>10</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>R. Leg Encumbrance</color>: <color_c_yellow>3</color> "
"When full: <color_c_yellow>11</color>\n"
"<color_c_white>R. Leg Coverage</color>:\n"
" Default: <color_c_yellow>10</color>\n"
" Melee: <color_c_yellow>10</color>\n"
" Ranged: <color_c_yellow>10</color>\n"
" Vitals: <color_c_yellow>0</color>\n" );
" Default: <color_c_yellow>10</color>\n" );
}
}
}
Expand Down Expand Up @@ -820,16 +793,10 @@ TEST_CASE( "armor coverage, warmth, and encumbrance", "[iteminfo][armor][coverag
"<color_c_white>Arms Encumbrance</color>: <color_c_yellow>3</color>\n"
"<color_c_white>Arms Coverage</color>:\n"
" Default: <color_c_yellow>90</color>\n"
" Melee: <color_c_yellow>90</color>\n"
" Ranged: <color_c_yellow>90</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>Torso Encumbrance</color>: <color_c_yellow>3</color>\n"
"<color_c_white>Torso Coverage</color>:\n"
" Default: <color_c_yellow>90</color>\n"
" Melee: <color_c_yellow>90</color>\n"
" Ranged: <color_c_yellow>90</color>\n"
" Vitals: <color_c_yellow>0</color>\n" );
" Default: <color_c_yellow>90</color>\n" );

item swat_armor( "test_swat_armor" );
REQUIRE( swat_armor.get_covered_body_parts().any() );
Expand Down Expand Up @@ -910,25 +877,16 @@ TEST_CASE( "armor coverage, warmth, and encumbrance", "[iteminfo][armor][coverag
"When full: <color_c_yellow>25</color>\n"
"<color_c_white>Arms Coverage</color>:\n"
" Default: <color_c_yellow>95</color>\n"
" Melee: <color_c_yellow>95</color>\n"
" Ranged: <color_c_yellow>95</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>Legs Encumbrance</color>: <color_c_yellow>12</color> "
"When full: <color_c_yellow>25</color>\n"
"<color_c_white>Legs Coverage</color>:\n"
" Default: <color_c_yellow>95</color>\n"
" Melee: <color_c_yellow>95</color>\n"
" Ranged: <color_c_yellow>95</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>Torso Encumbrance</color>: <color_c_yellow>12</color> "
"When full: <color_c_yellow>25</color>\n"
"<color_c_white>Torso Coverage</color>:\n"
" Default: <color_c_yellow>95</color>\n"
" Melee: <color_c_yellow>95</color>\n"
" Ranged: <color_c_yellow>95</color>\n"
" Vitals: <color_c_yellow>0</color>\n" );
" Default: <color_c_yellow>95</color>\n" );

// Test copy-from
item faux_fur_pants( "test_pants_faux_fur" );
Expand Down Expand Up @@ -1088,49 +1046,31 @@ TEST_CASE( "armor coverage, warmth, and encumbrance", "[iteminfo][armor][coverag
"When full: <color_c_yellow>9</color>\n"
"<color_c_white>L. Arm Coverage</color>:\n"
" Default: <color_c_yellow>50</color>\n"
" Melee: <color_c_yellow>50</color>\n"
" Ranged: <color_c_yellow>50</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>R. Arm Encumbrance</color>: <color_c_yellow>10</color> "
"When full: <color_c_yellow>25</color>\n"
"<color_c_white>R. Arm Coverage</color>:\n"
" Default: <color_c_yellow>100</color>\n"
" Melee: <color_c_yellow>100</color>\n"
" Ranged: <color_c_yellow>100</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>Head Encumbrance</color>: <color_c_yellow>5</color> "
"When full: <color_c_yellow>9</color>\n"
"<color_c_white>Head Coverage</color>:\n"
" Default: <color_c_yellow>50</color>\n"
" Melee: <color_c_yellow>50</color>\n"
" Ranged: <color_c_yellow>50</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>L. Leg Encumbrance</color>: <color_c_yellow>5</color> "
"When full: <color_c_yellow>9</color>\n"
"<color_c_white>L. Leg Coverage</color>:\n"
" Default: <color_c_yellow>50</color>\n"
" Melee: <color_c_yellow>50</color>\n"
" Ranged: <color_c_yellow>50</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>R. Leg Encumbrance</color>: <color_c_yellow>10</color> "
"When full: <color_c_yellow>25</color>\n"
"<color_c_white>R. Leg Coverage</color>:\n"
" Default: <color_c_yellow>100</color>\n"
" Melee: <color_c_yellow>100</color>\n"
" Ranged: <color_c_yellow>100</color>\n"
" Vitals: <color_c_yellow>0</color>\n"
"--\n"
"<color_c_white>Torso Encumbrance</color>: <color_c_yellow>10</color> "
"When full: <color_c_yellow>25</color>\n"
"<color_c_white>Torso Coverage</color>:\n"
" Default: <color_c_yellow>100</color>\n"
" Melee: <color_c_yellow>100</color>\n"
" Ranged: <color_c_yellow>100</color>\n"
" Vitals: <color_c_yellow>0</color>\n" );
" Default: <color_c_yellow>100</color>\n" );
}

SECTION( "armor with no coverage omits irrelevant info" ) {
Expand Down Expand Up @@ -1240,12 +1180,7 @@ TEST_CASE( "armor protection", "[iteminfo][armor][protection]" )
CHECK( item_info_str( longshirt, protection ) ==
"--\n"
"<color_c_white>Protection</color>:\n"
" Bash: <color_c_yellow>0.20</color>\n"
" Cut: <color_c_yellow>0.20</color>\n"
" Ballistic: <color_c_yellow>0.20</color>\n"
" Acid: <color_c_yellow>0.00</color>\n"
" Fire: <color_c_yellow>0.00</color>\n"
" Environmental: <color_c_yellow>0</color>\n" );
" Negligible Protection\n" );
}

SECTION( "moderate protection from physical and environmental damage" ) {
Expand Down

0 comments on commit 524a7db

Please sign in to comment.