OSDN Git Service

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