OSDN Git Service

[Refactor] #2745 SV_ANYを使っている箇所をlookup_kind() の中に限定した (暫定的処置、次のコミットで削除)
authorHourier <66951241+Hourier@users.noreply.github.com>
Fri, 4 Nov 2022 11:44:34 +0000 (20:44 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Fri, 4 Nov 2022 16:10:47 +0000 (01:10 +0900)
src/birth/inventory-initializer.cpp
src/market/building-craft-fix.cpp
src/object/object-kind-hook.cpp
src/spell/spells-object.cpp
src/store/articles-on-sale.cpp
src/sv-definition/sv-other-types.h

index bc95fe3..200cec9 100644 (file)
@@ -128,7 +128,7 @@ static void decide_initial_items(PlayerType *player_ptr, ObjectType *q_ptr)
         break;
     case PlayerRaceType::ANDROID:
         /* Flasks of oil */
-        q_ptr->prep(lookup_kind(ItemKindType::FLASK, SV_ANY));
+        q_ptr->prep(lookup_kind({ ItemKindType::FLASK }));
         ItemMagicApplier(player_ptr, q_ptr, 1, AM_NO_FIXED_ART).execute();
         q_ptr->number = (ITEM_NUMBER)rand_range(7, 12);
         add_outfit(player_ptr, q_ptr);
index 04183e3..e819c73 100644 (file)
@@ -176,7 +176,7 @@ static PRICE repair_broken_weapon_aux(PlayerType *player_ptr, PRICE bcost)
         auto tval = (one_in_(5) ? mo_ptr->tval : ItemKindType::SWORD);
         while (true) {
             BaseItemInfo *ck_ptr;
-            k_idx = lookup_kind(tval, SV_ANY);
+            k_idx = lookup_kind({ tval });
             ck_ptr = &baseitems_info[k_idx];
 
             if (tval == ItemKindType::SWORD) {
index cffc7de..25ebe96 100644 (file)
@@ -231,8 +231,6 @@ short lookup_kind(const BaseitemKey &key)
 
 /*!
  * @brief tvalとsvalに対応するベースアイテムのIDを検索する
- * Find the index of the BaseItemInfo with the given tval and sval
- * svalにSV_ANYが渡された場合はtvalが一致するすべてのベースアイテムから等確率でランダムに1つを選択する
  * @param tval 検索したいベースアイテムのtval
  * @param sval 検索したいベースアイテムのsval
  * @return tvalとsvalに対応するベースアイテムが存在すればそのID、存在しなければ0
index 98a880c..9dc527d 100644 (file)
@@ -64,27 +64,34 @@ enum class AmusementFlagType : byte {
     PILE, /* Drop 1-99 pile objects for one type */
 };
 
-struct amuse_type {
-    ItemKindType tval;
-    OBJECT_SUBTYPE_VALUE sval;
+class AmuseDefinition {
+public:
+    AmuseDefinition(const BaseitemKey &key, PERCENTAGE prob, AmusementFlagType flag)
+        : key(key)
+        , prob(prob)
+        , flag(flag)
+    {
+    }
+
+    BaseitemKey key;
     PERCENTAGE prob;
     AmusementFlagType flag;
 };
 
-static constexpr std::array<amuse_type, 13> amuse_info = { {
-    { ItemKindType::BOTTLE, SV_ANY, 5, AmusementFlagType::NOTHING },
-    { ItemKindType::JUNK, SV_ANY, 3, AmusementFlagType::MULTIPLE },
-    { ItemKindType::SPIKE, SV_ANY, 10, AmusementFlagType::PILE },
-    { ItemKindType::STATUE, SV_ANY, 15, AmusementFlagType::NOTHING },
-    { ItemKindType::CORPSE, SV_ANY, 15, AmusementFlagType::NO_UNIQUE },
-    { ItemKindType::SKELETON, SV_ANY, 10, AmusementFlagType::NO_UNIQUE },
-    { ItemKindType::FIGURINE, SV_ANY, 10, AmusementFlagType::NO_UNIQUE },
-    { ItemKindType::PARCHMENT, SV_ANY, 1, AmusementFlagType::NOTHING },
-    { ItemKindType::POLEARM, SV_TSURIZAO, 3, AmusementFlagType::NOTHING }, // Fishing Pole of Taikobo
-    { ItemKindType::SWORD, SV_BROKEN_DAGGER, 3, AmusementFlagType::FIXED_ART }, // Broken Dagger of Magician
-    { ItemKindType::SWORD, SV_BROKEN_DAGGER, 10, AmusementFlagType::NOTHING },
-    { ItemKindType::SWORD, SV_BROKEN_SWORD, 5, AmusementFlagType::NOTHING },
-    { ItemKindType::SCROLL, SV_SCROLL_AMUSEMENT, 10, AmusementFlagType::NOTHING },
+static const std::array<AmuseDefinition, 13> amuse_info = { {
+    { { ItemKindType::BOTTLE }, 5, AmusementFlagType::NOTHING },
+    { { ItemKindType::JUNK }, 3, AmusementFlagType::MULTIPLE },
+    { { ItemKindType::SPIKE }, 10, AmusementFlagType::PILE },
+    { { ItemKindType::STATUE }, 15, AmusementFlagType::NOTHING },
+    { { ItemKindType::CORPSE }, 15, AmusementFlagType::NO_UNIQUE },
+    { { ItemKindType::SKELETON }, 10, AmusementFlagType::NO_UNIQUE },
+    { { ItemKindType::FIGURINE }, 10, AmusementFlagType::NO_UNIQUE },
+    { { ItemKindType::PARCHMENT }, 1, AmusementFlagType::NOTHING },
+    { { ItemKindType::POLEARM, SV_TSURIZAO }, 3, AmusementFlagType::NOTHING }, // Fishing Pole of Taikobo
+    { { ItemKindType::SWORD, SV_BROKEN_DAGGER }, 3, AmusementFlagType::FIXED_ART }, // Broken Dagger of Magician
+    { { ItemKindType::SWORD, SV_BROKEN_DAGGER }, 10, AmusementFlagType::NOTHING },
+    { { ItemKindType::SWORD, SV_BROKEN_SWORD }, 5, AmusementFlagType::NOTHING },
+    { { ItemKindType::SCROLL, SV_SCROLL_AMUSEMENT }, 10, AmusementFlagType::NOTHING },
 } };
 
 static std::optional<FixedArtifactId> sweep_amusement_artifact(const bool insta_art, const short k_idx)
@@ -124,7 +131,7 @@ static std::optional<FixedArtifactId> sweep_amusement_artifact(const bool insta_
  */
 void generate_amusement(PlayerType *player_ptr, int num, bool known)
 {
-    ProbabilityTable<const amuse_type *> pt;
+    ProbabilityTable<const AmuseDefinition *> pt;
     for (const auto &am_ref : amuse_info) {
         pt.entry_item(&am_ref, am_ref.prob);
     }
@@ -132,7 +139,7 @@ void generate_amusement(PlayerType *player_ptr, int num, bool known)
     while (num > 0) {
         auto am_ptr = pt.pick_one_at_random();
 
-        const auto k_idx = lookup_kind(am_ptr->tval, am_ptr->sval);
+        const auto k_idx = lookup_kind(am_ptr->key);
         if (k_idx == 0) {
             continue;
         }
index c241fb8..d6e761c 100644 (file)
@@ -23,7 +23,7 @@
  * @details
  * 上から優先して配置する。
  * 重複して同じ商品を設定した場合、数量が増える。
- * 17エントリーまで設定可能。(最後はTV_NONE で止める)
+ * 17エントリーまで設定可能。
  * 種類が多すぎる場合、店舗を埋めつくすので注意。
  */
 const std::map<StoreSaleType, std::vector<BaseitemKey>> store_regular_sale_table = {
@@ -153,7 +153,7 @@ const std::map<StoreSaleType, std::vector<BaseitemKey>> store_sale_table = {
             { ItemKindType::FIGURINE, 0 },
             { ItemKindType::WHISTLE, 1 },
             { ItemKindType::ROD, SV_ROD_PESTICIDE },
-            { ItemKindType::STATUE, SV_ANY },
+            { ItemKindType::STATUE },
         } },
 
     {
@@ -336,7 +336,7 @@ const std::map<StoreSaleType, std::vector<BaseitemKey>> store_sale_table = {
             { ItemKindType::POTION, SV_POTION_RESIST_HEAT },
             { ItemKindType::POTION, SV_POTION_RESIST_COLD },
             { ItemKindType::FIGURINE, 0 },
-            { ItemKindType::STATUE, SV_ANY },
+            { ItemKindType::STATUE },
 
             { ItemKindType::SCROLL, SV_SCROLL_REMOVE_CURSE },
             { ItemKindType::SCROLL, SV_SCROLL_REMOVE_CURSE },
index 2800ba5..136ef3f 100644 (file)
@@ -1,13 +1,11 @@
 /*!
- * @brief enumで表現することが却って高コストになりそうなSV定義をここに格納する
+ * @brief enumで表現することが却って高コストになりそうなSV (ベースアイテムのサブタイプ)定義をここに格納する
  * @date 2020/05/28
  * @author Hourier
  */
 
 #pragma once
 
-/*** Object "sval" codes ***/
-#define SV_ANY 255
 #define SV_PHOTO 50
 
 /* The "sval" codes for TV_CORPSE */