OSDN Git Service

[Refactor] #41001 コードの整理をして不要な宣言等をなくした。 / Arrage declarations of variables and a...
authoriks <iks@users.sorceforge.jp>
Mon, 23 Nov 2020 10:14:42 +0000 (19:14 +0900)
committeriks <iks@users.sorceforge.jp>
Mon, 23 Nov 2020 10:14:42 +0000 (19:14 +0900)
src/birth/auto-roller.c
src/birth/auto-roller.h
src/birth/birth-stat.c

index 33cb6cd..142d65c 100644 (file)
 /*! オートローラの能力値的要求水準 / 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<sum<87) */
+    s32b tot_rand_1p = 320669745;
+    int i, j, tmp;
+    int ii[6];
+    int tval[6];
+    int tot = 0;
+
+    /* success count */
+    s32b succ = 0;
+
+    /* random combinations out of 60 (1d3+1d4+1d5) patterns */
+    int pp[18] = {
+        0, 0, 0, 0, 0, 0, 0, 0, /* 0-7 */
+        1, 3, 6, 9, 11, 11, 9, 6, 3, 1 /* 8-17 */
+    };
+
+    /* Copy */
+    for (i = 0; i < 6; i++) {
+        tval[i] = MAX(8, minval[i]);
+        tot += tval[i];
+    }
+
+    /* No Chance */
+    if (tot > 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<sum<87) */
-    s32b tot_rand_1p = 320669745;
-    int i, j, tmp;
-    int ii[6];
-    int tval[6];
-    int tot = 0;
-
-    /* success count */
-    s32b succ = 0;
-
-    /* random combinations out of 60 (1d3+1d4+1d5) patterns */
-    int pp[18] = {
-        0, 0, 0, 0, 0, 0, 0, 0, /* 0-7 */
-        1, 3, 6, 9, 11, 11, 9, 6, 3, 1 /* 8-17 */
-    };
-
-    /* Copy */
-    for (i = 0; i < 6; i++) 
-    {
-        tval[i] = MAX(8, minval[i]);
-        tot += tval[i];
-    }
-
-    /* No Chance */
-    if (tot > 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;
-}
index 318d5bf..df6040e 100644 (file)
@@ -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);
index 290e59f..06e7776 100644 (file)
 #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 現在の能力値