OSDN Git Service

[Refactor] Grid::has_monster()の定義
[hengbandforosx/hengbandosx.git] / src / monster / monster-processor.cpp
1 /*!
2  * @brief モンスターの特殊技能とターン経過処理 (移動等)/ Monster spells and movement for passaging a turn
3  * @date 2014/01/17
4  * @author
5  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
6  * This software may be copied and distributed for educational, research,\n
7  * and not for profit purposes provided that this copyright and statement\n
8  * are included in all such copies.  Other copyrights may also apply.\n
9  * 2014 Deskull rearranged comment for Doxygen.\n
10  * @details
11  * This file has several additions to it by Keldon Jones (keldon@umr.edu)
12  * to improve the general quality of the AI (version 0.1.1).
13  */
14
15 #include "monster/monster-processor.h"
16 #include "avatar/avatar.h"
17 #include "cmd-io/cmd-dump.h"
18 #include "core/speed-table.h"
19 #include "floor/cave.h"
20 #include "floor/geometry.h"
21 #include "game-option/play-record-options.h"
22 #include "grid/feature.h"
23 #include "io/write-diary.h"
24 #include "melee/melee-postprocess.h"
25 #include "melee/melee-spell.h"
26 #include "monster-floor/monster-direction.h"
27 #include "monster-floor/monster-generator.h"
28 #include "monster-floor/monster-move.h"
29 #include "monster-floor/monster-remover.h"
30 #include "monster-floor/monster-runaway.h"
31 #include "monster-floor/monster-summon.h"
32 #include "monster-floor/place-monster-types.h"
33 #include "monster-floor/quantum-effect.h"
34 #include "monster-race/monster-race.h"
35 #include "monster-race/race-flags-resistance.h"
36 #include "monster-race/race-indice-types.h"
37 #include "monster/monster-describer.h"
38 #include "monster/monster-description-types.h"
39 #include "monster/monster-flag-types.h"
40 #include "monster/monster-info.h"
41 #include "monster/monster-list.h"
42 #include "monster/monster-processor-util.h"
43 #include "monster/monster-status-setter.h"
44 #include "monster/monster-status.h"
45 #include "monster/monster-update.h"
46 #include "monster/monster-util.h"
47 #include "mspell/mspell-attack.h"
48 #include "mspell/mspell-judgement.h"
49 #include "object-enchant/trc-types.h"
50 #include "pet/pet-fall-off.h"
51 #include "player-base/player-class.h"
52 #include "player-info/ninja-data-type.h"
53 #include "player/player-move.h"
54 #include "player/player-skill.h"
55 #include "player/player-status-flags.h"
56 #include "player/special-defense-types.h"
57 #include "spell-realm/spells-hex.h"
58 #include "spell/summon-types.h"
59 #include "system/angband-system.h"
60 #include "system/floor-type-definition.h"
61 #include "system/grid-type-definition.h"
62 #include "system/monster-entity.h"
63 #include "system/monster-race-info.h"
64 #include "system/player-type-definition.h"
65 #include "system/redrawing-flags-updater.h"
66 #include "target/projection-path-calculator.h"
67 #include "view/display-messages.h"
68
69 void decide_drop_from_monster(PlayerType *player_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
70 bool process_stealth(PlayerType *player_ptr, MONSTER_IDX m_idx);
71 bool vanish_summoned_children(PlayerType *player_ptr, MONSTER_IDX m_idx, bool see_m);
72 bool awake_monster(PlayerType *player_ptr, MONSTER_IDX m_idx);
73 void process_angar(PlayerType *player_ptr, MONSTER_IDX m_idx, bool see_m);
74 bool explode_grenade(PlayerType *player_ptr, MONSTER_IDX m_idx);
75 bool decide_monster_multiplication(PlayerType *player_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
76 void process_special(PlayerType *player_ptr, MONSTER_IDX m_idx);
77 bool cast_spell(PlayerType *player_ptr, MONSTER_IDX m_idx, bool aware);
78
79 bool process_monster_fear(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
80
81 void sweep_monster_process(PlayerType *player_ptr);
82 bool decide_process_continue(PlayerType *player_ptr, MonsterEntity *m_ptr);
83
84 /*!
85  * @brief モンスター単体の1ターン行動処理メインルーチン /
86  * Process a monster
87  * @param player_ptr プレイヤーへの参照ポインタ
88  * @param m_idx 行動モンスターの参照ID
89  * @details
90  * The monster is known to be within 100 grids of the player\n
91  *\n
92  * In several cases, we directly update the monster lore\n
93  *\n
94  * Note that a monster is only allowed to "reproduce" if there\n
95  * are a limited number of "reproducing" monsters on the current\n
96  * level.  This should prevent the level from being "swamped" by\n
97  * reproducing monsters.  It also allows a large mass of mice to\n
98  * prevent a louse from multiplying, but this is a small price to\n
99  * pay for a simple ENERGY_MULTIPLICATION method.\n
100  *\n
101  * XXX Monster fear is slightly odd, in particular, monsters will\n
102  * fixate on opening a door even if they cannot open it.  Actually,\n
103  * the same thing happens to normal monsters when they hit a door\n
104  *\n
105  * In addition, monsters which *cannot* open or bash\n
106  * down a door will still stand there trying to open it...\n
107  *\n
108  * XXX Technically, need to check for monster in the way\n
109  * combined with that monster being in a wall (or door?)\n
110  *\n
111  * A "direction" of "5" means "pick a random direction".\n
112  */
113 void process_monster(PlayerType *player_ptr, MONSTER_IDX m_idx)
114 {
115     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
116     auto *r_ptr = &m_ptr->get_monrace();
117     turn_flags tmp_flags;
118     turn_flags *turn_flags_ptr = init_turn_flags(player_ptr->riding, m_idx, &tmp_flags);
119     turn_flags_ptr->see_m = is_seen(player_ptr, m_ptr);
120
121     decide_drop_from_monster(player_ptr, m_idx, turn_flags_ptr->is_riding_mon);
122     if (m_ptr->mflag2.has(MonsterConstantFlagType::CHAMELEON) && one_in_(13) && !m_ptr->is_asleep()) {
123         choose_new_monster(player_ptr, m_idx, false, MonsterRace::empty_id());
124         r_ptr = &m_ptr->get_monrace();
125     }
126
127     turn_flags_ptr->aware = process_stealth(player_ptr, m_idx);
128     if (vanish_summoned_children(player_ptr, m_idx, turn_flags_ptr->see_m)) {
129         return;
130     }
131
132     if (process_quantum_effect(player_ptr, m_idx, turn_flags_ptr->see_m)) {
133         return;
134     }
135
136     if (explode_grenade(player_ptr, m_idx)) {
137         return;
138     }
139
140     if (runaway_monster(player_ptr, turn_flags_ptr, m_idx)) {
141         return;
142     }
143
144     if (!awake_monster(player_ptr, m_idx)) {
145         return;
146     }
147
148     if (m_ptr->is_stunned() && one_in_(2)) {
149         return;
150     }
151
152     if (turn_flags_ptr->is_riding_mon) {
153         RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::BONUS);
154     }
155
156     process_angar(player_ptr, m_idx, turn_flags_ptr->see_m);
157
158     POSITION oy = m_ptr->fy;
159     POSITION ox = m_ptr->fx;
160     if (decide_monster_multiplication(player_ptr, m_idx, oy, ox)) {
161         return;
162     }
163
164     process_special(player_ptr, m_idx);
165     process_speak_sound(player_ptr, m_idx, oy, ox, turn_flags_ptr->aware);
166     if (cast_spell(player_ptr, m_idx, turn_flags_ptr->aware)) {
167         return;
168     }
169
170     DIRECTION mm[8];
171     mm[0] = mm[1] = mm[2] = mm[3] = 0;
172     mm[4] = mm[5] = mm[6] = mm[7] = 0;
173
174     if (!decide_monster_movement_direction(player_ptr, mm, m_idx, turn_flags_ptr->aware)) {
175         return;
176     }
177
178     int count = 0;
179     if (!process_monster_movement(player_ptr, turn_flags_ptr, m_idx, mm, { oy, ox }, &count)) {
180         return;
181     }
182
183     /*
184      *  Forward movements failed, but now received LOS attack!
185      *  Try to flow by smell.
186      */
187     if (player_ptr->no_flowed && count > 2 && m_ptr->target_y) {
188         m_ptr->mflag2.reset(MonsterConstantFlagType::NOFLOW);
189     }
190
191     if (!turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && !m_ptr->is_fearful() && !turn_flags_ptr->is_riding_mon && turn_flags_ptr->aware) {
192         if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell) {
193             if (make_attack_spell(player_ptr, m_idx)) {
194                 return;
195             }
196         }
197     }
198
199     update_map_flags(turn_flags_ptr);
200     update_lite_flags(turn_flags_ptr, r_ptr);
201     update_monster_race_flags(player_ptr, turn_flags_ptr, m_ptr);
202
203     if (!process_monster_fear(player_ptr, turn_flags_ptr, m_idx)) {
204         return;
205     }
206
207     if (m_ptr->ml) {
208         chg_virtue(player_ptr, Virtue::COMPASSION, -1);
209     }
210 }
211
212 /*!
213  * @brief 超隠密処理
214  * @param player_ptr プレイヤーへの参照ポインタ
215  * @param m_idx モンスターID
216  * @return モンスターがプレイヤーに気付いているならばTRUE、超隠密状態ならばFALSE
217  */
218 bool process_stealth(PlayerType *player_ptr, MONSTER_IDX m_idx)
219 {
220     auto ninja_data = PlayerClass(player_ptr).get_specific_data<ninja_data_type>();
221     if (!ninja_data || !ninja_data->s_stealth) {
222         return true;
223     }
224
225     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
226     auto *r_ptr = &m_ptr->get_monrace();
227     int tmp = player_ptr->lev * 6 + (player_ptr->skill_stl + 10) * 4;
228     if (player_ptr->monlite) {
229         tmp /= 3;
230     }
231
232     if (has_aggravate(player_ptr)) {
233         tmp /= 2;
234     }
235
236     if (r_ptr->level > (player_ptr->lev * player_ptr->lev / 20 + 10)) {
237         tmp /= 3;
238     }
239
240     return randint0(tmp) <= (r_ptr->level + 20);
241 }
242
243 /*!
244  * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
245  * @param player_ptr プレイヤーへの参照ポインタ
246  * @param m_idx モンスターID
247  * @param is_riding_mon 騎乗中であればTRUE
248  */
249 void decide_drop_from_monster(PlayerType *player_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
250 {
251     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
252     auto *r_ptr = &m_ptr->get_monrace();
253     if (!is_riding_mon || r_ptr->misc_flags.has(MonsterMiscType::RIDING)) {
254         return;
255     }
256
257     if (process_fall_off_horse(player_ptr, 0, true)) {
258 #ifdef JP
259         msg_print("地面に落とされた。");
260 #else
261         const auto m_name = monster_desc(player_ptr, &player_ptr->current_floor_ptr->m_list[player_ptr->riding], 0);
262         msg_format("You have fallen from %s.", m_name.data());
263 #endif
264     }
265 }
266
267 /*!
268  * @brief 召喚の親元が消滅した時、子供も消滅させる
269  * @param player_ptr プレイヤーへの参照ポインタ
270  * @param m_idx モンスターID
271  * @param see_m モンスターが視界内にいたらTRUE
272  * @return 召喚モンスターが消滅したらTRUE
273  */
274 bool vanish_summoned_children(PlayerType *player_ptr, MONSTER_IDX m_idx, bool see_m)
275 {
276     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
277
278     if (m_ptr->parent_m_idx == 0) {
279         return false;
280     }
281
282     // parent_m_idxが自分自身を指している場合は召喚主は消滅している
283     if (m_ptr->parent_m_idx != m_idx && MonsterRace(player_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx).is_valid()) {
284         return false;
285     }
286
287     if (see_m) {
288         const auto m_name = monster_desc(player_ptr, m_ptr, 0);
289         msg_format(_("%sは消え去った!", "%s^ disappears!"), m_name.data());
290     }
291
292     if (record_named_pet && m_ptr->is_named_pet()) {
293         const auto m_name = monster_desc(player_ptr, m_ptr, MD_INDEF_VISIBLE);
294         exe_write_diary(player_ptr, DiaryKind::NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
295     }
296
297     delete_monster_idx(player_ptr, m_idx);
298     return true;
299 }
300
301 /*!
302  * @brief 寝ているモンスターの起床を判定する
303  * @param player_ptr プレイヤーへの参照ポインタ
304  * @param m_idx モンスターID
305  * @return 寝たままならFALSE、起きているor起きたらTRUE
306  */
307 bool awake_monster(PlayerType *player_ptr, MONSTER_IDX m_idx)
308 {
309     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
310     auto *r_ptr = &m_ptr->get_monrace();
311     if (!m_ptr->is_asleep()) {
312         return true;
313     }
314
315     if (!has_aggravate(player_ptr)) {
316         return false;
317     }
318
319     (void)set_monster_csleep(player_ptr, m_idx, 0);
320     if (m_ptr->ml) {
321         const auto m_name = monster_desc(player_ptr, m_ptr, 0);
322         msg_format(_("%s^が目を覚ました。", "%s^ wakes up."), m_name.data());
323     }
324
325     if (is_original_ap_and_seen(player_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR)) {
326         r_ptr->r_wake++;
327     }
328
329     return true;
330 }
331
332 /*!
333  * @brief モンスターの怒り状態を判定する (怒っていたら敵に回す)
334  * @param player_ptr プレイヤーへの参照ポインタ
335  * @param m_idx モンスターID
336  * @param see_m モンスターが視界内にいたらTRUE
337  */
338 void process_angar(PlayerType *player_ptr, MONSTER_IDX m_idx, bool see_m)
339 {
340     auto &monster = player_ptr->current_floor_ptr->m_list[m_idx];
341     const auto &monrace = monster.get_monrace();
342     auto gets_angry = monster.is_friendly() && has_aggravate(player_ptr);
343     const auto should_aggravate = monster.is_pet();
344     auto has_hostile = monrace.kind_flags.has(MonsterKindType::UNIQUE) || (monrace.population_flags.has(MonsterPopulationType::NAZGUL));
345     has_hostile &= monster_has_hostile_align(player_ptr, nullptr, 10, -10, &monrace);
346     const auto has_resist_all = monrace.resistance_flags.has(MonsterResistanceType::RESIST_ALL);
347     if (should_aggravate && (has_hostile || has_resist_all)) {
348         gets_angry = true;
349     }
350
351     if (AngbandSystem::get_instance().is_phase_out() || !gets_angry) {
352         return;
353     }
354
355     const auto m_name = monster_desc(player_ptr, &monster, monster.is_pet() ? MD_ASSUME_VISIBLE : 0);
356
357     /* When riding a hostile alignment pet */
358     if (player_ptr->riding == m_idx) {
359         if (abs(player_ptr->alignment / 10) < randint0(player_ptr->skill_exp[PlayerSkillKindType::RIDING])) {
360             return;
361         }
362
363         msg_format(_("%s^が突然暴れだした!", "%s^ suddenly begins unruly!"), m_name.data());
364         if (!process_fall_off_horse(player_ptr, 1, true)) {
365             return;
366         }
367
368         msg_format(_("あなたは振り落とされた。", "You have fallen."));
369     }
370
371     if (monster.is_pet() || see_m) {
372         msg_format(_("%s^は突然敵にまわった!", "%s^ suddenly becomes hostile!"), m_name.data());
373     }
374
375     monster.set_hostile();
376 }
377
378 /*!
379  * @brief 手榴弾の爆発処理
380  * @param player_ptr プレイヤーへの参照ポインタ
381  * @param m_idx モンスターID
382  * @return 爆死したらTRUE
383  */
384 bool explode_grenade(PlayerType *player_ptr, MONSTER_IDX m_idx)
385 {
386     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
387     if (m_ptr->r_idx != MonsterRaceId::GRENADE) {
388         return false;
389     }
390
391     bool fear, dead;
392     mon_take_hit_mon(player_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
393     return dead;
394 }
395
396 /*!
397  * @brief モンスター依存の特別な行動を取らせる
398  * @param player_ptr プレイヤーへの参照ポインタ
399  * @param m_idx モンスターID
400  */
401 void process_special(PlayerType *player_ptr, MONSTER_IDX m_idx)
402 {
403     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
404     auto *r_ptr = &m_ptr->get_monrace();
405     auto can_do_special = r_ptr->ability_flags.has(MonsterAbilityType::SPECIAL);
406     can_do_special &= m_ptr->r_idx == MonsterRaceId::OHMU;
407     can_do_special &= !player_ptr->current_floor_ptr->inside_arena;
408     can_do_special &= !AngbandSystem::get_instance().is_phase_out();
409     can_do_special &= r_ptr->freq_spell != 0;
410     can_do_special &= randint1(100) <= r_ptr->freq_spell;
411     if (!can_do_special) {
412         return;
413     }
414
415     int count = 0;
416     DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
417     BIT_FLAGS p_mode = m_ptr->is_pet() ? PM_FORCE_PET : PM_NONE;
418
419     for (int k = 0; k < A_MAX; k++) {
420         if (summon_specific(player_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode))) {
421             if (player_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) {
422                 count++;
423             }
424         }
425     }
426
427     if (count && is_original_ap_and_seen(player_ptr, m_ptr)) {
428         r_ptr->r_ability_flags.set(MonsterAbilityType::SPECIAL);
429     }
430 }
431
432 /*!
433  * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
434  * @param player_ptr プレイヤーへの参照ポインタ
435  * @param m_idx モンスターID
436  * @param oy 分裂元モンスターのY座標
437  * @param ox 分裂元モンスターのX座標
438  * @return 実際に分裂したらTRUEを返す
439  */
440 bool decide_monster_multiplication(PlayerType *player_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
441 {
442     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
443     auto *r_ptr = &m_ptr->get_monrace();
444     if (r_ptr->misc_flags.has_not(MonsterMiscType::MULTIPLY) || (player_ptr->current_floor_ptr->num_repro >= MAX_REPRODUCTION)) {
445         return false;
446     }
447
448     int k = 0;
449     for (POSITION y = oy - 1; y <= oy + 1; y++) {
450         for (POSITION x = ox - 1; x <= ox + 1; x++) {
451             if (!in_bounds2(player_ptr->current_floor_ptr, y, x)) {
452                 continue;
453             }
454
455             if (player_ptr->current_floor_ptr->grid_array[y][x].has_monster()) {
456                 k++;
457             }
458         }
459     }
460
461     if (SpellHex(player_ptr).check_hex_barrier(m_idx, HEX_ANTI_MULTI)) {
462         k = 8;
463     }
464
465     constexpr auto chance_reproduction = 8;
466     if ((k < 4) && (!k || !randint0(k * chance_reproduction))) {
467         if (multiply_monster(player_ptr, m_idx, false, (m_ptr->is_pet() ? PM_FORCE_PET : 0))) {
468             if (player_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(player_ptr, m_ptr)) {
469                 r_ptr->r_misc_flags.set(MonsterMiscType::MULTIPLY);
470             }
471
472             return true;
473         }
474     }
475
476     return false;
477 }
478
479 /*!
480  * @brief モンスターに魔法を試行させる
481  * @param player_ptr プレイヤーへの参照ポインタ
482  * @param m_idx モンスターID
483  * @param aware モンスターがプレイヤーに気付いているならばTRUE、超隠密状態ならばFALSE
484  * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
485  */
486 bool cast_spell(PlayerType *player_ptr, MONSTER_IDX m_idx, bool aware)
487 {
488     auto &floor = *player_ptr->current_floor_ptr;
489     const auto &monster_from = floor.m_list[m_idx];
490     const auto &monrace = monster_from.get_monrace();
491     if ((monrace.freq_spell == 0) || (randint1(100) > monrace.freq_spell)) {
492         return false;
493     }
494
495     bool counterattack = false;
496     if (monster_from.target_y) {
497         Pos2D pos(monster_from.target_y, monster_from.target_x);
498         const auto t_m_idx = floor.get_grid(pos).m_idx;
499         const auto &monster_to = floor.m_list[t_m_idx];
500         const auto is_projectable = projectable(player_ptr, monster_from.fy, monster_from.fx, monster_from.target_y, monster_from.target_x);
501         if (t_m_idx && monster_from.is_hostile_to_melee(monster_to) && is_projectable) {
502             counterattack = true;
503         }
504     }
505
506     if (counterattack) {
507         if (monst_spell_monst(player_ptr, m_idx) || (aware && make_attack_spell(player_ptr, m_idx))) {
508             return true;
509         }
510     } else {
511         if ((aware && make_attack_spell(player_ptr, m_idx)) || monst_spell_monst(player_ptr, m_idx)) {
512             return true;
513         }
514     }
515
516     return false;
517 }
518
519 /*!
520  * @brief モンスターの恐怖状態を処理する
521  * @param player_ptr プレイヤーへの参照ポインタ
522  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
523  * @param m_idx モンスターID
524  * @param aware モンスターがプレイヤーに気付いているならばTRUE、超隠密状態ならばFALSE
525  * @return モンスターが戦いを決意したらTRUE
526  */
527 bool process_monster_fear(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
528 {
529     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
530     bool is_battle_determined = !turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && m_ptr->is_fearful() && turn_flags_ptr->aware;
531     if (!is_battle_determined) {
532         return false;
533     }
534
535     (void)set_monster_monfear(player_ptr, m_idx, 0);
536     if (!turn_flags_ptr->see_m) {
537         return true;
538     }
539
540     const auto m_name = monster_desc(player_ptr, m_ptr, 0);
541     msg_format(_("%s^は戦いを決意した!", "%s^ turns to fight!"), m_name.data());
542     return true;
543 }
544
545 /*!
546  * @brief 全モンスターのターン管理メインルーチン /
547  * Process all the "live" monsters, once per game turn.
548  * @details
549  * During each game current game turn, we scan through the list of all the "live" monsters,\n
550  * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
551  * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
552  *\n
553  * Note that monsters can never move in the monster array (except when the\n
554  * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
555  *\n
556  * This function is responsible for at least half of the processor time\n
557  * on a normal system with a "normal" amount of monsters and a player doing\n
558  * normal things.\n
559  *\n
560  * When the player is resting, virtually 90% of the processor time is spent\n
561  * in this function, and its children, "process_monster()" and "make_move()".\n
562  *\n
563  * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
564  * especially when the player is running.\n
565  *\n
566  * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
567  * monsters while they are still being "born".  A monster is "fresh" only\n
568  * during the game turn in which it is created, and we use the "hack_m_idx" to\n
569  * determine if the monster is yet to be processed during the game turn.\n
570  *\n
571  * Note the special "MFLAG_PREVENT_MAGIC" flag, which allows the player to get one\n
572  * move before any "nasty" monsters get to use their spell attacks.\n
573  *\n
574  * Note that when the "knowledge" about the currently tracked monster\n
575  * changes (flags, attacks, spells), we induce a redraw of the monster\n
576  * recall window.\n
577  */
578 void process_monsters(PlayerType *player_ptr)
579 {
580     const auto old_monrace_id = player_ptr->monster_race_idx;
581     old_race_flags tmp_flags(old_monrace_id);
582     old_race_flags *old_race_flags_ptr = &tmp_flags;
583     player_ptr->current_floor_ptr->monster_noise = false;
584     sweep_monster_process(player_ptr);
585     hack_m_idx = 0;
586     if (!MonsterRace(player_ptr->monster_race_idx).is_valid() || (player_ptr->monster_race_idx != old_monrace_id)) {
587         return;
588     }
589
590     update_player_window(player_ptr, old_race_flags_ptr);
591 }
592
593 /*!
594  * @brief フロア内のモンスターについてターン終了時の処理を繰り返す
595  * @param player_ptr プレイヤーへの参照ポインタ
596  */
597 void sweep_monster_process(PlayerType *player_ptr)
598 {
599     auto *floor_ptr = player_ptr->current_floor_ptr;
600     for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--) {
601         MonsterEntity *m_ptr;
602         m_ptr = &floor_ptr->m_list[i];
603
604         if (player_ptr->leaving) {
605             return;
606         }
607
608         if (!m_ptr->is_valid() || player_ptr->wild_mode) {
609             continue;
610         }
611
612         if (m_ptr->mflag.has(MonsterTemporaryFlagType::BORN)) {
613             m_ptr->mflag.reset(MonsterTemporaryFlagType::BORN);
614             continue;
615         }
616
617         if ((m_ptr->cdis >= MAX_MONSTER_SENSING) || !decide_process_continue(player_ptr, m_ptr)) {
618             continue;
619         }
620
621         byte speed = (player_ptr->riding == i) ? player_ptr->pspeed : m_ptr->get_temporary_speed();
622         m_ptr->energy_need -= speed_to_energy(speed);
623         if (m_ptr->energy_need > 0) {
624             continue;
625         }
626
627         m_ptr->energy_need += ENERGY_NEED();
628         hack_m_idx = i;
629         process_monster(player_ptr, i);
630         reset_target(m_ptr);
631         if (player_ptr->no_flowed && one_in_(3)) {
632             m_ptr->mflag2.set(MonsterConstantFlagType::NOFLOW);
633         }
634
635         if (!player_ptr->playing || player_ptr->is_dead || player_ptr->leaving) {
636             return;
637         }
638     }
639 }
640
641 /*!
642  * @brief 後続のモンスター処理が必要かどうか判定する (要調査)
643  * @param player_ptr プレイヤーへの参照ポインタ
644  * @param m_ptr モンスターへの参照ポインタ
645  * @return 後続処理が必要ならTRUE
646  */
647 bool decide_process_continue(PlayerType *player_ptr, MonsterEntity *m_ptr)
648 {
649     const auto &monrace = m_ptr->get_monrace();
650     if (!player_ptr->no_flowed) {
651         m_ptr->mflag2.reset(MonsterConstantFlagType::NOFLOW);
652     }
653
654     if (m_ptr->cdis <= (m_ptr->is_pet() ? (monrace.aaf > MAX_PLAYER_SIGHT ? MAX_PLAYER_SIGHT : monrace.aaf) : monrace.aaf)) {
655         return true;
656     }
657
658     auto should_continue = (m_ptr->cdis <= MAX_PLAYER_SIGHT) || AngbandSystem::get_instance().is_phase_out();
659     should_continue &= player_ptr->current_floor_ptr->has_los({ m_ptr->fy, m_ptr->fx }) || has_aggravate(player_ptr);
660     if (should_continue) {
661         return true;
662     }
663
664     if (m_ptr->target_y) {
665         return true;
666     }
667
668     return false;
669 }