2 * @brief モンスター魔法の実装 / Monster spells (attack player)
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-checker.h"
13 #include "blue-magic/blue-magic-checker.h"
14 #include "core/disturbance.h"
15 #include "dungeon/dungeon-flag-types.h"
16 #include "dungeon/quest.h"
17 #include "effect/attribute-types.h"
18 #include "effect/effect-characteristics.h"
19 #include "effect/effect-processor.h"
20 #include "floor/cave.h"
21 #include "floor/geometry.h"
22 #include "floor/line-of-sight.h"
23 #include "monster-floor/monster-move.h"
24 #include "monster-race/monster-race.h"
25 #include "monster-race/race-ability-mask.h"
26 #include "monster-race/race-flags2.h"
27 #include "monster-race/race-flags3.h"
28 #include "monster-race/race-flags7.h"
29 #include "monster-race/race-indice-types.h"
30 #include "monster/monster-describer.h"
31 #include "monster/monster-description-types.h"
32 #include "monster/monster-flag-types.h"
33 #include "monster/monster-info.h"
34 #include "monster/monster-status.h"
35 #include "mspell/assign-monster-spell.h"
36 #include "mspell/improper-mspell-remover.h"
37 #include "mspell/mspell-judgement.h"
38 #include "mspell/mspell-learn-checker.h"
39 #include "mspell/mspell-selector.h"
40 #include "mspell/mspell-util.h"
41 #include "object-enchant/object-curse.h"
42 #include "player-info/class-info.h"
43 #include "player-info/race-types.h"
44 #include "player/attack-defense-types.h"
45 #include "spell-kind/spells-world.h"
46 #include "spell-realm/spells-hex.h"
47 #include "spell/range-calc.h"
48 #include "system/dungeon-info.h"
49 #include "system/floor-type-definition.h"
50 #include "system/grid-type-definition.h"
51 #include "system/item-entity.h"
52 #include "system/monster-entity.h"
53 #include "system/monster-race-info.h"
54 #include "system/player-type-definition.h"
55 #include "target/projection-path-calculator.h"
56 #include "util/bit-flags-calculator.h"
57 #include "view/display-messages.h"
58 #include "world/world.h"
61 * @brief モンスターにとって所定の地点が召還に相応しい地点かどうかを返す。 /
62 * Determine if there is a space near the player in which a summoned creature can appear
63 * @param player_ptr プレイヤーへの参照ポインタ
64 * @param y1 判定を行いたいマスのY座標
65 * @param x1 判定を行いたいマスのX座標
66 * @return 召還に相応しいならばTRUEを返す
68 bool summon_possible(PlayerType *player_ptr, POSITION y1, POSITION x1)
70 auto *floor_ptr = player_ptr->current_floor_ptr;
71 for (POSITION y = y1 - 2; y <= y1 + 2; y++) {
72 for (POSITION x = x1 - 2; x <= x1 + 2; x++) {
73 if (!in_bounds(floor_ptr, y, x)) {
77 if (distance(y1, x1, y, x) > 2) {
81 if (pattern_tile(floor_ptr, y, x)) {
85 if (is_cave_empty_bold(player_ptr, y, x) && projectable(player_ptr, y1, x1, y, x) && projectable(player_ptr, y, x, y1, x1)) {
95 * @brief モンスターにとって死者復活を行うべき状態かどうかを返す /
96 * Determine if there is a space near the player in which a summoned creature can appear
97 * @param player_ptr プレイヤーへの参照ポインタ
98 * @param m_ptr 判定を行いたいモンスターの構造体参照ポインタ
99 * @return 死者復活が有効な状態ならばTRUEを返す。
101 bool raise_possible(PlayerType *player_ptr, MonsterEntity *m_ptr)
103 POSITION y = m_ptr->fy;
104 POSITION x = m_ptr->fx;
105 auto *floor_ptr = player_ptr->current_floor_ptr;
106 for (POSITION xx = x - 5; xx <= x + 5; xx++) {
108 for (POSITION yy = y - 5; yy <= y + 5; yy++) {
109 if (distance(y, x, yy, xx) > 5) {
112 if (!los(player_ptr, y, x, yy, xx)) {
115 if (!projectable(player_ptr, y, x, yy, xx)) {
119 g_ptr = &floor_ptr->grid_array[yy][xx];
120 for (const auto this_o_idx : g_ptr->o_idx_list) {
121 const auto &item = floor_ptr->o_list[this_o_idx];
122 if (item.bi_key.tval() == ItemKindType::CORPSE) {
123 auto corpse_r_idx = i2enum<MonsterRaceId>(item.pval);
124 if (!monster_has_hostile_align(player_ptr, m_ptr, 0, 0, &monraces_info[corpse_r_idx])) {
136 * @brief モンスターにとってボルト型魔法が有効な状態かを返す /
137 * Determine if a bolt spell will hit the player.
138 * @param player_ptr プレイヤーへの参照ポインタ
139 * @param y1 ボルト魔法発射地点のY座標
140 * @param x1 ボルト魔法発射地点のX座標
141 * @param y2 ボルト魔法目標地点のY座標
142 * @param x2 ボルト魔法目標地点のX座標
143 * @param is_friend モンスターがプレイヤーに害意を持たない(ペットか友好的)ならばTRUEをつける
144 * @return ボルト型魔法が有効ならばTRUEを返す。
146 * Originally, it was possible for a friendly to shoot another friendly.\n
147 * Change it so a "clean shot" means no equally friendly monster is\n
148 * between the attacker and target.\n
150 * This is exactly like "projectable", but it will\n
151 * return FALSE if a monster is in the way.\n
152 * no equally friendly monster is\n
153 * between the attacker and target.\n
155 bool clean_shot(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_friend)
157 auto *floor_ptr = player_ptr->current_floor_ptr;
158 projection_path grid_g(player_ptr, get_max_range(player_ptr), y1, x1, y2, x2, 0);
159 if (grid_g.path_num() == 0) {
163 const auto [last_y, last_x] = grid_g.back();
164 if ((last_y != y2) || (last_x != x2)) {
168 for (const auto &[y, x] : grid_g) {
169 if ((floor_ptr->grid_array[y][x].m_idx > 0) && (y != y2 || x != x2)) {
170 auto *m_ptr = &floor_ptr->m_list[floor_ptr->grid_array[y][x].m_idx];
171 if (is_friend == m_ptr->is_pet()) {
176 if (player_bold(player_ptr, y, x) && is_friend) {
185 * @brief モンスターのボルト型魔法処理 /
186 * Cast a bolt at the player Stop if we hit a monster Affect monsters and the player
187 * @param player_ptr プレイヤーへの参照ポインタ
188 * @param m_idx モンスターのID
193 * @param monspell モンスター魔法のID
194 * @param target_type モンスターからモンスターへ撃つならMONSTER_TO_MONSTER、モンスターからプレイヤーならMONSTER_TO_PLAYER
196 ProjectResult bolt(PlayerType *player_ptr, MONSTER_IDX m_idx, POSITION y, POSITION x, AttributeType typ, int dam_hp, int target_type)
199 switch (target_type) {
200 case MONSTER_TO_MONSTER:
201 flg = PROJECT_STOP | PROJECT_KILL;
203 case MONSTER_TO_PLAYER:
204 flg = PROJECT_STOP | PROJECT_KILL | PROJECT_PLAYER;
208 if (typ != AttributeType::MONSTER_SHOOT) {
209 flg |= PROJECT_REFLECTABLE;
212 return project(player_ptr, m_idx, 0, y, x, dam_hp, typ, flg);
216 * @brief モンスターのビーム型魔法処理 /
217 * @param player_ptr プレイヤーへの参照ポインタ
218 * @param m_idx モンスターのID
223 * @param monspell モンスター魔法のID
224 * @param target_type モンスターからモンスターへ撃つならMONSTER_TO_MONSTER、モンスターからプレイヤーならMONSTER_TO_PLAYER
226 ProjectResult beam(PlayerType *player_ptr, MONSTER_IDX m_idx, POSITION y, POSITION x, AttributeType typ, int dam_hp, int target_type)
229 switch (target_type) {
230 case MONSTER_TO_MONSTER:
231 flg = PROJECT_BEAM | PROJECT_KILL | PROJECT_THRU;
233 case MONSTER_TO_PLAYER:
234 flg = PROJECT_BEAM | PROJECT_KILL | PROJECT_THRU | PROJECT_PLAYER;
238 return project(player_ptr, m_idx, 0, y, x, dam_hp, typ, flg);
241 ProjectResult ball(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, AttributeType typ, int dam_hp, POSITION rad, int target_type)
243 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
244 if (target_type == MONSTER_TO_PLAYER) {
245 flg |= PROJECT_PLAYER;
248 return project(player_ptr, m_idx, rad, y, x, dam_hp, typ, flg);
252 * @brief モンスターのボール型&ブレス型魔法処理 /
253 * Cast a breath (or ball) attack at the player Pass over any monsters that may be in the way Affect grids, objects, monsters, and the player
254 * @param player_ptr プレイヤーへの参照ポインタ
257 * @param m_idx モンスターのID
261 * @param monspell モンスター魔法のID
262 * @param target_type モンスターからモンスターへ撃つならMONSTER_TO_MONSTER、モンスターからプレイヤーならMONSTER_TO_PLAYER
264 ProjectResult breath(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, AttributeType typ, int dam_hp, POSITION rad, int target_type)
266 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
267 auto *r_ptr = &monraces_info[m_ptr->r_idx];
268 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_BREATH;
269 if (target_type == MONSTER_TO_PLAYER) {
270 flg |= PROJECT_PLAYER;
274 rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2;
277 return project(player_ptr, m_idx, rad, y, x, dam_hp, typ, flg);
280 ProjectResult pointed(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, AttributeType typ, int dam_hp, int target_type)
282 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_AIMED;
283 if (target_type == MONSTER_TO_PLAYER) {
284 flg |= PROJECT_PLAYER;
287 return project(player_ptr, m_idx, 0, y, x, dam_hp, typ, flg);
290 ProjectResult rocket(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, AttributeType typ, int dam_hp, POSITION rad, int target_type)
292 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_STOP;
293 if (target_type == MONSTER_TO_PLAYER) {
294 flg |= PROJECT_PLAYER;
297 return project(player_ptr, m_idx, rad, y, x, dam_hp, typ, flg);
301 * @brief ID値が非魔術的な特殊技能かどうかを返す /
302 * Return TRUE if a spell is inate spell.
303 * @param spell 判定対象のID
304 * @return 非魔術的な特殊技能ならばTRUEを返す。
306 bool spell_is_inate(MonsterAbilityType spell)
308 return RF_ABILITY_NOMAGIC_MASK.has(spell);