OSDN Git Service

Merge pull request #3324 from habu1010/feature/fix-refrect-subwindows-on-perception
authorHabu <habu1010+github@gmail.com>
Sat, 20 May 2023 13:34:37 +0000 (22:34 +0900)
committerGitHub <noreply@github.com>
Sat, 20 May 2023 13:34:37 +0000 (22:34 +0900)
[Refactor] *鑑定*時のサブウィンドウ更新処理

12 files changed:
src/cmd-io/cmd-diary.cpp
src/effect/effect-player-resist-hurt.cpp
src/effect/effect-player-resist-hurt.h
src/mspell/summon-checker.cpp
src/player-base/player-class.cpp
src/player-base/player-class.h
src/player-base/player-race.cpp
src/player-base/player-race.h
src/player-info/race-info.cpp
src/player-info/race-info.h
src/player/player-damage.cpp
src/player/player-damage.h

index 3c6fdb2..500c081 100644 (file)
@@ -1,5 +1,4 @@
 #include "cmd-io/cmd-diary.h"
-#include "cmd-io/diary-subtitle-table.h"
 #include "core/asking-player.h"
 #include "core/show-file.h"
 #include "game-option/play-record-options.h"
 #include "util/int-char-converter.h"
 #include "view/display-messages.h"
 #include "world/world.h"
-#include <span>
 #include <sstream>
 #include <string>
 
 /*!
- * @brief 日記のサブタイトルの候補一覧を取得する
- *
- * 候補一覧の先頭は「最高の肉体を求めて」、末尾は「最高の頭脳を求めて」で
- * あるため、プレイヤーの職業に従い範囲を決定する。
- *
- * @return 候補一覧を参照するstd::spanオブジェクト
- */
-static auto get_subtitle_candidates(PlayerType *player_ptr)
-{
-    std::span<const std::string> candidates(diary_subtitles);
-    const auto max = diary_subtitles.size();
-
-    PlayerClass pc(player_ptr);
-
-    if (pc.is_tough()) {
-        return candidates.subspan(0, max - 1);
-    }
-
-    if (pc.is_wizard()) {
-        return candidates.subspan(1);
-    }
-
-    return candidates.subspan(1, max - 2);
-}
-
-/*!
  * @brief 日記のタイトル表記と内容出力
  * @param player_ptr プレイヤーへの参照ポインタ
  */
 static void display_diary(PlayerType *player_ptr)
 {
-    const auto subtitle_candidates = get_subtitle_candidates(player_ptr);
+    const auto subtitle_candidates = PlayerClass(player_ptr).get_subtitle_candidates();
     const auto choice = Rand_external(subtitle_candidates.size());
     const auto &subtitle = subtitle_candidates[choice];
 #ifdef JP
index ce15721..4c7fe14 100644 (file)
@@ -37,7 +37,7 @@
 
 // 毒を除く4元素.
 void effect_player_elements(
-    PlayerType *player_ptr, EffectPlayerType *ep_ptr, concptr attack_message, int (*damage_func)(PlayerType *, int, concptr, bool))
+    PlayerType *player_ptr, EffectPlayerType *ep_ptr, std::string_view attack_message, int (*damage_func)(PlayerType *, int, std::string_view, bool))
 {
     if (player_ptr->effects()->blindness()->is_blind()) {
         msg_print(attack_message);
index f223ddd..b3a9120 100644 (file)
@@ -1,11 +1,11 @@
 #pragma once
 
-#include "system/angband.h"
+#include <string_view>
 
 class EffectPlayerType;
 class PlayerType;
 void effect_player_elements(
-    PlayerType *player_ptr, EffectPlayerType *ep_ptr, concptr attack_message, int (*damage_func)(PlayerType *, int, concptr, bool));
+    PlayerType *player_ptr, EffectPlayerType *ep_ptr, std::string_view attack_message, int (*damage_func)(PlayerType *, int, std::string_view, bool));
 void effect_player_poison(PlayerType *player_ptr, EffectPlayerType *ep_ptr);
 void effect_player_nuke(PlayerType *player_ptr, EffectPlayerType *ep_ptr);
 void effect_player_missile(PlayerType *player_ptr, EffectPlayerType *ep_ptr);
index 307f2cb..c5960a5 100644 (file)
@@ -9,7 +9,7 @@
 #include "monster-race/race-flags8.h"
 #include "monster-race/race-indice-types.h"
 #include "monster/monster-util.h"
-#include "player-info/race-info.h"
+#include "player-base/player-race.h"
 #include "spell/summon-types.h"
 #include "system/monster-race-info.h"
 #include "system/player-type-definition.h"
@@ -87,7 +87,7 @@ bool check_summon_specific(PlayerType *player_ptr, MonsterRaceId summoner_idx, M
         is_match = (r_ptr->d_char == 'U') && r_ptr->ability_flags.has(MonsterAbilityType::ROCKET);
         break;
     case SUMMON_KIN: {
-        auto summon_kin_type = MonsterRace(summoner_idx).is_valid() ? monraces_info[summoner_idx].d_char : get_summon_symbol_from_player(player_ptr);
+        auto summon_kin_type = MonsterRace(summoner_idx).is_valid() ? monraces_info[summoner_idx].d_char : PlayerRace(player_ptr).get_summon_symbol();
         is_match = (r_ptr->d_char == summon_kin_type) && (r_idx != MonsterRaceId::HAGURE);
         break;
     }
index 7ce373c..c1650da 100644 (file)
@@ -5,6 +5,7 @@
  * @details PlayerRaceからPlayerClassへの依存はあるが、逆は依存させないこと.
  */
 #include "player-base/player-class.h"
+#include "cmd-io/diary-subtitle-table.h"
 #include "core/player-redraw-types.h"
 #include "inventory/inventory-slot-types.h"
 #include "mind/mind-elementalist.h"
@@ -536,3 +537,26 @@ bool PlayerClass::has_ninja_speed() const
     has_ninja_speed_sub |= can_attack_with_sub_hand(this->player_ptr);
     return has_ninja_speed_main && has_ninja_speed_sub;
 }
+
+/*!
+ * @brief 日記のサブタイトルの候補一覧を取得する
+ *
+ * 候補一覧の先頭は「最高の肉体を求めて」、末尾は「最高の頭脳を求めて」で
+ * あるため、プレイヤーの職業に従い範囲を決定する。
+ *
+ * @return 候補一覧を参照するstd::spanオブジェクト
+ */
+std::span<const std::string> PlayerClass::get_subtitle_candidates() const
+{
+    static const std::span<const std::string> candidates(diary_subtitles);
+    const auto max = diary_subtitles.size();
+    if (this->is_tough()) {
+        return candidates.subspan(0, max - 1);
+    }
+
+    if (this->is_wizard()) {
+        return candidates.subspan(1);
+    }
+
+    return candidates.subspan(1, max - 2);
+}
index b2498c1..f6c57c7 100644 (file)
@@ -1,12 +1,10 @@
 #pragma once
 
-#include "system/angband.h"
-
 #include "object-enchant/tr-flags.h"
 #include "system/player-type-definition.h"
-
 #include <initializer_list>
 #include <memory>
+#include <span>
 #include <variant>
 
 enum class SamuraiStanceType : uint8_t;
@@ -49,6 +47,7 @@ public:
     std::shared_ptr<T> get_specific_data() const;
 
     bool has_ninja_speed() const;
+    std::span<const std::string> get_subtitle_candidates() const;
 
 private:
     PlayerType *player_ptr;
index 1b2852a..f65a893 100644 (file)
@@ -248,3 +248,24 @@ int16_t PlayerRace::additional_constitution() const
 
     return result;
 }
