2 * @file monster-process.c
3 * @brief モンスターの特殊技能と移動処理/ Monster spells and movement
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"
43 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
44 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
45 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx);
46 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
47 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
48 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
49 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
50 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
51 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware);
52 bool runaway_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon, bool see_m);
53 void process_special(player_type *target_ptr, MONSTER_IDX m_idx);
54 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware);
55 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware);
58 * @brief モンスターが敵に接近するための方向を決める /
59 * Calculate the direction to the next enemy
60 * @param target_ptr プレーヤーへの参照ポインタ
61 * @param m_idx モンスターの参照ID
62 * @param mm 移動するべき方角IDを返す参照ポインタ
63 * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
65 static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
67 floor_type *floor_ptr = target_ptr->current_floor_ptr;
68 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
69 monster_race *r_ptr = &r_info[m_ptr->r_idx];
72 POSITION x = 0, y = 0;
73 if (target_ptr->riding_t_m_idx && player_bold(target_ptr, m_ptr->fy, m_ptr->fx))
75 y = floor_ptr->m_list[target_ptr->riding_t_m_idx].fy;
76 x = floor_ptr->m_list[target_ptr->riding_t_m_idx].fx;
78 else if (is_pet(m_ptr) && target_ptr->pet_t_m_idx)
80 y = floor_ptr->m_list[target_ptr->pet_t_m_idx].fy;
81 x = floor_ptr->m_list[target_ptr->pet_t_m_idx].fx;
87 if (target_ptr->phase_out)
89 start = randint1(floor_ptr->m_max - 1) + floor_ptr->m_max;
90 if (randint0(2)) plus = -1;
92 else start = floor_ptr->m_max + 1;
94 /* Scan thru all monsters */
95 for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus)
97 MONSTER_IDX dummy = (i % floor_ptr->m_max);
101 MONSTER_IDX t_idx = dummy;
102 t_ptr = &floor_ptr->m_list[t_idx];
104 /* The monster itself isn't a target */
105 if (t_ptr == m_ptr) continue;
107 if (!monster_is_valid(t_ptr)) continue;
111 /* Hack -- only fight away from player */
112 if (target_ptr->pet_follow_distance < 0)
114 /* No fighting near player */
115 if (t_ptr->cdis <= (0 - target_ptr->pet_follow_distance))
120 /* Hack -- no fighting away from player */
121 else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > target_ptr->pet_follow_distance))
126 if (r_ptr->aaf < t_ptr->cdis) continue;
129 /* Monster must be 'an enemy' */
130 if (!are_enemies(target_ptr, m_ptr, t_ptr)) continue;
132 /* Monster must be projectable if we can't pass through walls */
133 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) ||
134 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)))
136 if (!in_disintegration_range(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
140 if (!projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
143 /* OK -- we've got a target */
150 if (!x && !y) return FALSE;
153 /* Extract the direction */
158 if ((y < 0) && (x == 0))
165 else if ((y > 0) && (x == 0))
172 else if ((x > 0) && (y == 0))
179 else if ((x < 0) && (y == 0))
186 else if ((y < 0) && (x < 0))
193 else if ((y < 0) && (x > 0))
200 else if ((y > 0) && (x < 0))
207 else if ((y > 0) && (x > 0))
218 * @brief モンスターがプレイヤーから逃走するかどうかを返す /
219 * Returns whether a given monster will try to run from the player.
220 * @param m_idx 逃走するモンスターの参照ID
221 * @return モンスターがプレイヤーから逃走するならばTRUEを返す。
223 * Monsters will attempt to avoid very powerful players. See below.\n
225 * Because this function is called so often, little details are important\n
226 * for efficiency. Like not using "mod" or "div" when possible. And\n
227 * attempting to check the conditions in an optimal order. Note that\n
228 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
230 * Note that this function is responsible for about one to five percent\n
231 * of the processor use in normal conditions...\n
233 static bool mon_will_run(player_type *target_ptr, MONSTER_IDX m_idx)
235 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
236 monster_race *r_ptr = &r_info[m_ptr->r_idx];
240 HIT_POINT p_chp, p_mhp;
241 HIT_POINT m_chp, m_mhp;
244 /* Friends can be commanded to avoid the player */
247 /* Are we trying to avoid the player? */
248 return ((target_ptr->pet_follow_distance < 0) &&
249 (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
252 /* Keep monsters from running too far away */
253 if (m_ptr->cdis > MAX_SIGHT + 5) return FALSE;
255 /* All "afraid" monsters will run away */
256 if (MON_MONFEAR(m_ptr)) return TRUE;
258 /* Nearby monsters will not become terrified */
259 if (m_ptr->cdis <= 5) return FALSE;
261 /* Examine player power (level) */
262 p_lev = target_ptr->lev;
264 /* Examine monster power (level plus morale) */
265 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
267 /* Optimize extreme cases below */
268 if (m_lev > p_lev + 4) return FALSE;
269 if (m_lev + 4 <= p_lev) return TRUE;
271 /* Examine player health */
272 p_chp = target_ptr->chp;
273 p_mhp = target_ptr->mhp;
275 /* Examine monster health */
277 m_mhp = m_ptr->maxhp;
279 /* Prepare to optimize the calculation */
280 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
281 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
283 /* Strong players scare strong monsters */
284 if (p_val * m_mhp > m_val * p_mhp) return TRUE;
291 * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
292 * Search spell castable grid
293 * @param target_ptr プレーヤーへの参照ポインタ
294 * @param m_idx モンスターの参照ID
295 * @param yp 適したマスのY座標を返す参照ポインタ
296 * @param xp 適したマスのX座標を返す参照ポインタ
297 * @return 有効なマスがあった場合TRUEを返す
299 static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
301 floor_type *floor_ptr = target_ptr->current_floor_ptr;
302 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
303 monster_race *r_ptr = &r_info[m_ptr->r_idx];
305 /* Monster location */
306 POSITION y1 = m_ptr->fy;
307 POSITION x1 = m_ptr->fx;
309 /* Monster can already cast spell to player */
310 if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x)) return FALSE;
312 /* Set current grid cost */
313 int now_cost = floor_ptr->grid_array[y1][x1].cost;
314 if (now_cost == 0) now_cost = 999;
316 /* Can monster bash or open doors? */
317 bool can_open_door = FALSE;
318 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
320 can_open_door = TRUE;
323 /* Check nearby grids, diagonals first */
325 for (int i = 7; i >= 0; i--)
329 POSITION y = y1 + ddy_ddd[i];
330 POSITION x = x1 + ddx_ddd[i];
332 /* Ignore locations off of edge */
333 if (!in_bounds2(floor_ptr, y, x)) continue;
335 /* Simply move to player */
336 if (player_bold(target_ptr, y, x)) return FALSE;
339 g_ptr = &floor_ptr->grid_array[y][x];
343 /* Monster cannot kill or pass walls */
344 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))))
346 if (cost == 0) continue;
347 if (!can_open_door && is_closed_door(target_ptr, g_ptr->feat)) continue;
350 /* Hack -- for kill or pass wall monster.. */
351 if (cost == 0) cost = 998;
353 if (now_cost < cost) continue;
355 if (!projectable(target_ptr, y, x, target_ptr->y, target_ptr->x)) continue;
357 /* Accept louder sounds */
358 if (best < cost) continue;
361 (*yp) = y1 + ddy_ddd[i];
362 (*xp) = x1 + ddx_ddd[i];
365 if (best == 999) return FALSE;
372 * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
373 * Choose the "best" direction for "flowing"
374 * @param m_idx モンスターの参照ID
375 * @param yp 移動先のマスのY座標を返す参照ポインタ
376 * @param xp 移動先のマスのX座標を返す参照ポインタ
377 * @param no_flow モンスターにFLOWフラグが経っていない状態でTRUE
378 * @return 有効なマスがあった場合TRUEを返す
380 * Note that ghosts and rock-eaters are never allowed to "flow",\n
381 * since they should move directly towards the player.\n
383 * Prefer "non-diagonal" directions, but twiddle them a little\n
384 * to angle slightly towards the player's actual location.\n
386 * Allow very perceptive monsters to track old "spoor" left by\n
387 * previous locations occupied by the player. This will tend\n
388 * to have monsters end up either near the player or on a grid\n
389 * recently occupied by the player (and left via "teleport").\n
391 * Note that if "smell" is turned on, all monsters get vicious.\n
393 * Also note that teleporting away from a location will cause\n
394 * the monsters who were chasing you to converge on that location\n
395 * as long as you are still near enough to "annoy" them without\n
396 * being close enough to chase directly. I have no idea what will\n
397 * happen if you combine "smell" with low "aaf" values.\n
399 static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
402 floor_type *floor_ptr = target_ptr->current_floor_ptr;
403 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
404 monster_race *r_ptr = &r_info[m_ptr->r_idx];
406 /* Can monster cast attack spell? */
407 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
408 r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
409 r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
411 /* Can move spell castable grid? */
412 if (get_moves_aux2(target_ptr, m_idx, yp, xp)) return TRUE;
415 /* Monster can't flow */
416 if (no_flow) return FALSE;
418 /* Monster can go through rocks */
419 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) return FALSE;
420 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)) return FALSE;
422 /* Monster location */
423 POSITION y1 = m_ptr->fy;
424 POSITION x1 = m_ptr->fx;
426 /* Hack -- Player can see us, run towards him */
427 if (player_has_los_bold(target_ptr, y1, x1) && projectable(target_ptr, target_ptr->y, target_ptr->x, y1, x1)) return FALSE;
430 g_ptr = &floor_ptr->grid_array[y1][x1];
432 /* If we can hear noises, advance towards them */
434 bool use_scent = FALSE;
440 /* Otherwise, try to follow a scent trail */
441 else if (g_ptr->when)
444 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when - g_ptr->when > 127) return FALSE;
450 /* Otherwise, advance blindly */
456 /* Check nearby grids, diagonals first */
457 for (int i = 7; i >= 0; i--)
459 POSITION y = y1 + ddy_ddd[i];
460 POSITION x = x1 + ddx_ddd[i];
462 /* Ignore locations off of edge */
463 if (!in_bounds2(floor_ptr, y, x)) continue;
465 g_ptr = &floor_ptr->grid_array[y][x];
467 /* We're following a scent trail */
470 int when = g_ptr->when;
472 /* Accept younger scent */
473 if (best > when) continue;
477 /* We're using sound */
482 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
484 else cost = g_ptr->cost;
486 /* Accept louder sounds */
487 if ((cost == 0) || (best < cost)) continue;
491 /* Hack -- Save the "twiddled" location */
492 (*yp) = target_ptr->y + 16 * ddy_ddd[i];
493 (*xp) = target_ptr->x + 16 * ddx_ddd[i];
496 if (best == 999 || best == 0) return FALSE;
503 * @brief モンスターがプレイヤーから逃走することが可能なマスを走査する /
504 * Provide a location to flee to, but give the player a wide berth.
505 * @param m_idx モンスターの参照ID
506 * @param yp 移動先のマスのY座標を返す参照ポインタ
507 * @param xp 移動先のマスのX座標を返す参照ポインタ
508 * @return 有効なマスがあった場合TRUEを返す
510 * A monster may wish to flee to a location that is behind the player,\n
511 * but instead of heading directly for it, the monster should "swerve"\n
512 * around the player so that he has a smaller chance of getting hit.\n
514 static bool get_fear_moves_aux(floor_type *floor_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
516 POSITION gy = 0, gx = 0;
518 /* Monster location */
519 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
520 POSITION fy = m_ptr->fy;
521 POSITION fx = m_ptr->fx;
523 /* Desired destination */
524 POSITION y1 = fy - (*yp);
525 POSITION x1 = fx - (*xp);
527 /* Check nearby grids, diagonals first */
529 for (int i = 7; i >= 0; i--)
532 POSITION y = fy + ddy_ddd[i];
533 POSITION x = fx + ddx_ddd[i];
535 /* Ignore locations off of edge */
536 if (!in_bounds2(floor_ptr, y, x)) continue;
538 /* Calculate distance of this grid from our destination */
539 dis = distance(y, x, y1, x1);
541 /* Score this grid */
542 s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
544 /* No negative scores */
547 /* Ignore lower scores */
548 if (s < score) continue;
550 /* Save the score and time */
553 /* Save the location */
558 /* No legal move (?) */
559 if (score == -1) return FALSE;
570 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
573 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
574 * offsets of all the locations with a distance of n from a central point,
575 * with an offset of (0,0) indicating no more offsets at this distance.
577 * This is, of course, fairly unreadable, but it eliminates multiple loops
578 * from the previous version.
580 * It is probably better to replace these arrays with code to compute
581 * the relevant arrays, even if the storage is pre-allocated in hard
582 * coded sizes. At the very least, code should be included which is
583 * able to generate and dump these arrays (ala "los()").
585 * Also, the storage needs could be halved by using bytes.
587 * These arrays could be combined into two big arrays, using sub-arrays
588 * to hold the offsets and lengths of each portion of the sub-arrays, and
589 * this could perhaps also be used somehow in the "look" code.
593 static POSITION d_off_y_0[] = { 0 };
594 static POSITION d_off_x_0[] = { 0 };
596 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
597 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
599 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
600 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
602 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
603 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
605 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 };
606 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 };
609 static POSITION d_off_y_5[] =
610 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
611 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
614 static POSITION d_off_x_5[] =
615 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
616 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
620 static POSITION d_off_y_6[] =
621 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
622 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
625 static POSITION d_off_x_6[] =
626 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
627 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
628 -3, 2, 3, -1, 0, 1, 0 };
631 static POSITION d_off_y_7[] =
632 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
633 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
634 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
636 static POSITION d_off_x_7[] =
637 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
638 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
639 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
643 static POSITION d_off_y_8[] =
644 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
645 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
646 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
649 static POSITION d_off_x_8[] =
650 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
651 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
652 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
656 static POSITION d_off_y_9[] =
657 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
658 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
659 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
660 7, 8, 8, 8, 8, 9, 9, 9, 0 };
662 static POSITION d_off_x_9[] =
663 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
664 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
665 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
666 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
669 static POSITION *dist_offsets_y[10] =
671 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
672 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
675 static POSITION *dist_offsets_x[10] =
677 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
678 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
682 * @brief モンスターが逃げ込める安全な地点を返す /
683 * Choose a "safe" location near a monster for it to run toward.
684 * @param target_ptr プレーヤーへの参照ポインタ
685 * @param m_idx モンスターの参照ID
686 * @param yp 移動先のマスのY座標を返す参照ポインタ
687 * @param xp 移動先のマスのX座標を返す参照ポインタ
688 * @return 有効なマスがあった場合TRUEを返す
690 * A location is "safe" if it can be reached quickly and the player\n
691 * is not able to fire into it (it isn't a "clean shot"). So, this will\n
692 * cause monsters to "duck" behind walls. Hopefully, monsters will also\n
693 * try to run towards corridor openings if they are in a room.\n
695 * This function may take lots of CPU time if lots of monsters are\n
698 * Return TRUE if a safe location is available.\n
700 static bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
702 floor_type *floor_ptr = target_ptr->current_floor_ptr;
703 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
705 POSITION fy = m_ptr->fy;
706 POSITION fx = m_ptr->fx;
708 POSITION gy = 0, gx = 0, gdis = 0;
710 /* Start with adjacent locations, spread further */
711 for (POSITION d = 1; d < 10; d++)
713 /* Get the lists of points with a distance d from (fx, fy) */
715 y_offsets = dist_offsets_y[d];
718 x_offsets = dist_offsets_x[d];
720 /* Check the locations */
721 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
723 i++, dx = x_offsets[i], dy = y_offsets[i])
725 POSITION y = fy + dy;
726 POSITION x = fx + dx;
728 /* Skip illegal locations */
729 if (!in_bounds(floor_ptr, y, x)) continue;
732 g_ptr = &floor_ptr->grid_array[y][x];
734 /* Skip locations in a wall */
735 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], (m_idx == target_ptr->riding) ? CEM_RIDING : 0)) continue;
737 /* Check for "availability" (if monsters can flow) */
738 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
740 /* Ignore grids very far from the player */
741 if (g_ptr->dist == 0) continue;
743 /* Ignore too-distant grids */
744 if (g_ptr->dist > floor_ptr->grid_array[fy][fx].dist + 2 * d) continue;
747 /* Check for absence of shot (more or less) */
748 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x)) continue;
750 /* Calculate distance from player */
751 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
753 /* Remember if further than previous */
754 if (dis <= gdis) continue;
761 /* Check for success */
762 if (gdis <= 0) continue;
776 * @brief モンスターが隠れ潜める地点を返す /
777 * Choose a good hiding place near a monster for it to run toward.
778 * @param target_ptr プレーヤーへの参照ポインタ
779 * @param m_idx モンスターの参照ID
780 * @param yp 移動先のマスのY座標を返す参照ポインタ
781 * @param xp 移動先のマスのX座標を返す参照ポインタ
782 * @return 有効なマスがあった場合TRUEを返す
784 * Pack monsters will use this to "ambush" the player and lure him out\n
785 * of corridors into open space so they can swarm him.\n
787 * Return TRUE if a good location is available.\n
789 static bool find_hiding(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
791 floor_type *floor_ptr = target_ptr->current_floor_ptr;
792 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
793 monster_race *r_ptr = &r_info[m_ptr->r_idx];
795 POSITION fy = m_ptr->fy;
796 POSITION fx = m_ptr->fx;
798 POSITION gy = 0, gx = 0, gdis = 999;
800 /* Start with adjacent locations, spread further */
801 for (POSITION d = 1; d < 10; d++)
803 /* Get the lists of points with a distance d from (fx, fy) */
805 y_offsets = dist_offsets_y[d];
808 x_offsets = dist_offsets_x[d];
810 /* Check the locations */
811 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
813 i++, dx = x_offsets[i], dy = y_offsets[i])
815 POSITION y = fy + dy;
816 POSITION x = fx + dx;
818 /* Skip illegal locations */
819 if (!in_bounds(floor_ptr, y, x)) continue;
821 /* Skip occupied locations */
822 if (!monster_can_enter(target_ptr, y, x, r_ptr, 0)) continue;
824 /* Check for hidden, available grid */
825 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, fy, fx, y, x, FALSE))
828 /* Calculate distance from player */
829 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
831 /* Remember if closer than previous */
832 if (dis < gdis && dis >= 2)
840 if (gdis >= 999) continue;
853 * @brief モンスターの移動方向を返す /
854 * Choose "logical" directions for monster movement
855 * @param target_ptr プレーヤーへの参照ポインタ
856 * @param m_idx モンスターの参照ID
857 * @param mm 移動方向を返す方向IDの参照ポインタ
858 * @return 有効方向があった場合TRUEを返す
860 static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
862 floor_type *floor_ptr = target_ptr->current_floor_ptr;
863 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
864 monster_race *r_ptr = &r_info[m_ptr->r_idx];
865 POSITION y = 0, ay, x = 0, ax;
867 POSITION y2 = target_ptr->y;
868 POSITION x2 = target_ptr->x;
870 bool will_run = mon_will_run(target_ptr, m_idx);
872 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2));
873 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall));
875 /* Counter attack to an enemy monster */
876 if (!will_run && m_ptr->target_y)
878 int t_m_idx = floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
880 /* The monster must be an enemy, and in LOS */
882 are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[t_m_idx]) &&
883 los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
884 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
886 /* Extract the "pseudo-direction" */
887 y = m_ptr->fy - m_ptr->target_y;
888 x = m_ptr->fx - m_ptr->target_x;
893 if (!done && !will_run && is_hostile(m_ptr) &&
894 (r_ptr->flags1 & RF1_FRIENDS) &&
895 ((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)) ||
896 (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
899 * Animal packs try to get the player out of corridors
900 * (...unless they can move through walls -- TY)
902 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
903 !(r_ptr->flags2 & RF2_KILL_WALL))
907 /* Count room grids next to player */
908 for (i = 0; i < 8; i++)
910 int xx = target_ptr->x + ddx_ddd[i];
911 int yy = target_ptr->y + ddy_ddd[i];
913 if (!in_bounds2(floor_ptr, yy, xx)) continue;
915 g_ptr = &floor_ptr->grid_array[yy][xx];
918 if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0))
920 /* One more room grid */
924 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].info & CAVE_ROOM) room -= 2;
925 if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
927 /* Not in a room and strong player */
928 if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
929 (target_ptr->mhp + target_ptr->msp))
931 /* Find hiding place */
932 if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
936 /* Monster groups try to surround the player */
937 if (!done && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
941 /* Find an empty square near the player to fill */
942 for (i = 0; i < 8; i++)
944 /* Pick squares near player (semi-randomly) */
945 y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
946 x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
949 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
951 /* Attack the player */
958 if (!in_bounds2(floor_ptr, y2, x2)) continue;
960 /* Ignore filled grids */
961 if (!monster_can_enter(target_ptr, y2, x2, r_ptr, 0)) continue;
963 /* Try to fill this hole */
967 /* Extract the new "pseudo-direction" */
977 /* Flow towards the player */
978 (void)get_moves_aux(target_ptr, m_idx, &y2, &x2, no_flow);
980 /* Extract the "pseudo-direction" */
987 /* Apply fear if possible and necessary */
988 if (is_pet(m_ptr) && will_run)
990 /* XXX XXX Not very "smart" */
995 if (!done && will_run)
1000 /* Try to find safe place */
1001 if (find_safety(target_ptr, m_idx, &y, &x))
1003 /* Attempt to avoid the player */
1006 /* Adjust movement */
1007 if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x)) done = TRUE;
1013 /* This is not a very "smart" method XXX XXX */
1021 /* Check for no move */
1022 if (!x && !y) return FALSE;
1025 /* Extract the "absolute distances" */
1029 /* Do something weird */
1030 if (y < 0) move_val += 8;
1031 if (x > 0) move_val += 4;
1033 /* Prevent the diamond maneuvre */
1034 if (ay > (ax << 1)) move_val += 2;
1035 else if (ax > (ay << 1)) move_val++;
1037 /* Extract some directions */
1182 /* Wants to move... */
1187 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
1189 return !have_flag(f_ptr->flags, FF_GLASS) ||
1190 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
1191 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
1196 * @brief モンスター単体の1ターン行動処理メインルーチン /
1198 * @param target_ptr プレーヤーへの参照ポインタ
1199 * @param m_idx 行動モンスターの参照ID
1202 * The monster is known to be within 100 grids of the player\n
1204 * In several cases, we directly update the monster lore\n
1206 * Note that a monster is only allowed to "reproduce" if there\n
1207 * are a limited number of "reproducing" monsters on the current\n
1208 * level. This should prevent the level from being "swamped" by\n
1209 * reproducing monsters. It also allows a large mass of mice to\n
1210 * prevent a louse from multiplying, but this is a small price to\n
1211 * pay for a simple multiplication method.\n
1213 * XXX Monster fear is slightly odd, in particular, monsters will\n
1214 * fixate on opening a door even if they cannot open it. Actually,\n
1215 * the same thing happens to normal monsters when they hit a door\n
1217 * In addition, monsters which *cannot* open or bash\n
1218 * down a door will still stand there trying to open it...\n
1220 * XXX Technically, need to check for monster in the way\n
1221 * combined with that monster being in a wall (or door?)\n
1223 * A "direction" of "5" means "pick a random direction".\n
1225 void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1227 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1228 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1229 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1234 feature_type *f_ptr;
1235 monster_type *y_ptr;
1237 bool is_riding_mon = (m_idx == target_ptr->riding);
1238 bool see_m = is_seen(m_ptr);
1240 decide_drop_from_monster(target_ptr, m_idx, is_riding_mon);
1241 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
1243 choose_new_monster(target_ptr, m_idx, FALSE, 0);
1244 r_ptr = &r_info[m_ptr->r_idx];
1248 if (target_ptr->special_defense & NINJA_S_STEALTH)
1250 int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
1251 if (target_ptr->monlite) tmp /= 3;
1252 if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1253 if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
1254 if (randint0(tmp) > (r_ptr->level + 20)) aware = FALSE;
1257 if (vanish_summoned_children(target_ptr, m_idx, see_m)) return;
1258 if (process_quantum_effect(target_ptr,m_idx, see_m)) return;
1260 if (m_ptr->r_idx == MON_SHURYUUDAN)
1263 mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
1267 if (runaway_monster(target_ptr, m_idx, is_riding_mon, see_m)) return;
1269 awake_monster(target_ptr, m_idx);
1272 if (MON_STUNNED(m_ptr))
1274 /* Sometimes skip move */
1275 if (one_in_(2)) return;
1280 target_ptr->update |= (PU_BONUS);
1283 process_angar(target_ptr, m_idx, see_m);
1285 /* Get the origin */
1286 POSITION oy = m_ptr->fy;
1287 POSITION ox = m_ptr->fx;
1289 if (decide_monster_multiplication(target_ptr, m_idx, oy, ox)) return;
1291 process_special(target_ptr, m_idx);
1292 process_speak_sound(target_ptr, m_idx, oy, ox, aware);
1293 if (cast_spell(target_ptr, m_idx, aware)) return;
1295 /* Hack -- Assume no movement */
1296 mm[0] = mm[1] = mm[2] = mm[3] = 0;
1297 mm[4] = mm[5] = mm[6] = mm[7] = 0;
1299 if (!decide_monster_movement_direction(target_ptr, mm, m_idx, aware)) return;
1301 /* Assume nothing */
1302 bool do_turn = FALSE;
1303 bool do_move = FALSE;
1304 bool do_view = FALSE;
1305 bool must_alter_to_move = FALSE;
1307 /* Assume nothing */
1308 bool did_open_door = FALSE;
1309 bool did_bash_door = FALSE;
1310 bool did_take_item = FALSE;
1311 bool did_kill_item = FALSE;
1312 bool did_move_body = FALSE;
1313 bool did_pass_wall = FALSE;
1314 bool did_kill_wall = FALSE;
1316 /* Take a zero-terminated array of "directions" */
1318 for (i = 0; mm[i]; i++)
1320 /* Get the direction */
1323 /* Hack -- allow "randomized" motion */
1324 if (d == 5) d = ddd[randint0(8)];
1326 /* Get the destination */
1327 POSITION ny = oy + ddy[d];
1328 POSITION nx = ox + ddx[d];
1330 /* Ignore locations off of edge */
1331 if (!in_bounds2(target_ptr->current_floor_ptr, ny, nx)) continue;
1333 /* Access that grid */
1334 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1335 f_ptr = &f_info[g_ptr->feat];
1336 bool can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0);
1338 /* Access that grid's contents */
1339 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
1341 /* Hack -- player 'in' wall */
1342 if (player_bold(target_ptr, ny, nx))
1347 /* Possibly a monster to attack */
1348 else if (g_ptr->m_idx)
1353 /* Monster destroys walls (and doors) */
1354 else if ((r_ptr->flags2 & RF2_KILL_WALL) &&
1355 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !is_riding_mon) &&
1356 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
1357 check_hp_for_feat_destruction(f_ptr, m_ptr))
1359 /* Eat through walls/doors/rubble */
1361 if (!can_cross) must_alter_to_move = TRUE;
1363 /* Monster destroyed a wall (later) */
1364 did_kill_wall = TRUE;
1367 /* Floor is open? */
1370 /* Go ahead and move */
1373 /* Monster moves through walls (and doors) */
1374 if ((r_ptr->flags2 & RF2_PASS_WALL) && (!is_riding_mon || target_ptr->pass_wall) &&
1375 have_flag(f_ptr->flags, FF_CAN_PASS))
1377 /* Monster went through a wall */
1378 did_pass_wall = TRUE;
1382 /* Handle doors and secret doors */
1383 else if (is_closed_door(target_ptr, g_ptr->feat))
1385 bool may_bash = TRUE;
1387 /* Assume no move allowed */
1390 /* Creature can open doors. */
1391 if ((r_ptr->flags2 & RF2_OPEN_DOOR) && have_flag(f_ptr->flags, FF_OPEN) &&
1392 (!is_pet(m_ptr) || (target_ptr->pet_extra_flags & PF_OPEN_DOORS)))
1397 /* The door is open */
1398 did_open_door = TRUE;
1400 /* Do not bash the door */
1406 /* Locked doors (not jammed) */
1409 /* Try to unlock it */
1410 if (randint0(m_ptr->hp / 10) > f_ptr->power)
1412 /* Unlock the door */
1413 cave_alter_feat(target_ptr, ny, nx, FF_DISARM);
1415 /* Do not bash the door */
1423 /* Stuck doors -- attempt to bash them down if allowed */
1424 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) && have_flag(f_ptr->flags, FF_BASH) &&
1425 (!is_pet(m_ptr) || (target_ptr->pet_extra_flags & PF_OPEN_DOORS)))
1427 /* Attempt to Bash */
1428 if (check_hp_for_feat_destruction(f_ptr, m_ptr) && (randint0(m_ptr->hp / 10) > f_ptr->power))
1430 if (have_flag(f_ptr->flags, FF_GLASS))
1431 msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
1433 msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
1435 /* Disturb (sometimes) */
1436 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
1438 /* The door was bashed open */
1439 did_bash_door = TRUE;
1441 /* Hack -- fall into doorway */
1443 must_alter_to_move = TRUE;
1448 /* Deal with doors in the way */
1449 if (did_open_door || did_bash_door)
1451 /* Break down the door */
1452 if (did_bash_door && ((randint0(100) < 50) || (feat_state(target_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
1454 cave_alter_feat(target_ptr, ny, nx, FF_BASH);
1456 if (!monster_is_valid(m_ptr)) /* Killed by shards of glass, etc. */
1458 target_ptr->update |= (PU_FLOW);
1459 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1460 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
1469 cave_alter_feat(target_ptr, ny, nx, FF_OPEN);
1472 f_ptr = &f_info[g_ptr->feat];
1474 /* Handle viewable doors */
1479 /* Hack -- check for Glyph of Warding */
1480 if (do_move && is_glyph_grid(g_ptr) &&
1481 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(target_ptr, ny, nx)))
1483 /* Assume no move allowed */
1486 /* Break the ward */
1487 if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
1489 /* Describe observable breakage */
1490 if (g_ptr->info & CAVE_MARK)
1492 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
1495 /* Forget the rune */
1496 g_ptr->info &= ~(CAVE_MARK);
1498 /* Break the rune */
1499 g_ptr->info &= ~(CAVE_OBJECT);
1502 /* Allow movement */
1505 note_spot(target_ptr, ny, nx);
1508 else if (do_move && is_explosive_rune_grid(g_ptr) &&
1509 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(target_ptr, ny, nx)))
1511 /* Assume no move allowed */
1514 /* Break the ward */
1517 /* Break the ward */
1518 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
1520 /* Describe observable breakage */
1521 if (g_ptr->info & CAVE_MARK)
1523 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
1524 project(target_ptr, 0, 2, ny, nx, 2 * (target_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
1529 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
1532 /* Forget the rune */
1533 g_ptr->info &= ~(CAVE_MARK);
1535 /* Break the rune */
1536 g_ptr->info &= ~(CAVE_OBJECT);
1539 note_spot(target_ptr, ny, nx);
1540 lite_spot(target_ptr, ny, nx);
1542 if (!monster_is_valid(m_ptr)) return;
1543 /* Allow movement */
1548 /* The player is in the way */
1549 if (do_move && player_bold(target_ptr, ny, nx))
1551 /* Some monsters never attack */
1552 if (r_ptr->flags1 & RF1_NEVER_BLOW)
1554 /* Hack -- memorize lack of attacks */
1555 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
1561 /* In anti-melee dungeon, stupid or confused monster takes useless turn */
1562 if (do_move && (d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE))
1564 if (!MON_CONFUSED(m_ptr))
1566 if (!(r_ptr->flags2 & RF2_STUPID)) do_move = FALSE;
1569 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
1574 /* The player is in the way. Attack him. */
1577 if (!target_ptr->riding || one_in_(2))
1580 (void)make_attack_normal(target_ptr, m_idx);
1591 /* A monster is in the way */
1592 if (do_move && g_ptr->m_idx)
1594 monster_race *z_ptr = &r_info[y_ptr->r_idx];
1596 /* Assume no movement */
1599 /* Attack 'enemies' */
1600 if (((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW) &&
1601 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
1602 can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
1603 are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
1605 if (!(r_ptr->flags1 & RF1_NEVER_BLOW))
1607 if (r_ptr->flags2 & RF2_KILL_BODY)
1609 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_BODY);
1613 if (y_ptr->r_idx && (y_ptr->hp >= 0))
1615 if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return;
1617 /* In anti-melee dungeon, stupid or confused monster takes useless turn */
1618 else if (d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE)
1620 if (MON_CONFUSED(m_ptr)) return;
1621 else if (r_ptr->flags2 & RF2_STUPID)
1623 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
1631 /* Push past weaker monsters (unless leaving a wall) */
1632 else if ((r_ptr->flags2 & RF2_MOVE_BODY) && !(r_ptr->flags1 & RF1_NEVER_MOVE) &&
1633 (r_ptr->mexp > z_ptr->mexp) &&
1634 can_cross && (g_ptr->m_idx != target_ptr->riding) &&
1635 monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
1637 /* Allow movement */
1640 /* Monster pushed past another monster */
1641 did_move_body = TRUE;
1643 /* Wake up the moved monster */
1644 (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
1652 if (!target_ptr->riding_ryoute && !MON_MONFEAR(&target_ptr->current_floor_ptr->m_list[target_ptr->riding])) do_move = FALSE;
1655 if (did_kill_wall && do_move)
1657 if (one_in_(GRINDNOISE))
1659 if (have_flag(f_ptr->flags, FF_GLASS))
1660 msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
1662 msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
1665 cave_alter_feat(target_ptr, ny, nx, FF_HURT_DISI);
1667 if (!monster_is_valid(m_ptr)) /* Killed by shards of glass, etc. */
1669 target_ptr->update |= (PU_FLOW);
1670 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1671 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
1676 f_ptr = &f_info[g_ptr->feat];
1678 /* Note changes to viewable region */
1683 if (must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
1685 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0))
1687 /* Assume no move allowed */
1693 * Check if monster can cross terrain
1694 * This is checked after the normal attacks
1695 * to allow monsters to attack an enemy,
1696 * even if it can't enter the terrain.
1698 if (do_move && !can_cross && !did_kill_wall && !did_bash_door)
1700 /* Assume no move allowed */
1704 /* Some monsters never move */
1705 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
1707 /* Hack -- memorize lack of moves */
1708 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
1714 /* Creature has been allowed move */
1723 if (have_flag(f_ptr->flags, FF_TREE))
1725 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
1727 m_ptr->energy_need += ENERGY_NEED();
1733 /* Hack -- Update the old location */
1734 target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
1736 /* Mega-Hack -- move the old monster, if any */
1739 /* Move the old monster */
1743 /* Update the old monster */
1744 update_monster(target_ptr, g_ptr->m_idx, TRUE);
1747 /* Hack -- Update the new location */
1748 g_ptr->m_idx = m_idx;
1750 /* Move the monster */
1753 update_monster(target_ptr, m_idx, TRUE);
1755 lite_spot(target_ptr, oy, ox);
1756 lite_spot(target_ptr, ny, nx);
1760 /* sound(SOUND_WALK); */
1761 if (!move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP)) break;
1764 /* Possible disturb */
1767 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
1768 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= target_ptr->lev)))
1770 if (is_hostile(m_ptr))
1771 disturb(target_ptr, FALSE, TRUE);
1774 /* Take or Kill objects on the floor */
1775 bool is_takable_or_killable = g_ptr->o_idx > 0;
1776 is_takable_or_killable &= (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) != 0;
1777 bool is_pickup_items = (target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
1778 is_pickup_items &= (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
1779 is_takable_or_killable &= !is_pet(m_ptr) || is_pickup_items;
1780 if (!is_takable_or_killable)
1786 OBJECT_IDX this_o_idx, next_o_idx;
1787 bool do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) ? TRUE : FALSE;
1789 /* Scan all objects in the grid */
1790 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1792 BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
1793 GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
1794 object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
1795 next_o_idx = o_ptr->next_o_idx;
1800 if (o_ptr->tval == TV_GOLD) continue;
1803 * Skip "real" corpses and statues, to avoid extreme
1804 * silliness like a novice rogue pockets full of statues
1807 if ((o_ptr->tval == TV_CORPSE) ||
1808 (o_ptr->tval == TV_STATUE)) continue;
1811 /* Extract some flags */
1812 object_flags(o_ptr, flgs);
1814 /* Acquire the object name */
1815 object_desc(target_ptr, o_name, o_ptr, 0);
1816 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
1818 /* React to objects that hurt the monster */
1819 if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
1820 if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
1821 if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
1822 if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
1823 if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
1824 if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
1825 if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
1826 if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
1827 if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
1828 if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
1829 if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
1830 if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
1831 if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
1832 if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
1833 if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
1834 if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
1835 if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
1836 if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
1837 if (have_flag(flgs, TR_BRAND_ACID)) flgr |= (RFR_IM_ACID);
1838 if (have_flag(flgs, TR_BRAND_ELEC)) flgr |= (RFR_IM_ELEC);
1839 if (have_flag(flgs, TR_BRAND_FIRE)) flgr |= (RFR_IM_FIRE);
1840 if (have_flag(flgs, TR_BRAND_COLD)) flgr |= (RFR_IM_COLD);
1841 if (have_flag(flgs, TR_BRAND_POIS)) flgr |= (RFR_IM_POIS);
1843 /* The object cannot be picked up by the monster */
1844 if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
1845 ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
1847 /* Only give a message for "take_item" */
1848 if (do_take && (r_ptr->flags2 & RF2_STUPID))
1850 did_take_item = TRUE;
1852 /* Describe observable situations */
1853 if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
1855 msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
1860 /* Pick up the item */
1863 did_take_item = TRUE;
1865 /* Describe observable situations */
1866 if (player_can_see_bold(target_ptr, ny, nx))
1868 msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
1871 /* Excise the object */
1872 excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
1875 o_ptr->marked &= OM_TOUCHED;
1877 /* Forget location */
1878 o_ptr->iy = o_ptr->ix = 0;
1880 /* Memorize monster */
1881 o_ptr->held_m_idx = m_idx;
1884 o_ptr->next_o_idx = m_ptr->hold_o_idx;
1887 m_ptr->hold_o_idx = this_o_idx;
1890 /* Destroy the item if not a pet */
1891 else if (!is_pet(m_ptr))
1893 did_kill_item = TRUE;
1895 /* Describe observable situations */
1896 if (player_has_los_bold(target_ptr, ny, nx))
1898 msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
1901 delete_object_idx(target_ptr, this_o_idx);
1909 * Forward movements failed, but now received LOS attack!
1910 * Try to flow by smell.
1912 if (target_ptr->no_flowed && i > 2 && m_ptr->target_y)
1913 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
1915 /* If we haven't done anything, try casting a spell again */
1916 if (!do_turn && !do_move && !MON_MONFEAR(m_ptr) && !is_riding_mon && aware)
1918 /* Try to cast spell again */
1919 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
1921 if (make_attack_spell(m_idx, target_ptr)) return;
1925 /* Notice changes in view */
1928 target_ptr->update |= (PU_FLOW);
1929 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1932 /* Notice changes in view */
1933 if (do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
1934 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !target_ptr->phase_out)))
1936 target_ptr->update |= (PU_MON_LITE);
1939 /* Learn things from observable monster */
1940 if (is_original_ap_and_seen(target_ptr, m_ptr))
1942 /* Monster opened a door */
1943 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
1945 /* Monster bashed a door */
1946 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
1948 /* Monster tried to pick something up */
1949 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
1951 /* Monster tried to crush something */
1952 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
1954 /* Monster pushed past another monster */
1955 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
1957 /* Monster passed through a wall */
1958 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
1960 /* Monster destroyed a wall */
1961 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
1964 bool is_battle_determined = !do_turn && !do_move && MON_MONFEAR(m_ptr) && aware;
1965 if (!is_battle_determined) return;
1967 /* No longer afraid */
1968 (void)set_monster_monfear(target_ptr, m_idx, 0);
1970 /* Message if seen */
1973 GAME_TEXT m_name[MAX_NLEN];
1974 monster_desc(target_ptr, m_name, m_ptr, 0);
1975 msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
1978 if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
1983 * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
1984 * @param target_ptr プレーヤーへの参照ポインタ
1985 * @param m_idx モンスターID
1986 * @param is_riding_mon 騎乗中であればTRUE
1989 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
1991 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1992 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1993 if (!is_riding_mon || ((r_ptr->flags7 & RF7_RIDING) != 0)) return;
1995 if (rakuba(target_ptr, 0, TRUE))
1998 msg_print("地面に落とされた。");
2000 GAME_TEXT m_name[MAX_NLEN];
2001 monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
2002 msg_format("You have fallen from %s.", m_name);
2009 * @brief 召喚の親元が消滅した時、子供も消滅させる
2010 * @param target_ptr プレーヤーへの参照ポインタ
2011 * @param m_idx モンスターID
2012 * @param see_m モンスターが視界内にいたらTRUE
2013 * @return 召喚モンスターが消滅したらTRUE
2015 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
2017 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2018 if ((m_ptr->parent_m_idx == 0) || (target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx > 0))
2023 GAME_TEXT m_name[MAX_NLEN];
2024 monster_desc(target_ptr, m_name, m_ptr, 0);
2025 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
2028 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
2030 GAME_TEXT m_name[MAX_NLEN];
2031 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
2032 exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
2035 delete_monster_idx(target_ptr, m_idx);
2041 * @brief 寝ているモンスターの起床を判定する
2042 * @param target_ptr プレーヤーへの参照ポインタ
2043 * @param m_idx モンスターID
2046 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx)
2048 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2049 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2050 if (!MON_CSLEEP(m_ptr)) return;
2051 if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
2053 (void)set_monster_csleep(target_ptr, m_idx, 0);
2056 GAME_TEXT m_name[MAX_NLEN];
2057 monster_desc(target_ptr, m_name, m_ptr, 0);
2058 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
2061 if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
2069 * @brief モンスターの怒り状態を判定する (起こっていたら敵に回す)
2070 * @param target_ptr プレーヤーへの参照ポインタ
2071 * @param m_idx モンスターID
2072 * @param see_m モンスターが視界内にいたらTRUE
2075 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
2077 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2078 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2079 bool gets_angry = FALSE;
2080 if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
2083 if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
2084 monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
2089 if (target_ptr->phase_out || !gets_angry) return;
2091 if (is_pet(m_ptr) || see_m)
2093 GAME_TEXT m_name[MAX_NLEN];
2094 monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
2095 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
2098 set_hostile(target_ptr, m_ptr);
2103 * @brief 量子生物の量子的効果を実行する
2104 * @param target_ptr プレーヤーへの参照ポインタ
2105 * @param m_idx モンスターID
2106 * @param see_m モンスターが視界内にいたらTRUE
2107 * @return モンスターが量子的効果により消滅したらTRUE
2109 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
2111 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2112 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2113 if ((r_ptr->flags2 & RF2_QUANTUM) == 0) return FALSE;
2114 if (!randint0(2)) return FALSE;
2115 if (randint0((m_idx % 100) + 10)) return FALSE;
2117 bool can_disappear = (r_ptr->flags1 & RF1_UNIQUE) == 0;
2118 can_disappear &= (r_ptr->flags1 & RF1_QUESTOR) == 0;
2121 vanish_nonunique(target_ptr, m_idx, see_m);
2125 produce_quantum_effect(target_ptr, m_idx, see_m);
2131 * @brief ユニークでない量子生物を消滅させる
2132 * @param target_ptr プレーヤーへの参照ポインタ
2133 * @param m_idx モンスターID
2134 * @param see_m モンスターが視界内にいたらTRUE
2137 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
2139 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2142 GAME_TEXT m_name[MAX_NLEN];
2143 monster_desc(target_ptr, m_name, m_ptr, 0);
2144 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
2147 monster_death(target_ptr, m_idx, FALSE);
2148 delete_monster_idx(target_ptr, m_idx);
2149 if (is_pet(m_ptr) && !(m_ptr->ml))
2151 msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
2157 * @brief 量子生物ユニークの量子的効果 (ショート・テレポートまたは距離10のテレポート・アウェイ)を実行する
2158 * @param target_ptr プレーヤーへの参照ポインタ
2159 * @param m_idx モンスターID
2160 * @param see_m モンスターが視界内にいたらTRUE
2163 * プレーヤーが量子生物を観測しているか、量子生物がプレーヤーを観測している場合、互いの相対的な位置を確定させる
2164 * 波動関数の収縮はテレポートではないので反テレポート無効
2165 * todo パターンは収縮どころか拡散しているが、この際気にしてはいけない
2167 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
2169 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2170 bool coherent = los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x);
2171 if (!see_m && !coherent) return;
2175 GAME_TEXT m_name[MAX_NLEN];
2176 monster_desc(target_ptr, m_name, m_ptr, 0);
2177 msg_format(_("%sは量子的効果を起こした!", "%^s produced a decoherence!"), m_name);
2181 msg_print(_("量子的効果が起こった!", "A decoherence was produced!"));
2184 bool target = one_in_(2);
2185 const int blink = 32 * 5 + 4;
2188 (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx);
2193 teleport_player_away(m_idx, target_ptr, 10, TRUE);
2199 * @brief モンスター依存の特別な行動を取らせる
2200 * @param target_ptr プレーヤーへの参照ポインタ
2201 * @param m_idx モンスターID
2203 void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
2205 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2206 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2207 if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
2208 if (m_ptr->r_idx != MON_OHMU) return;
2209 if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
2210 if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
2213 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
2214 BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
2216 for (int k = 0; k < A_MAX; k++)
2218 if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
2220 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
2224 if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
2229 * @brief モンスターを喋らせたり足音を立てたりする
2230 * @param target_ptr プレーヤーへの参照ポインタ
2231 * @param m_idx モンスターID
2232 * @param oy モンスターが元々いたY座標
2233 * @param ox モンスターが元々いたX座標
2234 * @param aware 起きていればTRUE
2237 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware)
2239 if (target_ptr->phase_out) return;
2241 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2242 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2243 if (m_ptr->ap_r_idx == MON_CYBER &&
2244 one_in_(CYBERNOISE) &&
2245 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2247 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
2248 msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
2251 if (((ap_r_ptr->flags2 & RF2_CAN_SPEAK) == 0) || !aware ||
2252 !one_in_(SPEAK_CHANCE) ||
2253 !player_has_los_bold(target_ptr, oy, ox) ||
2254 !projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
2257 GAME_TEXT m_name[MAX_NLEN];
2258 char monmessage[1024];
2262 monster_desc(target_ptr, m_name, m_ptr, 0);
2264 strcpy(m_name, _("それ", "It"));
2266 if (MON_MONFEAR(m_ptr))
2267 filename = _("monfear_j.txt", "monfear.txt");
2268 else if (is_pet(m_ptr))
2269 filename = _("monpet_j.txt", "monpet.txt");
2270 else if (is_friendly(m_ptr))
2271 filename = _("monfrien_j.txt", "monfrien.txt");
2273 filename = _("monspeak_j.txt", "monspeak.txt");
2275 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
2277 msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
2283 * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
2284 * @param target_ptr プレーヤーへの参照ポインタ
2285 * @param m_idx モンスターID
2286 * @param oy 分裂元モンスターのY座標
2287 * @param ox 分裂元モンスターのX座標
2288 * @return 実際に分裂したらTRUEを返す
2290 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
2292 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2293 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2294 if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) || (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
2298 for (POSITION y = oy - 1; y <= oy + 1; y++)
2300 for (POSITION x = ox - 1; x <= ox + 1; x++)
2302 if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
2303 if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
2307 if (multiply_barrier(target_ptr, m_idx)) k = 8;
2309 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
2311 if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
2313 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
2315 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2327 * @brief モンスターの移動パターンを決定する
2328 * @param target_ptr プレーヤーへの参照ポインタ
2330 * @param m_idx モンスターID
2331 * @param aware 起きていればTRUE
2332 * @return 移動先が存在すればTRUE
2334 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware)
2336 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2337 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2339 if (MON_CONFUSED(m_ptr) || !aware)
2341 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2345 if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) && (randint0(100) < 75))
2347 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
2349 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2353 if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 50))
2355 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
2357 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2361 if ((r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 25))
2363 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
2365 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2369 if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2371 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2377 bool avoid = ((target_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
2378 bool lonely = (!avoid && (m_ptr->cdis > target_ptr->pet_follow_distance));
2379 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2380 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2381 if (!get_enemy_dir(target_ptr, m_idx, mm))
2383 if (avoid || lonely || distant)
2385 POSITION dis = target_ptr->pet_follow_distance;
2386 if (target_ptr->pet_follow_distance > PET_SEEK_DIST)
2388 target_ptr->pet_follow_distance = PET_SEEK_DIST;
2391 (void)get_moves(target_ptr, m_idx, mm);
2392 target_ptr->pet_follow_distance = (s16b)dis;
2399 if (!is_hostile(m_ptr))
2401 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2402 get_enemy_dir(target_ptr, m_idx, mm);
2406 if (!get_moves(target_ptr, m_idx, mm)) return FALSE;
2413 * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
2414 * @param target_ptr プレーヤーへの参照ポインタ
2415 * @param m_idx モンスターID
2416 * @param is_riding_mon 騎乗状態ならばTRUE
2417 * @param see_m モンスターが視界内にいたらTRUE
2418 * @return モンスターがフロアから消えたらTRUE
2420 bool runaway_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon, bool see_m)
2422 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2423 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2424 bool can_runaway = is_pet(m_ptr) || is_friendly(m_ptr);
2425 can_runaway &= ((r_ptr->flags1 & RF1_UNIQUE) != 0) || ((r_ptr->flags7 & RF7_NAZGUL) != 0);
2426 can_runaway &= !target_ptr->phase_out;
2427 if (!can_runaway) return FALSE;
2429 static int riding_pinch = 0;
2431 if (m_ptr->hp >= m_ptr->maxhp / 3)
2433 /* Reset the counter */
2434 if (is_riding_mon) riding_pinch = 0;
2439 GAME_TEXT m_name[MAX_NLEN];
2440 monster_desc(target_ptr, m_name, m_ptr, 0);
2441 if (is_riding_mon && riding_pinch < 2)
2443 msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
2444 "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
2446 disturb(target_ptr, TRUE, TRUE);
2452 msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
2453 if (rakuba(target_ptr, -1, FALSE))
2455 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
2461 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) &&
2462 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))
2464 msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
2467 msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s reads a scroll of teleport level."), m_name);
2468 msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
2471 if (is_riding_mon && rakuba(target_ptr, -1, FALSE))
2473 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
2476 check_quest_completion(target_ptr, m_ptr);
2477 delete_monster_idx(target_ptr, m_idx);
2483 * @brief モンスターに魔法を試行させる
2484 * @param target_ptr プレーヤーへの参照ポインタ
2485 * @param m_idx モンスターID
2486 * @param aware 起きていればTRUE
2487 * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
2489 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware)
2491 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2492 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2493 if ((r_ptr->freq_spell == 0) || (randint1(100) > r_ptr->freq_spell))
2496 bool counterattack = FALSE;
2497 if (m_ptr->target_y)
2499 MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
2500 if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
2501 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
2503 counterattack = TRUE;
2509 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
2510 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
2514 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
2515 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
2523 * @brief 全モンスターのターン管理メインルーチン /
2524 * Process all the "live" monsters, once per game turn.
2527 * During each game current game turn, we scan through the list of all the "live" monsters,\n
2528 * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
2529 * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
2531 * Note that monsters can never move in the monster array (except when the\n
2532 * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
2534 * This function is responsible for at least half of the processor time\n
2535 * on a normal system with a "normal" amount of monsters and a player doing\n
2538 * When the player is resting, virtually 90% of the processor time is spent\n
2539 * in this function, and its children, "process_monster()" and "make_move()".\n
2541 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
2542 * especially when the player is running.\n
2544 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
2545 * monsters while they are still being "born". A monster is "fresh" only\n
2546 * during the game turn in which it is created, and we use the "hack_m_idx" to\n
2547 * determine if the monster is yet to be processed during the game turn.\n
2549 * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
2550 * move before any "nasty" monsters get to use their spell attacks.\n
2552 * Note that when the "knowledge" about the currently tracked monster\n
2553 * changes (flags, attacks, spells), we induce a redraw of the monster\n
2556 void process_monsters(player_type *target_ptr)
2558 BIT_FLAGS old_r_flags1 = 0L;
2559 BIT_FLAGS old_r_flags2 = 0L;
2560 BIT_FLAGS old_r_flags3 = 0L;
2561 BIT_FLAGS old_r_flags4 = 0L;
2562 BIT_FLAGS old_r_flags5 = 0L;
2563 BIT_FLAGS old_r_flags6 = 0L;
2564 BIT_FLAGS old_r_flagsr = 0L;
2566 byte old_r_blows0 = 0;
2567 byte old_r_blows1 = 0;
2568 byte old_r_blows2 = 0;
2569 byte old_r_blows3 = 0;
2571 /* Clear monster fighting indicator */
2572 floor_type *floor_ptr = target_ptr->current_floor_ptr;
2573 floor_ptr->monster_noise = FALSE;
2575 /* Memorize old race */
2576 MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
2578 /* Acquire knowledge */
2579 byte old_r_cast_spell = 0;
2580 if (target_ptr->monster_race_idx)
2582 /* Acquire current monster */
2583 monster_race *r_ptr;
2584 r_ptr = &r_info[target_ptr->monster_race_idx];
2586 /* Memorize flags */
2587 old_r_flags1 = r_ptr->r_flags1;
2588 old_r_flags2 = r_ptr->r_flags2;
2589 old_r_flags3 = r_ptr->r_flags3;
2590 old_r_flags4 = r_ptr->r_flags4;
2591 old_r_flags5 = r_ptr->r_flags5;
2592 old_r_flags6 = r_ptr->r_flags6;
2593 old_r_flagsr = r_ptr->r_flagsr;
2595 /* Memorize blows */
2596 old_r_blows0 = r_ptr->r_blows[0];
2597 old_r_blows1 = r_ptr->r_blows[1];
2598 old_r_blows2 = r_ptr->r_blows[2];
2599 old_r_blows3 = r_ptr->r_blows[3];
2601 /* Memorize castings */
2602 old_r_cast_spell = r_ptr->r_cast_spell;
2605 /* Process the monsters (backwards) */
2607 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
2609 monster_type *m_ptr;
2610 monster_race *r_ptr;
2611 m_ptr = &floor_ptr->m_list[i];
2612 r_ptr = &r_info[m_ptr->r_idx];
2614 /* Handle "leaving" */
2615 if (target_ptr->leaving) break;
2617 /* Ignore "dead" monsters */
2618 if (!monster_is_valid(m_ptr)) continue;
2620 if (target_ptr->wild_mode) continue;
2623 /* Handle "fresh" monsters */
2624 if (m_ptr->mflag & MFLAG_BORN)
2626 /* No longer "fresh" */
2627 m_ptr->mflag &= ~(MFLAG_BORN);
2633 /* Hack -- Require proximity */
2634 if (m_ptr->cdis >= AAF_LIMIT) continue;
2636 POSITION fx = m_ptr->fx;
2637 POSITION fy = m_ptr->fy;
2639 /* Flow by smell is allowed */
2640 if (!target_ptr->no_flowed)
2642 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
2645 /* Assume no move */
2648 /* Handle "sensing radius" */
2649 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
2651 /* We can "sense" the player */
2655 /* Handle "sight" and "aggravation" */
2656 else if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
2657 (player_has_los_bold(target_ptr, fy, fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
2659 /* We can "see" or "feel" the player */
2663 else if (m_ptr->target_y) test = TRUE;
2666 if (!test) continue;
2669 if (target_ptr->riding == i)
2670 speed = target_ptr->pspeed;
2673 speed = m_ptr->mspeed;
2675 /* Monsters move quickly in Nightmare mode */
2676 if (ironman_nightmare) speed += 5;
2678 if (MON_FAST(m_ptr)) speed += 10;
2679 if (MON_SLOW(m_ptr)) speed -= 10;
2682 /* Give this monster some energy */
2683 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
2685 /* Not enough energy to move */
2686 if (m_ptr->energy_need > 0) continue;
2688 /* Use up "some" energy */
2689 m_ptr->energy_need += ENERGY_NEED();
2691 /* Save global index */
2694 /* Process the monster */
2695 process_monster(target_ptr, i);
2697 reset_target(m_ptr);
2699 /* Give up flow_by_smell when it might useless */
2700 if (target_ptr->no_flowed && one_in_(3))
2701 m_ptr->mflag2 |= MFLAG2_NOFLOW;
2703 /* Hack -- notice death or departure */
2704 if (!target_ptr->playing || target_ptr->is_dead) break;
2706 /* Notice leaving */
2707 if (target_ptr->leaving) break;
2710 /* Reset global index */
2714 /* Tracking a monster race (the same one we were before) */
2715 if (!target_ptr->monster_race_idx || (target_ptr->monster_race_idx != old_monster_race_idx))
2718 /* Acquire monster race */
2719 monster_race *r_ptr;
2720 r_ptr = &r_info[target_ptr->monster_race_idx];
2722 /* Check for knowledge change */
2723 if ((old_r_flags1 != r_ptr->r_flags1) ||
2724 (old_r_flags2 != r_ptr->r_flags2) ||
2725 (old_r_flags3 != r_ptr->r_flags3) ||
2726 (old_r_flags4 != r_ptr->r_flags4) ||
2727 (old_r_flags5 != r_ptr->r_flags5) ||
2728 (old_r_flags6 != r_ptr->r_flags6) ||
2729 (old_r_flagsr != r_ptr->r_flagsr) ||
2730 (old_r_blows0 != r_ptr->r_blows[0]) ||
2731 (old_r_blows1 != r_ptr->r_blows[1]) ||
2732 (old_r_blows2 != r_ptr->r_blows[2]) ||
2733 (old_r_blows3 != r_ptr->r_blows[3]) ||
2734 (old_r_cast_spell != r_ptr->r_cast_spell))
2736 target_ptr->window |= (PW_MONSTER);