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/line-of-sight.h"
11 #include "game-option/special-options.h"
12 #include "grid/feature-flag-types.h"
13 #include "io/cursor.h"
14 #include "io/screen-util.h"
15 #include "main/sound-definitions-table.h"
16 #include "main/sound-of-music.h"
17 #include "monster-race/monster-race.h"
18 #include "monster-race/race-flags2.h"
19 #include "monster-race/race-indice-types.h"
20 #include "monster/monster-describer.h"
21 #include "monster/monster-description-types.h"
22 #include "monster/monster-info.h"
23 #include "pet/pet-fall-off.h"
24 #include "spell/range-calc.h"
25 #include "spell/spell-types.h"
26 #include "system/floor-type-definition.h"
27 #include "target/projection-path-calculator.h"
28 #include "term/gameterm.h"
29 #include "util/bit-flags-calculator.h"
30 #include "view/display-messages.h"
33 * @brief 配置した鏡リストの次を取得する /
34 * Get another mirror. for SEEKER
35 * @param next_y 次の鏡のy座標を返す参照ポインタ
36 * @param next_x 次の鏡のx座標を返す参照ポインタ
37 * @param cury 現在の鏡のy座標
38 * @param curx 現在の鏡のx座標
40 static void next_mirror(player_type *creature_ptr, POSITION *next_y, POSITION *next_x, POSITION cury, POSITION curx)
42 POSITION mirror_x[10], mirror_y[10]; /* 鏡はもっと少ない */
43 int mirror_num = 0; /* 鏡の数 */
44 for (POSITION x = 0; x < creature_ptr->current_floor_ptr->width; x++) {
45 for (POSITION y = 0; y < creature_ptr->current_floor_ptr->height; y++) {
46 if (is_mirror_grid(&creature_ptr->current_floor_ptr->grid_array[y][x])) {
47 mirror_y[mirror_num] = y;
48 mirror_x[mirror_num] = x;
55 int num = randint0(mirror_num);
56 *next_y = mirror_y[num];
57 *next_x = mirror_x[num];
61 *next_y = cury + randint0(5) - 2;
62 *next_x = curx + randint0(5) - 2;
66 * todo 似たような処理が山ほど並んでいる、何とかならないものか
67 * todo 引数にそのまま再代入していてカオスすぎる。直すのは簡単ではない
68 * @brief 汎用的なビーム/ボルト/ボール系処理のルーチン Generic
69 * "beam"/"bolt"/"ball" projection routine.
70 * @param who 魔法を発動したモンスター(0ならばプレイヤー) / Index of "source"
71 * monster (zero for "player")
72 * @param rad 効果半径(ビーム/ボルト = 0 / ボール = 1以上) / Radius of explosion
73 * (0 = beam/bolt, 1 to 9 = ball)
74 * @param y 目標Y座標 / Target y location (or location to travel "towards")
75 * @param x 目標X座標 / Target x location (or location to travel "towards")
76 * @param dam 基本威力 / Base damage roll to apply to affected monsters (or
78 * @param typ 効果属性 / Type of damage to apply to monsters (and objects)
79 * @param flag 効果フラグ / Extra bit flags (see PROJECT_xxxx)
80 * @param monspell 効果元のモンスター魔法ID
81 * @return 何か一つでも効力があればTRUEを返す / TRUE if any "effects" of the
82 * projection were observed, else FALSE
84 bool project(player_type *caster_ptr, const MONSTER_IDX who, POSITION rad, POSITION y, POSITION x, const HIT_POINT dam, const EFFECT_ID typ, BIT_FLAGS flag,
94 int msec = delay_factor * delay_factor * delay_factor;
99 bool blind = caster_ptr->blind != 0;
100 bool old_hide = FALSE;
107 POSITION gm_rad = rad;
109 GAME_TEXT who_name[MAX_NLEN];
110 bool see_s_msg = TRUE;
114 monster_target_y = caster_ptr->y;
115 monster_target_x = caster_ptr->x;
117 if (flag & (PROJECT_JUMP)) {
120 flag &= ~(PROJECT_JUMP);
122 } else if (who <= 0) {
125 } else if (who > 0) {
126 x1 = caster_ptr->current_floor_ptr->m_list[who].fx;
127 y1 = caster_ptr->current_floor_ptr->m_list[who].fy;
128 monster_desc(caster_ptr, who_name, &caster_ptr->current_floor_ptr->m_list[who], MD_WRONGDOER_NAME);
139 if (flag & (PROJECT_THRU)) {
140 if ((x1 == x2) && (y1 == y2)) {
141 flag &= ~(PROJECT_THRU);
148 if (flag & PROJECT_HIDE)
150 flag |= PROJECT_HIDE;
153 for (dist = 0; dist < 32; dist++)
159 if (flag & (PROJECT_BEAM)) {
168 if (breath || (flag & PROJECT_BEAM))
169 flag |= (PROJECT_LOS);
171 case GF_DISINTEGRATE:
172 flag |= (PROJECT_GRID);
173 if (breath || (flag & PROJECT_BEAM))
174 flag |= (PROJECT_DISI);
178 /* Calculate the projection path */
179 path_n = projection_path(caster_ptr, path_g, (project_length ? project_length : get_max_range(caster_ptr)), y1, x1, y2, x2, flag);
180 handle_stuff(caster_ptr);
182 if (typ == GF_SEEKER) {
188 for (int i = 0; i < path_n; ++i) {
191 POSITION ny = get_grid_y(path_g[i]);
192 POSITION nx = get_grid_x(path_g[i]);
199 if (!blind && !(flag & (PROJECT_HIDE))) {
200 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
201 u16b p = bolt_pict(oy, ox, y, x, typ);
202 TERM_COLOR a = PICT_A(p);
203 SYMBOL_CODE c = PICT_C(p);
204 print_rel(caster_ptr, c, a, y, x);
205 move_cursor_relative(y, x);
206 if (need_term_fresh()) {
208 term_xtra(TERM_XTRA_DELAY, msec);
209 lite_spot(caster_ptr, y, x);
212 if (flag & (PROJECT_BEAM)) {
213 p = bolt_pict(y, x, y, x, typ);
216 print_rel(caster_ptr, c, a, y, x);
221 term_xtra(TERM_XTRA_DELAY, msec);
225 if (affect_item(caster_ptr, 0, 0, y, x, dam, GF_SEEKER))
227 if (!is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]))
230 monster_target_y = y;
231 monster_target_x = x;
232 remove_mirror(caster_ptr, y, x);
233 next_mirror(caster_ptr, &oy, &ox, y, x);
234 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);
235 for (j = last_i; j <= i; j++) {
236 y = get_grid_y(path_g[j]);
237 x = get_grid_x(path_g[j]);
238 if (affect_monster(caster_ptr, 0, 0, y, x, dam, GF_SEEKER, flag, TRUE))
240 if (!who && (project_m_n == 1) && !jump && (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0)) {
241 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];
243 if (!caster_ptr->image)
244 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
245 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
249 (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_SEEKER);
255 for (int i = last_i; i < path_n; i++) {
257 py = get_grid_y(path_g[i]);
258 px = get_grid_x(path_g[i]);
259 if (affect_monster(caster_ptr, 0, 0, py, px, dam, GF_SEEKER, flag, TRUE))
261 if (!who && (project_m_n == 1) && !jump) {
262 if (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0) {
263 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];
266 if (!caster_ptr->image)
267 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
268 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
273 (void)affect_feature(caster_ptr, 0, 0, py, px, dam, GF_SEEKER);
277 } else if (typ == GF_SUPER_RAY) {
283 for (int i = 0; i < path_n; ++i) {
286 POSITION ny = get_grid_y(path_g[i]);
287 POSITION nx = get_grid_x(path_g[i]);
294 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
298 p = bolt_pict(oy, ox, y, x, typ);
301 print_rel(caster_ptr, c, a, y, x);
302 move_cursor_relative(y, x);
304 term_xtra(TERM_XTRA_DELAY, msec);
305 lite_spot(caster_ptr, y, x);
307 if (flag & (PROJECT_BEAM)) {
308 p = bolt_pict(y, x, y, x, typ);
311 print_rel(caster_ptr, c, a, y, x);
316 term_xtra(TERM_XTRA_DELAY, msec);
320 if (affect_item(caster_ptr, 0, 0, y, x, dam, GF_SUPER_RAY))
322 if (!cave_has_flag_bold(caster_ptr->current_floor_ptr, y, x, FF_PROJECT)) {
328 if (is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]) && !second_step) {
329 monster_target_y = y;
330 monster_target_x = x;
331 remove_mirror(caster_ptr, y, x);
332 for (j = 0; j <= i; j++) {
333 y = get_grid_y(path_g[j]);
334 x = get_grid_x(path_g[j]);
335 (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_SUPER_RAY);
340 path_n += projection_path(
341 caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y - 1, x - 1, flag);
343 += projection_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y - 1, x, flag);
344 path_n += projection_path(
345 caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y - 1, x + 1, flag);
347 += projection_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y, x - 1, flag);
349 += projection_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y, x + 1, flag);
350 path_n += projection_path(
351 caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y + 1, x - 1, flag);
353 += projection_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y + 1, x, flag);
354 path_n += projection_path(
355 caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : get_max_range(caster_ptr)), y, x, y + 1, x + 1, flag);
359 for (int i = 0; i < path_n; i++) {
360 POSITION py = get_grid_y(path_g[i]);
361 POSITION px = get_grid_x(path_g[i]);
362 (void)affect_monster(caster_ptr, 0, 0, py, px, dam, GF_SUPER_RAY, flag, TRUE);
363 if (!who && (project_m_n == 1) && !jump) {
364 if (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0) {
365 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];
368 if (!caster_ptr->image)
369 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
370 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
375 (void)affect_feature(caster_ptr, 0, 0, py, px, dam, GF_SUPER_RAY);
382 for (k = 0; k < path_n; ++k) {
385 POSITION ny = get_grid_y(path_g[k]);
386 POSITION nx = get_grid_x(path_g[k]);
387 if (flag & PROJECT_DISI) {
388 if (cave_stop_disintegration(caster_ptr->current_floor_ptr, ny, nx) && (rad > 0))
390 } else if (flag & PROJECT_LOS) {
391 if (!cave_los_bold(caster_ptr->current_floor_ptr, ny, nx) && (rad > 0))
394 if (!cave_has_flag_bold(caster_ptr->current_floor_ptr, ny, nx, FF_PROJECT) && (rad > 0))
400 if (flag & (PROJECT_BEAM)) {
406 if (!blind && !(flag & (PROJECT_HIDE | PROJECT_FAST))) {
407 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
411 p = bolt_pict(oy, ox, y, x, typ);
414 print_rel(caster_ptr, c, a, y, x);
415 move_cursor_relative(y, x);
417 term_xtra(TERM_XTRA_DELAY, msec);
418 lite_spot(caster_ptr, y, x);
420 if (flag & (PROJECT_BEAM)) {
421 p = bolt_pict(y, x, y, x, typ);
424 print_rel(caster_ptr, c, a, y, x);
429 term_xtra(TERM_XTRA_DELAY, msec);
437 if (breath && !path_n) {
441 flag &= ~(PROJECT_HIDE);
448 int dist_hack = dist;
451 /* If we found a "target", explode there */
452 if (dist <= get_max_range(caster_ptr)) {
453 if ((flag & (PROJECT_BEAM)) && (grids > 0))
457 * Create a conical breath attack
466 flag &= ~(PROJECT_HIDE);
467 breath_shape(caster_ptr, path_g, dist, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, by, bx, typ);
469 for (dist = 0; dist <= rad; dist++) {
470 for (y = by - dist; y <= by + dist; y++) {
471 for (x = bx - dist; x <= bx + dist; x++) {
472 if (!in_bounds2(caster_ptr->current_floor_ptr, y, x))
474 if (distance(by, bx, y, x) != dist)
480 if (!los(caster_ptr, by, bx, y, x))
483 case GF_DISINTEGRATE:
484 if (!in_disintegration_range(caster_ptr->current_floor_ptr, by, bx, y, x))
488 if (!projectable(caster_ptr, by, bx, y, x))
499 gm[dist + 1] = grids;
507 if (!blind && !(flag & (PROJECT_HIDE))) {
508 for (int t = 0; t <= gm_rad; t++) {
509 for (int i = gm[t]; i < gm[t + 1]; i++) {
512 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
517 p = bolt_pict(y, x, y, x, typ);
520 print_rel(caster_ptr, c, a, y, x);
524 move_cursor_relative(by, bx);
526 if (need_term_fresh())
528 if (visual || drawn) {
529 term_xtra(TERM_XTRA_DELAY, msec);
534 for (int i = 0; i < grids; i++) {
537 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
538 lite_spot(caster_ptr, y, x);
542 move_cursor_relative(by, bx);
543 if (need_term_fresh())
548 update_creature(caster_ptr);
550 if (flag & PROJECT_KILL) {
551 see_s_msg = (who > 0) ? is_seen(caster_ptr, &caster_ptr->current_floor_ptr->m_list[who])
552 : (!who ? TRUE : (player_can_see_bold(caster_ptr, y1, x1) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y1, x1)));
555 if (flag & (PROJECT_GRID)) {
557 for (int i = 0; i < grids; i++) {
558 if (gm[dist + 1] == i)
563 int d = dist_to_line(y, x, y1, x1, by, bx);
564 if (affect_feature(caster_ptr, who, d, y, x, dam, typ))
567 if (affect_feature(caster_ptr, who, dist, y, x, dam, typ))
573 update_creature(caster_ptr);
574 if (flag & (PROJECT_ITEM)) {
576 for (int i = 0; i < grids; i++) {
577 if (gm[dist + 1] == i)
583 int d = dist_to_line(y, x, y1, x1, by, bx);
584 if (affect_item(caster_ptr, who, d, y, x, dam, typ))
587 if (affect_item(caster_ptr, who, dist, y, x, dam, typ))
593 if (flag & (PROJECT_KILL)) {
598 for (int i = 0; i < grids; i++) {
600 if (gm[dist + 1] == i)
606 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[y][x].m_idx];
607 monster_race *ref_ptr = &r_info[m_ptr->r_idx];
608 if ((flag & PROJECT_REFLECTABLE) && caster_ptr->current_floor_ptr->grid_array[y][x].m_idx && (ref_ptr->flags2 & RF2_REFLECTING)
609 && ((caster_ptr->current_floor_ptr->grid_array[y][x].m_idx != caster_ptr->riding) || !(flag & PROJECT_PLAYER)) && (!who || dist_hack > 1)
612 int max_attempts = 10;
614 t_y = y_saver - 1 + randint1(3);
615 t_x = x_saver - 1 + randint1(3);
617 } while (max_attempts && in_bounds2u(caster_ptr->current_floor_ptr, t_y, t_x) && !projectable(caster_ptr, y, x, t_y, t_x));
619 if (max_attempts < 1) {
624 sound(SOUND_REFLECT);
625 if (is_seen(caster_ptr, m_ptr)) {
626 if ((m_ptr->r_idx == MON_KENSHIROU) || (m_ptr->r_idx == MON_RAOU))
627 msg_print(_("「北斗神拳奥義・二指真空把!」", "The attack bounces!"));
628 else if (m_ptr->r_idx == MON_DIO)
629 msg_print(_("ディオ・ブランドーは指一本で攻撃を弾き返した!", "The attack bounces!"));
631 msg_print(_("攻撃は跳ね返った!", "The attack bounces!"));
634 if (is_original_ap_and_seen(caster_ptr, m_ptr))
635 ref_ptr->r_flags2 |= RF2_REFLECTING;
637 if (player_bold(caster_ptr, y, x) || one_in_(2))
638 flag &= ~(PROJECT_PLAYER);
640 flag |= PROJECT_PLAYER;
642 project(caster_ptr, caster_ptr->current_floor_ptr->grid_array[y][x].m_idx, 0, t_y, t_x, dam, typ, flag, monspell);
647 /* Find the closest point in the blast */
649 effective_dist = dist_to_line(y, x, y1, x1, by, bx);
651 effective_dist = dist;
654 if (caster_ptr->riding && player_bold(caster_ptr, y, x)) {
655 if (flag & PROJECT_PLAYER) {
656 if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE | PROJECT_AIMED)) {
658 * A beam or bolt is well aimed
660 * So don't affects the mount.
665 * The spell is not well aimed,
666 * So partly affect the mount too.
673 * This grid is the original target.
674 * Or aimed on your horse.
676 else if (((y == y2) && (x == x2)) || (flag & PROJECT_AIMED)) {
677 /* Hit the mount with full damage */
681 * Otherwise this grid is not the
682 * original target, it means that line
683 * of fire is obstructed by this
687 * A beam or bolt will hit either
688 * player or mount. Choose randomly.
690 else if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE)) {
692 /* Hit the mount with full damage */
694 flag |= PROJECT_PLAYER;
700 * The spell is not well aimed, so
701 * partly affect both player and
709 if (affect_monster(caster_ptr, who, effective_dist, y, x, dam, typ, flag, see_s_msg))
713 /* Player affected one monster (without "jumping") */
714 if (!who && (project_m_n == 1) && !jump) {
717 if (caster_ptr->current_floor_ptr->grid_array[y][x].m_idx > 0) {
718 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[y][x].m_idx];
721 if (!caster_ptr->image)
722 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
723 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[y][x].m_idx);
729 if (flag & (PROJECT_KILL)) {
731 for (int i = 0; i < grids; i++) {
733 if (gm[dist + 1] == i)
738 if (!player_bold(caster_ptr, y, x))
741 /* Find the closest point in the blast */
743 effective_dist = dist_to_line(y, x, y1, x1, by, bx);
745 effective_dist = dist;
748 if (caster_ptr->riding) {
749 if (flag & PROJECT_PLAYER) {
750 /* Hit the player with full damage */
754 * Hack -- When this grid was not the
755 * original target, a beam or bolt
756 * would hit either player or mount,
757 * and should be choosen randomly.
759 * But already choosen to hit the
760 * mount at this point.
762 * Or aimed on your horse.
764 else if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE | PROJECT_AIMED)) {
766 * A beam or bolt is well aimed
768 * So don't affects the player.
773 * The spell is not well aimed,
774 * So partly affect the player too.
780 if (affect_player(who, caster_ptr, who_name, effective_dist, y, x, dam, typ, flag, monspell, project))
785 if (caster_ptr->riding) {
786 GAME_TEXT m_name[MAX_NLEN];
787 monster_desc(caster_ptr, m_name, &caster_ptr->current_floor_ptr->m_list[caster_ptr->riding], 0);
788 if (rakubadam_m > 0) {
789 if (process_fall_off_horse(caster_ptr, rakubadam_m, FALSE)) {
790 msg_format(_("%^sに振り落とされた!", "%^s has thrown you off!"), m_name);
794 if (caster_ptr->riding && rakubadam_p > 0) {
795 if (process_fall_off_horse(caster_ptr, rakubadam_p, FALSE)) {
796 msg_format(_("%^sから落ちてしまった!", "You have fallen from %s."), m_name);