/*!
* @file monster-process.c
- * @brief モンスターの特殊技能と移動処理/ Monster spells and movement
+ * @brief モンスターの特殊技能とターン経過処理 (移動等)/ Monster spells and movement for passaging a turn
* @date 2014/01/17
* @author
* Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
#include "files.h"
#include "view-mainwindow.h"
+typedef struct {
+ bool is_riding_mon;
+ bool do_turn;
+ bool do_move;
+ bool do_view;
+ bool do_take;
+ bool must_alter_to_move;
+
+ bool did_open_door;
+ bool did_bash_door;
+ bool did_take_item;
+ bool did_kill_item;
+ bool did_move_body;
+ bool did_pass_wall;
+ bool did_kill_wall;
+} turn_flags;
+
+void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
+bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx);
+bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
+void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx);
+void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
+bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
+bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware);
+bool runaway_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon, bool see_m);
void process_special(player_type *target_ptr, MONSTER_IDX m_idx);
-bool multiply_monster(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
-void move_monster(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware);
+void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware);
+bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware);
+
+bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross);
+bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
+bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
+void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash);
+bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
+bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
+
+void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
+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);
+bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr);
+
+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);
+bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx);
+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);
+
+void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx);
/*!
* @brief モンスターが敵に接近するための方向を決める /
floor_type *floor_ptr = target_ptr->current_floor_ptr;
monster_type *m_ptr = &floor_ptr->m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
- monster_type *t_ptr;
POSITION x = 0, y = 0;
if (target_ptr->riding_t_m_idx && player_bold(target_ptr, m_ptr->fy, m_ptr->fx))
start = randint1(floor_ptr->m_max - 1) + floor_ptr->m_max;
if (randint0(2)) plus = -1;
}
- else start = floor_ptr->m_max + 1;
+ else
+ {
+ start = floor_ptr->m_max + 1;
+ }
- /* Scan thru all monsters */
for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus)
{
MONSTER_IDX dummy = (i % floor_ptr->m_max);
-
if (!dummy) continue;
MONSTER_IDX t_idx = dummy;
+ monster_type *t_ptr;
t_ptr = &floor_ptr->m_list[t_idx];
- /* The monster itself isn't a target */
if (t_ptr == m_ptr) continue;
-
if (!monster_is_valid(t_ptr)) continue;
if (is_pet(m_ptr))
{
- /* Hack -- only fight away from player */
if (target_ptr->pet_follow_distance < 0)
{
- /* No fighting near player */
if (t_ptr->cdis <= (0 - target_ptr->pet_follow_distance))
{
continue;
}
}
- /* Hack -- no fighting away from player */
else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > target_ptr->pet_follow_distance))
{
continue;
if (r_ptr->aaf < t_ptr->cdis) continue;
}
- /* Monster must be 'an enemy' */
if (!are_enemies(target_ptr, m_ptr, t_ptr)) continue;
- /* Monster must be projectable if we can't pass through walls */
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)))
{
if (!projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
}
- /* OK -- we've got a target */
y = t_ptr->fy;
x = t_ptr->fx;
if (!x && !y) return FALSE;
}
- /* Extract the direction */
x -= m_ptr->fx;
y -= m_ptr->fy;
- /* North */
+ /* North, South, East, West, North-West, North-East, South-West, South-East */
if ((y < 0) && (x == 0))
{
mm[0] = 8;
mm[1] = 7;
mm[2] = 9;
}
- /* South */
else if ((y > 0) && (x == 0))
{
mm[0] = 2;
mm[1] = 1;
mm[2] = 3;
}
- /* East */
else if ((x > 0) && (y == 0))
{
mm[0] = 6;
mm[1] = 9;
mm[2] = 3;
}
- /* West */
else if ((x < 0) && (y == 0))
{
mm[0] = 4;
mm[1] = 7;
mm[2] = 1;
}
- /* North-West */
else if ((y < 0) && (x < 0))
{
mm[0] = 7;
mm[1] = 4;
mm[2] = 8;
}
- /* North-East */
else if ((y < 0) && (x > 0))
{
mm[0] = 9;
mm[1] = 6;
mm[2] = 8;
}
- /* South-West */
else if ((y > 0) && (x < 0))
{
mm[0] = 1;
mm[1] = 4;
mm[2] = 2;
}
- /* South-East */
else if ((y > 0) && (x > 0))
{
mm[0] = 3;
return TRUE;
}
+
/*!
* @brief モンスターがプレイヤーから逃走するかどうかを返す /
* Returns whether a given monster will try to run from the player.
monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
- PLAYER_LEVEL p_lev;
- DEPTH m_lev;
- HIT_POINT p_chp, p_mhp;
- HIT_POINT m_chp, m_mhp;
- u32b p_val, m_val;
-
- /* Friends can be commanded to avoid the player */
if (is_pet(m_ptr))
{
- /* Are we trying to avoid the player? */
return ((target_ptr->pet_follow_distance < 0) &&
(m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
}
- /* Keep monsters from running too far away */
if (m_ptr->cdis > MAX_SIGHT + 5) return FALSE;
-
- /* All "afraid" monsters will run away */
if (MON_MONFEAR(m_ptr)) return TRUE;
-
- /* Nearby monsters will not become terrified */
if (m_ptr->cdis <= 5) return FALSE;
- /* Examine player power (level) */
- p_lev = target_ptr->lev;
-
- /* Examine monster power (level plus morale) */
- m_lev = r_ptr->level + (m_idx & 0x08) + 25;
-
- /* Optimize extreme cases below */
+ PLAYER_LEVEL p_lev = target_ptr->lev;
+ DEPTH m_lev = r_ptr->level + (m_idx & 0x08) + 25;
if (m_lev > p_lev + 4) return FALSE;
if (m_lev + 4 <= p_lev) return TRUE;
- /* Examine player health */
- p_chp = target_ptr->chp;
- p_mhp = target_ptr->mhp;
-
- /* Examine monster health */
- m_chp = m_ptr->hp;
- m_mhp = m_ptr->maxhp;
-
- /* Prepare to optimize the calculation */
- p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
- m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
-
- /* Strong players scare strong monsters */
+ HIT_POINT p_chp = target_ptr->chp;
+ HIT_POINT p_mhp = target_ptr->mhp;
+ HIT_POINT m_chp = m_ptr->hp;
+ HIT_POINT m_mhp = m_ptr->maxhp;
+ u32b p_val = (p_lev * p_mhp) + (p_chp << 2);
+ u32b m_val = (m_lev * m_mhp) + (m_chp << 2);
if (p_val * m_mhp > m_val * p_mhp) return TRUE;
return FALSE;
monster_type *m_ptr = &floor_ptr->m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
- /* Monster location */
POSITION y1 = m_ptr->fy;
POSITION x1 = m_ptr->fx;
- /* Monster can already cast spell to player */
if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x)) return FALSE;
- /* Set current grid cost */
int now_cost = floor_ptr->grid_array[y1][x1].cost;
if (now_cost == 0) now_cost = 999;
- /* Can monster bash or open doors? */
bool can_open_door = FALSE;
if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
{
can_open_door = TRUE;
}
- /* Check nearby grids, diagonals first */
int best = 999;
for (int i = 7; i >= 0; i--)
{
- int cost;
-
POSITION y = y1 + ddy_ddd[i];
POSITION x = x1 + ddx_ddd[i];
-
- /* Ignore locations off of edge */
if (!in_bounds2(floor_ptr, y, x)) continue;
-
- /* Simply move to player */
if (player_bold(target_ptr, y, x)) return FALSE;
grid_type *g_ptr;
g_ptr = &floor_ptr->grid_array[y][x];
-
- cost = g_ptr->cost;
-
- /* Monster cannot kill or pass walls */
+ int cost = g_ptr->cost;
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))))
{
if (cost == 0) continue;
if (!can_open_door && is_closed_door(target_ptr, g_ptr->feat)) continue;
}
- /* Hack -- for kill or pass wall monster.. */
if (cost == 0) cost = 998;
if (now_cost < cost) continue;
-
if (!projectable(target_ptr, y, x, target_ptr->y, target_ptr->x)) continue;
-
- /* Accept louder sounds */
if (best < cost) continue;
- best = cost;
- (*yp) = y1 + ddy_ddd[i];
- (*xp) = x1 + ddx_ddd[i];
+ best = cost;
+ *yp = y1 + ddy_ddd[i];
+ *xp = x1 + ddx_ddd[i];
}
if (best == 999) return FALSE;
monster_type *m_ptr = &floor_ptr->m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
- /* Can monster cast attack spell? */
if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
{
- /* Can move spell castable grid? */
if (get_moves_aux2(target_ptr, m_idx, yp, xp)) return TRUE;
}
- /* Monster can't flow */
if (no_flow) return FALSE;
-
- /* Monster can go through rocks */
if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) return FALSE;
if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)) return FALSE;
- /* Monster location */
POSITION y1 = m_ptr->fy;
POSITION x1 = m_ptr->fx;
-
- /* Hack -- Player can see us, run towards him */
if (player_has_los_bold(target_ptr, y1, x1) && projectable(target_ptr, target_ptr->y, target_ptr->x, y1, x1)) return FALSE;
- /* Monster grid */
g_ptr = &floor_ptr->grid_array[y1][x1];
- /* If we can hear noises, advance towards them */
int best;
bool use_scent = FALSE;
if (g_ptr->cost)
{
best = 999;
}
-
- /* Otherwise, try to follow a scent trail */
else if (g_ptr->when)
{
- /* Too old smell */
if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when - g_ptr->when > 127) return FALSE;
use_scent = TRUE;
best = 0;
}
-
- /* Otherwise, advance blindly */
else
{
return FALSE;
}
- /* Check nearby grids, diagonals first */
for (int i = 7; i >= 0; i--)
{
POSITION y = y1 + ddy_ddd[i];
POSITION x = x1 + ddx_ddd[i];
- /* Ignore locations off of edge */
if (!in_bounds2(floor_ptr, y, x)) continue;
g_ptr = &floor_ptr->grid_array[y][x];
-
- /* We're following a scent trail */
if (use_scent)
{
int when = g_ptr->when;
-
- /* Accept younger scent */
if (best > when) continue;
+
best = when;
}
-
- /* We're using sound */
else
{
int cost;
-
if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
+ {
cost = g_ptr->dist;
- else cost = g_ptr->cost;
+ }
+ else
+ {
+ cost = g_ptr->cost;
+ }
- /* Accept louder sounds */
if ((cost == 0) || (best < cost)) continue;
+
best = cost;
}
- /* Hack -- Save the "twiddled" location */
- (*yp) = target_ptr->y + 16 * ddy_ddd[i];
- (*xp) = target_ptr->x + 16 * ddx_ddd[i];
+ *yp = target_ptr->y + 16 * ddy_ddd[i];
+ *xp = target_ptr->x + 16 * ddx_ddd[i];
}
if (best == 999 || best == 0) return FALSE;
{
POSITION gy = 0, gx = 0;
- /* Monster location */
monster_type *m_ptr = &floor_ptr->m_list[m_idx];
POSITION fy = m_ptr->fy;
POSITION fx = m_ptr->fx;
- /* Desired destination */
POSITION y1 = fy - (*yp);
POSITION x1 = fx - (*xp);
- /* Check nearby grids, diagonals first */
int score = -1;
for (int i = 7; i >= 0; i--)
{
- POSITION dis, s;
POSITION y = fy + ddy_ddd[i];
POSITION x = fx + ddx_ddd[i];
-
- /* Ignore locations off of edge */
if (!in_bounds2(floor_ptr, y, x)) continue;
- /* Calculate distance of this grid from our destination */
- dis = distance(y, x, y1, x1);
-
- /* Score this grid */
- s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
-
- /* No negative scores */
+ POSITION dis = distance(y, x, y1, x1);
+ POSITION s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
if (s < 0) s = 0;
- /* Ignore lower scores */
if (s < score) continue;
- /* Save the score and time */
score = s;
-
- /* Save the location */
gy = y;
gx = x;
}
- /* No legal move (?) */
if (score == -1) return FALSE;
- /* Find deltas */
(*yp) = fy - gy;
(*xp) = fx - gx;
- /* Success */
return TRUE;
}
+
/*
* Hack -- Precompute a bunch of calls to distance() in find_safety() and
* find_hiding().
POSITION gy = 0, gx = 0, gdis = 0;
- /* Start with adjacent locations, spread further */
for (POSITION d = 1; d < 10; d++)
{
- /* Get the lists of points with a distance d from (fx, fy) */
POSITION *y_offsets;
y_offsets = dist_offsets_y[d];
POSITION *x_offsets;
x_offsets = dist_offsets_x[d];
- /* Check the locations */
for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
dx != 0 || dy != 0;
i++, dx = x_offsets[i], dy = y_offsets[i])
{
POSITION y = fy + dy;
POSITION x = fx + dx;
-
- /* Skip illegal locations */
if (!in_bounds(floor_ptr, y, x)) continue;
grid_type *g_ptr;
g_ptr = &floor_ptr->grid_array[y][x];
- /* Skip locations in a wall */
- if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], (m_idx == target_ptr->riding) ? CEM_RIDING : 0)) continue;
+ BIT_FLAGS16 riding_mode = (m_idx == target_ptr->riding) ? CEM_RIDING : 0;
+ if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], riding_mode))
+ continue;
- /* Check for "availability" (if monsters can flow) */
if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
{
- /* Ignore grids very far from the player */
if (g_ptr->dist == 0) continue;
-
- /* Ignore too-distant grids */
if (g_ptr->dist > floor_ptr->grid_array[fy][fx].dist + 2 * d) continue;
}
- /* Check for absence of shot (more or less) */
if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x)) continue;
- /* Calculate distance from player */
POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
-
- /* Remember if further than previous */
if (dis <= gdis) continue;
gy = y;
gdis = dis;
}
- /* Check for success */
if (gdis <= 0) continue;
- /* Good location */
- (*yp) = fy - gy;
- (*xp) = fx - gx;
+ *yp = fy - gy;
+ *xp = fx - gx;
return TRUE;
}
POSITION gy = 0, gx = 0, gdis = 999;
- /* Start with adjacent locations, spread further */
for (POSITION d = 1; d < 10; d++)
{
- /* Get the lists of points with a distance d from (fx, fy) */
POSITION *y_offsets;
y_offsets = dist_offsets_y[d];
POSITION *x_offsets;
x_offsets = dist_offsets_x[d];
- /* Check the locations */
for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
dx != 0 || dy != 0;
i++, dx = x_offsets[i], dy = y_offsets[i])
POSITION y = fy + dy;
POSITION x = fx + dx;
- /* Skip illegal locations */
if (!in_bounds(floor_ptr, y, x)) continue;
-
- /* Skip occupied locations */
if (!monster_can_enter(target_ptr, y, x, r_ptr, 0)) continue;
-
- /* Check for hidden, available grid */
if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, fy, fx, y, x, FALSE))
continue;
- /* Calculate distance from player */
POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
-
- /* Remember if closer than previous */
if (dis < gdis && dis >= 2)
{
gy = y;
monster_type *m_ptr = &floor_ptr->m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
POSITION y = 0, ay, x = 0, ax;
- int move_val = 0;
POSITION y2 = target_ptr->y;
POSITION x2 = target_ptr->x;
bool done = FALSE;
bool will_run = mon_will_run(target_ptr, m_idx);
grid_type *g_ptr;
- bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2));
- bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall));
+ bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) != 0) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2);
+ bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) != 0) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall);
- /* Counter attack to an enemy monster */
if (!will_run && m_ptr->target_y)
{
int t_m_idx = floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
-
- /* The monster must be an enemy, and in LOS */
- if (t_m_idx &&
+ if ((t_m_idx > 0) &&
are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[t_m_idx]) &&
los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
{
- /* Extract the "pseudo-direction" */
y = m_ptr->fy - m_ptr->target_y;
x = m_ptr->fx - m_ptr->target_x;
done = TRUE;
((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)) ||
(floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
{
- /*
- * Animal packs try to get the player out of corridors
- * (...unless they can move through walls -- TY)
- */
if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
!(r_ptr->flags2 & RF2_KILL_WALL))
{
- int i, room = 0;
-
- /* Count room grids next to player */
- for (i = 0; i < 8; i++)
+ int room = 0;
+ for (int i = 0; i < 8; i++)
{
int xx = target_ptr->x + ddx_ddd[i];
int yy = target_ptr->y + ddy_ddd[i];
if (!in_bounds2(floor_ptr, yy, xx)) continue;
g_ptr = &floor_ptr->grid_array[yy][xx];
-
- /* Check grid */
if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0))
{
- /* One more room grid */
room++;
}
}
+
if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].info & CAVE_ROOM) room -= 2;
if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
- /* Not in a room and strong player */
if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
(target_ptr->mhp + target_ptr->msp))
{
- /* Find hiding place */
if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
}
}
- /* Monster groups try to surround the player */
if (!done && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
{
- int i;
-
- /* Find an empty square near the player to fill */
- for (i = 0; i < 8; i++)
+ for (int i = 0; i < 8; i++)
{
- /* Pick squares near player (semi-randomly) */
y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
-
- /* Already there? */
if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
{
- /* Attack the player */
y2 = target_ptr->y;
x2 = target_ptr->x;
-
break;
}
if (!in_bounds2(floor_ptr, y2, x2)) continue;
-
- /* Ignore filled grids */
if (!monster_can_enter(target_ptr, y2, x2, r_ptr, 0)) continue;
- /* Try to fill this hole */
break;
}
- /* Extract the new "pseudo-direction" */
y = m_ptr->fy - y2;
x = m_ptr->fx - x2;
-
done = TRUE;
}
}
if (!done)
{
- /* Flow towards the player */
(void)get_moves_aux(target_ptr, m_idx, &y2, &x2, no_flow);
-
- /* Extract the "pseudo-direction" */
y = m_ptr->fy - y2;
x = m_ptr->fx - x2;
-
- /* Not done */
}
- /* Apply fear if possible and necessary */
if (is_pet(m_ptr) && will_run)
{
- /* XXX XXX Not very "smart" */
y = (-y), x = (-x);
}
else
{
int tmp_x = (-x);
int tmp_y = (-y);
-
- /* Try to find safe place */
- if (find_safety(target_ptr, m_idx, &y, &x))
+ if (find_safety(target_ptr, m_idx, &y, &x) && !no_flow)
{
- /* Attempt to avoid the player */
- if (!no_flow)
- {
- /* Adjust movement */
- if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x)) done = TRUE;
- }
+ if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x))
+ done = TRUE;
}
if (!done)
{
- /* This is not a very "smart" method XXX XXX */
y = tmp_y;
x = tmp_x;
}
}
}
-
- /* Check for no move */
if (!x && !y) return FALSE;
-
- /* Extract the "absolute distances" */
ax = ABS(x);
ay = ABS(y);
- /* Do something weird */
+ int move_val = 0;
if (y < 0) move_val += 8;
if (x > 0) move_val += 4;
- /* Prevent the diamond maneuvre */
if (ay > (ax << 1)) move_val += 2;
else if (ax > (ay << 1)) move_val++;
- /* Extract some directions */
switch (move_val)
{
case 0:
break;
}
- /* Wants to move... */
return TRUE;
}
{
monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
- monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
-
- int i, d;
- POSITION oy, ox, ny, nx;
-
DIRECTION mm[8];
- grid_type *g_ptr;
- feature_type *f_ptr;
- monster_type *y_ptr;
-
- bool do_turn;
- bool do_move;
- bool do_view;
- bool must_alter_to_move;
-
- bool did_open_door;
- bool did_bash_door;
- bool did_take_item;
- bool did_kill_item;
- bool did_move_body;
- bool did_pass_wall;
- bool did_kill_wall;
- bool gets_angry = FALSE;
- bool can_cross;
- bool aware = TRUE;
+ turn_flags tmp_flags;
+ turn_flags *turn_flags_ptr = &tmp_flags;
+ turn_flags_ptr->is_riding_mon = (m_idx == target_ptr->riding);
+ turn_flags_ptr->do_turn = FALSE;
+ turn_flags_ptr->do_move = FALSE;
+ turn_flags_ptr->do_view = FALSE;
+ turn_flags_ptr->must_alter_to_move = FALSE;
+ turn_flags_ptr->did_open_door = FALSE;
+ turn_flags_ptr->did_bash_door = FALSE;
+ turn_flags_ptr->did_take_item = FALSE;
+ turn_flags_ptr->did_kill_item = FALSE;
+ turn_flags_ptr->did_move_body = FALSE;
+ turn_flags_ptr->did_pass_wall = FALSE;
+ turn_flags_ptr->did_kill_wall = FALSE;
- bool fear, dead;
- bool is_riding_mon = (m_idx == target_ptr->riding);
bool see_m = is_seen(m_ptr);
- if (is_riding_mon && !(r_ptr->flags7 & RF7_RIDING))
- {
- if (rakuba(target_ptr, 0, TRUE))
- {
-#ifdef JP
- msg_print("地面に落とされた。");
-#else
- GAME_TEXT m_name[MAX_NLEN];
- monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
- msg_format("You have fallen from %s.", m_name);
-#endif
- }
- }
-
+ decide_drop_from_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon);
if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
{
choose_new_monster(target_ptr, m_idx, FALSE, 0);
r_ptr = &r_info[m_ptr->r_idx];
}
- /* Players hidden in shadow are almost imperceptable. -LM- */
- if (target_ptr->special_defense & NINJA_S_STEALTH)
- {
- int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
- if (target_ptr->monlite) tmp /= 3;
- if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
- if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
- /* Low-level monsters will find it difficult to locate the player. */
- if (randint0(tmp) > (r_ptr->level + 20)) aware = FALSE;
- }
-
- /* Are there its parent? */
- if (m_ptr->parent_m_idx && !target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx)
- {
- /* Its parent have gone, it also goes away. */
-
- if (see_m)
- {
- GAME_TEXT m_name[MAX_NLEN];
- monster_desc(target_ptr, m_name, m_ptr, 0);
- msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
- }
-
- if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
- {
- GAME_TEXT m_name[MAX_NLEN];
- monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
- exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
- }
-
- delete_monster_idx(target_ptr, m_idx);
-
- return;
- }
+ bool aware = process_stealth(target_ptr, m_idx);
+ if (vanish_summoned_children(target_ptr, m_idx, see_m)) return;
if (process_quantum_effect(target_ptr,m_idx, see_m)) return;
if (m_ptr->r_idx == MON_SHURYUUDAN)
{
+ bool fear, dead;
mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
if (dead) return;
}
- if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) && !target_ptr->phase_out)
+ if (runaway_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon, see_m)) return;
+
+ awake_monster(target_ptr, m_idx);
+
+ if (MON_STUNNED(m_ptr))
{
- static int riding_pinch = 0;
+ if (one_in_(2)) return;
+ }
- if (m_ptr->hp < m_ptr->maxhp / 3)
- {
- GAME_TEXT m_name[MAX_NLEN];
- monster_desc(target_ptr, m_name, m_ptr, 0);
+ if (turn_flags_ptr->is_riding_mon)
+ {
+ target_ptr->update |= (PU_BONUS);
+ }
- if (is_riding_mon && riding_pinch < 2)
- {
- msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
- "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
- riding_pinch++;
- disturb(target_ptr, TRUE, TRUE);
- }
- else
- {
- if (is_riding_mon)
- {
- msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
- if (rakuba(target_ptr, -1, FALSE))
- {
- msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
- }
- }
+ process_angar(target_ptr, m_idx, see_m);
- if (see_m)
- {
- 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) &&
- 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))
- {
- msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
- }
- msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s reads a scroll of teleport level."), m_name);
- msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
- }
+ POSITION oy = m_ptr->fy;
+ POSITION ox = m_ptr->fx;
+ if (decide_monster_multiplication(target_ptr, m_idx, oy, ox)) return;
- if (is_riding_mon && rakuba(target_ptr, -1, FALSE))
- {
- msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
- }
+ process_special(target_ptr, m_idx);
+ process_speak_sound(target_ptr, m_idx, oy, ox, aware);
+ if (cast_spell(target_ptr, m_idx, aware)) return;
- check_quest_completion(target_ptr, m_ptr);
- delete_monster_idx(target_ptr, m_idx);
- return;
- }
- }
- else
- {
- /* Reset the counter */
- if (is_riding_mon) riding_pinch = 0;
- }
- }
+ mm[0] = mm[1] = mm[2] = mm[3] = 0;
+ mm[4] = mm[5] = mm[6] = mm[7] = 0;
- /* Handle "sleep" */
- if (MON_CSLEEP(m_ptr))
- {
- /* Handle non-aggravation - Still sleeping */
- if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
+ if (!decide_monster_movement_direction(target_ptr, mm, m_idx, aware)) return;
- (void)set_monster_csleep(target_ptr, m_idx, 0);
+ int count = 0;
+ if(!process_monster_movement(target_ptr, turn_flags_ptr, m_idx, mm, oy, ox, &count)) return;
- /* Notice the "waking up" */
- if (m_ptr->ml)
- {
- GAME_TEXT m_name[MAX_NLEN];
- monster_desc(target_ptr, m_name, m_ptr, 0);
- msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
- }
+ /*
+ * Forward movements failed, but now received LOS attack!
+ * Try to flow by smell.
+ */
+ if (target_ptr->no_flowed && count > 2 && m_ptr->target_y)
+ m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
- /* Hack -- Count the wakings */
- if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
+ if (!turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && !MON_MONFEAR(m_ptr) && !turn_flags_ptr->is_riding_mon && aware)
+ {
+ if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
{
- r_ptr->r_wake++;
+ if (make_attack_spell(m_idx, target_ptr)) return;
}
}
- /* Handle "stun" */
- if (MON_STUNNED(m_ptr))
+ if (turn_flags_ptr->do_view)
{
- /* Sometimes skip move */
- if (one_in_(2)) return;
+ target_ptr->update |= (PU_FLOW);
+ target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
}
- if (is_riding_mon)
+ if (turn_flags_ptr->do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
+ || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !target_ptr->phase_out)))
{
- target_ptr->update |= (PU_BONUS);
+ target_ptr->update |= (PU_MON_LITE);
}
- /* No one wants to be your friend if you're aggravating */
- if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
- gets_angry = TRUE;
-
- /* Paranoia... no pet uniques outside wizard mode -- TY */
- if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
- monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
+ if (is_original_ap_and_seen(target_ptr, m_ptr))
{
- gets_angry = TRUE;
+ if (turn_flags_ptr->did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
+ if (turn_flags_ptr->did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
+ if (turn_flags_ptr->did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
+ if (turn_flags_ptr->did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
+ if (turn_flags_ptr->did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
+ if (turn_flags_ptr->did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
+ if (turn_flags_ptr->did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
}
- if (target_ptr->phase_out) gets_angry = FALSE;
+ bool is_battle_determined = !turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && MON_MONFEAR(m_ptr) && aware;
+ if (!is_battle_determined) return;
- if (gets_angry)
+ (void)set_monster_monfear(target_ptr, m_idx, 0);
+ if (see_m)
{
- if (is_pet(m_ptr) || see_m)
- {
- GAME_TEXT m_name[MAX_NLEN];
- monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
- msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
- }
-
- set_hostile(target_ptr, m_ptr);
+ GAME_TEXT m_name[MAX_NLEN];
+ monster_desc(target_ptr, m_name, m_ptr, 0);
+ msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
}
- /* Get the origin */
- oy = m_ptr->fy;
- ox = m_ptr->fx;
+ if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
+}
- if (multiply_monster(target_ptr, m_idx, oy, ox)) return;
- process_special(target_ptr, m_idx);
+/*!
+ * @brief 超隠密処理 (のはず todo)
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @return モンスターがプレーヤーを感知していればFALSE? (todo 要調査)
+ */
+bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx)
+{
+ if ((target_ptr->special_defense & NINJA_S_STEALTH) == 0) return TRUE;
- if (!target_ptr->phase_out)
- {
- /* Hack! "Cyber" monster makes noise... */
- if (m_ptr->ap_r_idx == MON_CYBER &&
- one_in_(CYBERNOISE) &&
- !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
- {
- if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
- msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
- }
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
+ if (target_ptr->monlite) tmp /= 3;
+ if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
+ if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
+ return (randint0(tmp) <= (r_ptr->level + 20));
+}
- /* Some monsters can speak */
- if ((ap_r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
- one_in_(SPEAK_CHANCE) &&
- player_has_los_bold(target_ptr, oy, ox) &&
- projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
- {
- GAME_TEXT m_name[MAX_NLEN];
- char monmessage[1024];
- concptr filename;
- /* Acquire the monster name/poss */
- if (m_ptr->ml)
- monster_desc(target_ptr, m_name, m_ptr, 0);
- else
- strcpy(m_name, _("それ", "It"));
-
- /* Select the file for monster quotes */
- if (MON_MONFEAR(m_ptr))
- filename = _("monfear_j.txt", "monfear.txt");
- else if (is_pet(m_ptr))
- filename = _("monpet_j.txt", "monpet.txt");
- else if (is_friendly(m_ptr))
- filename = _("monfrien_j.txt", "monfrien.txt");
- else
- filename = _("monspeak_j.txt", "monspeak.txt");
- /* Get the monster line */
- if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
- {
- /* Say something */
- msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
- }
- }
- }
+/*!
+ * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param is_riding_mon 騎乗中であればTRUE
+ * @return なし
+ */
+void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ if (!is_riding_mon || ((r_ptr->flags7 & RF7_RIDING) != 0)) return;
- /* Try to cast spell occasionally */
- if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
+ if (rakuba(target_ptr, 0, TRUE))
{
- bool counterattack = FALSE;
-
- /* Give priority to counter attack? */
- if (m_ptr->target_y)
- {
- MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
+#ifdef JP
+ msg_print("地面に落とされた。");
+#else
+ GAME_TEXT m_name[MAX_NLEN];
+ monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
+ msg_format("You have fallen from %s.", m_name);
+#endif
+ }
+}
- /* The monster must be an enemy, and projectable */
- if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
- projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
- {
- counterattack = TRUE;
- }
- }
- if (!counterattack)
- {
- /* Attempt to cast a spell */
- if (aware && make_attack_spell(m_idx, target_ptr)) return;
-
- /*
- * Attempt to cast a spell at an enemy other than the player
- * (may slow the game a smidgeon, but I haven't noticed.)
- */
- if (monst_spell_monst(target_ptr, m_idx)) return;
- }
- else
- {
- /* Attempt to do counter attack at first */
- if (monst_spell_monst(target_ptr, m_idx)) return;
+/*!
+ * @brief 召喚の親元が消滅した時、子供も消滅させる
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param see_m モンスターが視界内にいたらTRUE
+ * @return 召喚モンスターが消滅したらTRUE
+ */
+bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ if ((m_ptr->parent_m_idx == 0) || (target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx > 0))
+ return FALSE;
- if (aware && make_attack_spell(m_idx, target_ptr)) return;
- }
+ if (see_m)
+ {
+ GAME_TEXT m_name[MAX_NLEN];
+ monster_desc(target_ptr, m_name, m_ptr, 0);
+ msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
}
- /* Hack -- Assume no movement */
- mm[0] = mm[1] = mm[2] = mm[3] = 0;
- mm[4] = mm[5] = mm[6] = mm[7] = 0;
+ if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
+ {
+ GAME_TEXT m_name[MAX_NLEN];
+ monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
+ exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
+ }
- move_monster(target_ptr, mm, m_idx, aware);
+ delete_monster_idx(target_ptr, m_idx);
+ return TRUE;
+}
- /* Assume nothing */
- do_turn = FALSE;
- do_move = FALSE;
- do_view = FALSE;
- must_alter_to_move = FALSE;
- /* Assume nothing */
- did_open_door = FALSE;
- did_bash_door = FALSE;
- did_take_item = FALSE;
- did_kill_item = FALSE;
- did_move_body = FALSE;
- did_pass_wall = FALSE;
- did_kill_wall = FALSE;
+/*!
+ * @brief 寝ているモンスターの起床を判定する
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @return なし
+ */
+void awake_monster(player_type *target_ptr, MONSTER_IDX m_idx)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ if (!MON_CSLEEP(m_ptr)) return;
+ if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
- /* Take a zero-terminated array of "directions" */
- for (i = 0; mm[i]; i++)
+ (void)set_monster_csleep(target_ptr, m_idx, 0);
+ if (m_ptr->ml)
{
- /* Get the direction */
- d = mm[i];
+ GAME_TEXT m_name[MAX_NLEN];
+ monster_desc(target_ptr, m_name, m_ptr, 0);
+ msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
+ }
- /* Hack -- allow "randomized" motion */
- if (d == 5) d = ddd[randint0(8)];
+ if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
+ {
+ r_ptr->r_wake++;
+ }
+}
- /* Get the destination */
- ny = oy + ddy[d];
- nx = ox + ddx[d];
- /* Ignore locations off of edge */
- if (!in_bounds2(target_ptr->current_floor_ptr, ny, nx)) continue;
+/*!
+ * @brief モンスターの怒り状態を判定する (起こっていたら敵に回す)
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param see_m モンスターが視界内にいたらTRUE
+ * @return なし
+ */
+void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ bool gets_angry = FALSE;
+ if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
+ gets_angry = TRUE;
- /* Access that grid */
- g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
- f_ptr = &f_info[g_ptr->feat];
- can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0);
+ if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
+ monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
+ {
+ gets_angry = TRUE;
+ }
- /* Access that grid's contents */
- y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
+ if (target_ptr->phase_out || !gets_angry) return;
- /* Hack -- player 'in' wall */
- if (player_bold(target_ptr, ny, nx))
- {
- do_move = TRUE;
- }
+ if (is_pet(m_ptr) || see_m)
+ {
+ GAME_TEXT m_name[MAX_NLEN];
+ monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
+ msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
+ }
- /* Possibly a monster to attack */
- else if (g_ptr->m_idx)
- {
- do_move = TRUE;
- }
+ set_hostile(target_ptr, m_ptr);
+}
- /* Monster destroys walls (and doors) */
- else if ((r_ptr->flags2 & RF2_KILL_WALL) &&
- (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !is_riding_mon) &&
- have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
- check_hp_for_feat_destruction(f_ptr, m_ptr))
- {
- /* Eat through walls/doors/rubble */
- do_move = TRUE;
- if (!can_cross) must_alter_to_move = TRUE;
- /* Monster destroyed a wall (later) */
- did_kill_wall = TRUE;
- }
+/*!
+ * @brief 量子生物の量子的効果を実行する
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param see_m モンスターが視界内にいたらTRUE
+ * @return モンスターが量子的効果により消滅したらTRUE
+ */
+bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ if ((r_ptr->flags2 & RF2_QUANTUM) == 0) return FALSE;
+ if (!randint0(2)) return FALSE;
+ if (randint0((m_idx % 100) + 10)) return FALSE;
- /* Floor is open? */
- else if (can_cross)
- {
- /* Go ahead and move */
- do_move = TRUE;
+ bool can_disappear = (r_ptr->flags1 & RF1_UNIQUE) == 0;
+ can_disappear &= (r_ptr->flags1 & RF1_QUESTOR) == 0;
+ if (can_disappear)
+ {
+ vanish_nonunique(target_ptr, m_idx, see_m);
+ return TRUE;
+ }
+
+ produce_quantum_effect(target_ptr, m_idx, see_m);
+ return FALSE;
+}
- /* Monster moves through walls (and doors) */
- if ((r_ptr->flags2 & RF2_PASS_WALL) && (!is_riding_mon || target_ptr->pass_wall) &&
- have_flag(f_ptr->flags, FF_CAN_PASS))
- {
- /* Monster went through a wall */
- did_pass_wall = TRUE;
- }
- }
- /* Handle doors and secret doors */
- else if (is_closed_door(target_ptr, g_ptr->feat))
- {
- bool may_bash = TRUE;
+/*!
+ * @brief ユニークでない量子生物を消滅させる
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param see_m モンスターが視界内にいたらTRUE
+ * @return なし
+ */
+void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ if (see_m)
+ {
+ GAME_TEXT m_name[MAX_NLEN];
+ monster_desc(target_ptr, m_name, m_ptr, 0);
+ msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
+ }
- /* Assume no move allowed */
- do_move = FALSE;
+ monster_death(target_ptr, m_idx, FALSE);
+ delete_monster_idx(target_ptr, m_idx);
+ if (is_pet(m_ptr) && !(m_ptr->ml))
+ {
+ msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
+ }
+}
- /* Creature can open doors. */
- if ((r_ptr->flags2 & RF2_OPEN_DOOR) && have_flag(f_ptr->flags, FF_OPEN) &&
- (!is_pet(m_ptr) || (target_ptr->pet_extra_flags & PF_OPEN_DOORS)))
- {
- /* Closed doors */
- if (!f_ptr->power)
- {
- /* The door is open */
- did_open_door = TRUE;
- /* Do not bash the door */
- may_bash = FALSE;
+/*!
+ * @brief 量子生物ユニークの量子的効果 (ショート・テレポートまたは距離10のテレポート・アウェイ)を実行する
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param see_m モンスターが視界内にいたらTRUE
+ * @return なし
+ * @details
+ * プレーヤーが量子生物を観測しているか、量子生物がプレーヤーを観測している場合、互いの相対的な位置を確定させる
+ * 波動関数の収縮はテレポートではないので反テレポート無効
+ * todo パターンは収縮どころか拡散しているが、この際気にしてはいけない
+ */
+void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ bool coherent = los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x);
+ if (!see_m && !coherent) return;
- do_turn = TRUE;
- }
+ if (see_m)
+ {
+ GAME_TEXT m_name[MAX_NLEN];
+ monster_desc(target_ptr, m_name, m_ptr, 0);
+ msg_format(_("%sは量子的効果を起こした!", "%^s produced a decoherence!"), m_name);
+ }
+ else
+ {
+ msg_print(_("量子的効果が起こった!", "A decoherence was produced!"));
+ }
- /* Locked doors (not jammed) */
- else
- {
- /* Try to unlock it */
- if (randint0(m_ptr->hp / 10) > f_ptr->power)
- {
- /* Unlock the door */
- cave_alter_feat(target_ptr, ny, nx, FF_DISARM);
+ bool target = one_in_(2);
+ const int blink = 32 * 5 + 4;
+ if (target)
+ {
+ (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx);
- /* Do not bash the door */
- may_bash = FALSE;
+ }
+ else
+ {
+ teleport_player_away(m_idx, target_ptr, 10, TRUE);
+ }
+}
- do_turn = TRUE;
- }
- }
- }
- /* Stuck doors -- attempt to bash them down if allowed */
- if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) && have_flag(f_ptr->flags, FF_BASH) &&
- (!is_pet(m_ptr) || (target_ptr->pet_extra_flags & PF_OPEN_DOORS)))
- {
- /* Attempt to Bash */
- if (check_hp_for_feat_destruction(f_ptr, m_ptr) && (randint0(m_ptr->hp / 10) > f_ptr->power))
- {
- if (have_flag(f_ptr->flags, FF_GLASS))
- msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
- else
- msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
+/*!
+ * @brief モンスター依存の特別な行動を取らせる
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ */
+void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
+ if (m_ptr->r_idx != MON_OHMU) return;
+ if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
+ if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
- /* Disturb (sometimes) */
- if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
+ int count = 0;
+ DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
+ BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
- /* The door was bashed open */
- did_bash_door = TRUE;
+ for (int k = 0; k < A_MAX; k++)
+ {
+ if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
+ {
+ if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
+ }
+ }
- /* Hack -- fall into doorway */
- do_move = TRUE;
- must_alter_to_move = TRUE;
- }
- }
+ if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
+}
- /* Deal with doors in the way */
- if (did_open_door || did_bash_door)
- {
- /* Break down the door */
- if (did_bash_door && ((randint0(100) < 50) || (feat_state(target_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
- {
- cave_alter_feat(target_ptr, ny, nx, FF_BASH);
+/*!
+ * @brief モンスターを喋らせたり足音を立てたりする
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param oy モンスターが元々いたY座標
+ * @param ox モンスターが元々いたX座標
+ * @param aware 起きていればTRUE
+ * @return なし
+ */
+void process_speak_sound(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware)
+{
+ if (target_ptr->phase_out) return;
- if (!monster_is_valid(m_ptr)) /* Killed by shards of glass, etc. */
- {
- target_ptr->update |= (PU_FLOW);
- target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
- if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
+ if (m_ptr->ap_r_idx == MON_CYBER &&
+ one_in_(CYBERNOISE) &&
+ !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
+ {
+ if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
+ msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
+ }
- return;
- }
- }
+ if (((ap_r_ptr->flags2 & RF2_CAN_SPEAK) == 0) || !aware ||
+ !one_in_(SPEAK_CHANCE) ||
+ !player_has_los_bold(target_ptr, oy, ox) ||
+ !projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
+ return;
- /* Open the door */
- else
- {
- cave_alter_feat(target_ptr, ny, nx, FF_OPEN);
- }
+ GAME_TEXT m_name[MAX_NLEN];
+ char monmessage[1024];
+ concptr filename;
- f_ptr = &f_info[g_ptr->feat];
+ if (m_ptr->ml)
+ monster_desc(target_ptr, m_name, m_ptr, 0);
+ else
+ strcpy(m_name, _("それ", "It"));
- /* Handle viewable doors */
- do_view = TRUE;
- }
- }
+ if (MON_MONFEAR(m_ptr))
+ filename = _("monfear_j.txt", "monfear.txt");
+ else if (is_pet(m_ptr))
+ filename = _("monpet_j.txt", "monpet.txt");
+ else if (is_friendly(m_ptr))
+ filename = _("monfrien_j.txt", "monfrien.txt");
+ else
+ filename = _("monspeak_j.txt", "monspeak.txt");
- /* Hack -- check for Glyph of Warding */
- if (do_move && is_glyph_grid(g_ptr) &&
- !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(target_ptr, ny, nx)))
- {
- /* Assume no move allowed */
- do_move = FALSE;
+ if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
+ {
+ msg_format(_("%^s%s", "%^s %s"), m_name, monmessage);
+ }
+}
- /* Break the ward */
- if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
- {
- /* Describe observable breakage */
- if (g_ptr->info & CAVE_MARK)
- {
- msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
- }
- /* Forget the rune */
- g_ptr->info &= ~(CAVE_MARK);
+/*!
+ * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param oy 分裂元モンスターのY座標
+ * @param ox 分裂元モンスターのX座標
+ * @return 実際に分裂したらTRUEを返す
+ */
+bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) || (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
+ return FALSE;
- /* Break the rune */
- g_ptr->info &= ~(CAVE_OBJECT);
- g_ptr->mimic = 0;
+ int k = 0;
+ for (POSITION y = oy - 1; y <= oy + 1; y++)
+ {
+ for (POSITION x = ox - 1; x <= ox + 1; x++)
+ {
+ if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
+ if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
+ }
+ }
- /* Allow movement */
- do_move = TRUE;
+ if (multiply_barrier(target_ptr, m_idx)) k = 8;
- note_spot(target_ptr, ny, nx);
+ if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
+ {
+ if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
+ {
+ if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
+ {
+ r_ptr->r_flags2 |= (RF2_MULTIPLY);
}
+
+ return TRUE;
}
- else if (do_move && is_explosive_rune_grid(g_ptr) &&
- !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(target_ptr, ny, nx)))
- {
- /* Assume no move allowed */
- do_move = FALSE;
+ }
- /* Break the ward */
- if (!is_pet(m_ptr))
- {
- /* Break the ward */
- if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
- {
- /* Describe observable breakage */
- if (g_ptr->info & CAVE_MARK)
- {
- msg_print(_("ルーンが爆発した!", "The rune explodes!"));
- project(target_ptr, 0, 2, ny, nx, 2 * (target_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
- }
- }
- else
- {
- msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
- }
+ return FALSE;
+}
- /* Forget the rune */
- g_ptr->info &= ~(CAVE_MARK);
- /* Break the rune */
- g_ptr->info &= ~(CAVE_OBJECT);
- g_ptr->mimic = 0;
+/*!
+ * @brief モンスターの移動パターンを決定する
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param mm 移動方向
+ * @param m_idx モンスターID
+ * @param aware 起きていればTRUE
+ * @return 移動先が存在すればTRUE
+ */
+bool decide_monster_movement_direction(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
- note_spot(target_ptr, ny, nx);
- lite_spot(target_ptr, ny, nx);
+ if (MON_CONFUSED(m_ptr) || !aware)
+ {
+ mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ return TRUE;
+ }
- if (!monster_is_valid(m_ptr)) return;
- /* Allow movement */
- do_move = TRUE;
- }
- }
+ if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) && (randint0(100) < 75))
+ {
+ if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
- /* The player is in the way */
- if (do_move && player_bold(target_ptr, ny, nx))
- {
- /* Some monsters never attack */
- if (r_ptr->flags1 & RF1_NEVER_BLOW)
- {
- /* Hack -- memorize lack of attacks */
- if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
+ mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ return TRUE;
+ }
- /* Do not move */
- do_move = FALSE;
- }
+ if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 50))
+ {
+ if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
- /* In anti-melee dungeon, stupid or confused monster takes useless turn */
- if (do_move && (d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE))
- {
- if (!MON_CONFUSED(m_ptr))
- {
- if (!(r_ptr->flags2 & RF2_STUPID)) do_move = FALSE;
- else
- {
- if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
- }
- }
- }
+ mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ return TRUE;
+ }
- /* The player is in the way. Attack him. */
- if (do_move)
- {
- if (!target_ptr->riding || one_in_(2))
- {
- /* Do the attack */
- (void)make_attack_normal(target_ptr, m_idx);
+ if ((r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 25))
+ {
+ if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
+
+ mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ return TRUE;
+ }
- /* Do not move */
- do_move = FALSE;
+ if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
+ {
+ mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ return TRUE;
+ }
- /* Took a turn */
- do_turn = TRUE;
+ if (is_pet(m_ptr))
+ {
+ bool avoid = ((target_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
+ bool lonely = (!avoid && (m_ptr->cdis > target_ptr->pet_follow_distance));
+ bool distant = (m_ptr->cdis > PET_SEEK_DIST);
+ mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ if (!get_enemy_dir(target_ptr, m_idx, mm))
+ {
+ if (avoid || lonely || distant)
+ {
+ POSITION dis = target_ptr->pet_follow_distance;
+ if (target_ptr->pet_follow_distance > PET_SEEK_DIST)
+ {
+ target_ptr->pet_follow_distance = PET_SEEK_DIST;
}
+
+ (void)get_moves(target_ptr, m_idx, mm);
+ target_ptr->pet_follow_distance = (s16b)dis;
}
}
- /* A monster is in the way */
- if (do_move && g_ptr->m_idx)
- {
- monster_race *z_ptr = &r_info[y_ptr->r_idx];
+ return TRUE;
+ }
- /* Assume no movement */
- do_move = FALSE;
+ if (!is_hostile(m_ptr))
+ {
+ mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ get_enemy_dir(target_ptr, m_idx, mm);
+ return TRUE;
+ }
- /* Attack 'enemies' */
- if (((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW) &&
- (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
- can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
- are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
- {
- if (!(r_ptr->flags1 & RF1_NEVER_BLOW))
- {
- if (r_ptr->flags2 & RF2_KILL_BODY)
- {
- if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_BODY);
- }
+ if (!get_moves(target_ptr, m_idx, mm)) return FALSE;
- /* attack */
- if (y_ptr->r_idx && (y_ptr->hp >= 0))
- {
- if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return;
-
- /* In anti-melee dungeon, stupid or confused monster takes useless turn */
- else if (d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE)
- {
- if (MON_CONFUSED(m_ptr)) return;
- else if (r_ptr->flags2 & RF2_STUPID)
- {
- if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
- return;
- }
- }
- }
- }
- }
+ return TRUE;
+}
- /* Push past weaker monsters (unless leaving a wall) */
- else if ((r_ptr->flags2 & RF2_MOVE_BODY) && !(r_ptr->flags1 & RF1_NEVER_MOVE) &&
- (r_ptr->mexp > z_ptr->mexp) &&
- can_cross && (g_ptr->m_idx != target_ptr->riding) &&
- monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
- {
- /* Allow movement */
- do_move = TRUE;
- /* Monster pushed past another monster */
- did_move_body = TRUE;
+/*!
+ * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param is_riding_mon 騎乗状態ならばTRUE
+ * @param see_m モンスターが視界内にいたらTRUE
+ * @return モンスターがフロアから消えたらTRUE
+ */
+bool runaway_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon, bool see_m)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ bool can_runaway = is_pet(m_ptr) || is_friendly(m_ptr);
+ can_runaway &= ((r_ptr->flags1 & RF1_UNIQUE) != 0) || ((r_ptr->flags7 & RF7_NAZGUL) != 0);
+ can_runaway &= !target_ptr->phase_out;
+ if (!can_runaway) return FALSE;
+
+ static int riding_pinch = 0;
- /* Wake up the moved monster */
- (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
+ if (m_ptr->hp >= m_ptr->maxhp / 3)
+ {
+ /* Reset the counter */
+ if (is_riding_mon) riding_pinch = 0;
+
+ return FALSE;
+ }
- /* Message */
- }
+ GAME_TEXT m_name[MAX_NLEN];
+ monster_desc(target_ptr, m_name, m_ptr, 0);
+ if (is_riding_mon && riding_pinch < 2)
+ {
+ msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
+ "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
+ riding_pinch++;
+ disturb(target_ptr, TRUE, TRUE);
+ return FALSE;
+ }
+
+ if (is_riding_mon)
+ {
+ msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
+ if (rakuba(target_ptr, -1, FALSE))
+ {
+ msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
}
+ }
- if (is_riding_mon)
+ if (see_m)
+ {
+ 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) &&
+ 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))
{
- if (!target_ptr->riding_ryoute && !MON_MONFEAR(&target_ptr->current_floor_ptr->m_list[target_ptr->riding])) do_move = FALSE;
+ msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
}
- if (did_kill_wall && do_move)
+ msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s reads a scroll of teleport level."), m_name);
+ msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
+ }
+
+ if (is_riding_mon && rakuba(target_ptr, -1, FALSE))
+ {
+ msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
+ }
+
+ check_quest_completion(target_ptr, m_ptr);
+ delete_monster_idx(target_ptr, m_idx);
+ return TRUE;
+}
+
+
+/*!
+ * @brief モンスターに魔法を試行させる
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param aware 起きていればTRUE
+ * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
+ */
+bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ if ((r_ptr->freq_spell == 0) || (randint1(100) > r_ptr->freq_spell))
+ return FALSE;
+
+ bool counterattack = FALSE;
+ if (m_ptr->target_y)
+ {
+ MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
+ if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
+ projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
{
- if (one_in_(GRINDNOISE))
- {
- if (have_flag(f_ptr->flags, FF_GLASS))
- msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
- else
- msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
- }
+ counterattack = TRUE;
+ }
+ }
- cave_alter_feat(target_ptr, ny, nx, FF_HURT_DISI);
+ if (counterattack)
+ {
+ if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
+ if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
+ }
+ else
+ {
+ if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
+ if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
+ }
- if (!monster_is_valid(m_ptr)) /* Killed by shards of glass, etc. */
- {
- target_ptr->update |= (PU_FLOW);
- target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
- if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
+ return FALSE;
+}
- return;
- }
- f_ptr = &f_info[g_ptr->feat];
+/*!
+ * @brief モンスターの移動に関するメインルーチン
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param mm モンスターの移動方向
+ * @param oy 移動前の、モンスターのY座標
+ * @param ox 移動前の、モンスターのX座標
+ * @param count 移動回数 (のはず todo)
+ * @return 移動が阻害される何か (ドア等)があったらFALSE
+ */
+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)
+{
+ for (int i = 0; mm[i]; i++)
+ {
+ int d = mm[i];
+ if (d == 5) d = ddd[randint0(8)];
+
+ POSITION ny = oy + ddy[d];
+ POSITION nx = ox + ddx[d];
+ if (!in_bounds2(target_ptr->current_floor_ptr, ny, nx)) continue;
+
+ grid_type *g_ptr;
+ g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ bool can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0);
- /* Note changes to viewable region */
- do_view = TRUE;
- do_turn = TRUE;
+ if (!process_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx, can_cross))
+ {
+ if (!process_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
+ return FALSE;
}
- if (must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
+ if (!process_protection_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
{
- if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0))
- {
- /* Assume no move allowed */
- do_move = FALSE;
- }
+ if (!process_explosive_rune(target_ptr, turn_flags_ptr, m_ptr, ny, nx))
+ return FALSE;
+ }
+
+ exe_monster_attack_to_player(target_ptr, turn_flags_ptr, m_idx, ny, nx);
+ if (process_monster_attack_to_monster(target_ptr, turn_flags_ptr, m_idx, g_ptr, can_cross)) return FALSE;
+
+ if (turn_flags_ptr->is_riding_mon)
+ {
+ if (!target_ptr->riding_ryoute && !MON_MONFEAR(&target_ptr->current_floor_ptr->m_list[target_ptr->riding])) turn_flags_ptr->do_move = FALSE;
}
- /*
- * Check if monster can cross terrain
- * This is checked after the normal attacks
- * to allow monsters to attack an enemy,
- * even if it can't enter the terrain.
- */
- if (do_move && !can_cross && !did_kill_wall && !did_bash_door)
+ if (!process_post_dig_wall(target_ptr, turn_flags_ptr, m_ptr, ny, nx)) return FALSE;
+
+ if (turn_flags_ptr->must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
{
- /* Assume no move allowed */
- do_move = FALSE;
+ if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, turn_flags_ptr->is_riding_mon ? CEM_RIDING : 0))
+ turn_flags_ptr->do_move = FALSE;
}
- /* Some monsters never move */
- if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
+ if (turn_flags_ptr->do_move && !can_cross && !turn_flags_ptr->did_kill_wall && !turn_flags_ptr->did_bash_door)
+ turn_flags_ptr->do_move = FALSE;
+
+ if (turn_flags_ptr->do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
{
- /* Hack -- memorize lack of moves */
- if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
+ if (is_original_ap_and_seen(target_ptr, m_ptr))
+ r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
- /* Do not move */
- do_move = FALSE;
+ turn_flags_ptr->do_move = FALSE;
}
- /* Creature has been allowed move */
- if (!do_move)
+ if (!turn_flags_ptr->do_move)
{
- if (do_turn) break;
+ if (turn_flags_ptr->do_turn) break;
+
continue;
}
- do_turn = TRUE;
-
+ turn_flags_ptr->do_turn = TRUE;
+ feature_type *f_ptr;
+ f_ptr = &f_info[g_ptr->feat];
if (have_flag(f_ptr->flags, FF_TREE))
{
if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
}
}
- if (!is_riding_mon)
- {
- /* Hack -- Update the old location */
- target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
-
- /* Mega-Hack -- move the old monster, if any */
- if (g_ptr->m_idx)
- {
- /* Move the old monster */
- y_ptr->fy = oy;
- y_ptr->fx = ox;
-
- /* Update the old monster */
- update_monster(target_ptr, g_ptr->m_idx, TRUE);
- }
-
- /* Hack -- Update the new location */
- g_ptr->m_idx = m_idx;
+ if (!update_riding_monster(target_ptr, turn_flags_ptr, m_idx, oy, ox, ny, nx)) break;
- /* Move the monster */
- m_ptr->fy = ny;
- m_ptr->fx = nx;
- update_monster(target_ptr, m_idx, TRUE);
-
- lite_spot(target_ptr, oy, ox);
- lite_spot(target_ptr, ny, nx);
- }
- else
- {
- /* sound(SOUND_WALK); */
- if (!move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP)) break;
- }
-
- /* Possible disturb */
+ monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
if (m_ptr->ml &&
(disturb_move ||
(disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
disturb(target_ptr, FALSE, TRUE);
}
- /* Take or Kill objects on the floor */
bool is_takable_or_killable = g_ptr->o_idx > 0;
is_takable_or_killable &= (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) != 0;
+
bool is_pickup_items = (target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
is_pickup_items &= (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
+
is_takable_or_killable &= !is_pet(m_ptr) || is_pickup_items;
if (!is_takable_or_killable)
{
- if (do_turn) break;
+ if (turn_flags_ptr->do_turn) break;
+
continue;
}
- OBJECT_IDX this_o_idx, next_o_idx;
- bool do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) ? TRUE : FALSE;
-
- /* Scan all objects in the grid */
- for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
- {
- BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
- GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
- object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
- next_o_idx = o_ptr->next_o_idx;
-
- if (do_take)
- {
- /* Skip gold */
- if (o_ptr->tval == TV_GOLD) continue;
-
- /*
- * Skip "real" corpses and statues, to avoid extreme
- * silliness like a novice rogue pockets full of statues
- * and corpses.
- */
- if ((o_ptr->tval == TV_CORPSE) ||
- (o_ptr->tval == TV_STATUE)) continue;
- }
-
- /* Extract some flags */
- object_flags(o_ptr, flgs);
-
- /* Acquire the object name */
- object_desc(target_ptr, o_name, o_ptr, 0);
- monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
-
- /* React to objects that hurt the monster */
- if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
- if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
- if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
- if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
- if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
- if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
- if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
- if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
- if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
- if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
- if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
- if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
- if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
- if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
- if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
- if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
- if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
- if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
- if (have_flag(flgs, TR_BRAND_ACID)) flgr |= (RFR_IM_ACID);
- if (have_flag(flgs, TR_BRAND_ELEC)) flgr |= (RFR_IM_ELEC);
- if (have_flag(flgs, TR_BRAND_FIRE)) flgr |= (RFR_IM_FIRE);
- if (have_flag(flgs, TR_BRAND_COLD)) flgr |= (RFR_IM_COLD);
- if (have_flag(flgs, TR_BRAND_POIS)) flgr |= (RFR_IM_POIS);
-
- /* The object cannot be picked up by the monster */
- if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
- ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
- {
- /* Only give a message for "take_item" */
- if (do_take && (r_ptr->flags2 & RF2_STUPID))
- {
- did_take_item = TRUE;
-
- /* Describe observable situations */
- if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
- {
- msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
- }
- }
- }
+ update_object_by_monster_movement(target_ptr, turn_flags_ptr, m_idx, ny, nx);
- /* Pick up the item */
- else if (do_take)
- {
- did_take_item = TRUE;
+ if (turn_flags_ptr->do_turn) break;
- /* Describe observable situations */
- if (player_can_see_bold(target_ptr, ny, nx))
- {
- msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
- }
+ *count++;
+ }
- /* Excise the object */
- excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
+ return TRUE;
+}
- /* Forget mark */
- o_ptr->marked &= OM_TOUCHED;
- /* Forget location */
- o_ptr->iy = o_ptr->ix = 0;
+/*!
+ * @brief モンスターによる壁の透過・破壊を行う
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param m_ptr モンスターへの参照ポインタ
+ * @param ny モンスターのY座標
+ * @param nx モンスターのX座標
+ * @param can_cross モンスターが地形を踏破できるならばTRUE
+ * @return 透過も破壊もしなかった場合はFALSE、それ以外はTRUE
+ */
+bool process_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx, bool can_cross)
+{
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ grid_type *g_ptr;
+ g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
+ feature_type *f_ptr;
+ f_ptr = &f_info[g_ptr->feat];
+ if (player_bold(target_ptr, ny, nx))
+ {
+ turn_flags_ptr->do_move = TRUE;
+ return TRUE;
+ }
- /* Memorize monster */
- o_ptr->held_m_idx = m_idx;
+ if (g_ptr->m_idx > 0)
+ {
+ turn_flags_ptr->do_move = TRUE;
+ return TRUE;
+ }
+
+ if (((r_ptr->flags2 & RF2_KILL_WALL) != 0) &&
+ (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !turn_flags_ptr->is_riding_mon) &&
+ have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
+ check_hp_for_feat_destruction(f_ptr, m_ptr))
+ {
+ turn_flags_ptr->do_move = TRUE;
+ if (!can_cross) turn_flags_ptr->must_alter_to_move = TRUE;
- /* Build a stack */
- o_ptr->next_o_idx = m_ptr->hold_o_idx;
+ turn_flags_ptr->did_kill_wall = TRUE;
+ return TRUE;
+ }
+
+ if (!can_cross) return FALSE;
- /* Carry object */
- m_ptr->hold_o_idx = this_o_idx;
- }
+ turn_flags_ptr->do_move = TRUE;
+ if (((r_ptr->flags2 & RF2_PASS_WALL) != 0) && (!turn_flags_ptr->is_riding_mon || target_ptr->pass_wall) &&
+ have_flag(f_ptr->flags, FF_CAN_PASS))
+ {
+ turn_flags_ptr->did_pass_wall = TRUE;
+ }
- /* Destroy the item if not a pet */
- else if (!is_pet(m_ptr))
- {
- did_kill_item = TRUE;
+ return TRUE;
+}
- /* Describe observable situations */
- if (player_has_los_bold(target_ptr, ny, nx))
- {
- msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
- }
- delete_object_idx(target_ptr, this_o_idx);
- }
- }
+/*!
+ * @brief モンスターによるドアの開放・破壊を行う
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+ * @param m_ptr モンスターへの参照ポインタ
+ * @param ny モンスターのY座標
+ * @param nx モンスターのX座標
+ * @return モンスターが死亡した場合のみFALSE
+ */
+bool process_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
+{
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ grid_type *g_ptr;
+ g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
+ if (!is_closed_door(target_ptr, g_ptr->feat)) return TRUE;
- if (do_turn) break;
- }
+ feature_type *f_ptr;
+ f_ptr = &f_info[g_ptr->feat];
+ bool may_bash = bash_normal_door(target_ptr, turn_flags_ptr, m_ptr, ny, nx);
+ bash_glass_door(target_ptr, turn_flags_ptr, m_ptr, f_ptr, may_bash);
- /*
- * Forward movements failed, but now received LOS attack!
- * Try to flow by smell.
- */
- if (target_ptr->no_flowed && i > 2 && m_ptr->target_y)
- m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
+ if (!turn_flags_ptr->did_open_door && !turn_flags_ptr->did_bash_door) return TRUE;
- /* If we haven't done anything, try casting a spell again */
- if (!do_turn && !do_move && !MON_MONFEAR(m_ptr) && !is_riding_mon && aware)
+ if (turn_flags_ptr->did_bash_door &&
+ ((randint0(100) < 50) || (feat_state(target_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
{
- /* Try to cast spell again */
- if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
+ cave_alter_feat(target_ptr, ny, nx, FF_BASH);
+ if (!monster_is_valid(m_ptr))
{
- if (make_attack_spell(m_idx, target_ptr)) return;
+ target_ptr->update |= (PU_FLOW);
+ target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
+ if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
+
+ return FALSE;
}
}
-
- /* Notice changes in view */
- if (do_view)
+ else
{
- target_ptr->update |= (PU_FLOW);
- target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
+ cave_alter_feat(target_ptr, ny, nx, FF_OPEN);
}
- /* Notice changes in view */
- if (do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
- || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !target_ptr->phase_out)))
- {
- target_ptr->update |= (PU_MON_LITE);
- }
+ f_ptr = &f_info[g_ptr->feat];
+ turn_flags_ptr->do_view = TRUE;
+ return TRUE;
+}
- /* Learn things from observable monster */
- if (is_original_ap_and_seen(target_ptr, m_ptr))
- {
- /* Monster opened a door */
- if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
- /* Monster bashed a door */
- if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
+/*!
+ * @brief モンスターが普通のドアを開ける処理
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+ * @param m_ptr モンスターへの参照ポインタ
+ * @param ny モンスターのY座標
+ * @param nx モンスターのX座標
+ * @return ここではドアを開けず、ガラスのドアを開ける可能性があるならTRUE
+ */
+bool bash_normal_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
+{
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ grid_type *g_ptr;
+ g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
+ feature_type *f_ptr;
+ f_ptr = &f_info[g_ptr->feat];
+ turn_flags_ptr->do_move = FALSE;
+ if (((r_ptr->flags2 & RF2_OPEN_DOOR) == 0) || !have_flag(f_ptr->flags, FF_OPEN) ||
+ (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
+ return TRUE;
- /* Monster tried to pick something up */
- if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
+ if (f_ptr->power == 0)
+ {
+ turn_flags_ptr->did_open_door = TRUE;
+ turn_flags_ptr->do_turn = TRUE;
+ return FALSE;
+ }
- /* Monster tried to crush something */
- if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
+ if (randint0(m_ptr->hp / 10) > f_ptr->power)
+ {
+ cave_alter_feat(target_ptr, ny, nx, FF_DISARM);
+ turn_flags_ptr->do_turn = TRUE;
+ return FALSE;
+ }
- /* Monster pushed past another monster */
- if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
+ return TRUE;
+}
- /* Monster passed through a wall */
- if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
- /* Monster destroyed a wall */
- if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
- }
+/*!
+ * @brief モンスターがガラスのドアを開ける処理
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+ * @param m_ptr モンスターへの参照ポインタ
+ * @param g_ptr グリッドへの参照ポインタ
+ * @param f_ptr 地形への参照ポインタ
+ * @return なし
+ */
+void bash_glass_door(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, feature_type *f_ptr, bool may_bash)
+{
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ if (!may_bash || ((r_ptr->flags2 & RF2_BASH_DOOR) == 0) || !have_flag(f_ptr->flags, FF_BASH) ||
+ (is_pet(m_ptr) && ((target_ptr->pet_extra_flags & PF_OPEN_DOORS) == 0)))
+ return;
- bool is_battle_determined = !do_turn && !do_move && MON_MONFEAR(m_ptr) && aware;
- if (!is_battle_determined) return;
+ if (!check_hp_for_feat_destruction(f_ptr, m_ptr) || (randint0(m_ptr->hp / 10) <= f_ptr->power))
+ return;
- /* No longer afraid */
- (void)set_monster_monfear(target_ptr, m_idx, 0);
+ if (have_flag(f_ptr->flags, FF_GLASS))
+ msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
+ else
+ msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
- /* Message if seen */
- if (see_m)
- {
- GAME_TEXT m_name[MAX_NLEN];
- monster_desc(target_ptr, m_name, m_ptr, 0);
- msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
- }
+ if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
- if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
+ turn_flags_ptr->did_bash_door = TRUE;
+ turn_flags_ptr->do_move = TRUE;
+ turn_flags_ptr->must_alter_to_move = TRUE;
}
/*!
- * @brief 量子生物の量子的効果を実行する
+ * @brief 守りのルーンによるモンスターの移動制限を処理する
* @param target_ptr プレーヤーへの参照ポインタ
- * @param m_idx モンスターID
- * @param see_m モンスターが視界内にいたらTRUE
- * @return モンスターが量子的効果により消滅したらTRUE
+ * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+ * @param m_ptr モンスターへの参照ポインタ
+ * @param ny モンスターのY座標
+ * @param nx モンスターのX座標
+ * @return ルーンのある/なし
*/
-bool process_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
+bool process_protection_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
{
- monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ grid_type *g_ptr;
+ g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
- if ((r_ptr->flags2 & RF2_QUANTUM) == 0) return FALSE;
- if (!randint0(2)) return FALSE;
- if (randint0((m_idx % 100) + 10)) return FALSE;
+ if (!turn_flags_ptr->do_move || !is_glyph_grid(g_ptr) ||
+ (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
+ return FALSE;
- bool can_disappear = (r_ptr->flags1 & RF1_UNIQUE) == 0;
- can_disappear &= (r_ptr->flags1 & RF1_QUESTOR) == 0;
- if (can_disappear)
- {
- vanish_nonunique(target_ptr, m_idx, see_m);
+ turn_flags_ptr->do_move = FALSE;
+ if (is_pet(m_ptr) || (randint1(BREAK_GLYPH) >= r_ptr->level))
return TRUE;
+
+ if (g_ptr->info & CAVE_MARK)
+ {
+ msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
}
-
- produce_quantum_effect(target_ptr, m_idx, see_m);
- return FALSE;
+
+ g_ptr->info &= ~(CAVE_MARK);
+ g_ptr->info &= ~(CAVE_OBJECT);
+ g_ptr->mimic = 0;
+ turn_flags_ptr->do_move = TRUE;
+ note_spot(target_ptr, ny, nx);
+ return TRUE;
}
/*!
- * @brief ユニークでない量子生物を消滅させる
+ * @brief 爆発のルーンにを処理する
* @param target_ptr プレーヤーへの参照ポインタ
- * @param m_idx モンスターID
- * @param see_m モンスターが視界内にいたらTRUE
- * @return なし
+ * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+ * @param m_ptr モンスターへの参照ポインタ
+ * @param ny モンスターのY座標
+ * @param nx モンスターのX座標
+ * @return モンスターが死亡した場合のみFALSE
*/
-void vanish_nonunique(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
+bool process_explosive_rune(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
{
- monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
- if (see_m)
+ grid_type *g_ptr;
+ g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ if (!turn_flags_ptr->do_move || !is_explosive_rune_grid(g_ptr) ||
+ (((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) && player_bold(target_ptr, ny, nx)))
+ return TRUE;
+
+ turn_flags_ptr->do_move = FALSE;
+ if (is_pet(m_ptr)) return TRUE;
+
+ if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
{
- GAME_TEXT m_name[MAX_NLEN];
- monster_desc(target_ptr, m_name, m_ptr, 0);
- msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
+ if (g_ptr->info & CAVE_MARK)
+ {
+ msg_print(_("ルーンが爆発した!", "The rune explodes!"));
+ BIT_FLAGS project_flags = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI;
+ project(target_ptr, 0, 2, ny, nx, 2 * (target_ptr->lev + damroll(7, 7)), GF_MANA, project_flags, -1);
+ }
}
-
- monster_death(target_ptr, m_idx, FALSE);
- delete_monster_idx(target_ptr, m_idx);
- if (is_pet(m_ptr) && !(m_ptr->ml))
+ else
{
- msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
+ msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
}
+
+ g_ptr->info &= ~(CAVE_MARK);
+ g_ptr->info &= ~(CAVE_OBJECT);
+ g_ptr->mimic = 0;
+
+ note_spot(target_ptr, ny, nx);
+ lite_spot(target_ptr, ny, nx);
+
+ if (!monster_is_valid(m_ptr)) return FALSE;
+
+ turn_flags_ptr->do_move = TRUE;
+ return TRUE;
}
/*!
- * @brief 量子生物ユニークの量子的効果 (ショート・テレポートまたは距離10のテレポート・アウェイ)を実行する
+ * @brief モンスターが移動した結果、そこにプレーヤーがいたら直接攻撃を行う
* @param target_ptr プレーヤーへの参照ポインタ
+ * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
* @param m_idx モンスターID
- * @param see_m モンスターが視界内にいたらTRUE
+ * @param ny 移動後の、モンスターのY座標
+ * @param nx 移動後の、モンスターのX座標
* @return なし
* @details
- * プレーヤーが量子生物を観測しているか、量子生物がプレーヤーを観測している場合、互いの相対的な位置を確定させる
- * 波動関数の収縮はテレポートではないので反テレポート無効
- * todo パターンは収縮どころか拡散しているが、この際気にしてはいけない
+ * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
*/
-void produce_quantum_effect(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
+void exe_monster_attack_to_player(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
{
monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
- bool coherent = los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x);
- if (!see_m && !coherent) return;
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ if (!turn_flags_ptr->do_move || !player_bold(target_ptr, ny, nx))
+ return;
- if (see_m)
+ if (r_ptr->flags1 & RF1_NEVER_BLOW)
{
- GAME_TEXT m_name[MAX_NLEN];
- monster_desc(target_ptr, m_name, m_ptr, 0);
- msg_format(_("%sは量子的効果を起こした!", "%^s produced a decoherence!"), m_name);
+ if (is_original_ap_and_seen(target_ptr, m_ptr))
+ r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
+
+ turn_flags_ptr->do_move = FALSE;
}
- else
+
+ if (turn_flags_ptr->do_move && ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) != 0) && !MON_CONFUSED(m_ptr))
{
- msg_print(_("量子的効果が起こった!", "A decoherence was produced!"));
+ if (!(r_ptr->flags2 & RF2_STUPID))
+ turn_flags_ptr->do_move = FALSE;
+ else if (is_original_ap_and_seen(target_ptr, m_ptr))
+ r_ptr->r_flags2 |= (RF2_STUPID);
}
- bool target = one_in_(2);
- const int blink = 32 * 5 + 4;
- if (target)
- {
- (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx);
+ if (!turn_flags_ptr->do_move) return;
- }
- else
+ if (!target_ptr->riding || one_in_(2))
{
- teleport_player_away(m_idx, target_ptr, 10, TRUE);
+ (void)make_attack_normal(target_ptr, m_idx);
+ turn_flags_ptr->do_move = FALSE;
+ turn_flags_ptr->do_turn = TRUE;
}
}
-void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
+/*!
+ * @brief モンスターからモンスターへの攻撃処理
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param g_ptr グリッドへの参照ポインタ
+ * @param can_cross モンスターが地形を踏破できるならばTRUE
+ * @return ターン消費が発生したらTRUE
+ */
+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)
{
monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
- if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
- if (m_ptr->r_idx != MON_OHMU) return;
- if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
- if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
+ monster_type *y_ptr;
+ y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
+ if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) return FALSE;
- int count = 0;
- DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
- BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
+ monster_race *z_ptr = &r_info[y_ptr->r_idx];
+ turn_flags_ptr->do_move = FALSE;
+ if ((((r_ptr->flags2 & RF2_KILL_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_BLOW) == 0) &&
+ (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
+ can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
+ are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
+ {
+ return exe_monster_attack_to_monster(target_ptr, m_idx, g_ptr);
+ }
- for (int k = 0; k < A_MAX; k++)
+ if (((r_ptr->flags2 & RF2_MOVE_BODY) != 0) && ((r_ptr->flags1 & RF1_NEVER_MOVE) == 0) &&
+ (r_ptr->mexp > z_ptr->mexp) &&
+ can_cross && (g_ptr->m_idx != target_ptr->riding) &&
+ monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
{
- if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
- {
- if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
- }
+ turn_flags_ptr->do_move = TRUE;
+ turn_flags_ptr->did_move_body = TRUE;
+ (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
}
- if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
+ return FALSE;
}
/*!
- * @brief ã\83¢ã\83³ã\82¹ã\82¿ã\83¼ã\82\92å\88\86è£\82ã\81\95ã\81\9bる
+ * @brief ã\83¢ã\83³ã\82¹ã\82¿ã\83¼ã\81\8bã\82\89ã\83¢ã\83³ã\82¹ã\82¿ã\83¼ã\81¸ã\81®ç\9b´æ\8e¥æ\94»æ\92\83ã\82\92å®\9fè¡\8cã\81\99る
* @param target_ptr プレーヤーへの参照ポインタ
* @param m_idx モンスターID
- * @param oy 分裂元モンスターのY座標
- * @param ox 分裂元モンスターのX座標
- * @return 実際に分裂したらTRUEを返す
+ * @param g_ptr グリッドへの参照ポインタ
*/
-bool multiply_monster(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
+bool exe_monster_attack_to_monster(player_type *target_ptr, MONSTER_IDX m_idx, grid_type *g_ptr)
{
monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
- if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) && (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
- return FALSE;
-
- int k = 0;
- for (POSITION y = oy - 1; y <= oy + 1; y++)
- {
- for (POSITION x = ox - 1; x <= ox + 1; x++)
- {
- if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
- if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
- }
- }
+ monster_type *y_ptr;
+ y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
+ if ((r_ptr->flags1 & RF1_NEVER_BLOW) != 0) return FALSE;
- if (multiply_barrier(target_ptr, m_idx)) k = 8;
+ if (((r_ptr->flags2 & RF2_KILL_BODY) == 0) && is_original_ap_and_seen(target_ptr, m_ptr))
+ r_ptr->r_flags2 |= (RF2_KILL_BODY);
- if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
- {
- if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
- {
- if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
- {
- r_ptr->r_flags2 |= (RF2_MULTIPLY);
- }
+ if ((y_ptr->r_idx == 0) || (y_ptr->hp < 0)) return FALSE;
+ if (monst_attack_monst(target_ptr, m_idx, g_ptr->m_idx)) return TRUE;
+ if ((d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE) == 0) return FALSE;
+ if (MON_CONFUSED(m_ptr)) return TRUE;
+ if ((r_ptr->flags2 & RF2_STUPID) == 0) return FALSE;
- return TRUE;
- }
- }
+ if (is_original_ap_and_seen(target_ptr, m_ptr))
+ r_ptr->r_flags2 |= (RF2_STUPID);
- return FALSE;
+ return TRUE;
}
-void move_monster(player_type *target_ptr, DIRECTION *mm, MONSTER_IDX m_idx, bool aware)
+/*!
+ * @brief モンスターが壁を掘った後続処理を実行する
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+ * @param m_ptr モンスターへの参照ポインタ
+ * @param ny モンスターのY座標
+ * @param nx モンスターのX座標
+ * @return モンスターが死亡した場合のみFALSE
+ */
+bool process_post_dig_wall(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, POSITION ny, POSITION nx)
{
- monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ grid_type *g_ptr;
+ g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
+ feature_type *f_ptr;
+ f_ptr = &f_info[g_ptr->feat];
+ if (!turn_flags_ptr->did_kill_wall || !turn_flags_ptr->do_move) return TRUE;
- /* Confused -- 100% random */
- if (MON_CONFUSED(m_ptr) || !aware)
+ if (one_in_(GRINDNOISE))
{
- /* Try four "random" directions */
- mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ if (have_flag(f_ptr->flags, FF_GLASS))
+ msg_print(_("何かの砕ける音が聞こえる。", "There is a crashing sound."));
+ else
+ msg_print(_("ギシギシいう音が聞こえる。", "There is a grinding sound."));
}
- /* 75% random movement */
- else if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) &&
- (randint0(100) < 75))
- {
- /* Memorize flags */
- if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
-
- /* Try four "random" directions */
- mm[0] = mm[1] = mm[2] = mm[3] = 5;
- }
+ cave_alter_feat(target_ptr, ny, nx, FF_HURT_DISI);
- /* 50% random movement */
- else if ((r_ptr->flags1 & RF1_RAND_50) &&
- (randint0(100) < 50))
+ if (!monster_is_valid(m_ptr))
{
- /* Memorize flags */
- if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
+ target_ptr->update |= (PU_FLOW);
+ target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
+ if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
- /* Try four "random" directions */
- mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ return FALSE;
}
- /* 25% random movement */
- else if ((r_ptr->flags1 & RF1_RAND_25) &&
- (randint0(100) < 25))
- {
- /* Memorize flags */
- if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
+ f_ptr = &f_info[g_ptr->feat];
+ turn_flags_ptr->do_view = TRUE;
+ turn_flags_ptr->do_turn = TRUE;
+ return TRUE;
+}
- /* Try four "random" directions */
- mm[0] = mm[1] = mm[2] = mm[3] = 5;
- }
- /* Can't reach player - find something else to hit */
- else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
+/*!
+ * @brief 騎乗中のモンスター情報を更新する
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param oy 移動前の、モンスターのY座標
+ * @param ox 移動前の、モンスターのX座標
+ * @param ny 移動後の、モンスターのY座標
+ * @param ox 移動後の、モンスターのX座標
+ * @return アイテム等に影響を及ぼしたらTRUE
+ */
+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)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ grid_type *g_ptr;
+ g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
+ monster_type *y_ptr;
+ y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
+ if (turn_flags_ptr->is_riding_mon)
+ return move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP);
+
+ target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
+ if (g_ptr->m_idx)
{
- /* Try four "random" directions */
- mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ y_ptr->fy = oy;
+ y_ptr->fx = ox;
+ update_monster(target_ptr, g_ptr->m_idx, TRUE);
}
- /* Pets will follow the player */
- else if (is_pet(m_ptr))
- {
- /* Are we trying to avoid the player? */
- bool avoid = ((target_ptr->pet_follow_distance < 0) && (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
+ g_ptr->m_idx = m_idx;
+ m_ptr->fy = ny;
+ m_ptr->fx = nx;
+ update_monster(target_ptr, m_idx, TRUE);
- /* Do we want to find the player? */
- bool lonely = (!avoid && (m_ptr->cdis > target_ptr->pet_follow_distance));
+ lite_spot(target_ptr, oy, ox);
+ lite_spot(target_ptr, ny, nx);
+ return TRUE;
+}
- /* Should we find the player if we can't find a monster? */
- bool distant = (m_ptr->cdis > PET_SEEK_DIST);
- /* by default, move randomly */
- mm[0] = mm[1] = mm[2] = mm[3] = 5;
+/*!
+ * @brief モンスターの移動に伴うオブジェクト処理 (アイテム破壊等)
+ * @param target_ptr プレーヤーへの参照ポインタ
+ * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
+ * @param m_idx モンスターID
+ * @param ny 移動後の、モンスターのY座標
+ * @param ox 移動後の、モンスターのX座標
+ */
+void update_object_by_monster_movement(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
+{
+ monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+ monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ grid_type *g_ptr;
+ g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
- /* Look for an enemy */
- if (!get_enemy_dir(target_ptr, m_idx, mm))
+ OBJECT_IDX this_o_idx, next_o_idx;
+ turn_flags_ptr->do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
+ for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+ {
+ BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
+ GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
+ object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
+ next_o_idx = o_ptr->next_o_idx;
+
+ if (turn_flags_ptr->do_take)
{
- /* Find the player if necessary */
- if (avoid || lonely || distant)
- {
- /* Remember the leash length */
- POSITION dis = target_ptr->pet_follow_distance;
+ /* Skip gold, corpse and statue */
+ if (o_ptr->tval == TV_GOLD || (o_ptr->tval == TV_CORPSE) || (o_ptr->tval == TV_STATUE))
+ continue;
+ }
- /* Hack -- adjust follow distance temporarily */
- if (target_ptr->pet_follow_distance > PET_SEEK_DIST)
+ object_flags(o_ptr, flgs);
+ object_desc(target_ptr, o_name, o_ptr, 0);
+ monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
+
+ if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
+ if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
+ if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
+ if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
+ if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
+ if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
+ if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
+ if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
+ if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
+ if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
+ if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
+ if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
+ if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
+ if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
+ if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
+ if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
+ if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
+ if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
+ if (have_flag(flgs, TR_BRAND_ACID)) flgr |= (RFR_IM_ACID);
+ if (have_flag(flgs, TR_BRAND_ELEC)) flgr |= (RFR_IM_ELEC);
+ if (have_flag(flgs, TR_BRAND_FIRE)) flgr |= (RFR_IM_FIRE);
+ if (have_flag(flgs, TR_BRAND_COLD)) flgr |= (RFR_IM_COLD);
+ if (have_flag(flgs, TR_BRAND_POIS)) flgr |= (RFR_IM_POIS);
+
+ if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
+ ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
+ {
+ if (turn_flags_ptr->do_take && (r_ptr->flags2 & RF2_STUPID))
+ {
+ turn_flags_ptr->did_take_item = TRUE;
+ if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
{
- target_ptr->pet_follow_distance = PET_SEEK_DIST;
+ msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
}
-
- /* Find the player */
- (void)get_moves(target_ptr, m_idx, mm);
-
- /* Restore the leash */
- target_ptr->pet_follow_distance = (s16b)dis;
}
}
- }
+ else if (turn_flags_ptr->do_take)
+ {
+ turn_flags_ptr->did_take_item = TRUE;
+ if (player_can_see_bold(target_ptr, ny, nx))
+ {
+ msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
+ }
- /* Friendly monster movement */
- else if (!is_hostile(m_ptr))
- {
- /* by default, move randomly */
- mm[0] = mm[1] = mm[2] = mm[3] = 5;
+ excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
+ o_ptr->marked &= OM_TOUCHED;
+ o_ptr->iy = o_ptr->ix = 0;
+ o_ptr->held_m_idx = m_idx;
+ o_ptr->next_o_idx = m_ptr->hold_o_idx;
+ m_ptr->hold_o_idx = this_o_idx;
+ }
+ else if (!is_pet(m_ptr))
+ {
+ turn_flags_ptr->did_kill_item = TRUE;
+ if (player_has_los_bold(target_ptr, ny, nx))
+ {
+ msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
+ }
- /* Look for an enemy */
- get_enemy_dir(target_ptr, m_idx, mm);
- }
- /* Normal movement */
- else
- {
- /* Logical moves, may do nothing */
- if (!get_moves(target_ptr, m_idx, mm)) return;
+ delete_object_idx(target_ptr, this_o_idx);
+ }
}
}
byte old_r_blows2 = 0;
byte old_r_blows3 = 0;
- /* Clear monster fighting indicator */
floor_type *floor_ptr = target_ptr->current_floor_ptr;
floor_ptr->monster_noise = FALSE;
- /* Memorize old race */
MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
-
- /* Acquire knowledge */
byte old_r_cast_spell = 0;
if (target_ptr->monster_race_idx)
{
- /* Acquire current monster */
monster_race *r_ptr;
r_ptr = &r_info[target_ptr->monster_race_idx];
- /* Memorize flags */
old_r_flags1 = r_ptr->r_flags1;
old_r_flags2 = r_ptr->r_flags2;
old_r_flags3 = r_ptr->r_flags3;
old_r_flags6 = r_ptr->r_flags6;
old_r_flagsr = r_ptr->r_flagsr;
- /* Memorize blows */
old_r_blows0 = r_ptr->r_blows[0];
old_r_blows1 = r_ptr->r_blows[1];
old_r_blows2 = r_ptr->r_blows[2];
old_r_blows3 = r_ptr->r_blows[3];
- /* Memorize castings */
old_r_cast_spell = r_ptr->r_cast_spell;
}
- /* Process the monsters (backwards) */
- bool test;
for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
{
monster_type *m_ptr;
m_ptr = &floor_ptr->m_list[i];
r_ptr = &r_info[m_ptr->r_idx];
- /* Handle "leaving" */
if (target_ptr->leaving) break;
-
- /* Ignore "dead" monsters */
if (!monster_is_valid(m_ptr)) continue;
-
if (target_ptr->wild_mode) continue;
-
- /* Handle "fresh" monsters */
if (m_ptr->mflag & MFLAG_BORN)
{
- /* No longer "fresh" */
m_ptr->mflag &= ~(MFLAG_BORN);
-
- /* Skip */
continue;
}
- /* Hack -- Require proximity */
if (m_ptr->cdis >= AAF_LIMIT) continue;
POSITION fx = m_ptr->fx;
POSITION fy = m_ptr->fy;
-
- /* Flow by smell is allowed */
if (!target_ptr->no_flowed)
{
m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
}
- /* Assume no move */
- test = FALSE;
-
- /* Handle "sensing radius" */
+ bool test = FALSE;
if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
{
- /* We can "sense" the player */
test = TRUE;
}
-
- /* Handle "sight" and "aggravation" */
else if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
(player_has_los_bold(target_ptr, fy, fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
{
- /* We can "see" or "feel" the player */
+ test = TRUE;
+ }
+ else if (m_ptr->target_y)
+ {
test = TRUE;
}
- else if (m_ptr->target_y) test = TRUE;
-
- /* Do nothing */
if (!test) continue;
SPEED speed;
if (target_ptr->riding == i)
+ {
speed = target_ptr->pspeed;
+ }
else
{
speed = m_ptr->mspeed;
-
- /* Monsters move quickly in Nightmare mode */
if (ironman_nightmare) speed += 5;
if (MON_FAST(m_ptr)) speed += 10;
if (MON_SLOW(m_ptr)) speed -= 10;
}
- /* Give this monster some energy */
m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
-
- /* Not enough energy to move */
if (m_ptr->energy_need > 0) continue;
- /* Use up "some" energy */
m_ptr->energy_need += ENERGY_NEED();
-
- /* Save global index */
hack_m_idx = i;
-
- /* Process the monster */
process_monster(target_ptr, i);
-
reset_target(m_ptr);
- /* Give up flow_by_smell when it might useless */
if (target_ptr->no_flowed && one_in_(3))
m_ptr->mflag2 |= MFLAG2_NOFLOW;
- /* Hack -- notice death or departure */
if (!target_ptr->playing || target_ptr->is_dead) break;
-
- /* Notice leaving */
if (target_ptr->leaving) break;
}
- /* Reset global index */
hack_m_idx = 0;
-
-
- /* Tracking a monster race (the same one we were before) */
if (!target_ptr->monster_race_idx || (target_ptr->monster_race_idx != old_monster_race_idx))
return;
- /* Acquire monster race */
monster_race *r_ptr;
r_ptr = &r_info[target_ptr->monster_race_idx];
- /* Check for knowledge change */
if ((old_r_flags1 != r_ptr->r_flags1) ||
(old_r_flags2 != r_ptr->r_flags2) ||
(old_r_flags3 != r_ptr->r_flags3) ||