OSDN Git Service

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