OSDN Git Service

[Refactor] #3756 activation_type 構造体をActivationType クラスに変え、-1で無効値を表していたcontant フィールド変...
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 2 Dec 2023 05:30:45 +0000 (14:30 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 2 Dec 2023 06:00:43 +0000 (15:00 +0900)
src/action/activation-execution.cpp
src/object-enchant/activation-info-table.cpp
src/object-enchant/activation-info-table.h
src/system/item-entity.cpp
src/system/item-entity.h

index e9b42ef..4b51e77 100644 (file)
@@ -165,10 +165,10 @@ static bool activate_artifact(PlayerType *player_ptr, ItemEntity *o_ptr)
         return false;
     }
 
-    if (it_activation->constant >= 0) {
-        o_ptr->timeout = static_cast<short>(it_activation->constant);
+    if (it_activation->constant) {
+        o_ptr->timeout = static_cast<short>(*it_activation->constant);
         if (it_activation->dice > 0) {
-            o_ptr->timeout += randint1(it_activation->dice);
+            o_ptr->timeout += static_cast<short>(randint1(it_activation->dice));
         }
 
         return true;
index ebe2b42..3d3d3f5 100644 (file)
@@ -3,10 +3,9 @@
 #include "locale/language-switcher.h"
 
 /*!
- * @brief アイテムの発動効果テーブル /
- * Define flags, levels, values of activations
+ * @brief アイテムの発動効果テーブル
  */
-const std::vector<activation_type> activation_info = {
+const std::vector<ActivationType> activation_info = {
     { "SUNLIGHT", RandomArtActType::SUNLIGHT, 10, 250, 10, 0, _("太陽光線", "beam of sunlight") },
     { "BO_MISS_1", RandomArtActType::BO_MISS_1, 10, 250, 2, 0, _("マジック・ミサイル(2d6)", "magic missile (2d6)") },
     { "BA_POIS_1", RandomArtActType::BA_POIS_1, 10, 300, 4, 0, _("悪臭雲(12)", "stinking cloud (12)") },
@@ -48,13 +47,13 @@ const std::vector<activation_type> activation_info = {
     { "CAST_BA_STAR", RandomArtActType::CAST_BA_STAR, 70, 7500, 100, 0, _("スター・ボール・ダスト(150)", "cast star balls (150)") },
     { "BLADETURNER", RandomArtActType::BLADETURNER, 80, 20000, 80, 0,
         _("エレメントのブレス(300), 士気高揚、祝福、耐性", "breathe elements (300), hero, bless, and resistance") },
-    { "BR_FIRE", RandomArtActType::BR_FIRE, 50, 5000, -1, 0, _("火炎のブレス (200)", "fire breath (200)") },
-    { "BR_COLD", RandomArtActType::BR_COLD, 50, 5000, -1, 0, _("冷気のブレス (200)", "cold breath (200)") },
+    { "BR_FIRE", RandomArtActType::BR_FIRE, 50, 5000, std::nullopt, 0, _("火炎のブレス (200)", "fire breath (200)") },
+    { "BR_COLD", RandomArtActType::BR_COLD, 50, 5000, std::nullopt, 0, _("冷気のブレス (200)", "cold breath (200)") },
     { "BR_DRAGON", RandomArtActType::BR_DRAGON, 70, 10000, 30, 0, "" /* built by item_activation_dragon_breath() */ },
     { "CONFUSE", RandomArtActType::CONFUSE, 10, 500, 10, 0, _("パニック・モンスター", "confuse monster") },
     { "SLEEP", RandomArtActType::SLEEP, 10, 750, 15, 0, _("周囲のモンスターを眠らせる", "sleep nearby monsters") },
     { "QUAKE", RandomArtActType::QUAKE, 30, 600, 20, 0, _("地震", "earthquake") },
-    { "TERROR", RandomArtActType::TERROR, 20, 2500, -1, 0, _("恐慌", "terror") },
+    { "TERROR", RandomArtActType::TERROR, 20, 2500, std::nullopt, 0, _("恐慌", "terror") },
     { "TELE_AWAY", RandomArtActType::TELE_AWAY, 20, 2000, 15, 0, _("テレポート・アウェイ", "teleport away") },
     { "BANISH_EVIL", RandomArtActType::BANISH_EVIL, 40, 2000, 250, 0, _("邪悪消滅", "banish evil") },
     { "GENOCIDE", RandomArtActType::GENOCIDE, 50, 10000, 500, 0, _("抹殺", "genocide") },
@@ -138,7 +137,7 @@ const std::vector<activation_type> activation_info = {
     { "CAST_OFF", RandomArtActType::CAST_OFF, 30, 15000, 100, 0, _("脱衣と小宇宙燃焼", "cast it off and cosmic heroism") },
     { "FISHING", RandomArtActType::FISHING, 0, 100, 0, 0, _("釣りをする", "fishing") },
     { "INROU", RandomArtActType::INROU, 40, 15000, 150, 150, _("例のアレ", "reveal your identity") },
-    { "MURAMASA", RandomArtActType::MURAMASA, 0, 0, -1, 0, _("腕力の上昇", "increase STR") },
+    { "MURAMASA", RandomArtActType::MURAMASA, 0, 0, std::nullopt, 0, _("腕力の上昇", "increase STR") },
     { "BLOODY_MOON", RandomArtActType::BLOODY_MOON, 0, 0, 3333, 0, _("属性変更", "change zokusei") },
 
     { "CRIMSON", RandomArtActType::CRIMSON, 0, 50000, 15, 0, _("ファイア!", "fire!") },
index 0a3af8e..3cb277a 100644 (file)
@@ -1,17 +1,19 @@
 #pragma once
 
+#include <optional>
 #include <string>
 #include <vector>
 
 enum class RandomArtActType : short;
-struct activation_type {
+class ActivationType {
+public:
     std::string flag;
     RandomArtActType index;
     int level;
     int value;
-    int constant; // 発動間隔の最低ターン数
+    std::optional<int> constant; // 発動間隔の最低ターン数
     int dice; // 発動間隔の追加ターン数
     std::string desc;
 };
 
-extern const std::vector<activation_type> activation_info;
+extern const std::vector<ActivationType> activation_info;
index 2b91fa0..ba75399 100644 (file)
@@ -773,7 +773,7 @@ bool ItemEntity::is_inscribed() const
  * @brief オブジェクトから発動効果構造体を取得する。
  * @return 発動効果構造体 (なかったら無効イテレータ)
  */
-std::vector<activation_type>::const_iterator ItemEntity::find_activation_info() const
+std::vector<ActivationType>::const_iterator ItemEntity::find_activation_info() const
 {
     const auto index = this->get_activation_index();
     return std::find_if(activation_info.begin(), activation_info.end(), [index](const auto &x) { return x.index == index; });
@@ -884,7 +884,7 @@ std::string ItemEntity::explain_activation() const
     return this->bi_key.explain_activation();
 }
 
-std::string ItemEntity::build_timeout_description(const activation_type &act) const
+std::string ItemEntity::build_timeout_description(const ActivationType &act) const
 {
     const auto constant = act.constant;
     const auto dice = act.dice;
@@ -892,11 +892,11 @@ std::string ItemEntity::build_timeout_description(const activation_type &act) co
         return _("いつでも", "every turn");
     }
 
-    if (constant >= 0) {
+    if (constant) {
         std::stringstream ss;
         ss << _("", "every ");
         if (constant > 0) {
-            ss << constant;
+            ss << *constant;
             if (dice > 0) {
                 ss << '+';
             }
@@ -1033,7 +1033,7 @@ RandomArtActType ItemEntity::get_activation_index() const
     return this->activation_id;
 }
 
-std::string ItemEntity::build_activation_description(const activation_type &act) const
+std::string ItemEntity::build_activation_description(const ActivationType &act) const
 {
     switch (act.index) {
     case RandomArtActType::NONE:
index edfeec3..e14d87b 100644 (file)
@@ -24,10 +24,10 @@ enum class ItemKindType : short;
 enum class SmithEffectType : int16_t;
 enum class RandomArtActType : short;
 
+class ActivationType;
 class ArtifactType;
-class EgoItemDefinition;
 class BaseitemInfo;
-struct activation_type;
+class EgoItemDefinition;
 class ItemEntity {
 public:
     ItemEntity();
@@ -140,7 +140,7 @@ public:
     bool is_armour() const;
     bool is_cross_bow() const;
     bool is_inscribed() const;
-    std::vector<activation_type>::const_iterator find_activation_info() const;
+    std::vector<ActivationType>::const_iterator find_activation_info() const;
     bool has_activation() const;
 
     BaseitemInfo &get_baseitem() const;
@@ -160,7 +160,7 @@ private:
     void modify_ego_lite_flags(TrFlags &flags) const;
     RandomArtActType get_activation_index() const;
     std::string build_activation_description() const;
-    std::string build_timeout_description(const activation_type &act) const;
-    std::string build_activation_description(const activation_type &act) const;
+    std::string build_timeout_description(const ActivationType &act) const;
+    std::string build_activation_description(const ActivationType &act) const;
     std::string build_activation_description_dragon_breath() const;
 };