OSDN Git Service

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