OSDN Git Service

[Fix] 武器の (悪魔) エゴのAC修正が常に +1 になるのを直した
authortaotao54321 <taotao54321@gmail.com>
Sat, 6 Feb 2021 06:18:45 +0000 (15:18 +0900)
committertaotao54321 <taotao54321@gmail.com>
Sat, 6 Feb 2021 06:18:45 +0000 (15:18 +0900)
ego_item_type 構造体の max_to_a メンバの型が u8 から i16 に変更されたことによるエンバグ。
負数を u8 にキャストした際の動作を前提とするコードが残っていた。
max_to_a < 0 なら [max_to_a,-1] のランダムなAC修正が得られるように直した。
また、max_to_h, max_to_d にも同様の問題があるので一応直しておく。

src/object-enchant/apply-magic.c

index 1217034..e1a6cd3 100644 (file)
 #include "world/world.h"
 
 /*!
+ * @brief 0 および負数に対応した randint1()
+ * @param n
+ *
+ * n == 0 のとき、常に 0 を返す。
+ * n >  0 のとき、[1, n] の乱数を返す。
+ * n <  0 のとき、[n,-1] の乱数を返す。
+ */
+static int randint1_signed(const int n)
+{
+    if (n == 0)
+        return 0;
+
+    return n > 0 ? randint1(n) : -randint1(-n);
+}
+
+/*!
  * @brief 生成されたベースアイテムに魔法的な強化を与えるメインルーチン
  * Complete the "creation" of an object by applying "magic" to the item
  * @param owner_ptr プレーヤーへの参照ポインタ
@@ -264,26 +280,9 @@ void apply_magic(player_type *owner_ptr, object_type *o_ptr, DEPTH lev, BIT_FLAG
             if (e_ptr->max_pval)
                 o_ptr->pval -= randint1(e_ptr->max_pval);
         } else {
-            if (e_ptr->max_to_h) {
-                if (e_ptr->max_to_h > 127)
-                    o_ptr->to_h -= randint1(256 - e_ptr->max_to_h);
-                else
-                    o_ptr->to_h += randint1(e_ptr->max_to_h);
-            }
-
-            if (e_ptr->max_to_d) {
-                if (e_ptr->max_to_d > 127)
-                    o_ptr->to_d -= randint1(256 - e_ptr->max_to_d);
-                else
-                    o_ptr->to_d += randint1(e_ptr->max_to_d);
-            }
-
-            if (e_ptr->max_to_a) {
-                if (e_ptr->max_to_a > 127)
-                    o_ptr->to_a -= randint1(256 - e_ptr->max_to_a);
-                else
-                    o_ptr->to_a += randint1(e_ptr->max_to_a);
-            }
+            o_ptr->to_h += randint1_signed(e_ptr->max_to_h);
+            o_ptr->to_d += randint1_signed(e_ptr->max_to_d);
+            o_ptr->to_a += randint1_signed(e_ptr->max_to_a);
 
             if (o_ptr->name2 == EGO_ACCURACY) {
                 while (o_ptr->to_h < o_ptr->to_d + 10) {