1 #include "effect/effect-processor.h"
2 #include "core/stuff-handler.h"
3 #include "effect/effect-characteristics.h"
4 #include "effect/effect-feature.h"
5 #include "effect/effect-item.h"
6 #include "effect/effect-monster.h"
7 #include "effect/effect-player.h"
8 #include "effect/spells-effect-util.h"
9 #include "floor/cave.h"
10 #include "floor/geometry.h"
11 #include "floor/line-of-sight.h"
12 #include "game-option/map-screen-options.h"
13 #include "game-option/special-options.h"
14 #include "grid/feature-flag-types.h"
15 #include "grid/grid.h"
16 #include "io/cursor.h"
17 #include "io/screen-util.h"
18 #include "main/sound-definitions-table.h"
19 #include "main/sound-of-music.h"
20 #include "monster-race/monster-race.h"
21 #include "monster-race/race-flags2.h"
22 #include "monster-race/race-indice-types.h"
23 #include "monster/monster-describer.h"
24 #include "monster/monster-description-types.h"
25 #include "monster/monster-info.h"
26 #include "pet/pet-fall-off.h"
27 #include "player/player-status.h"
28 #include "spell/range-calc.h"
29 #include "spell/spell-types.h"
30 #include "system/floor-type-definition.h"
31 #include "system/monster-race-definition.h"
32 #include "system/monster-type-definition.h"
33 #include "system/player-type-definition.h"
34 #include "target/projection-path-calculator.h"
35 #include "term/gameterm.h"
36 #include "util/bit-flags-calculator.h"
37 #include "view/display-messages.h"
40 * @brief 配置した鏡リストの次を取得する /
41 * Get another mirror. for SEEKER
42 * @param next_y 次の鏡のy座標を返す参照ポインタ
43 * @param next_x 次の鏡のx座標を返す参照ポインタ
44 * @param cury 現在の鏡のy座標
45 * @param curx 現在の鏡のx座標
47 static void next_mirror(player_type *creature_ptr, POSITION *next_y, POSITION *next_x, POSITION cury, POSITION curx)
49 POSITION mirror_x[10], mirror_y[10]; /* 鏡はもっと少ない */
50 int mirror_num = 0; /* 鏡の数 */
51 for (POSITION x = 0; x < creature_ptr->current_floor_ptr->width; x++) {
52 for (POSITION y = 0; y < creature_ptr->current_floor_ptr->height; y++) {
53 if (is_mirror_grid(&creature_ptr->current_floor_ptr->grid_array[y][x])) {
54 mirror_y[mirror_num] = y;
55 mirror_x[mirror_num] = x;
62 int num = randint0(mirror_num);
63 *next_y = mirror_y[num];
64 *next_x = mirror_x[num];
68 *next_y = cury + randint0(5) - 2;
69 *next_x = curx + randint0(5) - 2;
73 * @brief 汎用的なビーム/ボルト/ボール系処理のルーチン Generic
74 * "beam"/"bolt"/"ball" projection routine.
75 * @param who 魔法を発動したモンスター(0ならばプレイヤー) / Index of "source"
76 * monster (zero for "player")
77 * @param rad 効果半径(ビーム/ボルト = 0 / ボール = 1以上) / Radius of explosion
78 * (0 = beam/bolt, 1 to 9 = ball)
79 * @param y 目標Y座標 / Target y location (or location to travel "towards")
80 * @param x 目標X座標 / Target x location (or location to travel "towards")
81 * @param dam 基本威力 / Base damage roll to apply to affected monsters (or
83 * @param typ 効果属性 / Type of damage to apply to monsters (and objects)
84 * @param flag 効果フラグ / Extra bit flags (see PROJECT_xxxx)
85 * @param monspell 効果元のモンスター魔法ID
86 * @todo 似たような処理が山ほど並んでいる、何とかならないものか
87 * @todo 引数にそのまま再代入していてカオスすぎる。直すのは簡単ではない
89 ProjectResult project(player_type *caster_ptr, const MONSTER_IDX who, POSITION rad, POSITION y, POSITION x, const HIT_POINT dam, const EFFECT_ID typ,
99 int msec = delay_factor * delay_factor * delay_factor;
103 bool blind = caster_ptr->blind != 0;
104 bool old_hide = false;
111 POSITION gm_rad = rad;
113 GAME_TEXT who_name[MAX_NLEN];
114 bool see_s_msg = true;
118 monster_target_y = caster_ptr->y;
119 monster_target_x = caster_ptr->x;
123 if (flag & (PROJECT_JUMP)) {
126 flag &= ~(PROJECT_JUMP);
128 } else if (who <= 0) {
131 } else if (who > 0) {
132 x1 = caster_ptr->current_floor_ptr->m_list[who].fx;
133 y1 = caster_ptr->current_floor_ptr->m_list[who].fy;
134 monster_desc(caster_ptr, who_name, &caster_ptr->current_floor_ptr->m_list[who], MD_WRONGDOER_NAME);
145 if (flag & (PROJECT_THRU)) {
146 if ((x1 == x2) && (y1 == y2)) {
147 flag &= ~(PROJECT_THRU);
154 if (flag & PROJECT_HIDE)
156 flag |= PROJECT_HIDE;
159 for (dist = 0; dist < 32; dist++)
165 if (flag & (PROJECT_BEAM)) {
174 if (breath || (flag & PROJECT_BEAM))
175 flag |= (PROJECT_LOS);
177 case GF_DISINTEGRATE:
178 flag |= (PROJECT_GRID);
179 if (breath || (flag & PROJECT_BEAM))
180 flag |= (PROJECT_DISI);
184 /* Calculate the projection path */
185 path_n = projection_path(caster_ptr, path_g, (project_length ? project_length : get_max_range(caster_ptr)), y1, x1, y2, x2, flag);
186 handle_stuff(caster_ptr);
188 if (typ == GF_SEEKER) {
194 for (int i = 0; i < path_n; ++i) {
197 POSITION ny = get_grid_y(path_g[i]);
198 POSITION nx = get_grid_x(path_g[i]);
206 if (!blind && !(flag & (PROJECT_HIDE))) {
207 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
208 u16b p = bolt_pict(oy, ox, y, x, typ);
209 TERM_COLOR a = PICT_A(p);
210 SYMBOL_CODE c = PICT_C(p);
211 print_rel(caster_ptr, c, a, y, x);
212 move_cursor_relative(y, x);
214 term_xtra(TERM_XTRA_DELAY, msec);
215 lite_spot(caster_ptr, y, x);
217 if (flag & (PROJECT_BEAM)) {
218 p = bolt_pict(y, x, y, x, typ);
221 print_rel(caster_ptr, c, a, y, x);
226 term_xtra(TERM_XTRA_DELAY, msec);
231 if (affect_item(caster_ptr, 0, 0, y, x, dam, GF_SEEKER))
233 if (!is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]))
236 monster_target_y = y;
237 monster_target_x = x;
238 remove_mirror(caster_ptr, y, x);
239 next_mirror(caster_ptr, &oy, &ox, y, x);
240 path_n = i + projection_path(caster_ptr, &(path_g[i + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, oy, ox, flag);
241 for (j = last_i; j <= i; j++) {
242 y = get_grid_y(path_g[j]);
243 x = get_grid_x(path_g[j]);
244 if (affect_monster(caster_ptr, 0, 0, y, x, dam, GF_SEEKER, flag, true))
246 if (!who && (project_m_n == 1) && !jump && (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0)) {
247 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx];
249 if (!caster_ptr->image)
250 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
251 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
255 (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_SEEKER);
261 for (int i = last_i; i < path_n; i++) {
263 py = get_grid_y(path_g[i]);
264 px = get_grid_x(path_g[i]);
265 if (affect_monster(caster_ptr, 0, 0, py, px, dam, GF_SEEKER, flag, true))
267 if (!who && (project_m_n == 1) && !jump) {
268 if (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0) {
269 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx];
272 if (!caster_ptr->image)
273 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
274 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
279 (void)affect_feature(caster_ptr, 0, 0, py, px, dam, GF_SEEKER);
283 } else if (typ == GF_SUPER_RAY) {
289 for (int i = 0; i < path_n; ++i) {
292 POSITION ny = get_grid_y(path_g[i]);
293 POSITION nx = get_grid_x(path_g[i]);
301 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
305 p = bolt_pict(oy, ox, y, x, typ);
308 print_rel(caster_ptr, c, a, y, x);
309 move_cursor_relative(y, x);
311 term_xtra(TERM_XTRA_DELAY, msec);
312 lite_spot(caster_ptr, y, x);
314 if (flag & (PROJECT_BEAM)) {
315 p = bolt_pict(y, x, y, x, typ);
318 print_rel(caster_ptr, c, a, y, x);
323 term_xtra(TERM_XTRA_DELAY, msec);
328 if (affect_item(caster_ptr, 0, 0, y, x, dam, GF_SUPER_RAY))
330 if (!cave_has_flag_bold(caster_ptr->current_floor_ptr, y, x, FF_PROJECT)) {
336 if (is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]) && !second_step) {
337 monster_target_y = y;
338 monster_target_x = x;
339 remove_mirror(caster_ptr, y, x);
340 for (j = 0; j <= i; j++) {
341 y = get_grid_y(path_g[j]);
342 x = get_grid_x(path_g[j]);
343 (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_SUPER_RAY);
348 path_n += projection_path(
349 caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y - 1, x - 1, flag);
351 += projection_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y - 1, x, flag);
352 path_n += projection_path(
353 caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y - 1, x + 1, flag);
355 += projection_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y, x - 1, flag);
357 += projection_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y, x + 1, flag);
358 path_n += projection_path(
359 caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y + 1, x - 1, flag);
361 += projection_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y + 1, x, flag);
362 path_n += projection_path(
363 caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y + 1, x + 1, flag);
367 for (int i = 0; i < path_n; i++) {
368 POSITION py = get_grid_y(path_g[i]);
369 POSITION px = get_grid_x(path_g[i]);
370 (void)affect_monster(caster_ptr, 0, 0, py, px, dam, GF_SUPER_RAY, flag, true);
371 if (!who && (project_m_n == 1) && !jump) {
372 if (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0) {
373 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx];
376 if (!caster_ptr->image)
377 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
378 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
383 (void)affect_feature(caster_ptr, 0, 0, py, px, dam, GF_SUPER_RAY);
390 for (k = 0; k < path_n; ++k) {
393 POSITION ny = get_grid_y(path_g[k]);
394 POSITION nx = get_grid_x(path_g[k]);
395 if (flag & PROJECT_DISI) {
396 if (cave_stop_disintegration(caster_ptr->current_floor_ptr, ny, nx) && (rad > 0))
398 } else if (flag & PROJECT_LOS) {
399 if (!cave_los_bold(caster_ptr->current_floor_ptr, ny, nx) && (rad > 0))
402 if (!cave_has_flag_bold(caster_ptr->current_floor_ptr, ny, nx, FF_PROJECT) && (rad > 0))
408 if (flag & (PROJECT_BEAM)) {
415 if (!blind && !(flag & (PROJECT_HIDE | PROJECT_FAST))) {
416 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
420 p = bolt_pict(oy, ox, y, x, typ);
423 print_rel(caster_ptr, c, a, y, x);
424 move_cursor_relative(y, x);
426 term_xtra(TERM_XTRA_DELAY, msec);
427 lite_spot(caster_ptr, y, x);
429 if (flag & (PROJECT_BEAM)) {
430 p = bolt_pict(y, x, y, x, typ);
433 print_rel(caster_ptr, c, a, y, x);
438 term_xtra(TERM_XTRA_DELAY, msec);
447 if (breath && !path_n) {
451 flag &= ~(PROJECT_HIDE);
458 int dist_hack = dist;
461 /* If we found a "target", explode there */
462 if (dist <= get_max_range(caster_ptr)) {
463 if ((flag & (PROJECT_BEAM)) && (grids > 0))
467 * Create a conical breath attack
476 flag &= ~(PROJECT_HIDE);
477 breath_shape(caster_ptr, path_g, dist, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, by, bx, typ);
479 for (dist = 0; dist <= rad; dist++) {
480 for (y = by - dist; y <= by + dist; y++) {
481 for (x = bx - dist; x <= bx + dist; x++) {
482 if (!in_bounds2(caster_ptr->current_floor_ptr, y, x))
484 if (distance(by, bx, y, x) != dist)
490 if (!los(caster_ptr, by, bx, y, x))
493 case GF_DISINTEGRATE:
494 if (!in_disintegration_range(caster_ptr->current_floor_ptr, by, bx, y, x))
498 if (!projectable(caster_ptr, by, bx, y, x))
509 gm[dist + 1] = grids;
517 if (!blind && !(flag & (PROJECT_HIDE)) && (msec > 0)) {
518 for (int t = 0; t <= gm_rad; t++) {
519 for (int i = gm[t]; i < gm[t + 1]; i++) {
522 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
527 p = bolt_pict(y, x, y, x, typ);
530 print_rel(caster_ptr, c, a, y, x);
534 move_cursor_relative(by, bx);
536 if (visual || drawn) {
537 term_xtra(TERM_XTRA_DELAY, msec);
542 for (int i = 0; i < grids; i++) {
545 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
546 lite_spot(caster_ptr, y, x);
550 move_cursor_relative(by, bx);
555 update_creature(caster_ptr);
557 if (flag & PROJECT_KILL) {
558 see_s_msg = (who > 0) ? is_seen(caster_ptr, &caster_ptr->current_floor_ptr->m_list[who])
559 : (!who ? true : (player_can_see_bold(caster_ptr, y1, x1) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y1, x1)));
562 if (flag & (PROJECT_GRID)) {
564 for (int i = 0; i < grids; i++) {
565 if (gm[dist + 1] == i)
570 int d = dist_to_line(y, x, y1, x1, by, bx);
571 if (affect_feature(caster_ptr, who, d, y, x, dam, typ))
574 if (affect_feature(caster_ptr, who, dist, y, x, dam, typ))
580 update_creature(caster_ptr);
581 if (flag & (PROJECT_ITEM)) {
583 for (int i = 0; i < grids; i++) {
584 if (gm[dist + 1] == i)
590 int d = dist_to_line(y, x, y1, x1, by, bx);
591 if (affect_item(caster_ptr, who, d, y, x, dam, typ))
594 if (affect_item(caster_ptr, who, dist, y, x, dam, typ))
600 if (flag & (PROJECT_KILL)) {
605 for (int i = 0; i < grids; i++) {
607 if (gm[dist + 1] == i)
613 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[y][x].m_idx];
614 monster_race *ref_ptr = &r_info[m_ptr->r_idx];
615 if ((flag & PROJECT_REFLECTABLE) && caster_ptr->current_floor_ptr->grid_array[y][x].m_idx && (ref_ptr->flags2 & RF2_REFLECTING)
616 && ((caster_ptr->current_floor_ptr->grid_array[y][x].m_idx != caster_ptr->riding) || !(flag & PROJECT_PLAYER)) && (!who || dist_hack > 1)
619 int max_attempts = 10;
621 t_y = y_saver - 1 + randint1(3);
622 t_x = x_saver - 1 + randint1(3);
624 } while (max_attempts && in_bounds2u(caster_ptr->current_floor_ptr, t_y, t_x) && !projectable(caster_ptr, y, x, t_y, t_x));
626 if (max_attempts < 1) {
631 sound(SOUND_REFLECT);
632 if (is_seen(caster_ptr, m_ptr)) {
633 if ((m_ptr->r_idx == MON_KENSHIROU) || (m_ptr->r_idx == MON_RAOU))
634 msg_print(_("「北斗神拳奥義・二指真空把!」", "The attack bounces!"));
635 else if (m_ptr->r_idx == MON_DIO)
636 msg_print(_("ディオ・ブランドーは指一本で攻撃を弾き返した!", "The attack bounces!"));
638 msg_print(_("攻撃は跳ね返った!", "The attack bounces!"));
641 if (is_original_ap_and_seen(caster_ptr, m_ptr))
642 ref_ptr->r_flags2 |= RF2_REFLECTING;
644 if (player_bold(caster_ptr, y, x) || one_in_(2))
645 flag &= ~(PROJECT_PLAYER);
647 flag |= PROJECT_PLAYER;
649 project(caster_ptr, caster_ptr->current_floor_ptr->grid_array[y][x].m_idx, 0, t_y, t_x, dam, typ, flag);
654 /* Find the closest point in the blast */
656 effective_dist = dist_to_line(y, x, y1, x1, by, bx);
658 effective_dist = dist;
661 if (caster_ptr->riding && player_bold(caster_ptr, y, x)) {
662 if (flag & PROJECT_PLAYER) {
663 if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE | PROJECT_AIMED)) {
665 * A beam or bolt is well aimed
667 * So don't affects the mount.
672 * The spell is not well aimed,
673 * So partly affect the mount too.
680 * This grid is the original target.
681 * Or aimed on your horse.
683 else if (((y == y2) && (x == x2)) || (flag & PROJECT_AIMED)) {
684 /* Hit the mount with full damage */
688 * Otherwise this grid is not the
689 * original target, it means that line
690 * of fire is obstructed by this
694 * A beam or bolt will hit either
695 * player or mount. Choose randomly.
697 else if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE)) {
699 /* Hit the mount with full damage */
701 flag |= PROJECT_PLAYER;
707 * The spell is not well aimed, so
708 * partly affect both player and
716 if (affect_monster(caster_ptr, who, effective_dist, y, x, dam, typ, flag, see_s_msg))
720 /* Player affected one monster (without "jumping") */
721 if (!who && (project_m_n == 1) && !jump) {
724 if (caster_ptr->current_floor_ptr->grid_array[y][x].m_idx > 0) {
725 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[y][x].m_idx];
728 if (!caster_ptr->image)
729 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
730 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[y][x].m_idx);
736 if (flag & (PROJECT_KILL)) {
738 for (int i = 0; i < grids; i++) {
740 if (gm[dist + 1] == i)
745 if (!player_bold(caster_ptr, y, x))
748 /* Find the closest point in the blast */
750 effective_dist = dist_to_line(y, x, y1, x1, by, bx);
752 effective_dist = dist;
755 if (caster_ptr->riding) {
756 if (flag & PROJECT_PLAYER) {
757 /* Hit the player with full damage */
761 * Hack -- When this grid was not the
762 * original target, a beam or bolt
763 * would hit either player or mount,
764 * and should be choosen randomly.
766 * But already choosen to hit the
767 * mount at this point.
769 * Or aimed on your horse.
771 else if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE | PROJECT_AIMED)) {
773 * A beam or bolt is well aimed
775 * So don't affects the player.
780 * The spell is not well aimed,
781 * So partly affect the player too.
787 if (affect_player(who, caster_ptr, who_name, effective_dist, y, x, dam, typ, flag, project)) {
789 res.affected_player = true;
794 if (caster_ptr->riding) {
795 GAME_TEXT m_name[MAX_NLEN];
796 monster_desc(caster_ptr, m_name, &caster_ptr->current_floor_ptr->m_list[caster_ptr->riding], 0);
797 if (rakubadam_m > 0) {
798 if (process_fall_off_horse(caster_ptr, rakubadam_m, false)) {
799 msg_format(_("%^sに振り落とされた!", "%^s has thrown you off!"), m_name);
803 if (caster_ptr->riding && rakubadam_p > 0) {
804 if (process_fall_off_horse(caster_ptr, rakubadam_p, false)) {
805 msg_format(_("%^sから落ちてしまった!", "You have fallen from %s."), m_name);