+
+/*!
+ * @brief 救援召喚時のモンスターシンボルを返す
+ * @param player_ptr プレイヤー情報への参照ポインタ
+ * @return シンボル文字
+ */
+char PlayerRace::get_summon_symbol() const
+{
+    auto symbol = 'N';
+    auto mmc_ptr = this->get_info();
+
+    auto l = strlen(mmc_ptr->symbol);
+    auto mul = 1;
+    for (size_t i = 0; i < l; i++) {
+        if (one_in_(mul)) {
+            symbol = mmc_ptr->symbol[i];
+        }
+        mul *= 13;
+    }
+    return symbol;
+}
index 85e243c..5bcdfb4 100644 (file)
@@ -26,6 +26,7 @@ public:
     int16_t additional_strength() const;
     int16_t additional_dexterity() const;
     int16_t additional_constitution() const;
+    char get_summon_symbol() const;
 
 private:
     PlayerType *player_ptr;
index a27920e..c35e0a4 100644 (file)
@@ -1,34 +1,3 @@
 #include "player-info/race-info.h"
-#include "core/player-redraw-types.h"
-#include "inventory/inventory-slot-types.h"
-#include "player-base/player-race.h"
-#include "player-info/mimic-info-table.h"
-#include "player-info/race-types.h"
-#include "player/race-info-table.h"
-#include "system/item-entity.h"
-#include "system/player-type-definition.h"
-#include "util/bit-flags-calculator.h"
-#include "util/enum-converter.h"
 
 const player_race_info *rp_ptr;
-
-/*!
- * @brief 救援召喚時のモンスターシンボルを返す
- * @param player_ptr プレイヤー情報への参照ポインタ
- * @return シンボル文字
- */
-char get_summon_symbol_from_player(PlayerType *player_ptr)
-{
-    auto symbol = 'N';
-    auto mmc_ptr = PlayerRace(player_ptr).get_info();
-
-    auto l = strlen(mmc_ptr->symbol);
-    auto mul = 1;
-    for (size_t i = 0; i < l; i++) {
-        if (one_in_(mul)) {
-            symbol = mmc_ptr->symbol[i];
-        }
-        mul *= 13;
-    }
-    return symbol;
-}
index 5242754..1b7cc66 100644 (file)
@@ -109,6 +109,3 @@ struct player_race_info {
 };
 
 extern const player_race_info *rp_ptr;
