OSDN Git Service

[Refactor] #1558 Replaced set_stun() to stun() and transferred it into the class...
authorHourier <66951241+Hourier@users.noreply.github.com>
Mon, 20 Sep 2021 07:39:49 +0000 (16:39 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Wed, 22 Sep 2021 11:37:03 +0000 (20:37 +0900)
20 files changed:
src/blue-magic/blue-magic-caster.cpp
src/cmd-action/cmd-mane.cpp
src/cmd-action/cmd-mind.cpp
src/cmd-action/cmd-shoot.cpp
src/core/magic-effects-timeout-reducer.cpp
src/effect/effect-monster-charm.cpp
src/effect/effect-monster-psi.cpp
src/effect/effect-player-resist-hurt.cpp
src/mind/mind-mindcrafter.cpp
src/monster-attack/monster-attack-player.cpp
src/monster-attack/monster-attack-status.cpp
src/object-use/quaff-execution.cpp
src/realm/realm-crusade.cpp
src/realm/realm-song.cpp
src/specific-object/chest.cpp
src/spell-kind/earthquake.cpp
src/spell/spells-staff-only.cpp
src/spell/spells-status.cpp
src/status/bad-status-setter.cpp
src/status/bad-status-setter.h

index a5879e8..898704e 100644 (file)
@@ -306,7 +306,7 @@ static bool switch_cast_blue_magic(player_type *player_ptr, bmc_type *bmc_ptr, R
     case RF_ABILITY::HEAL:
         msg_print(_("自分の傷に念を集中した。", "You concentrate on your wounds!"));
         (void)hp_player(player_ptr, bmc_ptr->plev * 4);
-        (void)set_stun(player_ptr, 0);
+        (void)BadStatusSetter(player_ptr).stun(0);
         (void)set_cut(player_ptr, 0);
         return true;
     case RF_ABILITY::INVULNER:
index f6cbab6..0b2d974 100644 (file)
@@ -802,7 +802,7 @@ static bool use_mane(player_type *player_ptr, RF_ABILITY spell)
     case RF_ABILITY::HEAL:
         msg_print(_("自分の傷に念を集中した。", "You concentrate on your wounds!"));
         (void)hp_player(player_ptr, plev * 6);
-        (void)set_stun(player_ptr, 0);
+        (void)BadStatusSetter(player_ptr).stun(0);
         (void)set_cut(player_ptr, 0);
         break;
     case RF_ABILITY::INVULNER:
index f32c0d6..25761ff 100644 (file)
@@ -218,7 +218,7 @@ static void check_mind_mindcrafter(player_type *player_ptr, cm_type *cm_ptr)
     }
 
     if (cm_ptr->b < 90) {
-        set_stun(player_ptr, player_ptr->effects()->stun()->current() + randint1(8));
+        (void)bss.stun(player_ptr->effects()->stun()->current() + randint1(8));
         return;
     }
 
index d8650da..e217b87 100644 (file)
@@ -74,6 +74,6 @@ void do_cmd_fire(player_type *player_ptr, SPELL_IDX snipe_type)
         msg_print(_("射撃の反動が体を襲った。", "The weapon's recoil stuns you. "));
         BadStatusSetter bss(player_ptr);
         (void)bss.slowness(player_ptr->slow + randint0(7) + 7, false);
-        (void)set_stun(player_ptr, effects->stun()->current() + randint1(25));
+        (void)bss.stun(effects->stun()->current() + randint1(25));
     }
 }
