Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reload wielded keybinding #36658

Merged
merged 2 commits into from
Jan 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1682,10 +1682,16 @@
},
{
"type": "keybinding",
"name": "Reload Wielded Item",
"name": "Reload Weapons",
"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 @@ -8477,6 +8478,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