OSDN Git Service

[Refactor] #2620 Moved BaseitemKey from articles-on-sale.h to baseitem-info-definition.h
authorHourier <66951241+Hourier@users.noreply.github.com>
Wed, 2 Nov 2022 15:47:43 +0000 (00:47 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Thu, 3 Nov 2022 16:10:43 +0000 (01:10 +0900)
src/market/building-initializer.cpp
src/store/articles-on-sale.cpp
src/store/articles-on-sale.h
src/system/baseitem-info-definition.cpp
src/system/baseitem-info-definition.h

index 9af848c..7b424ef 100644 (file)
@@ -35,12 +35,12 @@ void init_towns(void)
             }
 
             for (const auto &kind : store_regular_sale_table.at(sst)) {
-                auto k_idx = lookup_kind(kind.tval, kind.sval);
+                auto k_idx = lookup_kind(kind.type_value, kind.subtype_value);
                 store_ptr->regular.push_back(k_idx);
             }
 
             for (const auto &kind : store_sale_table.at(sst)) {
-                auto k_idx = lookup_kind(kind.tval, kind.sval);
+                auto k_idx = lookup_kind(kind.type_value, kind.subtype_value);
                 store_ptr->table.push_back(k_idx);
             }
         }
index d1932cc..c241fb8 100644 (file)
@@ -1,4 +1,6 @@
 #include "store/articles-on-sale.h"
+#include "object/tval-types.h"
+#include "store/store-owners.h"
 #include "sv-definition/sv-amulet-types.h"
 #include "sv-definition/sv-armor-types.h"
 #include "sv-definition/sv-bow-types.h"
@@ -14,6 +16,7 @@
 #include "sv-definition/sv-staff-types.h"
 #include "sv-definition/sv-wand-types.h"
 #include "sv-definition/sv-weapon-types.h"
+#include "system/baseitem-info-definition.h"
 
 /*!
  * @brief 店舗で常時販売するオブジェクトを定義する
index ee3db66..767bc92 100644 (file)
@@ -1,15 +1,9 @@
 #pragma once
 
-#include "object/tval-types.h"
-#include "store/store-owners.h"
-#include "store/store.h"
-#include "system/angband.h"
 #include <map>
+#include <vector>
 
-struct BaseitemKey {
-    ItemKindType tval;
-    OBJECT_SUBTYPE_VALUE sval;
-};
-
+enum class StoreSaleType;
+class BaseitemKey;
 extern const std::map<StoreSaleType, std::vector<BaseitemKey>> store_regular_sale_table;
 extern const std::map<StoreSaleType, std::vector<BaseitemKey>> store_sale_table;
index 2e7066f..90fb59b 100644 (file)
@@ -8,9 +8,41 @@
  */
 
 #include "system/baseitem-info-definition.h"
-#include "system/object-type-definition.h"
+#include "object/tval-types.h"
+
+BaseitemKey::BaseitemKey(ItemKindType type_value, int subtype_value)
+    : type_value(type_value)
+    , subtype_value(subtype_value)
+{
+}
+
+bool BaseitemKey::operator==(const BaseitemKey &other) const
+{
+    return (this->type_value == other.type_value) && (this->subtype_value == other.subtype_value);
+}
+
+// @details type_valueに大小があればそれを判定し、同一ならばsubtype_valueの大小を判定する.
+bool BaseitemKey::operator<(const BaseitemKey &other) const
+{
+    if (this->type_value < other.type_value) {
+        return true;
+    }
+
+    if (this->type_value > other.type_value) {
+        return false;
+    }
+
+    return this->subtype_value < other.subtype_value;
+}
+
+ItemKindType BaseitemKey::tval() const
+{
+    return this->type_value;
+}
+
+int BaseitemKey::sval() const
+{
+    return this->subtype_value;
+}
 
-/*
- * The object kind arrays
- */
 std::vector<BaseItemInfo> baseitems_info;
index 9dc2c93..ba241ae 100644 (file)
@@ -4,10 +4,50 @@
 #include "object-enchant/trg-types.h"
 #include "system/angband.h"
 #include "util/flag-group.h"
+#include <optional>
 #include <string>
 #include <vector>
 
 enum class ItemKindType : short;
+class BaseitemKey {
+public:
+    BaseitemKey(ItemKindType type_value, int subtype_value);
+    bool operator==(const BaseitemKey &other) const;
+    bool operator!=(const BaseitemKey &other) const
+    {
+        return !(*this == other);
+    }
+
+    bool operator<(const BaseitemKey &other) const;
+    bool operator>(const BaseitemKey &other) const
+    {
+        return other < *this;
+    }
+
+    bool operator<=(const BaseitemKey &other) const
+    {
+        return !(*this > other);
+    }
+
+    bool operator>=(const BaseitemKey &other) const
+    {
+        return !(*this < other);
+    }
+
+    ItemKindType tval() const;
+    int sval() const;
+
+    /*
+     * @todo アクセシビリティによるコンパイルエラーを避けるための一時的措置.
+     * @details svalは後でoptionalにする.
+     */
+    ItemKindType type_value;
+    int subtype_value;
+
+private:
+};
+
+enum class ItemKindType : short;
 enum class RandomArtActType : short;
 class BaseItemInfo {
 public: