From 902c4a76a2a11ced1050dffd3bb78cdf26fc0635 Mon Sep 17 00:00:00 2001 From: Habu Date: Wed, 3 Jul 2024 22:10:59 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20=E9=A0=98=E5=9F=9F=E3=81=AE?= =?utf8?q?=E8=AA=AC=E6=98=8E=E3=81=AE=E5=8F=96=E5=BE=97=E5=87=A6=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 領域の説明の取得で、通常の魔法領域と歌・武芸・呪術が同じ配列上に詰めて 配置されているため technic2magic というマクロで無理やり要素番号を計算 して取得している。 これをやめ、まず魔法領域と歌・武芸・呪術で配列を分け、取得はPlayerRealm クラスにget_explanationとget_subinfoを実装しこのメンバ関数によって行う ように修正する。 --- src/birth/birth-explanations-table.cpp | 9 +++++++-- src/birth/birth-explanations-table.h | 6 ++++-- src/birth/birth-select-realm.cpp | 8 ++++---- src/knowledge/knowledge-self.cpp | 4 ++-- src/player/player-realm.cpp | 37 ++++++++++++++++++++++++++++++++++ src/player/player-realm.h | 6 ++++++ src/realm/realm-names-table.h | 1 - 7 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/birth/birth-explanations-table.cpp b/src/birth/birth-explanations-table.cpp index faa3092f5..223bc0bdc 100644 --- a/src/birth/birth-explanations-table.cpp +++ b/src/birth/birth-explanations-table.cpp @@ -252,7 +252,7 @@ const std::vector personality_explanations = { }; /*! 魔法領域の詳細解説メッセージテーブル */ -const std::vector realm_explanations = { +const std::vector magic_explanations = { _("生命は回復能力に優れた魔法です。治療や防御、感知魔法が多く含まれていますが、攻撃呪文もわずかに持っています。特に高レベルの呪文にはアンデッドを塵に帰す力をあると言われています。", "Life magic is very good for healing; it relies mostly on healing, protection and detection spells. Also life magic has a few attack spells as well. It's said that some high level spells of life magic can disintegrate Undead monsters into ash."), @@ -282,7 +282,9 @@ const std::vector realm_explanations = { _("破邪は「正義」の魔法です。直接敵を傷つける魔法が多く含まれ、特に邪悪な敵に対する力は恐るべきものがあります。しかし、善良な敵にはあまり効果がありません。", "Crusade is a magic of 'Justice'. It includes damage spells, which are greatly effective against foul and evil monsters, but have poor effects against good monsters."), +}; +const std::vector technic_explanations = { _("歌集は、歌によって効果を発揮する魔法です。魔法と同様、使った時に効果のあるものと、歌い続けることによって持続して効果を発揮するものがあります。後者の場合は、MPの続く限り効果を発揮することができますが、同時に歌える歌は1つだけという制限もあります。", "Music magic works through the caster singing songs. There are two types of songs; one which shows effects instantly and another which shows effects continuously until SP runs out. The latter type has a limit: only one song can be sung at a time."), @@ -294,7 +296,7 @@ const std::vector realm_explanations = { }; /*! 魔法領域の簡易解説メッセージテーブル */ -const std::vector realm_subinfo = { +const std::vector magic_subinfo = { _("感知と防御と回復に優れています", "Good at detection and healing."), _("攻撃はできませんが非常に便利です", "Utility and protective spells."), _("感知と防御に優れています", "Good at detection and defence."), @@ -305,6 +307,9 @@ const std::vector realm_subinfo = { _("直接戦闘の補助に優れています", "Support for melee fighting."), _("攻撃と防御の両面に優れています", "Good at both offence and defence."), _("邪悪な怪物に対する攻撃に優れています", "Destroys evil creatures."), +}; + +const std::vector technic_subinfo = { _("様々な魔法効果を持った歌を歌います", "Songs with magical effects."), _("打撃攻撃に特殊能力を付加します", "Special abilities for melee."), _("敵を邪魔しつつ復讐を狙います", "Good at obstacle and revenge."), diff --git a/src/birth/birth-explanations-table.h b/src/birth/birth-explanations-table.h index 29d47f1cc..112f14c8c 100644 --- a/src/birth/birth-explanations-table.h +++ b/src/birth/birth-explanations-table.h @@ -6,5 +6,7 @@ extern const std::vector race_explanations; extern const std::vector class_explanations; extern const std::vector personality_explanations; -extern const std::vector realm_explanations; -extern const std::vector realm_subinfo; +extern const std::vector magic_explanations; +extern const std::vector technic_explanations; +extern const std::vector magic_subinfo; +extern const std::vector technic_subinfo; diff --git a/src/birth/birth-select-realm.cpp b/src/birth/birth-select-realm.cpp index 3765b5bac..0909bed5a 100644 --- a/src/birth/birth-select-realm.cpp +++ b/src/birth/birth-select-realm.cpp @@ -1,5 +1,4 @@ #include "birth/birth-select-realm.h" -#include "birth/birth-explanations-table.h" #include "birth/birth-util.h" #include "core/asking-player.h" #include "io/input-key-acceptor.h" @@ -91,12 +90,13 @@ static void move_birth_realm_cursor(birth_realm_type *birth_realm_ptr) if (birth_realm_ptr->cs == birth_realm_ptr->n) { birth_realm_ptr->cur = format("%c%c %s", '*', birth_realm_ptr->p2, _("ランダム", "Random")); } else { - const auto &realm_name = PlayerRealm::get_name(birth_realm_ptr->picks[birth_realm_ptr->cs]); + const auto realm = birth_realm_ptr->picks[birth_realm_ptr->cs]; + const auto &realm_name = PlayerRealm::get_name(realm); birth_realm_ptr->cur = format("%c%c %s", birth_realm_ptr->sym[birth_realm_ptr->cs], birth_realm_ptr->p2, realm_name.data()); c_put_str(TERM_L_BLUE, realm_name, 3, 40); prt(_("の特徴", ": Characteristic"), 3, 40 + realm_name->length()); - prt(realm_subinfo[technic2magic(birth_realm_ptr->picks[birth_realm_ptr->cs]) - 1], 4, 40); + prt(PlayerRealm::get_subinfo(realm), 4, 40); } c_put_str(TERM_YELLOW, birth_realm_ptr->cur, 12 + (birth_realm_ptr->cs / 5), 2 + 15 * (birth_realm_ptr->cs % 5)); @@ -255,7 +255,7 @@ static std::optional process_choose_realm(PlayerType *player_p } cleanup_realm_selection_window(); - display_wrap_around(realm_explanations[technic2magic(*selected_realm) - 1], 74, 12, 3); + display_wrap_around(PlayerRealm::get_explanation(*selected_realm), 74, 12, 3); if (check_realm_selection(player_ptr, choices.count())) { return selected_realm; diff --git a/src/knowledge/knowledge-self.cpp b/src/knowledge/knowledge-self.cpp index 529c0c6b9..bc8475388 100644 --- a/src/knowledge/knowledge-self.cpp +++ b/src/knowledge/knowledge-self.cpp @@ -85,13 +85,13 @@ static void dump_yourself(PlayerType *player_ptr, FILE *fff) PlayerRealm pr(player_ptr); if (pr.realm1().is_available()) { fprintf(fff, _("魔法: %s\n", "Realm: %s\n"), pr.realm1().get_name().data()); - dump_explanation(realm_explanations[technic2magic(player_ptr->realm1) - 1], fff); + dump_explanation(pr.realm1().get_explanation(), fff); } fprintf(fff, "\n"); if (pr.realm2().is_available()) { fprintf(fff, _("魔法: %s\n", "Realm: %s\n"), pr.realm2().get_name().data()); - dump_explanation(realm_explanations[technic2magic(player_ptr->realm2) - 1], fff); + dump_explanation(pr.realm2().get_explanation(), fff); } } diff --git a/src/player/player-realm.cpp b/src/player/player-realm.cpp index 7d4fc971b..79ea45675 100644 --- a/src/player/player-realm.cpp +++ b/src/player/player-realm.cpp @@ -1,4 +1,5 @@ #include "player/player-realm.h" +#include "birth/birth-explanations-table.h" #include "locale/localized-string.h" #include "object/tval-types.h" #include "player-info/class-info.h" @@ -90,6 +91,32 @@ const LocalizedString &PlayerRealm::get_name(int realm) return it->second; } +std::string_view PlayerRealm::get_explanation(int realm) +{ + const auto realm_enum = i2enum(realm); + if (MAGIC_REALM_RANGE.contains(realm_enum)) { + return magic_explanations[realm - 1]; + } + if (TECHNIC_REALM_RANGE.contains(realm_enum)) { + return technic_explanations[realm - MIN_TECHNIC]; + } + + THROW_EXCEPTION(std::invalid_argument, format("Invalid realm: %d", realm)); +} + +std::string_view PlayerRealm::get_subinfo(int realm) +{ + const auto realm_enum = i2enum(realm); + if (MAGIC_REALM_RANGE.contains(realm_enum)) { + return magic_subinfo[realm - 1]; + } + if (TECHNIC_REALM_RANGE.contains(realm_enum)) { + return technic_subinfo[realm - MIN_TECHNIC]; + } + + THROW_EXCEPTION(std::invalid_argument, format("Invalid realm: %d", realm)); +} + const magic_type &PlayerRealm::get_spell_info(int realm, int spell_id, std::optional pclass) { if (spell_id < 0 || 32 <= spell_id) { @@ -193,6 +220,16 @@ const LocalizedString &PlayerRealm::Realm::get_name() const return PlayerRealm::get_name(this->realm_); } +std::string_view PlayerRealm::Realm::get_explanation() const +{ + return PlayerRealm::get_explanation(this->realm_); +} + +std::string_view PlayerRealm::Realm::get_subinfo() const +{ + return PlayerRealm::get_subinfo(this->realm_); +} + const magic_type &PlayerRealm::Realm::get_spell_info(int spell_id) const { return PlayerRealm::get_spell_info(this->realm_, spell_id); diff --git a/src/player/player-realm.h b/src/player/player-realm.h index 8c3295f37..ae6153966 100644 --- a/src/player/player-realm.h +++ b/src/player/player-realm.h @@ -5,6 +5,8 @@ #include "util/flag-group.h" #include #include +#include +#include #include using RealmChoices = FlagGroup; @@ -19,6 +21,8 @@ public: PlayerRealm(PlayerType *player_ptr); static const LocalizedString &get_name(int realm); + static std::string_view get_explanation(int realm); + static std::string_view get_subinfo(int realm); static const magic_type &get_spell_info(int realm, int spell_id, std::optional pclass = std::nullopt); static const std::string &get_spell_name(int realm, int spell_id); static const std::string &get_spell_description(int realm, int spell_id); @@ -30,6 +34,8 @@ public: public: Realm(int realm); const LocalizedString &get_name() const; + std::string_view get_explanation() const; + std::string_view get_subinfo() const; const magic_type &get_spell_info(int spell_id) const; const std::string &get_spell_name(int spell_id) const; const std::string &get_spell_description(int spell_id) const; diff --git a/src/realm/realm-names-table.h b/src/realm/realm-names-table.h index 3ed7afa02..ae640f18c 100644 --- a/src/realm/realm-names-table.h +++ b/src/realm/realm-names-table.h @@ -18,4 +18,3 @@ constexpr auto VALID_REALM = std::ssize(MAGIC_REALM_RANGE) + std::ssize(TECHNIC_ enum class ItemKindType : short; #define tval2realm(A) (i2enum((A)-ItemKindType::LIFE_BOOK + 1)) -#define technic2magic(A) (is_magic(A) ? (A) : (A)-MIN_TECHNIC + 1 + MAX_MAGIC) -- 2.11.0