OSDN Git Service

[Refactor] Habu氏の指摘に対応した
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 2 Oct 2021 05:25:56 +0000 (14:25 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 2 Oct 2021 06:58:58 +0000 (15:58 +0900)
src/action/activation-execution.cpp
src/artifact/artifact-info.cpp
src/artifact/artifact-info.h
src/artifact/random-art-effects.h
src/object-enchant/activation-info-table.cpp
src/object-enchant/activation-info-table.h
src/object/object-info.cpp
src/object/object-value-calc.cpp

index 155dcb3..61274ae 100644 (file)
@@ -57,7 +57,7 @@ static void decide_activation_level(ae_type *ae_ptr)
     if (ae_ptr->o_ptr->is_random_artifact()) {
         auto act_ptr = find_activation_info(ae_ptr->o_ptr);
         if (act_ptr.has_value()) {
-            ae_ptr->lev = act_ptr->level;
+            ae_ptr->lev = act_ptr.value()->level;
         }
 
         return;
@@ -142,13 +142,14 @@ static bool check_activation_conditions(player_type *player_ptr, ae_type *ae_ptr
 static bool activate_artifact(player_type *player_ptr, object_type *o_ptr)
 {
     concptr name = k_info[o_ptr->k_idx].name.c_str();
-    auto act_ptr = find_activation_info(o_ptr);
-    if (!act_ptr.has_value()) {
+    auto tmp_act_ptr = find_activation_info(o_ptr);
+    if (!tmp_act_ptr.has_value()) {
         msg_print("Activation information is not found.");
         return false;
     }
 
-    if (!switch_activation(player_ptr, &o_ptr, &act_ptr.value(), name)) {
+    auto *act_ptr = tmp_act_ptr.value();
+    if (!switch_activation(player_ptr, &o_ptr, act_ptr, name)) {
         return false;
     }
 
index 31ea7ab..c705422 100644 (file)
@@ -45,12 +45,12 @@ int activation_index(const object_type *o_ptr)
  * @param o_ptr 対象のオブジェクト構造体ポインタ
  * @return 発動効果構造体のポインタを返す
  */
-const std::optional<activation_type> find_activation_info(const object_type *o_ptr)
+std::optional<const activation_type *> find_activation_info(const object_type *o_ptr)
 {
     const auto index = activation_index(o_ptr);
-    for (auto &p : activation_info) {
+    for (const auto &p : activation_info) {
         if (p.index == index) {
-            return p;
+            return &p;
         }
     }
 
index ed767b3..141c0f1 100644 (file)
@@ -10,4 +10,4 @@
 struct activation_type;
 struct object_type;;
 int activation_index(const object_type *o_ptr);
-const std::optional<activation_type> find_activation_info(const object_type *o_ptr);
+std::optional<const activation_type *> find_activation_info(const object_type *o_ptr);
index 21fa750..93900ad 100644 (file)
@@ -7,6 +7,7 @@
  * @brief ランダムアーティファクトの発動ID定義
  */
 enum random_art_activation_type : uint8_t {
+    ACT_NONE = 0,
     ACT_SUNLIGHT = 1,
     ACT_BO_MISS_1 = 2,
     ACT_BA_POIS_1 = 3,
index daf1e78..edad43b 100644 (file)
@@ -152,5 +152,5 @@ const std::vector<activation_type> activation_info = {
     { "ELBERETH", ACT_ELBERETH, 10, 30000, { 75, 0 }, _("エルベレスの結界", "Rune of Elbereth") },
     { "DETECT_TREASURE", ACT_DETECT_TREASURE, 10, 3000, {35, 0}, _("財宝感知", "detect treasure") },
 
-    { nullptr, 0, 0, 0, { 0, 0 }, "" },
+    { nullptr, ACT_NONE, 0, 0, { 0, 0 }, "" },
 };
index 1d8b0b4..d18f6c0 100644 (file)
@@ -3,9 +3,10 @@
 #include "system/angband.h"
 #include <vector>
 
+enum random_art_activation_type : uint8_t;
 struct activation_type {
     concptr flag;
-    byte index;
+    random_art_activation_type index;
     byte level;
     int32_t value;
     struct {
index 2330091..aca8986 100644 (file)
@@ -75,8 +75,8 @@ static concptr item_activation_aux(object_type *o_ptr)
         return _("未定義", "something undefined");
     }
 
-    concptr desc = act_ptr->desc;
-    switch (act_ptr->index) {
+    concptr desc = act_ptr.value()->desc;
+    switch (act_ptr.value()->index) {
     case ACT_BR_FIRE:
         if ((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_FLAMES))
             desc = _("火炎のブレス (200) と火への耐性", "breathe fire (200) and resist fire");
@@ -125,14 +125,14 @@ static concptr item_activation_aux(object_type *o_ptr)
     }
 
     /* Timeout description */
-    int constant = act_ptr->timeout.constant;
-    int dice = act_ptr->timeout.dice;
+    int constant = act_ptr.value()->timeout.constant;
+    int dice = act_ptr.value()->timeout.dice;
     if (constant == 0 && dice == 0) {
         /* We can activate it every turn */
         strcpy(timeout, _("いつでも", "every turn"));
     } else if (constant < 0) {
         /* Activations that have special timeout */
-        switch (act_ptr->index) {
+        switch (act_ptr.value()->index) {
         case ACT_BR_FIRE:
             sprintf(timeout, _("%d ターン毎", "every %d turns"), ((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_FLAMES)) ? 200 : 250);
             break;
index cddb272..2d8a538 100644 (file)
@@ -444,7 +444,7 @@ PRICE flag_cost(const object_type *o_ptr, int plusses)
     if (o_ptr->art_name && (o_ptr->art_flags.has(TR_ACTIVATE))) {
         auto act_ptr = find_activation_info(o_ptr);
         if (act_ptr.has_value()) {
-            total += act_ptr->value;
+            total += act_ptr.value()->value;
         }
     }