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;
79 turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr);
80 old_race_flags *init_old_race_flags(old_race_flags *old_race_flags_ptr);
82 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
83 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx);
84 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
85 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx);
86 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
87 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
88 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
89 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
90 bool explode_monster(player_type *target_ptr, MONSTER_IDX m_idx);
91 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
92 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware);
93 bool decide_pet_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx);
94 bool runaway_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
95 void escape_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, GAME_TEXT *m_name);
96 void process_special(player_type *target_ptr, MONSTER_IDX m_idx);
97 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware);
98 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware);
100 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross);
101 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
102 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
103 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash);
104 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
105 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
107 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
108 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);
109 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr);
111 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);
112 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
113 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);
115 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
117 void update_player_type(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_race *r_ptr);
118 void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr);
119 void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr);
120 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);
121 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
123 void save_old_race_flags(player_type *target_ptr, old_race_flags *old_race_flags_ptr);
124 void sweep_monster_process(player_type *target_ptr);
125 bool decide_process_continue(player_type *target_ptr, monster_type *m_ptr);
126 SPEED decide_monster_speed(player_type *target_ptr, monster_type *m_ptr, int monster_number);
127 void update_player_window(player_type *target_ptr, old_race_flags *old_race_flags_ptr);
130 * @brief モンスターが敵に接近するための方向を決める /
131 * Calculate the direction to the next enemy
132 * @param target_ptr プレーヤーへの参照ポインタ
133 * @param m_idx モンスターの参照ID
134 * @param mm 移動するべき方角IDを返す参照ポインタ
135 * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
137 static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
139 floor_type *floor_ptr = target_ptr->current_floor_ptr;
140 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
141 monster_race *r_ptr = &r_info[m_ptr->r_idx];
143 POSITION x = 0, y = 0;
144 if (target_ptr->riding_t_m_idx && player_bold(target_ptr, m_ptr->fy, m_ptr->fx))
146 y = floor_ptr->m_list[target_ptr->riding_t_m_idx].fy;
147 x = floor_ptr->m_list[target_ptr->riding_t_m_idx].fx;
149 else if (is_pet(m_ptr) && target_ptr->pet_t_m_idx)
151 y = floor_ptr->m_list[target_ptr->pet_t_m_idx].fy;
152 x = floor_ptr->m_list[target_ptr->pet_t_m_idx].fx;
158 if (target_ptr->phase_out)
160 start = randint1(floor_ptr->m_max - 1) + floor_ptr->m_max;
161 if (randint0(2)) plus = -1;
165 start = floor_ptr->m_max + 1;
168 for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus)
170 MONSTER_IDX dummy = (i % floor_ptr->m_max);
171 if (!dummy) continue;
173 MONSTER_IDX t_idx = dummy;
175 t_ptr = &floor_ptr->m_list[t_idx];
177 if (t_ptr == m_ptr) continue;
178 if (!monster_is_valid(t_ptr)) continue;
182 if (target_ptr->pet_follow_distance < 0)
184 if (t_ptr->cdis <= (0 - target_ptr->pet_follow_distance))
189 else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > target_ptr->pet_follow_distance))
194 if (r_ptr->aaf < t_ptr->cdis) continue;
197 if (!are_enemies(target_ptr, m_ptr, t_ptr)) continue;
199 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) ||
200 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)))
202 if (!in_disintegration_range(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
206 if (!projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
215 if (!x && !y) return FALSE;
221 /* North, South, East, West, North-West, North-East, South-West, South-East */
222 if ((y < 0) && (x == 0))
228 else if ((y > 0) && (x == 0))
234 else if ((x > 0) && (y == 0))
240 else if ((x < 0) && (y == 0))
246 else if ((y < 0) && (x < 0))
252 else if ((y < 0) && (x > 0))
258 else if ((y > 0) && (x < 0))
264 else if ((y > 0) && (x > 0))
276 * @brief モンスターがプレイヤーから逃走するかどうかを返す /
277 * Returns whether a given monster will try to run from the player.
278 * @param m_idx 逃走するモンスターの参照ID
279 * @return モンスターがプレイヤーから逃走するならばTRUEを返す。
281 * Monsters will attempt to avoid very powerful players. See below.\n
283 * Because this function is called so often, little details are important\n
284 * for efficiency. Like not using "mod" or "div" when possible. And\n
285 * attempting to check the conditions in an optimal order. Note that\n
286 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
288 * Note that this function is responsible for about one to five percent\n
289 * of the processor use in normal conditions...\n
291 static bool mon_will_run(player_type *target_ptr, MONSTER_IDX m_idx)
293 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
294 monster_race *r_ptr = &r_info[m_ptr->r_idx];
298 return ((target_ptr->pet_follow_distance < 0) &&
299 (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
302 if (m_ptr->cdis > MAX_SIGHT + 5) return FALSE;
303 if (MON_MONFEAR(m_ptr)) return TRUE;
304 if (m_ptr->cdis <= 5) return FALSE;
306 PLAYER_LEVEL p_lev = target_ptr->lev;
307 DEPTH m_lev = r_ptr->level + (m_idx & 0x08) + 25;
308 if (m_lev > p_lev + 4) return FALSE;
309 if (m_lev + 4 <= p_lev) return TRUE;
311 HIT_POINT p_chp = target_ptr->chp;
312 HIT_POINT p_mhp = target_ptr->mhp;
313 HIT_POINT m_chp = m_ptr->hp;
314 HIT_POINT m_mhp = m_ptr->maxhp;
315 u32b p_val = (p_lev * p_mhp) + (p_chp << 2);
316 u32b m_val = (m_lev * m_mhp) + (m_chp << 2);
317 if (p_val * m_mhp > m_val * p_mhp) return TRUE;
324 * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
325 * Search spell castable grid
326 * @param target_ptr プレーヤーへの参照ポインタ
327 * @param m_idx モンスターの参照ID
328 * @param yp 適したマスのY座標を返す参照ポインタ
329 * @param xp 適したマスのX座標を返す参照ポインタ
330 * @return 有効なマスがあった場合TRUEを返す
332 static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
334 floor_type *floor_ptr = target_ptr->current_floor_ptr;
335 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
336 monster_race *r_ptr = &r_info[m_ptr->r_idx];
338 POSITION y1 = m_ptr->fy;
339 POSITION x1 = m_ptr->fx;
341 if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x)) return FALSE;
343 int now_cost = floor_ptr->grid_array[y1][x1].cost;
344 if (now_cost == 0) now_cost = 999;
346 bool can_open_door = FALSE;
347 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
349 can_open_door = TRUE;
353 for (int i = 7; i >= 0; i--)
355 POSITION y = y1 + ddy_ddd[i];
356 POSITION x = x1 + ddx_ddd[i];
357 if (!in_bounds2(floor_ptr, y, x)) continue;
358 if (player_bold(target_ptr, y, x)) return FALSE;
361 g_ptr = &floor_ptr->grid_array[y][x];
362 int cost = g_ptr->cost;
363 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))))
365 if (cost == 0) continue;
366 if (!can_open_door && is_closed_door(target_ptr, g_ptr->feat)) continue;
369 if (cost == 0) cost = 998;
371 if (now_cost < cost) continue;
372 if (!projectable(target_ptr, y, x, target_ptr->y, target_ptr->x)) continue;
373 if (best < cost) continue;
376 *yp = y1 + ddy_ddd[i];
377 *xp = x1 + ddx_ddd[i];
380 if (best == 999) return FALSE;
387 * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
388 * Choose the "best" direction for "flowing"
389 * @param m_idx モンスターの参照ID
390 * @param yp 移動先のマスのY座標を返す参照ポインタ
391 * @param xp 移動先のマスのX座標を返す参照ポインタ
392 * @param no_flow モンスターにFLOWフラグが経っていない状態でTRUE
393 * @return 有効なマスがあった場合TRUEを返す
395 * Note that ghosts and rock-eaters are never allowed to "flow",\n
396 * since they should move directly towards the player.\n
398 * Prefer "non-diagonal" directions, but twiddle them a little\n
399 * to angle slightly towards the player's actual location.\n
401 * Allow very perceptive monsters to track old "spoor" left by\n
402 * previous locations occupied by the player. This will tend\n
403 * to have monsters end up either near the player or on a grid\n
404 * recently occupied by the player (and left via "teleport").\n
406 * Note that if "smell" is turned on, all monsters get vicious.\n
408 * Also note that teleporting away from a location will cause\n
409 * the monsters who were chasing you to converge on that location\n
410 * as long as you are still near enough to "annoy" them without\n
411 * being close enough to chase directly. I have no idea what will\n
412 * happen if you combine "smell" with low "aaf" values.\n
414 static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
417 floor_type *floor_ptr = target_ptr->current_floor_ptr;
418 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
419 monster_race *r_ptr = &r_info[m_ptr->r_idx];
421 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
422 r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
423 r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
425 if (get_moves_aux2(target_ptr, m_idx, yp, xp)) return TRUE;
428 if (no_flow) return FALSE;
429 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) return FALSE;
430 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)) return FALSE;
432 POSITION y1 = m_ptr->fy;
433 POSITION x1 = m_ptr->fx;
434 if (player_has_los_bold(target_ptr, y1, x1) && projectable(target_ptr, target_ptr->y, target_ptr->x, y1, x1)) return FALSE;
436 g_ptr = &floor_ptr->grid_array[y1][x1];
439 bool use_scent = FALSE;
444 else if (g_ptr->when)
446 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when - g_ptr->when > 127) return FALSE;
456 for (int i = 7; i >= 0; i--)
458 POSITION y = y1 + ddy_ddd[i];
459 POSITION x = x1 + ddx_ddd[i];
461 if (!in_bounds2(floor_ptr, y, x)) continue;
463 g_ptr = &floor_ptr->grid_array[y][x];
466 int when = g_ptr->when;
467 if (best > when) continue;
474 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
483 if ((cost == 0) || (best < cost)) continue;
488 *yp = target_ptr->y + 16 * ddy_ddd[i];
489 *xp = target_ptr->x + 16 * ddx_ddd[i];
492 if (best == 999 || best == 0) return FALSE;
499 * @brief モンスターがプレイヤーから逃走することが可能なマスを走査する /
500 * Provide a location to flee to, but give the player a wide berth.
501 * @param m_idx モンスターの参照ID
502 * @param yp 移動先のマスのY座標を返す参照ポインタ
503 * @param xp 移動先のマスのX座標を返す参照ポインタ
504 * @return 有効なマスがあった場合TRUEを返す
506 * A monster may wish to flee to a location that is behind the player,\n
507 * but instead of heading directly for it, the monster should "swerve"\n
508 * around the player so that he has a smaller chance of getting hit.\n
510 static bool get_fear_moves_aux(floor_type *floor_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
512 POSITION gy = 0, gx = 0;
514 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
515 POSITION fy = m_ptr->fy;
516 POSITION fx = m_ptr->fx;
518 POSITION y1 = fy - (*yp);
519 POSITION x1 = fx - (*xp);
522 for (int i = 7; i >= 0; i--)
524 POSITION y = fy + ddy_ddd[i];
525 POSITION x = fx + ddx_ddd[i];
526 if (!in_bounds2(floor_ptr, y, x)) continue;
528 POSITION dis = distance(y, x, y1, x1);
529 POSITION s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
532 if (s < score) continue;
539 if (score == -1) return FALSE;
549 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
552 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
553 * offsets of all the locations with a distance of n from a central point,
554 * with an offset of (0,0) indicating no more offsets at this distance.
556 * This is, of course, fairly unreadable, but it eliminates multiple loops
557 * from the previous version.
559 * It is probably better to replace these arrays with code to compute
560 * the relevant arrays, even if the storage is pre-allocated in hard
561 * coded sizes. At the very least, code should be included which is
562 * able to generate and dump these arrays (ala "los()").
564 * Also, the storage needs could be halved by using bytes.
566 * These arrays could be combined into two big arrays, using sub-arrays
567 * to hold the offsets and lengths of each portion of the sub-arrays, and
568 * this could perhaps also be used somehow in the "look" code.
572 static POSITION d_off_y_0[] = { 0 };
573 static POSITION d_off_x_0[] = { 0 };
575 static POSITION d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
576 static POSITION d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
578 static POSITION d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
579 static POSITION d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
581 static POSITION d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
582 static POSITION d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
584 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 };
585 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 };
588 static POSITION d_off_y_5[] =
589 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
590 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
593 static POSITION d_off_x_5[] =
594 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
595 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
599 static POSITION d_off_y_6[] =
600 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
601 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
604 static POSITION d_off_x_6[] =
605 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
606 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
607 -3, 2, 3, -1, 0, 1, 0 };
610 static POSITION d_off_y_7[] =
611 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
612 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
613 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
615 static POSITION d_off_x_7[] =
616 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
617 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
618 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
622 static POSITION d_off_y_8[] =
623 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
624 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
625 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
628 static POSITION d_off_x_8[] =
629 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
630 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
631 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
635 static POSITION d_off_y_9[] =
636 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
637 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
638 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
639 7, 8, 8, 8, 8, 9, 9, 9, 0 };
641 static POSITION d_off_x_9[] =
642 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
643 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
644 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
645 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
648 static POSITION *dist_offsets_y[10] =
650 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
651 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
654 static POSITION *dist_offsets_x[10] =
656 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
657 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
661 * @brief モンスターが逃げ込める安全な地点を返す /
662 * Choose a "safe" location near a monster for it to run toward.
663 * @param target_ptr プレーヤーへの参照ポインタ
664 * @param m_idx モンスターの参照ID
665 * @param yp 移動先のマスのY座標を返す参照ポインタ
666 * @param xp 移動先のマスのX座標を返す参照ポインタ
667 * @return 有効なマスがあった場合TRUEを返す
669 * A location is "safe" if it can be reached quickly and the player\n
670 * is not able to fire into it (it isn't a "clean shot"). So, this will\n
671 * cause monsters to "duck" behind walls. Hopefully, monsters will also\n
672 * try to run towards corridor openings if they are in a room.\n
674 * This function may take lots of CPU time if lots of monsters are\n
677 * Return TRUE if a safe location is available.\n
679 static bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
681 floor_type *floor_ptr = target_ptr->current_floor_ptr;
682 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
684 POSITION fy = m_ptr->fy;
685 POSITION fx = m_ptr->fx;
687 POSITION gy = 0, gx = 0, gdis = 0;
689 for (POSITION d = 1; d < 10; d++)
692 y_offsets = dist_offsets_y[d];
695 x_offsets = dist_offsets_x[d];
697 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
699 i++, dx = x_offsets[i], dy = y_offsets[i])
701 POSITION y = fy + dy;
702 POSITION x = fx + dx;
703 if (!in_bounds(floor_ptr, y, x)) continue;
706 g_ptr = &floor_ptr->grid_array[y][x];
708 BIT_FLAGS16 riding_mode = (m_idx == target_ptr->riding) ? CEM_RIDING : 0;
709 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], riding_mode))
712 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
714 if (g_ptr->dist == 0) continue;
715 if (g_ptr->dist > floor_ptr->grid_array[fy][fx].dist + 2 * d) continue;
718 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x)) continue;
720 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
721 if (dis <= gdis) continue;
728 if (gdis <= 0) continue;
741 * @brief モンスターが隠れ潜める地点を返す /
742 * Choose a good hiding place near a monster for it to run toward.
743 * @param target_ptr プレーヤーへの参照ポインタ
744 * @param m_idx モンスターの参照ID
745 * @param yp 移動先のマスのY座標を返す参照ポインタ
746 * @param xp 移動先のマスのX座標を返す参照ポインタ
747 * @return 有効なマスがあった場合TRUEを返す
749 * Pack monsters will use this to "ambush" the player and lure him out\n
750 * of corridors into open space so they can swarm him.\n
752 * Return TRUE if a good location is available.\n
754 static bool find_hiding(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
756 floor_type *floor_ptr = target_ptr->current_floor_ptr;
757 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
758 monster_race *r_ptr = &r_info[m_ptr->r_idx];
760 POSITION fy = m_ptr->fy;
761 POSITION fx = m_ptr->fx;
763 POSITION gy = 0, gx = 0, gdis = 999;
765 for (POSITION d = 1; d < 10; d++)
768 y_offsets = dist_offsets_y[d];
771 x_offsets = dist_offsets_x[d];
773 for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
775 i++, dx = x_offsets[i], dy = y_offsets[i])
777 POSITION y = fy + dy;
778 POSITION x = fx + dx;
780 if (!in_bounds(floor_ptr, y, x)) continue;
781 if (!monster_can_enter(target_ptr, y, x, r_ptr, 0)) continue;
782 if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, fy, fx, y, x, FALSE))
785 POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
786 if (dis < gdis && dis >= 2)
794 if (gdis >= 999) continue;
807 * @brief モンスターの移動方向を返す /
808 * Choose "logical" directions for monster movement
809 * @param target_ptr プレーヤーへの参照ポインタ
810 * @param m_idx モンスターの参照ID
811 * @param mm 移動方向を返す方向IDの参照ポインタ
812 * @return 有効方向があった場合TRUEを返す
814 static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
816 floor_type *floor_ptr = target_ptr->current_floor_ptr;
817 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
818 monster_race *r_ptr = &r_info[m_ptr->r_idx];
819 POSITION y = 0, ay, x = 0, ax;
820 POSITION y2 = target_ptr->y;
821 POSITION x2 = target_ptr->x;
823 bool will_run = mon_will_run(target_ptr, m_idx);
825 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) != 0) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2);
826 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) != 0) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall);
828 if (!will_run && m_ptr->target_y)
830 int t_m_idx = floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
832 are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[t_m_idx]) &&
833 los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
834 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
836 y = m_ptr->fy - m_ptr->target_y;
837 x = m_ptr->fx - m_ptr->target_x;
842 if (!done && !will_run && is_hostile(m_ptr) &&
843 (r_ptr->flags1 & RF1_FRIENDS) &&
844 ((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)) ||
845 (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
847 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
848 !(r_ptr->flags2 & RF2_KILL_WALL))
851 for (int i = 0; i < 8; i++)
853 int xx = target_ptr->x + ddx_ddd[i];
854 int yy = target_ptr->y + ddy_ddd[i];
856 if (!in_bounds2(floor_ptr, yy, xx)) continue;
858 g_ptr = &floor_ptr->grid_array[yy][xx];
859 if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0))
865 if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].info & CAVE_ROOM) room -= 2;
866 if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
868 if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
869 (target_ptr->mhp + target_ptr->msp))
871 if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
875 if (!done && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
877 for (int i = 0; i < 8; i++)
879 y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
880 x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
881 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
888 if (!in_bounds2(floor_ptr, y2, x2)) continue;
889 if (!monster_can_enter(target_ptr, y2, x2, r_ptr, 0)) continue;
902 (void)get_moves_aux(target_ptr, m_idx, &y2, &x2, no_flow);
907 if (is_pet(m_ptr) && will_run)
913 if (!done && will_run)
917 if (find_safety(target_ptr, m_idx, &y, &x) && !no_flow)
919 if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x))
931 if (!x && !y) return FALSE;
937 if (y < 0) move_val += 8;
938 if (x > 0) move_val += 4;
940 if (ay > (ax << 1)) move_val += 2;
941 else if (ax > (ay << 1)) move_val++;
1091 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
1093 return !have_flag(f_ptr->flags, FF_GLASS) ||
1094 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
1095 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
1100 * @brief モンスター単体の1ターン行動処理メインルーチン /
1102 * @param target_ptr プレーヤーへの参照ポインタ
1103 * @param m_idx 行動モンスターの参照ID
1106 * The monster is known to be within 100 grids of the player\n
1108 * In several cases, we directly update the monster lore\n
1110 * Note that a monster is only allowed to "reproduce" if there\n
1111 * are a limited number of "reproducing" monsters on the current\n
1112 * level. This should prevent the level from being "swamped" by\n
1113 * reproducing monsters. It also allows a large mass of mice to\n
1114 * prevent a louse from multiplying, but this is a small price to\n
1115 * pay for a simple multiplication method.\n
1117 * XXX Monster fear is slightly odd, in particular, monsters will\n
1118 * fixate on opening a door even if they cannot open it. Actually,\n
1119 * the same thing happens to normal monsters when they hit a door\n
1121 * In addition, monsters which *cannot* open or bash\n
1122 * down a door will still stand there trying to open it...\n
1124 * XXX Technically, need to check for monster in the way\n
1125 * combined with that monster being in a wall (or door?)\n
1127 * A "direction" of "5" means "pick a random direction".\n
1129 void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1131 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1132 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1133 turn_flags tmp_flags;
1134 turn_flags *turn_flags_ptr = init_turn_flags(target_ptr, m_idx, &tmp_flags);
1135 turn_flags_ptr->see_m = is_seen(m_ptr);
1137 decide_drop_from_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon);
1138 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
1140 choose_new_monster(target_ptr, m_idx, FALSE, 0);
1141 r_ptr = &r_info[m_ptr->r_idx];
1144 turn_flags_ptr->aware = process_stealth(target_ptr, m_idx);
1145 if (vanish_summoned_children(target_ptr, m_idx, turn_flags_ptr->see_m)) return;
1146 if (process_quantum_effect(target_ptr,m_idx, turn_flags_ptr->see_m)) return;
1147 if (explode_monster(target_ptr, m_idx)) return;
1148 if (runaway_monster(target_ptr, turn_flags_ptr, m_idx)) return;
1150 awake_monster(target_ptr, m_idx);
1151 if (MON_STUNNED(m_ptr))
1153 if (one_in_(2)) return;
1156 if (turn_flags_ptr->is_riding_mon)
1158 target_ptr->update |= (PU_BONUS);
1161 process_angar(target_ptr, m_idx, turn_flags_ptr->see_m);
1163 POSITION oy = m_ptr->fy;
1164 POSITION ox = m_ptr->fx;
1165 if (decide_monster_multiplication(target_ptr, m_idx, oy, ox)) return;
1167 process_special(target_ptr, m_idx);
1168 process_speak_sound(target_ptr, m_idx, oy, ox, turn_flags_ptr->aware);
1169 if (cast_spell(target_ptr, m_idx, turn_flags_ptr->aware)) return;
1172 mm[0] = mm[1] = mm[2] = mm[3] = 0;
1173 mm[4] = mm[5] = mm[6] = mm[7] = 0;
1175 if (!decide_monster_movement_direction(target_ptr, mm, m_idx, turn_flags_ptr->aware)) return;
1178 if(!process_monster_movement(target_ptr, turn_flags_ptr, m_idx, mm, oy, ox, &count)) return;
1181 * Forward movements failed, but now received LOS attack!
1182 * Try to flow by smell.
1184 if (target_ptr->no_flowed && count > 2 && m_ptr->target_y)
1185 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
1187 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)
1189 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
1191 if (make_attack_spell(m_idx, target_ptr)) return;
1195 update_player_type(target_ptr, turn_flags_ptr, r_ptr);
1196 update_monster_race_flags(target_ptr, turn_flags_ptr, m_ptr);
1198 if (!process_monster_fear(target_ptr, turn_flags_ptr, m_idx)) return;
1200 if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
1205 * @brief ターン経過フラグ構造体の初期化
1206 * @param target_ptr プレーヤーへの参照ポインタ
1207 * @param m_idx モンスターID
1208 * @return 初期化済のターン経過フラグ
1210 turn_flags *init_turn_flags(player_type *target_ptr, MONSTER_IDX m_idx, turn_flags *turn_flags_ptr)
1212 turn_flags_ptr->is_riding_mon = (m_idx == target_ptr->riding);
1213 turn_flags_ptr->do_turn = FALSE;
1214 turn_flags_ptr->do_move = FALSE;
1215 turn_flags_ptr->do_view = FALSE;
1216 turn_flags_ptr->must_alter_to_move = FALSE;
1217 turn_flags_ptr->did_open_door = FALSE;
1218 turn_flags_ptr->did_bash_door = FALSE;
1219 turn_flags_ptr->did_take_item = FALSE;
1220 turn_flags_ptr->did_kill_item = FALSE;
1221 turn_flags_ptr->did_move_body = FALSE;
1222 turn_flags_ptr->did_pass_wall = FALSE;
1223 turn_flags_ptr->did_kill_wall = FALSE;
1224 return turn_flags_ptr;
1230 * @param target_ptr プレーヤーへの参照ポインタ
1231 * @param m_idx モンスターID
1232 * @return モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1234 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx)
1236 if ((target_ptr->special_defense & NINJA_S_STEALTH) == 0) return TRUE;
1238 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1239 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1240 int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
1241 if (target_ptr->monlite) tmp /= 3;
1242 if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
1243 if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
1244 return (randint0(tmp) <= (r_ptr->level + 20));
1249 * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
1250 * @param target_ptr プレーヤーへの参照ポインタ
1251 * @param m_idx モンスターID
1252 * @param is_riding_mon 騎乗中であればTRUE
1255 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
1257 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1258 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1259 if (!is_riding_mon || ((r_ptr->flags7 & RF7_RIDING) != 0)) return;
1261 if (rakuba(target_ptr, 0, TRUE))
1264 msg_print("地面に落とされた。");
1266 GAME_TEXT m_name[MAX_NLEN];
1267 monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
1268 msg_format("You have fallen from %s.", m_name);
1275 * @brief 召喚の親元が消滅した時、子供も消滅させる
1276 * @param target_ptr プレーヤーへの参照ポインタ
1277 * @param m_idx モンスターID
1278 * @param see_m モンスターが視界内にいたらTRUE
1279 * @return 召喚モンスターが消滅したらTRUE
1281 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1283 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1284 if ((m_ptr->parent_m_idx == 0) || (target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx > 0))
1289 GAME_TEXT m_name[MAX_NLEN];
1290 monster_desc(target_ptr, m_name, m_ptr, 0);
1291 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1294 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1296 GAME_TEXT m_name[MAX_NLEN];
1297 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
1298 exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
1301 delete_monster_idx(target_ptr, m_idx);
1307 * @brief 寝ているモンスターの起床を判定する
1308 * @param target_ptr プレーヤーへの参照ポインタ
1309 * @param m_idx モンスターID
1312 void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1314 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1315 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1316 if (!MON_CSLEEP(m_ptr)) return;
1317 if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
1319 (void)set_monster_csleep(target_ptr, m_idx, 0);
1322 GAME_TEXT m_name[MAX_NLEN];
1323 monster_desc(target_ptr, m_name, m_ptr, 0);
1324 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
1327 if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
1335 * @brief モンスターの怒り状態を判定する (起こっていたら敵に回す)
1336 * @param target_ptr プレーヤーへの参照ポインタ
1337 * @param m_idx モンスターID
1338 * @param see_m モンスターが視界内にいたらTRUE
1341 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1343 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1344 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1345 bool gets_angry = FALSE;
1346 if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
1349 if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
1350 monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
1355 if (target_ptr->phase_out || !gets_angry) return;
1357 if (is_pet(m_ptr) || see_m)
1359 GAME_TEXT m_name[MAX_NLEN];
1360 monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
1361 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
1364 set_hostile(target_ptr, m_ptr);
1369 * @brief 量子生物の量子的効果を実行する
1370 * @param target_ptr プレーヤーへの参照ポインタ
1371 * @param m_idx モンスターID
1372 * @param see_m モンスターが視界内にいたらTRUE
1373 * @return モンスターが量子的効果により消滅したらTRUE
1375 bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1377 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1378 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1379 if ((r_ptr->flags2 & RF2_QUANTUM) == 0) return FALSE;
1380 if (!randint0(2)) return FALSE;
1381 if (randint0((m_idx % 100) + 10)) return FALSE;
1383 bool can_disappear = (r_ptr->flags1 & RF1_UNIQUE) == 0;
1384 can_disappear &= (r_ptr->flags1 & RF1_QUESTOR) == 0;
1387 vanish_nonunique(target_ptr, m_idx, see_m);
1391 produce_quantum_effect(target_ptr, m_idx, see_m);
1397 * @brief ユニークでない量子生物を消滅させる
1398 * @param target_ptr プレーヤーへの参照ポインタ
1399 * @param m_idx モンスターID
1400 * @param see_m モンスターが視界内にいたらTRUE
1403 void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1405 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1408 GAME_TEXT m_name[MAX_NLEN];
1409 monster_desc(target_ptr, m_name, m_ptr, 0);
1410 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
1413 monster_death(target_ptr, m_idx, FALSE);
1414 delete_monster_idx(target_ptr, m_idx);
1415 if (is_pet(m_ptr) && !(m_ptr->ml))
1417 msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
1423 * @brief 量子生物ユニークの量子的効果 (ショート・テレポートまたは距離10のテレポート・アウェイ)を実行する
1424 * @param target_ptr プレーヤーへの参照ポインタ
1425 * @param m_idx モンスターID
1426 * @param see_m モンスターが視界内にいたらTRUE
1429 * プレーヤーが量子生物を観測しているか、量子生物がプレーヤーを観測している場合、互いの相対的な位置を確定させる
1430 * 波動関数の収縮はテレポートではないので反テレポート無効
1431 * todo パターンは収縮どころか拡散しているが、この際気にしてはいけない
1433 void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
1435 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1436 bool coherent = los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x);
1437 if (!see_m && !coherent) return;
1441 GAME_TEXT m_name[MAX_NLEN];
1442 monster_desc(target_ptr, m_name, m_ptr, 0);
1443 msg_format(_("%sは量子的効果を起こした!", "%^s produced a decoherence!"), m_name);
1447 msg_print(_("量子的効果が起こった!", "A decoherence was produced!"));
1450 bool target = one_in_(2);
1451 const int blink = 32 * 5 + 4;
1454 (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx);
1458 teleport_player_away(m_idx, target_ptr, 10, TRUE);
1465 * @param target_ptr プレーヤーへの参照ポインタ
1466 * @param m_idx モンスターID
1469 bool explode_monster(player_type *target_ptr, MONSTER_IDX m_idx)
1471 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1472 if (m_ptr->r_idx != MON_SHURYUUDAN) return FALSE;
1475 mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
1481 * @brief モンスター依存の特別な行動を取らせる
1482 * @param target_ptr プレーヤーへの参照ポインタ
1483 * @param m_idx モンスターID
1486 void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
1488 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1489 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1490 if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
1491 if (m_ptr->r_idx != MON_OHMU) return;
1492 if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
1493 if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
1496 DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1497 BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
1499 for (int k = 0; k < A_MAX; k++)
1501 if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
1503 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
1507 if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
1512 * @brief モンスターを喋らせたり足音を立てたりする
1513 * @param target_ptr プレーヤーへの参照ポインタ
1514 * @param m_idx モンスターID
1515 * @param oy モンスターが元々いたY座標
1516 * @param ox モンスターが元々いたX座標
1517 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1520 void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware)
1522 if (target_ptr->phase_out) return;
1524 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1525 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1526 if (m_ptr->ap_r_idx == MON_CYBER &&
1527 one_in_(CYBERNOISE) &&
1528 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
1530 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
1531 msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
1534 if (((ap_r_ptr->flags2 & RF2_CAN_SPEAK) == 0) || !aware ||
1535 !one_in_(SPEAK_CHANCE) ||
1536 !player_has_los_bold(target_ptr, oy, ox) ||
1537 !projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
1540 GAME_TEXT m_name[MAX_NLEN];
1541 char monmessage[1024];
1545 monster_desc(target_ptr, m_name, m_ptr, 0);
1547 strcpy(m_name, _("それ", "It"));
1549 if (MON_MONFEAR(m_ptr))
1550 filename = _("monfear_j.txt", "monfear.txt");
1551 else if (is_pet(m_ptr))
1552 filename = _("monpet_j.txt", "monpet.txt");
1553 else if (is_friendly(m_ptr))
1554 filename = _("monfrien_j.txt", "monfrien.txt");
1556 filename = _("monspeak_j.txt", "monspeak.txt");
1558 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
1560 msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
1566 * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
1567 * @param target_ptr プレーヤーへの参照ポインタ
1568 * @param m_idx モンスターID
1569 * @param oy 分裂元モンスターのY座標
1570 * @param ox 分裂元モンスターのX座標
1571 * @return 実際に分裂したらTRUEを返す
1573 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
1575 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1576 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1577 if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) || (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
1581 for (POSITION y = oy - 1; y <= oy + 1; y++)
1583 for (POSITION x = ox - 1; x <= ox + 1; x++)
1585 if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
1586 if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
1590 if (multiply_barrier(target_ptr, m_idx)) k = 8;
1592 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
1594 if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
1596 if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
1598 r_ptr->r_flags2 |= (RF2_MULTIPLY);
1610 * @brief モンスターの移動パターンを決定する
1611 * @param target_ptr プレーヤーへの参照ポインタ
1613 * @param m_idx モンスターID
1614 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1615 * @return 移動先が存在すればTRUE
1617 bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware)
1619 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1620 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1622 if (MON_CONFUSED(m_ptr) || !aware)
1624 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1628 if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) && (randint0(100) < 75))
1630 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
1632 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1636 if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 50))
1638 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
1640 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1644 if ((r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 25))
1646 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
1648 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1652 if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
1654 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1658 if (decide_pet_movement_direction(target_ptr, mm, m_idx)) return TRUE;
1660 if (!is_hostile(m_ptr))
1662 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1663 get_enemy_dir(target_ptr, m_idx, mm);
1667 if (!get_moves(target_ptr, m_idx, mm)) return FALSE;
1674 * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
1675 * @param target_ptr プレーヤーへの参照ポインタ
1677 * @param m_idx モンスターID
1678 * @return モンスターがペットであればTRUE
1680 bool decide_pet_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx)
1682 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1683 if (!is_pet(m_ptr)) return FALSE;
1685 bool avoid = ((target_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
1686 bool lonely = (!avoid && (m_ptr->cdis > target_ptr->pet_follow_distance));
1687 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
1688 mm[0] = mm[1] = mm[2] = mm[3] = 5;
1689 if (get_enemy_dir(target_ptr, m_idx, mm)) return TRUE;
1690 if (!avoid && !lonely && !distant) return TRUE;
1692 POSITION dis = target_ptr->pet_follow_distance;
1693 if (target_ptr->pet_follow_distance > PET_SEEK_DIST)
1695 target_ptr->pet_follow_distance = PET_SEEK_DIST;
1698 (void)get_moves(target_ptr, m_idx, mm);
1699 target_ptr->pet_follow_distance = (s16b)dis;
1705 * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
1706 * @param target_ptr プレーヤーへの参照ポインタ
1707 * @param m_idx モンスターID
1708 * @param is_riding_mon 騎乗状態ならばTRUE
1709 * @param see_m モンスターが視界内にいたらTRUE
1710 * @return モンスターがフロアから消えたらTRUE
1712 bool runaway_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
1714 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1715 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1716 bool can_runaway = is_pet(m_ptr) || is_friendly(m_ptr);
1717 can_runaway &= ((r_ptr->flags1 & RF1_UNIQUE) != 0) || ((r_ptr->flags7 & RF7_NAZGUL) != 0);
1718 can_runaway &= !target_ptr->phase_out;
1719 if (!can_runaway) return FALSE;
1721 static int riding_pinch = 0;
1723 if (m_ptr->hp >= m_ptr->maxhp / 3)
1725 /* Reset the counter */
1726 if (turn_flags_ptr->is_riding_mon) riding_pinch = 0;
1731 GAME_TEXT m_name[MAX_NLEN];
1732 monster_desc(target_ptr, m_name, m_ptr, 0);
1733 if (turn_flags_ptr->is_riding_mon && riding_pinch < 2)
1735 msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
1736 "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
1738 disturb(target_ptr, TRUE, TRUE);
1742 escape_monster(target_ptr, turn_flags_ptr, m_ptr, m_name);
1743 check_quest_completion(target_ptr, m_ptr);
1744 delete_monster_idx(target_ptr, m_idx);
1750 * @brief HPが1/3未満になった有効的なユニークモンスターの逃走処理を行う
1751 * @param target_ptr プレーヤーへの参照ポインタ
1752 * @param is_riding_mon 騎乗状態ならばTRUE
1753 * @param m_ptr モンスターへの参照ポインタ
1754 * @param m_name モンスター名称
1755 * @param see_m モンスターが視界内にいたらTRUE
1758 void escape_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, GAME_TEXT *m_name)
1760 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1761 if (turn_flags_ptr->is_riding_mon)
1763 msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
1764 if (rakuba(target_ptr, -1, FALSE))
1766 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1770 if (turn_flags_ptr->see_m)
1772 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) &&
1773 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))
1775 msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
1778 msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s reads a scroll of teleport level."), m_name);
1779 msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
1782 if (turn_flags_ptr->is_riding_mon && rakuba(target_ptr, -1, FALSE))
1784 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
1790 * @brief モンスターに魔法を試行させる
1791 * @param target_ptr プレーヤーへの参照ポインタ
1792 * @param m_idx モンスターID
1793 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
1794 * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
1796 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware)
1798 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1799 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1800 if ((r_ptr->freq_spell == 0) || (randint1(100) > r_ptr->freq_spell))
1803 bool counterattack = FALSE;
1804 if (m_ptr->target_y)
1806 MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
1807 if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
1808 projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1810 counterattack = TRUE;
1816 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1817 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1821 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
1822 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
1830 * todo 少し長いが、これといってブロックとしてまとまった部分もないので暫定でこのままとする
1831 * @brief モンスターの移動に関するメインルーチン
1832 * @param target_ptr プレーヤーへの参照ポインタ
1833 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
1834 * @param m_idx モンスターID
1835 * @param mm モンスターの移動方向
1836 * @param oy 移動前の、モンスターのY座標
1837 * @param ox 移動前の、モンスターのX座標
1838 * @param count 移動回数 (のはず todo)
1839 * @return 移動が阻害される何か (ドア等)があったらFALSE
1841 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)
1843 for (int i = 0; mm[i]; i++)
1846 if (d == 5) d = ddd[randint0(8)];
1848 POSITION ny = oy + ddy[d];
1849 POSITION nx = ox + ddx[d];
1850 if (!in_bounds2(target_ptr->current_floor_ptr, ny, nx)) continue;
1853 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1854 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
1855 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1856 bool can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0);
1858 if (!process_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx, can_cross))
1860 if (!process_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1864 if (!process_protection_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1866 if (!process_explosive_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
1870 exe_monster_attack_to_player(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1871 if (process_monster_attack_to_monster(target_ptr, turn_flags_ptr, m_idx, g_ptr, can_cross)) return FALSE;
1873 if (turn_flags_ptr->is_riding_mon)
1875 if (!target_ptr->riding_ryoute && !MON_MONFEAR(&target_ptr->current_floor_ptr->m_list[target_ptr->riding])) turn_flags_ptr->do_move = FALSE;
1878 if (!process_post_dig_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx)) return FALSE;
1880 if (turn_flags_ptr->must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
1882 if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0))
1883 turn_flags_ptr->do_move = FALSE;
1886 if (turn_flags_ptr->do_move && !can_cross && !turn_flags_ptr->did_kill_wall && !turn_flags_ptr->did_bash_door)
1887 turn_flags_ptr->do_move = FALSE;
1889 if (turn_flags_ptr->do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
1891 if (is_original_ap_and_seen(target_ptr, m_ptr))
1892 r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
1894 turn_flags_ptr->do_move = FALSE;
1897 if (!turn_flags_ptr->do_move)
1899 if (turn_flags_ptr->do_turn) break;
1904 turn_flags_ptr->do_turn = TRUE;
1905 feature_type *f_ptr;
1906 f_ptr = &f_info[g_ptr->feat];
1907 if (have_flag(f_ptr->flags, FF_TREE))
1909 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
1911 m_ptr->energy_need += ENERGY_NEED();
1915 if (!update_riding_monster(target_ptr, turn_flags_ptr, m_idx, oy, ox, ny, nx)) break;
1917 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1920 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
1921 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= target_ptr->lev)))
1923 if (is_hostile(m_ptr))
1924 disturb(target_ptr, FALSE, TRUE);
1927 bool is_takable_or_killable = g_ptr->o_idx > 0;
1928 is_takable_or_killable &= (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) != 0;
1930 bool is_pickup_items = (target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
1931 is_pickup_items &= (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
1933 is_takable_or_killable &= !is_pet(m_ptr) || is_pickup_items;
1934 if (!is_takable_or_killable)
1936 if (turn_flags_ptr->do_turn) break;
1941 update_object_by_monster_movement(target_ptr, turn_flags_ptr, m_idx, ny, nx);
1942 if (turn_flags_ptr->do_turn) break;
1952 * @brief モンスターによる壁の透過・破壊を行う
1953 * @param target_ptr プレーヤーへの参照ポインタ
1954 * @param m_ptr モンスターへの参照ポインタ
1955 * @param ny モンスターのY座標
1956 * @param nx モンスターのX座標
1957 * @param can_cross モンスターが地形を踏破できるならばTRUE
1958 * @return 透過も破壊もしなかった場合はFALSE、それ以外はTRUE
1960 bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross)
1962 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1964 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
1965 feature_type *f_ptr;
1966 f_ptr = &f_info[g_ptr->feat];
1967 if (player_bold(target_ptr, ny, nx))
1969 turn_flags_ptr->do_move = TRUE;
1973 if (g_ptr->m_idx > 0)
1975 turn_flags_ptr->do_move = TRUE;
1979 if (((r_ptr->flags2 & RF2_KILL_WALL) != 0) &&
1980 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !turn_flags_ptr->is_riding_mon) &&
1981 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
1982 check_hp_for_feat_destruction(f_ptr, m_ptr))
1984 turn_flags_ptr->do_move = TRUE;
1985 if (!can_cross) turn_flags_ptr->must_alter_to_move = TRUE;
1987 turn_flags_ptr->did_kill_wall = TRUE;
1991 if (!can_cross) return FALSE;
1993 turn_flags_ptr->do_move = TRUE;
1994 if (((r_ptr->flags2 & RF2_PASS_WALL) != 0) && (!turn_flags_ptr->is_riding_mon || target_ptr->pass_wall) &&
1995 have_flag(f_ptr->flags, FF_CAN_PASS))
1997 turn_flags_ptr->did_pass_wall = TRUE;
2005 * @brief モンスターによるドアの開放・破壊を行う
2006 * @param target_ptr プレーヤーへの参照ポインタ
2007 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2008 * @param m_ptr モンスターへの参照ポインタ
2009 * @param ny モンスターのY座標
2010 * @param nx モンスターのX座標
2011 * @return モンスターが死亡した場合のみFALSE
2013 bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2015 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2017 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2018 if (!is_closed_door(target_ptr, g_ptr->feat)) return TRUE;
2020 feature_type *f_ptr;
2021 f_ptr = &f_info[g_ptr->feat];
2022 bool may_bash = bash_normal_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx);
2023 bash_glass_door(target_ptr, turn_flags_ptr, m_ptr, f_ptr, may_bash);
2025 if (!turn_flags_ptr->did_open_door && !turn_flags_ptr->did_bash_door) return TRUE;
2027 if (turn_flags_ptr->did_bash_door &&
2028 ((randint0(100) < 50) || (feat_state(target_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
2030 cave_alter_feat(target_ptr, ny, nx, FF_BASH);
2031 if (!monster_is_valid(m_ptr))
2033 target_ptr->update |= (PU_FLOW);
2034 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2035 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2042 cave_alter_feat(target_ptr, ny, nx, FF_OPEN);
2045 f_ptr = &f_info[g_ptr->feat];
2046 turn_flags_ptr->do_view = TRUE;
2052 * @brief モンスターが普通のドアを開ける処理
2053 * @param target_ptr プレーヤーへの参照ポインタ
2054 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2055 * @param m_ptr モンスターへの参照ポインタ
2056 * @param ny モンスターのY座標
2057 * @param nx モンスターのX座標
2058 * @return ここではドアを開けず、ガラスのドアを開ける可能性があるならTRUE
2060 bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2062 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2064 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2065 feature_type *f_ptr;
2066 f_ptr = &f_info[g_ptr->feat];
2067 turn_flags_ptr->do_move = FALSE;
2068 if (((r_ptr->flags2 & RF2_OPEN_DOOR) == 0) || !have_flag(f_ptr->flags, FF_OPEN) ||
2069 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2072 if (f_ptr->power == 0)
2074 turn_flags_ptr->did_open_door = TRUE;
2075 turn_flags_ptr->do_turn = TRUE;
2079 if (randint0(m_ptr->hp / 10) > f_ptr->power)
2081 cave_alter_feat(target_ptr, ny, nx, FF_DISARM);
2082 turn_flags_ptr->do_turn = TRUE;
2091 * @brief モンスターがガラスのドアを開ける処理
2092 * @param target_ptr プレーヤーへの参照ポインタ
2093 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2094 * @param m_ptr モンスターへの参照ポインタ
2095 * @param g_ptr グリッドへの参照ポインタ
2096 * @param f_ptr 地形への参照ポインタ
2099 void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash)
2101 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2102 if (!may_bash || ((r_ptr->flags2 & RF2_BASH_DOOR) == 0) || !have_flag(f_ptr->flags, FF_BASH) ||
2103 (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
2106 if (!check_hp_for_feat_destruction(f_ptr, m_ptr) || (randint0(m_ptr->hp / 10) <= f_ptr->power))
2109 if (have_flag(f_ptr->flags, FF_GLASS))
2110 msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
2112 msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
2114 if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
2116 turn_flags_ptr->did_bash_door = TRUE;
2117 turn_flags_ptr->do_move = TRUE;
2118 turn_flags_ptr->must_alter_to_move = TRUE;
2123 * @brief 守りのルーンによるモンスターの移動制限を処理する
2124 * @param target_ptr プレーヤーへの参照ポインタ
2125 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2126 * @param m_ptr モンスターへの参照ポインタ
2127 * @param ny モンスターのY座標
2128 * @param nx モンスターのX座標
2131 bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2134 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2135 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2136 if (!turn_flags_ptr->do_move || !is_glyph_grid(g_ptr) ||
2137 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2140 turn_flags_ptr->do_move = FALSE;
2141 if (is_pet(m_ptr) || (randint1(BREAK_GLYPH) >= r_ptr->level))
2144 if (g_ptr->info & CAVE_MARK)
2146 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2149 g_ptr->info &= ~(CAVE_MARK);
2150 g_ptr->info &= ~(CAVE_OBJECT);
2152 turn_flags_ptr->do_move = TRUE;
2153 note_spot(target_ptr, ny, nx);
2159 * @brief 爆発のルーンにを処理する
2160 * @param target_ptr プレーヤーへの参照ポインタ
2161 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2162 * @param m_ptr モンスターへの参照ポインタ
2163 * @param ny モンスターのY座標
2164 * @param nx モンスターのX座標
2165 * @return モンスターが死亡した場合のみFALSE
2167 bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2170 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2171 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2172 if (!turn_flags_ptr->do_move || !is_explosive_rune_grid(g_ptr) ||
2173 (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
2176 turn_flags_ptr->do_move = FALSE;
2177 if (is_pet(m_ptr)) return TRUE;
2179 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2181 if (g_ptr->info & CAVE_MARK)
2183 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2184 BIT_FLAGS project_flags = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI;
2185 project(target_ptr, 0, 2, ny, nx, 2 * (target_ptr->lev + damroll(7, 7)), GF_MANA, project_flags, -1);
2190 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2193 g_ptr->info &= ~(CAVE_MARK);
2194 g_ptr->info &= ~(CAVE_OBJECT);
2197 note_spot(target_ptr, ny, nx);
2198 lite_spot(target_ptr, ny, nx);
2200 if (!monster_is_valid(m_ptr)) return FALSE;
2202 turn_flags_ptr->do_move = TRUE;
2208 * @brief モンスターが移動した結果、そこにプレーヤーがいたら直接攻撃を行う
2209 * @param target_ptr プレーヤーへの参照ポインタ
2210 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2211 * @param m_idx モンスターID
2212 * @param ny 移動後の、モンスターのY座標
2213 * @param nx 移動後の、モンスターのX座標
2216 * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
2218 void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2220 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2221 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2222 if (!turn_flags_ptr->do_move || !player_bold(target_ptr, ny, nx))
2225 if (r_ptr->flags1 & RF1_NEVER_BLOW)
2227 if (is_original_ap_and_seen(target_ptr, m_ptr))
2228 r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
2230 turn_flags_ptr->do_move = FALSE;
2233 if (turn_flags_ptr->do_move && ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) != 0) && !MON_CONFUSED(m_ptr))
2235 if (!(r_ptr->flags2 & RF2_STUPID))
2236 turn_flags_ptr->do_move = FALSE;
2237 else if (is_original_ap_and_seen(target_ptr, m_ptr))
2238 r_ptr->r_flags2 |= (RF2_STUPID);
2241 if (!turn_flags_ptr->do_move) return;
2243 if (!target_ptr->riding || one_in_(2))
2245 (void)make_attack_normal(target_ptr, m_idx);
2246 turn_flags_ptr->do_move = FALSE;
2247 turn_flags_ptr->do_turn = TRUE;
2253 * @brief モンスターからモンスターへの攻撃処理
2254 * @param target_ptr プレーヤーへの参照ポインタ
2255 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2256 * @param m_idx モンスターID
2257 * @param g_ptr グリッドへの参照ポインタ
2258 * @param can_cross モンスターが地形を踏破できるならばTRUE
2259 * @return ターン消費が発生したらTRUE
2261 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)
2263 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2264 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2265 monster_type *y_ptr;
2266 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2267 if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) return FALSE;
2269 monster_race *z_ptr = &r_info[y_ptr->r_idx];
2270 turn_flags_ptr->do_move = FALSE;
2271 if ((((r_ptr->flags2 & RF2_KILL_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_BLOW) == 0) &&
2272 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
2273 can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
2274 are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
2276 return exe_monster_attack_to_monster(target_ptr, m_idx, g_ptr);
2279 if (((r_ptr->flags2 & RF2_MOVE_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_MOVE) == 0) &&
2280 (r_ptr->mexp > z_ptr->mexp) &&
2281 can_cross && (g_ptr->m_idx != target_ptr->riding) &&
2282 monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
2284 turn_flags_ptr->do_move = TRUE;
2285 turn_flags_ptr->did_move_body = TRUE;
2286 (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
2294 * @brief モンスターからモンスターへの直接攻撃を実行する
2295 * @param target_ptr プレーヤーへの参照ポインタ
2296 * @param m_idx モンスターID
2297 * @param g_ptr グリッドへの参照ポインタ
2299 bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr)
2301 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2302 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2303 monster_type *y_ptr;
2304 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2305 if ((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) return FALSE;
2307 if (((r_ptr->flags2 & RF2_KILL_BODY) == 0) && is_original_ap_and_seen(target_ptr, m_ptr))
2308 r_ptr->r_flags2 |= (RF2_KILL_BODY);
2310 if ((y_ptr->r_idx == 0) || (y_ptr->hp < 0)) return FALSE;
2311 if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return TRUE;
2312 if ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) == 0) return FALSE;
2313 if (MON_CONFUSED(m_ptr)) return TRUE;
2314 if ((r_ptr->flags2 & RF2_STUPID) == 0) return FALSE;
2316 if (is_original_ap_and_seen(target_ptr, m_ptr))
2317 r_ptr->r_flags2 |= (RF2_STUPID);
2324 * @brief モンスターが壁を掘った後続処理を実行する
2325 * @param target_ptr プレーヤーへの参照ポインタ
2326 * @turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2327 * @param m_ptr モンスターへの参照ポインタ
2328 * @param ny モンスターのY座標
2329 * @param nx モンスターのX座標
2330 * @return モンスターが死亡した場合のみFALSE
2332 bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
2334 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2336 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2337 feature_type *f_ptr;
2338 f_ptr = &f_info[g_ptr->feat];
2339 if (!turn_flags_ptr->did_kill_wall || !turn_flags_ptr->do_move) return TRUE;
2341 if (one_in_(GRINDNOISE))
2343 if (have_flag(f_ptr->flags, FF_GLASS))
2344 msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
2346 msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
2349 cave_alter_feat(target_ptr, ny, nx, FF_HURT_DISI);
2351 if (!monster_is_valid(m_ptr))
2353 target_ptr->update |= (PU_FLOW);
2354 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2355 if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2360 f_ptr = &f_info[g_ptr->feat];
2361 turn_flags_ptr->do_view = TRUE;
2362 turn_flags_ptr->do_turn = TRUE;
2368 * @brief 騎乗中のモンスター情報を更新する
2369 * @param target_ptr プレーヤーへの参照ポインタ
2370 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2371 * @param m_idx モンスターID
2372 * @param oy 移動前の、モンスターのY座標
2373 * @param ox 移動前の、モンスターのX座標
2374 * @param ny 移動後の、モンスターのY座標
2375 * @param ox 移動後の、モンスターのX座標
2376 * @return アイテム等に影響を及ぼしたらTRUE
2378 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)
2380 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2382 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2383 monster_type *y_ptr;
2384 y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2385 if (turn_flags_ptr->is_riding_mon)
2386 return move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP);
2388 target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
2393 update_monster(target_ptr, g_ptr->m_idx, TRUE);
2396 g_ptr->m_idx = m_idx;
2399 update_monster(target_ptr, m_idx, TRUE);
2401 lite_spot(target_ptr, oy, ox);
2402 lite_spot(target_ptr, ny, nx);
2408 * @brief モンスターの移動に伴うオブジェクト処理 (アイテム破壊等)
2409 * @param target_ptr プレーヤーへの参照ポインタ
2410 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2411 * @param m_idx モンスターID
2412 * @param ny 移動後の、モンスターのY座標
2413 * @param nx 移動後の、モンスターのX座標
2415 void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
2417 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2418 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2420 g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
2422 OBJECT_IDX this_o_idx, next_o_idx;
2423 turn_flags_ptr->do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
2424 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2426 BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
2427 GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
2428 object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
2429 next_o_idx = o_ptr->next_o_idx;
2431 if (turn_flags_ptr->do_take)
2433 /* Skip gold, corpse and statue */
2434 if (o_ptr->tval == TV_GOLD || (o_ptr->tval == TV_CORPSE) || (o_ptr->tval == TV_STATUE))
2438 object_flags(o_ptr, flgs);
2439 object_desc(target_ptr, o_name, o_ptr, 0);
2440 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
2441 update_object_flags(flgs, &flg2, &flg3, &flgr);
2443 bool is_special_object = object_is_artifact(o_ptr) ||
2444 ((r_ptr->flags3 & flg3) != 0) ||
2445 ((r_ptr->flags2 & flg2) != 0) ||
2446 (((~(r_ptr->flagsr) & flgr) != 0) && !(r_ptr->flagsr & RFR_RES_ALL));
2447 monster_pickup_object(target_ptr, turn_flags_ptr, m_idx, o_ptr, is_special_object, ny, nx, m_name, o_name, this_o_idx);
2453 * @brief オブジェクトのフラグを更新する
2455 void update_object_flags(BIT_FLAGS *flgs, BIT_FLAGS *flg2, BIT_FLAGS *flg3, BIT_FLAGS *flgr)
2457 if (have_flag(flgs, TR_SLAY_DRAGON)) *flg3 |= (RF3_DRAGON);
2458 if (have_flag(flgs, TR_KILL_DRAGON)) *flg3 |= (RF3_DRAGON);
2459 if (have_flag(flgs, TR_SLAY_TROLL)) *flg3 |= (RF3_TROLL);
2460 if (have_flag(flgs, TR_KILL_TROLL)) *flg3 |= (RF3_TROLL);
2461 if (have_flag(flgs, TR_SLAY_GIANT)) *flg3 |= (RF3_GIANT);
2462 if (have_flag(flgs, TR_KILL_GIANT)) *flg3 |= (RF3_GIANT);
2463 if (have_flag(flgs, TR_SLAY_ORC)) *flg3 |= (RF3_ORC);
2464 if (have_flag(flgs, TR_KILL_ORC)) *flg3 |= (RF3_ORC);
2465 if (have_flag(flgs, TR_SLAY_DEMON)) *flg3 |= (RF3_DEMON);
2466 if (have_flag(flgs, TR_KILL_DEMON)) *flg3 |= (RF3_DEMON);
2467 if (have_flag(flgs, TR_SLAY_UNDEAD)) *flg3 |= (RF3_UNDEAD);
2468 if (have_flag(flgs, TR_KILL_UNDEAD)) *flg3 |= (RF3_UNDEAD);
2469 if (have_flag(flgs, TR_SLAY_ANIMAL)) *flg3 |= (RF3_ANIMAL);
2470 if (have_flag(flgs, TR_KILL_ANIMAL)) *flg3 |= (RF3_ANIMAL);
2471 if (have_flag(flgs, TR_SLAY_EVIL)) *flg3 |= (RF3_EVIL);
2472 if (have_flag(flgs, TR_KILL_EVIL)) *flg3 |= (RF3_EVIL);
2473 if (have_flag(flgs, TR_SLAY_HUMAN)) *flg2 |= (RF2_HUMAN);
2474 if (have_flag(flgs, TR_KILL_HUMAN)) *flg2 |= (RF2_HUMAN);
2475 if (have_flag(flgs, TR_BRAND_ACID)) *flgr |= (RFR_IM_ACID);
2476 if (have_flag(flgs, TR_BRAND_ELEC)) *flgr |= (RFR_IM_ELEC);
2477 if (have_flag(flgs, TR_BRAND_FIRE)) *flgr |= (RFR_IM_FIRE);
2478 if (have_flag(flgs, TR_BRAND_COLD)) *flgr |= (RFR_IM_COLD);
2479 if (have_flag(flgs, TR_BRAND_POIS)) *flgr |= (RFR_IM_POIS);
2484 * @brief モンスターがアイテムを拾うか壊す処理
2485 * @param target_ptr プレーヤーへの参照ポインタ
2486 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2487 * @param m_idx モンスターID
2488 * @param o_ptr オブジェクトへの参照ポインタ
2489 * @param is_special_object モンスターが拾えないアイテム (アーティファクト等)であればTRUE
2490 * @param ny 移動後の、モンスターのY座標
2491 * @param nx 移動後の、モンスターのX座標
2492 * @param m_name モンスター名
2493 * @param o_name アイテム名
2494 * @param this_o_idx モンスターが乗ったオブジェクトID
2497 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)
2499 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2500 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2501 if (is_special_object)
2503 if (turn_flags_ptr->do_take && (r_ptr->flags2 & RF2_STUPID))
2505 turn_flags_ptr->did_take_item = TRUE;
2506 if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
2508 msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
2515 if (turn_flags_ptr->do_take)
2517 turn_flags_ptr->did_take_item = TRUE;
2518 if (player_can_see_bold(target_ptr, ny, nx))
2520 msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
2523 excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
2524 o_ptr->marked &= OM_TOUCHED;
2525 o_ptr->iy = o_ptr->ix = 0;
2526 o_ptr->held_m_idx = m_idx;
2527 o_ptr->next_o_idx = m_ptr->hold_o_idx;
2528 m_ptr->hold_o_idx = this_o_idx;
2532 if (is_pet(m_ptr)) return;
2534 turn_flags_ptr->did_kill_item = TRUE;
2535 if (player_has_los_bold(target_ptr, ny, nx))
2537 msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
2540 delete_object_idx(target_ptr, this_o_idx);
2545 * @brief updateフィールドを更新する
2546 * @param target_ptr プレーヤーへの参照ポインタ
2547 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2550 void update_player_type(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_race *r_ptr)
2552 if (turn_flags_ptr->do_view)
2554 target_ptr->update |= (PU_FLOW);
2555 target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2558 if (turn_flags_ptr->do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
2559 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !target_ptr->phase_out)))
2561 target_ptr->update |= (PU_MON_LITE);
2567 * @brief モンスターのフラグを更新する
2568 * @param target_ptr プレーヤーへの参照ポインタ
2569 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2570 * @param m_ptr モンスターへの参照ポインタ
2573 void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr)
2575 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2576 if (!is_original_ap_and_seen(target_ptr, m_ptr)) return;
2578 if (turn_flags_ptr->did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
2579 if (turn_flags_ptr->did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
2580 if (turn_flags_ptr->did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
2581 if (turn_flags_ptr->did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
2582 if (turn_flags_ptr->did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
2583 if (turn_flags_ptr->did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
2584 if (turn_flags_ptr->did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
2589 * @brief モンスターの恐怖状態を処理する
2590 * @param target_ptr プレーヤーへの参照ポインタ
2591 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
2592 * @param m_idx モンスターID
2593 * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
2594 * @return モンスターが戦いを決意したらTRUE
2596 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
2598 monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
2599 bool is_battle_determined = !turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && MON_MONFEAR(m_ptr) && turn_flags_ptr->aware;
2600 if (!is_battle_determined) return FALSE;
2602 (void)set_monster_monfear(target_ptr, m_idx, 0);
2603 if (!turn_flags_ptr->see_m) return TRUE;
2605 GAME_TEXT m_name[MAX_NLEN];
2606 monster_desc(target_ptr, m_name, m_ptr, 0);
2607 msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
2613 * @brief 全モンスターのターン管理メインルーチン /
2614 * Process all the "live" monsters, once per game turn.
2617 * During each game current game turn, we scan through the list of all the "live" monsters,\n
2618 * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
2619 * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
2621 * Note that monsters can never move in the monster array (except when the\n
2622 * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
2624 * This function is responsible for at least half of the processor time\n
2625 * on a normal system with a "normal" amount of monsters and a player doing\n
2628 * When the player is resting, virtually 90% of the processor time is spent\n
2629 * in this function, and its children, "process_monster()" and "make_move()".\n
2631 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
2632 * especially when the player is running.\n
2634 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
2635 * monsters while they are still being "born". A monster is "fresh" only\n
2636 * during the game turn in which it is created, and we use the "hack_m_idx" to\n
2637 * determine if the monster is yet to be processed during the game turn.\n
2639 * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
2640 * move before any "nasty" monsters get to use their spell attacks.\n
2642 * Note that when the "knowledge" about the currently tracked monster\n
2643 * changes (flags, attacks, spells), we induce a redraw of the monster\n
2646 void process_monsters(player_type *target_ptr)
2648 old_race_flags tmp_flags;
2649 old_race_flags *old_race_flags_ptr = init_old_race_flags(&tmp_flags);
2651 floor_type *floor_ptr = target_ptr->current_floor_ptr;
2652 floor_ptr->monster_noise = FALSE;
2654 MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
2655 save_old_race_flags(target_ptr, old_race_flags_ptr);
2656 sweep_monster_process(target_ptr);
2659 if (!target_ptr->monster_race_idx || (target_ptr->monster_race_idx != old_monster_race_idx))
2662 update_player_window(target_ptr, old_race_flags_ptr);
2667 * @brief old_race_flags_ptr の初期化
2669 old_race_flags *init_old_race_flags(old_race_flags *old_race_flags_ptr)
2671 old_race_flags_ptr->old_r_flags1 = 0L;
2672 old_race_flags_ptr->old_r_flags2 = 0L;
2673 old_race_flags_ptr->old_r_flags3 = 0L;
2674 old_race_flags_ptr->old_r_flags4 = 0L;
2675 old_race_flags_ptr->old_r_flags5 = 0L;
2676 old_race_flags_ptr->old_r_flags6 = 0L;
2677 old_race_flags_ptr->old_r_flagsr = 0L;
2679 old_race_flags_ptr->old_r_blows0 = 0;
2680 old_race_flags_ptr->old_r_blows1 = 0;
2681 old_race_flags_ptr->old_r_blows2 = 0;
2682 old_race_flags_ptr->old_r_blows3 = 0;
2684 old_race_flags_ptr->old_r_cast_spell = 0;
2685 return old_race_flags_ptr;
2690 * @brief 古いモンスター情報の保存
2691 * @param target_ptr プレーヤーへの参照ポインタ
2692 * @param old_race_flags_ptr モンスターフラグへの参照ポインタ
2695 void save_old_race_flags(player_type *target_ptr, old_race_flags *old_race_flags_ptr)
2697 if (target_ptr->monster_race_idx == 0) return;
2699 monster_race *r_ptr;
2700 r_ptr = &r_info[target_ptr->monster_race_idx];
2702 old_race_flags_ptr->old_r_flags1 = r_ptr->r_flags1;
2703 old_race_flags_ptr->old_r_flags2 = r_ptr->r_flags2;
2704 old_race_flags_ptr->old_r_flags3 = r_ptr->r_flags3;
2705 old_race_flags_ptr->old_r_flags4 = r_ptr->r_flags4;
2706 old_race_flags_ptr->old_r_flags5 = r_ptr->r_flags5;
2707 old_race_flags_ptr->old_r_flags6 = r_ptr->r_flags6;
2708 old_race_flags_ptr->old_r_flagsr = r_ptr->r_flagsr;
2710 old_race_flags_ptr->old_r_blows0 = r_ptr->r_blows[0];
2711 old_race_flags_ptr->old_r_blows1 = r_ptr->r_blows[1];
2712 old_race_flags_ptr->old_r_blows2 = r_ptr->r_blows[2];
2713 old_race_flags_ptr->old_r_blows3 = r_ptr->r_blows[3];
2715 old_race_flags_ptr->old_r_cast_spell = r_ptr->r_cast_spell;
2720 * @brief フロア内のモンスターについてターン終了時の処理を繰り返す
2721 * @param target_ptr プレーヤーへの参照ポインタ
2723 void sweep_monster_process(player_type *target_ptr)
2725 floor_type *floor_ptr = target_ptr->current_floor_ptr;
2726 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
2728 monster_type *m_ptr;
2729 monster_race *r_ptr;
2730 m_ptr = &floor_ptr->m_list[i];
2731 r_ptr = &r_info[m_ptr->r_idx];
2733 if (target_ptr->leaving) return;
2734 if (!monster_is_valid(m_ptr)) continue;
2735 if (target_ptr->wild_mode) continue;
2737 if (m_ptr->mflag & MFLAG_BORN)
2739 m_ptr->mflag &= ~(MFLAG_BORN);
2743 if (m_ptr->cdis >= AAF_LIMIT) continue;
2744 if (!decide_process_continue(target_ptr, m_ptr)) continue;
2746 SPEED speed = decide_monster_speed(target_ptr, m_ptr, i);
2747 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
2748 if (m_ptr->energy_need > 0) continue;
2750 m_ptr->energy_need += ENERGY_NEED();
2752 process_monster(target_ptr, i);
2753 reset_target(m_ptr);
2755 if (target_ptr->no_flowed && one_in_(3))
2756 m_ptr->mflag2 |= MFLAG2_NOFLOW;
2758 if (!target_ptr->playing || target_ptr->is_dead) return;
2759 if (target_ptr->leaving) return;
2765 * todo fy/fxへの代入は有効活用されていないはず
2766 * @brief 後続のモンスター処理が必要かどうか判定する (要調査)
2767 * @param target_ptr プレーヤーへの参照ポインタ
2768 * @param m_ptr モンスターへの参照ポインタ
2769 * @return 後続処理が必要ならTRUE
2771 bool decide_process_continue(player_type *target_ptr, monster_type *m_ptr)
2773 monster_race *r_ptr;
2774 r_ptr = &r_info[m_ptr->r_idx];
2775 POSITION fx = m_ptr->fx;
2776 POSITION fy = m_ptr->fy;
2777 if (!target_ptr->no_flowed)
2779 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
2782 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
2785 if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
2786 (player_has_los_bold(target_ptr, fy, fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
2789 if (m_ptr->target_y)
2797 * @brief モンスターの加速値を決定する
2798 * @param target_ptr プレーヤーへの参照ポインタ
2799 * @param m_ptr モンスターへの参照ポインタ
2800 * @param monster_number 走査中のモンスター番号
2803 SPEED decide_monster_speed(player_type *target_ptr, monster_type *m_ptr, int monster_number)
2806 if (target_ptr->riding == monster_number)
2808 speed = target_ptr->pspeed;
2812 speed = m_ptr->mspeed;
2813 if (ironman_nightmare) speed += 5;
2815 if (MON_FAST(m_ptr)) speed += 10;
2816 if (MON_SLOW(m_ptr)) speed -= 10;
2823 * @brief モンスターフラグの更新に基づき、モンスター表示を更新する
2824 * @param target_ptr プレーヤーへの参照ポインタ
2825 * @param old_race_flags_ptr モンスターフラグへの参照ポインタ
2828 void update_player_window(player_type *target_ptr, old_race_flags *old_race_flags_ptr)
2830 monster_race *r_ptr;
2831 r_ptr = &r_info[target_ptr->monster_race_idx];
2832 if ((old_race_flags_ptr->old_r_flags1 != r_ptr->r_flags1) ||
2833 (old_race_flags_ptr->old_r_flags2 != r_ptr->r_flags2) ||
2834 (old_race_flags_ptr->old_r_flags3 != r_ptr->r_flags3) ||
2835 (old_race_flags_ptr->old_r_flags4 != r_ptr->r_flags4) ||
2836 (old_race_flags_ptr->old_r_flags5 != r_ptr->r_flags5) ||
2837 (old_race_flags_ptr->old_r_flags6 != r_ptr->r_flags6) ||
2838 (old_race_flags_ptr->old_r_flagsr != r_ptr->r_flagsr) ||
2839 (old_race_flags_ptr->old_r_blows0 != r_ptr->r_blows[0]) ||
2840 (old_race_flags_ptr->old_r_blows1 != r_ptr->r_blows[1]) ||
2841 (old_race_flags_ptr->old_r_blows2 != r_ptr->r_blows[2]) ||
2842 (old_race_flags_ptr->old_r_blows3 != r_ptr->r_blows[3]) ||
2843 (old_race_flags_ptr->old_r_cast_spell != r_ptr->r_cast_spell))
2845 target_ptr->window |= (PW_MONSTER);