OSDN Git Service

5b41dd21c32df8ce4a78ba7ae09f631ba880ea44
[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-attack.h"
19 #include "monster/monster-direction.h"
20 #include "monster/monster-object.h"
21 #include "monster/monster-move.h"
22 #include "monster/monster-runaway.h"
23 #include "monster/monster-safety-hiding.h"
24 #include "monster/monster-util.h"
25 #include "monster/monster-update.h"
26 #include "monster/quantum-effect.h"
27
28 #include "cmd-dump.h"
29 #include "cmd-pet.h"
30 #include "creature.h"
31 #include "melee.h"
32 #include "spells.h"
33 #include "spells-floor.h"
34 #include "spells-summon.h"
35 #include "avatar.h"
36 #include "realm-hex.h"
37 #include "feature.h"
38 #include "grid.h"
39 #include "player-move.h"
40 #include "monster-status.h"
41 #include "monster-spell.h"
42 #include "monster-process.h"
43 #include "monsterrace-hook.h"
44 #include "floor.h"
45 #include "files.h"
46 #include "view-mainwindow.h"
47
48 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
49 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx);
50 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
51 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx);
52 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
53 bool explode_grenade(player_type *target_ptr, MONSTER_IDX m_idx);
54 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
55 void process_special(player_type *target_ptr, MONSTER_IDX m_idx);
56 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware);
57 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware);
58
59 bool process_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, DIRECTION *mm, POSITION oy, POSITION ox, int *count);
60 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
61 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
62
63 void sweep_monster_process(player_type *target_ptr);
64 bool decide_process_continue(player_type *target_ptr, monster_type *m_ptr);
65
66 /*!
67  * @brief モンスターがプレイヤーから逃走するかどうかを返す /
68  * Returns whether a given monster will try to run from the player.
69  * @param m_idx 逃走するモンスターの参照ID
70  * @return モンスターがプレイヤーから逃走するならばTRUEを返す。
71  * @details
72  * Monsters will attempt to avoid very powerful players.  See below.\n
73  *\n
74  * Because this function is called so often, little details are important\n
75  * for efficiency.  Like not using "mod" or "div" when possible.  And\n
76  * attempting to check the conditions in an optimal order.  Note that\n
77  * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
78  *\n
79  * Note that this function is responsible for about one to five percent\n
80  * of the processor use in normal conditions...\n
81  */
82 static bool mon_will_run(player_type *target_ptr, MONSTER_IDX m_idx)
83 {
84         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
85         monster_race *r_ptr = &r_info[m_ptr->r_idx];
86
87         if (is_pet(m_ptr))
88         {
89                 return ((target_ptr->pet_follow_distance < 0) &&
90                         (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
91         }
92
93         if (m_ptr->cdis > MAX_SIGHT + 5) return FALSE;
94         if (MON_MONFEAR(m_ptr)) return TRUE;
95         if (m_ptr->cdis <= 5) return FALSE;
96
97         PLAYER_LEVEL p_lev = target_ptr->lev;
98         DEPTH m_lev = r_ptr->level + (m_idx & 0x08) + 25;
99         if (m_lev > p_lev + 4) return FALSE;
100         if (m_lev + 4 <= p_lev) return TRUE;
101
102         HIT_POINT p_chp = target_ptr->chp;
103         HIT_POINT p_mhp = target_ptr->mhp;
104         HIT_POINT m_chp = m_ptr->hp;
105         HIT_POINT m_mhp = m_ptr->maxhp;
106         u32b p_val = (p_lev * p_mhp) + (p_chp << 2);
107         u32b m_val = (m_lev * m_mhp) + (m_chp << 2);
108         if (p_val * m_mhp > m_val * p_mhp) return TRUE;
109
110         return FALSE;
111 }
112
113
114 /*!
115  * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
116  * Search spell castable grid
117  * @param target_ptr プレーヤーへの参照ポインタ
118  * @param m_idx モンスターの参照ID
119  * @param yp 適したマスのY座標を返す参照ポインタ
120  * @param xp 適したマスのX座標を返す参照ポインタ
121  * @return 有効なマスがあった場合TRUEを返す
122  */
123 static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
124 {
125         floor_type *floor_ptr = target_ptr->current_floor_ptr;
126         monster_type *m_ptr = &floor_ptr->m_list[m_idx];
127         monster_race *r_ptr = &r_info[m_ptr->r_idx];
128
129         POSITION y1 = m_ptr->fy;
130         POSITION x1 = m_ptr->fx;
131
132         if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x)) return FALSE;
133
134         int now_cost = floor_ptr->grid_array[y1][x1].cost;
135         if (now_cost == 0) now_cost = 999;
136
137         bool can_open_door = FALSE;
138         if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
139         {
140                 can_open_door = TRUE;
141         }
142
143         int best = 999;
144         for (int i = 7; i >= 0; i--)
145         {
146                 POSITION y = y1 + ddy_ddd[i];
147                 POSITION x = x1 + ddx_ddd[i];
148                 if (!in_bounds2(floor_ptr, y, x)) continue;
149                 if (player_bold(target_ptr, y, x)) return FALSE;
150
151                 grid_type *g_ptr;
152                 g_ptr = &floor_ptr->grid_array[y][x];
153                 int cost = g_ptr->cost;
154                 if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) || ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding))))
155                 {
156                         if (cost == 0) continue;
157                         if (!can_open_door && is_closed_door(target_ptr, g_ptr->feat)) continue;
158                 }
159
160                 if (cost == 0) cost = 998;
161
162                 if (now_cost < cost) continue;
163                 if (!projectable(target_ptr, y, x, target_ptr->y, target_ptr->x)) continue;
164                 if (best < cost) continue;
165
166                 best = cost;
167                 *yp = y1 + ddy_ddd[i];
168                 *xp = x1 + ddx_ddd[i];
169         }
170
171         if (best == 999) return FALSE;
172
173         return TRUE;
174 }
175
176
177 /*!
178  * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
179  * Choose the "best" direction for "flowing"
180  * @param m_idx モンスターの参照ID
181  * @param yp 移動先のマスのY座標を返す参照ポインタ
182  * @param xp 移動先のマスのX座標を返す参照ポインタ
183  * @param no_flow モンスターにFLOWフラグが経っていない状態でTRUE
184  * @return 有効なマスがあった場合TRUEを返す
185  * @details
186  * Note that ghosts and rock-eaters are never allowed to "flow",\n
187  * since they should move directly towards the player.\n
188  *\n
189  * Prefer "non-diagonal" directions, but twiddle them a little\n
190  * to angle slightly towards the player's actual location.\n
191  *\n
192  * Allow very perceptive monsters to track old "spoor" left by\n
193  * previous locations occupied by the player.  This will tend\n
194  * to have monsters end up either near the player or on a grid\n
195  * recently occupied by the player (and left via "teleport").\n
196  *\n
197  * Note that if "smell" is turned on, all monsters get vicious.\n
198  *\n
199  * Also note that teleporting away from a location will cause\n
200  * the monsters who were chasing you to converge on that location\n
201  * as long as you are still near enough to "annoy" them without\n
202  * being close enough to chase directly.  I have no idea what will\n
203  * happen if you combine "smell" with low "aaf" values.\n
204  */
205 static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
206 {
207         grid_type *g_ptr;
208         floor_type *floor_ptr = target_ptr->current_floor_ptr;
209         monster_type *m_ptr = &floor_ptr->m_list[m_idx];
210         monster_race *r_ptr = &r_info[m_ptr->r_idx];
211
212         if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
213                 r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
214                 r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
215         {
216                 if (get_moves_aux2(target_ptr, m_idx, yp, xp)) return TRUE;
217         }
218
219         if (no_flow) return FALSE;
220         if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) return FALSE;
221         if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)) return FALSE;
222
223         POSITION y1 = m_ptr->fy;
224         POSITION x1 = m_ptr->fx;
225         if (player_has_los_bold(target_ptr, y1, x1) && projectable(target_ptr, target_ptr->y, target_ptr->x, y1, x1)) return FALSE;
226
227         g_ptr = &floor_ptr->grid_array[y1][x1];
228
229         int best;
230         bool use_scent = FALSE;
231         if (g_ptr->cost)
232         {
233                 best = 999;
234         }
235         else if (g_ptr->when)
236         {
237                 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when - g_ptr->when > 127) return FALSE;
238
239                 use_scent = TRUE;
240                 best = 0;
241         }
242         else
243         {
244                 return FALSE;
245         }
246
247         for (int i = 7; i >= 0; i--)
248         {
249                 POSITION y = y1 + ddy_ddd[i];
250                 POSITION x = x1 + ddx_ddd[i];
251
252                 if (!in_bounds2(floor_ptr, y, x)) continue;
253
254                 g_ptr = &floor_ptr->grid_array[y][x];
255                 if (use_scent)
256                 {
257                         int when = g_ptr->when;
258                         if (best > when) continue;
259
260                         best = when;
261                 }
262                 else
263                 {
264                         int cost;
265                         if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
266                         {
267                                 cost = g_ptr->dist;
268                         }
269                         else
270                         {
271                                 cost = g_ptr->cost;
272                         }
273
274                         if ((cost == 0) || (best < cost)) continue;
275
276                         best = cost;
277                 }
278
279                 *yp = target_ptr->y + 16 * ddy_ddd[i];
280                 *xp = target_ptr->x + 16 * ddx_ddd[i];
281         }
282
283         if (best == 999 || best == 0) return FALSE;
284
285         return TRUE;
286 }
287
288
289 /*!
290  * @brief モンスターがプレイヤーから逃走することが可能なマスを走査する /
291  * Provide a location to flee to, but give the player a wide berth.
292  * @param m_idx モンスターの参照ID
293  * @param yp 移動先のマスのY座標を返す参照ポインタ
294  * @param xp 移動先のマスのX座標を返す参照ポインタ
295  * @return 有効なマスがあった場合TRUEを返す
296  * @details
297  * A monster may wish to flee to a location that is behind the player,\n
298  * but instead of heading directly for it, the monster should "swerve"\n
299  * around the player so that he has a smaller chance of getting hit.\n
300  */
301 static bool get_fear_moves_aux(floor_type *floor_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
302 {
303         POSITION gy = 0, gx = 0;
304
305         monster_type *m_ptr = &floor_ptr->m_list[m_idx];
306         POSITION fy = m_ptr->fy;
307         POSITION fx = m_ptr->fx;
308
309         POSITION y1 = fy - (*yp);
310         POSITION x1 = fx - (*xp);
311
312         int score = -1;
313         for (int i = 7; i >= 0; i--)
314         {
315                 POSITION y = fy + ddy_ddd[i];
316                 POSITION x = fx + ddx_ddd[i];
317                 if (!in_bounds2(floor_ptr, y, x)) continue;
318
319                 POSITION dis = distance(y, x, y1, x1);
320                 POSITION s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
321                 if (s < 0) s = 0;
322
323                 if (s < score) continue;
324
325                 score = s;
326                 gy = y;
327                 gx = x;
328         }
329
330         if (score == -1) return FALSE;
331
332         (*yp) = fy - gy;
333         (*xp) = fx - gx;
334
335         return TRUE;
336 }
337
338
339 /*!
340  * todo 分割したいが条件が多すぎて適切な関数名と詳細処理を追いきれない……
341  * @brief モンスターの移動方向を返す /
342  * Choose "logical" directions for monster movement
343  * @param target_ptr プレーヤーへの参照ポインタ
344  * @param m_idx モンスターの参照ID
345  * @param mm 移動方向を返す方向IDの参照ポインタ
346  * @return 有効方向があった場合TRUEを返す
347  */
348 static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
349 {
350         floor_type *floor_ptr = target_ptr->current_floor_ptr;
351         monster_type *m_ptr = &floor_ptr->m_list[m_idx];
352         monster_race *r_ptr = &r_info[m_ptr->r_idx];
353         POSITION y = 0, x = 0;
354         POSITION y2 = target_ptr->y;
355         POSITION x2 = target_ptr->x;
356         bool done = FALSE;
357         bool will_run = mon_will_run(target_ptr, m_idx);
358         grid_type *g_ptr;
359         bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) != 0) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2);
360         bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) != 0) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall);
361
362         if (!will_run && m_ptr->target_y)
363         {
364                 int t_m_idx = floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
365                 if ((t_m_idx > 0) &&
366                         are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[t_m_idx]) &&
367                         los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
368                         projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
369                 {
370                         y = m_ptr->fy - m_ptr->target_y;
371                         x = m_ptr->fx - m_ptr->target_x;
372                         done = TRUE;
373                 }
374         }
375
376         if (!done && !will_run && is_hostile(m_ptr) &&
377                 (r_ptr->flags1 & RF1_FRIENDS) &&
378                 ((los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x) && projectable(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x)) ||
379                 (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
380         {
381                 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
382                         !(r_ptr->flags2 & RF2_KILL_WALL))
383                 {
384                         int room = 0;
385                         for (int i = 0; i < 8; i++)
386                         {
387                                 int xx = target_ptr->x + ddx_ddd[i];
388                                 int yy = target_ptr->y + ddy_ddd[i];
389
390                                 if (!in_bounds2(floor_ptr, yy, xx)) continue;
391
392                                 g_ptr = &floor_ptr->grid_array[yy][xx];
393                                 if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0))
394                                 {
395                                         room++;
396                                 }
397                         }
398
399                         if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].info & CAVE_ROOM) room -= 2;
400                         if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
401
402                         if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
403                                 (target_ptr->mhp + target_ptr->msp))
404                         {
405                                 if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
406                         }
407                 }
408
409                 if (!done && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
410                 {
411                         for (int i = 0; i < 8; i++)
412                         {
413                                 y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
414                                 x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
415                                 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
416                                 {
417                                         y2 = target_ptr->y;
418                                         x2 = target_ptr->x;
419                                         break;
420                                 }
421
422                                 if (!in_bounds2(floor_ptr, y2, x2)) continue;
423                                 if (!monster_can_enter(target_ptr, y2, x2, r_ptr, 0)) continue;
424
425                                 break;
426                         }
427
428                         y = m_ptr->fy - y2;
429                         x = m_ptr->fx - x2;
430                         done = TRUE;
431                 }
432         }
433
434         if (!done)
435         {
436                 (void)get_moves_aux(target_ptr, m_idx, &y2, &x2, no_flow);
437                 y = m_ptr->fy - y2;
438                 x = m_ptr->fx - x2;
439         }
440
441         if (is_pet(m_ptr) && will_run)
442         {
443                 y = (-y), x = (-x);
444         }
445         else
446         {
447                 if (!done && will_run)
448                 {
449                         int tmp_x = (-x);
450                         int tmp_y = (-y);
451                         if (find_safety(target_ptr, m_idx, &y, &x) && !no_flow)
452                         {
453                                 if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x))
454                                         done = TRUE;
455                         }
456
457                         if (!done)
458                         {
459                                 y = tmp_y;
460                                 x = tmp_x;
461                         }
462                 }
463         }
464
465         if (!x && !y) return FALSE;
466
467         store_moves_val(mm, y, x);
468         return TRUE;
469 }
470
471
472 /*!
473  * @brief モンスター単体の1ターン行動処理メインルーチン /
474  * Process a monster
475  * @param target_ptr プレーヤーへの参照ポインタ
476  * @param m_idx 行動モンスターの参照ID
477  * @return なし
478  * @details
479  * The monster is known to be within 100 grids of the player\n
480  *\n
481  * In several cases, we directly update the monster lore\n
482  *\n
483  * Note that a monster is only allowed to "reproduce" if there\n
484  * are a limited number of "reproducing" monsters on the current\n
485  * level.  This should prevent the level from being "swamped" by\n
486  * reproducing monsters.  It also allows a large mass of mice to\n
487  * prevent a louse from multiplying, but this is a small price to\n
488  * pay for a simple multiplication method.\n
489  *\n
490  * XXX Monster fear is slightly odd, in particular, monsters will\n
491  * fixate on opening a door even if they cannot open it.  Actually,\n
492  * the same thing happens to normal monsters when they hit a door\n
493  *\n
494  * In addition, monsters which *cannot* open or bash\n
495  * down a door will still stand there trying to open it...\n
496  *\n
497  * XXX Technically, need to check for monster in the way\n
498  * combined with that monster being in a wall (or door?)\n
499  *\n
500  * A "direction" of "5" means "pick a random direction".\n
501  */
502 void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
503 {
504         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
505         monster_race *r_ptr = &r_info[m_ptr->r_idx];
506         turn_flags tmp_flags;
507         turn_flags *turn_flags_ptr = init_turn_flags(target_ptr->riding, m_idx, &tmp_flags);
508         turn_flags_ptr->see_m = is_seen(m_ptr);
509
510         decide_drop_from_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon);
511         if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
512         {
513                 choose_new_monster(target_ptr, m_idx, FALSE, 0);
514                 r_ptr = &r_info[m_ptr->r_idx];
515         }
516
517         turn_flags_ptr->aware = process_stealth(target_ptr, m_idx);
518         if (vanish_summoned_children(target_ptr, m_idx, turn_flags_ptr->see_m)) return;
519         if (process_quantum_effect(target_ptr, m_idx, turn_flags_ptr->see_m)) return;
520         if (explode_grenade(target_ptr, m_idx)) return;
521         if (runaway_monster(target_ptr, turn_flags_ptr, m_idx)) return;
522
523         awake_monster(target_ptr, m_idx);
524         if (MON_STUNNED(m_ptr))
525         {
526                 if (one_in_(2)) return;
527         }
528
529         if (turn_flags_ptr->is_riding_mon)
530         {
531                 target_ptr->update |= (PU_BONUS);
532         }
533
534         process_angar(target_ptr, m_idx, turn_flags_ptr->see_m);
535
536         POSITION oy = m_ptr->fy;
537         POSITION ox = m_ptr->fx;
538         if (decide_monster_multiplication(target_ptr, m_idx, oy, ox)) return;
539
540         process_special(target_ptr, m_idx);
541         process_speak_sound(target_ptr, m_idx, oy, ox, turn_flags_ptr->aware);
542         if (cast_spell(target_ptr, m_idx, turn_flags_ptr->aware)) return;
543
544         DIRECTION mm[8];
545         mm[0] = mm[1] = mm[2] = mm[3] = 0;
546         mm[4] = mm[5] = mm[6] = mm[7] = 0;
547
548         if (!decide_monster_movement_direction(target_ptr, mm, m_idx, turn_flags_ptr->aware, get_moves)) return;
549
550         int count = 0;
551         if (!process_monster_movement(target_ptr, turn_flags_ptr, m_idx, mm, oy, ox, &count)) return;
552
553         /*
554          *  Forward movements failed, but now received LOS attack!
555          *  Try to flow by smell.
556          */
557         if (target_ptr->no_flowed && count > 2 && m_ptr->target_y)
558                 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
559
560         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)
561         {
562                 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
563                 {
564                         if (make_attack_spell(m_idx, target_ptr)) return;
565                 }
566         }
567
568         update_player_type(target_ptr, turn_flags_ptr, r_ptr);
569         update_monster_race_flags(target_ptr, turn_flags_ptr, m_ptr);
570
571         if (!process_monster_fear(target_ptr, turn_flags_ptr, m_idx)) return;
572
573         if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
574 }
575
576
577 /*!
578  * @brief 超隠密処理
579  * @param target_ptr プレーヤーへの参照ポインタ
580  * @param m_idx モンスターID
581  * @return モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
582  */
583 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx)
584 {
585         if ((target_ptr->special_defense & NINJA_S_STEALTH) == 0) return TRUE;
586
587         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
588         monster_race *r_ptr = &r_info[m_ptr->r_idx];
589         int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
590         if (target_ptr->monlite) tmp /= 3;
591         if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
592         if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
593         return (randint0(tmp) <= (r_ptr->level + 20));
594 }
595
596
597 /*!
598  * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
599  * @param target_ptr プレーヤーへの参照ポインタ
600  * @param m_idx モンスターID
601  * @param is_riding_mon 騎乗中であればTRUE
602  * @return なし
603  */
604 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
605 {
606         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
607         monster_race *r_ptr = &r_info[m_ptr->r_idx];
608         if (!is_riding_mon || ((r_ptr->flags7 & RF7_RIDING) != 0)) return;
609
610         if (rakuba(target_ptr, 0, TRUE))
611         {
612 #ifdef JP
613                 msg_print("地面に落とされた。");
614 #else
615                 GAME_TEXT m_name[MAX_NLEN];
616                 monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
617                 msg_format("You have fallen from %s.", m_name);
618 #endif
619         }
620 }
621
622
623 /*!
624  * @brief 召喚の親元が消滅した時、子供も消滅させる
625  * @param target_ptr プレーヤーへの参照ポインタ
626  * @param m_idx モンスターID
627  * @param see_m モンスターが視界内にいたらTRUE
628  * @return 召喚モンスターが消滅したらTRUE
629  */
630 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
631 {
632         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
633         if ((m_ptr->parent_m_idx == 0) || (target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx > 0))
634                 return FALSE;
635
636         if (see_m)
637         {
638                 GAME_TEXT m_name[MAX_NLEN];
639                 monster_desc(target_ptr, m_name, m_ptr, 0);
640                 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
641         }
642
643         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
644         {
645                 GAME_TEXT m_name[MAX_NLEN];
646                 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
647                 exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
648         }
649
650         delete_monster_idx(target_ptr, m_idx);
651         return TRUE;
652 }
653
654
655 /*!
656  * @brief 寝ているモンスターの起床を判定する
657  * @param target_ptr プレーヤーへの参照ポインタ
658  * @param m_idx モンスターID
659  * @return なし
660  */
661 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx)
662 {
663         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
664         monster_race *r_ptr = &r_info[m_ptr->r_idx];
665         if (!MON_CSLEEP(m_ptr)) return;
666         if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
667
668         (void)set_monster_csleep(target_ptr, m_idx, 0);
669         if (m_ptr->ml)
670         {
671                 GAME_TEXT m_name[MAX_NLEN];
672                 monster_desc(target_ptr, m_name, m_ptr, 0);
673                 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
674         }
675
676         if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
677         {
678                 r_ptr->r_wake++;
679         }
680 }
681
682
683 /*!
684  * @brief モンスターの怒り状態を判定する (起こっていたら敵に回す)
685  * @param target_ptr プレーヤーへの参照ポインタ
686  * @param m_idx モンスターID
687  * @param see_m モンスターが視界内にいたらTRUE
688  * @return なし
689  */
690 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
691 {
692         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
693         monster_race *r_ptr = &r_info[m_ptr->r_idx];
694         bool gets_angry = FALSE;
695         if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
696                 gets_angry = TRUE;
697
698         if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
699                 monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
700         {
701                 gets_angry = TRUE;
702         }
703
704         if (target_ptr->phase_out || !gets_angry) return;
705
706         if (is_pet(m_ptr) || see_m)
707         {
708                 GAME_TEXT m_name[MAX_NLEN];
709                 monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
710                 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
711         }
712
713         set_hostile(target_ptr, m_ptr);
714 }
715
716
717 /*!
718  * @brief 手榴弾の爆発処理
719  * @param target_ptr プレーヤーへの参照ポインタ
720  * @param m_idx モンスターID
721  * @return 爆死したらTRUE
722  */
723 bool explode_grenade(player_type *target_ptr, MONSTER_IDX m_idx)
724 {
725         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
726         if (m_ptr->r_idx != MON_GRENADE) return FALSE;
727
728         bool fear, dead;
729         mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
730         return dead;
731 }
732
733
734 /*!
735  * @brief モンスター依存の特別な行動を取らせる
736  * @param target_ptr プレーヤーへの参照ポインタ
737  * @param m_idx モンスターID
738  * @return なし
739  */
740 void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
741 {
742         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
743         monster_race *r_ptr = &r_info[m_ptr->r_idx];
744         if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
745         if (m_ptr->r_idx != MON_OHMU) return;
746         if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
747         if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
748
749         int count = 0;
750         DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
751         BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
752
753         for (int k = 0; k < A_MAX; k++)
754         {
755                 if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
756                 {
757                         if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
758                 }
759         }
760
761         if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
762 }
763
764
765 /*!
766  * @brief モンスターを喋らせたり足音を立てたりする
767  * @param target_ptr プレーヤーへの参照ポインタ
768  * @param m_idx モンスターID
769  * @param oy モンスターが元々いたY座標
770  * @param ox モンスターが元々いたX座標
771  * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
772  * @return なし
773  */
774 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware)
775 {
776         if (target_ptr->phase_out) return;
777
778         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
779         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
780         if (m_ptr->ap_r_idx == MON_CYBER &&
781                 one_in_(CYBERNOISE) &&
782                 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
783         {
784                 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
785                 msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
786         }
787
788         if (((ap_r_ptr->flags2 & RF2_CAN_SPEAK) == 0) || !aware ||
789                 !one_in_(SPEAK_CHANCE) ||
790                 !player_has_los_bold(target_ptr, oy, ox) ||
791                 !projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
792                 return;
793
794         GAME_TEXT m_name[MAX_NLEN];
795         char monmessage[1024];
796         concptr filename;
797
798         if (m_ptr->ml)
799                 monster_desc(target_ptr, m_name, m_ptr, 0);
800         else
801                 strcpy(m_name, _("それ", "It"));
802
803         if (MON_MONFEAR(m_ptr))
804                 filename = _("monfear_j.txt", "monfear.txt");
805         else if (is_pet(m_ptr))
806                 filename = _("monpet_j.txt", "monpet.txt");
807         else if (is_friendly(m_ptr))
808                 filename = _("monfrien_j.txt", "monfrien.txt");
809         else
810                 filename = _("monspeak_j.txt", "monspeak.txt");
811
812         if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
813         {
814                 msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
815         }
816 }
817
818
819 /*!
820  * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
821  * @param target_ptr プレーヤーへの参照ポインタ
822  * @param m_idx モンスターID
823  * @param oy 分裂元モンスターのY座標
824  * @param ox 分裂元モンスターのX座標
825  * @return 実際に分裂したらTRUEを返す
826  */
827 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
828 {
829         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
830         monster_race *r_ptr = &r_info[m_ptr->r_idx];
831         if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) || (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
832                 return FALSE;
833
834         int k = 0;
835         for (POSITION y = oy - 1; y <= oy + 1; y++)
836         {
837                 for (POSITION x = ox - 1; x <= ox + 1; x++)
838                 {
839                         if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
840                         if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
841                 }
842         }
843
844         if (multiply_barrier(target_ptr, m_idx)) k = 8;
845
846         if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
847         {
848                 if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
849                 {
850                         if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
851                         {
852                                 r_ptr->r_flags2 |= (RF2_MULTIPLY);
853                         }
854
855                         return TRUE;
856                 }
857         }
858
859         return FALSE;
860 }
861
862
863 /*!
864  * @brief モンスターに魔法を試行させる
865  * @param target_ptr プレーヤーへの参照ポインタ
866  * @param m_idx モンスターID
867  * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
868  * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
869  */
870 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware)
871 {
872         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
873         monster_race *r_ptr = &r_info[m_ptr->r_idx];
874         if ((r_ptr->freq_spell == 0) || (randint1(100) > r_ptr->freq_spell))
875                 return FALSE;
876
877         bool counterattack = FALSE;
878         if (m_ptr->target_y)
879         {
880                 MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
881                 if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
882                         projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
883                 {
884                         counterattack = TRUE;
885                 }
886         }
887
888         if (counterattack)
889         {
890                 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
891                 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
892         }
893         else
894         {
895                 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
896                 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
897         }
898
899         return FALSE;
900 }
901
902
903 /*!
904  * todo 少し長いが、これといってブロックとしてまとまった部分もないので暫定でこのままとする
905  * @brief モンスターの移動に関するメインルーチン
906  * @param target_ptr プレーヤーへの参照ポインタ
907  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
908  * @param m_idx モンスターID
909  * @param mm モンスターの移動方向
910  * @param oy 移動前の、モンスターのY座標
911  * @param ox 移動前の、モンスターのX座標
912  * @param count 移動回数 (のはず todo)
913  * @return 移動が阻害される何か (ドア等)があったらFALSE
914  */
915 bool process_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, DIRECTION *mm, POSITION oy, POSITION ox, int *count)
916 {
917         for (int i = 0; mm[i]; i++)
918         {
919                 int d = mm[i];
920                 if (d == 5) d = ddd[randint0(8)];
921
922                 POSITION ny = oy + ddy[d];
923                 POSITION nx = ox + ddx[d];
924                 if (!in_bounds2(target_ptr->current_floor_ptr, ny, nx)) continue;
925
926                 grid_type *g_ptr;
927                 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
928                 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
929                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
930                 bool can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0);
931
932                 if (!process_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx, can_cross))
933                 {
934                         if (!process_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
935                                 return FALSE;
936                 }
937
938                 if (!process_protection_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
939                 {
940                         if (!process_explosive_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
941                                 return FALSE;
942                 }
943
944                 exe_monster_attack_to_player(target_ptr, turn_flags_ptr, m_idx, ny, nx);
945                 if (process_monster_attack_to_monster(target_ptr, turn_flags_ptr, m_idx, g_ptr, can_cross)) return FALSE;
946
947                 if (turn_flags_ptr->is_riding_mon)
948                 {
949                         if (!target_ptr->riding_ryoute && !MON_MONFEAR(&target_ptr->current_floor_ptr->m_list[target_ptr->riding])) turn_flags_ptr->do_move = FALSE;
950                 }
951
952                 if (!process_post_dig_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx)) return FALSE;
953
954                 if (turn_flags_ptr->must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
955                 {
956                         if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0))
957                                 turn_flags_ptr->do_move = FALSE;
958                 }
959
960                 if (turn_flags_ptr->do_move && !can_cross && !turn_flags_ptr->did_kill_wall && !turn_flags_ptr->did_bash_door)
961                         turn_flags_ptr->do_move = FALSE;
962
963                 if (turn_flags_ptr->do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
964                 {
965                         if (is_original_ap_and_seen(target_ptr, m_ptr))
966                                 r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
967
968                         turn_flags_ptr->do_move = FALSE;
969                 }
970
971                 if (!turn_flags_ptr->do_move)
972                 {
973                         if (turn_flags_ptr->do_turn) break;
974
975                         continue;
976                 }
977
978                 turn_flags_ptr->do_turn = TRUE;
979                 feature_type *f_ptr;
980                 f_ptr = &f_info[g_ptr->feat];
981                 if (have_flag(f_ptr->flags, FF_TREE))
982                 {
983                         if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
984                         {
985                                 m_ptr->energy_need += ENERGY_NEED();
986                         }
987                 }
988
989                 if (!update_riding_monster(target_ptr, turn_flags_ptr, m_idx, oy, ox, ny, nx)) break;
990
991                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
992                 if (m_ptr->ml &&
993                         (disturb_move ||
994                         (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
995                                 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= target_ptr->lev)))
996                 {
997                         if (is_hostile(m_ptr))
998                                 disturb(target_ptr, FALSE, TRUE);
999                 }
1000
1001                 bool is_takable_or_killable = g_ptr->o_idx > 0;
1002                 is_takable_or_killable &= (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) != 0;
1003
1004                 bool is_pickup_items = (target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
1005                 is_pickup_items &= (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
1006
1007                 is_takable_or_killable &= !is_pet(m_ptr) || is_pickup_items;
1008                 if (!is_takable_or_killable)
1009                 {
1010                         if (turn_flags_ptr->do_turn) break;
1011
1012                         continue;
1013                 }
1014
1015                 update_object_by_monster_movement(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1016                 if (turn_flags_ptr->do_turn) break;
1017
1018                 (*count)++;
1019         }
1020
1021         return TRUE;
1022 }
1023
1024
1025 /*!
1026  * @brief モンスターの恐怖状態を処理する
1027  * @param target_ptr プレーヤーへの参照ポインタ
1028  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
1029  * @param m_idx モンスターID
1030  * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1031  * @return モンスターが戦いを決意したらTRUE
1032  */
1033 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
1034 {
1035         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1036         bool is_battle_determined = !turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && MON_MONFEAR(m_ptr) && turn_flags_ptr->aware;
1037         if (!is_battle_determined) return FALSE;
1038
1039         (void)set_monster_monfear(target_ptr, m_idx, 0);
1040         if (!turn_flags_ptr->see_m) return TRUE;
1041
1042         GAME_TEXT m_name[MAX_NLEN];
1043         monster_desc(target_ptr, m_name, m_ptr, 0);
1044         msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
1045         return TRUE;
1046 }
1047
1048
1049 /*!
1050  * @brief 全モンスターのターン管理メインルーチン /
1051  * Process all the "live" monsters, once per game turn.
1052  * @return なし
1053  * @details
1054  * During each game current game turn, we scan through the list of all the "live" monsters,\n
1055  * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
1056  * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
1057  *\n
1058  * Note that monsters can never move in the monster array (except when the\n
1059  * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
1060  *\n
1061  * This function is responsible for at least half of the processor time\n
1062  * on a normal system with a "normal" amount of monsters and a player doing\n
1063  * normal things.\n
1064  *\n
1065  * When the player is resting, virtually 90% of the processor time is spent\n
1066  * in this function, and its children, "process_monster()" and "make_move()".\n
1067  *\n
1068  * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
1069  * especially when the player is running.\n
1070  *\n
1071  * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
1072  * monsters while they are still being "born".  A monster is "fresh" only\n
1073  * during the game turn in which it is created, and we use the "hack_m_idx" to\n
1074  * determine if the monster is yet to be processed during the game turn.\n
1075  *\n
1076  * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
1077  * move before any "nasty" monsters get to use their spell attacks.\n
1078  *\n
1079  * Note that when the "knowledge" about the currently tracked monster\n
1080  * changes (flags, attacks, spells), we induce a redraw of the monster\n
1081  * recall window.\n
1082  */
1083 void process_monsters(player_type *target_ptr)
1084 {
1085         old_race_flags tmp_flags;
1086         old_race_flags *old_race_flags_ptr = init_old_race_flags(&tmp_flags);
1087
1088         floor_type *floor_ptr = target_ptr->current_floor_ptr;
1089         floor_ptr->monster_noise = FALSE;
1090
1091         MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
1092         save_old_race_flags(target_ptr->monster_race_idx, old_race_flags_ptr);
1093         sweep_monster_process(target_ptr);
1094
1095         hack_m_idx = 0;
1096         if (!target_ptr->monster_race_idx || (target_ptr->monster_race_idx != old_monster_race_idx))
1097                 return;
1098
1099         update_player_window(target_ptr, old_race_flags_ptr);
1100 }
1101
1102
1103 /*!
1104  * @brief フロア内のモンスターについてターン終了時の処理を繰り返す
1105  * @param target_ptr プレーヤーへの参照ポインタ
1106  */
1107 void sweep_monster_process(player_type *target_ptr)
1108 {
1109         floor_type *floor_ptr = target_ptr->current_floor_ptr;
1110         for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
1111         {
1112                 monster_type *m_ptr;
1113                 m_ptr = &floor_ptr->m_list[i];
1114
1115                 if (target_ptr->leaving) return;
1116                 if (!monster_is_valid(m_ptr)) continue;
1117                 if (target_ptr->wild_mode) continue;
1118
1119                 if (m_ptr->mflag & MFLAG_BORN)
1120                 {
1121                         m_ptr->mflag &= ~(MFLAG_BORN);
1122                         continue;
1123                 }
1124
1125                 if (m_ptr->cdis >= AAF_LIMIT) continue;
1126                 if (!decide_process_continue(target_ptr, m_ptr)) continue;
1127
1128                 SPEED speed = (target_ptr->riding == i) ? target_ptr->pspeed : decide_monster_speed(m_ptr);
1129                 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
1130                 if (m_ptr->energy_need > 0) continue;
1131
1132                 m_ptr->energy_need += ENERGY_NEED();
1133                 hack_m_idx = i;
1134                 process_monster(target_ptr, i);
1135                 reset_target(m_ptr);
1136
1137                 if (target_ptr->no_flowed && one_in_(3))
1138                         m_ptr->mflag2 |= MFLAG2_NOFLOW;
1139
1140                 if (!target_ptr->playing || target_ptr->is_dead) return;
1141                 if (target_ptr->leaving) return;
1142         }
1143 }
1144
1145
1146 /*!
1147  * @brief 後続のモンスター処理が必要かどうか判定する (要調査)
1148  * @param target_ptr プレーヤーへの参照ポインタ
1149  * @param m_ptr モンスターへの参照ポインタ
1150  * @return 後続処理が必要ならTRUE
1151  */
1152 bool decide_process_continue(player_type *target_ptr, monster_type *m_ptr)
1153 {
1154         monster_race *r_ptr;
1155         r_ptr = &r_info[m_ptr->r_idx];
1156         if (!target_ptr->no_flowed)
1157         {
1158                 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
1159         }
1160
1161         if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
1162                 return TRUE;
1163
1164         if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
1165                 (player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
1166                 return TRUE;
1167
1168         if (m_ptr->target_y)
1169                 return TRUE;
1170
1171         return FALSE;
1172 }