index b5fb098..42622c0 100644 (file)
@@ -217,7 +217,7 @@ void reduce_magic_effects_timeout(player_type *player_ptr)
     auto player_stun = effects->stun();
     if (player_stun->is_stunned()) {
         int adjust = adj_con_fix[player_ptr->stat_index[A_CON]] + 1;
-        (void)set_stun(player_ptr, player_stun->current() - adjust);
+        (void)bss.stun(player_stun->current() - adjust);
     }
 
     if (player_ptr->cut) {
index 104eaf5..1cea781 100644 (file)
@@ -217,7 +217,7 @@ static void effect_monster_domination_corrupted_addition(player_type *player_ptr
     BadStatusSetter bss(player_ptr);
     switch (randint1(4)) {
     case 1:
-        set_stun(player_ptr, player_ptr->effects()->stun()->current() + em_ptr->dam / 2);
+        (void)bss.stun(player_ptr->effects()->stun()->current() + em_ptr->dam / 2);
         return;
     case 2:
         (void)bss.confusion(player_ptr->confused + em_ptr->dam / 2);
index d98e57a..df135a3 100644 (file)
@@ -107,7 +107,7 @@ static void effect_monster_psi_reflect_extra_effect(player_type *player_ptr, eff
         (void)bss.confusion(player_ptr->confused + 3 + randint1(em_ptr->dam));
         return;
     case 2:
-        set_stun(player_ptr, player_ptr->effects()->stun()->current() + randint1(em_ptr->dam));
+        (void)bss.stun(player_ptr->effects()->stun()->current() + randint1(em_ptr->dam));
         return;
     case 3:
         if (any_bits(em_ptr->r_ptr->flags3, RF3_NO_FEAR)) {
index f794486..ed8a510 100644 (file)
@@ -145,7 +145,7 @@ void effect_player_plasma(player_type *player_ptr, effect_player_type *ep_ptr)
 
     if (!has_resist_sound(player_ptr) && !check_multishadow(player_ptr)) {
         int plus_stun = (randint1((ep_ptr->dam > 40) ? 35 : (ep_ptr->dam * 3 / 4 + 5)));
-        (void)set_stun(player_ptr, player_ptr->effects()->stun()->current() + plus_stun);
+        (void)BadStatusSetter(player_ptr).stun(player_ptr->effects()->stun()->current() + plus_stun);
     }
 
     if (!(has_resist_fire(player_ptr) || is_oppose_fire(player_ptr) || has_immune_fire(player_ptr)))
@@ -208,8 +208,9 @@ void effect_player_water(player_type *player_ptr, effect_player_type *ep_ptr)
     BadStatusSetter bss(player_ptr);
     if (!check_multishadow(player_ptr)) {
         if (!has_resist_sound(player_ptr) && !has_res_water) {
-            set_stun(player_ptr, player_ptr->effects()->stun()->current() + randint1(40));
+            (void)bss.stun(player_ptr->effects()->stun()->current() + randint1(40));
         }
+
         if (!has_resist_conf(player_ptr) && !has_res_water) {
             (void)bss.confusion(player_ptr->confused + randint1(5) + 5);
         }
@@ -284,7 +285,7 @@ void effect_player_sound(player_type *player_ptr, effect_player_type *ep_ptr)
 
     if (!has_resist_sound(player_ptr) && !check_multishadow(player_ptr)) {
         int plus_stun = (randint1((ep_ptr->dam > 90) ? 35 : (ep_ptr->dam / 3 + 5)));
-        (void)set_stun(player_ptr, player_ptr->effects()->stun()->current() + plus_stun);
+        (void)BadStatusSetter(player_ptr).stun(player_ptr->effects()->stun()->current() + plus_stun);
     }
 
     if (!has_resist_sound(player_ptr) || one_in_(13))
@@ -341,7 +342,7 @@ void effect_player_force(player_type *player_ptr, effect_player_type *ep_ptr)
     if (player_ptr->blind)
         msg_print(_("運動エネルギーで攻撃された!", "You are hit by kinetic force!"));
     if (!has_resist_sound(player_ptr) && !check_multishadow(player_ptr)) {
-        (void)set_stun(player_ptr, player_ptr->effects()->stun()->current() + randint1(20));
+        (void)BadStatusSetter(player_ptr).stun(player_ptr->effects()->stun()->current() + randint1(20));
     }
 
     ep_ptr->get_damage = take_hit(player_ptr, DAMAGE_ATTACK, ep_ptr->dam, ep_ptr->killer);
@@ -352,7 +353,7 @@ void effect_player_rocket(player_type *player_ptr, effect_player_type *ep_ptr)
     if (player_ptr->blind)
         msg_print(_("爆発があった!", "There is an explosion!"));
     if (!has_resist_sound(player_ptr) && !check_multishadow(player_ptr)) {
-        (void)set_stun(player_ptr, player_ptr->effects()->stun()->current() + randint1(20));
+        (void)BadStatusSetter(player_ptr).stun(player_ptr->effects()->stun()->current() + randint1(20));
     }
 
     ep_ptr->dam = ep_ptr->dam * calc_rocket_damage_rate(player_ptr, CALC_RAND) / 100;
@@ -526,8 +527,10 @@ void effect_player_time(player_type *player_ptr, effect_player_type *ep_ptr)
 
 void effect_player_gravity(player_type *player_ptr, effect_player_type *ep_ptr)
 {
-    if (player_ptr->blind)
+    if (player_ptr->blind) {
         msg_print(_("何か重いもので攻撃された!", "You are hit by something heavy!"));
+    }
+
     msg_print(_("周辺の重力がゆがんだ。", "Gravity warps around you."));
 
     if (!check_multishadow(player_ptr)) {
@@ -538,13 +541,12 @@ void effect_player_gravity(player_type *player_ptr, effect_player_type *ep_ptr)
         }
 
         if (!(has_resist_sound(player_ptr) || player_ptr->levitation)) {
-            int plus_stun = (randint1((ep_ptr->dam > 90) ? 35 : (ep_ptr->dam / 3 + 5)));
-            (void)set_stun(player_ptr, player_ptr->effects()->stun()->current() + plus_stun);
+            auto plus_stun = (randint1((ep_ptr->dam > 90) ? 35 : (ep_ptr->dam / 3 + 5)));
+            (void)bss.stun(player_ptr->effects()->stun()->current() + plus_stun);
         }
     }
 
     ep_ptr->dam = ep_ptr->dam * calc_gravity_damage_rate(player_ptr, CALC_RAND) / 100;
-
     if (!player_ptr->levitation || one_in_(13)) {
         inventory_damage(player_ptr, BreakerCold(), 2);
     }
@@ -600,19 +602,22 @@ void effect_player_meteor(player_type *player_ptr, effect_player_type *ep_ptr)
 
 void effect_player_icee(player_type *player_ptr, effect_player_type *ep_ptr)
 {
-    if (player_ptr->blind)
+    if (player_ptr->blind) {
         msg_print(_("何か鋭く冷たいもので攻撃された!", "You are hit by something sharp and cold!"));
+    }
 
     ep_ptr->get_damage = cold_dam(player_ptr, ep_ptr->dam, ep_ptr->killer, false);
-    if (check_multishadow(player_ptr))
+    if (check_multishadow(player_ptr)) {
         return;
+    }
 
+    BadStatusSetter bss(player_ptr);
     if (!has_resist_shard(player_ptr)) {
         (void)set_cut(player_ptr, player_ptr->cut + damroll(5, 8));
     }
 
     if (!has_resist_sound(player_ptr)) {
-        (void)set_stun(player_ptr, player_ptr->effects()->stun()->current() + randint1(15));
+        (void)bss.stun(player_ptr->effects()->stun()->current() + randint1(15));
     }
 
     if ((!(has_resist_cold(player_ptr) || is_oppose_cold(player_ptr))) || one_in_(12)) {
index d3c3f9d..4ee7dda 100644 (file)
@@ -226,7 +226,7 @@ bool cast_mindcrafter_spell(player_type *player_ptr, mind_mindcrafter_type spell
     case ADRENALINE_CHANNELING: {
         BadStatusSetter bss(player_ptr);
         (void)bss.afraidness(0);
-        set_stun(player_ptr, 0);
+        (void)bss.stun(0);
         if (!is_fast(player_ptr) || !is_hero(player_ptr)) {
             hp_player(player_ptr, plev);
         }
index 16b0d25..7da9393 100644 (file)
@@ -240,7 +240,7 @@ static void calc_player_stun(player_type *player_ptr, monap_type *monap_ptr)
     }
 
     if (stun_plus > 0) {
-        (void)set_stun(player_ptr, player_ptr->effects()->stun()->current() + stun_plus);
+        (void)BadStatusSetter(player_ptr).stun(player_ptr->effects()->stun()->current() + stun_plus);
     }
 }
 
index 87864e2..a6dbb07 100644 (file)
@@ -128,8 +128,10 @@ void process_stun_attack(player_type *player_ptr, monap_type *monap_ptr)
     }
 
     auto *r_ptr = &r_info[monap_ptr->m_ptr->r_idx];
-    if (set_stun(player_ptr, player_ptr->effects()->stun()->current() + 10 + randint1(r_ptr->level / 4)))
+    auto current_stun = player_ptr->effects()->stun()->current();
+    if (BadStatusSetter(player_ptr).stun(current_stun + 10 + randint1(r_ptr->level / 4))) {
         monap_ptr->obvious = true;
+    }
 }
 
 /*!
index 5251f96..ca22418 100644 (file)
@@ -104,7 +104,8 @@ static bool detonation(player_type *player_ptr)
 {
     msg_print(_("体の中で激しい爆発が起きた!", "Massive explosions rupture your body!"));
     take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(50, 20), _("爆発の薬", "a potion of Detonation"));
-    (void)set_stun(player_ptr, player_ptr->effects()->stun()->current() + 75);
+    BadStatusSetter bss(player_ptr);
+    (void)bss.stun(player_ptr->effects()->stun()->current() + 75);
     (void)set_cut(player_ptr, player_ptr->cut + 5000);
     return true;
 }
index 61f13bc..42f8979 100644 (file)
@@ -175,7 +175,7 @@ concptr do_crusade_spell(player_type *player_ptr, SPELL_IDX spell, spell_type mo
             BadStatusSetter bss(player_ptr);
             set_cut(player_ptr, 0);
             (void)bss.poison(0);
-            set_stun(player_ptr, 0);
+            (void)bss.stun(0);
         }
 
         break;
@@ -336,7 +336,7 @@ concptr do_crusade_spell(player_type *player_ptr, SPELL_IDX spell, spell_type mo
             hp_player(player_ptr, heal);
             (void)bss.afraidness(0);
             (void)bss.poison(0);
-            set_stun(player_ptr, 0);
+            (void)bss.stun(0);
             set_cut(player_ptr, 0);
         }
 
index d04ac03..718906a 100644 (file)
@@ -882,37 +882,39 @@ concptr do_music_spell(player_type *player_ptr, SPELL_IDX spell, spell_type mode
 
         break;
     }
-    case 28:
-        if (name)
+    case 28: {
+        if (name) {
             return _("ヤヴァンナの助け", "Relief of Yavanna");
-        if (desc)
+        }
+
+        if (desc) {
             return _("強力な回復の歌で、負傷と朦朧状態も全快する。", "Powerful healing song. Also completely heals cuts and being stunned.");
+        }
 
-        /* Stop singing before start another */
-        if (cast || fail)
+        if (cast || fail) {
             stop_singing(player_ptr);
+        }
 
         if (cast) {
             msg_print(_("歌を通して体に活気が戻ってきた...", "Life flows through you as you sing the song..."));
             start_singing(player_ptr, spell, MUSIC_H_LIFE);
         }
 
-        {
-            DICE_NUMBER dice = 15;
-            DICE_SID sides = 10;
-
-            if (info)
-                return info_heal(dice, sides, 0);
+        auto dice = 15;
+        auto sides = 10;
+        if (info) {
+            return info_heal(dice, sides, 0);
+        }
 
-            if (cont) {
-                hp_player(player_ptr, damroll(dice, sides));
-                set_stun(player_ptr, 0);
-                set_cut(player_ptr, 0);
-            }
+        if (cont) {
+            hp_player(player_ptr, damroll(dice, sides));
+            BadStatusSetter bss(player_ptr);
+            (void)bss.stun(0);
+            set_cut(player_ptr, 0);
         }
 
         break;
-
+    }
     case 29:
         if (name)
             return _("再生の歌", "Goddess's rebirth");
index 384c543..84badb6 100644 (file)
@@ -283,7 +283,7 @@ void chest_trap(player_type *player_ptr, POSITION y, POSITION x, OBJECT_IDX o_id
                     if (!player_ptr->free_act) {
                         (void)bss.paralysis(player_ptr->paralyzed + 2 + randint0(6));
                     } else {
-                        (void)set_stun(player_ptr, effects->stun()->current() + 10 + randint0(100));
+                        (void)bss.stun(effects->stun()->current() + 10 + randint0(100));
                     }
                 } else if (one_in_(3))
                     apply_disenchant(player_ptr, 0);
index 6f5df8b..f971b64 100644 (file)
@@ -141,6 +141,7 @@ bool earthquake(player_type *player_ptr, POSITION cy, POSITION cx, POSITION r, M
         } else {
             auto effects = player_ptr->effects();
             auto stun_value = effects->stun()->current();
+            BadStatusSetter bss(player_ptr);
             switch (randint1(3)) {
             case 1: {
                 msg_print(_("降り注ぐ岩をうまく避けた!", "You nimbly dodge the blast!"));
@@ -150,13 +151,13 @@ bool earthquake(player_type *player_ptr, POSITION cy, POSITION cx, POSITION r, M
             case 2: {
                 msg_print(_("岩石があなたに直撃した!", "You are bashed by rubble!"));
                 damage = damroll(10, 4);
-                (void)set_stun(player_ptr, stun_value + randint1(50));
+                (void)bss.stun(stun_value + randint1(50));
                 break;
             }
             case 3: {
                 msg_print(_("あなたは床と壁との間に挟まれてしまった!", "You are crushed between the floor and ceiling!"));
                 damage = damroll(10, 4);
-                (void)set_stun(player_ptr, stun_value + randint1(50));
+                (void)bss.stun(stun_value + randint1(50));
                 break;
             }
             }
index 92426dd..b1d5fe6 100644 (file)
@@ -36,7 +36,7 @@ bool cleansing_nova(player_type *player_ptr, bool magic, bool powerful)
     if (hp_player(player_ptr, 50))
         ident = true;
 
-    if (set_stun(player_ptr, 0))
+    if (bss.stun(0))
         ident = true;
 
     if (set_cut(player_ptr, 0))
index ac1564e..a099a15 100644 (file)
@@ -286,7 +286,7 @@ bool life_stream(player_type *player_ptr, bool message, bool virtue_change)
     (void)bss.blindness(0);
     (void)bss.confusion(0);
     (void)bss.hallucination(0);
-    (void)set_stun(player_ptr, 0);
+    (void)bss.stun(0);
     (void)set_cut(player_ptr, 0);
     (void)bss.paralysis(0);
     (void)restore_all_status(player_ptr);
@@ -403,7 +403,7 @@ bool cure_critical_wounds(player_type *player_ptr, HIT_POINT pow)
         ident = true;
     }
 
-    if (set_stun(player_ptr, 0)) {
+    if (bss.stun(0)) {
         ident = true;
     }
 
@@ -438,7 +438,7 @@ bool true_healing(player_type *player_ptr, HIT_POINT pow)
         ident = true;
     }
 
-    if (set_stun(player_ptr, 0)) {
+    if (bss.stun(0)) {
         ident = true;
     }
 
index 0126379..60b5f94 100644 (file)
@@ -408,16 +408,19 @@ bool BadStatusSetter::slowness(TIME_EFFECT v, bool do_dec)
  * @details
  * Note the special code to only notice "range" changes.
  */
-bool set_stun(player_type *player_ptr, TIME_EFFECT v)
+bool BadStatusSetter::stun(TIME_EFFECT v)
 {
-    bool notice = false;
+    auto notice = false;
     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
-    if (player_ptr->is_dead)
+    if (this->player_ptr->is_dead) {
         return false;
-    if (PlayerRace(player_ptr).equals(player_race_type::GOLEM) || PlayerClass(player_ptr).can_resist_stun())
+    }
+
+    if (PlayerRace(this->player_ptr).equals(player_race_type::GOLEM) || PlayerClass(this->player_ptr).can_resist_stun()) {
         v = 0;
+    }
 
-    auto player_stun = player_ptr->effects()->stun();
+    auto player_stun = this->player_ptr->effects()->stun();
     auto old_aux = player_stun->get_rank();
     auto new_aux = PlayerStun::get_rank(v);
     if (new_aux > old_aux) {
@@ -425,35 +428,35 @@ bool set_stun(player_type *player_ptr, TIME_EFFECT v)
         msg_print(stun_mes.data());
         if (randint1(1000) < v || one_in_(16)) {
             msg_print(_("割れるような頭痛がする。", "A vicious blow hits your head."));
-
             if (one_in_(3)) {
-                if (!has_sustain_int(player_ptr))
-                    (void)do_dec_stat(player_ptr, A_INT);
-                if (!has_sustain_wis(player_ptr))
-                    (void)do_dec_stat(player_ptr, A_WIS);
+                if (!has_sustain_int(this->player_ptr))
+                    (void)do_dec_stat(this->player_ptr, A_INT);
+                if (!has_sustain_wis(this->player_ptr))
+                    (void)do_dec_stat(this->player_ptr, A_WIS);
             } else if (one_in_(2)) {
-                if (!has_sustain_int(player_ptr))
-                    (void)do_dec_stat(player_ptr, A_INT);
+                if (!has_sustain_int(this->player_ptr))
+                    (void)do_dec_stat(this->player_ptr, A_INT);
             } else {
-                if (!has_sustain_wis(player_ptr))
-                    (void)do_dec_stat(player_ptr, A_WIS);
+                if (!has_sustain_wis(this->player_ptr))
+                    (void)do_dec_stat(this->player_ptr, A_WIS);
             }
         }
 
-        if (player_ptr->special_defense & KATA_MASK) {
+        if (this->player_ptr->special_defense & KATA_MASK) {
             msg_print(_("型が崩れた。", "You lose your stance."));
-            player_ptr->special_defense &= ~(KATA_MASK);
-            player_ptr->update |= (PU_BONUS);
-            player_ptr->update |= (PU_MONSTERS);
-            player_ptr->redraw |= (PR_STATE);
-            player_ptr->redraw |= (PR_STATUS);
-            player_ptr->action = ACTION_NONE;
+            this->player_ptr->special_defense &= ~(KATA_MASK);
+            this->player_ptr->update |= (PU_BONUS);
+            this->player_ptr->update |= (PU_MONSTERS);
+            this->player_ptr->redraw |= (PR_STATE);
+            this->player_ptr->redraw |= (PR_STATUS);
+            this->player_ptr->action = ACTION_NONE;
         }
 
-        if (player_ptr->concent)
-            reset_concentration(player_ptr, true);
+        if (this->player_ptr->concent) {
+            reset_concentration(this->player_ptr, true);
+        }
 
-        SpellHex spell_hex(player_ptr);
+        SpellHex spell_hex(this->player_ptr);
         if (spell_hex.is_spelling_any()) {
             (void)spell_hex.stop_all_spells();
         }
@@ -462,8 +465,9 @@ bool set_stun(player_type *player_ptr, TIME_EFFECT v)
     } else if (new_aux < old_aux) {
         if (new_aux == PlayerStunRank::NONE) {
             msg_print(_("やっと朦朧状態から回復した。", "You are no longer stunned."));
-            if (disturb_state)
-                disturb(player_ptr, false, false);
+            if (disturb_state) {
+                disturb(this->player_ptr, false, false);
+            }
         }
 
         notice = true;
@@ -475,12 +479,12 @@ bool set_stun(player_type *player_ptr, TIME_EFFECT v)
     }
 
     if (disturb_state) {
-        disturb(player_ptr, false, false);
+        disturb(this->player_ptr, false, false);
     }
 
-    player_ptr->update |= PU_BONUS;
-    player_ptr->redraw |= PR_STUN;
-    handle_stuff(player_ptr);
+    this->player_ptr->update |= PU_BONUS;
+    this->player_ptr->redraw |= PR_STUN;
+    handle_stuff(this->player_ptr);
     return true;
 }
 
index 63afcde..cc79846 100644 (file)
@@ -16,10 +16,10 @@ public:
     bool paralysis(TIME_EFFECT v);
     bool hallucination(TIME_EFFECT v);
     bool slowness(TIME_EFFECT v, bool do_dec);
+    bool stun(TIME_EFFECT v);
 
 private:
     player_type *player_ptr;
 };
 
-bool set_stun(player_type *player_ptr, TIME_EFFECT v);
 bool set_cut(player_type *player_ptr, TIME_EFFECT v);