Skip to content

Commit

Permalink
overflow items before consuming/using them to avoid removing items wi…
Browse files Browse the repository at this point in the history
…th migrated charges in their migration pocket
  • Loading branch information
mqrause committed Jul 30, 2023
1 parent 2741ea4 commit f5489e4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2636,13 +2636,15 @@ void activity_handlers::eat_menu_do_turn( player_activity *, Character *you )
void activity_handlers::consume_food_menu_do_turn( player_activity *, Character * )
{
avatar &player_character = get_avatar();
avatar_action::eat( player_character, game_menus::inv::consume_food( player_character ) );
item_location loc = game_menus::inv::consume_food( player_character );
avatar_action::eat( player_character, loc );
}

void activity_handlers::consume_drink_menu_do_turn( player_activity *, Character * )
{
avatar &player_character = get_avatar();
avatar_action::eat( player_character, game_menus::inv::consume_drink( player_character ) );
item_location loc = game_menus::inv::consume_drink( player_character );
avatar_action::eat( player_character, loc );
}

void activity_handlers::consume_meds_menu_do_turn( player_activity *, Character * )
Expand Down
7 changes: 5 additions & 2 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ bool avatar_action::eat_here( avatar &you )
return false;
}

void avatar_action::eat( avatar &you, const item_location &loc )
void avatar_action::eat( avatar &you, item_location &loc )
{
std::string filter;
if( !you.activity.str_values.empty() ) {
Expand All @@ -922,7 +922,7 @@ void avatar_action::eat( avatar &you, const item_location &loc )
you.activity.id() );
}

void avatar_action::eat( avatar &you, const item_location &loc,
void avatar_action::eat( avatar &you, item_location &loc,
const std::vector<int> &consume_menu_selections,
const std::vector<item_location> &consume_menu_selected_items,
const std::string &consume_menu_filter,
Expand All @@ -933,6 +933,7 @@ void avatar_action::eat( avatar &you, const item_location &loc,
add_msg( _( "Never mind." ) );
return;
}
loc.overflow();
you.assign_activity( consume_activity_actor( loc, consume_menu_selections,
consume_menu_selected_items, consume_menu_filter, type ) );
you.last_item = item( *loc ).typeId();
Expand Down Expand Up @@ -1094,6 +1095,8 @@ void avatar_action::use_item( avatar &you, item_location &loc, std::string const
}
}

loc.overflow();

if( loc->is_comestible() && loc->is_frozen_liquid() ) {
add_msg( _( "Try as you might, you can't consume frozen liquids." ) );
return;
Expand Down
4 changes: 2 additions & 2 deletions src/avatar_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace avatar_action
{

/** Eat food or fuel 'E' (or 'a') */
void eat( avatar &you, const item_location &loc );
void eat( avatar &you, const item_location &loc,
void eat( avatar &you, item_location &loc );
void eat( avatar &you, item_location &loc,
const std::vector<int> &consume_menu_selections,
const std::vector<item_location> &consume_menu_selected_items,
const std::string &consume_menu_filter, activity_id type );
Expand Down
12 changes: 8 additions & 4 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1748,12 +1748,16 @@ void game::open_consume_item_menu()

avatar &player_character = get_avatar();
switch( as_m.ret ) {
case 0:
avatar_action::eat( player_character, game_menus::inv::consume_food( player_character ) );
case 0: {
item_location loc = game_menus::inv::consume_food( player_character );
avatar_action::eat( player_character, loc );
break;
case 1:
avatar_action::eat( player_character, game_menus::inv::consume_drink( player_character ) );
}
case 1: {
item_location loc = game_menus::inv::consume_drink( player_character );
avatar_action::eat( player_character, loc );
break;
}
case 2:
avatar_action::eat_or_use( player_character, game_menus::inv::consume_meds( player_character ) );
break;
Expand Down
2 changes: 1 addition & 1 deletion src/item_pocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ static void move_to_parent_pocket_recursive( const tripoint &pos, item &it,
if( parent_pocket && parent_pocket->can_contain( it ).success() ) {
add_msg( m_bad, _( "Your %1$s falls into your %2$s." ), it.display_name(),
loc.parent_item()->label( 1 ) );
loc.parent_pocket()->insert_item( it );
parent_pocket->insert_item( it );
return;
}
if( loc.where() == item_location::type::container ) {
Expand Down

0 comments on commit f5489e4

Please sign in to comment.