Skip to content

Commit

Permalink
Unload containers into tile key (#52201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saicchi authored Oct 19, 2021
1 parent 54ad164 commit 732faf4
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 25 deletions.
4 changes: 2 additions & 2 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2095,9 +2095,9 @@
},
{
"type": "keybinding",
"name": "Drop Item",
"name": "Unload container",
"category": "DEFAULTMODE",
"id": "drop",
"id": "unload_container",
"bindings": [ { "input_method": "keyboard_any", "key": "d" } ]
},
{
Expand Down
6 changes: 3 additions & 3 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ std::string action_ident( action_id act )
return "cast_spell";
case ACTION_SELECT_FIRE_MODE:
return "select_fire_mode";
case ACTION_DROP:
return "drop";
case ACTION_UNLOAD_CONTAINER:
return "unload_container";
case ACTION_DIR_DROP:
return "drop_adj";
case ACTION_BIONICS:
Expand Down Expand Up @@ -851,7 +851,7 @@ action_id handle_action_menu()
// Everything below here can be accessed through
// the inventory screen, so it's sorted to the
// end of the list.
REGISTER_ACTION( ACTION_DROP );
REGISTER_ACTION( ACTION_UNLOAD_CONTAINER );
REGISTER_ACTION( ACTION_COMPARE );
REGISTER_ACTION( ACTION_ORGANIZE );
REGISTER_ACTION( ACTION_USE );
Expand Down
4 changes: 2 additions & 2 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ enum action_id : int {
ACTION_SELECT_FIRE_MODE,
/** Cast a spell (only if any spells are known) */
ACTION_CAST_SPELL,
/** Open the drop-item menu */
ACTION_DROP,
/** Unload container in a given direction */
ACTION_UNLOAD_CONTAINER,
/** Drop items in a given direction */
ACTION_DIR_DROP,
/** Open the bionics menu */
Expand Down
14 changes: 7 additions & 7 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ input_context get_default_mode_input_context()
ctxt.register_action( "cast_spell" );
ctxt.register_action( "fire_burst" );
ctxt.register_action( "select_fire_mode" );
ctxt.register_action( "drop" );
ctxt.register_action( "unload_container" );
ctxt.register_action( "drop_adj" );
ctxt.register_action( "bionics" );
ctxt.register_action( "mutations" );
Expand Down Expand Up @@ -7771,16 +7771,16 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
return game::vmenu_ret::QUIT;
}

void game::drop()
void game::unload_container()
{
u.drop( game_menus::inv::multidrop( u ), u.pos() );
if( const cata::optional<tripoint> pnt = choose_adjacent( _( "Unload where?" ) ) ) {
u.drop( game_menus::inv::unload_container( u ), *pnt );
}
}

void game::drop_in_direction()
void game::drop_in_direction( const tripoint &pnt )
{
if( const cata::optional<tripoint> pnt = choose_adjacent( _( "Drop where?" ) ) ) {
u.drop( game_menus::inv::multidrop( u ), *pnt );
}
u.drop( game_menus::inv::multidrop( u ), pnt );
}

// Used to set up the first Hotkey in the display set
Expand Down
4 changes: 2 additions & 2 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,8 @@ class game
void pickup( const tripoint &p );
void pickup_feet(); // Pick items at player position ',', min 1

void drop(); // Drop an item 'd'
void drop_in_direction(); // Drop w/ direction 'D'
void unload_container(); // Unload a container w/ direction 'd'
void drop_in_direction( const tripoint &pnt ); // Drop w/ direction 'D'

void butcher(); // Butcher a corpse 'B'

Expand Down
85 changes: 83 additions & 2 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#include "units.h"
#include "units_utility.h"
#include "value_ptr.h"
#include "vehicle_selector.h"
#include "vpart_position.h"

static const activity_id ACT_EAT_MENU( "ACT_EAT_MENU" );
static const activity_id ACT_CONSUME_FOOD_MENU( "ACT_CONSUME_FOOD_MENU" );
Expand Down Expand Up @@ -1617,8 +1619,7 @@ drop_locations game_menus::inv::holster( avatar &you, const item_location &holst
inventory_drop_selector insert_menu( you, holster_preset, _( "ITEMS TO INSERT" ),
/*warn_liquid=*/false );
insert_menu.add_character_items( you );
insert_menu.add_map_items( you.pos() );
insert_menu.add_vehicle_items( you.pos() );
insert_menu.add_nearby_items( 1 );
insert_menu.set_display_stats( false );

insert_menu.set_title( title );
Expand Down Expand Up @@ -1646,6 +1647,86 @@ void game_menus::inv::insert_items( avatar &you, item_location &holster )
}
}

