Skip to content

Commit

Permalink
Provide insertion failure reasons from only eligible pockets
Browse files Browse the repository at this point in the history
When trying to insert "plastic painkiller bottle" into a full backpack,
the failure reason was previously shown as "item is too short". This
commit instead makes the failure reason only show from pockets that
could possibly contain the item.

In effect, the failure reason when inserting "plastic painkiller bottle"
into a full backpack will now instead be "not enough space".
  • Loading branch information
inogenous committed Jul 28, 2024
1 parent b7ae537 commit 6fe4f90
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,7 @@ ret_val<void> item_contents::can_contain( const item &it, int &copies_remaining,
units::volume remaining_parent_volume ) const
{
ret_val<void> ret = ret_val<void>::make_failure( _( "is not a container" ) );
bool has_ret = false;

if( copies_remaining <= 0 ) {
return ret_val<void>::make_success();
Expand Down Expand Up @@ -1139,7 +1140,15 @@ ret_val<void> item_contents::can_contain( const item &it, int &copies_remaining,
if( copies_remaining <= 0 ) {
return ret_val<void>::make_success();
}
int n = copies_remaining;
bool could_contain = pocket.can_contain( it, n, /*ignore_contents=*/true ).success();
if( has_ret && !could_contain ) {
// This pocket could never contain the item, even if the pocket was emptied.
// So we would prefer to get the failure msg from another pocket which could potentially hold the item.
continue;
}
ret = ret_val<void>::make_failure( pocket_contain_code.str() );
has_ret = true;
}
return ret;
}
Expand Down

0 comments on commit 6fe4f90

Please sign in to comment.