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).
18 #include "monsterrace-hook.h"
21 #include "spells-summon.h"
24 #include "realm-hex.h"
25 #include "object-flavor.h"
26 #include "object-hook.h"
29 #include "player-move.h"
30 #include "monster-status.h"
31 #include "monster-spell.h"
36 * @brief モンスターが敵に接近するための方向を決める /
37 * Calculate the direction to the next enemy
38 * @param m_idx モンスターの参照ID
39 * @param mm 移動するべき方角IDを返す参照ポインタ
40 * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
42 static bool get_enemy_dir(MONSTER_IDX m_idx, int *mm)
45 POSITION x = 0, y = 0;
50 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
51 monster_race *r_ptr = &r_info[m_ptr->r_idx];
54 if (riding_t_m_idx && player_bold(m_ptr->fy, m_ptr->fx))
56 y = current_floor_ptr->m_list[riding_t_m_idx].fy;
57 x = current_floor_ptr->m_list[riding_t_m_idx].fx;
59 else if (is_pet(m_ptr) && pet_t_m_idx)
61 y = current_floor_ptr->m_list[pet_t_m_idx].fy;
62 x = current_floor_ptr->m_list[pet_t_m_idx].fx;
66 if (p_ptr->inside_battle)
68 start = randint1(m_max-1)+m_max;
69 if(randint0(2)) plus = -1;
71 else start = m_max + 1;
73 /* Scan thru all monsters */
74 for (i = start; ((i < start + m_max) && (i > start - m_max)); i+=plus)
76 MONSTER_IDX dummy = (i % m_max);
81 t_ptr = ¤t_floor_ptr->m_list[t_idx];
83 /* The monster itself isn't a target */
84 if (t_ptr == m_ptr) continue;
86 if (!monster_is_valid(t_ptr)) continue;
90 /* Hack -- only fight away from player */
91 if (p_ptr->pet_follow_distance < 0)
93 /* No fighting near player */
94 if (t_ptr->cdis <= (0 - p_ptr->pet_follow_distance))
99 /* Hack -- no fighting away from player */
100 else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > p_ptr->pet_follow_distance))
105 if (r_ptr->aaf < t_ptr->cdis) continue;
108 /* Monster must be 'an enemy' */
109 if (!are_enemies(m_ptr, t_ptr)) continue;
111 /* Monster must be projectable if we can't pass through walls */
112 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) ||
113 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding)))
115 if (!in_disintegration_range(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
119 if (!projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
122 /* OK -- we've got a target */
128 if (!x && !y) return FALSE;
131 /* Extract the direction */
136 if ((y < 0) && (x == 0))
143 else if ((y > 0) && (x == 0))
150 else if ((x > 0) && (y == 0))
157 else if ((x < 0) && (y == 0))
164 else if ((y < 0) && (x < 0))
171 else if ((y < 0) && (x > 0))
178 else if ((y > 0) && (x < 0))
185 else if ((y > 0) && (x > 0))
192 /* Found a monster */
197 * @brief モンスターがプレイヤーから逃走するかどうかを返す /
198 * Returns whether a given monster will try to run from the player.
199 * @param m_idx 逃走するモンスターの参照ID
200 * @return モンスターがプレイヤーから逃走するならばTRUEを返す。
202 * Monsters will attempt to avoid very powerful players. See below.\n
204 * Because this function is called so often, little details are important\n
205 * for efficiency. Like not using "mod" or "div" when possible. And\n
206 * attempting to check the conditions in an optimal order. Note that\n
207 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
209 * Note that this function is responsible for about one to five percent\n
210 * of the processor use in normal conditions...\n
212 static bool mon_will_run(MONSTER_IDX m_idx)
214 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
218 monster_race *r_ptr = &r_info[m_ptr->r_idx];
222 HIT_POINT p_chp, p_mhp;
223 HIT_POINT m_chp, m_mhp;
228 /* Friends can be commanded to avoid the player */
231 /* Are we trying to avoid the player? */
232 return ((p_ptr->pet_follow_distance < 0) &&
233 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
236 /* Keep monsters from running too far away */
237 if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE);
239 /* All "afraid" monsters will run away */
240 if (MON_MONFEAR(m_ptr)) return (TRUE);
244 /* Nearby monsters will not become terrified */
245 if (m_ptr->cdis <= 5) return (FALSE);
247 /* Examine player power (level) */
250 /* Examine monster power (level plus morale) */
251 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
253 /* Optimize extreme cases below */
254 if (m_lev > p_lev + 4) return (FALSE);
255 if (m_lev + 4 <= p_lev) return (TRUE);
257 /* Examine player health */
261 /* Examine monster health */
263 m_mhp = m_ptr->maxhp;
265 /* Prepare to optimize the calculation */
266 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
267 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
269 /* Strong players scare strong monsters */
270 if (p_val * m_mhp > m_val * p_mhp) return (TRUE);
274 /* Assume no terror */
280 * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
281 * Search spell castable grid
282 * @param m_idx モンスターの参照ID
283 * @param yp 適したマスのY座標を返す参照ポインタ
284 * @param xp 適したマスのX座標を返す参照ポインタ
285 * @return 有効なマスがあった場合TRUEを返す
287 static bool get_moves_aux2(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
290 POSITION y, x, y1, x1;
293 bool can_open_door = FALSE;
296 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
297 monster_race *r_ptr = &r_info[m_ptr->r_idx];
299 /* Monster location */
303 /* Monster can already cast spell to player */
304 if (projectable(y1, x1, p_ptr->y, p_ptr->x)) return (FALSE);
306 /* Set current grid cost */
307 now_cost = current_floor_ptr->grid_array[y1][x1].cost;
308 if (now_cost == 0) now_cost = 999;
310 /* Can monster bash or open doors? */
311 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
313 can_open_door = TRUE;
316 /* Check nearby grids, diagonals first */
317 for (i = 7; i >= 0; i--)
324 /* Ignore locations off of edge */
325 if (!in_bounds2(y, x)) continue;
327 /* Simply move to player */
328 if (player_bold(y, x)) return (FALSE);
330 g_ptr = ¤t_floor_ptr->grid_array[y][x];
334 /* Monster cannot kill or pass walls */
335 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))))
337 if (cost == 0) continue;
338 if (!can_open_door && is_closed_door(g_ptr->feat)) continue;
341 /* Hack -- for kill or pass wall monster.. */
342 if (cost == 0) cost = 998;
344 if (now_cost < cost) continue;
346 if (!projectable(y, x, p_ptr->y, p_ptr->x)) continue;
348 /* Accept louder sounds */
349 if (best < cost) continue;
352 (*yp) = y1 + ddy_ddd[i];
353 (*xp) = x1 + ddx_ddd[i];
356 /* No legal move (?) */
357 if (best == 999) return (FALSE);
365 * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
366 * Choose the "best" direction for "flowing"
367 * @param m_idx モンスターの参照ID
368 * @param yp 移動先のマスのY座標を返す参照ポインタ
369 * @param xp 移動先のマスのX座標を返す参照ポインタ
370 * @param no_flow モンスターにFLOWフラグが経っていない状態でTRUE
371 * @return 有効なマスがあった場合TRUEを返す
373 * Note that ghosts and rock-eaters are never allowed to "flow",\n
374 * since they should move directly towards the player.\n
376 * Prefer "non-diagonal" directions, but twiddle them a little\n
377 * to angle slightly towards the player's actual location.\n
379 * Allow very perceptive monsters to track old "spoor" left by\n
380 * previous locations occupied by the player. This will tend\n
381 * to have monsters end up either near the player or on a grid\n
382 * recently occupied by the player (and left via "teleport").\n
384 * Note that if "smell" is turned on, all monsters get vicious.\n
386 * Also note that teleporting away from a location will cause\n
387 * the monsters who were chasing you to converge on that location\n
388 * as long as you are still near enough to "annoy" them without\n
389 * being close enough to chase directly. I have no idea what will\n
390 * happen if you combine "smell" with low "aaf" values.\n
392 static bool get_moves_aux(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
395 POSITION y, x, y1, x1;
398 bool use_scent = FALSE;
400 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
401 monster_race *r_ptr = &r_info[m_ptr->r_idx];
403 /* Can monster cast attack spell? */
404 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
405 r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
406 r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
408 /* Can move spell castable grid? */
409 if (get_moves_aux2(m_idx, yp, xp)) return (TRUE);
412 /* Monster can't flow */
413 if (no_flow) return (FALSE);
415 /* Monster can go through rocks */
416 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) return (FALSE);
417 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding)) return (FALSE);
419 /* Monster location */
423 /* Hack -- Player can see us, run towards him */
424 if (player_has_los_bold(y1, x1) && projectable(p_ptr->y, p_ptr->x, y1, x1)) return (FALSE);
427 g_ptr = ¤t_floor_ptr->grid_array[y1][x1];
429 /* If we can hear noises, advance towards them */
435 /* Otherwise, try to follow a scent trail */
436 else if (g_ptr->when)
439 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].when - g_ptr->when > 127) return (FALSE);
445 /* Otherwise, advance blindly */
451 /* Check nearby grids, diagonals first */
452 for (i = 7; i >= 0; i--)
457 /* Ignore locations off of edge */
458 if (!in_bounds2(y, x)) continue;
460 g_ptr = ¤t_floor_ptr->grid_array[y][x];
462 /* We're following a scent trail */
465 int when = g_ptr->when;
467 /* Accept younger scent */
468 if (best > when) continue;
472 /* We're using sound */
477 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
479 else cost = g_ptr->cost;
481 /* Accept louder sounds */
482 if ((cost == 0) || (best < cost)) continue;
486 /* Hack -- Save the "twiddled" location */
487 (*yp) = p_ptr->y + 16 * ddy_ddd[i];
488 (*xp) = p_ptr->x + 16 * ddx_ddd[i];
491 /* No legal move (?) */
492 if (best == 999 || best == 0) return (FALSE);
500 * @brief モンスターがプレイヤーから逃走することが可能なマスを走査する /
501 * Provide a location to flee to, but give the player a wide berth.
502 * @param m_idx モンスターの参照ID
503 * @param yp 移動先のマスのY座標を返す参照ポインタ
504 * @param xp 移動先のマスのX座標を返す参照ポインタ
505 * @return 有効なマスがあった場合TRUEを返す
507 * A monster may wish to flee to a location that is behind the player,\n
508 * but instead of heading directly for it, the monster should "swerve"\n
509 * around the player so that he has a smaller chance of getting hit.\n
511 static bool get_fear_moves_aux(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
513 POSITION y, x, y1, x1, fy, fx, gy = 0, gx = 0;
517 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
519 /* Monster location */
523 /* Desired destination */
527 /* Check nearby grids, diagonals first */
528 for (i = 7; i >= 0; i--)
535 /* Ignore locations off of edge */
536 if (!in_bounds2(y, x)) continue;
538 /* Don't move toward player */
539 /* if (current_floor_ptr->grid_array[y][x].dist < 3) continue; */ /* Hmm.. Need it? */
541 /* Calculate distance of this grid from our destination */
542 dis = distance(y, x, y1, x1);
544 /* Score this grid */
545 s = 5000 / (dis + 3) - 500 / (current_floor_ptr->grid_array[y][x].dist + 1);
547 /* No negative scores */
550 /* Ignore lower scores */
551 if (s < score) continue;
553 /* Save the score and time */
556 /* Save the location */
561 /* No legal move (?) */
562 if (score == -1) return (FALSE);
573 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
576 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
577 * offsets of all the locations with a distance of n from a central point,
578 * with an offset of (0,0) indicating no more offsets at this distance.
580 * This is, of course, fairly unreadable, but it eliminates multiple loops
581 * from the previous version.
583 * It is probably better to replace these arrays with code to compute
584 * the relevant arrays, even if the storage is pre-allocated in hard
585 * coded sizes. At the very least, code should be included which is
586 * able to generate and dump these arrays (ala "los()").
588 * Also, the storage needs could be halved by using bytes.
590 * These arrays could be combined into two big arrays, using sub-arrays
591 * to hold the offsets and lengths of each portion of the sub-arrays, and
592 * this could perhaps also be used somehow in the "look" code.
596 static POSITION d_off_y_0[] = { 0 };
597 static POSITION d_off_x_0[] = { 0 };
599 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
600 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
602 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
603 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
605 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
606 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
608 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 };
609 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 };
612 static POSITION d_off_y_5[] =
613 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
614 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
617 static POSITION d_off_x_5[] =
618 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
619 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
623 static POSITION d_off_y_6[] =
624 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
625 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
628 static POSITION d_off_x_6[] =
629 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
630 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
631 -3, 2, 3, -1, 0, 1, 0 };
634 static POSITION d_off_y_7[] =
635 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
636 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
637 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
639 static POSITION d_off_x_7[] =
640 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
641 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
642 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
646 static POSITION d_off_y_8[] =
647 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
648 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
649 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
652 static POSITION d_off_x_8[] =
653 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
654 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
655 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
659 static POSITION d_off_y_9[] =
660 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
661 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
662 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
663 7, 8, 8, 8, 8, 9, 9, 9, 0 };
665 static POSITION d_off_x_9[] =
666 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
667 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
668 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
669 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
672 static POSITION *dist_offsets_y[10] =
674 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
675 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
678 static POSITION *dist_offsets_x[10] =
680 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
681 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
685 * @brief モンスターが逃げ込める安全な地点を返す /
686 * Choose a "safe" location near a monster for it to run toward.
687 * @param m_idx モンスターの参照ID
688 * @param yp 移動先のマスのY座標を返す参照ポインタ
689 * @param xp 移動先のマスのX座標を返す参照ポインタ
690 * @return 有効なマスがあった場合TRUEを返す
692 * A location is "safe" if it can be reached quickly and the player\n
693 * is not able to fire into it (it isn't a "clean shot"). So, this will\n
694 * cause monsters to "duck" behind walls. Hopefully, monsters will also\n
695 * try to run towards corridor openings if they are in a room.\n
697 * This function may take lots of CPU time if lots of monsters are\n
700 * Return TRUE if a safe location is available.\n
702 static bool find_safety(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
704 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
706 POSITION fy = m_ptr->fy;
707 POSITION fx = m_ptr->fx;
709 POSITION y, x, dy, dx, d, dis, i;
710 POSITION gy = 0, gx = 0, gdis = 0;
717 /* Start with adjacent locations, spread further */
718 for (d = 1; d < 10; d++)
720 /* Get the lists of points with a distance d from (fx, fy) */
721 y_offsets = dist_offsets_y[d];
722 x_offsets = dist_offsets_x[d];
724 /* Check the locations */
725 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
727 i++, dx = x_offsets[i], dy = y_offsets[i])
732 /* Skip illegal locations */
733 if (!in_bounds(y, x)) continue;
735 g_ptr = ¤t_floor_ptr->grid_array[y][x];
737 /* Skip locations in a wall */
738 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], (m_idx == p_ptr->riding) ? CEM_RIDING : 0)) continue;
740 /* Check for "availability" (if monsters can flow) */
741 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
743 /* Ignore grids very far from the player */
744 if (g_ptr->dist == 0) continue;
746 /* Ignore too-distant grids */
747 if (g_ptr->dist > current_floor_ptr->grid_array[fy][fx].dist + 2 * d) continue;
750 /* Check for absence of shot (more or less) */
751 if (!projectable(p_ptr->y, p_ptr->x, y, x))
753 /* Calculate distance from player */
754 dis = distance(y, x, p_ptr->y, p_ptr->x);
756 /* Remember if further than previous */
766 /* Check for success */
773 /* Found safe place */
784 * @brief モンスターが隠れ潜める地点を返す /
785 * Choose a good hiding place near a monster for it to run toward.
786 * @param m_idx モンスターの参照ID
787 * @param yp 移動先のマスのY座標を返す参照ポインタ
788 * @param xp 移動先のマスのX座標を返す参照ポインタ
789 * @return 有効なマスがあった場合TRUEを返す
791 * Pack monsters will use this to "ambush" the player and lure him out\n
792 * of corridors into open space so they can swarm him.\n
794 * Return TRUE if a good location is available.\n
796 static bool find_hiding(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
798 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
799 monster_race *r_ptr = &r_info[m_ptr->r_idx];
801 POSITION fy = m_ptr->fy;
802 POSITION fx = m_ptr->fx;
804 POSITION y, x, dy, dx, d, dis, i;
805 POSITION gy = 0, gx = 0, gdis = 999;
807 POSITION *y_offsets, *x_offsets;
809 /* Start with adjacent locations, spread further */
810 for (d = 1; d < 10; d++)
812 /* Get the lists of points with a distance d from (fx, fy) */
813 y_offsets = dist_offsets_y[d];
814 x_offsets = dist_offsets_x[d];
816 /* Check the locations */
817 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
819 i++, dx = x_offsets[i], dy = y_offsets[i])
824 /* Skip illegal locations */
825 if (!in_bounds(y, x)) continue;
827 /* Skip occupied locations */
828 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
830 /* Check for hidden, available grid */
831 if (!projectable(p_ptr->y, p_ptr->x, y, x) && clean_shot(fy, fx, y, x, FALSE))
833 /* Calculate distance from player */
834 dis = distance(y, x, p_ptr->y, p_ptr->x);
836 /* Remember if closer than previous */
837 if (dis < gdis && dis >= 2)
846 /* Check for success */
853 /* Found good place */
864 * @brief モンスターの移動方向を返す /
865 * Choose "logical" directions for monster movement
866 * @param m_idx モンスターの参照ID
867 * @param mm 移動方向を返す方向IDの参照ポインタ
868 * @return 有効方向があった場合TRUEを返す
870 static bool get_moves(MONSTER_IDX m_idx, DIRECTION *mm)
872 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
873 monster_race *r_ptr = &r_info[m_ptr->r_idx];
874 POSITION y = 0, ay, x = 0, ax;
876 POSITION y2 = p_ptr->y;
877 POSITION x2 = p_ptr->x;
879 bool will_run = mon_will_run(m_idx);
881 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2));
882 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall));
884 /* Counter attack to an enemy monster */
885 if (!will_run && m_ptr->target_y)
887 int t_m_idx = current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
889 /* The monster must be an enemy, and in LOS */
891 are_enemies(m_ptr, ¤t_floor_ptr->m_list[t_m_idx]) &&
892 los(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
893 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
895 /* Extract the "pseudo-direction" */
896 y = m_ptr->fy - m_ptr->target_y;
897 x = m_ptr->fx - m_ptr->target_x;
902 if (!done && !will_run && is_hostile(m_ptr) &&
903 (r_ptr->flags1 & RF1_FRIENDS) &&
904 ((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)) ||
905 (current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
908 * Animal packs try to get the player out of corridors
909 * (...unless they can move through walls -- TY)
911 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
912 !(r_ptr->flags2 & RF2_KILL_WALL))
916 /* Count room grids next to player */
917 for (i = 0; i < 8; i++)
919 int xx = p_ptr->x + ddx_ddd[i];
920 int yy = p_ptr->y + ddy_ddd[i];
922 if (!in_bounds2(yy, xx)) continue;
924 g_ptr = ¤t_floor_ptr->grid_array[yy][xx];
927 if (monster_can_cross_terrain(g_ptr->feat, r_ptr, 0))
929 /* One more room grid */
933 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_ROOM) room -= 2;
934 if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
936 /* Not in a room and strong player */
937 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
938 (p_ptr->mhp + p_ptr->msp))
940 /* Find hiding place */
941 if (find_hiding(m_idx, &y, &x)) done = TRUE;
945 /* Monster groups try to surround the player */
946 if (!done && (current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
950 /* Find an empty square near the player to fill */
951 for (i = 0; i < 8; i++)
953 /* Pick squares near player (semi-randomly) */
954 y2 = p_ptr->y + ddy_ddd[(m_idx + i) & 7];
955 x2 = p_ptr->x + ddx_ddd[(m_idx + i) & 7];
958 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
960 /* Attack the player */
967 if (!in_bounds2(y2, x2)) continue;
969 /* Ignore filled grids */
970 if (!monster_can_enter(y2, x2, r_ptr, 0)) continue;
972 /* Try to fill this hole */
976 /* Extract the new "pseudo-direction" */
986 /* Flow towards the player */
987 (void)get_moves_aux(m_idx, &y2, &x2, no_flow);
989 /* Extract the "pseudo-direction" */
996 /* Apply fear if possible and necessary */
997 if (is_pet(m_ptr) && will_run)
999 /* XXX XXX Not very "smart" */
1004 if (!done && will_run)
1009 /* Try to find safe place */
1010 if (find_safety(m_idx, &y, &x))
1012 /* Attempt to avoid the player */
1015 /* Adjust movement */
1016 if (get_fear_moves_aux(m_idx, &y, &x)) done = TRUE;
1022 /* This is not a very "smart" method XXX XXX */
1030 /* Check for no move */
1031 if (!x && !y) return (FALSE);
1034 /* Extract the "absolute distances" */
1038 /* Do something weird */
1039 if (y < 0) move_val += 8;
1040 if (x > 0) move_val += 4;
1042 /* Prevent the diamond maneuvre */
1043 if (ay > (ax << 1)) move_val += 2;
1044 else if (ax > (ay << 1)) move_val++;
1046 /* Extract some directions */
1191 /* Wants to move... */
1197 * @brief モンスターから敵モンスターへの命中判定
1198 * @param power 打撃属性による基本命中値
1199 * @param level 攻撃側モンスターのレベル
1200 * @param ac 目標モンスターのAC
1201 * @param stun 攻撃側モンスターが朦朧状態ならTRUEを返す
1202 * @return 命中ならばTRUEを返す
1204 static int check_hit2(int power, DEPTH level, ARMOUR_CLASS ac, int stun)
1208 /* Percentile dice */
1211 if (stun && one_in_(2)) return FALSE;
1213 /* Hack -- Always miss or hit */
1214 if (k < 10) return (k < 5);
1216 /* Calculate the "attack quality" */
1217 i = (power + (level * 3));
1219 /* Power and Level compete against Armor */
1220 if ((i > 0) && (randint1(i) > ((ac * 3) / 4))) return (TRUE);
1227 #define BLOW_EFFECT_TYPE_NONE 0
1228 #define BLOW_EFFECT_TYPE_FEAR 1
1229 #define BLOW_EFFECT_TYPE_SLEEP 2
1230 #define BLOW_EFFECT_TYPE_HEAL 3
1234 * @brief モンスターから敵モンスターへの打撃攻撃処理
1235 * @param m_idx 攻撃側モンスターの参照ID
1236 * @param t_idx 目標側モンスターの参照ID
1237 * @return 実際に打撃処理が行われた場合TRUEを返す
1239 static bool monst_attack_monst(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
1241 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1242 monster_type *t_ptr = ¤t_floor_ptr->m_list[t_idx];
1244 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1245 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1247 ARMOUR_CLASS ap_cnt;
1251 GAME_TEXT m_name[MAX_NLEN], t_name[MAX_NLEN];
1252 char temp[MAX_NLEN];
1254 bool explode = FALSE, touched = FALSE, fear = FALSE, dead = FALSE;
1255 POSITION y_saver = t_ptr->fy;
1256 POSITION x_saver = t_ptr->fx;
1259 bool see_m = is_seen(m_ptr);
1260 bool see_t = is_seen(t_ptr);
1261 bool see_either = see_m || see_t;
1263 /* Can the player be aware of this attack? */
1264 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1265 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1267 /* Cannot attack self */
1268 if (m_idx == t_idx) return FALSE;
1270 /* Not allowed to attack */
1271 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1273 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) return (FALSE);
1278 /* Extract the effective monster level */
1279 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1281 monster_desc(m_name, m_ptr, 0);
1282 monster_desc(t_name, t_ptr, 0);
1284 /* Assume no blink */
1287 if (!see_either && known)
1292 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(TRUE, TRUE);
1294 /* Scan through all four blows */
1295 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1297 bool obvious = FALSE;
1299 HIT_POINT power = 0;
1300 HIT_POINT damage = 0;
1304 /* Extract the attack infomation */
1305 int effect = r_ptr->blow[ap_cnt].effect;
1306 int method = r_ptr->blow[ap_cnt].method;
1307 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1308 int d_side = r_ptr->blow[ap_cnt].d_side;
1310 if (!monster_is_valid(m_ptr)) break;
1312 /* Stop attacking if the target dies! */
1313 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1316 /* Hack -- no more attacks */
1319 if (method == RBM_SHOOT) continue;
1321 /* Extract the attack "power" */
1322 power = mbe_info[effect].power;
1325 if (!effect || check_hit2(power, rlev, ac, MON_STUNNED(m_ptr)))
1327 (void)set_monster_csleep(t_idx, 0);
1331 /* Redraw the health bar */
1332 if (p_ptr->health_who == t_idx) p_ptr->redraw |= (PR_HEALTH);
1333 if (p_ptr->riding == t_idx) p_ptr->redraw |= (PR_UHEALTH);
1336 /* Describe the attack method */
1341 act = _("%sを殴った。", "hits %s.");
1348 act = _("%sを触った。", "touches %s.");
1355 act = _("%sをパンチした。", "punches %s.");
1362 act = _("%sを蹴った。", "kicks %s.");
1369 act = _("%sをひっかいた。", "claws %s.");
1376 act = _("%sを噛んだ。", "bites %s.");
1383 act = _("%sを刺した。", "stings %s.");
1390 act = _("%sを斬った。", "slashes %s.");
1396 act = _("%sを角で突いた。", "butts %s.");
1403 act = _("%sに体当りした。", "crushes %s.");
1410 act = _("%sを飲み込んだ。", "engulfs %s.");
1417 act = _("%sに請求書をよこした。", "charges %s.");
1424 act = _("%sの体の上を這い回った。", "crawls on %s.");
1431 act = _("%sによだれをたらした。", "drools on %s.");
1438 act = _("%sに唾を吐いた。", "spits on %s.");
1445 if (see_either) disturb(TRUE, TRUE);
1446 act = _("爆発した。", "explodes.");
1454 act = _("%sをにらんだ。", "gazes at %s.");
1461 act = _("%sに泣きついた。", "wails at %s.");
1468 act = _("%sに胞子を飛ばした。", "releases spores at %s.");
1475 act = _("%sにXXX4を飛ばした。", "projects XXX4's at %s.");
1482 act = _("%sに金をせがんだ。", "begs %s for money.");
1489 act = _("%sを侮辱した。", "insults %s.");
1496 act = _("%sにむかってうめいた。", "moans at %s.");
1503 act = _("%sにむかって歌った。", "sings to %s.");
1509 if (act && see_either)
1512 if (do_silly_attack) act = silly_attacks2[randint0(MAX_SILLY_ATTACK)];
1513 strfmt(temp, act, t_name);
1514 msg_format("%^sは%s", m_name, temp);
1516 if (do_silly_attack)
1518 act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
1519 strfmt(temp, "%s %s.", act, t_name);
1521 else strfmt(temp, act, t_name);
1522 msg_format("%^s %s", m_name, temp);
1526 /* Hack -- assume all attacks are obvious */
1529 /* Roll out the damage */
1530 damage = damroll(d_dice, d_side);
1532 /* Assume no effect */
1533 effect_type = BLOW_EFFECT_TYPE_NONE;
1537 /* Apply appropriate damage */
1546 if ((randint1(rlev*2+250) > (ac+200)) || one_in_(13))
1548 int tmp_damage = damage - (damage * ((ac < 150) ? ac : 150) / 250);
1549 damage = MAX(damage, tmp_damage * 2);
1556 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1571 if ((p_ptr->riding != m_idx) && one_in_(2)) blinked = TRUE;
1607 effect_type = BLOW_EFFECT_TYPE_FEAR;
1611 effect_type = BLOW_EFFECT_TYPE_SLEEP;
1615 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1616 if (damage > 23) earthquake_aux(m_ptr->fy, m_ptr->fx, 8, m_idx);
1631 pt = GF_HYPODYNAMIA;
1632 effect_type = BLOW_EFFECT_TYPE_HEAL;
1650 /* Do damage if not exploding */
1653 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1654 damage, pt, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1657 switch (effect_type)
1659 case BLOW_EFFECT_TYPE_FEAR:
1660 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1661 damage, GF_TURN_ALL, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1664 case BLOW_EFFECT_TYPE_SLEEP:
1665 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1666 r_ptr->level, GF_OLD_SLEEP, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1669 case BLOW_EFFECT_TYPE_HEAL:
1670 if ((monster_living(m_idx)) && (damage > 2))
1672 bool did_heal = FALSE;
1674 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
1677 m_ptr->hp += damroll(4, damage / 6);
1678 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
1680 /* Redraw (later) if needed */
1681 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1682 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1684 /* Special message */
1685 if (see_m && did_heal)
1687 msg_format(_("%sは体力を回復したようだ。", "%^s appears healthier."), m_name);
1696 if ((tr_ptr->flags2 & RF2_AURA_FIRE) && m_ptr->r_idx)
1698 if (!(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
1702 msg_format(_("%^sは突然熱くなった!", "%^s is suddenly very hot!"), m_name);
1704 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_FIRE;
1705 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
1706 damroll (1 + ((tr_ptr->level) / 26),
1707 1 + ((tr_ptr->level) / 17)),
1708 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1712 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
1717 if ((tr_ptr->flags3 & RF3_AURA_COLD) && m_ptr->r_idx)
1719 if (!(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK))
1723 msg_format(_("%^sは突然寒くなった!", "%^s is suddenly very cold!"), m_name);
1725 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags3 |= RF3_AURA_COLD;
1726 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
1727 damroll (1 + ((tr_ptr->level) / 26),
1728 1 + ((tr_ptr->level) / 17)),
1729 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1733 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
1738 if ((tr_ptr->flags2 & RF2_AURA_ELEC) && m_ptr->r_idx)
1740 if (!(r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK))
1744 msg_format(_("%^sは電撃を食らった!", "%^s gets zapped!"), m_name);
1746 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_ELEC;
1747 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
1748 damroll (1 + ((tr_ptr->level) / 26),
1749 1 + ((tr_ptr->level) / 17)),
1750 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1754 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
1761 /* Monster missed player */
1764 /* Analyze failed attacks */
1780 (void)set_monster_csleep(t_idx, 0);
1782 /* Visible monsters */
1786 msg_format("%sは%^sの攻撃をかわした。", t_name, m_name);
1788 msg_format("%^s misses %s.", m_name, t_name);
1798 /* Analyze "visible" monsters only */
1799 if (is_original_ap_and_seen(m_ptr) && !do_silly_attack)
1801 /* Count "obvious" attacks (and ones that cause damage) */
1802 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
1804 /* Count attacks of this type */
1805 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
1807 r_ptr->r_blows[ap_cnt]++;
1815 sound(SOUND_EXPLODE);
1817 /* Cancel Invulnerability */
1818 (void)set_monster_invulner(m_idx, 0, FALSE);
1819 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
1824 if (blinked && m_ptr->r_idx)
1826 if (teleport_barrier(m_idx))
1830 msg_print(_("泥棒は笑って逃げ...ようとしたがバリアに防がれた。", "The thief flees laughing...? But magic barrier obstructs it."));
1841 msg_print(_("泥棒は笑って逃げた!", "The thief flees laughing!"));
1848 teleport_away(m_idx, MAX_SIGHT * 2 + 5, 0L);
1856 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
1858 return !have_flag(f_ptr->flags, FF_GLASS) ||
1859 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
1860 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
1865 * @brief モンスター単体の1ターン行動処理メインルーチン /
1867 * @param m_idx 行動モンスターの参照ID
1870 * The monster is known to be within 100 grids of the player\n
1872 * In several cases, we directly update the monster lore\n
1874 * Note that a monster is only allowed to "reproduce" if there\n
1875 * are a limited number of "reproducing" monsters on the current\n
1876 * level. This should prevent the level from being "swamped" by\n
1877 * reproducing monsters. It also allows a large mass of mice to\n
1878 * prevent a louse from multiplying, but this is a small price to\n
1879 * pay for a simple multiplication method.\n
1881 * XXX Monster fear is slightly odd, in particular, monsters will\n
1882 * fixate on opening a door even if they cannot open it. Actually,\n
1883 * the same thing happens to normal monsters when they hit a door\n
1885 * In addition, monsters which *cannot* open or bash\n
1886 * down a door will still stand there trying to open it...\n
1888 * XXX Technically, need to check for monster in the way\n
1889 * combined with that monster being in a wall (or door?)\n
1891 * A "direction" of "5" means "pick a random direction".\n
1893 void process_monster(MONSTER_IDX m_idx)
1895 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1896 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1897 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1900 POSITION oy, ox, ny, nx;
1905 feature_type *f_ptr;
1907 monster_type *y_ptr;
1912 bool must_alter_to_move;
1921 bool gets_angry = FALSE;
1926 bool is_riding_mon = (m_idx == p_ptr->riding);
1927 bool see_m = is_seen(m_ptr);
1929 if (is_riding_mon && !(r_ptr->flags7 & RF7_RIDING))
1931 if (rakuba(0, TRUE))
1934 msg_print("地面に落とされた。");
1936 GAME_TEXT m_name[MAX_NLEN];
1937 monster_desc(m_name, ¤t_floor_ptr->m_list[p_ptr->riding], 0);
1938 msg_format("You have fallen from %s.", m_name);
1943 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
1945 choose_new_monster(m_idx, FALSE, 0);
1946 r_ptr = &r_info[m_ptr->r_idx];
1949 /* Players hidden in shadow are almost imperceptable. -LM- */
1950 if (p_ptr->special_defense & NINJA_S_STEALTH)
1952 int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
1953 if (p_ptr->monlite) tmp /= 3;
1954 if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1955 if (r_ptr->level > (p_ptr->lev * p_ptr->lev / 20 + 10)) tmp /= 3;
1956 /* Low-level monsters will find it difficult to locate the player. */
1957 if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
1960 /* Are there its parent? */
1961 if (m_ptr->parent_m_idx && !current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx)
1963 /* Its parent have gone, it also goes away. */
1967 GAME_TEXT m_name[MAX_NLEN];
1968 monster_desc(m_name, m_ptr, 0);
1969 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1972 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1974 GAME_TEXT m_name[MAX_NLEN];
1975 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1976 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
1979 delete_monster_idx(m_idx);
1984 /* Quantum monsters are odd */
1985 if (r_ptr->flags2 & (RF2_QUANTUM))
1987 /* Sometimes skip move */
1988 if (!randint0(2)) return;
1991 if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
1995 if (is_pet(m_ptr) && !(m_ptr->ml)) sad = TRUE;
1999 GAME_TEXT m_name[MAX_NLEN];
2000 monster_desc(m_name, m_ptr, 0);
2002 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
2005 /* Generate treasure, etc */
2006 monster_death(m_idx, FALSE);
2008 delete_monster_idx(m_idx);
2011 msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
2018 if (m_ptr->r_idx == MON_SHURYUUDAN)
2020 mon_take_hit_mon(m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
2024 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) && !p_ptr->inside_battle)
2026 static int riding_pinch = 0;
2028 if (m_ptr->hp < m_ptr->maxhp/3)
2030 GAME_TEXT m_name[MAX_NLEN];
2031 monster_desc(m_name, m_ptr, 0);
2033 if (is_riding_mon && riding_pinch < 2)
2035 msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
2036 "%^s seems to be in so much pain, and trying to escape from your restriction."), m_name);
2038 disturb(TRUE, TRUE);
2044 msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
2045 if (rakuba(-1, FALSE))
2047 msg_print(_("地面に落とされた。", "You have fallen from riding pet."));
2053 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) &&
2054 player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x))
2056 msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
2058 msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s read a scroll of teleport level."), m_name);
2059 msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
2062 if (is_riding_mon && rakuba(-1, FALSE))
2064 msg_print(_("地面に落とされた。", "You have fallen from riding pet."));
2067 check_quest_completion(m_ptr);
2068 delete_monster_idx(m_idx);
2074 /* Reset the counter */
2075 if (is_riding_mon) riding_pinch = 0;
2079 /* Handle "sleep" */
2080 if (MON_CSLEEP(m_ptr))
2082 /* Handle non-aggravation - Still sleeping */
2083 if (!(p_ptr->cursed & TRC_AGGRAVATE)) return;
2085 (void)set_monster_csleep(m_idx, 0);
2087 /* Notice the "waking up" */
2090 GAME_TEXT m_name[MAX_NLEN];
2091 monster_desc(m_name, m_ptr, 0);
2092 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
2095 /* Hack -- Count the wakings */
2096 if (is_original_ap_and_seen(m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
2103 if (MON_STUNNED(m_ptr))
2105 /* Sometimes skip move */
2106 if (one_in_(2)) return;
2111 p_ptr->update |= (PU_BONUS);
2114 /* No one wants to be your friend if you're aggravating */
2115 if (is_friendly(m_ptr) && (p_ptr->cursed & TRC_AGGRAVATE))
2118 /* Paranoia... no pet uniques outside wizard mode -- TY */
2119 if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
2120 monster_has_hostile_align(NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
2125 if (p_ptr->inside_battle) gets_angry = FALSE;
2129 if (is_pet(m_ptr) || see_m)
2131 GAME_TEXT m_name[MAX_NLEN];
2132 monster_desc(m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
2133 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
2139 /* Get the origin */
2143 /* Attempt to "multiply" if able and allowed */
2144 if ((r_ptr->flags2 & RF2_MULTIPLY) && (current_floor_ptr->num_repro < MAX_REPRO))
2149 /* Count the adjacent monsters */
2150 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2152 for (x = ox - 1; x <= ox + 1; x++)
2154 /* Ignore locations off of edge */
2155 if (!in_bounds2(y, x)) continue;
2156 if (current_floor_ptr->grid_array[y][x].m_idx) k++;
2161 if (multiply_barrier(m_idx)) k = 8;
2163 /* Hack -- multiply slower in crowded areas */
2164 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
2166 /* Try to multiply */
2167 if (multiply_monster(m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
2169 /* Take note if visible */
2170 if (current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(m_ptr))
2172 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2175 /* Multiplying takes energy */
2181 if (r_ptr->a_ability_flags2 & RF6_SPECIAL)
2183 /* Hack -- Ohmu scatters molds! */
2184 if (m_ptr->r_idx == MON_OHMU)
2186 if (!p_ptr->inside_arena && !p_ptr->inside_battle)
2188 if (r_ptr->freq_spell && (randint1(100) <= r_ptr->freq_spell))
2191 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
2192 BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
2194 for (k = 0; k < A_MAX; k++)
2196 if (summon_specific(m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode), '\0'))
2198 if (current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
2202 if (count && is_original_ap_and_seen(m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
2208 if (!p_ptr->inside_battle)
2210 /* Hack! "Cyber" monster makes noise... */
2211 if (m_ptr->ap_r_idx == MON_CYBER &&
2212 one_in_(CYBERNOISE) &&
2213 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2215 if (disturb_minor) disturb(FALSE, FALSE);
2216 msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
2219 /* Some monsters can speak */
2220 if ((ap_r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2221 one_in_(SPEAK_CHANCE) &&
2222 player_has_los_bold(oy, ox) &&
2223 projectable(oy, ox, p_ptr->y, p_ptr->x))
2225 GAME_TEXT m_name[MAX_NLEN];
2226 char monmessage[1024];
2229 /* Acquire the monster name/poss */
2231 monster_desc(m_name, m_ptr, 0);
2233 strcpy(m_name, _("それ", "It"));
2235 /* Select the file for monster quotes */
2236 if (MON_MONFEAR(m_ptr))
2237 filename = _("monfear_j.txt", "monfear.txt");
2238 else if (is_pet(m_ptr))
2239 filename = _("monpet_j.txt", "monpet.txt");
2240 else if (is_friendly(m_ptr))
2241 filename = _("monfrien_j.txt", "monfrien.txt");
2243 filename = _("monspeak_j.txt", "monspeak.txt");
2244 /* Get the monster line */
2245 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
2248 msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
2253 /* Try to cast spell occasionally */
2254 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
2256 bool counterattack = FALSE;
2258 /* Give priority to counter attack? */
2259 if (m_ptr->target_y)
2261 MONSTER_IDX t_m_idx = current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
2263 /* The monster must be an enemy, and projectable */
2264 if (t_m_idx && are_enemies(m_ptr, ¤t_floor_ptr->m_list[t_m_idx]) &&
2265 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
2267 counterattack = TRUE;
2273 /* Attempt to cast a spell */
2274 if (aware && make_attack_spell(m_idx)) return;
2277 * Attempt to cast a spell at an enemy other than the player
2278 * (may slow the game a smidgeon, but I haven't noticed.)
2280 if (monst_spell_monst(m_idx)) return;
2284 /* Attempt to do counter attack at first */
2285 if (monst_spell_monst(m_idx)) return;
2287 if (aware && make_attack_spell(m_idx)) return;
2291 /* Hack -- Assume no movement */
2292 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2293 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2296 /* Confused -- 100% random */
2297 if (MON_CONFUSED(m_ptr) || !aware)
2299 /* Try four "random" directions */
2300 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2303 /* 75% random movement */
2304 else if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) &&
2305 (randint0(100) < 75))
2307 /* Memorize flags */
2308 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
2310 /* Try four "random" directions */
2311 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2314 /* 50% random movement */
2315 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2316 (randint0(100) < 50))
2318 /* Memorize flags */
2319 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
2321 /* Try four "random" directions */
2322 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2325 /* 25% random movement */
2326 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2327 (randint0(100) < 25))
2329 /* Memorize flags */
2330 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
2332 /* Try four "random" directions */
2333 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2336 /* Can't reach player - find something else to hit */
2337 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2339 /* Try four "random" directions */
2340 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2342 /* Look for an enemy */
2343 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2344 get_enemy_dir(m_idx, mm);
2348 /* Pets will follow the player */
2349 else if (is_pet(m_ptr))
2351 /* Are we trying to avoid the player? */
2352 bool avoid = ((p_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2354 /* Do we want to find the player? */
2355 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
2357 /* Should we find the player if we can't find a monster? */
2358 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2360 /* by default, move randomly */
2361 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2363 /* Look for an enemy */
2364 if (!get_enemy_dir(m_idx, mm))
2366 /* Find the player if necessary */
2367 if (avoid || lonely || distant)
2369 /* Remember the leash length */
2370 POSITION dis = p_ptr->pet_follow_distance;
2372 /* Hack -- adjust follow distance temporarily */
2373 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
2375 p_ptr->pet_follow_distance = PET_SEEK_DIST;
2378 /* Find the player */
2379 (void)get_moves(m_idx, mm);
2381 /* Restore the leash */
2382 p_ptr->pet_follow_distance = (s16b)dis;
2387 /* Friendly monster movement */
2388 else if (!is_hostile(m_ptr))
2390 /* by default, move randomly */
2391 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2393 /* Look for an enemy */
2394 get_enemy_dir(m_idx, mm);
2396 /* Normal movement */
2399 /* Logical moves, may do nothing */
2400 if (!get_moves(m_idx, mm)) return;
2403 /* Assume nothing */
2407 must_alter_to_move = FALSE;
2409 /* Assume nothing */
2410 did_open_door = FALSE;
2411 did_bash_door = FALSE;
2412 did_take_item = FALSE;
2413 did_kill_item = FALSE;
2414 did_move_body = FALSE;
2415 did_pass_wall = FALSE;
2416 did_kill_wall = FALSE;
2418 /* Take a zero-terminated array of "directions" */
2419 for (i = 0; mm[i]; i++)
2421 /* Get the direction */
2424 /* Hack -- allow "randomized" motion */
2425 if (d == 5) d = ddd[randint0(8)];
2427 /* Get the destination */
2431 /* Ignore locations off of edge */
2432 if (!in_bounds2(ny, nx)) continue;
2434 /* Access that grid */
2435 g_ptr = ¤t_floor_ptr->grid_array[ny][nx];
2436 f_ptr = &f_info[g_ptr->feat];
2437 can_cross = monster_can_cross_terrain(g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0);
2439 /* Access that grid's contents */
2440 y_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
2442 /* Hack -- player 'in' wall */
2443 if (player_bold(ny, nx))
2448 /* Possibly a monster to attack */
2449 else if (g_ptr->m_idx)
2454 /* Monster destroys walls (and doors) */
2455 else if ((r_ptr->flags2 & RF2_KILL_WALL) &&
2456 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !is_riding_mon) &&
2457 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
2458 check_hp_for_feat_destruction(f_ptr, m_ptr))
2460 /* Eat through walls/doors/rubble */
2462 if (!can_cross) must_alter_to_move = TRUE;
2464 /* Monster destroyed a wall (later) */
2465 did_kill_wall = TRUE;
2468 /* Floor is open? */
2471 /* Go ahead and move */
2474 /* Monster moves through walls (and doors) */
2475 if ((r_ptr->flags2 & RF2_PASS_WALL) && (!is_riding_mon || p_ptr->pass_wall) &&
2476 have_flag(f_ptr->flags, FF_CAN_PASS))
2478 /* Monster went through a wall */
2479 did_pass_wall = TRUE;
2483 /* Handle doors and secret doors */
2484 else if (is_closed_door(g_ptr->feat))
2486 bool may_bash = TRUE;
2488 /* Assume no move allowed */
2491 /* Creature can open doors. */
2492 if ((r_ptr->flags2 & RF2_OPEN_DOOR) && have_flag(f_ptr->flags, FF_OPEN) &&
2493 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2498 /* The door is open */
2499 did_open_door = TRUE;
2501 /* Do not bash the door */
2507 /* Locked doors (not jammed) */
2510 /* Try to unlock it */
2511 if (randint0(m_ptr->hp / 10) > f_ptr->power)
2513 /* Unlock the door */
2514 cave_alter_feat(ny, nx, FF_DISARM);
2516 /* Do not bash the door */
2524 /* Stuck doors -- attempt to bash them down if allowed */
2525 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) && have_flag(f_ptr->flags, FF_BASH) &&
2526 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2528 /* Attempt to Bash */
2529 if (check_hp_for_feat_destruction(f_ptr, m_ptr) && (randint0(m_ptr->hp / 10) > f_ptr->power))
2531 if (have_flag(f_ptr->flags, FF_GLASS))
2532 msg_print(_("ガラスが砕ける音がした!", "You hear a glass was crashed!"));
2534 msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
2536 /* Disturb (sometimes) */
2537 if (disturb_minor) disturb(FALSE, FALSE);
2539 /* The door was bashed open */
2540 did_bash_door = TRUE;
2542 /* Hack -- fall into doorway */
2544 must_alter_to_move = TRUE;
2549 /* Deal with doors in the way */
2550 if (did_open_door || did_bash_door)
2552 /* Break down the door */
2553 if (did_bash_door && ((randint0(100) < 50) || (feat_state(g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
2555 cave_alter_feat(ny, nx, FF_BASH);
2557 if (!monster_is_valid(m_ptr)) /* Killed by shards of glass, etc. */
2559 p_ptr->update |= (PU_FLOW);
2560 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2561 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2570 cave_alter_feat(ny, nx, FF_OPEN);
2573 f_ptr = &f_info[g_ptr->feat];
2575 /* Handle viewable doors */
2580 /* Hack -- check for Glyph of Warding */
2581 if (do_move && is_glyph_grid(g_ptr) &&
2582 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
2584 /* Assume no move allowed */
2587 /* Break the ward */
2588 if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
2590 /* Describe observable breakage */
2591 if (g_ptr->info & CAVE_MARK)
2593 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2596 /* Forget the rune */
2597 g_ptr->info &= ~(CAVE_MARK);
2599 /* Break the rune */
2600 g_ptr->info &= ~(CAVE_OBJECT);
2603 /* Allow movement */
2609 else if (do_move && is_explosive_rune_grid(g_ptr) &&
2610 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
2612 /* Assume no move allowed */
2615 /* Break the ward */
2618 /* Break the ward */
2619 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2621 /* Describe observable breakage */
2622 if (g_ptr->info & CAVE_MARK)
2624 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2625 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);
2630 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2633 /* Forget the rune */
2634 g_ptr->info &= ~(CAVE_MARK);
2636 /* Break the rune */
2637 g_ptr->info &= ~(CAVE_OBJECT);
2643 if (!monster_is_valid(m_ptr)) return;
2644 /* Allow movement */
2649 /* The player is in the way */
2650 if (do_move && player_bold(ny, nx))
2652 /* Some monsters never attack */
2653 if (r_ptr->flags1 & RF1_NEVER_BLOW)
2655 /* Hack -- memorize lack of attacks */
2656 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
2662 /* In anti-melee dungeon, stupid or confused monster takes useless current_world_ptr->game_turn */
2663 if (do_move && (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE))
2665 if (!MON_CONFUSED(m_ptr))
2667 if (!(r_ptr->flags2 & RF2_STUPID)) do_move = FALSE;
2670 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
2675 /* The player is in the way. Attack him. */
2678 if (!p_ptr->riding || one_in_(2))
2681 (void)make_attack_normal(m_idx);
2686 /* Took a current_world_ptr->game_turn */
2692 /* A monster is in the way */
2693 if (do_move && g_ptr->m_idx)
2695 monster_race *z_ptr = &r_info[y_ptr->r_idx];
2697 /* Assume no movement */
2700 /* Attack 'enemies' */
2701 if (((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW) &&
2702 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
2703 can_cross && (g_ptr->m_idx != p_ptr->riding)) ||
2704 are_enemies(m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
2706 if (!(r_ptr->flags1 & RF1_NEVER_BLOW))
2708 if (r_ptr->flags2 & RF2_KILL_BODY)
2710 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_BODY);
2714 if (y_ptr->r_idx && (y_ptr->hp >= 0))
2716 if (monst_attack_monst(m_idx, g_ptr->m_idx)) return;
2718 /* In anti-melee dungeon, stupid or confused monster takes useless current_world_ptr->game_turn */
2719 else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE)
2721 if (MON_CONFUSED(m_ptr)) return;
2722 else if (r_ptr->flags2 & RF2_STUPID)
2724 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
2732 /* Push past weaker monsters (unless leaving a wall) */
2733 else if ((r_ptr->flags2 & RF2_MOVE_BODY) && !(r_ptr->flags1 & RF1_NEVER_MOVE) &&
2734 (r_ptr->mexp > z_ptr->mexp) &&
2735 can_cross && (g_ptr->m_idx != p_ptr->riding) &&
2736 monster_can_cross_terrain(current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
2738 /* Allow movement */
2741 /* Monster pushed past another monster */
2742 did_move_body = TRUE;
2744 /* Wake up the moved monster */
2745 (void)set_monster_csleep(g_ptr->m_idx, 0);
2753 if (!p_ptr->riding_ryoute && !MON_MONFEAR(¤t_floor_ptr->m_list[p_ptr->riding])) do_move = FALSE;
2756 if (did_kill_wall && do_move)
2758 if (one_in_(GRINDNOISE))
2760 if (have_flag(f_ptr->flags, FF_GLASS))
2761 msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
2763 msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
2766 cave_alter_feat(ny, nx, FF_HURT_DISI);
2768 if (!monster_is_valid(m_ptr)) /* Killed by shards of glass, etc. */
2770 p_ptr->update |= (PU_FLOW);
2771 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2772 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2777 f_ptr = &f_info[g_ptr->feat];
2779 /* Note changes to viewable region */
2784 if (must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
2786 if (!monster_can_cross_terrain(g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0))
2788 /* Assume no move allowed */
2794 * Check if monster can cross terrain
2795 * This is checked after the normal attacks
2796 * to allow monsters to attack an enemy,
2797 * even if it can't enter the terrain.
2799 if (do_move && !can_cross && !did_kill_wall && !did_bash_door)
2801 /* Assume no move allowed */
2805 /* Some monsters never move */
2806 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
2808 /* Hack -- memorize lack of moves */
2809 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
2815 /* Creature has been allowed move */
2820 if (have_flag(f_ptr->flags, FF_TREE))
2822 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
2824 m_ptr->energy_need += ENERGY_NEED();
2830 /* Hack -- Update the old location */
2831 current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
2833 /* Mega-Hack -- move the old monster, if any */
2836 /* Move the old monster */
2840 /* Update the old monster */
2841 update_monster(g_ptr->m_idx, TRUE);
2844 /* Hack -- Update the new location */
2845 g_ptr->m_idx = m_idx;
2847 /* Move the monster */
2850 update_monster(m_idx, TRUE);
2857 /* sound(SOUND_WALK); */
2858 if (!move_player_effect(ny, nx, MPE_DONT_PICKUP)) break;
2861 /* Possible disturb */
2864 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) ||
2865 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)))
2867 if (is_hostile(m_ptr))
2868 disturb(FALSE, TRUE);
2871 /* Take or Kill objects on the floor */
2872 if (g_ptr->o_idx && (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
2873 (!is_pet(m_ptr) || ((p_ptr->pet_extra_flags & PF_PICKUP_ITEMS) && (r_ptr->flags2 & RF2_TAKE_ITEM))))
2875 OBJECT_IDX this_o_idx, next_o_idx;
2876 bool do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) ? TRUE : FALSE;
2878 /* Scan all objects in the grid */
2879 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2881 BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
2882 GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
2883 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
2884 next_o_idx = o_ptr->next_o_idx;
2889 if (o_ptr->tval == TV_GOLD) continue;
2892 * Skip "real" corpses and statues, to avoid extreme
2893 * silliness like a novice rogue pockets full of statues
2896 if ((o_ptr->tval == TV_CORPSE) ||
2897 (o_ptr->tval == TV_STATUE)) continue;
2900 /* Extract some flags */
2901 object_flags(o_ptr, flgs);
2903 /* Acquire the object name */
2904 object_desc(o_name, o_ptr, 0);
2905 monster_desc(m_name, m_ptr, MD_INDEF_HIDDEN);
2907 /* React to objects that hurt the monster */
2908 if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
2909 if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
2910 if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
2911 if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
2912 if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
2913 if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
2914 if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
2915 if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
2916 if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
2917 if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
2918 if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
2919 if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
2920 if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
2921 if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
2922 if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
2923 if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
2924 if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
2925 if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
2926 if (have_flag(flgs, TR_BRAND_ACID)) flgr |= (RFR_IM_ACID);
2927 if (have_flag(flgs, TR_BRAND_ELEC)) flgr |= (RFR_IM_ELEC);
2928 if (have_flag(flgs, TR_BRAND_FIRE)) flgr |= (RFR_IM_FIRE);
2929 if (have_flag(flgs, TR_BRAND_COLD)) flgr |= (RFR_IM_COLD);
2930 if (have_flag(flgs, TR_BRAND_POIS)) flgr |= (RFR_IM_POIS);
2932 /* The object cannot be picked up by the monster */
2933 if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
2934 ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
2936 /* Only give a message for "take_item" */
2937 if (do_take && (r_ptr->flags2 & RF2_STUPID))
2939 did_take_item = TRUE;
2941 /* Describe observable situations */
2942 if (m_ptr->ml && player_can_see_bold(ny, nx))
2944 msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
2949 /* Pick up the item */
2952 did_take_item = TRUE;
2954 /* Describe observable situations */
2955 if (player_can_see_bold(ny, nx))
2957 msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
2960 /* Excise the object */
2961 excise_object_idx(this_o_idx);
2964 o_ptr->marked &= OM_TOUCHED;
2966 /* Forget location */
2967 o_ptr->iy = o_ptr->ix = 0;
2969 /* Memorize monster */
2970 o_ptr->held_m_idx = m_idx;
2973 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2976 m_ptr->hold_o_idx = this_o_idx;
2979 /* Destroy the item if not a pet */
2980 else if (!is_pet(m_ptr))
2982 did_kill_item = TRUE;
2984 /* Describe observable situations */
2985 if (player_has_los_bold(ny, nx))
2987 msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
2990 delete_object_idx(this_o_idx);
2996 /* Stop when done */
3001 * Forward movements failed, but now received LOS attack!
3002 * Try to flow by smell.
3004 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3005 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3007 /* If we haven't done anything, try casting a spell again */
3008 if (!do_turn && !do_move && !MON_MONFEAR(m_ptr) && !is_riding_mon && aware)
3010 /* Try to cast spell again */
3011 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
3013 if (make_attack_spell(m_idx)) return;
3018 /* Notice changes in view */
3021 p_ptr->update |= (PU_FLOW);
3022 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3025 /* Notice changes in view */
3026 if (do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
3027 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !p_ptr->inside_battle)))
3029 p_ptr->update |= (PU_MON_LITE);
3032 /* Learn things from observable monster */
3033 if (is_original_ap_and_seen(m_ptr))
3035 /* Monster opened a door */
3036 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3038 /* Monster bashed a door */
3039 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3041 /* Monster tried to pick something up */
3042 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3044 /* Monster tried to crush something */
3045 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3047 /* Monster pushed past another monster */
3048 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3050 /* Monster passed through a wall */
3051 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3053 /* Monster destroyed a wall */
3054 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3058 /* Hack -- get "bold" if out of options */
3059 if (!do_turn && !do_move && MON_MONFEAR(m_ptr) && aware)
3061 /* No longer afraid */
3062 (void)set_monster_monfear(m_idx, 0);
3064 /* Message if seen */
3067 GAME_TEXT m_name[MAX_NLEN];
3068 monster_desc(m_name, m_ptr, 0);
3069 msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
3072 if (m_ptr->ml) chg_virtue(V_COMPASSION, -1);
3074 /* Actually do something now (?) */
3079 * @brief 全モンスターのターン管理メインルーチン /
3080 * Process all the "live" monsters, once per game current_world_ptr->game_turn.
3083 * During each game current_world_ptr->game_turn, we scan through the list of all the "live" monsters,\n
3084 * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
3085 * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
3087 * Note that monsters can never move in the monster array (except when the\n
3088 * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
3090 * This function is responsible for at least half of the processor time\n
3091 * on a normal system with a "normal" amount of monsters and a player doing\n
3094 * When the player is resting, virtually 90% of the processor time is spent\n
3095 * in this function, and its children, "process_monster()" and "make_move()".\n
3097 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
3098 * especially when the player is running.\n
3100 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
3101 * monsters while they are still being "born". A monster is "fresh" only\n
3102 * during the current_world_ptr->game_turn in which it is created, and we use the "hack_m_idx" to\n
3103 * determine if the monster is yet to be processed during the current current_world_ptr->game_turn.\n
3105 * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
3106 * move before any "nasty" monsters get to use their spell attacks.\n
3108 * Note that when the "knowledge" about the currently tracked monster\n
3109 * changes (flags, attacks, spells), we induce a redraw of the monster\n
3112 void process_monsters(void)
3119 monster_type *m_ptr;
3120 monster_race *r_ptr;
3122 MONRACE_IDX old_monster_race_idx;
3124 BIT_FLAGS old_r_flags1 = 0L;
3125 BIT_FLAGS old_r_flags2 = 0L;
3126 BIT_FLAGS old_r_flags3 = 0L;
3127 BIT_FLAGS old_r_flags4 = 0L;
3128 BIT_FLAGS old_r_flags5 = 0L;
3129 BIT_FLAGS old_r_flags6 = 0L;
3130 BIT_FLAGS old_r_flagsr = 0L;
3132 byte old_r_blows0 = 0;
3133 byte old_r_blows1 = 0;
3134 byte old_r_blows2 = 0;
3135 byte old_r_blows3 = 0;
3137 byte old_r_cast_spell = 0;
3141 /* Clear monster fighting indicator */
3144 /* Memorize old race */
3145 old_monster_race_idx = p_ptr->monster_race_idx;
3147 /* Acquire knowledge */
3148 if (p_ptr->monster_race_idx)
3150 /* Acquire current monster */
3151 r_ptr = &r_info[p_ptr->monster_race_idx];
3153 /* Memorize flags */
3154 old_r_flags1 = r_ptr->r_flags1;
3155 old_r_flags2 = r_ptr->r_flags2;
3156 old_r_flags3 = r_ptr->r_flags3;
3157 old_r_flags4 = r_ptr->r_flags4;
3158 old_r_flags5 = r_ptr->r_flags5;
3159 old_r_flags6 = r_ptr->r_flags6;
3160 old_r_flagsr = r_ptr->r_flagsr;
3162 /* Memorize blows */
3163 old_r_blows0 = r_ptr->r_blows[0];
3164 old_r_blows1 = r_ptr->r_blows[1];
3165 old_r_blows2 = r_ptr->r_blows[2];
3166 old_r_blows3 = r_ptr->r_blows[3];
3168 /* Memorize castings */
3169 old_r_cast_spell = r_ptr->r_cast_spell;
3173 /* Process the monsters (backwards) */
3174 for (i = m_max - 1; i >= 1; i--)
3176 /* Access the monster */
3177 m_ptr = ¤t_floor_ptr->m_list[i];
3178 r_ptr = &r_info[m_ptr->r_idx];
3180 /* Handle "leaving" */
3181 if (p_ptr->leaving) break;
3183 /* Ignore "dead" monsters */
3184 if (!monster_is_valid(m_ptr)) continue;
3186 if (p_ptr->wild_mode) continue;
3189 /* Handle "fresh" monsters */
3190 if (m_ptr->mflag & MFLAG_BORN)
3192 /* No longer "fresh" */
3193 m_ptr->mflag &= ~(MFLAG_BORN);
3199 /* Hack -- Require proximity */
3200 if (m_ptr->cdis >= AAF_LIMIT) continue;
3205 /* Flow by smell is allowed */
3206 if (!p_ptr->no_flowed)
3208 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3211 /* Assume no move */
3214 /* Handle "sensing radius" */
3215 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
3217 /* We can "sense" the player */
3221 /* Handle "sight" and "aggravation" */
3222 else if ((m_ptr->cdis <= MAX_SIGHT || p_ptr->inside_battle) &&
3223 (player_has_los_bold(fy, fx) || (p_ptr->cursed & TRC_AGGRAVATE)))
3225 /* We can "see" or "feel" the player */
3229 #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... */
3230 /* Hack -- Monsters can "smell" the player from far away */
3231 /* Note that most monsters have "aaf" of "20" or so */
3232 else if (!(m_ptr->mflag2 & MFLAG2_NOFLOW) &&
3233 cave_have_flag_bold(p_ptr->y, p_ptr->x, FF_MOVE) &&
3234 (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].when == current_floor_ptr->grid_array[fy][fx].when) &&
3235 (current_floor_ptr->grid_array[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3236 (current_floor_ptr->grid_array[fy][fx].dist < r_ptr->aaf))
3238 /* We can "smell" the player */
3242 else if (m_ptr->target_y) test = TRUE;
3245 if (!test) continue;
3248 if (p_ptr->riding == i)
3249 speed = p_ptr->pspeed;
3252 speed = m_ptr->mspeed;
3254 /* Monsters move quickly in Nightmare mode */
3255 if (ironman_nightmare) speed += 5;
3257 if (MON_FAST(m_ptr)) speed += 10;
3258 if (MON_SLOW(m_ptr)) speed -= 10;
3261 /* Give this monster some energy */
3262 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
3264 /* Not enough energy to move */
3265 if (m_ptr->energy_need > 0) continue;
3267 /* Use up "some" energy */
3268 m_ptr->energy_need += ENERGY_NEED();
3271 /* Save global index */
3274 /* Process the monster */
3277 reset_target(m_ptr);
3279 /* Give up flow_by_smell when it might useless */
3280 if (p_ptr->no_flowed && one_in_(3))
3281 m_ptr->mflag2 |= MFLAG2_NOFLOW;
3283 /* Hack -- notice death or departure */
3284 if (!p_ptr->playing || p_ptr->is_dead) break;
3286 /* Notice leaving */
3287 if (p_ptr->leaving) break;
3290 /* Reset global index */
3294 /* Tracking a monster race (the same one we were before) */
3295 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
3297 /* Acquire monster race */
3298 r_ptr = &r_info[p_ptr->monster_race_idx];
3300 /* Check for knowledge change */
3301 if ((old_r_flags1 != r_ptr->r_flags1) ||
3302 (old_r_flags2 != r_ptr->r_flags2) ||
3303 (old_r_flags3 != r_ptr->r_flags3) ||
3304 (old_r_flags4 != r_ptr->r_flags4) ||
3305 (old_r_flags5 != r_ptr->r_flags5) ||
3306 (old_r_flags6 != r_ptr->r_flags6) ||
3307 (old_r_flagsr != r_ptr->r_flagsr) ||
3308 (old_r_blows0 != r_ptr->r_blows[0]) ||
3309 (old_r_blows1 != r_ptr->r_blows[1]) ||
3310 (old_r_blows2 != r_ptr->r_blows[2]) ||
3311 (old_r_blows3 != r_ptr->r_blows[3]) ||
3312 (old_r_cast_spell != r_ptr->r_cast_spell))
3314 p_ptr->window |= (PW_MONSTER);