OSDN Git Service

[Refactor] #4169 TimedEffects::PlayerFear をshared_ptr から普通のクラスに差し替えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Tue, 28 May 2024 10:39:23 +0000 (19:39 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Tue, 28 May 2024 13:45:00 +0000 (22:45 +0900)
13 files changed:
src/cmd-action/cmd-attack.cpp
src/core/magic-effects-timeout-reducer.cpp
src/load/player-info-loader.cpp
src/mind/mind-samurai.cpp
src/player-info/self-info.cpp
src/save/player-writer.cpp
src/status/bad-status-setter.cpp
src/status/buff-setter.cpp
src/system/player-type-definition.cpp
src/timed-effect/player-fear.h
src/timed-effect/timed-effects.cpp
src/timed-effect/timed-effects.h
src/window/main-window-stat-poster.cpp

index 007f34b..782ab83 100644 (file)
@@ -47,7 +47,6 @@
 #include "system/monster-entity.h"
 #include "system/monster-race-info.h"
 #include "system/player-type-definition.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-hallucination.h"
 #include "timed-effect/player-stun.h"
 #include "timed-effect/timed-effects.h"
@@ -250,7 +249,7 @@ bool do_cmd_attack(PlayerType *player_ptr, POSITION y, POSITION x, combat_option
         }
     }
 
