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;
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 safe_coordinate 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);
98 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
99 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx);
100 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
101 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx);
102 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
103 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
104 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
105 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
106 bool explode_monster(player_type *target_ptr, MONSTER_IDX m_idx);
107 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
108 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware);
109 bool random_walk(player_type *target_ptr, DIRECTION *mm, monster_type *m_ptr);
110 bool decide_pet_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx);
111 bool runaway_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
112 void escape_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, GAME_TEXT *m_name);
113 void process_special(player_type *target_ptr, MONSTER_IDX m_idx);
114 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware);
115 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware);
117 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross);
118 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
119 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
120 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash);
121 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
122 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
124 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
125 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);
126 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr);
128 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);
129 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
130 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);
132 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
134 void update_player_type(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_race *r_ptr);
135 void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr);
136 void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr);
137 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);
138 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
140 void save_old_race_flags(player_type *target_ptr, old_race_flags *old_race_flags_ptr);
141 void sweep_monster_process(player_type *target_ptr);
142 bool decide_process_continue(player_type *target_ptr, monster_type *m_ptr);
143 SPEED decide_monster_speed(player_type *target_ptr, monster_type *m_ptr, int monster_number);
144 void update_player_window(player_type *target_ptr, old_race_flags *old_race_flags_ptr);
147 * @brief モンスターが敵に接近するための方向を計算するメインルーチン
148 * Calculate the direction to the next enemy
149 * @param target_ptr プレーヤーへの参照ポインタ
150 * @param m_idx モンスターの参照ID
151 * @param mm 移動するべき方角IDを返す参照ポインタ
152 * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
154 bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
156 floor_type *floor_ptr = target_ptr->current_floor_ptr;
157 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
159 POSITION x = 0, y = 0;
160 if (target_ptr->riding_t_m_idx && player_bold(target_ptr, m_ptr->fy, m_ptr->fx))
162 y = floor_ptr->m_list[target_ptr->riding_t_m_idx].fy;
163 x = floor_ptr->m_list[target_ptr->riding_t_m_idx].fx;
165 else if (is_pet(m_ptr) && target_ptr->pet_t_m_idx)
167 y = floor_ptr->m_list[target_ptr->pet_t_m_idx].fy;
168 x = floor_ptr->m_list[target_ptr->pet_t_m_idx].fx;
174 if (target_ptr->phase_out)
176 start = randint1(floor_ptr->m_max - 1) + floor_ptr->m_max;
177 if (randint0(2)) plus = -1;
181 start = floor_ptr->m_max + 1;
184 decide_enemy_approch_direction(target_ptr, m_idx, start, plus, &y, &x);
186 if ((x == 0) && (y == 0)) return FALSE;
192 store_enemy_approch_direction(mm, y, x);
198 * @brief モンスターが敵に接近するための方向を決定する
199 * @param target_ptr プレーヤーへの参照ポインタ
200 * @param m_idx モンスターID
201 * @param start モンスターIDの開始
202 * @param plus モンスターIDの増減 (1/2 の確率で+1、1/2の確率で-1)
203 * @param y モンスターの移動方向Y
204 * @param x モンスターの移動方向X
207 void decide_enemy_approch_direction(player_type *target_ptr, MONSTER_IDX m_idx, int start, int plus, POSITION *y, POSITION *x)
209 floor_type *floor_ptr = target_ptr->current_floor_ptr;
210 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
211 monster_race *r_ptr = &r_info[m_ptr->r_idx];
212 for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus)
214 MONSTER_IDX dummy = (i % floor_ptr->m_max);
215 if (dummy == 0) continue;
217 MONSTER_IDX t_idx = dummy;
219 t_ptr = &floor_ptr->m_list[t_idx];
220 if (t_ptr == m_ptr) continue;
221 if (!monster_is_valid(t_ptr)) continue;
222 if (decide_pet_approch_direction(target_ptr, m_ptr, t_ptr)) continue;
223 if (!are_enemies(target_ptr, m_ptr, t_ptr)) continue;
225 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) ||
226 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)))
228 if (!in_disintegration_range(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
232 if (!projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
243 * @brief ペットが敵に接近するための方向を決定する
244 * @param target_ptr プレーヤーへの参照ポインタ
245 * @param m_ptr 移動を試みているモンスターへの参照ポインタ
246 * @param t_ptr 移動先モンスターへの参照ポインタ
247 * @param plus モンスターIDの増減 (1/2 の確率で+1、1/2の確率で-1)
248 * @return ペットがモンスターに近づくならばTRUE
250 bool decide_pet_approch_direction(player_type *target_ptr, monster_type *m_ptr, monster_type *t_ptr)
252 monster_race *r_ptr = &r_info[m_ptr->r_idx];
253 if (!is_pet(m_ptr)) return FALSE;
255 if (target_ptr->pet_follow_distance < 0)
257 if (t_ptr->cdis <= (0 - target_ptr->pet_follow_distance))
262 else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > target_ptr->pet_follow_distance))
267 return (r_ptr->aaf < t_ptr->cdis);
272 * @brief モンスターの移動方向を保存する
277 void store_enemy_approch_direction(int *mm, POSITION y, POSITION x)
279 /* North, South, East, West, North-West, North-East, South-West, South-East */
280 if ((y < 0) && (x == 0))
286 else if ((y > 0) && (x == 0))
292 else if ((x > 0) && (y == 0))
298 else if ((x < 0) && (y == 0))
304 else if ((y < 0) && (x < 0))
310 else if ((y < 0) && (x > 0))
316 else if ((y > 0) && (x < 0))
322 else if ((y > 0) && (x > 0))
332 * @brief モンスターがプレイヤーから逃走するかどうかを返す /
333 * Returns whether a given monster will try to run from the player.
334 * @param m_idx 逃走するモンスターの参照ID
335 * @return モンスターがプレイヤーから逃走するならばTRUEを返す。
337 * Monsters will attempt to avoid very powerful players. See below.\n
339 * Because this function is called so often, little details are important\n
340 * for efficiency. Like not using "mod" or "div" when possible. And\n
341 * attempting to check the conditions in an optimal order. Note that\n
342 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
344 * Note that this function is responsible for about one to five percent\n
345 * of the processor use in normal conditions...\n
347 static bool mon_will_run(player_type *target_ptr, MONSTER_IDX m_idx)
349 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
350 monster_race *r_ptr = &r_info[m_ptr->r_idx];
354 return ((target_ptr->pet_follow_distance < 0) &&
355 (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
358 if (m_ptr->cdis > MAX_SIGHT + 5) return FALSE;
359 if (MON_MONFEAR(m_ptr)) return TRUE;
360 if (m_ptr->cdis <= 5) return FALSE;
362 PLAYER_LEVEL p_lev = target_ptr->lev;
363 DEPTH m_lev = r_ptr->level + (m_idx & 0x08) + 25;
364 if (m_lev > p_lev + 4) return FALSE;
365 if (m_lev + 4 <= p_lev) return TRUE;
367 HIT_POINT p_chp = target_ptr->chp;
368 HIT_POINT p_mhp = target_ptr->mhp;
369 HIT_POINT m_chp = m_ptr->hp;
370 HIT_POINT m_mhp = m_ptr->maxhp;
371 u32b p_val = (p_lev * p_mhp) + (p_chp << 2);
372 u32b m_val = (m_lev * m_mhp) + (m_chp << 2);
373 if (p_val * m_mhp > m_val * p_mhp) return TRUE;
380 * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
381 * Search spell castable grid
382 * @param target_ptr プレーヤーへの参照ポインタ
383 * @param m_idx モンスターの参照ID
384 * @param yp 適したマスのY座標を返す参照ポインタ
385 * @param xp 適したマスのX座標を返す参照ポインタ
386 * @return 有効なマスがあった場合TRUEを返す
388 static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
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 POSITION y1 = m_ptr->fy;
395 POSITION x1 = m_ptr->fx;
397 if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x)) return FALSE;
399 int now_cost = floor_ptr->grid_array[y1][x1].cost;
400 if (now_cost == 0) now_cost = 999;
402 bool can_open_door = FALSE;
403 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
405 can_open_door = TRUE;
409 for (int i = 7; i >= 0; i--)
411 POSITION y = y1 + ddy_ddd[i];
412 POSITION x = x1 + ddx_ddd[i];
413 if (!in_bounds2(floor_ptr, y, x)) continue;
414 if (player_bold(target_ptr, y, x)) return FALSE;
417 g_ptr = &floor_ptr->grid_array[y][x];
418 int cost = g_ptr->cost;
419 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))))
421 if (cost == 0) continue;
422 if (!can_open_door && is_closed_door(target_ptr, g_ptr->feat)) continue;
425 if (cost == 0) cost = 998;
427 if (now_cost < cost) continue;
428 if (!projectable(target_ptr, y, x, target_ptr->y, target_ptr->x)) continue;
429 if (best < cost) continue;
432 *yp = y1 + ddy_ddd[i];
433 *xp = x1 + ddx_ddd[i];
436 if (best == 999) return FALSE;
443 * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
444 * Choose the "best" direction for "flowing"
445 * @param m_idx モンスターの参照ID
446 * @param yp 移動先のマスのY座標を返す参照ポインタ
447 * @param xp 移動先のマスのX座標を返す参照ポインタ
448 * @param no_flow モンスターにFLOWフラグが経っていない状態でTRUE
449 * @return 有効なマスがあった場合TRUEを返す
451 * Note that ghosts and rock-eaters are never allowed to "flow",\n
452 * since they should move directly towards the player.\n
454 * Prefer "non-diagonal" directions, but twiddle them a little\n
455 * to angle slightly towards the player's actual location.\n
457 * Allow very perceptive monsters to track old "spoor" left by\n
458 * previous locations occupied by the player. This will tend\n
459 * to have monsters end up either near the player or on a grid\n
460 * recently occupied by the player (and left via "teleport").\n
462 * Note that if "smell" is turned on, all monsters get vicious.\n
464 * Also note that teleporting away from a location will cause\n
465 * the monsters who were chasing you to converge on that location\n
466 * as long as you are still near enough to "annoy" them without\n
467 * being close enough to chase directly. I have no idea what will\n
468 * happen if you combine "smell" with low "aaf" values.\n
470 static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
473 floor_type *floor_ptr = target_ptr->current_floor_ptr;
474 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
475 monster_race *r_ptr = &r_info[m_ptr->r_idx];
477 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
478 r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
479 r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
481 if (get_moves_aux2(target_ptr, m_idx, yp, xp)) return TRUE;
484 if (no_flow) return FALSE;
485 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) return FALSE;
486 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)) return FALSE;
488 POSITION y1 = m_ptr->fy;
489 POSITION x1 = m_ptr->fx;
490 if (player_has_los_bold(target_ptr, y1, x1) && projectable(target_ptr, target_ptr->y, target_ptr->x, y1, x1)) return FALSE;
492 g_ptr = &floor_ptr->grid_array[y1][x1];
495 bool use_scent = FALSE;
500 else if (g_ptr->when)
502 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when - g_ptr->when > 127) return FALSE;
512 for (int i = 7; i >= 0; i--)
514 POSITION y = y1 + ddy_ddd[i];
515 POSITION x = x1 + ddx_ddd[i];
517 if (!in_bounds2(floor_ptr, y, x)) continue;
519 g_ptr = &floor_ptr->grid_array[y][x];
522 int when = g_ptr->when;
523 if (best > when) continue;
530 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
539 if ((cost == 0) || (best < cost)) continue;
544 *yp = target_ptr->y + 16 * ddy_ddd[i];
545 *xp = target_ptr->x + 16 * ddx_ddd[i];
548 if (best == 999 || best == 0) return FALSE;
555 * @brief モンスターがプレイヤーから逃走することが可能なマスを走査する /
556 * Provide a location to flee to, but give the player a wide berth.
557 * @param m_idx モンスターの参照ID
558 * @param yp 移動先のマスのY座標を返す参照ポインタ
559 * @param xp 移動先のマスのX座標を返す参照ポインタ
560 * @return 有効なマスがあった場合TRUEを返す
562 * A monster may wish to flee to a location that is behind the player,\n
563 * but instead of heading directly for it, the monster should "swerve"\n
564 * around the player so that he has a smaller chance of getting hit.\n
566 static bool get_fear_moves_aux(floor_type *floor_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
568 POSITION gy = 0, gx = 0;
570 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
571 POSITION fy = m_ptr->fy;
572 POSITION fx = m_ptr->fx;
574 POSITION y1 = fy - (*yp);
575 POSITION x1 = fx - (*xp);
578 for (int i = 7; i >= 0; i--)
580 POSITION y = fy + ddy_ddd[i];
581 POSITION x = fx + ddx_ddd[i];
582 if (!in_bounds2(floor_ptr, y, x)) continue;
584 POSITION dis = distance(y, x, y1, x1);
585 POSITION s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
588 if (s < score) continue;
595 if (score == -1) return FALSE;
605 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
608 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
609 * offsets of all the locations with a distance of n from a central point,
610 * with an offset of (0,0) indicating no more offsets at this distance.
612 * This is, of course, fairly unreadable, but it eliminates multiple loops
613 * from the previous version.
615 * It is probably better to replace these arrays with code to compute
616 * the relevant arrays, even if the storage is pre-allocated in hard
617 * coded sizes. At the very least, code should be included which is
618 * able to generate and dump these arrays (ala "los()").
620 * Also, the storage needs could be halved by using bytes.
622 * These arrays could be combined into two big arrays, using sub-arrays
623 * to hold the offsets and lengths of each portion of the sub-arrays, and
624 * this could perhaps also be used somehow in the "look" code.
628 static POSITION d_off_y_0[] = { 0 };
629 static POSITION d_off_x_0[] = { 0 };
631 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
632 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
634 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
635 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
637 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
638 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
640 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 };
641 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 };
644 static POSITION d_off_y_5[] =
645 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
646 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
649 static POSITION d_off_x_5[] =
650 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
651 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
655 static POSITION d_off_y_6[] =
656 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
657 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
660 static POSITION d_off_x_6[] =
661 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
662 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
663 -3, 2, 3, -1, 0, 1, 0 };
666 static POSITION d_off_y_7[] =
667 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
668 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
669 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
671 static POSITION d_off_x_7[] =
672 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
673 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
674 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
678 static POSITION d_off_y_8[] =
679 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
680 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
681 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
684 static POSITION d_off_x_8[] =
685 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
686 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
687 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
691 static POSITION d_off_y_9[] =
692 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
693 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
694 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
695 7, 8, 8, 8, 8, 9, 9, 9, 0 };
697 static POSITION d_off_x_9[] =
698 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
699 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
700 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
701 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
704 static POSITION *dist_offsets_y[10] =
706 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
707 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
710 static POSITION *dist_offsets_x[10] =
712 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
713 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
717 * @brief モンスターが逃げ込める安全な地点を返す /
718 * Choose a "safe" location near a monster for it to run toward.
719 * @param target_ptr プレーヤーへの参照ポインタ
720 * @param m_idx モンスターの参照ID
721 * @param yp 移動先のマスのY座標を返す参照ポインタ
722 * @param xp 移動先のマスのX座標を返す参照ポインタ
723 * @return 有効なマスがあった場合TRUEを返す
725 * A location is "safe" if it can be reached quickly and the player\n
726 * is not able to fire into it (it isn't a "clean shot"). So, this will\n
727 * cause monsters to "duck" behind walls. Hopefully, monsters will also\n
728 * try to run towards corridor openings if they are in a room.\n
730 * This function may take lots of CPU time if lots of monsters are\n
733 * Return TRUE if a safe location is available.\n
735 bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
737 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
738 for (POSITION d = 1; d < 10; d++)
741 y_offsets = dist_offsets_y[d];
744 x_offsets = dist_offsets_x[d];
746 safe_coordinate candidate = sweep_safe_coordinate(target_ptr, m_idx, y_offsets, x_offsets, d);
748 if (candidate.gdis <= 0) continue;
750 *yp = m_ptr->fy - candidate.gy;
751 *xp = m_ptr->fx - candidate.gx;
761 * @brief モンスターが逃げ込める地点を走査する
762 * @param target_ptr プレーヤーへの参照ポインタ
763 * @param m_idx モンスターID
766 * @param d モンスターがいる地点からの距離
768 safe_coordinate sweep_safe_coordinate(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *y_offsets, POSITION *x_offsets, int d)
770 safe_coordinate candidate;
774 floor_type *floor_ptr = target_ptr->current_floor_ptr;
775 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
776 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
778 i++, dx = x_offsets[i], dy = y_offsets[i])
780 POSITION y = m_ptr->fy + dy;
781 POSITION x = m_ptr->fx + dx;
782 if (!in_bounds(floor_ptr, y, x)) continue;
785 g_ptr = &floor_ptr->grid_array[y][x];
787 BIT_FLAGS16 riding_mode = (m_idx == target_ptr->riding) ? CEM_RIDING : 0;
788 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], riding_mode))
791 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
793 if (g_ptr->dist == 0) continue;
794 if (g_ptr->dist > floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist + 2 * d) continue;
797 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x)) continue;
799 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
800 if (dis <= candidate.gdis) continue;
804 candidate.gdis = dis;
812 * @brief モンスターが隠れ潜める地点を返す /
813 * Choose a good hiding place near a monster for it to run toward.
814 * @param target_ptr プレーヤーへの参照ポインタ
815 * @param m_idx モンスターの参照ID
816 * @param yp 移動先のマスのY座標を返す参照ポインタ
817 * @param xp 移動先のマスのX座標を返す参照ポインタ
818 * @return 有効なマスがあった場合TRUEを返す
820 * Pack monsters will use this to "ambush" the player and lure him out\n
821 * of corridors into open space so they can swarm him.\n
823 * Return TRUE if a good location is available.\n
825 bool find_hiding(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
827 floor_type *floor_ptr = target_ptr->current_floor_ptr;
828 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
829 monster_race *r_ptr = &r_info[m_ptr->r_idx];
831 POSITION fy = m_ptr->fy;
832 POSITION fx = m_ptr->fx;
834 POSITION gy = 0, gx = 0, gdis = 999;
836 for (POSITION d = 1; d < 10; d++)
839 y_offsets = dist_offsets_y[d];
842 x_offsets = dist_offsets_x[d];
844 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
846 i++, dx = x_offsets[i], dy = y_offsets[i])
848 POSITION y = fy + dy;
849 POSITION x = fx + dx;
851 if (!in_bounds(floor_ptr, y, x)) continue;
852 if (!monster_can_enter(target_ptr, y, x, r_ptr, 0)) continue;
853 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, fy, fx, y, x, FALSE))
856 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
857 if (dis < gdis && dis >= 2)
865 if (gdis >= 999) continue;
878 * todo 分割したいが条件が多すぎて適切な関数名と詳細処理を追いきれない……
879 * @brief モンスターの移動方向を返す /
880 * Choose "logical" directions for monster movement
881 * @param target_ptr プレーヤーへの参照ポインタ
882 * @param m_idx モンスターの参照ID
883 * @param mm 移動方向を返す方向IDの参照ポインタ
884 * @return 有効方向があった場合TRUEを返す
886 static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
888 floor_type *floor_ptr = target_ptr->current_floor_ptr;
889 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
890 monster_race *r_ptr = &r_info[m_ptr->r_idx];
891 POSITION y = 0, ay, x = 0, ax;
892 POSITION y2 = target_ptr->y;
893 POSITION x2 = target_ptr->x;
895 bool will_run = mon_will_run(target_ptr, m_idx);
897 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) != 0) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2);
898 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) != 0) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall);
900 if (!will_run && m_ptr->target_y)
902 int t_m_idx = floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
904 are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[t_m_idx]) &&
905 los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
906 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
908 y = m_ptr->fy - m_ptr->target_y;
909 x = m_ptr->fx - m_ptr->target_x;
914 if (!done && !will_run && is_hostile(m_ptr) &&
915 (r_ptr->flags1 & RF1_FRIENDS) &&
916 ((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)) ||
917 (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
919 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
920 !(r_ptr->flags2 & RF2_KILL_WALL))
923 for (int i = 0; i < 8; i++)
925 int xx = target_ptr->x + ddx_ddd[i];
926 int yy = target_ptr->y + ddy_ddd[i];
928 if (!in_bounds2(floor_ptr, yy, xx)) continue;
930 g_ptr = &floor_ptr->grid_array[yy][xx];
931 if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0))
937 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].info & CAVE_ROOM) room -= 2;
938 if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
940 if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
941 (target_ptr->mhp + target_ptr->msp))
943 if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
947 if (!done && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
949 for (int i = 0; i < 8; i++)
951 y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
952 x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
953 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
960 if (!in_bounds2(floor_ptr, y2, x2)) continue;
961 if (!monster_can_enter(target_ptr, y2, x2, r_ptr, 0)) continue;
974 (void)get_moves_aux(target_ptr, m_idx, &y2, &x2, no_flow);
979 if (is_pet(m_ptr) && will_run)
985 if (!done && will_run)
989 if (find_safety(target_ptr, m_idx, &y, &x) && !no_flow)
991 if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x))
1003 if (!x && !y) return FALSE;
1009 if (y < 0) move_val += 8;
1010 if (x > 0) move_val += 4;
1012 if (ay > (ax << 1)) move_val += 2;
1013 else if (ax > (ay << 1)) move_val++;
1163 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
1165 return !have_flag(f_ptr->flags, FF_GLASS) ||
1166 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
1167 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
1172 * @brief モンスター単体の1ターン行動処理メインルーチン /
1174 * @param target_ptr プレーヤーへの参照ポインタ
1175 * @param m_idx 行動モンスターの参照ID
1178 * The monster is known to be within 100 grids of the player\n
1180 * In several cases, we directly update the monster lore\n
1182 * Note that a monster is only allowed to "reproduce" if there\n
1183 * are a limited number of "reproducing" monsters on the current\n
1184 * level. This should prevent the level from being "swamped" by\n
1185 * reproducing monsters. It also allows a large mass of mice to\n
1186 * prevent a louse from multiplying, but this is a small price to\n
1187 * pay for a simple multiplication method.\n
1189 * XXX Monster fear is slightly odd, in particular, monsters will\n
1190 * fixate on opening a door even if they cannot open it. Actually,\n
1191 * the same thing happens to normal monsters when they hit a door\n
1193 * In addition, monsters which *cannot* open or bash\n
1194 * down a door will still stand there trying to open it...\n
1196 * XXX Technically, need to check for monster in the way\n
1197 * combined with that monster being in a wall (or door?)\n
1199 * A "direction" of "5" means "pick a random direction".\n
1201 void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1203 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1204 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1205 turn_flags tmp_flags;
1206 turn_flags *turn_flags_ptr = init_turn_flags(target_ptr, m_idx, &tmp_flags);
1207 turn_flags_ptr->see_m = is_seen(m_ptr);
1209 decide_drop_from_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon);
1210 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
1212 choose_new_monster(target_ptr, m_idx, FALSE, 0);
1213 r_ptr = &r_info[m_ptr->r_idx];
1216 turn_flags_ptr->aware = process_stealth(target_ptr, m_idx);
1217 if (vanish_summoned_children(target_ptr, m_idx, turn_flags_ptr->see_m)) return;
1218 if (process_quantum_effect(target_ptr, m_idx, turn_flags_ptr->see_m)) return;
1219 if (explode_monster(target_ptr, m_idx)) return;
1220 if (runaway_monster(target_ptr, turn_flags_ptr, m_idx)) return;
1222 awake_monster(target_ptr, m_idx);
1223 if (MON_STUNNED(m_ptr))
1225 if (one_in_(2)) return;
1228 if (turn_flags_ptr->is_riding_mon)
1230 target_ptr->update |= (PU_BONUS);
1233 process_angar(target_ptr, m_idx, turn_flags_ptr->see_m);
1235 POSITION oy = m_ptr->fy;
1236 POSITION ox = m_ptr->fx;
1237 if (decide_monster_multiplication(target_ptr, m_idx, oy, ox)) return;
1239 process_special(target_ptr, m_idx);
1240 process_speak_sound(target_ptr, m_idx, oy, ox, turn_flags_ptr->aware);
1241 if (cast_spell(target_ptr, m_idx, turn_flags_ptr->aware)) return;
1244 mm[0] = mm[1] = mm[2] = mm[3] = 0;
1245 mm[4] = mm[5] = mm[6] = mm[7] = 0;
1247 if (!decide_monster_movement_direction(target_ptr, mm, m_idx, turn_flags_ptr->aware)) return;
1250 if (!process_monster_movement(target_ptr, turn_flags_ptr, m_idx, mm, oy, ox, &count)) return;
1253 * Forward movements failed, but now received LOS attack!
1254 * Try to flow by smell.
1256 if (target_ptr->no_flowed && count > 2 && m_ptr->target_y)
1257 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
1259 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)
1261 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
1263 if (make_attack_spell(m_idx, target_ptr)) return;
1267 update_player_type(target_ptr, turn_flags_ptr, r_ptr);
1268 update_monster_race_flags(target_ptr, turn_flags_ptr, m_ptr);
1270 if (!process_monster_fear(target_ptr, turn_flags_ptr, m_idx)) return;
1272 if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
1277 * @brief ターン経過フラグ構造体の初期化
1278 * @param target_ptr プレーヤーへの参照ポインタ
1279 * @param m_idx モンスターID
1280 * @return 初期化済のターン経過フラグ
1282 turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr)
1284 turn_flags_ptr->is_riding_mon = (m_idx == target_ptr->riding);
1285 turn_flags_ptr->do_turn = FALSE;
1286 turn_flags_ptr->do_move = FALSE;
1287 turn_flags_ptr->do_view = FALSE;
1288 turn_flags_ptr->must_alter_to_move = FALSE;
1289 turn_flags_ptr->did_open_door = FALSE;
1290 turn_flags_ptr->did_bash_door = FALSE;
1291 turn_flags_ptr->did_take_item = FALSE;
1292 turn_flags_ptr->did_kill_item = FALSE;
1293 turn_flags_ptr->did_move_body = FALSE;
1294 turn_flags_ptr->did_pass_wall = FALSE;
1295 turn_flags_ptr->did_kill_wall = FALSE;
1296 return turn_flags_ptr;
1302 * @param target_ptr プレーヤーへの参照ポインタ
1303 * @param m_idx モンスターID
1304 * @return モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1306 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx)
1308 if ((target_ptr->special_defense & NINJA_S_STEALTH) == 0) return TRUE;
1310 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1311 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1312 int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
1313 if (target_ptr->monlite) tmp /= 3;
1314 if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1315 if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
1316 return (randint0(tmp) <= (r_ptr->level + 20));
1321 * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
1322 * @param target_ptr プレーヤーへの参照ポインタ
1323 * @param m_idx モンスターID
1324 * @param is_riding_mon 騎乗中であればTRUE
1327 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
1329 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1330 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1331 if (!is_riding_mon || ((r_ptr->flags7 & RF7_RIDING) != 0)) return;
1333 if (rakuba(target_ptr, 0, TRUE))
1336 msg_print("地面に落とされた。");
1338 GAME_TEXT m_name[MAX_NLEN];
1339 monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
1340 msg_format("You have fallen from %s.", m_name);
1347 * @brief 召喚の親元が消滅した時、子供も消滅させる
1348 * @param target_ptr プレーヤーへの参照ポインタ
1349 * @param m_idx モンスターID
1350 * @param see_m モンスターが視界内にいたらTRUE
1351 * @return 召喚モンスターが消滅したらTRUE
1353 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1355 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1356 if ((m_ptr->parent_m_idx == 0) || (target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx > 0))
1361 GAME_TEXT m_name[MAX_NLEN];
1362 monster_desc(target_ptr, m_name, m_ptr, 0);
1363 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1366 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1368 GAME_TEXT m_name[MAX_NLEN];
1369 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
1370 exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
1373 delete_monster_idx(target_ptr, m_idx);
1379 * @brief 寝ているモンスターの起床を判定する
1380 * @param target_ptr プレーヤーへの参照ポインタ
1381 * @param m_idx モンスターID
1384 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1386 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1387 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1388 if (!MON_CSLEEP(m_ptr)) return;
1389 if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
1391 (void)set_monster_csleep(target_ptr, m_idx, 0);
1394 GAME_TEXT m_name[MAX_NLEN];
1395 monster_desc(target_ptr, m_name, m_ptr, 0);
1396 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
1399 if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
1407 * @brief モンスターの怒り状態を判定する (起こっていたら敵に回す)
1408 * @param target_ptr プレーヤーへの参照ポインタ
1409 * @param m_idx モンスターID
1410 * @param see_m モンスターが視界内にいたらTRUE
1413 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1415 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1416 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1417 bool gets_angry = FALSE;
1418 if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
1421 if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
1422 monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
1427 if (target_ptr->phase_out || !gets_angry) return;
1429 if (is_pet(m_ptr) || see_m)
1431 GAME_TEXT m_name[MAX_NLEN];
1432 monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
1433 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
1436 set_hostile(target_ptr, m_ptr);
1441 * @brief 量子生物の量子的効果を実行する
1442 * @param target_ptr プレーヤーへの参照ポインタ
1443 * @param m_idx モンスターID
1444 * @param see_m モンスターが視界内にいたらTRUE
1445 * @return モンスターが量子的効果により消滅したらTRUE
1447 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1449 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1450 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1451 if ((r_ptr->flags2 & RF2_QUANTUM) == 0) return FALSE;
1452 if (!randint0(2)) return FALSE;
1453 if (randint0((m_idx % 100) + 10)) return FALSE;
1455 bool can_disappear = (r_ptr->flags1 & RF1_UNIQUE) == 0;
1456 can_disappear &= (r_ptr->flags1 & RF1_QUESTOR) == 0;
1459 vanish_nonunique(target_ptr, m_idx, see_m);
1463 produce_quantum_effect(target_ptr, m_idx, see_m);
1469 * @brief ユニークでない量子生物を消滅させる
1470 * @param target_ptr プレーヤーへの参照ポインタ
1471 * @param m_idx モンスターID
1472 * @param see_m モンスターが視界内にいたらTRUE
1475 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1477 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1480 GAME_TEXT m_name[MAX_NLEN];
1481 monster_desc(target_ptr, m_name, m_ptr, 0);
1482 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1485 monster_death(target_ptr, m_idx, FALSE);
1486 delete_monster_idx(target_ptr, m_idx);
1487 if (is_pet(m_ptr) && !(m_ptr->ml))
1489 msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
1495 * @brief 量子生物ユニークの量子的効果 (ショート・テレポートまたは距離10のテレポート・アウェイ)を実行する
1496 * @param target_ptr プレーヤーへの参照ポインタ
1497 * @param m_idx モンスターID
1498 * @param see_m モンスターが視界内にいたらTRUE
1501 * プレーヤーが量子生物を観測しているか、量子生物がプレーヤーを観測している場合、互いの相対的な位置を確定させる
1502 * 波動関数の収縮はテレポートではないので反テレポート無効
1503 * todo パターンは収縮どころか拡散しているが、この際気にしてはいけない
1505 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1507 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1508 bool coherent = los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x);
1509 if (!see_m && !coherent) return;
1513 GAME_TEXT m_name[MAX_NLEN];
1514 monster_desc(target_ptr, m_name, m_ptr, 0);
1515 msg_format(_("%sは量子的効果を起こした!", "%^s produced a decoherence!"), m_name);
1519 msg_print(_("量子的効果が起こった!", "A decoherence was produced!"));
1522 bool target = one_in_(2);
1523 const int blink = 32 * 5 + 4;
1526 (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx);
1530 teleport_player_away(m_idx, target_ptr, 10, TRUE);
1537 * @param target_ptr プレーヤーへの参照ポインタ
1538 * @param m_idx モンスターID
1541 bool explode_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1543 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1544 if (m_ptr->r_idx != MON_SHURYUUDAN) return FALSE;
1547 mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
1553 * @brief モンスター依存の特別な行動を取らせる
1554 * @param target_ptr プレーヤーへの参照ポインタ
1555 * @param m_idx モンスターID
1558 void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
1560 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1561 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1562 if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
1563 if (m_ptr->r_idx != MON_OHMU) return;
1564 if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
1565 if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
1568 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1569 BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
1571 for (int k = 0; k < A_MAX; k++)
1573 if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
1575 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
1579 if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
1584 * @brief モンスターを喋らせたり足音を立てたりする
1585 * @param target_ptr プレーヤーへの参照ポインタ
1586 * @param m_idx モンスターID
1587 * @param oy モンスターが元々いたY座標
1588 * @param ox モンスターが元々いたX座標
1589 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1592 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware)
1594 if (target_ptr->phase_out) return;
1596 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1597 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1598 if (m_ptr->ap_r_idx == MON_CYBER &&
1599 one_in_(CYBERNOISE) &&
1600 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
1602 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
1603 msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
1606 if (((ap_r_ptr->flags2 & RF2_CAN_SPEAK) == 0) || !aware ||
1607 !one_in_(SPEAK_CHANCE) ||
1608 !player_has_los_bold(target_ptr, oy, ox) ||
1609 !projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
1612 GAME_TEXT m_name[MAX_NLEN];
1613 char monmessage[1024];
1617 monster_desc(target_ptr, m_name, m_ptr, 0);
1619 strcpy(m_name, _("それ", "It"));
1621 if (MON_MONFEAR(m_ptr))
1622 filename = _("monfear_j.txt", "monfear.txt");
1623 else if (is_pet(m_ptr))
1624 filename = _("monpet_j.txt", "monpet.txt");
1625 else if (is_friendly(m_ptr))
1626 filename = _("monfrien_j.txt", "monfrien.txt");
1628 filename = _("monspeak_j.txt", "monspeak.txt");
1630 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
1632 msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
1638 * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
1639 * @param target_ptr プレーヤーへの参照ポインタ
1640 * @param m_idx モンスターID
1641 * @param oy 分裂元モンスターのY座標
1642 * @param ox 分裂元モンスターのX座標
1643 * @return 実際に分裂したらTRUEを返す
1645 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
1647 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1648 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1649 if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) || (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
1653 for (POSITION y = oy - 1; y <= oy + 1; y++)
1655 for (POSITION x = ox - 1; x <= ox + 1; x++)
1657 if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
1658 if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
1662 if (multiply_barrier(target_ptr, m_idx)) k = 8;
1664 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
1666 if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
1668 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
1670 r_ptr->r_flags2 |= (RF2_MULTIPLY);
1682 * @brief モンスターの移動パターンを決定する
1683 * @param target_ptr プレーヤーへの参照ポインタ
1685 * @param m_idx モンスターID
1686 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1687 * @return 移動先が存在すればTRUE
1689 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware)
1691 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1692 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1694 if (MON_CONFUSED(m_ptr) || !aware)
1696 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1700 if (random_walk(target_ptr, mm, m_ptr)) return TRUE;
1702 if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
1704 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1708 if (decide_pet_movement_direction(target_ptr, mm, m_idx)) return TRUE;
1710 if (!is_hostile(m_ptr))
1712 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1713 get_enemy_dir(target_ptr, m_idx, mm);
1717 if (!get_moves(target_ptr, m_idx, mm)) return FALSE;
1724 * todo ↓のように書いたが、"5"とはもしかして「その場に留まる」という意味か?
1725 * @brief 不規則歩行フラグを持つモンスターの移動方向をその確率に基づいて決定する
1726 * @param target_ptr プレーヤーへの参照ポインタ
1728 * @param m_ptr モンスターへの参照ポインタ
1729 * @return 不規則な方向へ歩くことになったらTRUE
1731 bool random_walk(player_type *target_ptr, DIRECTION *mm, monster_type *m_ptr)
1733 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1734 if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) && (randint0(100) < 75))
1736 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
1738 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1742 if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 50))
1744 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_50;
1746 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1750 if ((r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 25))
1752 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
1754 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1763 * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
1764 * @param target_ptr プレーヤーへの参照ポインタ
1766 * @param m_idx モンスターID
1767 * @return モンスターがペットであればTRUE
1769 bool decide_pet_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx)
1771 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1772 if (!is_pet(m_ptr)) return FALSE;
1774 bool avoid = ((target_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
1775 bool lonely = (!avoid && (m_ptr->cdis > target_ptr->pet_follow_distance));
1776 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
1777 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1778 if (get_enemy_dir(target_ptr, m_idx, mm)) return TRUE;
1779 if (!avoid && !lonely && !distant) return TRUE;
1781 POSITION dis = target_ptr->pet_follow_distance;
1782 if (target_ptr->pet_follow_distance > PET_SEEK_DIST)
1784 target_ptr->pet_follow_distance = PET_SEEK_DIST;
1787 (void)get_moves(target_ptr, m_idx, mm);
1788 target_ptr->pet_follow_distance = (s16b)dis;
1794 * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
1795 * @param target_ptr プレーヤーへの参照ポインタ
1796 * @param m_idx モンスターID
1797 * @param is_riding_mon 騎乗状態ならばTRUE
1798 * @param see_m モンスターが視界内にいたらTRUE
1799 * @return モンスターがフロアから消えたらTRUE
1801 bool runaway_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
1803 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1804 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1805 bool can_runaway = is_pet(m_ptr) || is_friendly(m_ptr);
1806 can_runaway &= ((r_ptr->flags1 & RF1_UNIQUE) != 0) || ((r_ptr->flags7 & RF7_NAZGUL) != 0);
1807 can_runaway &= !target_ptr->phase_out;
1808 if (!can_runaway) return FALSE;
1810 static int riding_pinch = 0;
1812 if (m_ptr->hp >= m_ptr->maxhp / 3)
1814 /* Reset the counter */
1815 if (turn_flags_ptr->is_riding_mon) riding_pinch = 0;
1820 GAME_TEXT m_name[MAX_NLEN];
1821 monster_desc(target_ptr, m_name, m_ptr, 0);
1822 if (turn_flags_ptr->is_riding_mon && riding_pinch < 2)
1824 msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
1825 "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
1827 disturb(target_ptr, TRUE, TRUE);
1831 escape_monster(target_ptr, turn_flags_ptr, m_ptr, m_name);
1832 check_quest_completion(target_ptr, m_ptr);
1833 delete_monster_idx(target_ptr, m_idx);
1839 * @brief HPが1/3未満になった有効的なユニークモンスターの逃走処理を行う
1840 * @param target_ptr プレーヤーへの参照ポインタ
1841 * @param is_riding_mon 騎乗状態ならばTRUE
1842 * @param m_ptr モンスターへの参照ポインタ
1843 * @param m_name モンスター名称
1844 * @param see_m モンスターが視界内にいたらTRUE
1847 void escape_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, GAME_TEXT *m_name)
1849 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1850 if (turn_flags_ptr->is_riding_mon)
1852 msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
1853 if (rakuba(target_ptr, -1, FALSE))
1855 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1859 if (turn_flags_ptr->see_m)
1861 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) &&
1862 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))
1864 msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
1867 msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s reads a scroll of teleport level."), m_name);
1868 msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
1871 if (turn_flags_ptr->is_riding_mon && rakuba(target_ptr, -1, FALSE))
1873 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1879 * @brief モンスターに魔法を試行させる
1880 * @param target_ptr プレーヤーへの参照ポインタ
1881 * @param m_idx モンスターID
1882 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1883 * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
1885 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware)
1887 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1888 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1889 if ((r_ptr->freq_spell == 0) || (randint1(100) > r_ptr->freq_spell))
1892 bool counterattack = FALSE;
1893 if (m_ptr->target_y)
1895 MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
1896 if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
1897 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1899 counterattack = TRUE;
1905 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1906 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1910 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1911 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1919 * todo 少し長いが、これといってブロックとしてまとまった部分もないので暫定でこのままとする
1920 * @brief モンスターの移動に関するメインルーチン
1921 * @param target_ptr プレーヤーへの参照ポインタ
1922 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
1923 * @param m_idx モンスターID
1924 * @param mm モンスターの移動方向
1925 * @param oy 移動前の、モンスターのY座標
1926 * @param ox 移動前の、モンスターのX座標
1927 * @param count 移動回数 (のはず todo)
1928 * @return 移動が阻害される何か (ドア等)があったらFALSE
1930 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)
1932 for (int i = 0; mm[i]; i++)
1935 if (d == 5) d = ddd[randint0(8)];
1937 POSITION ny = oy + ddy[d];
1938 POSITION nx = ox + ddx[d];
1939 if (!in_bounds2(target_ptr->current_floor_ptr, ny, nx)) continue;
1942 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1943 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1944 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1945 bool can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0);
1947 if (!process_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx, can_cross))
1949 if (!process_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1953 if (!process_protection_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1955 if (!process_explosive_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1959 exe_monster_attack_to_player(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1960 if (process_monster_attack_to_monster(target_ptr, turn_flags_ptr, m_idx, g_ptr, can_cross)) return FALSE;
1962 if (turn_flags_ptr->is_riding_mon)
1964 if (!target_ptr->riding_ryoute && !MON_MONFEAR(&target_ptr->current_floor_ptr->m_list[target_ptr->riding])) turn_flags_ptr->do_move = FALSE;
1967 if (!process_post_dig_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx)) return FALSE;
1969 if (turn_flags_ptr->must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
1971 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0))
1972 turn_flags_ptr->do_move = FALSE;
1975 if (turn_flags_ptr->do_move && !can_cross && !turn_flags_ptr->did_kill_wall && !turn_flags_ptr->did_bash_door)
1976 turn_flags_ptr->do_move = FALSE;
1978 if (turn_flags_ptr->do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
1980 if (is_original_ap_and_seen(target_ptr, m_ptr))
1981 r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
1983 turn_flags_ptr->do_move = FALSE;
1986 if (!turn_flags_ptr->do_move)
1988 if (turn_flags_ptr->do_turn) break;
1993 turn_flags_ptr->do_turn = TRUE;
1994 feature_type *f_ptr;
1995 f_ptr = &f_info[g_ptr->feat];
1996 if (have_flag(f_ptr->flags, FF_TREE))
1998 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
2000 m_ptr->energy_need += ENERGY_NEED();
2004 if (!update_riding_monster(target_ptr, turn_flags_ptr, m_idx, oy, ox, ny, nx)) break;
2006 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2009 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
2010 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= target_ptr->lev)))
2012 if (is_hostile(m_ptr))
2013 disturb(target_ptr, FALSE, TRUE);
2016 bool is_takable_or_killable = g_ptr->o_idx > 0;
2017 is_takable_or_killable &= (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) != 0;
2019 bool is_pickup_items = (target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
2020 is_pickup_items &= (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
2022 is_takable_or_killable &= !is_pet(m_ptr) || is_pickup_items;
2023 if (!is_takable_or_killable)
2025 if (turn_flags_ptr->do_turn) break;
2030 update_object_by_monster_movement(target_ptr, turn_flags_ptr, m_idx, ny, nx);
2031 if (turn_flags_ptr->do_turn) break;
2041 * @brief モンスターによる壁の透過・破壊を行う
2042 * @param target_ptr プレーヤーへの参照ポインタ
2043 * @param m_ptr モンスターへの参照ポインタ
2044 * @param ny モンスターのY座標
2045 * @param nx モンスターのX座標
2046 * @param can_cross モンスターが地形を踏破できるならばTRUE
2047 * @return 透過も破壊もしなかった場合はFALSE、それ以外はTRUE
2049 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross)
2051 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2053 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2054 feature_type *f_ptr;
2055 f_ptr = &f_info[g_ptr->feat];
2056 if (player_bold(target_ptr, ny, nx))
2058 turn_flags_ptr->do_move = TRUE;
2062 if (g_ptr->m_idx > 0)
2064 turn_flags_ptr->do_move = TRUE;
2068 if (((r_ptr->flags2 & RF2_KILL_WALL) != 0) &&
2069 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !turn_flags_ptr->is_riding_mon) &&
2070 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
2071 check_hp_for_feat_destruction(f_ptr, m_ptr))
2073 turn_flags_ptr->do_move = TRUE;
2074 if (!can_cross) turn_flags_ptr->must_alter_to_move = TRUE;
2076 turn_flags_ptr->did_kill_wall = TRUE;
2080 if (!can_cross) return FALSE;
2082 turn_flags_ptr->do_move = TRUE;
2083 if (((r_ptr->flags2 & RF2_PASS_WALL) != 0) && (!turn_flags_ptr->is_riding_mon || target_ptr->pass_wall) &&
2084 have_flag(f_ptr->flags, FF_CAN_PASS))
2086 turn_flags_ptr->did_pass_wall = TRUE;
2094 * @brief モンスターによるドアの開放・破壊を行う
2095 * @param target_ptr プレーヤーへの参照ポインタ
2096 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2097 * @param m_ptr モンスターへの参照ポインタ
2098 * @param ny モンスターのY座標
2099 * @param nx モンスターのX座標
2100 * @return モンスターが死亡した場合のみFALSE
2102 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2104 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2106 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2107 if (!is_closed_door(target_ptr, g_ptr->feat)) return TRUE;
2109 feature_type *f_ptr;
2110 f_ptr = &f_info[g_ptr->feat];
2111 bool may_bash = bash_normal_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx);
2112 bash_glass_door(target_ptr, turn_flags_ptr, m_ptr, f_ptr, may_bash);
2114 if (!turn_flags_ptr->did_open_door && !turn_flags_ptr->did_bash_door) return TRUE;
2116 if (turn_flags_ptr->did_bash_door &&
2117 ((randint0(100) < 50) || (feat_state(target_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
2119 cave_alter_feat(target_ptr, ny, nx, FF_BASH);
2120 if (!monster_is_valid(m_ptr))
2122 target_ptr->update |= (PU_FLOW);
2123 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2124 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2131 cave_alter_feat(target_ptr, ny, nx, FF_OPEN);
2134 f_ptr = &f_info[g_ptr->feat];
2135 turn_flags_ptr->do_view = TRUE;
2141 * @brief モンスターが普通のドアを開ける処理
2142 * @param target_ptr プレーヤーへの参照ポインタ
2143 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2144 * @param m_ptr モンスターへの参照ポインタ
2145 * @param ny モンスターのY座標
2146 * @param nx モンスターのX座標
2147 * @return ここではドアを開けず、ガラスのドアを開ける可能性があるならTRUE
2149 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2151 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2153 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2154 feature_type *f_ptr;
2155 f_ptr = &f_info[g_ptr->feat];
2156 turn_flags_ptr->do_move = FALSE;
2157 if (((r_ptr->flags2 & RF2_OPEN_DOOR) == 0) || !have_flag(f_ptr->flags, FF_OPEN) ||
2158 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2161 if (f_ptr->power == 0)
2163 turn_flags_ptr->did_open_door = TRUE;
2164 turn_flags_ptr->do_turn = TRUE;
2168 if (randint0(m_ptr->hp / 10) > f_ptr->power)
2170 cave_alter_feat(target_ptr, ny, nx, FF_DISARM);
2171 turn_flags_ptr->do_turn = TRUE;
2180 * @brief モンスターがガラスのドアを開ける処理
2181 * @param target_ptr プレーヤーへの参照ポインタ
2182 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2183 * @param m_ptr モンスターへの参照ポインタ
2184 * @param g_ptr グリッドへの参照ポインタ
2185 * @param f_ptr 地形への参照ポインタ
2188 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash)
2190 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2191 if (!may_bash || ((r_ptr->flags2 & RF2_BASH_DOOR) == 0) || !have_flag(f_ptr->flags, FF_BASH) ||
2192 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2195 if (!check_hp_for_feat_destruction(f_ptr, m_ptr) || (randint0(m_ptr->hp / 10) <= f_ptr->power))
2198 if (have_flag(f_ptr->flags, FF_GLASS))
2199 msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
2201 msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
2203 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
2205 turn_flags_ptr->did_bash_door = TRUE;
2206 turn_flags_ptr->do_move = TRUE;
2207 turn_flags_ptr->must_alter_to_move = TRUE;
2212 * @brief 守りのルーンによるモンスターの移動制限を処理する
2213 * @param target_ptr プレーヤーへの参照ポインタ
2214 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2215 * @param m_ptr モンスターへの参照ポインタ
2216 * @param ny モンスターのY座標
2217 * @param nx モンスターのX座標
2220 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2223 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2224 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2225 if (!turn_flags_ptr->do_move || !is_glyph_grid(g_ptr) ||
2226 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2229 turn_flags_ptr->do_move = FALSE;
2230 if (is_pet(m_ptr) || (randint1(BREAK_GLYPH) >= r_ptr->level))
2233 if (g_ptr->info & CAVE_MARK)
2235 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2238 g_ptr->info &= ~(CAVE_MARK);
2239 g_ptr->info &= ~(CAVE_OBJECT);
2241 turn_flags_ptr->do_move = TRUE;
2242 note_spot(target_ptr, ny, nx);
2248 * @brief 爆発のルーンにを処理する
2249 * @param target_ptr プレーヤーへの参照ポインタ
2250 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2251 * @param m_ptr モンスターへの参照ポインタ
2252 * @param ny モンスターのY座標
2253 * @param nx モンスターのX座標
2254 * @return モンスターが死亡した場合のみFALSE
2256 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2259 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2260 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2261 if (!turn_flags_ptr->do_move || !is_explosive_rune_grid(g_ptr) ||
2262 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2265 turn_flags_ptr->do_move = FALSE;
2266 if (is_pet(m_ptr)) return TRUE;
2268 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2270 if (g_ptr->info & CAVE_MARK)
2272 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2273 BIT_FLAGS project_flags = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI;
2274 project(target_ptr, 0, 2, ny, nx, 2 * (target_ptr->lev + damroll(7, 7)), GF_MANA, project_flags, -1);
2279 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2282 g_ptr->info &= ~(CAVE_MARK);
2283 g_ptr->info &= ~(CAVE_OBJECT);
2286 note_spot(target_ptr, ny, nx);
2287 lite_spot(target_ptr, ny, nx);
2289 if (!monster_is_valid(m_ptr)) return FALSE;
2291 turn_flags_ptr->do_move = TRUE;
2297 * @brief モンスターが移動した結果、そこにプレーヤーがいたら直接攻撃を行う
2298 * @param target_ptr プレーヤーへの参照ポインタ
2299 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2300 * @param m_idx モンスターID
2301 * @param ny 移動後の、モンスターのY座標
2302 * @param nx 移動後の、モンスターのX座標
2305 * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
2307 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2309 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2310 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2311 if (!turn_flags_ptr->do_move || !player_bold(target_ptr, ny, nx))
2314 if (r_ptr->flags1 & RF1_NEVER_BLOW)
2316 if (is_original_ap_and_seen(target_ptr, m_ptr))
2317 r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
2319 turn_flags_ptr->do_move = FALSE;
2322 if (turn_flags_ptr->do_move && ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) != 0) && !MON_CONFUSED(m_ptr))
2324 if (!(r_ptr->flags2 & RF2_STUPID))
2325 turn_flags_ptr->do_move = FALSE;
2326 else if (is_original_ap_and_seen(target_ptr, m_ptr))
2327 r_ptr->r_flags2 |= (RF2_STUPID);
2330 if (!turn_flags_ptr->do_move) return;
2332 if (!target_ptr->riding || one_in_(2))
2334 (void)make_attack_normal(target_ptr, m_idx);
2335 turn_flags_ptr->do_move = FALSE;
2336 turn_flags_ptr->do_turn = TRUE;
2342 * @brief モンスターからモンスターへの攻撃処理
2343 * @param target_ptr プレーヤーへの参照ポインタ
2344 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2345 * @param m_idx モンスターID
2346 * @param g_ptr グリッドへの参照ポインタ
2347 * @param can_cross モンスターが地形を踏破できるならばTRUE
2348 * @return ターン消費が発生したらTRUE
2350 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)
2352 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2353 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2354 monster_type *y_ptr;
2355 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2356 if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) return FALSE;
2358 monster_race *z_ptr = &r_info[y_ptr->r_idx];
2359 turn_flags_ptr->do_move = FALSE;
2360 if ((((r_ptr->flags2 & RF2_KILL_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_BLOW) == 0) &&
2361 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
2362 can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
2363 are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
2365 return exe_monster_attack_to_monster(target_ptr, m_idx, g_ptr);
2368 if (((r_ptr->flags2 & RF2_MOVE_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_MOVE) == 0) &&
2369 (r_ptr->mexp > z_ptr->mexp) &&
2370 can_cross && (g_ptr->m_idx != target_ptr->riding) &&
2371 monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
2373 turn_flags_ptr->do_move = TRUE;
2374 turn_flags_ptr->did_move_body = TRUE;
2375 (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
2383 * @brief モンスターからモンスターへの直接攻撃を実行する
2384 * @param target_ptr プレーヤーへの参照ポインタ
2385 * @param m_idx モンスターID
2386 * @param g_ptr グリッドへの参照ポインタ
2388 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr)
2390 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2391 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2392 monster_type *y_ptr;
2393 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2394 if ((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) return FALSE;
2396 if (((r_ptr->flags2 & RF2_KILL_BODY) == 0) && is_original_ap_and_seen(target_ptr, m_ptr))
2397 r_ptr->r_flags2 |= (RF2_KILL_BODY);
2399 if ((y_ptr->r_idx == 0) || (y_ptr->hp < 0)) return FALSE;
2400 if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return TRUE;
2401 if ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) == 0) return FALSE;
2402 if (MON_CONFUSED(m_ptr)) return TRUE;
2403 if ((r_ptr->flags2 & RF2_STUPID) == 0) return FALSE;
2405 if (is_original_ap_and_seen(target_ptr, m_ptr))
2406 r_ptr->r_flags2 |= (RF2_STUPID);
2413 * @brief モンスターが壁を掘った後続処理を実行する
2414 * @param target_ptr プレーヤーへの参照ポインタ
2415 * @turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2416 * @param m_ptr モンスターへの参照ポインタ
2417 * @param ny モンスターのY座標
2418 * @param nx モンスターのX座標
2419 * @return モンスターが死亡した場合のみFALSE
2421 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2423 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2425 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2426 feature_type *f_ptr;
2427 f_ptr = &f_info[g_ptr->feat];
2428 if (!turn_flags_ptr->did_kill_wall || !turn_flags_ptr->do_move) return TRUE;
2430 if (one_in_(GRINDNOISE))
2432 if (have_flag(f_ptr->flags, FF_GLASS))
2433 msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
2435 msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
2438 cave_alter_feat(target_ptr, ny, nx, FF_HURT_DISI);
2440 if (!monster_is_valid(m_ptr))
2442 target_ptr->update |= (PU_FLOW);
2443 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2444 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2449 f_ptr = &f_info[g_ptr->feat];
2450 turn_flags_ptr->do_view = TRUE;
2451 turn_flags_ptr->do_turn = TRUE;
2457 * @brief 騎乗中のモンスター情報を更新する
2458 * @param target_ptr プレーヤーへの参照ポインタ
2459 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2460 * @param m_idx モンスターID
2461 * @param oy 移動前の、モンスターのY座標
2462 * @param ox 移動前の、モンスターのX座標
2463 * @param ny 移動後の、モンスターのY座標
2464 * @param ox 移動後の、モンスターのX座標
2465 * @return アイテム等に影響を及ぼしたらTRUE
2467 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)
2469 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2471 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2472 monster_type *y_ptr;
2473 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2474 if (turn_flags_ptr->is_riding_mon)
2475 return move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP);
2477 target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
2482 update_monster(target_ptr, g_ptr->m_idx, TRUE);
2485 g_ptr->m_idx = m_idx;
2488 update_monster(target_ptr, m_idx, TRUE);
2490 lite_spot(target_ptr, oy, ox);
2491 lite_spot(target_ptr, ny, nx);
2497 * @brief モンスターの移動に伴うオブジェクト処理 (アイテム破壊等)
2498 * @param target_ptr プレーヤーへの参照ポインタ
2499 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2500 * @param m_idx モンスターID
2501 * @param ny 移動後の、モンスターのY座標
2502 * @param nx 移動後の、モンスターのX座標
2504 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2506 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2507 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2509 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2511 OBJECT_IDX this_o_idx, next_o_idx;
2512 turn_flags_ptr->do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
2513 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2515 BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
2516 GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
2517 object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
2518 next_o_idx = o_ptr->next_o_idx;
2520 if (turn_flags_ptr->do_take)
2522 /* Skip gold, corpse and statue */
2523 if (o_ptr->tval == TV_GOLD || (o_ptr->tval == TV_CORPSE) || (o_ptr->tval == TV_STATUE))
2527 object_flags(o_ptr, flgs);
2528 object_desc(target_ptr, o_name, o_ptr, 0);
2529 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
2530 update_object_flags(flgs, &flg2, &flg3, &flgr);
2532 bool is_special_object = object_is_artifact(o_ptr) ||
2533 ((r_ptr->flags3 & flg3) != 0) ||
2534 ((r_ptr->flags2 & flg2) != 0) ||
2535 (((~(r_ptr->flagsr) & flgr) != 0) && !(r_ptr->flagsr & RFR_RES_ALL));
2536 monster_pickup_object(target_ptr, turn_flags_ptr, m_idx, o_ptr, is_special_object, ny, nx, m_name, o_name, this_o_idx);
2542 * @brief オブジェクトのフラグを更新する
2544 void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr)
2546 if (have_flag(flgs, TR_SLAY_DRAGON)) *flg3 |= (RF3_DRAGON);
2547 if (have_flag(flgs, TR_KILL_DRAGON)) *flg3 |= (RF3_DRAGON);
2548 if (have_flag(flgs, TR_SLAY_TROLL)) *flg3 |= (RF3_TROLL);
2549 if (have_flag(flgs, TR_KILL_TROLL)) *flg3 |= (RF3_TROLL);
2550 if (have_flag(flgs, TR_SLAY_GIANT)) *flg3 |= (RF3_GIANT);
2551 if (have_flag(flgs, TR_KILL_GIANT)) *flg3 |= (RF3_GIANT);
2552 if (have_flag(flgs, TR_SLAY_ORC)) *flg3 |= (RF3_ORC);
2553 if (have_flag(flgs, TR_KILL_ORC)) *flg3 |= (RF3_ORC);
2554 if (have_flag(flgs, TR_SLAY_DEMON)) *flg3 |= (RF3_DEMON);
2555 if (have_flag(flgs, TR_KILL_DEMON)) *flg3 |= (RF3_DEMON);
2556 if (have_flag(flgs, TR_SLAY_UNDEAD)) *flg3 |= (RF3_UNDEAD);
2557 if (have_flag(flgs, TR_KILL_UNDEAD)) *flg3 |= (RF3_UNDEAD);
2558 if (have_flag(flgs, TR_SLAY_ANIMAL)) *flg3 |= (RF3_ANIMAL);
2559 if (have_flag(flgs, TR_KILL_ANIMAL)) *flg3 |= (RF3_ANIMAL);
2560 if (have_flag(flgs, TR_SLAY_EVIL)) *flg3 |= (RF3_EVIL);
2561 if (have_flag(flgs, TR_KILL_EVIL)) *flg3 |= (RF3_EVIL);
2562 if (have_flag(flgs, TR_SLAY_HUMAN)) *flg2 |= (RF2_HUMAN);
2563 if (have_flag(flgs, TR_KILL_HUMAN)) *flg2 |= (RF2_HUMAN);
2564 if (have_flag(flgs, TR_BRAND_ACID)) *flgr |= (RFR_IM_ACID);
2565 if (have_flag(flgs, TR_BRAND_ELEC)) *flgr |= (RFR_IM_ELEC);
2566 if (have_flag(flgs, TR_BRAND_FIRE)) *flgr |= (RFR_IM_FIRE);
2567 if (have_flag(flgs, TR_BRAND_COLD)) *flgr |= (RFR_IM_COLD);
2568 if (have_flag(flgs, TR_BRAND_POIS)) *flgr |= (RFR_IM_POIS);
2573 * @brief モンスターがアイテムを拾うか壊す処理
2574 * @param target_ptr プレーヤーへの参照ポインタ
2575 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2576 * @param m_idx モンスターID
2577 * @param o_ptr オブジェクトへの参照ポインタ
2578 * @param is_special_object モンスターが拾えないアイテム (アーティファクト等)であればTRUE
2579 * @param ny 移動後の、モンスターのY座標
2580 * @param nx 移動後の、モンスターのX座標
2581 * @param m_name モンスター名
2582 * @param o_name アイテム名
2583 * @param this_o_idx モンスターが乗ったオブジェクトID
2586 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)
2588 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2589 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2590 if (is_special_object)
2592 if (turn_flags_ptr->do_take && (r_ptr->flags2 & RF2_STUPID))
2594 turn_flags_ptr->did_take_item = TRUE;
2595 if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
2597 msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
2604 if (turn_flags_ptr->do_take)
2606 turn_flags_ptr->did_take_item = TRUE;
2607 if (player_can_see_bold(target_ptr, ny, nx))
2609 msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
2612 excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
2613 o_ptr->marked &= OM_TOUCHED;
2614 o_ptr->iy = o_ptr->ix = 0;
2615 o_ptr->held_m_idx = m_idx;
2616 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2617 m_ptr->hold_o_idx = this_o_idx;
2621 if (is_pet(m_ptr)) return;
2623 turn_flags_ptr->did_kill_item = TRUE;
2624 if (player_has_los_bold(target_ptr, ny, nx))
2626 msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
2629 delete_object_idx(target_ptr, this_o_idx);
2634 * @brief updateフィールドを更新する
2635 * @param target_ptr プレーヤーへの参照ポインタ
2636 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2639 void update_player_type(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_race *r_ptr)
2641 if (turn_flags_ptr->do_view)
2643 target_ptr->update |= (PU_FLOW);
2644 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2647 if (turn_flags_ptr->do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
2648 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !target_ptr->phase_out)))
2650 target_ptr->update |= (PU_MON_LITE);
2656 * @brief モンスターのフラグを更新する
2657 * @param target_ptr プレーヤーへの参照ポインタ
2658 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2659 * @param m_ptr モンスターへの参照ポインタ
2662 void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr)
2664 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2665 if (!is_original_ap_and_seen(target_ptr, m_ptr)) return;
2667 if (turn_flags_ptr->did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
2668 if (turn_flags_ptr->did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2669 if (turn_flags_ptr->did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
2670 if (turn_flags_ptr->did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
2671 if (turn_flags_ptr->did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
2672 if (turn_flags_ptr->did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
2673 if (turn_flags_ptr->did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2678 * @brief モンスターの恐怖状態を処理する
2679 * @param target_ptr プレーヤーへの参照ポインタ
2680 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2681 * @param m_idx モンスターID
2682 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
2683 * @return モンスターが戦いを決意したらTRUE
2685 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
2687 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2688 bool is_battle_determined = !turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && MON_MONFEAR(m_ptr) && turn_flags_ptr->aware;
2689 if (!is_battle_determined) return FALSE;
2691 (void)set_monster_monfear(target_ptr, m_idx, 0);
2692 if (!turn_flags_ptr->see_m) return TRUE;
2694 GAME_TEXT m_name[MAX_NLEN];
2695 monster_desc(target_ptr, m_name, m_ptr, 0);
2696 msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
2702 * @brief 全モンスターのターン管理メインルーチン /
2703 * Process all the "live" monsters, once per game turn.
2706 * During each game current game turn, we scan through the list of all the "live" monsters,\n
2707 * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
2708 * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
2710 * Note that monsters can never move in the monster array (except when the\n
2711 * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
2713 * This function is responsible for at least half of the processor time\n
2714 * on a normal system with a "normal" amount of monsters and a player doing\n
2717 * When the player is resting, virtually 90% of the processor time is spent\n
2718 * in this function, and its children, "process_monster()" and "make_move()".\n
2720 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
2721 * especially when the player is running.\n
2723 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
2724 * monsters while they are still being "born". A monster is "fresh" only\n
2725 * during the game turn in which it is created, and we use the "hack_m_idx" to\n
2726 * determine if the monster is yet to be processed during the game turn.\n
2728 * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
2729 * move before any "nasty" monsters get to use their spell attacks.\n
2731 * Note that when the "knowledge" about the currently tracked monster\n
2732 * changes (flags, attacks, spells), we induce a redraw of the monster\n
2735 void process_monsters(player_type *target_ptr)
2737 old_race_flags tmp_flags;
2738 old_race_flags *old_race_flags_ptr = init_old_race_flags(&tmp_flags);
2740 floor_type *floor_ptr = target_ptr->current_floor_ptr;
2741 floor_ptr->monster_noise = FALSE;
2743 MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
2744 save_old_race_flags(target_ptr, old_race_flags_ptr);
2745 sweep_monster_process(target_ptr);
2748 if (!target_ptr->monster_race_idx || (target_ptr->monster_race_idx != old_monster_race_idx))
2751 update_player_window(target_ptr, old_race_flags_ptr);
2756 * @brief old_race_flags_ptr の初期化
2758 old_race_flags *init_old_race_flags(old_race_flags *old_race_flags_ptr)
2760 old_race_flags_ptr->old_r_flags1 = 0L;
2761 old_race_flags_ptr->old_r_flags2 = 0L;
2762 old_race_flags_ptr->old_r_flags3 = 0L;
2763 old_race_flags_ptr->old_r_flags4 = 0L;
2764 old_race_flags_ptr->old_r_flags5 = 0L;
2765 old_race_flags_ptr->old_r_flags6 = 0L;
2766 old_race_flags_ptr->old_r_flagsr = 0L;
2768 old_race_flags_ptr->old_r_blows0 = 0;
2769 old_race_flags_ptr->old_r_blows1 = 0;
2770 old_race_flags_ptr->old_r_blows2 = 0;
2771 old_race_flags_ptr->old_r_blows3 = 0;
2773 old_race_flags_ptr->old_r_cast_spell = 0;
2774 return old_race_flags_ptr;
2779 * @brief 古いモンスター情報の保存
2780 * @param target_ptr プレーヤーへの参照ポインタ
2781 * @param old_race_flags_ptr モンスターフラグへの参照ポインタ
2784 void save_old_race_flags(player_type *target_ptr, old_race_flags *old_race_flags_ptr)
2786 if (target_ptr->monster_race_idx == 0) return;
2788 monster_race *r_ptr;
2789 r_ptr = &r_info[target_ptr->monster_race_idx];
2791 old_race_flags_ptr->old_r_flags1 = r_ptr->r_flags1;
2792 old_race_flags_ptr->old_r_flags2 = r_ptr->r_flags2;
2793 old_race_flags_ptr->old_r_flags3 = r_ptr->r_flags3;
2794 old_race_flags_ptr->old_r_flags4 = r_ptr->r_flags4;
2795 old_race_flags_ptr->old_r_flags5 = r_ptr->r_flags5;
2796 old_race_flags_ptr->old_r_flags6 = r_ptr->r_flags6;
2797 old_race_flags_ptr->old_r_flagsr = r_ptr->r_flagsr;
2799 old_race_flags_ptr->old_r_blows0 = r_ptr->r_blows[0];
2800 old_race_flags_ptr->old_r_blows1 = r_ptr->r_blows[1];
2801 old_race_flags_ptr->old_r_blows2 = r_ptr->r_blows[2];
2802 old_race_flags_ptr->old_r_blows3 = r_ptr->r_blows[3];
2804 old_race_flags_ptr->old_r_cast_spell = r_ptr->r_cast_spell;
2809 * @brief フロア内のモンスターについてターン終了時の処理を繰り返す
2810 * @param target_ptr プレーヤーへの参照ポインタ
2812 void sweep_monster_process(player_type *target_ptr)
2814 floor_type *floor_ptr = target_ptr->current_floor_ptr;
2815 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
2817 monster_type *m_ptr;
2818 monster_race *r_ptr;
2819 m_ptr = &floor_ptr->m_list[i];
2820 r_ptr = &r_info[m_ptr->r_idx];
2822 if (target_ptr->leaving) return;
2823 if (!monster_is_valid(m_ptr)) continue;
2824 if (target_ptr->wild_mode) continue;
2826 if (m_ptr->mflag & MFLAG_BORN)
2828 m_ptr->mflag &= ~(MFLAG_BORN);
2832 if (m_ptr->cdis >= AAF_LIMIT) continue;
2833 if (!decide_process_continue(target_ptr, m_ptr)) continue;
2835 SPEED speed = decide_monster_speed(target_ptr, m_ptr, i);
2836 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
2837 if (m_ptr->energy_need > 0) continue;
2839 m_ptr->energy_need += ENERGY_NEED();
2841 process_monster(target_ptr, i);
2842 reset_target(m_ptr);
2844 if (target_ptr->no_flowed && one_in_(3))
2845 m_ptr->mflag2 |= MFLAG2_NOFLOW;
2847 if (!target_ptr->playing || target_ptr->is_dead) return;
2848 if (target_ptr->leaving) return;
2854 * todo fy/fxへの代入は有効活用されていないはず
2855 * @brief 後続のモンスター処理が必要かどうか判定する (要調査)
2856 * @param target_ptr プレーヤーへの参照ポインタ
2857 * @param m_ptr モンスターへの参照ポインタ
2858 * @return 後続処理が必要ならTRUE
2860 bool decide_process_continue(player_type *target_ptr, monster_type *m_ptr)
2862 monster_race *r_ptr;
2863 r_ptr = &r_info[m_ptr->r_idx];
2864 POSITION fx = m_ptr->fx;
2865 POSITION fy = m_ptr->fy;
2866 if (!target_ptr->no_flowed)
2868 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
2871 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
2874 if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
2875 (player_has_los_bold(target_ptr, fy, fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
2878 if (m_ptr->target_y)
2886 * @brief モンスターの加速値を決定する
2887 * @param target_ptr プレーヤーへの参照ポインタ
2888 * @param m_ptr モンスターへの参照ポインタ
2889 * @param monster_number 走査中のモンスター番号
2892 SPEED decide_monster_speed(player_type *target_ptr, monster_type *m_ptr, int monster_number)
2895 if (target_ptr->riding == monster_number)
2897 speed = target_ptr->pspeed;
2901 speed = m_ptr->mspeed;
2902 if (ironman_nightmare) speed += 5;
2904 if (MON_FAST(m_ptr)) speed += 10;
2905 if (MON_SLOW(m_ptr)) speed -= 10;
2912 * @brief モンスターフラグの更新に基づき、モンスター表示を更新する
2913 * @param target_ptr プレーヤーへの参照ポインタ
2914 * @param old_race_flags_ptr モンスターフラグへの参照ポインタ
2917 void update_player_window(player_type *target_ptr, old_race_flags *old_race_flags_ptr)
2919 monster_race *r_ptr;
2920 r_ptr = &r_info[target_ptr->monster_race_idx];
2921 if ((old_race_flags_ptr->old_r_flags1 != r_ptr->r_flags1) ||
2922 (old_race_flags_ptr->old_r_flags2 != r_ptr->r_flags2) ||
2923 (old_race_flags_ptr->old_r_flags3 != r_ptr->r_flags3) ||
2924 (old_race_flags_ptr->old_r_flags4 != r_ptr->r_flags4) ||
2925 (old_race_flags_ptr->old_r_flags5 != r_ptr->r_flags5) ||
2926 (old_race_flags_ptr->old_r_flags6 != r_ptr->r_flags6) ||
2927 (old_race_flags_ptr->old_r_flagsr != r_ptr->r_flagsr) ||
2928 (old_race_flags_ptr->old_r_blows0 != r_ptr->r_blows[0]) ||
2929 (old_race_flags_ptr->old_r_blows1 != r_ptr->r_blows[1]) ||
2930 (old_race_flags_ptr->old_r_blows2 != r_ptr->r_blows[2]) ||
2931 (old_race_flags_ptr->old_r_blows3 != r_ptr->r_blows[3]) ||
2932 (old_race_flags_ptr->old_r_cast_spell != r_ptr->r_cast_spell))
2934 target_ptr->window |= (PW_MONSTER);