static bool valid_unload_container( const item_location &container )
{
// Item must be a container.
if( !container->is_container() ) {
return false;
}

// Container must contain at least one item
if( container->empty_container() ) {
return false;
}

// This item must not be a liquid, relies on containers
// only being able to store one liquid at a time
if( container->num_item_stacks() == 1 && container->only_item().made_of( phase_id::LIQUID ) ) {
return false;
}

return true;
}

// Due to current item_location limitations, these won't work.
// When item_location gets updated to get items inside containers outside the player inventory
// uncomment this
// static item_location unload_container_item( drop_location &droplc, item *it, avatar &you )
// {
// switch( droplc.first.where() ) {
// case item_location::type::invalid:
// return item_location();
// case item_location::type::character:
// return item_location( you, it );
// case item_location::type::map:
// return item_location( map_cursor( droplc.first.position() ), it );
// case item_location::type::vehicle: {
// const cata::optional<vpart_reference> vp =
// get_map().veh_at( droplc.first.position() ).part_with_feature( "CARGO", true );
// if( !vp ) {
// return item_location();
// }
// return item_location( vehicle_cursor( vp->vehicle(), vp->part_index() ), it );
// }
// case item_location::type::container:
// return item_location( droplc.first, it );
// default:
// return item_location();
// }
// }

drop_locations game_menus::inv::unload_container( avatar &you )
{
inventory_filter_preset unload_preset( valid_unload_container );

inventory_drop_selector insert_menu( you, unload_preset, _( "CONTAINERS TO UNLOAD" ),
/*warn_liquid=*/false );
insert_menu.add_character_items( you );
// When item_location gets updated to get items inside containers outside the player inventory
// uncomment this
//insert_menu.add_nearby_items( 1 );
insert_menu.set_display_stats( false );

insert_menu.set_title( _( "Select containers to unload" ) );

drop_locations dropped;
for( drop_location &droplc : insert_menu.execute() ) {
for( item *it : droplc.first->all_items_top( item_pocket::pocket_type::CONTAINER ) ) {
// no liquids
if( !it->made_of( phase_id::LIQUID ) ) {
dropped.emplace_back( item_location( droplc.first, it ), it->count() );
// When item_location gets updated to get items inside containers outside the player inventory
// uncomment this
// item_location iloc = unload_container_item( droplc, it, you );
// if( iloc ) {
// dropped.emplace_back( iloc, it->count() );
// }
}
}
}
return dropped;
}

class saw_barrel_inventory_preset: public weapon_inventory_preset
{
public:
Expand Down
1 change: 1 addition & 0 deletions src/game_inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ item_location wield( avatar &you );
/** Item wielding/unwielding menu. */
drop_locations holster( avatar &you, const item_location &holster );
void insert_items( avatar &you, item_location &holster );
drop_locations unload_container( avatar &you );
/** Choosing a gun to saw down it's barrel. */
item_location saw_barrel( Character &you, item &tool );
/** Choose item to wear. */
Expand Down
16 changes: 9 additions & 7 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2183,16 +2183,18 @@ bool game::do_regular_action( action_id &act, avatar &player_character,
}
break;

case ACTION_DROP:
case ACTION_UNLOAD_CONTAINER:
// You CAN drop things to your own tile while in the shell.
drop();
unload_container();
break;

case ACTION_DIR_DROP:
if( player_character.has_active_mutation( trait_SHELL2 ) ) {
add_msg( m_info, _( "You can't drop things to another tile while you're in your shell." ) );
} else {
drop_in_direction();
if( const cata::optional<tripoint> pnt = choose_adjacent( _( "Drop where?" ) ) ) {
if( *pnt != player_character.pos() &&
player_character.has_active_mutation( trait_SHELL2 ) ) {
add_msg( m_info, _( "You can't drop things to another tile while you're in your shell." ) );
} else {
drop_in_direction( *pnt );
}
}
break;
case ACTION_BIONICS:
Expand Down

0 comments on commit 732faf4

Please sign in to comment.