From: Hourier Date: Thu, 23 Jul 2020 12:01:38 +0000 (+0900) Subject: [Refactor] #40479 Separated mspell-lite.c/h from mspell-attack.c X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=8a375de6b5d5197656a930af313f40e682f455a4;p=hengband%2Fhengband.git [Refactor] #40479 Separated mspell-lite.c/h from mspell-attack.c --- diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj index 54c056642..afacfc0ff 100644 --- a/Hengband/Hengband/Hengband.vcxproj +++ b/Hengband/Hengband/Hengband.vcxproj @@ -271,6 +271,7 @@ + @@ -817,6 +818,7 @@ + diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters index f9abbfcd1..3adab8d75 100644 --- a/Hengband/Hengband/Hengband.vcxproj.filters +++ b/Hengband/Hengband/Hengband.vcxproj.filters @@ -1868,6 +1868,9 @@ mspell + + mspell + @@ -4063,6 +4066,9 @@ mspell + + mspell + diff --git a/src/Makefile.am b/src/Makefile.am index e76ae8c20..bc53e1849 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -470,6 +470,7 @@ hengband_SOURCES = \ mspell/mspell-curse.c mspell/mspell-curse.h \ mspell/mspell-dispel.c mspell/mspell-dispel.h \ mspell/mspell-judgement.c mspell/mspell-judgement.h \ + mspell/mspell-lite.c mspell/mspell-lite.h \ mspell/mspell-summon.c mspell/mspell-summon.h \ mspell/mspell-util.c mspell/mspell-util.h \ mspell/mspell-type.h \ diff --git a/src/action/tunnel-execution.c b/src/action/tunnel-execution.c index 4261a4bfc..dc68bc846 100644 --- a/src/action/tunnel-execution.c +++ b/src/action/tunnel-execution.c @@ -1,6 +1,6 @@ #include "action/tunnel-execution.h" #include "core/player-update-types.h" -#include "floor/floor.h" +#include "floor/cave.h" #include "grid/feature.h" #include "grid/grid.h" #include "main/sound-definitions-table.h" diff --git a/src/cmd-building/cmd-store.c b/src/cmd-building/cmd-store.c index 8dd1b66ea..18a0ac9c8 100644 --- a/src/cmd-building/cmd-store.c +++ b/src/cmd-building/cmd-store.c @@ -5,9 +5,9 @@ #include "core/stuff-handler.h" #include "core/window-redrawer.h" #include "flavor/flavor-describer.h" +#include "floor/cave.h" #include "floor/floor-events.h" #include "floor/floor-town.h" -#include "floor/floor.h" #include "floor/wild.h" #include "game-option/birth-options.h" #include "game-option/input-options.h" @@ -26,7 +26,6 @@ #include "store/store.h" #include "system/floor-type-definition.h" #include "term/screen-processor.h" -#include "util/bit-flags-calculator.h" #include "view/display-messages.h" #include "view/display-store.h" #include "world/world.h" diff --git a/src/floor/cave.c b/src/floor/cave.c index d17c0a419..0594dc62b 100644 --- a/src/floor/cave.c +++ b/src/floor/cave.c @@ -102,3 +102,5 @@ bool cave_los_bold(floor_type *floor_ptr, POSITION y, POSITION x) { return feat_ bool feat_supports_los(FEAT_IDX f_idx) { return have_flag(f_info[f_idx].flags, FF_LOS); } bool cave_los_grid(grid_type *grid_ptr) { return feat_supports_los(grid_ptr->feat); } + +bool cave_have_flag_grid(grid_type *grid_ptr, int feature_flags) { return have_flag(f_info[grid_ptr->feat].flags, feature_flags); } diff --git a/src/floor/cave.h b/src/floor/cave.h index acda8363d..7411f0b8a 100644 --- a/src/floor/cave.h +++ b/src/floor/cave.h @@ -16,3 +16,4 @@ bool cave_stop_disintegration(floor_type *floor_ptr, POSITION y, POSITION x); bool cave_los_bold(floor_type *floor_ptr, POSITION y, POSITION x); bool feat_supports_los(FEAT_IDX f_idx); bool cave_los_grid(grid_type *grid_ptr); +bool cave_have_flag_grid(grid_type *grid_ptr, int feature_flags); diff --git a/src/floor/floor.h b/src/floor/floor.h index b50881e45..d33af79cb 100644 --- a/src/floor/floor.h +++ b/src/floor/floor.h @@ -11,10 +11,6 @@ extern floor_type floor_info; ((G) == &(C)->current_floor_ptr->grid_array[(C)->y][(C)->x]) -#define cave_have_flag_grid(C,INDEX) \ - (have_flag(f_info[(C)->feat].flags, (INDEX))) - - /* * Determine if a "legal" grid is a "clean" floor grid * Determine if terrain-change spells are allowed in a grid. diff --git a/src/floor/wild.c b/src/floor/wild.c index 7d43ebcb6..695369608 100644 --- a/src/floor/wild.c +++ b/src/floor/wild.c @@ -15,8 +15,8 @@ #include "dungeon/dungeon-flag-types.h" #include "dungeon/dungeon.h" #include "dungeon/quest.h" +#include "floor/cave.h" #include "floor/floor-town.h" -#include "floor/floor.h" #include "game-option/birth-options.h" #include "game-option/map-screen-options.h" #include "grid/feature.h" diff --git a/src/io/cursor.c b/src/io/cursor.c index 6fc406c00..5d81a1d85 100644 --- a/src/io/cursor.c +++ b/src/io/cursor.c @@ -4,6 +4,7 @@ #include "core/stuff-handler.h" #include "effect/effect-characteristics.h" #include "effect/spells-effect-util.h" +#include "floor/cave.h" #include "floor/floor.h" #include "game-option/map-screen-options.h" #include "game-option/special-options.h" @@ -13,7 +14,6 @@ #include "io/targeting.h" #include "system/floor-type-definition.h" #include "term/term-color-types.h" -#include "util/bit-flags-calculator.h" #include "view/display-map.h" #include "window/main-window-util.h" #include "world/world.h" diff --git a/src/mspell/mspell-attack.c b/src/mspell/mspell-attack.c index 9633c557d..408317088 100644 --- a/src/mspell/mspell-attack.c +++ b/src/mspell/mspell-attack.c @@ -28,6 +28,7 @@ #include "mspell/mspell-attack-util.h" #include "mspell/mspell-checker.h" #include "mspell/mspell-judgement.h" +#include "mspell/mspell-lite.h" #include "mspell/mspell-mask-definitions.h" #include "mspell/mspell-selector.h" #include "mspell/mspell-util.h" @@ -45,72 +46,6 @@ #include "monster/monster-description-types.h" #endif -/*! - * @brief モンスターがプレイヤーにダメージを与えるための最適な座標を算出する / - * @param target_ptr プレーヤーへの参照ポインタ - * @param m_ptr 技能を使用するモンスター構造体の参照ポインタ - * @param yp 最適な目標地点のY座標を返す参照ポインタ - * @param xp 最適な目標地点のX座標を返す参照ポインタ - * @param f_flag 射線に入れるのを避ける地形の所持フラグ - * @param path_check 射線を判定するための関数ポインタ - * @return 有効な座標があった場合TRUEを返す - */ -static bool adjacent_grid_check(player_type *target_ptr, monster_type *m_ptr, POSITION *yp, POSITION *xp, int f_flag, - bool (*path_check)(player_type *, POSITION, POSITION, POSITION, POSITION)) -{ - static int tonari_y[4][8] = { { -1, -1, -1, 0, 0, 1, 1, 1 }, { -1, -1, -1, 0, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0, -1, -1, -1 }, { 1, 1, 1, 0, 0, -1, -1, -1 } }; - static int tonari_x[4][8] = { { -1, 0, 1, -1, 1, -1, 0, 1 }, { 1, 0, -1, 1, -1, 1, 0, -1 }, { -1, 0, 1, -1, 1, -1, 0, 1 }, { 1, 0, -1, 1, -1, 1, 0, -1 } }; - - int next; - if (m_ptr->fy < target_ptr->y && m_ptr->fx < target_ptr->x) - next = 0; - else if (m_ptr->fy < target_ptr->y) - next = 1; - else if (m_ptr->fx < target_ptr->x) - next = 2; - else - next = 3; - - floor_type *floor_ptr = target_ptr->current_floor_ptr; - for (int i = 0; i < 8; i++) { - int next_x = *xp + tonari_x[next][i]; - int next_y = *yp + tonari_y[next][i]; - grid_type *g_ptr; - g_ptr = &floor_ptr->grid_array[next_y][next_x]; - if (!cave_have_flag_grid(g_ptr, f_flag)) - continue; - - if (path_check(target_ptr, m_ptr->fy, m_ptr->fx, next_y, next_x)) { - *yp = next_y; - *xp = next_x; - return TRUE; - } - } - - return FALSE; -} - -static void decide_lite_range(player_type *target_ptr, msa_type *msa_ptr) -{ - if ((msa_ptr->f4 & RF4_BR_LITE) == 0) - return; - - msa_ptr->y_br_lite = msa_ptr->y; - msa_ptr->x_br_lite = msa_ptr->x; - if (los(target_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y_br_lite, msa_ptr->x_br_lite)) { - feature_type *f_ptr = &f_info[target_ptr->current_floor_ptr->grid_array[msa_ptr->y_br_lite][msa_ptr->x_br_lite].feat]; - if (!have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT) && one_in_(2)) - msa_ptr->f4 &= ~(RF4_BR_LITE); - } else if (!adjacent_grid_check(target_ptr, msa_ptr->m_ptr, &msa_ptr->y_br_lite, &msa_ptr->x_br_lite, FF_LOS, los)) - msa_ptr->f4 &= ~(RF4_BR_LITE); - - if ((msa_ptr->f4 & RF4_BR_LITE) != 0) - return; - - msa_ptr->y_br_lite = 0; - msa_ptr->x_br_lite = 0; -} - static void feature_projection(floor_type *floor_ptr, msa_type *msa_ptr) { feature_type *f_ptr = &f_info[floor_ptr->grid_array[msa_ptr->y][msa_ptr->x].feat]; diff --git a/src/mspell/mspell-lite.c b/src/mspell/mspell-lite.c new file mode 100644 index 000000000..f2d77a815 --- /dev/null +++ b/src/mspell/mspell-lite.c @@ -0,0 +1,80 @@ +/*! + * @brief モンスターの魔法によってフロアを明るくする処理及びその判定 + * @date 2020/07/23 + * @author Hourier + */ + +#include "mspell/mspell-lite.h" +#include "floor/cave.h" +#include "floor/floor.h" +#include "grid/feature.h" +#include "grid/grid.h" +#include "monster-race/race-flags4.h" +#include "mspell/mspell-attack-util.h" +#include "system/floor-type-definition.h" +#include "system/monster-type-definition.h" +#include "util/bit-flags-calculator.h" + +/*! + * @brief モンスターがプレイヤーにダメージを与えるための最適な座標を算出する / + * @param target_ptr プレーヤーへの参照ポインタ + * @param m_ptr 技能を使用するモンスター構造体の参照ポインタ + * @param yp 最適な目標地点のY座標を返す参照ポインタ + * @param xp 最適な目標地点のX座標を返す参照ポインタ + * @param f_flag 射線に入れるのを避ける地形の所持フラグ + * @param path_check 射線を判定するための関数ポインタ + * @return 有効な座標があった場合TRUEを返す + */ +bool adjacent_grid_check(player_type *target_ptr, monster_type *m_ptr, POSITION *yp, POSITION *xp, int f_flag, path_check_pf path_check) +{ + static int tonari_y[4][8] = { { -1, -1, -1, 0, 0, 1, 1, 1 }, { -1, -1, -1, 0, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0, -1, -1, -1 }, { 1, 1, 1, 0, 0, -1, -1, -1 } }; + static int tonari_x[4][8] = { { -1, 0, 1, -1, 1, -1, 0, 1 }, { 1, 0, -1, 1, -1, 1, 0, -1 }, { -1, 0, 1, -1, 1, -1, 0, 1 }, { 1, 0, -1, 1, -1, 1, 0, -1 } }; + + int next; + if (m_ptr->fy < target_ptr->y && m_ptr->fx < target_ptr->x) + next = 0; + else if (m_ptr->fy < target_ptr->y) + next = 1; + else if (m_ptr->fx < target_ptr->x) + next = 2; + else + next = 3; + + for (int i = 0; i < 8; i++) { + int next_x = *xp + tonari_x[next][i]; + int next_y = *yp + tonari_y[next][i]; + grid_type *g_ptr; + g_ptr = &target_ptr->current_floor_ptr->grid_array[next_y][next_x]; + if (!cave_have_flag_grid(g_ptr, f_flag)) + continue; + + if (path_check(target_ptr, m_ptr->fy, m_ptr->fx, next_y, next_x)) { + *yp = next_y; + *xp = next_x; + return TRUE; + } + } + + return FALSE; +} + +void decide_lite_range(player_type *target_ptr, msa_type *msa_ptr) +{ + if ((msa_ptr->f4 & RF4_BR_LITE) == 0) + return; + + msa_ptr->y_br_lite = msa_ptr->y; + msa_ptr->x_br_lite = msa_ptr->x; + if (los(target_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y_br_lite, msa_ptr->x_br_lite)) { + feature_type *f_ptr = &f_info[target_ptr->current_floor_ptr->grid_array[msa_ptr->y_br_lite][msa_ptr->x_br_lite].feat]; + if (!have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT) && one_in_(2)) + msa_ptr->f4 &= ~(RF4_BR_LITE); + } else if (!adjacent_grid_check(target_ptr, msa_ptr->m_ptr, &msa_ptr->y_br_lite, &msa_ptr->x_br_lite, FF_LOS, los)) + msa_ptr->f4 &= ~(RF4_BR_LITE); + + if ((msa_ptr->f4 & RF4_BR_LITE) != 0) + return; + + msa_ptr->y_br_lite = 0; + msa_ptr->x_br_lite = 0; +} diff --git a/src/mspell/mspell-lite.h b/src/mspell/mspell-lite.h new file mode 100644 index 000000000..16feb9eb9 --- /dev/null +++ b/src/mspell/mspell-lite.h @@ -0,0 +1,9 @@ +#pragma once + +#include "system/angband.h" + +typedef struct monster_type monster_type; +typedef struct msa_type msa_type; +typedef bool (*path_check_pf)(player_type *, POSITION, POSITION, POSITION, POSITION); +bool adjacent_grid_check(player_type *target_ptr, monster_type *m_ptr, POSITION *yp, POSITION *xp, int f_flag, path_check_pf path_check); +void decide_lite_range(player_type *target_ptr, msa_type *msa_ptr); diff --git a/src/pet/pet-fall-off.c b/src/pet/pet-fall-off.c index d4246791e..11d966a2b 100644 --- a/src/pet/pet-fall-off.c +++ b/src/pet/pet-fall-off.c @@ -9,7 +9,7 @@ #include "core/player-update-types.h" #include "core/stuff-handler.h" #include "core/window-redrawer.h" -#include "floor/floor.h" +#include "floor/cave.h" #include "grid/feature.h" #include "io/targeting.h" #include "monster-race/monster-race.h" @@ -19,7 +19,6 @@ #include "player/player-move.h" #include "player/player-skill.h" #include "system/floor-type-definition.h" -#include "util/bit-flags-calculator.h" #include "view/display-messages.h" /*! diff --git a/src/spell-kind/spells-detection.c b/src/spell-kind/spells-detection.c index fbe5b495f..9a21ac52b 100644 --- a/src/spell-kind/spells-detection.c +++ b/src/spell-kind/spells-detection.c @@ -2,8 +2,8 @@ #include "core/window-redrawer.h" #include "dungeon/dungeon-flag-types.h" #include "dungeon/dungeon.h" +#include "floor/cave.h" #include "floor/floor-save.h" -#include "floor/floor.h" #include "grid/grid.h" #include "grid/trap.h" #include "monster-race/monster-race.h" @@ -22,7 +22,6 @@ #include "realm/realm-song.h" #include "system/floor-type-definition.h" #include "system/object-type-definition.h" -#include "util/bit-flags-calculator.h" #include "util/string-processor.h" #include "view/display-messages.h" diff --git a/src/spell/spells-object.c b/src/spell/spells-object.c index 8cbd466d8..12a5b51af 100644 --- a/src/spell/spells-object.c +++ b/src/spell/spells-object.c @@ -14,8 +14,8 @@ #include "core/window-redrawer.h" #include "flavor/flavor-describer.h" #include "flavor/object-flavor-types.h" +#include "floor/cave.h" #include "floor/floor-object.h" -#include "floor/floor.h" #include "game-option/disturbance-options.h" #include "grid/feature.h" #include "grid/grid.h"