From ab397cbfea58c9d1fb2355624131fc7de98ba601 Mon Sep 17 00:00:00 2001 From: Hourier Date: Sun, 12 Sep 2021 00:13:38 +0900 Subject: [PATCH] [Refactor] #1473 Replaced casting_hex_num() to add_casting_num() --- src/realm/realm-hex.cpp | 9 +++++---- src/spell-realm/spells-hex.cpp | 15 ++++++++++++++- src/spell-realm/spells-hex.h | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/realm/realm-hex.cpp b/src/realm/realm-hex.cpp index 8e213dbff..d6cf9d628 100644 --- a/src/realm/realm-hex.cpp +++ b/src/realm/realm-hex.cpp @@ -592,8 +592,9 @@ concptr do_hex_spell(player_type *player_ptr, spell_hex_type spell, spell_type m if ((!o_ptr->k_idx) || (!o_ptr->is_cursed())) { exe_spell(player_ptr, REALM_HEX, spell, SPELL_STOP); - SpellHex(player_ptr).reset_casting_flag(spell); - casting_hex_num(player_ptr)--; + SpellHex spell_hex(player_ptr); + spell_hex.reset_casting_flag(spell); + spell_hex.add_casting_num(false); if (get_singing_song_id(player_ptr) == 0) set_action(player_ptr, ACTION_NONE); } @@ -682,7 +683,7 @@ concptr do_hex_spell(player_type *player_ptr, spell_hex_type spell, spell_type m SpellHex spell_hex(player_ptr); spell_hex.reset_casting_flag(HEX_RESTORE); if (cont) { - casting_hex_num(player_ptr)--; + spell_hex.add_casting_num(false); } if (spell_hex.get_casting_num() > 0) { @@ -887,7 +888,7 @@ concptr do_hex_spell(player_type *player_ptr, spell_hex_type spell, spell_type m if (cast && add) { SpellHex spell_hex(player_ptr); spell_hex.set_casting_flag(spell); - casting_hex_num(player_ptr)++; + spell_hex.add_casting_num(true); if (player_ptr->action != ACTION_SPELL) set_action(player_ptr, ACTION_SPELL); diff --git a/src/spell-realm/spells-hex.cpp b/src/spell-realm/spells-hex.cpp index 226d5cc14..c60c488c3 100644 --- a/src/spell-realm/spells-hex.cpp +++ b/src/spell-realm/spells-hex.cpp @@ -103,7 +103,7 @@ bool SpellHex::stop_one_spell() auto n = this->casting_spells[A2I(choice)]; exe_spell(this->player_ptr, REALM_HEX, n, SPELL_STOP); this->reset_casting_flag(static_cast(n)); - casting_hex_num(this->player_ptr)--; + this->add_casting_num(false); } this->player_ptr->update |= PU_BONUS | PU_HP | PU_MANA | PU_SPELLS; @@ -455,3 +455,16 @@ int32_t SpellHex::get_casting_num() const { return this->player_ptr->magic_num2[0]; } + +/*! + * @brief 詠唱番号の加減算を行う + * @param is_incremental 加算ならtrue、減算ならfalse + */ +void SpellHex::add_casting_num(bool is_incremental) +{ + if (is_incremental) { + this->player_ptr->magic_num2[0]++; + } else { + this->player_ptr->magic_num2[0]--; + } +} diff --git a/src/spell-realm/spells-hex.h b/src/spell-realm/spells-hex.h index f99fcff25..53aedaed1 100644 --- a/src/spell-realm/spells-hex.h +++ b/src/spell-realm/spells-hex.h @@ -26,6 +26,7 @@ public: void set_casting_flag(spell_hex_type type); void reset_casting_flag(spell_hex_type type); int32_t get_casting_num() const; + void add_casting_num(bool is_incremental); private: player_type *player_ptr; @@ -43,7 +44,6 @@ private: void gain_exp_master(const int spell); }; -#define casting_hex_num(P_PTR) ((P_PTR)->magic_num2[0]) #define hex_revenge_power(P_PTR) ((P_PTR)->magic_num1[2]) #define hex_revenge_turn(P_PTR) ((P_PTR)->magic_num2[2]) #define hex_revenge_type(P_PTR) ((P_PTR)->magic_num2[1]) -- 2.11.0