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 "grid/feature.h"
12 #include "main/sound-definitions-table.h"
13 #include "main/sound-of-music.h"
14 #include "monster-race/monster-race.h"
15 #include "monster-race/race-flags2.h"
16 #include "monster-race/race-indice-types.h"
17 #include "monster/monster-describer.h"
18 #include "monster/monster-description-types.h"
19 #include "monster/monster-info.h"
20 #include "pet/pet-fall-off.h"
21 #include "spell/spell-types.h"
22 #include "spell/range-calc.h"
23 #include "term/gameterm.h"
24 #include "util/bit-flags-calculator.h"
25 #include "view/display-main-window.h" // 暫定、後で消すかも.
26 #include "view/display-messages.h"
29 * @brief 配置した鏡リストの次を取得する /
30 * Get another mirror. for SEEKER
31 * @param next_y 次の鏡のy座標を返す参照ポインタ
32 * @param next_x 次の鏡のx座標を返す参照ポインタ
33 * @param cury 現在の鏡のy座標
34 * @param curx 現在の鏡のx座標
36 static void next_mirror(player_type *creature_ptr, POSITION *next_y, POSITION *next_x, POSITION cury, POSITION curx)
38 POSITION mirror_x[10], mirror_y[10]; /* 鏡はもっと少ない */
39 int mirror_num = 0; /* 鏡の数 */
40 for (POSITION x = 0; x < creature_ptr->current_floor_ptr->width; x++) {
41 for (POSITION y = 0; y < creature_ptr->current_floor_ptr->height; y++) {
42 if (is_mirror_grid(&creature_ptr->current_floor_ptr->grid_array[y][x])) {
43 mirror_y[mirror_num] = y;
44 mirror_x[mirror_num] = x;
51 int num = randint0(mirror_num);
52 *next_y = mirror_y[num];
53 *next_x = mirror_x[num];
57 *next_y = cury + randint0(5) - 2;
58 *next_x = curx + randint0(5) - 2;
62 * todo 似たような処理が山ほど並んでいる、何とかならないものか
63 * todo 引数にそのまま再代入していてカオスすぎる。直すのは簡単ではない
64 * @brief 汎用的なビーム/ボルト/ボール系処理のルーチン Generic
65 * "beam"/"bolt"/"ball" projection routine.
66 * @param who 魔法を発動したモンスター(0ならばプレイヤー) / Index of "source"
67 * monster (zero for "player")
68 * @param rad 効果半径(ビーム/ボルト = 0 / ボール = 1以上) / Radius of explosion
69 * (0 = beam/bolt, 1 to 9 = ball)
70 * @param y 目標Y座標 / Target y location (or location to travel "towards")
71 * @param x 目標X座標 / Target x location (or location to travel "towards")
72 * @param dam 基本威力 / Base damage roll to apply to affected monsters (or
74 * @param typ 効果属性 / Type of damage to apply to monsters (and objects)
75 * @param flag 効果フラグ / Extra bit flags (see PROJECT_xxxx)
76 * @param monspell 効果元のモンスター魔法ID
77 * @return 何か一つでも効力があればTRUEを返す / TRUE if any "effects" of the
78 * projection were observed, else FALSE
80 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)
86 /* For reflecting monsters */
89 int msec = delay_factor * delay_factor * delay_factor;
94 bool blind = caster_ptr->blind != 0;
95 bool old_hide = FALSE;
102 POSITION gm_rad = rad;
104 GAME_TEXT who_name[MAX_NLEN];
105 bool see_s_msg = TRUE;
109 monster_target_y = caster_ptr->y;
110 monster_target_x = caster_ptr->x;
112 if (flag & (PROJECT_JUMP)) {
115 flag &= ~(PROJECT_JUMP);
117 } else if (who <= 0) {
120 } else if (who > 0) {
121 x1 = caster_ptr->current_floor_ptr->m_list[who].fx;
122 y1 = caster_ptr->current_floor_ptr->m_list[who].fy;
123 monster_desc(caster_ptr, who_name, &caster_ptr->current_floor_ptr->m_list[who], MD_WRONGDOER_NAME);
134 if (flag & (PROJECT_THRU)) {
135 if ((x1 == x2) && (y1 == y2)) {
136 flag &= ~(PROJECT_THRU);
143 if (flag & PROJECT_HIDE)
145 flag |= PROJECT_HIDE;
148 for (dist = 0; dist < 32; dist++)
154 if (flag & (PROJECT_BEAM)) {
163 if (breath || (flag & PROJECT_BEAM))
164 flag |= (PROJECT_LOS);
166 case GF_DISINTEGRATE:
167 flag |= (PROJECT_GRID);
168 if (breath || (flag & PROJECT_BEAM))
169 flag |= (PROJECT_DISI);
173 /* Calculate the projection path */
174 path_n = project_path(caster_ptr, path_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, flag);
175 handle_stuff(caster_ptr);
177 if (typ == GF_SEEKER) {
183 for (int i = 0; i < path_n; ++i) {
186 POSITION ny = GRID_Y(path_g[i]);
187 POSITION nx = GRID_X(path_g[i]);
194 if (!blind && !(flag & (PROJECT_HIDE))) {
195 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
196 u16b p = bolt_pict(oy, ox, y, x, typ);
197 TERM_COLOR a = PICT_A(p);
198 SYMBOL_CODE c = PICT_C(p);
199 print_rel(caster_ptr, c, a, y, x);
200 move_cursor_relative(y, x);
202 Term_xtra(TERM_XTRA_DELAY, msec);
203 lite_spot(caster_ptr, y, x);
205 if (flag & (PROJECT_BEAM)) {
206 p = bolt_pict(y, x, y, x, typ);
209 print_rel(caster_ptr, c, a, y, x);
214 Term_xtra(TERM_XTRA_DELAY, msec);
218 if (affect_item(caster_ptr, 0, 0, y, x, dam, GF_SEEKER))
220 if (!is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]))
223 monster_target_y = y;
224 monster_target_x = x;
225 remove_mirror(caster_ptr, y, x);
226 next_mirror(caster_ptr, &oy, &ox, y, x);
227 path_n = i + project_path(caster_ptr, &(path_g[i + 1]), (project_length ? project_length : MAX_RANGE), y, x, oy, ox, flag);
228 for (j = last_i; j <= i; j++) {
229 y = GRID_Y(path_g[j]);
230 x = GRID_X(path_g[j]);
231 if (affect_monster(caster_ptr, 0, 0, y, x, dam, GF_SEEKER, flag, TRUE))
233 if (!who && (project_m_n == 1) && !jump && (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0)) {
234 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];
236 if (!caster_ptr->image)
237 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
238 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
242 (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_SEEKER);
248 for (int i = last_i; i < path_n; i++) {
250 py = GRID_Y(path_g[i]);
251 px = GRID_X(path_g[i]);
252 if (affect_monster(caster_ptr, 0, 0, py, px, dam, GF_SEEKER, flag, TRUE))
254 if (!who && (project_m_n == 1) && !jump) {
255 if (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0) {
256 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];
259 if (!caster_ptr->image)
260 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
261 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
266 (void)affect_feature(caster_ptr, 0, 0, py, px, dam, GF_SEEKER);
270 } else if (typ == GF_SUPER_RAY) {
276 for (int i = 0; i < path_n; ++i) {
279 POSITION ny = GRID_Y(path_g[i]);
280 POSITION nx = GRID_X(path_g[i]);
287 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
291 p = bolt_pict(oy, ox, y, x, typ);
294 print_rel(caster_ptr, c, a, y, x);
295 move_cursor_relative(y, x);
297 Term_xtra(TERM_XTRA_DELAY, msec);
298 lite_spot(caster_ptr, y, x);
300 if (flag & (PROJECT_BEAM)) {
301 p = bolt_pict(y, x, y, x, typ);
304 print_rel(caster_ptr, c, a, y, x);
309 Term_xtra(TERM_XTRA_DELAY, msec);
313 if (affect_item(caster_ptr, 0, 0, y, x, dam, GF_SUPER_RAY))
315 if (!cave_have_flag_bold(caster_ptr->current_floor_ptr, y, x, FF_PROJECT)) {
321 if (is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]) && !second_step) {
322 monster_target_y = y;
323 monster_target_x = x;
324 remove_mirror(caster_ptr, y, x);
325 for (j = 0; j <= i; j++) {
326 y = GRID_Y(path_g[j]);
327 x = GRID_X(path_g[j]);
328 (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_SUPER_RAY);
333 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y - 1, x - 1, flag);
334 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y - 1, x, flag);
335 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y - 1, 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, 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 - 1, flag);
339 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y + 1, x, flag);
340 path_n += project_path(caster_ptr, &(path_g[path_n + 1]), (project_length ? project_length : MAX_RANGE), y, x, y + 1, x + 1, flag);
344 for (int i = 0; i < path_n; i++) {
345 POSITION py = GRID_Y(path_g[i]);
346 POSITION px = GRID_X(path_g[i]);
347 (void)affect_monster(caster_ptr, 0, 0, py, px, dam, GF_SUPER_RAY, flag, TRUE);
348 if (!who && (project_m_n == 1) && !jump) {
349 if (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0) {
350 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];
353 if (!caster_ptr->image)
354 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
355 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx);
360 (void)affect_feature(caster_ptr, 0, 0, py, px, dam, GF_SUPER_RAY);
367 for (k = 0; k < path_n; ++k) {
370 POSITION ny = GRID_Y(path_g[k]);
371 POSITION nx = GRID_X(path_g[k]);
372 if (flag & PROJECT_DISI) {
373 if (cave_stop_disintegration(caster_ptr->current_floor_ptr, ny, nx) && (rad > 0))
375 } else if (flag & PROJECT_LOS) {
376 if (!cave_los_bold(caster_ptr->current_floor_ptr, ny, nx) && (rad > 0))
379 if (!cave_have_flag_bold(caster_ptr->current_floor_ptr, ny, nx, FF_PROJECT) && (rad > 0))
385 if (flag & (PROJECT_BEAM)) {
391 if (!blind && !(flag & (PROJECT_HIDE | PROJECT_FAST))) {
392 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
396 p = bolt_pict(oy, ox, y, x, typ);
399 print_rel(caster_ptr, c, a, y, x);
400 move_cursor_relative(y, x);
402 Term_xtra(TERM_XTRA_DELAY, msec);
403 lite_spot(caster_ptr, y, x);
405 if (flag & (PROJECT_BEAM)) {
406 p = bolt_pict(y, x, y, x, typ);
409 print_rel(caster_ptr, c, a, y, x);
414 Term_xtra(TERM_XTRA_DELAY, msec);
422 if (breath && !path_n) {
426 flag &= ~(PROJECT_HIDE);
433 int dist_hack = dist;
436 /* If we found a "target", explode there */
437 if (dist <= MAX_RANGE) {
438 if ((flag & (PROJECT_BEAM)) && (grids > 0))
442 * Create a conical breath attack
451 flag &= ~(PROJECT_HIDE);
452 breath_shape(caster_ptr, path_g, dist, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, by, bx, typ);
454 for (dist = 0; dist <= rad; dist++) {
455 for (y = by - dist; y <= by + dist; y++) {
456 for (x = bx - dist; x <= bx + dist; x++) {
457 if (!in_bounds2(caster_ptr->current_floor_ptr, y, x))
459 if (distance(by, bx, y, x) != dist)
465 if (!los(caster_ptr, by, bx, y, x))
468 case GF_DISINTEGRATE:
469 if (!in_disintegration_range(caster_ptr->current_floor_ptr, by, bx, y, x))
473 if (!projectable(caster_ptr, by, bx, y, x))
484 gm[dist + 1] = grids;
492 if (!blind && !(flag & (PROJECT_HIDE))) {
493 for (int t = 0; t <= gm_rad; t++) {
494 for (int i = gm[t]; i < gm[t + 1]; i++) {
497 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
502 p = bolt_pict(y, x, y, x, typ);
505 print_rel(caster_ptr, c, a, y, x);
509 move_cursor_relative(by, bx);
511 if (visual || drawn) {
512 Term_xtra(TERM_XTRA_DELAY, msec);
517 for (int i = 0; i < grids; i++) {
520 if (panel_contains(y, x) && player_has_los_bold(caster_ptr, y, x)) {
521 lite_spot(caster_ptr, y, x);
525 move_cursor_relative(by, bx);
530 update_creature(caster_ptr);
532 if (flag & PROJECT_KILL) {
533 see_s_msg = (who > 0) ? is_seen(caster_ptr, &caster_ptr->current_floor_ptr->m_list[who])
534 : (!who ? TRUE : (player_can_see_bold(caster_ptr, y1, x1) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y1, x1)));
537 if (flag & (PROJECT_GRID)) {
539 for (int i = 0; i < grids; i++) {
540 if (gm[dist + 1] == i)
545 int d = dist_to_line(y, x, y1, x1, by, bx);
546 if (affect_feature(caster_ptr, who, d, y, x, dam, typ))
549 if (affect_feature(caster_ptr, who, dist, y, x, dam, typ))
555 update_creature(caster_ptr);
556 if (flag & (PROJECT_ITEM)) {
558 for (int i = 0; i < grids; i++) {
559 if (gm[dist + 1] == i)
565 int d = dist_to_line(y, x, y1, x1, by, bx);
566 if (affect_item(caster_ptr, who, d, y, x, dam, typ))
569 if (affect_item(caster_ptr, who, dist, y, x, dam, typ))
575 if (flag & (PROJECT_KILL)) {
580 for (int i = 0; i < grids; i++) {
582 if (gm[dist + 1] == i)
588 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[y][x].m_idx];
589 monster_race *ref_ptr = &r_info[m_ptr->r_idx];
590 if ((flag & PROJECT_REFLECTABLE) && caster_ptr->current_floor_ptr->grid_array[y][x].m_idx && (ref_ptr->flags2 & RF2_REFLECTING)
591 && ((caster_ptr->current_floor_ptr->grid_array[y][x].m_idx != caster_ptr->riding) || !(flag & PROJECT_PLAYER)) && (!who || dist_hack > 1)
594 int max_attempts = 10;
596 t_y = y_saver - 1 + randint1(3);
597 t_x = x_saver - 1 + randint1(3);
599 } while (max_attempts && in_bounds2u(caster_ptr->current_floor_ptr, t_y, t_x) && !projectable(caster_ptr, y, x, t_y, t_x));
601 if (max_attempts < 1) {
606 sound(SOUND_REFLECT);
607 if (is_seen(caster_ptr, m_ptr)) {
608 if ((m_ptr->r_idx == MON_KENSHIROU) || (m_ptr->r_idx == MON_RAOU))
609 msg_print(_("「北斗神拳奥義・二指真空把!」", "The attack bounces!"));
610 else if (m_ptr->r_idx == MON_DIO)
611 msg_print(_("ディオ・ブランドーは指一本で攻撃を弾き返した!", "The attack bounces!"));
613 msg_print(_("攻撃は跳ね返った!", "The attack bounces!"));
616 if (is_original_ap_and_seen(caster_ptr, m_ptr))
617 ref_ptr->r_flags2 |= RF2_REFLECTING;
619 if (player_bold(caster_ptr, y, x) || one_in_(2))
620 flag &= ~(PROJECT_PLAYER);
622 flag |= PROJECT_PLAYER;
624 project(caster_ptr, caster_ptr->current_floor_ptr->grid_array[y][x].m_idx, 0, t_y, t_x, dam, typ, flag, monspell);
629 /* Find the closest point in the blast */
631 effective_dist = dist_to_line(y, x, y1, x1, by, bx);
633 effective_dist = dist;
636 if (caster_ptr->riding && player_bold(caster_ptr, y, x)) {
637 if (flag & PROJECT_PLAYER) {
638 if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE | PROJECT_AIMED)) {
640 * A beam or bolt is well aimed
642 * So don't affects the mount.
647 * The spell is not well aimed,
648 * So partly affect the mount too.
655 * This grid is the original target.
656 * Or aimed on your horse.
658 else if (((y == y2) && (x == x2)) || (flag & PROJECT_AIMED)) {
659 /* Hit the mount with full damage */
663 * Otherwise this grid is not the
664 * original target, it means that line
665 * of fire is obstructed by this
669 * A beam or bolt will hit either
670 * player or mount. Choose randomly.
672 else if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE)) {
674 /* Hit the mount with full damage */
676 flag |= PROJECT_PLAYER;
682 * The spell is not well aimed, so
683 * partly affect both player and
691 if (affect_monster(caster_ptr, who, effective_dist, y, x, dam, typ, flag, see_s_msg))
695 /* Player affected one monster (without "jumping") */
696 if (!who && (project_m_n == 1) && !jump) {
699 if (caster_ptr->current_floor_ptr->grid_array[y][x].m_idx > 0) {
700 monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[caster_ptr->current_floor_ptr->grid_array[y][x].m_idx];
703 if (!caster_ptr->image)
704 monster_race_track(caster_ptr, m_ptr->ap_r_idx);
705 health_track(caster_ptr, caster_ptr->current_floor_ptr->grid_array[y][x].m_idx);
711 if (flag & (PROJECT_KILL)) {
713 for (int i = 0; i < grids; i++) {
715 if (gm[dist + 1] == i)
720 if (!player_bold(caster_ptr, y, x))
723 /* Find the closest point in the blast */
725 effective_dist = dist_to_line(y, x, y1, x1, by, bx);
727 effective_dist = dist;
730 if (caster_ptr->riding) {
731 if (flag & PROJECT_PLAYER) {
732 /* Hit the player with full damage */
736 * Hack -- When this grid was not the
737 * original target, a beam or bolt
738 * would hit either player or mount,
739 * and should be choosen randomly.
741 * But already choosen to hit the
742 * mount at this point.
744 * Or aimed on your horse.
746 else if (flag & (PROJECT_BEAM | PROJECT_REFLECTABLE | PROJECT_AIMED)) {
748 * A beam or bolt is well aimed
750 * So don't affects the player.
755 * The spell is not well aimed,
756 * So partly affect the player too.
762 if (affect_player(who, caster_ptr, who_name, effective_dist, y, x, dam, typ, flag, monspell, project))
767 if (caster_ptr->riding) {
768 GAME_TEXT m_name[MAX_NLEN];
769 monster_desc(caster_ptr, m_name, &caster_ptr->current_floor_ptr->m_list[caster_ptr->riding], 0);
770 if (rakubadam_m > 0) {
771 if (process_fall_off_horse(caster_ptr, rakubadam_m, FALSE)) {
772 msg_format(_("%^sに振り落とされた!", "%^s has thrown you off!"), m_name);
776 if (caster_ptr->riding && rakubadam_p > 0) {
777 if (process_fall_off_horse(caster_ptr, rakubadam_p, FALSE)) {
778 msg_format(_("%^sから落ちてしまった!", "You have fallen from %s."), m_name);