From c0c1f3486f031bd0c102966947107850331ce230 Mon Sep 17 00:00:00 2001 From: Hourier Date: Thu, 4 Jun 2020 19:06:11 +0900 Subject: [PATCH] [Refactor] #40414 Unified spells-mirror.c/h into racial-mirror-master.c/h --- Hengband/Hengband/Hengband.vcxproj | 2 - Hengband/Hengband/Hengband.vcxproj.filters | 6 -- src/Makefile.am | 1 - src/mind/mind.c | 2 +- src/mind/racial-mirror-master.c | 161 +++++++++++++++++++++++++++-- src/mind/racial-mirror-master.h | 4 + src/spell/spells-mirror.c | 158 ---------------------------- src/spell/spells-mirror.h | 6 -- 8 files changed, 160 insertions(+), 180 deletions(-) delete mode 100644 src/spell/spells-mirror.c delete mode 100644 src/spell/spells-mirror.h diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj index f528fe643..c0c1955d6 100644 --- a/Hengband/Hengband/Hengband.vcxproj +++ b/Hengband/Hengband/Hengband.vcxproj @@ -355,7 +355,6 @@ - @@ -565,7 +564,6 @@ - diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters index d1456c7df..4c230d647 100644 --- a/Hengband/Hengband/Hengband.vcxproj.filters +++ b/Hengband/Hengband/Hengband.vcxproj.filters @@ -1097,9 +1097,6 @@ object - - spell - spell @@ -2374,9 +2371,6 @@ object - - spell - spell diff --git a/src/Makefile.am b/src/Makefile.am index a8a2780b8..1ea35f3c8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -394,7 +394,6 @@ hengband_SOURCES = \ spell/spells-diceroll.c spell/spells-diceroll.h \ spell/spells-floor.c spell/spells-floor.h \ spell/spells-hex.c spell/spells-hex.h \ - spell/spells-mirror.c spell/spells-mirror.h \ spell/spells-object.c spell/spells-object.h \ spell/spells-status.c spell/spells-status.h \ spell/spells-summon.c spell/spells-summon.h \ diff --git a/src/mind/mind.c b/src/mind/mind.c index 60cd7945f..08f6f69ca 100644 --- a/src/mind/mind.c +++ b/src/mind/mind.c @@ -27,6 +27,7 @@ #include "main/sound-definitions-table.h" #include "mind/racial-force-trainer.h" #include "mind/racial-ninja.h" +#include "mind/racial-mirror-master.h" #include "monster/monster-status.h" #include "player/avatar.h" #include "player/player-class.h" @@ -38,7 +39,6 @@ #include "spell/process-effect.h" #include "spell/spells-detection.h" #include "spell/spells-floor.h" -#include "spell/spells-mirror.h" #include "spell/spells-status.h" #include "spell/spells-summon.h" #include "spell/spells-type.h" diff --git a/src/mind/racial-mirror-master.c b/src/mind/racial-mirror-master.c index d9293b7d7..0a13ecb9e 100644 --- a/src/mind/racial-mirror-master.c +++ b/src/mind/racial-mirror-master.c @@ -1,18 +1,20 @@ -#include "system/angband.h" +#include "mind/racial-mirror-master.h" #include "cmd-action/cmd-pet.h" #include "effect/effect-characteristics.h" -#include "mind/racial-mirror-master.h" +#include "effect/effect-feature.h" +#include "effect/effect-item.h" +#include "effect/effect-monster.h" +#include "effect/spells-effect-util.h" #include "spell/process-effect.h" #include "spell/spells-type.h" +#include "term/gameterm.h" +#include "view/display-main-window.h" #include "world/world.h" /* * @brief Multishadow effects is determined by turn */ -bool check_multishadow(player_type *creature_ptr) -{ - return (creature_ptr->multishadow != 0) && ((current_world_ptr->game_turn & 1) != 0); -} +bool check_multishadow(player_type *creature_ptr) { return (creature_ptr->multishadow != 0) && ((current_world_ptr->game_turn & 1) != 0); } /*! * 静水 @@ -65,3 +67,150 @@ void remove_all_mirrors(player_type *caster_ptr, bool explode) } } } + +/*! + * @brief 鏡魔法「封魔結界」の効果処理 + * @param dam ダメージ量 + * @return 効果があったらTRUEを返す + */ +bool binding_field(player_type *caster_ptr, HIT_POINT dam) +{ + POSITION mirror_x[10], mirror_y[10]; /* 鏡はもっと少ない */ + int mirror_num = 0; /* 鏡の数 */ + int msec = delay_factor * delay_factor * delay_factor; + + /* 三角形の頂点 */ + POSITION point_x[3]; + POSITION point_y[3]; + + /* Default target of monsterspell is player */ + monster_target_y = caster_ptr->y; + monster_target_x = caster_ptr->x; + + for (POSITION x = 0; x < caster_ptr->current_floor_ptr->width; x++) { + for (POSITION y = 0; y < caster_ptr->current_floor_ptr->height; y++) { + if (is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]) && distance(caster_ptr->y, caster_ptr->x, y, x) <= MAX_RANGE + && distance(caster_ptr->y, caster_ptr->x, y, x) != 0 && player_has_los_bold(caster_ptr, y, x) + && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) { + mirror_y[mirror_num] = y; + mirror_x[mirror_num] = x; + mirror_num++; + } + } + } + + if (mirror_num < 2) + return FALSE; + + point_x[0] = randint0(mirror_num); + do { + point_x[1] = randint0(mirror_num); + } while (point_x[0] == point_x[1]); + + point_y[0] = mirror_y[point_x[0]]; + point_x[0] = mirror_x[point_x[0]]; + point_y[1] = mirror_y[point_x[1]]; + point_x[1] = mirror_x[point_x[1]]; + point_y[2] = caster_ptr->y; + point_x[2] = caster_ptr->x; + + POSITION x = point_x[0] + point_x[1] + point_x[2]; + POSITION y = point_y[0] + point_y[1] + point_y[2]; + + POSITION centersign = (point_x[0] * 3 - x) * (point_y[1] * 3 - y) - (point_y[0] * 3 - y) * (point_x[1] * 3 - x); + if (centersign == 0) + return FALSE; + + POSITION x1 = point_x[0] < point_x[1] ? point_x[0] : point_x[1]; + x1 = x1 < point_x[2] ? x1 : point_x[2]; + POSITION y1 = point_y[0] < point_y[1] ? point_y[0] : point_y[1]; + y1 = y1 < point_y[2] ? y1 : point_y[2]; + + POSITION x2 = point_x[0] > point_x[1] ? point_x[0] : point_x[1]; + x2 = x2 > point_x[2] ? x2 : point_x[2]; + POSITION y2 = point_y[0] > point_y[1] ? point_y[0] : point_y[1]; + y2 = y2 > point_y[2] ? y2 : point_y[2]; + + for (y = y1; y <= y2; y++) { + for (x = x1; x <= x2; x++) { + if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0 + && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0 + && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) { + if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) { + if (!(caster_ptr->blind) && panel_contains(y, x)) { + u16b p = bolt_pict(y, x, y, x, GF_MANA); + print_rel(caster_ptr, PICT_C(p), PICT_A(p), y, x); + move_cursor_relative(y, x); + Term_fresh(); + Term_xtra(TERM_XTRA_DELAY, msec); + } + } + } + } + } + + for (y = y1; y <= y2; y++) { + for (x = x1; x <= x2; x++) { + if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0 + && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0 + && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) { + if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) { + (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_MANA); + } + } + } + } + + for (y = y1; y <= y2; y++) { + for (x = x1; x <= x2; x++) { + if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0 + && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0 + && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) { + if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) { + (void)affect_item(caster_ptr, 0, 0, y, x, dam, GF_MANA); + } + } + } + } + + for (y = y1; y <= y2; y++) { + for (x = x1; x <= x2; x++) { + if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0 + && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0 + && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) { + if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) { + (void)affect_monster(caster_ptr, 0, 0, y, x, dam, GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP), TRUE); + } + } + } + } + + if (one_in_(7)) { + msg_print(_("鏡が結界に耐えきれず、壊れてしまった。", "The field broke a mirror")); + remove_mirror(caster_ptr, point_y[0], point_x[0]); + } + + return TRUE; +} + +/*! + * @brief 鏡魔法「鏡の封印」の効果処理 + * @param dam ダメージ量 + * @return 効果があったらTRUEを返す + */ +void seal_of_mirror(player_type *caster_ptr, HIT_POINT dam) +{ + for (POSITION x = 0; x < caster_ptr->current_floor_ptr->width; x++) { + for (POSITION y = 0; y < caster_ptr->current_floor_ptr->height; y++) { + if (!is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x])) + continue; + + if (!affect_monster(caster_ptr, 0, 0, y, x, dam, GF_GENOCIDE, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP), TRUE)) + continue; + + if (!caster_ptr->current_floor_ptr->grid_array[y][x].m_idx) { + remove_mirror(caster_ptr, y, x); + } + } + } +} diff --git a/src/mind/racial-mirror-master.h b/src/mind/racial-mirror-master.h index 057b30968..28f559a0f 100644 --- a/src/mind/racial-mirror-master.h +++ b/src/mind/racial-mirror-master.h @@ -1,5 +1,9 @@ #pragma once +#include "system/angband.h" + bool check_multishadow(player_type *creature_ptr); bool mirror_concentration(player_type *creature_ptr); void remove_all_mirrors(player_type *caster_ptr, bool explode); +bool binding_field(player_type *caster_ptr, HIT_POINT dam); +void seal_of_mirror(player_type *caster_ptr, HIT_POINT dam); diff --git a/src/spell/spells-mirror.c b/src/spell/spells-mirror.c deleted file mode 100644 index 743dc3c2b..000000000 --- a/src/spell/spells-mirror.c +++ /dev/null @@ -1,158 +0,0 @@ -#include "spell/spells-mirror.h" -#include "effect/effect-feature.h" -#include "effect/effect-item.h" -#include "effect/effect-monster.h" -#include "effect/effect-characteristics.h" -#include "effect/spells-effect-util.h" -#include "effect/effect-monster.h" -#include "floor/floor.h" -#include "spell/spells-type.h" -#include "term/gameterm.h" -#include "view/display-main-window.h" - -/*! - * @brief 鏡魔法「封魔結界」の効果処理 - * @param dam ダメージ量 - * @return 効果があったらTRUEを返す - */ -bool binding_field(player_type *caster_ptr, HIT_POINT dam) -{ - POSITION mirror_x[10], mirror_y[10]; /* 鏡はもっと少ない */ - int mirror_num = 0; /* 鏡の数 */ - int msec = delay_factor * delay_factor * delay_factor; - - /* 三角形の頂点 */ - POSITION point_x[3]; - POSITION point_y[3]; - - /* Default target of monsterspell is player */ - monster_target_y = caster_ptr->y; - monster_target_x = caster_ptr->x; - - for (POSITION x = 0; x < caster_ptr->current_floor_ptr->width; x++) { - for (POSITION y = 0; y < caster_ptr->current_floor_ptr->height; y++) { - if (is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]) && distance(caster_ptr->y, caster_ptr->x, y, x) <= MAX_RANGE - && distance(caster_ptr->y, caster_ptr->x, y, x) != 0 && player_has_los_bold(caster_ptr, y, x) - && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) { - mirror_y[mirror_num] = y; - mirror_x[mirror_num] = x; - mirror_num++; - } - } - } - - if (mirror_num < 2) - return FALSE; - - point_x[0] = randint0(mirror_num); - do { - point_x[1] = randint0(mirror_num); - } while (point_x[0] == point_x[1]); - - point_y[0] = mirror_y[point_x[0]]; - point_x[0] = mirror_x[point_x[0]]; - point_y[1] = mirror_y[point_x[1]]; - point_x[1] = mirror_x[point_x[1]]; - point_y[2] = caster_ptr->y; - point_x[2] = caster_ptr->x; - - POSITION x = point_x[0] + point_x[1] + point_x[2]; - POSITION y = point_y[0] + point_y[1] + point_y[2]; - - POSITION centersign = (point_x[0] * 3 - x) * (point_y[1] * 3 - y) - (point_y[0] * 3 - y) * (point_x[1] * 3 - x); - if (centersign == 0) - return FALSE; - - POSITION x1 = point_x[0] < point_x[1] ? point_x[0] : point_x[1]; - x1 = x1 < point_x[2] ? x1 : point_x[2]; - POSITION y1 = point_y[0] < point_y[1] ? point_y[0] : point_y[1]; - y1 = y1 < point_y[2] ? y1 : point_y[2]; - - POSITION x2 = point_x[0] > point_x[1] ? point_x[0] : point_x[1]; - x2 = x2 > point_x[2] ? x2 : point_x[2]; - POSITION y2 = point_y[0] > point_y[1] ? point_y[0] : point_y[1]; - y2 = y2 > point_y[2] ? y2 : point_y[2]; - - for (y = y1; y <= y2; y++) { - for (x = x1; x <= x2; x++) { - if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0 - && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0 - && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) { - if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) { - if (!(caster_ptr->blind) && panel_contains(y, x)) { - u16b p = bolt_pict(y, x, y, x, GF_MANA); - print_rel(caster_ptr, PICT_C(p), PICT_A(p), y, x); - move_cursor_relative(y, x); - Term_fresh(); - Term_xtra(TERM_XTRA_DELAY, msec); - } - } - } - } - } - - for (y = y1; y <= y2; y++) { - for (x = x1; x <= x2; x++) { - if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0 - && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0 - && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) { - if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) { - (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_MANA); - } - } - } - } - - for (y = y1; y <= y2; y++) { - for (x = x1; x <= x2; x++) { - if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0 - && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0 - && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) { - if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) { - (void)affect_item(caster_ptr, 0, 0, y, x, dam, GF_MANA); - } - } - } - } - - for (y = y1; y <= y2; y++) { - for (x = x1; x <= x2; x++) { - if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0 - && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0 - && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) { - if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) { - (void)affect_monster(caster_ptr, 0, 0, y, x, dam, GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP), TRUE); - } - } - } - } - - if (one_in_(7)) { - msg_print(_("鏡が結界に耐えきれず、壊れてしまった。", "The field broke a mirror")); - remove_mirror(caster_ptr, point_y[0], point_x[0]); - } - - return TRUE; -} - -/*! - * @brief 鏡魔法「鏡の封印」の効果処理 - * @param dam ダメージ量 - * @return 効果があったらTRUEを返す - */ -void seal_of_mirror(player_type *caster_ptr, HIT_POINT dam) -{ - for (POSITION x = 0; x < caster_ptr->current_floor_ptr->width; x++) { - for (POSITION y = 0; y < caster_ptr->current_floor_ptr->height; y++) { - if (!is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x])) - continue; - - if (!affect_monster(caster_ptr, 0, 0, y, x, dam, GF_GENOCIDE, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP), TRUE)) - continue; - - if (!caster_ptr->current_floor_ptr->grid_array[y][x].m_idx) { - remove_mirror(caster_ptr, y, x); - } - } - } -} diff --git a/src/spell/spells-mirror.h b/src/spell/spells-mirror.h deleted file mode 100644 index 0c00caea5..000000000 --- a/src/spell/spells-mirror.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "system/angband.h" - -bool binding_field(player_type *caster_ptr, HIT_POINT dam); -void seal_of_mirror(player_type *caster_ptr, HIT_POINT dam); -- 2.11.0