From 7d0cba630c4fe4397c3793068e6c94690eb4b149 Mon Sep 17 00:00:00 2001 From: iks Date: Mon, 23 Nov 2020 19:14:42 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#41001=20=E3=82=B3=E3=83=BC?= =?utf8?q?=E3=83=89=E3=81=AE=E6=95=B4=E7=90=86=E3=82=92=E3=81=97=E3=81=A6?= =?utf8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E5=AE=A3=E8=A8=80=E7=AD=89=E3=82=92?= =?utf8?q?=E3=81=AA=E3=81=8F=E3=81=97=E3=81=9F=E3=80=82=20/=20Arrage=20dec?= =?utf8?q?larations=20of=20variables=20and=20a=20funciton.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/birth/auto-roller.c | 160 +++++++++++++++++++++++------------------------- src/birth/auto-roller.h | 16 +---- src/birth/birth-stat.c | 10 +++ 3 files changed, 88 insertions(+), 98 deletions(-) diff --git a/src/birth/auto-roller.c b/src/birth/auto-roller.c index 33cb6cdc0..142d65c35 100644 --- a/src/birth/auto-roller.c +++ b/src/birth/auto-roller.c @@ -16,13 +16,87 @@ /*! オートローラの能力値的要求水準 / Autoroll limit */ s16b stat_limit[6]; -/*! オートローラ中、各能力値が水準を超えた回数 / Autoroll matches */ -s32b stat_match[6]; - /*! オートローラの試行回数 / Autoroll round */ s32b auto_round; s32b auto_upper_round; +/*! オートローラの要求値実現確率 */ +s32b autoroll_chance; + +/*! + * @breif オートローラーで指定した能力値以上が出る確率を計算する。 + * @return 確率 / 100 + */ +static s32b get_autoroller_prob(int *minval) +{ + /* 1 percent of the valid random space (60^6 && 72 86) + return -999; + + /* bubble sort for speed-up */ + for (i = 0; i < 5; i++) { + for (j = 5; j > i; j--) { + if (tval[j - 1] < tval[j]) { + tmp = tval[j - 1]; + tval[j - 1] = tval[j]; + tval[j] = tmp; + } + } + } + + tot = 0; + + /* calc. prob. */ + for (ii[0] = tval[0]; ii[0] < 18; ii[0]++) { + for (ii[1] = tval[1]; ii[1] < 18; ii[1]++) { + for (ii[2] = tval[2]; ii[2] < 18; ii[2]++) { + for (ii[3] = tval[3]; ii[3] < 18; ii[3]++) { + for (ii[4] = tval[4]; ii[4] < 18; ii[4]++) { + for (ii[5] = tval[5]; ii[5] < 18; ii[5]++) { + tot = ii[0] + ii[1] + ii[2] + ii[3] + ii[4] + ii[5]; + + if (tot > 86) + break; + if (tot <= 72) + continue; + + succ += (pp[ii[0]] * pp[ii[1]] * pp[ii[2]] * pp[ii[3]] * pp[ii[4]] * pp[ii[5]]); + + /* If given condition is easy enough, quit calc. to save CPU. */ + if (succ > 320670) + return -1; + } + } + } + } + } + } + + return tot_rand_1p / succ; +} + /*! * @brief オートローラで得たい能力値の基準を決める。 * @param creature_ptr プレーヤーへの参照ポインタ @@ -455,83 +529,3 @@ bool get_chara_limits(player_type *creature_ptr, chara_limit_type *chara_limit_p chara_limit_ptr->scmax = (s16b)cval[7]; return TRUE; } - -/* - * @breif オートローラーで指定した能力値以上が出る確率を計算する。 - * @return 確率 / 100 - */ - static s32b get_autoroller_prob(int *minval) -{ - /* 1 percent of the valid random space (60^6 && 72 86) return -999; - - /* bubble sort for speed-up */ - for (i = 0; i < 5; i++) - { - for (j = 5; j > i; j--) - { - if (tval[j - 1] < tval[j]) - { - tmp = tval[j - 1]; - tval[j - 1] = tval[j]; - tval[j] = tmp; - } - } - } - - tot = 0; - - /* calc. prob. */ - for (ii[0] = tval[0]; ii[0] < 18; ii[0]++) - { - for (ii[1] = tval[1]; ii[1] < 18; ii[1]++) - { - for (ii[2] = tval[2]; ii[2] < 18; ii[2]++) - { - for (ii[3] = tval[3]; ii[3] < 18; ii[3]++) - { - for (ii[4] = tval[4]; ii[4] < 18; ii[4]++) - { - for (ii[5] = tval[5]; ii[5] < 18; ii[5]++) - { - tot = ii[0] + ii[1] + ii[2] + ii[3] + ii[4] + ii[5]; - - if (tot > 86) break; - if (tot <= 72) continue; - - succ += (pp[ii[0]] * pp[ii[1]] * pp[ii[2]] * pp[ii[3]] * pp[ii[4]] * pp[ii[5]]); - - /* If given condition is easy enough, quit calc. to save CPU. */ - if (succ > 320670) return -1; - } - } - } - } - } - } - - return tot_rand_1p / succ; -} diff --git a/src/birth/auto-roller.h b/src/birth/auto-roller.h index 318d5bfa4..df6040ef2 100644 --- a/src/birth/auto-roller.h +++ b/src/birth/auto-roller.h @@ -11,24 +11,10 @@ typedef struct { } chara_limit_type; extern s16b stat_limit[6]; -extern s32b stat_match[6]; extern s32b auto_round; extern s32b auto_upper_round; - -/*! オートローラの要求値実現確率 */ -static s32b autoroll_chance; - -/* emulate 5 + 1d3 + 1d4 + 1d5 by randint0(60) */ -static BASE_STATUS rand3_4_5[60] = { - 8, 9, 9, 9, 10, 10, 10, 10, 10, 10, /*00-09*/ - 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, /*10-19*/ - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, /*20-29*/ - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, /*30-49*/ - 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, /*40-49*/ - 15, 15, 15, 15, 15, 15, 16, 16, 16, 17 /*50-59*/ -}; +extern s32b autoroll_chance; bool get_stat_limits(player_type *creature_ptr); void initialize_chara_limit(chara_limit_type *chara_limit_ptr); bool get_chara_limits(player_type *creature_ptr, chara_limit_type *chara_limit_ptr); -static s32b get_autoroller_prob(int *minval); diff --git a/src/birth/birth-stat.c b/src/birth/birth-stat.c index 290e59f8c..06e7776c4 100644 --- a/src/birth/birth-stat.c +++ b/src/birth/birth-stat.c @@ -10,6 +10,16 @@ #include "spell/spells-status.h" #include "player/player-race-types.h" +/*! オートロール能力値の乱数分布 / emulate 5 + 1d3 + 1d4 + 1d5 by randint0(60) */ +BASE_STATUS rand3_4_5[60] = { + 8, 9, 9, 9, 10, 10, 10, 10, 10, 10, /*00-09*/ + 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, /*10-19*/ + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, /*20-29*/ + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, /*30-49*/ + 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, /*40-49*/ + 15, 15, 15, 15, 15, 15, 16, 16, 16, 17 /*50-59*/ +}; + /*! * @brief プレイヤーの能力値表現に基づいて加減算を行う。 * @param value 現在の能力値 -- 2.11.0