2 * @file monster-process.c
3 * @brief モンスターの特殊技能とターン経過処理 (移動等)/ Monster spells and movement for passaging a turn
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
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).
24 #include "spells-floor.h"
25 #include "spells-summon.h"
28 #include "realm-hex.h"
29 #include "object-flavor.h"
30 #include "object-hook.h"
33 #include "player-move.h"
34 #include "monster-status.h"
35 #include "monster-spell.h"
36 #include "monster-process.h"
37 #include "monsterrace-hook.h"
41 #include "view-mainwindow.h"
49 bool must_alter_to_move;
60 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
61 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx);
62 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
63 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx);
64 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
65 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
66 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
67 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
68 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
69 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware);
70 bool runaway_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon, bool see_m);
71 void process_special(player_type *target_ptr, MONSTER_IDX m_idx);
72 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware);
73 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware);
75 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross);
76 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
77 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
78 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash);
79 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
80 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
82 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
83 bool process_monster_attack_to_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, grid_type *g_ptr, bool can_cross);
84 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr);
86 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);
87 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
88 bool update_riding_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, POSITION ny, POSITION nx);
90 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
93 * @brief モンスターが敵に接近するための方向を決める /
94 * Calculate the direction to the next enemy
95 * @param target_ptr プレーヤーへの参照ポインタ
96 * @param m_idx モンスターの参照ID
97 * @param mm 移動するべき方角IDを返す参照ポインタ
98 * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
100 static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
102 floor_type *floor_ptr = target_ptr->current_floor_ptr;
103 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
104 monster_race *r_ptr = &r_info[m_ptr->r_idx];
106 POSITION x = 0, y = 0;
107 if (target_ptr->riding_t_m_idx && player_bold(target_ptr, m_ptr->fy, m_ptr->fx))
109 y = floor_ptr->m_list[target_ptr->riding_t_m_idx].fy;
110 x = floor_ptr->m_list[target_ptr->riding_t_m_idx].fx;
112 else if (is_pet(m_ptr) && target_ptr->pet_t_m_idx)
114 y = floor_ptr->m_list[target_ptr->pet_t_m_idx].fy;
115 x = floor_ptr->m_list[target_ptr->pet_t_m_idx].fx;
121 if (target_ptr->phase_out)
123 start = randint1(floor_ptr->m_max - 1) + floor_ptr->m_max;
124 if (randint0(2)) plus = -1;
128 start = floor_ptr->m_max + 1;
131 for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus)
133 MONSTER_IDX dummy = (i % floor_ptr->m_max);
134 if (!dummy) continue;
136 MONSTER_IDX t_idx = dummy;
138 t_ptr = &floor_ptr->m_list[t_idx];
140 if (t_ptr == m_ptr) continue;
141 if (!monster_is_valid(t_ptr)) continue;
145 if (target_ptr->pet_follow_distance < 0)
147 if (t_ptr->cdis <= (0 - target_ptr->pet_follow_distance))
152 else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > target_ptr->pet_follow_distance))
157 if (r_ptr->aaf < t_ptr->cdis) continue;
160 if (!are_enemies(target_ptr, m_ptr, t_ptr)) continue;
162 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) ||
163 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)))
165 if (!in_disintegration_range(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
169 if (!projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
178 if (!x && !y) return FALSE;
184 /* North, South, East, West, North-West, North-East, South-West, South-East */
185 if ((y < 0) && (x == 0))
191 else if ((y > 0) && (x == 0))
197 else if ((x > 0) && (y == 0))
203 else if ((x < 0) && (y == 0))
209 else if ((y < 0) && (x < 0))
215 else if ((y < 0) && (x > 0))
221 else if ((y > 0) && (x < 0))
227 else if ((y > 0) && (x > 0))
239 * @brief モンスターがプレイヤーから逃走するかどうかを返す /
240 * Returns whether a given monster will try to run from the player.
241 * @param m_idx 逃走するモンスターの参照ID
242 * @return モンスターがプレイヤーから逃走するならばTRUEを返す。
244 * Monsters will attempt to avoid very powerful players. See below.\n
246 * Because this function is called so often, little details are important\n
247 * for efficiency. Like not using "mod" or "div" when possible. And\n
248 * attempting to check the conditions in an optimal order. Note that\n
249 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
251 * Note that this function is responsible for about one to five percent\n
252 * of the processor use in normal conditions...\n
254 static bool mon_will_run(player_type *target_ptr, MONSTER_IDX m_idx)
256 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
257 monster_race *r_ptr = &r_info[m_ptr->r_idx];
261 return ((target_ptr->pet_follow_distance < 0) &&
262 (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
265 if (m_ptr->cdis > MAX_SIGHT + 5) return FALSE;
266 if (MON_MONFEAR(m_ptr)) return TRUE;
267 if (m_ptr->cdis <= 5) return FALSE;
269 PLAYER_LEVEL p_lev = target_ptr->lev;
270 DEPTH m_lev = r_ptr->level + (m_idx & 0x08) + 25;
271 if (m_lev > p_lev + 4) return FALSE;
272 if (m_lev + 4 <= p_lev) return TRUE;
274 HIT_POINT p_chp = target_ptr->chp;
275 HIT_POINT p_mhp = target_ptr->mhp;
276 HIT_POINT m_chp = m_ptr->hp;
277 HIT_POINT m_mhp = m_ptr->maxhp;
278 u32b p_val = (p_lev * p_mhp) + (p_chp << 2);
279 u32b m_val = (m_lev * m_mhp) + (m_chp << 2);
280 if (p_val * m_mhp > m_val * p_mhp) return TRUE;
287 * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
288 * Search spell castable grid
289 * @param target_ptr プレーヤーへの参照ポインタ
290 * @param m_idx モンスターの参照ID
291 * @param yp 適したマスのY座標を返す参照ポインタ
292 * @param xp 適したマスのX座標を返す参照ポインタ
293 * @return 有効なマスがあった場合TRUEを返す
295 static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
297 floor_type *floor_ptr = target_ptr->current_floor_ptr;
298 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
299 monster_race *r_ptr = &r_info[m_ptr->r_idx];
301 POSITION y1 = m_ptr->fy;
302 POSITION x1 = m_ptr->fx;
304 if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x)) return FALSE;
306 int now_cost = floor_ptr->grid_array[y1][x1].cost;
307 if (now_cost == 0) now_cost = 999;
309 bool can_open_door = FALSE;
310 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
312 can_open_door = TRUE;
316 for (int i = 7; i >= 0; i--)
318 POSITION y = y1 + ddy_ddd[i];
319 POSITION x = x1 + ddx_ddd[i];
320 if (!in_bounds2(floor_ptr, y, x)) continue;
321 if (player_bold(target_ptr, y, x)) return FALSE;
324 g_ptr = &floor_ptr->grid_array[y][x];
325 int cost = g_ptr->cost;
326 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))))
328 if (cost == 0) continue;
329 if (!can_open_door && is_closed_door(target_ptr, g_ptr->feat)) continue;
332 if (cost == 0) cost = 998;
334 if (now_cost < cost) continue;
335 if (!projectable(target_ptr, y, x, target_ptr->y, target_ptr->x)) continue;
336 if (best < cost) continue;
339 *yp = y1 + ddy_ddd[i];
340 *xp = x1 + ddx_ddd[i];
343 if (best == 999) return FALSE;
350 * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
351 * Choose the "best" direction for "flowing"
352 * @param m_idx モンスターの参照ID
353 * @param yp 移動先のマスのY座標を返す参照ポインタ
354 * @param xp 移動先のマスのX座標を返す参照ポインタ
355 * @param no_flow モンスターにFLOWフラグが経っていない状態でTRUE
356 * @return 有効なマスがあった場合TRUEを返す
358 * Note that ghosts and rock-eaters are never allowed to "flow",\n
359 * since they should move directly towards the player.\n
361 * Prefer "non-diagonal" directions, but twiddle them a little\n
362 * to angle slightly towards the player's actual location.\n
364 * Allow very perceptive monsters to track old "spoor" left by\n
365 * previous locations occupied by the player. This will tend\n
366 * to have monsters end up either near the player or on a grid\n
367 * recently occupied by the player (and left via "teleport").\n
369 * Note that if "smell" is turned on, all monsters get vicious.\n
371 * Also note that teleporting away from a location will cause\n
372 * the monsters who were chasing you to converge on that location\n
373 * as long as you are still near enough to "annoy" them without\n
374 * being close enough to chase directly. I have no idea what will\n
375 * happen if you combine "smell" with low "aaf" values.\n
377 static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
380 floor_type *floor_ptr = target_ptr->current_floor_ptr;
381 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
382 monster_race *r_ptr = &r_info[m_ptr->r_idx];
384 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
385 r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
386 r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
388 if (get_moves_aux2(target_ptr, m_idx, yp, xp)) return TRUE;
391 if (no_flow) return FALSE;
392 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) return FALSE;
393 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)) return FALSE;
395 POSITION y1 = m_ptr->fy;
396 POSITION x1 = m_ptr->fx;
397 if (player_has_los_bold(target_ptr, y1, x1) && projectable(target_ptr, target_ptr->y, target_ptr->x, y1, x1)) return FALSE;
399 g_ptr = &floor_ptr->grid_array[y1][x1];
402 bool use_scent = FALSE;
407 else if (g_ptr->when)
409 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when - g_ptr->when > 127) return FALSE;
419 for (int i = 7; i >= 0; i--)
421 POSITION y = y1 + ddy_ddd[i];
422 POSITION x = x1 + ddx_ddd[i];
424 if (!in_bounds2(floor_ptr, y, x)) continue;
426 g_ptr = &floor_ptr->grid_array[y][x];
429 int when = g_ptr->when;
430 if (best > when) continue;
437 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
446 if ((cost == 0) || (best < cost)) continue;
451 *yp = target_ptr->y + 16 * ddy_ddd[i];
452 *xp = target_ptr->x + 16 * ddx_ddd[i];
455 if (best == 999 || best == 0) return FALSE;
462 * @brief モンスターがプレイヤーから逃走することが可能なマスを走査する /
463 * Provide a location to flee to, but give the player a wide berth.
464 * @param m_idx モンスターの参照ID
465 * @param yp 移動先のマスのY座標を返す参照ポインタ
466 * @param xp 移動先のマスのX座標を返す参照ポインタ
467 * @return 有効なマスがあった場合TRUEを返す
469 * A monster may wish to flee to a location that is behind the player,\n
470 * but instead of heading directly for it, the monster should "swerve"\n
471 * around the player so that he has a smaller chance of getting hit.\n
473 static bool get_fear_moves_aux(floor_type *floor_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
475 POSITION gy = 0, gx = 0;
477 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
478 POSITION fy = m_ptr->fy;
479 POSITION fx = m_ptr->fx;
481 POSITION y1 = fy - (*yp);
482 POSITION x1 = fx - (*xp);
485 for (int i = 7; i >= 0; i--)
487 POSITION y = fy + ddy_ddd[i];
488 POSITION x = fx + ddx_ddd[i];
489 if (!in_bounds2(floor_ptr, y, x)) continue;
491 POSITION dis = distance(y, x, y1, x1);
492 POSITION s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
495 if (s < score) continue;
502 if (score == -1) return FALSE;
512 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
515 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
516 * offsets of all the locations with a distance of n from a central point,
517 * with an offset of (0,0) indicating no more offsets at this distance.
519 * This is, of course, fairly unreadable, but it eliminates multiple loops
520 * from the previous version.
522 * It is probably better to replace these arrays with code to compute
523 * the relevant arrays, even if the storage is pre-allocated in hard
524 * coded sizes. At the very least, code should be included which is
525 * able to generate and dump these arrays (ala "los()").
527 * Also, the storage needs could be halved by using bytes.
529 * These arrays could be combined into two big arrays, using sub-arrays
530 * to hold the offsets and lengths of each portion of the sub-arrays, and
531 * this could perhaps also be used somehow in the "look" code.
535 static POSITION d_off_y_0[] = { 0 };
536 static POSITION d_off_x_0[] = { 0 };
538 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
539 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
541 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
542 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
544 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
545 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
547 static POSITION d_off_y_4[] = { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
548 static POSITION d_off_x_4[] = { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4, -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
551 static POSITION d_off_y_5[] =
552 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
553 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
556 static POSITION d_off_x_5[] =
557 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
558 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
562 static POSITION d_off_y_6[] =
563 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
564 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
567 static POSITION d_off_x_6[] =
568 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
569 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
570 -3, 2, 3, -1, 0, 1, 0 };
573 static POSITION d_off_y_7[] =
574 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
575 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
576 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
578 static POSITION d_off_x_7[] =
579 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
580 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
581 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
585 static POSITION d_off_y_8[] =
586 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
587 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
588 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
591 static POSITION d_off_x_8[] =
592 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
593 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
594 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
598 static POSITION d_off_y_9[] =
599 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
600 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
601 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
602 7, 8, 8, 8, 8, 9, 9, 9, 0 };
604 static POSITION d_off_x_9[] =
605 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
606 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
607 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
608 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
611 static POSITION *dist_offsets_y[10] =
613 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
614 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
617 static POSITION *dist_offsets_x[10] =
619 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
620 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
624 * @brief モンスターが逃げ込める安全な地点を返す /
625 * Choose a "safe" location near a monster for it to run toward.
626 * @param target_ptr プレーヤーへの参照ポインタ
627 * @param m_idx モンスターの参照ID
628 * @param yp 移動先のマスのY座標を返す参照ポインタ
629 * @param xp 移動先のマスのX座標を返す参照ポインタ
630 * @return 有効なマスがあった場合TRUEを返す
632 * A location is "safe" if it can be reached quickly and the player\n
633 * is not able to fire into it (it isn't a "clean shot"). So, this will\n
634 * cause monsters to "duck" behind walls. Hopefully, monsters will also\n
635 * try to run towards corridor openings if they are in a room.\n
637 * This function may take lots of CPU time if lots of monsters are\n
640 * Return TRUE if a safe location is available.\n
642 static bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
644 floor_type *floor_ptr = target_ptr->current_floor_ptr;
645 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
647 POSITION fy = m_ptr->fy;
648 POSITION fx = m_ptr->fx;
650 POSITION gy = 0, gx = 0, gdis = 0;
652 for (POSITION d = 1; d < 10; d++)
655 y_offsets = dist_offsets_y[d];
658 x_offsets = dist_offsets_x[d];
660 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
662 i++, dx = x_offsets[i], dy = y_offsets[i])
664 POSITION y = fy + dy;
665 POSITION x = fx + dx;
666 if (!in_bounds(floor_ptr, y, x)) continue;
669 g_ptr = &floor_ptr->grid_array[y][x];
671 BIT_FLAGS16 riding_mode = (m_idx == target_ptr->riding) ? CEM_RIDING : 0;
672 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], riding_mode))
675 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
677 if (g_ptr->dist == 0) continue;
678 if (g_ptr->dist > floor_ptr->grid_array[fy][fx].dist + 2 * d) continue;
681 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x)) continue;
683 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
684 if (dis <= gdis) continue;
691 if (gdis <= 0) continue;
704 * @brief モンスターが隠れ潜める地点を返す /
705 * Choose a good hiding place near a monster for it to run toward.
706 * @param target_ptr プレーヤーへの参照ポインタ
707 * @param m_idx モンスターの参照ID
708 * @param yp 移動先のマスのY座標を返す参照ポインタ
709 * @param xp 移動先のマスのX座標を返す参照ポインタ
710 * @return 有効なマスがあった場合TRUEを返す
712 * Pack monsters will use this to "ambush" the player and lure him out\n
713 * of corridors into open space so they can swarm him.\n
715 * Return TRUE if a good location is available.\n
717 static bool find_hiding(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
719 floor_type *floor_ptr = target_ptr->current_floor_ptr;
720 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
721 monster_race *r_ptr = &r_info[m_ptr->r_idx];
723 POSITION fy = m_ptr->fy;
724 POSITION fx = m_ptr->fx;
726 POSITION gy = 0, gx = 0, gdis = 999;
728 for (POSITION d = 1; d < 10; d++)
731 y_offsets = dist_offsets_y[d];
734 x_offsets = dist_offsets_x[d];
736 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
738 i++, dx = x_offsets[i], dy = y_offsets[i])
740 POSITION y = fy + dy;
741 POSITION x = fx + dx;
743 if (!in_bounds(floor_ptr, y, x)) continue;
744 if (!monster_can_enter(target_ptr, y, x, r_ptr, 0)) continue;
745 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, fy, fx, y, x, FALSE))
748 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
749 if (dis < gdis && dis >= 2)
757 if (gdis >= 999) continue;
770 * @brief モンスターの移動方向を返す /
771 * Choose "logical" directions for monster movement
772 * @param target_ptr プレーヤーへの参照ポインタ
773 * @param m_idx モンスターの参照ID
774 * @param mm 移動方向を返す方向IDの参照ポインタ
775 * @return 有効方向があった場合TRUEを返す
777 static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
779 floor_type *floor_ptr = target_ptr->current_floor_ptr;
780 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
781 monster_race *r_ptr = &r_info[m_ptr->r_idx];
782 POSITION y = 0, ay, x = 0, ax;
783 POSITION y2 = target_ptr->y;
784 POSITION x2 = target_ptr->x;
786 bool will_run = mon_will_run(target_ptr, m_idx);
788 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) != 0) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2);
789 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) != 0) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall);
791 if (!will_run && m_ptr->target_y)
793 int t_m_idx = floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
795 are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[t_m_idx]) &&
796 los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
797 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
799 y = m_ptr->fy - m_ptr->target_y;
800 x = m_ptr->fx - m_ptr->target_x;
805 if (!done && !will_run && is_hostile(m_ptr) &&
806 (r_ptr->flags1 & RF1_FRIENDS) &&
807 ((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)) ||
808 (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
810 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
811 !(r_ptr->flags2 & RF2_KILL_WALL))
814 for (int i = 0; i < 8; i++)
816 int xx = target_ptr->x + ddx_ddd[i];
817 int yy = target_ptr->y + ddy_ddd[i];
819 if (!in_bounds2(floor_ptr, yy, xx)) continue;
821 g_ptr = &floor_ptr->grid_array[yy][xx];
822 if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0))
828 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].info & CAVE_ROOM) room -= 2;
829 if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
831 if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
832 (target_ptr->mhp + target_ptr->msp))
834 if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
838 if (!done && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
840 for (int i = 0; i < 8; i++)
842 y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
843 x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
844 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
851 if (!in_bounds2(floor_ptr, y2, x2)) continue;
852 if (!monster_can_enter(target_ptr, y2, x2, r_ptr, 0)) continue;
865 (void)get_moves_aux(target_ptr, m_idx, &y2, &x2, no_flow);
870 if (is_pet(m_ptr) && will_run)
876 if (!done && will_run)
880 if (find_safety(target_ptr, m_idx, &y, &x) && !no_flow)
882 if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x))
894 if (!x && !y) return FALSE;
900 if (y < 0) move_val += 8;
901 if (x > 0) move_val += 4;
903 if (ay > (ax << 1)) move_val += 2;
904 else if (ax > (ay << 1)) move_val++;
1054 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
1056 return !have_flag(f_ptr->flags, FF_GLASS) ||
1057 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
1058 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
1063 * @brief モンスター単体の1ターン行動処理メインルーチン /
1065 * @param target_ptr プレーヤーへの参照ポインタ
1066 * @param m_idx 行動モンスターの参照ID
1069 * The monster is known to be within 100 grids of the player\n
1071 * In several cases, we directly update the monster lore\n
1073 * Note that a monster is only allowed to "reproduce" if there\n
1074 * are a limited number of "reproducing" monsters on the current\n
1075 * level. This should prevent the level from being "swamped" by\n
1076 * reproducing monsters. It also allows a large mass of mice to\n
1077 * prevent a louse from multiplying, but this is a small price to\n
1078 * pay for a simple multiplication method.\n
1080 * XXX Monster fear is slightly odd, in particular, monsters will\n
1081 * fixate on opening a door even if they cannot open it. Actually,\n
1082 * the same thing happens to normal monsters when they hit a door\n
1084 * In addition, monsters which *cannot* open or bash\n
1085 * down a door will still stand there trying to open it...\n
1087 * XXX Technically, need to check for monster in the way\n
1088 * combined with that monster being in a wall (or door?)\n
1090 * A "direction" of "5" means "pick a random direction".\n
1092 void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1094 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1095 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1098 turn_flags tmp_flags;
1099 turn_flags *turn_flags_ptr = &tmp_flags;
1100 turn_flags_ptr->is_riding_mon = (m_idx == target_ptr->riding);
1101 turn_flags_ptr->do_turn = FALSE;
1102 turn_flags_ptr->do_move = FALSE;
1103 turn_flags_ptr->do_view = FALSE;
1104 turn_flags_ptr->must_alter_to_move = FALSE;
1105 turn_flags_ptr->did_open_door = FALSE;
1106 turn_flags_ptr->did_bash_door = FALSE;
1107 turn_flags_ptr->did_take_item = FALSE;
1108 turn_flags_ptr->did_kill_item = FALSE;
1109 turn_flags_ptr->did_move_body = FALSE;
1110 turn_flags_ptr->did_pass_wall = FALSE;
1111 turn_flags_ptr->did_kill_wall = FALSE;
1113 bool see_m = is_seen(m_ptr);
1115 decide_drop_from_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon);
1116 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
1118 choose_new_monster(target_ptr, m_idx, FALSE, 0);
1119 r_ptr = &r_info[m_ptr->r_idx];
1122 bool aware = process_stealth(target_ptr, m_idx);
1124 if (vanish_summoned_children(target_ptr, m_idx, see_m)) return;
1125 if (process_quantum_effect(target_ptr,m_idx, see_m)) return;
1127 if (m_ptr->r_idx == MON_SHURYUUDAN)
1130 mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
1134 if (runaway_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon, see_m)) return;
1136 awake_monster(target_ptr, m_idx);
1138 if (MON_STUNNED(m_ptr))
1140 if (one_in_(2)) return;
1143 if (turn_flags_ptr->is_riding_mon)
1145 target_ptr->update |= (PU_BONUS);
1148 process_angar(target_ptr, m_idx, see_m);
1150 POSITION oy = m_ptr->fy;
1151 POSITION ox = m_ptr->fx;
1152 if (decide_monster_multiplication(target_ptr, m_idx, oy, ox)) return;
1154 process_special(target_ptr, m_idx);
1155 process_speak_sound(target_ptr, m_idx, oy, ox, aware);
1156 if (cast_spell(target_ptr, m_idx, aware)) return;
1158 mm[0] = mm[1] = mm[2] = mm[3] = 0;
1159 mm[4] = mm[5] = mm[6] = mm[7] = 0;
1161 if (!decide_monster_movement_direction(target_ptr, mm, m_idx, aware)) return;
1164 if(!process_monster_movement(target_ptr, turn_flags_ptr, m_idx, mm, oy, ox, &count)) return;
1167 * Forward movements failed, but now received LOS attack!
1168 * Try to flow by smell.
1170 if (target_ptr->no_flowed && count > 2 && m_ptr->target_y)
1171 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
1173 if (!turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && !MON_MONFEAR(m_ptr) && !turn_flags_ptr->is_riding_mon && aware)
1175 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
1177 if (make_attack_spell(m_idx, target_ptr)) return;
1181 if (turn_flags_ptr->do_view)
1183 target_ptr->update |= (PU_FLOW);
1184 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1187 if (turn_flags_ptr->do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
1188 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !target_ptr->phase_out)))
1190 target_ptr->update |= (PU_MON_LITE);
1193 if (is_original_ap_and_seen(target_ptr, m_ptr))
1195 if (turn_flags_ptr->did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
1196 if (turn_flags_ptr->did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
1197 if (turn_flags_ptr->did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
1198 if (turn_flags_ptr->did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
1199 if (turn_flags_ptr->did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
1200 if (turn_flags_ptr->did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
1201 if (turn_flags_ptr->did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
1204 bool is_battle_determined = !turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && MON_MONFEAR(m_ptr) && aware;
1205 if (!is_battle_determined) return;
1207 (void)set_monster_monfear(target_ptr, m_idx, 0);
1210 GAME_TEXT m_name[MAX_NLEN];
1211 monster_desc(target_ptr, m_name, m_ptr, 0);
1212 msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
1215 if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
1220 * @brief 超隠密処理 (のはず todo)
1221 * @param target_ptr プレーヤーへの参照ポインタ
1222 * @param m_idx モンスターID
1223 * @return モンスターがプレーヤーを感知していればFALSE? (todo 要調査)
1225 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx)
1227 if ((target_ptr->special_defense & NINJA_S_STEALTH) == 0) return TRUE;
1229 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1230 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1231 int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
1232 if (target_ptr->monlite) tmp /= 3;
1233 if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1234 if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
1235 return (randint0(tmp) <= (r_ptr->level + 20));
1240 * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
1241 * @param target_ptr プレーヤーへの参照ポインタ
1242 * @param m_idx モンスターID
1243 * @param is_riding_mon 騎乗中であればTRUE
1246 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
1248 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1249 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1250 if (!is_riding_mon || ((r_ptr->flags7 & RF7_RIDING) != 0)) return;
1252 if (rakuba(target_ptr, 0, TRUE))
1255 msg_print("地面に落とされた。");
1257 GAME_TEXT m_name[MAX_NLEN];
1258 monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
1259 msg_format("You have fallen from %s.", m_name);
1266 * @brief 召喚の親元が消滅した時、子供も消滅させる
1267 * @param target_ptr プレーヤーへの参照ポインタ
1268 * @param m_idx モンスターID
1269 * @param see_m モンスターが視界内にいたらTRUE
1270 * @return 召喚モンスターが消滅したらTRUE
1272 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1274 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1275 if ((m_ptr->parent_m_idx == 0) || (target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx > 0))
1280 GAME_TEXT m_name[MAX_NLEN];
1281 monster_desc(target_ptr, m_name, m_ptr, 0);
1282 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1285 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1287 GAME_TEXT m_name[MAX_NLEN];
1288 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
1289 exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
1292 delete_monster_idx(target_ptr, m_idx);
1298 * @brief 寝ているモンスターの起床を判定する
1299 * @param target_ptr プレーヤーへの参照ポインタ
1300 * @param m_idx モンスターID
1303 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1305 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1306 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1307 if (!MON_CSLEEP(m_ptr)) return;
1308 if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
1310 (void)set_monster_csleep(target_ptr, m_idx, 0);
1313 GAME_TEXT m_name[MAX_NLEN];
1314 monster_desc(target_ptr, m_name, m_ptr, 0);
1315 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
1318 if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
1326 * @brief モンスターの怒り状態を判定する (起こっていたら敵に回す)
1327 * @param target_ptr プレーヤーへの参照ポインタ
1328 * @param m_idx モンスターID
1329 * @param see_m モンスターが視界内にいたらTRUE
1332 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1334 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1335 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1336 bool gets_angry = FALSE;
1337 if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
1340 if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
1341 monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
1346 if (target_ptr->phase_out || !gets_angry) return;
1348 if (is_pet(m_ptr) || see_m)
1350 GAME_TEXT m_name[MAX_NLEN];
1351 monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
1352 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
1355 set_hostile(target_ptr, m_ptr);
1360 * @brief 量子生物の量子的効果を実行する
1361 * @param target_ptr プレーヤーへの参照ポインタ
1362 * @param m_idx モンスターID
1363 * @param see_m モンスターが視界内にいたらTRUE
1364 * @return モンスターが量子的効果により消滅したらTRUE
1366 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1368 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1369 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1370 if ((r_ptr->flags2 & RF2_QUANTUM) == 0) return FALSE;
1371 if (!randint0(2)) return FALSE;
1372 if (randint0((m_idx % 100) + 10)) return FALSE;
1374 bool can_disappear = (r_ptr->flags1 & RF1_UNIQUE) == 0;
1375 can_disappear &= (r_ptr->flags1 & RF1_QUESTOR) == 0;
1378 vanish_nonunique(target_ptr, m_idx, see_m);
1382 produce_quantum_effect(target_ptr, m_idx, see_m);
1388 * @brief ユニークでない量子生物を消滅させる
1389 * @param target_ptr プレーヤーへの参照ポインタ
1390 * @param m_idx モンスターID
1391 * @param see_m モンスターが視界内にいたらTRUE
1394 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1396 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1399 GAME_TEXT m_name[MAX_NLEN];
1400 monster_desc(target_ptr, m_name, m_ptr, 0);
1401 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1404 monster_death(target_ptr, m_idx, FALSE);
1405 delete_monster_idx(target_ptr, m_idx);
1406 if (is_pet(m_ptr) && !(m_ptr->ml))
1408 msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
1414 * @brief 量子生物ユニークの量子的効果 (ショート・テレポートまたは距離10のテレポート・アウェイ)を実行する
1415 * @param target_ptr プレーヤーへの参照ポインタ
1416 * @param m_idx モンスターID
1417 * @param see_m モンスターが視界内にいたらTRUE
1420 * プレーヤーが量子生物を観測しているか、量子生物がプレーヤーを観測している場合、互いの相対的な位置を確定させる
1421 * 波動関数の収縮はテレポートではないので反テレポート無効
1422 * todo パターンは収縮どころか拡散しているが、この際気にしてはいけない
1424 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1426 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1427 bool coherent = los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x);
1428 if (!see_m && !coherent) return;
1432 GAME_TEXT m_name[MAX_NLEN];
1433 monster_desc(target_ptr, m_name, m_ptr, 0);
1434 msg_format(_("%sは量子的効果を起こした!", "%^s produced a decoherence!"), m_name);
1438 msg_print(_("量子的効果が起こった!", "A decoherence was produced!"));
1441 bool target = one_in_(2);
1442 const int blink = 32 * 5 + 4;
1445 (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx);
1450 teleport_player_away(m_idx, target_ptr, 10, TRUE);
1456 * @brief モンスター依存の特別な行動を取らせる
1457 * @param target_ptr プレーヤーへの参照ポインタ
1458 * @param m_idx モンスターID
1460 void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
1462 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1463 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1464 if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
1465 if (m_ptr->r_idx != MON_OHMU) return;
1466 if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
1467 if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
1470 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1471 BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
1473 for (int k = 0; k < A_MAX; k++)
1475 if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
1477 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
1481 if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
1486 * @brief モンスターを喋らせたり足音を立てたりする
1487 * @param target_ptr プレーヤーへの参照ポインタ
1488 * @param m_idx モンスターID
1489 * @param oy モンスターが元々いたY座標
1490 * @param ox モンスターが元々いたX座標
1491 * @param aware 起きていればTRUE
1494 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware)
1496 if (target_ptr->phase_out) return;
1498 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1499 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1500 if (m_ptr->ap_r_idx == MON_CYBER &&
1501 one_in_(CYBERNOISE) &&
1502 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
1504 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
1505 msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
1508 if (((ap_r_ptr->flags2 & RF2_CAN_SPEAK) == 0) || !aware ||
1509 !one_in_(SPEAK_CHANCE) ||
1510 !player_has_los_bold(target_ptr, oy, ox) ||
1511 !projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
1514 GAME_TEXT m_name[MAX_NLEN];
1515 char monmessage[1024];
1519 monster_desc(target_ptr, m_name, m_ptr, 0);
1521 strcpy(m_name, _("それ", "It"));
1523 if (MON_MONFEAR(m_ptr))
1524 filename = _("monfear_j.txt", "monfear.txt");
1525 else if (is_pet(m_ptr))
1526 filename = _("monpet_j.txt", "monpet.txt");
1527 else if (is_friendly(m_ptr))
1528 filename = _("monfrien_j.txt", "monfrien.txt");
1530 filename = _("monspeak_j.txt", "monspeak.txt");
1532 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
1534 msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
1540 * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
1541 * @param target_ptr プレーヤーへの参照ポインタ
1542 * @param m_idx モンスターID
1543 * @param oy 分裂元モンスターのY座標
1544 * @param ox 分裂元モンスターのX座標
1545 * @return 実際に分裂したらTRUEを返す
1547 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
1549 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1550 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1551 if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) || (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
1555 for (POSITION y = oy - 1; y <= oy + 1; y++)
1557 for (POSITION x = ox - 1; x <= ox + 1; x++)
1559 if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
1560 if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
1564 if (multiply_barrier(target_ptr, m_idx)) k = 8;
1566 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
1568 if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
1570 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
1572 r_ptr->r_flags2 |= (RF2_MULTIPLY);
1584 * @brief モンスターの移動パターンを決定する
1585 * @param target_ptr プレーヤーへの参照ポインタ
1587 * @param m_idx モンスターID
1588 * @param aware 起きていればTRUE
1589 * @return 移動先が存在すればTRUE
1591 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware)
1593 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1594 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1596 if (MON_CONFUSED(m_ptr) || !aware)
1598 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1602 if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) && (randint0(100) < 75))
1604 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
1606 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1610 if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 50))
1612 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
1614 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1618 if ((r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 25))
1620 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
1622 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1626 if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
1628 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1634 bool avoid = ((target_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
1635 bool lonely = (!avoid && (m_ptr->cdis > target_ptr->pet_follow_distance));
1636 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
1637 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1638 if (!get_enemy_dir(target_ptr, m_idx, mm))
1640 if (avoid || lonely || distant)
1642 POSITION dis = target_ptr->pet_follow_distance;
1643 if (target_ptr->pet_follow_distance > PET_SEEK_DIST)
1645 target_ptr->pet_follow_distance = PET_SEEK_DIST;
1648 (void)get_moves(target_ptr, m_idx, mm);
1649 target_ptr->pet_follow_distance = (s16b)dis;
1656 if (!is_hostile(m_ptr))
1658 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1659 get_enemy_dir(target_ptr, m_idx, mm);
1663 if (!get_moves(target_ptr, m_idx, mm)) return FALSE;
1670 * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
1671 * @param target_ptr プレーヤーへの参照ポインタ
1672 * @param m_idx モンスターID
1673 * @param is_riding_mon 騎乗状態ならばTRUE
1674 * @param see_m モンスターが視界内にいたらTRUE
1675 * @return モンスターがフロアから消えたらTRUE
1677 bool runaway_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon, bool see_m)
1679 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1680 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1681 bool can_runaway = is_pet(m_ptr) || is_friendly(m_ptr);
1682 can_runaway &= ((r_ptr->flags1 & RF1_UNIQUE) != 0) || ((r_ptr->flags7 & RF7_NAZGUL) != 0);
1683 can_runaway &= !target_ptr->phase_out;
1684 if (!can_runaway) return FALSE;
1686 static int riding_pinch = 0;
1688 if (m_ptr->hp >= m_ptr->maxhp / 3)
1690 /* Reset the counter */
1691 if (is_riding_mon) riding_pinch = 0;
1696 GAME_TEXT m_name[MAX_NLEN];
1697 monster_desc(target_ptr, m_name, m_ptr, 0);
1698 if (is_riding_mon && riding_pinch < 2)
1700 msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
1701 "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
1703 disturb(target_ptr, TRUE, TRUE);
1709 msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
1710 if (rakuba(target_ptr, -1, FALSE))
1712 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1718 if ((r_ptr->flags2 & RF2_CAN_SPEAK) && (m_ptr->r_idx != MON_GRIP) && (m_ptr->r_idx != MON_WOLF) && (m_ptr->r_idx != MON_FANG) &&
1719 player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx) && projectable(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x))
1721 msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
1724 msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s reads a scroll of teleport level."), m_name);
1725 msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
1728 if (is_riding_mon && rakuba(target_ptr, -1, FALSE))
1730 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1733 check_quest_completion(target_ptr, m_ptr);
1734 delete_monster_idx(target_ptr, m_idx);
1740 * @brief モンスターに魔法を試行させる
1741 * @param target_ptr プレーヤーへの参照ポインタ
1742 * @param m_idx モンスターID
1743 * @param aware 起きていればTRUE
1744 * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
1746 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware)
1748 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1749 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1750 if ((r_ptr->freq_spell == 0) || (randint1(100) > r_ptr->freq_spell))
1753 bool counterattack = FALSE;
1754 if (m_ptr->target_y)
1756 MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
1757 if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
1758 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1760 counterattack = TRUE;
1766 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1767 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1771 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1772 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1780 * @brief モンスターの移動に関するメインルーチン
1781 * @param target_ptr プレーヤーへの参照ポインタ
1782 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
1783 * @param m_idx モンスターID
1784 * @param mm モンスターの移動方向
1785 * @param oy 移動前の、モンスターのY座標
1786 * @param ox 移動前の、モンスターのX座標
1787 * @param count 移動回数 (のはず todo)
1788 * @return 移動が阻害される何か (ドア等)があったらFALSE
1790 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)
1792 for (int i = 0; mm[i]; i++)
1795 if (d == 5) d = ddd[randint0(8)];
1797 POSITION ny = oy + ddy[d];
1798 POSITION nx = ox + ddx[d];
1799 if (!in_bounds2(target_ptr->current_floor_ptr, ny, nx)) continue;
1802 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1803 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1804 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1805 bool can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0);
1807 if (!process_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx, can_cross))
1809 if (!process_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1813 if (!process_protection_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1815 if (!process_explosive_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1819 exe_monster_attack_to_player(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1820 if (process_monster_attack_to_monster(target_ptr, turn_flags_ptr, m_idx, g_ptr, can_cross)) return FALSE;
1822 if (turn_flags_ptr->is_riding_mon)
1824 if (!target_ptr->riding_ryoute && !MON_MONFEAR(&target_ptr->current_floor_ptr->m_list[target_ptr->riding])) turn_flags_ptr->do_move = FALSE;
1827 if (!process_post_dig_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx)) return FALSE;
1829 if (turn_flags_ptr->must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
1831 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0))
1832 turn_flags_ptr->do_move = FALSE;
1835 if (turn_flags_ptr->do_move && !can_cross && !turn_flags_ptr->did_kill_wall && !turn_flags_ptr->did_bash_door)
1836 turn_flags_ptr->do_move = FALSE;
1838 if (turn_flags_ptr->do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
1840 if (is_original_ap_and_seen(target_ptr, m_ptr))
1841 r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
1843 turn_flags_ptr->do_move = FALSE;
1846 if (!turn_flags_ptr->do_move)
1848 if (turn_flags_ptr->do_turn) break;
1853 turn_flags_ptr->do_turn = TRUE;
1854 feature_type *f_ptr;
1855 f_ptr = &f_info[g_ptr->feat];
1856 if (have_flag(f_ptr->flags, FF_TREE))
1858 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
1860 m_ptr->energy_need += ENERGY_NEED();
1864 if (!update_riding_monster(target_ptr, turn_flags_ptr, m_idx, oy, ox, ny, nx)) break;
1866 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1869 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
1870 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= target_ptr->lev)))
1872 if (is_hostile(m_ptr))
1873 disturb(target_ptr, FALSE, TRUE);
1876 bool is_takable_or_killable = g_ptr->o_idx > 0;
1877 is_takable_or_killable &= (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) != 0;
1879 bool is_pickup_items = (target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
1880 is_pickup_items &= (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
1882 is_takable_or_killable &= !is_pet(m_ptr) || is_pickup_items;
1883 if (!is_takable_or_killable)
1885 if (turn_flags_ptr->do_turn) break;
1890 update_object_by_monster_movement(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1892 if (turn_flags_ptr->do_turn) break;
1902 * @brief モンスターによる壁の透過・破壊を行う
1903 * @param target_ptr プレーヤーへの参照ポインタ
1904 * @param m_ptr モンスターへの参照ポインタ
1905 * @param ny モンスターのY座標
1906 * @param nx モンスターのX座標
1907 * @param can_cross モンスターが地形を踏破できるならばTRUE
1908 * @return 透過も破壊もしなかった場合はFALSE、それ以外はTRUE
1910 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross)
1912 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1914 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1915 feature_type *f_ptr;
1916 f_ptr = &f_info[g_ptr->feat];
1917 if (player_bold(target_ptr, ny, nx))
1919 turn_flags_ptr->do_move = TRUE;
1923 if (g_ptr->m_idx > 0)
1925 turn_flags_ptr->do_move = TRUE;
1929 if (((r_ptr->flags2 & RF2_KILL_WALL) != 0) &&
1930 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !turn_flags_ptr->is_riding_mon) &&
1931 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
1932 check_hp_for_feat_destruction(f_ptr, m_ptr))
1934 turn_flags_ptr->do_move = TRUE;
1935 if (!can_cross) turn_flags_ptr->must_alter_to_move = TRUE;
1937 turn_flags_ptr->did_kill_wall = TRUE;
1941 if (!can_cross) return FALSE;
1943 turn_flags_ptr->do_move = TRUE;
1944 if (((r_ptr->flags2 & RF2_PASS_WALL) != 0) && (!turn_flags_ptr->is_riding_mon || target_ptr->pass_wall) &&
1945 have_flag(f_ptr->flags, FF_CAN_PASS))
1947 turn_flags_ptr->did_pass_wall = TRUE;
1955 * @brief モンスターによるドアの開放・破壊を行う
1956 * @param target_ptr プレーヤーへの参照ポインタ
1957 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
1958 * @param m_ptr モンスターへの参照ポインタ
1959 * @param ny モンスターのY座標
1960 * @param nx モンスターのX座標
1961 * @return モンスターが死亡した場合のみFALSE
1963 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
1965 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1967 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1968 if (!is_closed_door(target_ptr, g_ptr->feat)) return TRUE;
1970 feature_type *f_ptr;
1971 f_ptr = &f_info[g_ptr->feat];
1972 bool may_bash = bash_normal_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx);
1973 bash_glass_door(target_ptr, turn_flags_ptr, m_ptr, f_ptr, may_bash);
1975 if (!turn_flags_ptr->did_open_door && !turn_flags_ptr->did_bash_door) return TRUE;
1977 if (turn_flags_ptr->did_bash_door &&
1978 ((randint0(100) < 50) || (feat_state(target_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
1980 cave_alter_feat(target_ptr, ny, nx, FF_BASH);
1981 if (!monster_is_valid(m_ptr))
1983 target_ptr->update |= (PU_FLOW);
1984 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1985 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
1992 cave_alter_feat(target_ptr, ny, nx, FF_OPEN);
1995 f_ptr = &f_info[g_ptr->feat];
1996 turn_flags_ptr->do_view = TRUE;
2002 * @brief モンスターが普通のドアを開ける処理
2003 * @param target_ptr プレーヤーへの参照ポインタ
2004 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2005 * @param m_ptr モンスターへの参照ポインタ
2006 * @param ny モンスターのY座標
2007 * @param nx モンスターのX座標
2008 * @return ここではドアを開けず、ガラスのドアを開ける可能性があるならTRUE
2010 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2012 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2014 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2015 feature_type *f_ptr;
2016 f_ptr = &f_info[g_ptr->feat];
2017 turn_flags_ptr->do_move = FALSE;
2018 if (((r_ptr->flags2 & RF2_OPEN_DOOR) == 0) || !have_flag(f_ptr->flags, FF_OPEN) ||
2019 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2022 if (f_ptr->power == 0)
2024 turn_flags_ptr->did_open_door = TRUE;
2025 turn_flags_ptr->do_turn = TRUE;
2029 if (randint0(m_ptr->hp / 10) > f_ptr->power)
2031 cave_alter_feat(target_ptr, ny, nx, FF_DISARM);
2032 turn_flags_ptr->do_turn = TRUE;
2041 * @brief モンスターがガラスのドアを開ける処理
2042 * @param target_ptr プレーヤーへの参照ポインタ
2043 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2044 * @param m_ptr モンスターへの参照ポインタ
2045 * @param g_ptr グリッドへの参照ポインタ
2046 * @param f_ptr 地形への参照ポインタ
2049 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash)
2051 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2052 if (!may_bash || ((r_ptr->flags2 & RF2_BASH_DOOR) == 0) || !have_flag(f_ptr->flags, FF_BASH) ||
2053 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2056 if (!check_hp_for_feat_destruction(f_ptr, m_ptr) || (randint0(m_ptr->hp / 10) <= f_ptr->power))
2059 if (have_flag(f_ptr->flags, FF_GLASS))
2060 msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
2062 msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
2064 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
2066 turn_flags_ptr->did_bash_door = TRUE;
2067 turn_flags_ptr->do_move = TRUE;
2068 turn_flags_ptr->must_alter_to_move = TRUE;
2073 * @brief 守りのルーンによるモンスターの移動制限を処理する
2074 * @param target_ptr プレーヤーへの参照ポインタ
2075 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2076 * @param m_ptr モンスターへの参照ポインタ
2077 * @param ny モンスターのY座標
2078 * @param nx モンスターのX座標
2081 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2084 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2085 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2086 if (!turn_flags_ptr->do_move || !is_glyph_grid(g_ptr) ||
2087 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2090 turn_flags_ptr->do_move = FALSE;
2091 if (is_pet(m_ptr) || (randint1(BREAK_GLYPH) >= r_ptr->level))
2094 if (g_ptr->info & CAVE_MARK)
2096 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2099 g_ptr->info &= ~(CAVE_MARK);
2100 g_ptr->info &= ~(CAVE_OBJECT);
2102 turn_flags_ptr->do_move = TRUE;
2103 note_spot(target_ptr, ny, nx);
2109 * @brief 爆発のルーンにを処理する
2110 * @param target_ptr プレーヤーへの参照ポインタ
2111 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2112 * @param m_ptr モンスターへの参照ポインタ
2113 * @param ny モンスターのY座標
2114 * @param nx モンスターのX座標
2115 * @return モンスターが死亡した場合のみFALSE
2117 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2120 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2121 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2122 if (!turn_flags_ptr->do_move || !is_explosive_rune_grid(g_ptr) ||
2123 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2126 turn_flags_ptr->do_move = FALSE;
2127 if (is_pet(m_ptr)) return TRUE;
2129 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2131 if (g_ptr->info & CAVE_MARK)
2133 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2134 BIT_FLAGS project_flags = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI;
2135 project(target_ptr, 0, 2, ny, nx, 2 * (target_ptr->lev + damroll(7, 7)), GF_MANA, project_flags, -1);
2140 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2143 g_ptr->info &= ~(CAVE_MARK);
2144 g_ptr->info &= ~(CAVE_OBJECT);
2147 note_spot(target_ptr, ny, nx);
2148 lite_spot(target_ptr, ny, nx);
2150 if (!monster_is_valid(m_ptr)) return FALSE;
2152 turn_flags_ptr->do_move = TRUE;
2158 * @brief モンスターが移動した結果、そこにプレーヤーがいたら直接攻撃を行う
2159 * @param target_ptr プレーヤーへの参照ポインタ
2160 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2161 * @param m_idx モンスターID
2162 * @param ny 移動後の、モンスターのY座標
2163 * @param nx 移動後の、モンスターのX座標
2166 * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
2168 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2170 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2171 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2172 if (!turn_flags_ptr->do_move || !player_bold(target_ptr, ny, nx))
2175 if (r_ptr->flags1 & RF1_NEVER_BLOW)
2177 if (is_original_ap_and_seen(target_ptr, m_ptr))
2178 r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
2180 turn_flags_ptr->do_move = FALSE;
2183 if (turn_flags_ptr->do_move && ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) != 0) && !MON_CONFUSED(m_ptr))
2185 if (!(r_ptr->flags2 & RF2_STUPID))
2186 turn_flags_ptr->do_move = FALSE;
2187 else if (is_original_ap_and_seen(target_ptr, m_ptr))
2188 r_ptr->r_flags2 |= (RF2_STUPID);
2191 if (!turn_flags_ptr->do_move) return;
2193 if (!target_ptr->riding || one_in_(2))
2195 (void)make_attack_normal(target_ptr, m_idx);
2196 turn_flags_ptr->do_move = FALSE;
2197 turn_flags_ptr->do_turn = TRUE;
2203 * @brief モンスターからモンスターへの攻撃処理
2204 * @param target_ptr プレーヤーへの参照ポインタ
2205 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2206 * @param m_idx モンスターID
2207 * @param g_ptr グリッドへの参照ポインタ
2208 * @param can_cross モンスターが地形を踏破できるならばTRUE
2209 * @return ターン消費が発生したらTRUE
2211 bool process_monster_attack_to_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, grid_type *g_ptr, bool can_cross)
2213 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2214 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2215 monster_type *y_ptr;
2216 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2217 if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) return FALSE;
2219 monster_race *z_ptr = &r_info[y_ptr->r_idx];
2220 turn_flags_ptr->do_move = FALSE;
2221 if ((((r_ptr->flags2 & RF2_KILL_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_BLOW) == 0) &&
2222 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
2223 can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
2224 are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
2226 return exe_monster_attack_to_monster(target_ptr, m_idx, g_ptr);
2229 if (((r_ptr->flags2 & RF2_MOVE_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_MOVE) == 0) &&
2230 (r_ptr->mexp > z_ptr->mexp) &&
2231 can_cross && (g_ptr->m_idx != target_ptr->riding) &&
2232 monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
2234 turn_flags_ptr->do_move = TRUE;
2235 turn_flags_ptr->did_move_body = TRUE;
2236 (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
2244 * @brief モンスターからモンスターへの直接攻撃を実行する
2245 * @param target_ptr プレーヤーへの参照ポインタ
2246 * @param m_idx モンスターID
2247 * @param g_ptr グリッドへの参照ポインタ
2249 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr)
2251 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2252 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2253 monster_type *y_ptr;
2254 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2255 if ((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) return FALSE;
2257 if (((r_ptr->flags2 & RF2_KILL_BODY) == 0) && is_original_ap_and_seen(target_ptr, m_ptr))
2258 r_ptr->r_flags2 |= (RF2_KILL_BODY);
2260 if ((y_ptr->r_idx == 0) || (y_ptr->hp < 0)) return FALSE;
2261 if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return TRUE;
2262 if ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) == 0) return FALSE;
2263 if (MON_CONFUSED(m_ptr)) return TRUE;
2264 if ((r_ptr->flags2 & RF2_STUPID) == 0) return FALSE;
2266 if (is_original_ap_and_seen(target_ptr, m_ptr))
2267 r_ptr->r_flags2 |= (RF2_STUPID);
2274 * @brief モンスターが壁を掘った後続処理を実行する
2275 * @param target_ptr プレーヤーへの参照ポインタ
2276 * @turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2277 * @param m_ptr モンスターへの参照ポインタ
2278 * @param ny モンスターのY座標
2279 * @param nx モンスターのX座標
2280 * @return モンスターが死亡した場合のみFALSE
2282 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2284 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2286 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2287 feature_type *f_ptr;
2288 f_ptr = &f_info[g_ptr->feat];
2289 if (!turn_flags_ptr->did_kill_wall || !turn_flags_ptr->do_move) return TRUE;
2291 if (one_in_(GRINDNOISE))
2293 if (have_flag(f_ptr->flags, FF_GLASS))
2294 msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
2296 msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
2299 cave_alter_feat(target_ptr, ny, nx, FF_HURT_DISI);
2301 if (!monster_is_valid(m_ptr))
2303 target_ptr->update |= (PU_FLOW);
2304 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2305 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2310 f_ptr = &f_info[g_ptr->feat];
2311 turn_flags_ptr->do_view = TRUE;
2312 turn_flags_ptr->do_turn = TRUE;
2318 * @brief 騎乗中のモンスター情報を更新する
2319 * @param target_ptr プレーヤーへの参照ポインタ
2320 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2321 * @param m_idx モンスターID
2322 * @param oy 移動前の、モンスターのY座標
2323 * @param ox 移動前の、モンスターのX座標
2324 * @param ny 移動後の、モンスターのY座標
2325 * @param ox 移動後の、モンスターのX座標
2326 * @return アイテム等に影響を及ぼしたらTRUE
2328 bool update_riding_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, POSITION ny, POSITION nx)
2330 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2332 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2333 monster_type *y_ptr;
2334 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2335 if (turn_flags_ptr->is_riding_mon)
2336 return move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP);
2338 target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
2343 update_monster(target_ptr, g_ptr->m_idx, TRUE);
2346 g_ptr->m_idx = m_idx;
2349 update_monster(target_ptr, m_idx, TRUE);
2351 lite_spot(target_ptr, oy, ox);
2352 lite_spot(target_ptr, ny, nx);
2358 * @brief モンスターの移動に伴うオブジェクト処理 (アイテム破壊等)
2359 * @param target_ptr プレーヤーへの参照ポインタ
2360 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2361 * @param m_idx モンスターID
2362 * @param ny 移動後の、モンスターのY座標
2363 * @param ox 移動後の、モンスターのX座標
2365 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2367 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2368 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2370 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2372 OBJECT_IDX this_o_idx, next_o_idx;
2373 turn_flags_ptr->do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
2374 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2376 BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
2377 GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
2378 object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
2379 next_o_idx = o_ptr->next_o_idx;
2381 if (turn_flags_ptr->do_take)
2383 /* Skip gold, corpse and statue */
2384 if (o_ptr->tval == TV_GOLD || (o_ptr->tval == TV_CORPSE) || (o_ptr->tval == TV_STATUE))
2388 object_flags(o_ptr, flgs);
2389 object_desc(target_ptr, o_name, o_ptr, 0);
2390 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
2392 if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
2393 if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
2394 if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
2395 if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
2396 if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
2397 if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
2398 if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
2399 if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
2400 if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
2401 if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
2402 if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
2403 if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
2404 if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
2405 if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
2406 if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
2407 if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
2408 if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
2409 if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
2410 if (have_flag(flgs, TR_BRAND_ACID)) flgr |= (RFR_IM_ACID);
2411 if (have_flag(flgs, TR_BRAND_ELEC)) flgr |= (RFR_IM_ELEC);
2412 if (have_flag(flgs, TR_BRAND_FIRE)) flgr |= (RFR_IM_FIRE);
2413 if (have_flag(flgs, TR_BRAND_COLD)) flgr |= (RFR_IM_COLD);
2414 if (have_flag(flgs, TR_BRAND_POIS)) flgr |= (RFR_IM_POIS);
2416 if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
2417 ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
2419 if (turn_flags_ptr->do_take && (r_ptr->flags2 & RF2_STUPID))
2421 turn_flags_ptr->did_take_item = TRUE;
2422 if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
2424 msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
2428 else if (turn_flags_ptr->do_take)
2430 turn_flags_ptr->did_take_item = TRUE;
2431 if (player_can_see_bold(target_ptr, ny, nx))
2433 msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
2436 excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
2437 o_ptr->marked &= OM_TOUCHED;
2438 o_ptr->iy = o_ptr->ix = 0;
2439 o_ptr->held_m_idx = m_idx;
2440 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2441 m_ptr->hold_o_idx = this_o_idx;
2443 else if (!is_pet(m_ptr))
2445 turn_flags_ptr->did_kill_item = TRUE;
2446 if (player_has_los_bold(target_ptr, ny, nx))
2448 msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
2451 delete_object_idx(target_ptr, this_o_idx);
2458 * @brief 全モンスターのターン管理メインルーチン /
2459 * Process all the "live" monsters, once per game turn.
2462 * During each game current game turn, we scan through the list of all the "live" monsters,\n
2463 * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
2464 * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
2466 * Note that monsters can never move in the monster array (except when the\n
2467 * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
2469 * This function is responsible for at least half of the processor time\n
2470 * on a normal system with a "normal" amount of monsters and a player doing\n
2473 * When the player is resting, virtually 90% of the processor time is spent\n
2474 * in this function, and its children, "process_monster()" and "make_move()".\n
2476 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
2477 * especially when the player is running.\n
2479 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
2480 * monsters while they are still being "born". A monster is "fresh" only\n
2481 * during the game turn in which it is created, and we use the "hack_m_idx" to\n
2482 * determine if the monster is yet to be processed during the game turn.\n
2484 * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
2485 * move before any "nasty" monsters get to use their spell attacks.\n
2487 * Note that when the "knowledge" about the currently tracked monster\n
2488 * changes (flags, attacks, spells), we induce a redraw of the monster\n
2491 void process_monsters(player_type *target_ptr)
2493 BIT_FLAGS old_r_flags1 = 0L;
2494 BIT_FLAGS old_r_flags2 = 0L;
2495 BIT_FLAGS old_r_flags3 = 0L;
2496 BIT_FLAGS old_r_flags4 = 0L;
2497 BIT_FLAGS old_r_flags5 = 0L;
2498 BIT_FLAGS old_r_flags6 = 0L;
2499 BIT_FLAGS old_r_flagsr = 0L;
2501 byte old_r_blows0 = 0;
2502 byte old_r_blows1 = 0;
2503 byte old_r_blows2 = 0;
2504 byte old_r_blows3 = 0;
2506 floor_type *floor_ptr = target_ptr->current_floor_ptr;
2507 floor_ptr->monster_noise = FALSE;
2509 MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
2510 byte old_r_cast_spell = 0;
2511 if (target_ptr->monster_race_idx)
2513 monster_race *r_ptr;
2514 r_ptr = &r_info[target_ptr->monster_race_idx];
2516 old_r_flags1 = r_ptr->r_flags1;
2517 old_r_flags2 = r_ptr->r_flags2;
2518 old_r_flags3 = r_ptr->r_flags3;
2519 old_r_flags4 = r_ptr->r_flags4;
2520 old_r_flags5 = r_ptr->r_flags5;
2521 old_r_flags6 = r_ptr->r_flags6;
2522 old_r_flagsr = r_ptr->r_flagsr;
2524 old_r_blows0 = r_ptr->r_blows[0];
2525 old_r_blows1 = r_ptr->r_blows[1];
2526 old_r_blows2 = r_ptr->r_blows[2];
2527 old_r_blows3 = r_ptr->r_blows[3];
2529 old_r_cast_spell = r_ptr->r_cast_spell;
2532 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
2534 monster_type *m_ptr;
2535 monster_race *r_ptr;
2536 m_ptr = &floor_ptr->m_list[i];
2537 r_ptr = &r_info[m_ptr->r_idx];
2539 if (target_ptr->leaving) break;
2540 if (!monster_is_valid(m_ptr)) continue;
2541 if (target_ptr->wild_mode) continue;
2543 if (m_ptr->mflag & MFLAG_BORN)
2545 m_ptr->mflag &= ~(MFLAG_BORN);
2549 if (m_ptr->cdis >= AAF_LIMIT) continue;
2551 POSITION fx = m_ptr->fx;
2552 POSITION fy = m_ptr->fy;
2553 if (!target_ptr->no_flowed)
2555 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
2559 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
2563 else if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
2564 (player_has_los_bold(target_ptr, fy, fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
2568 else if (m_ptr->target_y)
2573 if (!test) continue;
2576 if (target_ptr->riding == i)
2578 speed = target_ptr->pspeed;
2582 speed = m_ptr->mspeed;
2583 if (ironman_nightmare) speed += 5;
2585 if (MON_FAST(m_ptr)) speed += 10;
2586 if (MON_SLOW(m_ptr)) speed -= 10;
2589 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
2590 if (m_ptr->energy_need > 0) continue;
2592 m_ptr->energy_need += ENERGY_NEED();
2594 process_monster(target_ptr, i);
2595 reset_target(m_ptr);
2597 if (target_ptr->no_flowed && one_in_(3))
2598 m_ptr->mflag2 |= MFLAG2_NOFLOW;
2600 if (!target_ptr->playing || target_ptr->is_dead) break;
2601 if (target_ptr->leaving) break;
2605 if (!target_ptr->monster_race_idx || (target_ptr->monster_race_idx != old_monster_race_idx))
2608 monster_race *r_ptr;
2609 r_ptr = &r_info[target_ptr->monster_race_idx];
2611 if ((old_r_flags1 != r_ptr->r_flags1) ||
2612 (old_r_flags2 != r_ptr->r_flags2) ||
2613 (old_r_flags3 != r_ptr->r_flags3) ||
2614 (old_r_flags4 != r_ptr->r_flags4) ||
2615 (old_r_flags5 != r_ptr->r_flags5) ||
2616 (old_r_flags6 != r_ptr->r_flags6) ||
2617 (old_r_flagsr != r_ptr->r_flagsr) ||
2618 (old_r_blows0 != r_ptr->r_blows[0]) ||
2619 (old_r_blows1 != r_ptr->r_blows[1]) ||
2620 (old_r_blows2 != r_ptr->r_blows[2]) ||
2621 (old_r_blows3 != r_ptr->r_blows[3]) ||
2622 (old_r_cast_spell != r_ptr->r_cast_spell))
2624 target_ptr->window |= (PW_MONSTER);