OSDN Git Service

[Refactor] #2807 Renamed struct monster_race to class MonsterRaceInfo
[hengbandforosx/hengbandosx.git] / src / system / monster-type-definition.cpp
1 #include "system/monster-type-definition.h"
2 #include "game-option/birth-options.h"
3 #include "monster-race/monster-race.h"
4 #include "monster-race/race-indice-types.h"
5 #include "monster-race/race-kind-flags.h"
6 #include "monster/monster-status.h"
7 #include "system/monster-race-definition.h"
8 #include "util/string-processor.h"
9
10 bool MonsterEntity::is_friendly() const
11 {
12     return this->mflag2.has(MonsterConstantFlagType::FRIENDLY);
13 }
14
15 bool MonsterEntity::is_pet() const
16 {
17     return this->mflag2.has(MonsterConstantFlagType::PET);
18 }
19
20 bool MonsterEntity::is_hostile() const
21 {
22     return !this->is_friendly() && !this->is_pet();
23 }
24
25 bool MonsterEntity::is_original_ap() const
26 {
27     return this->ap_r_idx == this->r_idx;
28 }
29
30 /*!
31  * @brief モンスターがアイテム類に擬態しているかどうかを返す
32  * @param m_ptr モンスターの参照ポインタ
33  * @return モンスターがアイテム類に擬態しているならTRUE、そうでなければFALSE
34  * @details
35  * ユニークミミックは常時擬態状態
36  * 一般モンスターもビハインダーだけ特別扱い
37  * その他増やしたい時はis_special_mimic に「|=」で追加すること
38  *
39  */
40 bool MonsterEntity::is_mimicry() const
41 {
42     auto is_special_mimic = this->ap_r_idx == MonsterRaceId::BEHINDER;
43     if (is_special_mimic) {
44         return true;
45     }
46
47     const auto &r_ref = monraces_info[this->ap_r_idx];
48     const auto mimic_symbols = "/|\\()[]=$,.!?&`#%<>+~";
49     if (angband_strchr(mimic_symbols, r_ref.d_char) == nullptr) {
50         return false;
51     }
52
53     if (r_ref.kind_flags.has(MonsterKindType::UNIQUE)) {
54         return true;
55     }
56
57     return r_ref.behavior_flags.has(MonsterBehaviorType::NEVER_MOVE) || this->is_asleep();
58 }
59
60 bool MonsterEntity::is_valid() const
61 {
62     return MonsterRace(this->r_idx).is_valid();
63 }
64
65 MonsterRaceId MonsterEntity::get_real_r_idx() const
66 {
67     const auto &r_ref = monraces_info[this->r_idx];
68     if (this->mflag2.has_not(MonsterConstantFlagType::CHAMELEON)) {
69         return this->r_idx;
70     }
71
72     return r_ref.kind_flags.has(MonsterKindType::UNIQUE) ? MonsterRaceId::CHAMELEON_K : MonsterRaceId::CHAMELEON;
73 }
74
75 /*!
76  * @brief モンスターの真の種族を返す / Extract monster race pointer of a monster's true form
77  * @return 本当のモンスター種族参照ポインタ
78  */
79 MonsterRaceInfo &MonsterEntity::get_real_r_ref() const
80 {
81     return monraces_info[this->get_real_r_idx()];
82 }
83
84 short MonsterEntity::get_remaining_sleep() const
85 {
86     return this->mtimed[MTIMED_CSLEEP];
87 }
88
89 bool MonsterEntity::is_asleep() const
90 {
91     return this->get_remaining_sleep() > 0;
92 }
93
94 short MonsterEntity::get_remaining_acceleration() const
95 {
96     return this->mtimed[MTIMED_FAST];
97 }
98
99 bool MonsterEntity::is_accelerated() const
100 {
101     return this->get_remaining_acceleration() > 0;
102 }
103
104 short MonsterEntity::get_remaining_deceleration() const
105 {
106     return this->mtimed[MTIMED_SLOW];
107 }
108
109 bool MonsterEntity::is_decelerated() const
110 {
111     return this->get_remaining_deceleration() > 0;
112 }
113
114 short MonsterEntity::get_remaining_stun() const
115 {
116     return this->mtimed[MTIMED_STUNNED];
117 }
118
119 bool MonsterEntity::is_stunned() const
120 {
121     return this->get_remaining_stun() > 0;
122 }
123
124 short MonsterEntity::get_remaining_confusion() const
125 {
126     return this->mtimed[MTIMED_CONFUSED];
127 }
128
129 bool MonsterEntity::is_confused() const
130 {
131     return this->get_remaining_confusion() > 0;
132 }
133
134 short MonsterEntity::get_remaining_fear() const
135 {
136     return this->mtimed[MTIMED_MONFEAR];
137 }
138
139 bool MonsterEntity::is_fearful() const
140 {
141     return this->get_remaining_fear() > 0;
142 }
143
144 short MonsterEntity::get_remaining_invulnerability() const
145 {
146     return this->mtimed[MTIMED_INVULNER];
147 }
148
149 bool MonsterEntity::is_invulnerable() const
150 {
151     return this->get_remaining_invulnerability() > 0;
152 }
153
154 /*
155  * @brief 悪夢モード、一時加速、一時減速に基づくモンスターの現在速度を返す
156  */
157 byte MonsterEntity::get_temporary_speed() const
158 {
159     auto speed = this->mspeed;
160     if (ironman_nightmare) {
161         speed += 5;
162     }
163
164     if (this->is_accelerated()) {
165         speed += 10;
166     }
167
168     if (this->is_decelerated()) {
169         speed -= 10;
170     }
171
172     return speed;
173 }