#include #include #include #include #include #include #include #include #include "avatar.h" #include "body_part_set.h" #include "bodypart.h" #include "calendar.h" #include "cata_scope_helpers.h" #include "cata_catch.h" #include "character.h" #include "character_attire.h" #include "flag.h" #include "item.h" #include "item_location.h" #include "iteminfo_query.h" #include "magic_enchantment.h" #include "itype.h" #include "options_helpers.h" #include "output.h" #include "pimpl.h" #include "player_helpers.h" #include "pocket_type.h" #include "recipe.h" #include "recipe_dictionary.h" #include "ret_val.h" #include "string_formatter.h" #include "subbodypart.h" #include "type_id.h" #include "units.h" #include "value_ptr.h" static const bodypart_str_id body_part_test_alt_arm_l( "test_alt_arm_l" ); static const damage_type_id damage_acid( "acid" ); static const damage_type_id damage_bash( "bash" ); static const damage_type_id damage_bullet( "bullet" ); static const damage_type_id damage_cut( "cut" ); static const damage_type_id damage_heat( "heat" ); static const damage_type_id damage_stab( "stab" ); static const enchantment_id enchantment_ENCH_TEST_ALT_ARMS( "ENCH_TEST_ALT_ARMS" ); static const itype_id itype_arm_splint( "arm_splint" ); static const itype_id itype_attachable_ear_muffs( "attachable_ear_muffs" ); static const itype_id itype_backpack( "backpack" ); static const itype_id itype_ballistic_vest_esapi( "ballistic_vest_esapi" ); static const itype_id itype_battery( "battery" ); static const itype_id itype_bio_ethanol( "bio_ethanol" ); static const itype_id itype_bio_nostril( "bio_nostril" ); static const itype_id itype_bio_power_storage( "bio_power_storage" ); static const itype_id itype_candle( "candle" ); static const itype_id itype_candle_wax( "candle_wax" ); static const itype_id itype_dress_shirt( "dress_shirt" ); static const itype_id itype_face_shield( "face_shield" ); static const itype_id itype_hat_hard( "hat_hard" ); static const itype_id itype_heavy_battery_cell( "heavy_battery_cell" ); static const itype_id itype_iodine( "iodine" ); static const itype_id itype_match( "match" ); static const itype_id itype_medium_battery_cell( "medium_battery_cell" ); static const itype_id itype_nape_protector( "nape_protector" ); static const itype_id itype_oxy_torch( "oxy_torch" ); static const itype_id itype_test_2x4( "test_2x4" ); static const itype_id itype_test_apple( "test_apple" ); static const itype_id itype_test_armor_chitin( "test_armor_chitin" ); static const itype_id itype_test_armor_chitin_copy( "test_armor_chitin_copy" ); static const itype_id itype_test_armor_chitin_copy_prop( "test_armor_chitin_copy_prop" ); static const itype_id itype_test_armor_chitin_copy_rel( "test_armor_chitin_copy_rel" ); static const itype_id itype_test_armor_chitin_copy_w_armor( "test_armor_chitin_copy_w_armor" ); static const itype_id itype_test_armor_chitin_copy_w_armor_prop( "test_armor_chitin_copy_w_armor_prop" ); static const itype_id itype_test_armor_chitin_copy_w_armor_rel( "test_armor_chitin_copy_w_armor_rel" ); static const itype_id itype_test_arrow_wood( "test_arrow_wood" ); static const itype_id itype_test_backpack( "test_backpack" ); static const itype_id itype_test_balloon( "test_balloon" ); static const itype_id itype_test_battery_disposable( "test_battery_disposable" ); static const itype_id itype_test_bio_purifier( "test_bio_purifier" ); static const itype_id itype_test_bitter_almond( "test_bitter_almond" ); static const itype_id itype_test_brew_wine( "test_brew_wine" ); static const itype_id itype_test_briefcase( "test_briefcase" ); static const itype_id itype_test_cmdline_book( "test_cmdline_book" ); static const itype_id itype_test_compbow( "test_compbow" ); static const itype_id itype_test_complex_tanktop( "test_complex_tanktop" ); static const itype_id itype_test_condom( "test_condom" ); static const itype_id itype_test_cordless_drill( "test_cordless_drill" ); static const itype_id itype_test_crafted_suppressor( "test_crafted_suppressor" ); static const itype_id itype_test_dragon_book( "test_dragon_book" ); static const itype_id itype_test_ear_plugs( "test_ear_plugs" ); static const itype_id itype_test_fire_ax( "test_fire_ax" ); static const itype_id itype_test_glock( "test_glock" ); static const itype_id itype_test_gum( "test_gum" ); static const itype_id itype_test_halligan( "test_halligan" ); static const itype_id itype_test_hallu_nutmeg( "test_hallu_nutmeg" ); static const itype_id itype_test_hazmat_suit( "test_hazmat_suit" ); static const itype_id itype_test_item_info_repair_tool( "test_item_info_repair_tool" ); static const itype_id itype_test_jack_small( "test_jack_small" ); static const itype_id itype_test_jug_plastic( "test_jug_plastic" ); static const itype_id itype_test_longshirt( "test_longshirt" ); static const itype_id itype_test_matches( "test_matches" ); static const itype_id itype_test_meower_armor( "test_meower_armor" ); static const itype_id itype_test_multimag_gun_integral_ammo( "test_multimag_gun_integral_ammo" ); static const itype_id itype_test_nuclear_carafe( "test_nuclear_carafe" ); static const itype_id itype_test_nutrient_info_component1( "test_nutrient_info_component1" ); static const itype_id itype_test_nutrient_info_item( "test_nutrient_info_item" ); static const itype_id itype_test_pants_faux_fur( "test_pants_faux_fur" ); static const itype_id itype_test_pine_nuts( "test_pine_nuts" ); static const itype_id itype_test_pipe( "test_pipe" ); static const itype_id itype_test_plate( "test_plate" ); static const itype_id itype_test_pointy_stick( "test_pointy_stick" ); static const itype_id itype_test_portion_faux_fur_pants_suit( "test_portion_faux_fur_pants_suit" ); static const itype_id itype_test_power_armor( "test_power_armor" ); static const itype_id itype_test_quiver( "test_quiver" ); static const itype_id itype_test_rag( "test_rag" ); static const itype_id itype_test_rock( "test_rock" ); static const itype_id itype_test_sheet_metal( "test_sheet_metal" ); static const itype_id itype_test_smart_phone( "test_smart_phone" ); static const itype_id itype_test_socks( "test_socks" ); static const itype_id itype_test_soldering_iron( "test_soldering_iron" ); static const itype_id itype_test_sonic_screwdriver( "test_sonic_screwdriver" ); static const itype_id itype_test_swat_armor( "test_swat_armor" ); static const itype_id itype_test_tail_encumber( "test_tail_encumber" ); static const itype_id itype_test_thumb( "test_thumb" ); static const itype_id itype_test_tool_belt_pocket_mix( "test_tool_belt_pocket_mix" ); static const itype_id itype_test_waterskin( "test_waterskin" ); static const itype_id itype_test_wine( "test_wine" ); static const itype_id itype_test_zentai_resist_stab_cut( "test_zentai_resist_stab_cut" ); static const itype_id itype_textbook_chemistry( "textbook_chemistry" ); static const itype_id itype_tshirt( "tshirt" ); static const itype_id itype_zentai( "zentai" ); static const material_id material_wool( "wool" ); static const recipe_id recipe_pur_tablets( "pur_tablets" ); static const recipe_id recipe_test_nutrient_info_item( "test_nutrient_info_item" ); static const skill_id skill_survival( "survival" ); static const sub_bodypart_str_id sub_body_part_eyes_right( "eyes_right" ); static const trait_id trait_ANTIFRUIT( "ANTIFRUIT" ); static const trait_id trait_CANNIBAL( "CANNIBAL" ); static const trait_id trait_WOOLALLERGY( "WOOLALLERGY" ); static const vitamin_id vitamin_human_flesh_vitamin( "human_flesh_vitamin" ); // ITEM INFO // ========= // // When looking at the description of any item in the game, the information you see comes from the // item::info function, which calls functions like basic_info, armor_info, food_info and many others // to build a complete string describing the item. // // The included info depends on: // // - Relevancy to current item (damage for weapons, coverage for armor, vitamins for food, etc.) // - Including one or more appropriate iteminfo_part::PART_NAME flags in the `info` function call // // Color-highlighted text in item info uses a semantic markup in the code (ex. "good", "bad") that // becomes translated to color codes for output: // // // // // // // //
// // Each xxx_info function takes a std::vector reference, where each line or snippet of // info will be appended. The main item::info function assembles all these into a string. // // The test cases here mostly test item::info directly, using std::vector flags to // request only the parts relevant to the current test. // // To run all the tests in this file: // // tests/cata_test [iteminfo] // // Other tags: [book], [food], [pocket], [quality], [weapon], [volume], [weight], and many others // Call the info() function on an item with given flags, and return the formatted string. static std::string item_info_str( const item &it, const std::vector &part_flags ) { // Old captures from test_info_equals/contains, in case needed //int encumber = i.type->armor ? i.type->armor->encumber : -1; //int max_encumber = i.type->armor ? i.type->armor->max_encumber : -1; //CAPTURE( encumber ); //CAPTURE( max_encumber ); //CAPTURE( i.typeId() ); //CAPTURE( i.has_flag( "FIT" ) ); //CAPTURE( i.has_flag( "VARSIZE" ) ); //CAPTURE( i.get_clothing_mod_val( clothing_mod_type_encumbrance ) ); //CAPTURE( i.get_sizing( get_avatar(), true ) ); std::vector info_v; const iteminfo_query query_v( part_flags ); it.info( info_v, &query_v, 1 ); return format_item_info( info_v, {} ); } // Related JSON fields: // "volume" // "weight" // "longest_side" // // Functions: // item::basic_info TEST_CASE( "item_volume_and_weight", "[iteminfo][volume][weight]" ) { clear_avatar(); item plank( itype_test_2x4 ); // Volume and weight are shown together, though the units may differ std::vector vol_weight = { iteminfo_parts::BASE_VOLUME, iteminfo_parts::BASE_WEIGHT }; SECTION( "metric volume" ) { override_option opt_volume( "VOLUME_UNITS", "l" ); SECTION( "metric weight" ) { override_option opt_weight( "USE_METRIC_WEIGHTS", "kg" ); CHECK( item_info_str( plank, vol_weight ) == "Volume: 4.40 L Weight: 2.20 kg\n" ); } SECTION( "imperial weight" ) { override_option opt_weight( "USE_METRIC_WEIGHTS", "lbs" ); CHECK( item_info_str( plank, vol_weight ) == "Volume: 4.40 L Weight: 4.85 lbs\n" ); } } SECTION( "imperial volume" ) { override_option opt_volume( "VOLUME_UNITS", "qt" ); SECTION( "metric weight" ) { override_option opt_weight( "USE_METRIC_WEIGHTS", "kg" ); CHECK( item_info_str( plank, vol_weight ) == "Volume: 4.65 qt Weight: 2.20 kg\n" ); } SECTION( "imperial weight" ) { override_option opt_weight( "USE_METRIC_WEIGHTS", "lbs" ); CHECK( item_info_str( plank, vol_weight ) == "Volume: 4.65 qt Weight: 4.85 lbs\n" ); } } SECTION( "imperial length" ) { override_option opt_dist( "DISTANCE_UNITS", "imperial" ); CHECK( item_info_str( plank, { iteminfo_parts::BASE_LENGTH } ) == "Length: 51 in.\n" ); } SECTION( "metric length" ) { override_option opt_dist( "DISTANCE_UNITS", "metric" ); CHECK( item_info_str( plank, { iteminfo_parts::BASE_LENGTH } ) == "Length: 130 cm\n" ); } } // Related JSON fields: // "material" // "category" // "description" // // Functions: // item::basic_info TEST_CASE( "item_material_category_description", "[iteminfo][material][category][description]" ) { clear_avatar(); // TODO: Test magical focus, in-progress crafts (also part of DESCRIPTION) std::vector material = { iteminfo_parts::BASE_MATERIAL }; std::vector category = { iteminfo_parts::BASE_CATEGORY }; std::vector description = { iteminfo_parts::DESCRIPTION }; SECTION( "fire ax" ) { item axe( itype_test_fire_ax ); CHECK( item_info_str( axe, material ) == "Material: Steel, Wood\n" ); CHECK( item_info_str( axe, category ) == "Category: Tools\n" ); CHECK( item_info_str( axe, description ) == "--\n" "This is a large, two-handed pickhead axe normally used by firefighters." " It makes a powerful melee weapon, but is a bit slow to recover between swings.\n" ); } SECTION( "plank" ) { item plank( itype_test_2x4 ); CHECK( item_info_str( plank, material ) == "Material: Wood\n" ); CHECK( item_info_str( plank, category ) == "Category: Spare parts\n" ); CHECK( item_info_str( plank, description ) == "--\n" "A narrow, thick plank of wood, like a 2 by 4 or similar piece of dimensional lumber." " Makes a decent melee weapon, and can be used for all kinds of construction.\n" ); } } // Related JSON fields: // none // // Functions: // item::basic_info TEST_CASE( "item_owner", "[iteminfo][owner]" ) { clear_avatar(); SECTION( "item owned by player" ) { item my_rock( itype_test_rock ); my_rock.set_owner( get_player_character() ); REQUIRE_FALSE( my_rock.get_owner().is_null() ); CHECK( item_info_str( my_rock, { iteminfo_parts::BASE_OWNER } ) == "Owner: Your Followers\n" ); } SECTION( "item with no owner" ) { item nobodys_rock( itype_test_rock ); REQUIRE( nobodys_rock.get_owner().is_null() ); CHECK( item_info_str( nobodys_rock, { iteminfo_parts::BASE_OWNER } ).empty() ); } } // Related JSON fields: // "min_skills" // "min_strength" // "min_intelligence" // "min_perception" // // Functions: // item::basic_info TEST_CASE( "item_requirements", "[iteminfo][requirements]" ) { // TODO: // - get_min_str() - type->min_str with special gun/gunmod handling // NOTE: BOOK_REQUIREMENTS_INT is separate // NOTE: There are presently no in-game items with min_dex, min_int, or min_per clear_avatar(); std::vector reqs = { iteminfo_parts::BASE_REQUIREMENTS }; item compbow( itype_test_compbow ); item sonic( itype_test_sonic_screwdriver ); REQUIRE( compbow.type->min_str == 6 ); CHECK( item_info_str( compbow, reqs ) == "--\n" "Minimum requirements:\n" "strength 6\n" ); REQUIRE( sonic.type->min_int == 9 ); REQUIRE( sonic.type->min_per == 5 ); CHECK( item_info_str( sonic, reqs ) == "--\n" "Minimum requirements:\n" "intelligence 9, perception 5, electronics 3, and devices 2\n" ); } // Related JSON fields: // "comestible_type": "MED": // "quench" // "fun" // "stim" // "charges" (portions) // "addiction_potential" // // Functions: // item::med_info TEST_CASE( "med_info", "[iteminfo][med]" ) { clear_avatar(); // Parts to test std::vector quench = { iteminfo_parts::MED_QUENCH }; std::vector joy = { iteminfo_parts::MED_JOY }; std::vector stimulation = { iteminfo_parts::MED_STIMULATION }; std::vector portions = { iteminfo_parts::MED_PORTIONS }; std::vector consume_time = { iteminfo_parts::MED_CONSUME_TIME }; std::vector addicting = { iteminfo_parts::DESCRIPTION_MED_ADDICTING }; // Items with comestible_type "MED" SECTION( "item that is medication shows medicinal attributes in med_info" ) { item gum( itype_test_gum ); REQUIRE( gum.is_medication() ); CHECK( item_info_str( gum, quench ) == "--\nQuench: 50\n" ); CHECK( item_info_str( gum, joy ) == "--\nEnjoyability: 5\n" ); CHECK( item_info_str( gum, stimulation ) == "--\nStimulation: Upper\n" ); CHECK( item_info_str( gum, portions ) == "--\nPortions: 10\n" ); CHECK( item_info_str( gum, consume_time ) == "--\nConsume time: 5 seconds\n" ); CHECK( item_info_str( gum, addicting ) == "--\n* Consuming this item is addicting.\n" ); } SECTION( "item that is not medication does not show med_info" ) { item apple( itype_test_apple ); REQUIRE_FALSE( apple.is_medication() ); CHECK( item_info_str( apple, quench ).empty() ); CHECK( item_info_str( apple, joy ).empty() ); CHECK( item_info_str( apple, stimulation ).empty() ); CHECK( item_info_str( apple, portions ).empty() ); CHECK( item_info_str( apple, consume_time ).empty() ); CHECK( item_info_str( apple, addicting ).empty() ); } } // Related JSON fields: // "price" // "price_postapoc" // // Functions: // item::final_info TEST_CASE( "item_price_and_barter_value", "[iteminfo][price]" ) { clear_avatar(); // Price and barter value are displayed together on a single line std::vector price_barter = { iteminfo_parts::BASE_PRICE, iteminfo_parts::BASE_BARTER }; SECTION( "item with different price and barter value" ) { item pipe( itype_test_pipe ); REQUIRE( pipe.price( false ) == 7500 ); REQUIRE( pipe.price( true ) == 300 ); CHECK( item_info_str( pipe, price_barter ) == "--\n" "Price: $75.00 Barter value: $3.00\n" ); } } // Related JSON fields: // "encumbrance" // "max_encumbrance" // "pocket_data" // "coverage" // - "rigid" // - "max_contains_volume" // // Functions: // item::armor_info TEST_CASE( "item_rigidity", "[iteminfo][rigidity]" ) { clear_avatar(); // Rigidity and encumbrance are related; non-rigid items have flexible encumbrance. std::vector rigidity = { iteminfo_parts::BASE_RIGIDITY }; std::vector encumbrance = { iteminfo_parts::ARMOR_ENCUMBRANCE }; SECTION( "items with rigid pockets have a single encumbrance value" ) { item briefcase( itype_test_briefcase ); REQUIRE( briefcase.all_pockets_rigid() ); CHECK( item_info_str( briefcase, encumbrance ) == "--\n" "Encumbrance" " 30: The arms. The hands.\n" ); } SECTION( "non-rigid items indicate their flexible volume/encumbrance" ) { item waterskin( itype_test_waterskin ); item backpack( itype_test_backpack ); item quiver( itype_test_quiver ); item condom( itype_test_condom ); SECTION( "rigidity indicator" ) { REQUIRE_FALSE( waterskin.all_pockets_rigid() ); REQUIRE_FALSE( backpack.all_pockets_rigid() ); REQUIRE_FALSE( quiver.all_pockets_rigid() ); REQUIRE_FALSE( condom.all_pockets_rigid() ); CHECK( item_info_str( waterskin, rigidity ) == "--\n" "* This item's pockets are not rigid." " Its volume and encumbrance increase with contents.\n" ); CHECK( item_info_str( backpack, rigidity ) == "--\n" "* This item's pockets are not rigid." " Its volume and encumbrance increase with contents.\n" ); CHECK( item_info_str( quiver, rigidity ) == "--\n" "* This item's pockets are not rigid." " Its volume and encumbrance increase with contents.\n" ); // Non-armor item - volume increases, but not encumbrance CHECK( item_info_str( condom, rigidity ) == "--\n" "* This item's pockets are not rigid." " Its volume increases with contents.\n" ); } SECTION( "encumbrance when empty and full" ) { // test_waterskin does not define "encumbrance" or "max_encumbrance", so base // encumbrance is 0, and max_encumbrance is set by the item factory (finalize_post) // based on the pocket "max_contains_volume" (1 encumbrance per 250 ml). CHECK( item_info_str( waterskin, encumbrance ) == "--\n" "Encumbrance" " 0, When full 6: The legs.\n" ); // test_backpack has an explicit "encumbrance" and "max_encumbrance" CHECK( item_info_str( backpack, encumbrance ) == "--\n" "Encumbrance" " 2, When full 15: The torso.\n" ); // quiver has no volume, only an implicit volume via ammo CHECK( item_info_str( quiver, encumbrance ) == "--\n" "Encumbrance" " 3, When full 11: The legs.\n" ); } } } // Related JSON fields: // "bashing" // "cutting" // "to_hit" // // Functions: // item::combat_info TEST_CASE( "weapon_attack_ratings_and_moves", "[iteminfo][weapon]" ) { clear_avatar(); Character &player_character = get_player_character(); // new DPS calculations depend on the avatar's stats, so make sure they're consistent REQUIRE( player_character.get_str() == 8 ); REQUIRE( player_character.get_dex() == 8 ); item rag( itype_test_rag ); item rock( itype_test_rock ); item halligan( itype_test_halligan ); item mr_pointy( itype_test_pointy_stick ); item arrow( itype_test_arrow_wood ); SECTION( "melee damage" ) { // Melee damage comes from the "bashing" and "cutting" attributes in JSON // NOTE: BASE_DAMAGE info has no newline, since BASE_TOHIT always follows it std::vector damage = { iteminfo_parts::BASE_DAMAGE }; SECTION( "no damage" ) { CHECK( item_info_str( rag, damage ).empty() ); } SECTION( "bash" ) { CHECK( item_info_str( rock, damage ) == "--\n" "Melee damage:" " Bash: 7" ); } SECTION( "bash and cut" ) { CHECK( item_info_str( halligan, damage ) == "--\n" "Melee damage:" " Bash: 20" " Cut: 5" ); } SECTION( "bash and pierce" ) { // Pierce damage comes from "cut" value, if item has the STAB or SPEAR flag REQUIRE( mr_pointy.has_flag( flag_SPEAR ) ); CHECK( item_info_str( mr_pointy, damage ) == "--\n" "Melee damage:" " Bash: 5" " Pierce: 9" ); } SECTION( "bash and cut (ranged ammo)" ) { CHECK( item_info_str( arrow, damage ) == "--\n" "Melee damage:" " Bash: 2" " Cut: 1" ); } } SECTION( "to-hit rating" ) { // To-hit rating comes from the "to_hit" attribute in the item's JSON. std::vector to_hit = { iteminfo_parts::BASE_TOHIT }; CHECK( item_info_str( rock, to_hit ) == "--\n" " To-hit bonus: -2\n" ); CHECK( item_info_str( halligan, to_hit ) == "--\n" " To-hit bonus: +0\n" ); CHECK( item_info_str( mr_pointy, to_hit ) == "--\n" " To-hit bonus: -1\n" ); CHECK( item_info_str( arrow, to_hit ) == "--\n" " To-hit bonus: -2\n" ); } SECTION( "base moves" ) { // Moves are calculated in item::attack_time based on item volume, weight, and count. // Those calculations are outside the scope of these tests, but we can at least ensure // they have expected values before checking the item info string. // If one of these fails, it suggests attack_time() changed: REQUIRE( rock.attack_time( player_character ) == 79 ); REQUIRE( halligan.attack_time( player_character ) == 145 ); REQUIRE( mr_pointy.attack_time( player_character ) == 100 ); REQUIRE( arrow.attack_time( player_character ) == 65 ); std::vector moves = { iteminfo_parts::BASE_MOVES }; CHECK( item_info_str( rock, moves ) == "--\n" "Base moves per attack: 79\n" ); CHECK( item_info_str( halligan, moves ) == "--\n" "Base moves per attack: 145\n" ); CHECK( item_info_str( mr_pointy, moves ) == "--\n" "Base moves per attack: 100\n" ); CHECK( item_info_str( arrow, moves ) == "--\n" "Base moves per attack: 65\n" ); } SECTION( "base damage per second" ) { // Damage per second is dynamically calculated in item::dps and item::effective_dps based on // many different factors, all outside the scope of these tests. Here we just hope they // have the expected values in the item info summary. std::vector dps = { iteminfo_parts::BASE_DPS }; CHECK( item_info_str( rock, dps ) == "--\n" "Typical damage per second:\n" "Best: 4.68" " Vs. Agile: 2.17" " Vs. Armored: 0.07\n" ); CHECK( item_info_str( halligan, dps ) == "--\n" "Typical damage per second:\n" "Best: 7.03" " Vs. Agile: 3.80" " Vs. Armored: 1.26\n" ); CHECK( item_info_str( mr_pointy, dps ) == "--\n" "Typical damage per second:\n" "Best: 6.49" " Vs. Agile: 3.25" " Vs. Armored: 0.05\n" ); CHECK( item_info_str( arrow, dps ) == "--\n" "Typical damage per second:\n" "Best: 3.31" " Vs. Agile: 1.49" " Vs. Armored: 0.00\n" ); } SECTION( "stamina per swing" ) { // Stamina cost per swing is dynamically calculated based on many different // factors, all outside the scope of these tests. Here we just hope they // have the expected values in the item info summary. std::vector stam = { iteminfo_parts::BASE_STAMINA }; CHECK( item_info_str( rock, stam ) == "--\n" "Stamina use:" " Costs about 1.00%" " stamina to swing.\n" ); CHECK( item_info_str( halligan, stam ) == "--\n" "Stamina use:" " Costs about 3.20%" " stamina to swing.\n" ); CHECK( item_info_str( mr_pointy, stam ) == "--\n" "Stamina use:" " Costs about 1.20%" " stamina to swing.\n" ); CHECK( item_info_str( arrow, stam ) == "--\n" "Stamina use:" " Costs about 0.80%" " stamina to swing.\n" ); } SECTION( "base damage per stamina" ) { // Damage per stamina is dynamically calculated based on many different factors, // all outside the scope of these tests. Here we just hope they // have the expected values in the item info summary. std::vector dpstam = { iteminfo_parts::BASE_DPSTAM }; CHECK( item_info_str( rock, dpstam ) == "--\n" "Typical damage per stamina:\n" "Best: 5.14" " Vs. Agile: 2.38" " Vs. Armored: 0.07\n" ); CHECK( item_info_str( halligan, dpstam ) == "--\n" "Typical damage per stamina:\n" "Best: 2.56" " Vs. Agile: 1.38" " Vs. Armored: 0.46\n" ); CHECK( item_info_str( mr_pointy, dpstam ) == "--\n" "Typical damage per stamina:\n" "Best: 6.13" " Vs. Agile: 3.06" " Vs. Armored: 0.04\n" ); CHECK( item_info_str( arrow, dpstam ) == "--\n" "Typical damage per stamina:\n" "Best: 4.87" " Vs. Agile: 2.20" " Vs. Armored: 0.00\n" ); } } // Related JSON fields: // "techniques" - list of technique ids, ex. [ "WBLOCK_1", "BRUTAL", "SWEEP" ] // // Technique descriptions are defined in data/json/techniques.json // // Functions: // item::combat_info TEST_CASE( "techniques_when_wielded", "[iteminfo][weapon][techniques]" ) { clear_avatar(); item halligan( itype_test_halligan ); CHECK( item_info_str( halligan, { iteminfo_parts::DESCRIPTION_TECHNIQUES } ) == "--\n" "Techniques when wielded:" " Brutal Strike:" " Stun 1 turn, knockback 1 tile, crit only, min 2 melee * Only works on a non-stunned mundane target of similar or smaller size, may fail on enemies grabbing you," " Sweep Attack:" " Down 2 turns, min 3 melee * Only works on a non-downed humanoid target of similar or smaller size incapable of flight, and" " Block:" " Medium blocking ability \n" ); item plank( itype_test_2x4 ); CHECK( item_info_str( plank, { iteminfo_parts::DESCRIPTION_TECHNIQUES } ) == "--\n" "Techniques when wielded:" " Block:" " Medium blocking ability \n" ); } static std::vector bodyparts_to_check() { return { bodypart_id( "torso" ), bodypart_id( "arm_l" ), bodypart_id( "arm_r" ), bodypart_id( "leg_l" ), bodypart_id( "leg_r" ), bodypart_id( "hand_l" ), bodypart_id( "hand_r" ), bodypart_id( "head" ), bodypart_id( "mouth" ), bodypart_id( "foot_l" ), bodypart_id( "foot_r" ), }; } static void verify_item_coverage( const item &i, const std::map &expected ) { CAPTURE( i.typeId() ); REQUIRE( i.get_covered_body_parts().any() ); for( const bodypart_id &bp : bodyparts_to_check() ) { CAPTURE( bp.id() ); REQUIRE( i.get_coverage( bp ) == expected.at( bp ) ); } } static void verify_item_warmth_by_bodypart( const item &i ) { CAPTURE( i.typeId() ); std::vector> warmth_by_bodypart; i.get_warmth_by_bodypart( warmth_by_bodypart ); for( const bodypart_id &bp : bodyparts_to_check() ) { CAPTURE( bp.id() ); const auto found = std::find_if( warmth_by_bodypart.begin(), warmth_by_bodypart.end(), [&]( const auto & entry ) { return entry.first == bp; } ); const int warmth = found == warmth_by_bodypart.end() ? 0 : found->second; CHECK( warmth == i.get_warmth( bp ) ); } } static void verify_item_encumbrance( const item &i, item::encumber_flags flags, int average, const std::map &expected ) { CAPTURE( i.typeId() ); REQUIRE( i.get_avg_encumber( get_player_character(), flags ) == average ); for( const bodypart_id &bp : bodyparts_to_check() ) { CAPTURE( bp.id() ); REQUIRE( i.get_encumber( get_player_character(), bp, flags ) == expected.at( bp ) ); } } TEST_CASE( "warmth_by_bodypart_matches_single_bodypart_queries", "[iteminfo][armor][warmth]" ) { item splint( itype_arm_splint ); REQUIRE( splint.set_side( side::LEFT ) ); verify_item_warmth_by_bodypart( splint ); REQUIRE( splint.set_side( side::RIGHT ) ); verify_item_warmth_by_bodypart( splint ); } // Related JSON fields: // "covers" // "coverage" // "warmth" // "encumbrance" // // Functions: // item::armor_info TEST_CASE( "armor_coverage_warmth_and_encumbrance", "[iteminfo][armor][coverage]" ) { clear_avatar(); SECTION( "armor with coverage shows covered body parts, warmth, encumbrance, and protection values" ) { // Long-sleeved shirt covering torso and arms item longshirt( itype_test_longshirt ); verify_item_coverage( longshirt, { { bodypart_id( "torso" ), 90 }, { bodypart_id( "arm_l" ), 90 }, { bodypart_id( "arm_r" ), 90 }, { bodypart_id( "leg_l" ), 0 }, { bodypart_id( "leg_r" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, } ); CHECK( item_info_str( longshirt, { iteminfo_parts::ARMOR_BODYPARTS } ) == "--\n" "Covers:" " The arms." " The torso.\n" ); // Coverage and warmth are displayed together on a single line. // Use actual item values so the test doesn't break when new body parts // with similar_bodypart links change the average coverage. std::vector cov_warm_shirt = { iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH }; int shirt_cov = longshirt.get_avg_coverage(); int shirt_warmth = longshirt.get_warmth(); REQUIRE( shirt_cov > 0 ); REQUIRE( shirt_warmth > 0 ); CHECK( item_info_str( longshirt, cov_warm_shirt ) == "--\n" "Total Coverage" " " + std::to_string( shirt_cov ) + "%:" " The arms. The torso.\n" "Warmth" " " + std::to_string( shirt_warmth ) + ":" " The arms. The torso.\n" ); verify_item_encumbrance( longshirt, item::encumber_flags::none, 3, { { bodypart_id( "torso" ), 3 }, { bodypart_id( "arm_l" ), 3 }, { bodypart_id( "arm_r" ), 3 }, { bodypart_id( "leg_l" ), 0 }, { bodypart_id( "leg_r" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, } ); verify_item_encumbrance( longshirt, item::encumber_flags::assume_full, 3, { { bodypart_id( "torso" ), 3 }, { bodypart_id( "arm_l" ), 3 }, { bodypart_id( "arm_r" ), 3 }, { bodypart_id( "leg_l" ), 0 }, { bodypart_id( "leg_r" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, } ); CHECK( item_info_str( longshirt, { iteminfo_parts::ARMOR_ENCUMBRANCE } ) == "--\n" "Size/Fit: (poor fit)\n" "Encumbrance" " 3: The arms. The torso.\n" ); item swat_armor( itype_test_swat_armor ); REQUIRE( swat_armor.get_covered_body_parts().any() ); CHECK( item_info_str( swat_armor, { iteminfo_parts::ARMOR_BODYPARTS } ) == "--\n" "Covers:" " The arms." " The legs." " The torso.\n" ); std::vector cov_warm_swat = { iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH }; int swat_armor_cov = swat_armor.get_avg_coverage(); int swat_armor_warmth = swat_armor.get_warmth(); REQUIRE( swat_armor_cov > 0 ); REQUIRE( swat_armor_warmth > 0 ); CHECK( item_info_str( swat_armor, cov_warm_swat ) == "--\n" "Total Coverage" " " + std::to_string( swat_armor_cov ) + "%: The arms. The legs. The torso.\n" "Warmth" " " + std::to_string( swat_armor_warmth ) + ": The arms. The legs. The torso.\n" ); verify_item_coverage( swat_armor, { { bodypart_id( "torso" ), 95 }, { bodypart_id( "leg_l" ), 95 }, { bodypart_id( "leg_r" ), 95 }, { bodypart_id( "arm_l" ), 95 }, { bodypart_id( "arm_r" ), 95 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "hand_r" ), 0 }, { bodypart_id( "hand_l" ), 0 }, } ); verify_item_encumbrance( swat_armor, item::encumber_flags::none, 12, { { bodypart_id( "torso" ), 12 }, { bodypart_id( "leg_l" ), 12 }, { bodypart_id( "leg_r" ), 12 }, { bodypart_id( "arm_l" ), 12 }, { bodypart_id( "arm_r" ), 12 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, } ); verify_item_encumbrance( swat_armor, item::encumber_flags::assume_full, 25, { { bodypart_id( "torso" ), 25 }, { bodypart_id( "leg_l" ), 25 }, { bodypart_id( "leg_r" ), 25 }, { bodypart_id( "arm_l" ), 25 }, { bodypart_id( "arm_r" ), 25 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, } ); CHECK( item_info_str( swat_armor, { iteminfo_parts::ARMOR_ENCUMBRANCE } ) == "--\n" "Encumbrance " " 12, When full 25:" " The arms." " The legs." " The torso.\n" ); // Test copy-from item faux_fur_pants( itype_test_pants_faux_fur ); REQUIRE( faux_fur_pants.get_covered_body_parts().any() ); CHECK( item_info_str( faux_fur_pants, { iteminfo_parts::ARMOR_BODYPARTS } ) == "--\n" "Covers:" " The legs.\n" ); std::vector cov_warm_pants = { iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH }; REQUIRE( faux_fur_pants.get_avg_coverage() == 95 ); REQUIRE( faux_fur_pants.get_warmth() == 70 ); CHECK( item_info_str( faux_fur_pants, cov_warm_pants ) == "--\n" "Total Coverage 95%: The legs.\n" "Warmth 70: The legs.\n" ); verify_item_coverage( faux_fur_pants, { { bodypart_id( "torso" ), 0 }, { bodypart_id( "leg_l" ), 95 }, { bodypart_id( "leg_r" ), 95 }, { bodypart_id( "arm_l" ), 0 }, { bodypart_id( "arm_r" ), 0 }, { bodypart_id( "foot_r" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, } ); verify_item_encumbrance( faux_fur_pants, item::encumber_flags::none, 16, { { bodypart_id( "torso" ), 0 }, { bodypart_id( "leg_l" ), 16 }, { bodypart_id( "leg_r" ), 16 }, { bodypart_id( "arm_l" ), 0 }, { bodypart_id( "arm_r" ), 0 }, { bodypart_id( "foot_r" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, } ); verify_item_encumbrance( faux_fur_pants, item::encumber_flags::assume_full, 20, { { bodypart_id( "torso" ), 0 }, { bodypart_id( "leg_l" ), 20 }, { bodypart_id( "leg_r" ), 20 }, { bodypart_id( "arm_l" ), 0 }, { bodypart_id( "arm_r" ), 0 }, { bodypart_id( "foot_r" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, } ); item faux_fur_suit( itype_test_portion_faux_fur_pants_suit ); REQUIRE( faux_fur_suit.get_covered_body_parts().any() ); CHECK( item_info_str( faux_fur_suit, { iteminfo_parts::ARMOR_BODYPARTS } ) == "--\n" "Covers:" " The arms." " The head." " The legs." " The torso.\n" ); std::vector cov_warm_suit = { iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH }; REQUIRE( faux_fur_suit.get_avg_coverage() == 75 ); REQUIRE( faux_fur_suit.get_warmth() == 5 ); verify_item_warmth_by_bodypart( faux_fur_suit ); CHECK( item_info_str( faux_fur_suit, cov_warm_suit ) == "--\n" "Total Coverage:\n" " 50%: The head. The l. arm. The l. leg.\n" " 100%: The r. arm. The r. leg. The torso.\n" "Warmth" " 5: The arms. The head. The legs. The torso.\n" ); REQUIRE( faux_fur_suit.get_avg_coverage() == 75 ); verify_item_coverage( faux_fur_suit, { { bodypart_id( "torso" ), 100 }, { bodypart_id( "leg_l" ), 50 }, { bodypart_id( "leg_r" ), 100 }, { bodypart_id( "arm_l" ), 50 }, { bodypart_id( "arm_r" ), 100 }, { bodypart_id( "head" ), 50 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, } ); verify_item_encumbrance( faux_fur_suit, item::encumber_flags::none, 7, { { bodypart_id( "torso" ), 10 }, { bodypart_id( "leg_l" ), 5 }, { bodypart_id( "leg_r" ), 10 }, { bodypart_id( "arm_l" ), 5 }, { bodypart_id( "arm_r" ), 10 }, { bodypart_id( "head" ), 5 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, } ); verify_item_encumbrance( faux_fur_suit, item::encumber_flags::assume_full, 17, { { bodypart_id( "torso" ), 25 }, { bodypart_id( "leg_l" ), 9 }, { bodypart_id( "leg_r" ), 25 }, { bodypart_id( "arm_l" ), 9 }, { bodypart_id( "arm_r" ), 25 }, { bodypart_id( "head" ), 9 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, } ); CHECK( item_info_str( faux_fur_suit, { iteminfo_parts::ARMOR_ENCUMBRANCE } ) == "--\n" "Size/Fit: (poor fit)\n" "Encumbrance:\n" " 5, When full 9:" " The head." " The l. arm." " The l. leg.\n" " 10, When full 25:" " The r. arm." " The r. leg." " The torso.\n" ); // test complex materials armors item super_tank_top( itype_test_complex_tanktop ); REQUIRE( super_tank_top.get_covered_body_parts().any() ); CHECK( item_info_str( super_tank_top, { iteminfo_parts::ARMOR_BODYPARTS } ) == "--\n" "Covers:" " The torso.\n" ); std::vector cov_warm_super_tank = { iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH }; REQUIRE( super_tank_top.get_avg_coverage() == 100 ); REQUIRE( super_tank_top.get_warmth() == 20 ); verify_item_warmth_by_bodypart( super_tank_top ); CHECK( item_info_str( super_tank_top, cov_warm_super_tank ) == "--\n" "Total Coverage 100%: The torso.\n" "Warmth 20: The torso.\n" ); verify_item_coverage( super_tank_top, { { bodypart_id( "torso" ), 100 }, { bodypart_id( "leg_l" ), 0 }, { bodypart_id( "leg_r" ), 0 }, { bodypart_id( "arm_l" ), 0 }, { bodypart_id( "arm_r" ), 0 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "hand_r" ), 0 }, { bodypart_id( "hand_l" ), 0 }, } ); verify_item_encumbrance( super_tank_top, item::encumber_flags::none, 7, { { bodypart_id( "torso" ), 7 }, { bodypart_id( "leg_l" ), 0 }, { bodypart_id( "leg_r" ), 0 }, { bodypart_id( "arm_l" ), 0 }, { bodypart_id( "arm_r" ), 0 }, { bodypart_id( "head" ), 0 }, { bodypart_id( "foot_l" ), 0 }, { bodypart_id( "foot_r" ), 0 }, { bodypart_id( "eyes" ), 0 }, { bodypart_id( "mouth" ), 0 }, { bodypart_id( "hand_l" ), 0 }, { bodypart_id( "hand_r" ), 0 }, } ); CHECK( item_info_str( super_tank_top, { iteminfo_parts::ARMOR_ENCUMBRANCE } ) == "--\n" "Encumbrance" " 7: The torso.\n" ); } SECTION( "armor with no coverage omits irrelevant info" ) { // Ear plugs with no coverage, and no other info to display item ear_plugs( itype_test_ear_plugs ); REQUIRE_FALSE( ear_plugs.get_covered_body_parts().any() ); CHECK( item_info_str( ear_plugs, { iteminfo_parts::ARMOR_BODYPARTS, iteminfo_parts::ARMOR_COVERAGE, iteminfo_parts::ARMOR_WARMTH, iteminfo_parts::ARMOR_ENCUMBRANCE, iteminfo_parts::ARMOR_PROTECTION } ) == "--\n" "Covers: Nothing.\n" ); } } // Related JSON fields: // material softness // padded flag TEST_CASE( "armor_rigidity", "[iteminfo][armor][coverage]" ) { clear_avatar(); // test complex materials armors item super_tank_top( itype_test_complex_tanktop ); REQUIRE( super_tank_top.get_covered_body_parts().any() ); CHECK( item_info_str( super_tank_top, { iteminfo_parts::ARMOR_RIGIDITY } ) == "--\n" "This armor is rigid.\n" "This armor is comfortable.\n" ); } // Related JSON fields: // "covers" // "flags" // "power_armor" // // Functions: // item::armor_fit_info TEST_CASE( "armor_fit_and_sizing", "[iteminfo][armor][fit]" ) { clear_avatar(); std::vector varsize = { iteminfo_parts::DESCRIPTION_FLAGS_VARSIZE }; std::vector sided = { iteminfo_parts::DESCRIPTION_FLAGS_SIDED }; std::vector powerarmor = { iteminfo_parts::DESCRIPTION_FLAGS_POWERARMOR }; // TODO: Test items with these //std::vector helmet_compat = { iteminfo_parts::DESCRIPTION_FLAGS_HELMETCOMPAT }; //std::vector fits = { iteminfo_parts::DESCRIPTION_FLAGS_FITS }; //std::vector irradiation = { iteminfo_parts::DESCRIPTION_IRRADIATION }; //std::vector powerarmor_rad = { iteminfo_parts::DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT }; // Items with VARSIZE flag can be fitted item socks( itype_test_socks ); CHECK( item_info_str( socks, varsize ) == "--\n" "* This clothing can be refitted.\n" ); // Sided armor is show as sided item briefcase( itype_test_briefcase ); CHECK( item_info_str( briefcase, sided ) == "--\n" "* This item can be worn on either side of the body.\n" ); item power_armor( itype_test_power_armor ); CHECK_THAT( item_info_str( power_armor, powerarmor ), Catch::Matchers::EndsWith( "* This gear is a part of power armor.\n" ) ); } static void expected_armor_values( const item &armor, float bash, float cut, float stab, float bullet, float acid = 0.0f, float fire = 0.0f, float env = 0.0f ) { CAPTURE( armor.typeId().str() ); REQUIRE( armor.resist( damage_bash ) == Approx( bash ) ); REQUIRE( armor.resist( damage_cut ) == Approx( cut ) ); REQUIRE( armor.resist( damage_stab ) == Approx( stab ) ); REQUIRE( armor.resist( damage_bullet ) == Approx( bullet ) ); REQUIRE( armor.resist( damage_acid ) == Approx( acid ) ); REQUIRE( armor.resist( damage_heat ) == Approx( fire ) ); REQUIRE( armor.get_env_resist() == Approx( env ) ); } TEST_CASE( "armor_stats", "[armor][protection]" ) { expected_armor_values( item( itype_zentai ), 0.1f, 0.1f, 0.08f, 0.1f ); expected_armor_values( item( itype_tshirt ), 0.1f, 0.1f, 0.08f, 0.1f ); expected_armor_values( item( itype_dress_shirt ), 0.1f, 0.1f, 0.08f, 0.1f ); } TEST_CASE( "helmet_with_pockets_stats", "[iteminfo][armor][protection]" ) { bodypart_id bp_head = body_part_head.id(); bodypart_id bp_eyes = body_part_eyes.id(); sub_bodypart_id eye_r = sub_body_part_eyes_right.id(); item hh( itype_hat_hard ); THEN( "base stats" ) { //resistance stats CHECK( hh.resist( damage_bash, false, bp_head ) == Approx( 8.f ) ); CHECK( hh.resist( damage_bash, false, bp_eyes ) == Approx( 0.f ) ); CHECK( hh.resist( damage_bash, false, eye_r ) == Approx( 0.f ) ); //warmth stats: 5 (hat's warmth) * 0.4 (hat's body part coverage) CHECK( hh.get_warmth( bp_head ) == 2 ); CHECK( hh.get_warmth( bp_eyes ) == 0 ); verify_item_warmth_by_bodypart( hh ); } WHEN( "inserting face shield" ) { item face_shield( itype_face_shield ); REQUIRE( hh.put_in( face_shield, pocket_type::CONTAINER ).success() ); THEN( "eyes should be protected" ) { CHECK( hh.resist( damage_bash, false, bp_head ) == Approx( 8.f ) ); CHECK( hh.resist( damage_bash, false, bp_eyes ) == Approx( 6.f ) ); CHECK( hh.resist( damage_bash, false, eye_r ) == Approx( 6.f ) ); } THEN( "warmth should not change" ) { CHECK( hh.get_warmth( bp_head ) == 2 ); CHECK( hh.get_warmth( bp_eyes ) == 0 ); verify_item_warmth_by_bodypart( hh ); } THEN( "breathbility should be 0" ) { CHECK( hh.breathability( bp_eyes ) == 0 ); } } WHEN( "adding nape protector to the helmet" ) { item nape_protector( itype_nape_protector ); REQUIRE( hh.put_in( nape_protector, pocket_type::CONTAINER ).success() ); THEN( "head's warmth is increased" ) { CHECK( nape_protector.get_warmth( bp_head ) == 2 ); //2 (base warmth) + 4 (nape's warmth) * 0.4 (nape's body part coverage) CHECK( hh.get_warmth( bp_head ) == 4 ); verify_item_warmth_by_bodypart( hh ); } WHEN( "adding ear muffs to the helmet" ) { item ear_muffs( itype_attachable_ear_muffs ); REQUIRE( hh.put_in( ear_muffs, pocket_type::CONTAINER ).success() ); THEN( "head's warmth should be increased even more" ) { CHECK( ear_muffs.get_warmth( bp_head ) == 2 ); CHECK( hh.get_warmth( bp_head ) == 6 ); verify_item_warmth_by_bodypart( hh ); } } } } TEST_CASE( "vest_with_plate_stats", "[iteminfo][armor][protection]" ) { bodypart_id bp_torso = body_part_torso.id(); item vest = item( itype_ballistic_vest_esapi ); //nylon: 1 (mat resist) * 1 (thickness) //kevlar: 1.5 * 4.4 CHECK( vest.resist( damage_bash, false, bp_torso ) == Approx( 7.6f ) ); WHEN( "inserting plate" ) { CHECK( vest.put_in( item( itype_test_plate ), pocket_type::CONTAINER ).success() ); THEN( "resist should be increased" ) { //previous + 1 * 25 CHECK( vest.resist( damage_bash, false, bp_torso ) == Approx( 32.6f ) ); } } } // Check that a string is provided in some iteminfo // By providing last_pos, order can also be checked static void test_string( const std::string &info, const std::string &tested, size_t &last_pos ) { INFO( string_format( "Checking for \"%s\" in:", tested ) ); INFO( info ); size_t pos = info.find( tested ); CHECK( pos != std::string::npos ); CHECK( pos >= last_pos ); last_pos = pos; } // Armor protction is based on materials, thickness, and/or environmental protection rating. // For armor defined in JSON: // // - "materials" determine the resistance factors (bash, cut, fire etc.) // - "material_thickness" multiplies bash, cut, and bullet resistance // - "environmental_protection" gives acid and fire resist (N/10 if less than 10) // // See doc/DEVELOPER_FAQ.md "How armor protection is calculated" for more. // // Materials and protection calculations are not tested here; only their display in item info. // // item::armor_protection_info TEST_CASE( "armor_protection", "[iteminfo][armor][protection]" ) { clear_avatar(); std::vector protection = { iteminfo_parts::ARMOR_PROTECTION }; std::vector more_protection = { iteminfo_parts::ARMOR_PROTECTION, iteminfo_parts::ARMOR_ENCUMBRANCE }; // TODO: // - Air filtration or gas mask (inactive/active) // - Damaged armor reduces protection SECTION( "no protection from physical, no protection from environmental" ) { // Long-sleeved shirt, material:cotton, thickness:0.2 // 1/1/1 bash/cut/bullet x 1 thickness // 0/0/0 acid/fire/env item longshirt( itype_test_longshirt ); expected_armor_values( longshirt, 0.2f, 0.2f, 0.16f, 0.2f ); REQUIRE( longshirt.get_covered_body_parts().any() ); // Protection info displayed on two lines CHECK( item_info_str( longshirt, protection ) == "--\n" "Protection for: The arms. The torso.\n" "Coverage: Normal.\n" " Default: 90\n" "Protection:\n" " Negligible Protection\n" ); } SECTION( "moderate protection from physical and environmental damage" ) { // Hazmat suit, material:plastic, thickness:2 // 2/2/1 bash/cut/bullet x 2 thickness // 9/1/20 acid/fire/env item hazmat( itype_test_hazmat_suit ); REQUIRE( hazmat.get_covered_body_parts().any() ); expected_armor_values( hazmat, 4, 4, 3.2, 2, 9, 1, 20 ); const std::string bp_header_string = "Protection for:"; const std::vector bodyparts = { "The arms.", " The eyes.", " The feet.", " The hands.", " The head.", " The legs.", " The mouth.", " The torso." }; const std::string coverage_string = "Coverage: Outer.\n" " Default: 100\n"; const std::string prot_header_string = "Protection:\n"; const std::string bash_string = " Bash: 4.00\n"; const std::string cut_string = " Cut: 4.00\n"; const std::string ballistic_string = " Ballistic: 2.00\n"; const std::string pierce_string = " Pierce: 3.20\n"; const std::string acid_string = " Acid: 9.00\n"; const std::string fire_string = " Fire: 1.00\n"; const std::string env_string = " Environmental: 20\n"; // Protection info displayed on two lines const std::string info = item_info_str( hazmat, protection ); size_t pos = 0; test_string( info, bp_header_string, pos ); for( const std::string &bodyparts_string : bodyparts ) { test_string( info, bodyparts_string, pos ); } test_string( info, coverage_string, pos ); test_string( info, prot_header_string, pos ); test_string( info, bash_string, pos ); test_string( info, cut_string, pos ); test_string( info, ballistic_string, pos ); test_string( info, pierce_string, pos ); test_string( info, acid_string, pos ); test_string( info, fire_string, pos ); test_string( info, env_string, pos ); } SECTION( "check that material resistances are properly overriden" ) { // Zentai suit, material:lycra_resist_override_stab, thickness:1 // 2/2/2/50 bash/cut/bullet/stab x 1 thickness item zentai( itype_test_zentai_resist_stab_cut ); REQUIRE( zentai.get_covered_body_parts().any() ); expected_armor_values( zentai, 2, 2, 50, 2, 9, 2, 10 ); // Protection info displayed on two lines const std::string info = item_info_str( zentai, protection ); const std::string protection_head_str = "Protection for:"; const std::vector bodyparts = { "The arms.", " The eyes.", " The feet.", " The hands.", " The head.", " The legs.", " The mouth.", " The torso." }; const std::string coverage_str = "Coverage: Close to skin.\n" " Default: 100\n"; const std::string prot_header_str = "Protection:\n"; const std::string bash_str = " Bash: 2.00\n"; const std::string cut_str = " Cut: 2.00\n"; const std::string ballistic_str = " Ballistic: 2.00\n"; const std::string pierce_str = " Pierce: 50.00\n"; const std::string acid_str = " Acid: 9.00\n"; const std::string fire_str = " Fire: 2.00\n"; const std::string env_str = " Environmental: 10\n"; size_t pos = 0; test_string( info, protection_head_str, pos ); for( const std::string &bodyparts_str : bodyparts ) { test_string( info, bodyparts_str, pos ); } test_string( info, coverage_str, pos ); test_string( info, prot_header_str, pos ); test_string( info, bash_str, pos ); test_string( info, cut_str, pos ); test_string( info, ballistic_str, pos ); test_string( info, pierce_str, pos ); test_string( info, acid_str, pos ); test_string( info, fire_str, pos ); test_string( info, env_str, pos ); } SECTION( "complex protection from physical and environmental damage" ) { item super_tanktop( itype_test_complex_tanktop ); REQUIRE( super_tanktop.get_covered_body_parts().any() ); // these values are averaged values but test that assumed armor portion is working at all expected_armor_values( super_tanktop, 15.33333f, 15.33333f, 12.26667f, 10.66667f ); // Protection info displayed on two lines const std::string info = item_info_str( super_tanktop, more_protection ); const std::string encumbrance_str = "Encumbrance 7: The torso.\n"; const std::string bodyparts_str = "Protection for: The torso.\n"; const std::string coverage_str = "Coverage: Close to skin.\n" " Default: 100\n"; const std::string protection_str = "Protection: 4% chance, Median chance, 4% chance\n"; const std::string bash_str = " Bash: 1.00, 12.00, 23.00\n"; const std::string cut_str = " Cut: 1.00, 12.00, 23.00\n"; const std::string ballistic_str = " Ballistic: 1.00, 8.50, 16.00\n"; const std::string pierce_str = " Pierce: 0.80, 9.60, 18.40\n"; size_t pos = 0; test_string( info, encumbrance_str, pos ); test_string( info, bodyparts_str, pos ); test_string( info, coverage_str, pos ); test_string( info, protection_str, pos ); test_string( info, bash_str, pos ); test_string( info, cut_str, pos ); test_string( info, ballistic_str, pos ); test_string( info, pierce_str, pos ); } SECTION( "pet armor with good physical and environmental protection" ) { // Kevlar cat harness, for reasons // material:layered_kevlar, thickness:2 // 1.5/2/5 bash/cut/bullet x 2 thickness // 5/40/10 acid/fire/env item meower_armor( itype_test_meower_armor ); expected_armor_values( meower_armor, 3, 4, 3.2, 10, 5, 40, 10 ); const std::string info = item_info_str( meower_armor, protection ); const std::string header_str = "Protection:\n"; const std::string bash_str = " Bash: 3.00\n"; const std::string cut_str = " Cut: 4.00\n"; const std::string ballistic_str = " Ballistic: 10.00\n"; const std::string acid_str = " Acid: 5.00\n"; const std::string fire_str = " Fire: 40.00\n"; const std::string env_str = " Environmental: 10\n"; size_t pos = 0; test_string( info, header_str, pos ); test_string( info, bash_str, pos ); test_string( info, cut_str, pos ); test_string( info, ballistic_str, pos ); test_string( info, acid_str, pos ); test_string( info, fire_str, pos ); test_string( info, env_str, pos ); } } // Related JSON fields: // "fun" // "time" // "skill" // "required_level" // "max_level" // "intelligence" // // Functions: // item::book_info TEST_CASE( "book_info", "[iteminfo][book]" ) { clear_avatar(); // Parts to test std::vector summary = { iteminfo_parts::BOOK_SUMMARY }; std::vector reqs_begin = { iteminfo_parts::BOOK_REQUIREMENTS_BEGINNER }; std::vector skill_min = { iteminfo_parts::BOOK_SKILLRANGE_MIN }; std::vector skill_max = { iteminfo_parts::BOOK_SKILLRANGE_MAX }; std::vector reqs_int = { iteminfo_parts::BOOK_REQUIREMENTS_INT }; std::vector morale = { iteminfo_parts::BOOK_MORALECHANGE }; std::vector time_per_chapter = { iteminfo_parts::BOOK_TIMEPERCHAPTER }; // TODO: include test for these: // std::vector num_unread = { iteminfo_parts::BOOK_NUMUNREADCHAPTERS }; // std::vector included_recipes = { iteminfo_parts::BOOK_INCLUDED_RECIPES }; item dragon( itype_test_dragon_book ); item cmdline( itype_test_cmdline_book ); // TODO: add martial arts book to test data REQUIRE( dragon.is_book() ); REQUIRE( cmdline.is_book() ); // summary is shown for martial arts books and "just for fun" books, but no others WHEN( "book has not been identified" ) { THEN( "some basic book info is shown" ) { // Some info is always shown CHECK( item_info_str( cmdline, summary ) == "--\n" "Just for fun.\n" ); CHECK( item_info_str( cmdline, reqs_begin ) == "--\n" "It can be understood by beginners.\n" ); } THEN( "other book info is hidden" ) { CHECK( item_info_str( cmdline, skill_min ).empty() ); CHECK( item_info_str( cmdline, skill_max ).empty() ); CHECK( item_info_str( cmdline, reqs_int ).empty() ); CHECK( item_info_str( cmdline, morale ).empty() ); CHECK( item_info_str( cmdline, time_per_chapter ).empty() ); } } WHEN( "book has been identified" ) { avatar &player_character = get_avatar(); player_character.identify( cmdline ); player_character.identify( dragon ); THEN( "some basic book info is shown" ) { CHECK( item_info_str( cmdline, summary ) == "--\n" "Just for fun.\n" ); CHECK( item_info_str( cmdline, reqs_begin ) == "--\n" "It can be understood by beginners.\n" ); } THEN( "morale (fun) info is shown" ) { // JSON field: "fun" CHECK( item_info_str( cmdline, morale ) == "--\n" "Reading this book affects your morale by +2\n" ); CHECK( item_info_str( dragon, morale ) == "--\n" "Reading this book affects your morale by -1\n" ); } THEN( "time per chapter is shown" ) { // JSON field: "time" CHECK( item_info_str( cmdline, time_per_chapter ) == "--\n" "A chapter of this book takes 5" " minutes to read.\n" ); CHECK( item_info_str( dragon, time_per_chapter ) == "--\n" "A chapter of this book takes 50" " minutes to read.\n" ); } THEN( "book requirement info is shown" ) { // Book with skill min/max and intelligence requirement // JSON fields: "required_level", "max_level", "intelligence" CHECK( item_info_str( dragon, skill_min ) == "--\n" "Requires computers level 4 to understand.\n" ); CHECK( item_info_str( dragon, skill_max ) == "--\n" "Can bring your computers skill to 7.\n" "Your current computers skill is 0.\n" ); CHECK( item_info_str( dragon, reqs_int ) == "--\n" "Requires intelligence of 12 to easily read.\n" ); } THEN( "no requirement info is shown if book has none" ) { // Book with no requirements CHECK( item_info_str( cmdline, skill_min ).empty() ); CHECK( item_info_str( cmdline, skill_max ).empty() ); CHECK( item_info_str( cmdline, reqs_int ).empty() ); } } } // Related JSON fields: // "range" // "ranged_damage" // - "amount" // "skill" // "critical_multiplier" (ammo) // "magazines" // // Functions: // item::gun_info TEST_CASE( "gun_or_other_ranged_weapon_attributes", "[iteminfo][weapon][gun]" ) { clear_avatar(); item compbow( itype_test_compbow ); item glock( itype_test_glock ); item rag( itype_test_rag ); SECTION( "weapon damage" ) { std::vector damage = { iteminfo_parts::GUN_DAMAGE, iteminfo_parts::GUN_DAMAGE_PELLETS, iteminfo_parts::GUN_DAMAGE_TOTAL }; CHECK( item_info_str( compbow, damage ) == "--\n" "Ranged damage:" " 27\n" ); } // TODO: Test glock damage with and without ammo (test_glock has -1 damage when unloaded) SECTION( "maximum range" ) { std::vector max_range = { iteminfo_parts::GUN_MAX_RANGE }; CHECK( item_info_str( compbow, max_range ) == "--\n" "Maximum range: 18\n" ); CHECK( item_info_str( glock, max_range ) == "--\n" "Maximum range: 14\n" ); } SECTION( "skill used" ) { std::vector used_skill = { iteminfo_parts::GUN_USEDSKILL }; CHECK( item_info_str( compbow, used_skill ) == "--\n" "Skill used: archery\n" ); CHECK( item_info_str( glock, used_skill ) == "--\n" "Skill used: handguns\n" ); } SECTION( "ammo capacity of weapon" ) { std::vector gun_capacity = { iteminfo_parts::GUN_CAPACITY }; CHECK( item_info_str( compbow, gun_capacity ) == "--\n" "Capacity: 1 round of arrows\n" ); // FIXME: Why empty? CHECK( item_info_str( glock, gun_capacity ).empty() ); } SECTION( "default ammo when weapon is unloaded" ) { std::vector default_ammo = { iteminfo_parts::GUN_DEFAULT_AMMO }; CHECK( item_info_str( compbow, default_ammo ) == "--\n" "Weapon is not loaded, so stats below assume the default ammo:" " wooden broadhead arrow\n" ); CHECK( item_info_str( glock, default_ammo ) == "--\n" "Weapon is not loaded, so stats below assume the default ammo:" " Test 9mm ammo\n" ); } SECTION( "critical multiplier" ) { std::vector crit_multiplier = { iteminfo_parts::AMMO_DAMAGE_CRIT_MULTIPLIER }; CHECK( item_info_str( compbow, crit_multiplier ) == "--\n" "Critical multiplier: 10\n" ); CHECK( item_info_str( glock, crit_multiplier ) == "--\n" "Critical multiplier: 2\n" ); } SECTION( "recoil" ) { std::vector recoil = { iteminfo_parts::GUN_RECOIL }; CHECK( item_info_str( compbow, recoil ).empty() ); CHECK( item_info_str( glock, recoil ) == "--\n" "Effective recoil: 3.12 MOA\n" ); } SECTION( "gun type and current magazine" ) { std::vector magazine = { iteminfo_parts::GUN_MAGAZINE }; // When unloaded, the "Magazine:" section should not be shown CHECK( item_info_str( glock, magazine ).empty() ); // TODO: Test guns having "Type:" (not many exist; ex. ar15_retool_300blk) // TODO: Test with magazine inserted, ex. "Magazine: Glock 17 17-round magazine" } SECTION( "gun aiming stats" ) { std::vector aim_stats = { iteminfo_parts::GUN_AIMING_STATS }; CHECK( item_info_str( glock, aim_stats ) == "--\n" "Regular\n" "Even chance of good hit at range: 2\n" "Time to reach aim level: 233 moves\n" "Careful\n" "Even chance of good hit at range: 3\n" "Time to reach aim level: 399 moves\n" "Precise\n" "Even chance of good hit at range: 4\n" "Time to reach aim level: 645 moves\n" ); } SECTION( "compatible magazines" ) { std::vector allowed_mags = { iteminfo_parts::GUN_ALLOWED_MAGAZINES }; // expect magazine_compatible().empty() if magazine_integral() // Compound bow has integral magazine, not compatible ones REQUIRE( compbow.magazine_integral() ); REQUIRE( compbow.magazine_compatible().empty() ); // No compatible magazine info should be shown CHECK( item_info_str( compbow, allowed_mags ).empty() ); // Glock has compatible magazines, not integral REQUIRE_FALSE( glock.magazine_integral() ); REQUIRE_FALSE( glock.magazine_compatible().empty() ); // Should show compatible magazines CHECK( item_info_str( glock, allowed_mags ) == "--\n" "Compatible magazines:\n" "Types: Test Glock extended magazine and Test Glock magazine\n" ); // Rag does not have integral or compatible magazines REQUIRE_FALSE( rag.magazine_integral() ); REQUIRE( rag.magazine_compatible().empty() ); // No magazine info should be shown CHECK( item_info_str( rag, allowed_mags ).empty() ); } SECTION( "armor piercing" ) { CHECK( item_info_str( compbow, { iteminfo_parts::GUN_ARMORPIERCE } ) == "--\n" "Armor-pierce: 1\n" ); } SECTION( "time to reload weapon" ) { CHECK( item_info_str( compbow, { iteminfo_parts::GUN_RELOAD_TIME } ) == "--\n" "Reload time: 110 moves\n" ); } SECTION( "weapon firing modes" ) { CHECK( item_info_str( compbow, { iteminfo_parts::GUN_FIRE_MODES } ) == "--\n" "Fire modes: manual (1)\n" ); } SECTION( "weapon mods" ) { CHECK( item_info_str( compbow, { iteminfo_parts::DESCRIPTION_GUN_MODS } ) == "--\n" "Mods:\n" "# dampening:\n" " [-empty-]\n" "# sights:\n" " [-empty-]\n" "# stabilizer:\n" " [-empty-]\n" "# underbarrel:\n" " [-empty-]\n" ); } SECTION( "weapon dispersion" ) { CHECK( item_info_str( compbow, { iteminfo_parts::GUN_DISPERSION } ) == "--\n" "Dispersion: 9.60 MOA\n" ); } SECTION( "needing two hands to fire" ) { REQUIRE( compbow.has_flag( flag_FIRE_TWOHAND ) ); CHECK( item_info_str( compbow, { iteminfo_parts::DESCRIPTION_TWOHANDED } ) == "--\n" "This weapon needs two free hands to fire.\n" ); } } // Functions: // item::gun_info TEST_CASE( "gun_armor_piercing_dispersion_and_other_stats", "[iteminfo][gun][misc]" ) { clear_avatar(); std::vector disp_sight = { iteminfo_parts::GUN_DISPERSION_SIGHT }; // TODO: Test these //std::vector recoil_bipod = { iteminfo_parts::GUN_RECOIL_BIPOD }; //std::vector ammo_remain = { iteminfo_parts::AMMO_REMAINING }; //std::vector ammo_upscost = { iteminfo_parts::AMMO_UPSCOST }; //std::vector gun_casings = { iteminfo_parts::DESCRIPTION_GUN_CASINGS }; item glock( itype_test_glock ); CHECK( item_info_str( glock, disp_sight ) == "--\n" "Sight dispersion: 0.44 MOA\n" ); // TODO: Add a test gun with thest attributes //CHECK( item_info_str( glock, recoil_bipod ).empty() ); //CHECK( item_info_str( glock, ammo_remain ).empty() ); //CHECK( item_info_str( glock, ammo_upscost ).empty() ); //CHECK( item_info_str( glock, gun_casings ).empty() ); } // Battery-only-loaded multimag: gun_info must render without crash, report // the projectile pocket's true capacity, and surface the per-shot draw. TEST_CASE( "multimag_gun_info_with_battery_only_loaded", "[iteminfo][gun][multimag]" ) { clear_avatar(); item gun( itype_test_multimag_gun_integral_ammo ); REQUIRE( gun.uses_firing_requirements() ); item battery( itype_heavy_battery_cell ); battery.ammo_set( itype_battery, 100 ); REQUIRE( gun.put_in( battery, pocket_type::MAGAZINE_WELL ).success() ); const std::vector capacity_parts = { iteminfo_parts::GUN_CAPACITY }; const std::string capacity = item_info_str( gun, capacity_parts ); CAPTURE( capacity ); CHECK( capacity.find( "Capacity" ) != std::string::npos ); CHECK( capacity.find( ">1 round of " ) != std::string::npos ); CHECK( capacity.find( ">0 round" ) == std::string::npos ); const std::vector per_shot_parts = { iteminfo_parts::AMMO_TO_FIRE }; const std::string per_shot = item_info_str( gun, per_shot_parts ); CAPTURE( per_shot ); CHECK( per_shot.find( "Per-shot consumption" ) != std::string::npos ); } // Related JSON fields: // "sight_dispersion" // "aim_speed" // "handling_modifier" // "damage_modifier" // - "amount" // "flags" // "mod_targets" // "location" // // Functions: // item::gunmod_info TEST_CASE( "gunmod_info", "[iteminfo][gunmod]" ) { clear_avatar(); std::vector reach = { iteminfo_parts::DESCRIPTION_GUNMOD_REACH }; std::vector no_sights = { iteminfo_parts::DESCRIPTION_GUNMOD_DISABLESSIGHTS }; std::vector consumable = { iteminfo_parts::DESCRIPTION_GUNMOD_CONSUMABLE }; std::vector disp_sight = { iteminfo_parts::GUNMOD_DISPERSION_SIGHT }; std::vector field_of_view = { iteminfo_parts::GUNMOD_FIELD_OF_VIEW}; std::vector aim_speed_modifier = { iteminfo_parts::GUNMOD_AIM_SPEED_MODIFIER }; std::vector damage = { iteminfo_parts::GUNMOD_DAMAGE }; std::vector handling = { iteminfo_parts::GUNMOD_HANDLING }; std::vector usedon = { iteminfo_parts::GUNMOD_USEDON }; std::vector location = { iteminfo_parts::GUNMOD_LOCATION }; // TODO for gunmod_info: //std::vector gunmod = { iteminfo_parts::DESCRIPTION_GUNMOD }; //std::vector armorpierce = { iteminfo_parts::GUNMOD_ARMORPIERCE }; //std::vector ammo = { iteminfo_parts::GUNMOD_AMMO }; //std::vector reload = { iteminfo_parts::GUNMOD_RELOAD }; //std::vector strength = { iteminfo_parts::GUNMOD_STRENGTH }; //std::vector add_mod = { iteminfo_parts::GUNMOD_ADD_MOD }; //std::vector blacklist_mod = { iteminfo_parts::GUNMOD_BLACKLIST_MOD }; item supp( itype_test_crafted_suppressor ); REQUIRE( supp.is_gunmod() ); /* FIXME: This only applies if is_gun() ?? CHECK( item_info_str( supp, { iteminfo_parts::DESCRIPTION_GUNMOD } ) == "--\n" "* This mod must be attached to a gun, it can not be fired separately.\n" ); */ SECTION( "gunmod flags" ) { REQUIRE( supp.has_flag( flag_REACH_ATTACK ) ); CHECK( item_info_str( supp, reach ) == "--\n" "When attached to a gun, allows making" " reach melee attacks with it.\n" ); REQUIRE( supp.has_flag( flag_DISABLE_SIGHTS ) ); CHECK( item_info_str( supp, no_sights ) == "--\n" "This mod obscures sights of the base weapon.\n" ); REQUIRE( supp.has_flag( flag_CONSUMABLE ) ); CHECK( item_info_str( supp, consumable ) == "--\n" "This mod might suffer wear when firing the base weapon.\n" ); } CHECK( item_info_str( supp, disp_sight ) == "--\n" "Sight dispersion: 0.11 MOA\n" ); CHECK( item_info_str( supp, field_of_view ) == "--\n" "Field of view: 300\n" ); CHECK( item_info_str( supp, aim_speed_modifier ) == "--\n" "Aim speed modifier: 0\n" ); CHECK( item_info_str( supp, damage ) == "--\n" "Damage: -5\n" ); CHECK( item_info_str( supp, handling ) == "--\n" "Handling modifier: +1\n" ); // FIXME: This is a different order than given in JSON, and not alphabetical either; // could be made more predictable by making enumerate_as_string do sorting /* CHECK( item_info_str( supp, usedon ) == "--\n" "Used on: rifle and pistol\n" ); */ CHECK( item_info_str( supp, location ) == "--\n" "Location: muzzle\n" ); } // Functions: // item::ammo_info TEST_CASE( "ammunition", "[iteminfo][ammo]" ) { clear_avatar(); std::vector ammo = { iteminfo_parts::AMMO_REMAINING_OR_TYPES, iteminfo_parts::AMMO_DAMAGE_VALUE, iteminfo_parts::AMMO_DAMAGE_PELLETS, iteminfo_parts::AMMO_DAMAGE_TOTAL, iteminfo_parts::AMMO_DAMAGE_PROPORTIONAL, iteminfo_parts::AMMO_DAMAGE_AP, iteminfo_parts::AMMO_DAMAGE_RANGE, iteminfo_parts::AMMO_DAMAGE_DISPERSION, iteminfo_parts::AMMO_DAMAGE_RECOIL, iteminfo_parts::AMMO_DAMAGE_CRIT_MULTIPLIER }; SECTION( "simple item with ammo damage" ) { item rock( itype_test_rock ); CHECK( item_info_str( rock, ammo ) == "--\n" "Ammunition type: rocks\n" "Ranged damage: 7\n" "Armor-pierce: 0\n" "Range: 10 Dispersion: 0.14 MOA\n" "Recoil: 0.00 MOA Critical multiplier: 2\n" ); } SECTION( "batteries" ) { item batt_dispose( itype_test_battery_disposable ); // FIXME: is_battery is only true if type = "BATTERY" // no items in the game have this property anymore //REQUIRE( batt_dispose.is_battery() ); REQUIRE( batt_dispose.ammo_data() ); REQUIRE( batt_dispose.ammo_data()->nname( 1 ) == "battery" ); // No ammo info should be displayed CHECK( item_info_str( batt_dispose, ammo ).empty() ); } } // Functions: // item::food_info TEST_CASE( "nutrients_in_food", "[iteminfo][food]" ) { clear_avatar(); item test_item( itype_test_nutrient_info_item ); SECTION( "fixed nutrient values in regular item" ) { CHECK( item_info_str( test_item, { iteminfo_parts::FOOD_NUTRITION } ) == "--\n" "Calories (kcal): 100" ); CHECK( item_info_str( test_item, { iteminfo_parts::FOOD_VITAMINS } ) == "--\n" "Vitamins (RDA): 1 g Calcium (100%)\n" ); } SECTION( "nutrient ranges for recipe exemplars", "[iteminfo]" ) { test_item.set_var( "recipe_exemplar", "test_nutrient_info_item" ); CHECK( item_info_str( test_item, { iteminfo_parts::FOOD_NUTRITION } ) == "--\n" "Nutrition will vary with chosen ingredients.\n" "Calories (kcal):" " 100-200" ); CHECK( item_info_str( test_item, { iteminfo_parts::FOOD_VITAMINS } ) == "--\n" "Nutrition will vary with chosen ingredients.\n" "Vitamins (RDA): 1-2 g Calcium (100-200%)\n" ); } } // Related JSON fields: // "spoils_in" // // Functions: // item::food_info TEST_CASE( "food_freshness_and_lifetime", "[iteminfo][food]" ) { clear_avatar(); Character &player_character = get_player_character(); // Ensure test character has no skill estimating spoilage player_character.empty_skills(); REQUIRE_FALSE( player_character.can_estimate_rot() ); item nuts( itype_test_pine_nuts ); REQUIRE( nuts.goes_bad() ); // TODO: // - flags FREEZERBURN, MUSHY, NO_PARASITES // - traits: SAPROVORE, bio_digestion // - with can_estimate_rot() == true SECTION( "food is fresh" ) { REQUIRE( nuts.is_fresh() ); CHECK( item_info_str( nuts, { iteminfo_parts::FOOD_ROT } ) == "--\n" "* This item is perishable, and at room temperature has" " an estimated nominal shelf life of 6 weeks.\n" "* This food looks as fresh as it can be.\n" ); } SECTION( "food is old" ) { nuts.mod_rot( nuts.type->comestible->spoils ); REQUIRE( nuts.is_going_bad() ); CHECK( item_info_str( nuts, { iteminfo_parts::FOOD_ROT } ) == "--\n" "* This item is perishable, and at room temperature has" " an estimated nominal shelf life of 6 weeks.\n" "* This food looks old. It's on the brink of becoming inedible.\n" ); } } // Related JSON fields: // "fun" // "charges" // // Functions: // item::food_info TEST_CASE( "basic_food_info", "[iteminfo][food]" ) { clear_avatar(); std::vector joy = { iteminfo_parts::FOOD_JOY }; std::vector portions = { iteminfo_parts::FOOD_PORTIONS }; std::vector consume_time = { iteminfo_parts::FOOD_CONSUME_TIME }; // TODO: Test these: //std::vector smell = { iteminfo_parts::FOOD_SMELL }; //std::vector vit_effects = { iteminfo_parts::FOOD_VIT_EFFECTS }; item apple( itype_test_apple ); item nuts( itype_test_pine_nuts ); item wine( itype_test_wine ); REQUIRE( apple.is_food() ); REQUIRE( nuts.is_food() ); REQUIRE( wine.is_food() ); CHECK( item_info_str( apple, joy ) == "--\nEnjoyability: 10\n" ); CHECK( item_info_str( apple, portions ) == "--\nPortions: 1\n" ); CHECK( item_info_str( apple, consume_time ) == "--\nConsume time: 50 seconds\n" ); CHECK( item_info_str( nuts, joy ) == "--\nEnjoyability: 2\n" ); CHECK( item_info_str( nuts, portions ) == "--\nPortions: 4\n" ); CHECK( item_info_str( nuts, consume_time ) == "--\nConsume time: 12 seconds\n" ); CHECK( item_info_str( wine, joy ) == "--\nEnjoyability: -5\n" ); CHECK( item_info_str( wine, portions ) == "--\nPortions: 7\n" ); CHECK( item_info_str( wine, consume_time ) == "--\nConsume time: 2 seconds\n" ); } // Related JSON fields: // "material" (determines allergen) // // Functions: // item::food_info TEST_CASE( "food_character_is_allergic_to", "[iteminfo][food][allergy]" ) { clear_avatar(); Character &player_character = get_player_character(); std::vector allergen = { iteminfo_parts::FOOD_ALLERGEN }; GIVEN( "character allergic to fruit" ) { player_character.toggle_trait( trait_ANTIFRUIT ); REQUIRE( player_character.has_trait( trait_ANTIFRUIT ) ); THEN( "fruit indicates an allergic reaction" ) { item apple( itype_test_apple ); REQUIRE( apple.has_flag( flag_ALLERGEN_FRUIT ) ); CHECK( item_info_str( apple, allergen ) == "--\n" "* This food will cause an allergic reaction.\n" ); } THEN( "nuts do not indicate an allergic reaction" ) { item nuts( itype_test_pine_nuts ); REQUIRE_FALSE( nuts.has_flag( flag_ALLERGEN_FRUIT ) ); CHECK( item_info_str( nuts, allergen ).empty() ); } } } // Related JSON fields: // "flags" // // Functions: // item::food_info TEST_CASE( "food_with_hidden_poison_or_hallucinogen", "[iteminfo][food][poison][hallu]" ) { clear_avatar(); // Test food with hidden effects item almond( itype_test_bitter_almond ); item nutmeg( itype_test_hallu_nutmeg ); // Ensure they are food REQUIRE( almond.is_food() ); REQUIRE( nutmeg.is_food() ); // Ensure they have the expected flags REQUIRE( almond.has_flag( flag_HIDDEN_POISON ) ); REQUIRE( nutmeg.has_flag( flag_HIDDEN_HALLU ) ); // Parts flags for display std::vector poison = { iteminfo_parts::FOOD_POISON }; std::vector hallu = { iteminfo_parts::FOOD_HALLUCINOGENIC }; Character &player_character = get_player_character(); // Seeing hidden poison or hallucinogen depends on character survival skill // At low level, no info is shown GIVEN( "survival 2" ) { player_character.set_skill_level( skill_survival, 2 ); REQUIRE( static_cast( player_character.get_skill_level( skill_survival ) ) == 2 ); THEN( "cannot see hidden poison or hallucinogen" ) { CHECK( item_info_str( almond, poison ).empty() ); CHECK( item_info_str( nutmeg, hallu ).empty() ); } } // Hidden poison is visible at survival level 3 GIVEN( "survival 3" ) { player_character.set_skill_level( skill_survival, 3 ); REQUIRE( static_cast( player_character.get_skill_level( skill_survival ) ) == 3 ); THEN( "can see hidden poison" ) { CHECK( item_info_str( almond, poison ) == "--\n" "* On closer inspection, this appears to be" " poisonous.\n" ); } THEN( "cannot see hidden hallucinogen" ) { CHECK( item_info_str( nutmeg, hallu ).empty() ); } } // Hidden hallucinogen is not visible until survival level 5 GIVEN( "survival 4" ) { player_character.set_skill_level( skill_survival, 4 ); REQUIRE( static_cast( player_character.get_skill_level( skill_survival ) ) == 4 ); THEN( "still cannot see hidden hallucinogen" ) { CHECK( item_info_str( nutmeg, hallu ).empty() ); } } GIVEN( "survival 5" ) { player_character.set_skill_level( skill_survival, 5 ); REQUIRE( static_cast( player_character.get_skill_level( skill_survival ) ) == 5 ); THEN( "can see hidden hallucinogen" ) { CHECK( item_info_str( nutmeg, hallu ) == "--\n" "* On closer inspection, this appears to be" " hallucinogenic.\n" ); } } } // Related JSON fields: // "material" (human flesh is "hflesh") // // Functions: // item::food_info TEST_CASE( "food_that_is_made_of_human_flesh", "[iteminfo][food][cannibal]" ) { // TODO: Test food that is_tainted(): "This food is *tainted* and will poison you" clear_avatar(); Character &player_character = get_player_character(); std::vector cannibal = { iteminfo_parts::FOOD_CANNIBALISM }; item thumb( itype_test_thumb ); REQUIRE( thumb.has_vitamin( vitamin_human_flesh_vitamin ) ); GIVEN( "character is not a cannibal" ) { REQUIRE_FALSE( player_character.has_trait( trait_CANNIBAL ) ); THEN( "human flesh is indicated as bad" ) { // red highlight CHECK( item_info_str( thumb, cannibal ) == "--\n" "* This food contains human flesh.\n" ); } } GIVEN( "character is a cannibal" ) { player_character.toggle_trait( trait_CANNIBAL ); REQUIRE( player_character.has_trait( trait_CANNIBAL ) ); THEN( "human flesh is indicated as good" ) { // green highlight CHECK( item_info_str( thumb, cannibal ) == "--\n" "* This food contains human flesh.\n" ); } } } // Related JSON fields: // "flags" // // Functions: // item::final_info // FIXME: Move conducivity out of final_info TEST_CASE( "item_conductivity", "[iteminfo][conductivity]" ) { clear_avatar(); std::vector conductivity = { iteminfo_parts::DESCRIPTION_CONDUCTIVITY }; SECTION( "non-conductive items" ) { item plank( itype_test_2x4 ); REQUIRE_FALSE( plank.conductive() ); CHECK( item_info_str( plank, conductivity ) == "--\n" "* This item does not conduct electricity.\n" ); item axe( itype_test_fire_ax ); REQUIRE_FALSE( axe.conductive() ); CHECK( item_info_str( axe, conductivity ) == "--\n" "* This item does not conduct electricity.\n" ); } SECTION( "conductive items" ) { // Pipe is made of conductive material (steel) item pipe( itype_test_pipe ); REQUIRE( pipe.conductive() ); CHECK( item_info_str( pipe, conductivity ) == "--\n" "* This item conducts electricity.\n" ); // Halligan bar is made of conductive material (steel) item halligan( itype_test_halligan ); REQUIRE( halligan.conductive() ); CHECK( item_info_str( halligan, conductivity ) == "--\n" "* This item conducts electricity.\n" ); // Balloon is made of non-conductive rubber, but has CONDUCTIVE flag item balloon( itype_test_balloon ); REQUIRE( balloon.conductive() ); CHECK( item_info_str( balloon, conductivity ) == "--\n" "* This item effectively conducts" " electricity, as it has no guard.\n" ); } } // Related JSON fields: // "qualities" // // Functions: // item::qualities_info TEST_CASE( "list_of_item_qualities", "[iteminfo][quality]" ) { clear_avatar(); std::vector qualities = { iteminfo_parts::QUALITIES }; SECTION( "Halligan bar" ) { item halligan( itype_test_halligan ); CHECK( item_info_str( halligan, qualities ) == "--\n" "Has qualities:\n" "Level 1 digging quality\n" "Level 2 hammering quality\n" "Level 4 prying quality\n" "Level 1 nail prying quality\n" ); } SECTION( "bottle jack" ) { item jack( itype_test_jack_small ); SECTION( "metric units" ) { override_option opt_kg( "USE_METRIC_WEIGHTS", "kg" ); CHECK( item_info_str( jack, qualities ) == "--\n" "Has qualities:\n" "Level 4 jacking quality, rated at" " 2000 kg\n" ); } SECTION( "imperial units" ) { override_option opt_lbs( "USE_METRIC_WEIGHTS", "lbs" ); CHECK( item_info_str( jack, qualities ) == "--\n" "Has qualities:\n" "Level 4 jacking quality, rated at" " 4409 lbs\n" ); } } SECTION( "sonic screwdriver" ) { item sonic( itype_test_sonic_screwdriver ); CHECK( item_info_str( sonic, qualities ) == "--\n" "Has qualities:\n" "Level 30 lockpicking quality\n" "Level 2 prying quality\n" "Level 2 screw driving quality\n" "Level 1 fine screw driving quality\n" "Level 1 bolt turning quality\n" ); } SECTION( "cordless drill" ) { // Cordless drill has both qualities and charged_qualities item drill( itype_test_cordless_drill ); item battery( itype_medium_battery_cell ); // Without enough charges CHECK( item_info_str( drill, qualities ) == "--\n" "Has qualities:\n" "Level 1 screw driving quality\n" "Needs 5 or more charges for qualities:\n" "Level 3 drilling quality\n" ); // With enough charges int bat_charges = drill.type->charges_to_use(); battery.ammo_set( battery.ammo_default(), bat_charges ); drill.put_in( battery, pocket_type::MAGAZINE_WELL ); REQUIRE( drill.ammo_remaining( ) == bat_charges ); CHECK( item_info_str( drill, qualities ) == "--\n" "Has qualities:\n" "Level 1 screw driving quality\n" "Has enough charges for qualities:\n" "Level 3 drilling quality\n" ); } } // Related JSON fields: // "actions" // // Functions: // item::actions_info TEST_CASE( "list_of_item_actions", "[iteminfo][action]" ) { clear_avatar(); std::vector actions = { iteminfo_parts::ACTIONS }; SECTION( "Halligan bar" ) { item halligan( itype_test_halligan ); CHECK( item_info_str( halligan, actions ) == "--\n" "Actions: Pry crate, window, door or nails, Dig pit here, Dig water channel here, Fill pit / tamp ground, and Upturn earth\n" ); } } // Related JSON fields: // "flags" (USE_UPS, RECHARGE) // // Functions: // item::tool_info TEST_CASE( "tool_info", "[iteminfo][tool]" ) { // TODO: Find a tool using this //std::vector mag_current = { iteminfo_parts::TOOL_MAGAZINE_CURRENT }; clear_avatar(); SECTION( "maximum charges" ) { std::vector capacity = { iteminfo_parts::TOOL_CAPACITY }; item matches( itype_test_matches ); CHECK( item_info_str( matches, capacity ) == "--\n" "Maximum 20 charges of match.\n" ); } SECTION( "tool with charges" ) { std::vector charges = { iteminfo_parts::TOOL_CHARGES }; item matches( itype_test_matches ); matches.ammo_set( itype_match ); REQUIRE( matches.ammo_remaining( ) > 0 ); CHECK( item_info_str( matches, charges ) == "--\n" "Charges: 20\n" ); } SECTION( "candle with feedback on burnout" ) { std::vector burnout = { iteminfo_parts::TOOL_BURNOUT }; item candle( itype_candle ); candle.ammo_set( itype_candle_wax ); REQUIRE( candle.ammo_remaining( ) > 0 ); CHECK( item_info_str( candle, burnout ) == "--\n" "Fuel: It's new, and ready to burn.\n" ); candle.ammo_set( itype_candle_wax, 49 ); CHECK( item_info_str( candle, burnout ) == "--\n" "Fuel: More than half has burned away.\n" ); } SECTION( "UPS charged tool" ) { std::vector recharge_ups = { iteminfo_parts::DESCRIPTION_RECHARGE_UPSMODDED }; item smartphone( itype_test_smart_phone ); REQUIRE( smartphone.has_flag( flag_USE_UPS ) ); CHECK( item_info_str( smartphone, recharge_ups ) == "--\n" "* This tool has been modified to use a" " universal power supply and is" " not compatible with" " standard batteries.\n" ); } SECTION( "compatible magazines" ) { std::vector magazine_compat = { iteminfo_parts::TOOL_MAGAZINE_COMPATIBLE }; // Rag has no magazine capacity item rag( itype_test_rag ); REQUIRE_FALSE( rag.magazine_integral() ); REQUIRE( rag.magazine_compatible().empty() ); CHECK( item_info_str( rag, magazine_compat ).empty() ); // Acetylene torch is a tool with compatible magazines // Other tools with "Compatible magazine": electric hair trimmer, circular saw item oxy_torch( itype_oxy_torch ); REQUIRE_FALSE( oxy_torch.magazine_integral() ); REQUIRE_FALSE( oxy_torch.magazine_compatible().empty() ); CHECK( item_info_str( oxy_torch, magazine_compat ) == "--\n" "Compatible magazines:\n" "Types: small welding tank, tiny welding tank, and welding tank\n" ); } } // Related JSON fields: // "type": "bionic" // "capacity" // "occupied_bodyparts" // "fuel_capacity" // "env_protec" // // Functions: // item::bionic_info TEST_CASE( "bionic_info", "[iteminfo][bionic]" ) { // TODO: Add a test for this //std::vector slots = { iteminfo_parts::DESCRIPTION_CBM_SLOTS }; // FIXME: bionic_info has NO OTHER iteminfo_parts filters! // TODO: Add tests for: // - bash protection // - cut protection // - balliastic protection // - stat bonus // - weight capacity modifier // - weight capacity bonus clear_avatar(); item burner( itype_bio_ethanol ); item power( itype_bio_power_storage ); item nostril( itype_bio_nostril ); item test_purifier( itype_test_bio_purifier ); REQUIRE( burner.is_bionic() ); REQUIRE( power.is_bionic() ); REQUIRE( nostril.is_bionic() ); REQUIRE( test_purifier.is_bionic() ); CHECK( item_info_str( burner, {} ) == "--\n" "* This bionic can produce power from the following fuel:" " Alcohol\n" ); std::string power_info = item_info_str( power, {} ); { CAPTURE( power_info ); // NOTE: No trailing newline // Multiple alternatives due to potential localizations CHECK( ( power_info == "--\n" "Power Capacity:" " 100000000 mJ" || power_info == "--\n" "Power Capacity:" " 100,000,000 mJ" ) ); } // NOTE: Funky trailing space CHECK( item_info_str( nostril, {} ) == "--\n" "Encumbrance: " "mouth 10" ); CHECK( item_info_str( test_purifier, {} ) == "--\n" "Environmental Protection: " "mouth 15" ); } // Functions: // item::repair_info TEST_CASE( "repairable_and_with_what_tools", "[iteminfo][repair]" ) { clear_avatar(); item test_repair_item( itype_test_item_info_repair_tool ); item hazmat( itype_test_hazmat_suit ); item rock( itype_test_rock ); std::vector repaired = { iteminfo_parts::DESCRIPTION_REPAIREDWITH }; CHECK( item_info_str( test_repair_item, repaired ) == "--\n" "Repair using TEST item info repair tool.\n" "With TEST repair item.\n" ); // FIXME: Use an item that can only be repaired by test tools CHECK( item_info_str( hazmat, repaired ) == "--\n" "Repair using integrated soldering iron, integrated welder, gunsmith repair kit, firearm repair kit, soldering iron, portable soldering iron, or TEST soldering iron.\n" "With plastic chunk.\n" ); CHECK( item_info_str( rock, repaired ) == "--\n" "* This item is not repairable.\n" ); } // Functions: // item::disassembly_info TEST_CASE( "disassembly_time_and_yield", "[iteminfo][disassembly]" ) { clear_avatar(); std::vector disassemble = { iteminfo_parts::DESCRIPTION_COMPONENTS_DISASSEMBLE }; item iron( itype_test_soldering_iron ); item metal( itype_test_sheet_metal ); CHECK( item_info_str( iron, disassemble ) == "--\n" "Disassembly takes about 20 minutes, requires 1 tool" " with cutting of 2 or more and 1 tool with" " screw driving of 1 or more and might" // i do not understand why clang yells two spaces are needed for `and 59in. copper` // but i cannot figure how to fix it properly //NOLINTNEXTLINE(cata-text-style) " yield: 2 electronic scraps, 1 copper, 1 scrap metal, and 59in. copper" " wires.\n" ); CHECK( item_info_str( metal, disassemble ) == "--\n" "Disassembly takes about 2 minutes, requires 1 tool" " with metal sawing of 2 or more and might" " yield: 24 TEST small metal sheets.\n" ); } // Related JSON fields: // "flags" // // The DESCRIPTION_FLAGS part shows descriptions of item "flags" from data/json/flags.json. // // Functions: // item::final_info // FIXME: Factor out of final_info TEST_CASE( "item_description_flags", "[iteminfo][flags]" ) { clear_avatar(); std::vector flags = { iteminfo_parts::DESCRIPTION_FLAGS }; item halligan( itype_test_halligan ); item hazmat( itype_test_hazmat_suit ); // Halligan bar has a couple flags REQUIRE( halligan.has_flag( flag_BELT_CLIP ) ); REQUIRE( halligan.has_flag( flag_DURABLE_MELEE ) ); CHECK( item_info_str( halligan, flags ) == "--\n" "* This item can be clipped onto a belt loop of the appropriate size.\n" "* As a weapon, this item is well-made and will" " withstand the punishment of combat.\n" ); // Hazmat suit has a lot of flags REQUIRE( hazmat.has_flag( flag_ELECTRIC_IMMUNE ) ); REQUIRE( hazmat.has_flag( flag_GAS_PROOF ) ); REQUIRE( hazmat.has_flag( flag_OUTER ) ); REQUIRE( hazmat.has_flag( flag_RAD_PROOF ) ); REQUIRE( hazmat.has_flag( flag_RAINPROOF ) ); REQUIRE( hazmat.has_flag( flag_WATERPROOF ) ); CHECK( item_info_str( hazmat, flags ) == "--\n" "* This gear completely protects you from" " electric discharges.\n" "* This gear completely protects you from" " any gas.\n" "* This gear is generally worn over clothing.\n" "* This clothing completely protects you from" " radiation.\n" "* This clothing is designed to keep you dry in the rain.\n" "* This clothing won't let water through." " Even if you jump into a river.\n" ); } // Functions: // item::final_info TEST_CASE( "show_available_recipes_with_item_as_an_ingredient", "[iteminfo][recipes]" ) { clear_avatar(); avatar &player_character = get_avatar(); const recipe *purtab = &recipe_pur_tablets.obj(); recipe_subset &known_recipes = const_cast ( player_character.get_learned_recipes() ); known_recipes.clear(); // FIXME: Factor out of final_info std::vector crafting = { iteminfo_parts::DESCRIPTION_APPLICABLE_RECIPES }; GIVEN( "character carries the only component of a known recipe" ) { player_character.worn.wear_item( player_character, item( itype_backpack ), false, false ); player_character.learn_recipe( &recipe_test_nutrient_info_item.obj() ); item_location component = player_character.i_add( item( itype_test_nutrient_info_component1 ) ); player_character.invalidate_crafting_inventory(); // can_craft_recipe answers are cached per turn restore_on_out_of_scope restore_turn( calendar::turn ); calendar::turn += 7_days; THEN( "recipe listed as craftable" ) { CHECK( item_info_str( *component, crafting ) == "--\nYou could use it to craft: nutrient test item\n" ); } } GIVEN( "character has a potassium iodide tablet and no skill" ) { player_character.worn.wear_item( player_character, item( itype_backpack ), false, false ); item_location iodine = player_character.i_add( item( itype_iodine ) ); player_character.empty_skills(); REQUIRE( !player_character.knows_recipe( purtab ) ); THEN( "nothing is craftable from it" ) { CHECK( item_info_str( *iodine, crafting ) == "--\nYou know of nothing you could craft with it.\n" ); } WHEN( "they acquire the needed skills" ) { player_character.set_skill_level( purtab->skill_used, purtab->difficulty ); REQUIRE( static_cast( player_character.get_skill_level( purtab->skill_used ) ) == purtab->difficulty ); THEN( "still nothing is craftable from it" ) { CHECK( item_info_str( *iodine, crafting ) == "--\nYou know of nothing you could craft with it.\n" ); } WHEN( "they have no book, but have the recipe memorized" ) { player_character.learn_recipe( purtab ); REQUIRE( player_character.knows_recipe( purtab ) ); THEN( "they can use potassium iodide tablets to craft it" ) { CHECK( item_info_str( *iodine, crafting ) == "--\n" "You could use it to craft: " "water purification tablet\n" ); } } WHEN( "they have the recipe in a book, but not memorized" ) { item_location textbook = player_character.i_add( item( itype_textbook_chemistry ) ); player_character.identify( *textbook ); REQUIRE( player_character.has_identified( itype_textbook_chemistry ) ); player_character.invalidate_crafting_inventory(); THEN( "they can use potassium iodide tablets to craft it" ) { CHECK( item_info_str( *iodine, crafting ) == "--\n" "You could use it to craft: " "water purification tablet\n" ); } } } } } // Pocket tests below relate to te JSON "pocket_data" fields: // // - "max_contains_volume" // - "max_contains_weight" // - "max_item_length" // - "max_item_volume" // - "watertight" // - "moves" // - "rigid" // Functions: // item_contents::info // item_pocket::general_info TEST_CASE( "pocket_info_for_a_simple_container", "[iteminfo][pocket][container]" ) { clear_avatar(); item test_waterskin( itype_test_waterskin ); std::vector pockets = { iteminfo_parts::DESCRIPTION_POCKETS }; override_option opt_vol( "VOLUME_UNITS", "l" ); override_option opt_weight( "USE_METRIC_WEIGHTS", "kg" ); override_option opt_dist( "DISTANCE_UNITS", "metric" ); // Simple containers with only one pocket show a "Total capacity" section // with all the pocket's restrictions and other attributes CHECK( item_info_str( test_waterskin, pockets ) == "--\n" "Total capacity:\n" "Volume: 1.50 L Weight: 3.00 kg\n" "Item length: 0 cm to 12 cm\n" "Maximum item volume: 0.015 L\n" "Base moves to remove item: 220\n" "This pocket can contain a liquid.\n" ); } // Functions: // item_contents::info // item_pocket::general_info TEST_CASE( "pocket_info_units_-_imperial_or_metric", "[iteminfo][pocket][units]" ) { clear_avatar(); item test_jug( itype_test_jug_plastic ); std::vector pockets = { iteminfo_parts::DESCRIPTION_POCKETS }; GIVEN( "metric units" ) { override_option opt_vol( "VOLUME_UNITS", "l" ); override_option opt_weight( "USE_METRIC_WEIGHTS", "kg" ); override_option opt_dist( "DISTANCE_UNITS", "metric" ); THEN( "pocket capacity is shown in liters, kilograms, and millimeters" ) { CHECK( item_info_str( test_jug, pockets ) == "--\n" "Total capacity:\n" "Volume: 3.75 L Weight: 5.00 kg\n" "Item length: 0 mm to 226 mm\n" "Maximum item volume: 0.015 L\n" "Base moves to remove item: 100\n" "This pocket is rigid.\n" "This pocket can contain a liquid.\n" ); } } GIVEN( "imperial units" ) { override_option opt_vol( "VOLUME_UNITS", "qt" ); override_option opt_weight( "USE_METRIC_WEIGHTS", "lbs" ); override_option opt_dist( "DISTANCE_UNITS", "imperial" ); THEN( "pocket capacity is shown in quarts, pounds, and inches" ) { CHECK( item_info_str( test_jug, pockets ) == "--\n" "Total capacity:\n" "Volume: 3.97 qt Weight: 11.02 lbs\n" "Item length: 0 in. to 8 in.\n" "Maximum item volume: 0.016 qt\n" "Base moves to remove item: 100\n" "This pocket is rigid.\n" "This pocket can contain a liquid.\n" ); } } } // Functions: // item_contents::info // item_pocket::general_info TEST_CASE( "pocket_info_for_a_multi-pocket_item", "[iteminfo][pocket][multiple]" ) { clear_avatar(); item test_belt( itype_test_tool_belt_pocket_mix ); std::vector pockets = { iteminfo_parts::DESCRIPTION_POCKETS }; override_option opt_vol( "VOLUME_UNITS", "l" ); override_option opt_weight( "USE_METRIC_WEIGHTS", "kg" ); override_option opt_dist( "DISTANCE_UNITS", "metric" ); // When multiple pockets have the same attributes, they are combined headings like: // // Pockets 1, 2, and 3 // Volume: ... Weight: ... // // The "Total capacity" indicates the sum Volume/Weight capacity of all pockets. CHECK( item_info_str( test_belt, pockets ) == "--\n" "Total capacity:\n" "Volume: 7.00 L Weight: 9.00 kg\n" "--\n" "Pocket 1\n" "Volume: 1.00 L Weight: 1.50 kg\n" "Item length: 0 cm to 40 cm\n" "Base moves to remove item: 100\n" "--\n" "Pockets 2 and 3\n" "Volume: 1.50 L Weight: 1.50 kg\n" "Item length: 0 cm to 70 cm\n" "Minimum item volume: 0.050 L\n" "Base moves to remove item: 50\n" "This is a holster, it only holds one item at a time.\n" "Restrictions:\n" "* Item must clip onto a belt loop\n" "* or Item must fit in a sheath\n" "--\n" "Pockets 4, 5, and 6\n" "Volume: 1.00 L Weight: 1.50 kg\n" "Item length: 0 cm to 70 cm\n" "Minimum item volume: 0.050 L\n" "Base moves to remove item: 50\n" "This is a holster, it only holds one item at a time.\n" "Restrictions:\n" "* Item must clip onto a belt loop\n" "* or Item must fit in a sheath\n" ); } TEST_CASE( "ammo_restriction_info", "[iteminfo][ammo_restriction]" ) { SECTION( "container pocket with ammo restriction" ) { // For non-MAGAZINE pockets with ammo_restriction, pocket info shows what it can hold std::vector pockets = { iteminfo_parts::DESCRIPTION_POCKETS }; // Quiver is a CONTAINER with ammo_restriction "arrow" or "bolt" item quiver( itype_test_quiver ); // Not a magazine, but it should have ammo_types REQUIRE_FALSE( quiver.is_magazine() ); REQUIRE_FALSE( quiver.ammo_types().empty() ); CHECK( item_info_str( quiver, pockets ) == "--\n" "Total capacity:\n" "Holds: 20 rounds of arrows\n" "Holds: 20 rounds of bolts\n" "Base moves to remove item: 20\n" ); } SECTION( "magazine pocket with ammo restriction" ) { // For MAGAZINE pockets, ammo_restriction is shown in magazine info std::vector mag_cap = { iteminfo_parts::MAGAZINE_CAPACITY }; // Matches are TOOL with MAGAZINE pocket, and ammo_restriction "match" item matches( itype_test_matches ); REQUIRE( matches.is_magazine() ); REQUIRE_FALSE( matches.ammo_types().empty() ); // But they have the NO_RELOAD flag, so their capacity should not be displayed REQUIRE( matches.has_flag( flag_NO_RELOAD ) ); CHECK( item_info_str( matches, mag_cap ).empty() ); // Compound bow is a GUN with integral MAGAZINE pocket, ammo_restriction "arrow" item compbow( itype_test_compbow ); REQUIRE( compbow.is_magazine() ); REQUIRE_FALSE( compbow.ammo_types().empty() ); // It can be reloaded, so its magazine capacity should be displayed REQUIRE_FALSE( compbow.has_flag( flag_NO_RELOAD ) ); CHECK( item_info_str( compbow, mag_cap ) == "--\n" "Capacity: 1 round of arrows\n" ); } } // Functions: // vol_to_info from item.cpp TEST_CASE( "vol_to_info", "[iteminfo][volume]" ) { clear_avatar(); override_option opt_vol( "VOLUME_UNITS", "l" ); iteminfo vol = vol_to_info( "BASE", "Volume", 3_liter ); // strings CHECK( vol.sType == "BASE" ); CHECK( vol.sName == "Volume" ); CHECK( vol.sFmt == " L" ); CHECK( vol.sValue == "3.00" ); // doubles CHECK( vol.dValue == 3.0 ); // booleans CHECK( vol.bDrawName == true ); CHECK( vol.bLowerIsBetter == true ); CHECK( vol.bNewLine == false ); CHECK( vol.bShowPlus == false ); CHECK( vol.is_int == false ); CHECK( vol.three_decimal == false ); } // Functions: // weight_to_info from item.cpp TEST_CASE( "weight_to_info", "[iteminfo][weight]" ) { clear_avatar(); override_option opt( "USE_METRIC_WEIGHTS", "kg" ); iteminfo wt = weight_to_info( "BASE", "Weight", 3_kilogram ); // strings CHECK( wt.sType == "BASE" ); CHECK( wt.sName == "Weight" ); CHECK( wt.sFmt == " kg" ); CHECK( wt.sValue == "3.00" ); // doubles CHECK( wt.dValue == 3.0 ); // booleans CHECK( wt.bDrawName == true ); CHECK( wt.bLowerIsBetter == true ); CHECK( wt.bNewLine == false ); CHECK( wt.bShowPlus == false ); CHECK( wt.is_int == false ); CHECK( wt.three_decimal == false ); } // Functions: // item::final_info TEST_CASE( "final_info", "[iteminfo][final]" ) { clear_avatar(); Character &player_character = get_player_character(); SECTION( "material allergy" ) { item socks( itype_test_socks ); REQUIRE( socks.made_of( material_wool ) ); WHEN( "avatar has a wool allergy" ) { player_character.toggle_trait( trait_WOOLALLERGY ); REQUIRE( player_character.has_trait( trait_WOOLALLERGY ) ); CHECK( item_info_str( socks, { iteminfo_parts::DESCRIPTION_ALLERGEN } ) == "--\n" "Can't wear that, it's made of wool!\n" ); } } SECTION( "fermentation and brewing" ) { std::vector brew_duration = { iteminfo_parts::DESCRIPTION_BREWABLE_DURATION }; std::vector brew_products = { iteminfo_parts::DESCRIPTION_BREWABLE_PRODUCTS }; item wine_must( itype_test_brew_wine ); REQUIRE( wine_must.brewing_time() == 12_hours ); // TODO: DESCRIPTION_ACTIVATABLE_TRANSFORMATION (sourdough?) CHECK( item_info_str( wine_must, brew_duration ) == "--\n" "* Once set in a vat, this will ferment in around 12 hours.\n" ); CHECK( item_info_str( wine_must, brew_products ) == "--\n" "* Fermenting this will produce test tennis ball wine.\n" "* Fermenting this will produce yeast.\n" ); } SECTION( "radioactivity" ) { std::vector radioactive = { iteminfo_parts::DESCRIPTION_RADIOACTIVITY_ALWAYS }; item carafe( itype_test_nuclear_carafe ); REQUIRE( carafe.has_flag( flag_RADIOACTIVE ) ); REQUIRE( carafe.has_flag( flag_LEAK_ALWAYS ) ); CHECK( item_info_str( carafe, radioactive ) == "--\n" "* This object is surrounded" " by a sickly green glow.\n" ); } } // Each item::xxx_info function has a `debug` argument, though only a few use it. The main // item::info function sets it based on whether the global game variable `debug_mode` is true. // // The item::debug_info function prints debug info for the item if iteminfo_parts::BASE_DEBUG is // given, and the `debug` argument passed to the function is true. This function used to be part of // item::basic_info, and as of this writing is now invoked just after that function. // // Functions: // item::debug_info // FIXME: This fails when run with other tests. May not be worth having a test on... TEST_CASE( "item_debug_info", "[iteminfo][debug][!mayfail][.]" ) { clear_avatar(); SECTION( "debug info displayed when debug_mode is true" ) { // Lightly aged pine nuts item nuts( itype_test_pine_nuts ); calendar::turn += 8_hours; // Quick-check a couple expected values for debug info REQUIRE( nuts.age() == 8_hours ); REQUIRE( nuts.charges == 4 ); // Debug info may be enabled with an iteminfo_parts flag std::vector debug_part = { iteminfo_parts::BASE_DEBUG }; const iteminfo_query debug_query( debug_part ); // Invoke item::debug_info directly, so we can pass debug = true // (instead of relying on item::info to use the debug_mode global setting) std::vector info_vec; nuts.debug_info( info_vec, &debug_query, 1, true ); // FIXME: "last rot" and "last temp" are expected to be 0, but may have values (ex. 43200) // Need to figure out what processing to do before this check to make them predictable CHECK( format_item_info( info_vec, {} ) == "age (hours): 8\n" "charges: 4\n" "damage: 0\n" "active: 1\n" "burn: 0\n" "tags: \n" // NOLINT(cata-text-style) "age (turns): 28800\n" "rot (turns): 0\n" " max rot (turns): 3888000\n" "last rot: 0\n" "last temp: 0\n" "Temp: 0\n" "Spec ener: -10\n" "Spec heat lq: 2200\n" "Spec heat sld: 2200\n" "latent heat: 20\n" "Freeze point: 32\n" ); } } TEST_CASE( "Armor_values_preserved_after_copy-from", "[iteminfo][armor][protection]" ) { // Normal item definition, no copy item armor( itype_test_armor_chitin ); // Copied item definition, no explicit "armor" field item armor_copy( itype_test_armor_chitin_copy ); // Copied item definition, explicit "armor" field defined item armor_copy_w_armor( itype_test_armor_chitin_copy_w_armor ); // Copied item definition, no explicit "armor" field, using "proportional" item armor_copy_prop( itype_test_armor_chitin_copy_prop ); // Copied item definition, explicit "armor" field defined, using "proportional" item armor_copy_w_armor_prop( itype_test_armor_chitin_copy_w_armor_prop ); // Copied item definition, no explicit "armor" field, using "relative" item armor_copy_rel( itype_test_armor_chitin_copy_rel ); // Copied item definition, explicit "armor" field defined, using "relative" item armor_copy_w_armor_rel( itype_test_armor_chitin_copy_w_armor_rel ); std::vector infoparts = { iteminfo_parts::ARMOR_PROTECTION }; std::string a_str = item_info_str( armor, infoparts ); std::string a_copy_str = item_info_str( armor_copy, infoparts ); std::string a_copy_w_armor_str = item_info_str( armor_copy_w_armor, infoparts ); std::string a_copy_prop_str = item_info_str( armor_copy_prop, infoparts ); std::string a_copy_w_armor_prop_str = item_info_str( armor_copy_w_armor_prop, infoparts ); std::string a_copy_rel_str = item_info_str( armor_copy_rel, infoparts ); std::string a_copy_w_armor_rel_str = item_info_str( armor_copy_w_armor_rel, infoparts ); const auto copy_from_test = []( const std::string & info ) { const std::string header_string = "--\n" "Protection for: The legs. The torso.\n" "Coverage: Outer.\n" " Default: 90\n" "Protection:\n"; const std::string bash_string = " Bash: 10.00\n"; const std::string cut_string = " Cut: 12.00\n"; const std::string ballistic_string = " Ballistic: 5.60\n"; const std::string pierce_string = " Pierce: 9.60\n"; const std::string acid_string = " Acid: 3.60\n"; const std::string fire_string = " Fire: 1.50\n"; const std::string env_string = " Environmental: 6\n"; size_t pos = 0; test_string( info, header_string, pos ); test_string( info, bash_string, pos ); test_string( info, cut_string, pos ); test_string( info, ballistic_string, pos ); test_string( info, acid_string, pos ); test_string( info, fire_string, pos ); test_string( info, env_string, pos ); }; copy_from_test( a_str ); copy_from_test( a_copy_str ); copy_from_test( a_copy_w_armor_str ); const auto proportional_test = []( const std::string & info ) { const std::string header_str = "--\n" "Protection for: The legs. The torso.\n" "Coverage: Outer.\n" " Default: 90\n" "Protection:\n"; const std::string bash_str = " Bash: 12.00\n"; const std::string cut_str = " Cut: 14.40\n"; const std::string ballistic_str = " Ballistic: 6.72\n"; const std::string pierce_str = " Pierce: 11.52\n"; const std::string acid_str = " Acid: 4.20\n"; const std::string fire_str = " Fire: 1.75\n"; const std::string env_str = " Environmental: 7\n"; size_t pos = 0; test_string( info, header_str, pos ); test_string( info, bash_str, pos ); test_string( info, cut_str, pos ); test_string( info, ballistic_str, pos ); test_string( info, acid_str, pos ); test_string( info, fire_str, pos ); test_string( info, env_str, pos ); }; proportional_test( a_copy_prop_str ); proportional_test( a_copy_w_armor_prop_str ); const auto relative_test = []( const std::string & info ) { const std::string header_str = "--\n" "Protection for: The legs. The torso.\n" "Coverage: Outer.\n" " Default: 90\n" "Protection:\n"; const std::string bash_str = " Bash: 15.00\n"; const std::string cut_str = " Cut: 18.00\n"; const std::string ballistic_str = " Ballistic: 8.40\n"; const std::string pierce_str = " Pierce: 14.40\n"; const std::string acid_str = " Acid: 4.80\n"; const std::string fire_str = " Fire: 2.00\n"; const std::string env_str = " Environmental: 8\n"; size_t pos = 0; test_string( info, header_str, pos ); test_string( info, bash_str, pos ); test_string( info, cut_str, pos ); test_string( info, ballistic_str, pos ); test_string( info, acid_str, pos ); test_string( info, fire_str, pos ); test_string( info, env_str, pos ); }; relative_test( a_copy_rel_str ); relative_test( a_copy_w_armor_rel_str ); } // Character-aware body part display filtering for armor info. // When similar_bodypart expands item coverage at load time (e.g. arm_l -> alt_arm_l), // the display should only show body parts the viewing character actually has. TEST_CASE( "armor_info_character_aware_body_parts", "[iteminfo][armor][limbs]" ) { // Exact color-tagged fragments with trailing punctuation to avoid partial matches. // "arms" could match inside "alt arms" without the color tags. const std::string arms_frag = "arms."; const std::string alt_arms_frag = "Alt Arms."; const std::string torso_frag = "torso."; auto make_alt_arm_viewer = []() { Character &viewer = get_player_character(); clear_character( viewer, true ); viewer.enchantment_cache->force_add( *enchantment_ENCH_TEST_ALT_ARMS, viewer ); viewer.recalculate_bodyparts(); REQUIRE( viewer.has_part( body_part_test_alt_arm_l ) ); }; SECTION( "default human sees standard limb names" ) { clear_avatar(); item longshirt( itype_test_longshirt ); std::string info = item_info_str( longshirt, { iteminfo_parts::ARMOR_BODYPARTS } ); CHECK( info.find( arms_frag ) != std::string::npos ); CHECK( info.find( alt_arms_frag ) == std::string::npos ); CHECK( info.find( torso_frag ) != std::string::npos ); } SECTION( "alt-arm character sees alt limb names" ) { make_alt_arm_viewer(); item longshirt( itype_test_longshirt ); std::string info = item_info_str( longshirt, { iteminfo_parts::ARMOR_BODYPARTS } ); CHECK( info.find( alt_arms_frag ) != std::string::npos ); CHECK( info.find( arms_frag ) == std::string::npos ); CHECK( info.find( torso_frag ) != std::string::npos ); } SECTION( "coverage section filtered by viewer anatomy" ) { make_alt_arm_viewer(); item longshirt( itype_test_longshirt ); std::string info = item_info_str( longshirt, { iteminfo_parts::ARMOR_COVERAGE } ); CHECK( info.find( alt_arms_frag ) != std::string::npos ); CHECK( info.find( arms_frag ) == std::string::npos ); } SECTION( "warmth section filtered by viewer anatomy" ) { make_alt_arm_viewer(); item longshirt( itype_test_longshirt ); std::string info = item_info_str( longshirt, { iteminfo_parts::ARMOR_WARMTH } ); CHECK( info.find( alt_arms_frag ) != std::string::npos ); CHECK( info.find( arms_frag ) == std::string::npos ); } SECTION( "encumbrance section filtered by viewer anatomy" ) { make_alt_arm_viewer(); item longshirt( itype_test_longshirt ); std::string info = item_info_str( longshirt, { iteminfo_parts::ARMOR_ENCUMBRANCE } ); CHECK( info.find( alt_arms_frag ) != std::string::npos ); CHECK( info.find( arms_frag ) == std::string::npos ); } SECTION( "breathability section filtered by viewer anatomy" ) { make_alt_arm_viewer(); item longshirt( itype_test_longshirt ); std::string info = item_info_str( longshirt, { iteminfo_parts::ARMOR_BREATHABILITY } ); CHECK( info.find( alt_arms_frag ) != std::string::npos ); CHECK( info.find( arms_frag ) == std::string::npos ); } SECTION( "fallback annotation for anatomy-incompatible items" ) { clear_avatar(); item tail_item( itype_test_tail_encumber ); std::string info = item_info_str( tail_item, { iteminfo_parts::ARMOR_BODYPARTS } ); CHECK( info.find( "not for your anatomy" ) != std::string::npos ); } SECTION( "no empty section headers for anatomy-incompatible items" ) { clear_avatar(); item tail_item( itype_test_tail_encumber ); std::string cov = item_info_str( tail_item, { iteminfo_parts::ARMOR_COVERAGE } ); std::string enc = item_info_str( tail_item, { iteminfo_parts::ARMOR_ENCUMBRANCE } ); std::string wrm = item_info_str( tail_item, { iteminfo_parts::ARMOR_WARMTH } ); std::string brt = item_info_str( tail_item, { iteminfo_parts::ARMOR_BREATHABILITY } ); CHECK( cov.find( "Total Coverage" ) == std::string::npos ); CHECK( enc.find( "Encumbrance" ) == std::string::npos ); CHECK( wrm.find( "Warmth" ) == std::string::npos ); CHECK( brt.find( "Breathability" ) == std::string::npos ); } SECTION( "coverage value correct for default human" ) { clear_avatar(); item longshirt( itype_test_longshirt ); std::string info = item_info_str( longshirt, { iteminfo_parts::ARMOR_COVERAGE } ); CHECK( info.find( "90%" ) != std::string::npos ); CHECK( info.find( arms_frag ) != std::string::npos ); CHECK( info.find( torso_frag ) != std::string::npos ); } SECTION( "coverage value correct for alt-arm character" ) { make_alt_arm_viewer(); item longshirt( itype_test_longshirt ); std::string info = item_info_str( longshirt, { iteminfo_parts::ARMOR_COVERAGE } ); CHECK( info.find( "90%" ) != std::string::npos ); CHECK( info.find( alt_arms_frag ) != std::string::npos ); CHECK( info.find( torso_frag ) != std::string::npos ); } }