2 * @file monster-process.c
3 * @brief モンスターの特殊技能とターン経過処理 (移動等)/ Monster spells and movement for passaging a turn
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7 * This software may be copied and distributed for educational, research,\n
8 * and not for profit purposes provided that this copyright and statement\n
9 * are included in all such copies. Other copyrights may also apply.\n
10 * 2014 Deskull rearranged comment for Doxygen.\n
12 * This file has several additions to it by Keldon Jones (keldon@umr.edu)
13 * to improve the general quality of the AI (version 0.1.1).
24 #include "spells-floor.h"
25 #include "spells-summon.h"
28 #include "realm-hex.h"
29 #include "object-flavor.h"
30 #include "object-hook.h"
33 #include "player-move.h"
34 #include "monster-status.h"
35 #include "monster-spell.h"
36 #include "monster-process.h"
37 #include "monsterrace-hook.h"
41 #include "view-mainwindow.h"
51 bool must_alter_to_move;
62 turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr);
64 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
65 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx);
66 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
67 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx);
68 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
69 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
70 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
71 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
72 bool explode_monster(player_type *target_ptr, MONSTER_IDX m_idx);
73 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
74 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware);
75 bool runaway_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
76 void escape_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, GAME_TEXT *m_name);
77 void process_special(player_type *target_ptr, MONSTER_IDX m_idx);
78 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware);
79 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware);
81 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross);
82 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
83 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
84 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash);
85 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
86 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
88 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
89 bool process_monster_attack_to_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, grid_type *g_ptr, bool can_cross);
90 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr);
92 bool process_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, DIRECTION *mm, POSITION oy, POSITION ox, int *count);
93 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
94 bool update_riding_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, POSITION ny, POSITION nx);
96 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
98 void update_player_type(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_race *r_ptr);
99 void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr);
100 void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr);
101 void monster_pickup_object(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, object_type *o_ptr, bool is_special_object, POSITION ny, POSITION nx, GAME_TEXT *m_name, GAME_TEXT *o_name, OBJECT_IDX this_o_idx);
102 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
105 * @brief モンスターが敵に接近するための方向を決める /
106 * Calculate the direction to the next enemy
107 * @param target_ptr プレーヤーへの参照ポインタ
108 * @param m_idx モンスターの参照ID
109 * @param mm 移動するべき方角IDを返す参照ポインタ
110 * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
112 static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
114 floor_type *floor_ptr = target_ptr->current_floor_ptr;
115 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
116 monster_race *r_ptr = &r_info[m_ptr->r_idx];
118 POSITION x = 0, y = 0;
119 if (target_ptr->riding_t_m_idx && player_bold(target_ptr, m_ptr->fy, m_ptr->fx))
121 y = floor_ptr->m_list[target_ptr->riding_t_m_idx].fy;
122 x = floor_ptr->m_list[target_ptr->riding_t_m_idx].fx;
124 else if (is_pet(m_ptr) && target_ptr->pet_t_m_idx)
126 y = floor_ptr->m_list[target_ptr->pet_t_m_idx].fy;
127 x = floor_ptr->m_list[target_ptr->pet_t_m_idx].fx;
133 if (target_ptr->phase_out)
135 start = randint1(floor_ptr->m_max - 1) + floor_ptr->m_max;
136 if (randint0(2)) plus = -1;
140 start = floor_ptr->m_max + 1;
143 for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus)
145 MONSTER_IDX dummy = (i % floor_ptr->m_max);
146 if (!dummy) continue;
148 MONSTER_IDX t_idx = dummy;
150 t_ptr = &floor_ptr->m_list[t_idx];
152 if (t_ptr == m_ptr) continue;
153 if (!monster_is_valid(t_ptr)) continue;
157 if (target_ptr->pet_follow_distance < 0)
159 if (t_ptr->cdis <= (0 - target_ptr->pet_follow_distance))
164 else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > target_ptr->pet_follow_distance))
169 if (r_ptr->aaf < t_ptr->cdis) continue;
172 if (!are_enemies(target_ptr, m_ptr, t_ptr)) continue;
174 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) ||
175 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)))
177 if (!in_disintegration_range(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
181 if (!projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
190 if (!x && !y) return FALSE;
196 /* North, South, East, West, North-West, North-East, South-West, South-East */
197 if ((y < 0) && (x == 0))
203 else if ((y > 0) && (x == 0))
209 else if ((x > 0) && (y == 0))
215 else if ((x < 0) && (y == 0))
221 else if ((y < 0) && (x < 0))
227 else if ((y < 0) && (x > 0))
233 else if ((y > 0) && (x < 0))
239 else if ((y > 0) && (x > 0))
251 * @brief モンスターがプレイヤーから逃走するかどうかを返す /
252 * Returns whether a given monster will try to run from the player.
253 * @param m_idx 逃走するモンスターの参照ID
254 * @return モンスターがプレイヤーから逃走するならばTRUEを返す。
256 * Monsters will attempt to avoid very powerful players. See below.\n
258 * Because this function is called so often, little details are important\n
259 * for efficiency. Like not using "mod" or "div" when possible. And\n
260 * attempting to check the conditions in an optimal order. Note that\n
261 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
263 * Note that this function is responsible for about one to five percent\n
264 * of the processor use in normal conditions...\n
266 static bool mon_will_run(player_type *target_ptr, MONSTER_IDX m_idx)
268 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
269 monster_race *r_ptr = &r_info[m_ptr->r_idx];
273 return ((target_ptr->pet_follow_distance < 0) &&
274 (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
277 if (m_ptr->cdis > MAX_SIGHT + 5) return FALSE;
278 if (MON_MONFEAR(m_ptr)) return TRUE;
279 if (m_ptr->cdis <= 5) return FALSE;
281 PLAYER_LEVEL p_lev = target_ptr->lev;
282 DEPTH m_lev = r_ptr->level + (m_idx & 0x08) + 25;
283 if (m_lev > p_lev + 4) return FALSE;
284 if (m_lev + 4 <= p_lev) return TRUE;
286 HIT_POINT p_chp = target_ptr->chp;
287 HIT_POINT p_mhp = target_ptr->mhp;
288 HIT_POINT m_chp = m_ptr->hp;
289 HIT_POINT m_mhp = m_ptr->maxhp;
290 u32b p_val = (p_lev * p_mhp) + (p_chp << 2);
291 u32b m_val = (m_lev * m_mhp) + (m_chp << 2);
292 if (p_val * m_mhp > m_val * p_mhp) return TRUE;
299 * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
300 * Search spell castable grid
301 * @param target_ptr プレーヤーへの参照ポインタ
302 * @param m_idx モンスターの参照ID
303 * @param yp 適したマスのY座標を返す参照ポインタ
304 * @param xp 適したマスのX座標を返す参照ポインタ
305 * @return 有効なマスがあった場合TRUEを返す
307 static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
309 floor_type *floor_ptr = target_ptr->current_floor_ptr;
310 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
311 monster_race *r_ptr = &r_info[m_ptr->r_idx];
313 POSITION y1 = m_ptr->fy;
314 POSITION x1 = m_ptr->fx;
316 if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x)) return FALSE;
318 int now_cost = floor_ptr->grid_array[y1][x1].cost;
319 if (now_cost == 0) now_cost = 999;
321 bool can_open_door = FALSE;
322 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
324 can_open_door = TRUE;
328 for (int i = 7; i >= 0; i--)
330 POSITION y = y1 + ddy_ddd[i];
331 POSITION x = x1 + ddx_ddd[i];
332 if (!in_bounds2(floor_ptr, y, x)) continue;
333 if (player_bold(target_ptr, y, x)) return FALSE;
336 g_ptr = &floor_ptr->grid_array[y][x];
337 int cost = g_ptr->cost;
338 if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) || ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding))))
340 if (cost == 0) continue;
341 if (!can_open_door && is_closed_door(target_ptr, g_ptr->feat)) continue;
344 if (cost == 0) cost = 998;
346 if (now_cost < cost) continue;
347 if (!projectable(target_ptr, y, x, target_ptr->y, target_ptr->x)) continue;
348 if (best < cost) continue;
351 *yp = y1 + ddy_ddd[i];
352 *xp = x1 + ddx_ddd[i];
355 if (best == 999) return FALSE;
362 * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
363 * Choose the "best" direction for "flowing"
364 * @param m_idx モンスターの参照ID
365 * @param yp 移動先のマスのY座標を返す参照ポインタ
366 * @param xp 移動先のマスのX座標を返す参照ポインタ
367 * @param no_flow モンスターにFLOWフラグが経っていない状態でTRUE
368 * @return 有効なマスがあった場合TRUEを返す
370 * Note that ghosts and rock-eaters are never allowed to "flow",\n
371 * since they should move directly towards the player.\n
373 * Prefer "non-diagonal" directions, but twiddle them a little\n
374 * to angle slightly towards the player's actual location.\n
376 * Allow very perceptive monsters to track old "spoor" left by\n
377 * previous locations occupied by the player. This will tend\n
378 * to have monsters end up either near the player or on a grid\n
379 * recently occupied by the player (and left via "teleport").\n
381 * Note that if "smell" is turned on, all monsters get vicious.\n
383 * Also note that teleporting away from a location will cause\n
384 * the monsters who were chasing you to converge on that location\n
385 * as long as you are still near enough to "annoy" them without\n
386 * being close enough to chase directly. I have no idea what will\n
387 * happen if you combine "smell" with low "aaf" values.\n
389 static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
392 floor_type *floor_ptr = target_ptr->current_floor_ptr;
393 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
394 monster_race *r_ptr = &r_info[m_ptr->r_idx];
396 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
397 r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
398 r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
400 if (get_moves_aux2(target_ptr, m_idx, yp, xp)) return TRUE;
403 if (no_flow) return FALSE;
404 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) return FALSE;
405 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)) return FALSE;
407 POSITION y1 = m_ptr->fy;
408 POSITION x1 = m_ptr->fx;
409 if (player_has_los_bold(target_ptr, y1, x1) && projectable(target_ptr, target_ptr->y, target_ptr->x, y1, x1)) return FALSE;
411 g_ptr = &floor_ptr->grid_array[y1][x1];
414 bool use_scent = FALSE;
419 else if (g_ptr->when)
421 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when - g_ptr->when > 127) return FALSE;
431 for (int i = 7; i >= 0; i--)
433 POSITION y = y1 + ddy_ddd[i];
434 POSITION x = x1 + ddx_ddd[i];
436 if (!in_bounds2(floor_ptr, y, x)) continue;
438 g_ptr = &floor_ptr->grid_array[y][x];
441 int when = g_ptr->when;
442 if (best > when) continue;
449 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
458 if ((cost == 0) || (best < cost)) continue;
463 *yp = target_ptr->y + 16 * ddy_ddd[i];
464 *xp = target_ptr->x + 16 * ddx_ddd[i];
467 if (best == 999 || best == 0) return FALSE;
474 * @brief モンスターがプレイヤーから逃走することが可能なマスを走査する /
475 * Provide a location to flee to, but give the player a wide berth.
476 * @param m_idx モンスターの参照ID
477 * @param yp 移動先のマスのY座標を返す参照ポインタ
478 * @param xp 移動先のマスのX座標を返す参照ポインタ
479 * @return 有効なマスがあった場合TRUEを返す
481 * A monster may wish to flee to a location that is behind the player,\n
482 * but instead of heading directly for it, the monster should "swerve"\n
483 * around the player so that he has a smaller chance of getting hit.\n
485 static bool get_fear_moves_aux(floor_type *floor_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
487 POSITION gy = 0, gx = 0;
489 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
490 POSITION fy = m_ptr->fy;
491 POSITION fx = m_ptr->fx;
493 POSITION y1 = fy - (*yp);
494 POSITION x1 = fx - (*xp);
497 for (int i = 7; i >= 0; i--)
499 POSITION y = fy + ddy_ddd[i];
500 POSITION x = fx + ddx_ddd[i];
501 if (!in_bounds2(floor_ptr, y, x)) continue;
503 POSITION dis = distance(y, x, y1, x1);
504 POSITION s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
507 if (s < score) continue;
514 if (score == -1) return FALSE;
524 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
527 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
528 * offsets of all the locations with a distance of n from a central point,
529 * with an offset of (0,0) indicating no more offsets at this distance.
531 * This is, of course, fairly unreadable, but it eliminates multiple loops
532 * from the previous version.
534 * It is probably better to replace these arrays with code to compute
535 * the relevant arrays, even if the storage is pre-allocated in hard
536 * coded sizes. At the very least, code should be included which is
537 * able to generate and dump these arrays (ala "los()").
539 * Also, the storage needs could be halved by using bytes.
541 * These arrays could be combined into two big arrays, using sub-arrays
542 * to hold the offsets and lengths of each portion of the sub-arrays, and
543 * this could perhaps also be used somehow in the "look" code.
547 static POSITION d_off_y_0[] = { 0 };
548 static POSITION d_off_x_0[] = { 0 };
550 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
551 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
553 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
554 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
556 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
557 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
559 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 };
560 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 };
563 static POSITION d_off_y_5[] =
564 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
565 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
568 static POSITION d_off_x_5[] =
569 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
570 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
574 static POSITION d_off_y_6[] =
575 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
576 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
579 static POSITION d_off_x_6[] =
580 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
581 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
582 -3, 2, 3, -1, 0, 1, 0 };
585 static POSITION d_off_y_7[] =
586 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
587 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
588 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
590 static POSITION d_off_x_7[] =
591 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
592 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
593 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
597 static POSITION d_off_y_8[] =
598 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
599 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
600 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
603 static POSITION d_off_x_8[] =
604 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
605 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
606 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
610 static POSITION d_off_y_9[] =
611 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
612 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
613 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
614 7, 8, 8, 8, 8, 9, 9, 9, 0 };
616 static POSITION d_off_x_9[] =
617 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
618 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
619 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
620 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
623 static POSITION *dist_offsets_y[10] =
625 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
626 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
629 static POSITION *dist_offsets_x[10] =
631 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
632 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
636 * @brief モンスターが逃げ込める安全な地点を返す /
637 * Choose a "safe" location near a monster for it to run toward.
638 * @param target_ptr プレーヤーへの参照ポインタ
639 * @param m_idx モンスターの参照ID
640 * @param yp 移動先のマスのY座標を返す参照ポインタ
641 * @param xp 移動先のマスのX座標を返す参照ポインタ
642 * @return 有効なマスがあった場合TRUEを返す
644 * A location is "safe" if it can be reached quickly and the player\n
645 * is not able to fire into it (it isn't a "clean shot"). So, this will\n
646 * cause monsters to "duck" behind walls. Hopefully, monsters will also\n
647 * try to run towards corridor openings if they are in a room.\n
649 * This function may take lots of CPU time if lots of monsters are\n
652 * Return TRUE if a safe location is available.\n
654 static bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
656 floor_type *floor_ptr = target_ptr->current_floor_ptr;
657 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
659 POSITION fy = m_ptr->fy;
660 POSITION fx = m_ptr->fx;
662 POSITION gy = 0, gx = 0, gdis = 0;
664 for (POSITION d = 1; d < 10; d++)
667 y_offsets = dist_offsets_y[d];
670 x_offsets = dist_offsets_x[d];
672 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
674 i++, dx = x_offsets[i], dy = y_offsets[i])
676 POSITION y = fy + dy;
677 POSITION x = fx + dx;
678 if (!in_bounds(floor_ptr, y, x)) continue;
681 g_ptr = &floor_ptr->grid_array[y][x];
683 BIT_FLAGS16 riding_mode = (m_idx == target_ptr->riding) ? CEM_RIDING : 0;
684 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], riding_mode))
687 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
689 if (g_ptr->dist == 0) continue;
690 if (g_ptr->dist > floor_ptr->grid_array[fy][fx].dist + 2 * d) continue;
693 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x)) continue;
695 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
696 if (dis <= gdis) continue;
703 if (gdis <= 0) continue;
716 * @brief モンスターが隠れ潜める地点を返す /
717 * Choose a good hiding place near a monster for it to run toward.
718 * @param target_ptr プレーヤーへの参照ポインタ
719 * @param m_idx モンスターの参照ID
720 * @param yp 移動先のマスのY座標を返す参照ポインタ
721 * @param xp 移動先のマスのX座標を返す参照ポインタ
722 * @return 有効なマスがあった場合TRUEを返す
724 * Pack monsters will use this to "ambush" the player and lure him out\n
725 * of corridors into open space so they can swarm him.\n
727 * Return TRUE if a good location is available.\n
729 static bool find_hiding(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
731 floor_type *floor_ptr = target_ptr->current_floor_ptr;
732 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
733 monster_race *r_ptr = &r_info[m_ptr->r_idx];
735 POSITION fy = m_ptr->fy;
736 POSITION fx = m_ptr->fx;
738 POSITION gy = 0, gx = 0, gdis = 999;
740 for (POSITION d = 1; d < 10; d++)
743 y_offsets = dist_offsets_y[d];
746 x_offsets = dist_offsets_x[d];
748 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
750 i++, dx = x_offsets[i], dy = y_offsets[i])
752 POSITION y = fy + dy;
753 POSITION x = fx + dx;
755 if (!in_bounds(floor_ptr, y, x)) continue;
756 if (!monster_can_enter(target_ptr, y, x, r_ptr, 0)) continue;
757 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, fy, fx, y, x, FALSE))
760 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
761 if (dis < gdis && dis >= 2)
769 if (gdis >= 999) continue;
782 * @brief モンスターの移動方向を返す /
783 * Choose "logical" directions for monster movement
784 * @param target_ptr プレーヤーへの参照ポインタ
785 * @param m_idx モンスターの参照ID
786 * @param mm 移動方向を返す方向IDの参照ポインタ
787 * @return 有効方向があった場合TRUEを返す
789 static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
791 floor_type *floor_ptr = target_ptr->current_floor_ptr;
792 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
793 monster_race *r_ptr = &r_info[m_ptr->r_idx];
794 POSITION y = 0, ay, x = 0, ax;
795 POSITION y2 = target_ptr->y;
796 POSITION x2 = target_ptr->x;
798 bool will_run = mon_will_run(target_ptr, m_idx);
800 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) != 0) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2);
801 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) != 0) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall);
803 if (!will_run && m_ptr->target_y)
805 int t_m_idx = floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
807 are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[t_m_idx]) &&
808 los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
809 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
811 y = m_ptr->fy - m_ptr->target_y;
812 x = m_ptr->fx - m_ptr->target_x;
817 if (!done && !will_run && is_hostile(m_ptr) &&
818 (r_ptr->flags1 & RF1_FRIENDS) &&
819 ((los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x) && projectable(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x)) ||
820 (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
822 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
823 !(r_ptr->flags2 & RF2_KILL_WALL))
826 for (int i = 0; i < 8; i++)
828 int xx = target_ptr->x + ddx_ddd[i];
829 int yy = target_ptr->y + ddy_ddd[i];
831 if (!in_bounds2(floor_ptr, yy, xx)) continue;
833 g_ptr = &floor_ptr->grid_array[yy][xx];
834 if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0))
840 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].info & CAVE_ROOM) room -= 2;
841 if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
843 if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
844 (target_ptr->mhp + target_ptr->msp))
846 if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
850 if (!done && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
852 for (int i = 0; i < 8; i++)
854 y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
855 x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
856 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
863 if (!in_bounds2(floor_ptr, y2, x2)) continue;
864 if (!monster_can_enter(target_ptr, y2, x2, r_ptr, 0)) continue;
877 (void)get_moves_aux(target_ptr, m_idx, &y2, &x2, no_flow);
882 if (is_pet(m_ptr) && will_run)
888 if (!done && will_run)
892 if (find_safety(target_ptr, m_idx, &y, &x) && !no_flow)
894 if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x))
906 if (!x && !y) return FALSE;
912 if (y < 0) move_val += 8;
913 if (x > 0) move_val += 4;
915 if (ay > (ax << 1)) move_val += 2;
916 else if (ax > (ay << 1)) move_val++;
1066 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
1068 return !have_flag(f_ptr->flags, FF_GLASS) ||
1069 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
1070 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
1075 * @brief モンスター単体の1ターン行動処理メインルーチン /
1077 * @param target_ptr プレーヤーへの参照ポインタ
1078 * @param m_idx 行動モンスターの参照ID
1081 * The monster is known to be within 100 grids of the player\n
1083 * In several cases, we directly update the monster lore\n
1085 * Note that a monster is only allowed to "reproduce" if there\n
1086 * are a limited number of "reproducing" monsters on the current\n
1087 * level. This should prevent the level from being "swamped" by\n
1088 * reproducing monsters. It also allows a large mass of mice to\n
1089 * prevent a louse from multiplying, but this is a small price to\n
1090 * pay for a simple multiplication method.\n
1092 * XXX Monster fear is slightly odd, in particular, monsters will\n
1093 * fixate on opening a door even if they cannot open it. Actually,\n
1094 * the same thing happens to normal monsters when they hit a door\n
1096 * In addition, monsters which *cannot* open or bash\n
1097 * down a door will still stand there trying to open it...\n
1099 * XXX Technically, need to check for monster in the way\n
1100 * combined with that monster being in a wall (or door?)\n
1102 * A "direction" of "5" means "pick a random direction".\n
1104 void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1106 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1107 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1108 turn_flags tmp_flags;
1109 turn_flags *turn_flags_ptr = init_turn_flags(target_ptr, m_idx, &tmp_flags);
1110 turn_flags_ptr->see_m = is_seen(m_ptr);
1112 decide_drop_from_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon);
1113 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
1115 choose_new_monster(target_ptr, m_idx, FALSE, 0);
1116 r_ptr = &r_info[m_ptr->r_idx];
1119 turn_flags_ptr->aware = process_stealth(target_ptr, m_idx);
1120 if (vanish_summoned_children(target_ptr, m_idx, turn_flags_ptr->see_m)) return;
1121 if (process_quantum_effect(target_ptr,m_idx, turn_flags_ptr->see_m)) return;
1122 if (explode_monster(target_ptr, m_idx)) return;
1123 if (runaway_monster(target_ptr, turn_flags_ptr, m_idx)) return;
1125 awake_monster(target_ptr, m_idx);
1126 if (MON_STUNNED(m_ptr))
1128 if (one_in_(2)) return;
1131 if (turn_flags_ptr->is_riding_mon)
1133 target_ptr->update |= (PU_BONUS);
1136 process_angar(target_ptr, m_idx, turn_flags_ptr->see_m);
1138 POSITION oy = m_ptr->fy;
1139 POSITION ox = m_ptr->fx;
1140 if (decide_monster_multiplication(target_ptr, m_idx, oy, ox)) return;
1142 process_special(target_ptr, m_idx);
1143 process_speak_sound(target_ptr, m_idx, oy, ox, turn_flags_ptr->aware);
1144 if (cast_spell(target_ptr, m_idx, turn_flags_ptr->aware)) return;
1147 mm[0] = mm[1] = mm[2] = mm[3] = 0;
1148 mm[4] = mm[5] = mm[6] = mm[7] = 0;
1150 if (!decide_monster_movement_direction(target_ptr, mm, m_idx, turn_flags_ptr->aware)) return;
1153 if(!process_monster_movement(target_ptr, turn_flags_ptr, m_idx, mm, oy, ox, &count)) return;
1156 * Forward movements failed, but now received LOS attack!
1157 * Try to flow by smell.
1159 if (target_ptr->no_flowed && count > 2 && m_ptr->target_y)
1160 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
1162 if (!turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && !MON_MONFEAR(m_ptr) && !turn_flags_ptr->is_riding_mon && turn_flags_ptr->aware)
1164 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
1166 if (make_attack_spell(m_idx, target_ptr)) return;
1170 update_player_type(target_ptr, turn_flags_ptr, r_ptr);
1171 update_monster_race_flags(target_ptr, turn_flags_ptr, m_ptr);
1173 if (!process_monster_fear(target_ptr, turn_flags_ptr, m_idx)) return;
1175 if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
1180 * @brief ターン経過フラグ構造体の初期化
1181 * @param target_ptr プレーヤーへの参照ポインタ
1182 * @param m_idx モンスターID
1183 * @return 初期化済のターン経過フラグ
1185 turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr)
1187 turn_flags_ptr->is_riding_mon = (m_idx == target_ptr->riding);
1188 turn_flags_ptr->do_turn = FALSE;
1189 turn_flags_ptr->do_move = FALSE;
1190 turn_flags_ptr->do_view = FALSE;
1191 turn_flags_ptr->must_alter_to_move = FALSE;
1192 turn_flags_ptr->did_open_door = FALSE;
1193 turn_flags_ptr->did_bash_door = FALSE;
1194 turn_flags_ptr->did_take_item = FALSE;
1195 turn_flags_ptr->did_kill_item = FALSE;
1196 turn_flags_ptr->did_move_body = FALSE;
1197 turn_flags_ptr->did_pass_wall = FALSE;
1198 turn_flags_ptr->did_kill_wall = FALSE;
1199 return turn_flags_ptr;
1205 * @param target_ptr プレーヤーへの参照ポインタ
1206 * @param m_idx モンスターID
1207 * @return モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1209 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx)
1211 if ((target_ptr->special_defense & NINJA_S_STEALTH) == 0) return TRUE;
1213 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1214 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1215 int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
1216 if (target_ptr->monlite) tmp /= 3;
1217 if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1218 if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
1219 return (randint0(tmp) <= (r_ptr->level + 20));
1224 * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
1225 * @param target_ptr プレーヤーへの参照ポインタ
1226 * @param m_idx モンスターID
1227 * @param is_riding_mon 騎乗中であればTRUE
1230 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
1232 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1233 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1234 if (!is_riding_mon || ((r_ptr->flags7 & RF7_RIDING) != 0)) return;
1236 if (rakuba(target_ptr, 0, TRUE))
1239 msg_print("地面に落とされた。");
1241 GAME_TEXT m_name[MAX_NLEN];
1242 monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
1243 msg_format("You have fallen from %s.", m_name);
1250 * @brief 召喚の親元が消滅した時、子供も消滅させる
1251 * @param target_ptr プレーヤーへの参照ポインタ
1252 * @param m_idx モンスターID
1253 * @param see_m モンスターが視界内にいたらTRUE
1254 * @return 召喚モンスターが消滅したらTRUE
1256 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1258 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1259 if ((m_ptr->parent_m_idx == 0) || (target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx > 0))
1264 GAME_TEXT m_name[MAX_NLEN];
1265 monster_desc(target_ptr, m_name, m_ptr, 0);
1266 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1269 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1271 GAME_TEXT m_name[MAX_NLEN];
1272 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
1273 exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
1276 delete_monster_idx(target_ptr, m_idx);
1282 * @brief 寝ているモンスターの起床を判定する
1283 * @param target_ptr プレーヤーへの参照ポインタ
1284 * @param m_idx モンスターID
1287 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1289 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1290 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1291 if (!MON_CSLEEP(m_ptr)) return;
1292 if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
1294 (void)set_monster_csleep(target_ptr, m_idx, 0);
1297 GAME_TEXT m_name[MAX_NLEN];
1298 monster_desc(target_ptr, m_name, m_ptr, 0);
1299 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
1302 if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
1310 * @brief モンスターの怒り状態を判定する (起こっていたら敵に回す)
1311 * @param target_ptr プレーヤーへの参照ポインタ
1312 * @param m_idx モンスターID
1313 * @param see_m モンスターが視界内にいたらTRUE
1316 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1318 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1319 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1320 bool gets_angry = FALSE;
1321 if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
1324 if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
1325 monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
1330 if (target_ptr->phase_out || !gets_angry) return;
1332 if (is_pet(m_ptr) || see_m)
1334 GAME_TEXT m_name[MAX_NLEN];
1335 monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
1336 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
1339 set_hostile(target_ptr, m_ptr);
1344 * @brief 量子生物の量子的効果を実行する
1345 * @param target_ptr プレーヤーへの参照ポインタ
1346 * @param m_idx モンスターID
1347 * @param see_m モンスターが視界内にいたらTRUE
1348 * @return モンスターが量子的効果により消滅したらTRUE
1350 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1352 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1353 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1354 if ((r_ptr->flags2 & RF2_QUANTUM) == 0) return FALSE;
1355 if (!randint0(2)) return FALSE;
1356 if (randint0((m_idx % 100) + 10)) return FALSE;
1358 bool can_disappear = (r_ptr->flags1 & RF1_UNIQUE) == 0;
1359 can_disappear &= (r_ptr->flags1 & RF1_QUESTOR) == 0;
1362 vanish_nonunique(target_ptr, m_idx, see_m);
1366 produce_quantum_effect(target_ptr, m_idx, see_m);
1372 * @brief ユニークでない量子生物を消滅させる
1373 * @param target_ptr プレーヤーへの参照ポインタ
1374 * @param m_idx モンスターID
1375 * @param see_m モンスターが視界内にいたらTRUE
1378 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1380 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1383 GAME_TEXT m_name[MAX_NLEN];
1384 monster_desc(target_ptr, m_name, m_ptr, 0);
1385 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1388 monster_death(target_ptr, m_idx, FALSE);
1389 delete_monster_idx(target_ptr, m_idx);
1390 if (is_pet(m_ptr) && !(m_ptr->ml))
1392 msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
1398 * @brief 量子生物ユニークの量子的効果 (ショート・テレポートまたは距離10のテレポート・アウェイ)を実行する
1399 * @param target_ptr プレーヤーへの参照ポインタ
1400 * @param m_idx モンスターID
1401 * @param see_m モンスターが視界内にいたらTRUE
1404 * プレーヤーが量子生物を観測しているか、量子生物がプレーヤーを観測している場合、互いの相対的な位置を確定させる
1405 * 波動関数の収縮はテレポートではないので反テレポート無効
1406 * todo パターンは収縮どころか拡散しているが、この際気にしてはいけない
1408 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1410 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1411 bool coherent = los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x);
1412 if (!see_m && !coherent) return;
1416 GAME_TEXT m_name[MAX_NLEN];
1417 monster_desc(target_ptr, m_name, m_ptr, 0);
1418 msg_format(_("%sは量子的効果を起こした!", "%^s produced a decoherence!"), m_name);
1422 msg_print(_("量子的効果が起こった!", "A decoherence was produced!"));
1425 bool target = one_in_(2);
1426 const int blink = 32 * 5 + 4;
1429 (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx);
1434 teleport_player_away(m_idx, target_ptr, 10, TRUE);
1441 * @param target_ptr プレーヤーへの参照ポインタ
1442 * @param m_idx モンスターID
1445 bool explode_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1447 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1448 if (m_ptr->r_idx != MON_SHURYUUDAN) return FALSE;
1451 mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
1457 * @brief モンスター依存の特別な行動を取らせる
1458 * @param target_ptr プレーヤーへの参照ポインタ
1459 * @param m_idx モンスターID
1462 void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
1464 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1465 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1466 if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
1467 if (m_ptr->r_idx != MON_OHMU) return;
1468 if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
1469 if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
1472 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1473 BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
1475 for (int k = 0; k < A_MAX; k++)
1477 if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
1479 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
1483 if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
1488 * @brief モンスターを喋らせたり足音を立てたりする
1489 * @param target_ptr プレーヤーへの参照ポインタ
1490 * @param m_idx モンスターID
1491 * @param oy モンスターが元々いたY座標
1492 * @param ox モンスターが元々いたX座標
1493 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1496 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware)
1498 if (target_ptr->phase_out) return;
1500 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1501 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1502 if (m_ptr->ap_r_idx == MON_CYBER &&
1503 one_in_(CYBERNOISE) &&
1504 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
1506 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
1507 msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
1510 if (((ap_r_ptr->flags2 & RF2_CAN_SPEAK) == 0) || !aware ||
1511 !one_in_(SPEAK_CHANCE) ||
1512 !player_has_los_bold(target_ptr, oy, ox) ||
1513 !projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
1516 GAME_TEXT m_name[MAX_NLEN];
1517 char monmessage[1024];
1521 monster_desc(target_ptr, m_name, m_ptr, 0);
1523 strcpy(m_name, _("それ", "It"));
1525 if (MON_MONFEAR(m_ptr))
1526 filename = _("monfear_j.txt", "monfear.txt");
1527 else if (is_pet(m_ptr))
1528 filename = _("monpet_j.txt", "monpet.txt");
1529 else if (is_friendly(m_ptr))
1530 filename = _("monfrien_j.txt", "monfrien.txt");
1532 filename = _("monspeak_j.txt", "monspeak.txt");
1534 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
1536 msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
1542 * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
1543 * @param target_ptr プレーヤーへの参照ポインタ
1544 * @param m_idx モンスターID
1545 * @param oy 分裂元モンスターのY座標
1546 * @param ox 分裂元モンスターのX座標
1547 * @return 実際に分裂したらTRUEを返す
1549 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
1551 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1552 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1553 if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) || (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
1557 for (POSITION y = oy - 1; y <= oy + 1; y++)
1559 for (POSITION x = ox - 1; x <= ox + 1; x++)
1561 if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
1562 if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
1566 if (multiply_barrier(target_ptr, m_idx)) k = 8;
1568 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
1570 if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
1572 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
1574 r_ptr->r_flags2 |= (RF2_MULTIPLY);
1586 * @brief モンスターの移動パターンを決定する
1587 * @param target_ptr プレーヤーへの参照ポインタ
1589 * @param m_idx モンスターID
1590 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1591 * @return 移動先が存在すればTRUE
1593 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware)
1595 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1596 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1598 if (MON_CONFUSED(m_ptr) || !aware)
1600 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1604 if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) && (randint0(100) < 75))
1606 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
1608 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1612 if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 50))
1614 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
1616 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1620 if ((r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 25))
1622 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
1624 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1628 if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
1630 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1636 bool avoid = ((target_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
1637 bool lonely = (!avoid && (m_ptr->cdis > target_ptr->pet_follow_distance));
1638 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
1639 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1640 if (!get_enemy_dir(target_ptr, m_idx, mm))
1642 if (avoid || lonely || distant)
1644 POSITION dis = target_ptr->pet_follow_distance;
1645 if (target_ptr->pet_follow_distance > PET_SEEK_DIST)
1647 target_ptr->pet_follow_distance = PET_SEEK_DIST;
1650 (void)get_moves(target_ptr, m_idx, mm);
1651 target_ptr->pet_follow_distance = (s16b)dis;
1658 if (!is_hostile(m_ptr))
1660 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1661 get_enemy_dir(target_ptr, m_idx, mm);
1665 if (!get_moves(target_ptr, m_idx, mm)) return FALSE;
1672 * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
1673 * @param target_ptr プレーヤーへの参照ポインタ
1674 * @param m_idx モンスターID
1675 * @param is_riding_mon 騎乗状態ならばTRUE
1676 * @param see_m モンスターが視界内にいたらTRUE
1677 * @return モンスターがフロアから消えたらTRUE
1679 bool runaway_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
1681 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1682 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1683 bool can_runaway = is_pet(m_ptr) || is_friendly(m_ptr);
1684 can_runaway &= ((r_ptr->flags1 & RF1_UNIQUE) != 0) || ((r_ptr->flags7 & RF7_NAZGUL) != 0);
1685 can_runaway &= !target_ptr->phase_out;
1686 if (!can_runaway) return FALSE;
1688 static int riding_pinch = 0;
1690 if (m_ptr->hp >= m_ptr->maxhp / 3)
1692 /* Reset the counter */
1693 if (turn_flags_ptr->is_riding_mon) riding_pinch = 0;
1698 GAME_TEXT m_name[MAX_NLEN];
1699 monster_desc(target_ptr, m_name, m_ptr, 0);
1700 if (turn_flags_ptr->is_riding_mon && riding_pinch < 2)
1702 msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
1703 "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
1705 disturb(target_ptr, TRUE, TRUE);
1709 escape_monster(target_ptr, turn_flags_ptr, m_ptr, m_name);
1710 check_quest_completion(target_ptr, m_ptr);
1711 delete_monster_idx(target_ptr, m_idx);
1717 * @brief HPが1/3未満になった有効的なユニークモンスターの逃走処理を行う
1718 * @param target_ptr プレーヤーへの参照ポインタ
1719 * @param is_riding_mon 騎乗状態ならばTRUE
1720 * @param m_ptr モンスターへの参照ポインタ
1721 * @param m_name モンスター名称
1722 * @param see_m モンスターが視界内にいたらTRUE
1725 void escape_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, GAME_TEXT *m_name)
1727 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1728 if (turn_flags_ptr->is_riding_mon)
1730 msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
1731 if (rakuba(target_ptr, -1, FALSE))
1733 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1737 if (turn_flags_ptr->see_m)
1739 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) &&
1740 player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx) && projectable(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x))
1742 msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
1745 msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s reads a scroll of teleport level."), m_name);
1746 msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
1749 if (turn_flags_ptr->is_riding_mon && rakuba(target_ptr, -1, FALSE))
1751 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1757 * @brief モンスターに魔法を試行させる
1758 * @param target_ptr プレーヤーへの参照ポインタ
1759 * @param m_idx モンスターID
1760 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1761 * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
1763 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware)
1765 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1766 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1767 if ((r_ptr->freq_spell == 0) || (randint1(100) > r_ptr->freq_spell))
1770 bool counterattack = FALSE;
1771 if (m_ptr->target_y)
1773 MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
1774 if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
1775 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1777 counterattack = TRUE;
1783 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1784 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1788 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1789 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1797 * @brief モンスターの移動に関するメインルーチン
1798 * @param target_ptr プレーヤーへの参照ポインタ
1799 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
1800 * @param m_idx モンスターID
1801 * @param mm モンスターの移動方向
1802 * @param oy 移動前の、モンスターのY座標
1803 * @param ox 移動前の、モンスターのX座標
1804 * @param count 移動回数 (のはず todo)
1805 * @return 移動が阻害される何か (ドア等)があったらFALSE
1807 bool process_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, DIRECTION *mm, POSITION oy, POSITION ox, int *count)
1809 for (int i = 0; mm[i]; i++)
1812 if (d == 5) d = ddd[randint0(8)];
1814 POSITION ny = oy + ddy[d];
1815 POSITION nx = ox + ddx[d];
1816 if (!in_bounds2(target_ptr->current_floor_ptr, ny, nx)) continue;
1819 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1820 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1821 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1822 bool can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0);
1824 if (!process_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx, can_cross))
1826 if (!process_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1830 if (!process_protection_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1832 if (!process_explosive_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1836 exe_monster_attack_to_player(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1837 if (process_monster_attack_to_monster(target_ptr, turn_flags_ptr, m_idx, g_ptr, can_cross)) return FALSE;
1839 if (turn_flags_ptr->is_riding_mon)
1841 if (!target_ptr->riding_ryoute && !MON_MONFEAR(&target_ptr->current_floor_ptr->m_list[target_ptr->riding])) turn_flags_ptr->do_move = FALSE;
1844 if (!process_post_dig_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx)) return FALSE;
1846 if (turn_flags_ptr->must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
1848 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0))
1849 turn_flags_ptr->do_move = FALSE;
1852 if (turn_flags_ptr->do_move && !can_cross && !turn_flags_ptr->did_kill_wall && !turn_flags_ptr->did_bash_door)
1853 turn_flags_ptr->do_move = FALSE;
1855 if (turn_flags_ptr->do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
1857 if (is_original_ap_and_seen(target_ptr, m_ptr))
1858 r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
1860 turn_flags_ptr->do_move = FALSE;
1863 if (!turn_flags_ptr->do_move)
1865 if (turn_flags_ptr->do_turn) break;
1870 turn_flags_ptr->do_turn = TRUE;
1871 feature_type *f_ptr;
1872 f_ptr = &f_info[g_ptr->feat];
1873 if (have_flag(f_ptr->flags, FF_TREE))
1875 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
1877 m_ptr->energy_need += ENERGY_NEED();
1881 if (!update_riding_monster(target_ptr, turn_flags_ptr, m_idx, oy, ox, ny, nx)) break;
1883 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1886 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
1887 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= target_ptr->lev)))
1889 if (is_hostile(m_ptr))
1890 disturb(target_ptr, FALSE, TRUE);
1893 bool is_takable_or_killable = g_ptr->o_idx > 0;
1894 is_takable_or_killable &= (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) != 0;
1896 bool is_pickup_items = (target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
1897 is_pickup_items &= (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
1899 is_takable_or_killable &= !is_pet(m_ptr) || is_pickup_items;
1900 if (!is_takable_or_killable)
1902 if (turn_flags_ptr->do_turn) break;
1907 update_object_by_monster_movement(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1909 if (turn_flags_ptr->do_turn) break;
1919 * @brief モンスターによる壁の透過・破壊を行う
1920 * @param target_ptr プレーヤーへの参照ポインタ
1921 * @param m_ptr モンスターへの参照ポインタ
1922 * @param ny モンスターのY座標
1923 * @param nx モンスターのX座標
1924 * @param can_cross モンスターが地形を踏破できるならばTRUE
1925 * @return 透過も破壊もしなかった場合はFALSE、それ以外はTRUE
1927 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross)
1929 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1931 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1932 feature_type *f_ptr;
1933 f_ptr = &f_info[g_ptr->feat];
1934 if (player_bold(target_ptr, ny, nx))
1936 turn_flags_ptr->do_move = TRUE;
1940 if (g_ptr->m_idx > 0)
1942 turn_flags_ptr->do_move = TRUE;
1946 if (((r_ptr->flags2 & RF2_KILL_WALL) != 0) &&
1947 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !turn_flags_ptr->is_riding_mon) &&
1948 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
1949 check_hp_for_feat_destruction(f_ptr, m_ptr))
1951 turn_flags_ptr->do_move = TRUE;
1952 if (!can_cross) turn_flags_ptr->must_alter_to_move = TRUE;
1954 turn_flags_ptr->did_kill_wall = TRUE;
1958 if (!can_cross) return FALSE;
1960 turn_flags_ptr->do_move = TRUE;
1961 if (((r_ptr->flags2 & RF2_PASS_WALL) != 0) && (!turn_flags_ptr->is_riding_mon || target_ptr->pass_wall) &&
1962 have_flag(f_ptr->flags, FF_CAN_PASS))
1964 turn_flags_ptr->did_pass_wall = TRUE;
1972 * @brief モンスターによるドアの開放・破壊を行う
1973 * @param target_ptr プレーヤーへの参照ポインタ
1974 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
1975 * @param m_ptr モンスターへの参照ポインタ
1976 * @param ny モンスターのY座標
1977 * @param nx モンスターのX座標
1978 * @return モンスターが死亡した場合のみFALSE
1980 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
1982 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1984 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1985 if (!is_closed_door(target_ptr, g_ptr->feat)) return TRUE;
1987 feature_type *f_ptr;
1988 f_ptr = &f_info[g_ptr->feat];
1989 bool may_bash = bash_normal_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx);
1990 bash_glass_door(target_ptr, turn_flags_ptr, m_ptr, f_ptr, may_bash);
1992 if (!turn_flags_ptr->did_open_door && !turn_flags_ptr->did_bash_door) return TRUE;
1994 if (turn_flags_ptr->did_bash_door &&
1995 ((randint0(100) < 50) || (feat_state(target_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
1997 cave_alter_feat(target_ptr, ny, nx, FF_BASH);
1998 if (!monster_is_valid(m_ptr))
2000 target_ptr->update |= (PU_FLOW);
2001 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2002 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2009 cave_alter_feat(target_ptr, ny, nx, FF_OPEN);
2012 f_ptr = &f_info[g_ptr->feat];
2013 turn_flags_ptr->do_view = TRUE;
2019 * @brief モンスターが普通のドアを開ける処理
2020 * @param target_ptr プレーヤーへの参照ポインタ
2021 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2022 * @param m_ptr モンスターへの参照ポインタ
2023 * @param ny モンスターのY座標
2024 * @param nx モンスターのX座標
2025 * @return ここではドアを開けず、ガラスのドアを開ける可能性があるならTRUE
2027 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2029 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2031 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2032 feature_type *f_ptr;
2033 f_ptr = &f_info[g_ptr->feat];
2034 turn_flags_ptr->do_move = FALSE;
2035 if (((r_ptr->flags2 & RF2_OPEN_DOOR) == 0) || !have_flag(f_ptr->flags, FF_OPEN) ||
2036 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2039 if (f_ptr->power == 0)
2041 turn_flags_ptr->did_open_door = TRUE;
2042 turn_flags_ptr->do_turn = TRUE;
2046 if (randint0(m_ptr->hp / 10) > f_ptr->power)
2048 cave_alter_feat(target_ptr, ny, nx, FF_DISARM);
2049 turn_flags_ptr->do_turn = TRUE;
2058 * @brief モンスターがガラスのドアを開ける処理
2059 * @param target_ptr プレーヤーへの参照ポインタ
2060 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2061 * @param m_ptr モンスターへの参照ポインタ
2062 * @param g_ptr グリッドへの参照ポインタ
2063 * @param f_ptr 地形への参照ポインタ
2066 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash)
2068 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2069 if (!may_bash || ((r_ptr->flags2 & RF2_BASH_DOOR) == 0) || !have_flag(f_ptr->flags, FF_BASH) ||
2070 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2073 if (!check_hp_for_feat_destruction(f_ptr, m_ptr) || (randint0(m_ptr->hp / 10) <= f_ptr->power))
2076 if (have_flag(f_ptr->flags, FF_GLASS))
2077 msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
2079 msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
2081 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
2083 turn_flags_ptr->did_bash_door = TRUE;
2084 turn_flags_ptr->do_move = TRUE;
2085 turn_flags_ptr->must_alter_to_move = TRUE;
2090 * @brief 守りのルーンによるモンスターの移動制限を処理する
2091 * @param target_ptr プレーヤーへの参照ポインタ
2092 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2093 * @param m_ptr モンスターへの参照ポインタ
2094 * @param ny モンスターのY座標
2095 * @param nx モンスターのX座標
2098 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2101 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2102 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2103 if (!turn_flags_ptr->do_move || !is_glyph_grid(g_ptr) ||
2104 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2107 turn_flags_ptr->do_move = FALSE;
2108 if (is_pet(m_ptr) || (randint1(BREAK_GLYPH) >= r_ptr->level))
2111 if (g_ptr->info & CAVE_MARK)
2113 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2116 g_ptr->info &= ~(CAVE_MARK);
2117 g_ptr->info &= ~(CAVE_OBJECT);
2119 turn_flags_ptr->do_move = TRUE;
2120 note_spot(target_ptr, ny, nx);
2126 * @brief 爆発のルーンにを処理する
2127 * @param target_ptr プレーヤーへの参照ポインタ
2128 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2129 * @param m_ptr モンスターへの参照ポインタ
2130 * @param ny モンスターのY座標
2131 * @param nx モンスターのX座標
2132 * @return モンスターが死亡した場合のみFALSE
2134 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2137 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2138 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2139 if (!turn_flags_ptr->do_move || !is_explosive_rune_grid(g_ptr) ||
2140 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2143 turn_flags_ptr->do_move = FALSE;
2144 if (is_pet(m_ptr)) return TRUE;
2146 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2148 if (g_ptr->info & CAVE_MARK)
2150 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2151 BIT_FLAGS project_flags = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI;
2152 project(target_ptr, 0, 2, ny, nx, 2 * (target_ptr->lev + damroll(7, 7)), GF_MANA, project_flags, -1);
2157 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2160 g_ptr->info &= ~(CAVE_MARK);
2161 g_ptr->info &= ~(CAVE_OBJECT);
2164 note_spot(target_ptr, ny, nx);
2165 lite_spot(target_ptr, ny, nx);
2167 if (!monster_is_valid(m_ptr)) return FALSE;
2169 turn_flags_ptr->do_move = TRUE;
2175 * @brief モンスターが移動した結果、そこにプレーヤーがいたら直接攻撃を行う
2176 * @param target_ptr プレーヤーへの参照ポインタ
2177 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2178 * @param m_idx モンスターID
2179 * @param ny 移動後の、モンスターのY座標
2180 * @param nx 移動後の、モンスターのX座標
2183 * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
2185 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2187 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2188 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2189 if (!turn_flags_ptr->do_move || !player_bold(target_ptr, ny, nx))
2192 if (r_ptr->flags1 & RF1_NEVER_BLOW)
2194 if (is_original_ap_and_seen(target_ptr, m_ptr))
2195 r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
2197 turn_flags_ptr->do_move = FALSE;
2200 if (turn_flags_ptr->do_move && ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) != 0) && !MON_CONFUSED(m_ptr))
2202 if (!(r_ptr->flags2 & RF2_STUPID))
2203 turn_flags_ptr->do_move = FALSE;
2204 else if (is_original_ap_and_seen(target_ptr, m_ptr))
2205 r_ptr->r_flags2 |= (RF2_STUPID);
2208 if (!turn_flags_ptr->do_move) return;
2210 if (!target_ptr->riding || one_in_(2))
2212 (void)make_attack_normal(target_ptr, m_idx);
2213 turn_flags_ptr->do_move = FALSE;
2214 turn_flags_ptr->do_turn = TRUE;
2220 * @brief モンスターからモンスターへの攻撃処理
2221 * @param target_ptr プレーヤーへの参照ポインタ
2222 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2223 * @param m_idx モンスターID
2224 * @param g_ptr グリッドへの参照ポインタ
2225 * @param can_cross モンスターが地形を踏破できるならばTRUE
2226 * @return ターン消費が発生したらTRUE
2228 bool process_monster_attack_to_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, grid_type *g_ptr, bool can_cross)
2230 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2231 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2232 monster_type *y_ptr;
2233 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2234 if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) return FALSE;
2236 monster_race *z_ptr = &r_info[y_ptr->r_idx];
2237 turn_flags_ptr->do_move = FALSE;
2238 if ((((r_ptr->flags2 & RF2_KILL_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_BLOW) == 0) &&
2239 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
2240 can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
2241 are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
2243 return exe_monster_attack_to_monster(target_ptr, m_idx, g_ptr);
2246 if (((r_ptr->flags2 & RF2_MOVE_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_MOVE) == 0) &&
2247 (r_ptr->mexp > z_ptr->mexp) &&
2248 can_cross && (g_ptr->m_idx != target_ptr->riding) &&
2249 monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
2251 turn_flags_ptr->do_move = TRUE;
2252 turn_flags_ptr->did_move_body = TRUE;
2253 (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
2261 * @brief モンスターからモンスターへの直接攻撃を実行する
2262 * @param target_ptr プレーヤーへの参照ポインタ
2263 * @param m_idx モンスターID
2264 * @param g_ptr グリッドへの参照ポインタ
2266 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr)
2268 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2269 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2270 monster_type *y_ptr;
2271 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2272 if ((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) return FALSE;
2274 if (((r_ptr->flags2 & RF2_KILL_BODY) == 0) && is_original_ap_and_seen(target_ptr, m_ptr))
2275 r_ptr->r_flags2 |= (RF2_KILL_BODY);
2277 if ((y_ptr->r_idx == 0) || (y_ptr->hp < 0)) return FALSE;
2278 if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return TRUE;
2279 if ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) == 0) return FALSE;
2280 if (MON_CONFUSED(m_ptr)) return TRUE;
2281 if ((r_ptr->flags2 & RF2_STUPID) == 0) return FALSE;
2283 if (is_original_ap_and_seen(target_ptr, m_ptr))
2284 r_ptr->r_flags2 |= (RF2_STUPID);
2291 * @brief モンスターが壁を掘った後続処理を実行する
2292 * @param target_ptr プレーヤーへの参照ポインタ
2293 * @turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2294 * @param m_ptr モンスターへの参照ポインタ
2295 * @param ny モンスターのY座標
2296 * @param nx モンスターのX座標
2297 * @return モンスターが死亡した場合のみFALSE
2299 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2301 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2303 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2304 feature_type *f_ptr;
2305 f_ptr = &f_info[g_ptr->feat];
2306 if (!turn_flags_ptr->did_kill_wall || !turn_flags_ptr->do_move) return TRUE;
2308 if (one_in_(GRINDNOISE))
2310 if (have_flag(f_ptr->flags, FF_GLASS))
2311 msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
2313 msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
2316 cave_alter_feat(target_ptr, ny, nx, FF_HURT_DISI);
2318 if (!monster_is_valid(m_ptr))
2320 target_ptr->update |= (PU_FLOW);
2321 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2322 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2327 f_ptr = &f_info[g_ptr->feat];
2328 turn_flags_ptr->do_view = TRUE;
2329 turn_flags_ptr->do_turn = TRUE;
2335 * @brief 騎乗中のモンスター情報を更新する
2336 * @param target_ptr プレーヤーへの参照ポインタ
2337 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2338 * @param m_idx モンスターID
2339 * @param oy 移動前の、モンスターのY座標
2340 * @param ox 移動前の、モンスターのX座標
2341 * @param ny 移動後の、モンスターのY座標
2342 * @param ox 移動後の、モンスターのX座標
2343 * @return アイテム等に影響を及ぼしたらTRUE
2345 bool update_riding_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, POSITION ny, POSITION nx)
2347 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2349 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2350 monster_type *y_ptr;
2351 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2352 if (turn_flags_ptr->is_riding_mon)
2353 return move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP);
2355 target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
2360 update_monster(target_ptr, g_ptr->m_idx, TRUE);
2363 g_ptr->m_idx = m_idx;
2366 update_monster(target_ptr, m_idx, TRUE);
2368 lite_spot(target_ptr, oy, ox);
2369 lite_spot(target_ptr, ny, nx);
2375 * @brief モンスターの移動に伴うオブジェクト処理 (アイテム破壊等)
2376 * @param target_ptr プレーヤーへの参照ポインタ
2377 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2378 * @param m_idx モンスターID
2379 * @param ny 移動後の、モンスターのY座標
2380 * @param nx 移動後の、モンスターのX座標
2382 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2384 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2385 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2387 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2389 OBJECT_IDX this_o_idx, next_o_idx;
2390 turn_flags_ptr->do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
2391 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2393 BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
2394 GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
2395 object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
2396 next_o_idx = o_ptr->next_o_idx;
2398 if (turn_flags_ptr->do_take)
2400 /* Skip gold, corpse and statue */
2401 if (o_ptr->tval == TV_GOLD || (o_ptr->tval == TV_CORPSE) || (o_ptr->tval == TV_STATUE))
2405 object_flags(o_ptr, flgs);
2406 object_desc(target_ptr, o_name, o_ptr, 0);
2407 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
2408 update_object_flags(flgs, &flg2, &flg3, &flgr);
2410 bool is_special_object = object_is_artifact(o_ptr) ||
2411 ((r_ptr->flags3 & flg3) != 0) ||
2412 ((r_ptr->flags2 & flg2) != 0) ||
2413 (((~(r_ptr->flagsr) & flgr) != 0) && !(r_ptr->flagsr & RFR_RES_ALL));
2414 monster_pickup_object(target_ptr, turn_flags_ptr, m_idx, o_ptr, is_special_object, ny, nx, m_name, o_name, this_o_idx);
2420 * @brief オブジェクトのフラグを更新する
2422 void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr)
2424 if (have_flag(flgs, TR_SLAY_DRAGON)) *flg3 |= (RF3_DRAGON);
2425 if (have_flag(flgs, TR_KILL_DRAGON)) *flg3 |= (RF3_DRAGON);
2426 if (have_flag(flgs, TR_SLAY_TROLL)) *flg3 |= (RF3_TROLL);
2427 if (have_flag(flgs, TR_KILL_TROLL)) *flg3 |= (RF3_TROLL);
2428 if (have_flag(flgs, TR_SLAY_GIANT)) *flg3 |= (RF3_GIANT);
2429 if (have_flag(flgs, TR_KILL_GIANT)) *flg3 |= (RF3_GIANT);
2430 if (have_flag(flgs, TR_SLAY_ORC)) *flg3 |= (RF3_ORC);
2431 if (have_flag(flgs, TR_KILL_ORC)) *flg3 |= (RF3_ORC);
2432 if (have_flag(flgs, TR_SLAY_DEMON)) *flg3 |= (RF3_DEMON);
2433 if (have_flag(flgs, TR_KILL_DEMON)) *flg3 |= (RF3_DEMON);
2434 if (have_flag(flgs, TR_SLAY_UNDEAD)) *flg3 |= (RF3_UNDEAD);
2435 if (have_flag(flgs, TR_KILL_UNDEAD)) *flg3 |= (RF3_UNDEAD);
2436 if (have_flag(flgs, TR_SLAY_ANIMAL)) *flg3 |= (RF3_ANIMAL);
2437 if (have_flag(flgs, TR_KILL_ANIMAL)) *flg3 |= (RF3_ANIMAL);
2438 if (have_flag(flgs, TR_SLAY_EVIL)) *flg3 |= (RF3_EVIL);
2439 if (have_flag(flgs, TR_KILL_EVIL)) *flg3 |= (RF3_EVIL);
2440 if (have_flag(flgs, TR_SLAY_HUMAN)) *flg2 |= (RF2_HUMAN);
2441 if (have_flag(flgs, TR_KILL_HUMAN)) *flg2 |= (RF2_HUMAN);
2442 if (have_flag(flgs, TR_BRAND_ACID)) *flgr |= (RFR_IM_ACID);
2443 if (have_flag(flgs, TR_BRAND_ELEC)) *flgr |= (RFR_IM_ELEC);
2444 if (have_flag(flgs, TR_BRAND_FIRE)) *flgr |= (RFR_IM_FIRE);
2445 if (have_flag(flgs, TR_BRAND_COLD)) *flgr |= (RFR_IM_COLD);
2446 if (have_flag(flgs, TR_BRAND_POIS)) *flgr |= (RFR_IM_POIS);
2451 * @brief モンスターがアイテムを拾うか壊す処理
2452 * @param target_ptr プレーヤーへの参照ポインタ
2453 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2454 * @param m_idx モンスターID
2455 * @param o_ptr オブジェクトへの参照ポインタ
2456 * @param is_special_object モンスターが拾えないアイテム (アーティファクト等)であればTRUE
2457 * @param ny 移動後の、モンスターのY座標
2458 * @param nx 移動後の、モンスターのX座標
2459 * @param m_name モンスター名
2460 * @param o_name アイテム名
2461 * @param this_o_idx モンスターが乗ったオブジェクトID
2464 void monster_pickup_object(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, object_type *o_ptr, bool is_special_object, POSITION ny, POSITION nx, GAME_TEXT *m_name, GAME_TEXT *o_name, OBJECT_IDX this_o_idx)
2466 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2467 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2468 if (is_special_object)
2470 if (turn_flags_ptr->do_take && (r_ptr->flags2 & RF2_STUPID))
2472 turn_flags_ptr->did_take_item = TRUE;
2473 if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
2475 msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
2482 if (turn_flags_ptr->do_take)
2484 turn_flags_ptr->did_take_item = TRUE;
2485 if (player_can_see_bold(target_ptr, ny, nx))
2487 msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
2490 excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
2491 o_ptr->marked &= OM_TOUCHED;
2492 o_ptr->iy = o_ptr->ix = 0;
2493 o_ptr->held_m_idx = m_idx;
2494 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2495 m_ptr->hold_o_idx = this_o_idx;
2499 if (is_pet(m_ptr)) return;
2501 turn_flags_ptr->did_kill_item = TRUE;
2502 if (player_has_los_bold(target_ptr, ny, nx))
2504 msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
2507 delete_object_idx(target_ptr, this_o_idx);
2512 * @brief updateフィールドを更新する
2513 * @param target_ptr プレーヤーへの参照ポインタ
2514 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2517 void update_player_type(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_race *r_ptr)
2519 if (turn_flags_ptr->do_view)
2521 target_ptr->update |= (PU_FLOW);
2522 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2525 if (turn_flags_ptr->do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
2526 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !target_ptr->phase_out)))
2528 target_ptr->update |= (PU_MON_LITE);
2534 * @brief モンスターのフラグを更新する
2535 * @param target_ptr プレーヤーへの参照ポインタ
2536 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2537 * @param m_ptr モンスターへの参照ポインタ
2540 void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr)
2542 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2543 if (!is_original_ap_and_seen(target_ptr, m_ptr)) return;
2545 if (turn_flags_ptr->did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
2546 if (turn_flags_ptr->did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2547 if (turn_flags_ptr->did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
2548 if (turn_flags_ptr->did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
2549 if (turn_flags_ptr->did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
2550 if (turn_flags_ptr->did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
2551 if (turn_flags_ptr->did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2556 * @brief モンスターの恐怖状態を処理する
2557 * @param target_ptr プレーヤーへの参照ポインタ
2558 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2559 * @param m_idx モンスターID
2560 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
2561 * @return モンスターが戦いを決意したらTRUE
2563 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
2565 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2566 bool is_battle_determined = !turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && MON_MONFEAR(m_ptr) && turn_flags_ptr->aware;
2567 if (!is_battle_determined) return FALSE;
2569 (void)set_monster_monfear(target_ptr, m_idx, 0);
2570 if (!turn_flags_ptr->see_m) return TRUE;
2572 GAME_TEXT m_name[MAX_NLEN];
2573 monster_desc(target_ptr, m_name, m_ptr, 0);
2574 msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
2580 * @brief 全モンスターのターン管理メインルーチン /
2581 * Process all the "live" monsters, once per game turn.
2584 * During each game current game turn, we scan through the list of all the "live" monsters,\n
2585 * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
2586 * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
2588 * Note that monsters can never move in the monster array (except when the\n
2589 * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
2591 * This function is responsible for at least half of the processor time\n
2592 * on a normal system with a "normal" amount of monsters and a player doing\n
2595 * When the player is resting, virtually 90% of the processor time is spent\n
2596 * in this function, and its children, "process_monster()" and "make_move()".\n
2598 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
2599 * especially when the player is running.\n
2601 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
2602 * monsters while they are still being "born". A monster is "fresh" only\n
2603 * during the game turn in which it is created, and we use the "hack_m_idx" to\n
2604 * determine if the monster is yet to be processed during the game turn.\n
2606 * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
2607 * move before any "nasty" monsters get to use their spell attacks.\n
2609 * Note that when the "knowledge" about the currently tracked monster\n
2610 * changes (flags, attacks, spells), we induce a redraw of the monster\n
2613 void process_monsters(player_type *target_ptr)
2615 BIT_FLAGS old_r_flags1 = 0L;
2616 BIT_FLAGS old_r_flags2 = 0L;
2617 BIT_FLAGS old_r_flags3 = 0L;
2618 BIT_FLAGS old_r_flags4 = 0L;
2619 BIT_FLAGS old_r_flags5 = 0L;
2620 BIT_FLAGS old_r_flags6 = 0L;
2621 BIT_FLAGS old_r_flagsr = 0L;
2623 byte old_r_blows0 = 0;
2624 byte old_r_blows1 = 0;
2625 byte old_r_blows2 = 0;
2626 byte old_r_blows3 = 0;
2628 floor_type *floor_ptr = target_ptr->current_floor_ptr;
2629 floor_ptr->monster_noise = FALSE;
2631 MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
2632 byte old_r_cast_spell = 0;
2633 if (target_ptr->monster_race_idx)
2635 monster_race *r_ptr;
2636 r_ptr = &r_info[target_ptr->monster_race_idx];
2638 old_r_flags1 = r_ptr->r_flags1;
2639 old_r_flags2 = r_ptr->r_flags2;
2640 old_r_flags3 = r_ptr->r_flags3;
2641 old_r_flags4 = r_ptr->r_flags4;
2642 old_r_flags5 = r_ptr->r_flags5;
2643 old_r_flags6 = r_ptr->r_flags6;
2644 old_r_flagsr = r_ptr->r_flagsr;
2646 old_r_blows0 = r_ptr->r_blows[0];
2647 old_r_blows1 = r_ptr->r_blows[1];
2648 old_r_blows2 = r_ptr->r_blows[2];
2649 old_r_blows3 = r_ptr->r_blows[3];
2651 old_r_cast_spell = r_ptr->r_cast_spell;
2654 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
2656 monster_type *m_ptr;
2657 monster_race *r_ptr;
2658 m_ptr = &floor_ptr->m_list[i];
2659 r_ptr = &r_info[m_ptr->r_idx];
2661 if (target_ptr->leaving) break;
2662 if (!monster_is_valid(m_ptr)) continue;
2663 if (target_ptr->wild_mode) continue;
2665 if (m_ptr->mflag & MFLAG_BORN)
2667 m_ptr->mflag &= ~(MFLAG_BORN);
2671 if (m_ptr->cdis >= AAF_LIMIT) continue;
2673 POSITION fx = m_ptr->fx;
2674 POSITION fy = m_ptr->fy;
2675 if (!target_ptr->no_flowed)
2677 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
2681 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
2685 else if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
2686 (player_has_los_bold(target_ptr, fy, fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
2690 else if (m_ptr->target_y)
2695 if (!test) continue;
2698 if (target_ptr->riding == i)
2700 speed = target_ptr->pspeed;
2704 speed = m_ptr->mspeed;
2705 if (ironman_nightmare) speed += 5;
2707 if (MON_FAST(m_ptr)) speed += 10;
2708 if (MON_SLOW(m_ptr)) speed -= 10;
2711 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
2712 if (m_ptr->energy_need > 0) continue;
2714 m_ptr->energy_need += ENERGY_NEED();
2716 process_monster(target_ptr, i);
2717 reset_target(m_ptr);
2719 if (target_ptr->no_flowed && one_in_(3))
2720 m_ptr->mflag2 |= MFLAG2_NOFLOW;
2722 if (!target_ptr->playing || target_ptr->is_dead) break;
2723 if (target_ptr->leaving) break;
2727 if (!target_ptr->monster_race_idx || (target_ptr->monster_race_idx != old_monster_race_idx))
2730 monster_race *r_ptr;
2731 r_ptr = &r_info[target_ptr->monster_race_idx];
2733 if ((old_r_flags1 != r_ptr->r_flags1) ||
2734 (old_r_flags2 != r_ptr->r_flags2) ||
2735 (old_r_flags3 != r_ptr->r_flags3) ||
2736 (old_r_flags4 != r_ptr->r_flags4) ||
2737 (old_r_flags5 != r_ptr->r_flags5) ||
2738 (old_r_flags6 != r_ptr->r_flags6) ||
2739 (old_r_flagsr != r_ptr->r_flagsr) ||
2740 (old_r_blows0 != r_ptr->r_blows[0]) ||
2741 (old_r_blows1 != r_ptr->r_blows[1]) ||
2742 (old_r_blows2 != r_ptr->r_blows[2]) ||
2743 (old_r_blows3 != r_ptr->r_blows[3]) ||
2744 (old_r_cast_spell != r_ptr->r_cast_spell))
2746 target_ptr->window |= (PW_MONSTER);