From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sat, 8 Jun 2024 08:55:33 +0000 (+0900) Subject: [Refactor] lore_do_probe() をMonraceList とMonsterRaceInfo にそれぞれ移植した X-Git-Tag: 3.0.1.15-Beta~17^2~3 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=6b97994909f31e384ee28ab5092cfc86a9c5d4cd;p=hengbandforosx%2Fhengbandosx.git [Refactor] lore_do_probe() をMonraceList とMonsterRaceInfo にそれぞれ移植した --- diff --git a/src/core/stuff-handler.cpp b/src/core/stuff-handler.cpp index 8dd06d95c..619e25d24 100644 --- a/src/core/stuff-handler.cpp +++ b/src/core/stuff-handler.cpp @@ -3,7 +3,6 @@ #include "player/player-status.h" #include "system/player-type-definition.h" #include "system/redrawing-flags-updater.h" -#include "tracking/lore-tracker.h" /*! * @brief 全更新処理をチェックして処理していく diff --git a/src/lore/lore-store.cpp b/src/lore/lore-store.cpp index e7ff70ce9..6ba4fe978 100644 --- a/src/lore/lore-store.cpp +++ b/src/lore/lore-store.cpp @@ -14,99 +14,6 @@ #include "system/redrawing-flags-updater.h" #include "tracking/lore-tracker.h" -template -static int count_lore_mflag_group(const EnumClassFlagGroup &flags, const EnumClassFlagGroup &r_flags) -{ - auto result_flags = flags; - auto num = result_flags.reset(r_flags).count(); - return num; -} - -/*! - * @brief モンスターの調査による思い出補完処理 - * @param monrace_id 補完されるモンスター種族ID - * @return 何か追加で明らかになったか否か - */ -bool lore_do_probe(MonsterRaceId monrace_id) -{ - auto &monrace = monraces_info[monrace_id]; - auto n = false; - if (monrace.r_wake != MAX_UCHAR) { - n = true; - } - - if (monrace.r_ignore != MAX_UCHAR) { - n = true; - } - - monrace.r_wake = MAX_UCHAR; - monrace.r_ignore = MAX_UCHAR; - for (auto i = 0; i < 4; i++) { - const auto &blow = monrace.blows[i]; - if ((blow.effect != RaceBlowEffectType::NONE) || (blow.method != RaceBlowMethodType::NONE)) { - if (monrace.r_blows[i] != MAX_UCHAR) { - n = true; - } - - monrace.r_blows[i] = MAX_UCHAR; - } - } - - using Mdt = MonsterDropType; - auto num_drops = (monrace.drop_flags.has(Mdt::DROP_4D2) ? 8 : 0); - num_drops += (monrace.drop_flags.has(Mdt::DROP_3D2) ? 6 : 0); - num_drops += (monrace.drop_flags.has(Mdt::DROP_2D2) ? 4 : 0); - num_drops += (monrace.drop_flags.has(Mdt::DROP_1D2) ? 2 : 0); - num_drops += (monrace.drop_flags.has(Mdt::DROP_90) ? 1 : 0); - num_drops += (monrace.drop_flags.has(Mdt::DROP_60) ? 1 : 0); - if (monrace.drop_flags.has_not(Mdt::ONLY_GOLD)) { - if (monrace.r_drop_item != num_drops) { - n = true; - } - - monrace.r_drop_item = num_drops; - } - - if (monrace.drop_flags.has_not(Mdt::ONLY_ITEM)) { - if (monrace.r_drop_gold != num_drops) { - n = true; - } - - monrace.r_drop_gold = num_drops; - } - - if (monrace.r_cast_spell != MAX_UCHAR) { - n = true; - } - - monrace.r_cast_spell = MAX_UCHAR; - n |= count_lore_mflag_group(monrace.resistance_flags, monrace.r_resistance_flags) > 0; - n |= count_lore_mflag_group(monrace.ability_flags, monrace.r_ability_flags) > 0; - n |= count_lore_mflag_group(monrace.behavior_flags, monrace.r_behavior_flags) > 0; - n |= count_lore_mflag_group(monrace.drop_flags, monrace.r_drop_flags) > 0; - n |= count_lore_mflag_group(monrace.feature_flags, monrace.r_feature_flags) > 0; - n |= count_lore_mflag_group(monrace.special_flags, monrace.r_special_flags) > 0; - n |= count_lore_mflag_group(monrace.misc_flags, monrace.r_misc_flags) > 0; - - monrace.r_resistance_flags = monrace.resistance_flags; - monrace.r_ability_flags = monrace.ability_flags; - monrace.r_behavior_flags = monrace.behavior_flags; - monrace.r_drop_flags = monrace.drop_flags; - monrace.r_feature_flags = monrace.feature_flags; - monrace.r_special_flags = monrace.special_flags; - monrace.r_misc_flags = monrace.misc_flags; - if (!monrace.r_can_evolve) { - n = true; - } - - monrace.r_can_evolve = true; - if (LoreTracker::get_instance().is_tracking(monrace_id)) { - RedrawingFlagsUpdater::get_instance().set_flag(SubWindowRedrawingFlag::MONSTER_LORE); - } - - return n; -} - /*! * @brief モンスターの撃破に伴うドロップ情報の記憶処理 * @param num_item 手に入れたアイテム数 diff --git a/src/lore/lore-store.h b/src/lore/lore-store.h index e9a9286be..5e411e125 100644 --- a/src/lore/lore-store.h +++ b/src/lore/lore-store.h @@ -2,5 +2,4 @@ enum class MonsterRaceId : short; class MonsterEntity; -bool lore_do_probe(MonsterRaceId r_idx); void lore_treasure(const MonsterEntity &monster, int num_item, int num_gold); diff --git a/src/market/building-monster.cpp b/src/market/building-monster.cpp index e34c66835..e84befd4b 100644 --- a/src/market/building-monster.cpp +++ b/src/market/building-monster.cpp @@ -73,7 +73,7 @@ bool research_mon(PlayerType *player_ptr) prt(buf, 16, 10); std::vector monrace_ids; - const auto &monraces = MonraceList::get_instance(); + auto &monraces = MonraceList::get_instance(); for (const auto &[monrace_id, monrace] : monraces) { if (!monrace.is_valid()) { continue; @@ -146,7 +146,7 @@ bool research_mon(PlayerType *player_ptr) term_addstr(-1, TERM_WHITE, _(" ['r'思い出, ' 'で続行, ESC]", " [(r)ecall, ESC, space to continue]")); while (true) { if (recall) { - if (lore_do_probe(monrace_id)) { + if (monraces.probe_lore(monrace_id)) { const auto &monrace = monraces.get_monrace(monrace_id); #ifdef JP msg_format("%sについてさらに詳しくなった気がする。", monrace.name.data()); diff --git a/src/player-attack/attack-chaos-effect.cpp b/src/player-attack/attack-chaos-effect.cpp index 016a9178e..4a0ac104b 100644 --- a/src/player-attack/attack-chaos-effect.cpp +++ b/src/player-attack/attack-chaos-effect.cpp @@ -162,7 +162,7 @@ static void attack_probe(PlayerType *player_ptr, player_attack_type *pa_ptr) msg_print(nullptr); msg_print(probed_monster_info(player_ptr, pa_ptr->m_ptr, pa_ptr->r_ptr)); msg_print(nullptr); - if (lore_do_probe(pa_ptr->r_idx)) { + if (MonraceList::get_instance().probe_lore(pa_ptr->r_idx)) { #ifdef JP msg_format("%sについてさらに詳しくなった気がする。", pa_ptr->r_ptr->name.data()); #else diff --git a/src/spell-kind/spells-sight.cpp b/src/spell-kind/spells-sight.cpp index 98ec14134..5231ab048 100644 --- a/src/spell-kind/spells-sight.cpp +++ b/src/spell-kind/spells-sight.cpp @@ -27,6 +27,7 @@ #include "system/redrawing-flags-updater.h" #include "target/projection-path-calculator.h" #include "term/screen-processor.h" +#include "tracking/lore-tracker.h" #include "view/display-messages.h" /*! @@ -469,7 +470,7 @@ bool probing(PlayerType *player_ptr) move_cursor_relative(monster.fy, monster.fx); inkey(); term_erase(0, 0); - if (lore_do_probe(monster.r_idx)) { + if (monrace.probe_lore()) { #ifdef JP msg_format("%sについてさらに詳しくなった気がする。", monrace.name.data()); #else @@ -477,6 +478,9 @@ bool probing(PlayerType *player_ptr) msg_format("You now know more about %s.", nm.data()); #endif msg_print(nullptr); + if (LoreTracker::get_instance().is_tracking(monster.r_idx)) { + RedrawingFlagsUpdater::get_instance().set_flag(SubWindowRedrawingFlag::MONSTER_LORE); + } } probe = true; diff --git a/src/system/monster-race-info.cpp b/src/system/monster-race-info.cpp index 2ba68e2db..8bb68fe83 100644 --- a/src/system/monster-race-info.cpp +++ b/src/system/monster-race-info.cpp @@ -2,10 +2,22 @@ #include "monster-race/race-indice-types.h" #include "monster-race/race-resistance-mask.h" #include "monster/horror-descriptions.h" +#include "system/redrawing-flags-updater.h" +#include "tracking/lore-tracker.h" #include "util/probability-table.h" #include "world/world.h" #include +namespace { +template +static int count_lore_mflag_group(const EnumClassFlagGroup &flags, const EnumClassFlagGroup &r_flags) +{ + auto result_flags = flags; + auto num = result_flags.reset(r_flags).count(); + return num; +} +} + std::map monraces_info; MonsterRaceInfo::MonsterRaceInfo() @@ -222,13 +234,88 @@ int MonsterRaceInfo::calc_capture_value() const * @return 反応メッセージ * @details 実際に見るとは限らない (悪夢モードで宿に泊まった時など) */ -std::string MonsterRaceInfo::build_eldritch_horror_message(std::string_view description) +std::string MonsterRaceInfo::build_eldritch_horror_message(std::string_view description) const { const auto &horror_message = this->decide_horror_message(); constexpr auto fmt = _("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"); return format(fmt, horror_message.data(), description.data()); } +bool MonsterRaceInfo::probe_lore() +{ + auto n = false; + if (this->r_wake != MAX_UCHAR) { + n = true; + } + + if (this->r_ignore != MAX_UCHAR) { + n = true; + } + + this->r_wake = MAX_UCHAR; + this->r_ignore = MAX_UCHAR; + for (auto i = 0; i < 4; i++) { + const auto &blow = this->blows[i]; + if ((blow.effect != RaceBlowEffectType::NONE) || (blow.method != RaceBlowMethodType::NONE)) { + if (this->r_blows[i] != MAX_UCHAR) { + n = true; + } + + this->r_blows[i] = MAX_UCHAR; + } + } + + using Mdt = MonsterDropType; + auto num_drops = (this->drop_flags.has(Mdt::DROP_4D2) ? 8 : 0); + num_drops += (this->drop_flags.has(Mdt::DROP_3D2) ? 6 : 0); + num_drops += (this->drop_flags.has(Mdt::DROP_2D2) ? 4 : 0); + num_drops += (this->drop_flags.has(Mdt::DROP_1D2) ? 2 : 0); + num_drops += (this->drop_flags.has(Mdt::DROP_90) ? 1 : 0); + num_drops += (this->drop_flags.has(Mdt::DROP_60) ? 1 : 0); + if (this->drop_flags.has_not(Mdt::ONLY_GOLD)) { + if (this->r_drop_item != num_drops) { + n = true; + } + + this->r_drop_item = num_drops; + } + + if (this->drop_flags.has_not(Mdt::ONLY_ITEM)) { + if (this->r_drop_gold != num_drops) { + n = true; + } + + this->r_drop_gold = num_drops; + } + + if (this->r_cast_spell != MAX_UCHAR) { + n = true; + } + + this->r_cast_spell = MAX_UCHAR; + n |= count_lore_mflag_group(this->resistance_flags, this->r_resistance_flags) > 0; + n |= count_lore_mflag_group(this->ability_flags, this->r_ability_flags) > 0; + n |= count_lore_mflag_group(this->behavior_flags, this->r_behavior_flags) > 0; + n |= count_lore_mflag_group(this->drop_flags, this->r_drop_flags) > 0; + n |= count_lore_mflag_group(this->feature_flags, this->r_feature_flags) > 0; + n |= count_lore_mflag_group(this->special_flags, this->r_special_flags) > 0; + n |= count_lore_mflag_group(this->misc_flags, this->r_misc_flags) > 0; + + this->r_resistance_flags = this->resistance_flags; + this->r_ability_flags = this->ability_flags; + this->r_behavior_flags = this->behavior_flags; + this->r_drop_flags = this->drop_flags; + this->r_feature_flags = this->feature_flags; + this->r_special_flags = this->special_flags; + this->r_misc_flags = this->misc_flags; + if (!this->r_can_evolve) { + n = true; + } + + this->r_can_evolve = true; + return n; +} + /*! * @brief エルドリッチホラーの形容詞種別を決める * @return エルドリッチホラーの形容詞 @@ -600,3 +687,12 @@ void MonraceList::reset_all_visuals() monrace.symbol_config = monrace.symbol_definition; } } + +bool MonraceList::probe_lore(MonsterRaceId monrace_id) +{ + if (LoreTracker::get_instance().is_tracking(monrace_id)) { + RedrawingFlagsUpdater::get_instance().set_flag(SubWindowRedrawingFlag::MONSTER_LORE); + } + + return this->get_monrace(monrace_id).probe_lore(); +} diff --git a/src/system/monster-race-info.h b/src/system/monster-race-info.h index 44b5fe2fa..0c23f2768 100644 --- a/src/system/monster-race-info.h +++ b/src/system/monster-race-info.h @@ -151,8 +151,9 @@ public: int calc_power() const; int calc_figurine_value() const; int calc_capture_value() const; + std::string build_eldritch_horror_message(std::string_view description) const; - std::string build_eldritch_horror_message(std::string_view description); + bool probe_lore(); private: const std::string &decide_horror_message() const; @@ -197,6 +198,7 @@ public: const MonsterRaceInfo &pick_monrace_at_random() const; void reset_all_visuals(); + bool probe_lore(MonsterRaceId monrace_id); private: MonraceList() = default;