Skip to content

Commit

Permalink
Fix batch availability with charged tool requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrox committed Dec 13, 2020
1 parent 1d20a56 commit 36b7016
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 36b7016

Please sign in to comment.