OSDN Git Service

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