OSDN Git Service

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