From ecb1ab4ba1eeea2e23686a27c8c4eeb75effe9a7 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 3 Nov 2024 23:35:00 +0900 Subject: [PATCH 01/15] =?UTF-8?q?[Refactor]=20#4569=20describe=5Fflavor()?= =?UTF-8?q?=20=E3=82=92=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=97=E3=81=A7?= =?UTF-8?q?=E3=83=9D=E3=82=A4=E3=83=B3=E3=82=BF=E3=82=92=E5=8F=82=E7=85=A7?= =?UTF-8?q?=E3=81=B8=E5=A4=89=E3=81=88=E3=82=89=E3=82=8C=E3=82=8B=E7=AE=87?= =?UTF-8?q?=E6=89=80=E3=82=92=E5=A4=89=E3=81=88=E3=81=9F=20(=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=AB=E3=83=80=E3=81=AE=E9=A0=AD=E6=96=87=E5=AD=97?= =?UTF-8?q?=EF=BC=9Asp)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/spell-kind/spells-enchant.cpp | 2 +- src/spell-kind/spells-equipment.cpp | 60 ++++++++++++++-------------- src/spell-kind/spells-fetcher.cpp | 10 ++--- src/spell-kind/spells-perception.cpp | 7 +--- src/spell-realm/spells-sorcery.cpp | 2 +- src/spell/spells-object.cpp | 30 +++++++------- src/spell/spells-status.cpp | 9 ++--- 7 files changed, 57 insertions(+), 63 deletions(-) diff --git a/src/spell-kind/spells-enchant.cpp b/src/spell-kind/spells-enchant.cpp index 59a9432f3f..0b14ca1b68 100644 --- a/src/spell-kind/spells-enchant.cpp +++ b/src/spell-kind/spells-enchant.cpp @@ -136,7 +136,7 @@ bool mundane_spell(PlayerType *player_ptr, bool only_equip) POSITION iy = item_ptr->iy; POSITION ix = item_ptr->ix; auto marked = item_ptr->marked; - auto inscription = std::move(item_ptr->inscription); + auto &&inscription = std::move(item_ptr->inscription); item_ptr->generate(item_ptr->bi_id); item_ptr->iy = iy; item_ptr->ix = ix; diff --git a/src/spell-kind/spells-equipment.cpp b/src/spell-kind/spells-equipment.cpp index 7161b74234..cc40e4cb5e 100644 --- a/src/spell-kind/spells-equipment.cpp +++ b/src/spell-kind/spells-equipment.cpp @@ -34,63 +34,63 @@ bool apply_disenchant(PlayerType *player_ptr, BIT_FLAGS mode) }; const auto t = rand_choice(candidates); - auto *o_ptr = &player_ptr->inventory_list[t]; - if (!o_ptr->is_valid()) { + auto &item = player_ptr->inventory_list[t]; + if (!item.is_valid()) { return false; } - if (!o_ptr->is_weapon_armour_ammo()) { + if (!item.is_weapon_armour_ammo()) { return false; } - if ((o_ptr->to_h <= 0) && (o_ptr->to_d <= 0) && (o_ptr->to_a <= 0) && (o_ptr->pval <= 1)) { + if ((item.to_h <= 0) && (item.to_d <= 0) && (item.to_a <= 0) && (item.pval <= 1)) { return false; } - const auto item_name = describe_flavor(player_ptr, *o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY)); - if (o_ptr->is_fixed_or_random_artifact() && evaluate_percent(71)) { + const auto item_name = describe_flavor(player_ptr, item, (OD_OMIT_PREFIX | OD_NAME_ONLY)); + if (item.is_fixed_or_random_artifact() && evaluate_percent(71)) { #ifdef JP msg_format("%s(%c)は劣化を跳ね返した!", item_name.data(), index_to_label(t)); #else - msg_format("Your %s (%c) resist%s disenchantment!", item_name.data(), index_to_label(t), ((o_ptr->number != 1) ? "" : "s")); + msg_format("Your %s (%c) resist%s disenchantment!", item_name.data(), index_to_label(t), (item.number != 1) ? "" : "s"); #endif return true; } - int to_h = o_ptr->to_h; - int to_d = o_ptr->to_d; - int to_a = o_ptr->to_a; - int pval = o_ptr->pval; + int to_h = item.to_h; + int to_d = item.to_d; + int to_a = item.to_a; + int pval = item.pval; - if (o_ptr->to_h > 0) { - o_ptr->to_h--; + if (item.to_h > 0) { + item.to_h--; } - if ((o_ptr->to_h > 5) && one_in_(5)) { - o_ptr->to_h--; + if ((item.to_h > 5) && one_in_(5)) { + item.to_h--; } - if (o_ptr->to_d > 0) { - o_ptr->to_d--; + if (item.to_d > 0) { + item.to_d--; } - if ((o_ptr->to_d > 5) && one_in_(5)) { - o_ptr->to_d--; + if ((item.to_d > 5) && one_in_(5)) { + item.to_d--; } - if (o_ptr->to_a > 0) { - o_ptr->to_a--; + if (item.to_a > 0) { + item.to_a--; } - if ((o_ptr->to_a > 5) && one_in_(5)) { - o_ptr->to_a--; + if ((item.to_a > 5) && one_in_(5)) { + item.to_a--; } - if ((o_ptr->pval > 1) && one_in_(13) && !(mode & 0x01)) { - o_ptr->pval--; + if ((item.pval > 1) && one_in_(13) && !(mode & 0x01)) { + item.pval--; } - bool is_actually_disenchanted = to_h != o_ptr->to_h; - is_actually_disenchanted |= to_d != o_ptr->to_d; - is_actually_disenchanted |= to_a != o_ptr->to_a; - is_actually_disenchanted |= pval != o_ptr->pval; + auto is_actually_disenchanted = to_h != item.to_h; + is_actually_disenchanted |= to_d != item.to_d; + is_actually_disenchanted |= to_a != item.to_a; + is_actually_disenchanted |= pval != item.pval; if (!is_actually_disenchanted) { return true; } @@ -98,7 +98,7 @@ bool apply_disenchant(PlayerType *player_ptr, BIT_FLAGS mode) #ifdef JP msg_format("%s(%c)は劣化してしまった!", item_name.data(), index_to_label(t)); #else - msg_format("Your %s (%c) %s disenchanted!", item_name.data(), index_to_label(t), ((o_ptr->number != 1) ? "were" : "was")); + msg_format("Your %s (%c) %s disenchanted!", item_name.data(), index_to_label(t), (item.number != 1) ? "were" : "was"); #endif chg_virtue(player_ptr, Virtue::HARMONY, 1); chg_virtue(player_ptr, Virtue::ENCHANT, -2); diff --git a/src/spell-kind/spells-fetcher.cpp b/src/spell-kind/spells-fetcher.cpp index 9445f166eb..68e525606d 100644 --- a/src/spell-kind/spells-fetcher.cpp +++ b/src/spell-kind/spells-fetcher.cpp @@ -97,8 +97,8 @@ void fetch_item(PlayerType *player_ptr, DIRECTION dir, WEIGHT wgt, bool require_ } } - auto *o_ptr = &floor.o_list[g_ptr->o_idx_list.front()]; - if (o_ptr->weight > wgt) { + auto &item = floor.o_list[g_ptr->o_idx_list.front()]; + if (item.weight > wgt) { msg_print(_("そのアイテムは重過ぎます。", "The object is too heavy.")); return; } @@ -106,10 +106,10 @@ void fetch_item(PlayerType *player_ptr, DIRECTION dir, WEIGHT wgt, bool require_ OBJECT_IDX i = g_ptr->o_idx_list.front(); g_ptr->o_idx_list.pop_front(); floor.grid_array[p_pos.y][p_pos.x].o_idx_list.add(&floor, i); /* 'move' it */ - o_ptr->iy = p_pos.y; - o_ptr->ix = p_pos.x; + item.iy = p_pos.y; + item.ix = p_pos.x; - const auto item_name = describe_flavor(player_ptr, *o_ptr, OD_NAME_ONLY); + const auto item_name = describe_flavor(player_ptr, item, OD_NAME_ONLY); msg_format(_("%s^があなたの足元に飛んできた。", "%s^ flies through the air to your feet."), item_name.data()); note_spot(player_ptr, p_pos.y, p_pos.x); RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::MAP); diff --git a/src/spell-kind/spells-perception.cpp b/src/spell-kind/spells-perception.cpp index 9ea5110e87..dceccc4b8e 100644 --- a/src/spell-kind/spells-perception.cpp +++ b/src/spell-kind/spells-perception.cpp @@ -135,7 +135,6 @@ bool ident_spell(PlayerType *player_ptr, bool only_equip) } auto old_known = identify_item(player_ptr, o_ptr); - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); if (i_idx >= INVEN_MAIN_HAND) { msg_format(_("%s^: %s(%c)。", "%s^: %s (%c)."), describe_use(player_ptr, i_idx), item_name.data(), index_to_label(i_idx)); @@ -176,19 +175,15 @@ bool identify_fully(PlayerType *player_ptr, bool only_equip) } constexpr auto s = _("*鑑定*するべきアイテムがない。", "You have nothing to *identify*."); - short i_idx; auto *o_ptr = choose_object(player_ptr, &i_idx, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), *item_tester); - if (!o_ptr) { + if (o_ptr == nullptr) { return false; } auto old_known = identify_item(player_ptr, o_ptr); - o_ptr->ident |= (IDENT_FULL_KNOWN); - window_stuff(player_ptr); - const auto item_name = describe_flavor(player_ptr, *o_ptr, 0); if (i_idx >= INVEN_MAIN_HAND) { msg_format(_("%s^: %s(%c)。", "%s^: %s (%c)."), describe_use(player_ptr, i_idx), item_name.data(), index_to_label(i_idx)); diff --git a/src/spell-realm/spells-sorcery.cpp b/src/spell-realm/spells-sorcery.cpp index 03a7186cda..00229b0622 100644 --- a/src/spell-realm/spells-sorcery.cpp +++ b/src/spell-realm/spells-sorcery.cpp @@ -32,7 +32,7 @@ bool alchemy(PlayerType *player_ptr) constexpr auto s = _("金に変えられる物がありません。", "You have nothing to turn to gold."); short i_idx; auto *o_ptr = choose_object(player_ptr, &i_idx, q, s, (USE_INVEN | USE_FLOOR)); - if (!o_ptr) { + if (o_ptr == nullptr) { return false; } diff --git a/src/spell/spells-object.cpp b/src/spell/spells-object.cpp index 0ac26e3fd8..88a047b1bb 100644 --- a/src/spell/spells-object.cpp +++ b/src/spell/spells-object.cpp @@ -201,14 +201,14 @@ void acquirement(PlayerType *player_ptr, POSITION y1, POSITION x1, int num, bool bool curse_armor(PlayerType *player_ptr) { /* Curse the body armor */ - auto *o_ptr = &player_ptr->inventory_list[INVEN_BODY]; - if (!o_ptr->is_valid()) { + auto &item = player_ptr->inventory_list[INVEN_BODY]; + if (!item.is_valid()) { return false; } - const auto item_name = describe_flavor(player_ptr, *o_ptr, OD_OMIT_PREFIX); + const auto item_name = describe_flavor(player_ptr, item, OD_OMIT_PREFIX); - if (o_ptr->is_fixed_or_random_artifact() && one_in_(2)) { + if (item.is_fixed_or_random_artifact() && one_in_(2)) { #ifdef JP msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "防具", item_name.data()); #else @@ -219,16 +219,16 @@ bool curse_armor(PlayerType *player_ptr) msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), item_name.data()); chg_virtue(player_ptr, Virtue::ENCHANT, -5); - o_ptr->fa_id = FixedArtifactId::NONE; - o_ptr->ego_idx = EgoType::BLASTED; - o_ptr->to_a = 0 - randint1(5) - randint1(5); - o_ptr->to_h = 0; - o_ptr->to_d = 0; - o_ptr->ac = 0; - o_ptr->damage_dice = Dice(0, 0); - o_ptr->art_flags.clear(); - o_ptr->curse_flags.set(CurseTraitType::CURSED); - o_ptr->ident |= IDENT_BROKEN; + item.fa_id = FixedArtifactId::NONE; + item.ego_idx = EgoType::BLASTED; + item.to_a = 0 - randint1(5) - randint1(5); + item.to_h = 0; + item.to_d = 0; + item.ac = 0; + item.damage_dice = Dice(0, 0); + item.art_flags.clear(); + item.curse_flags.set(CurseTraitType::CURSED); + item.ident |= IDENT_BROKEN; auto &rfu = RedrawingFlagsUpdater::get_instance(); static constexpr auto flags_srf = { StatusRecalculatingFlag::BONUS, @@ -478,7 +478,7 @@ bool enchant_spell(PlayerType *player_ptr, HIT_PROB num_hit, int num_dam, ARMOUR short i_idx; const auto options = USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT; auto *o_ptr = choose_object(player_ptr, &i_idx, q, s, options, item_tester); - if (!o_ptr) { + if (o_ptr == nullptr) { return false; } diff --git a/src/spell/spells-status.cpp b/src/spell/spells-status.cpp index 14ac2ebf67..d49dc175c9 100644 --- a/src/spell/spells-status.cpp +++ b/src/spell/spells-status.cpp @@ -568,7 +568,7 @@ bool fishing(PlayerType *player_ptr) */ bool cosmic_cast_off(PlayerType *player_ptr, ItemEntity **o_ptr_ptr) { - auto *o_ptr = (*o_ptr_ptr); + auto *o_ptr = *o_ptr_ptr; /* Cast off activated item */ INVENTORY_IDX slot; @@ -582,15 +582,14 @@ bool cosmic_cast_off(PlayerType *player_ptr, ItemEntity **o_ptr_ptr) return false; } - ItemEntity forge; - (&forge)->copy_from(o_ptr); + ItemEntity item = *o_ptr; inven_item_increase(player_ptr, slot, (0 - o_ptr->number)); inven_item_optimize(player_ptr, slot); - OBJECT_IDX old_o_idx = drop_near(player_ptr, &forge, 0, player_ptr->y, player_ptr->x); + OBJECT_IDX old_o_idx = drop_near(player_ptr, &item, 0, player_ptr->y, player_ptr->x); *o_ptr_ptr = &player_ptr->current_floor_ptr->o_list[old_o_idx]; - const auto item_name = describe_flavor(player_ptr, forge, OD_NAME_ONLY); + const auto item_name = describe_flavor(player_ptr, item, OD_NAME_ONLY); msg_format(_("%sを脱ぎ捨てた。", "You cast off %s."), item_name.data()); sound(SOUND_TAKE_OFF); From 6f4ceb26693dd9a0b8396cbecda22d3a94a06c3d Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sat, 9 Nov 2024 21:57:58 +0900 Subject: [PATCH 02/15] =?UTF-8?q?[Refactor]=20#4595=20MonsterEntity::get?= =?UTF-8?q?=5Fposition()=E3=80=81get=5Ftarget=5Fposition()=20=E3=82=92?= =?UTF-8?q?=E5=AE=9F=E8=A3=85=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/monster-floor/monster-sweep-grid.cpp | 4 ++-- src/system/monster-entity.cpp | 10 ++++++++++ src/system/monster-entity.h | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/monster-floor/monster-sweep-grid.cpp b/src/monster-floor/monster-sweep-grid.cpp index cc5bd96363..b46bfcbb05 100644 --- a/src/monster-floor/monster-sweep-grid.cpp +++ b/src/monster-floor/monster-sweep-grid.cpp @@ -54,11 +54,11 @@ bool MonsterSweepGrid::get_movable_grid() auto y2 = this->player_ptr->y; auto x2 = this->player_ptr->x; this->will_run = this->mon_will_run(); - Pos2D pos_monster_from(monster_from.fy, monster_from.fx); + const auto pos_monster_from = monster_from.get_position(); const auto no_flow = monster_from.mflag2.has(MonsterConstantFlagType::NOFLOW) && (floor.get_grid(pos_monster_from).get_cost(monrace.get_grid_flow_type()) > 2); this->can_pass_wall = monrace.feature_flags.has(MonsterFeatureType::PASS_WALL) && (!monster_from.is_riding() || has_pass_wall(this->player_ptr)); if (!this->will_run && monster_from.target_y) { - Pos2D pos_target(monster_from.target_y, monster_from.target_x); + const auto pos_target = monster_from.get_target_position(); int t_m_idx = floor.get_grid(pos_target).m_idx; if (t_m_idx > 0) { const auto is_enemies = monster_from.is_hostile_to_melee(floor.m_list[t_m_idx]); diff --git a/src/system/monster-entity.cpp b/src/system/monster-entity.cpp index b283c2cb56..a4309e0c01 100644 --- a/src/system/monster-entity.cpp +++ b/src/system/monster-entity.cpp @@ -517,6 +517,16 @@ bool MonsterEntity::is_riding() const return this->mflag2.has(MonsterConstantFlagType::RIDING); } +Pos2D MonsterEntity::get_position() const +{ + return { this->fy, this->fx }; +} + +Pos2D MonsterEntity::get_target_position() const +{ + return { this->target_y, this->target_x }; +} + bool MonsterEntity::can_ring_boss_call_nazgul() const { auto is_boss = this->r_idx == MonraceId::MORGOTH; diff --git a/src/system/monster-entity.h b/src/system/monster-entity.h index 59b2391883..c243d02ffa 100644 --- a/src/system/monster-entity.h +++ b/src/system/monster-entity.h @@ -6,6 +6,7 @@ #include "object/object-index-list.h" #include "system/angband.h" #include "util/flag-group.h" +#include "util/point-2d.h" #include #include @@ -101,6 +102,8 @@ class MonsterEntity { std::optional order_pet_whistle(const MonsterEntity &other) const; std::optional order_pet_dismission(const MonsterEntity &other) const; bool is_riding() const; + Pos2D get_position() const; + Pos2D get_target_position() const; bool can_ring_boss_call_nazgul() const; void set_individual_speed(bool force_fixed_speed); From 47fc113b370badd3e5bda557c36d55177eac7164 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sat, 9 Nov 2024 23:54:46 +0900 Subject: [PATCH 03/15] =?UTF-8?q?[Refactor]=20#4595=20msa=5Ftype::get=5Fpo?= =?UTF-8?q?sition()=20=E3=82=92=E5=AE=9F=E8=A3=85=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mspell/mspell-attack-util.cpp | 5 +++++ src/mspell/mspell-attack-util.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/mspell/mspell-attack-util.cpp b/src/mspell/mspell-attack-util.cpp index 4914b77cf7..de6ed163e7 100644 --- a/src/mspell/mspell-attack-util.cpp +++ b/src/mspell/mspell-attack-util.cpp @@ -16,3 +16,8 @@ msa_type::msa_type(PlayerType *player_ptr, MONSTER_IDX m_idx) this->no_inate = !evaluate_percent(this->r_ptr->freq_spell * 2); this->ability_flags = this->r_ptr->ability_flags; } + +Pos2D msa_type::get_position() const +{ + return Pos2D(this->y, this->x); +} diff --git a/src/mspell/mspell-attack-util.h b/src/mspell/mspell-attack-util.h index a6a245cb8f..c468f5dfc4 100644 --- a/src/mspell/mspell-attack-util.h +++ b/src/mspell/mspell-attack-util.h @@ -3,6 +3,7 @@ #include "monster-race/race-ability-flags.h" #include "system/angband.h" #include "util/flag-group.h" +#include "util/point-2d.h" #include #include @@ -40,4 +41,6 @@ struct msa_type { MonraceDefinition *r_ptr; bool no_inate; EnumClassFlagGroup ability_flags; + + Pos2D get_position() const; }; From 5e9b7c8adf72ebd595f406ed1bd83b240c45d884 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 10 Nov 2024 00:11:34 +0900 Subject: [PATCH 04/15] =?UTF-8?q?[Refactor]=20#4595=20path=5Fcheck=5Fpf=20?= =?UTF-8?q?=E3=81=AE=E9=96=A2=E6=95=B0=E3=83=9D=E3=82=A4=E3=83=B3=E3=82=BF?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4=E3=81=97=E3=81=A6enum=20class=20?= =?UTF-8?q?=E3=81=AB=E5=B7=AE=E3=81=97=E6=9B=BF=E3=81=88=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mspell/mspell-lite.cpp | 22 +++++++++++++++++----- src/mspell/mspell-lite.h | 8 ++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/mspell/mspell-lite.cpp b/src/mspell/mspell-lite.cpp index 0623288488..78c8a5f52e 100644 --- a/src/mspell/mspell-lite.cpp +++ b/src/mspell/mspell-lite.cpp @@ -33,10 +33,10 @@ * @param yp 最適な目標地点のY座標を返す参照ポインタ * @param xp 最適な目標地点のX座標を返す参照ポインタ * @param f_flag 射線に入れるのを避ける地形の所持フラグ - * @param path_check 射線を判定するための関数ポインタ + * @param checker 射線判定の振り分け * @return 有効な座標があった場合TRUEを返す */ -bool adjacent_grid_check(PlayerType *player_ptr, MonsterEntity *m_ptr, POSITION *yp, POSITION *xp, TerrainCharacteristics f_flag, path_check_pf path_check) +bool adjacent_grid_check(PlayerType *player_ptr, MonsterEntity *m_ptr, POSITION *yp, POSITION *xp, TerrainCharacteristics f_flag, PathChecker checker) { 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 } }; @@ -61,7 +61,19 @@ bool adjacent_grid_check(PlayerType *player_ptr, MonsterEntity *m_ptr, POSITION continue; } - if (path_check(player_ptr, m_ptr->fy, m_ptr->fx, next_y, next_x)) { + bool check_result; + switch (checker) { + case PathChecker::PROJECTION: + check_result = projectable(player_ptr, m_ptr->fy, m_ptr->fx, next_y, next_x); + break; + case PathChecker::LOS: + check_result = los(player_ptr, m_ptr->fy, m_ptr->fx, next_y, next_x); + break; + default: + THROW_EXCEPTION(std::logic_error, format("Invalid PathChecker is specified! %d", enum2i(checker))); + } + + if (check_result) { *yp = next_y; *xp = next_x; return true; @@ -85,7 +97,7 @@ void decide_lite_range(PlayerType *player_ptr, msa_type *msa_ptr) if (terrain.flags.has_not(TerrainCharacteristics::LOS) && terrain.flags.has(TerrainCharacteristics::PROJECT) && one_in_(2)) { msa_ptr->ability_flags.reset(MonsterAbilityType::BR_LITE); } - } else if (!adjacent_grid_check(player_ptr, msa_ptr->m_ptr, &msa_ptr->y_br_lite, &msa_ptr->x_br_lite, TerrainCharacteristics::LOS, los)) { + } else if (!adjacent_grid_check(player_ptr, msa_ptr->m_ptr, &msa_ptr->y_br_lite, &msa_ptr->x_br_lite, TerrainCharacteristics::LOS, PathChecker::LOS)) { msa_ptr->ability_flags.reset(MonsterAbilityType::BR_LITE); } @@ -193,7 +205,7 @@ bool decide_lite_projection(PlayerType *player_ptr, msa_type *msa_ptr) msa_ptr->success = false; check_lite_area_by_mspell(player_ptr, msa_ptr); if (!msa_ptr->success) { - msa_ptr->success = adjacent_grid_check(player_ptr, msa_ptr->m_ptr, &msa_ptr->y, &msa_ptr->x, TerrainCharacteristics::PROJECT, projectable); + msa_ptr->success = adjacent_grid_check(player_ptr, msa_ptr->m_ptr, &msa_ptr->y, &msa_ptr->x, TerrainCharacteristics::PROJECT, PathChecker::PROJECTION); } decide_lite_breath(msa_ptr); diff --git a/src/mspell/mspell-lite.h b/src/mspell/mspell-lite.h index 83b515912e..9d1068f236 100644 --- a/src/mspell/mspell-lite.h +++ b/src/mspell/mspell-lite.h @@ -2,12 +2,16 @@ #include "system/angband.h" +enum class PathChecker { + PROJECTION, + LOS, +}; + class MonsterEntity; struct msa_type; class PlayerType; -typedef bool (*path_check_pf)(PlayerType *, POSITION, POSITION, POSITION, POSITION); enum class TerrainCharacteristics; -bool adjacent_grid_check(PlayerType *player_ptr, MonsterEntity *m_ptr, POSITION *yp, POSITION *xp, TerrainCharacteristics f_flag, path_check_pf path_check); +bool adjacent_grid_check(PlayerType *player_ptr, MonsterEntity *m_ptr, POSITION *yp, POSITION *xp, TerrainCharacteristics f_flag, PathChecker checker); void decide_lite_range(PlayerType *player_ptr, msa_type *msa_ptr); bool decide_lite_projection(PlayerType *player_ptr, msa_type *msa_ptr); void decide_lite_area(PlayerType *player_ptr, msa_type *msa_ptr); From b12365df31209ee0b2959522f0d11a05902291a0 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 10 Nov 2024 00:13:26 +0900 Subject: [PATCH 05/15] =?UTF-8?q?[Refactor]=20#4595=20projectable()=20?= =?UTF-8?q?=E3=81=AE=E5=BC=95=E6=95=B0=E3=82=92POSITION=20=E3=81=8B?= =?UTF-8?q?=E3=82=89Pos2D=20=E3=81=AB=E5=A4=89=E3=81=88=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/blue-magic/blue-magic-caster.cpp | 4 +- src/cmd-action/cmd-mane.cpp | 4 +- src/effect/effect-player.cpp | 22 ++--- src/effect/effect-processor.cpp | 20 ++-- src/floor/floor-leaver.cpp | 10 +- src/floor/floor-object.cpp | 3 +- src/floor/floor-util.cpp | 9 +- src/floor/geometry.cpp | 5 +- src/grid/trap.cpp | 12 +-- src/melee/melee-spell-flags-checker.cpp | 35 +++---- src/mind/mind-force-trainer.cpp | 2 +- src/mind/mind-mirror-master.cpp | 13 +-- src/monster-floor/monster-direction.cpp | 50 +++++----- src/monster-floor/monster-generator.cpp | 8 +- src/monster-floor/monster-move.cpp | 7 +- src/monster-floor/monster-runaway.cpp | 5 +- src/monster-floor/monster-safety-hiding.cpp | 58 +++++------ src/monster-floor/monster-sweep-grid.cpp | 103 ++++++++++---------- src/monster-floor/monster-sweep-grid.h | 3 +- src/monster/monster-processor.cpp | 15 +-- src/monster/monster-status-setter.cpp | 17 ++-- src/monster/monster-update.cpp | 26 ++--- src/mspell/mspell-checker.cpp | 37 +++---- src/mspell/mspell-judgement.cpp | 22 +++-- src/mspell/mspell-lite.cpp | 22 ++--- src/object-activation/activation-others.cpp | 2 +- src/object/warning.cpp | 13 +-- src/realm/realm-hissatsu.cpp | 7 +- src/spell-kind/spells-fetcher.cpp | 4 +- src/spell-kind/spells-sight.cpp | 12 +-- src/spell-kind/spells-world.cpp | 2 +- src/spell-realm/spells-chaos.cpp | 28 +++--- src/spell/range-calc.cpp | 22 +++-- src/spell/spells-summon.cpp | 17 ++-- src/target/projection-path-calculator.cpp | 12 +-- src/target/projection-path-calculator.h | 2 +- src/target/target-preparation.cpp | 12 +-- src/target/target-setter.cpp | 4 +- 38 files changed, 336 insertions(+), 313 deletions(-) diff --git a/src/blue-magic/blue-magic-caster.cpp b/src/blue-magic/blue-magic-caster.cpp index 4b20f60287..ca67d04cac 100644 --- a/src/blue-magic/blue-magic-caster.cpp +++ b/src/blue-magic/blue-magic-caster.cpp @@ -49,7 +49,7 @@ static bool cast_blue_dispel(PlayerType *player_ptr) const Pos2D pos(target_row, target_col); const auto &grid = player_ptr->current_floor_ptr->get_grid(pos); const auto m_idx = grid.m_idx; - if ((m_idx == 0) || !grid.has_los() || !projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col)) { + if ((m_idx == 0) || !grid.has_los() || !projectable(player_ptr, player_ptr->get_position(), pos)) { return true; } @@ -98,7 +98,7 @@ static std::optional exe_blue_teleport_back(PlayerType *player_ptr) const auto &floor = *player_ptr->current_floor_ptr; const Pos2D pos(target_row, target_col); const auto &grid = floor.get_grid(pos); - if (!grid.has_monster() || !grid.has_los() || !projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col)) { + if (!grid.has_monster() || !grid.has_los() || !projectable(player_ptr, player_ptr->get_position(), pos)) { return std::nullopt; } diff --git a/src/cmd-action/cmd-mane.cpp b/src/cmd-action/cmd-mane.cpp index 1bb9be4103..6a84ce90d7 100644 --- a/src/cmd-action/cmd-mane.cpp +++ b/src/cmd-action/cmd-mane.cpp @@ -319,7 +319,7 @@ static bool use_mane(PlayerType *player_ptr, MonsterAbilityType spell) const auto m_idx = grid.m_idx; auto should_dispel = m_idx == 0; should_dispel &= grid.has_los(); - should_dispel &= projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col); + should_dispel &= projectable(player_ptr, player_ptr->get_position(), pos); if (!should_dispel) { break; } @@ -959,7 +959,7 @@ static bool use_mane(PlayerType *player_ptr, MonsterAbilityType spell) const auto &grid_target = floor.get_grid(pos); auto should_teleport = grid_target.has_monster(); should_teleport &= grid_target.has_los(); - should_teleport &= projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col); + should_teleport &= projectable(player_ptr, player_ptr->get_position(), pos); if (!should_teleport) { break; } diff --git a/src/effect/effect-player.cpp b/src/effect/effect-player.cpp index 01b060c978..6ee88f00e2 100644 --- a/src/effect/effect-player.cpp +++ b/src/effect/effect-player.cpp @@ -88,27 +88,25 @@ static bool process_bolt_reflection(PlayerType *player_ptr, EffectPlayerType *ep } msg_print(mes); - POSITION t_y; - POSITION t_x; + Pos2D pos(0, 0); if (is_monster(ep_ptr->src_idx)) { - auto *floor_ptr = player_ptr->current_floor_ptr; - auto *m_ptr = &floor_ptr->m_list[ep_ptr->src_idx]; + const auto &floor = *player_ptr->current_floor_ptr; + const auto &monster = floor.m_list[ep_ptr->src_idx]; do { - t_y = m_ptr->fy - 1 + randint1(3); - t_x = m_ptr->fx - 1 + randint1(3); + const Pos2DVec vec(randint1(3) - 1, randint1(3) - 1); + pos = monster.get_position() + vec; max_attempts--; - } while (max_attempts && in_bounds2u(floor_ptr, t_y, t_x) && !projectable(player_ptr, player_ptr->y, player_ptr->x, t_y, t_x)); + } while (max_attempts && in_bounds2u(&floor, pos.y, pos.x) && !projectable(player_ptr, player_ptr->get_position(), pos)); if (max_attempts < 1) { - t_y = m_ptr->fy; - t_x = m_ptr->fx; + pos = monster.get_position(); } } else { - t_y = player_ptr->y - 1 + randint1(3); - t_x = player_ptr->x - 1 + randint1(3); + const Pos2DVec vec(randint1(3) - 1, randint1(3) - 1); + pos = player_ptr->get_position() + vec; } - (*project)(player_ptr, 0, 0, t_y, t_x, ep_ptr->dam, ep_ptr->attribute, (PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE), std::nullopt); + (*project)(player_ptr, 0, 0, pos.y, pos.x, ep_ptr->dam, ep_ptr->attribute, (PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE), std::nullopt); disturb(player_ptr, true, true); return true; } diff --git a/src/effect/effect-processor.cpp b/src/effect/effect-processor.cpp index 9926ebb06f..46005cf73c 100644 --- a/src/effect/effect-processor.cpp +++ b/src/effect/effect-processor.cpp @@ -227,6 +227,8 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO for (auto dist = 0; dist <= rad; dist++) { for (auto y = by - dist; y <= by + dist; y++) { for (auto x = bx - dist; x <= bx + dist; x++) { + const Pos2D pos(y, x); + const Pos2D pos_breath(by, bx); if (!in_bounds2(player_ptr->current_floor_ptr, y, x)) { continue; } @@ -247,7 +249,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO } break; default: - if (!projectable(player_ptr, by, bx, y, x)) { + if (!projectable(player_ptr, pos_breath, pos)) { continue; } break; @@ -303,7 +305,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO if (flag & PROJECT_KILL) { see_s_msg = is_monster(src_idx) ? is_seen(player_ptr, &player_ptr->current_floor_ptr->m_list[src_idx]) - : (is_player(src_idx) ? true : (player_can_see_bold(player_ptr, y1, x1) && projectable(player_ptr, player_ptr->y, player_ptr->x, y1, x1))); + : (is_player(src_idx) ? true : (player_can_see_bold(player_ptr, y1, x1) && projectable(player_ptr, player_ptr->get_position(), { y1, x1 }))); } if (flag & (PROJECT_GRID)) { @@ -370,17 +372,17 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO MonraceDefinition *ref_ptr = &m_ptr->get_monrace(); if ((flag & PROJECT_REFLECTABLE) && grid.m_idx && ref_ptr->misc_flags.has(MonsterMiscType::REFLECTING) && (!m_ptr->is_riding() || !(flag & PROJECT_PLAYER)) && (!src_idx || path_n > 1) && !one_in_(10)) { - POSITION t_y, t_x; + Pos2D pos_target(0, 0); int max_attempts = 10; do { - t_y = y1 - 1 + randint1(3); - t_x = x1 - 1 + randint1(3); + pos_target.y = y1 - 1 + randint1(3); + pos_target.x = x1 - 1 + randint1(3); max_attempts--; - } while (max_attempts && in_bounds2u(player_ptr->current_floor_ptr, t_y, t_x) && !projectable(player_ptr, pos.y, pos.x, t_y, t_x)); + } while (max_attempts && in_bounds2u(player_ptr->current_floor_ptr, pos_target.y, pos_target.x) && !projectable(player_ptr, pos, pos_target)); if (max_attempts < 1) { - t_y = y1; - t_x = x1; + pos_target.y = y1; + pos_target.x = x1; } if (is_seen(player_ptr, m_ptr)) { @@ -406,7 +408,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX src_idx, POSITIO flag |= PROJECT_PLAYER; } - project(player_ptr, grid.m_idx, 0, t_y, t_x, dam, typ, flag); + project(player_ptr, grid.m_idx, 0, pos_target.y, pos_target.x, dam, typ, flag); continue; } } diff --git a/src/floor/floor-leaver.cpp b/src/floor/floor-leaver.cpp index b3826abdb5..c2d8a36443 100644 --- a/src/floor/floor-leaver.cpp +++ b/src/floor/floor-leaver.cpp @@ -58,16 +58,18 @@ static bool check_pet_preservation_conditions(PlayerType *player_ptr, MonsterEnt return false; } - auto dis = distance(player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx); + const auto p_pos = player_ptr->get_position(); + const auto m_pos = m_ptr->get_position(); + const auto dis = distance(player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx); if (m_ptr->is_confused() || m_ptr->is_stunned() || m_ptr->is_asleep() || m_ptr->has_parent()) { return true; } const auto should_preserve = m_ptr->is_named(); - auto sight_from_player = player_ptr->current_floor_ptr->has_los({ m_ptr->fy, m_ptr->fx }); - sight_from_player &= projectable(player_ptr, player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx); + auto sight_from_player = player_ptr->current_floor_ptr->has_los(m_pos); + sight_from_player &= projectable(player_ptr, player_ptr->get_position(), m_ptr->get_position()); auto sight_from_monster = los(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x); - sight_from_monster &= projectable(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x); + sight_from_monster &= projectable(player_ptr, m_pos, p_pos); if (should_preserve && (sight_from_player || sight_from_monster)) { return dis > 3; } diff --git a/src/floor/floor-object.cpp b/src/floor/floor-object.cpp index c97cd7816a..ffbe4bfbef 100644 --- a/src/floor/floor-object.cpp +++ b/src/floor/floor-object.cpp @@ -359,10 +359,11 @@ OBJECT_IDX drop_near(PlayerType *player_ptr, ItemEntity *j_ptr, PERCENTAGE chanc ty = y + dy; tx = x + dx; + const Pos2D pos_target(ty, tx); if (!in_bounds(floor_ptr, ty, tx)) { continue; } - if (!projectable(player_ptr, y, x, ty, tx)) { + if (!projectable(player_ptr, { y, x }, pos_target)) { continue; } diff --git a/src/floor/floor-util.cpp b/src/floor/floor-util.cpp index 09cfd2a863..a135266cc1 100644 --- a/src/floor/floor-util.cpp +++ b/src/floor/floor-util.cpp @@ -156,13 +156,14 @@ void wipe_o_list(FloorType *floor_ptr) */ void scatter(PlayerType *player_ptr, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode) { - auto *floor_ptr = player_ptr->current_floor_ptr; + const Pos2D pos(y, x); + const auto &floor = *player_ptr->current_floor_ptr; POSITION nx, ny; while (true) { ny = rand_spread(y, d); nx = rand_spread(x, d); - - if (!in_bounds(floor_ptr, ny, nx)) { + const Pos2D pos_neighbor(ny, nx); + if (!in_bounds(&floor, ny, nx)) { continue; } if ((d > 1) && (distance(y, x, ny, nx) > d)) { @@ -175,7 +176,7 @@ void scatter(PlayerType *player_ptr, POSITION *yp, POSITION *xp, POSITION y, POS continue; } - if (projectable(player_ptr, y, x, ny, nx)) { + if (projectable(player_ptr, { y, x }, pos_neighbor)) { break; } } diff --git a/src/floor/geometry.cpp b/src/floor/geometry.cpp index 38c0b93f07..597f59ce81 100644 --- a/src/floor/geometry.cpp +++ b/src/floor/geometry.cpp @@ -202,8 +202,9 @@ Pos2D mmove2(const Pos2D &pos_orig, const Pos2D &pos1, const Pos2D &pos2) */ bool is_seen(PlayerType *player_ptr, MonsterEntity *m_ptr) { - bool is_inside_view = !ignore_unview; + auto is_inside_view = !ignore_unview; is_inside_view |= AngbandSystem::get_instance().is_phase_out(); - is_inside_view |= player_can_see_bold(player_ptr, m_ptr->fy, m_ptr->fx) && projectable(player_ptr, player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx); + const auto m_pos = m_ptr->get_position(); + is_inside_view |= player_can_see_bold(player_ptr, m_ptr->fy, m_ptr->fx) && projectable(player_ptr, player_ptr->get_position(), m_pos); return m_ptr->ml && is_inside_view; } diff --git a/src/grid/trap.cpp b/src/grid/trap.cpp index 194a31764f..63ca397235 100644 --- a/src/grid/trap.cpp +++ b/src/grid/trap.cpp @@ -574,23 +574,21 @@ void hit_trap(PlayerType *player_ptr, bool break_trap) for (lev = player_ptr->current_floor_ptr->dun_level; lev >= 20; lev -= 1 + lev / 16) { const auto num = levs[std::min(lev / 10, 9)]; for (auto i = 0; i < num; i++) { - POSITION x1 = rand_spread(p_pos.x, 7); - POSITION y1 = rand_spread(p_pos.y, 5); - - if (!in_bounds(player_ptr->current_floor_ptr, y1, x1)) { + const Pos2D pos(rand_spread(p_pos.y, 5), rand_spread(p_pos.x, 7)); + if (!in_bounds(player_ptr->current_floor_ptr, pos.y, pos.x)) { continue; } /* Require line of projection */ - if (!projectable(player_ptr, player_ptr->y, player_ptr->x, y1, x1)) { + if (!projectable(player_ptr, p_pos, pos)) { continue; } - if (auto m_idx = summon_specific(player_ptr, y1, x1, lev, SUMMON_ARMAGE_EVIL, (PM_NO_PET))) { + if (auto m_idx = summon_specific(player_ptr, pos.y, pos.x, lev, SUMMON_ARMAGE_EVIL, (PM_NO_PET))) { evil_idx = *m_idx; } - if (auto m_idx = summon_specific(player_ptr, y1, x1, lev, SUMMON_ARMAGE_GOOD, (PM_NO_PET))) { + if (auto m_idx = summon_specific(player_ptr, pos.y, pos.x, lev, SUMMON_ARMAGE_GOOD, (PM_NO_PET))) { good_idx = *m_idx; } diff --git a/src/melee/melee-spell-flags-checker.cpp b/src/melee/melee-spell-flags-checker.cpp index f4feb857b1..26b942a5a1 100644 --- a/src/melee/melee-spell-flags-checker.cpp +++ b/src/melee/melee-spell-flags-checker.cpp @@ -34,7 +34,7 @@ static void decide_melee_spell_target(PlayerType *player_ptr, melee_spell_type * ms_ptr->target_idx = player_ptr->pet_t_m_idx; ms_ptr->t_ptr = &player_ptr->current_floor_ptr->m_list[ms_ptr->target_idx]; - if ((ms_ptr->m_idx == ms_ptr->target_idx) || !projectable(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx)) { + if ((ms_ptr->m_idx == ms_ptr->target_idx) || !projectable(player_ptr, ms_ptr->m_ptr->get_position(), ms_ptr->t_ptr->get_position())) { ms_ptr->target_idx = 0; } } @@ -59,7 +59,7 @@ static void decide_indirection_melee_spell(PlayerType *player_ptr, melee_spell_t return; } - if (projectable(player_ptr, monster_from.fy, monster_from.fx, monster_to.fy, monster_to.fx)) { + if (projectable(player_ptr, monster_from.get_position(), monster_to.get_position())) { return; } @@ -95,7 +95,7 @@ static bool check_melee_spell_projection(PlayerType *player_ptr, melee_spell_typ const auto &monster_from = *ms_ptr->m_ptr; const auto &monster_to = *ms_ptr->t_ptr; const auto is_enemies = monster_from.is_hostile_to_melee(monster_to); - const auto is_projectable = projectable(player_ptr, monster_from.fy, monster_from.fx, monster_to.fy, monster_to.fx); + const auto is_projectable = projectable(player_ptr, monster_from.get_position(), monster_to.get_position()); if (!monster_to.is_valid() || (ms_ptr->m_idx == ms_ptr->target_idx) || !is_enemies || !is_projectable) { continue; } @@ -159,19 +159,19 @@ static void check_melee_spell_distance(PlayerType *player_ptr, melee_spell_type return; } - auto real_y = ms_ptr->y; - auto real_x = ms_ptr->x; - get_project_point(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, &real_y, &real_x, 0L); - auto should_preserve = !projectable(player_ptr, real_y, real_x, player_ptr->y, player_ptr->x); + const auto p_pos = player_ptr->get_position(); + Pos2D pos_real(ms_ptr->y, ms_ptr->x); + get_project_point(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, &pos_real.y, &pos_real.x, 0L); + auto should_preserve = !projectable(player_ptr, pos_real, p_pos); should_preserve &= ms_ptr->ability_flags.has(MonsterAbilityType::BA_LITE); - should_preserve &= distance(real_y, real_x, player_ptr->y, player_ptr->x) <= 4; - should_preserve &= los(player_ptr, real_y, real_x, player_ptr->y, player_ptr->x); + should_preserve &= distance(pos_real.y, pos_real.x, p_pos.y, p_pos.x) <= 4; + should_preserve &= los(player_ptr, pos_real.y, pos_real.x, p_pos.y, p_pos.x); if (should_preserve) { ms_ptr->ability_flags.reset(MonsterAbilityType::BA_LITE); return; } - int dist = distance(real_y, real_x, player_ptr->y, player_ptr->x); + const auto dist = distance(pos_real.y, pos_real.x, p_pos.y, p_pos.x); if (dist <= 2) { ms_ptr->ability_flags.reset(ball_mask_except_rocket); return; @@ -181,14 +181,14 @@ static void check_melee_spell_distance(PlayerType *player_ptr, melee_spell_type return; } - auto ball_when_powerful_rad4 = { + const auto ball_when_powerful_rad4 = { MonsterAbilityType::BA_ACID, MonsterAbilityType::BA_ELEC, MonsterAbilityType::BA_FIRE, MonsterAbilityType::BA_COLD }; - auto *r_ptr = &ms_ptr->m_ptr->get_monrace(); - if (r_ptr->misc_flags.has(MonsterMiscType::POWERFUL)) { + const auto &monrace = ms_ptr->m_ptr->get_monrace(); + if (monrace.misc_flags.has(MonsterMiscType::POWERFUL)) { ms_ptr->ability_flags.reset(ball_when_powerful_rad4); } @@ -201,10 +201,11 @@ static void check_melee_spell_rocket(PlayerType *player_ptr, melee_spell_type *m return; } - POSITION real_y = ms_ptr->y; - POSITION real_x = ms_ptr->x; - get_project_point(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, &real_y, &real_x, PROJECT_STOP); - if (projectable(player_ptr, real_y, real_x, player_ptr->y, player_ptr->x) && (distance(real_y, real_x, player_ptr->y, player_ptr->x) <= 2)) { + const auto p_pos = player_ptr->get_position(); + const auto m_pos = ms_ptr->m_ptr->get_position(); + Pos2D pos_real(ms_ptr->y, ms_ptr->x); + get_project_point(player_ptr, m_pos.y, m_pos.x, &pos_real.y, &pos_real.x, PROJECT_STOP); + if (projectable(player_ptr, pos_real, p_pos) && (distance(pos_real.y, pos_real.x, p_pos.y, p_pos.x) <= 2)) { ms_ptr->ability_flags.reset(MonsterAbilityType::ROCKET); } } diff --git a/src/mind/mind-force-trainer.cpp b/src/mind/mind-force-trainer.cpp index 7e581e5118..bdeed1765f 100644 --- a/src/mind/mind-force-trainer.cpp +++ b/src/mind/mind-force-trainer.cpp @@ -334,7 +334,7 @@ bool cast_force_spell(PlayerType *player_ptr, MindForceTrainerType spell) const Pos2D pos(target_row, target_col); const auto &grid = player_ptr->current_floor_ptr->get_grid(pos); const auto m_idx = grid.m_idx; - const auto is_projectable = projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col); + const auto is_projectable = projectable(player_ptr, player_ptr->get_position(), pos); if ((m_idx == 0) || !grid.has_los() || !is_projectable) { break; } diff --git a/src/mind/mind-mirror-master.cpp b/src/mind/mind-mirror-master.cpp index bed50c63fb..34ea4d82bf 100644 --- a/src/mind/mind-mirror-master.cpp +++ b/src/mind/mind-mirror-master.cpp @@ -80,6 +80,7 @@ bool binding_field(PlayerType *player_ptr, int dam) const auto max_range = AngbandSystem::get_instance().get_max_range(); const auto &floor = *player_ptr->current_floor_ptr; + const auto p_pos = player_ptr->get_position(); for (auto x = 0; x < floor.width; x++) { for (auto y = 0; y < floor.height; y++) { const Pos2D pos(y, x); @@ -88,8 +89,8 @@ bool binding_field(PlayerType *player_ptr, int dam) continue; } - const auto dist = distance(player_ptr->y, player_ptr->x, pos.y, pos.x); - const auto is_projectable = projectable(player_ptr, player_ptr->y, player_ptr->x, pos.y, pos.x); + const auto dist = distance(p_pos.y, p_pos.x, pos.y, pos.x); + const auto is_projectable = projectable(player_ptr, p_pos, pos); if ((dist == 0) || (dist > max_range) || !grid.has_los() || !is_projectable) { continue; } @@ -149,7 +150,7 @@ bool binding_field(PlayerType *player_ptr, int dam) continue; } - if (floor.has_los(pos) && projectable(player_ptr, player_ptr->y, player_ptr->x, y, x)) { + if (floor.has_los(pos) && projectable(player_ptr, p_pos, pos)) { if (!(player_ptr->effects()->blindness().is_blind()) && panel_contains(y, x)) { print_bolt_pict(player_ptr, y, x, y, x, AttributeType::MANA); move_cursor_relative(y, x); @@ -175,7 +176,7 @@ bool binding_field(PlayerType *player_ptr, int dam) continue; } - if (floor.has_los(pos) && projectable(player_ptr, player_ptr->y, player_ptr->x, y, x)) { + if (floor.has_los(pos) && projectable(player_ptr, p_pos, pos)) { (void)affect_feature(player_ptr, 0, 0, y, x, dam, AttributeType::MANA); } } @@ -196,7 +197,7 @@ bool binding_field(PlayerType *player_ptr, int dam) continue; } - if (floor.has_los(pos) && projectable(player_ptr, player_ptr->y, player_ptr->x, y, x)) { + if (floor.has_los(pos) && projectable(player_ptr, p_pos, pos)) { (void)affect_item(player_ptr, 0, 0, y, x, dam, AttributeType::MANA); } } @@ -217,7 +218,7 @@ bool binding_field(PlayerType *player_ptr, int dam) continue; } - if (floor.has_los(pos) && projectable(player_ptr, player_ptr->y, player_ptr->x, y, x)) { + if (floor.has_los(pos) && projectable(player_ptr, p_pos, pos)) { constexpr auto flags = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP; (void)affect_monster(player_ptr, 0, 0, y, x, dam, AttributeType::MANA, flags, true); } diff --git a/src/monster-floor/monster-direction.cpp b/src/monster-floor/monster-direction.cpp index a1917d787a..b925bec85a 100644 --- a/src/monster-floor/monster-direction.cpp +++ b/src/monster-floor/monster-direction.cpp @@ -23,27 +23,27 @@ /*! * @brief ペットが敵に接近するための方向を決定する * @param player_ptr プレイヤーへの参照ポインタ - * @param m_ptr 移動を試みているモンスターへの参照ポインタ - * @param t_ptr 移動先モンスターへの参照ポインタ + * @param monster_from 移動を試みているモンスターへの参照ポインタ + * @param monster_to 移動先モンスターへの参照ポインタ * @param plus モンスターIDの増減 (1/2 の確率で+1、1/2の確率で-1) * @return ペットがモンスターに近づくならばTRUE */ -static bool decide_pet_approch_direction(PlayerType *player_ptr, MonsterEntity *m_ptr, MonsterEntity *t_ptr) +static bool decide_pet_approch_direction(PlayerType *player_ptr, const MonsterEntity &monster_from, const MonsterEntity &monster_to) { - auto *r_ptr = &m_ptr->get_monrace(); - if (!m_ptr->is_pet()) { + const auto &monrace = monster_from.get_monrace(); + if (!monster_from.is_pet()) { return false; } if (player_ptr->pet_follow_distance < 0) { - if (t_ptr->cdis <= (0 - player_ptr->pet_follow_distance)) { + if (monster_to.cdis <= (0 - player_ptr->pet_follow_distance)) { return true; } - } else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > player_ptr->pet_follow_distance)) { + } else if ((monster_from.cdis < monster_to.cdis) && (monster_to.cdis > player_ptr->pet_follow_distance)) { return true; } - return r_ptr->aaf < t_ptr->cdis; + return monrace.aaf < monster_to.cdis; } /*! @@ -57,44 +57,44 @@ static bool decide_pet_approch_direction(PlayerType *player_ptr, MonsterEntity * */ static void decide_enemy_approch_direction(PlayerType *player_ptr, MONSTER_IDX m_idx, int start, int plus, POSITION *y, POSITION *x) { - auto *floor_ptr = player_ptr->current_floor_ptr; - auto *m_ptr = &floor_ptr->m_list[m_idx]; - auto *r_ptr = &m_ptr->get_monrace(); - for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus) { - MONSTER_IDX dummy = (i % floor_ptr->m_max); + auto &floor = *player_ptr->current_floor_ptr; + const auto &monster_from = floor.m_list[m_idx]; + const auto &monrace = monster_from.get_monrace(); + for (int i = start; ((i < start + floor.m_max) && (i > start - floor.m_max)); i += plus) { + const auto dummy = (i % floor.m_max); if (dummy == 0) { continue; } - MONSTER_IDX t_idx = dummy; - auto *t_ptr = &floor_ptr->m_list[t_idx]; - if (t_ptr == m_ptr) { + const auto t_idx = dummy; + const auto &monster_to = floor.m_list[t_idx]; + if (&monster_to == &monster_from) { continue; } - if (!t_ptr->is_valid()) { + if (!monster_to.is_valid()) { continue; } - if (decide_pet_approch_direction(player_ptr, m_ptr, t_ptr)) { + if (decide_pet_approch_direction(player_ptr, monster_from, monster_to)) { continue; } - if (!m_ptr->is_hostile_to_melee(*t_ptr)) { + if (!monster_from.is_hostile_to_melee(monster_to)) { continue; } - const auto can_pass_wall = r_ptr->feature_flags.has(MonsterFeatureType::PASS_WALL) && (!m_ptr->is_riding() || has_pass_wall(player_ptr)); - const auto can_kill_wall = r_ptr->feature_flags.has(MonsterFeatureType::KILL_WALL) && !m_ptr->is_riding(); + const auto can_pass_wall = monrace.feature_flags.has(MonsterFeatureType::PASS_WALL) && (!monster_from.is_riding() || has_pass_wall(player_ptr)); + const auto can_kill_wall = monrace.feature_flags.has(MonsterFeatureType::KILL_WALL) && !monster_from.is_riding(); if (can_pass_wall || can_kill_wall) { - if (!in_disintegration_range(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) { + if (!in_disintegration_range(&floor, monster_from.fy, monster_from.fx, monster_to.fy, monster_to.fx)) { continue; } } else { - if (!projectable(player_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) { + if (!projectable(player_ptr, monster_from.get_position(), monster_to.get_position())) { continue; } } - *y = t_ptr->fy; - *x = t_ptr->fx; + *y = monster_to.fy; + *x = monster_to.fx; return; } } diff --git a/src/monster-floor/monster-generator.cpp b/src/monster-floor/monster-generator.cpp index 0d564ba55a..4195523b70 100644 --- a/src/monster-floor/monster-generator.cpp +++ b/src/monster-floor/monster-generator.cpp @@ -51,6 +51,7 @@ */ bool mon_scatter(PlayerType *player_ptr, MonraceId r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist) { + const Pos2D pos(y, x); int place_x[MON_SCAT_MAXD]{}; int place_y[MON_SCAT_MAXD]{}; int num[MON_SCAT_MAXD]{}; @@ -65,12 +66,13 @@ bool mon_scatter(PlayerType *player_ptr, MonraceId r_idx, POSITION *yp, POSITION } auto *floor_ptr = player_ptr->current_floor_ptr; - for (POSITION nx = x - max_dist; nx <= x + max_dist; nx++) { - for (POSITION ny = y - max_dist; ny <= y + max_dist; ny++) { + for (auto nx = x - max_dist; nx <= x + max_dist; nx++) { + for (auto ny = y - max_dist; ny <= y + max_dist; ny++) { + const Pos2D pos_neighbor(ny, nx); if (!in_bounds(floor_ptr, ny, nx)) { continue; } - if (!projectable(player_ptr, y, x, ny, nx)) { + if (!projectable(player_ptr, pos, pos_neighbor)) { continue; } if (MonraceList::is_valid(r_idx)) { diff --git a/src/monster-floor/monster-move.cpp b/src/monster-floor/monster-move.cpp index 4b42bfa7e1..4d720f444a 100644 --- a/src/monster-floor/monster-move.cpp +++ b/src/monster-floor/monster-move.cpp @@ -474,7 +474,9 @@ bool process_monster_movement(PlayerType *player_ptr, turn_flags *turn_flags_ptr } const auto &ap_r_ref = monster.get_appearance_monrace(); - const auto is_projectable = projectable(player_ptr, player_ptr->y, player_ptr->x, monster.fy, monster.fx); + const auto p_pos = player_ptr->get_position(); //!< @details 関数が長すぎてプレイヤーの座標が不変であることを保証できない. + const auto m_pos = monster.get_position(); + const auto is_projectable = projectable(player_ptr, p_pos, m_pos); const auto can_see = disturb_near && monster.mflag.has(MonsterTemporaryFlagType::VIEW) && is_projectable; const auto is_high_level = disturb_high && (ap_r_ref.r_tkills > 0) && (ap_r_ref.level >= player_ptr->lev); const auto is_unknown_level = disturb_unknown && (ap_r_ref.r_tkills == 0); @@ -550,6 +552,7 @@ static std::string_view get_speak_filename(const MonsterEntity &monster) */ void process_speak_sound(PlayerType *player_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox, bool aware) { + const Pos2D pos(oy, ox); if (AngbandSystem::get_instance().is_phase_out()) { return; } @@ -566,7 +569,7 @@ void process_speak_sound(PlayerType *player_ptr, MONSTER_IDX m_idx, POSITION oy, const auto can_speak = monster.get_appearance_monrace().speak_flags.any(); constexpr auto chance_speak = 8; - if (!can_speak || !aware || !one_in_(chance_speak) || !floor.has_los({ oy, ox }) || !projectable(player_ptr, oy, ox, player_ptr->y, player_ptr->x)) { + if (!can_speak || !aware || !one_in_(chance_speak) || !floor.has_los({ oy, ox }) || !projectable(player_ptr, pos, player_ptr->get_position())) { return; } diff --git a/src/monster-floor/monster-runaway.cpp b/src/monster-floor/monster-runaway.cpp index dafd4099cd..24ba2dd88a 100644 --- a/src/monster-floor/monster-runaway.cpp +++ b/src/monster-floor/monster-runaway.cpp @@ -60,8 +60,9 @@ static void escape_monster(PlayerType *player_ptr, turn_flags *turn_flags_ptr, M auto speak = m_ptr->get_monrace().speak_flags.has_any_of(flags); speak &= !is_acting_monster(m_ptr->r_idx); - speak &= player_ptr->current_floor_ptr->has_los({ m_ptr->fy, m_ptr->fx }); - speak &= projectable(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x); + const auto m_pos = m_ptr->get_position(); + speak &= player_ptr->current_floor_ptr->has_los(m_pos); + speak &= projectable(player_ptr, m_pos, player_ptr->get_position()); if (speak) { msg_format(_("%s^「ピンチだ!退却させてもらう!」", "%s^ says 'It is the pinch! I will retreat'."), m_name); } diff --git a/src/monster-floor/monster-safety-hiding.cpp b/src/monster-floor/monster-safety-hiding.cpp index 11aeae523a..c211182d2e 100644 --- a/src/monster-floor/monster-safety-hiding.cpp +++ b/src/monster-floor/monster-safety-hiding.cpp @@ -32,45 +32,45 @@ static coordinate_candidate sweep_safe_coordinate(PlayerType *player_ptr, MONSTER_IDX m_idx, const POSITION *y_offsets, const POSITION *x_offsets, int d) { coordinate_candidate candidate; - auto *floor_ptr = player_ptr->current_floor_ptr; - auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx]; - for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0]; dx != 0 || dy != 0; i++, dx = x_offsets[i], dy = y_offsets[i]) { - POSITION y = m_ptr->fy + dy; - POSITION x = m_ptr->fx + dx; - if (!in_bounds(floor_ptr, y, x)) { + const auto &floor = *player_ptr->current_floor_ptr; + const auto &monster = player_ptr->current_floor_ptr->m_list[m_idx]; + const auto p_pos = player_ptr->get_position(); + const auto m_pos = monster.get_position(); + for (auto i = 0, dx = x_offsets[0], dy = y_offsets[0]; dx != 0 || dy != 0; i++, dx = x_offsets[i], dy = y_offsets[i]) { + const Pos2DVec vec(dy, dx); + const auto pos = m_pos + vec; + if (!in_bounds(&floor, pos.y, pos.x)) { continue; } - auto *r_ptr = &m_ptr->get_monrace(); - Grid *g_ptr; - g_ptr = &floor_ptr->grid_array[y][x]; - - BIT_FLAGS16 riding_mode = m_ptr->is_riding() ? CEM_RIDING : 0; - if (!monster_can_cross_terrain(player_ptr, g_ptr->feat, r_ptr, riding_mode)) { + const auto &monrace = monster.get_monrace(); + const auto &grid = floor.get_grid(pos); + BIT_FLAGS16 riding_mode = monster.is_riding() ? CEM_RIDING : 0; + if (!monster_can_cross_terrain(player_ptr, grid.feat, &monrace, riding_mode)) { continue; } - if (m_ptr->mflag2.has_not(MonsterConstantFlagType::NOFLOW)) { - const auto dist = g_ptr->get_distance(r_ptr->get_grid_flow_type()); + if (monster.mflag2.has_not(MonsterConstantFlagType::NOFLOW)) { + const auto dist = grid.get_distance(monrace.get_grid_flow_type()); if (dist == 0) { continue; } - if (dist > floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].get_distance(r_ptr->get_grid_flow_type()) + 2 * d) { + if (dist > floor.get_grid(m_pos).get_distance(monrace.get_grid_flow_type()) + 2 * d) { continue; } } - if (projectable(player_ptr, player_ptr->y, player_ptr->x, y, x)) { + if (projectable(player_ptr, p_pos, pos)) { continue; } - POSITION dis = distance(y, x, player_ptr->y, player_ptr->x); + POSITION dis = distance(pos.y, pos.x, p_pos.y, p_pos.x); if (dis <= candidate.gdis) { continue; } - candidate.gy = y; - candidate.gx = x; + candidate.gy = pos.y; + candidate.gx = pos.x; candidate.gdis = dis; } @@ -132,24 +132,26 @@ bool find_safety(PlayerType *player_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITI static void sweep_hiding_candidate( PlayerType *player_ptr, MonsterEntity *m_ptr, const POSITION *y_offsets, const POSITION *x_offsets, coordinate_candidate *candidate) { - auto *r_ptr = &m_ptr->get_monrace(); + const auto &monrace = m_ptr->get_monrace(); + const auto p_pos = player_ptr->get_position(); + const auto m_pos = m_ptr->get_position(); for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0]; dx != 0 || dy != 0; i++, dx = x_offsets[i], dy = y_offsets[i]) { - POSITION y = m_ptr->fy + dy; - POSITION x = m_ptr->fx + dx; - if (!in_bounds(player_ptr->current_floor_ptr, y, x)) { + const Pos2DVec vec(dy, dx); + const auto pos = m_pos + vec; + if (!in_bounds(player_ptr->current_floor_ptr, pos.y, pos.x)) { continue; } - if (!monster_can_enter(player_ptr, y, x, r_ptr, 0)) { + if (!monster_can_enter(player_ptr, pos.y, pos.x, &monrace, 0)) { continue; } - if (projectable(player_ptr, player_ptr->y, player_ptr->x, y, x) || !clean_shot(player_ptr, m_ptr->fy, m_ptr->fx, y, x, false)) { + if (projectable(player_ptr, p_pos, pos) || !clean_shot(player_ptr, m_ptr->fy, m_ptr->fx, pos.y, pos.x, false)) { continue; } - POSITION dis = distance(y, x, player_ptr->y, player_ptr->x); + POSITION dis = distance(pos.y, pos.x, player_ptr->y, player_ptr->x); if (dis < candidate->gdis && dis >= 2) { - candidate->gy = y; - candidate->gx = x; + candidate->gy = pos.y; + candidate->gx = pos.x; candidate->gdis = dis; } } diff --git a/src/monster-floor/monster-sweep-grid.cpp b/src/monster-floor/monster-sweep-grid.cpp index b46bfcbb05..11cfb9e8e1 100644 --- a/src/monster-floor/monster-sweep-grid.cpp +++ b/src/monster-floor/monster-sweep-grid.cpp @@ -58,15 +58,16 @@ bool MonsterSweepGrid::get_movable_grid() const auto no_flow = monster_from.mflag2.has(MonsterConstantFlagType::NOFLOW) && (floor.get_grid(pos_monster_from).get_cost(monrace.get_grid_flow_type()) > 2); this->can_pass_wall = monrace.feature_flags.has(MonsterFeatureType::PASS_WALL) && (!monster_from.is_riding() || has_pass_wall(this->player_ptr)); if (!this->will_run && monster_from.target_y) { - const auto pos_target = monster_from.get_target_position(); - int t_m_idx = floor.get_grid(pos_target).m_idx; + const auto pos_to = monster_from.get_target_position(); + int t_m_idx = floor.get_grid(pos_to).m_idx; if (t_m_idx > 0) { const auto is_enemies = monster_from.is_hostile_to_melee(floor.m_list[t_m_idx]); - const auto is_los = los(this->player_ptr, monster_from.fy, monster_from.fx, monster_from.target_y, monster_from.target_x); - const auto is_projectable = projectable(this->player_ptr, monster_from.fy, monster_from.fx, monster_from.target_y, monster_from.target_x); + const Pos2D pos_from = monster_from.get_position(); + const auto is_los = los(this->player_ptr, pos_from.y, pos_from.x, pos_to.y, pos_to.x); + const auto is_projectable = projectable(this->player_ptr, pos_from, pos_to); if (is_enemies && is_los && is_projectable) { - y = monster_from.fy - monster_from.target_y; - x = monster_from.fx - monster_from.target_x; + y = pos_from.y - pos_to.y; + x = pos_from.x - pos_to.x; this->done = true; } } @@ -134,43 +135,46 @@ bool MonsterSweepGrid::mon_will_run() void MonsterSweepGrid::check_hiding_grid(POSITION *y, POSITION *x, POSITION *y2, POSITION *x2) { - auto *floor_ptr = this->player_ptr->current_floor_ptr; - auto *m_ptr = &floor_ptr->m_list[this->m_idx]; - auto *r_ptr = &m_ptr->get_monrace(); - if (this->done || this->will_run || !m_ptr->is_hostile() || r_ptr->misc_flags.has_not(MonsterMiscType::HAS_FRIENDS)) { + const auto &floor = *this->player_ptr->current_floor_ptr; + const auto &monster = floor.m_list[this->m_idx]; + const auto &monrace = monster.get_monrace(); + if (this->done || this->will_run || !monster.is_hostile() || monrace.misc_flags.has_not(MonsterMiscType::HAS_FRIENDS)) { return; } - const auto gf = r_ptr->get_grid_flow_type(); - if ((!los(this->player_ptr, m_ptr->fy, m_ptr->fx, this->player_ptr->y, this->player_ptr->x) || !projectable(this->player_ptr, m_ptr->fy, m_ptr->fx, this->player_ptr->y, this->player_ptr->x))) { - if (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].get_distance(gf) >= MAX_PLAYER_SIGHT / 2) { + const auto p_pos = this->player_ptr->get_position(); + const auto m_pos = monster.get_position(); + const auto gf = monrace.get_grid_flow_type(); + const auto distance = floor.get_grid(m_pos).get_distance(gf); + if ((!los(this->player_ptr, m_pos.y, m_pos.x, p_pos.y, p_pos.x) || !projectable(this->player_ptr, m_pos, p_pos))) { + if (distance >= MAX_PLAYER_SIGHT / 2) { return; } } this->search_room_to_run(y, x); - if (this->done || (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].get_distance(gf) >= 3)) { + if (this->done || (distance >= 3)) { return; } for (auto i = 0; i < 8; i++) { - *y2 = this->player_ptr->y + ddy_ddd[(this->m_idx + i) & 7]; - *x2 = this->player_ptr->x + ddx_ddd[(this->m_idx + i) & 7]; - if ((m_ptr->fy == *y2) && (m_ptr->fx == *x2)) { - *y2 = this->player_ptr->y; - *x2 = this->player_ptr->x; + *y2 = p_pos.y + ddy_ddd[(this->m_idx + i) & 7]; + *x2 = p_pos.x + ddx_ddd[(this->m_idx + i) & 7]; + if ((monster.fy == *y2) && (monster.fx == *x2)) { + *y2 = p_pos.y; + *x2 = p_pos.x; break; } - if (!in_bounds2(floor_ptr, *y2, *x2) || !monster_can_enter(this->player_ptr, *y2, *x2, r_ptr, 0)) { + if (!in_bounds2(&floor, *y2, *x2) || !monster_can_enter(this->player_ptr, *y2, *x2, &monrace, 0)) { continue; } break; } - *y = m_ptr->fy - *y2; - *x = m_ptr->fx - *x2; + *y = m_pos.y - *y2; + *x = m_pos.x - *x2; this->done = true; } @@ -257,13 +261,12 @@ void MonsterSweepGrid::sweep_movable_grid(POSITION *yp, POSITION *xp, bool no_fl return; } - auto y1 = monster.fy; - auto x1 = monster.fx; - const Pos2D pos(y1, x1); - const auto &grid = floor.get_grid(pos); + const auto p_pos = this->player_ptr->get_position(); + const auto m_pos = monster.get_position(); + const auto &grid = floor.get_grid(m_pos); const auto gf = monrace.get_grid_flow_type(); - if (grid.has_los() && projectable(this->player_ptr, this->player_ptr->y, this->player_ptr->x, y1, x1)) { - if ((distance(y1, x1, this->player_ptr->y, this->player_ptr->x) == 1) || (monrace.freq_spell > 0) || (grid.get_cost(gf) > 5)) { + if (grid.has_los() && projectable(this->player_ptr, p_pos, m_pos)) { + if ((distance(m_pos.y, m_pos.x, p_pos.y, p_pos.x) == 1) || (monrace.freq_spell > 0) || (grid.get_cost(gf) > 5)) { return; } } @@ -272,7 +275,6 @@ void MonsterSweepGrid::sweep_movable_grid(POSITION *yp, POSITION *xp, bool no_fl if (grid.get_cost(gf)) { this->best = 999; } else if (grid.when) { - const auto p_pos = this->player_ptr->get_position(); if (floor.get_grid(p_pos).when - grid.when > 127) { return; } @@ -283,7 +285,7 @@ void MonsterSweepGrid::sweep_movable_grid(POSITION *yp, POSITION *xp, bool no_fl return; } - this->determine_when_cost(yp, xp, y1, x1, use_scent); + this->determine_when_cost(yp, xp, m_pos.y, m_pos.x, use_scent); } bool MonsterSweepGrid::check_movable_grid(POSITION *yp, POSITION *xp, const bool no_flow) @@ -318,28 +320,27 @@ bool MonsterSweepGrid::check_movable_grid(POSITION *yp, POSITION *xp, const bool */ bool MonsterSweepGrid::sweep_ranged_attack_grid(POSITION *yp, POSITION *xp) { - const auto *floor_ptr = this->player_ptr->current_floor_ptr; - const auto *m_ptr = &floor_ptr->m_list[this->m_idx]; - const auto *r_ptr = &m_ptr->get_monrace(); - const auto y1 = m_ptr->fy; - const auto x1 = m_ptr->fx; - if (projectable(this->player_ptr, y1, x1, this->player_ptr->y, this->player_ptr->x)) { + const auto &floor = *this->player_ptr->current_floor_ptr; + const auto &monster = floor.m_list[this->m_idx]; + const auto &monrace = monster.get_monrace(); + const auto m_pos = monster.get_position(); + if (projectable(this->player_ptr, m_pos, this->player_ptr->get_position())) { return false; } - const auto gf = r_ptr->get_grid_flow_type(); - int now_cost = floor_ptr->grid_array[y1][x1].get_cost(gf); + const auto gf = monrace.get_grid_flow_type(); + int now_cost = floor.grid_array[m_pos.y][m_pos.x].get_cost(gf); if (now_cost == 0) { now_cost = 999; } - if (r_ptr->behavior_flags.has_any_of({ MonsterBehaviorType::BASH_DOOR, MonsterBehaviorType::OPEN_DOOR })) { + if (monrace.behavior_flags.has_any_of({ MonsterBehaviorType::BASH_DOOR, MonsterBehaviorType::OPEN_DOOR })) { this->can_open_door = true; } for (auto i = 7; i >= 0; i--) { - const Pos2D pos(y1 + ddy_ddd[i], x1 + ddx_ddd[i]); - if (!in_bounds2(floor_ptr, pos.y, pos.x)) { + const Pos2D pos(m_pos.y + ddy_ddd[i], m_pos.x + ddx_ddd[i]); + if (!in_bounds2(&floor, pos.y, pos.x)) { continue; } @@ -347,24 +348,24 @@ bool MonsterSweepGrid::sweep_ranged_attack_grid(POSITION *yp, POSITION *xp) return false; } - const auto &grid = floor_ptr->get_grid(pos); + const auto &grid = floor.get_grid(pos); this->cost = grid.get_cost(gf); - if (!this->is_best_cost(pos.y, pos.x, now_cost)) { + if (!this->is_best_cost(pos, now_cost)) { continue; } this->best = this->cost; - *yp = y1 + ddy_ddd[i]; - *xp = x1 + ddx_ddd[i]; + *yp = m_pos.y + ddy_ddd[i]; + *xp = m_pos.x + ddx_ddd[i]; } return this->best != 999; } -bool MonsterSweepGrid::is_best_cost(const POSITION y, const POSITION x, const int now_cost) +bool MonsterSweepGrid::is_best_cost(const Pos2D &pos, const int now_cost) { - auto *floor_ptr = this->player_ptr->current_floor_ptr; - const auto &monster = floor_ptr->m_list[this->m_idx]; + const auto &floor = *this->player_ptr->current_floor_ptr; + const auto &monster = floor.m_list[this->m_idx]; const auto &monrace = monster.get_monrace(); auto is_riding = monster.is_riding(); if ((monrace.feature_flags.has_not(MonsterFeatureType::PASS_WALL) || (is_riding && !has_pass_wall(this->player_ptr))) && (monrace.feature_flags.has_not(MonsterFeatureType::KILL_WALL) || is_riding)) { @@ -372,8 +373,8 @@ bool MonsterSweepGrid::is_best_cost(const POSITION y, const POSITION x, const in return false; } - auto *g_ptr = &floor_ptr->grid_array[y][x]; - if (!this->can_open_door && is_closed_door(this->player_ptr, g_ptr->feat)) { + const auto &grid = floor.get_grid(pos); + if (!this->can_open_door && is_closed_door(this->player_ptr, grid.feat)) { return false; } } @@ -386,7 +387,7 @@ bool MonsterSweepGrid::is_best_cost(const POSITION y, const POSITION x, const in return false; } - if (!projectable(this->player_ptr, y, x, this->player_ptr->y, this->player_ptr->x)) { + if (!projectable(this->player_ptr, pos, this->player_ptr->get_position())) { return false; } diff --git a/src/monster-floor/monster-sweep-grid.h b/src/monster-floor/monster-sweep-grid.h index bb5065536b..045fb43b78 100644 --- a/src/monster-floor/monster-sweep-grid.h +++ b/src/monster-floor/monster-sweep-grid.h @@ -1,6 +1,7 @@ #pragma once #include "system/angband.h" +#include "util/point-2d.h" class PlayerType; class MonsterSweepGrid { @@ -28,5 +29,5 @@ class MonsterSweepGrid { void search_room_to_run(POSITION *y, POSITION *x); void search_pet_runnable_grid(POSITION *y, POSITION *x, bool no_flow); void determine_when_cost(POSITION *yp, POSITION *xp, POSITION y1, POSITION x1, const bool use_scent); - bool is_best_cost(const POSITION y, const POSITION x, const int now_cost); + bool is_best_cost(const Pos2D &pos, const int now_cost); }; diff --git a/src/monster/monster-processor.cpp b/src/monster/monster-processor.cpp index ee42c95570..fc26ac6c09 100644 --- a/src/monster/monster-processor.cpp +++ b/src/monster/monster-processor.cpp @@ -533,25 +533,26 @@ bool decide_monster_multiplication(PlayerType *player_ptr, MONSTER_IDX m_idx, PO */ bool cast_spell(PlayerType *player_ptr, MONSTER_IDX m_idx, bool aware) { - auto &floor = *player_ptr->current_floor_ptr; + const auto &floor = *player_ptr->current_floor_ptr; const auto &monster_from = floor.m_list[m_idx]; const auto &monrace = monster_from.get_monrace(); if ((monrace.freq_spell == 0) || (randint1(100) > monrace.freq_spell)) { return false; } - bool counterattack = false; + auto counter_attack = false; if (monster_from.target_y) { - Pos2D pos(monster_from.target_y, monster_from.target_x); - const auto t_m_idx = floor.get_grid(pos).m_idx; + const auto pos_to = monster_from.get_target_position(); + const auto t_m_idx = floor.get_grid(pos_to).m_idx; const auto &monster_to = floor.m_list[t_m_idx]; - const auto is_projectable = projectable(player_ptr, monster_from.fy, monster_from.fx, monster_from.target_y, monster_from.target_x); + const auto pos_from = monster_from.get_position(); + const auto is_projectable = projectable(player_ptr, pos_from, pos_to); if (t_m_idx && monster_from.is_hostile_to_melee(monster_to) && is_projectable) { - counterattack = true; + counter_attack = true; } } - if (counterattack) { + if (counter_attack) { if (monst_spell_monst(player_ptr, m_idx) || (aware && make_attack_spell(player_ptr, m_idx))) { return true; } diff --git a/src/monster/monster-status-setter.cpp b/src/monster/monster-status-setter.cpp index 5f1a5afe6e..b6f05006b7 100644 --- a/src/monster/monster-status-setter.cpp +++ b/src/monster/monster-status-setter.cpp @@ -340,16 +340,16 @@ bool set_monster_invulner(PlayerType *player_ptr, MONSTER_IDX m_idx, int v, bool bool set_monster_timewalk(PlayerType *player_ptr, MONSTER_IDX m_idx, int num, bool vs_player) { auto &floor = *player_ptr->current_floor_ptr; - auto *m_ptr = &floor.m_list[m_idx]; + auto &monster = floor.m_list[m_idx]; auto &world = AngbandWorld::get_instance(); if (world.timewalk_m_idx) { return false; } if (vs_player) { - const auto m_name = monster_desc(player_ptr, m_ptr, 0); + const auto m_name = monster_desc(player_ptr, &monster, 0); std::string mes; - switch (m_ptr->r_idx) { + switch (monster.r_idx) { case MonraceId::DIO: mes = _("「『ザ・ワールド』! 時は止まった!」", format("%s yells 'The World! Time has stopped!'", m_name.data())); break; @@ -374,12 +374,12 @@ bool set_monster_timewalk(PlayerType *player_ptr, MONSTER_IDX m_idx, int num, bo } while (num--) { - if (!m_ptr->is_valid()) { + if (!monster.is_valid()) { break; } process_monster(player_ptr, world.timewalk_m_idx); - m_ptr->reset_target(); + monster.reset_target(); handle_stuff(player_ptr); if (vs_player) { term_xtra(TERM_XTRA_DELAY, 500); @@ -395,11 +395,12 @@ bool set_monster_timewalk(PlayerType *player_ptr, MONSTER_IDX m_idx, int num, bo }; rfu.set_flags(flags); world.timewalk_m_idx = 0; - auto should_output_message = floor.has_los({ m_ptr->fy, m_ptr->fx }); - should_output_message &= projectable(player_ptr, player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx); + const auto m_pos = monster.get_position(); + auto should_output_message = floor.has_los(m_pos); + should_output_message &= projectable(player_ptr, player_ptr->get_position(), m_pos); if (vs_player || should_output_message) { std::string mes; - switch (m_ptr->r_idx) { + switch (monster.r_idx) { case MonraceId::DIAVOLO: mes = _("これが我が『キング・クリムゾン』の能力! 『時間を消し去って』飛び越えさせた…!!", "This is the ability of my 'King Crimson'! 'Erase the time' and let it jump over... !!"); diff --git a/src/monster/monster-update.cpp b/src/monster/monster-update.cpp index 631d61cdc4..68c7074501 100644 --- a/src/monster/monster-update.cpp +++ b/src/monster/monster-update.cpp @@ -475,37 +475,39 @@ static void decide_sight_invisible_monster(PlayerType *player_ptr, um_type *um_p */ static void update_invisible_monster(PlayerType *player_ptr, um_type *um_ptr, MONSTER_IDX m_idx) { - auto *m_ptr = um_ptr->m_ptr; - if (m_ptr->ml) { + auto &monster = *um_ptr->m_ptr; + if (monster.ml) { return; } - m_ptr->ml = true; + monster.ml = true; lite_spot(player_ptr, um_ptr->fy, um_ptr->fx); HealthBarTracker::get_instance().set_flag_if_tracking(m_idx); - if (m_ptr->is_riding()) { + if (monster.is_riding()) { RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::UHEALTH); } if (!player_ptr->effects()->hallucination().is_hallucinated()) { - auto *r_ptr = &m_ptr->get_monrace(); - if ((m_ptr->ap_r_idx == MonraceId::KAGE) && (monraces_info[MonraceId::KAGE].r_sights < MAX_SHORT)) { + auto *r_ptr = &monster.get_monrace(); + if ((monster.ap_r_idx == MonraceId::KAGE) && (monraces_info[MonraceId::KAGE].r_sights < MAX_SHORT)) { monraces_info[MonraceId::KAGE].r_sights++; - } else if (m_ptr->is_original_ap() && (r_ptr->r_sights < MAX_SHORT)) { + } else if (monster.is_original_ap() && (r_ptr->r_sights < MAX_SHORT)) { r_ptr->r_sights++; } } const auto &world = AngbandWorld::get_instance(); - if (world.is_loading_now && world.character_dungeon && !AngbandSystem::get_instance().is_phase_out() && m_ptr->get_appearance_monrace().misc_flags.has(MonsterMiscType::ELDRITCH_HORROR)) { - m_ptr->mflag.set(MonsterTemporaryFlagType::SANITY_BLAST); + if (world.is_loading_now && world.character_dungeon && !AngbandSystem::get_instance().is_phase_out() && monster.get_appearance_monrace().misc_flags.has(MonsterMiscType::ELDRITCH_HORROR)) { + monster.mflag.set(MonsterTemporaryFlagType::SANITY_BLAST); } - const auto projectable_from_monster = projectable(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x); - const auto projectable_from_player = projectable(player_ptr, player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx); + const auto p_pos = player_ptr->get_position(); + const auto m_pos = monster.get_position(); + const auto projectable_from_monster = projectable(player_ptr, m_pos, p_pos); + const auto projectable_from_player = projectable(player_ptr, p_pos, m_pos); if (disturb_near && projectable_from_monster && projectable_from_player) { - if (disturb_pets || m_ptr->is_hostile()) { + if (disturb_pets || monster.is_hostile()) { disturb(player_ptr, true, true); } } diff --git a/src/mspell/mspell-checker.cpp b/src/mspell/mspell-checker.cpp index 18da129786..df39767883 100644 --- a/src/mspell/mspell-checker.cpp +++ b/src/mspell/mspell-checker.cpp @@ -65,10 +65,12 @@ */ bool summon_possible(PlayerType *player_ptr, POSITION y1, POSITION x1) { - auto *floor_ptr = player_ptr->current_floor_ptr; - for (POSITION y = y1 - 2; y <= y1 + 2; y++) { - for (POSITION x = x1 - 2; x <= x1 + 2; x++) { - if (!in_bounds(floor_ptr, y, x)) { + const auto &floor = *player_ptr->current_floor_ptr; + const Pos2D pos1(y1, x1); + for (auto y = y1 - 2; y <= y1 + 2; y++) { + for (auto x = x1 - 2; x <= x1 + 2; x++) { + const Pos2D pos(y, x); + if (!in_bounds(&floor, y, x)) { continue; } @@ -76,11 +78,11 @@ bool summon_possible(PlayerType *player_ptr, POSITION y1, POSITION x1) continue; } - if (pattern_tile(floor_ptr, y, x)) { + if (pattern_tile(&floor, y, x)) { continue; } - if (is_cave_empty_bold(player_ptr, y, x) && projectable(player_ptr, y1, x1, y, x) && projectable(player_ptr, y, x, y1, x1)) { + if (is_cave_empty_bold(player_ptr, y, x) && projectable(player_ptr, pos1, pos) && projectable(player_ptr, pos, pos1)) { return true; } } @@ -98,25 +100,24 @@ bool summon_possible(PlayerType *player_ptr, POSITION y1, POSITION x1) */ bool raise_possible(PlayerType *player_ptr, MonsterEntity *m_ptr) { - POSITION y = m_ptr->fy; - POSITION x = m_ptr->fx; - auto *floor_ptr = player_ptr->current_floor_ptr; - for (POSITION xx = x - 5; xx <= x + 5; xx++) { - Grid *g_ptr; - for (POSITION yy = y - 5; yy <= y + 5; yy++) { - if (distance(y, x, yy, xx) > 5) { + const auto m_pos = m_ptr->get_position(); + const auto &floor = *player_ptr->current_floor_ptr; + for (auto xx = m_pos.x - 5; xx <= m_pos.x + 5; xx++) { + for (auto yy = m_pos.y - 5; yy <= m_pos.y + 5; yy++) { + const Pos2D pos(yy, xx); + if (distance(m_pos.y, m_pos.x, yy, xx) > 5) { continue; } - if (!los(player_ptr, y, x, yy, xx)) { + if (!los(player_ptr, m_pos.y, m_pos.x, yy, xx)) { continue; } - if (!projectable(player_ptr, y, x, yy, xx)) { + if (!projectable(player_ptr, m_pos, pos)) { continue; } - g_ptr = &floor_ptr->grid_array[yy][xx]; - for (const auto this_o_idx : g_ptr->o_idx_list) { - const auto &item = floor_ptr->o_list[this_o_idx]; + const auto &grid = floor.get_grid(pos); + for (const auto this_o_idx : grid.o_idx_list) { + const auto &item = floor.o_list[this_o_idx]; if (item.bi_key.tval() == ItemKindType::MONSTER_REMAINS) { const auto &monrace = item.get_monrace(); if (!monster_has_hostile_align(player_ptr, m_ptr, 0, 0, &monrace)) { diff --git a/src/mspell/mspell-judgement.cpp b/src/mspell/mspell-judgement.cpp index e322f46ff8..ba14711c35 100644 --- a/src/mspell/mspell-judgement.cpp +++ b/src/mspell/mspell-judgement.cpp @@ -90,6 +90,8 @@ bool direct_beam(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, */ bool breath_direct(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, POSITION rad, AttributeType typ, bool is_friend) { + const Pos2D pos_source(y1, x1); + const Pos2D pos_target(y2, x2); BIT_FLAGS flg; switch (typ) { case AttributeType::LITE: @@ -104,21 +106,22 @@ bool breath_direct(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2 break; } - ProjectionPath grid_g(player_ptr, AngbandSystem::get_instance().get_max_range(), { y1, x1 }, { y2, x2 }, flg); + auto &floor = *player_ptr->current_floor_ptr; + ProjectionPath grid_g(player_ptr, AngbandSystem::get_instance().get_max_range(), pos_source, pos_target, flg); auto path_n = 0; POSITION y = y1; POSITION x = x1; for (const auto &[ny, nx] : grid_g) { if (flg & PROJECT_DISI) { - if (cave_stop_disintegration(player_ptr->current_floor_ptr, ny, nx)) { + if (cave_stop_disintegration(&floor, ny, nx)) { break; } } else if (flg & PROJECT_LOS) { - if (!cave_los_bold(player_ptr->current_floor_ptr, ny, nx)) { + if (!cave_los_bold(&floor, ny, nx)) { break; } } else { - if (!cave_has_flag_bold(player_ptr->current_floor_ptr, ny, nx, TerrainCharacteristics::PROJECT)) { + if (!cave_has_flag_bold(&floor, ny, nx, TerrainCharacteristics::PROJECT)) { break; } } @@ -131,25 +134,26 @@ bool breath_direct(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2 bool hit2 = false; bool hityou = false; if (path_n == 0) { + const auto p_pos = player_ptr->get_position(); if (flg & PROJECT_DISI) { - if (in_disintegration_range(player_ptr->current_floor_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) { + if (in_disintegration_range(&floor, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) { hit2 = true; } - if (in_disintegration_range(player_ptr->current_floor_ptr, y1, x1, player_ptr->y, player_ptr->x) && (distance(y1, x1, player_ptr->y, player_ptr->x) <= rad)) { + if (in_disintegration_range(&floor, y1, x1, p_pos.y, p_pos.x) && (distance(y1, x1, p_pos.y, p_pos.x) <= rad)) { hityou = true; } } else if (flg & PROJECT_LOS) { if (los(player_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) { hit2 = true; } - if (los(player_ptr, y1, x1, player_ptr->y, player_ptr->x) && (distance(y1, x1, player_ptr->y, player_ptr->x) <= rad)) { + if (los(player_ptr, y1, x1, p_pos.y, p_pos.x) && (distance(y1, x1, p_pos.y, p_pos.x) <= rad)) { hityou = true; } } else { - if (projectable(player_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) { + if (projectable(player_ptr, pos_source, pos_target) && (distance(y1, x1, y2, x2) <= rad)) { hit2 = true; } - if (projectable(player_ptr, y1, x1, player_ptr->y, player_ptr->x) && (distance(y1, x1, player_ptr->y, player_ptr->x) <= rad)) { + if (projectable(player_ptr, pos_source, p_pos) && (distance(y1, x1, p_pos.y, p_pos.x) <= rad)) { hityou = true; } } diff --git a/src/mspell/mspell-lite.cpp b/src/mspell/mspell-lite.cpp index 78c8a5f52e..631676f808 100644 --- a/src/mspell/mspell-lite.cpp +++ b/src/mspell/mspell-lite.cpp @@ -38,6 +38,7 @@ */ bool adjacent_grid_check(PlayerType *player_ptr, MonsterEntity *m_ptr, POSITION *yp, POSITION *xp, TerrainCharacteristics f_flag, PathChecker checker) { + const Pos2D pos(*yp, *xp); 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 } }; @@ -53,29 +54,28 @@ bool adjacent_grid_check(PlayerType *player_ptr, MonsterEntity *m_ptr, POSITION } for (int i = 0; i < 8; i++) { - int next_x = *xp + tonari_x[next][i]; - int next_y = *yp + tonari_y[next][i]; - Grid *g_ptr; - g_ptr = &player_ptr->current_floor_ptr->grid_array[next_y][next_x]; - if (!g_ptr->cave_has_flag(f_flag)) { + const Pos2DVec vec(tonari_y[next][i], tonari_x[next][i]); + const auto pos_next = pos + vec; + const auto &grid = player_ptr->current_floor_ptr->get_grid(pos_next); + if (!grid.cave_has_flag(f_flag)) { continue; } bool check_result; switch (checker) { case PathChecker::PROJECTION: - check_result = projectable(player_ptr, m_ptr->fy, m_ptr->fx, next_y, next_x); + check_result = projectable(player_ptr, m_ptr->get_position(), pos_next); break; case PathChecker::LOS: - check_result = los(player_ptr, m_ptr->fy, m_ptr->fx, next_y, next_x); + check_result = los(player_ptr, m_ptr->fy, m_ptr->fx, pos_next.y, pos_next.x); break; default: THROW_EXCEPTION(std::logic_error, format("Invalid PathChecker is specified! %d", enum2i(checker))); } if (check_result) { - *yp = next_y; - *xp = next_x; + *yp = pos_next.y; + *xp = pos_next.x; return true; } } @@ -133,7 +133,7 @@ static void check_lite_area_by_mspell(PlayerType *player_ptr, msa_type *msa_ptr) auto light_by_disintegration = msa_ptr->ability_flags.has(MonsterAbilityType::BR_DISI); light_by_disintegration &= msa_ptr->m_ptr->cdis < system.get_max_range() / 2; light_by_disintegration &= in_disintegration_range(player_ptr->current_floor_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x); - light_by_disintegration &= one_in_(10) || (projectable(player_ptr, msa_ptr->y, msa_ptr->x, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx) && one_in_(2)); + light_by_disintegration &= one_in_(10) || (projectable(player_ptr, msa_ptr->get_position(), msa_ptr->m_ptr->get_position()) && one_in_(2)); if (light_by_disintegration) { msa_ptr->do_spell = DO_SPELL_BR_DISI; msa_ptr->success = true; @@ -197,7 +197,7 @@ static void decide_lite_breath(msa_type *msa_ptr) bool decide_lite_projection(PlayerType *player_ptr, msa_type *msa_ptr) { - if (projectable(player_ptr, msa_ptr->m_ptr->fy, msa_ptr->m_ptr->fx, msa_ptr->y, msa_ptr->x)) { + if (projectable(player_ptr, msa_ptr->m_ptr->get_position(), msa_ptr->get_position())) { feature_projection(*player_ptr->current_floor_ptr, msa_ptr); return true; } diff --git a/src/object-activation/activation-others.cpp b/src/object-activation/activation-others.cpp index 3a17ef7432..a66f100609 100644 --- a/src/object-activation/activation-others.cpp +++ b/src/object-activation/activation-others.cpp @@ -440,7 +440,7 @@ bool activate_dispel_magic(PlayerType *player_ptr) return true; } - if (!floor.has_los(pos) || !projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col)) { + if (!floor.has_los(pos) || !projectable(player_ptr, player_ptr->get_position(), pos)) { return true; } diff --git a/src/object/warning.cpp b/src/object/warning.cpp index 89ae527fda..97c0b0c8d5 100644 --- a/src/object/warning.cpp +++ b/src/object/warning.cpp @@ -348,17 +348,18 @@ static int blow_damcalc(MonsterEntity *m_ptr, PlayerType *player_ptr, const Mons */ bool process_warning(PlayerType *player_ptr, POSITION xx, POSITION yy) { - POSITION mx, my; -#define WARNING_AWARE_RANGE 12 + const Pos2D pos(yy, xx); + constexpr auto warning_aware_range = 12; int dam_max = 0; static int old_damage = 0; auto &floor = *player_ptr->current_floor_ptr; const auto &dungeon = floor.get_dungeon_definition(); - for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++) { - for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++) { + for (auto mx = xx - warning_aware_range; mx < xx + warning_aware_range + 1; mx++) { + for (auto my = yy - warning_aware_range; my < yy + warning_aware_range + 1; my++) { + const Pos2D pos_neighbor(my, mx); int dam_max0 = 0; - if (!in_bounds(&floor, my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE)) { + if (!in_bounds(&floor, my, mx) || (distance(my, mx, yy, xx) > warning_aware_range)) { continue; } @@ -380,7 +381,7 @@ bool process_warning(PlayerType *player_ptr, POSITION xx, POSITION yy) auto *r_ptr = &m_ptr->get_monrace(); /* Monster spells (only powerful ones)*/ - if (projectable(player_ptr, my, mx, yy, xx)) { + if (projectable(player_ptr, pos_neighbor, pos)) { const auto flags = r_ptr->ability_flags; if (dungeon.flags.has_not(DungeonFeatureType::NO_MAGIC)) { diff --git a/src/realm/realm-hissatsu.cpp b/src/realm/realm-hissatsu.cpp index f3729c8556..50572359d8 100644 --- a/src/realm/realm-hissatsu.cpp +++ b/src/realm/realm-hissatsu.cpp @@ -651,14 +651,15 @@ std::optional do_hissatsu_spell(PlayerType *player_ptr, SPELL_IDX s case 27: if (cast) { POSITION y, x; - if (!tgt_pt(player_ptr, &x, &y)) { return std::nullopt; } + const Pos2D pos(y, x); + const auto p_pos = player_ptr->get_position(); const auto is_teleportable = cave_player_teleportable_bold(player_ptr, y, x, TELEPORT_SPONTANEOUS); - const auto dist = distance(y, x, player_ptr->y, player_ptr->x); - if (!is_teleportable || (dist > MAX_PLAYER_SIGHT / 2) || !projectable(player_ptr, player_ptr->y, player_ptr->x, y, x)) { + const auto dist = distance(y, x, p_pos.y, p_pos.x); + if (!is_teleportable || (dist > MAX_PLAYER_SIGHT / 2) || !projectable(player_ptr, p_pos, pos)) { msg_print(_("失敗!", "You cannot move to that place!")); break; } diff --git a/src/spell-kind/spells-fetcher.cpp b/src/spell-kind/spells-fetcher.cpp index 9445f166eb..9d4d147771 100644 --- a/src/spell-kind/spells-fetcher.cpp +++ b/src/spell-kind/spells-fetcher.cpp @@ -72,7 +72,7 @@ void fetch_item(PlayerType *player_ptr, DIRECTION dir, WEIGHT wgt, bool require_ if (!floor.has_los(pos)) { msg_print(_("そこはあなたの視界に入っていません。", "You have no direct line of sight to that location.")); return; - } else if (!projectable(player_ptr, p_pos.y, p_pos.x, ty, tx)) { + } else if (!projectable(player_ptr, p_pos, pos)) { msg_print(_("そこは壁の向こうです。", "You have no direct line of sight to that location.")); return; } @@ -134,7 +134,7 @@ bool fetch_monster(PlayerType *player_ptr) if (!floor.has_los(pos)) { return false; } - if (!projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col)) { + if (!projectable(player_ptr, player_ptr->get_position(), pos)) { return false; } diff --git a/src/spell-kind/spells-sight.cpp b/src/spell-kind/spells-sight.cpp index 1f476d012f..acee635bc1 100644 --- a/src/spell-kind/spells-sight.cpp +++ b/src/spell-kind/spells-sight.cpp @@ -45,15 +45,15 @@ bool project_all_los(PlayerType *player_ptr, AttributeType typ, int dam) { auto &floor = *player_ptr->current_floor_ptr; + const auto p_pos = player_ptr->get_position(); for (short i = 1; i < floor.m_max; i++) { auto &monster = floor.m_list[i]; if (!monster.is_valid()) { continue; } - auto y = monster.fy; - auto x = monster.fx; - if (!floor.has_los({ y, x }) || !projectable(player_ptr, player_ptr->y, player_ptr->x, y, x)) { + const auto m_pos = monster.get_position(); + if (!floor.has_los(m_pos) || !projectable(player_ptr, p_pos, m_pos)) { continue; } @@ -69,10 +69,8 @@ bool project_all_los(PlayerType *player_ptr, AttributeType typ, int dam) } monster.mflag.reset(MonsterTemporaryFlagType::LOS); - auto y = monster.fy; - auto x = monster.fx; - - if (project(player_ptr, 0, 0, y, x, dam, typ, flg).notice) { + const auto m_pos = monster.get_position(); + if (project(player_ptr, 0, 0, m_pos.y, m_pos.x, dam, typ, flg).notice) { obvious = true; } } diff --git a/src/spell-kind/spells-world.cpp b/src/spell-kind/spells-world.cpp index b3e43b9873..d5cdb365e7 100644 --- a/src/spell-kind/spells-world.cpp +++ b/src/spell-kind/spells-world.cpp @@ -232,7 +232,7 @@ bool teleport_level_other(PlayerType *player_ptr) if (!grid.has_los()) { return true; } - if (!projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col)) { + if (!projectable(player_ptr, player_ptr->get_position(), pos)) { return true; } diff --git a/src/spell-realm/spells-chaos.cpp b/src/spell-realm/spells-chaos.cpp index 32274425c4..45c1dca39f 100644 --- a/src/spell-realm/spells-chaos.cpp +++ b/src/spell-realm/spells-chaos.cpp @@ -207,31 +207,29 @@ bool vanish_dungeon(PlayerType *player_ptr) */ void cast_meteor(PlayerType *player_ptr, int dam, POSITION rad) { - int b = 10 + randint1(10); - for (int i = 0; i < b; i++) { - POSITION y = 0, x = 0; + const auto b = 10 + randint1(10); + const auto p_pos = player_ptr->get_position(); + for (auto i = 0; i < b; i++) { + Pos2D pos(0, 0); int count; - for (count = 0; count <= 20; count++) { - int dy, dx, d; - - x = player_ptr->x - 8 + randint0(17); - y = player_ptr->y - 8 + randint0(17); - dx = (player_ptr->x > x) ? (player_ptr->x - x) : (x - player_ptr->x); - dy = (player_ptr->y > y) ? (player_ptr->y - y) : (y - player_ptr->y); - d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1)); + const Pos2DVec vec(randint0(17) - 8, randint0(17) - 8); + pos = p_pos + vec; + const auto dx = std::abs(player_ptr->x - pos.x); + const auto dy = std::abs(player_ptr->y - pos.y); + const auto d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1)); if (d >= 9) { continue; } auto *floor_ptr = player_ptr->current_floor_ptr; - if (!in_bounds(floor_ptr, y, x)) { + if (!in_bounds(floor_ptr, pos.y, pos.x)) { continue; } - const auto is_projectable = projectable(player_ptr, player_ptr->y, player_ptr->x, y, x); - if (!is_projectable || !cave_has_flag_bold(floor_ptr, y, x, TerrainCharacteristics::PROJECT)) { + const auto is_projectable = projectable(player_ptr, p_pos, pos); + if (!is_projectable || !cave_has_flag_bold(floor_ptr, pos.y, pos.x, TerrainCharacteristics::PROJECT)) { continue; } @@ -242,6 +240,6 @@ void cast_meteor(PlayerType *player_ptr, int dam, POSITION rad) continue; } - project(player_ptr, 0, rad, y, x, dam, AttributeType::METEOR, PROJECT_KILL | PROJECT_JUMP | PROJECT_ITEM); + project(player_ptr, 0, rad, pos.y, pos.x, dam, AttributeType::METEOR, PROJECT_KILL | PROJECT_JUMP | PROJECT_ITEM); } } diff --git a/src/spell/range-calc.cpp b/src/spell/range-calc.cpp index 7a092f3aef..856e84bc6d 100644 --- a/src/spell/range-calc.cpp +++ b/src/spell/range-calc.cpp @@ -223,16 +223,18 @@ void breath_shape(PlayerType *player_ptr, const ProjectionPath &path, int dist, } /* Travel from center outward */ + const Pos2D pos_breath(by, bx); for (cdis = 0; cdis <= brad; cdis++) { - for (POSITION y = by - cdis; y <= by + cdis; y++) { - for (POSITION x = bx - cdis; x <= bx + cdis; x++) { - if (!in_bounds(floor_ptr, y, x)) { + for (auto y = pos_breath.y - cdis; y <= pos_breath.y + cdis; y++) { + for (auto x = pos_breath.x - cdis; x <= pos_breath.x + cdis; x++) { + const Pos2D pos(y, x); + if (!in_bounds(floor_ptr, pos.y, pos.x)) { continue; } - if (distance(y1, x1, y, x) != bdis) { + if (distance(y1, x1, pos.y, pos.x) != bdis) { continue; } - if (distance(by, bx, y, x) != cdis) { + if (distance(pos_breath.y, pos_breath.x, pos.y, pos.x) != cdis) { continue; } @@ -240,26 +242,26 @@ void breath_shape(PlayerType *player_ptr, const ProjectionPath &path, int dist, case AttributeType::LITE: case AttributeType::LITE_WEAK: /* Lights are stopped by opaque terrains */ - if (!los(player_ptr, by, bx, y, x)) { + if (!los(player_ptr, pos_breath.y, pos_breath.x, pos.y, pos.x)) { continue; } break; case AttributeType::DISINTEGRATE: /* Disintegration are stopped only by perma-walls */ - if (!in_disintegration_range(floor_ptr, by, bx, y, x)) { + if (!in_disintegration_range(floor_ptr, pos_breath.y, pos_breath.x, pos.y, pos.x)) { continue; } break; default: /* Ball explosions are stopped by walls */ - if (!projectable(player_ptr, by, bx, y, x)) { + if (!projectable(player_ptr, pos_breath, pos)) { continue; } break; } - gy[*pgrids] = y; - gx[*pgrids] = x; + gy[*pgrids] = pos.y; + gx[*pgrids] = pos.x; (*pgrids)++; } } diff --git a/src/spell/spells-summon.cpp b/src/spell/spells-summon.cpp index 2d1c6af026..459b4d2845 100644 --- a/src/spell/spells-summon.cpp +++ b/src/spell/spells-summon.cpp @@ -297,19 +297,22 @@ void mitokohmon(PlayerType *player_ptr) } if (!count) { - for (int i = player_ptr->current_floor_ptr->m_max - 1; i > 0; i--) { - MonsterEntity *m_ptr; - m_ptr = &player_ptr->current_floor_ptr->m_list[i]; - if (!m_ptr->is_valid()) { + const auto &floor = *player_ptr->current_floor_ptr; + const auto p_pos = player_ptr->get_position(); + for (auto i = floor.m_max - 1; i > 0; i--) { + const auto &monster = floor.m_list[i]; + if (!monster.is_valid()) { continue; } - if (!((m_ptr->r_idx == MonraceId::SUKE) || (m_ptr->r_idx == MonraceId::KAKU))) { + if (!((monster.r_idx == MonraceId::SUKE) || (monster.r_idx == MonraceId::KAKU))) { continue; } - if (!los(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x)) { + + const auto m_pos = monster.get_position(); + if (!los(player_ptr, m_pos.y, m_pos.x, p_pos.y, p_pos.x)) { continue; } - if (!projectable(player_ptr, m_ptr->fy, m_ptr->fx, player_ptr->y, player_ptr->x)) { + if (!projectable(player_ptr, m_pos, p_pos)) { continue; } count++; diff --git a/src/target/projection-path-calculator.cpp b/src/target/projection-path-calculator.cpp index 9e4c0b6eae..86a365e7d9 100644 --- a/src/target/projection-path-calculator.cpp +++ b/src/target/projection-path-calculator.cpp @@ -257,17 +257,13 @@ ProjectionPath::ProjectionPath(PlayerType *player_ptr, int range, const Pos2D &p * * This is slightly (but significantly) different from "los(y1,x1,y2,x2)". */ -bool projectable(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2) +bool projectable(PlayerType *player_ptr, const Pos2D &pos1, const Pos2D &pos2) { - ProjectionPath grid_g(player_ptr, (project_length ? project_length : AngbandSystem::get_instance().get_max_range()), { y1, x1 }, { y2, x2 }, 0); + ProjectionPath grid_g(player_ptr, (project_length ? project_length : AngbandSystem::get_instance().get_max_range()), pos1, pos2, 0); if (grid_g.path_num() == 0) { return true; } - const auto &[y, x] = grid_g.back(); - if ((y != y2) || (x != x2)) { - return false; - } - - return true; + const auto &pos = grid_g.back(); + return pos == pos2; } diff --git a/src/target/projection-path-calculator.h b/src/target/projection-path-calculator.h index 0c7103726e..c3bae966ea 100644 --- a/src/target/projection-path-calculator.h +++ b/src/target/projection-path-calculator.h @@ -21,4 +21,4 @@ class ProjectionPath { std::vector position; }; -bool projectable(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2); +bool projectable(PlayerType *player_ptr, const Pos2D &pos1, const Pos2D &pos2); diff --git a/src/target/target-preparation.cpp b/src/target/target-preparation.cpp index 7fa11a31ba..db5d76adfa 100644 --- a/src/target/target-preparation.cpp +++ b/src/target/target-preparation.cpp @@ -40,9 +40,9 @@ */ bool target_able(PlayerType *player_ptr, MONSTER_IDX m_idx) { - auto *floor_ptr = player_ptr->current_floor_ptr; - auto *m_ptr = &floor_ptr->m_list[m_idx]; - if (!m_ptr->is_valid()) { + const auto &floor = *player_ptr->current_floor_ptr; + const auto &monster = floor.m_list[m_idx]; + if (!monster.is_valid()) { return false; } @@ -50,15 +50,15 @@ bool target_able(PlayerType *player_ptr, MONSTER_IDX m_idx) return false; } - if (!m_ptr->ml) { + if (!monster.ml) { return false; } - if (m_ptr->is_riding()) { + if (monster.is_riding()) { return true; } - if (!projectable(player_ptr, player_ptr->y, player_ptr->x, m_ptr->fy, m_ptr->fx)) { + if (!projectable(player_ptr, player_ptr->get_position(), monster.get_position())) { return false; } diff --git a/src/target/target-setter.cpp b/src/target/target-setter.cpp index afaaaabf5f..c435d837a1 100644 --- a/src/target/target-setter.cpp +++ b/src/target/target-setter.cpp @@ -189,7 +189,7 @@ static void describe_projectablity(PlayerType *player_ptr, ts_type *ts_ptr) const auto cheatinfo = format(" X:%d Y:%d LOS:%d LOP:%d", ts_ptr->x, ts_ptr->y, los(player_ptr, player_ptr->y, player_ptr->x, ts_ptr->y, ts_ptr->x), - projectable(player_ptr, player_ptr->y, player_ptr->x, ts_ptr->y, ts_ptr->x)); + projectable(player_ptr, player_ptr->get_position(), { ts_ptr->y, ts_ptr->x })); angband_strcat(ts_ptr->info, cheatinfo, sizeof(ts_ptr->info)); } @@ -430,7 +430,7 @@ static void describe_grid_wizard(PlayerType *player_ptr, ts_type *ts_ptr) constexpr auto fmt = " X:%d Y:%d LOS:%d LOP:%d SPECIAL:%d"; const auto is_los = los(player_ptr, player_ptr->y, player_ptr->x, ts_ptr->y, ts_ptr->x); - const auto is_projectable = projectable(player_ptr, player_ptr->y, player_ptr->x, ts_ptr->y, ts_ptr->x); + const auto is_projectable = projectable(player_ptr, player_ptr->get_position(), { ts_ptr->y, ts_ptr->x }); const auto cheatinfo = format(fmt, ts_ptr->x, ts_ptr->y, is_los, is_projectable, ts_ptr->g_ptr->special); angband_strcat(ts_ptr->info, cheatinfo, sizeof(ts_ptr->info)); } From ffffeb604c4ed97938b9a5e64a4f3c4620afc1c4 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 10 Nov 2024 14:27:26 +0900 Subject: [PATCH 06/15] =?UTF-8?q?[Refactor]=20#4007=20build=5Froom=5Fvault?= =?UTF-8?q?()=20=E3=82=92=E6=95=B4=E5=BD=A2=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/room/rooms-vault.cpp | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/room/rooms-vault.cpp b/src/room/rooms-vault.cpp index 4ed0d0577c..ca9e4c455e 100644 --- a/src/room/rooms-vault.cpp +++ b/src/room/rooms-vault.cpp @@ -167,41 +167,36 @@ static void build_bubble_vault(PlayerType *player_ptr, const Pos2D &pos0, const /* Create a random vault that looks like a collection of overlapping rooms */ static void build_room_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize) { - POSITION x1, x2, y1, y2, xhsize, yhsize; - int i; - /* get offset from center */ - xhsize = xsize / 2; - yhsize = ysize / 2; + const auto xhsize = xsize / 2; + const auto yhsize = ysize / 2; msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("部屋型ランダムVaultを生成しました。", "Room Vault.")); /* fill area so don't get problems with on_defeat_arena_monster levels */ - auto *floor_ptr = player_ptr->current_floor_ptr; - for (x1 = 0; x1 < xsize; x1++) { - POSITION x = x0 - xhsize + x1; - - for (y1 = 0; y1 < ysize; y1++) { - POSITION y = y0 - yhsize + y1; - - place_bold(player_ptr, y, x, GB_EXTRA); - floor_ptr->grid_array[y][x].info &= (~CAVE_ICKY); + auto &floor = *player_ptr->current_floor_ptr; + for (auto x1 = 0; x1 < xsize; x1++) { + const auto x = x0 - xhsize + x1; + for (auto y1 = 0; y1 < ysize; y1++) { + const Pos2D pos(y0 - yhsize + y1, x); + place_bold(player_ptr, pos.y, pos.x, GB_EXTRA); + floor.get_grid(pos).info &= (~CAVE_ICKY); } } /* add ten random rooms */ - for (i = 0; i < 10; i++) { - x1 = randint1(xhsize) * 2 + x0 - xhsize; - x2 = randint1(xhsize) * 2 + x0 - xhsize; - y1 = randint1(yhsize) * 2 + y0 - yhsize; - y2 = randint1(yhsize) * 2 + y0 - yhsize; + for (auto i = 0; i < 10; i++) { + const auto x1 = randint1(xhsize) * 2 + x0 - xhsize; + const auto x2 = randint1(xhsize) * 2 + x0 - xhsize; + const auto y1 = randint1(yhsize) * 2 + y0 - yhsize; + const auto y2 = randint1(yhsize) * 2 + y0 - yhsize; build_room(player_ptr, x1, x2, y1, y2); } /* Add some random doors */ - for (i = 0; i < 500; i++) { - x1 = randint1(xsize - 3) - xhsize + x0 + 1; - y1 = randint1(ysize - 3) - yhsize + y0 + 1; + for (auto i = 0; i < 500; i++) { + const auto x1 = randint1(xsize - 3) - xhsize + x0 + 1; + const auto y1 = randint1(ysize - 3) - yhsize + y0 + 1; add_door(player_ptr, x1, y1); } From 089605f6434b3f32fba04c6a726a50de67d832ca Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:01:53 +0900 Subject: [PATCH 07/15] =?UTF-8?q?[Refactor]=20#4007=20build=5Fcave=5Fvault?= =?UTF-8?q?()=20=E3=82=92=E6=95=B4=E5=BD=A2=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/room/rooms-vault.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/room/rooms-vault.cpp b/src/room/rooms-vault.cpp index ca9e4c455e..3092a38946 100644 --- a/src/room/rooms-vault.cpp +++ b/src/room/rooms-vault.cpp @@ -207,43 +207,40 @@ static void build_room_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, P /* Create a random vault out of a fractal grid */ static void build_cave_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, POSITION xsiz, POSITION ysiz) { - int grd, roug, cutoff; - bool done, light, room; - POSITION xhsize, yhsize, xsize, ysize, x, y; - /* round to make sizes even */ - xhsize = xsiz / 2; - yhsize = ysiz / 2; - xsize = xhsize * 2; - ysize = yhsize * 2; + const auto xhsize = xsiz / 2; + const auto yhsize = ysiz / 2; + const auto xsize = xhsize * 2; + const auto ysize = yhsize * 2; msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("洞穴ランダムVaultを生成しました。", "Cave Vault.")); - light = done = false; - room = true; + auto light = false; + auto done = false; + auto room = true; - auto *floor_ptr = player_ptr->current_floor_ptr; + auto &floor = *player_ptr->current_floor_ptr; while (!done) { /* testing values for these parameters feel free to adjust */ - grd = 1 << randint0(4); + const auto grd = 1 << randint0(4); /* want average of about 16 */ - roug = randint1(8) * randint1(4); + const auto roug = randint1(8) * randint1(4); /* about size/2 */ - cutoff = randint1(xsize / 4) + randint1(ysize / 4) + randint1(xsize / 4) + randint1(ysize / 4); + const auto cutoff = randint1(xsize / 4) + randint1(ysize / 4) + randint1(xsize / 4) + randint1(ysize / 4); /* make it */ - generate_hmap(floor_ptr, y0, x0, xsize, ysize, grd, roug, cutoff); + generate_hmap(&floor, y0, x0, xsize, ysize, grd, roug, cutoff); /* Convert to normal format+ clean up */ done = generate_fracave(player_ptr, y0, x0, xsize, ysize, cutoff, light, room); } /* Set icky flag because is a vault */ - for (x = 0; x <= xsize; x++) { - for (y = 0; y <= ysize; y++) { - floor_ptr->grid_array[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY; + for (auto x = 0; x <= xsize; x++) { + for (auto y = 0; y <= ysize; y++) { + floor.get_grid({ y0 - yhsize + y, x0 - xhsize + x }).info |= CAVE_ICKY; } } From 20a8f7e7fe3006e7711a477b211a8a390d40fc1f Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:18:08 +0900 Subject: [PATCH 08/15] =?UTF-8?q?[Refactor]=20#4007=20coord=5Ftrans()=20?= =?UTF-8?q?=E3=82=92=E6=95=B4=E5=BD=A2=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/room/rooms-vault.cpp | 43 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/room/rooms-vault.cpp b/src/room/rooms-vault.cpp index 3092a38946..b4f8989ea2 100644 --- a/src/room/rooms-vault.cpp +++ b/src/room/rooms-vault.cpp @@ -249,18 +249,14 @@ static void build_cave_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, P } /*! - * @brief Vault地形を回転、上下左右反転するための座標変換を返す / coordinate translation code - * @param x 変換したい点のX座標参照ポインタ - * @param y 変換したい点のY座標参照ポインタ - * @param xoffset Vault生成時の基準X座標 - * @param yoffset Vault生成時の基準Y座標 + * @brief Vault地形を回転、上下左右反転するための座標変換を返す + * @param pos_initial 変換したい点 + * @param offset Vault生成時の座標オフセット * @param transno 処理ID + * @return 回転後の座標 */ -static void coord_trans(POSITION *x, POSITION *y, POSITION xoffset, POSITION yoffset, int transno) +static Pos2D coord_trans(const Pos2D &pos_initial, const Pos2DVec &offset, int transno) { - int i; - int temp; - /* * transno specifies what transformation is required. (0-7) * The lower two bits indicate by how much the vault is rotated, @@ -270,21 +266,22 @@ static void coord_trans(POSITION *x, POSITION *y, POSITION xoffset, POSITION yof * be expressed simply in terms of swapping and inverting the * x and y coordinates. */ - for (i = 0; i < transno % 4; i++) { + Pos2D pos = pos_initial; + for (auto i = 0; i < transno % 4; i++) { /* rotate by 90 degrees */ - temp = *x; - *x = -(*y); - *y = temp; + auto temp = pos.x; + pos.x = -pos.y; + pos.y = temp; } if (transno / 4) { /* Reflect depending on status of 3rd bit. */ - *x = -(*x); + pos.x = -pos.x; } /* Add offsets so vault stays in the first quadrant */ - *x += xoffset; - *y += yoffset; + pos += offset; + return pos; } /*! @@ -315,8 +312,9 @@ static void build_vault( j = dy; /* Flip / rotate */ - coord_trans(&i, &j, xoffset, yoffset, transno); - + const auto pos = coord_trans({ j, i }, { yoffset, xoffset }, transno); + i = pos.x; + j = pos.y; if (transno % 2 == 0) { /* no swap of x/y */ x = xval - (xmax / 2) + i; @@ -514,8 +512,9 @@ static void build_vault( j = dy; /* Flip / rotate */ - coord_trans(&i, &j, xoffset, yoffset, transno); - + const auto pos = coord_trans({ j, i }, { yoffset, xoffset }, transno); + i = pos.x; + j = pos.y; if (transno % 2 == 0) { /* no swap of x/y */ x = xval - (xmax / 2) + i; @@ -1012,7 +1011,9 @@ bool build_fixed_room(PlayerType *player_ptr, dun_data_type *dd_ptr, int typ, bo num_transformation &= ~1; } - coord_trans(&x, &y, 0, 0, num_transformation); + const auto pos = coord_trans({ y, x }, { 0, 0 }, num_transformation); + y = pos.y; + x = pos.x; const auto y_offset = y < 0 ? -y - 1 : 0; const auto x_offset = x < 0 ? -x - 1 : 0; From 779d3067d98e1ae469e8bc57584e0a524009181f Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:32:09 +0900 Subject: [PATCH 09/15] =?UTF-8?q?[Refactor]=20#4007=20build=5Fvault()=20?= =?UTF-8?q?=E3=82=92=E6=95=B4=E5=BD=A2=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/room/rooms-vault.cpp | 137 ++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 67 deletions(-) diff --git a/src/room/rooms-vault.cpp b/src/room/rooms-vault.cpp index b4f8989ea2..65041a7408 100644 --- a/src/room/rooms-vault.cpp +++ b/src/room/rooms-vault.cpp @@ -299,22 +299,21 @@ static Pos2D coord_trans(const Pos2D &pos_initial, const Pos2DVec &offset, int t static void build_vault( PlayerType *player_ptr, POSITION yval, POSITION xval, POSITION ymax, POSITION xmax, concptr data, POSITION xoffset, POSITION yoffset, int transno) { - POSITION dx, dy, x, y, i, j; - concptr t; - Grid *g_ptr; - /* Place dungeon features and objects */ - auto *floor_ptr = player_ptr->current_floor_ptr; - for (t = data, dy = 0; dy < ymax; dy++) { - for (dx = 0; dx < xmax; dx++, t++) { + auto &floor = *player_ptr->current_floor_ptr; + auto t = data; + for (auto dy = 0; dy < ymax; dy++) { + for (auto dx = 0; dx < xmax; dx++, t++) { /* prevent loop counter from being overwritten */ - i = dx; - j = dy; + auto i = dx; + auto j = dy; /* Flip / rotate */ const auto pos = coord_trans({ j, i }, { yoffset, xoffset }, transno); i = pos.x; j = pos.y; + int x; + int y; if (transno % 2 == 0) { /* no swap of x/y */ x = xval - (xmax / 2) + i; @@ -329,44 +328,45 @@ static void build_vault( if (*t == ' ') { continue; } - g_ptr = &floor_ptr->grid_array[y][x]; + + auto &grid = floor.grid_array[y][x]; /* Lay down a floor */ - place_grid(player_ptr, g_ptr, GB_FLOOR); + place_grid(player_ptr, &grid, GB_FLOOR); /* Remove any mimic */ - g_ptr->mimic = 0; + grid.mimic = 0; /* Part of a vault */ - g_ptr->info |= (CAVE_ROOM | CAVE_ICKY); + grid.info |= (CAVE_ROOM | CAVE_ICKY); /* Analyze the grid */ switch (*t) { /* Granite wall (outer) */ case '%': - place_grid(player_ptr, g_ptr, GB_OUTER_NOPERM); + place_grid(player_ptr, &grid, GB_OUTER_NOPERM); break; /* Granite wall (inner) */ case '#': - place_grid(player_ptr, g_ptr, GB_INNER); + place_grid(player_ptr, &grid, GB_INNER); break; /* Glass wall (inner) */ case '$': - place_grid(player_ptr, g_ptr, GB_INNER); - g_ptr->feat = feat_glass_wall; + place_grid(player_ptr, &grid, GB_INNER); + grid.feat = feat_glass_wall; break; /* Permanent wall (inner) */ case 'X': - place_grid(player_ptr, g_ptr, GB_INNER_PERM); + place_grid(player_ptr, &grid, GB_INNER_PERM); break; /* Permanent glass wall (inner) */ case 'Y': - place_grid(player_ptr, g_ptr, GB_INNER_PERM); - g_ptr->feat = feat_permanent_glass_wall; + place_grid(player_ptr, &grid, GB_INNER_PERM); + grid.feat = feat_permanent_glass_wall; break; /* Treasure/trap */ @@ -374,7 +374,7 @@ static void build_vault( if (evaluate_percent(75)) { place_object(player_ptr, y, x, 0L); } else { - place_trap(floor_ptr, y, x); + place_trap(&floor, y, x); } break; @@ -385,7 +385,7 @@ static void build_vault( /* Tree */ case ':': - g_ptr->feat = feat_tree; + grid.feat = feat_tree; break; /* Secret doors */ @@ -396,8 +396,8 @@ static void build_vault( /* Secret glass doors */ case '-': place_secret_door(player_ptr, y, x, DOOR_GLASS_DOOR); - if (is_closed_door(player_ptr, g_ptr->feat)) { - g_ptr->mimic = feat_glass_wall; + if (is_closed_door(player_ptr, grid.feat)) { + grid.mimic = feat_glass_wall; } break; @@ -408,113 +408,116 @@ static void build_vault( /* Trap */ case '^': - place_trap(floor_ptr, y, x); + place_trap(&floor, y, x); break; /* Black market in a dungeon */ case 'S': - set_cave_feat(floor_ptr, y, x, feat_black_market); + set_cave_feat(&floor, y, x, feat_black_market); store_init(VALID_TOWNS, StoreSaleType::BLACK); break; /* The Pattern */ case 'p': - set_cave_feat(floor_ptr, y, x, feat_pattern_start); + set_cave_feat(&floor, y, x, feat_pattern_start); break; case 'a': - set_cave_feat(floor_ptr, y, x, feat_pattern_1); + set_cave_feat(&floor, y, x, feat_pattern_1); break; case 'b': - set_cave_feat(floor_ptr, y, x, feat_pattern_2); + set_cave_feat(&floor, y, x, feat_pattern_2); break; case 'c': - set_cave_feat(floor_ptr, y, x, feat_pattern_3); + set_cave_feat(&floor, y, x, feat_pattern_3); break; case 'd': - set_cave_feat(floor_ptr, y, x, feat_pattern_4); + set_cave_feat(&floor, y, x, feat_pattern_4); break; case 'P': - set_cave_feat(floor_ptr, y, x, feat_pattern_end); + set_cave_feat(&floor, y, x, feat_pattern_end); break; case 'B': - set_cave_feat(floor_ptr, y, x, feat_pattern_exit); + set_cave_feat(&floor, y, x, feat_pattern_exit); break; case 'A': /* Reward for Pattern walk */ - floor_ptr->object_level = floor_ptr->base_level + 12; + floor.object_level = floor.base_level + 12; place_object(player_ptr, y, x, AM_GOOD | AM_GREAT); - floor_ptr->object_level = floor_ptr->base_level; + floor.object_level = floor.base_level; break; case '~': - set_cave_feat(floor_ptr, y, x, feat_shallow_water); + set_cave_feat(&floor, y, x, feat_shallow_water); break; case '=': - set_cave_feat(floor_ptr, y, x, feat_deep_water); + set_cave_feat(&floor, y, x, feat_deep_water); break; case 'v': - set_cave_feat(floor_ptr, y, x, feat_shallow_lava); + set_cave_feat(&floor, y, x, feat_shallow_lava); break; case 'w': - set_cave_feat(floor_ptr, y, x, feat_deep_lava); + set_cave_feat(&floor, y, x, feat_deep_lava); break; case 'f': - set_cave_feat(floor_ptr, y, x, feat_shallow_acid_puddle); + set_cave_feat(&floor, y, x, feat_shallow_acid_puddle); break; case 'F': - set_cave_feat(floor_ptr, y, x, feat_deep_acid_puddle); + set_cave_feat(&floor, y, x, feat_deep_acid_puddle); break; case 'g': - set_cave_feat(floor_ptr, y, x, feat_shallow_poisonous_puddle); + set_cave_feat(&floor, y, x, feat_shallow_poisonous_puddle); break; case 'G': - set_cave_feat(floor_ptr, y, x, feat_deep_poisonous_puddle); + set_cave_feat(&floor, y, x, feat_deep_poisonous_puddle); break; case 'h': - set_cave_feat(floor_ptr, y, x, feat_cold_zone); + set_cave_feat(&floor, y, x, feat_cold_zone); break; case 'H': - set_cave_feat(floor_ptr, y, x, feat_heavy_cold_zone); + set_cave_feat(&floor, y, x, feat_heavy_cold_zone); break; case 'i': - set_cave_feat(floor_ptr, y, x, feat_electrical_zone); + set_cave_feat(&floor, y, x, feat_electrical_zone); break; case 'I': - set_cave_feat(floor_ptr, y, x, feat_heavy_electrical_zone); + set_cave_feat(&floor, y, x, feat_heavy_electrical_zone); break; } } } /* Place dungeon monsters and objects */ - for (t = data, dy = 0; dy < ymax; dy++) { - for (dx = 0; dx < xmax; dx++, t++) { + t = data; + for (auto dy = 0; dy < ymax; dy++) { + for (auto dx = 0; dx < xmax; dx++, t++) { /* prevent loop counter from being overwritten */ - i = dx; - j = dy; + auto i = dx; + auto j = dy; /* Flip / rotate */ const auto pos = coord_trans({ j, i }, { yoffset, xoffset }, transno); i = pos.x; j = pos.y; + int y; + int x; if (transno % 2 == 0) { /* no swap of x/y */ x = xval - (xmax / 2) + i; @@ -533,53 +536,53 @@ static void build_vault( /* Analyze the symbol */ switch (*t) { case '&': { - floor_ptr->monster_level = floor_ptr->base_level + 5; + floor.monster_level = floor.base_level + 5; place_random_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP)); - floor_ptr->monster_level = floor_ptr->base_level; + floor.monster_level = floor.base_level; break; } /* Meaner monster */ case '@': { - floor_ptr->monster_level = floor_ptr->base_level + 11; + floor.monster_level = floor.base_level + 11; place_random_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP)); - floor_ptr->monster_level = floor_ptr->base_level; + floor.monster_level = floor.base_level; break; } /* Meaner monster, plus treasure */ case '9': { - floor_ptr->monster_level = floor_ptr->base_level + 9; + floor.monster_level = floor.base_level + 9; place_random_monster(player_ptr, y, x, PM_ALLOW_SLEEP); - floor_ptr->monster_level = floor_ptr->base_level; - floor_ptr->object_level = floor_ptr->base_level + 7; + floor.monster_level = floor.base_level; + floor.object_level = floor.base_level + 7; place_object(player_ptr, y, x, AM_GOOD); - floor_ptr->object_level = floor_ptr->base_level; + floor.object_level = floor.base_level; break; } /* Nasty monster and treasure */ case '8': { - floor_ptr->monster_level = floor_ptr->base_level + 40; + floor.monster_level = floor.base_level + 40; place_random_monster(player_ptr, y, x, PM_ALLOW_SLEEP); - floor_ptr->monster_level = floor_ptr->base_level; - floor_ptr->object_level = floor_ptr->base_level + 20; + floor.monster_level = floor.base_level; + floor.object_level = floor.base_level + 20; place_object(player_ptr, y, x, AM_GOOD | AM_GREAT); - floor_ptr->object_level = floor_ptr->base_level; + floor.object_level = floor.base_level; break; } /* Monster and/or object */ case ',': { if (one_in_(2)) { - floor_ptr->monster_level = floor_ptr->base_level + 3; + floor.monster_level = floor.base_level + 3; place_random_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP)); - floor_ptr->monster_level = floor_ptr->base_level; + floor.monster_level = floor.base_level; } if (one_in_(2)) { - floor_ptr->object_level = floor_ptr->base_level + 7; + floor.object_level = floor.base_level + 7; place_object(player_ptr, y, x, 0L); - floor_ptr->object_level = floor_ptr->base_level; + floor.object_level = floor.base_level; } break; } From d2633cea576df8b5a86d5d0ac5b0b6570e1b4a66 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:32:57 +0900 Subject: [PATCH 10/15] =?UTF-8?q?[Refactor]=20#4007=20build=5Ftarget=5Fvau?= =?UTF-8?q?lt()=20=E3=82=92=E6=95=B4=E5=BD=A2=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/room/rooms-vault.cpp | 61 +++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/src/room/rooms-vault.cpp b/src/room/rooms-vault.cpp index 65041a7408..85012c6efd 100644 --- a/src/room/rooms-vault.cpp +++ b/src/room/rooms-vault.cpp @@ -598,45 +598,36 @@ static void build_vault( */ static void build_target_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize) { - POSITION rad, x, y; - /* Make a random metric */ - POSITION h1, h2, h3, h4; - h1 = randint1(32) - 16; - h2 = randint1(16); - h3 = randint1(32); - h4 = randint1(32) - 16; + const auto h1 = randint1(32) - 16; + const auto h2 = randint1(16); + const auto h3 = randint1(32); + const auto h4 = randint1(32) - 16; msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("対称形ランダムVaultを生成しました。", "Target Vault")); - /* work out outer radius */ - if (xsize > ysize) { - rad = ysize / 2; - } else { - rad = xsize / 2; - } + const auto rad = xsize > ysize ? ysize / 2 : xsize / 2; /* Make floor */ - auto *floor_ptr = player_ptr->current_floor_ptr; - for (x = x0 - rad; x <= x0 + rad; x++) { - for (y = y0 - rad; y <= y0 + rad; y++) { - /* clear room flag */ - floor_ptr->grid_array[y][x].info &= ~(CAVE_ROOM); - - /* Vault - so is "icky" */ - floor_ptr->grid_array[y][x].info |= CAVE_ICKY; - - if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1) { + auto &floor = *player_ptr->current_floor_ptr; + for (auto x = x0 - rad; x <= x0 + rad; x++) { + for (auto y = y0 - rad; y <= y0 + rad; y++) { + const Pos2D pos(y, x); + auto &grid = floor.get_grid(pos); + grid.info &= ~(CAVE_ROOM); + grid.info |= CAVE_ICKY; + + if (dist2(y0, x0, pos.y, pos.x, h1, h2, h3, h4) <= rad - 1) { /* inside- so is floor */ - place_bold(player_ptr, y, x, GB_FLOOR); + place_bold(player_ptr, pos.y, pos.x, GB_FLOOR); } else { /* make granite outside so on_defeat_arena_monster works */ - place_bold(player_ptr, y, x, GB_EXTRA); + place_bold(player_ptr, pos.y, pos.x, GB_EXTRA); } /* proper boundary for on_defeat_arena_monster */ - if (((y + rad) == y0) || ((y - rad) == y0) || ((x + rad) == x0) || ((x - rad) == x0)) { - place_bold(player_ptr, y, x, GB_EXTRA); + if (((pos.y + rad) == y0) || ((pos.y - rad) == y0) || ((pos.x + rad) == x0) || ((pos.x - rad) == x0)) { + place_bold(player_ptr, pos.y, pos.x, GB_EXTRA); } } } @@ -645,8 +636,8 @@ static void build_target_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, add_outer_wall(player_ptr, x0, y0, false, x0 - rad - 1, y0 - rad - 1, x0 + rad + 1, y0 + rad + 1); /* Add inner wall */ - for (x = x0 - rad / 2; x <= x0 + rad / 2; x++) { - for (y = y0 - rad / 2; y <= y0 + rad / 2; y++) { + for (auto x = x0 - rad / 2; x <= x0 + rad / 2; x++) { + for (auto y = y0 - rad / 2; y <= y0 + rad / 2; y++) { if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2) { /* Make an internal wall */ place_bold(player_ptr, y, x, GB_INNER); @@ -655,20 +646,20 @@ static void build_target_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, } /* Add perpendicular walls */ - for (x = x0 - rad; x <= x0 + rad; x++) { + for (auto x = x0 - rad; x <= x0 + rad; x++) { place_bold(player_ptr, y0, x, GB_INNER); } - for (y = y0 - rad; y <= y0 + rad; y++) { + for (auto y = y0 - rad; y <= y0 + rad; y++) { place_bold(player_ptr, y, x0, GB_INNER); } /* Make inner vault */ - for (y = y0 - 1; y <= y0 + 1; y++) { + for (auto y = y0 - 1; y <= y0 + 1; y++) { place_bold(player_ptr, y, x0 - 1, GB_INNER); place_bold(player_ptr, y, x0 + 1, GB_INNER); } - for (x = x0 - 1; x <= x0 + 1; x++) { + for (auto x = x0 - 1; x <= x0 + 1; x++) { place_bold(player_ptr, y0 - 1, x, GB_INNER); place_bold(player_ptr, y0 + 1, x, GB_INNER); } @@ -677,8 +668,8 @@ static void build_target_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, /* Add doors to vault */ /* get two distances so can place doors relative to centre */ - x = (rad - 2) / 4 + 1; - y = rad / 2 + x; + auto x = (rad - 2) / 4 + 1; + auto y = rad / 2 + x; add_door(player_ptr, x0 + x, y0); add_door(player_ptr, x0 + y, y0); From d1248bf5166277e2bacd15235076819dc653273c Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:34:37 +0900 Subject: [PATCH 11/15] =?UTF-8?q?[Refactor]=20#4007=20build=5Felemental=5F?= =?UTF-8?q?vault()=20=E3=82=92=E6=95=B4=E5=BD=A2=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/room/rooms-vault.cpp | 45 ++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/room/rooms-vault.cpp b/src/room/rooms-vault.cpp index 85012c6efd..e2355ad5e0 100644 --- a/src/room/rooms-vault.cpp +++ b/src/room/rooms-vault.cpp @@ -693,29 +693,23 @@ static void build_target_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, */ static void build_elemental_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, POSITION xsiz, POSITION ysiz) { - int grd, roug; - int c1, c2, c3; - bool done = false; - POSITION xsize, ysize, xhsize, yhsize, x, y; - int i; - int type; - msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("精霊界ランダムVaultを生成しました。", "Elemental Vault")); /* round to make sizes even */ - xhsize = xsiz / 2; - yhsize = ysiz / 2; - xsize = xhsize * 2; - ysize = yhsize * 2; + const auto xhsize = xsiz / 2; + const auto yhsize = ysiz / 2; + const auto xsize = xhsize * 2; + const auto ysize = yhsize * 2; - auto *floor_ptr = player_ptr->current_floor_ptr; - if (floor_ptr->dun_level < 25) { + auto &floor = *player_ptr->current_floor_ptr; + lake_type type; + if (floor.dun_level < 25) { /* Earth vault (Rubble) */ type = LAKE_T_EARTH_VAULT; - } else if (floor_ptr->dun_level < 50) { + } else if (floor.dun_level < 50) { /* Air vault (Trees) */ type = LAKE_T_AIR_VAULT; - } else if (floor_ptr->dun_level < 75) { + } else if (floor.dun_level < 75) { /* Water vault (shallow water) */ type = LAKE_T_WATER_VAULT; } else { @@ -723,39 +717,40 @@ static void build_elemental_vault(PlayerType *player_ptr, POSITION x0, POSITION type = LAKE_T_FIRE_VAULT; } + auto done = false; while (!done) { /* testing values for these parameters: feel free to adjust */ - grd = 1 << (randint0(3)); + const auto grd = 1 << (randint0(3)); /* want average of about 16 */ - roug = randint1(8) * randint1(4); + const auto roug = randint1(8) * randint1(4); /* Make up size of various componants */ /* Floor */ - c3 = 2 * xsize / 3; + const auto c3 = 2 * xsize / 3; /* Deep water/lava */ - c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5; + const auto c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5; /* Shallow boundary */ - c2 = (c1 + c3) / 2; + const auto c2 = (c1 + c3) / 2; /* make it */ - generate_hmap(floor_ptr, y0, x0, xsize, ysize, grd, roug, c3); + generate_hmap(&floor, y0, x0, xsize, ysize, grd, roug, c3); /* Convert to normal format+ clean up */ done = generate_lake(player_ptr, y0, x0, xsize, ysize, c1, c2, c3, type); } /* Set icky flag because is a vault */ - for (x = 0; x <= xsize; x++) { - for (y = 0; y <= ysize; y++) { - floor_ptr->grid_array[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY; + for (auto x = 0; x <= xsize; x++) { + for (auto y = 0; y <= ysize; y++) { + floor.grid_array[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY; } } /* make a few rooms in the vault */ - for (i = 1; i <= (xsize * ysize) / 50; i++) { + for (auto i = 1; i <= (xsize * ysize) / 50; i++) { build_small_room(player_ptr, x0 + randint0(xsize - 4) - xsize / 2 + 2, y0 + randint0(ysize - 4) - ysize / 2 + 2); } From 0fc64944fab60016fe93ea26e6c3f8825f89be76 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:35:06 +0900 Subject: [PATCH 12/15] =?UTF-8?q?[Refactor]=20#4007=20build=5Fmini=5Fc=5Fv?= =?UTF-8?q?ault()=20=E3=82=92=E6=95=B4=E5=BD=A2=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/room/rooms-vault.cpp | 88 +++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/src/room/rooms-vault.cpp b/src/room/rooms-vault.cpp index e2355ad5e0..a4b21a7ba4 100644 --- a/src/room/rooms-vault.cpp +++ b/src/room/rooms-vault.cpp @@ -767,78 +767,72 @@ static void build_elemental_vault(PlayerType *player_ptr, POSITION x0, POSITION */ static void build_mini_c_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize) { - POSITION dy, dx; - POSITION y1, x1, y2, x2, y, x, total; - int m, n, num_vertices; - msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("小型チェッカーランダムVaultを生成しました。", "Mini Checker Board Vault.")); /* Pick a random room size */ - dy = ysize / 2 - 1; - dx = xsize / 2 - 1; - - y1 = y0 - dy; - x1 = x0 - dx; - y2 = y0 + dy; - x2 = x0 + dx; + const auto dy = ysize / 2 - 1; + const auto dx = xsize / 2 - 1; + const auto y1 = y0 - dy; + const auto x1 = x0 - dx; + const auto y2 = y0 + dy; + const auto x2 = x0 + dx; /* generate the room */ - auto *floor_ptr = player_ptr->current_floor_ptr; - for (x = x1 - 2; x <= x2 + 2; x++) { - if (!in_bounds(floor_ptr, y1 - 2, x)) { + auto &floor = *player_ptr->current_floor_ptr; + for (auto x = x1 - 2; x <= x2 + 2; x++) { + const Pos2D pos(y1 - 2, x); + if (!in_bounds(&floor, pos.y, pos.x)) { break; } - floor_ptr->grid_array[y1 - 2][x].info |= (CAVE_ROOM | CAVE_ICKY); - - place_bold(player_ptr, y1 - 2, x, GB_OUTER_NOPERM); + floor.get_grid(pos).info |= (CAVE_ROOM | CAVE_ICKY); + place_bold(player_ptr, pos.y, pos.x, GB_OUTER_NOPERM); } - for (x = x1 - 2; x <= x2 + 2; x++) { - if (!in_bounds(floor_ptr, y2 + 2, x)) { + for (auto x = x1 - 2; x <= x2 + 2; x++) { + const Pos2D pos(y2 + 2, x); + if (!in_bounds(&floor, pos.y, pos.x)) { break; } - floor_ptr->grid_array[y2 + 2][x].info |= (CAVE_ROOM | CAVE_ICKY); - - place_bold(player_ptr, y2 + 2, x, GB_OUTER_NOPERM); + floor.get_grid(pos).info |= (CAVE_ROOM | CAVE_ICKY); + place_bold(player_ptr, pos.y, pos.x, GB_OUTER_NOPERM); } - for (y = y1 - 2; y <= y2 + 2; y++) { - if (!in_bounds(floor_ptr, y, x1 - 2)) { + for (auto y = y1 - 2; y <= y2 + 2; y++) { + const Pos2D pos(y, x1 - 2); + if (!in_bounds(&floor, pos.y, pos.x)) { break; } - floor_ptr->grid_array[y][x1 - 2].info |= (CAVE_ROOM | CAVE_ICKY); - - place_bold(player_ptr, y, x1 - 2, GB_OUTER_NOPERM); + floor.get_grid(pos).info |= (CAVE_ROOM | CAVE_ICKY); + place_bold(player_ptr, pos.y, pos.x, GB_OUTER_NOPERM); } - for (y = y1 - 2; y <= y2 + 2; y++) { - if (!in_bounds(floor_ptr, y, x2 + 2)) { + for (auto y = y1 - 2; y <= y2 + 2; y++) { + if (!in_bounds(&floor, y, x2 + 2)) { break; } - floor_ptr->grid_array[y][x2 + 2].info |= (CAVE_ROOM | CAVE_ICKY); - - place_bold(player_ptr, y, x2 + 2, GB_OUTER_NOPERM); + const Pos2D pos(y, x2 + 2); + floor.get_grid(pos).info |= (CAVE_ROOM | CAVE_ICKY); + place_bold(player_ptr, pos.y, pos.x, GB_OUTER_NOPERM); } - for (y = y1 - 1; y <= y2 + 1; y++) { - for (x = x1 - 1; x <= x2 + 1; x++) { - auto *g_ptr = &floor_ptr->grid_array[y][x]; - - g_ptr->info |= (CAVE_ROOM | CAVE_ICKY); + for (auto y = y1 - 1; y <= y2 + 1; y++) { + for (auto x = x1 - 1; x <= x2 + 1; x++) { + auto &grid = floor.get_grid({ y, x }); + grid.info |= (CAVE_ROOM | CAVE_ICKY); /* Permanent walls */ - place_grid(player_ptr, g_ptr, GB_INNER_PERM); + place_grid(player_ptr, &grid, GB_INNER_PERM); } } /* dimensions of vertex array */ - m = dx + 1; - n = dy + 1; - num_vertices = m * n; + const auto m = dx + 1; + const auto n = dy + 1; + const auto num_vertices = m * n; /* initialize array of visited vertices */ std::vector visited(num_vertices); @@ -847,11 +841,11 @@ static void build_mini_c_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, r_visit(player_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited.data()); /* Make it look like a checker board vault */ - for (x = x1; x <= x2; x++) { - for (y = y1; y <= y2; y++) { - total = x - x1 + y - y1; + for (auto x = x1; x <= x2; x++) { + for (auto y = y1; y <= y2; y++) { + const auto total = x - x1 + y - y1; /* If total is odd- and is a floor then make a wall */ - if ((total % 2 == 1) && floor_ptr->grid_array[y][x].is_floor()) { + if ((total % 2 == 1) && floor.grid_array[y][x].is_floor()) { place_bold(player_ptr, y, x, GB_INNER); } } @@ -860,12 +854,12 @@ static void build_mini_c_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, /* Make a couple of entrances */ if (one_in_(2)) { /* left and right */ - y = randint1(dy) + dy / 2; + const auto y = randint1(dy) + dy / 2; place_bold(player_ptr, y1 + y, x1 - 1, GB_INNER); place_bold(player_ptr, y1 + y, x2 + 1, GB_INNER); } else { /* top and bottom */ - x = randint1(dx) + dx / 2; + const auto x = randint1(dx) + dx / 2; place_bold(player_ptr, y1 - 1, x1 + x, GB_INNER); place_bold(player_ptr, y2 + 1, x1 + x, GB_INNER); } From bf110dbf9cabee53cfa4fc3bb54d0008c8121a5a Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:35:47 +0900 Subject: [PATCH 13/15] =?UTF-8?q?[Refactor]=20#4007=20build=5Fcastle=5Fvau?= =?UTF-8?q?lt()=20=E3=82=92=E6=95=B4=E5=BD=A2=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/room/rooms-vault.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/room/rooms-vault.cpp b/src/room/rooms-vault.cpp index a4b21a7ba4..311694478b 100644 --- a/src/room/rooms-vault.cpp +++ b/src/room/rooms-vault.cpp @@ -876,28 +876,24 @@ static void build_mini_c_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, */ static void build_castle_vault(PlayerType *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize) { - POSITION dy, dx; - POSITION y1, x1, y2, x2; - POSITION y, x; - /* Pick a random room size */ - dy = ysize / 2 - 1; - dx = xsize / 2 - 1; - - y1 = y0 - dy; - x1 = x0 - dx; - y2 = y0 + dy; - x2 = x0 + dx; + const auto dy = ysize / 2 - 1; + const auto dx = xsize / 2 - 1; + const auto y1 = y0 - dy; + const auto x1 = x0 - dx; + const auto y2 = y0 + dy; + const auto x2 = x0 + dx; msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("城型ランダムVaultを生成しました。", "Castle Vault")); /* generate the room */ - auto *floor_ptr = player_ptr->current_floor_ptr; - for (y = y1 - 1; y <= y2 + 1; y++) { - for (x = x1 - 1; x <= x2 + 1; x++) { - floor_ptr->grid_array[y][x].info |= (CAVE_ROOM | CAVE_ICKY); + auto &floor = *player_ptr->current_floor_ptr; + for (auto y = y1 - 1; y <= y2 + 1; y++) { + for (auto x = x1 - 1; x <= x2 + 1; x++) { + const Pos2D pos(y, x); + floor.get_grid(pos).info |= (CAVE_ROOM | CAVE_ICKY); /* Make everything a floor */ - place_bold(player_ptr, y, x, GB_FLOOR); + place_bold(player_ptr, pos.y, pos.x, GB_FLOOR); } } From 221edda674fb7e439bffe02aa53d5012dd2717b6 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Wed, 13 Nov 2024 23:16:47 +0900 Subject: [PATCH 14/15] =?UTF-8?q?[Refactor]=20know=5Fdetails()=20=E3=82=92?= =?UTF-8?q?lore=5Ftype=20=E3=81=A8MonraceDefinition=20=E3=81=AEis=5Fdetail?= =?UTF-8?q?s=5Fknown()=20=E3=81=AB=E7=B9=B0=E3=82=8A=E8=BE=BC=E3=82=93?= =?UTF-8?q?=E3=81=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lore/lore-calculator.cpp | 43 ++++++-------------------------- src/lore/lore-calculator.h | 1 - src/lore/lore-util.cpp | 5 ++++ src/lore/lore-util.h | 1 + src/system/monster-race-info.cpp | 18 +++++++++++++ src/system/monster-race-info.h | 1 + src/view/display-lore-status.cpp | 2 +- src/view/display-lore.cpp | 2 +- 8 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/lore/lore-calculator.cpp b/src/lore/lore-calculator.cpp index d8cd18eec3..f1f403bfca 100644 --- a/src/lore/lore-calculator.cpp +++ b/src/lore/lore-calculator.cpp @@ -45,34 +45,6 @@ std::string dice_to_string(int base_damage, int dice_num, int dice_side, int dic return ss.str(); } -/*! - * @brief モンスターの詳細情報(HP,AC,スキルダメージの量)を得ることができるかを返す - * @param r_idx モンスターの種族ID - * @return モンスターの詳細情報を得る条件が満たされているならtrue、そうでないならfalse - * @details - * The higher the level, the fewer kills needed. - */ -bool know_details(MonraceId r_idx) -{ - const auto &monrace = monraces_info[r_idx]; - const auto level = monrace.level; - const auto kills = monrace.r_tkills; - - if (monrace.r_cast_spell == MAX_UCHAR) { - return true; - } - if (kills > 304 / (4 + level)) { - return true; - } - if (monrace.kind_flags.has_not(MonsterKindType::UNIQUE)) { - return false; - } - if (kills > 304 / (38 + (5 * level) / 4)) { - return true; - } - return false; -} - /*! * @brief モンスターの打撃威力を知ることができるかどうかを返す * Determine if the "damage" of the given attack is known @@ -120,19 +92,18 @@ bool know_blow_damage(MonraceId r_idx, int i) */ void add_lore_of_damage_skill(PlayerType *player_ptr, lore_type *lore_ptr, MonsterAbilityType ms_type, concptr msg, byte color) { - MonraceId r_idx = lore_ptr->r_idx; - - if (!know_details(r_idx) && !lore_ptr->know_everything) { + if (!lore_ptr->is_details_known() && !lore_ptr->know_everything) { // ダメージ量の情報なし lore_ptr->lore_msgs.emplace_back(format(msg, ""), color); return; } - int base_damage = monspell_race_damage(player_ptr, ms_type, r_idx, BASE_DAM); - int dice_num = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_NUM); - int dice_side = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_SIDE); - int dice_mult = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_MULT); - int dice_div = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_DIV); + const auto monrace_id = lore_ptr->r_idx; + const auto base_damage = monspell_race_damage(player_ptr, ms_type, monrace_id, BASE_DAM); + const auto dice_num = monspell_race_damage(player_ptr, ms_type, monrace_id, DICE_NUM); + const auto dice_side = monspell_race_damage(player_ptr, ms_type, monrace_id, DICE_SIDE); + const auto dice_mult = monspell_race_damage(player_ptr, ms_type, monrace_id, DICE_MULT); + const auto dice_div = monspell_race_damage(player_ptr, ms_type, monrace_id, DICE_DIV); std::stringstream dam_info; dam_info << '(' << dice_to_string(base_damage, dice_num, dice_side, dice_mult, dice_div) << ')'; lore_ptr->lore_msgs.emplace_back(format(msg, dam_info.str().data()), color); diff --git a/src/lore/lore-calculator.h b/src/lore/lore-calculator.h index a78e7dd262..84c9ee58a4 100644 --- a/src/lore/lore-calculator.h +++ b/src/lore/lore-calculator.h @@ -9,7 +9,6 @@ enum class MonraceId : short; struct lore_type; class PlayerType; std::string dice_to_string(int base_damage, int dice_num, int dice_side, int dice_mult, int dice_div); -bool know_details(MonraceId r_idx); bool know_blow_damage(MonraceId r_idx, int i); void add_lore_of_damage_skill(PlayerType *player_ptr, lore_type *lore_ptr, MonsterAbilityType ms_type, concptr msg, byte color); void set_flags_for_full_knowledge(lore_type *lore_ptr); diff --git a/src/lore/lore-util.cpp b/src/lore/lore-util.cpp index 7b44f06431..ee54b932c5 100644 --- a/src/lore/lore-util.cpp +++ b/src/lore/lore-util.cpp @@ -63,6 +63,11 @@ bool lore_type::has_reinforce() const return this->r_ptr->has_reinforce(); } +bool lore_type::is_details_known() const +{ + return MonraceList::get_instance().get_monrace(this->r_idx).is_details_known(); +} + std::vector lore_type::build_speed_description() const { std::vector texts; diff --git a/src/lore/lore-util.h b/src/lore/lore-util.h index 4010d06a1e..4fe54db92f 100644 --- a/src/lore/lore-util.h +++ b/src/lore/lore-util.h @@ -84,6 +84,7 @@ struct lore_type { EnumClassFlagGroup misc_flags; bool has_reinforce() const; + bool is_details_known() const; std::optional> build_kill_unique_description() const; std::string build_revenge_description(bool has_defeated) const; diff --git a/src/system/monster-race-info.cpp b/src/system/monster-race-info.cpp index 008a7d61c8..e1650cfcae 100644 --- a/src/system/monster-race-info.cpp +++ b/src/system/monster-race-info.cpp @@ -475,6 +475,24 @@ bool MonraceDefinition::should_display(bool is_alive) const return this->max_num == 0; } +/*! + * @brief 詳細情報(HP,AC,スキルダメージの量)を得ることができるかを返す + * @return モンスターの詳細情報を得る条件が満たされているか否か + * @details 高レベルモンスターほど撃破数は少なくても詳細を知ることができる + */ +bool MonraceDefinition::is_details_known() const +{ + if ((this->r_cast_spell == MAX_UCHAR) || (this->r_tkills > 304 / (4 + this->level))) { + return true; + } + + if (this->kind_flags.has_not(MonsterKindType::UNIQUE)) { + return false; + } + + return this->r_tkills > 304 / (38 + (5 * this->level) / 4); +} + void MonraceDefinition::reset_current_numbers() { this->cur_num = 0; diff --git a/src/system/monster-race-info.h b/src/system/monster-race-info.h index 83f18aee37..c25c1e6f12 100644 --- a/src/system/monster-race-info.h +++ b/src/system/monster-race-info.h @@ -151,6 +151,7 @@ class MonraceDefinition { //!< @todo ここから先はミュータブルなフィールドなので分離すべき. bool has_entity() const; bool should_display(bool is_alive) const; + bool is_details_known() const; void reset_current_numbers(); void increment_current_numbers(); diff --git a/src/view/display-lore-status.cpp b/src/view/display-lore-status.cpp index a3992a8454..19bad10730 100644 --- a/src/view/display-lore-status.cpp +++ b/src/view/display-lore-status.cpp @@ -10,7 +10,7 @@ void display_monster_hp_ac(lore_type *lore_ptr) { - if (!know_details(lore_ptr->r_idx) && !lore_ptr->know_everything) { + if (!lore_ptr->is_details_known() && !lore_ptr->know_everything) { return; } diff --git a/src/view/display-lore.cpp b/src/view/display-lore.cpp index d2e69b9055..7db0b6cbfc 100644 --- a/src/view/display-lore.cpp +++ b/src/view/display-lore.cpp @@ -516,7 +516,7 @@ void display_monster_launching(PlayerType *player_ptr, lore_type *lore_ptr) } std::string msg; - if (know_details(lore_ptr->r_idx) || lore_ptr->know_everything) { + if (lore_ptr->is_details_known() || lore_ptr->know_everything) { msg = format(_("威力 %s の射撃をする", "fire an arrow (Power:%s)"), lore_ptr->r_ptr->shoot_damage_dice.to_string().data()); } else { msg = _("射撃をする", "fire an arrow"); From 3c366101dccc31c7fc80f311ca072a8d9773cf00 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Wed, 13 Nov 2024 23:26:00 +0900 Subject: [PATCH 15/15] =?UTF-8?q?[Refactor]=20know=5Fblow=5Fdamage()=20?= =?UTF-8?q?=E3=82=92lore=5Ftype=20=E3=81=A8MonraceDefinition=20=E3=81=AEis?= =?UTF-8?q?=5Fblow=5Fdamage=5Fknown()=20=E3=81=AB=E7=B9=B0=E3=82=8A?= =?UTF-8?q?=E8=BE=BC=E3=82=93=E3=81=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lore/lore-calculator.cpp | 38 ------------------------------- src/lore/lore-calculator.h | 1 - src/lore/lore-util.cpp | 5 ++++ src/lore/lore-util.h | 1 + src/system/monster-race-info.cpp | 25 ++++++++++++++++++++ src/system/monster-race-info.h | 1 + src/view/display-lore-attacks.cpp | 4 ++-- 7 files changed, 34 insertions(+), 41 deletions(-) diff --git a/src/lore/lore-calculator.cpp b/src/lore/lore-calculator.cpp index f1f403bfca..862f867d7f 100644 --- a/src/lore/lore-calculator.cpp +++ b/src/lore/lore-calculator.cpp @@ -45,44 +45,6 @@ std::string dice_to_string(int base_damage, int dice_num, int dice_side, int dic return ss.str(); } -/*! - * @brief モンスターの打撃威力を知ることができるかどうかを返す - * Determine if the "damage" of the given attack is known - * @param r_idx モンスターの種族ID - * @param i 確認したい攻撃手番 - * @return 敵のダメージダイスを知る条件が満たされているならtrue、そうでないならfalse - * @details - *
- * the higher the level of the monster, the fewer the attacks you need,
- * the more damage an attack does, the more attacks you need
- * 
- */ -bool know_blow_damage(MonraceId r_idx, int i) -{ - const auto &monrace = monraces_info[r_idx]; - auto level = monrace.level; - auto a = monrace.r_blows[i]; - auto d = monrace.blows[i].damage_dice.maxroll(); - - if (d >= ((4 + level) * MAX_UCHAR) / 80) { - d = ((4 + level) * MAX_UCHAR - 1) / 80; - } - - if ((4 + level) * a > 80 * d) { - return true; - } - - if (monrace.kind_flags.has_not(MonsterKindType::UNIQUE)) { - return false; - } - - if ((4 + level) * (2 * a) > 80 * d) { - return true; - } - - return false; -} - /*! * @brief lore_ptrにダメージを与えるスキルの情報を追加する * @param lore_ptr 知識情報 diff --git a/src/lore/lore-calculator.h b/src/lore/lore-calculator.h index 84c9ee58a4..a62a157efd 100644 --- a/src/lore/lore-calculator.h +++ b/src/lore/lore-calculator.h @@ -9,6 +9,5 @@ enum class MonraceId : short; struct lore_type; class PlayerType; std::string dice_to_string(int base_damage, int dice_num, int dice_side, int dice_mult, int dice_div); -bool know_blow_damage(MonraceId r_idx, int i); void add_lore_of_damage_skill(PlayerType *player_ptr, lore_type *lore_ptr, MonsterAbilityType ms_type, concptr msg, byte color); void set_flags_for_full_knowledge(lore_type *lore_ptr); diff --git a/src/lore/lore-util.cpp b/src/lore/lore-util.cpp index ee54b932c5..69ca7dbd88 100644 --- a/src/lore/lore-util.cpp +++ b/src/lore/lore-util.cpp @@ -68,6 +68,11 @@ bool lore_type::is_details_known() const return MonraceList::get_instance().get_monrace(this->r_idx).is_details_known(); } +bool lore_type::is_blow_damage_known(int num_blow) const +{ + return MonraceList::get_instance().get_monrace(this->r_idx).is_blow_damage_known(num_blow); +} + std::vector lore_type::build_speed_description() const { std::vector texts; diff --git a/src/lore/lore-util.h b/src/lore/lore-util.h index 4fe54db92f..c97f5597f5 100644 --- a/src/lore/lore-util.h +++ b/src/lore/lore-util.h @@ -85,6 +85,7 @@ struct lore_type { bool has_reinforce() const; bool is_details_known() const; + bool is_blow_damage_known(int num_blow) const; std::optional> build_kill_unique_description() const; std::string build_revenge_description(bool has_defeated) const; diff --git a/src/system/monster-race-info.cpp b/src/system/monster-race-info.cpp index e1650cfcae..22689d8423 100644 --- a/src/system/monster-race-info.cpp +++ b/src/system/monster-race-info.cpp @@ -493,6 +493,31 @@ bool MonraceDefinition::is_details_known() const return this->r_tkills > 304 / (38 + (5 * this->level) / 4); } +/*! + * @brief モンスターの打撃威力を知ることができるかどうかを返す + * @param num_blow 確認したい攻撃手番 + * @return 敵のダメージダイスを知る条件が満たされているか否か + * @details レベルの高いモンスターほど被打撃数が少なくても打撃威力が分かる + */ +bool MonraceDefinition::is_blow_damage_known(int num_blow) const +{ + const auto r_blow = this->r_blows[num_blow]; + auto max_damage = this->blows[num_blow].damage_dice.maxroll(); + if (max_damage >= ((4 + this->level) * MAX_UCHAR) / 80) { + max_damage = ((4 + this->level) * MAX_UCHAR - 1) / 80; + } + + if ((4 + this->level) * r_blow > 80 * max_damage) { + return true; + } + + if (this->kind_flags.has_not(MonsterKindType::UNIQUE)) { + return false; + } + + return (4 + this->level) * (2 * r_blow) > 80 * max_damage; +} + void MonraceDefinition::reset_current_numbers() { this->cur_num = 0; diff --git a/src/system/monster-race-info.h b/src/system/monster-race-info.h index c25c1e6f12..6503a18340 100644 --- a/src/system/monster-race-info.h +++ b/src/system/monster-race-info.h @@ -152,6 +152,7 @@ class MonraceDefinition { bool has_entity() const; bool should_display(bool is_alive) const; bool is_details_known() const; + bool is_blow_damage_known(int num_blow) const; void reset_current_numbers(); void increment_current_numbers(); diff --git a/src/view/display-lore-attacks.cpp b/src/view/display-lore-attacks.cpp index c39a079e3b..d639582a38 100644 --- a/src/view/display-lore-attacks.cpp +++ b/src/view/display-lore-attacks.cpp @@ -21,7 +21,7 @@ static void display_monster_blow_jp(lore_type *lore_ptr, int attack_numbers, con hooked_roff(format("%s^は", Who::who(lore_ptr->msex).data())); } - if (damage_dice.is_valid() && (lore_ptr->know_everything || know_blow_damage(lore_ptr->r_idx, m))) { + if (damage_dice.is_valid() && (lore_ptr->know_everything || lore_ptr->is_blow_damage_known(m))) { hook_c_roff(TERM_L_WHITE, format(" %s ", damage_dice.to_string().data())); hooked_roff("のダメージで"); } @@ -82,7 +82,7 @@ static void display_monster_blow_en(lore_type *lore_ptr, int attack_numbers, con if (lore_ptr->q != nullptr) { hooked_roff(" to "); hook_c_roff(lore_ptr->qc, lore_ptr->q); - if (damage_dice.is_valid() && (lore_ptr->know_everything || know_blow_damage(lore_ptr->r_idx, m))) { + if (damage_dice.is_valid() && (lore_ptr->know_everything || lore_ptr->is_blow_damage_known(m))) { hooked_roff(" with damage"); hook_c_roff(TERM_L_WHITE, format(" %s", damage_dice.to_string().data())); }