1 #include "spell/process-effect.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/floor.h"
10 #include "game-option/special-options.h"
11 #include "main/sound-definitions-table.h"
12 #include "main/sound-of-music.h"
13 #include "monster-race/monster-race.h"
14 #include "monster-race/race-flags2.h"
15 #include "monster-race/race-indice-types.h"
16 #include "monster/monster-describer.h"
17 #include "monster/monster-description-types.h"
18 #include "monster/monster-info.h"
19 #include "pet/pet-fall-off.h"
20 #include "spell/spell-types.h"
21 #include "spell/range-calc.h"
22 #include "term/gameterm.h"
23 #include "util/bit-flags-calculator.h"
24 #include "view/display-main-window.h" // 暫定、後で消すかも.
25 #include "view/display-messages.h"
28 * @brief 配置した鏡リストの次を取得する /
29 * Get another mirror. for SEEKER
30 * @param next_y 次の鏡のy座標を返す参照ポインタ
31 * @param next_x 次の鏡のx座標を返す参照ポインタ
32 * @param cury 現在の鏡のy座標
33 * @param curx 現在の鏡のx座標
35 static void next_mirror(player_type *creature_ptr, POSITION *next_y, POSITION *next_x, POSITION cury, POSITION curx)
37 POSITION mirror_x[10], mirror_y[10]; /* 鏡はもっと少ない */
38 int mirror_num = 0; /* 鏡の数 */
39 for (POSITION x = 0; x < creature_ptr->current_floor_ptr->width; x++) {
40 for (POSITION y = 0; y < creature_ptr->current_floor_ptr->height; y++) {
41 if (is_mirror_grid(&creature_ptr->current_floor_ptr->grid_array[y][x])) {
42 mirror_y[mirror_num] = y;
43 mirror_x[mirror_num] = x;
50 int num = randint0(mirror_num);
51 *next_y = mirror_y[num];
52 *next_x = mirror_x[num];
56 *next_y = cury + randint0(5) - 2;
57 *next_x = curx + randint0(5) - 2;
61 * todo 似たような処理が山ほど並んでいる、何とかならないものか
62 * todo 引数にそのまま再代入していてカオスすぎる。直すのは簡単ではない
63 * @brief 汎用的なビーム/ボルト/ボール系処理のルーチン Generic
64 * "beam"/"bolt"/"ball" projection routine.
65 * @param who 魔法を発動したモンスター(0ならばプレイヤー) / Index of "source"
66 * monster (zero for "player")
67 * @param rad 効果半径(ビーム/ボルト = 0 / ボール = 1以上) / Radius of explosion
68 * (0 = beam/bolt, 1 to 9 = ball)
69 * @param y 目標Y座標 / Target y location (or location to travel "towards")
70 * @param x 目標X座標 / Target x location (or location to travel "towards")
71 * @param dam 基本威力 / Base damage roll to apply to affected monsters (or
73 * @param typ 効果属性 / Type of damage to apply to monsters (and objects)
74 * @param flag 効果フラグ / Extra bit flags (see PROJECT_xxxx)
75 * @param monspell 効果元のモンスター魔法ID
76 * @return 何か一つでも効力があればTRUEを返す / TRUE if any "effects" of the
77 * projection were observed, else FALSE
79 bool project(player_type *caster_ptr, MONSTER_IDX who, POSITION rad, POSITION y, POSITION x, HIT_POINT dam, EFFECT_ID typ, BIT_FLAGS flag, int monspell)
85 /* For reflecting monsters */
88 int msec = delay_factor * delay_factor * delay_factor;
93 bool blind = caster_ptr->blind != 0;
94 bool old_hide = FALSE;
101 POSITION gm_rad = rad;
103 GAME_TEXT who_name[MAX_NLEN];
104 bool see_s_msg = TRUE;
108 monster_target_y = caster_ptr->y;
109 monster_target_x = caster_ptr->x;
111 if (flag & (PROJECT_JUMP)) {
114 flag &= ~(PROJECT_JUMP);
116 } else if (who <= 0) {
119 } else if (who > 0) {
120 x1 = caster_ptr->current_floor_ptr->m_list[who].fx;
121 y1 = caster_ptr->current_floor_ptr->m_list[who].fy;
122 monster_desc(caster_ptr, who_name, &caster_ptr->current_floor_ptr->m_list[who], MD_WRONGDOER_NAME);
133 if (flag & (PROJECT_THRU)) {
134 if ((x1 == x2) && (y1 == y2)) {
135 flag &= ~(PROJECT_THRU);
142 if (flag & PROJECT_HIDE)
144 flag |= PROJECT_HIDE;
147 for (dist = 0; dist < 32; dist++)
153 if (flag & (PROJECT_BEAM)) {
162 if (breath || (flag & PROJECT_BEAM))
163 flag |= (PROJECT_LOS);
165 case GF_DISINTEGRATE:
166 flag |= (PROJECT_GRID);
167 if (breath || (flag & PROJECT_BEAM))
168 flag |= (PROJECT_DISI);
172 /* Calculate the projection path */
173 path_n = project_path(caster_ptr, path_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, flag);
174 handle_stuff(caster_ptr);
176 if (typ == GF_SEEKER) {
182 for (int i = 0; i < path_n; ++i) {
185 POSITION ny = GRID_Y(path_g[i]);
186 POSITION nx = GRID_X(path_g[i]);
193 if (!blind && !(flag & (PROJECT_HIDE))) {
194 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
195 u16b p = bolt_pict(oy, ox, y, x, typ);
196 TERM_COLOR a = PICT_A(p);
197 SYMBOL_CODE c = PICT_C(p);
198 print_rel(caster_ptr, c, a, y, x);
199 move_cursor_relative(y, x);
201 Term_xtra(TERM_XTRA_DELAY, msec);
202 lite_spot(caster_ptr, y, x);
204 if (flag & (PROJECT_BEAM)) {
205 p = bolt_pict(y, x, y, x, typ);
208 print_rel(caster_ptr, c, a, y, x);
213 Term_xtra(TERM_XTRA_DELAY, msec);
217 if (affect_item(caster_ptr, 0, 0, y, x, dam, GF_SEEKER))
219 if (!is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]))
222 monster_target_y = y;
223 monster_target_x = x;
224 remove_mirror(caster_ptr, y, x);
225 next_mirror(caster_ptr, &oy, &ox, y, x);
226 path_n = i + project_path(caster_ptr, &(path_g[i + 1]), (project_length ? project_length : MAX_RANGE), y, x, oy, ox, flag);
227 for (j = last_i; j <= i; j++) {
228 y = GRID_Y(path_g[j]);
229 x = GRID_X(path_g[j]);
230 if (affect_monster(caster_ptr, 0, 0, y, x, dam, GF_SEEKER, flag, TRUE))
232 if (!who && (project_m_n == 1) && !jump && (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0)) {
233 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];
235 if (!caster_ptr->image)
236 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
237 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
241 (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_SEEKER);
247 for (int i = last_i; i < path_n; i++) {
249 py = GRID_Y(path_g[i]);
250 px = GRID_X(path_g[i]);
251 if (affect_monster(caster_ptr, 0, 0, py, px, dam, GF_SEEKER, flag, TRUE))
253 if (!who && (project_m_n == 1) && !jump) {
254 if (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0) {
255 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];
258 if (!caster_ptr->image)
259 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
260 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
265 (void)affect_feature(caster_ptr, 0, 0, py, px, dam, GF_SEEKER);
269 } else if (typ == GF_SUPER_RAY) {
275 for (int i = 0; i < path_n; ++i) {
278 POSITION ny = GRID_Y(path_g[i]);
279 POSITION nx = GRID_X(path_g[i]);
286 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
290 p = bolt_pict(oy, ox, y, x, typ);
293 print_rel(caster_ptr, c, a, y, x);
294 move_cursor_relative(y, x);
296 Term_xtra(TERM_XTRA_DELAY, msec);
297 lite_spot(caster_ptr, y, x);
299 if (flag & (PROJECT_BEAM)) {
300 p = bolt_pict(y, x, y, x, typ);
303 print_rel(caster_ptr, c, a, y, x);
308 Term_xtra(TERM_XTRA_DELAY, msec);
312 if (affect_item(caster_ptr, 0, 0, y, x, dam, GF_SUPER_RAY))
314 if (!cave_have_flag_bold(caster_ptr->current_floor_ptr, y, x, FF_PROJECT)) {
320 if (is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]) && !second_step) {
321 monster_target_y = y;
322 monster_target_x = x;
323 remove_mirror(caster_ptr, y, x);
324 for (j = 0; j <= i; j++) {
325 y = GRID_Y(path_g[j]);
326 x = GRID_X(path_g[j]);
327 (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_SUPER_RAY);
332 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y - 1, x - 1, flag);
333 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y - 1, x, flag);
334 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y - 1, x + 1, flag);
335 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y, x - 1, flag);
336 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y, x + 1, flag);
337 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y + 1, x - 1, flag);
338 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y + 1, x, flag);
339 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y + 1, x + 1, flag);
343 for (int i = 0; i < path_n; i++) {
344 POSITION py = GRID_Y(path_g[i]);
345 POSITION px = GRID_X(path_g[i]);
346 (void)affect_monster(caster_ptr, 0, 0, py, px, dam, GF_SUPER_RAY, flag, TRUE);
347 if (!who && (project_m_n == 1) && !jump) {
348 if (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0) {
349 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];
352 if (!caster_ptr->image)
353 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
354 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
359 (void)affect_feature(caster_ptr, 0, 0, py, px, dam, GF_SUPER_RAY);
366 for (k = 0; k < path_n; ++k) {
369 POSITION ny = GRID_Y(path_g[k]);
370 POSITION nx = GRID_X(path_g[k]);
371 if (flag & PROJECT_DISI) {
372 if (cave_stop_disintegration(caster_ptr->current_floor_ptr, ny, nx) && (rad > 0))
374 } else if (flag & PROJECT_LOS) {
375 if (!cave_los_bold(caster_ptr->current_floor_ptr, ny, nx) && (rad > 0))
378 if (!cave_have_flag_bold(caster_ptr->current_floor_ptr, ny, nx, FF_PROJECT) && (rad > 0))
384 if (flag & (PROJECT_BEAM)) {
390 if (!blind && !(flag & (PROJECT_HIDE | PROJECT_FAST))) {
391 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
395 p = bolt_pict(oy, ox, y, x, typ);
398 print_rel(caster_ptr, c, a, y, x);
399 move_cursor_relative(y, x);
401 Term_xtra(TERM_XTRA_DELAY, msec);
402 lite_spot(caster_ptr, y, x);
404 if (flag & (PROJECT_BEAM)) {
405 p = bolt_pict(y, x, y, x, typ);
408 print_rel(caster_ptr, c, a, y, x);
413 Term_xtra(TERM_XTRA_DELAY, msec);
421 if (breath && !path_n) {
425 flag &= ~(PROJECT_HIDE);
432 int dist_hack = dist;
435 /* If we found a "target", explode there */
436 if (dist <= MAX_RANGE) {
437 if ((flag & (PROJECT_BEAM)) && (grids > 0))
441 * Create a conical breath attack
450 flag &= ~(PROJECT_HIDE);
451 breath_shape(caster_ptr, path_g, dist, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, by, bx, typ);
453 for (dist = 0; dist <= rad; dist++) {
454 for (y = by - dist; y <= by + dist; y++) {
455 for (x = bx - dist; x <= bx + dist; x++) {
456 if (!in_bounds2(caster_ptr->current_floor_ptr, y, x))
458 if (distance(by, bx, y, x) != dist)
464 if (!los(caster_ptr, by, bx, y, x))
467 case GF_DISINTEGRATE:
468 if (!in_disintegration_range(caster_ptr->current_floor_ptr, by, bx, y, x))
472 if (!projectable(caster_ptr, by, bx, y, x))
483 gm[dist + 1] = grids;
491 if (!blind && !(flag & (PROJECT_HIDE))) {
492 for (int t = 0; t <= gm_rad; t++) {
493 for (int i = gm[t]; i < gm[t + 1]; i++) {
496 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
501 p = bolt_pict(y, x, y, x, typ);
504 print_rel(caster_ptr, c, a, y, x);
508 move_cursor_relative(by, bx);
510 if (visual || drawn) {
511 Term_xtra(TERM_XTRA_DELAY, msec);
516 for (int i = 0; i < grids; i++) {
519 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
520 lite_spot(caster_ptr, y, x);
524 move_cursor_relative(by, bx);
529 update_creature(caster_ptr);
531 if (flag & PROJECT_KILL) {
532 see_s_msg = (who > 0) ? is_seen(caster_ptr, &caster_ptr->current_floor_ptr->m_list[who])
533 : (!who ? TRUE : (player_can_see_bold(caster_ptr, y1, x1) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y1, x1)));
536 if (flag & (PROJECT_GRID)) {
538 for (int i = 0; i < grids; i++) {
539 if (gm[dist + 1] == i)
544 int d = dist_to_line(y, x, y1, x1, by, bx);
545 if (affect_feature(caster_ptr, who, d, y, x, dam, typ))
548 if (affect_feature(caster_ptr, who, dist, y, x, dam, typ))
554 update_creature(caster_ptr);
555 if (flag & (PROJECT_ITEM)) {
557 for (int i = 0; i < grids; i++) {
558 if (gm[dist + 1] == i)
564 int d = dist_to_line(y, x, y1, x1, by, bx);
565 if (affect_item(caster_ptr, who, d, y, x, dam, typ))
568 if (affect_item(caster_ptr, who, dist, y, x, dam, typ))
574 if (flag & (PROJECT_KILL)) {
579 for (int i = 0; i < grids; i++) {
581 if (gm[dist + 1] == i)
587 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[y][x].m_idx];
588 monster_race *ref_ptr = &r_info[m_ptr->r_idx];
589 if ((flag & PROJECT_REFLECTABLE) && caster_ptr->current_floor_ptr->grid_array[y][x].m_idx && (ref_ptr->flags2 & RF2_REFLECTING)
590 && ((caster_ptr->current_floor_ptr->grid_array[y][x].m_idx != caster_ptr->riding) || !(flag & PROJECT_PLAYER)) && (!who || dist_hack > 1)
593 int max_attempts = 10;
595 t_y = y_saver - 1 + randint1(3);
596 t_x = x_saver - 1 + randint1(3);
598 } while (max_attempts && in_bounds2u(caster_ptr->current_floor_ptr, t_y, t_x) && !projectable(caster_ptr, y, x, t_y, t_x));
600 if (max_attempts < 1) {
605 sound(SOUND_REFLECT);
606 if (is_seen(caster_ptr, m_ptr)) {
607 if ((m_ptr->r_idx == MON_KENSHIROU) || (m_ptr->r_idx == MON_RAOU))
608 msg_print(_("「北斗神拳奥義・二指真空把!」", "The attack bounces!"));
609 else if (m_ptr->r_idx == MON_DIO)
610 msg_print(_("ディオ・ブランドーは指一本で攻撃を弾き返した!", "The attack bounces!"));
612 msg_print(_("攻撃は跳ね返った!", "The attack bounces!"));
615 if (is_original_ap_and_seen(caster_ptr, m_ptr))
616 ref_ptr->r_flags2 |= RF2_REFLECTING;
618 if (player_bold(caster_ptr, y, x) || one_in_(2))
619 flag &= ~(PROJECT_PLAYER);
621 flag |= PROJECT_PLAYER;
623 project(caster_ptr, caster_ptr->current_floor_ptr->grid_array[y][x].m_idx, 0, t_y, t_x, dam, typ, flag, monspell);
628 /* Find the closest point in the blast */
630 effective_dist = dist_to_line(y, x, y1, x1, by, bx);
632 effective_dist = dist;
635 if (caster_ptr->riding && player_bold(caster_ptr, y, x)) {
636 if (flag & PROJECT_PLAYER) {
637 if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE | PROJECT_AIMED)) {
639 * A beam or bolt is well aimed
641 * So don't affects the mount.
646 * The spell is not well aimed,
647 * So partly affect the mount too.
654 * This grid is the original target.
655 * Or aimed on your horse.
657 else if (((y == y2) && (x == x2)) || (flag & PROJECT_AIMED)) {
658 /* Hit the mount with full damage */
662 * Otherwise this grid is not the
663 * original target, it means that line
664 * of fire is obstructed by this
668 * A beam or bolt will hit either
669 * player or mount. Choose randomly.
671 else if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE)) {
673 /* Hit the mount with full damage */
675 flag |= PROJECT_PLAYER;
681 * The spell is not well aimed, so
682 * partly affect both player and
690 if (affect_monster(caster_ptr, who, effective_dist, y, x, dam, typ, flag, see_s_msg))
694 /* Player affected one monster (without "jumping") */
695 if (!who && (project_m_n == 1) && !jump) {
698 if (caster_ptr->current_floor_ptr->grid_array[y][x].m_idx > 0) {
699 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[y][x].m_idx];
702 if (!caster_ptr->image)
703 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
704 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[y][x].m_idx);
710 if (flag & (PROJECT_KILL)) {
712 for (int i = 0; i < grids; i++) {
714 if (gm[dist + 1] == i)
719 if (!player_bold(caster_ptr, y, x))
722 /* Find the closest point in the blast */
724 effective_dist = dist_to_line(y, x, y1, x1, by, bx);
726 effective_dist = dist;
729 if (caster_ptr->riding) {
730 if (flag & PROJECT_PLAYER) {
731 /* Hit the player with full damage */
735 * Hack -- When this grid was not the
736 * original target, a beam or bolt
737 * would hit either player or mount,
738 * and should be choosen randomly.
740 * But already choosen to hit the
741 * mount at this point.
743 * Or aimed on your horse.
745 else if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE | PROJECT_AIMED)) {
747 * A beam or bolt is well aimed
749 * So don't affects the player.
754 * The spell is not well aimed,
755 * So partly affect the player too.
761 if (affect_player(who, caster_ptr, who_name, effective_dist, y, x, dam, typ, flag, monspell, project))
766 if (caster_ptr->riding) {
767 GAME_TEXT m_name[MAX_NLEN];
768 monster_desc(caster_ptr, m_name, &caster_ptr->current_floor_ptr->m_list[caster_ptr->riding], 0);
769 if (rakubadam_m > 0) {
770 if (process_fall_off_horse(caster_ptr, rakubadam_m, FALSE)) {
771 msg_format(_("%^sに振り落とされた!", "%^s has thrown you off!"), m_name);
775 if (caster_ptr->riding && rakubadam_p > 0) {
776 if (process_fall_off_horse(caster_ptr, rakubadam_p, FALSE)) {
777 msg_format(_("%^sから落ちてしまった!", "You have fallen from %s."), m_name);