From 4dca1efc2cc5dc6f369d54979c07608787a8e0a7 Mon Sep 17 00:00:00 2001 From: taotao54321 Date: Sat, 6 Feb 2021 15:18:45 +0900 Subject: [PATCH] =?utf8?q?[Fix]=20=E6=AD=A6=E5=99=A8=E3=81=AE=20(=E6=82=AA?= =?utf8?q?=E9=AD=94)=20=E3=82=A8=E3=82=B4=E3=81=AEAC=E4=BF=AE=E6=AD=A3?= =?utf8?q?=E3=81=8C=E5=B8=B8=E3=81=AB=20+1=20=E3=81=AB=E3=81=AA=E3=82=8B?= =?utf8?q?=E3=81=AE=E3=82=92=E7=9B=B4=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/object-enchant/apply-magic.c b/src/object-enchant/apply-magic.c index 1217034a3..e1a6cd3ce 100644 --- a/src/object-enchant/apply-magic.c +++ b/src/object-enchant/apply-magic.c @@ -35,6 +35,22 @@ #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) { -- 2.11.0