2 * @file monster-process.c
3 * @brief モンスターの特殊技能とターン経過処理 (移動等)/ Monster spells and movement for passaging a turn
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7 * This software may be copied and distributed for educational, research,\n
8 * and not for profit purposes provided that this copyright and statement\n
9 * are included in all such copies. Other copyrights may also apply.\n
10 * 2014 Deskull rearranged comment for Doxygen.\n
12 * This file has several additions to it by Keldon Jones (keldon@umr.edu)
13 * to improve the general quality of the AI (version 0.1.1).
24 #include "spells-floor.h"
25 #include "spells-summon.h"
28 #include "realm-hex.h"
29 #include "object-flavor.h"
30 #include "object-hook.h"
33 #include "player-move.h"
34 #include "monster-status.h"
35 #include "monster-spell.h"
36 #include "monster-process.h"
37 #include "monsterrace-hook.h"
41 #include "view-mainwindow.h"
49 bool must_alter_to_move;
60 turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr);
62 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
63 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx);
64 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
65 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx);
66 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
67 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
68 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
69 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
70 bool explode_monster(player_type *target_ptr, MONSTER_IDX m_idx);
71 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
72 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware);
73 bool runaway_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon, bool see_m);
74 void escape_monster(player_type *target_ptr, bool is_riding_mon, monster_type *m_ptr, GAME_TEXT *m_name, bool see_m);
75 void process_special(player_type *target_ptr, MONSTER_IDX m_idx);
76 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware);
77 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware);
79 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross);
80 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
81 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
82 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash);
83 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
84 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
86 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
87 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);
88 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr);
90 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);
91 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
92 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);
94 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
96 void update_player_type(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_race *r_ptr);
97 void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr);
98 void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr);
99 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);
100 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, bool aware, bool see_m);
103 * @brief モンスターが敵に接近するための方向を決める /
104 * Calculate the direction to the next enemy
105 * @param target_ptr プレーヤーへの参照ポインタ
106 * @param m_idx モンスターの参照ID
107 * @param mm 移動するべき方角IDを返す参照ポインタ
108 * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
110 static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
112 floor_type *floor_ptr = target_ptr->current_floor_ptr;
113 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
114 monster_race *r_ptr = &r_info[m_ptr->r_idx];
116 POSITION x = 0, y = 0;
117 if (target_ptr->riding_t_m_idx && player_bold(target_ptr, m_ptr->fy, m_ptr->fx))
119 y = floor_ptr->m_list[target_ptr->riding_t_m_idx].fy;
120 x = floor_ptr->m_list[target_ptr->riding_t_m_idx].fx;
122 else if (is_pet(m_ptr) && target_ptr->pet_t_m_idx)
124 y = floor_ptr->m_list[target_ptr->pet_t_m_idx].fy;
125 x = floor_ptr->m_list[target_ptr->pet_t_m_idx].fx;
131 if (target_ptr->phase_out)
133 start = randint1(floor_ptr->m_max - 1) + floor_ptr->m_max;
134 if (randint0(2)) plus = -1;
138 start = floor_ptr->m_max + 1;
141 for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus)
143 MONSTER_IDX dummy = (i % floor_ptr->m_max);
144 if (!dummy) continue;
146 MONSTER_IDX t_idx = dummy;
148 t_ptr = &floor_ptr->m_list[t_idx];
150 if (t_ptr == m_ptr) continue;
151 if (!monster_is_valid(t_ptr)) continue;
155 if (target_ptr->pet_follow_distance < 0)
157 if (t_ptr->cdis <= (0 - target_ptr->pet_follow_distance))
162 else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > target_ptr->pet_follow_distance))
167 if (r_ptr->aaf < t_ptr->cdis) continue;
170 if (!are_enemies(target_ptr, m_ptr, t_ptr)) continue;
172 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) ||
173 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)))
175 if (!in_disintegration_range(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
179 if (!projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
188 if (!x && !y) return FALSE;
194 /* North, South, East, West, North-West, North-East, South-West, South-East */
195 if ((y < 0) && (x == 0))
201 else if ((y > 0) && (x == 0))
207 else if ((x > 0) && (y == 0))
213 else if ((x < 0) && (y == 0))
219 else if ((y < 0) && (x < 0))
225 else if ((y < 0) && (x > 0))
231 else if ((y > 0) && (x < 0))
237 else if ((y > 0) && (x > 0))
249 * @brief モンスターがプレイヤーから逃走するかどうかを返す /
250 * Returns whether a given monster will try to run from the player.
251 * @param m_idx 逃走するモンスターの参照ID
252 * @return モンスターがプレイヤーから逃走するならばTRUEを返す。
254 * Monsters will attempt to avoid very powerful players. See below.\n
256 * Because this function is called so often, little details are important\n
257 * for efficiency. Like not using "mod" or "div" when possible. And\n
258 * attempting to check the conditions in an optimal order. Note that\n
259 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
261 * Note that this function is responsible for about one to five percent\n
262 * of the processor use in normal conditions...\n
264 static bool mon_will_run(player_type *target_ptr, MONSTER_IDX m_idx)
266 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
267 monster_race *r_ptr = &r_info[m_ptr->r_idx];
271 return ((target_ptr->pet_follow_distance < 0) &&
272 (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
275 if (m_ptr->cdis > MAX_SIGHT + 5) return FALSE;
276 if (MON_MONFEAR(m_ptr)) return TRUE;
277 if (m_ptr->cdis <= 5) return FALSE;
279 PLAYER_LEVEL p_lev = target_ptr->lev;
280 DEPTH m_lev = r_ptr->level + (m_idx & 0x08) + 25;
281 if (m_lev > p_lev + 4) return FALSE;
282 if (m_lev + 4 <= p_lev) return TRUE;
284 HIT_POINT p_chp = target_ptr->chp;
285 HIT_POINT p_mhp = target_ptr->mhp;
286 HIT_POINT m_chp = m_ptr->hp;
287 HIT_POINT m_mhp = m_ptr->maxhp;
288 u32b p_val = (p_lev * p_mhp) + (p_chp << 2);
289 u32b m_val = (m_lev * m_mhp) + (m_chp << 2);
290 if (p_val * m_mhp > m_val * p_mhp) return TRUE;
297 * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
298 * Search spell castable grid
299 * @param target_ptr プレーヤーへの参照ポインタ
300 * @param m_idx モンスターの参照ID
301 * @param yp 適したマスのY座標を返す参照ポインタ
302 * @param xp 適したマスのX座標を返す参照ポインタ
303 * @return 有効なマスがあった場合TRUEを返す
305 static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
307 floor_type *floor_ptr = target_ptr->current_floor_ptr;
308 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
309 monster_race *r_ptr = &r_info[m_ptr->r_idx];
311 POSITION y1 = m_ptr->fy;
312 POSITION x1 = m_ptr->fx;
314 if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x)) return FALSE;
316 int now_cost = floor_ptr->grid_array[y1][x1].cost;
317 if (now_cost == 0) now_cost = 999;
319 bool can_open_door = FALSE;
320 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
322 can_open_door = TRUE;
326 for (int i = 7; i >= 0; i--)
328 POSITION y = y1 + ddy_ddd[i];
329 POSITION x = x1 + ddx_ddd[i];
330 if (!in_bounds2(floor_ptr, y, x)) continue;
331 if (player_bold(target_ptr, y, x)) return FALSE;
334 g_ptr = &floor_ptr->grid_array[y][x];
335 int cost = g_ptr->cost;
336 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))))
338 if (cost == 0) continue;
339 if (!can_open_door && is_closed_door(target_ptr, g_ptr->feat)) continue;
342 if (cost == 0) cost = 998;
344 if (now_cost < cost) continue;
345 if (!projectable(target_ptr, y, x, target_ptr->y, target_ptr->x)) continue;
346 if (best < cost) continue;
349 *yp = y1 + ddy_ddd[i];
350 *xp = x1 + ddx_ddd[i];
353 if (best == 999) return FALSE;
360 * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
361 * Choose the "best" direction for "flowing"
362 * @param m_idx モンスターの参照ID
363 * @param yp 移動先のマスのY座標を返す参照ポインタ
364 * @param xp 移動先のマスのX座標を返す参照ポインタ
365 * @param no_flow モンスターにFLOWフラグが経っていない状態でTRUE
366 * @return 有効なマスがあった場合TRUEを返す
368 * Note that ghosts and rock-eaters are never allowed to "flow",\n
369 * since they should move directly towards the player.\n
371 * Prefer "non-diagonal" directions, but twiddle them a little\n
372 * to angle slightly towards the player's actual location.\n
374 * Allow very perceptive monsters to track old "spoor" left by\n
375 * previous locations occupied by the player. This will tend\n
376 * to have monsters end up either near the player or on a grid\n
377 * recently occupied by the player (and left via "teleport").\n
379 * Note that if "smell" is turned on, all monsters get vicious.\n
381 * Also note that teleporting away from a location will cause\n
382 * the monsters who were chasing you to converge on that location\n
383 * as long as you are still near enough to "annoy" them without\n
384 * being close enough to chase directly. I have no idea what will\n
385 * happen if you combine "smell" with low "aaf" values.\n
387 static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
390 floor_type *floor_ptr = target_ptr->current_floor_ptr;
391 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
392 monster_race *r_ptr = &r_info[m_ptr->r_idx];
394 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
395 r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
396 r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
398 if (get_moves_aux2(target_ptr, m_idx, yp, xp)) return TRUE;
401 if (no_flow) return FALSE;
402 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) return FALSE;
403 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)) return FALSE;
405 POSITION y1 = m_ptr->fy;
406 POSITION x1 = m_ptr->fx;
407 if (player_has_los_bold(target_ptr, y1, x1) && projectable(target_ptr, target_ptr->y, target_ptr->x, y1, x1)) return FALSE;
409 g_ptr = &floor_ptr->grid_array[y1][x1];
412 bool use_scent = FALSE;
417 else if (g_ptr->when)
419 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when - g_ptr->when > 127) return FALSE;
429 for (int i = 7; i >= 0; i--)
431 POSITION y = y1 + ddy_ddd[i];
432 POSITION x = x1 + ddx_ddd[i];
434 if (!in_bounds2(floor_ptr, y, x)) continue;
436 g_ptr = &floor_ptr->grid_array[y][x];
439 int when = g_ptr->when;
440 if (best > when) continue;
447 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
456 if ((cost == 0) || (best < cost)) continue;
461 *yp = target_ptr->y + 16 * ddy_ddd[i];
462 *xp = target_ptr->x + 16 * ddx_ddd[i];
465 if (best == 999 || best == 0) return FALSE;
472 * @brief モンスターがプレイヤーから逃走することが可能なマスを走査する /
473 * Provide a location to flee to, but give the player a wide berth.
474 * @param m_idx モンスターの参照ID
475 * @param yp 移動先のマスのY座標を返す参照ポインタ
476 * @param xp 移動先のマスのX座標を返す参照ポインタ
477 * @return 有効なマスがあった場合TRUEを返す
479 * A monster may wish to flee to a location that is behind the player,\n
480 * but instead of heading directly for it, the monster should "swerve"\n
481 * around the player so that he has a smaller chance of getting hit.\n
483 static bool get_fear_moves_aux(floor_type *floor_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
485 POSITION gy = 0, gx = 0;
487 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
488 POSITION fy = m_ptr->fy;
489 POSITION fx = m_ptr->fx;
491 POSITION y1 = fy - (*yp);
492 POSITION x1 = fx - (*xp);
495 for (int i = 7; i >= 0; i--)
497 POSITION y = fy + ddy_ddd[i];
498 POSITION x = fx + ddx_ddd[i];
499 if (!in_bounds2(floor_ptr, y, x)) continue;
501 POSITION dis = distance(y, x, y1, x1);
502 POSITION s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
505 if (s < score) continue;
512 if (score == -1) return FALSE;
522 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
525 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
526 * offsets of all the locations with a distance of n from a central point,
527 * with an offset of (0,0) indicating no more offsets at this distance.
529 * This is, of course, fairly unreadable, but it eliminates multiple loops
530 * from the previous version.
532 * It is probably better to replace these arrays with code to compute
533 * the relevant arrays, even if the storage is pre-allocated in hard
534 * coded sizes. At the very least, code should be included which is
535 * able to generate and dump these arrays (ala "los()").
537 * Also, the storage needs could be halved by using bytes.
539 * These arrays could be combined into two big arrays, using sub-arrays
540 * to hold the offsets and lengths of each portion of the sub-arrays, and
541 * this could perhaps also be used somehow in the "look" code.
545 static POSITION d_off_y_0[] = { 0 };
546 static POSITION d_off_x_0[] = { 0 };
548 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
549 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
551 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
552 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
554 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
555 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
557 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 };
558 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 };
561 static POSITION d_off_y_5[] =
562 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
563 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
566 static POSITION d_off_x_5[] =
567 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
568 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
572 static POSITION d_off_y_6[] =
573 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
574 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
577 static POSITION d_off_x_6[] =
578 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
579 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
580 -3, 2, 3, -1, 0, 1, 0 };
583 static POSITION d_off_y_7[] =
584 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
585 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
586 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
588 static POSITION d_off_x_7[] =
589 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
590 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
591 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
595 static POSITION d_off_y_8[] =
596 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
597 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
598 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
601 static POSITION d_off_x_8[] =
602 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
603 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
604 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
608 static POSITION d_off_y_9[] =
609 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
610 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
611 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
612 7, 8, 8, 8, 8, 9, 9, 9, 0 };
614 static POSITION d_off_x_9[] =
615 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
616 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
617 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
618 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
621 static POSITION *dist_offsets_y[10] =
623 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
624 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
627 static POSITION *dist_offsets_x[10] =
629 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
630 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
634 * @brief モンスターが逃げ込める安全な地点を返す /
635 * Choose a "safe" location near a monster for it to run toward.
636 * @param target_ptr プレーヤーへの参照ポインタ
637 * @param m_idx モンスターの参照ID
638 * @param yp 移動先のマスのY座標を返す参照ポインタ
639 * @param xp 移動先のマスのX座標を返す参照ポインタ
640 * @return 有効なマスがあった場合TRUEを返す
642 * A location is "safe" if it can be reached quickly and the player\n
643 * is not able to fire into it (it isn't a "clean shot"). So, this will\n
644 * cause monsters to "duck" behind walls. Hopefully, monsters will also\n
645 * try to run towards corridor openings if they are in a room.\n
647 * This function may take lots of CPU time if lots of monsters are\n
650 * Return TRUE if a safe location is available.\n
652 static bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
654 floor_type *floor_ptr = target_ptr->current_floor_ptr;
655 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
657 POSITION fy = m_ptr->fy;
658 POSITION fx = m_ptr->fx;
660 POSITION gy = 0, gx = 0, gdis = 0;
662 for (POSITION d = 1; d < 10; d++)
665 y_offsets = dist_offsets_y[d];
668 x_offsets = dist_offsets_x[d];
670 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
672 i++, dx = x_offsets[i], dy = y_offsets[i])
674 POSITION y = fy + dy;
675 POSITION x = fx + dx;
676 if (!in_bounds(floor_ptr, y, x)) continue;
679 g_ptr = &floor_ptr->grid_array[y][x];
681 BIT_FLAGS16 riding_mode = (m_idx == target_ptr->riding) ? CEM_RIDING : 0;
682 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], riding_mode))
685 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
687 if (g_ptr->dist == 0) continue;
688 if (g_ptr->dist > floor_ptr->grid_array[fy][fx].dist + 2 * d) continue;
691 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x)) continue;
693 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
694 if (dis <= gdis) continue;
701 if (gdis <= 0) continue;
714 * @brief モンスターが隠れ潜める地点を返す /
715 * Choose a good hiding place near a monster for it to run toward.
716 * @param target_ptr プレーヤーへの参照ポインタ
717 * @param m_idx モンスターの参照ID
718 * @param yp 移動先のマスのY座標を返す参照ポインタ
719 * @param xp 移動先のマスのX座標を返す参照ポインタ
720 * @return 有効なマスがあった場合TRUEを返す
722 * Pack monsters will use this to "ambush" the player and lure him out\n
723 * of corridors into open space so they can swarm him.\n
725 * Return TRUE if a good location is available.\n
727 static bool find_hiding(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
729 floor_type *floor_ptr = target_ptr->current_floor_ptr;
730 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
731 monster_race *r_ptr = &r_info[m_ptr->r_idx];
733 POSITION fy = m_ptr->fy;
734 POSITION fx = m_ptr->fx;
736 POSITION gy = 0, gx = 0, gdis = 999;
738 for (POSITION d = 1; d < 10; d++)
741 y_offsets = dist_offsets_y[d];
744 x_offsets = dist_offsets_x[d];
746 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
748 i++, dx = x_offsets[i], dy = y_offsets[i])
750 POSITION y = fy + dy;
751 POSITION x = fx + dx;
753 if (!in_bounds(floor_ptr, y, x)) continue;
754 if (!monster_can_enter(target_ptr, y, x, r_ptr, 0)) continue;
755 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, fy, fx, y, x, FALSE))
758 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
759 if (dis < gdis && dis >= 2)
767 if (gdis >= 999) continue;
780 * @brief モンスターの移動方向を返す /
781 * Choose "logical" directions for monster movement
782 * @param target_ptr プレーヤーへの参照ポインタ
783 * @param m_idx モンスターの参照ID
784 * @param mm 移動方向を返す方向IDの参照ポインタ
785 * @return 有効方向があった場合TRUEを返す
787 static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
789 floor_type *floor_ptr = target_ptr->current_floor_ptr;
790 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
791 monster_race *r_ptr = &r_info[m_ptr->r_idx];
792 POSITION y = 0, ay, x = 0, ax;
793 POSITION y2 = target_ptr->y;
794 POSITION x2 = target_ptr->x;
796 bool will_run = mon_will_run(target_ptr, m_idx);
798 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) != 0) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2);
799 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) != 0) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall);
801 if (!will_run && m_ptr->target_y)
803 int t_m_idx = floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
805 are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[t_m_idx]) &&
806 los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
807 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
809 y = m_ptr->fy - m_ptr->target_y;
810 x = m_ptr->fx - m_ptr->target_x;
815 if (!done && !will_run && is_hostile(m_ptr) &&
816 (r_ptr->flags1 & RF1_FRIENDS) &&
817 ((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)) ||
818 (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
820 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
821 !(r_ptr->flags2 & RF2_KILL_WALL))
824 for (int i = 0; i < 8; i++)
826 int xx = target_ptr->x + ddx_ddd[i];
827 int yy = target_ptr->y + ddy_ddd[i];
829 if (!in_bounds2(floor_ptr, yy, xx)) continue;
831 g_ptr = &floor_ptr->grid_array[yy][xx];
832 if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0))
838 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].info & CAVE_ROOM) room -= 2;
839 if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
841 if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
842 (target_ptr->mhp + target_ptr->msp))
844 if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
848 if (!done && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
850 for (int i = 0; i < 8; i++)
852 y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
853 x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
854 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
861 if (!in_bounds2(floor_ptr, y2, x2)) continue;
862 if (!monster_can_enter(target_ptr, y2, x2, r_ptr, 0)) continue;
875 (void)get_moves_aux(target_ptr, m_idx, &y2, &x2, no_flow);
880 if (is_pet(m_ptr) && will_run)
886 if (!done && will_run)
890 if (find_safety(target_ptr, m_idx, &y, &x) && !no_flow)
892 if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x))
904 if (!x && !y) return FALSE;
910 if (y < 0) move_val += 8;
911 if (x > 0) move_val += 4;
913 if (ay > (ax << 1)) move_val += 2;
914 else if (ax > (ay << 1)) move_val++;
1064 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
1066 return !have_flag(f_ptr->flags, FF_GLASS) ||
1067 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
1068 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
1073 * @brief モンスター単体の1ターン行動処理メインルーチン /
1075 * @param target_ptr プレーヤーへの参照ポインタ
1076 * @param m_idx 行動モンスターの参照ID
1079 * The monster is known to be within 100 grids of the player\n
1081 * In several cases, we directly update the monster lore\n
1083 * Note that a monster is only allowed to "reproduce" if there\n
1084 * are a limited number of "reproducing" monsters on the current\n
1085 * level. This should prevent the level from being "swamped" by\n
1086 * reproducing monsters. It also allows a large mass of mice to\n
1087 * prevent a louse from multiplying, but this is a small price to\n
1088 * pay for a simple multiplication method.\n
1090 * XXX Monster fear is slightly odd, in particular, monsters will\n
1091 * fixate on opening a door even if they cannot open it. Actually,\n
1092 * the same thing happens to normal monsters when they hit a door\n
1094 * In addition, monsters which *cannot* open or bash\n
1095 * down a door will still stand there trying to open it...\n
1097 * XXX Technically, need to check for monster in the way\n
1098 * combined with that monster being in a wall (or door?)\n
1100 * A "direction" of "5" means "pick a random direction".\n
1102 void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1104 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1105 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1106 turn_flags tmp_flags;
1107 turn_flags *turn_flags_ptr = init_turn_flags(target_ptr, m_idx, &tmp_flags);
1108 bool see_m = is_seen(m_ptr);
1110 decide_drop_from_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon);
1111 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
1113 choose_new_monster(target_ptr, m_idx, FALSE, 0);
1114 r_ptr = &r_info[m_ptr->r_idx];
1117 bool aware = process_stealth(target_ptr, m_idx);
1118 if (vanish_summoned_children(target_ptr, m_idx, see_m)) return;
1119 if (process_quantum_effect(target_ptr,m_idx, see_m)) return;
1120 if (explode_monster(target_ptr, m_idx)) return;
1121 if (runaway_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon, see_m)) return;
1123 awake_monster(target_ptr, m_idx);
1124 if (MON_STUNNED(m_ptr))
1126 if (one_in_(2)) return;
1129 if (turn_flags_ptr->is_riding_mon)
1131 target_ptr->update |= (PU_BONUS);
1134 process_angar(target_ptr, m_idx, see_m);
1136 POSITION oy = m_ptr->fy;
1137 POSITION ox = m_ptr->fx;
1138 if (decide_monster_multiplication(target_ptr, m_idx, oy, ox)) return;
1140 process_special(target_ptr, m_idx);
1141 process_speak_sound(target_ptr, m_idx, oy, ox, aware);
1142 if (cast_spell(target_ptr, m_idx, aware)) return;
1145 mm[0] = mm[1] = mm[2] = mm[3] = 0;
1146 mm[4] = mm[5] = mm[6] = mm[7] = 0;
1148 if (!decide_monster_movement_direction(target_ptr, mm, m_idx, aware)) return;
1151 if(!process_monster_movement(target_ptr, turn_flags_ptr, m_idx, mm, oy, ox, &count)) return;
1154 * Forward movements failed, but now received LOS attack!
1155 * Try to flow by smell.
1157 if (target_ptr->no_flowed && count > 2 && m_ptr->target_y)
1158 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
1160 if (!turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && !MON_MONFEAR(m_ptr) && !turn_flags_ptr->is_riding_mon && aware)
1162 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
1164 if (make_attack_spell(m_idx, target_ptr)) return;
1168 update_player_type(target_ptr, turn_flags_ptr, r_ptr);
1169 update_monster_race_flags(target_ptr, turn_flags_ptr, m_ptr);
1171 if (!process_monster_fear(target_ptr, turn_flags_ptr, m_idx, aware, see_m)) return;
1173 if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
1178 * @brief ターン経過フラグ構造体の初期化
1179 * @param target_ptr プレーヤーへの参照ポインタ
1180 * @param m_idx モンスターID
1181 * @return 初期化済のターン経過フラグ
1183 turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr)
1185 turn_flags_ptr->is_riding_mon = (m_idx == target_ptr->riding);
1186 turn_flags_ptr->do_turn = FALSE;
1187 turn_flags_ptr->do_move = FALSE;
1188 turn_flags_ptr->do_view = FALSE;
1189 turn_flags_ptr->must_alter_to_move = FALSE;
1190 turn_flags_ptr->did_open_door = FALSE;
1191 turn_flags_ptr->did_bash_door = FALSE;
1192 turn_flags_ptr->did_take_item = FALSE;
1193 turn_flags_ptr->did_kill_item = FALSE;
1194 turn_flags_ptr->did_move_body = FALSE;
1195 turn_flags_ptr->did_pass_wall = FALSE;
1196 turn_flags_ptr->did_kill_wall = FALSE;
1197 return turn_flags_ptr;
1202 * @brief 超隠密処理 (のはず todo)
1203 * @param target_ptr プレーヤーへの参照ポインタ
1204 * @param m_idx モンスターID
1205 * @return 超隠密状態ならばTRUE
1207 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx)
1209 if ((target_ptr->special_defense & NINJA_S_STEALTH) == 0) return TRUE;
1211 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1212 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1213 int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
1214 if (target_ptr->monlite) tmp /= 3;
1215 if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1216 if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
1217 return (randint0(tmp) <= (r_ptr->level + 20));
1222 * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
1223 * @param target_ptr プレーヤーへの参照ポインタ
1224 * @param m_idx モンスターID
1225 * @param is_riding_mon 騎乗中であればTRUE
1228 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
1230 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1231 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1232 if (!is_riding_mon || ((r_ptr->flags7 & RF7_RIDING) != 0)) return;
1234 if (rakuba(target_ptr, 0, TRUE))
1237 msg_print("地面に落とされた。");
1239 GAME_TEXT m_name[MAX_NLEN];
1240 monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
1241 msg_format("You have fallen from %s.", m_name);
1248 * @brief 召喚の親元が消滅した時、子供も消滅させる
1249 * @param target_ptr プレーヤーへの参照ポインタ
1250 * @param m_idx モンスターID
1251 * @param see_m モンスターが視界内にいたらTRUE
1252 * @return 召喚モンスターが消滅したらTRUE
1254 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1256 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1257 if ((m_ptr->parent_m_idx == 0) || (target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx > 0))
1262 GAME_TEXT m_name[MAX_NLEN];
1263 monster_desc(target_ptr, m_name, m_ptr, 0);
1264 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1267 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1269 GAME_TEXT m_name[MAX_NLEN];
1270 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
1271 exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
1274 delete_monster_idx(target_ptr, m_idx);
1280 * @brief 寝ているモンスターの起床を判定する
1281 * @param target_ptr プレーヤーへの参照ポインタ
1282 * @param m_idx モンスターID
1285 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1287 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1288 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1289 if (!MON_CSLEEP(m_ptr)) return;
1290 if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
1292 (void)set_monster_csleep(target_ptr, m_idx, 0);
1295 GAME_TEXT m_name[MAX_NLEN];
1296 monster_desc(target_ptr, m_name, m_ptr, 0);
1297 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
1300 if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
1308 * @brief モンスターの怒り状態を判定する (起こっていたら敵に回す)
1309 * @param target_ptr プレーヤーへの参照ポインタ
1310 * @param m_idx モンスターID
1311 * @param see_m モンスターが視界内にいたらTRUE
1314 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1316 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1317 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1318 bool gets_angry = FALSE;
1319 if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
1322 if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
1323 monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
1328 if (target_ptr->phase_out || !gets_angry) return;
1330 if (is_pet(m_ptr) || see_m)
1332 GAME_TEXT m_name[MAX_NLEN];
1333 monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
1334 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
1337 set_hostile(target_ptr, m_ptr);
1342 * @brief 量子生物の量子的効果を実行する
1343 * @param target_ptr プレーヤーへの参照ポインタ
1344 * @param m_idx モンスターID
1345 * @param see_m モンスターが視界内にいたらTRUE
1346 * @return モンスターが量子的効果により消滅したらTRUE
1348 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1350 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1351 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1352 if ((r_ptr->flags2 & RF2_QUANTUM) == 0) return FALSE;
1353 if (!randint0(2)) return FALSE;
1354 if (randint0((m_idx % 100) + 10)) return FALSE;
1356 bool can_disappear = (r_ptr->flags1 & RF1_UNIQUE) == 0;
1357 can_disappear &= (r_ptr->flags1 & RF1_QUESTOR) == 0;
1360 vanish_nonunique(target_ptr, m_idx, see_m);
1364 produce_quantum_effect(target_ptr, m_idx, see_m);
1370 * @brief ユニークでない量子生物を消滅させる
1371 * @param target_ptr プレーヤーへの参照ポインタ
1372 * @param m_idx モンスターID
1373 * @param see_m モンスターが視界内にいたらTRUE
1376 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1378 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1381 GAME_TEXT m_name[MAX_NLEN];
1382 monster_desc(target_ptr, m_name, m_ptr, 0);
1383 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1386 monster_death(target_ptr, m_idx, FALSE);
1387 delete_monster_idx(target_ptr, m_idx);
1388 if (is_pet(m_ptr) && !(m_ptr->ml))
1390 msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
1396 * @brief 量子生物ユニークの量子的効果 (ショート・テレポートまたは距離10のテレポート・アウェイ)を実行する
1397 * @param target_ptr プレーヤーへの参照ポインタ
1398 * @param m_idx モンスターID
1399 * @param see_m モンスターが視界内にいたらTRUE
1402 * プレーヤーが量子生物を観測しているか、量子生物がプレーヤーを観測している場合、互いの相対的な位置を確定させる
1403 * 波動関数の収縮はテレポートではないので反テレポート無効
1404 * todo パターンは収縮どころか拡散しているが、この際気にしてはいけない
1406 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1408 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1409 bool coherent = los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x);
1410 if (!see_m && !coherent) return;
1414 GAME_TEXT m_name[MAX_NLEN];
1415 monster_desc(target_ptr, m_name, m_ptr, 0);
1416 msg_format(_("%sは量子的効果を起こした!", "%^s produced a decoherence!"), m_name);
1420 msg_print(_("量子的効果が起こった!", "A decoherence was produced!"));
1423 bool target = one_in_(2);
1424 const int blink = 32 * 5 + 4;
1427 (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx);
1432 teleport_player_away(m_idx, target_ptr, 10, TRUE);
1439 * @param target_ptr プレーヤーへの参照ポインタ
1440 * @param m_idx モンスターID
1443 bool explode_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1445 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1446 if (m_ptr->r_idx != MON_SHURYUUDAN) return FALSE;
1449 mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
1455 * @brief モンスター依存の特別な行動を取らせる
1456 * @param target_ptr プレーヤーへの参照ポインタ
1457 * @param m_idx モンスターID
1460 void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
1462 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1463 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1464 if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
1465 if (m_ptr->r_idx != MON_OHMU) return;
1466 if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
1467 if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
1470 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1471 BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
1473 for (int k = 0; k < A_MAX; k++)
1475 if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
1477 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
1481 if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
1486 * @brief モンスターを喋らせたり足音を立てたりする
1487 * @param target_ptr プレーヤーへの参照ポインタ
1488 * @param m_idx モンスターID
1489 * @param oy モンスターが元々いたY座標
1490 * @param ox モンスターが元々いたX座標
1491 * @param aware 超隠密状態ならばTRUE
1494 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware)
1496 if (target_ptr->phase_out) return;
1498 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1499 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1500 if (m_ptr->ap_r_idx == MON_CYBER &&
1501 one_in_(CYBERNOISE) &&
1502 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
1504 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
1505 msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
1508 if (((ap_r_ptr->flags2 & RF2_CAN_SPEAK) == 0) || !aware ||
1509 !one_in_(SPEAK_CHANCE) ||
1510 !player_has_los_bold(target_ptr, oy, ox) ||
1511 !projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
1514 GAME_TEXT m_name[MAX_NLEN];
1515 char monmessage[1024];
1519 monster_desc(target_ptr, m_name, m_ptr, 0);
1521 strcpy(m_name, _("それ", "It"));
1523 if (MON_MONFEAR(m_ptr))
1524 filename = _("monfear_j.txt", "monfear.txt");
1525 else if (is_pet(m_ptr))
1526 filename = _("monpet_j.txt", "monpet.txt");
1527 else if (is_friendly(m_ptr))
1528 filename = _("monfrien_j.txt", "monfrien.txt");
1530 filename = _("monspeak_j.txt", "monspeak.txt");
1532 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
1534 msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
1540 * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
1541 * @param target_ptr プレーヤーへの参照ポインタ
1542 * @param m_idx モンスターID
1543 * @param oy 分裂元モンスターのY座標
1544 * @param ox 分裂元モンスターのX座標
1545 * @return 実際に分裂したらTRUEを返す
1547 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
1549 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1550 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1551 if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) || (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
1555 for (POSITION y = oy - 1; y <= oy + 1; y++)
1557 for (POSITION x = ox - 1; x <= ox + 1; x++)
1559 if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
1560 if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
1564 if (multiply_barrier(target_ptr, m_idx)) k = 8;
1566 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
1568 if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
1570 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
1572 r_ptr->r_flags2 |= (RF2_MULTIPLY);
1584 * @brief モンスターの移動パターンを決定する
1585 * @param target_ptr プレーヤーへの参照ポインタ
1587 * @param m_idx モンスターID
1588 * @param aware 超隠密状態ならばTRUE
1589 * @return 移動先が存在すればTRUE
1591 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware)
1593 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1594 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1596 if (MON_CONFUSED(m_ptr) || !aware)
1598 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1602 if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) && (randint0(100) < 75))
1604 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
1606 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1610 if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 50))
1612 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
1614 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1618 if ((r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 25))
1620 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
1622 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1626 if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
1628 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1634 bool avoid = ((target_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
1635 bool lonely = (!avoid && (m_ptr->cdis > target_ptr->pet_follow_distance));
1636 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
1637 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1638 if (!get_enemy_dir(target_ptr, m_idx, mm))
1640 if (avoid || lonely || distant)
1642 POSITION dis = target_ptr->pet_follow_distance;
1643 if (target_ptr->pet_follow_distance > PET_SEEK_DIST)
1645 target_ptr->pet_follow_distance = PET_SEEK_DIST;
1648 (void)get_moves(target_ptr, m_idx, mm);
1649 target_ptr->pet_follow_distance = (s16b)dis;
1656 if (!is_hostile(m_ptr))
1658 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1659 get_enemy_dir(target_ptr, m_idx, mm);
1663 if (!get_moves(target_ptr, m_idx, mm)) return FALSE;
1670 * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
1671 * @param target_ptr プレーヤーへの参照ポインタ
1672 * @param m_idx モンスターID
1673 * @param is_riding_mon 騎乗状態ならばTRUE
1674 * @param see_m モンスターが視界内にいたらTRUE
1675 * @return モンスターがフロアから消えたらTRUE
1677 bool runaway_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon, bool see_m)
1679 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1680 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1681 bool can_runaway = is_pet(m_ptr) || is_friendly(m_ptr);
1682 can_runaway &= ((r_ptr->flags1 & RF1_UNIQUE) != 0) || ((r_ptr->flags7 & RF7_NAZGUL) != 0);
1683 can_runaway &= !target_ptr->phase_out;
1684 if (!can_runaway) return FALSE;
1686 static int riding_pinch = 0;
1688 if (m_ptr->hp >= m_ptr->maxhp / 3)
1690 /* Reset the counter */
1691 if (is_riding_mon) riding_pinch = 0;
1696 GAME_TEXT m_name[MAX_NLEN];
1697 monster_desc(target_ptr, m_name, m_ptr, 0);
1698 if (is_riding_mon && riding_pinch < 2)
1700 msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
1701 "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
1703 disturb(target_ptr, TRUE, TRUE);
1707 escape_monster(target_ptr, is_riding_mon, m_ptr, m_name, see_m);
1708 check_quest_completion(target_ptr, m_ptr);
1709 delete_monster_idx(target_ptr, m_idx);
1715 * @brief HPが1/3未満になった有効的なユニークモンスターの逃走処理を行う
1716 * @param target_ptr プレーヤーへの参照ポインタ
1717 * @param is_riding_mon 騎乗状態ならばTRUE
1718 * @param m_ptr モンスターへの参照ポインタ
1719 * @param m_name モンスター名称
1720 * @param see_m モンスターが視界内にいたらTRUE
1723 void escape_monster(player_type *target_ptr, bool is_riding_mon, monster_type *m_ptr, GAME_TEXT *m_name, bool see_m)
1725 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1728 msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
1729 if (rakuba(target_ptr, -1, FALSE))
1731 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1737 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) &&
1738 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))
1740 msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
1743 msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s reads a scroll of teleport level."), m_name);
1744 msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
1747 if (is_riding_mon && rakuba(target_ptr, -1, FALSE))
1749 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1755 * @brief モンスターに魔法を試行させる
1756 * @param target_ptr プレーヤーへの参照ポインタ
1757 * @param m_idx モンスターID
1758 * @param aware 超隠密状態ならばTRUE
1759 * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
1761 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware)
1763 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1764 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1765 if ((r_ptr->freq_spell == 0) || (randint1(100) > r_ptr->freq_spell))
1768 bool counterattack = FALSE;
1769 if (m_ptr->target_y)
1771 MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
1772 if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
1773 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1775 counterattack = TRUE;
1781 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1782 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1786 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1787 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1795 * @brief モンスターの移動に関するメインルーチン
1796 * @param target_ptr プレーヤーへの参照ポインタ
1797 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
1798 * @param m_idx モンスターID
1799 * @param mm モンスターの移動方向
1800 * @param oy 移動前の、モンスターのY座標
1801 * @param ox 移動前の、モンスターのX座標
1802 * @param count 移動回数 (のはず todo)
1803 * @return 移動が阻害される何か (ドア等)があったらFALSE
1805 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)
1807 for (int i = 0; mm[i]; i++)
1810 if (d == 5) d = ddd[randint0(8)];
1812 POSITION ny = oy + ddy[d];
1813 POSITION nx = ox + ddx[d];
1814 if (!in_bounds2(target_ptr->current_floor_ptr, ny, nx)) continue;
1817 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1818 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1819 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1820 bool can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0);
1822 if (!process_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx, can_cross))
1824 if (!process_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1828 if (!process_protection_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1830 if (!process_explosive_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1834 exe_monster_attack_to_player(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1835 if (process_monster_attack_to_monster(target_ptr, turn_flags_ptr, m_idx, g_ptr, can_cross)) return FALSE;
1837 if (turn_flags_ptr->is_riding_mon)
1839 if (!target_ptr->riding_ryoute && !MON_MONFEAR(&target_ptr->current_floor_ptr->m_list[target_ptr->riding])) turn_flags_ptr->do_move = FALSE;
1842 if (!process_post_dig_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx)) return FALSE;
1844 if (turn_flags_ptr->must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
1846 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0))
1847 turn_flags_ptr->do_move = FALSE;
1850 if (turn_flags_ptr->do_move && !can_cross && !turn_flags_ptr->did_kill_wall && !turn_flags_ptr->did_bash_door)
1851 turn_flags_ptr->do_move = FALSE;
1853 if (turn_flags_ptr->do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
1855 if (is_original_ap_and_seen(target_ptr, m_ptr))
1856 r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
1858 turn_flags_ptr->do_move = FALSE;
1861 if (!turn_flags_ptr->do_move)
1863 if (turn_flags_ptr->do_turn) break;
1868 turn_flags_ptr->do_turn = TRUE;
1869 feature_type *f_ptr;
1870 f_ptr = &f_info[g_ptr->feat];
1871 if (have_flag(f_ptr->flags, FF_TREE))
1873 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
1875 m_ptr->energy_need += ENERGY_NEED();
1879 if (!update_riding_monster(target_ptr, turn_flags_ptr, m_idx, oy, ox, ny, nx)) break;
1881 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1884 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
1885 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= target_ptr->lev)))
1887 if (is_hostile(m_ptr))
1888 disturb(target_ptr, FALSE, TRUE);
1891 bool is_takable_or_killable = g_ptr->o_idx > 0;
1892 is_takable_or_killable &= (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) != 0;
1894 bool is_pickup_items = (target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
1895 is_pickup_items &= (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
1897 is_takable_or_killable &= !is_pet(m_ptr) || is_pickup_items;
1898 if (!is_takable_or_killable)
1900 if (turn_flags_ptr->do_turn) break;
1905 update_object_by_monster_movement(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1907 if (turn_flags_ptr->do_turn) break;
1917 * @brief モンスターによる壁の透過・破壊を行う
1918 * @param target_ptr プレーヤーへの参照ポインタ
1919 * @param m_ptr モンスターへの参照ポインタ
1920 * @param ny モンスターのY座標
1921 * @param nx モンスターのX座標
1922 * @param can_cross モンスターが地形を踏破できるならばTRUE
1923 * @return 透過も破壊もしなかった場合はFALSE、それ以外はTRUE
1925 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross)
1927 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1929 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1930 feature_type *f_ptr;
1931 f_ptr = &f_info[g_ptr->feat];
1932 if (player_bold(target_ptr, ny, nx))
1934 turn_flags_ptr->do_move = TRUE;
1938 if (g_ptr->m_idx > 0)
1940 turn_flags_ptr->do_move = TRUE;
1944 if (((r_ptr->flags2 & RF2_KILL_WALL) != 0) &&
1945 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !turn_flags_ptr->is_riding_mon) &&
1946 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
1947 check_hp_for_feat_destruction(f_ptr, m_ptr))
1949 turn_flags_ptr->do_move = TRUE;
1950 if (!can_cross) turn_flags_ptr->must_alter_to_move = TRUE;
1952 turn_flags_ptr->did_kill_wall = TRUE;
1956 if (!can_cross) return FALSE;
1958 turn_flags_ptr->do_move = TRUE;
1959 if (((r_ptr->flags2 & RF2_PASS_WALL) != 0) && (!turn_flags_ptr->is_riding_mon || target_ptr->pass_wall) &&
1960 have_flag(f_ptr->flags, FF_CAN_PASS))
1962 turn_flags_ptr->did_pass_wall = TRUE;
1970 * @brief モンスターによるドアの開放・破壊を行う
1971 * @param target_ptr プレーヤーへの参照ポインタ
1972 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
1973 * @param m_ptr モンスターへの参照ポインタ
1974 * @param ny モンスターのY座標
1975 * @param nx モンスターのX座標
1976 * @return モンスターが死亡した場合のみFALSE
1978 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
1980 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1982 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1983 if (!is_closed_door(target_ptr, g_ptr->feat)) return TRUE;
1985 feature_type *f_ptr;
1986 f_ptr = &f_info[g_ptr->feat];
1987 bool may_bash = bash_normal_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx);
1988 bash_glass_door(target_ptr, turn_flags_ptr, m_ptr, f_ptr, may_bash);
1990 if (!turn_flags_ptr->did_open_door && !turn_flags_ptr->did_bash_door) return TRUE;
1992 if (turn_flags_ptr->did_bash_door &&
1993 ((randint0(100) < 50) || (feat_state(target_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
1995 cave_alter_feat(target_ptr, ny, nx, FF_BASH);
1996 if (!monster_is_valid(m_ptr))
1998 target_ptr->update |= (PU_FLOW);
1999 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2000 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2007 cave_alter_feat(target_ptr, ny, nx, FF_OPEN);
2010 f_ptr = &f_info[g_ptr->feat];
2011 turn_flags_ptr->do_view = TRUE;
2017 * @brief モンスターが普通のドアを開ける処理
2018 * @param target_ptr プレーヤーへの参照ポインタ
2019 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2020 * @param m_ptr モンスターへの参照ポインタ
2021 * @param ny モンスターのY座標
2022 * @param nx モンスターのX座標
2023 * @return ここではドアを開けず、ガラスのドアを開ける可能性があるならTRUE
2025 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2027 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2029 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2030 feature_type *f_ptr;
2031 f_ptr = &f_info[g_ptr->feat];
2032 turn_flags_ptr->do_move = FALSE;
2033 if (((r_ptr->flags2 & RF2_OPEN_DOOR) == 0) || !have_flag(f_ptr->flags, FF_OPEN) ||
2034 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2037 if (f_ptr->power == 0)
2039 turn_flags_ptr->did_open_door = TRUE;
2040 turn_flags_ptr->do_turn = TRUE;
2044 if (randint0(m_ptr->hp / 10) > f_ptr->power)
2046 cave_alter_feat(target_ptr, ny, nx, FF_DISARM);
2047 turn_flags_ptr->do_turn = TRUE;
2056 * @brief モンスターがガラスのドアを開ける処理
2057 * @param target_ptr プレーヤーへの参照ポインタ
2058 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2059 * @param m_ptr モンスターへの参照ポインタ
2060 * @param g_ptr グリッドへの参照ポインタ
2061 * @param f_ptr 地形への参照ポインタ
2064 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash)
2066 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2067 if (!may_bash || ((r_ptr->flags2 & RF2_BASH_DOOR) == 0) || !have_flag(f_ptr->flags, FF_BASH) ||
2068 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2071 if (!check_hp_for_feat_destruction(f_ptr, m_ptr) || (randint0(m_ptr->hp / 10) <= f_ptr->power))
2074 if (have_flag(f_ptr->flags, FF_GLASS))
2075 msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
2077 msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
2079 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
2081 turn_flags_ptr->did_bash_door = TRUE;
2082 turn_flags_ptr->do_move = TRUE;
2083 turn_flags_ptr->must_alter_to_move = TRUE;
2088 * @brief 守りのルーンによるモンスターの移動制限を処理する
2089 * @param target_ptr プレーヤーへの参照ポインタ
2090 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2091 * @param m_ptr モンスターへの参照ポインタ
2092 * @param ny モンスターのY座標
2093 * @param nx モンスターのX座標
2096 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2099 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2100 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2101 if (!turn_flags_ptr->do_move || !is_glyph_grid(g_ptr) ||
2102 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2105 turn_flags_ptr->do_move = FALSE;
2106 if (is_pet(m_ptr) || (randint1(BREAK_GLYPH) >= r_ptr->level))
2109 if (g_ptr->info & CAVE_MARK)
2111 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2114 g_ptr->info &= ~(CAVE_MARK);
2115 g_ptr->info &= ~(CAVE_OBJECT);
2117 turn_flags_ptr->do_move = TRUE;
2118 note_spot(target_ptr, ny, nx);
2124 * @brief 爆発のルーンにを処理する
2125 * @param target_ptr プレーヤーへの参照ポインタ
2126 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2127 * @param m_ptr モンスターへの参照ポインタ
2128 * @param ny モンスターのY座標
2129 * @param nx モンスターのX座標
2130 * @return モンスターが死亡した場合のみFALSE
2132 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2135 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2136 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2137 if (!turn_flags_ptr->do_move || !is_explosive_rune_grid(g_ptr) ||
2138 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2141 turn_flags_ptr->do_move = FALSE;
2142 if (is_pet(m_ptr)) return TRUE;
2144 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2146 if (g_ptr->info & CAVE_MARK)
2148 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2149 BIT_FLAGS project_flags = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI;
2150 project(target_ptr, 0, 2, ny, nx, 2 * (target_ptr->lev + damroll(7, 7)), GF_MANA, project_flags, -1);
2155 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2158 g_ptr->info &= ~(CAVE_MARK);
2159 g_ptr->info &= ~(CAVE_OBJECT);
2162 note_spot(target_ptr, ny, nx);
2163 lite_spot(target_ptr, ny, nx);
2165 if (!monster_is_valid(m_ptr)) return FALSE;
2167 turn_flags_ptr->do_move = TRUE;
2173 * @brief モンスターが移動した結果、そこにプレーヤーがいたら直接攻撃を行う
2174 * @param target_ptr プレーヤーへの参照ポインタ
2175 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2176 * @param m_idx モンスターID
2177 * @param ny 移動後の、モンスターのY座標
2178 * @param nx 移動後の、モンスターのX座標
2181 * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
2183 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2185 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2186 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2187 if (!turn_flags_ptr->do_move || !player_bold(target_ptr, ny, nx))
2190 if (r_ptr->flags1 & RF1_NEVER_BLOW)
2192 if (is_original_ap_and_seen(target_ptr, m_ptr))
2193 r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
2195 turn_flags_ptr->do_move = FALSE;
2198 if (turn_flags_ptr->do_move && ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) != 0) && !MON_CONFUSED(m_ptr))
2200 if (!(r_ptr->flags2 & RF2_STUPID))
2201 turn_flags_ptr->do_move = FALSE;
2202 else if (is_original_ap_and_seen(target_ptr, m_ptr))
2203 r_ptr->r_flags2 |= (RF2_STUPID);
2206 if (!turn_flags_ptr->do_move) return;
2208 if (!target_ptr->riding || one_in_(2))
2210 (void)make_attack_normal(target_ptr, m_idx);
2211 turn_flags_ptr->do_move = FALSE;
2212 turn_flags_ptr->do_turn = TRUE;
2218 * @brief モンスターからモンスターへの攻撃処理
2219 * @param target_ptr プレーヤーへの参照ポインタ
2220 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2221 * @param m_idx モンスターID
2222 * @param g_ptr グリッドへの参照ポインタ
2223 * @param can_cross モンスターが地形を踏破できるならばTRUE
2224 * @return ターン消費が発生したらTRUE
2226 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)
2228 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2229 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2230 monster_type *y_ptr;
2231 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2232 if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) return FALSE;
2234 monster_race *z_ptr = &r_info[y_ptr->r_idx];
2235 turn_flags_ptr->do_move = FALSE;
2236 if ((((r_ptr->flags2 & RF2_KILL_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_BLOW) == 0) &&
2237 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
2238 can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
2239 are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
2241 return exe_monster_attack_to_monster(target_ptr, m_idx, g_ptr);
2244 if (((r_ptr->flags2 & RF2_MOVE_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_MOVE) == 0) &&
2245 (r_ptr->mexp > z_ptr->mexp) &&
2246 can_cross && (g_ptr->m_idx != target_ptr->riding) &&
2247 monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
2249 turn_flags_ptr->do_move = TRUE;
2250 turn_flags_ptr->did_move_body = TRUE;
2251 (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
2259 * @brief モンスターからモンスターへの直接攻撃を実行する
2260 * @param target_ptr プレーヤーへの参照ポインタ
2261 * @param m_idx モンスターID
2262 * @param g_ptr グリッドへの参照ポインタ
2264 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr)
2266 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2267 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2268 monster_type *y_ptr;
2269 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2270 if ((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) return FALSE;
2272 if (((r_ptr->flags2 & RF2_KILL_BODY) == 0) && is_original_ap_and_seen(target_ptr, m_ptr))
2273 r_ptr->r_flags2 |= (RF2_KILL_BODY);
2275 if ((y_ptr->r_idx == 0) || (y_ptr->hp < 0)) return FALSE;
2276 if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return TRUE;
2277 if ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) == 0) return FALSE;
2278 if (MON_CONFUSED(m_ptr)) return TRUE;
2279 if ((r_ptr->flags2 & RF2_STUPID) == 0) return FALSE;
2281 if (is_original_ap_and_seen(target_ptr, m_ptr))
2282 r_ptr->r_flags2 |= (RF2_STUPID);
2289 * @brief モンスターが壁を掘った後続処理を実行する
2290 * @param target_ptr プレーヤーへの参照ポインタ
2291 * @turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2292 * @param m_ptr モンスターへの参照ポインタ
2293 * @param ny モンスターのY座標
2294 * @param nx モンスターのX座標
2295 * @return モンスターが死亡した場合のみFALSE
2297 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2299 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2301 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2302 feature_type *f_ptr;
2303 f_ptr = &f_info[g_ptr->feat];
2304 if (!turn_flags_ptr->did_kill_wall || !turn_flags_ptr->do_move) return TRUE;
2306 if (one_in_(GRINDNOISE))
2308 if (have_flag(f_ptr->flags, FF_GLASS))
2309 msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
2311 msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
2314 cave_alter_feat(target_ptr, ny, nx, FF_HURT_DISI);
2316 if (!monster_is_valid(m_ptr))
2318 target_ptr->update |= (PU_FLOW);
2319 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2320 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2325 f_ptr = &f_info[g_ptr->feat];
2326 turn_flags_ptr->do_view = TRUE;
2327 turn_flags_ptr->do_turn = TRUE;
2333 * @brief 騎乗中のモンスター情報を更新する
2334 * @param target_ptr プレーヤーへの参照ポインタ
2335 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2336 * @param m_idx モンスターID
2337 * @param oy 移動前の、モンスターのY座標
2338 * @param ox 移動前の、モンスターのX座標
2339 * @param ny 移動後の、モンスターのY座標
2340 * @param ox 移動後の、モンスターのX座標
2341 * @return アイテム等に影響を及ぼしたらTRUE
2343 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)
2345 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2347 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2348 monster_type *y_ptr;
2349 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2350 if (turn_flags_ptr->is_riding_mon)
2351 return move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP);
2353 target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
2358 update_monster(target_ptr, g_ptr->m_idx, TRUE);
2361 g_ptr->m_idx = m_idx;
2364 update_monster(target_ptr, m_idx, TRUE);
2366 lite_spot(target_ptr, oy, ox);
2367 lite_spot(target_ptr, ny, nx);
2373 * @brief モンスターの移動に伴うオブジェクト処理 (アイテム破壊等)
2374 * @param target_ptr プレーヤーへの参照ポインタ
2375 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2376 * @param m_idx モンスターID
2377 * @param ny 移動後の、モンスターのY座標
2378 * @param nx 移動後の、モンスターのX座標
2380 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2382 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2383 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2385 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2387 OBJECT_IDX this_o_idx, next_o_idx;
2388 turn_flags_ptr->do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
2389 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2391 BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
2392 GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
2393 object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
2394 next_o_idx = o_ptr->next_o_idx;
2396 if (turn_flags_ptr->do_take)
2398 /* Skip gold, corpse and statue */
2399 if (o_ptr->tval == TV_GOLD || (o_ptr->tval == TV_CORPSE) || (o_ptr->tval == TV_STATUE))
2403 object_flags(o_ptr, flgs);
2404 object_desc(target_ptr, o_name, o_ptr, 0);
2405 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
2406 update_object_flags(flgs, &flg2, &flg3, &flgr);
2408 bool is_special_object = object_is_artifact(o_ptr) ||
2409 ((r_ptr->flags3 & flg3) != 0) ||
2410 ((r_ptr->flags2 & flg2) != 0) ||
2411 (((~(r_ptr->flagsr) & flgr) != 0) && !(r_ptr->flagsr & RFR_RES_ALL));
2412 monster_pickup_object(target_ptr, turn_flags_ptr, m_idx, o_ptr, is_special_object, ny, nx, m_name, o_name, this_o_idx);
2418 * @brief オブジェクトのフラグを更新する
2420 void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr)
2422 if (have_flag(flgs, TR_SLAY_DRAGON)) *flg3 |= (RF3_DRAGON);
2423 if (have_flag(flgs, TR_KILL_DRAGON)) *flg3 |= (RF3_DRAGON);
2424 if (have_flag(flgs, TR_SLAY_TROLL)) *flg3 |= (RF3_TROLL);
2425 if (have_flag(flgs, TR_KILL_TROLL)) *flg3 |= (RF3_TROLL);
2426 if (have_flag(flgs, TR_SLAY_GIANT)) *flg3 |= (RF3_GIANT);
2427 if (have_flag(flgs, TR_KILL_GIANT)) *flg3 |= (RF3_GIANT);
2428 if (have_flag(flgs, TR_SLAY_ORC)) *flg3 |= (RF3_ORC);
2429 if (have_flag(flgs, TR_KILL_ORC)) *flg3 |= (RF3_ORC);
2430 if (have_flag(flgs, TR_SLAY_DEMON)) *flg3 |= (RF3_DEMON);
2431 if (have_flag(flgs, TR_KILL_DEMON)) *flg3 |= (RF3_DEMON);
2432 if (have_flag(flgs, TR_SLAY_UNDEAD)) *flg3 |= (RF3_UNDEAD);
2433 if (have_flag(flgs, TR_KILL_UNDEAD)) *flg3 |= (RF3_UNDEAD);
2434 if (have_flag(flgs, TR_SLAY_ANIMAL)) *flg3 |= (RF3_ANIMAL);
2435 if (have_flag(flgs, TR_KILL_ANIMAL)) *flg3 |= (RF3_ANIMAL);
2436 if (have_flag(flgs, TR_SLAY_EVIL)) *flg3 |= (RF3_EVIL);
2437 if (have_flag(flgs, TR_KILL_EVIL)) *flg3 |= (RF3_EVIL);
2438 if (have_flag(flgs, TR_SLAY_HUMAN)) *flg2 |= (RF2_HUMAN);
2439 if (have_flag(flgs, TR_KILL_HUMAN)) *flg2 |= (RF2_HUMAN);
2440 if (have_flag(flgs, TR_BRAND_ACID)) *flgr |= (RFR_IM_ACID);
2441 if (have_flag(flgs, TR_BRAND_ELEC)) *flgr |= (RFR_IM_ELEC);
2442 if (have_flag(flgs, TR_BRAND_FIRE)) *flgr |= (RFR_IM_FIRE);
2443 if (have_flag(flgs, TR_BRAND_COLD)) *flgr |= (RFR_IM_COLD);
2444 if (have_flag(flgs, TR_BRAND_POIS)) *flgr |= (RFR_IM_POIS);
2449 * @brief モンスターがアイテムを拾うか壊す処理
2450 * @param target_ptr プレーヤーへの参照ポインタ
2451 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2452 * @param m_idx モンスターID
2453 * @param o_ptr オブジェクトへの参照ポインタ
2454 * @param is_special_object モンスターが拾えないアイテム (アーティファクト等)であればTRUE
2455 * @param ny 移動後の、モンスターのY座標
2456 * @param nx 移動後の、モンスターのX座標
2457 * @param m_name モンスター名
2458 * @param o_name アイテム名
2459 * @param this_o_idx モンスターが乗ったオブジェクトID
2462 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)
2464 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2465 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2466 if (is_special_object)
2468 if (turn_flags_ptr->do_take && (r_ptr->flags2 & RF2_STUPID))
2470 turn_flags_ptr->did_take_item = TRUE;
2471 if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
2473 msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
2480 if (turn_flags_ptr->do_take)
2482 turn_flags_ptr->did_take_item = TRUE;
2483 if (player_can_see_bold(target_ptr, ny, nx))
2485 msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
2488 excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
2489 o_ptr->marked &= OM_TOUCHED;
2490 o_ptr->iy = o_ptr->ix = 0;
2491 o_ptr->held_m_idx = m_idx;
2492 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2493 m_ptr->hold_o_idx = this_o_idx;
2497 if (is_pet(m_ptr)) return;
2499 turn_flags_ptr->did_kill_item = TRUE;
2500 if (player_has_los_bold(target_ptr, ny, nx))
2502 msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
2505 delete_object_idx(target_ptr, this_o_idx);
2510 * @brief updateフィールドを更新する
2511 * @param target_ptr プレーヤーへの参照ポインタ
2512 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2515 void update_player_type(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_race *r_ptr)
2517 if (turn_flags_ptr->do_view)
2519 target_ptr->update |= (PU_FLOW);
2520 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2523 if (turn_flags_ptr->do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
2524 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !target_ptr->phase_out)))
2526 target_ptr->update |= (PU_MON_LITE);
2532 * @brief モンスターのフラグを更新する
2533 * @param target_ptr プレーヤーへの参照ポインタ
2534 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2535 * @param m_ptr モンスターへの参照ポインタ
2538 void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr)
2540 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2541 if (!is_original_ap_and_seen(target_ptr, m_ptr)) return;
2543 if (turn_flags_ptr->did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
2544 if (turn_flags_ptr->did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2545 if (turn_flags_ptr->did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
2546 if (turn_flags_ptr->did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
2547 if (turn_flags_ptr->did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
2548 if (turn_flags_ptr->did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
2549 if (turn_flags_ptr->did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2554 * @brief モンスターの恐怖状態を処理する
2555 * @param target_ptr プレーヤーへの参照ポインタ
2556 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2557 * @param m_idx モンスターID
2558 * @param aware 超隠密状態ならばTRUE
2559 * @return モンスターが戦いを決意したらTRUE
2561 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, bool aware, bool see_m)
2563 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2564 bool is_battle_determined = !turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && MON_MONFEAR(m_ptr) && aware;
2565 if (!is_battle_determined) return FALSE;
2567 (void)set_monster_monfear(target_ptr, m_idx, 0);
2568 if (!see_m) return TRUE;
2570 GAME_TEXT m_name[MAX_NLEN];
2571 monster_desc(target_ptr, m_name, m_ptr, 0);
2572 msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
2578 * @brief 全モンスターのターン管理メインルーチン /
2579 * Process all the "live" monsters, once per game turn.
2582 * During each game current game turn, we scan through the list of all the "live" monsters,\n
2583 * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
2584 * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
2586 * Note that monsters can never move in the monster array (except when the\n
2587 * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
2589 * This function is responsible for at least half of the processor time\n
2590 * on a normal system with a "normal" amount of monsters and a player doing\n
2593 * When the player is resting, virtually 90% of the processor time is spent\n
2594 * in this function, and its children, "process_monster()" and "make_move()".\n
2596 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
2597 * especially when the player is running.\n
2599 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
2600 * monsters while they are still being "born". A monster is "fresh" only\n
2601 * during the game turn in which it is created, and we use the "hack_m_idx" to\n
2602 * determine if the monster is yet to be processed during the game turn.\n
2604 * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
2605 * move before any "nasty" monsters get to use their spell attacks.\n
2607 * Note that when the "knowledge" about the currently tracked monster\n
2608 * changes (flags, attacks, spells), we induce a redraw of the monster\n
2611 void process_monsters(player_type *target_ptr)
2613 BIT_FLAGS old_r_flags1 = 0L;
2614 BIT_FLAGS old_r_flags2 = 0L;
2615 BIT_FLAGS old_r_flags3 = 0L;
2616 BIT_FLAGS old_r_flags4 = 0L;
2617 BIT_FLAGS old_r_flags5 = 0L;
2618 BIT_FLAGS old_r_flags6 = 0L;
2619 BIT_FLAGS old_r_flagsr = 0L;
2621 byte old_r_blows0 = 0;
2622 byte old_r_blows1 = 0;
2623 byte old_r_blows2 = 0;
2624 byte old_r_blows3 = 0;
2626 floor_type *floor_ptr = target_ptr->current_floor_ptr;
2627 floor_ptr->monster_noise = FALSE;
2629 MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
2630 byte old_r_cast_spell = 0;
2631 if (target_ptr->monster_race_idx)
2633 monster_race *r_ptr;
2634 r_ptr = &r_info[target_ptr->monster_race_idx];
2636 old_r_flags1 = r_ptr->r_flags1;
2637 old_r_flags2 = r_ptr->r_flags2;
2638 old_r_flags3 = r_ptr->r_flags3;
2639 old_r_flags4 = r_ptr->r_flags4;
2640 old_r_flags5 = r_ptr->r_flags5;
2641 old_r_flags6 = r_ptr->r_flags6;
2642 old_r_flagsr = r_ptr->r_flagsr;
2644 old_r_blows0 = r_ptr->r_blows[0];
2645 old_r_blows1 = r_ptr->r_blows[1];
2646 old_r_blows2 = r_ptr->r_blows[2];
2647 old_r_blows3 = r_ptr->r_blows[3];
2649 old_r_cast_spell = r_ptr->r_cast_spell;
2652 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
2654 monster_type *m_ptr;
2655 monster_race *r_ptr;
2656 m_ptr = &floor_ptr->m_list[i];
2657 r_ptr = &r_info[m_ptr->r_idx];
2659 if (target_ptr->leaving) break;
2660 if (!monster_is_valid(m_ptr)) continue;
2661 if (target_ptr->wild_mode) continue;
2663 if (m_ptr->mflag & MFLAG_BORN)
2665 m_ptr->mflag &= ~(MFLAG_BORN);
2669 if (m_ptr->cdis >= AAF_LIMIT) continue;
2671 POSITION fx = m_ptr->fx;
2672 POSITION fy = m_ptr->fy;
2673 if (!target_ptr->no_flowed)
2675 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
2679 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
2683 else if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
2684 (player_has_los_bold(target_ptr, fy, fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
2688 else if (m_ptr->target_y)
2693 if (!test) continue;
2696 if (target_ptr->riding == i)
2698 speed = target_ptr->pspeed;
2702 speed = m_ptr->mspeed;
2703 if (ironman_nightmare) speed += 5;
2705 if (MON_FAST(m_ptr)) speed += 10;
2706 if (MON_SLOW(m_ptr)) speed -= 10;
2709 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
2710 if (m_ptr->energy_need > 0) continue;
2712 m_ptr->energy_need += ENERGY_NEED();
2714 process_monster(target_ptr, i);
2715 reset_target(m_ptr);
2717 if (target_ptr->no_flowed && one_in_(3))
2718 m_ptr->mflag2 |= MFLAG2_NOFLOW;
2720 if (!target_ptr->playing || target_ptr->is_dead) break;
2721 if (target_ptr->leaving) break;
2725 if (!target_ptr->monster_race_idx || (target_ptr->monster_race_idx != old_monster_race_idx))
2728 monster_race *r_ptr;
2729 r_ptr = &r_info[target_ptr->monster_race_idx];
2731 if ((old_r_flags1 != r_ptr->r_flags1) ||
2732 (old_r_flags2 != r_ptr->r_flags2) ||
2733 (old_r_flags3 != r_ptr->r_flags3) ||
2734 (old_r_flags4 != r_ptr->r_flags4) ||
2735 (old_r_flags5 != r_ptr->r_flags5) ||
2736 (old_r_flags6 != r_ptr->r_flags6) ||
2737 (old_r_flagsr != r_ptr->r_flagsr) ||
2738 (old_r_blows0 != r_ptr->r_blows[0]) ||
2739 (old_r_blows1 != r_ptr->r_blows[1]) ||
2740 (old_r_blows2 != r_ptr->r_blows[2]) ||
2741 (old_r_blows3 != r_ptr->r_blows[3]) ||
2742 (old_r_cast_spell != r_ptr->r_cast_spell))
2744 target_ptr->window |= (PW_MONSTER);