Skip to content

Commit

Permalink
only fill items as much as parent containers allow
Browse files Browse the repository at this point in the history
  • Loading branch information
mqrause committed Aug 9, 2022
1 parent 416457f commit 9042339
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ void activity_handlers::fill_liquid_do_turn( player_activity *act, Character *yo
break;
}
case liquid_target_type::CONTAINER:
you->pour_into( *act_ref.targets.at( 0 ), liquid, true );
you->pour_into( act_ref.targets.at( 0 ), liquid, true );
break;
case liquid_target_type::MAP:
if( iexamine::has_keg( act_ref.coords.at( 1 ) ) ) {
Expand Down
14 changes: 8 additions & 6 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5524,19 +5524,21 @@ bool Character::sees_with_specials( const Creature &critter ) const
return false;
}

bool Character::pour_into( item &container, item &liquid, bool ignore_settings )
bool Character::pour_into( item_location &container, item &liquid, bool ignore_settings )
{
std::string err;
int amount = container.get_remaining_capacity_for_liquid( liquid, *this, &err );
int max_remaining_capacity = container->get_remaining_capacity_for_liquid( liquid, *this, &err );
int amount = container->all_pockets_rigid() ? max_remaining_capacity :
std::min( max_remaining_capacity, container.max_charges_by_parent_recursive( liquid ) );

if( !err.empty() ) {
if( !container.has_item_with( [&liquid]( const item & it ) {
if( !container->has_item_with( [&liquid]( const item & it ) {
return it.typeId() == liquid.typeId();
} ) ) {
add_msg_if_player( m_bad, err );
} else {
//~ you filled <container> to the brim with <liquid>
add_msg_if_player( _( "You filled %1$s to the brim with %2$s." ), container.tname(),
add_msg_if_player( _( "You filled %1$s to the brim with %2$s." ), container->tname(),
liquid.tname() );
}
return false;
Expand All @@ -5547,9 +5549,9 @@ bool Character::pour_into( item &container, item &liquid, bool ignore_settings )
amount = std::min( amount, liquid.charges );
}

add_msg_if_player( _( "You pour %1$s into the %2$s." ), liquid.tname(), container.tname() );
add_msg_if_player( _( "You pour %1$s into the %2$s." ), liquid.tname(), container->tname() );

liquid.charges -= container.fill_with( liquid, amount, false, false, ignore_settings );
liquid.charges -= container->fill_with( liquid, amount, false, false, ignore_settings );
inv->unsort();

if( liquid.charges > 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ class Character : public Creature, public visitable
* possible at all. `true` indicates at least some of the liquid has been moved.
*/
/**@{*/
bool pour_into( item &container, item &liquid, bool ignore_settings );
bool pour_into( item_location &container, item &liquid, bool ignore_settings );
bool pour_into( const vpart_reference &vp, item &liquid ) const;
/**@}*/

Expand Down
2 changes: 1 addition & 1 deletion src/handle_liquid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ bool perform_liquid_transfer( item &liquid, const tripoint *const source_pos,
// not on ground or similar. TODO: implement storing arbitrary container locations.
if( target.item_loc && create_activity() ) {
serialize_liquid_target( player_character.activity, target.item_loc );
} else if( player_character.pour_into( *target.item_loc, liquid, true ) ) {
} else if( player_character.pour_into( target.item_loc, liquid, true ) ) {
if( target.item_loc->needs_processing() ) {
// Polymorphism fail, have to introspect into the type to set the target container as active.
switch( target.item_loc.where() ) {
Expand Down

0 comments on commit 9042339

Please sign in to comment.