From e27a9ee590002d7e2bc91b9fcd16ba08928bc584 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sat, 17 Sep 2022 12:32:03 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#2647=20is=5Fmimicry()=20=E3=82=92m?= =?utf8?q?onster=5Ftype=20=E3=81=AE=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7?= =?utf8?q?=E3=82=AF=E3=83=88=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=81=A8?= =?utf8?q?=E3=81=97=E3=81=A6=E5=86=8D=E5=AE=9A=E7=BE=A9=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/monster/monster-info.cpp | 33 ---------------------------- src/monster/monster-info.h | 2 -- src/monster/monster-status.cpp | 2 +- src/monster/monster-status.h | 2 +- src/system/monster-type-definition.cpp | 39 ++++++++++++++++++++++++++++++++++ src/system/monster-type-definition.h | 1 + src/target/target-preparation.cpp | 2 +- 7 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/monster/monster-info.cpp b/src/monster/monster-info.cpp index 1cb6b67a3..7540153ea 100644 --- a/src/monster/monster-info.cpp +++ b/src/monster/monster-info.cpp @@ -267,39 +267,6 @@ bool is_original_ap_and_seen(PlayerType *player_ptr, monster_type *m_ptr) } /*! - * @brief モンスターがアイテム類に擬態しているかどうかを返す - * - * モンスターがアイテム類に擬態しているかどうかを返す。 - * 擬態の条件: - * - シンボルが以下のいずれかであること: /|\()[]=$,.!?&`#%<>+~ - * - 動かない、もしくは眠っていること - * - * 但し、以下のモンスターは例外的に擬態しているとする - * それ・生ける虚無『ヌル』・ビハインダー - * - * @param m_ptr モンスターの参照ポインタ - * @return モンスターがアイテム類に擬態しているならTRUE、そうでなければFALSE - */ -bool is_mimicry(monster_type *m_ptr) -{ - if (m_ptr->ap_r_idx == MonsterRaceId::IT || m_ptr->ap_r_idx == MonsterRaceId::NULL_ || m_ptr->ap_r_idx == MonsterRaceId::BEHINDER) { - return true; - } - - auto *r_ptr = &r_info[m_ptr->ap_r_idx]; - - if (angband_strchr("/|\\()[]=$,.!?&`#%<>+~", r_ptr->d_char) == nullptr) { - return false; - } - - if (r_ptr->behavior_flags.has_not(MonsterBehaviorType::NEVER_MOVE) && !monster_csleep_remaining(m_ptr)) { - return false; - } - - return true; -} - -/*! * @brief モンスターの真の種族を返す / Extract monster race pointer of a monster's true form * @param m_ptr モンスターの参照ポインタ * @return 本当のモンスター種族参照ポインタ diff --git a/src/monster/monster-info.h b/src/monster/monster-info.h index ff510aa49..22bf1e98d 100644 --- a/src/monster/monster-info.h +++ b/src/monster/monster-info.h @@ -17,8 +17,6 @@ bool are_enemies(PlayerType *player_ptr, monster_type *m_ptr1, monster_type *m_p bool monster_has_hostile_align(PlayerType *player_ptr, monster_type *m_ptr, int pa_good, int pa_evil, monster_race *r_ptr); bool is_original_ap_and_seen(PlayerType *player_ptr, monster_type *m_ptr); -bool is_mimicry(monster_type *m_ptr); - monster_race *real_r_ptr(monster_type *m_ptr); MonsterRaceId real_r_idx(monster_type *m_ptr); void monster_name(PlayerType *player_ptr, MONSTER_IDX m_idx, char *m_name); diff --git a/src/monster/monster-status.cpp b/src/monster/monster-status.cpp index 3f10e030d..9a188fcce 100644 --- a/src/monster/monster-status.cpp +++ b/src/monster/monster-status.cpp @@ -528,7 +528,7 @@ bool monster_is_valid(monster_type *m_ptr) return MonsterRace(m_ptr->r_idx).is_valid(); } -TIME_EFFECT monster_csleep_remaining(monster_type *m_ptr) +TIME_EFFECT monster_csleep_remaining(const monster_type *m_ptr) { return m_ptr->mtimed[MTIMED_CSLEEP]; } diff --git a/src/monster/monster-status.h b/src/monster/monster-status.h index 38346e2de..c16414fc5 100644 --- a/src/monster/monster-status.h +++ b/src/monster/monster-status.h @@ -17,7 +17,7 @@ void monster_gain_exp(PlayerType *player_ptr, MONSTER_IDX m_idx, MonsterRaceId s void process_monsters_mtimed(PlayerType *player_ptr, int mtimed_idx); -TIME_EFFECT monster_csleep_remaining(monster_type *m_ptr); +TIME_EFFECT monster_csleep_remaining(const monster_type *m_ptr); TIME_EFFECT monster_fast_remaining(monster_type *m_ptr); TIME_EFFECT monster_slow_remaining(monster_type *m_ptr); TIME_EFFECT monster_stunned_remaining(monster_type *m_ptr); diff --git a/src/system/monster-type-definition.cpp b/src/system/monster-type-definition.cpp index 73624e18f..1235d1872 100644 --- a/src/system/monster-type-definition.cpp +++ b/src/system/monster-type-definition.cpp @@ -1,4 +1,10 @@ #include "system/monster-type-definition.h" +#include "monster-race/monster-race.h" +#include "monster-race/race-indice-types.h" +#include "monster-race/race-kind-flags.h" +#include "monster/monster-status.h" +#include "system/monster-race-definition.h" +#include "util/string-processor.h" bool monster_type::is_friendly() const { @@ -19,3 +25,36 @@ bool monster_type::is_original_ap() const { return this->ap_r_idx == this->r_idx; } + +/*! + * @brief モンスターがアイテム類に擬態しているかどうかを返す + * + * モンスターがアイテム類に擬態しているかどうかを返す。 + * 擬態の条件: + * - シンボルが以下のいずれかであること: /|\()[]=$,.!?&`#%<>+~ + * - 動かない、もしくは眠っていること + * + * 但し、以下のモンスターは例外的に擬態しているとする + * それ・生ける虚無『ヌル』・ビハインダー + * + * @param m_ptr モンスターの参照ポインタ + * @return モンスターがアイテム類に擬態しているならTRUE、そうでなければFALSE + */ +bool monster_type::is_mimicry() const +{ + if (this->ap_r_idx == MonsterRaceId::IT || this->ap_r_idx == MonsterRaceId::NULL_ || this->ap_r_idx == MonsterRaceId::BEHINDER) { + return true; + } + + auto *r_ptr = &r_info[this->ap_r_idx]; + + if (angband_strchr("/|\\()[]=$,.!?&`#%<>+~", r_ptr->d_char) == nullptr) { + return false; + } + + if (r_ptr->behavior_flags.has_not(MonsterBehaviorType::NEVER_MOVE) && !monster_csleep_remaining(this)) { + return false; + } + + return true; +} diff --git a/src/system/monster-type-definition.h b/src/system/monster-type-definition.h index 95764c413..718fb1cf0 100644 --- a/src/system/monster-type-definition.h +++ b/src/system/monster-type-definition.h @@ -56,4 +56,5 @@ struct monster_type { bool is_pet() const; bool is_hostile() const; bool is_original_ap() const; + bool is_mimicry() const; }; diff --git a/src/target/target-preparation.cpp b/src/target/target-preparation.cpp index afde24138..e9e25840a 100644 --- a/src/target/target-preparation.cpp +++ b/src/target/target-preparation.cpp @@ -196,7 +196,7 @@ void target_sensing_monsters_prepare(PlayerType *player_ptr, std::vectormflag2.has_none_of({ MonsterConstantFlagType::MARK, MonsterConstantFlagType::SHOW }) && m_ptr->mflag.has_not(MonsterTemporaryFlagType::ESP)) { + if (m_ptr->is_mimicry() && m_ptr->mflag2.has_none_of({ MonsterConstantFlagType::MARK, MonsterConstantFlagType::SHOW }) && m_ptr->mflag.has_not(MonsterTemporaryFlagType::ESP)) { continue; } -- 2.11.0