OSDN Git Service

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