-
-class PlayerType;
-char get_summon_symbol_from_player(PlayerType *player_ptr);
index c14716c..0a826e7 100644 (file)
@@ -76,7 +76,7 @@
 #include <sstream>
 #include <string>
 
-using dam_func = int (*)(PlayerType *player_ptr, int dam, concptr kb_str, bool aura);
+using dam_func = int (*)(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura);
 
 /*!
  * @brief 酸攻撃による装備のAC劣化処理 /
@@ -139,7 +139,7 @@ static bool acid_minus_ac(PlayerType *player_ptr)
  * @return 修正HPダメージ量
  * @details 酸オーラは存在しないが関数ポインタのために引数だけは用意している
  */
-int acid_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
+int acid_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
 {
     int inv = (dam < 30) ? 1 : (dam < 60) ? 2
                                           : 3;
@@ -177,7 +177,7 @@ int acid_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
  * @param aura オーラよるダメージが原因ならばTRUE
  * @return 修正HPダメージ量
  */
-int elec_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
+int elec_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
 {
     int inv = (dam < 30) ? 1 : (dam < 60) ? 2
                                           : 3;
@@ -213,7 +213,7 @@ int elec_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
  * @param aura オーラよるダメージが原因ならばTRUE
  * @return 修正HPダメージ量
  */
-int fire_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
+int fire_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
 {
     int inv = (dam < 30) ? 1 : (dam < 60) ? 2
                                           : 3;
@@ -249,7 +249,7 @@ int fire_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
  * @param aura オーラよるダメージが原因ならばTRUE
  * @return 修正HPダメージ量
  */
-int cold_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
+int cold_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
 {
     int inv = (dam < 30) ? 1 : (dam < 60) ? 2
                                           : 3;
@@ -282,7 +282,7 @@ int cold_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
  * the game when he dies, since the "You die." message is shown before
  * setting the player to "dead".
  */
-int take_hit(PlayerType *player_ptr, int damage_type, int damage, concptr hit_from)
+int take_hit(PlayerType *player_ptr, int damage_type, int damage, std::string_view hit_from)
 {
     int old_chp = player_ptr->chp;
     int warning = (player_ptr->mhp * hitpoint_warn / 10);
@@ -385,9 +385,9 @@ int take_hit(PlayerType *player_ptr, int damage_type, int damage, concptr hit_fr
                 exe_write_diary(player_ptr, DIARY_ARENA, -1 - player_ptr->arena_number, m_name);
             }
         } else {
-            auto q_idx = quest_number(player_ptr, floor_ref.dun_level);
-            bool seppuku = streq(hit_from, "Seppuku");
-            bool winning_seppuku = w_ptr->total_winner && seppuku;
+            const auto q_idx = quest_number(player_ptr, floor_ref.dun_level);
+            const auto seppuku = hit_from == "Seppuku";
+            const auto winning_seppuku = w_ptr->total_winner && seppuku;
 
             play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
 
@@ -409,9 +409,9 @@ int take_hit(PlayerType *player_ptr, int damage_type, int damage, concptr hit_fr
 
                 auto hallucintion_state = is_hallucinated ? _("幻覚に歪んだ", "hallucinatingly distorted ") : "";
 #ifdef JP
-                player_ptr->died_from = format("%s%s%s", paralysis_state, hallucintion_state, hit_from);
+                player_ptr->died_from = format("%s%s%s", paralysis_state, hallucintion_state, hit_from.data());
 #else
-                player_ptr->died_from = format("%s%s%s", hallucintion_state, hit_from, paralysis_state);
+                player_ptr->died_from = format("%s%s%s", hallucintion_state, hit_from.data(), paralysis_state);
 #endif
             }
 
index 03afec3..56debe1 100644 (file)
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "system/angband.h"
+#include <string_view>
 
 #define DAMAGE_FORCE 1
 #define DAMAGE_GENO 2
@@ -11,9 +11,9 @@
 
 class MonsterEntity;
 class PlayerType;
-int take_hit(PlayerType *player_ptr, int damage_type, int damage, concptr kb_str);
-int acid_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura);
-int elec_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura);
-int fire_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura);
-int cold_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura);
+int take_hit(PlayerType *player_ptr, int damage_type, int damage, std::string_view kb_str);
+int acid_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura);
+int elec_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura);
+int fire_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura);
+int cold_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura);
 void touch_zap_player(MonsterEntity *m_ptr, PlayerType *player_ptr);