Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crafting tests for vacuum molding #37

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/requirements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,21 @@ bool requirement_data::has_comps( const read_only_visitable &crafting_inv,
{
bool retval = true;
int total_UPS_charges_used = 0;
for( const auto &set_of_tools : vec ) {
for( const std::vector<T> &set_of_tools : vec ) {
bool has_tool_in_set = false;
int UPS_charges_used = std::numeric_limits<int>::max();
const std::function<void( int )> use_ups = [ &UPS_charges_used ]( int charges ) {
UPS_charges_used = std::min( UPS_charges_used, charges );
};

for( const auto &tool : set_of_tools ) {
for( const T &tool : set_of_tools ) {
if( tool.has( crafting_inv, filter, batch, flags, use_ups ) ) {
tool.available = available_status::a_true;
} else {
// Trying to track down why the crafting tests are failing?
// Uncomment the below to see the group of requirements that are lacking satisfaction
// Add a printf("\n") to the loop above this to separate different groups onto a separate line
// printf( "T: %s ", tool.type.str().c_str() );
tool.available = available_status::a_false;
}
has_tool_in_set = has_tool_in_set || tool.available == available_status::a_true;
Expand Down
9 changes: 6 additions & 3 deletions tests/crafting_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ TEST_CASE( "tools use charge to craft", "[crafting][charge]" )
tools.insert( tools.end(), 2, item( "blade" ) );
tools.insert( tools.end(), 5, item( "cable" ) );
tools.insert( tools.end(), 2, item( "polycarbonate_sheet" ) );
tools.insert( tools.end(), 1, item( "knife_paring" ) );
tools.emplace_back( "motor_tiny" );
tools.emplace_back( "power_supply" );
tools.emplace_back( "scrap" );
Expand All @@ -437,8 +438,8 @@ TEST_CASE( "tools use charge to craft", "[crafting][charge]" )
// - 10 charges of surface heat

WHEN( "each tool has enough charges" ) {
item hotplate = tool_with_ammo( "hotplate", 20 );
REQUIRE( hotplate.ammo_remaining() == 20 );
item hotplate = tool_with_ammo( "hotplate", 30 );
REQUIRE( hotplate.ammo_remaining() == 30 );
tools.push_back( hotplate );
item soldering = tool_with_ammo( "soldering_iron", 20 );
REQUIRE( soldering.ammo_remaining() == 20 );
Expand All @@ -459,6 +460,7 @@ TEST_CASE( "tools use charge to craft", "[crafting][charge]" )
WHEN( "multiple tools have enough combined charges" ) {
tools.insert( tools.end(), 2, tool_with_ammo( "hotplate", 5 ) );
tools.insert( tools.end(), 2, tool_with_ammo( "soldering_iron", 5 ) );
tools.insert( tools.end(), 1, tool_with_ammo( "vac_mold", 4 ) );

THEN( "crafting succeeds, and uses charges from multiple tools" ) {
prep_craft( recipe_id( "carver_off" ), tools, true );
Expand All @@ -477,9 +479,10 @@ TEST_CASE( "tools use charge to craft", "[crafting][charge]" )
tools.push_back( soldering_iron );
item UPS( "UPS_off" );
item UPS_mag( UPS.magazine_default() );
UPS_mag.ammo_set( UPS_mag.ammo_default(), 500 );
UPS_mag.ammo_set( UPS_mag.ammo_default(), 510 );
UPS.put_in( UPS_mag, item_pocket::pocket_type::MAGAZINE_WELL );
tools.emplace_back( UPS );
tools.push_back( tool_with_ammo( "vac_mold", 4 ) );

THEN( "crafting succeeds, and uses charges from the UPS" ) {
prep_craft( recipe_id( "carver_off" ), tools, true );
Expand Down