Skip to content

Commit

Permalink
Recast spell
Browse files Browse the repository at this point in the history
  • Loading branch information
Brambor committed Jan 2, 2025
1 parent 0c04b9f commit f9882e6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3281,6 +3281,12 @@
"category": "DEFAULTMODE",
"bindings": [ { "input_method": "keyboard_any", "key": "]" } ]
},
{
"type": "keybinding",
"id": "recast_spell",
"name": "Repeat last supernatural ability",
"category": "DEFAULTMODE"
},
{
"type": "keybinding",
"id": "diary",
Expand Down
3 changes: 3 additions & 0 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ std::string action_ident( action_id act )
return "fire_burst";
case ACTION_CAST_SPELL:
return "cast_spell";
case ACTION_RECAST_SPELL:
return "recast_spell";
case ACTION_SELECT_FIRE_MODE:
return "select_fire_mode";
case ACTION_SELECT_DEFAULT_AMMO:
Expand Down Expand Up @@ -979,6 +981,7 @@ action_id handle_action_menu()
REGISTER_ACTION( ACTION_RELOAD_WEAPON );
REGISTER_ACTION( ACTION_RELOAD_WIELDED );
REGISTER_ACTION( ACTION_CAST_SPELL );
REGISTER_ACTION( ACTION_RECAST_SPELL );
REGISTER_ACTION( ACTION_SELECT_FIRE_MODE );
REGISTER_ACTION( ACTION_SELECT_DEFAULT_AMMO );
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 @@ -188,6 +188,8 @@ enum action_id : int {
ACTION_SELECT_DEFAULT_AMMO,
/** Cast a spell (only if any spells are known) */
ACTION_CAST_SPELL,
/** Recast last spell */
ACTION_RECAST_SPELL,
/** Open the insert-item menu */
ACTION_INSERT_ITEM,
/** Unload container in a given direction */
Expand Down
1 change: 1 addition & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,7 @@ input_context get_default_mode_input_context()
ctxt.register_action( "throw_wielded" );
ctxt.register_action( "fire" );
ctxt.register_action( "cast_spell" );
ctxt.register_action( "recast_spell" );
ctxt.register_action( "fire_burst" );
ctxt.register_action( "select_fire_mode" );
ctxt.register_action( "select_default_ammo" );
Expand Down
16 changes: 14 additions & 2 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ static void open_movement_mode_menu()
}
}

static void cast_spell()
static void cast_spell( bool recast_spell = false )
{
Character &player_character = get_player_character();
player_character.magic->clear_opens_spellbook_data();
Expand Down Expand Up @@ -1873,11 +1873,19 @@ static void cast_spell()
}
}

spell &sp = player_character.magic->select_spell( player_character );
if( recast_spell && player_character.magic->last_spell.is_null() ) {
popup( _( "Cast a spell first" ) );
return;
}

spell &sp = recast_spell
? player_character.magic->get_spell( player_character.magic->last_spell )
: player_character.magic->select_spell( player_character );
// if no spell was selected
if( sp.id().is_null() ) {
return;
}
player_character.magic->last_spell = sp.id();
player_character.cast_spell( sp, false, std::nullopt );
}

Expand Down Expand Up @@ -2638,6 +2646,10 @@ bool game::do_regular_action( action_id &act, avatar &player_character,
cast_spell();
break;

case ACTION_RECAST_SPELL:
cast_spell( true );
break;

case ACTION_FIRE_BURST: {
if( weapon ) {
if( weapon->gun_set_mode( gun_mode_BURST ) || weapon->gun_set_mode( gun_mode_AUTO ) ) {
Expand Down
2 changes: 2 additions & 0 deletions src/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ class known_magic
spell &select_spell( Character &guy );
// get all known spells
std::vector<spell *> get_spells();
// Last spell casted
spell_id last_spell = spell_id::NULL_ID(); // NOLINT(cata-serialize)
// directly get the character known spells
std::map<spell_id, spell> &get_spellbook() {
return spellbook;
Expand Down

0 comments on commit f9882e6

Please sign in to comment.