1 #include "mspell/mspell-attack.h"
2 #include "blue-magic/blue-magic-checker.h"
3 #include "core/disturbance.h"
4 #include "core/player-redraw-types.h"
5 #include "dungeon/dungeon-flag-types.h"
6 #include "dungeon/dungeon.h"
7 #include "dungeon/quest.h"
8 #include "floor/cave.h"
9 #include "monster-floor/monster-move.h"
10 #include "monster-race/monster-race.h"
11 #include "monster-race/race-flags-ability1.h"
12 #include "monster-race/race-flags-ability2.h"
13 #include "monster-race/race-flags2.h"
14 #include "monster-race/race-flags4.h"
15 #include "monster-race/race-indice-types.h"
16 #include "monster/monster-describer.h"
17 #include "monster/monster-flag-types.h"
18 #include "monster/monster-info.h"
19 #include "monster/monster-status.h"
20 #include "mspell/assign-monster-spell.h"
21 #include "mspell/improper-mspell-remover.h"
22 #include "mspell/mspell-attack-util.h"
23 #include "mspell/mspell-checker.h"
24 #include "mspell/mspell-lite.h"
25 #include "mspell/mspell-mask-definitions.h"
26 #include "mspell/mspell-selector.h"
27 #include "mspell/mspell-util.h"
28 #include "player/attack-defense-types.h"
29 #include "spell-kind/spells-world.h"
30 #include "spell-realm/spells-hex.h"
31 #include "system/floor-type-definition.h"
32 #include "target/projection-path-calculator.h"
33 #include "view/display-messages.h"
34 #include "world/world.h"
37 #include "monster/monster-description-types.h"
40 static void set_no_magic_mask(msa_type *msa_ptr)
42 if (!msa_ptr->no_inate)
45 msa_ptr->f4 &= ~(RF4_NOMAGIC_MASK);
46 msa_ptr->f5 &= ~(RF5_NOMAGIC_MASK);
47 msa_ptr->f6 &= ~(RF6_NOMAGIC_MASK);
50 static void check_mspell_stupid(player_type *target_ptr, msa_type *msa_ptr)
52 floor_type *floor_ptr = target_ptr->current_floor_ptr;
53 msa_ptr->in_no_magic_dungeon = (d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC) && floor_ptr->dun_level
54 && (!floor_ptr->inside_quest || is_fixed_quest_idx(floor_ptr->inside_quest));
55 if (!msa_ptr->in_no_magic_dungeon || ((msa_ptr->r_ptr->flags2 & RF2_STUPID) != 0))
58 msa_ptr->f4 &= RF4_NOMAGIC_MASK;
59 msa_ptr->f5 &= RF5_NOMAGIC_MASK;
60 msa_ptr->f6 &= RF6_NOMAGIC_MASK;
63 static void check_mspell_smart(player_type *target_ptr, msa_type *msa_ptr)
65 if ((msa_ptr->r_ptr->flags2 & RF2_SMART) == 0)
68 if ((msa_ptr->m_ptr->hp < msa_ptr->m_ptr->maxhp / 10) && (randint0(100) < 50)) {
69 msa_ptr->f4 &= (RF4_INT_MASK);
70 msa_ptr->f5 &= (RF5_INT_MASK);
71 msa_ptr->f6 &= (RF6_INT_MASK);
74 if ((msa_ptr->f6 & RF6_TELE_LEVEL) && is_teleport_level_ineffective(target_ptr, 0)) {
75 msa_ptr->f6 &= ~(RF6_TELE_LEVEL);
79 static void check_mspell_arena(player_type *target_ptr, msa_type *msa_ptr)
81 if (!target_ptr->current_floor_ptr->inside_arena && !target_ptr->phase_out)
84 msa_ptr->f4 &= ~(RF4_SUMMON_MASK);
85 msa_ptr->f5 &= ~(RF5_SUMMON_MASK);
86 msa_ptr->f6 &= ~(RF6_SUMMON_MASK | RF6_TELE_LEVEL);
88 if (msa_ptr->m_ptr->r_idx == MON_ROLENTO)
89 msa_ptr->f6 &= ~(RF6_SPECIAL);
92 static bool check_mspell_non_stupid(player_type *target_ptr, msa_type *msa_ptr)
94 if ((msa_ptr->r_ptr->flags2 & RF2_STUPID) != 0)
98 msa_ptr->f5 &= ~(RF5_DRAIN_MANA);
100 if (((msa_ptr->f4 & RF4_BOLT_MASK) || (msa_ptr->f5 & RF5_BOLT_MASK) || (msa_ptr->f6 & RF6_BOLT_MASK))
101 && !clean_shot(target_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, target_ptr->y, target_ptr->x, FALSE)) {
102 msa_ptr->f4 &= ~(RF4_BOLT_MASK);
103 msa_ptr->f5 &= ~(RF5_BOLT_MASK);
104 msa_ptr->f6 &= ~(RF6_BOLT_MASK);
107 if (((msa_ptr->f4 & RF4_SUMMON_MASK) || (msa_ptr->f5 & RF5_SUMMON_MASK) || (msa_ptr->f6 & RF6_SUMMON_MASK))
108 && !(summon_possible(target_ptr, msa_ptr->y, msa_ptr->x))) {
109 msa_ptr->f4 &= ~(RF4_SUMMON_MASK);
110 msa_ptr->f5 &= ~(RF5_SUMMON_MASK);
111 msa_ptr->f6 &= ~(RF6_SUMMON_MASK);
114 if ((msa_ptr->f6 & RF6_RAISE_DEAD) && !raise_possible(target_ptr, msa_ptr->m_ptr))
115 msa_ptr->f6 &= ~(RF6_RAISE_DEAD);
117 if (((msa_ptr->f6 & RF6_SPECIAL) != 0) && (msa_ptr->m_ptr->r_idx == MON_ROLENTO) && !summon_possible(target_ptr, msa_ptr->y, msa_ptr->x))
118 msa_ptr->f6 &= ~(RF6_SPECIAL);
120 return (msa_ptr->f4 != 0) || (msa_ptr->f5 != 0) || (msa_ptr->f6 != 0);
123 static void set_mspell_list(msa_type *msa_ptr)
125 for (int k = 0; k < 32; k++)
126 if (msa_ptr->f4 & (1L << k))
127 msa_ptr->mspells[msa_ptr->num++] = k + RF4_SPELL_START;
129 for (int k = 0; k < 32; k++)
130 if (msa_ptr->f5 & (1L << k))
131 msa_ptr->mspells[msa_ptr->num++] = k + RF5_SPELL_START;
133 for (int k = 0; k < 32; k++)
134 if (msa_ptr->f6 & (1L << k))
135 msa_ptr->mspells[msa_ptr->num++] = k + RF6_SPELL_START;
138 static void describe_mspell_monster(player_type *target_ptr, msa_type *msa_ptr)
140 monster_desc(target_ptr, msa_ptr->m_name, msa_ptr->m_ptr, 0x00);
144 /* Get the monster possessive ("his"/"her"/"its") */
146 monster_desc(target_ptr, m_poss, msa_ptr->m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
150 static bool switch_do_spell(player_type *target_ptr, msa_type *msa_ptr)
152 switch (msa_ptr->do_spell) {
153 case DO_SPELL_NONE: {
156 msa_ptr->thrown_spell = choose_attack_spell(target_ptr, msa_ptr);
157 if (msa_ptr->thrown_spell)
163 case DO_SPELL_BR_LITE:
164 msa_ptr->thrown_spell = 96 + 14; /* RF4_BR_LITE */
166 case DO_SPELL_BR_DISI:
167 msa_ptr->thrown_spell = 96 + 31; /* RF4_BR_DISI */
169 case DO_SPELL_BA_LITE:
170 msa_ptr->thrown_spell = 128 + 20; /* RF5_BA_LITE */
177 static bool check_mspell_continuation(player_type *target_ptr, msa_type *msa_ptr)
179 if ((msa_ptr->f4 == 0) && (msa_ptr->f5 == 0) && (msa_ptr->f6 == 0))
182 remove_bad_spells(msa_ptr->m_idx, target_ptr, &msa_ptr->f4, &msa_ptr->f5, &msa_ptr->f6);
183 check_mspell_arena(target_ptr, msa_ptr);
184 if ((msa_ptr->f4 == 0) && (msa_ptr->f5 == 0) && (msa_ptr->f6 == 0) || !check_mspell_non_stupid(target_ptr, msa_ptr))
187 set_mspell_list(msa_ptr);
188 if ((msa_ptr->num == 0) || !target_ptr->playing || target_ptr->is_dead || target_ptr->leaving)
191 describe_mspell_monster(target_ptr, msa_ptr);
192 if (!switch_do_spell(target_ptr, msa_ptr) || (msa_ptr->thrown_spell == 0))
198 static bool check_mspell_unexploded(player_type *target_ptr, msa_type *msa_ptr)
200 PERCENTAGE fail_rate = 25 - (msa_ptr->rlev + 3) / 4;
201 if (msa_ptr->r_ptr->flags2 & RF2_STUPID)
204 if (!spell_is_inate(msa_ptr->thrown_spell)
205 && (msa_ptr->in_no_magic_dungeon || (monster_stunned_remaining(msa_ptr->m_ptr) && one_in_(2)) || (randint0(100) < fail_rate))) {
206 disturb(target_ptr, TRUE, TRUE);
207 msg_format(_("%^sは呪文を唱えようとしたが失敗した。", "%^s tries to cast a spell, but fails."), msa_ptr->m_name);
211 if (!spell_is_inate(msa_ptr->thrown_spell) && magic_barrier(target_ptr, msa_ptr->m_idx)) {
212 msg_format(_("反魔法バリアが%^sの呪文をかき消した。", "Anti magic barrier cancels the spell which %^s casts."), msa_ptr->m_name);
219 static bool check_thrown_mspell(player_type *target_ptr, msa_type *msa_ptr)
221 bool direct = player_bold(target_ptr, msa_ptr->y, msa_ptr->x);
222 msa_ptr->can_remember = is_original_ap_and_seen(target_ptr, msa_ptr->m_ptr);
226 switch (msa_ptr->thrown_spell) {
227 case 96 + 2: /* RF4_DISPEL */
228 case 96 + 4: /* RF4_SHOOT */
229 case 128 + 9: /* RF5_DRAIN_MANA */
230 case 128 + 10: /* RF5_MIND_BLAST */
231 case 128 + 11: /* RF5_BRAIN_SMASH */
232 case 128 + 12: /* RF5_CAUSE_1 */
233 case 128 + 13: /* RF5_CAUSE_2 */
234 case 128 + 14: /* RF5_CAUSE_3 */
235 case 128 + 15: /* RF5_CAUSE_4 */
236 case 128 + 16: /* RF5_BO_ACID */
237 case 128 + 17: /* RF5_BO_ELEC */
238 case 128 + 18: /* RF5_BO_FIRE */
239 case 128 + 19: /* RF5_BO_COLD */
240 case 128 + 21: /* RF5_BO_NETH */
241 case 128 + 22: /* RF5_BO_WATE */
242 case 128 + 23: /* RF5_BO_MANA */
243 case 128 + 24: /* RF5_BO_PLAS */
244 case 128 + 25: /* RF5_BO_ICEE */
245 case 128 + 26: /* RF5_MISSILE */
246 case 128 + 27: /* RF5_SCARE */
247 case 128 + 28: /* RF5_BLIND */
248 case 128 + 29: /* RF5_CONF */
249 case 128 + 30: /* RF5_SLOW */
250 case 128 + 31: /* RF5_HOLD */
251 case 160 + 1: /* RF6_HAND_DOOM */
252 case 160 + 8: /* RF6_TELE_TO */
253 case 160 + 9: /* RF6_TELE_AWAY */
254 case 160 + 10: /* RF6_TELE_LEVEL */
255 case 160 + 11: /* RF6_PSY_SPEAR */
256 case 160 + 12: /* RF6_DARKNESS */
257 case 160 + 14: /* RF6_FORGET */
264 static void check_mspell_imitation(player_type *target_ptr, msa_type *msa_ptr)
266 bool seen = (!target_ptr->blind && msa_ptr->m_ptr->ml);
267 bool can_imitate = player_has_los_bold(target_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx);
268 if (!seen || !can_imitate || (current_world_ptr->timewalk_m_idx != 0) || (target_ptr->pclass != CLASS_IMITATOR))
271 /* Not RF6_SPECIAL */
272 if (msa_ptr->thrown_spell == 167)
275 if (target_ptr->mane_num == MAX_MANE) {
276 target_ptr->mane_num--;
277 for (int i = 0; i < target_ptr->mane_num; i++) {
278 target_ptr->mane_spell[i] = target_ptr->mane_spell[i + 1];
279 target_ptr->mane_dam[i] = target_ptr->mane_dam[i + 1];
283 target_ptr->mane_spell[target_ptr->mane_num] = msa_ptr->thrown_spell - 96;
284 target_ptr->mane_dam[target_ptr->mane_num] = msa_ptr->dam;
285 target_ptr->mane_num++;
286 target_ptr->new_mane = TRUE;
287 target_ptr->redraw |= PR_IMITATION;
290 static void remember_mspell(msa_type *msa_ptr)
292 if (!msa_ptr->can_remember)
295 if (msa_ptr->thrown_spell < 32 * 4) {
296 msa_ptr->r_ptr->r_flags4 |= (1L << (msa_ptr->thrown_spell - 32 * 3));
297 if (msa_ptr->r_ptr->r_cast_spell < MAX_UCHAR)
298 msa_ptr->r_ptr->r_cast_spell++;
303 if (msa_ptr->thrown_spell < 32 * 5) {
304 msa_ptr->r_ptr->r_flags5 |= (1L << (msa_ptr->thrown_spell - 32 * 4));
305 if (msa_ptr->r_ptr->r_cast_spell < MAX_UCHAR)
306 msa_ptr->r_ptr->r_cast_spell++;
311 if (msa_ptr->thrown_spell < 32 * 6) {
312 msa_ptr->r_ptr->r_flags6 |= (1L << (msa_ptr->thrown_spell - 32 * 5));
313 if (msa_ptr->r_ptr->r_cast_spell < MAX_UCHAR)
314 msa_ptr->r_ptr->r_cast_spell++;
319 * @brief モンスターの特殊技能メインルーチン /
320 * Creatures can cast spells, shoot missiles, and breathe.
321 * @param target_ptr プレーヤーへの参照ポインタ
322 * @param m_idx モンスター構造体配列のID
323 * @return 実際に特殊技能を利用したらTRUEを返す
325 bool make_attack_spell(player_type *target_ptr, MONSTER_IDX m_idx)
328 msa_type *msa_ptr = initialize_msa_type(target_ptr, &tmp_msa, m_idx);
329 if (monster_confused_remaining(msa_ptr->m_ptr)) {
330 reset_target(msa_ptr->m_ptr);
334 if (((msa_ptr->m_ptr->mflag & MFLAG_NICE) != 0) || !is_hostile(msa_ptr->m_ptr)
335 || ((msa_ptr->m_ptr->cdis > get_max_range(target_ptr)) && !msa_ptr->m_ptr->target_y))
338 decide_lite_range(target_ptr, msa_ptr);
339 if (!decide_lite_projection(target_ptr, msa_ptr))
342 reset_target(msa_ptr->m_ptr);
343 msa_ptr->rlev = ((msa_ptr->r_ptr->level >= 1) ? msa_ptr->r_ptr->level : 1);
344 set_no_magic_mask(msa_ptr);
345 decide_lite_area(target_ptr, msa_ptr);
346 check_mspell_stupid(target_ptr, msa_ptr);
347 check_mspell_smart(target_ptr, msa_ptr);
348 if (!check_mspell_continuation(target_ptr, msa_ptr))
351 if (check_mspell_unexploded(target_ptr, msa_ptr))
354 if (!check_thrown_mspell(target_ptr, msa_ptr))
357 msa_ptr->dam = monspell_to_player(target_ptr, msa_ptr->thrown_spell, msa_ptr->y, msa_ptr->x, m_idx);
358 if (msa_ptr->dam < 0)
361 if ((target_ptr->action == ACTION_LEARN) && msa_ptr->thrown_spell > 175)
362 learn_spell(target_ptr, msa_ptr->thrown_spell - 96);
364 check_mspell_imitation(target_ptr, msa_ptr);
365 remember_mspell(msa_ptr);
366 if (target_ptr->is_dead && (msa_ptr->r_ptr->r_deaths < MAX_SHORT) && !target_ptr->current_floor_ptr->inside_arena)
367 msa_ptr->r_ptr->r_deaths++;