diff --git a/src/monexamine.cpp b/src/monexamine.cpp index 6b59b74588ea..da0c6ef5d484 100644 --- a/src/monexamine.cpp +++ b/src/monexamine.cpp @@ -76,6 +76,7 @@ bool monexamine::pet_menu( monster &z ) remove_bag, drop_all, give_items, + take_items, mon_armor_add, mon_harness_remove, mon_armor_remove, @@ -124,6 +125,7 @@ bool monexamine::pet_menu( monster &z ) amenu.addentry( give_items, true, 'g', _( "Place items into bag" ) ); amenu.addentry( remove_bag, true, 'b', _( "Remove bag from %s" ), pet_name ); if( !z.inv.empty() ) { + amenu.addentry( take_items, true, 'G', _( "Take items from bag" ) ); amenu.addentry( drop_all, true, 'd', _( "Remove all items from bag" ) ); } } else if( !z.has_flag( MF_RIDEABLE_MECH ) ) { @@ -276,6 +278,9 @@ bool monexamine::pet_menu( monster &z ) break; case give_items: return give_items_to( z ); + case take_items: + take_items_from( z ); + break; case mon_armor_add: return add_armor( z ); case mon_harness_remove: @@ -732,6 +737,40 @@ bool monexamine::give_items_to( monster &z ) return false; } +void monexamine::take_items_from( monster &z ) +{ + const std::string pet_name = z.get_name(); + std::vector &monster_inv = z.inv; + if( monster_inv.empty() ) { + return; + } + + int i = 0; + uilist selection_menu; + selection_menu.text = string_format( _( "Select an item to remove from the %s." ), pet_name ); + selection_menu.addentry( i++, true, MENU_AUTOASSIGN, _( "Cancel" ) ); + for( auto iter : monster_inv ) { + selection_menu.addentry( i++, true, MENU_AUTOASSIGN, _( "Retrieve %s" ), iter.tname() ); + } + selection_menu.selected = 1; + selection_menu.query(); + const int index = selection_menu.ret; + if( index == 0 || index == UILIST_CANCEL || index < 0 || + index > static_cast( monster_inv.size() ) ) { + return; + } + + // because the first entry is the cancel option + const int selection = index - 1; + item retrieved_item = monster_inv[selection]; + monster_inv.erase( monster_inv.begin() + selection ); + + add_msg( _( "You remove the %1$s from the %2$s's bag." ), retrieved_item.tname(), pet_name ); + + avatar &you = get_avatar(); + you.i_add( retrieved_item ); +} + bool monexamine::add_armor( monster &z ) { std::string pet_name = z.get_name(); diff --git a/src/monexamine.h b/src/monexamine.h index 67f31593a00b..fa0ba71c6e3f 100644 --- a/src/monexamine.h +++ b/src/monexamine.h @@ -19,6 +19,7 @@ void attach_bag_to( monster &z ); void remove_bag_from( monster &z ); void dump_items( monster &z ); bool give_items_to( monster &z ); +void take_items_from( monster &z ); bool add_armor( monster &z ); void remove_armor( monster &z ); void remove_harness( monster &z );