-    if (effects->fear()->is_fearful()) {
+    if (effects->fear().is_fearful()) {
         if (m_ptr->ml) {
             sound(SOUND_ATTACK_FAILED);
             msg_format(_("恐くて%sを攻撃できない!", "You are too fearful to attack %s!"), m_name.data());
index 0e16dbd..e0d772c 100644 (file)
@@ -19,7 +19,6 @@
 #include "system/player-type-definition.h"
 #include "timed-effect/player-acceleration.h"
 #include "timed-effect/player-deceleration.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-hallucination.h"
 #include "timed-effect/player-paralysis.h"
 #include "timed-effect/player-poison.h"
@@ -140,7 +139,7 @@ void reduce_magic_effects_timeout(PlayerType *player_ptr)
         (void)bss.mod_confusion(-1);
     }
 
-    if (effects->fear()->is_fearful()) {
+    if (effects->fear().is_fearful()) {
         (void)bss.mod_fear(-1);
     }
 
index 45a7e5d..b3d8b7c 100644 (file)
@@ -26,7 +26,6 @@
 #include "system/player-type-definition.h"
 #include "timed-effect/player-acceleration.h"
 #include "timed-effect/player-deceleration.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-hallucination.h"
 #include "timed-effect/player-paralysis.h"
 #include "timed-effect/player-poison.h"
@@ -366,7 +365,7 @@ static void rd_status(PlayerType *player_ptr)
     const auto effects = player_ptr->effects();
     effects->acceleration()->set(rd_s16b());
     effects->deceleration()->set(rd_s16b());
-    effects->fear()->set(rd_s16b());
+    effects->fear().set(rd_s16b());
     effects->cut().set(rd_s16b());
     effects->stun()->set(rd_s16b());
     effects->poison()->set(rd_s16b());
index 4002d5f..81db139 100644 (file)
@@ -35,7 +35,6 @@
 #include "system/redrawing-flags-updater.h"
 #include "term/screen-processor.h"
 #include "term/z-form.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-stun.h"
 #include "timed-effect/timed-effects.h"
 #include "util/bit-flags-calculator.h"
@@ -384,7 +383,7 @@ bool choose_samurai_stance(PlayerType *player_ptr)
         return false;
     }
 
-    if (effects->fear()->is_fearful()) {
+    if (effects->fear().is_fearful()) {
         msg_print(_("体が震えて構えられない!", "You are trembling with fear!"));
         return false;
     }
index f0e928e..d32df9f 100644 (file)
@@ -30,7 +30,6 @@
 #include "term/gameterm.h"
 #include "term/screen-processor.h"
 #include "term/z-form.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-hallucination.h"
 #include "timed-effect/player-poison.h"
 #include "timed-effect/player-stun.h"
@@ -48,7 +47,7 @@ static void set_bad_status_info(PlayerType *player_ptr, self_info_type *self_ptr
         self_ptr->info_list.emplace_back(_("あなたは混乱している。", "You are confused."));
     }
 
-    if (effects->fear()->is_fearful()) {
+    if (effects->fear().is_fearful()) {
         self_ptr->info_list.emplace_back(_("あなたは恐怖に侵されている。", "You are terrified."));
     }
 
@@ -330,8 +329,9 @@ void report_magics(PlayerType *player_ptr)
             _("あなたは混乱している", "You are confused"));
     }
 
-    if (effects->fear()->is_fearful()) {
-        info.emplace_back(report_magics_aux(effects->fear()->current()),
+    const auto &fear = effects->fear();
+    if (fear.is_fearful()) {
+        info.emplace_back(report_magics_aux(fear.current()),
             _("あなたは恐怖に侵されている", "You are terrified"));
     }
 
@@ -341,7 +341,7 @@ void report_magics(PlayerType *player_ptr)
             _("あなたは毒に侵されている", "You are poisoned"));
     }
 
-    auto hallucination = effects->hallucination();
+    const auto hallucination = effects->hallucination();
     if (hallucination->is_hallucinated()) {
         info.emplace_back(report_magics_aux(hallucination->current()),
             _("あなたは幻覚を見ている", "You are hallucinating"));
index 9cc7f06..ec7a044 100644 (file)
@@ -13,7 +13,6 @@
 #include "system/player-type-definition.h"
 #include "timed-effect/player-acceleration.h"
 #include "timed-effect/player-deceleration.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-hallucination.h"
 #include "timed-effect/player-paralysis.h"
 #include "timed-effect/player-poison.h"
@@ -168,7 +167,7 @@ void wr_player(PlayerType *player_ptr)
     wr_s16b(player_ptr->enchant_energy_need);
     wr_s16b(effects->acceleration()->current());
     wr_s16b(effects->deceleration()->current());
-    wr_s16b(effects->fear()->current());
+    wr_s16b(effects->fear().current());
     wr_s16b(effects->cut().current());
     wr_s16b(effects->stun()->current());
     wr_s16b(effects->poison()->current());
index ddeb205..b2acb45 100644 (file)
@@ -20,7 +20,6 @@
 #include "system/player-type-definition.h"
 #include "system/redrawing-flags-updater.h"
 #include "timed-effect/player-deceleration.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-hallucination.h"
 #include "timed-effect/player-paralysis.h"
 #include "timed-effect/player-poison.h"
@@ -247,9 +246,9 @@ bool BadStatusSetter::set_fear(const TIME_EFFECT tmp_v)
         return false;
     }
 
-    auto fear = this->player_ptr->effects()->fear();
+    auto &fear = this->player_ptr->effects()->fear();
     if (v > 0) {
-        if (!fear->is_fearful()) {
+        if (!fear.is_fearful()) {
             msg_print(_("何もかも恐くなってきた!", "You are terrified!"));
             if (PlayerClass(this->player_ptr).lose_balance()) {
                 msg_print(_("型が崩れた。", "You lose your stance."));
@@ -260,13 +259,13 @@ bool BadStatusSetter::set_fear(const TIME_EFFECT tmp_v)
             chg_virtue(this->player_ptr, Virtue::VALOUR, -1);
         }
     } else {
-        if (fear->is_fearful()) {
+        if (fear.is_fearful()) {
             msg_print(_("やっと恐怖を振り払った。", "You feel bolder now."));
             notice = true;
         }
     }
 
-    fear->set(v);
+    fear.set(v);
     RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::TIMED_EFFECT);
     if (!notice) {
         return false;
@@ -282,7 +281,7 @@ bool BadStatusSetter::set_fear(const TIME_EFFECT tmp_v)
 
 bool BadStatusSetter::mod_fear(const TIME_EFFECT tmp_v)
 {
-    return this->set_fear(this->player_ptr->effects()->fear()->current() + tmp_v);
+    return this->set_fear(this->player_ptr->effects()->fear().current() + tmp_v);
 }
 
 /*!
index 7416c12..10be887 100644 (file)
@@ -20,7 +20,6 @@
 #include "system/redrawing-flags-updater.h"
 #include "timed-effect/player-acceleration.h"
 #include "timed-effect/player-deceleration.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-hallucination.h"
 #include "timed-effect/player-paralysis.h"
 #include "timed-effect/player-poison.h"
@@ -40,7 +39,7 @@ void reset_tim_flags(PlayerType *player_ptr)
     effects->blindness().reset();
     effects->paralysis()->reset();
     effects->confusion().reset();
-    effects->fear()->reset();
+    effects->fear().reset();
     effects->hallucination()->reset();
     effects->poison()->reset();
     effects->cut().reset();
index 4a0e58c..6d0bcd0 100644 (file)
@@ -4,7 +4,6 @@
 #include "system/angband-exceptions.h"
 #include "system/redrawing-flags-updater.h"
 #include "timed-effect/player-deceleration.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-hallucination.h"
 #include "timed-effect/player-paralysis.h"
 #include "timed-effect/player-poison.h"
@@ -50,7 +49,7 @@ bool PlayerType::is_fully_healthy() const
     is_fully_healthy &= !effects->blindness().is_blind();
     is_fully_healthy &= !effects->confusion().is_confused();
     is_fully_healthy &= !effects->poison()->is_poisoned();
-    is_fully_healthy &= !effects->fear()->is_fearful();
+    is_fully_healthy &= !effects->fear().is_fearful();
     is_fully_healthy &= !effects->stun()->is_stunned();
     is_fully_healthy &= !effects->cut().is_cut();
     is_fully_healthy &= !effects->deceleration()->is_slow();
index 76547b7..645b77d 100644 (file)
@@ -3,6 +3,11 @@
 class PlayerFear {
 public:
     PlayerFear() = default;
+    ~PlayerFear() = default;
+    PlayerFear(const PlayerFear &) = delete;
+    PlayerFear(PlayerFear &&) = delete;
+    PlayerFear &operator=(const PlayerFear &) = delete;
+    PlayerFear &operator=(PlayerFear &&) = delete;
 
     short current() const;
     bool is_fearful() const;
index 88f6e3b..69b9daa 100644 (file)
@@ -7,15 +7,13 @@
 #include "timed-effect/timed-effects.h"
 #include "timed-effect/player-acceleration.h"
 #include "timed-effect/player-deceleration.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-hallucination.h"
 #include "timed-effect/player-paralysis.h"
 #include "timed-effect/player-poison.h"
 #include "timed-effect/player-stun.h"
 
 TimedEffects::TimedEffects()
-    : player_fear(std::make_shared<PlayerFear>())
-    , player_hallucination(std::make_shared<PlayerHallucination>())
+    : player_hallucination(std::make_shared<PlayerHallucination>())
     , player_paralysis(std::make_shared<PlayerParalysis>())
     , player_stun(std::make_shared<PlayerStun>())
     , player_acceleration(std::make_shared<PlayerAcceleration>())
@@ -54,7 +52,12 @@ const PlayerCut &TimedEffects::cut() const
     return this->player_cut;
 }
 
-std::shared_ptr<PlayerFear> TimedEffects::fear() const
+PlayerFear &TimedEffects::fear()
+{
+    return this->player_fear;
+}
+
+const PlayerFear &TimedEffects::fear() const
 {
     return this->player_fear;
 }
index f1b3b69..62225b1 100644 (file)
@@ -3,11 +3,11 @@
 #include "timed-effect/player-blindness.h"
 #include "timed-effect/player-confusion.h"
 #include "timed-effect/player-cut.h"
+#include "timed-effect/player-fear.h"
 #include <memory>
 
 class PlayerAcceleration;
 class PlayerDeceleration;
-class PlayerFear;
 class PlayerHallucination;
 class PlayerParalysis;
 class PlayerPoison;
@@ -27,7 +27,8 @@ public:
     const PlayerConfusion &confusion() const;
     PlayerCut &cut();
     const PlayerCut &cut() const;
-    std::shared_ptr<PlayerFear> fear() const;
+    PlayerFear &fear();
+    const PlayerFear &fear() const;
     std::shared_ptr<PlayerHallucination> hallucination() const;
     std::shared_ptr<PlayerParalysis> paralysis() const;
     std::shared_ptr<PlayerStun> stun() const;
@@ -39,7 +40,7 @@ private:
     PlayerBlindness player_blindness{};
     PlayerConfusion player_confusion{};
     PlayerCut player_cut{};
-    std::shared_ptr<PlayerFear> player_fear;
+    PlayerFear player_fear{};
     std::shared_ptr<PlayerHallucination> player_hallucination;
     std::shared_ptr<PlayerParalysis> player_paralysis;
     std::shared_ptr<PlayerStun> player_stun;
index f0db833..f8390c2 100644 (file)
@@ -24,7 +24,6 @@
 #include "term/term-color-types.h"
 #include "term/z-form.h"
 #include "timed-effect/player-deceleration.h"
-#include "timed-effect/player-fear.h"
 #include "timed-effect/player-hallucination.h"
 #include "timed-effect/player-paralysis.h"
 #include "timed-effect/player-poison.h"
@@ -587,7 +586,7 @@ void print_status(PlayerType *player_ptr)
         ADD_BAR_FLAG(BAR_ALTER);
     }
 
-    if (effects->fear()->is_fearful()) {
+    if (effects->fear().is_fearful()) {
         ADD_BAR_FLAG(BAR_AFRAID);
     }