OSDN Git Service

[Feature] PlayerRealm: 職業を指定して魔法情報を取得
authorHabu <habu1010+github@gmail.com>
Sun, 30 Jun 2024 15:28:28 +0000 (00:28 +0900)
committerHabu <habu1010+github@gmail.com>
Sun, 30 Jun 2024 15:34:03 +0000 (00:34 +0900)
PlayerRealmクラスの静的メンバ関数 get_spell_info に、指定した職業の
テーブルから魔法情報を取得できるようにする引数を追加する。
引数を省略した場合はこれまで通り現在のプレイヤーの職業のテーブル
(グローバル変数mp_ptrが指している)から魔法情報を取得する。

src/player/player-realm.cpp
src/player/player-realm.h

index 94b11be..18c02e0 100644 (file)
@@ -89,7 +89,7 @@ const LocalizedString &PlayerRealm::get_name(int realm)
     return it->second;
 }
 
-const magic_type &PlayerRealm::get_spell_info(int realm, int spell_idx)
+const magic_type &PlayerRealm::get_spell_info(int realm, int spell_idx, std::optional<PlayerClassType> pclass)
 {
     if (spell_idx < 0 || 32 <= spell_idx) {
         THROW_EXCEPTION(std::invalid_argument, format("Invalid spell idx: %d", spell_idx));
@@ -98,6 +98,9 @@ const magic_type &PlayerRealm::get_spell_info(int realm, int spell_idx)
     const auto realm_enum = i2enum<magic_realm_type>(realm);
 
     if (MAGIC_REALM_RANGE.contains(realm_enum)) {
+        if (pclass) {
+            return class_magics_info.at(enum2i(*pclass)).info[realm - 1][spell_idx];
+        }
         return mp_ptr->info[realm - 1][spell_idx];
     }
     if (TECHNIC_REALM_RANGE.contains(realm_enum)) {
index 89e84e1..bf59e1d 100644 (file)
@@ -4,6 +4,7 @@
 #include "system/angband.h"
 #include "util/flag-group.h"
 #include <cstdint>
+#include <optional>
 #include <vector>
 
 using RealmChoices = FlagGroup<magic_realm_type, REALM_MAX>;
@@ -18,7 +19,7 @@ public:
     PlayerRealm(PlayerType *player_ptr);
 
     static const LocalizedString &get_name(int realm);
-    static const magic_type &get_spell_info(int realm, int num);
+    static const magic_type &get_spell_info(int realm, int num, std::optional<PlayerClassType> pclass = std::nullopt);
     static ItemKindType get_book(int realm);
     static RealmChoices get_realm1_choices(PlayerClassType pclass);
     static RealmChoices get_realm2_choices(PlayerClassType pclass);