OSDN Git Service

[Refactor] #2617 Habu氏の助言に従い、イテレータを直接参照したりArtifactType 型の戻り値をvoidにしたりした
authorHourier <66951241+Hourier@users.noreply.github.com>
Tue, 13 Sep 2022 13:17:08 +0000 (22:17 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Tue, 13 Sep 2022 14:33:03 +0000 (23:33 +0900)
src/artifact/fixed-art-generator.cpp
src/artifact/fixed-art-generator.h
src/object-enchant/item-magic-applier.cpp
src/save/save.cpp
src/wizard/wizard-special-process.cpp

index e7efa72..a145f3f 100644 (file)
@@ -223,23 +223,21 @@ static void invest_curse_to_fixed_artifact(const ArtifactType &a_ref, ObjectType
  * @param o_ptr 生成に割り当てたいオブジェクトの構造体参照ポインタ
  * @return 適用したアーティファクト情報への参照ポインタ
  */
-std::unique_ptr<ArtifactType> apply_artifact(PlayerType *player_ptr, ObjectType *o_ptr)
+void apply_artifact(PlayerType *player_ptr, ObjectType *o_ptr)
 {
-    auto a_ptr = std::make_unique<ArtifactType>(a_info.at(o_ptr->fixed_artifact_idx));
-    o_ptr->pval = a_ptr->pval;
-    o_ptr->ac = a_ptr->ac;
-    o_ptr->dd = a_ptr->dd;
-    o_ptr->ds = a_ptr->ds;
-    o_ptr->to_a = a_ptr->to_a;
-    o_ptr->to_h = a_ptr->to_h;
-    o_ptr->to_d = a_ptr->to_d;
-    o_ptr->weight = a_ptr->weight;
-    o_ptr->activation_id = a_ptr->act_idx;
-
-    invest_curse_to_fixed_artifact(*a_ptr, o_ptr);
-    fixed_artifact_random_abilities(player_ptr, *a_ptr, o_ptr);
-
-    return a_ptr;
+    auto &a_ref = a_info.at(o_ptr->fixed_artifact_idx);
+    o_ptr->pval = a_ref.pval;
+    o_ptr->ac = a_ref.ac;
+    o_ptr->dd = a_ref.dd;
+    o_ptr->ds = a_ref.ds;
+    o_ptr->to_a = a_ref.to_a;
+    o_ptr->to_h = a_ref.to_h;
+    o_ptr->to_d = a_ref.to_d;
+    o_ptr->weight = a_ref.weight;
+    o_ptr->activation_id = a_ref.act_idx;
+
+    invest_curse_to_fixed_artifact(a_ref, o_ptr);
+    fixed_artifact_random_abilities(player_ptr, a_ref, o_ptr);
 }
 
 /*!
@@ -271,7 +269,7 @@ bool create_named_art(PlayerType *player_ptr, FixedArtifactId a_idx, POSITION y,
     q_ptr->prep(i);
     q_ptr->fixed_artifact_idx = a_idx;
 
-    (void)apply_artifact(player_ptr, q_ptr);
+    apply_artifact(player_ptr, q_ptr);
 
     return drop_near(player_ptr, q_ptr, -1, y, x) > 0;
 }
index ebb72a7..f235cd1 100644 (file)
@@ -5,7 +5,6 @@
  */
 
 #include "system/angband.h"
-#include <memory>
 
 enum class FixedArtifactId : short;
 class ArtifactType;
@@ -13,5 +12,5 @@ class ObjectType;
 class PlayerType;
 bool create_named_art(PlayerType *player_ptr, FixedArtifactId a_idx, POSITION y, POSITION x);
 bool make_artifact(PlayerType *player_ptr, ObjectType *o_ptr);
-std::unique_ptr<ArtifactType> apply_artifact(PlayerType *player_ptr, ObjectType *o_ptr);
+void apply_artifact(PlayerType *player_ptr, ObjectType *o_ptr);
 bool make_artifact_special(PlayerType *player_ptr, ObjectType *o_ptr);
index d5effc0..8463768 100644 (file)
@@ -181,10 +181,11 @@ bool ItemMagicApplier::set_fixed_artifact_generation_info()
         return false;
     }
 
-    auto a_ptr = apply_artifact(this->player_ptr, this->o_ptr);
-    a_ptr->is_generated = true;
+    apply_artifact(this->player_ptr, this->o_ptr);
+    auto &a_ref = a_info.at(this->o_ptr->fixed_artifact_idx);
+    a_ref.is_generated = true;
     if (w_ptr->character_dungeon) {
-        a_ptr->floor_id = this->player_ptr->floor_id;
+        a_ref.floor_id = this->player_ptr->floor_id;
     }
 
     return true;
index 9095889..5b0f839 100644 (file)
@@ -174,7 +174,7 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type)
     for (auto i = 0U; i < tmp16u; i++) {
         const auto a_idx = i2enum<FixedArtifactId>(i);
         const auto it = a_info.find(a_idx);
-        const auto &a_ref = it != a_info.end() ? a_info.at(a_idx) : dummy;
+        const auto &a_ref = it != a_info.end() ? it->second : dummy;
         wr_bool(a_ref.is_generated);
         wr_s16b(a_ref.floor_id);
     }
index 346dc53..1ff56b9 100644 (file)
@@ -390,7 +390,7 @@ void wiz_create_named_art(PlayerType *player_ptr)
         return;
     }
 
-    auto &a_ref = a_info.at(a_idx);
+    auto &a_ref = it->second;
     if (a_ref.is_generated) {
         msg_print("It's already allocated.");
         return;