2 * @brief モンスター魔法の実装(対モンスター処理) / Monster spells (attack monster)
5 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
9 * 2014 Deskull rearranged comment for Doxygen.
12 #include "mspell/mspell-judgement.h"
13 #include "dungeon/dungeon.h"
14 #include "effect/effect-characteristics.h"
15 #include "floor/cave.h"
16 #include "floor/line-of-sight.h"
17 #include "grid/grid.h"
18 #include "main/sound-definitions-table.h"
19 #include "monster-race/monster-race.h"
20 #include "monster-race/race-flags-resistance.h"
21 #include "monster-race/race-flags4.h"
22 #include "monster/monster-info.h"
23 #include "monster/monster-status.h"
24 #include "player/attack-defense-types.h"
25 #include "player/player-race.h"
26 #include "player/special-defense-types.h"
27 #include "player/player-status-flags.h"
28 #include "realm/realm-song-numbers.h"
29 #include "spell/range-calc.h"
30 #include "spell/spell-types.h"
31 #include "system/floor-type-definition.h"
32 #include "target/projection-path-calculator.h"
35 * @brief モンスターが敵対モンスターにビームを当てること可能かを判定する /
36 * Determine if a beam spell will hit the target.
37 * @param target_ptr プレーヤーへの参照ポインタ
42 * @param m_ptr 使用するモンスターの構造体参照ポインタ
43 * @return ビームが到達可能ならばTRUEを返す
45 bool direct_beam(player_type *target_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, monster_type *m_ptr)
47 floor_type *floor_ptr = target_ptr->current_floor_ptr;
49 int grid_n = projection_path(target_ptr, grid_g, get_max_range(target_ptr), y1, x1, y2, x2, PROJECT_THRU);
55 bool is_friend = is_pet(m_ptr);
56 for (int i = 0; i < grid_n; i++) {
57 y = get_grid_y(grid_g[i]);
58 x = get_grid_x(grid_g[i]);
60 if (y == y2 && x == x2)
62 else if (is_friend && floor_ptr->grid_array[y][x].m_idx > 0 && !are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[floor_ptr->grid_array[y][x].m_idx])) {
66 if (is_friend && player_bold(target_ptr, y, x))
76 * @brief モンスターが敵対モンスターに直接ブレスを当てることが可能かを判定する /
77 * Determine if a breath will hit the target.
84 * @param is_friend TRUEならば、プレイヤーを巻き込む時にブレスの判定をFALSEにする。
85 * @return ブレスを直接当てられるならばTRUEを返す
87 bool breath_direct(player_type *master_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, POSITION rad, EFFECT_ID typ, bool is_friend)
104 int grid_n = projection_path(master_ptr, grid_g, get_max_range(master_ptr), y1, x1, y2, x2, flg);
108 for (i = 0; i < grid_n; ++i) {
109 int ny = get_grid_y(grid_g[i]);
110 int nx = get_grid_x(grid_g[i]);
112 if (flg & PROJECT_DISI) {
113 if (cave_stop_disintegration(master_ptr->current_floor_ptr, ny, nx))
115 } else if (flg & PROJECT_LOS) {
116 if (!cave_los_bold(master_ptr->current_floor_ptr, ny, nx))
119 if (!cave_has_flag_bold(master_ptr->current_floor_ptr, ny, nx, FF_PROJECT))
131 if (flg & PROJECT_DISI) {
132 if (in_disintegration_range(master_ptr->current_floor_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad))
134 if (in_disintegration_range(master_ptr->current_floor_ptr, y1, x1, master_ptr->y, master_ptr->x)
135 && (distance(y1, x1, master_ptr->y, master_ptr->x) <= rad))
137 } else if (flg & PROJECT_LOS) {
138 if (los(master_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad))
140 if (los(master_ptr, y1, x1, master_ptr->y, master_ptr->x) && (distance(y1, x1, master_ptr->y, master_ptr->x) <= rad))
143 if (projectable(master_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad))
145 if (projectable(master_ptr, y1, x1, master_ptr->y, master_ptr->x) && (distance(y1, x1, master_ptr->y, master_ptr->x) <= rad))
150 POSITION gx[1024], gy[1024];
152 POSITION gm_rad = rad;
153 breath_shape(master_ptr, grid_g, grid_n, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, y, x, typ);
154 for (i = 0; i < grids; i++) {
157 if ((y == y2) && (x == x2))
159 if (player_bold(master_ptr, y, x))
166 if (is_friend && hityou)
173 * @brief モンスターが特殊能力の目標地点を決める処理 /
174 * Get the actual center point of ball spells (rad > 1) (originally from TOband)
175 * @param target_ptr プレーヤーへの参照ポインタ
178 * @param ty 目標Y座標を返す参照ポインタ
179 * @param tx 目標X座標を返す参照ポインタ
180 * @param flg 判定のフラグ配列
183 void get_project_point(player_type *target_ptr, POSITION sy, POSITION sx, POSITION *ty, POSITION *tx, BIT_FLAGS flg)
186 int path_n = projection_path(target_ptr, path_g, get_max_range(target_ptr), sy, sx, *ty, *tx, flg);
189 for (int i = 0; i < path_n; i++) {
190 sy = get_grid_y(path_g[i]);
191 sx = get_grid_x(path_g[i]);
192 if (!cave_has_flag_bold(target_ptr->current_floor_ptr, sy, sx, FF_PROJECT))
201 * @brief モンスターが敵モンスターに魔力消去を使うかどうかを返す /
202 * Check should monster cast dispel spell at other monster.
203 * @param target_ptr プレーヤーへの参照ポインタ
204 * @param m_idx 術者のモンスターID
205 * @param t_idx 目標のモンスターID
206 * @return 魔力消去を使うべきならばTRUEを変えす。
208 bool dispel_check_monster(player_type *target_ptr, MONSTER_IDX m_idx, MONSTER_IDX t_idx)
210 monster_type *t_ptr = &target_ptr->current_floor_ptr->m_list[t_idx];
211 if (monster_invulner_remaining(t_ptr))
214 if ((t_ptr->mspeed < 135) && monster_fast_remaining(t_ptr))
217 if ((t_idx == target_ptr->riding) && dispel_check(target_ptr, m_idx))
224 * @brief モンスターがプレイヤーに魔力消去を与えるべきかを判定するルーチン
225 * Check should monster cast dispel spell.
226 * @param m_idx モンスターの構造体配列ID
227 * @return 魔力消去をかけるべきならTRUEを返す。
229 bool dispel_check(player_type *creature_ptr, MONSTER_IDX m_idx)
231 if (is_invuln(creature_ptr))
234 if (creature_ptr->wraith_form)
237 if (creature_ptr->shield)
240 if (creature_ptr->magicdef)
243 if (creature_ptr->multishadow)
246 if (creature_ptr->dustrobe)
249 if (creature_ptr->shero && (creature_ptr->pclass != CLASS_BERSERKER))
252 if (creature_ptr->mimic_form == MIMIC_DEMON_LORD)
255 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[m_idx];
256 monster_race *r_ptr = &r_info[m_ptr->r_idx];
257 if (r_ptr->flags4 & RF4_BR_ACID) {
258 if (!has_immune_acid(creature_ptr) && (creature_ptr->oppose_acid || music_singing(creature_ptr, MUSIC_RESIST)))
261 if (creature_ptr->special_defense & DEFENSE_ACID)
265 if (r_ptr->flags4 & RF4_BR_FIRE) {
266 if (!((creature_ptr->prace == RACE_BALROG) && creature_ptr->lev > 44)) {
267 if (!has_immune_fire(creature_ptr) && (creature_ptr->oppose_fire || music_singing(creature_ptr, MUSIC_RESIST)))
270 if (creature_ptr->special_defense & DEFENSE_FIRE)
275 if (r_ptr->flags4 & RF4_BR_ELEC) {
276 if (!has_immune_elec(creature_ptr) && (creature_ptr->oppose_elec || music_singing(creature_ptr, MUSIC_RESIST)))
279 if (creature_ptr->special_defense & DEFENSE_ELEC)
283 if (r_ptr->flags4 & RF4_BR_COLD) {
284 if (!has_immune_cold(creature_ptr) && (creature_ptr->oppose_cold || music_singing(creature_ptr, MUSIC_RESIST)))
287 if (creature_ptr->special_defense & DEFENSE_COLD)
291 if (((r_ptr->flags4 & (RF4_BR_POIS | RF4_BR_NUKE)) != 0) && !((creature_ptr->pclass == CLASS_NINJA) && (creature_ptr->lev > 44))) {
292 if (creature_ptr->oppose_pois || music_singing(creature_ptr, MUSIC_RESIST))
295 if (creature_ptr->special_defense & DEFENSE_POIS)
299 if (creature_ptr->ult_res)
302 if (creature_ptr->tsuyoshi)
305 if ((creature_ptr->special_attack & ATTACK_ACID) && !(r_ptr->flagsr & RFR_EFF_IM_ACID_MASK))
308 if ((creature_ptr->special_attack & ATTACK_FIRE) && !(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
311 if ((creature_ptr->special_attack & ATTACK_ELEC) && !(r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK))
314 if ((creature_ptr->special_attack & ATTACK_COLD) && !(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK))
317 if ((creature_ptr->special_attack & ATTACK_POIS) && !(r_ptr->flagsr & RFR_EFF_IM_POIS_MASK))
320 if ((creature_ptr->pspeed < 145) && is_fast(creature_ptr))
323 if (creature_ptr->lightspeed && (m_ptr->mspeed < 136))
326 if (creature_ptr->riding && (creature_ptr->current_floor_ptr->m_list[creature_ptr->riding].mspeed < 135)
327 && monster_fast_remaining(&creature_ptr->current_floor_ptr->m_list[creature_ptr->riding]))