Skip to content

Commit

Permalink
Merge pull request #75304 from inogenous/insert-message-from-valid-po…
Browse files Browse the repository at this point in the history
…cket

Provide insertion failure reasons from only eligible pockets
  • Loading branch information
Maleclypse authored Jul 29, 2024
2 parents 14f5841 + 6fe4f90 commit 6e69fb7
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 6e69fb7

Please sign in to comment.