diff --git a/data/mods/TEST_DATA/pocket_mods_test.json b/data/mods/TEST_DATA/pocket_mods_test.json new file mode 100644 index 0000000000000..5d4258a806dc2 --- /dev/null +++ b/data/mods/TEST_DATA/pocket_mods_test.json @@ -0,0 +1,179 @@ +[ + { + "type": "test_data", + "pocket_mod_data": { + "change existing magazine well": { + "base_item": "debug_gun_with_mag_well", + "mod_item": "debug_retool_mag_well", + "expected_pockets": { "MAGAZINE_WELL": 1 } + }, + "add magazine well to item without one": { + "base_item": "debug_gun_no_mag_well", + "mod_item": "debug_retool_mag_well", + "expected_pockets": { "MAGAZINE_WELL": 1 } + }, + "add pocket to pocketless tool": { + "base_item": "debug_tool_no_pockets", + "mod_item": "debug_retool_container_no_mag_well", + "expected_pockets": { "CONTAINER": 1 } + }, + "add pocket to tool with pocket": { + "base_item": "debug_tool_one_pocket", + "mod_item": "debug_retool_container_no_mag_well", + "expected_pockets": { "CONTAINER": 2 } + } + } + }, + { + "id": "debug_gun_no_mag_well", + "type": "GUN", + "name": { "str": "debug gun without mag well" }, + "copy-from": "rifle_auto", + "description": "Just a debug gun.", + "weight": "902 g", + "volume": "1550 ml", + "longest_side": "520 mm", + "price": 125000, + "price_postapoc": 4000, + "to_hit": -1, + "material": [ "aluminum", "steel", "plastic" ], + "symbol": "(", + "color": "black", + "ammo": [ "NULL" ], + "dispersion": 150, + "durability": 7, + "min_cycle_recoil": 1350, + "weapon_category": [ "AUTOMATIC_RIFLES" ], + "valid_mod_locations": [ [ "bore", 1 ], [ "grip", 1 ], [ "mechanism", 4 ], [ "sling", 1 ], [ "stock accessory", 2 ], [ "stock", 1 ] ], + "melee_damage": { "bash": 12 } + }, + { + "id": "debug_gun_with_mag_well", + "type": "GUN", + "name": "debug gun with mag well", + "copy-from": "debug_gun_no_mag_well", + "pocket_data": [ + { + "pocket_type": "MAGAZINE_WELL", + "ammo_restriction": { "223": 20 } + } + ] + }, + { + "id": "debug_tool_no_pockets", + "type": "TOOL", + "name": "debug tool with no pockets", + "description": "debug", + "symbol": "(", + "volume": "1L", + "weight": "1kg" + }, + { + "id": "debug_tool_one_pocket", + "type": "TOOL", + "name": "debug tool with one pocket", + "copy-from": "debug_tool_no_pockets", + "pocket_data": [ + { + "pocket_type": "CONTAINER", + "max_contains_volume": "2L" + } + ] + }, + { + "id": "debug_retool_container_no_mag_well", + "type": "TOOLMOD", + "name": "debug toolmod to add container", + "description": "debug", + "symbol": "(", + "volume": "1L", + "weight": "1kg", + "pocket_mods": [ + { + "pocket_type": "CONTAINER", + "max_contains_volume": "1L" + } + ] + }, + { + "id": "debug_retool_mag_well", + "type": "GUNMOD", + "name": { "str": "debug gunmod to add/alter magazine well" }, + "description": "This is a complete upper receiver assembly containing a barrel, handguard, and bolt carrier group that, given the right knowledge, is installable upon an AR-15-style rifleā€™s lower frame. Swappable uppers allow compatible firearms to be retooled for different cartridges and barrel lengths, with this kit furnishing a weapon with a standard 16-inch barrel chambered for .223 Remington ammunition.", + "weight": "2268 g", + "volume": "1550 ml", + "longest_side": "480 mm", + "integral_volume": "1550 ml", + "integral_weight": "2268 g", + "integral_longest_side": "41 cm", + "barrel_length": "406 mm", + "price": 25999, + "price_postapoc": 1000, + "material": [ "steel", "aluminum", "plastic" ], + "symbol": ":", + "color": "green", + "location": "bore", + "mod_targets": [ "debug_modular_ar15" ], + "install_time": "5 m", + "ammo_modifier": [ "223" ], + "magazine_adaptor": [ + [ + "223", + [ + "stanag30", + "stanag5", + "stanag5ranger", + "stanag10", + "stanag10ranger", + "stanag20", + "stanag20ranger", + "stanag30ranger", + "stanag40", + "stanag40ranger", + "stanag50", + "stanag60", + "stanag60drum", + "stanag90", + "stanag100", + "stanag100drum", + "stanag150", + "stanag20_beowulf", + "stanag20ranger_beowulf", + "stanag30_beowulf", + "stanag30ranger_beowulf", + "survivor223mag" + ] + ] + ], + "pocket_mods": [ + { + "pocket_type": "MAGAZINE_WELL", + "item_restriction": [ + "stanag30", + "stanag5", + "stanag5ranger", + "stanag10", + "stanag10ranger", + "stanag20", + "stanag20ranger", + "stanag30ranger", + "stanag40", + "stanag40ranger", + "stanag50", + "stanag60", + "stanag60drum", + "stanag90", + "stanag100", + "stanag100drum", + "stanag150", + "stanag20_beowulf", + "stanag20ranger_beowulf", + "stanag30_beowulf", + "stanag30ranger_beowulf", + "survivor223mag" + ] + } + ], + "add_mod": [ [ "brass catcher", 1 ], [ "bayonet lug", 1 ], [ "rail", 2 ], [ "sights", 1 ], [ "underbarrel", 1 ], [ "muzzle", 1 ] ] + } +] diff --git a/src/test_data.cpp b/src/test_data.cpp index d896483bfe546..b1e8710b6ace8 100644 --- a/src/test_data.cpp +++ b/src/test_data.cpp @@ -7,6 +7,7 @@ std::map> test_data::drag_data; std::map test_data::eff_data; std::map test_data::expected_dps; std::map> test_data::container_spawn_data; +std::map test_data::pocket_mod_data; std::map test_data::npc_boarding_data; void efficiency_data::deserialize( const JsonObject &jo ) @@ -40,6 +41,13 @@ void container_spawn_test_data::deserialize( const JsonObject &jo ) } } +void pocket_mod_test_data::deserialize( const JsonObject &jo ) +{ + jo.read( "base_item", base_item ); + jo.read( "mod_item", mod_item ); + jo.read( "expected_pockets", expected_pockets ); +} + void npc_boarding_test_data::deserialize( const JsonObject &jo ) { jo.read( "vehicle", veh_prototype ); @@ -111,6 +119,12 @@ void test_data::load( const JsonObject &jo ) } } + if( jo.has_object( "pocket_mod_data" ) ) { + std::map new_pocket_mod_data; + jo.read( "pocket_mod_data", new_pocket_mod_data ); + pocket_mod_data.insert( new_pocket_mod_data.begin(), new_pocket_mod_data.end() ); + } + if( jo.has_object( "npc_boarding_data" ) ) { std::map new_boarding_data; jo.read( "npc_boarding_data", new_boarding_data ); diff --git a/src/test_data.h b/src/test_data.h index 831c88afaf305..064f223f830bf 100644 --- a/src/test_data.h +++ b/src/test_data.h @@ -8,6 +8,7 @@ #include "point.h" #include "type_id.h" +#include "pocket_type.h" class JsonObject; @@ -40,6 +41,14 @@ struct container_spawn_test_data { void deserialize( const JsonObject &jo ); }; +struct pocket_mod_test_data { + itype_id base_item; + itype_id mod_item; + std::map expected_pockets; + + void deserialize( const JsonObject &jo ); +}; + struct npc_boarding_test_data { vproto_id veh_prototype; tripoint player_pos; @@ -58,6 +67,7 @@ class test_data static std::map eff_data; static std::map expected_dps; static std::map> container_spawn_data; + static std::map pocket_mod_data; static std::map npc_boarding_data; static void load( const JsonObject &jo ); diff --git a/tests/item_pocket_test.cpp b/tests/item_pocket_test.cpp index 0e0bb48ac8627..afcea4b3adfe5 100644 --- a/tests/item_pocket_test.cpp +++ b/tests/item_pocket_test.cpp @@ -27,6 +27,7 @@ #include "mapgen_helpers.h" #include "player_helpers.h" #include "ret_val.h" +#include "test_data.h" #include "type_id.h" #include "units.h" #include "value_ptr.h" @@ -2811,3 +2812,44 @@ TEST_CASE( "auto_whitelist", "[item][pocket][item_spawn]" ) check_whitelist( *spawned_w_modifier, edited, id ); } } + +TEST_CASE( "pocket_mods", "[pocket][toolmod][gunmod]" ) +{ + for( std::pair &pocket_mod_data : + test_data::pocket_mod_data ) { + SECTION( pocket_mod_data.first ) { + item base_it( pocket_mod_data.second.base_item ); + item mod_it( pocket_mod_data.second.mod_item ); + + base_it.put_in( mod_it, pocket_type::MOD ); + + std::vector new_pockets( base_it.get_contents().get_pockets( []( + item_pocket const & ) { + return true; + } ) ); + + for( std::pair &expected : + pocket_mod_data.second.expected_pockets ) { + std::vector pockets( base_it.get_contents().get_pockets( [expected]( + item_pocket const & pock ) { + return pock.is_type( expected.first ); + } ) ); + CAPTURE( expected.first ); + CHECK( expected.second == pockets.size() ); + } + + bool same_pocket_data = new_pockets.size() == base_it.type->pockets.size(); + if( same_pocket_data ) { + for( const item_pocket *pocket : new_pockets ) { + if( std::find( base_it.type->pockets.begin(), base_it.type->pockets.end(), + *pocket->get_pocket_data() ) == base_it.type->pockets.end() ) { + same_pocket_data = false; + break; + } + } + } + + CHECK_FALSE( same_pocket_data ); + } + } +}