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;
63 BIT_FLAGS old_r_flags1;
64 BIT_FLAGS old_r_flags2;
65 BIT_FLAGS old_r_flags3;
66 BIT_FLAGS old_r_flags4;
67 BIT_FLAGS old_r_flags5;
68 BIT_FLAGS old_r_flags6;
69 BIT_FLAGS old_r_flagsr;
76 byte old_r_cast_spell;
83 } coordinate_candidate;
85 turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr);
86 old_race_flags *init_old_race_flags(old_race_flags *old_race_flags_ptr);
88 bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm);
89 void decide_enemy_approch_direction(player_type *target_ptr, MONSTER_IDX m_idx, int start, int plus, POSITION *y, POSITION *x);
90 bool decide_pet_approch_direction(player_type *target_ptr, monster_type *m_ptr, monster_type *t_ptr);
91 void store_enemy_approch_direction(int *mm, POSITION y, POSITION x);
93 bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp);
94 coordinate_candidate sweep_safe_coordinate(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *y_offsets, POSITION *x_offsets, int d);
96 bool find_hiding(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp);
97 void sweep_hiding_candidate(player_type *target_ptr, monster_type *m_ptr, POSITION *y_offsets, POSITION *x_offsets, coordinate_candidate *candidate);
99 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
100 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx);
101 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
102 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx);
103 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
104 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
105 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
106 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
107 bool explode_monster(player_type *target_ptr, MONSTER_IDX m_idx);
108 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
109 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware);
110 bool random_walk(player_type *target_ptr, DIRECTION *mm, monster_type *m_ptr);
111 bool decide_pet_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx);
112 bool runaway_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
113 void escape_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, GAME_TEXT *m_name);
114 void process_special(player_type *target_ptr, MONSTER_IDX m_idx);
115 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware);
116 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware);
118 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross);
119 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
120 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
121 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash);
122 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
123 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
125 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
126 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);
127 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr);
129 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);
130 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
131 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);
133 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
135 void update_player_type(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_race *r_ptr);
136 void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr);
137 void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr);
138 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);
139 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
141 void save_old_race_flags(player_type *target_ptr, old_race_flags *old_race_flags_ptr);
142 void sweep_monster_process(player_type *target_ptr);
143 bool decide_process_continue(player_type *target_ptr, monster_type *m_ptr);
144 SPEED decide_monster_speed(player_type *target_ptr, monster_type *m_ptr, int monster_number);
145 void update_player_window(player_type *target_ptr, old_race_flags *old_race_flags_ptr);
148 * @brief モンスターが敵に接近するための方向を計算するメインルーチン
149 * Calculate the direction to the next enemy
150 * @param target_ptr プレーヤーへの参照ポインタ
151 * @param m_idx モンスターの参照ID
152 * @param mm 移動するべき方角IDを返す参照ポインタ
153 * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
155 bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
157 floor_type *floor_ptr = target_ptr->current_floor_ptr;
158 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
160 POSITION x = 0, y = 0;
161 if (target_ptr->riding_t_m_idx && player_bold(target_ptr, m_ptr->fy, m_ptr->fx))
163 y = floor_ptr->m_list[target_ptr->riding_t_m_idx].fy;
164 x = floor_ptr->m_list[target_ptr->riding_t_m_idx].fx;
166 else if (is_pet(m_ptr) && target_ptr->pet_t_m_idx)
168 y = floor_ptr->m_list[target_ptr->pet_t_m_idx].fy;
169 x = floor_ptr->m_list[target_ptr->pet_t_m_idx].fx;
175 if (target_ptr->phase_out)
177 start = randint1(floor_ptr->m_max - 1) + floor_ptr->m_max;
178 if (randint0(2)) plus = -1;
182 start = floor_ptr->m_max + 1;
185 decide_enemy_approch_direction(target_ptr, m_idx, start, plus, &y, &x);
187 if ((x == 0) && (y == 0)) return FALSE;
193 store_enemy_approch_direction(mm, y, x);
199 * @brief モンスターが敵に接近するための方向を決定する
200 * @param target_ptr プレーヤーへの参照ポインタ
201 * @param m_idx モンスターID
202 * @param start モンスターIDの開始
203 * @param plus モンスターIDの増減 (1/2 の確率で+1、1/2の確率で-1)
204 * @param y モンスターの移動方向Y
205 * @param x モンスターの移動方向X
208 void decide_enemy_approch_direction(player_type *target_ptr, MONSTER_IDX m_idx, int start, int plus, POSITION *y, POSITION *x)
210 floor_type *floor_ptr = target_ptr->current_floor_ptr;
211 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
212 monster_race *r_ptr = &r_info[m_ptr->r_idx];
213 for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus)
215 MONSTER_IDX dummy = (i % floor_ptr->m_max);
216 if (dummy == 0) continue;
218 MONSTER_IDX t_idx = dummy;
220 t_ptr = &floor_ptr->m_list[t_idx];
221 if (t_ptr == m_ptr) continue;
222 if (!monster_is_valid(t_ptr)) continue;
223 if (decide_pet_approch_direction(target_ptr, m_ptr, t_ptr)) continue;
224 if (!are_enemies(target_ptr, m_ptr, t_ptr)) continue;
226 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) ||
227 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)))
229 if (!in_disintegration_range(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
233 if (!projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
244 * @brief ペットが敵に接近するための方向を決定する
245 * @param target_ptr プレーヤーへの参照ポインタ
246 * @param m_ptr 移動を試みているモンスターへの参照ポインタ
247 * @param t_ptr 移動先モンスターへの参照ポインタ
248 * @param plus モンスターIDの増減 (1/2 の確率で+1、1/2の確率で-1)
249 * @return ペットがモンスターに近づくならばTRUE
251 bool decide_pet_approch_direction(player_type *target_ptr, monster_type *m_ptr, monster_type *t_ptr)
253 monster_race *r_ptr = &r_info[m_ptr->r_idx];
254 if (!is_pet(m_ptr)) return FALSE;
256 if (target_ptr->pet_follow_distance < 0)
258 if (t_ptr->cdis <= (0 - target_ptr->pet_follow_distance))
263 else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > target_ptr->pet_follow_distance))
268 return (r_ptr->aaf < t_ptr->cdis);
273 * @brief モンスターの移動方向を保存する
278 void store_enemy_approch_direction(int *mm, POSITION y, POSITION x)
280 /* North, South, East, West, North-West, North-East, South-West, South-East */
281 if ((y < 0) && (x == 0))
287 else if ((y > 0) && (x == 0))
293 else if ((x > 0) && (y == 0))
299 else if ((x < 0) && (y == 0))
305 else if ((y < 0) && (x < 0))
311 else if ((y < 0) && (x > 0))
317 else if ((y > 0) && (x < 0))
323 else if ((y > 0) && (x > 0))
333 * @brief モンスターがプレイヤーから逃走するかどうかを返す /
334 * Returns whether a given monster will try to run from the player.
335 * @param m_idx 逃走するモンスターの参照ID
336 * @return モンスターがプレイヤーから逃走するならばTRUEを返す。
338 * Monsters will attempt to avoid very powerful players. See below.\n
340 * Because this function is called so often, little details are important\n
341 * for efficiency. Like not using "mod" or "div" when possible. And\n
342 * attempting to check the conditions in an optimal order. Note that\n
343 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
345 * Note that this function is responsible for about one to five percent\n
346 * of the processor use in normal conditions...\n
348 static bool mon_will_run(player_type *target_ptr, MONSTER_IDX m_idx)
350 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
351 monster_race *r_ptr = &r_info[m_ptr->r_idx];
355 return ((target_ptr->pet_follow_distance < 0) &&
356 (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
359 if (m_ptr->cdis > MAX_SIGHT + 5) return FALSE;
360 if (MON_MONFEAR(m_ptr)) return TRUE;
361 if (m_ptr->cdis <= 5) return FALSE;
363 PLAYER_LEVEL p_lev = target_ptr->lev;
364 DEPTH m_lev = r_ptr->level + (m_idx & 0x08) + 25;
365 if (m_lev > p_lev + 4) return FALSE;
366 if (m_lev + 4 <= p_lev) return TRUE;
368 HIT_POINT p_chp = target_ptr->chp;
369 HIT_POINT p_mhp = target_ptr->mhp;
370 HIT_POINT m_chp = m_ptr->hp;
371 HIT_POINT m_mhp = m_ptr->maxhp;
372 u32b p_val = (p_lev * p_mhp) + (p_chp << 2);
373 u32b m_val = (m_lev * m_mhp) + (m_chp << 2);
374 if (p_val * m_mhp > m_val * p_mhp) return TRUE;
381 * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
382 * Search spell castable grid
383 * @param target_ptr プレーヤーへの参照ポインタ
384 * @param m_idx モンスターの参照ID
385 * @param yp 適したマスのY座標を返す参照ポインタ
386 * @param xp 適したマスのX座標を返す参照ポインタ
387 * @return 有効なマスがあった場合TRUEを返す
389 static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
391 floor_type *floor_ptr = target_ptr->current_floor_ptr;
392 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
393 monster_race *r_ptr = &r_info[m_ptr->r_idx];
395 POSITION y1 = m_ptr->fy;
396 POSITION x1 = m_ptr->fx;
398 if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x)) return FALSE;
400 int now_cost = floor_ptr->grid_array[y1][x1].cost;
401 if (now_cost == 0) now_cost = 999;
403 bool can_open_door = FALSE;
404 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
406 can_open_door = TRUE;
410 for (int i = 7; i >= 0; i--)
412 POSITION y = y1 + ddy_ddd[i];
413 POSITION x = x1 + ddx_ddd[i];
414 if (!in_bounds2(floor_ptr, y, x)) continue;
415 if (player_bold(target_ptr, y, x)) return FALSE;
418 g_ptr = &floor_ptr->grid_array[y][x];
419 int cost = g_ptr->cost;
420 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))))
422 if (cost == 0) continue;
423 if (!can_open_door && is_closed_door(target_ptr, g_ptr->feat)) continue;
426 if (cost == 0) cost = 998;
428 if (now_cost < cost) continue;
429 if (!projectable(target_ptr, y, x, target_ptr->y, target_ptr->x)) continue;
430 if (best < cost) continue;
433 *yp = y1 + ddy_ddd[i];
434 *xp = x1 + ddx_ddd[i];
437 if (best == 999) return FALSE;
444 * todo まだ分割せず放置 (このままいくと3000行を超えかねない)
445 * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
446 * Choose the "best" direction for "flowing"
447 * @param m_idx モンスターの参照ID
448 * @param yp 移動先のマスのY座標を返す参照ポインタ
449 * @param xp 移動先のマスのX座標を返す参照ポインタ
450 * @param no_flow モンスターにFLOWフラグが経っていない状態でTRUE
451 * @return 有効なマスがあった場合TRUEを返す
453 * Note that ghosts and rock-eaters are never allowed to "flow",\n
454 * since they should move directly towards the player.\n
456 * Prefer "non-diagonal" directions, but twiddle them a little\n
457 * to angle slightly towards the player's actual location.\n
459 * Allow very perceptive monsters to track old "spoor" left by\n
460 * previous locations occupied by the player. This will tend\n
461 * to have monsters end up either near the player or on a grid\n
462 * recently occupied by the player (and left via "teleport").\n
464 * Note that if "smell" is turned on, all monsters get vicious.\n
466 * Also note that teleporting away from a location will cause\n
467 * the monsters who were chasing you to converge on that location\n
468 * as long as you are still near enough to "annoy" them without\n
469 * being close enough to chase directly. I have no idea what will\n
470 * happen if you combine "smell" with low "aaf" values.\n
472 static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
475 floor_type *floor_ptr = target_ptr->current_floor_ptr;
476 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
477 monster_race *r_ptr = &r_info[m_ptr->r_idx];
479 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
480 r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
481 r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
483 if (get_moves_aux2(target_ptr, m_idx, yp, xp)) return TRUE;
486 if (no_flow) return FALSE;
487 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) return FALSE;
488 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)) return FALSE;
490 POSITION y1 = m_ptr->fy;
491 POSITION x1 = m_ptr->fx;
492 if (player_has_los_bold(target_ptr, y1, x1) && projectable(target_ptr, target_ptr->y, target_ptr->x, y1, x1)) return FALSE;
494 g_ptr = &floor_ptr->grid_array[y1][x1];
497 bool use_scent = FALSE;
502 else if (g_ptr->when)
504 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when - g_ptr->when > 127) return FALSE;
514 for (int i = 7; i >= 0; i--)
516 POSITION y = y1 + ddy_ddd[i];
517 POSITION x = x1 + ddx_ddd[i];
519 if (!in_bounds2(floor_ptr, y, x)) continue;
521 g_ptr = &floor_ptr->grid_array[y][x];
524 int when = g_ptr->when;
525 if (best > when) continue;
532 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
541 if ((cost == 0) || (best < cost)) continue;
546 *yp = target_ptr->y + 16 * ddy_ddd[i];
547 *xp = target_ptr->x + 16 * ddx_ddd[i];
550 if (best == 999 || best == 0) return FALSE;
557 * @brief モンスターがプレイヤーから逃走することが可能なマスを走査する /
558 * Provide a location to flee to, but give the player a wide berth.
559 * @param m_idx モンスターの参照ID
560 * @param yp 移動先のマスのY座標を返す参照ポインタ
561 * @param xp 移動先のマスのX座標を返す参照ポインタ
562 * @return 有効なマスがあった場合TRUEを返す
564 * A monster may wish to flee to a location that is behind the player,\n
565 * but instead of heading directly for it, the monster should "swerve"\n
566 * around the player so that he has a smaller chance of getting hit.\n
568 static bool get_fear_moves_aux(floor_type *floor_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
570 POSITION gy = 0, gx = 0;
572 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
573 POSITION fy = m_ptr->fy;
574 POSITION fx = m_ptr->fx;
576 POSITION y1 = fy - (*yp);
577 POSITION x1 = fx - (*xp);
580 for (int i = 7; i >= 0; i--)
582 POSITION y = fy + ddy_ddd[i];
583 POSITION x = fx + ddx_ddd[i];
584 if (!in_bounds2(floor_ptr, y, x)) continue;
586 POSITION dis = distance(y, x, y1, x1);
587 POSITION s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
590 if (s < score) continue;
597 if (score == -1) return FALSE;
607 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
610 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
611 * offsets of all the locations with a distance of n from a central point,
612 * with an offset of (0,0) indicating no more offsets at this distance.
614 * This is, of course, fairly unreadable, but it eliminates multiple loops
615 * from the previous version.
617 * It is probably better to replace these arrays with code to compute
618 * the relevant arrays, even if the storage is pre-allocated in hard
619 * coded sizes. At the very least, code should be included which is
620 * able to generate and dump these arrays (ala "los()").
622 * Also, the storage needs could be halved by using bytes.
624 * These arrays could be combined into two big arrays, using sub-arrays
625 * to hold the offsets and lengths of each portion of the sub-arrays, and
626 * this could perhaps also be used somehow in the "look" code.
630 static POSITION d_off_y_0[] = { 0 };
631 static POSITION d_off_x_0[] = { 0 };
633 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
634 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
636 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
637 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
639 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
640 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
642 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 };
643 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 };
646 static POSITION d_off_y_5[] =
647 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
648 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
651 static POSITION d_off_x_5[] =
652 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
653 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
657 static POSITION d_off_y_6[] =
658 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
659 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
662 static POSITION d_off_x_6[] =
663 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
664 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
665 -3, 2, 3, -1, 0, 1, 0 };
668 static POSITION d_off_y_7[] =
669 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
670 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
671 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
673 static POSITION d_off_x_7[] =
674 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
675 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
676 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
680 static POSITION d_off_y_8[] =
681 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
682 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
683 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
686 static POSITION d_off_x_8[] =
687 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
688 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
689 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
693 static POSITION d_off_y_9[] =
694 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
695 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
696 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
697 7, 8, 8, 8, 8, 9, 9, 9, 0 };
699 static POSITION d_off_x_9[] =
700 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
701 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
702 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
703 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
706 static POSITION *dist_offsets_y[10] =
708 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
709 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
712 static POSITION *dist_offsets_x[10] =
714 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
715 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
718 coordinate_candidate init_coordinate_candidate(void)
720 coordinate_candidate candidate;
728 * @brief モンスターが逃げ込める安全な地点を返す /
729 * Choose a "safe" location near a monster for it to run toward.
730 * @param target_ptr プレーヤーへの参照ポインタ
731 * @param m_idx モンスターの参照ID
732 * @param yp 移動先のマスのY座標を返す参照ポインタ
733 * @param xp 移動先のマスのX座標を返す参照ポインタ
734 * @return 有効なマスがあった場合TRUEを返す
736 * A location is "safe" if it can be reached quickly and the player\n
737 * is not able to fire into it (it isn't a "clean shot"). So, this will\n
738 * cause monsters to "duck" behind walls. Hopefully, monsters will also\n
739 * try to run towards corridor openings if they are in a room.\n
741 * This function may take lots of CPU time if lots of monsters are\n
744 * Return TRUE if a safe location is available.\n
746 bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
748 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
749 for (POSITION d = 1; d < 10; d++)
752 y_offsets = dist_offsets_y[d];
755 x_offsets = dist_offsets_x[d];
757 coordinate_candidate candidate = sweep_safe_coordinate(target_ptr, m_idx, y_offsets, x_offsets, d);
759 if (candidate.gdis <= 0) continue;
761 *yp = m_ptr->fy - candidate.gy;
762 *xp = m_ptr->fx - candidate.gx;
772 * @brief モンスターが逃げ込める地点を走査する
773 * @param target_ptr プレーヤーへの参照ポインタ
774 * @param m_idx モンスターID
777 * @param d モンスターがいる地点からの距離
778 * @return 逃げ込める地点の候補地
780 coordinate_candidate sweep_safe_coordinate(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *y_offsets, POSITION *x_offsets, int d)
782 coordinate_candidate candidate = init_coordinate_candidate();
783 floor_type *floor_ptr = target_ptr->current_floor_ptr;
784 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
785 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
787 i++, dx = x_offsets[i], dy = y_offsets[i])
789 POSITION y = m_ptr->fy + dy;
790 POSITION x = m_ptr->fx + dx;
791 if (!in_bounds(floor_ptr, y, x)) continue;
794 g_ptr = &floor_ptr->grid_array[y][x];
796 BIT_FLAGS16 riding_mode = (m_idx == target_ptr->riding) ? CEM_RIDING : 0;
797 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], riding_mode))
800 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
802 if (g_ptr->dist == 0) continue;
803 if (g_ptr->dist > floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist + 2 * d) continue;
806 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x)) continue;
808 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
809 if (dis <= candidate.gdis) continue;
813 candidate.gdis = dis;
821 * @brief モンスターが隠れ潜める地点を返す /
822 * Choose a good hiding place near a monster for it to run toward.
823 * @param target_ptr プレーヤーへの参照ポインタ
824 * @param m_idx モンスターの参照ID
825 * @param yp 移動先のマスのY座標を返す参照ポインタ
826 * @param xp 移動先のマスのX座標を返す参照ポインタ
827 * @return 有効なマスがあった場合TRUEを返す
829 * Pack monsters will use this to "ambush" the player and lure him out\n
830 * of corridors into open space so they can swarm him.\n
832 * Return TRUE if a good location is available.\n
834 bool find_hiding(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
836 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
837 coordinate_candidate candidate = init_coordinate_candidate();
838 candidate.gdis = 999;
840 for (POSITION d = 1; d < 10; d++)
843 y_offsets = dist_offsets_y[d];
846 x_offsets = dist_offsets_x[d];
848 sweep_hiding_candidate(target_ptr, m_ptr, y_offsets, x_offsets, &candidate);
849 if (candidate.gdis >= 999) continue;
851 *yp = m_ptr->fy - candidate.gy;
852 *xp = m_ptr->fx - candidate.gx;
861 * @brief モンスターが隠れられる地点を走査する
862 * @param target_ptr プレーヤーへの参照ポインタ
863 * @param m_idx モンスターID
866 * @param candidate 隠れられる地点の候補地
869 void sweep_hiding_candidate(player_type *target_ptr, monster_type *m_ptr, POSITION *y_offsets, POSITION *x_offsets, coordinate_candidate *candidate)
871 monster_race *r_ptr = &r_info[m_ptr->r_idx];
872 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
874 i++, dx = x_offsets[i], dy = y_offsets[i])
876 POSITION y = m_ptr->fy + dy;
877 POSITION x = m_ptr->fx + dx;
878 if (!in_bounds(target_ptr->current_floor_ptr, y, x)) continue;
879 if (!monster_can_enter(target_ptr, y, x, r_ptr, 0)) continue;
880 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, m_ptr->fy, m_ptr->fx, y, x, FALSE))
883 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
884 if (dis < candidate->gdis && dis >= 2)
888 candidate->gdis = dis;
895 * todo 分割したいが条件が多すぎて適切な関数名と詳細処理を追いきれない……
896 * @brief モンスターの移動方向を返す /
897 * Choose "logical" directions for monster movement
898 * @param target_ptr プレーヤーへの参照ポインタ
899 * @param m_idx モンスターの参照ID
900 * @param mm 移動方向を返す方向IDの参照ポインタ
901 * @return 有効方向があった場合TRUEを返す
903 static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
905 floor_type *floor_ptr = target_ptr->current_floor_ptr;
906 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
907 monster_race *r_ptr = &r_info[m_ptr->r_idx];
908 POSITION y = 0, ay, x = 0, ax;
909 POSITION y2 = target_ptr->y;
910 POSITION x2 = target_ptr->x;
912 bool will_run = mon_will_run(target_ptr, m_idx);
914 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) != 0) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2);
915 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) != 0) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall);
917 if (!will_run && m_ptr->target_y)
919 int t_m_idx = floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
921 are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[t_m_idx]) &&
922 los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
923 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
925 y = m_ptr->fy - m_ptr->target_y;
926 x = m_ptr->fx - m_ptr->target_x;
931 if (!done && !will_run && is_hostile(m_ptr) &&
932 (r_ptr->flags1 & RF1_FRIENDS) &&
933 ((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)) ||
934 (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
936 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
937 !(r_ptr->flags2 & RF2_KILL_WALL))
940 for (int i = 0; i < 8; i++)
942 int xx = target_ptr->x + ddx_ddd[i];
943 int yy = target_ptr->y + ddy_ddd[i];
945 if (!in_bounds2(floor_ptr, yy, xx)) continue;
947 g_ptr = &floor_ptr->grid_array[yy][xx];
948 if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0))
954 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].info & CAVE_ROOM) room -= 2;
955 if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
957 if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
958 (target_ptr->mhp + target_ptr->msp))
960 if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
964 if (!done && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
966 for (int i = 0; i < 8; i++)
968 y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
969 x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
970 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
977 if (!in_bounds2(floor_ptr, y2, x2)) continue;
978 if (!monster_can_enter(target_ptr, y2, x2, r_ptr, 0)) continue;
991 (void)get_moves_aux(target_ptr, m_idx, &y2, &x2, no_flow);
996 if (is_pet(m_ptr) && will_run)
1002 if (!done && will_run)
1006 if (find_safety(target_ptr, m_idx, &y, &x) && !no_flow)
1008 if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x))
1020 if (!x && !y) return FALSE;
1026 if (y < 0) move_val += 8;
1027 if (x > 0) move_val += 4;
1029 if (ay > (ax << 1)) move_val += 2;
1030 else if (ax > (ay << 1)) move_val++;
1180 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
1182 return !have_flag(f_ptr->flags, FF_GLASS) ||
1183 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
1184 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
1189 * @brief モンスター単体の1ターン行動処理メインルーチン /
1191 * @param target_ptr プレーヤーへの参照ポインタ
1192 * @param m_idx 行動モンスターの参照ID
1195 * The monster is known to be within 100 grids of the player\n
1197 * In several cases, we directly update the monster lore\n
1199 * Note that a monster is only allowed to "reproduce" if there\n
1200 * are a limited number of "reproducing" monsters on the current\n
1201 * level. This should prevent the level from being "swamped" by\n
1202 * reproducing monsters. It also allows a large mass of mice to\n
1203 * prevent a louse from multiplying, but this is a small price to\n
1204 * pay for a simple multiplication method.\n
1206 * XXX Monster fear is slightly odd, in particular, monsters will\n
1207 * fixate on opening a door even if they cannot open it. Actually,\n
1208 * the same thing happens to normal monsters when they hit a door\n
1210 * In addition, monsters which *cannot* open or bash\n
1211 * down a door will still stand there trying to open it...\n
1213 * XXX Technically, need to check for monster in the way\n
1214 * combined with that monster being in a wall (or door?)\n
1216 * A "direction" of "5" means "pick a random direction".\n
1218 void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1220 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1221 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1222 turn_flags tmp_flags;
1223 turn_flags *turn_flags_ptr = init_turn_flags(target_ptr, m_idx, &tmp_flags);
1224 turn_flags_ptr->see_m = is_seen(m_ptr);
1226 decide_drop_from_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon);
1227 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
1229 choose_new_monster(target_ptr, m_idx, FALSE, 0);
1230 r_ptr = &r_info[m_ptr->r_idx];
1233 turn_flags_ptr->aware = process_stealth(target_ptr, m_idx);
1234 if (vanish_summoned_children(target_ptr, m_idx, turn_flags_ptr->see_m)) return;
1235 if (process_quantum_effect(target_ptr, m_idx, turn_flags_ptr->see_m)) return;
1236 if (explode_monster(target_ptr, m_idx)) return;
1237 if (runaway_monster(target_ptr, turn_flags_ptr, m_idx)) return;
1239 awake_monster(target_ptr, m_idx);
1240 if (MON_STUNNED(m_ptr))
1242 if (one_in_(2)) return;
1245 if (turn_flags_ptr->is_riding_mon)
1247 target_ptr->update |= (PU_BONUS);
1250 process_angar(target_ptr, m_idx, turn_flags_ptr->see_m);
1252 POSITION oy = m_ptr->fy;
1253 POSITION ox = m_ptr->fx;
1254 if (decide_monster_multiplication(target_ptr, m_idx, oy, ox)) return;
1256 process_special(target_ptr, m_idx);
1257 process_speak_sound(target_ptr, m_idx, oy, ox, turn_flags_ptr->aware);
1258 if (cast_spell(target_ptr, m_idx, turn_flags_ptr->aware)) return;
1261 mm[0] = mm[1] = mm[2] = mm[3] = 0;
1262 mm[4] = mm[5] = mm[6] = mm[7] = 0;
1264 if (!decide_monster_movement_direction(target_ptr, mm, m_idx, turn_flags_ptr->aware)) return;
1267 if (!process_monster_movement(target_ptr, turn_flags_ptr, m_idx, mm, oy, ox, &count)) return;
1270 * Forward movements failed, but now received LOS attack!
1271 * Try to flow by smell.
1273 if (target_ptr->no_flowed && count > 2 && m_ptr->target_y)
1274 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
1276 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)
1278 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
1280 if (make_attack_spell(m_idx, target_ptr)) return;
1284 update_player_type(target_ptr, turn_flags_ptr, r_ptr);
1285 update_monster_race_flags(target_ptr, turn_flags_ptr, m_ptr);
1287 if (!process_monster_fear(target_ptr, turn_flags_ptr, m_idx)) return;
1289 if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
1294 * @brief ターン経過フラグ構造体の初期化
1295 * @param target_ptr プレーヤーへの参照ポインタ
1296 * @param m_idx モンスターID
1297 * @return 初期化済のターン経過フラグ
1299 turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr)
1301 turn_flags_ptr->is_riding_mon = (m_idx == target_ptr->riding);
1302 turn_flags_ptr->do_turn = FALSE;
1303 turn_flags_ptr->do_move = FALSE;
1304 turn_flags_ptr->do_view = FALSE;
1305 turn_flags_ptr->must_alter_to_move = FALSE;
1306 turn_flags_ptr->did_open_door = FALSE;
1307 turn_flags_ptr->did_bash_door = FALSE;
1308 turn_flags_ptr->did_take_item = FALSE;
1309 turn_flags_ptr->did_kill_item = FALSE;
1310 turn_flags_ptr->did_move_body = FALSE;
1311 turn_flags_ptr->did_pass_wall = FALSE;
1312 turn_flags_ptr->did_kill_wall = FALSE;
1313 return turn_flags_ptr;
1319 * @param target_ptr プレーヤーへの参照ポインタ
1320 * @param m_idx モンスターID
1321 * @return モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1323 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx)
1325 if ((target_ptr->special_defense & NINJA_S_STEALTH) == 0) return TRUE;
1327 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1328 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1329 int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
1330 if (target_ptr->monlite) tmp /= 3;
1331 if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1332 if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
1333 return (randint0(tmp) <= (r_ptr->level + 20));
1338 * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
1339 * @param target_ptr プレーヤーへの参照ポインタ
1340 * @param m_idx モンスターID
1341 * @param is_riding_mon 騎乗中であればTRUE
1344 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
1346 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1347 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1348 if (!is_riding_mon || ((r_ptr->flags7 & RF7_RIDING) != 0)) return;
1350 if (rakuba(target_ptr, 0, TRUE))
1353 msg_print("地面に落とされた。");
1355 GAME_TEXT m_name[MAX_NLEN];
1356 monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
1357 msg_format("You have fallen from %s.", m_name);
1364 * @brief 召喚の親元が消滅した時、子供も消滅させる
1365 * @param target_ptr プレーヤーへの参照ポインタ
1366 * @param m_idx モンスターID
1367 * @param see_m モンスターが視界内にいたらTRUE
1368 * @return 召喚モンスターが消滅したらTRUE
1370 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1372 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1373 if ((m_ptr->parent_m_idx == 0) || (target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx > 0))
1378 GAME_TEXT m_name[MAX_NLEN];
1379 monster_desc(target_ptr, m_name, m_ptr, 0);
1380 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1383 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1385 GAME_TEXT m_name[MAX_NLEN];
1386 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
1387 exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
1390 delete_monster_idx(target_ptr, m_idx);
1396 * @brief 寝ているモンスターの起床を判定する
1397 * @param target_ptr プレーヤーへの参照ポインタ
1398 * @param m_idx モンスターID
1401 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1403 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1404 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1405 if (!MON_CSLEEP(m_ptr)) return;
1406 if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
1408 (void)set_monster_csleep(target_ptr, m_idx, 0);
1411 GAME_TEXT m_name[MAX_NLEN];
1412 monster_desc(target_ptr, m_name, m_ptr, 0);
1413 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
1416 if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
1424 * @brief モンスターの怒り状態を判定する (起こっていたら敵に回す)
1425 * @param target_ptr プレーヤーへの参照ポインタ
1426 * @param m_idx モンスターID
1427 * @param see_m モンスターが視界内にいたらTRUE
1430 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1432 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1433 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1434 bool gets_angry = FALSE;
1435 if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
1438 if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
1439 monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
1444 if (target_ptr->phase_out || !gets_angry) return;
1446 if (is_pet(m_ptr) || see_m)
1448 GAME_TEXT m_name[MAX_NLEN];
1449 monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
1450 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
1453 set_hostile(target_ptr, m_ptr);
1458 * @brief 量子生物の量子的効果を実行する
1459 * @param target_ptr プレーヤーへの参照ポインタ
1460 * @param m_idx モンスターID
1461 * @param see_m モンスターが視界内にいたらTRUE
1462 * @return モンスターが量子的効果により消滅したらTRUE
1464 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1466 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1467 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1468 if ((r_ptr->flags2 & RF2_QUANTUM) == 0) return FALSE;
1469 if (!randint0(2)) return FALSE;
1470 if (randint0((m_idx % 100) + 10)) return FALSE;
1472 bool can_disappear = (r_ptr->flags1 & RF1_UNIQUE) == 0;
1473 can_disappear &= (r_ptr->flags1 & RF1_QUESTOR) == 0;
1476 vanish_nonunique(target_ptr, m_idx, see_m);
1480 produce_quantum_effect(target_ptr, m_idx, see_m);
1486 * @brief ユニークでない量子生物を消滅させる
1487 * @param target_ptr プレーヤーへの参照ポインタ
1488 * @param m_idx モンスターID
1489 * @param see_m モンスターが視界内にいたらTRUE
1492 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1494 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1497 GAME_TEXT m_name[MAX_NLEN];
1498 monster_desc(target_ptr, m_name, m_ptr, 0);
1499 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1502 monster_death(target_ptr, m_idx, FALSE);
1503 delete_monster_idx(target_ptr, m_idx);
1504 if (is_pet(m_ptr) && !(m_ptr->ml))
1506 msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
1512 * @brief 量子生物ユニークの量子的効果 (ショート・テレポートまたは距離10のテレポート・アウェイ)を実行する
1513 * @param target_ptr プレーヤーへの参照ポインタ
1514 * @param m_idx モンスターID
1515 * @param see_m モンスターが視界内にいたらTRUE
1518 * プレーヤーが量子生物を観測しているか、量子生物がプレーヤーを観測している場合、互いの相対的な位置を確定させる
1519 * 波動関数の収縮はテレポートではないので反テレポート無効
1520 * todo パターンは収縮どころか拡散しているが、この際気にしてはいけない
1522 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1524 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1525 bool coherent = los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x);
1526 if (!see_m && !coherent) return;
1530 GAME_TEXT m_name[MAX_NLEN];
1531 monster_desc(target_ptr, m_name, m_ptr, 0);
1532 msg_format(_("%sは量子的効果を起こした!", "%^s produced a decoherence!"), m_name);
1536 msg_print(_("量子的効果が起こった!", "A decoherence was produced!"));
1539 bool target = one_in_(2);
1540 const int blink = 32 * 5 + 4;
1543 (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx);
1547 teleport_player_away(m_idx, target_ptr, 10, TRUE);
1554 * @param target_ptr プレーヤーへの参照ポインタ
1555 * @param m_idx モンスターID
1558 bool explode_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1560 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1561 if (m_ptr->r_idx != MON_SHURYUUDAN) return FALSE;
1564 mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
1570 * @brief モンスター依存の特別な行動を取らせる
1571 * @param target_ptr プレーヤーへの参照ポインタ
1572 * @param m_idx モンスターID
1575 void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
1577 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1578 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1579 if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
1580 if (m_ptr->r_idx != MON_OHMU) return;
1581 if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
1582 if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
1585 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1586 BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
1588 for (int k = 0; k < A_MAX; k++)
1590 if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
1592 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
1596 if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
1601 * @brief モンスターを喋らせたり足音を立てたりする
1602 * @param target_ptr プレーヤーへの参照ポインタ
1603 * @param m_idx モンスターID
1604 * @param oy モンスターが元々いたY座標
1605 * @param ox モンスターが元々いたX座標
1606 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1609 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware)
1611 if (target_ptr->phase_out) return;
1613 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1614 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1615 if (m_ptr->ap_r_idx == MON_CYBER &&
1616 one_in_(CYBERNOISE) &&
1617 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
1619 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
1620 msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
1623 if (((ap_r_ptr->flags2 & RF2_CAN_SPEAK) == 0) || !aware ||
1624 !one_in_(SPEAK_CHANCE) ||
1625 !player_has_los_bold(target_ptr, oy, ox) ||
1626 !projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
1629 GAME_TEXT m_name[MAX_NLEN];
1630 char monmessage[1024];
1634 monster_desc(target_ptr, m_name, m_ptr, 0);
1636 strcpy(m_name, _("それ", "It"));
1638 if (MON_MONFEAR(m_ptr))
1639 filename = _("monfear_j.txt", "monfear.txt");
1640 else if (is_pet(m_ptr))
1641 filename = _("monpet_j.txt", "monpet.txt");
1642 else if (is_friendly(m_ptr))
1643 filename = _("monfrien_j.txt", "monfrien.txt");
1645 filename = _("monspeak_j.txt", "monspeak.txt");
1647 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
1649 msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
1655 * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
1656 * @param target_ptr プレーヤーへの参照ポインタ
1657 * @param m_idx モンスターID
1658 * @param oy 分裂元モンスターのY座標
1659 * @param ox 分裂元モンスターのX座標
1660 * @return 実際に分裂したらTRUEを返す
1662 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
1664 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1665 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1666 if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) || (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
1670 for (POSITION y = oy - 1; y <= oy + 1; y++)
1672 for (POSITION x = ox - 1; x <= ox + 1; x++)
1674 if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
1675 if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
1679 if (multiply_barrier(target_ptr, m_idx)) k = 8;
1681 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
1683 if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
1685 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
1687 r_ptr->r_flags2 |= (RF2_MULTIPLY);
1699 * @brief モンスターの移動パターンを決定する
1700 * @param target_ptr プレーヤーへの参照ポインタ
1702 * @param m_idx モンスターID
1703 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1704 * @return 移動先が存在すればTRUE
1706 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware)
1708 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1709 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1711 if (MON_CONFUSED(m_ptr) || !aware)
1713 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1717 if (random_walk(target_ptr, mm, m_ptr)) return TRUE;
1719 if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
1721 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1725 if (decide_pet_movement_direction(target_ptr, mm, m_idx)) return TRUE;
1727 if (!is_hostile(m_ptr))
1729 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1730 get_enemy_dir(target_ptr, m_idx, mm);
1734 if (!get_moves(target_ptr, m_idx, mm)) return FALSE;
1741 * todo ↓のように書いたが、"5"とはもしかして「その場に留まる」という意味か?
1742 * @brief 不規則歩行フラグを持つモンスターの移動方向をその確率に基づいて決定する
1743 * @param target_ptr プレーヤーへの参照ポインタ
1745 * @param m_ptr モンスターへの参照ポインタ
1746 * @return 不規則な方向へ歩くことになったらTRUE
1748 bool random_walk(player_type *target_ptr, DIRECTION *mm, monster_type *m_ptr)
1750 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1751 if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) && (randint0(100) < 75))
1753 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
1755 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1759 if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 50))
1761 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_50;
1763 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1767 if ((r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 25))
1769 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
1771 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1780 * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
1781 * @param target_ptr プレーヤーへの参照ポインタ
1783 * @param m_idx モンスターID
1784 * @return モンスターがペットであればTRUE
1786 bool decide_pet_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx)
1788 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1789 if (!is_pet(m_ptr)) return FALSE;
1791 bool avoid = ((target_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
1792 bool lonely = (!avoid && (m_ptr->cdis > target_ptr->pet_follow_distance));
1793 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
1794 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1795 if (get_enemy_dir(target_ptr, m_idx, mm)) return TRUE;
1796 if (!avoid && !lonely && !distant) return TRUE;
1798 POSITION dis = target_ptr->pet_follow_distance;
1799 if (target_ptr->pet_follow_distance > PET_SEEK_DIST)
1801 target_ptr->pet_follow_distance = PET_SEEK_DIST;
1804 (void)get_moves(target_ptr, m_idx, mm);
1805 target_ptr->pet_follow_distance = (s16b)dis;
1811 * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
1812 * @param target_ptr プレーヤーへの参照ポインタ
1813 * @param m_idx モンスターID
1814 * @param is_riding_mon 騎乗状態ならばTRUE
1815 * @param see_m モンスターが視界内にいたらTRUE
1816 * @return モンスターがフロアから消えたらTRUE
1818 bool runaway_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
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_runaway = is_pet(m_ptr) || is_friendly(m_ptr);
1823 can_runaway &= ((r_ptr->flags1 & RF1_UNIQUE) != 0) || ((r_ptr->flags7 & RF7_NAZGUL) != 0);
1824 can_runaway &= !target_ptr->phase_out;
1825 if (!can_runaway) return FALSE;
1827 static int riding_pinch = 0;
1829 if (m_ptr->hp >= m_ptr->maxhp / 3)
1831 /* Reset the counter */
1832 if (turn_flags_ptr->is_riding_mon) riding_pinch = 0;
1837 GAME_TEXT m_name[MAX_NLEN];
1838 monster_desc(target_ptr, m_name, m_ptr, 0);
1839 if (turn_flags_ptr->is_riding_mon && riding_pinch < 2)
1841 msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
1842 "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
1844 disturb(target_ptr, TRUE, TRUE);
1848 escape_monster(target_ptr, turn_flags_ptr, m_ptr, m_name);
1849 check_quest_completion(target_ptr, m_ptr);
1850 delete_monster_idx(target_ptr, m_idx);
1856 * @brief HPが1/3未満になった有効的なユニークモンスターの逃走処理を行う
1857 * @param target_ptr プレーヤーへの参照ポインタ
1858 * @param is_riding_mon 騎乗状態ならばTRUE
1859 * @param m_ptr モンスターへの参照ポインタ
1860 * @param m_name モンスター名称
1861 * @param see_m モンスターが視界内にいたらTRUE
1864 void escape_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, GAME_TEXT *m_name)
1866 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1867 if (turn_flags_ptr->is_riding_mon)
1869 msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
1870 if (rakuba(target_ptr, -1, FALSE))
1872 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1876 if (turn_flags_ptr->see_m)
1878 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) &&
1879 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))
1881 msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
1884 msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s reads a scroll of teleport level."), m_name);
1885 msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
1888 if (turn_flags_ptr->is_riding_mon && rakuba(target_ptr, -1, FALSE))
1890 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1896 * @brief モンスターに魔法を試行させる
1897 * @param target_ptr プレーヤーへの参照ポインタ
1898 * @param m_idx モンスターID
1899 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1900 * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
1902 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware)
1904 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1905 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1906 if ((r_ptr->freq_spell == 0) || (randint1(100) > r_ptr->freq_spell))
1909 bool counterattack = FALSE;
1910 if (m_ptr->target_y)
1912 MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
1913 if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
1914 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1916 counterattack = TRUE;
1922 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1923 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1927 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1928 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1936 * todo 少し長いが、これといってブロックとしてまとまった部分もないので暫定でこのままとする
1937 * @brief モンスターの移動に関するメインルーチン
1938 * @param target_ptr プレーヤーへの参照ポインタ
1939 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
1940 * @param m_idx モンスターID
1941 * @param mm モンスターの移動方向
1942 * @param oy 移動前の、モンスターのY座標
1943 * @param ox 移動前の、モンスターのX座標
1944 * @param count 移動回数 (のはず todo)
1945 * @return 移動が阻害される何か (ドア等)があったらFALSE
1947 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)
1949 for (int i = 0; mm[i]; i++)
1952 if (d == 5) d = ddd[randint0(8)];
1954 POSITION ny = oy + ddy[d];
1955 POSITION nx = ox + ddx[d];
1956 if (!in_bounds2(target_ptr->current_floor_ptr, ny, nx)) continue;
1959 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1960 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1961 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1962 bool can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0);
1964 if (!process_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx, can_cross))
1966 if (!process_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1970 if (!process_protection_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1972 if (!process_explosive_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1976 exe_monster_attack_to_player(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1977 if (process_monster_attack_to_monster(target_ptr, turn_flags_ptr, m_idx, g_ptr, can_cross)) return FALSE;
1979 if (turn_flags_ptr->is_riding_mon)
1981 if (!target_ptr->riding_ryoute && !MON_MONFEAR(&target_ptr->current_floor_ptr->m_list[target_ptr->riding])) turn_flags_ptr->do_move = FALSE;
1984 if (!process_post_dig_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx)) return FALSE;
1986 if (turn_flags_ptr->must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
1988 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0))
1989 turn_flags_ptr->do_move = FALSE;
1992 if (turn_flags_ptr->do_move && !can_cross && !turn_flags_ptr->did_kill_wall && !turn_flags_ptr->did_bash_door)
1993 turn_flags_ptr->do_move = FALSE;
1995 if (turn_flags_ptr->do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
1997 if (is_original_ap_and_seen(target_ptr, m_ptr))
1998 r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
2000 turn_flags_ptr->do_move = FALSE;
2003 if (!turn_flags_ptr->do_move)
2005 if (turn_flags_ptr->do_turn) break;
2010 turn_flags_ptr->do_turn = TRUE;
2011 feature_type *f_ptr;
2012 f_ptr = &f_info[g_ptr->feat];
2013 if (have_flag(f_ptr->flags, FF_TREE))
2015 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
2017 m_ptr->energy_need += ENERGY_NEED();
2021 if (!update_riding_monster(target_ptr, turn_flags_ptr, m_idx, oy, ox, ny, nx)) break;
2023 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2026 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
2027 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= target_ptr->lev)))
2029 if (is_hostile(m_ptr))
2030 disturb(target_ptr, FALSE, TRUE);
2033 bool is_takable_or_killable = g_ptr->o_idx > 0;
2034 is_takable_or_killable &= (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) != 0;
2036 bool is_pickup_items = (target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
2037 is_pickup_items &= (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
2039 is_takable_or_killable &= !is_pet(m_ptr) || is_pickup_items;
2040 if (!is_takable_or_killable)
2042 if (turn_flags_ptr->do_turn) break;
2047 update_object_by_monster_movement(target_ptr, turn_flags_ptr, m_idx, ny, nx);
2048 if (turn_flags_ptr->do_turn) break;
2058 * @brief モンスターによる壁の透過・破壊を行う
2059 * @param target_ptr プレーヤーへの参照ポインタ
2060 * @param m_ptr モンスターへの参照ポインタ
2061 * @param ny モンスターのY座標
2062 * @param nx モンスターのX座標
2063 * @param can_cross モンスターが地形を踏破できるならばTRUE
2064 * @return 透過も破壊もしなかった場合はFALSE、それ以外はTRUE
2066 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross)
2068 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2070 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2071 feature_type *f_ptr;
2072 f_ptr = &f_info[g_ptr->feat];
2073 if (player_bold(target_ptr, ny, nx))
2075 turn_flags_ptr->do_move = TRUE;
2079 if (g_ptr->m_idx > 0)
2081 turn_flags_ptr->do_move = TRUE;
2085 if (((r_ptr->flags2 & RF2_KILL_WALL) != 0) &&
2086 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !turn_flags_ptr->is_riding_mon) &&
2087 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
2088 check_hp_for_feat_destruction(f_ptr, m_ptr))
2090 turn_flags_ptr->do_move = TRUE;
2091 if (!can_cross) turn_flags_ptr->must_alter_to_move = TRUE;
2093 turn_flags_ptr->did_kill_wall = TRUE;
2097 if (!can_cross) return FALSE;
2099 turn_flags_ptr->do_move = TRUE;
2100 if (((r_ptr->flags2 & RF2_PASS_WALL) != 0) && (!turn_flags_ptr->is_riding_mon || target_ptr->pass_wall) &&
2101 have_flag(f_ptr->flags, FF_CAN_PASS))
2103 turn_flags_ptr->did_pass_wall = TRUE;
2111 * @brief モンスターによるドアの開放・破壊を行う
2112 * @param target_ptr プレーヤーへの参照ポインタ
2113 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2114 * @param m_ptr モンスターへの参照ポインタ
2115 * @param ny モンスターのY座標
2116 * @param nx モンスターのX座標
2117 * @return モンスターが死亡した場合のみFALSE
2119 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2121 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2123 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2124 if (!is_closed_door(target_ptr, g_ptr->feat)) return TRUE;
2126 feature_type *f_ptr;
2127 f_ptr = &f_info[g_ptr->feat];
2128 bool may_bash = bash_normal_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx);
2129 bash_glass_door(target_ptr, turn_flags_ptr, m_ptr, f_ptr, may_bash);
2131 if (!turn_flags_ptr->did_open_door && !turn_flags_ptr->did_bash_door) return TRUE;
2133 if (turn_flags_ptr->did_bash_door &&
2134 ((randint0(100) < 50) || (feat_state(target_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
2136 cave_alter_feat(target_ptr, ny, nx, FF_BASH);
2137 if (!monster_is_valid(m_ptr))
2139 target_ptr->update |= (PU_FLOW);
2140 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2141 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2148 cave_alter_feat(target_ptr, ny, nx, FF_OPEN);
2151 f_ptr = &f_info[g_ptr->feat];
2152 turn_flags_ptr->do_view = TRUE;
2158 * @brief モンスターが普通のドアを開ける処理
2159 * @param target_ptr プレーヤーへの参照ポインタ
2160 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2161 * @param m_ptr モンスターへの参照ポインタ
2162 * @param ny モンスターのY座標
2163 * @param nx モンスターのX座標
2164 * @return ここではドアを開けず、ガラスのドアを開ける可能性があるならTRUE
2166 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2168 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2170 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2171 feature_type *f_ptr;
2172 f_ptr = &f_info[g_ptr->feat];
2173 turn_flags_ptr->do_move = FALSE;
2174 if (((r_ptr->flags2 & RF2_OPEN_DOOR) == 0) || !have_flag(f_ptr->flags, FF_OPEN) ||
2175 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2178 if (f_ptr->power == 0)
2180 turn_flags_ptr->did_open_door = TRUE;
2181 turn_flags_ptr->do_turn = TRUE;
2185 if (randint0(m_ptr->hp / 10) > f_ptr->power)
2187 cave_alter_feat(target_ptr, ny, nx, FF_DISARM);
2188 turn_flags_ptr->do_turn = TRUE;
2197 * @brief モンスターがガラスのドアを開ける処理
2198 * @param target_ptr プレーヤーへの参照ポインタ
2199 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2200 * @param m_ptr モンスターへの参照ポインタ
2201 * @param g_ptr グリッドへの参照ポインタ
2202 * @param f_ptr 地形への参照ポインタ
2205 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash)
2207 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2208 if (!may_bash || ((r_ptr->flags2 & RF2_BASH_DOOR) == 0) || !have_flag(f_ptr->flags, FF_BASH) ||
2209 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2212 if (!check_hp_for_feat_destruction(f_ptr, m_ptr) || (randint0(m_ptr->hp / 10) <= f_ptr->power))
2215 if (have_flag(f_ptr->flags, FF_GLASS))
2216 msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
2218 msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
2220 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
2222 turn_flags_ptr->did_bash_door = TRUE;
2223 turn_flags_ptr->do_move = TRUE;
2224 turn_flags_ptr->must_alter_to_move = TRUE;
2229 * @brief 守りのルーンによるモンスターの移動制限を処理する
2230 * @param target_ptr プレーヤーへの参照ポインタ
2231 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2232 * @param m_ptr モンスターへの参照ポインタ
2233 * @param ny モンスターのY座標
2234 * @param nx モンスターのX座標
2237 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2240 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2241 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2242 if (!turn_flags_ptr->do_move || !is_glyph_grid(g_ptr) ||
2243 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2246 turn_flags_ptr->do_move = FALSE;
2247 if (is_pet(m_ptr) || (randint1(BREAK_GLYPH) >= r_ptr->level))
2250 if (g_ptr->info & CAVE_MARK)
2252 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2255 g_ptr->info &= ~(CAVE_MARK);
2256 g_ptr->info &= ~(CAVE_OBJECT);
2258 turn_flags_ptr->do_move = TRUE;
2259 note_spot(target_ptr, ny, nx);
2265 * @brief 爆発のルーンにを処理する
2266 * @param target_ptr プレーヤーへの参照ポインタ
2267 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2268 * @param m_ptr モンスターへの参照ポインタ
2269 * @param ny モンスターのY座標
2270 * @param nx モンスターのX座標
2271 * @return モンスターが死亡した場合のみFALSE
2273 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2276 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2277 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2278 if (!turn_flags_ptr->do_move || !is_explosive_rune_grid(g_ptr) ||
2279 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2282 turn_flags_ptr->do_move = FALSE;
2283 if (is_pet(m_ptr)) return TRUE;
2285 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2287 if (g_ptr->info & CAVE_MARK)
2289 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2290 BIT_FLAGS project_flags = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI;
2291 project(target_ptr, 0, 2, ny, nx, 2 * (target_ptr->lev + damroll(7, 7)), GF_MANA, project_flags, -1);
2296 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2299 g_ptr->info &= ~(CAVE_MARK);
2300 g_ptr->info &= ~(CAVE_OBJECT);
2303 note_spot(target_ptr, ny, nx);
2304 lite_spot(target_ptr, ny, nx);
2306 if (!monster_is_valid(m_ptr)) return FALSE;
2308 turn_flags_ptr->do_move = TRUE;
2314 * @brief モンスターが移動した結果、そこにプレーヤーがいたら直接攻撃を行う
2315 * @param target_ptr プレーヤーへの参照ポインタ
2316 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2317 * @param m_idx モンスターID
2318 * @param ny 移動後の、モンスターのY座標
2319 * @param nx 移動後の、モンスターのX座標
2322 * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
2324 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2326 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2327 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2328 if (!turn_flags_ptr->do_move || !player_bold(target_ptr, ny, nx))
2331 if (r_ptr->flags1 & RF1_NEVER_BLOW)
2333 if (is_original_ap_and_seen(target_ptr, m_ptr))
2334 r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
2336 turn_flags_ptr->do_move = FALSE;
2339 if (turn_flags_ptr->do_move && ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) != 0) && !MON_CONFUSED(m_ptr))
2341 if (!(r_ptr->flags2 & RF2_STUPID))
2342 turn_flags_ptr->do_move = FALSE;
2343 else if (is_original_ap_and_seen(target_ptr, m_ptr))
2344 r_ptr->r_flags2 |= (RF2_STUPID);
2347 if (!turn_flags_ptr->do_move) return;
2349 if (!target_ptr->riding || one_in_(2))
2351 (void)make_attack_normal(target_ptr, m_idx);
2352 turn_flags_ptr->do_move = FALSE;
2353 turn_flags_ptr->do_turn = TRUE;
2359 * @brief モンスターからモンスターへの攻撃処理
2360 * @param target_ptr プレーヤーへの参照ポインタ
2361 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2362 * @param m_idx モンスターID
2363 * @param g_ptr グリッドへの参照ポインタ
2364 * @param can_cross モンスターが地形を踏破できるならばTRUE
2365 * @return ターン消費が発生したらTRUE
2367 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)
2369 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2370 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2371 monster_type *y_ptr;
2372 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2373 if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) return FALSE;
2375 monster_race *z_ptr = &r_info[y_ptr->r_idx];
2376 turn_flags_ptr->do_move = FALSE;
2377 if ((((r_ptr->flags2 & RF2_KILL_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_BLOW) == 0) &&
2378 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
2379 can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
2380 are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
2382 return exe_monster_attack_to_monster(target_ptr, m_idx, g_ptr);
2385 if (((r_ptr->flags2 & RF2_MOVE_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_MOVE) == 0) &&
2386 (r_ptr->mexp > z_ptr->mexp) &&
2387 can_cross && (g_ptr->m_idx != target_ptr->riding) &&
2388 monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
2390 turn_flags_ptr->do_move = TRUE;
2391 turn_flags_ptr->did_move_body = TRUE;
2392 (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
2400 * @brief モンスターからモンスターへの直接攻撃を実行する
2401 * @param target_ptr プレーヤーへの参照ポインタ
2402 * @param m_idx モンスターID
2403 * @param g_ptr グリッドへの参照ポインタ
2405 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr)
2407 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2408 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2409 monster_type *y_ptr;
2410 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2411 if ((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) return FALSE;
2413 if (((r_ptr->flags2 & RF2_KILL_BODY) == 0) && is_original_ap_and_seen(target_ptr, m_ptr))
2414 r_ptr->r_flags2 |= (RF2_KILL_BODY);
2416 if ((y_ptr->r_idx == 0) || (y_ptr->hp < 0)) return FALSE;
2417 if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return TRUE;
2418 if ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) == 0) return FALSE;
2419 if (MON_CONFUSED(m_ptr)) return TRUE;
2420 if ((r_ptr->flags2 & RF2_STUPID) == 0) return FALSE;
2422 if (is_original_ap_and_seen(target_ptr, m_ptr))
2423 r_ptr->r_flags2 |= (RF2_STUPID);
2430 * @brief モンスターが壁を掘った後続処理を実行する
2431 * @param target_ptr プレーヤーへの参照ポインタ
2432 * @turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2433 * @param m_ptr モンスターへの参照ポインタ
2434 * @param ny モンスターのY座標
2435 * @param nx モンスターのX座標
2436 * @return モンスターが死亡した場合のみFALSE
2438 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2440 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2442 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2443 feature_type *f_ptr;
2444 f_ptr = &f_info[g_ptr->feat];
2445 if (!turn_flags_ptr->did_kill_wall || !turn_flags_ptr->do_move) return TRUE;
2447 if (one_in_(GRINDNOISE))
2449 if (have_flag(f_ptr->flags, FF_GLASS))
2450 msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
2452 msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
2455 cave_alter_feat(target_ptr, ny, nx, FF_HURT_DISI);
2457 if (!monster_is_valid(m_ptr))
2459 target_ptr->update |= (PU_FLOW);
2460 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2461 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2466 f_ptr = &f_info[g_ptr->feat];
2467 turn_flags_ptr->do_view = TRUE;
2468 turn_flags_ptr->do_turn = TRUE;
2474 * @brief 騎乗中のモンスター情報を更新する
2475 * @param target_ptr プレーヤーへの参照ポインタ
2476 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2477 * @param m_idx モンスターID
2478 * @param oy 移動前の、モンスターのY座標
2479 * @param ox 移動前の、モンスターのX座標
2480 * @param ny 移動後の、モンスターのY座標
2481 * @param ox 移動後の、モンスターのX座標
2482 * @return アイテム等に影響を及ぼしたらTRUE
2484 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)
2486 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2488 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2489 monster_type *y_ptr;
2490 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2491 if (turn_flags_ptr->is_riding_mon)
2492 return move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP);
2494 target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
2499 update_monster(target_ptr, g_ptr->m_idx, TRUE);
2502 g_ptr->m_idx = m_idx;
2505 update_monster(target_ptr, m_idx, TRUE);
2507 lite_spot(target_ptr, oy, ox);
2508 lite_spot(target_ptr, ny, nx);
2514 * @brief モンスターの移動に伴うオブジェクト処理 (アイテム破壊等)
2515 * @param target_ptr プレーヤーへの参照ポインタ
2516 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2517 * @param m_idx モンスターID
2518 * @param ny 移動後の、モンスターのY座標
2519 * @param nx 移動後の、モンスターのX座標
2521 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2523 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2524 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2526 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2528 OBJECT_IDX this_o_idx, next_o_idx;
2529 turn_flags_ptr->do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
2530 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2532 BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
2533 GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
2534 object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
2535 next_o_idx = o_ptr->next_o_idx;
2537 if (turn_flags_ptr->do_take)
2539 /* Skip gold, corpse and statue */
2540 if (o_ptr->tval == TV_GOLD || (o_ptr->tval == TV_CORPSE) || (o_ptr->tval == TV_STATUE))
2544 object_flags(o_ptr, flgs);
2545 object_desc(target_ptr, o_name, o_ptr, 0);
2546 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
2547 update_object_flags(flgs, &flg2, &flg3, &flgr);
2549 bool is_special_object = object_is_artifact(o_ptr) ||
2550 ((r_ptr->flags3 & flg3) != 0) ||
2551 ((r_ptr->flags2 & flg2) != 0) ||
2552 (((~(r_ptr->flagsr) & flgr) != 0) && !(r_ptr->flagsr & RFR_RES_ALL));
2553 monster_pickup_object(target_ptr, turn_flags_ptr, m_idx, o_ptr, is_special_object, ny, nx, m_name, o_name, this_o_idx);
2559 * @brief オブジェクトのフラグを更新する
2561 void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr)
2563 if (have_flag(flgs, TR_SLAY_DRAGON)) *flg3 |= (RF3_DRAGON);
2564 if (have_flag(flgs, TR_KILL_DRAGON)) *flg3 |= (RF3_DRAGON);
2565 if (have_flag(flgs, TR_SLAY_TROLL)) *flg3 |= (RF3_TROLL);
2566 if (have_flag(flgs, TR_KILL_TROLL)) *flg3 |= (RF3_TROLL);
2567 if (have_flag(flgs, TR_SLAY_GIANT)) *flg3 |= (RF3_GIANT);
2568 if (have_flag(flgs, TR_KILL_GIANT)) *flg3 |= (RF3_GIANT);
2569 if (have_flag(flgs, TR_SLAY_ORC)) *flg3 |= (RF3_ORC);
2570 if (have_flag(flgs, TR_KILL_ORC)) *flg3 |= (RF3_ORC);
2571 if (have_flag(flgs, TR_SLAY_DEMON)) *flg3 |= (RF3_DEMON);
2572 if (have_flag(flgs, TR_KILL_DEMON)) *flg3 |= (RF3_DEMON);
2573 if (have_flag(flgs, TR_SLAY_UNDEAD)) *flg3 |= (RF3_UNDEAD);
2574 if (have_flag(flgs, TR_KILL_UNDEAD)) *flg3 |= (RF3_UNDEAD);
2575 if (have_flag(flgs, TR_SLAY_ANIMAL)) *flg3 |= (RF3_ANIMAL);
2576 if (have_flag(flgs, TR_KILL_ANIMAL)) *flg3 |= (RF3_ANIMAL);
2577 if (have_flag(flgs, TR_SLAY_EVIL)) *flg3 |= (RF3_EVIL);
2578 if (have_flag(flgs, TR_KILL_EVIL)) *flg3 |= (RF3_EVIL);
2579 if (have_flag(flgs, TR_SLAY_HUMAN)) *flg2 |= (RF2_HUMAN);
2580 if (have_flag(flgs, TR_KILL_HUMAN)) *flg2 |= (RF2_HUMAN);
2581 if (have_flag(flgs, TR_BRAND_ACID)) *flgr |= (RFR_IM_ACID);
2582 if (have_flag(flgs, TR_BRAND_ELEC)) *flgr |= (RFR_IM_ELEC);
2583 if (have_flag(flgs, TR_BRAND_FIRE)) *flgr |= (RFR_IM_FIRE);
2584 if (have_flag(flgs, TR_BRAND_COLD)) *flgr |= (RFR_IM_COLD);
2585 if (have_flag(flgs, TR_BRAND_POIS)) *flgr |= (RFR_IM_POIS);
2590 * @brief モンスターがアイテムを拾うか壊す処理
2591 * @param target_ptr プレーヤーへの参照ポインタ
2592 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2593 * @param m_idx モンスターID
2594 * @param o_ptr オブジェクトへの参照ポインタ
2595 * @param is_special_object モンスターが拾えないアイテム (アーティファクト等)であればTRUE
2596 * @param ny 移動後の、モンスターのY座標
2597 * @param nx 移動後の、モンスターのX座標
2598 * @param m_name モンスター名
2599 * @param o_name アイテム名
2600 * @param this_o_idx モンスターが乗ったオブジェクトID
2603 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)
2605 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2606 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2607 if (is_special_object)
2609 if (turn_flags_ptr->do_take && (r_ptr->flags2 & RF2_STUPID))
2611 turn_flags_ptr->did_take_item = TRUE;
2612 if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
2614 msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
2621 if (turn_flags_ptr->do_take)
2623 turn_flags_ptr->did_take_item = TRUE;
2624 if (player_can_see_bold(target_ptr, ny, nx))
2626 msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
2629 excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
2630 o_ptr->marked &= OM_TOUCHED;
2631 o_ptr->iy = o_ptr->ix = 0;
2632 o_ptr->held_m_idx = m_idx;
2633 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2634 m_ptr->hold_o_idx = this_o_idx;
2638 if (is_pet(m_ptr)) return;
2640 turn_flags_ptr->did_kill_item = TRUE;
2641 if (player_has_los_bold(target_ptr, ny, nx))
2643 msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
2646 delete_object_idx(target_ptr, this_o_idx);
2651 * @brief updateフィールドを更新する
2652 * @param target_ptr プレーヤーへの参照ポインタ
2653 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2656 void update_player_type(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_race *r_ptr)
2658 if (turn_flags_ptr->do_view)
2660 target_ptr->update |= (PU_FLOW);
2661 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2664 if (turn_flags_ptr->do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
2665 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !target_ptr->phase_out)))
2667 target_ptr->update |= (PU_MON_LITE);
2673 * @brief モンスターのフラグを更新する
2674 * @param target_ptr プレーヤーへの参照ポインタ
2675 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2676 * @param m_ptr モンスターへの参照ポインタ
2679 void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr)
2681 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2682 if (!is_original_ap_and_seen(target_ptr, m_ptr)) return;
2684 if (turn_flags_ptr->did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
2685 if (turn_flags_ptr->did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2686 if (turn_flags_ptr->did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
2687 if (turn_flags_ptr->did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
2688 if (turn_flags_ptr->did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
2689 if (turn_flags_ptr->did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
2690 if (turn_flags_ptr->did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2695 * @brief モンスターの恐怖状態を処理する
2696 * @param target_ptr プレーヤーへの参照ポインタ
2697 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2698 * @param m_idx モンスターID
2699 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
2700 * @return モンスターが戦いを決意したらTRUE
2702 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
2704 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2705 bool is_battle_determined = !turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && MON_MONFEAR(m_ptr) && turn_flags_ptr->aware;
2706 if (!is_battle_determined) return FALSE;
2708 (void)set_monster_monfear(target_ptr, m_idx, 0);
2709 if (!turn_flags_ptr->see_m) return TRUE;
2711 GAME_TEXT m_name[MAX_NLEN];
2712 monster_desc(target_ptr, m_name, m_ptr, 0);
2713 msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
2719 * @brief 全モンスターのターン管理メインルーチン /
2720 * Process all the "live" monsters, once per game turn.
2723 * During each game current game turn, we scan through the list of all the "live" monsters,\n
2724 * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
2725 * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
2727 * Note that monsters can never move in the monster array (except when the\n
2728 * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
2730 * This function is responsible for at least half of the processor time\n
2731 * on a normal system with a "normal" amount of monsters and a player doing\n
2734 * When the player is resting, virtually 90% of the processor time is spent\n
2735 * in this function, and its children, "process_monster()" and "make_move()".\n
2737 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
2738 * especially when the player is running.\n
2740 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
2741 * monsters while they are still being "born". A monster is "fresh" only\n
2742 * during the game turn in which it is created, and we use the "hack_m_idx" to\n
2743 * determine if the monster is yet to be processed during the game turn.\n
2745 * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
2746 * move before any "nasty" monsters get to use their spell attacks.\n
2748 * Note that when the "knowledge" about the currently tracked monster\n
2749 * changes (flags, attacks, spells), we induce a redraw of the monster\n
2752 void process_monsters(player_type *target_ptr)
2754 old_race_flags tmp_flags;
2755 old_race_flags *old_race_flags_ptr = init_old_race_flags(&tmp_flags);
2757 floor_type *floor_ptr = target_ptr->current_floor_ptr;
2758 floor_ptr->monster_noise = FALSE;
2760 MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
2761 save_old_race_flags(target_ptr, old_race_flags_ptr);
2762 sweep_monster_process(target_ptr);
2765 if (!target_ptr->monster_race_idx || (target_ptr->monster_race_idx != old_monster_race_idx))
2768 update_player_window(target_ptr, old_race_flags_ptr);
2773 * @brief old_race_flags_ptr の初期化
2775 old_race_flags *init_old_race_flags(old_race_flags *old_race_flags_ptr)
2777 old_race_flags_ptr->old_r_flags1 = 0L;
2778 old_race_flags_ptr->old_r_flags2 = 0L;
2779 old_race_flags_ptr->old_r_flags3 = 0L;
2780 old_race_flags_ptr->old_r_flags4 = 0L;
2781 old_race_flags_ptr->old_r_flags5 = 0L;
2782 old_race_flags_ptr->old_r_flags6 = 0L;
2783 old_race_flags_ptr->old_r_flagsr = 0L;
2785 old_race_flags_ptr->old_r_blows0 = 0;
2786 old_race_flags_ptr->old_r_blows1 = 0;
2787 old_race_flags_ptr->old_r_blows2 = 0;
2788 old_race_flags_ptr->old_r_blows3 = 0;
2790 old_race_flags_ptr->old_r_cast_spell = 0;
2791 return old_race_flags_ptr;
2796 * @brief 古いモンスター情報の保存
2797 * @param target_ptr プレーヤーへの参照ポインタ
2798 * @param old_race_flags_ptr モンスターフラグへの参照ポインタ
2801 void save_old_race_flags(player_type *target_ptr, old_race_flags *old_race_flags_ptr)
2803 if (target_ptr->monster_race_idx == 0) return;
2805 monster_race *r_ptr;
2806 r_ptr = &r_info[target_ptr->monster_race_idx];
2808 old_race_flags_ptr->old_r_flags1 = r_ptr->r_flags1;
2809 old_race_flags_ptr->old_r_flags2 = r_ptr->r_flags2;
2810 old_race_flags_ptr->old_r_flags3 = r_ptr->r_flags3;
2811 old_race_flags_ptr->old_r_flags4 = r_ptr->r_flags4;
2812 old_race_flags_ptr->old_r_flags5 = r_ptr->r_flags5;
2813 old_race_flags_ptr->old_r_flags6 = r_ptr->r_flags6;
2814 old_race_flags_ptr->old_r_flagsr = r_ptr->r_flagsr;
2816 old_race_flags_ptr->old_r_blows0 = r_ptr->r_blows[0];
2817 old_race_flags_ptr->old_r_blows1 = r_ptr->r_blows[1];
2818 old_race_flags_ptr->old_r_blows2 = r_ptr->r_blows[2];
2819 old_race_flags_ptr->old_r_blows3 = r_ptr->r_blows[3];
2821 old_race_flags_ptr->old_r_cast_spell = r_ptr->r_cast_spell;
2826 * @brief フロア内のモンスターについてターン終了時の処理を繰り返す
2827 * @param target_ptr プレーヤーへの参照ポインタ
2829 void sweep_monster_process(player_type *target_ptr)
2831 floor_type *floor_ptr = target_ptr->current_floor_ptr;
2832 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
2834 monster_type *m_ptr;
2835 monster_race *r_ptr;
2836 m_ptr = &floor_ptr->m_list[i];
2837 r_ptr = &r_info[m_ptr->r_idx];
2839 if (target_ptr->leaving) return;
2840 if (!monster_is_valid(m_ptr)) continue;
2841 if (target_ptr->wild_mode) continue;
2843 if (m_ptr->mflag & MFLAG_BORN)
2845 m_ptr->mflag &= ~(MFLAG_BORN);
2849 if (m_ptr->cdis >= AAF_LIMIT) continue;
2850 if (!decide_process_continue(target_ptr, m_ptr)) continue;
2852 SPEED speed = decide_monster_speed(target_ptr, m_ptr, i);
2853 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
2854 if (m_ptr->energy_need > 0) continue;
2856 m_ptr->energy_need += ENERGY_NEED();
2858 process_monster(target_ptr, i);
2859 reset_target(m_ptr);
2861 if (target_ptr->no_flowed && one_in_(3))
2862 m_ptr->mflag2 |= MFLAG2_NOFLOW;
2864 if (!target_ptr->playing || target_ptr->is_dead) return;
2865 if (target_ptr->leaving) return;
2871 * @brief 後続のモンスター処理が必要かどうか判定する (要調査)
2872 * @param target_ptr プレーヤーへの参照ポインタ
2873 * @param m_ptr モンスターへの参照ポインタ
2874 * @return 後続処理が必要ならTRUE
2876 bool decide_process_continue(player_type *target_ptr, monster_type *m_ptr)
2878 monster_race *r_ptr;
2879 r_ptr = &r_info[m_ptr->r_idx];
2880 if (!target_ptr->no_flowed)
2882 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
2885 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
2888 if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
2889 (player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
2892 if (m_ptr->target_y)
2900 * @brief モンスターの加速値を決定する
2901 * @param target_ptr プレーヤーへの参照ポインタ
2902 * @param m_ptr モンスターへの参照ポインタ
2903 * @param monster_number 走査中のモンスター番号
2906 SPEED decide_monster_speed(player_type *target_ptr, monster_type *m_ptr, int monster_number)
2909 if (target_ptr->riding == monster_number)
2911 speed = target_ptr->pspeed;
2915 speed = m_ptr->mspeed;
2916 if (ironman_nightmare) speed += 5;
2918 if (MON_FAST(m_ptr)) speed += 10;
2919 if (MON_SLOW(m_ptr)) speed -= 10;
2926 * @brief モンスターフラグの更新に基づき、モンスター表示を更新する
2927 * @param target_ptr プレーヤーへの参照ポインタ
2928 * @param old_race_flags_ptr モンスターフラグへの参照ポインタ
2931 void update_player_window(player_type *target_ptr, old_race_flags *old_race_flags_ptr)
2933 monster_race *r_ptr;
2934 r_ptr = &r_info[target_ptr->monster_race_idx];
2935 if ((old_race_flags_ptr->old_r_flags1 != r_ptr->r_flags1) ||
2936 (old_race_flags_ptr->old_r_flags2 != r_ptr->r_flags2) ||
2937 (old_race_flags_ptr->old_r_flags3 != r_ptr->r_flags3) ||
2938 (old_race_flags_ptr->old_r_flags4 != r_ptr->r_flags4) ||
2939 (old_race_flags_ptr->old_r_flags5 != r_ptr->r_flags5) ||
2940 (old_race_flags_ptr->old_r_flags6 != r_ptr->r_flags6) ||
2941 (old_race_flags_ptr->old_r_flagsr != r_ptr->r_flagsr) ||
2942 (old_race_flags_ptr->old_r_blows0 != r_ptr->r_blows[0]) ||
2943 (old_race_flags_ptr->old_r_blows1 != r_ptr->r_blows[1]) ||
2944 (old_race_flags_ptr->old_r_blows2 != r_ptr->r_blows[2]) ||
2945 (old_race_flags_ptr->old_r_blows3 != r_ptr->r_blows[3]) ||
2946 (old_race_flags_ptr->old_r_cast_spell != r_ptr->r_cast_spell))
2948 target_ptr->window |= (PW_MONSTER);