OSDN Git Service

Merge pull request #3279 from habu1010/feature/display-etc-screen-on-center
[hengbandforosx/hengbandosx.git] / src / monster-floor / monster-move.cpp
1 /*!
2  * @brief モンスターの移動に関する処理
3  * @date 2020/03/08
4  * @author Hourier
5  */
6
7 #include "monster-floor/monster-move.h"
8 #include "core/disturbance.h"
9 #include "core/player-update-types.h"
10 #include "core/speed-table.h"
11 #include "core/window-redrawer.h"
12 #include "effect/attribute-types.h"
13 #include "effect/effect-characteristics.h"
14 #include "effect/effect-processor.h"
15 #include "floor/cave.h"
16 #include "floor/geometry.h"
17 #include "game-option/disturbance-options.h"
18 #include "grid/feature.h"
19 #include "grid/grid.h"
20 #include "io/files-util.h"
21 #include "monster-attack/monster-attack-processor.h"
22 #include "monster-floor/monster-object.h"
23 #include "monster-race/monster-race.h"
24 #include "monster-race/race-flags1.h"
25 #include "monster-race/race-flags2.h"
26 #include "monster-race/race-flags7.h"
27 #include "monster-race/race-flags8.h"
28 #include "monster-race/race-indice-types.h"
29 #include "monster/monster-describer.h"
30 #include "monster/monster-flag-types.h"
31 #include "monster/monster-info.h"
32 #include "monster/monster-processor-util.h"
33 #include "monster/monster-status.h"
34 #include "monster/monster-update.h"
35 #include "pet/pet-util.h"
36 #include "player/player-status-flags.h"
37 #include "system/floor-type-definition.h"
38 #include "system/grid-type-definition.h"
39 #include "system/monster-entity.h"
40 #include "system/monster-race-info.h"
41 #include "system/player-type-definition.h"
42 #include "system/terrain-type-definition.h"
43 #include "target/projection-path-calculator.h"
44 #include "util/bit-flags-calculator.h"
45 #include "view/display-messages.h"
46
47 static bool check_hp_for_terrain_destruction(TerrainType *f_ptr, MonsterEntity *m_ptr)
48 {
49     auto can_destroy = f_ptr->flags.has_not(TerrainCharacteristics::GLASS);
50     can_destroy |= monraces_info[m_ptr->r_idx].behavior_flags.has(MonsterBehaviorType::STUPID);
51     can_destroy |= m_ptr->hp >= std::max(m_ptr->maxhp / 3, 200);
52     return can_destroy;
53 }
54
55 /*!
56  * @brief モンスターによる壁の透過・破壊を行う
57  * @param player_ptr プレイヤーへの参照ポインタ
58  * @param m_ptr モンスターへの参照ポインタ
59  * @param ny モンスターのY座標
60  * @param nx モンスターのX座標
61  * @param can_cross モンスターが地形を踏破できるならばTRUE
62  * @return 透過も破壊もしなかった場合はFALSE、それ以外はTRUE
63  */
64 static bool process_wall(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MonsterEntity *m_ptr, POSITION ny, POSITION nx, bool can_cross)
65 {
66     auto *r_ptr = &monraces_info[m_ptr->r_idx];
67     auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
68     auto *f_ptr = &terrains_info[g_ptr->feat];
69     if (player_bold(player_ptr, ny, nx)) {
70         turn_flags_ptr->do_move = true;
71         return true;
72     }
73
74     if (g_ptr->m_idx > 0) {
75         turn_flags_ptr->do_move = true;
76         return true;
77     }
78
79     using Mft = MonsterFeatureType;
80     using Tc = TerrainCharacteristics;
81     auto can_kill_wall = r_ptr->feature_flags.has(Mft::KILL_WALL);
82     can_kill_wall &= can_cross ? f_ptr->flags.has_not(Tc::LOS) : !turn_flags_ptr->is_riding_mon;
83     can_kill_wall &= f_ptr->flags.has(Tc::HURT_DISI);
84     can_kill_wall &= f_ptr->flags.has_not(Tc::PERMANENT);
85     can_kill_wall &= check_hp_for_terrain_destruction(f_ptr, m_ptr);
86     if (can_kill_wall) {
87         turn_flags_ptr->do_move = true;
88         if (!can_cross) {
89             turn_flags_ptr->must_alter_to_move = true;
90         }
91
92         turn_flags_ptr->did_kill_wall = true;
93         return true;
94     }
95
96     if (!can_cross) {
97         return false;
98     }
99
100     turn_flags_ptr->do_move = true;
101     if ((r_ptr->feature_flags.has(Mft::PASS_WALL)) && (!turn_flags_ptr->is_riding_mon || has_pass_wall(player_ptr)) && f_ptr->flags.has(Tc::CAN_PASS)) {
102         turn_flags_ptr->did_pass_wall = true;
103     }
104
105     return true;
106 }
107
108 /*!
109  * @brief モンスターが普通のドアを開ける処理
110  * @param player_ptr プレイヤーへの参照ポインタ
111  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
112  * @param m_ptr モンスターへの参照ポインタ
113  * @param ny モンスターのY座標
114  * @param nx モンスターのX座標
115  * @return ここではドアを開けず、ガラスのドアを開ける可能性があるならTRUE
116  */
117 static bool bash_normal_door(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MonsterEntity *m_ptr, POSITION ny, POSITION nx)
118 {
119     auto *r_ptr = &monraces_info[m_ptr->r_idx];
120     auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
121     auto *f_ptr = &terrains_info[g_ptr->feat];
122     turn_flags_ptr->do_move = false;
123     using Tc = TerrainCharacteristics;
124     auto can_bash = r_ptr->behavior_flags.has_not(MonsterBehaviorType::OPEN_DOOR);
125     can_bash |= f_ptr->flags.has_not(Tc::OPEN);
126     can_bash |= m_ptr->is_pet() && ((player_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0);
127     if (can_bash) {
128         return true;
129     }
130
131     if (f_ptr->power == 0) {
132         turn_flags_ptr->did_open_door = true;
133         turn_flags_ptr->do_turn = true;
134         return false;
135     }
136
137     if (randint0(m_ptr->hp / 10) > f_ptr->power) {
138         cave_alter_feat(player_ptr, ny, nx, Tc::DISARM);
139         turn_flags_ptr->do_turn = true;
140         return false;
141     }
142
143     return true;
144 }
145
146 /*!
147  * @brief モンスターがガラスのドアを開ける処理
148  * @param player_ptr プレイヤーへの参照ポインタ
149  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
150  * @param m_ptr モンスターへの参照ポインタ
151  * @param g_ptr グリッドへの参照ポインタ
152  * @param f_ptr 地形への参照ポインタ
153  */
154 static void bash_glass_door(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MonsterEntity *m_ptr, TerrainType *f_ptr, bool may_bash)
155 {
156     auto *r_ptr = &monraces_info[m_ptr->r_idx];
157     auto can_bash = may_bash;
158     can_bash &= r_ptr->behavior_flags.has(MonsterBehaviorType::BASH_DOOR);
159     can_bash &= f_ptr->flags.has(TerrainCharacteristics::BASH);
160     can_bash &= !m_ptr->is_pet() || any_bits(player_ptr->pet_extra_flags, PF_OPEN_DOORS);
161     if (!can_bash) {
162         return;
163     }
164
165     if (!check_hp_for_terrain_destruction(f_ptr, m_ptr) || (randint0(m_ptr->hp / 10) <= f_ptr->power)) {
166         return;
167     }
168
169     if (f_ptr->flags.has(TerrainCharacteristics::GLASS)) {
170         msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
171     } else {
172         msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
173     }
174
175     if (disturb_minor) {
176         disturb(player_ptr, false, false);
177     }
178
179     turn_flags_ptr->did_bash_door = true;
180     turn_flags_ptr->do_move = true;
181     turn_flags_ptr->must_alter_to_move = true;
182 }
183
184 /*!
185  * @brief モンスターによるドアの開放・破壊を行う
186  * @param player_ptr プレイヤーへの参照ポインタ
187  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
188  * @param m_ptr モンスターへの参照ポインタ
189  * @param ny モンスターのY座標
190  * @param nx モンスターのX座標
191  * @return モンスターが死亡した場合のみFALSE
192  */
193 static bool process_door(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MonsterEntity *m_ptr, POSITION ny, POSITION nx)
194 {
195     auto *r_ptr = &monraces_info[m_ptr->r_idx];
196     const auto &g_ref = player_ptr->current_floor_ptr->grid_array[ny][nx];
197     if (!is_closed_door(player_ptr, g_ref.feat)) {
198         return true;
199     }
200
201     auto *terrain_ptr = &terrains_info[g_ref.feat];
202     auto may_bash = bash_normal_door(player_ptr, turn_flags_ptr, m_ptr, ny, nx);
203     bash_glass_door(player_ptr, turn_flags_ptr, m_ptr, terrain_ptr, may_bash);
204     if (!turn_flags_ptr->did_open_door && !turn_flags_ptr->did_bash_door) {
205         return true;
206     }
207
208     const auto is_open = feat_state(player_ptr->current_floor_ptr, g_ref.feat, TerrainCharacteristics::OPEN) == g_ref.feat;
209     if (turn_flags_ptr->did_bash_door && ((randint0(100) < 50) || is_open || terrain_ptr->flags.has(TerrainCharacteristics::GLASS))) {
210         cave_alter_feat(player_ptr, ny, nx, TerrainCharacteristics::BASH);
211         if (!m_ptr->is_valid()) {
212             player_ptr->update |= (PU_FLOW);
213             player_ptr->window_flags |= (PW_OVERHEAD | PW_DUNGEON);
214             if (is_original_ap_and_seen(player_ptr, m_ptr)) {
215                 r_ptr->r_behavior_flags.set(MonsterBehaviorType::BASH_DOOR);
216             }
217
218             return false;
219         }
220     } else {
221         cave_alter_feat(player_ptr, ny, nx, TerrainCharacteristics::OPEN);
222     }
223
224     turn_flags_ptr->do_view = true;
225     return true;
226 }
227
228 /*!
229  * @brief 守りのルーンによるモンスターの移動制限を処理する
230  * @param player_ptr プレイヤーへの参照ポインタ
231  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
232  * @param m_ptr モンスターへの参照ポインタ
233  * @param ny モンスターのY座標
234  * @param nx モンスターのX座標
235  * @return ルーンに侵入できるか否か
236  */
237 static bool process_protection_rune(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MonsterEntity *m_ptr, POSITION ny, POSITION nx)
238 {
239     auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
240     auto *r_ptr = &monraces_info[m_ptr->r_idx];
241     auto can_enter = turn_flags_ptr->do_move;
242     can_enter &= g_ptr->is_rune_protection();
243     can_enter &= (r_ptr->behavior_flags.has_not(MonsterBehaviorType::NEVER_BLOW)) || !player_bold(player_ptr, ny, nx);
244     if (!can_enter) {
245         return false;
246     }
247
248     turn_flags_ptr->do_move = false;
249     if (m_ptr->is_pet() || (randint1(BREAK_RUNE_PROTECTION) >= r_ptr->level)) {
250         return true;
251     }
252
253     if (g_ptr->is_mark()) {
254         msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
255     }
256
257     g_ptr->info &= ~(CAVE_MARK);
258     g_ptr->info &= ~(CAVE_OBJECT);
259     g_ptr->mimic = 0;
260     turn_flags_ptr->do_move = true;
261     note_spot(player_ptr, ny, nx);
262     return true;
263 }
264
265 /*!
266  * @brief 爆発のルーンを処理する
267  * @param player_ptr プレイヤーへの参照ポインタ
268  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
269  * @param m_ptr モンスターへの参照ポインタ
270  * @param ny モンスターのY座標
271  * @param nx モンスターのX座標
272  * @return モンスターが死亡した場合のみFALSE
273  */
274 static bool process_explosive_rune(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MonsterEntity *m_ptr, POSITION ny, POSITION nx)
275 {
276     auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
277     auto *r_ptr = &monraces_info[m_ptr->r_idx];
278     auto should_explode = turn_flags_ptr->do_move;
279     should_explode &= g_ptr->is_rune_explosion();
280     should_explode &= (r_ptr->behavior_flags.has_not(MonsterBehaviorType::NEVER_BLOW)) || !player_bold(player_ptr, ny, nx);
281     if (!should_explode) {
282         return true;
283     }
284
285     turn_flags_ptr->do_move = false;
286     if (m_ptr->is_pet()) {
287         return true;
288     }
289
290     if (randint1(BREAK_RUNE_EXPLOSION) > r_ptr->level) {
291         if (g_ptr->info & CAVE_MARK) {
292             msg_print(_("ルーンが爆発した!", "The rune explodes!"));
293             BIT_FLAGS project_flags = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI;
294             project(player_ptr, 0, 2, ny, nx, 2 * (player_ptr->lev + damroll(7, 7)), AttributeType::MANA, project_flags);
295         }
296     } else {
297         msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
298     }
299
300     g_ptr->info &= ~(CAVE_MARK);
301     g_ptr->info &= ~(CAVE_OBJECT);
302     g_ptr->mimic = 0;
303
304     note_spot(player_ptr, ny, nx);
305     lite_spot(player_ptr, ny, nx);
306
307     if (!m_ptr->is_valid()) {
308         return false;
309     }
310
311     turn_flags_ptr->do_move = true;
312     return true;
313 }
314
315 /*!
316  * @brief モンスターが壁を掘った後続処理を実行する
317  * @param player_ptr プレイヤーへの参照ポインタ
318  * @turn_flags_ptr ターン経過処理フラグへの参照ポインタ
319  * @param m_ptr モンスターへの参照ポインタ
320  * @param ny モンスターのY座標
321  * @param nx モンスターのX座標
322  * @return モンスターが死亡した場合のみFALSE
323  */
324 static bool process_post_dig_wall(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MonsterEntity *m_ptr, POSITION ny, POSITION nx)
325 {
326     auto *r_ptr = &monraces_info[m_ptr->r_idx];
327     grid_type *g_ptr;
328     g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
329     TerrainType *f_ptr;
330     f_ptr = &terrains_info[g_ptr->feat];
331     if (!turn_flags_ptr->did_kill_wall || !turn_flags_ptr->do_move) {
332         return true;
333     }
334
335     constexpr auto chance_sound = 20;
336     if (one_in_(chance_sound)) {
337         if (f_ptr->flags.has(TerrainCharacteristics::GLASS)) {
338             msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
339         } else {
340             msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
341         }
342     }
343
344     cave_alter_feat(player_ptr, ny, nx, TerrainCharacteristics::HURT_DISI);
345
346     if (!m_ptr->is_valid()) {
347         player_ptr->update |= (PU_FLOW);
348         player_ptr->window_flags |= (PW_OVERHEAD | PW_DUNGEON);
349         if (is_original_ap_and_seen(player_ptr, m_ptr)) {
350             r_ptr->r_feature_flags.set(MonsterFeatureType::KILL_WALL);
351         }
352
353         return false;
354     }
355
356     f_ptr = &terrains_info[g_ptr->feat];
357     turn_flags_ptr->do_view = true;
358     turn_flags_ptr->do_turn = true;
359     return true;
360 }
361
362 /*!
363  * @brief モンスターの移動に関するメインルーチン
364  * @param player_ptr プレイヤーへの参照ポインタ
365  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
366  * @param m_idx モンスターID
367  * @param mm モンスターの移動方向
368  * @param oy 移動前の、モンスターのY座標
369  * @param ox 移動前の、モンスターのX座標
370  * @param count 移動回数 (のはず todo)
371  * @return 移動が阻害される何か (ドア等)があったらFALSE
372  * @todo 少し長いが、これといってブロックとしてまとまった部分もないので暫定でこのままとする
373  */
374 bool process_monster_movement(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, DIRECTION *mm, POSITION oy, POSITION ox, int *count)
375 {
376     for (int i = 0; mm[i]; i++) {
377         int d = mm[i];
378         if (d == 5) {
379             d = ddd[randint0(8)];
380         }
381
382         POSITION ny = oy + ddy[d];
383         POSITION nx = ox + ddx[d];
384         if (!in_bounds2(player_ptr->current_floor_ptr, ny, nx)) {
385             continue;
386         }
387
388         grid_type *g_ptr;
389         g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
390         auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
391         auto *r_ptr = &monraces_info[m_ptr->r_idx];
392         bool can_cross = monster_can_cross_terrain(player_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0);
393
394         if (!process_wall(player_ptr, turn_flags_ptr, m_ptr, ny, nx, can_cross)) {
395             if (!process_door(player_ptr, turn_flags_ptr, m_ptr, ny, nx)) {
396                 return false;
397             }
398         }
399
400         if (!process_protection_rune(player_ptr, turn_flags_ptr, m_ptr, ny, nx)) {
401             if (!process_explosive_rune(player_ptr, turn_flags_ptr, m_ptr, ny, nx)) {
402                 return false;
403             }
404         }
405
406         exe_monster_attack_to_player(player_ptr, turn_flags_ptr, m_idx, ny, nx);
407         if (process_monster_attack_to_monster(player_ptr, turn_flags_ptr, m_idx, g_ptr, can_cross)) {
408             return false;
409         }
410
411         if (turn_flags_ptr->is_riding_mon) {
412             const auto &m_ref = player_ptr->current_floor_ptr->m_list[player_ptr->riding];
413             if (!player_ptr->riding_ryoute && !m_ref.is_fearful()) {
414                 turn_flags_ptr->do_move = false;
415             }
416         }
417
418         if (!process_post_dig_wall(player_ptr, turn_flags_ptr, m_ptr, ny, nx)) {
419             return false;
420         }
421
422         if (turn_flags_ptr->must_alter_to_move && r_ptr->feature_flags.has(MonsterFeatureType::AQUATIC)) {
423             if (!monster_can_cross_terrain(player_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0)) {
424                 turn_flags_ptr->do_move = false;
425             }
426         }
427
428         if (turn_flags_ptr->do_move && !can_cross && !turn_flags_ptr->did_kill_wall && !turn_flags_ptr->did_bash_door) {
429             turn_flags_ptr->do_move = false;
430         }
431
432         if (turn_flags_ptr->do_move && r_ptr->behavior_flags.has(MonsterBehaviorType::NEVER_MOVE)) {
433             if (is_original_ap_and_seen(player_ptr, m_ptr)) {
434                 r_ptr->r_behavior_flags.set(MonsterBehaviorType::NEVER_MOVE);
435             }
436
437             turn_flags_ptr->do_move = false;
438         }
439
440         if (!turn_flags_ptr->do_move) {
441             if (turn_flags_ptr->do_turn) {
442                 break;
443             }
444
445             continue;
446         }
447
448         turn_flags_ptr->do_turn = true;
449         const auto &terrain_ref = terrains_info[g_ptr->feat];
450         auto can_recover_energy = terrain_ref.flags.has(TerrainCharacteristics::TREE);
451         can_recover_energy &= r_ptr->feature_flags.has_not(MonsterFeatureType::CAN_FLY);
452         can_recover_energy &= r_ptr->wilderness_flags.has_not(MonsterWildernessType::WILD_WOOD);
453         if (can_recover_energy) {
454             m_ptr->energy_need += ENERGY_NEED();
455         }
456
457         if (!update_riding_monster(player_ptr, turn_flags_ptr, m_idx, oy, ox, ny, nx)) {
458             break;
459         }
460
461         const auto &ap_r_ref = monraces_info[m_ptr->ap_r_idx];
462         const auto is_projectable = projectable(player_ptr, player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx);
463         const auto can_see = disturb_near && m_ptr->mflag.has(MonsterTemporaryFlagType::VIEW) && is_projectable;
464         const auto is_high_level = disturb_high && (ap_r_ref.r_tkills > 0) && (ap_r_ref.level >= player_ptr->lev);
465         if (m_ptr->ml && (disturb_move || can_see || is_high_level)) {
466             if (m_ptr->is_hostile()) {
467                 disturb(player_ptr, false, true);
468             }
469         }
470
471         bool is_takable_or_killable = !g_ptr->o_idx_list.empty();
472         is_takable_or_killable &= r_ptr->behavior_flags.has_any_of({ MonsterBehaviorType::TAKE_ITEM, MonsterBehaviorType::KILL_ITEM });
473
474         bool is_pickup_items = (player_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
475         is_pickup_items &= r_ptr->behavior_flags.has(MonsterBehaviorType::TAKE_ITEM);
476
477         is_takable_or_killable &= !m_ptr->is_pet() || is_pickup_items;
478         if (!is_takable_or_killable) {
479             if (turn_flags_ptr->do_turn) {
480                 break;
481             }
482
483             continue;
484         }
485
486         update_object_by_monster_movement(player_ptr, turn_flags_ptr, m_idx, ny, nx);
487         if (turn_flags_ptr->do_turn) {
488             break;
489         }
490
491         (*count)++;
492     }
493
494     return true;
495 }
496
497 static bool can_speak(const MonsterRaceInfo &ap_r_ref, MonsterSpeakType mon_speak_type)
498 {
499     const auto can_speak_all = ap_r_ref.speak_flags.has(MonsterSpeakType::SPEAK_ALL);
500     const auto can_speak_specific = ap_r_ref.speak_flags.has(mon_speak_type);
501     return can_speak_all || can_speak_specific;
502 }
503
504 static std::string_view get_speak_filename(MonsterEntity *m_ptr)
505 {
506     const auto &ap_r_ref = monraces_info[m_ptr->ap_r_idx];
507     if (m_ptr->is_fearful() && can_speak(ap_r_ref, MonsterSpeakType::SPEAK_FEAR)) {
508         return _("monfear_j.txt", "monfear.txt");
509     }
510
511     constexpr auto monspeak_txt(_("monspeak_j.txt", "monspeak.txt"));
512     if (m_ptr->is_pet() && can_speak(ap_r_ref, MonsterSpeakType::SPEAK_BATTLE)) {
513         return monspeak_txt;
514     }
515
516     if (m_ptr->is_friendly() && can_speak(ap_r_ref, MonsterSpeakType::SPEAK_FRIEND)) {
517         return _("monfrien_j.txt", "monfrien.txt");
518     }
519
520     if (can_speak(ap_r_ref, MonsterSpeakType::SPEAK_BATTLE)) {
521         return monspeak_txt;
522     }
523
524     return "";
525 }
526
527 /*!
528  * @brief モンスターを喋らせたり足音を立てたりする
529  * @param player_ptr プレイヤーへの参照ポインタ
530  * @param m_idx モンスターID
531  * @param oy モンスターが元々いたY座標
532  * @param ox モンスターが元々いたX座標
533  * @param aware モンスターがプレイヤーに気付いているならばTRUE、超隠密状態ならばFALSE
534  */
535 void process_speak_sound(PlayerType *player_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware)
536 {
537     if (player_ptr->phase_out) {
538         return;
539     }
540
541     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
542     constexpr auto chance_noise = 20;
543     if (m_ptr->ap_r_idx == MonsterRaceId::CYBER && one_in_(chance_noise) && !m_ptr->ml && (m_ptr->cdis <= MAX_PLAYER_SIGHT)) {
544         if (disturb_minor) {
545             disturb(player_ptr, false, false);
546         }
547         msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
548     }
549
550     auto can_speak = monraces_info[m_ptr->ap_r_idx].speak_flags.any();
551     constexpr auto chance_speak = 8;
552     if (!can_speak || !aware || !one_in_(chance_speak) || !player_has_los_bold(player_ptr, oy, ox) || !projectable(player_ptr, oy, ox, player_ptr->y, player_ptr->x)) {
553         return;
554     }
555
556     const auto m_name = m_ptr->ml ? monster_desc(player_ptr, m_ptr, 0) : std::string(_("それ", "It"));
557     auto filename = get_speak_filename(m_ptr);
558     if (filename.empty()) {
559         return;
560     }
561
562     const auto monmessage = get_random_line(filename.data(), enum2i(m_ptr->ap_r_idx));
563     if (monmessage.has_value()) {
564         msg_format(_("%s^%s", "%s^ %s"), m_name.data(), monmessage->data());
565     }
566 }
567
568 /*!
569  * @brief モンスターの目標地点をセットする / Set the target of counter attack
570  * @param m_ptr モンスターの参照ポインタ
571  * @param y 目標y座標
572  * @param x 目標x座標
573  */
574 void set_target(MonsterEntity *m_ptr, POSITION y, POSITION x)
575 {
576     m_ptr->target_y = y;
577     m_ptr->target_x = x;
578 }
579
580 /*!
581  * @brief モンスターの目標地点をリセットする / Reset the target of counter attack
582  * @param m_ptr モンスターの参照ポインタ
583  */
584 void reset_target(MonsterEntity *m_ptr)
585 {
586     set_target(m_ptr, 0, 0);
587 }