Skip to content

Commit

Permalink
Allow disabling plugging tools in for the charge-using tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamayana committed Dec 6, 2023
1 parent 29aafd4 commit 07678ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion data/mods/TEST_DATA/appliance.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"color": "light_cyan",
"ammo_type": [ "battery" ],
"capacity": 1000000000,
"count" : 1000000000,
"count": 1000000000,
"flags": [ "NO_SALVAGE", "NO_UNLOAD", "NO_RELOAD", "RECHARGE", "NO_REPAIR" ],
"pocket_data": [ { "pocket_type": "MAGAZINE", "rigid": true, "ammo_restriction": { "battery": 1000000000 } } ],
"melee_damage": { "bash": 20 }
Expand Down
25 changes: 13 additions & 12 deletions tests/crafting_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ TEST_CASE( "crafting_with_a_companion", "[.]" )
}
}

static void give_tools( const std::vector<item> &tools )
static void give_tools( const std::vector<item> &tools, const bool plug_in )
{
Character &player_character = get_player_character();
player_character.clear_worn();
Expand All @@ -380,12 +380,13 @@ static void give_tools( const std::vector<item> &tools )
if( gear.get_quality( qual_BOIL, false ) == 0 ) {
item_location added_tool = player_character.i_add( gear );
REQUIRE( added_tool );
if( added_tool->can_link_up() ) {
if( plug_in && added_tool->can_link_up() ) {
added_tool->link = cata::make_value<item::link_data>();
added_tool->link->t_state = link_state::vehicle_port;
added_tool->link->t_abs_pos = get_map().getglobal( player_character.pos() + tripoint_north );
added_tool->link->last_processed = calendar::turn;
added_tool->link->t_veh_safe = get_map().veh_at( player_character.pos() + tripoint_north )->vehicle().get_safe_reference();
added_tool->link->t_veh_safe = get_map().veh_at( player_character.pos() +
tripoint_north )->vehicle().get_safe_reference();
added_tool->set_link_traits();
REQUIRE( added_tool->link->t_veh_safe );
}
Expand Down Expand Up @@ -427,7 +428,7 @@ static void grant_profs_to_character( Character &you, const recipe &r )
}

static void prep_craft( const recipe_id &rid, const std::vector<item> &tools,
bool expect_craftable, int offset = 0, bool grant_profs = false )
bool expect_craftable, int offset = 0, bool grant_profs = false, bool plug_in_tools = true )
{
clear_avatar();
clear_map();
Expand All @@ -448,7 +449,7 @@ static void prep_craft( const recipe_id &rid, const std::vector<item> &tools,
optional_vpart_position battery_part = get_map().veh_at( battery_pos );
REQUIRE( battery_part.has_value() );

give_tools( tools );
give_tools( tools, plug_in_tools );
const inventory &crafting_inv = player_character.crafting_inventory();

bool can_craft_with_crafting_inv = r.deduped_requirements()
Expand Down Expand Up @@ -561,7 +562,7 @@ TEST_CASE( "proficiency_gain_short_crafts", "[crafting][proficiency]" )

do {
turns_taken += test_craft_for_prof( rec, proficiency_prof_carving, 1.0f );
give_tools( tools );
give_tools( tools, true );

// Escape door to avoid infinite loop if there is no progress
REQUIRE( turns_taken < max_turns );
Expand Down Expand Up @@ -860,7 +861,7 @@ TEST_CASE( "tools_use_charge_to_craft", "[crafting][charge]" )
tools.push_back( plastic_molding );

THEN( "crafting succeeds, and uses charges from each tool" ) {
prep_craft( recipe_carver_off, tools, true );
prep_craft( recipe_carver_off, tools, true, 0, false, false );
int turns = actually_test_craft( recipe_carver_off, INT_MAX );
CAPTURE( turns );
CHECK( get_remaining_charges( "hotplate_induction" ) == 0 );
Expand All @@ -874,7 +875,7 @@ TEST_CASE( "tools_use_charge_to_craft", "[crafting][charge]" )
tools.insert( tools.end(), 1, tool_with_ammo( "vac_mold", 4 ) );

THEN( "crafting succeeds, and uses charges from multiple tools" ) {
prep_craft( recipe_carver_off, tools, true );
prep_craft( recipe_carver_off, tools, true, 0, false, false );
actually_test_craft( recipe_carver_off, INT_MAX );
CHECK( get_remaining_charges( "hotplate_induction" ) == 0 );
CHECK( get_remaining_charges( "soldering_iron" ) == 0 );
Expand All @@ -896,7 +897,7 @@ TEST_CASE( "tools_use_charge_to_craft", "[crafting][charge]" )
tools.push_back( tool_with_ammo( "vac_mold", 4 ) );

THEN( "crafting succeeds, and uses charges from the UPS" ) {
prep_craft( recipe_carver_off, tools, true );
prep_craft( recipe_carver_off, tools, true, 0, false, false );
actually_test_craft( recipe_carver_off, INT_MAX );
CHECK( get_remaining_charges( "hotplate" ) == 0 );
CHECK( get_remaining_charges( "soldering_iron" ) == 0 );
Expand All @@ -919,7 +920,7 @@ TEST_CASE( "tools_use_charge_to_craft", "[crafting][charge]" )
tools.push_back( ups );

THEN( "crafting fails, and no charges are used" ) {
prep_craft( recipe_carver_off, tools, false );
prep_craft( recipe_carver_off, tools, false, 0, false, false );
CHECK( get_remaining_charges( "UPS_off" ) == 10 );
}
}
Expand Down Expand Up @@ -1191,7 +1192,7 @@ static void test_skill_progression( const recipe_id &test_recipe, int expected_t
REQUIRE( previous_knowledge < new_knowledge );
previous_knowledge = new_knowledge;
}
give_tools( tools );
give_tools( tools, true );
} while( static_cast<int>( you.get_skill_level( skill_used ) ) == starting_skill_level );
CAPTURE( test_recipe.str() );
CAPTURE( expected_turns_taken );
Expand Down Expand Up @@ -1355,7 +1356,7 @@ TEST_CASE( "book_proficiency_mitigation", "[crafting][proficiency]" )
WHEN( "player has a book mitigating lack of proficiency" ) {
std::vector<item> books;
books.emplace_back( "manual_tailor" );
give_tools( books );
give_tools( books, true );
get_player_character().invalidate_crafting_inventory();
int mitigated_time_taken = test_recipe.batch_time( get_player_character(), 1, 1, 0 );
THEN( "it takes less time to craft the recipe" ) {
Expand Down

0 comments on commit 07678ac

Please sign in to comment.