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-summon.h"
27 #include "realm-hex.h"
28 #include "object-flavor.h"
29 #include "object-hook.h"
32 #include "player-move.h"
33 #include "monster-status.h"
34 #include "monster-spell.h"
35 #include "monster-process.h"
36 #include "monsterrace-hook.h"
43 * @brief モンスターが敵に接近するための方向を決める /
44 * Calculate the direction to the next enemy
45 * @param m_idx モンスターの参照ID
46 * @param mm 移動するべき方角IDを返す参照ポインタ
47 * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
49 static bool get_enemy_dir(MONSTER_IDX m_idx, int *mm)
52 POSITION x = 0, y = 0;
57 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
58 monster_race *r_ptr = &r_info[m_ptr->r_idx];
61 if (riding_t_m_idx && player_bold(m_ptr->fy, m_ptr->fx))
63 y = current_floor_ptr->m_list[riding_t_m_idx].fy;
64 x = current_floor_ptr->m_list[riding_t_m_idx].fx;
66 else if (is_pet(m_ptr) && pet_t_m_idx)
68 y = current_floor_ptr->m_list[pet_t_m_idx].fy;
69 x = current_floor_ptr->m_list[pet_t_m_idx].fx;
73 if (p_ptr->inside_battle)
75 start = randint1(current_floor_ptr->m_max-1)+current_floor_ptr->m_max;
76 if(randint0(2)) plus = -1;
78 else start = current_floor_ptr->m_max + 1;
80 /* Scan thru all monsters */
81 for (i = start; ((i < start + current_floor_ptr->m_max) && (i > start - current_floor_ptr->m_max)); i+=plus)
83 MONSTER_IDX dummy = (i % current_floor_ptr->m_max);
88 t_ptr = ¤t_floor_ptr->m_list[t_idx];
90 /* The monster itself isn't a target */
91 if (t_ptr == m_ptr) continue;
93 if (!monster_is_valid(t_ptr)) continue;
97 /* Hack -- only fight away from player */
98 if (p_ptr->pet_follow_distance < 0)
100 /* No fighting near player */
101 if (t_ptr->cdis <= (0 - p_ptr->pet_follow_distance))
106 /* Hack -- no fighting away from player */
107 else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > p_ptr->pet_follow_distance))
112 if (r_ptr->aaf < t_ptr->cdis) continue;
115 /* Monster must be 'an enemy' */
116 if (!are_enemies(m_ptr, t_ptr)) continue;
118 /* Monster must be projectable if we can't pass through walls */
119 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) ||
120 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding)))
122 if (!in_disintegration_range(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
126 if (!projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
129 /* OK -- we've got a target */
135 if (!x && !y) return FALSE;
138 /* Extract the direction */
143 if ((y < 0) && (x == 0))
150 else if ((y > 0) && (x == 0))
157 else if ((x > 0) && (y == 0))
164 else if ((x < 0) && (y == 0))
171 else if ((y < 0) && (x < 0))
178 else if ((y < 0) && (x > 0))
185 else if ((y > 0) && (x < 0))
192 else if ((y > 0) && (x > 0))
199 /* Found a monster */
204 * @brief モンスターがプレイヤーから逃走するかどうかを返す /
205 * Returns whether a given monster will try to run from the player.
206 * @param m_idx 逃走するモンスターの参照ID
207 * @return モンスターがプレイヤーから逃走するならばTRUEを返す。
209 * Monsters will attempt to avoid very powerful players. See below.\n
211 * Because this function is called so often, little details are important\n
212 * for efficiency. Like not using "mod" or "div" when possible. And\n
213 * attempting to check the conditions in an optimal order. Note that\n
214 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
216 * Note that this function is responsible for about one to five percent\n
217 * of the processor use in normal conditions...\n
219 static bool mon_will_run(MONSTER_IDX m_idx)
221 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
225 monster_race *r_ptr = &r_info[m_ptr->r_idx];
229 HIT_POINT p_chp, p_mhp;
230 HIT_POINT m_chp, m_mhp;
235 /* Friends can be commanded to avoid the player */
238 /* Are we trying to avoid the player? */
239 return ((p_ptr->pet_follow_distance < 0) &&
240 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
243 /* Keep monsters from running too far away */
244 if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE);
246 /* All "afraid" monsters will run away */
247 if (MON_MONFEAR(m_ptr)) return (TRUE);
251 /* Nearby monsters will not become terrified */
252 if (m_ptr->cdis <= 5) return (FALSE);
254 /* Examine player power (level) */
257 /* Examine monster power (level plus morale) */
258 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
260 /* Optimize extreme cases below */
261 if (m_lev > p_lev + 4) return (FALSE);
262 if (m_lev + 4 <= p_lev) return (TRUE);
264 /* Examine player health */
268 /* Examine monster health */
270 m_mhp = m_ptr->maxhp;
272 /* Prepare to optimize the calculation */
273 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
274 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
276 /* Strong players scare strong monsters */
277 if (p_val * m_mhp > m_val * p_mhp) return (TRUE);
281 /* Assume no terror */
287 * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
288 * Search spell castable grid
289 * @param m_idx モンスターの参照ID
290 * @param yp 適したマスのY座標を返す参照ポインタ
291 * @param xp 適したマスのX座標を返す参照ポインタ
292 * @return 有効なマスがあった場合TRUEを返す
294 static bool get_moves_aux2(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
297 POSITION y, x, y1, x1;
300 bool can_open_door = FALSE;
303 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
304 monster_race *r_ptr = &r_info[m_ptr->r_idx];
306 /* Monster location */
310 /* Monster can already cast spell to player */
311 if (projectable(y1, x1, p_ptr->y, p_ptr->x)) return (FALSE);
313 /* Set current grid cost */
314 now_cost = current_floor_ptr->grid_array[y1][x1].cost;
315 if (now_cost == 0) now_cost = 999;
317 /* Can monster bash or open doors? */
318 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
320 can_open_door = TRUE;
323 /* Check nearby grids, diagonals first */
324 for (i = 7; i >= 0; i--)
331 /* Ignore locations off of edge */
332 if (!in_bounds2(y, x)) continue;
334 /* Simply move to player */
335 if (player_bold(y, x)) return (FALSE);
337 g_ptr = ¤t_floor_ptr->grid_array[y][x];
341 /* Monster cannot kill or pass walls */
342 if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) || ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding))))
344 if (cost == 0) continue;
345 if (!can_open_door && is_closed_door(g_ptr->feat)) continue;
348 /* Hack -- for kill or pass wall monster.. */
349 if (cost == 0) cost = 998;
351 if (now_cost < cost) continue;
353 if (!projectable(y, x, p_ptr->y, p_ptr->x)) continue;
355 /* Accept louder sounds */
356 if (best < cost) continue;
359 (*yp) = y1 + ddy_ddd[i];
360 (*xp) = x1 + ddx_ddd[i];
363 /* No legal move (?) */
364 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(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
402 POSITION y, x, y1, x1;
405 bool use_scent = FALSE;
407 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
408 monster_race *r_ptr = &r_info[m_ptr->r_idx];
410 /* Can monster cast attack spell? */
411 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
412 r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
413 r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
415 /* Can move spell castable grid? */
416 if (get_moves_aux2(m_idx, yp, xp)) return (TRUE);
419 /* Monster can't flow */
420 if (no_flow) return (FALSE);
422 /* Monster can go through rocks */
423 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) return (FALSE);
424 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding)) return (FALSE);
426 /* Monster location */
430 /* Hack -- Player can see us, run towards him */
431 if (player_has_los_bold(y1, x1) && projectable(p_ptr->y, p_ptr->x, y1, x1)) return (FALSE);
434 g_ptr = ¤t_floor_ptr->grid_array[y1][x1];
436 /* If we can hear noises, advance towards them */
442 /* Otherwise, try to follow a scent trail */
443 else if (g_ptr->when)
446 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].when - g_ptr->when > 127) return (FALSE);
452 /* Otherwise, advance blindly */
458 /* Check nearby grids, diagonals first */
459 for (i = 7; i >= 0; i--)
464 /* Ignore locations off of edge */
465 if (!in_bounds2(y, x)) continue;
467 g_ptr = ¤t_floor_ptr->grid_array[y][x];
469 /* We're following a scent trail */
472 int when = g_ptr->when;
474 /* Accept younger scent */
475 if (best > when) continue;
479 /* We're using sound */
484 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
486 else cost = g_ptr->cost;
488 /* Accept louder sounds */
489 if ((cost == 0) || (best < cost)) continue;
493 /* Hack -- Save the "twiddled" location */
494 (*yp) = p_ptr->y + 16 * ddy_ddd[i];
495 (*xp) = p_ptr->x + 16 * ddx_ddd[i];
498 /* No legal move (?) */
499 if (best == 999 || best == 0) return (FALSE);
507 * @brief モンスターがプレイヤーから逃走することが可能なマスを走査する /
508 * Provide a location to flee to, but give the player a wide berth.
509 * @param m_idx モンスターの参照ID
510 * @param yp 移動先のマスのY座標を返す参照ポインタ
511 * @param xp 移動先のマスのX座標を返す参照ポインタ
512 * @return 有効なマスがあった場合TRUEを返す
514 * A monster may wish to flee to a location that is behind the player,\n
515 * but instead of heading directly for it, the monster should "swerve"\n
516 * around the player so that he has a smaller chance of getting hit.\n
518 static bool get_fear_moves_aux(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
520 POSITION y, x, y1, x1, fy, fx, gy = 0, gx = 0;
524 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
526 /* Monster location */
530 /* Desired destination */
534 /* Check nearby grids, diagonals first */
535 for (i = 7; i >= 0; i--)
542 /* Ignore locations off of edge */
543 if (!in_bounds2(y, x)) continue;
545 /* Don't move toward player */
546 /* if (current_floor_ptr->grid_array[y][x].dist < 3) continue; */ /* Hmm.. Need it? */
548 /* Calculate distance of this grid from our destination */
549 dis = distance(y, x, y1, x1);
551 /* Score this grid */
552 s = 5000 / (dis + 3) - 500 / (current_floor_ptr->grid_array[y][x].dist + 1);
554 /* No negative scores */
557 /* Ignore lower scores */
558 if (s < score) continue;
560 /* Save the score and time */
563 /* Save the location */
568 /* No legal move (?) */
569 if (score == -1) return (FALSE);
580 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
583 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
584 * offsets of all the locations with a distance of n from a central point,
585 * with an offset of (0,0) indicating no more offsets at this distance.
587 * This is, of course, fairly unreadable, but it eliminates multiple loops
588 * from the previous version.
590 * It is probably better to replace these arrays with code to compute
591 * the relevant arrays, even if the storage is pre-allocated in hard
592 * coded sizes. At the very least, code should be included which is
593 * able to generate and dump these arrays (ala "los()").
595 * Also, the storage needs could be halved by using bytes.
597 * These arrays could be combined into two big arrays, using sub-arrays
598 * to hold the offsets and lengths of each portion of the sub-arrays, and
599 * this could perhaps also be used somehow in the "look" code.
603 static POSITION d_off_y_0[] = { 0 };
604 static POSITION d_off_x_0[] = { 0 };
606 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
607 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
609 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
610 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
612 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
613 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
615 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 };
616 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 };
619 static POSITION d_off_y_5[] =
620 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
621 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
624 static POSITION d_off_x_5[] =
625 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
626 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
630 static POSITION d_off_y_6[] =
631 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
632 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
635 static POSITION d_off_x_6[] =
636 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
637 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
638 -3, 2, 3, -1, 0, 1, 0 };
641 static POSITION d_off_y_7[] =
642 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
643 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
644 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
646 static POSITION d_off_x_7[] =
647 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
648 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
649 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
653 static POSITION d_off_y_8[] =
654 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
655 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
656 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
659 static POSITION d_off_x_8[] =
660 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
661 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
662 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
666 static POSITION d_off_y_9[] =
667 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
668 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
669 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
670 7, 8, 8, 8, 8, 9, 9, 9, 0 };
672 static POSITION d_off_x_9[] =
673 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
674 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
675 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
676 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
679 static POSITION *dist_offsets_y[10] =
681 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
682 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
685 static POSITION *dist_offsets_x[10] =
687 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
688 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
692 * @brief モンスターが逃げ込める安全な地点を返す /
693 * Choose a "safe" location near a monster for it to run toward.
694 * @param m_idx モンスターの参照ID
695 * @param yp 移動先のマスのY座標を返す参照ポインタ
696 * @param xp 移動先のマスのX座標を返す参照ポインタ
697 * @return 有効なマスがあった場合TRUEを返す
699 * A location is "safe" if it can be reached quickly and the player\n
700 * is not able to fire into it (it isn't a "clean shot"). So, this will\n
701 * cause monsters to "duck" behind walls. Hopefully, monsters will also\n
702 * try to run towards corridor openings if they are in a room.\n
704 * This function may take lots of CPU time if lots of monsters are\n
707 * Return TRUE if a safe location is available.\n
709 static bool find_safety(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
711 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
713 POSITION fy = m_ptr->fy;
714 POSITION fx = m_ptr->fx;
716 POSITION y, x, dy, dx, d, dis, i;
717 POSITION gy = 0, gx = 0, gdis = 0;
724 /* Start with adjacent locations, spread further */
725 for (d = 1; d < 10; d++)
727 /* Get the lists of points with a distance d from (fx, fy) */
728 y_offsets = dist_offsets_y[d];
729 x_offsets = dist_offsets_x[d];
731 /* Check the locations */
732 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
734 i++, dx = x_offsets[i], dy = y_offsets[i])
739 /* Skip illegal locations */
740 if (!in_bounds(y, x)) continue;
742 g_ptr = ¤t_floor_ptr->grid_array[y][x];
744 /* Skip locations in a wall */
745 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], (m_idx == p_ptr->riding) ? CEM_RIDING : 0)) continue;
747 /* Check for "availability" (if monsters can flow) */
748 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
750 /* Ignore grids very far from the player */
751 if (g_ptr->dist == 0) continue;
753 /* Ignore too-distant grids */
754 if (g_ptr->dist > current_floor_ptr->grid_array[fy][fx].dist + 2 * d) continue;
757 /* Check for absence of shot (more or less) */
758 if (!projectable(p_ptr->y, p_ptr->x, y, x))
760 /* Calculate distance from player */
761 dis = distance(y, x, p_ptr->y, p_ptr->x);
763 /* Remember if further than previous */
773 /* Check for success */
780 /* Found safe place */
791 * @brief モンスターが隠れ潜める地点を返す /
792 * Choose a good hiding place near a monster for it to run toward.
793 * @param m_idx モンスターの参照ID
794 * @param yp 移動先のマスのY座標を返す参照ポインタ
795 * @param xp 移動先のマスのX座標を返す参照ポインタ
796 * @return 有効なマスがあった場合TRUEを返す
798 * Pack monsters will use this to "ambush" the player and lure him out\n
799 * of corridors into open space so they can swarm him.\n
801 * Return TRUE if a good location is available.\n
803 static bool find_hiding(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
805 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
806 monster_race *r_ptr = &r_info[m_ptr->r_idx];
808 POSITION fy = m_ptr->fy;
809 POSITION fx = m_ptr->fx;
811 POSITION y, x, dy, dx, d, dis, i;
812 POSITION gy = 0, gx = 0, gdis = 999;
814 POSITION *y_offsets, *x_offsets;
816 /* Start with adjacent locations, spread further */
817 for (d = 1; d < 10; d++)
819 /* Get the lists of points with a distance d from (fx, fy) */
820 y_offsets = dist_offsets_y[d];
821 x_offsets = dist_offsets_x[d];
823 /* Check the locations */
824 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
826 i++, dx = x_offsets[i], dy = y_offsets[i])
831 /* Skip illegal locations */
832 if (!in_bounds(y, x)) continue;
834 /* Skip occupied locations */
835 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
837 /* Check for hidden, available grid */
838 if (!projectable(p_ptr->y, p_ptr->x, y, x) && clean_shot(fy, fx, y, x, FALSE))
840 /* Calculate distance from player */
841 dis = distance(y, x, p_ptr->y, p_ptr->x);
843 /* Remember if closer than previous */
844 if (dis < gdis && dis >= 2)
853 /* Check for success */
860 /* Found good place */
871 * @brief モンスターの移動方向を返す /
872 * Choose "logical" directions for monster movement
873 * @param m_idx モンスターの参照ID
874 * @param mm 移動方向を返す方向IDの参照ポインタ
875 * @return 有効方向があった場合TRUEを返す
877 static bool get_moves(MONSTER_IDX m_idx, DIRECTION *mm)
879 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
880 monster_race *r_ptr = &r_info[m_ptr->r_idx];
881 POSITION y = 0, ay, x = 0, ax;
883 POSITION y2 = p_ptr->y;
884 POSITION x2 = p_ptr->x;
886 bool will_run = mon_will_run(m_idx);
888 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2));
889 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall));
891 /* Counter attack to an enemy monster */
892 if (!will_run && m_ptr->target_y)
894 int t_m_idx = current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
896 /* The monster must be an enemy, and in LOS */
898 are_enemies(m_ptr, ¤t_floor_ptr->m_list[t_m_idx]) &&
899 los(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
900 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
902 /* Extract the "pseudo-direction" */
903 y = m_ptr->fy - m_ptr->target_y;
904 x = m_ptr->fx - m_ptr->target_x;
909 if (!done && !will_run && is_hostile(m_ptr) &&
910 (r_ptr->flags1 & RF1_FRIENDS) &&
911 ((los(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x) && projectable(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x)) ||
912 (current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
915 * Animal packs try to get the player out of corridors
916 * (...unless they can move through walls -- TY)
918 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
919 !(r_ptr->flags2 & RF2_KILL_WALL))
923 /* Count room grids next to player */
924 for (i = 0; i < 8; i++)
926 int xx = p_ptr->x + ddx_ddd[i];
927 int yy = p_ptr->y + ddy_ddd[i];
929 if (!in_bounds2(yy, xx)) continue;
931 g_ptr = ¤t_floor_ptr->grid_array[yy][xx];
934 if (monster_can_cross_terrain(g_ptr->feat, r_ptr, 0))
936 /* One more room grid */
940 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_ROOM) room -= 2;
941 if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
943 /* Not in a room and strong player */
944 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
945 (p_ptr->mhp + p_ptr->msp))
947 /* Find hiding place */
948 if (find_hiding(m_idx, &y, &x)) done = TRUE;
952 /* Monster groups try to surround the player */
953 if (!done && (current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
957 /* Find an empty square near the player to fill */
958 for (i = 0; i < 8; i++)
960 /* Pick squares near player (semi-randomly) */
961 y2 = p_ptr->y + ddy_ddd[(m_idx + i) & 7];
962 x2 = p_ptr->x + ddx_ddd[(m_idx + i) & 7];
965 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
967 /* Attack the player */
974 if (!in_bounds2(y2, x2)) continue;
976 /* Ignore filled grids */
977 if (!monster_can_enter(y2, x2, r_ptr, 0)) continue;
979 /* Try to fill this hole */
983 /* Extract the new "pseudo-direction" */
993 /* Flow towards the player */
994 (void)get_moves_aux(m_idx, &y2, &x2, no_flow);
996 /* Extract the "pseudo-direction" */
1003 /* Apply fear if possible and necessary */
1004 if (is_pet(m_ptr) && will_run)
1006 /* XXX XXX Not very "smart" */
1011 if (!done && will_run)
1016 /* Try to find safe place */
1017 if (find_safety(m_idx, &y, &x))
1019 /* Attempt to avoid the player */
1022 /* Adjust movement */
1023 if (get_fear_moves_aux(m_idx, &y, &x)) done = TRUE;
1029 /* This is not a very "smart" method XXX XXX */
1037 /* Check for no move */
1038 if (!x && !y) return (FALSE);
1041 /* Extract the "absolute distances" */
1045 /* Do something weird */
1046 if (y < 0) move_val += 8;
1047 if (x > 0) move_val += 4;
1049 /* Prevent the diamond maneuvre */
1050 if (ay > (ax << 1)) move_val += 2;
1051 else if (ax > (ay << 1)) move_val++;
1053 /* Extract some directions */
1198 /* Wants to move... */
1204 * @brief モンスターから敵モンスターへの命中判定
1205 * @param power 打撃属性による基本命中値
1206 * @param level 攻撃側モンスターのレベル
1207 * @param ac 目標モンスターのAC
1208 * @param stun 攻撃側モンスターが朦朧状態ならTRUEを返す
1209 * @return 命中ならばTRUEを返す
1211 static int check_hit2(int power, DEPTH level, ARMOUR_CLASS ac, int stun)
1215 /* Percentile dice */
1218 if (stun && one_in_(2)) return FALSE;
1220 /* Hack -- Always miss or hit */
1221 if (k < 10) return (k < 5);
1223 /* Calculate the "attack quality" */
1224 i = (power + (level * 3));
1226 /* Power and Level compete against Armor */
1227 if ((i > 0) && (randint1(i) > ((ac * 3) / 4))) return (TRUE);
1234 #define BLOW_EFFECT_TYPE_NONE 0
1235 #define BLOW_EFFECT_TYPE_FEAR 1
1236 #define BLOW_EFFECT_TYPE_SLEEP 2
1237 #define BLOW_EFFECT_TYPE_HEAL 3
1241 * @brief モンスターから敵モンスターへの打撃攻撃処理
1242 * @param m_idx 攻撃側モンスターの参照ID
1243 * @param t_idx 目標側モンスターの参照ID
1244 * @return 実際に打撃処理が行われた場合TRUEを返す
1246 static bool monst_attack_monst(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
1248 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1249 monster_type *t_ptr = ¤t_floor_ptr->m_list[t_idx];
1251 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1252 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1254 ARMOUR_CLASS ap_cnt;
1258 GAME_TEXT m_name[MAX_NLEN], t_name[MAX_NLEN];
1259 char temp[MAX_NLEN];
1261 bool explode = FALSE, touched = FALSE, fear = FALSE, dead = FALSE;
1262 POSITION y_saver = t_ptr->fy;
1263 POSITION x_saver = t_ptr->fx;
1266 bool see_m = is_seen(m_ptr);
1267 bool see_t = is_seen(t_ptr);
1268 bool see_either = see_m || see_t;
1270 /* Can the player be aware of this attack? */
1271 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1272 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1274 /* Cannot attack self */
1275 if (m_idx == t_idx) return FALSE;
1277 /* Not allowed to attack */
1278 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1280 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) return (FALSE);
1285 /* Extract the effective monster level */
1286 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1288 monster_desc(m_name, m_ptr, 0);
1289 monster_desc(t_name, t_ptr, 0);
1291 /* Assume no blink */
1294 if (!see_either && known)
1296 current_floor_ptr->monster_noise = TRUE;
1299 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(TRUE, TRUE);
1301 /* Scan through all four blows */
1302 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1304 bool obvious = FALSE;
1306 HIT_POINT power = 0;
1307 HIT_POINT damage = 0;
1311 /* Extract the attack infomation */
1312 int effect = r_ptr->blow[ap_cnt].effect;
1313 int method = r_ptr->blow[ap_cnt].method;
1314 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1315 int d_side = r_ptr->blow[ap_cnt].d_side;
1317 if (!monster_is_valid(m_ptr)) break;
1319 /* Stop attacking if the target dies! */
1320 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1323 /* Hack -- no more attacks */
1326 if (method == RBM_SHOOT) continue;
1328 /* Extract the attack "power" */
1329 power = mbe_info[effect].power;
1332 if (!effect || check_hit2(power, rlev, ac, MON_STUNNED(m_ptr)))
1334 (void)set_monster_csleep(t_idx, 0);
1338 /* Redraw the health bar */
1339 if (p_ptr->health_who == t_idx) p_ptr->redraw |= (PR_HEALTH);
1340 if (p_ptr->riding == t_idx) p_ptr->redraw |= (PR_UHEALTH);
1343 /* Describe the attack method */
1348 act = _("%sを殴った。", "hits %s.");
1355 act = _("%sを触った。", "touches %s.");
1362 act = _("%sをパンチした。", "punches %s.");
1369 act = _("%sを蹴った。", "kicks %s.");
1376 act = _("%sをひっかいた。", "claws %s.");
1383 act = _("%sを噛んだ。", "bites %s.");
1390 act = _("%sを刺した。", "stings %s.");
1397 act = _("%sを斬った。", "slashes %s.");
1403 act = _("%sを角で突いた。", "butts %s.");
1410 act = _("%sに体当りした。", "crushes %s.");
1417 act = _("%sを飲み込んだ。", "engulfs %s.");
1424 act = _("%sに請求書をよこした。", "charges %s.");
1431 act = _("%sの体の上を這い回った。", "crawls on %s.");
1438 act = _("%sによだれをたらした。", "drools on %s.");
1445 act = _("%sに唾を吐いた。", "spits on %s.");
1452 if (see_either) disturb(TRUE, TRUE);
1453 act = _("爆発した。", "explodes.");
1461 act = _("%sをにらんだ。", "gazes at %s.");
1468 act = _("%sに泣きついた。", "wails at %s.");
1475 act = _("%sに胞子を飛ばした。", "releases spores at %s.");
1482 act = _("%sにXXX4を飛ばした。", "projects XXX4's at %s.");
1489 act = _("%sに金をせがんだ。", "begs %s for money.");
1496 act = _("%sを侮辱した。", "insults %s.");
1503 act = _("%sにむかってうめいた。", "moans at %s.");
1510 act = _("%sにむかって歌った。", "sings to %s.");
1516 if (act && see_either)
1519 if (do_silly_attack) act = silly_attacks2[randint0(MAX_SILLY_ATTACK)];
1520 strfmt(temp, act, t_name);
1521 msg_format("%^sは%s", m_name, temp);
1523 if (do_silly_attack)
1525 act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
1526 strfmt(temp, "%s %s.", act, t_name);
1528 else strfmt(temp, act, t_name);
1529 msg_format("%^s %s", m_name, temp);
1533 /* Hack -- assume all attacks are obvious */
1536 /* Roll out the damage */
1537 damage = damroll(d_dice, d_side);
1539 /* Assume no effect */
1540 effect_type = BLOW_EFFECT_TYPE_NONE;
1544 /* Apply appropriate damage */
1553 if ((randint1(rlev*2+250) > (ac+200)) || one_in_(13))
1555 int tmp_damage = damage - (damage * ((ac < 150) ? ac : 150) / 250);
1556 damage = MAX(damage, tmp_damage * 2);
1563 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1578 if ((p_ptr->riding != m_idx) && one_in_(2)) blinked = TRUE;
1614 effect_type = BLOW_EFFECT_TYPE_FEAR;
1618 effect_type = BLOW_EFFECT_TYPE_SLEEP;
1622 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1623 if (damage > 23) earthquake_aux(m_ptr->fy, m_ptr->fx, 8, m_idx);
1638 pt = GF_HYPODYNAMIA;
1639 effect_type = BLOW_EFFECT_TYPE_HEAL;
1657 /* Do damage if not exploding */
1660 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1661 damage, pt, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1664 switch (effect_type)
1666 case BLOW_EFFECT_TYPE_FEAR:
1667 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1668 damage, GF_TURN_ALL, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1671 case BLOW_EFFECT_TYPE_SLEEP:
1672 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1673 r_ptr->level, GF_OLD_SLEEP, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1676 case BLOW_EFFECT_TYPE_HEAL:
1677 if ((monster_living(m_idx)) && (damage > 2))
1679 bool did_heal = FALSE;
1681 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
1684 m_ptr->hp += damroll(4, damage / 6);
1685 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
1687 /* Redraw (later) if needed */
1688 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1689 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1691 /* Special message */
1692 if (see_m && did_heal)
1694 msg_format(_("%sは体力を回復したようだ。", "%^s appears healthier."), m_name);
1703 if ((tr_ptr->flags2 & RF2_AURA_FIRE) && m_ptr->r_idx)
1705 if (!(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
1709 msg_format(_("%^sは突然熱くなった!", "%^s is suddenly very hot!"), m_name);
1711 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_FIRE;
1712 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
1713 damroll (1 + ((tr_ptr->level) / 26),
1714 1 + ((tr_ptr->level) / 17)),
1715 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1719 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
1724 if ((tr_ptr->flags3 & RF3_AURA_COLD) && m_ptr->r_idx)
1726 if (!(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK))
1730 msg_format(_("%^sは突然寒くなった!", "%^s is suddenly very cold!"), m_name);
1732 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags3 |= RF3_AURA_COLD;
1733 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
1734 damroll (1 + ((tr_ptr->level) / 26),
1735 1 + ((tr_ptr->level) / 17)),
1736 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1740 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
1745 if ((tr_ptr->flags2 & RF2_AURA_ELEC) && m_ptr->r_idx)
1747 if (!(r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK))
1751 msg_format(_("%^sは電撃を食らった!", "%^s gets zapped!"), m_name);
1753 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_ELEC;
1754 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
1755 damroll (1 + ((tr_ptr->level) / 26),
1756 1 + ((tr_ptr->level) / 17)),
1757 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1761 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
1768 /* Monster missed player */
1771 /* Analyze failed attacks */
1787 (void)set_monster_csleep(t_idx, 0);
1789 /* Visible monsters */
1793 msg_format("%sは%^sの攻撃をかわした。", t_name, m_name);
1795 msg_format("%^s misses %s.", m_name, t_name);
1805 /* Analyze "visible" monsters only */
1806 if (is_original_ap_and_seen(m_ptr) && !do_silly_attack)
1808 /* Count "obvious" attacks (and ones that cause damage) */
1809 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
1811 /* Count attacks of this type */
1812 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
1814 r_ptr->r_blows[ap_cnt]++;
1822 sound(SOUND_EXPLODE);
1824 /* Cancel Invulnerability */
1825 (void)set_monster_invulner(m_idx, 0, FALSE);
1826 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
1831 if (blinked && m_ptr->r_idx)
1833 if (teleport_barrier(m_idx))
1837 msg_print(_("泥棒は笑って逃げ...ようとしたがバリアに防がれた。", "The thief flees laughing...? But magic barrier obstructs it."));
1841 current_floor_ptr->monster_noise = TRUE;
1848 msg_print(_("泥棒は笑って逃げた!", "The thief flees laughing!"));
1852 current_floor_ptr->monster_noise = TRUE;
1855 teleport_away(m_idx, MAX_SIGHT * 2 + 5, 0L);
1863 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
1865 return !have_flag(f_ptr->flags, FF_GLASS) ||
1866 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
1867 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
1872 * @brief モンスター単体の1ターン行動処理メインルーチン /
1874 * @param m_idx 行動モンスターの参照ID
1877 * The monster is known to be within 100 grids of the player\n
1879 * In several cases, we directly update the monster lore\n
1881 * Note that a monster is only allowed to "reproduce" if there\n
1882 * are a limited number of "reproducing" monsters on the current\n
1883 * level. This should prevent the level from being "swamped" by\n
1884 * reproducing monsters. It also allows a large mass of mice to\n
1885 * prevent a louse from multiplying, but this is a small price to\n
1886 * pay for a simple multiplication method.\n
1888 * XXX Monster fear is slightly odd, in particular, monsters will\n
1889 * fixate on opening a door even if they cannot open it. Actually,\n
1890 * the same thing happens to normal monsters when they hit a door\n
1892 * In addition, monsters which *cannot* open or bash\n
1893 * down a door will still stand there trying to open it...\n
1895 * XXX Technically, need to check for monster in the way\n
1896 * combined with that monster being in a wall (or door?)\n
1898 * A "direction" of "5" means "pick a random direction".\n
1900 void process_monster(MONSTER_IDX m_idx)
1902 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1903 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1904 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1907 POSITION oy, ox, ny, nx;
1912 feature_type *f_ptr;
1914 monster_type *y_ptr;
1919 bool must_alter_to_move;
1928 bool gets_angry = FALSE;
1933 bool is_riding_mon = (m_idx == p_ptr->riding);
1934 bool see_m = is_seen(m_ptr);
1936 if (is_riding_mon && !(r_ptr->flags7 & RF7_RIDING))
1938 if (rakuba(0, TRUE))
1941 msg_print("地面に落とされた。");
1943 GAME_TEXT m_name[MAX_NLEN];
1944 monster_desc(m_name, ¤t_floor_ptr->m_list[p_ptr->riding], 0);
1945 msg_format("You have fallen from %s.", m_name);
1950 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
1952 choose_new_monster(m_idx, FALSE, 0);
1953 r_ptr = &r_info[m_ptr->r_idx];
1956 /* Players hidden in shadow are almost imperceptable. -LM- */
1957 if (p_ptr->special_defense & NINJA_S_STEALTH)
1959 int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
1960 if (p_ptr->monlite) tmp /= 3;
1961 if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1962 if (r_ptr->level > (p_ptr->lev * p_ptr->lev / 20 + 10)) tmp /= 3;
1963 /* Low-level monsters will find it difficult to locate the player. */
1964 if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
1967 /* Are there its parent? */
1968 if (m_ptr->parent_m_idx && !current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx)
1970 /* Its parent have gone, it also goes away. */
1974 GAME_TEXT m_name[MAX_NLEN];
1975 monster_desc(m_name, m_ptr, 0);
1976 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1979 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1981 GAME_TEXT m_name[MAX_NLEN];
1982 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1983 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
1986 delete_monster_idx(m_idx);
1991 /* Quantum monsters are odd */
1992 if (r_ptr->flags2 & (RF2_QUANTUM))
1994 /* Sometimes skip move */
1995 if (!randint0(2)) return;
1998 if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2002 if (is_pet(m_ptr) && !(m_ptr->ml)) sad = TRUE;
2006 GAME_TEXT m_name[MAX_NLEN];
2007 monster_desc(m_name, m_ptr, 0);
2009 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
2012 /* Generate treasure, etc */
2013 monster_death(m_idx, FALSE);
2015 delete_monster_idx(m_idx);
2018 msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
2025 if (m_ptr->r_idx == MON_SHURYUUDAN)
2027 mon_take_hit_mon(m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
2031 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) && !p_ptr->inside_battle)
2033 static int riding_pinch = 0;
2035 if (m_ptr->hp < m_ptr->maxhp/3)
2037 GAME_TEXT m_name[MAX_NLEN];
2038 monster_desc(m_name, m_ptr, 0);
2040 if (is_riding_mon && riding_pinch < 2)
2042 msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
2043 "%^s seems to be in so much pain, and trying to escape from your restriction."), m_name);
2045 disturb(TRUE, TRUE);
2051 msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
2052 if (rakuba(-1, FALSE))
2054 msg_print(_("地面に落とされた。", "You have fallen from riding pet."));
2060 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) &&
2061 player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x))
2063 msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
2065 msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s read a scroll of teleport level."), m_name);
2066 msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
2069 if (is_riding_mon && rakuba(-1, FALSE))
2071 msg_print(_("地面に落とされた。", "You have fallen from riding pet."));
2074 check_quest_completion(m_ptr);
2075 delete_monster_idx(m_idx);
2081 /* Reset the counter */
2082 if (is_riding_mon) riding_pinch = 0;
2086 /* Handle "sleep" */
2087 if (MON_CSLEEP(m_ptr))
2089 /* Handle non-aggravation - Still sleeping */
2090 if (!(p_ptr->cursed & TRC_AGGRAVATE)) return;
2092 (void)set_monster_csleep(m_idx, 0);
2094 /* Notice the "waking up" */
2097 GAME_TEXT m_name[MAX_NLEN];
2098 monster_desc(m_name, m_ptr, 0);
2099 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
2102 /* Hack -- Count the wakings */
2103 if (is_original_ap_and_seen(m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
2110 if (MON_STUNNED(m_ptr))
2112 /* Sometimes skip move */
2113 if (one_in_(2)) return;
2118 p_ptr->update |= (PU_BONUS);
2121 /* No one wants to be your friend if you're aggravating */
2122 if (is_friendly(m_ptr) && (p_ptr->cursed & TRC_AGGRAVATE))
2125 /* Paranoia... no pet uniques outside wizard mode -- TY */
2126 if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
2127 monster_has_hostile_align(NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
2132 if (p_ptr->inside_battle) gets_angry = FALSE;
2136 if (is_pet(m_ptr) || see_m)
2138 GAME_TEXT m_name[MAX_NLEN];
2139 monster_desc(m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
2140 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
2146 /* Get the origin */
2150 /* Attempt to "multiply" if able and allowed */
2151 if ((r_ptr->flags2 & RF2_MULTIPLY) && (current_floor_ptr->num_repro < MAX_REPRO))
2156 /* Count the adjacent monsters */
2157 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2159 for (x = ox - 1; x <= ox + 1; x++)
2161 /* Ignore locations off of edge */
2162 if (!in_bounds2(y, x)) continue;
2163 if (current_floor_ptr->grid_array[y][x].m_idx) k++;
2168 if (multiply_barrier(m_idx)) k = 8;
2170 /* Hack -- multiply slower in crowded areas */
2171 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
2173 /* Try to multiply */
2174 if (multiply_monster(m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
2176 /* Take note if visible */
2177 if (current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(m_ptr))
2179 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2182 /* Multiplying takes energy */
2188 if (r_ptr->a_ability_flags2 & RF6_SPECIAL)
2190 /* Hack -- Ohmu scatters molds! */
2191 if (m_ptr->r_idx == MON_OHMU)
2193 if (!p_ptr->inside_arena && !p_ptr->inside_battle)
2195 if (r_ptr->freq_spell && (randint1(100) <= r_ptr->freq_spell))
2198 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
2199 BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
2201 for (k = 0; k < A_MAX; k++)
2203 if (summon_specific(m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
2205 if (current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
2209 if (count && is_original_ap_and_seen(m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
2215 if (!p_ptr->inside_battle)
2217 /* Hack! "Cyber" monster makes noise... */
2218 if (m_ptr->ap_r_idx == MON_CYBER &&
2219 one_in_(CYBERNOISE) &&
2220 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2222 if (disturb_minor) disturb(FALSE, FALSE);
2223 msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
2226 /* Some monsters can speak */
2227 if ((ap_r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2228 one_in_(SPEAK_CHANCE) &&
2229 player_has_los_bold(oy, ox) &&
2230 projectable(oy, ox, p_ptr->y, p_ptr->x))
2232 GAME_TEXT m_name[MAX_NLEN];
2233 char monmessage[1024];
2236 /* Acquire the monster name/poss */
2238 monster_desc(m_name, m_ptr, 0);
2240 strcpy(m_name, _("それ", "It"));
2242 /* Select the file for monster quotes */
2243 if (MON_MONFEAR(m_ptr))
2244 filename = _("monfear_j.txt", "monfear.txt");
2245 else if (is_pet(m_ptr))
2246 filename = _("monpet_j.txt", "monpet.txt");
2247 else if (is_friendly(m_ptr))
2248 filename = _("monfrien_j.txt", "monfrien.txt");
2250 filename = _("monspeak_j.txt", "monspeak.txt");
2251 /* Get the monster line */
2252 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
2255 msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
2260 /* Try to cast spell occasionally */
2261 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
2263 bool counterattack = FALSE;
2265 /* Give priority to counter attack? */
2266 if (m_ptr->target_y)
2268 MONSTER_IDX t_m_idx = current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
2270 /* The monster must be an enemy, and projectable */
2271 if (t_m_idx && are_enemies(m_ptr, ¤t_floor_ptr->m_list[t_m_idx]) &&
2272 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
2274 counterattack = TRUE;
2280 /* Attempt to cast a spell */
2281 if (aware && make_attack_spell(m_idx)) return;
2284 * Attempt to cast a spell at an enemy other than the player
2285 * (may slow the game a smidgeon, but I haven't noticed.)
2287 if (monst_spell_monst(m_idx)) return;
2291 /* Attempt to do counter attack at first */
2292 if (monst_spell_monst(m_idx)) return;
2294 if (aware && make_attack_spell(m_idx)) return;
2298 /* Hack -- Assume no movement */
2299 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2300 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2303 /* Confused -- 100% random */
2304 if (MON_CONFUSED(m_ptr) || !aware)
2306 /* Try four "random" directions */
2307 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2310 /* 75% random movement */
2311 else if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) &&
2312 (randint0(100) < 75))
2314 /* Memorize flags */
2315 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
2317 /* Try four "random" directions */
2318 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2321 /* 50% random movement */
2322 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2323 (randint0(100) < 50))
2325 /* Memorize flags */
2326 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
2328 /* Try four "random" directions */
2329 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2332 /* 25% random movement */
2333 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2334 (randint0(100) < 25))
2336 /* Memorize flags */
2337 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
2339 /* Try four "random" directions */
2340 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2343 /* Can't reach player - find something else to hit */
2344 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2346 /* Try four "random" directions */
2347 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2349 /* Look for an enemy */
2350 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2351 get_enemy_dir(m_idx, mm);
2355 /* Pets will follow the player */
2356 else if (is_pet(m_ptr))
2358 /* Are we trying to avoid the player? */
2359 bool avoid = ((p_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2361 /* Do we want to find the player? */
2362 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
2364 /* Should we find the player if we can't find a monster? */
2365 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2367 /* by default, move randomly */
2368 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2370 /* Look for an enemy */
2371 if (!get_enemy_dir(m_idx, mm))
2373 /* Find the player if necessary */
2374 if (avoid || lonely || distant)
2376 /* Remember the leash length */
2377 POSITION dis = p_ptr->pet_follow_distance;
2379 /* Hack -- adjust follow distance temporarily */
2380 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
2382 p_ptr->pet_follow_distance = PET_SEEK_DIST;
2385 /* Find the player */
2386 (void)get_moves(m_idx, mm);
2388 /* Restore the leash */
2389 p_ptr->pet_follow_distance = (s16b)dis;
2394 /* Friendly monster movement */
2395 else if (!is_hostile(m_ptr))
2397 /* by default, move randomly */
2398 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2400 /* Look for an enemy */
2401 get_enemy_dir(m_idx, mm);
2403 /* Normal movement */
2406 /* Logical moves, may do nothing */
2407 if (!get_moves(m_idx, mm)) return;
2410 /* Assume nothing */
2414 must_alter_to_move = FALSE;
2416 /* Assume nothing */
2417 did_open_door = FALSE;
2418 did_bash_door = FALSE;
2419 did_take_item = FALSE;
2420 did_kill_item = FALSE;
2421 did_move_body = FALSE;
2422 did_pass_wall = FALSE;
2423 did_kill_wall = FALSE;
2425 /* Take a zero-terminated array of "directions" */
2426 for (i = 0; mm[i]; i++)
2428 /* Get the direction */
2431 /* Hack -- allow "randomized" motion */
2432 if (d == 5) d = ddd[randint0(8)];
2434 /* Get the destination */
2438 /* Ignore locations off of edge */
2439 if (!in_bounds2(ny, nx)) continue;
2441 /* Access that grid */
2442 g_ptr = ¤t_floor_ptr->grid_array[ny][nx];
2443 f_ptr = &f_info[g_ptr->feat];
2444 can_cross = monster_can_cross_terrain(g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0);
2446 /* Access that grid's contents */
2447 y_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
2449 /* Hack -- player 'in' wall */
2450 if (player_bold(ny, nx))
2455 /* Possibly a monster to attack */
2456 else if (g_ptr->m_idx)
2461 /* Monster destroys walls (and doors) */
2462 else if ((r_ptr->flags2 & RF2_KILL_WALL) &&
2463 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !is_riding_mon) &&
2464 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
2465 check_hp_for_feat_destruction(f_ptr, m_ptr))
2467 /* Eat through walls/doors/rubble */
2469 if (!can_cross) must_alter_to_move = TRUE;
2471 /* Monster destroyed a wall (later) */
2472 did_kill_wall = TRUE;
2475 /* Floor is open? */
2478 /* Go ahead and move */
2481 /* Monster moves through walls (and doors) */
2482 if ((r_ptr->flags2 & RF2_PASS_WALL) && (!is_riding_mon || p_ptr->pass_wall) &&
2483 have_flag(f_ptr->flags, FF_CAN_PASS))
2485 /* Monster went through a wall */
2486 did_pass_wall = TRUE;
2490 /* Handle doors and secret doors */
2491 else if (is_closed_door(g_ptr->feat))
2493 bool may_bash = TRUE;
2495 /* Assume no move allowed */
2498 /* Creature can open doors. */
2499 if ((r_ptr->flags2 & RF2_OPEN_DOOR) && have_flag(f_ptr->flags, FF_OPEN) &&
2500 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2505 /* The door is open */
2506 did_open_door = TRUE;
2508 /* Do not bash the door */
2514 /* Locked doors (not jammed) */
2517 /* Try to unlock it */
2518 if (randint0(m_ptr->hp / 10) > f_ptr->power)
2520 /* Unlock the door */
2521 cave_alter_feat(ny, nx, FF_DISARM);
2523 /* Do not bash the door */
2531 /* Stuck doors -- attempt to bash them down if allowed */
2532 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) && have_flag(f_ptr->flags, FF_BASH) &&
2533 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2535 /* Attempt to Bash */
2536 if (check_hp_for_feat_destruction(f_ptr, m_ptr) && (randint0(m_ptr->hp / 10) > f_ptr->power))
2538 if (have_flag(f_ptr->flags, FF_GLASS))
2539 msg_print(_("ガラスが砕ける音がした!", "You hear a glass was crashed!"));
2541 msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
2543 /* Disturb (sometimes) */
2544 if (disturb_minor) disturb(FALSE, FALSE);
2546 /* The door was bashed open */
2547 did_bash_door = TRUE;
2549 /* Hack -- fall into doorway */
2551 must_alter_to_move = TRUE;
2556 /* Deal with doors in the way */
2557 if (did_open_door || did_bash_door)
2559 /* Break down the door */
2560 if (did_bash_door && ((randint0(100) < 50) || (feat_state(g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
2562 cave_alter_feat(ny, nx, FF_BASH);
2564 if (!monster_is_valid(m_ptr)) /* Killed by shards of glass, etc. */
2566 p_ptr->update |= (PU_FLOW);
2567 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2568 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2577 cave_alter_feat(ny, nx, FF_OPEN);
2580 f_ptr = &f_info[g_ptr->feat];
2582 /* Handle viewable doors */
2587 /* Hack -- check for Glyph of Warding */
2588 if (do_move && is_glyph_grid(g_ptr) &&
2589 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
2591 /* Assume no move allowed */
2594 /* Break the ward */
2595 if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
2597 /* Describe observable breakage */
2598 if (g_ptr->info & CAVE_MARK)
2600 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2603 /* Forget the rune */
2604 g_ptr->info &= ~(CAVE_MARK);
2606 /* Break the rune */
2607 g_ptr->info &= ~(CAVE_OBJECT);
2610 /* Allow movement */
2616 else if (do_move && is_explosive_rune_grid(g_ptr) &&
2617 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
2619 /* Assume no move allowed */
2622 /* Break the ward */
2625 /* Break the ward */
2626 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2628 /* Describe observable breakage */
2629 if (g_ptr->info & CAVE_MARK)
2631 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2632 project(0, 2, ny, nx, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
2637 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2640 /* Forget the rune */
2641 g_ptr->info &= ~(CAVE_MARK);
2643 /* Break the rune */
2644 g_ptr->info &= ~(CAVE_OBJECT);
2650 if (!monster_is_valid(m_ptr)) return;
2651 /* Allow movement */
2656 /* The player is in the way */
2657 if (do_move && player_bold(ny, nx))
2659 /* Some monsters never attack */
2660 if (r_ptr->flags1 & RF1_NEVER_BLOW)
2662 /* Hack -- memorize lack of attacks */
2663 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
2669 /* In anti-melee dungeon, stupid or confused monster takes useless current_world_ptr->game_turn */
2670 if (do_move && (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE))
2672 if (!MON_CONFUSED(m_ptr))
2674 if (!(r_ptr->flags2 & RF2_STUPID)) do_move = FALSE;
2677 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
2682 /* The player is in the way. Attack him. */
2685 if (!p_ptr->riding || one_in_(2))
2688 (void)make_attack_normal(m_idx);
2693 /* Took a current_world_ptr->game_turn */
2699 /* A monster is in the way */
2700 if (do_move && g_ptr->m_idx)
2702 monster_race *z_ptr = &r_info[y_ptr->r_idx];
2704 /* Assume no movement */
2707 /* Attack 'enemies' */
2708 if (((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW) &&
2709 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
2710 can_cross && (g_ptr->m_idx != p_ptr->riding)) ||
2711 are_enemies(m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
2713 if (!(r_ptr->flags1 & RF1_NEVER_BLOW))
2715 if (r_ptr->flags2 & RF2_KILL_BODY)
2717 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_BODY);
2721 if (y_ptr->r_idx && (y_ptr->hp >= 0))
2723 if (monst_attack_monst(m_idx, g_ptr->m_idx)) return;
2725 /* In anti-melee dungeon, stupid or confused monster takes useless current_world_ptr->game_turn */
2726 else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE)
2728 if (MON_CONFUSED(m_ptr)) return;
2729 else if (r_ptr->flags2 & RF2_STUPID)
2731 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
2739 /* Push past weaker monsters (unless leaving a wall) */
2740 else if ((r_ptr->flags2 & RF2_MOVE_BODY) && !(r_ptr->flags1 & RF1_NEVER_MOVE) &&
2741 (r_ptr->mexp > z_ptr->mexp) &&
2742 can_cross && (g_ptr->m_idx != p_ptr->riding) &&
2743 monster_can_cross_terrain(current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
2745 /* Allow movement */
2748 /* Monster pushed past another monster */
2749 did_move_body = TRUE;
2751 /* Wake up the moved monster */
2752 (void)set_monster_csleep(g_ptr->m_idx, 0);
2760 if (!p_ptr->riding_ryoute && !MON_MONFEAR(¤t_floor_ptr->m_list[p_ptr->riding])) do_move = FALSE;
2763 if (did_kill_wall && do_move)
2765 if (one_in_(GRINDNOISE))
2767 if (have_flag(f_ptr->flags, FF_GLASS))
2768 msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
2770 msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
2773 cave_alter_feat(ny, nx, FF_HURT_DISI);
2775 if (!monster_is_valid(m_ptr)) /* Killed by shards of glass, etc. */
2777 p_ptr->update |= (PU_FLOW);
2778 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2779 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2784 f_ptr = &f_info[g_ptr->feat];
2786 /* Note changes to viewable region */
2791 if (must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
2793 if (!monster_can_cross_terrain(g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0))
2795 /* Assume no move allowed */
2801 * Check if monster can cross terrain
2802 * This is checked after the normal attacks
2803 * to allow monsters to attack an enemy,
2804 * even if it can't enter the terrain.
2806 if (do_move && !can_cross && !did_kill_wall && !did_bash_door)
2808 /* Assume no move allowed */
2812 /* Some monsters never move */
2813 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
2815 /* Hack -- memorize lack of moves */
2816 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
2822 /* Creature has been allowed move */
2827 if (have_flag(f_ptr->flags, FF_TREE))
2829 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
2831 m_ptr->energy_need += ENERGY_NEED();
2837 /* Hack -- Update the old location */
2838 current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
2840 /* Mega-Hack -- move the old monster, if any */
2843 /* Move the old monster */
2847 /* Update the old monster */
2848 update_monster(g_ptr->m_idx, TRUE);
2851 /* Hack -- Update the new location */
2852 g_ptr->m_idx = m_idx;
2854 /* Move the monster */
2857 update_monster(m_idx, TRUE);
2864 /* sound(SOUND_WALK); */
2865 if (!move_player_effect(ny, nx, MPE_DONT_PICKUP)) break;
2868 /* Possible disturb */
2871 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) ||
2872 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)))
2874 if (is_hostile(m_ptr))
2875 disturb(FALSE, TRUE);
2878 /* Take or Kill objects on the floor */
2879 if (g_ptr->o_idx && (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
2880 (!is_pet(m_ptr) || ((p_ptr->pet_extra_flags & PF_PICKUP_ITEMS) && (r_ptr->flags2 & RF2_TAKE_ITEM))))
2882 OBJECT_IDX this_o_idx, next_o_idx;
2883 bool do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) ? TRUE : FALSE;
2885 /* Scan all objects in the grid */
2886 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2888 BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
2889 GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
2890 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
2891 next_o_idx = o_ptr->next_o_idx;
2896 if (o_ptr->tval == TV_GOLD) continue;
2899 * Skip "real" corpses and statues, to avoid extreme
2900 * silliness like a novice rogue pockets full of statues
2903 if ((o_ptr->tval == TV_CORPSE) ||
2904 (o_ptr->tval == TV_STATUE)) continue;
2907 /* Extract some flags */
2908 object_flags(o_ptr, flgs);
2910 /* Acquire the object name */
2911 object_desc(o_name, o_ptr, 0);
2912 monster_desc(m_name, m_ptr, MD_INDEF_HIDDEN);
2914 /* React to objects that hurt the monster */
2915 if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
2916 if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
2917 if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
2918 if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
2919 if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
2920 if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
2921 if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
2922 if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
2923 if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
2924 if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
2925 if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
2926 if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
2927 if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
2928 if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
2929 if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
2930 if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
2931 if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
2932 if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
2933 if (have_flag(flgs, TR_BRAND_ACID)) flgr |= (RFR_IM_ACID);
2934 if (have_flag(flgs, TR_BRAND_ELEC)) flgr |= (RFR_IM_ELEC);
2935 if (have_flag(flgs, TR_BRAND_FIRE)) flgr |= (RFR_IM_FIRE);
2936 if (have_flag(flgs, TR_BRAND_COLD)) flgr |= (RFR_IM_COLD);
2937 if (have_flag(flgs, TR_BRAND_POIS)) flgr |= (RFR_IM_POIS);
2939 /* The object cannot be picked up by the monster */
2940 if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
2941 ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
2943 /* Only give a message for "take_item" */
2944 if (do_take && (r_ptr->flags2 & RF2_STUPID))
2946 did_take_item = TRUE;
2948 /* Describe observable situations */
2949 if (m_ptr->ml && player_can_see_bold(ny, nx))
2951 msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
2956 /* Pick up the item */
2959 did_take_item = TRUE;
2961 /* Describe observable situations */
2962 if (player_can_see_bold(ny, nx))
2964 msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
2967 /* Excise the object */
2968 excise_object_idx(this_o_idx);
2971 o_ptr->marked &= OM_TOUCHED;
2973 /* Forget location */
2974 o_ptr->iy = o_ptr->ix = 0;
2976 /* Memorize monster */
2977 o_ptr->held_m_idx = m_idx;
2980 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2983 m_ptr->hold_o_idx = this_o_idx;
2986 /* Destroy the item if not a pet */
2987 else if (!is_pet(m_ptr))
2989 did_kill_item = TRUE;
2991 /* Describe observable situations */
2992 if (player_has_los_bold(ny, nx))
2994 msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
2997 delete_object_idx(this_o_idx);
3003 /* Stop when done */
3008 * Forward movements failed, but now received LOS attack!
3009 * Try to flow by smell.
3011 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3012 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3014 /* If we haven't done anything, try casting a spell again */
3015 if (!do_turn && !do_move && !MON_MONFEAR(m_ptr) && !is_riding_mon && aware)
3017 /* Try to cast spell again */
3018 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
3020 if (make_attack_spell(m_idx)) return;
3025 /* Notice changes in view */
3028 p_ptr->update |= (PU_FLOW);
3029 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3032 /* Notice changes in view */
3033 if (do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
3034 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !p_ptr->inside_battle)))
3036 p_ptr->update |= (PU_MON_LITE);
3039 /* Learn things from observable monster */
3040 if (is_original_ap_and_seen(m_ptr))
3042 /* Monster opened a door */
3043 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3045 /* Monster bashed a door */
3046 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3048 /* Monster tried to pick something up */
3049 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3051 /* Monster tried to crush something */
3052 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3054 /* Monster pushed past another monster */
3055 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3057 /* Monster passed through a wall */
3058 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3060 /* Monster destroyed a wall */
3061 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3065 /* Hack -- get "bold" if out of options */
3066 if (!do_turn && !do_move && MON_MONFEAR(m_ptr) && aware)
3068 /* No longer afraid */
3069 (void)set_monster_monfear(m_idx, 0);
3071 /* Message if seen */
3074 GAME_TEXT m_name[MAX_NLEN];
3075 monster_desc(m_name, m_ptr, 0);
3076 msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
3079 if (m_ptr->ml) chg_virtue(V_COMPASSION, -1);
3081 /* Actually do something now (?) */
3086 * @brief 全モンスターのターン管理メインルーチン /
3087 * Process all the "live" monsters, once per game current_world_ptr->game_turn.
3090 * During each game current_world_ptr->game_turn, we scan through the list of all the "live" monsters,\n
3091 * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
3092 * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
3094 * Note that monsters can never move in the monster array (except when the\n
3095 * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
3097 * This function is responsible for at least half of the processor time\n
3098 * on a normal system with a "normal" amount of monsters and a player doing\n
3101 * When the player is resting, virtually 90% of the processor time is spent\n
3102 * in this function, and its children, "process_monster()" and "make_move()".\n
3104 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
3105 * especially when the player is running.\n
3107 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
3108 * monsters while they are still being "born". A monster is "fresh" only\n
3109 * during the current_world_ptr->game_turn in which it is created, and we use the "hack_m_idx" to\n
3110 * determine if the monster is yet to be processed during the current current_world_ptr->game_turn.\n
3112 * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
3113 * move before any "nasty" monsters get to use their spell attacks.\n
3115 * Note that when the "knowledge" about the currently tracked monster\n
3116 * changes (flags, attacks, spells), we induce a redraw of the monster\n
3119 void process_monsters(void)
3126 monster_type *m_ptr;
3127 monster_race *r_ptr;
3129 MONRACE_IDX old_monster_race_idx;
3131 BIT_FLAGS old_r_flags1 = 0L;
3132 BIT_FLAGS old_r_flags2 = 0L;
3133 BIT_FLAGS old_r_flags3 = 0L;
3134 BIT_FLAGS old_r_flags4 = 0L;
3135 BIT_FLAGS old_r_flags5 = 0L;
3136 BIT_FLAGS old_r_flags6 = 0L;
3137 BIT_FLAGS old_r_flagsr = 0L;
3139 byte old_r_blows0 = 0;
3140 byte old_r_blows1 = 0;
3141 byte old_r_blows2 = 0;
3142 byte old_r_blows3 = 0;
3144 byte old_r_cast_spell = 0;
3148 /* Clear monster fighting indicator */
3149 current_floor_ptr->monster_noise = FALSE;
3151 /* Memorize old race */
3152 old_monster_race_idx = p_ptr->monster_race_idx;
3154 /* Acquire knowledge */
3155 if (p_ptr->monster_race_idx)
3157 /* Acquire current monster */
3158 r_ptr = &r_info[p_ptr->monster_race_idx];
3160 /* Memorize flags */
3161 old_r_flags1 = r_ptr->r_flags1;
3162 old_r_flags2 = r_ptr->r_flags2;
3163 old_r_flags3 = r_ptr->r_flags3;
3164 old_r_flags4 = r_ptr->r_flags4;
3165 old_r_flags5 = r_ptr->r_flags5;
3166 old_r_flags6 = r_ptr->r_flags6;
3167 old_r_flagsr = r_ptr->r_flagsr;
3169 /* Memorize blows */
3170 old_r_blows0 = r_ptr->r_blows[0];
3171 old_r_blows1 = r_ptr->r_blows[1];
3172 old_r_blows2 = r_ptr->r_blows[2];
3173 old_r_blows3 = r_ptr->r_blows[3];
3175 /* Memorize castings */
3176 old_r_cast_spell = r_ptr->r_cast_spell;
3180 /* Process the monsters (backwards) */
3181 for (i = current_floor_ptr->m_max - 1; i >= 1; i--)
3183 /* Access the monster */
3184 m_ptr = ¤t_floor_ptr->m_list[i];
3185 r_ptr = &r_info[m_ptr->r_idx];
3187 /* Handle "leaving" */
3188 if (p_ptr->leaving) break;
3190 /* Ignore "dead" monsters */
3191 if (!monster_is_valid(m_ptr)) continue;
3193 if (p_ptr->wild_mode) continue;
3196 /* Handle "fresh" monsters */
3197 if (m_ptr->mflag & MFLAG_BORN)
3199 /* No longer "fresh" */
3200 m_ptr->mflag &= ~(MFLAG_BORN);
3206 /* Hack -- Require proximity */
3207 if (m_ptr->cdis >= AAF_LIMIT) continue;
3212 /* Flow by smell is allowed */
3213 if (!p_ptr->no_flowed)
3215 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3218 /* Assume no move */
3221 /* Handle "sensing radius" */
3222 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
3224 /* We can "sense" the player */
3228 /* Handle "sight" and "aggravation" */
3229 else if ((m_ptr->cdis <= MAX_SIGHT || p_ptr->inside_battle) &&
3230 (player_has_los_bold(fy, fx) || (p_ptr->cursed & TRC_AGGRAVATE)))
3232 /* We can "see" or "feel" the player */
3236 #if 0 /* (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].when == current_floor_ptr->grid_array[fy][fx].when) is always FALSE... */
3237 /* Hack -- Monsters can "smell" the player from far away */
3238 /* Note that most monsters have "aaf" of "20" or so */
3239 else if (!(m_ptr->mflag2 & MFLAG2_NOFLOW) &&
3240 cave_have_flag_bold(p_ptr->y, p_ptr->x, FF_MOVE) &&
3241 (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].when == current_floor_ptr->grid_array[fy][fx].when) &&
3242 (current_floor_ptr->grid_array[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3243 (current_floor_ptr->grid_array[fy][fx].dist < r_ptr->aaf))
3245 /* We can "smell" the player */
3249 else if (m_ptr->target_y) test = TRUE;
3252 if (!test) continue;
3255 if (p_ptr->riding == i)
3256 speed = p_ptr->pspeed;
3259 speed = m_ptr->mspeed;
3261 /* Monsters move quickly in Nightmare mode */
3262 if (ironman_nightmare) speed += 5;
3264 if (MON_FAST(m_ptr)) speed += 10;
3265 if (MON_SLOW(m_ptr)) speed -= 10;
3268 /* Give this monster some energy */
3269 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
3271 /* Not enough energy to move */
3272 if (m_ptr->energy_need > 0) continue;
3274 /* Use up "some" energy */
3275 m_ptr->energy_need += ENERGY_NEED();
3278 /* Save global index */
3281 /* Process the monster */
3284 reset_target(m_ptr);
3286 /* Give up flow_by_smell when it might useless */
3287 if (p_ptr->no_flowed && one_in_(3))
3288 m_ptr->mflag2 |= MFLAG2_NOFLOW;
3290 /* Hack -- notice death or departure */
3291 if (!p_ptr->playing || p_ptr->is_dead) break;
3293 /* Notice leaving */
3294 if (p_ptr->leaving) break;
3297 /* Reset global index */
3301 /* Tracking a monster race (the same one we were before) */
3302 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
3304 /* Acquire monster race */
3305 r_ptr = &r_info[p_ptr->monster_race_idx];
3307 /* Check for knowledge change */
3308 if ((old_r_flags1 != r_ptr->r_flags1) ||
3309 (old_r_flags2 != r_ptr->r_flags2) ||
3310 (old_r_flags3 != r_ptr->r_flags3) ||
3311 (old_r_flags4 != r_ptr->r_flags4) ||
3312 (old_r_flags5 != r_ptr->r_flags5) ||
3313 (old_r_flags6 != r_ptr->r_flags6) ||
3314 (old_r_flagsr != r_ptr->r_flagsr) ||
3315 (old_r_blows0 != r_ptr->r_blows[0]) ||
3316 (old_r_blows1 != r_ptr->r_blows[1]) ||
3317 (old_r_blows2 != r_ptr->r_blows[2]) ||
3318 (old_r_blows3 != r_ptr->r_blows[3]) ||
3319 (old_r_cast_spell != r_ptr->r_cast_spell))
3321 p_ptr->window |= (PW_MONSTER);