OSDN Git Service

[Feature] 鍛冶効果を付与したアイテムの仕様変更
authorHabu <habu1010+github@gmail.com>
Tue, 14 Sep 2021 22:06:16 +0000 (07:06 +0900)
committerHabu <habu1010+github@gmail.com>
Wed, 15 Sep 2021 14:13:42 +0000 (23:13 +0900)
今まで付与した鍛冶効果を object_type::xtra3(他の情報と共用) に持たせていたが
そこまでメモリをケチる必要も無いので専用の効果保存メンバ
object_type::smith_effect を設けてそこに格納するようにする。
また、発動効果の付与を別枠でできるようにするための準備として、発動効果を
格納する object_type::smith_act_idx も用意しておく。

src/load/item-loader.cpp
src/load/savedata-flag-types.h
src/object-enchant/object-smith.cpp
src/object-enchant/smith-info.cpp
src/object-enchant/smith-types.h
src/save/item-writer.cpp
src/system/object-type-definition.h

index 393e090..10fc6e9 100644 (file)
@@ -213,6 +213,18 @@ void rd_item(object_type *o_ptr)
     else
         o_ptr->stack_idx = 0;
 
+    if ((flags & SAVE_ITEM_SMITH) && !loading_savefile_version_is_older_than(7)) {
+        int16_t tmp16s;
+        rd_s16b(&tmp16s);
+        if (tmp16s > 0) {
+            o_ptr->smith_effect = static_cast<SmithEffect>(tmp16s);
+        }
+        rd_s16b(&tmp16s);
+        if (tmp16s > 0) {
+            o_ptr->smith_act_idx = static_cast<random_art_activation_type>(tmp16s);
+        }
+    }
+
     if (flags & SAVE_ITEM_INSCRIPTION) {
         char buf[128];
         rd_string(buf, sizeof(buf));
index cffbf7d..cf488aa 100644 (file)
@@ -15,7 +15,7 @@ enum savedata_item_flag_type {
        SAVE_ITEM_DS = 0x00000800,
        SAVE_ITEM_IDENT = 0x00001000,
        SAVE_ITEM_MARKED = 0x00002000,
-       SAVE_ITEM_00004000 = 0x00004000, //<! 未使用
+       SAVE_ITEM_SMITH = 0x00004000,
        SAVE_ITEM_00008000 = 0x00008000, //<! 未使用
        SAVE_ITEM_00010000 = 0x00010000, //<! 未使用
        SAVE_ITEM_00020000 = 0x00020000, //<! 未使用
index 85f9823..cd89f8c 100644 (file)
@@ -235,12 +235,7 @@ std::optional<random_art_activation_type> Smith::get_effect_activation(SmithEffe
  */
 std::optional<SmithEffect> Smith::object_effect(const object_type *o_ptr)
 {
-    auto effect = i2enum<SmithEffect>(o_ptr->xtra3);
-    if (!o_ptr->is_weapon_armour_ammo() || effect == SmithEffect::NONE) {
-        return std::nullopt;
-    }
-
-    return effect;
+    return o_ptr->smith_effect;
 }
 
 /*!
index 3a7a25d..cab785a 100644 (file)
@@ -33,14 +33,14 @@ BasicSmithInfo::BasicSmithInfo(SmithEffect effect, concptr name, SmithCategory c
 
 bool BasicSmithInfo::add_essence(player_type *, object_type *o_ptr, int) const
 {
-    o_ptr->xtra3 = static_cast<decltype(o_ptr->xtra3)>(effect);
+    o_ptr->smith_effect = effect;
 
     return true;
 }
 
 void BasicSmithInfo::erase_essence(object_type *o_ptr) const
 {
-    o_ptr->xtra3 = 0;
+    o_ptr->smith_effect = std::nullopt;
     auto flgs = object_flags(o_ptr);
     if (flgs.has_none_of(TR_PVAL_FLAG_MASK))
         o_ptr->pval = 0;
index b692d0a..3beb9df 100644 (file)
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
 
 #include "system/system-variables.h"
 
@@ -126,7 +126,7 @@ enum class SmithEffect {
     RESISTANCE = 220, //!< 全耐性
     SLAY_GLOVE = 221, //!< 殺戮の小手
 
-    SAVE_EFFECT_MAX = 256, //!< 鍛冶師の銘付きアイテムに付与された鍛冶効果の保存領域が1バイトなので、この値未満を割り当てる必要あり
+    SAVE_EFFECT_MAX = 8192, //!< 鍛冶師の銘付きアイテムに付与された鍛冶効果の保存領域は2バイト。とりあえず余裕を持って8192としておく。
 
     //! @note これ以降は鍛冶師の銘付きアイテムになる鍛冶効果ではないので、効果番号を保存しなくてよい。
     //  鍛冶効果のリストを管理するためだけのものである。したがって SAVE_EFFECT_MAX 以降に自動的に番号の割り振りを行う
index fcd9a45..d28c265 100644 (file)
@@ -3,6 +3,7 @@
 #include "object/object-kind.h"
 #include "save/save-util.h"
 #include "system/object-type-definition.h"
+#include "util/enum-converter.h"
 #include "util/quarks.h"
 
 static void write_item_flags(object_type *o_ptr, BIT_FLAGS *flags)
@@ -85,6 +86,10 @@ static void write_item_flags(object_type *o_ptr, BIT_FLAGS *flags)
     if (o_ptr->stack_idx)
         *flags |= SAVE_ITEM_STACK_IDX;
 
+    if (o_ptr->is_smith()) {
+        *flags |= SAVE_ITEM_SMITH;
+    }
+
     wr_u32b(*flags);
 }
 
@@ -153,6 +158,19 @@ static void write_item_info(object_type *o_ptr, const BIT_FLAGS flags)
 
     if (flags & SAVE_ITEM_STACK_IDX)
         wr_s16b(o_ptr->stack_idx);
+
+    if (flags & SAVE_ITEM_SMITH) {
+        if (o_ptr->smith_effect.has_value()){
+            wr_s16b(enum2i(o_ptr->smith_effect.value()));
+        } else {
+            wr_s16b(0);
+        }
+        if (o_ptr->smith_act_idx.has_value()) {
+            wr_s16b(enum2i(o_ptr->smith_act_idx.value()));
+        } else {
+            wr_s16b(0);
+        }
+    }
 }
 
 /*!
index e3e8766..b160377 100644 (file)
@@ -7,13 +7,17 @@
  * @date 2021/05/02
  */
 
+#include "object-enchant/tr-flags.h"
 #include "object-enchant/trc-types.h"
 #include "object/tval-types.h"
 #include "system/angband.h"
 #include "system/system-variables.h"
 #include "util/flag-group.h"
 
-#include "object-enchant/tr-flags.h"
+#include <optional>
+
+enum class SmithEffect;
+enum random_art_activation_type : uint8_t;
 
 struct player_type;
 typedef struct object_type {
@@ -33,10 +37,13 @@ typedef struct object_type {
 
     XTRA8 xtra1{}; /*!< Extra info type (now unused) */
     XTRA16 xtra2{}; /*!< エゴ/アーティファクトの発動ID / Extra info activation index */
-    XTRA8 xtra3{}; /*!< 複数の使用用途 捕らえたモンスターの速度,付加した特殊なエッセンスID / Extra info for weaponsmith */
+    XTRA8 xtra3{}; /*!< 複数の使用用途 捕らえたモンスターの速度 / Extra info */
     XTRA16 xtra4{}; /*!< 複数の使用用途 光源の残り寿命、あるいは捕らえたモンスターの現HP / Extra info fuel or captured monster's current HP */
     XTRA16 xtra5{}; /*!< 複数の使用用途 捕らえたモンスターの最大HP / Extra info captured monster's max HP */
 
+    std::optional<SmithEffect> smith_effect; //!< 鍛冶で付与された効果
+    std::optional<random_art_activation_type> smith_act_idx; //!< 鍛冶で付与された発動効果のID
+
     HIT_PROB to_h{}; /*!< Plusses to hit */
     HIT_POINT to_d{}; /*!< Plusses to damage */
     ARMOUR_CLASS to_a{}; /*!< Plusses to AC */