Skip to content

Commit

Permalink
Add reload wielded keybinding (#36658)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramza13 authored and kevingranade committed Jan 5, 2020
1 parent 264b304 commit ca62787
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,12 @@
"category": "DEFAULTMODE",
"id": "reload_weapon"
},
{
"type": "keybinding",
"name": "Reload Wielded Item",
"category": "DEFAULTMODE",
"id": "reload_wielded"
},
{
"type": "keybinding",
"name": "Unload or Empty Wielded Item",
Expand Down
3 changes: 3 additions & 0 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ std::string action_ident( action_id act )
return "reload_item";
case ACTION_RELOAD_WEAPON:
return "reload_weapon";
case ACTION_RELOAD_WIELDED:
return "reload_wielded";
case ACTION_UNLOAD:
return "unload";
case ACTION_MEND:
Expand Down Expand Up @@ -860,6 +862,7 @@ action_id handle_action_menu()
REGISTER_ACTION( ACTION_FIRE );
REGISTER_ACTION( ACTION_RELOAD_ITEM );
REGISTER_ACTION( ACTION_RELOAD_WEAPON );
REGISTER_ACTION( ACTION_RELOAD_WIELDED );
REGISTER_ACTION( ACTION_CAST_SPELL );
REGISTER_ACTION( ACTION_SELECT_FIRE_MODE );
REGISTER_ACTION( ACTION_THROW );
Expand Down
2 changes: 2 additions & 0 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ enum action_id : int {
ACTION_RELOAD_ITEM,
/** Attempt to reload wielded weapon, then fall back to the load item select menu */
ACTION_RELOAD_WEAPON,
/** Attempt to reload wielded object*/
ACTION_RELOAD_WIELDED,
/** Open the unload item (e.g. firearms) select menu */
ACTION_UNLOAD,
/** Open the mending menu (e.g. when using a sewing kit) */
Expand Down
11 changes: 11 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,7 @@ input_context get_default_mode_input_context()
ctxt.register_action( "pick_style" );
ctxt.register_action( "reload_item" );
ctxt.register_action( "reload_weapon" );
ctxt.register_action( "reload_wielded" );
ctxt.register_action( "unload" );
ctxt.register_action( "throw" );
ctxt.register_action( "fire" );
Expand Down Expand Up @@ -8486,6 +8487,16 @@ void game::reload_item()
reload( item_loc );
}

void game::reload_wielded()
{
if( u.weapon.is_null() || !u.weapon.is_reloadable() ) {
add_msg( _( "You aren't holding something you can reload." ) );
return;
}
item_location item_loc = item_location( u, &u.weapon );
reload( item_loc );
}

void game::reload_weapon( bool try_everything )
{
// As a special streamlined activity, hitting reload repeatedly should:
Expand Down
1 change: 1 addition & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ class game
void reload( item_location &loc, bool prompt = false, bool empty = true );
public:
void reload_item(); // Reload an item
void reload_wielded();
void reload_weapon( bool try_everything = true ); // Reload a wielded gun/tool 'r'
// Places the player at the specified point; hurts feet, lists items etc.
point place_player( const tripoint &dest );
Expand Down
4 changes: 4 additions & 0 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,10 @@ bool game::handle_action()
reload_weapon();
break;

case ACTION_RELOAD_WIELDED:
reload_wielded();
break;

case ACTION_UNLOAD:
avatar_action::unload( u );
break;
Expand Down

0 comments on commit ca62787

Please sign in to comment.