From e78477b266c53aed2097ca996eef4caae11da6c8 Mon Sep 17 00:00:00 2001 From: Hourier Date: Thu, 20 Aug 2020 19:01:05 +0900 Subject: [PATCH] [Refactor] #40577 Moved projectable() from floor.c/h to projection-path-calculator.c/h --- src/blue-magic/blue-magic-caster.c | 2 +- src/cmd-action/cmd-mane.c | 2 +- src/effect/effect-player.c | 2 +- src/effect/effect-processor.c | 28 ++++++++++----------- src/floor/floor-leaver.c | 2 +- src/floor/floor-object.c | 2 +- src/floor/floor.c | 28 --------------------- src/floor/floor.h | 14 ----------- src/floor/geometry.c | 2 +- src/grid/trap.c | 2 +- src/io/cursor.c | 4 +-- src/melee/melee-spell-flags-checker.c | 2 +- src/mind/mind-force-trainer.c | 2 +- src/mind/mind-mirror-master.c | 2 +- src/mind/mind-ninja.c | 4 +-- src/monster-floor/monster-direction.c | 2 +- src/monster-floor/monster-generator.c | 1 + src/monster-floor/monster-move.c | 2 +- src/monster-floor/monster-runaway.c | 2 +- src/monster-floor/monster-safety-hiding.c | 2 +- src/monster-floor/monster-sweep-grid.c | 2 +- src/monster/monster-processor.c | 2 +- src/monster/monster-status-setter.c | 2 +- src/monster/monster-update.c | 2 +- src/mspell/mspell-attack.c | 2 +- src/mspell/mspell-checker.c | 9 +++---- src/mspell/mspell-judgement.c | 13 +++++----- src/mspell/mspell-lite.c | 2 +- src/object/warning.c | 2 +- src/realm/realm-hissatsu.c | 2 +- src/spell-kind/spells-fetcher.c | 5 ++-- src/spell-kind/spells-lite.c | 1 + src/spell-kind/spells-sight.c | 2 +- src/spell-kind/spells-world.c | 2 +- src/spell-realm/spells-chaos.c | 2 +- src/spell-realm/spells-crusade.c | 2 +- src/spell/range-calc.c | 6 ++--- src/spell/spells-summon.c | 2 +- src/target/projection-path-calculator.c | 42 ++++++++++++++++++++++++++++++- src/target/projection-path-calculator.h | 4 +++ src/target/target-setter.c | 2 +- 41 files changed, 108 insertions(+), 107 deletions(-) diff --git a/src/blue-magic/blue-magic-caster.c b/src/blue-magic/blue-magic-caster.c index 58dcbec35..c71c07d15 100644 --- a/src/blue-magic/blue-magic-caster.c +++ b/src/blue-magic/blue-magic-caster.c @@ -8,7 +8,6 @@ #include "blue-magic/learnt-info.h" #include "core/hp-mp-processor.h" #include "floor/cave.h" -#include "floor/floor.h" #include "grid/grid.h" #include "monster-race/monster-race.h" #include "monster-race/race-flags-resistance.h" @@ -29,6 +28,7 @@ #include "status/body-improvement.h" #include "status/buff-setter.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "target/target-checker.h" #include "target/target-getter.h" #include "target/target-setter.h" diff --git a/src/cmd-action/cmd-mane.c b/src/cmd-action/cmd-mane.c index 9ae142439..13c32da62 100644 --- a/src/cmd-action/cmd-mane.c +++ b/src/cmd-action/cmd-mane.c @@ -18,7 +18,6 @@ #include "core/window-redrawer.h" #include "floor/cave.h" #include "floor/floor-object.h" -#include "floor/floor.h" #include "game-option/disturbance-options.h" #include "game-option/text-display-options.h" #include "grid/grid.h" @@ -50,6 +49,7 @@ #include "status/body-improvement.h" #include "status/buff-setter.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "target/target-checker.h" #include "target/target-getter.h" #include "target/target-setter.h" diff --git a/src/effect/effect-player.c b/src/effect/effect-player.c index 8a32c6c31..2a10f4b03 100644 --- a/src/effect/effect-player.c +++ b/src/effect/effect-player.c @@ -11,7 +11,6 @@ #include "effect/effect-player-util.h" #include "effect/spells-effect-util.h" #include "floor/cave.h" -#include "floor/floor.h" #include "main/sound-definitions-table.h" #include "main/sound-of-music.h" #include "mind/mind-ninja.h" @@ -24,6 +23,7 @@ #include "spell-realm/spells-hex.h" #include "spell/spell-types.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "view/display-messages.h" typedef enum effect_player_check_result { diff --git a/src/effect/effect-processor.c b/src/effect/effect-processor.c index 05dc1f912..3a31ff035 100644 --- a/src/effect/effect-processor.c +++ b/src/effect/effect-processor.c @@ -189,8 +189,8 @@ bool project(player_type *caster_ptr, const MONSTER_IDX who, POSITION rad, POSIT for (int i = 0; i < path_n; ++i) { POSITION oy = y; POSITION ox = x; - POSITION ny = GRID_Y(path_g[i]); - POSITION nx = GRID_X(path_g[i]); + POSITION ny = get_grid_y(path_g[i]); + POSITION nx = get_grid_x(path_g[i]); y = ny; x = nx; gy[grids] = y; @@ -232,8 +232,8 @@ bool project(player_type *caster_ptr, const MONSTER_IDX who, POSITION rad, POSIT next_mirror(caster_ptr, &oy, &ox, y, x); 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); for (j = last_i; j <= i; j++) { - y = GRID_Y(path_g[j]); - x = GRID_X(path_g[j]); + y = get_grid_y(path_g[j]); + x = get_grid_x(path_g[j]); if (affect_monster(caster_ptr, 0, 0, y, x, dam, GF_SEEKER, flag, TRUE)) notice = TRUE; if (!who && (project_m_n == 1) && !jump && (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0)) { @@ -253,8 +253,8 @@ bool project(player_type *caster_ptr, const MONSTER_IDX who, POSITION rad, POSIT for (int i = last_i; i < path_n; i++) { POSITION py, px; - py = GRID_Y(path_g[i]); - px = GRID_X(path_g[i]); + py = get_grid_y(path_g[i]); + px = get_grid_x(path_g[i]); if (affect_monster(caster_ptr, 0, 0, py, px, dam, GF_SEEKER, flag, TRUE)) notice = TRUE; if (!who && (project_m_n == 1) && !jump) { @@ -282,8 +282,8 @@ bool project(player_type *caster_ptr, const MONSTER_IDX who, POSITION rad, POSIT for (int i = 0; i < path_n; ++i) { POSITION oy = y; POSITION ox = x; - POSITION ny = GRID_Y(path_g[i]); - POSITION nx = GRID_X(path_g[i]); + POSITION ny = get_grid_y(path_g[i]); + POSITION nx = get_grid_x(path_g[i]); y = ny; x = nx; gy[grids] = y; @@ -329,8 +329,8 @@ bool project(player_type *caster_ptr, const MONSTER_IDX who, POSITION rad, POSIT monster_target_x = x; remove_mirror(caster_ptr, y, x); for (j = 0; j <= i; j++) { - y = GRID_Y(path_g[j]); - x = GRID_X(path_g[j]); + y = get_grid_y(path_g[j]); + x = get_grid_x(path_g[j]); (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_SUPER_RAY); } @@ -352,8 +352,8 @@ bool project(player_type *caster_ptr, const MONSTER_IDX who, POSITION rad, POSIT } for (int i = 0; i < path_n; i++) { - POSITION py = GRID_Y(path_g[i]); - POSITION px = GRID_X(path_g[i]); + POSITION py = get_grid_y(path_g[i]); + POSITION px = get_grid_x(path_g[i]); (void)affect_monster(caster_ptr, 0, 0, py, px, dam, GF_SUPER_RAY, flag, TRUE); if (!who && (project_m_n == 1) && !jump) { if (caster_ptr->current_floor_ptr->grid_array[project_m_y][project_m_x].m_idx > 0) { @@ -377,8 +377,8 @@ bool project(player_type *caster_ptr, const MONSTER_IDX who, POSITION rad, POSIT for (k = 0; k < path_n; ++k) { POSITION oy = y; POSITION ox = x; - POSITION ny = GRID_Y(path_g[k]); - POSITION nx = GRID_X(path_g[k]); + POSITION ny = get_grid_y(path_g[k]); + POSITION nx = get_grid_x(path_g[k]); if (flag & PROJECT_DISI) { if (cave_stop_disintegration(caster_ptr->current_floor_ptr, ny, nx) && (rad > 0)) break; diff --git a/src/floor/floor-leaver.c b/src/floor/floor-leaver.c index de1438dd5..59e641614 100644 --- a/src/floor/floor-leaver.c +++ b/src/floor/floor-leaver.c @@ -7,7 +7,6 @@ #include "floor/floor-mode-changer.h" #include "floor/floor-save-util.h" #include "floor/floor-save.h" -#include "floor/floor.h" #include "floor/line-of-sight.h" #include "game-option/birth-options.h" #include "game-option/play-record-options.h" @@ -33,6 +32,7 @@ #include "system/artifact-type-definition.h" #include "system/floor-type-definition.h" #include "system/monster-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/bit-flags-calculator.h" #include "view/display-messages.h" #include "world/world.h" diff --git a/src/floor/floor-object.c b/src/floor/floor-object.c index a02cb87cc..80a64c011 100644 --- a/src/floor/floor-object.c +++ b/src/floor/floor-object.c @@ -10,7 +10,6 @@ #include "flavor/flavor-describer.h" #include "flavor/object-flavor-types.h" #include "floor/cave.h" -#include "floor/floor.h" #include "game-option/birth-options.h" #include "game-option/cheat-options.h" #include "game-option/cheat-types.h" @@ -35,6 +34,7 @@ #include "system/artifact-type-definition.h" #include "system/floor-type-definition.h" #include "system/system-variables.h" +#include "target/projection-path-calculator.h" #include "util/bit-flags-calculator.h" #include "view/display-messages.h" #include "wizard/wizard-messages.h" diff --git a/src/floor/floor.c b/src/floor/floor.c index 0baf3c4f2..f00830991 100644 --- a/src/floor/floor.c +++ b/src/floor/floor.c @@ -160,34 +160,6 @@ void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x) } /*! - * @briefプレイヤーの攻撃射程(マス) / Maximum range (spells, etc) - * @param creature_ptr プレーヤーへの参照ポインタ - * @return 射程 - */ -int get_max_range(player_type *creature_ptr) { return creature_ptr->phase_out ? 36 : 18; } - -/* - * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive - * at the final destination, assuming no monster gets in the way. - * - * This is slightly (but significantly) different from "los(y1,x1,y2,x2)". - */ -bool projectable(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2) -{ - u16b grid_g[512]; - int grid_n = projection_path(player_ptr, grid_g, (project_length ? project_length : get_max_range(player_ptr)), y1, x1, y2, x2, 0); - if (!grid_n) - return TRUE; - - POSITION y = GRID_Y(grid_g[grid_n - 1]); - POSITION x = GRID_X(grid_g[grid_n - 1]); - if ((y != y2) || (x != x2)) - return FALSE; - - return TRUE; -} - -/*! * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed" * @param player_ptr プレーヤーへの参照ポインタ * @param y y座標 diff --git a/src/floor/floor.h b/src/floor/floor.h index 8126898fa..ba617fdc2 100644 --- a/src/floor/floor.h +++ b/src/floor/floor.h @@ -4,23 +4,9 @@ extern floor_type floor_info; -/* - * Convert a "grid" (G) into a "location" (Y) - */ -#define GRID_Y(G) \ - ((int)((G) / 256U)) - -/* - * Convert a "grid" (G) into a "location" (X) - */ -#define GRID_X(G) \ - ((int)((G) % 256U)) - void update_smell(floor_type *floor_ptr, player_type *subject_ptr); void forget_flow(floor_type *floor_ptr); void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x); -int get_max_range(player_type *creature_ptr); -bool projectable(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2); bool cave_valid_bold(floor_type *floor_ptr, POSITION y, POSITION x); void wipe_o_list(floor_type *floor_ptr); bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y); diff --git a/src/floor/geometry.c b/src/floor/geometry.c index f542b82ce..c3e4a85f7 100644 --- a/src/floor/geometry.c +++ b/src/floor/geometry.c @@ -1,10 +1,10 @@ #include "floor/geometry.h" #include "floor/cave.h" -#include "floor/floor.h" #include "game-option/text-display-options.h" #include "grid/feature.h" #include "grid/grid.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/bit-flags-calculator.h" /*! diff --git a/src/grid/trap.c b/src/grid/trap.c index 57a9fa2d4..6cf8c6b7a 100644 --- a/src/grid/trap.c +++ b/src/grid/trap.c @@ -8,7 +8,6 @@ #include "effect/effect-processor.h" #include "floor/cave.h" #include "floor/floor-mode-changer.h" -#include "floor/floor.h" #include "game-option/birth-options.h" #include "game-option/special-options.h" #include "grid/feature.h" @@ -37,6 +36,7 @@ #include "status/base-status.h" #include "status/element-resistance.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/bit-flags-calculator.h" #include "view/display-messages.h" #include "world/world.h" diff --git a/src/io/cursor.c b/src/io/cursor.c index a57ae2f95..d5925b3ec 100644 --- a/src/io/cursor.c +++ b/src/io/cursor.c @@ -48,8 +48,8 @@ void print_path(player_type *player_ptr, POSITION y, POSITION x) player_ptr->redraw |= (PR_MAP); handle_stuff(player_ptr); for (int i = 0; i < path_n; i++) { - POSITION ny = GRID_Y(path_g[i]); - POSITION nx = GRID_X(path_g[i]); + POSITION ny = get_grid_y(path_g[i]); + POSITION nx = get_grid_x(path_g[i]); grid_type *g_ptr = &floor_ptr->grid_array[ny][nx]; if (panel_contains(ny, nx)) { TERM_COLOR a = default_color; diff --git a/src/melee/melee-spell-flags-checker.c b/src/melee/melee-spell-flags-checker.c index a7da29d05..28e9d9da4 100644 --- a/src/melee/melee-spell-flags-checker.c +++ b/src/melee/melee-spell-flags-checker.c @@ -2,7 +2,6 @@ #include "dungeon/dungeon-flag-types.h" #include "dungeon/dungeon.h" #include "effect/effect-characteristics.h" -#include "floor/floor.h" #include "floor/line-of-sight.h" #include "melee/melee-spell-util.h" #include "monster-floor/monster-move.h" @@ -24,6 +23,7 @@ #include "spell-kind/spells-world.h" #include "spell/spell-types.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" static void decide_melee_spell_target(player_type *target_ptr, melee_spell_type *ms_ptr) { diff --git a/src/mind/mind-force-trainer.c b/src/mind/mind-force-trainer.c index 6750c8758..c69fbc363 100644 --- a/src/mind/mind-force-trainer.c +++ b/src/mind/mind-force-trainer.c @@ -6,7 +6,6 @@ #include "core/stuff-handler.h" #include "effect/spells-effect-util.h" #include "floor/cave.h" -#include "floor/floor.h" #include "floor/geometry.h" #include "game-option/disturbance-options.h" #include "grid/grid.h" @@ -27,6 +26,7 @@ #include "spell/spell-types.h" #include "status/temporary-resistance.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "target/target-checker.h" #include "target/target-getter.h" #include "target/target-setter.h" diff --git a/src/mind/mind-mirror-master.c b/src/mind/mind-mirror-master.c index 6ef3411ce..f83b2f755 100644 --- a/src/mind/mind-mirror-master.c +++ b/src/mind/mind-mirror-master.c @@ -11,7 +11,6 @@ #include "effect/effect-processor.h" #include "effect/spells-effect-util.h" #include "floor/cave.h" -#include "floor/floor.h" #include "game-option/disturbance-options.h" #include "game-option/special-options.h" #include "grid/feature.h" @@ -32,6 +31,7 @@ #include "status/sight-setter.h" #include "system/floor-type-definition.h" #include "target/grid-selector.h" +#include "target/projection-path-calculator.h" #include "target/target-getter.h" #include "term/gameterm.h" #include "util/bit-flags-calculator.h" diff --git a/src/mind/mind-ninja.c b/src/mind/mind-ninja.c index e95dc2ec1..548f7cb25 100644 --- a/src/mind/mind-ninja.c +++ b/src/mind/mind-ninja.c @@ -136,8 +136,8 @@ bool rush_attack(player_type *attacker_ptr, bool *mdeath) for (int i = 0; i < path_n; i++) { monster_type *m_ptr; - int ny = GRID_Y(path_g[i]); - int nx = GRID_X(path_g[i]); + int ny = get_grid_y(path_g[i]); + int nx = get_grid_x(path_g[i]); if (is_cave_empty_bold(attacker_ptr, ny, nx) && player_can_enter(attacker_ptr, floor_ptr->grid_array[ny][nx].feat, 0)) { ty = ny; diff --git a/src/monster-floor/monster-direction.c b/src/monster-floor/monster-direction.c index 714dc8842..f63b26e2a 100644 --- a/src/monster-floor/monster-direction.c +++ b/src/monster-floor/monster-direction.c @@ -6,7 +6,6 @@ #include "monster-floor/monster-direction.h" #include "floor/cave.h" -#include "floor/floor.h" #include "monster-race/monster-race.h" #include "monster-race/race-flags1.h" #include "monster-race/race-flags2.h" @@ -17,6 +16,7 @@ #include "pet/pet-util.h" #include "spell/range-calc.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" /*! * @brief ペットが敵に接近するための方向を決定する diff --git a/src/monster-floor/monster-generator.c b/src/monster-floor/monster-generator.c index 464ff59a2..bae81600e 100644 --- a/src/monster-floor/monster-generator.c +++ b/src/monster-floor/monster-generator.c @@ -26,6 +26,7 @@ #include "mspell/summon-checker.h" #include "spell/spells-summon.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/string-processor.h" #include "view/display-messages.h" diff --git a/src/monster-floor/monster-move.c b/src/monster-floor/monster-move.c index e884c68b7..d03994a49 100644 --- a/src/monster-floor/monster-move.c +++ b/src/monster-floor/monster-move.c @@ -12,7 +12,6 @@ #include "effect/effect-characteristics.h" #include "effect/effect-processor.h" #include "floor/cave.h" -#include "floor/floor.h" #include "game-option/disturbance-options.h" #include "grid/feature.h" #include "io/files-util.h" @@ -32,6 +31,7 @@ #include "pet/pet-util.h" #include "spell/spell-types.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/bit-flags-calculator.h" #include "view/display-messages.h" diff --git a/src/monster-floor/monster-runaway.c b/src/monster-floor/monster-runaway.c index 8bfcc61fa..4a3fe966f 100644 --- a/src/monster-floor/monster-runaway.c +++ b/src/monster-floor/monster-runaway.c @@ -8,7 +8,6 @@ #include "core/disturbance.h" #include "dungeon/quest-completion-checker.h" #include "floor/cave.h" -#include "floor/floor.h" #include "grid/grid.h" #include "monster-race/monster-race.h" #include "monster-race/race-flags1.h" @@ -20,6 +19,7 @@ #include "monster-floor/monster-remover.h" #include "pet/pet-fall-off.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "view/display-messages.h" /*! diff --git a/src/monster-floor/monster-safety-hiding.c b/src/monster-floor/monster-safety-hiding.c index e6c50d046..4d054b007 100644 --- a/src/monster-floor/monster-safety-hiding.c +++ b/src/monster-floor/monster-safety-hiding.c @@ -6,7 +6,6 @@ #include "monster-floor/monster-safety-hiding.h" #include "floor/cave.h" -#include "floor/floor.h" #include "grid/grid.h" #include "monster-floor/monster-dist-offsets.h" #include "monster-race/monster-race.h" @@ -14,6 +13,7 @@ #include "monster/monster-info.h" #include "mspell/mspell-checker.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" /*! * @brief モンスターが逃げ込める地点を走査する diff --git a/src/monster-floor/monster-sweep-grid.c b/src/monster-floor/monster-sweep-grid.c index de8f9858a..6d499906f 100644 --- a/src/monster-floor/monster-sweep-grid.c +++ b/src/monster-floor/monster-sweep-grid.c @@ -6,7 +6,6 @@ #include "monster-floor/monster-sweep-grid.h" #include "floor/cave.h" -#include "floor/floor.h" #include "floor/line-of-sight.h" #include "grid/feature.h" #include "grid/grid.h" @@ -23,6 +22,7 @@ #include "monster/monster-status.h" #include "mspell/mspell-mask-definitions.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" /*! * @brief モンスターがプレイヤーから逃走するかどうかを返す / diff --git a/src/monster/monster-processor.c b/src/monster/monster-processor.c index 8787a2202..07eaaa8d4 100644 --- a/src/monster/monster-processor.c +++ b/src/monster/monster-processor.c @@ -17,7 +17,6 @@ #include "core/player-update-types.h" #include "core/speed-table.h" #include "floor/cave.h" -#include "floor/floor.h" #include "game-option/play-record-options.h" #include "grid/feature.h" #include "grid/grid.h" @@ -60,6 +59,7 @@ #include "spell/spells-summon.h" #include "system/floor-type-definition.h" #include "system/monster-type-definition.h" +#include "target/projection-path-calculator.h" #include "view/display-messages.h" void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon); diff --git a/src/monster/monster-status-setter.c b/src/monster/monster-status-setter.c index 55d7f2ae4..ab62d613a 100644 --- a/src/monster/monster-status-setter.c +++ b/src/monster/monster-status-setter.c @@ -7,7 +7,6 @@ #include "core/window-redrawer.h" #include "dungeon/quest-completion-checker.h" #include "floor/cave.h" -#include "floor/floor.h" #include "monster-floor/monster-move.h" #include "monster-race/monster-race.h" #include "monster-race/race-flags3.h" @@ -21,6 +20,7 @@ #include "player/avatar.h" #include "system/floor-type-definition.h" #include "system/monster-type-definition.h" +#include "target/projection-path-calculator.h" #include "view/display-messages.h" #include "world/world.h" diff --git a/src/monster/monster-update.c b/src/monster/monster-update.c index bc0a1141c..d384a5419 100644 --- a/src/monster/monster-update.c +++ b/src/monster/monster-update.c @@ -12,7 +12,6 @@ #include "dungeon/dungeon-flag-types.h" #include "dungeon/dungeon.h" #include "floor/cave.h" -#include "floor/floor.h" #include "game-option/birth-options.h" #include "game-option/disturbance-options.h" #include "grid/grid.h" @@ -32,6 +31,7 @@ #include "player/special-defense-types.h" #include "status/element-resistance.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" /*! * @brief 騎乗中のモンスター情報を更新する diff --git a/src/mspell/mspell-attack.c b/src/mspell/mspell-attack.c index 2cec2b7a5..33faf8a7a 100644 --- a/src/mspell/mspell-attack.c +++ b/src/mspell/mspell-attack.c @@ -6,7 +6,6 @@ #include "dungeon/dungeon.h" #include "dungeon/quest.h" #include "floor/cave.h" -#include "floor/floor.h" #include "monster-floor/monster-move.h" #include "monster-race/monster-race.h" #include "monster-race/race-flags-ability1.h" @@ -30,6 +29,7 @@ #include "spell-kind/spells-world.h" #include "spell-realm/spells-hex.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "view/display-messages.h" #include "world/world.h" #ifdef JP diff --git a/src/mspell/mspell-checker.c b/src/mspell/mspell-checker.c index 2cf3e0ed7..542ae387e 100644 --- a/src/mspell/mspell-checker.c +++ b/src/mspell/mspell-checker.c @@ -19,7 +19,6 @@ #include "effect/effect-characteristics.h" #include "effect/effect-processor.h" #include "floor/cave.h" -#include "floor/floor.h" #include "floor/line-of-sight.h" #include "grid/grid.h" #include "monster-floor/monster-move.h" @@ -153,14 +152,14 @@ bool clean_shot(player_type *target_ptr, POSITION y1, POSITION x1, POSITION y2, if (!grid_n) return FALSE; - POSITION y = GRID_Y(grid_g[grid_n - 1]); - POSITION x = GRID_X(grid_g[grid_n - 1]); + POSITION y = get_grid_y(grid_g[grid_n - 1]); + POSITION x = get_grid_x(grid_g[grid_n - 1]); if ((y != y2) || (x != x2)) return FALSE; for (int i = 0; i < grid_n; i++) { - y = GRID_Y(grid_g[i]); - x = GRID_X(grid_g[i]); + y = get_grid_y(grid_g[i]); + x = get_grid_x(grid_g[i]); if ((floor_ptr->grid_array[y][x].m_idx > 0) && !((y == y2) && (x == x2))) { monster_type *m_ptr = &floor_ptr->m_list[floor_ptr->grid_array[y][x].m_idx]; diff --git a/src/mspell/mspell-judgement.c b/src/mspell/mspell-judgement.c index 2bce3e487..044d3e339 100644 --- a/src/mspell/mspell-judgement.c +++ b/src/mspell/mspell-judgement.c @@ -13,7 +13,6 @@ #include "dungeon/dungeon.h" #include "effect/effect-characteristics.h" #include "floor/cave.h" -#include "floor/floor.h" #include "floor/line-of-sight.h" #include "grid/grid.h" #include "main/sound-definitions-table.h" @@ -54,8 +53,8 @@ bool direct_beam(player_type *target_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION y, x; bool is_friend = is_pet(m_ptr); for (int i = 0; i < grid_n; i++) { - y = GRID_Y(grid_g[i]); - x = GRID_X(grid_g[i]); + y = get_grid_y(grid_g[i]); + x = get_grid_x(grid_g[i]); if (y == y2 && x == x2) hit2 = TRUE; @@ -106,8 +105,8 @@ bool breath_direct(player_type *master_ptr, POSITION y1, POSITION x1, POSITION y POSITION y = y1; POSITION x = x1; for (i = 0; i < grid_n; ++i) { - int ny = GRID_Y(grid_g[i]); - int nx = GRID_X(grid_g[i]); + int ny = get_grid_y(grid_g[i]); + int nx = get_grid_x(grid_g[i]); if (flg & PROJECT_DISI) { if (cave_stop_disintegration(master_ptr->current_floor_ptr, ny, nx)) @@ -187,8 +186,8 @@ void get_project_point(player_type *target_ptr, POSITION sy, POSITION sx, POSITI *ty = sy; *tx = sx; for (int i = 0; i < path_n; i++) { - sy = GRID_Y(path_g[i]); - sx = GRID_X(path_g[i]); + sy = get_grid_y(path_g[i]); + sx = get_grid_x(path_g[i]); if (!cave_have_flag_bold(target_ptr->current_floor_ptr, sy, sx, FF_PROJECT)) break; diff --git a/src/mspell/mspell-lite.c b/src/mspell/mspell-lite.c index 68730a2e9..99ad4ea34 100644 --- a/src/mspell/mspell-lite.c +++ b/src/mspell/mspell-lite.c @@ -8,7 +8,6 @@ #include "dungeon/dungeon-flag-types.h" #include "dungeon/dungeon.h" #include "floor/cave.h" -#include "floor/floor.h" #include "floor/line-of-sight.h" #include "grid/feature.h" #include "grid/grid.h" @@ -25,6 +24,7 @@ #include "spell/range-calc.h" #include "system/floor-type-definition.h" #include "system/monster-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/bit-flags-calculator.h" /*! diff --git a/src/object/warning.c b/src/object/warning.c index 45544e882..3c9cc94ce 100644 --- a/src/object/warning.c +++ b/src/object/warning.c @@ -7,7 +7,6 @@ #include "flavor/flavor-describer.h" #include "flavor/object-flavor-types.h" #include "floor/cave.h" -#include "floor/floor.h" #include "game-option/input-options.h" #include "grid/feature.h" #include "grid/grid.h" @@ -34,6 +33,7 @@ #include "spell/spell-types.h" #include "status/element-resistance.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/bit-flags-calculator.h" #include "view/display-messages.h" diff --git a/src/realm/realm-hissatsu.c b/src/realm/realm-hissatsu.c index 890cb043d..79484550e 100644 --- a/src/realm/realm-hissatsu.c +++ b/src/realm/realm-hissatsu.c @@ -14,7 +14,6 @@ #include "effect/effect-processor.h" #include "effect/spells-effect-util.h" #include "floor/cave.h" -#include "floor/floor.h" #include "grid/feature-flag-types.h" #include "grid/grid.h" #include "inventory/inventory-slot-types.h" @@ -43,6 +42,7 @@ #include "status/bad-status-setter.h" #include "system/floor-type-definition.h" #include "target/grid-selector.h" +#include "target/projection-path-calculator.h" #include "target/target-getter.h" #include "term/screen-processor.h" #include "util/bit-flags-calculator.h" diff --git a/src/spell-kind/spells-fetcher.c b/src/spell-kind/spells-fetcher.c index b17a84436..1dc375739 100644 --- a/src/spell-kind/spells-fetcher.c +++ b/src/spell-kind/spells-fetcher.c @@ -5,7 +5,6 @@ #include "flavor/flavor-describer.h" #include "flavor/object-flavor-types.h" #include "floor/cave.h" -#include "floor/floor.h" #include "grid/feature-flag-types.h" #include "grid/grid.h" #include "monster-race/monster-race.h" @@ -139,8 +138,8 @@ bool fetch_monster(player_type *caster_ptr) path_n = projection_path(caster_ptr, path_g, get_max_range(caster_ptr), target_row, target_col, caster_ptr->y, caster_ptr->x, 0); ty = target_row, tx = target_col; for (i = 1; i < path_n; i++) { - POSITION ny = GRID_Y(path_g[i]); - POSITION nx = GRID_X(path_g[i]); + POSITION ny = get_grid_y(path_g[i]); + POSITION nx = get_grid_x(path_g[i]); grid_type *g_ptr = &caster_ptr->current_floor_ptr->grid_array[ny][nx]; if (in_bounds(caster_ptr->current_floor_ptr, ny, nx) && is_cave_empty_bold(caster_ptr, ny, nx) && !(g_ptr->info & CAVE_OBJECT) diff --git a/src/spell-kind/spells-lite.c b/src/spell-kind/spells-lite.c index efc44aac5..e2665873a 100644 --- a/src/spell-kind/spells-lite.c +++ b/src/spell-kind/spells-lite.c @@ -18,6 +18,7 @@ #include "spell-kind/spells-launcher.h" #include "spell/spell-types.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/bit-flags-calculator.h" #include "view/display-messages.h" #include "world/world.h" diff --git a/src/spell-kind/spells-sight.c b/src/spell-kind/spells-sight.c index 97e16fd20..542d212ac 100644 --- a/src/spell-kind/spells-sight.c +++ b/src/spell-kind/spells-sight.c @@ -5,7 +5,6 @@ #include "effect/effect-characteristics.h" #include "effect/effect-processor.h" #include "floor/cave.h" -#include "floor/floor.h" #include "game-option/birth-options.h" #include "grid/grid.h" #include "io/cursor.h" @@ -24,6 +23,7 @@ #include "player/avatar.h" #include "spell/spell-types.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "term/screen-processor.h" #include "view/display-messages.h" diff --git a/src/spell-kind/spells-world.c b/src/spell-kind/spells-world.c index 5bb4a3080..2028a8f5d 100644 --- a/src/spell-kind/spells-world.c +++ b/src/spell-kind/spells-world.c @@ -8,7 +8,6 @@ #include "floor/cave.h" #include "floor/floor-mode-changer.h" #include "floor/floor-town.h" -#include "floor/floor.h" #include "floor/geometry.h" #include "floor/wild.h" #include "game-option/birth-options.h" @@ -29,6 +28,7 @@ #include "monster/monster-info.h" #include "system/floor-type-definition.h" #include "system/monster-type-definition.h" +#include "target/projection-path-calculator.h" #include "target/target-checker.h" #include "target/target-setter.h" #include "target/target-types.h" diff --git a/src/spell-realm/spells-chaos.c b/src/spell-realm/spells-chaos.c index 6bff74e11..e0511ecab 100644 --- a/src/spell-realm/spells-chaos.c +++ b/src/spell-realm/spells-chaos.c @@ -6,7 +6,6 @@ #include "effect/effect-characteristics.h" #include "effect/effect-processor.h" #include "floor/cave.h" -#include "floor/floor.h" #include "grid/feature.h" #include "grid/grid.h" #include "monster/monster-describer.h" @@ -18,6 +17,7 @@ #include "spell-kind/spells-launcher.h" #include "spell/spell-types.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/bit-flags-calculator.h" #include "view/display-messages.h" diff --git a/src/spell-realm/spells-crusade.c b/src/spell-realm/spells-crusade.c index fcd7e305b..ff0523e17 100644 --- a/src/spell-realm/spells-crusade.c +++ b/src/spell-realm/spells-crusade.c @@ -12,7 +12,6 @@ #include "effect/effect-characteristics.h" #include "effect/effect-processor.h" #include "floor/cave.h" -#include "floor/floor.h" #include "game-option/disturbance-options.h" #include "grid/feature-flag-types.h" #include "grid/grid.h" @@ -20,6 +19,7 @@ #include "spell/range-calc.h" #include "spell/spell-types.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "target/target-checker.h" #include "target/target-getter.h" #include "util/bit-flags-calculator.h" diff --git a/src/spell/range-calc.c b/src/spell/range-calc.c index 2183ecf2f..3dc8926f8 100644 --- a/src/spell/range-calc.c +++ b/src/spell/range-calc.c @@ -6,12 +6,12 @@ #include "spell/range-calc.h" #include "floor/cave.h" -#include "floor/floor.h" #include "floor/line-of-sight.h" #include "grid/feature.h" #include "grid/grid.h" #include "spell/spell-types.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/bit-flags-calculator.h" /* @@ -224,8 +224,8 @@ void breath_shape(player_type *caster_ptr, u16b *path_g, int dist, int *pgrids, { if ((0 < dist) && (path_n < dist)) { - POSITION ny = GRID_Y(path_g[path_n]); - POSITION nx = GRID_X(path_g[path_n]); + POSITION ny = get_grid_y(path_g[path_n]); + POSITION nx = get_grid_x(path_g[path_n]); POSITION nd = distance(ny, nx, y1, x1); if (bdis >= nd) diff --git a/src/spell/spells-summon.c b/src/spell/spells-summon.c index 96cbf38a7..f00a3fa90 100644 --- a/src/spell/spells-summon.c +++ b/src/spell/spells-summon.c @@ -2,7 +2,6 @@ #include "core/hp-mp-processor.h" #include "effect/spells-effect-util.h" #include "floor/floor-object.h" -#include "floor/floor.h" #include "floor/line-of-sight.h" #include "game-option/birth-options.h" #include "inventory/inventory-object.h" @@ -29,6 +28,7 @@ #include "status/bad-status-setter.h" #include "sv-definition/sv-other-types.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "util/string-processor.h" #include "view/display-messages.h" diff --git a/src/target/projection-path-calculator.c b/src/target/projection-path-calculator.c index 0cf2590ab..3667e6d0b 100644 --- a/src/target/projection-path-calculator.c +++ b/src/target/projection-path-calculator.c @@ -1,5 +1,6 @@ #include "target/projection-path-calculator.h" #include "effect/effect-characteristics.h" +#include "effect/spells-effect-util.h" #include "floor/cave.h" #include "grid/feature-flag-types.h" #include "grid/grid.h" @@ -185,7 +186,8 @@ static void calc_projection_others(player_type *player_ptr, projection_path_type break; } - if (((pp_ptr->flag & PROJECT_STOP) != 0) && (pp_ptr->n > 0) && (player_bold(player_ptr, pp_ptr->y, pp_ptr->x) || floor_ptr->grid_array[pp_ptr->y][pp_ptr->x].m_idx != 0)) + if (((pp_ptr->flag & PROJECT_STOP) != 0) && (pp_ptr->n > 0) + && (player_bold(player_ptr, pp_ptr->y, pp_ptr->x) || floor_ptr->grid_array[pp_ptr->y][pp_ptr->x].m_idx != 0)) break; if (!in_bounds(floor_ptr, pp_ptr->y, pp_ptr->x)) @@ -233,3 +235,41 @@ int projection_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION calc_projection_others(player_ptr, pp_ptr); return pp_ptr->n; } + +/* + * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive + * at the final destination, assuming no monster gets in the way. + * + * This is slightly (but significantly) different from "los(y1,x1,y2,x2)". + */ +bool projectable(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2) +{ + u16b grid_g[512]; + int grid_n = projection_path(player_ptr, grid_g, (project_length ? project_length : get_max_range(player_ptr)), y1, x1, y2, x2, 0); + if (!grid_n) + return TRUE; + + POSITION y = get_grid_y(grid_g[grid_n - 1]); + POSITION x = get_grid_x(grid_g[grid_n - 1]); + if ((y != y2) || (x != x2)) + return FALSE; + + return TRUE; +} + +/*! + * @briefƒvƒŒƒCƒ„[‚̍UŒ‚ŽË’ö(ƒ}ƒX) / Maximum range (spells, etc) + * @param creature_ptr ƒvƒŒ[ƒ„[‚Ö‚ÌŽQÆƒ|ƒCƒ“ƒ^ + * @return ŽË’ö + */ +int get_max_range(player_type *creature_ptr) { return creature_ptr->phase_out ? 36 : 18; } + +/* + * Convert a "grid" (G) into a "location" (Y) + */ +POSITION get_grid_y(u16b grid) { return (int)(grid / 256U); } + +/* + * Convert a "grid" (G) into a "location" (X) + */ +POSITION get_grid_x(u16b grid) { return (int)(grid % 256U); } diff --git a/src/target/projection-path-calculator.h b/src/target/projection-path-calculator.h index 97709d39d..c7a10f7d9 100644 --- a/src/target/projection-path-calculator.h +++ b/src/target/projection-path-calculator.h @@ -3,3 +3,7 @@ #include "system/angband.h" int projection_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg); +bool projectable(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2); +int get_max_range(player_type *creature_ptr); +POSITION get_grid_y(u16b grid); +POSITION get_grid_x(u16b grid); diff --git a/src/target/target-setter.c b/src/target/target-setter.c index a263b102f..32fe165ec 100644 --- a/src/target/target-setter.c +++ b/src/target/target-setter.c @@ -3,7 +3,6 @@ #include "core/player-update-types.h" #include "core/stuff-handler.h" #include "core/window-redrawer.h" -#include "floor/floor.h" #include "floor/line-of-sight.h" #include "game-option/cheat-options.h" #include "game-option/game-play-options.h" @@ -14,6 +13,7 @@ #include "io/screen-util.h" #include "main/sound-of-music.h" #include "system/floor-type-definition.h" +#include "target/projection-path-calculator.h" #include "target/target-checker.h" #include "target/target-describer.h" #include "target/target-preparation.h" -- 2.11.0