Skip to content

Commit

Permalink
Merge pull request #46029 from Qrox/batch-availability
Browse files Browse the repository at this point in the history
Fix batch availability with charged tool requirements
  • Loading branch information
Rivet-the-Zombie authored Dec 15, 2020
2 parents 0b19b36 + 36b7016 commit 98cb58d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/requirements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,16 @@ bool tool_comp::has(
} else {
int charges_required = count * batch * item::find_type( type )->charge_factor();

if( ( flags & craft_flags::start_only ) != craft_flags::none ) {
charges_required = charges_required / 20 + charges_required % 20;
// The `type->tool` check excludes items counted by charge used as tools,
// such as water purification tablets.
if( ( flags & craft_flags::start_only ) != craft_flags::none && type->tool ) {
// See Character::craft_consume_tools. In theory only
// `charges_required / 20 + charges_required % 20` charges are
// consumed during the first 5% progress, however that equation
// sometimes decreases when the batch size increases, so we take
// the largest remainder value 19 to make this function return
// false consistently for large batch sizes.
charges_required = std::min( charges_required, charges_required / 20 + 19 );
}

int charges_found = crafting_inv.charges_of( type, charges_required, filter, visitor );
Expand Down

0 comments on commit 98cb58d

Please sign in to comment.