diff --git a/src/item.cpp b/src/item.cpp index 140cf5b937483..5e19d79eb1726 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -3108,15 +3108,21 @@ static void armor_encumb_bp_info( const item &it, std::vector &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 &info ) @@ -3268,20 +3274,45 @@ void item::armor_protection_info( std::vector &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( "%s%s:", 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( "%s%s:", bp_desc, _( "Protection when active" ) ) ); diff --git a/tests/iteminfo_test.cpp b/tests/iteminfo_test.cpp index 35c8d7838c808..8fc589e11ca33 100644 --- a/tests/iteminfo_test.cpp +++ b/tests/iteminfo_test.cpp @@ -404,30 +404,18 @@ TEST_CASE( "item rigidity", "[iteminfo][rigidity]" ) "L. Arm Encumbrance: 30\n" "L. Arm Coverage:\n" " Default: 10\n" - " Melee: 10\n" - " Ranged: 10\n" - " Vitals: 0\n" "--\n" "R. Arm Encumbrance: 30\n" "R. Arm Coverage:\n" " Default: 10\n" - " Melee: 10\n" - " Ranged: 10\n" - " Vitals: 0\n" "--\n" "L. Hand Encumbrance: 30\n" "L. Hand Coverage:\n" " Default: 10\n" - " Melee: 10\n" - " Ranged: 10\n" - " Vitals: 0\n" "--\n" "R. Hand Encumbrance: 30\n" "R. Hand Coverage:\n" - " Default: 10\n" - " Melee: 10\n" - " Ranged: 10\n" - " Vitals: 0\n" ); + " Default: 10\n" ); } SECTION( "non-rigid items indicate their flexible volume/encumbrance" ) { @@ -466,17 +454,11 @@ TEST_CASE( "item rigidity", "[iteminfo][rigidity]" ) "When full: 6\n" "L. Leg Coverage:\n" " Default: 5\n" - " Melee: 5\n" - " Ranged: 5\n" - " Vitals: 0\n" "--\n" "R. Leg Encumbrance: 0 " "When full: 6\n" "R. Leg Coverage:\n" - " Default: 5\n" - " Melee: 5\n" - " Ranged: 5\n" - " Vitals: 0\n" ); + " Default: 5\n" ); // test_backpack has an explicit "encumbrance" and "max_encumbrance" CHECK( item_info_str( backpack, encumbrance ) == @@ -484,10 +466,7 @@ TEST_CASE( "item rigidity", "[iteminfo][rigidity]" ) "Torso Encumbrance: 2 " "When full: 15\n" "Torso Coverage:\n" - " Default: 30\n" - " Melee: 30\n" - " Ranged: 30\n" - " Vitals: 0\n" ); + " Default: 30\n" ); // quiver has no volume, only an implicit volume via ammo CHECK( item_info_str( quiver, encumbrance ) == @@ -496,17 +475,11 @@ TEST_CASE( "item rigidity", "[iteminfo][rigidity]" ) "When full: 11\n" "L. Leg Coverage:\n" " Default: 10\n" - " Melee: 10\n" - " Ranged: 10\n" - " Vitals: 0\n" "--\n" "R. Leg Encumbrance: 3 " "When full: 11\n" "R. Leg Coverage:\n" - " Default: 10\n" - " Melee: 10\n" - " Ranged: 10\n" - " Vitals: 0\n" ); + " Default: 10\n" ); } } } @@ -820,16 +793,10 @@ TEST_CASE( "armor coverage, warmth, and encumbrance", "[iteminfo][armor][coverag "Arms Encumbrance: 3\n" "Arms Coverage:\n" " Default: 90\n" - " Melee: 90\n" - " Ranged: 90\n" - " Vitals: 0\n" "--\n" "Torso Encumbrance: 3\n" "Torso Coverage:\n" - " Default: 90\n" - " Melee: 90\n" - " Ranged: 90\n" - " Vitals: 0\n" ); + " Default: 90\n" ); item swat_armor( "test_swat_armor" ); REQUIRE( swat_armor.get_covered_body_parts().any() ); @@ -910,25 +877,16 @@ TEST_CASE( "armor coverage, warmth, and encumbrance", "[iteminfo][armor][coverag "When full: 25\n" "Arms Coverage:\n" " Default: 95\n" - " Melee: 95\n" - " Ranged: 95\n" - " Vitals: 0\n" "--\n" "Legs Encumbrance: 12 " "When full: 25\n" "Legs Coverage:\n" " Default: 95\n" - " Melee: 95\n" - " Ranged: 95\n" - " Vitals: 0\n" "--\n" "Torso Encumbrance: 12 " "When full: 25\n" "Torso Coverage:\n" - " Default: 95\n" - " Melee: 95\n" - " Ranged: 95\n" - " Vitals: 0\n" ); + " Default: 95\n" ); // Test copy-from item faux_fur_pants( "test_pants_faux_fur" ); @@ -1088,49 +1046,31 @@ TEST_CASE( "armor coverage, warmth, and encumbrance", "[iteminfo][armor][coverag "When full: 9\n" "L. Arm Coverage:\n" " Default: 50\n" - " Melee: 50\n" - " Ranged: 50\n" - " Vitals: 0\n" "--\n" "R. Arm Encumbrance: 10 " "When full: 25\n" "R. Arm Coverage:\n" " Default: 100\n" - " Melee: 100\n" - " Ranged: 100\n" - " Vitals: 0\n" "--\n" "Head Encumbrance: 5 " "When full: 9\n" "Head Coverage:\n" " Default: 50\n" - " Melee: 50\n" - " Ranged: 50\n" - " Vitals: 0\n" "--\n" "L. Leg Encumbrance: 5 " "When full: 9\n" "L. Leg Coverage:\n" " Default: 50\n" - " Melee: 50\n" - " Ranged: 50\n" - " Vitals: 0\n" "--\n" "R. Leg Encumbrance: 10 " "When full: 25\n" "R. Leg Coverage:\n" " Default: 100\n" - " Melee: 100\n" - " Ranged: 100\n" - " Vitals: 0\n" "--\n" "Torso Encumbrance: 10 " "When full: 25\n" "Torso Coverage:\n" - " Default: 100\n" - " Melee: 100\n" - " Ranged: 100\n" - " Vitals: 0\n" ); + " Default: 100\n" ); } SECTION( "armor with no coverage omits irrelevant info" ) { @@ -1240,12 +1180,7 @@ TEST_CASE( "armor protection", "[iteminfo][armor][protection]" ) CHECK( item_info_str( longshirt, protection ) == "--\n" "Protection:\n" - " Bash: 0.20\n" - " Cut: 0.20\n" - " Ballistic: 0.20\n" - " Acid: 0.00\n" - " Fire: 0.00\n" - " Environmental: 0\n" ); + " Negligible Protection\n" ); } SECTION( "moderate protection from physical and environmental damage" ) {