• R/O
  • HTTP
  • SSH
  • HTTPS

hengband: Commit

変愚蛮怒のメインリポジトリです


Commit MetaInfo

Revisão40ed37984772aec7ddce90d17c1d01ae30f60ade (tree)
Hora2017-09-14 22:03:41
AutorDeskull <desull@user...>
CommiterDeskull

Mensagem de Log

hradishさんから寄稿してもらったオートローラーのブランチ。 / Branch auto-roller by hradish.

Mudança Sumário

Diff

--- a/src/birth.c
+++ b/src/birth.c
@@ -21,7 +21,7 @@
2121 * system may have problems because the user can't stop the
2222 * autoroller for this number of rolls.
2323 */
24-#define AUTOROLLER_STEP 5431L
24+#define AUTOROLLER_STEP 54321L
2525
2626 #if 0
2727 /*!
@@ -2046,6 +2046,9 @@ static cptr realm_subinfo[VALID_REALM] =
20462046 /*! オートローラの能力値的要求水準 / Autoroll limit */
20472047 static s16b stat_limit[6];
20482048
2049+/*! オートローラの要求値実現確率 */
2050+static s32b autoroll_chance;
2051+
20492052 /*! オートローラの年齢、身長、体重、社会的地位の要求水準 */
20502053 static struct {
20512054 s16b agemin, agemax;
@@ -2054,11 +2057,20 @@ static struct {
20542057 s16b scmin, scmax;
20552058 } chara_limit;
20562059
2057-/*! オートローラ中、各能力値が水準を超えた回数 / Autoroll matches */
2058-static s32b stat_match[6];
2059-
20602060 /*! オートローラの試行回数 / Autoroll round */
20612061 static s32b auto_round;
2062+static s32b auto_round2;
2063+
2064+/* emulate 5 + 1d3 + 1d4 + 1d5 by randint0(60) */
2065+const int rand3_4_5[60] =
2066+{
2067+ 8, 9, 9, 9, 10, 10, 10, 10, 10, 10, /*00-09*/
2068+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, /*10-19*/
2069+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, /*20-29*/
2070+ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, /*30-49*/
2071+ 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, /*40-49*/
2072+ 15, 15, 15, 15, 15, 15, 16, 16, 16, 17 /*50-59*/
2073+};
20622074
20632075 /*!
20642076 * @brief プレイヤー作成を中断して変愚蛮怒を終了する
@@ -2676,48 +2688,45 @@ static void get_stats(void)
26762688 while (TRUE)
26772689 {
26782690 int i;
2691+ int j = 0;
26792692 int sum = 0;
2680-
2693+ int val;
2694+ s32b tmp;
26812695 /* Roll some dice */
26822696 for (i = 0; i < 2; i++)
26832697 {
2684- s32b tmp = randint0(60*60*60);
2685- int val;
2698+ /* randint0(60*60*60) for 3 stats. */
2699+ tmp = randint0(216000);
26862700
26872701 /* Extract 5 + 1d3 + 1d4 + 1d5 */
2688- val = 5 + 3;
2689- val += tmp % 3; tmp /= 3;
2690- val += tmp % 4; tmp /= 4;
2691- val += tmp % 5; tmp /= 5;
2702+ val = rand3_4_5[tmp % 60];
26922703
26932704 /* Save that value */
26942705 sum += val;
2695- p_ptr->stat_cur[3*i] = p_ptr->stat_max[3*i] = val;
2706+ p_ptr->stat_cur[j] = p_ptr->stat_max[j] = val;
2707+ j++;
26962708
2709+ tmp /= 60;
26972710 /* Extract 5 + 1d3 + 1d4 + 1d5 */
2698- val = 5 + 3;
2699- val += tmp % 3; tmp /= 3;
2700- val += tmp % 4; tmp /= 4;
2701- val += tmp % 5; tmp /= 5;
2711+ val = rand3_4_5[tmp % 60];
27022712
27032713 /* Save that value */
27042714 sum += val;
2705- p_ptr->stat_cur[3*i+1] = p_ptr->stat_max[3*i+1] = val;
2715+ p_ptr->stat_cur[j] = p_ptr->stat_max[j] = val;
2716+ j++;
27062717
2718+ tmp /= 60;
27072719 /* Extract 5 + 1d3 + 1d4 + 1d5 */
2708- val = 5 + 3;
2709- val += tmp % 3; tmp /= 3;
2710- val += tmp % 4; tmp /= 4;
2711- val += tmp;
2720+ val = rand3_4_5[tmp];
27122721
27132722 /* Save that value */
27142723 sum += val;
2715- p_ptr->stat_cur[3*i+2] = p_ptr->stat_max[3*i+2] = val;
2724+ p_ptr->stat_cur[j] = p_ptr->stat_max[j] = val;
2725+ j++;
27162726 }
27172727
27182728 /* Verify totals */
2719- if ((sum > 42+5*6) && (sum < 57+5*6)) break;
2720- /* 57 was 54... I hate 'magic numbers' :< TY */
2729+ if ((sum > 72) && (sum < 87)) break;
27212730 }
27222731 }
27232732
@@ -3165,15 +3174,14 @@ static void get_money(void)
31653174 */
31663175 static void birth_put_stats(void)
31673176 {
3168- int i, j, m, p;
3177+ int i, j, m;
31693178 int col;
3170- byte attr;
31713179 char buf[80];
31723180
31733181
31743182 if (autoroller)
31753183 {
3176- col = 42;
3184+ col = 22;
31773185 /* Put the stats (and percents) */
31783186 for (i = 0; i < 6; i++)
31793187 {
@@ -3186,35 +3194,6 @@ static void birth_put_stats(void)
31863194 /* Put the stat */
31873195 cnv_stat(m, buf);
31883196 c_put_str(TERM_L_GREEN, buf, 3+i, col+24);
3189-
3190- /* Put the percent */
3191- if (stat_match[i])
3192- {
3193- if (stat_match[i] > 1000000L)
3194- {
3195- /* Prevent overflow */
3196- p = stat_match[i] / (auto_round / 1000L);
3197- }
3198- else
3199- {
3200- p = 1000L * stat_match[i] / auto_round;
3201- }
3202-
3203- attr = (p < 100) ? TERM_YELLOW : TERM_L_GREEN;
3204- sprintf(buf, "%3d.%d%%", p/10, p%10);
3205- c_put_str(attr, buf, 3+i, col+13);
3206- }
3207-
3208- /* Never happened */
3209- else
3210- {
3211-#ifdef JP
3212- c_put_str(TERM_RED, "(なし)", 3+i, col+13);
3213-#else
3214- c_put_str(TERM_RED, "(NONE)", 3+i, col+13);
3215-#endif
3216-
3217- }
32183197 }
32193198 }
32203199 }
@@ -4807,6 +4786,83 @@ static bool get_player_seikaku(void)
48074786 return TRUE;
48084787 }
48094788
4789+/*
4790+ calc. probability of satisfying the required status set
4791+ return : inverted prob. / 100
4792+*/
4793+static s32b get_autoroller_prob(int *minval){
4794+
4795+ /* 1 percent of the valid random space (60^6 && 72<sum<87) */
4796+ s32b tot_rand_1p = 320669745;
4797+ int i, j, tmp;
4798+ int ii[6];
4799+ int tval[6];
4800+ int tot = 0;
4801+ /* success count */
4802+ s32b succ = 0;
4803+ /* random combinations out of 60 (1d3+1d4+1d5) patterns */
4804+ int pp[18] =
4805+ {
4806+ 0, 0, 0, 0, 0, 0, 0, 0, /* 0-7 */
4807+ 1, 3, 6, 9, 11, 11, 9, 6, 3, 1 /* 8-17 */
4808+ };
4809+
4810+ /* Copy */
4811+ for(i = 0; i < 6; i++)
4812+ {
4813+ tval[i] = MAX(8, minval[i]);
4814+ tot += tval[i];
4815+ }
4816+
4817+ /* No Chance */
4818+ if(tot > 86) return -999;
4819+
4820+ /* bubble sort for speed-up */
4821+ for(i = 0; i < 5; i++)
4822+ {
4823+ for(j = 5; j > i; j--)
4824+ {
4825+ if(tval[j-1] < tval[j])
4826+ {
4827+ tmp = tval[j-1];
4828+ tval[j-1] = tval[j];
4829+ tval[j] = tmp;
4830+ }
4831+ }
4832+ }
4833+
4834+ tot = 0;
4835+
4836+ /* calc. prob. */
4837+ for(ii[0] = tval[0]; ii[0] < 18; ii[0]++)
4838+ {
4839+ for(ii[1] = tval[1]; ii[1] < 18; ii[1]++)
4840+ {
4841+ for(ii[2] = tval[2]; ii[2] < 18; ii[2]++)
4842+ {
4843+ for(ii[3] = tval[3]; ii[3] < 18; ii[3]++)
4844+ {
4845+ for(ii[4] = tval[4]; ii[4] < 18; ii[4]++)
4846+ {
4847+ for(ii[5] = tval[5]; ii[5] < 18; ii[5]++)
4848+ {
4849+ tot = ii[0] + ii[1] + ii[2] + ii[3] + ii[4] + ii[5];
4850+ if(tot > 86) break;
4851+ if(tot <= 72) continue;
4852+ succ += ( pp[ii[0]] * pp[ii[1]] * pp[ii[2]] * pp[ii[3]] * pp[ii[4]] * pp[ii[5]] );
4853+ /* If given condition is easy enough, quit calc. to save CPU. */
4854+ if(succ > 320670) return -1;
4855+ }
4856+ }
4857+ }
4858+ }
4859+ }
4860+ }
4861+
4862+ return tot_rand_1p / succ;
4863+}
4864+
4865+
48104866 #ifdef ALLOW_AUTOROLLER
48114867 /*!
48124868 * @brief オートローラで得たい能力値の基準を決める。
@@ -4838,11 +4894,15 @@ static bool get_stat_limits(void)
48384894 put_str(" Base Rac Cla Per Total Maximum", 13, 10);
48394895 #endif
48404896
4897+#ifdef JP
4898+ put_str(" 確率: 非常に容易(1/10000以上)", 23, 10);
4899+#else
4900+ put_str(" Prob: Quite Easy(>1/10000)", 23, 10);
4901+#endif
48414902 /* Output the maximum stats */
48424903 for (i = 0; i < 6; i++)
48434904 {
48444905 /* Reset the "success" counter */
4845- stat_match[i] = 0;
48464906 cval[i] = 3;
48474907
48484908 /* Race/Class bonus */
@@ -4911,7 +4971,22 @@ static bool get_stat_limits(void)
49114971 /* Move Cursol */
49124972 if (cs != os)
49134973 {
4914- if(os == 6)
4974+ if(os == 7)
4975+ {
4976+ autoroll_chance = get_autoroller_prob(cval);
4977+
4978+#ifdef JP
4979+ if(autoroll_chance == -999) sprintf(buf, " 確率: 不可能(合計86超) ");
4980+ else if(autoroll_chance < 1) sprintf(buf, " 確率: 非常に容易(1/10000以上)");
4981+ else sprintf(buf, " 確率: 約 1/%8d00 ", autoroll_chance);
4982+#else
4983+ if(autoroll_chance == -999) sprintf(buf, " Prob: Impossible(>86 tot stats)");
4984+ else if(autoroll_chance < 1) sprintf(buf, " Prob: Quite Easy(>1/10000) ");
4985+ else sprintf(buf, " Prob: ~ 1/%8d00 ", autoroll_chance);
4986+#endif
4987+ put_str(buf,23,10);
4988+ }
4989+ else if(os == 6)
49154990 {
49164991 #ifdef JP
49174992 c_put_str(TERM_WHITE, "決定する", 21, 35);
@@ -5060,7 +5135,7 @@ static bool get_stat_limits(void)
50605135 bell();
50615136 break;
50625137 }
5063- if(c == ESCAPE || ((c == ' ' || c == '\r' || c == '\n') && cs == 6))break;
5138+ if(c == ESCAPE || ((c == ' ' || c == '\r' || c == '\n') && cs == 6 && autoroll_chance != -999))break;
50645139 }
50655140
50665141 for (i = 0; i < 6; i++)
@@ -6041,6 +6116,8 @@ static bool player_birth_aux(void)
60416116 {
60426117 /* Clear fields */
60436118 auto_round = 0L;
6119+ auto_round2 = 0L;
6120+ autoroll_chance = -1L;
60446121 }
60456122
60466123 /* Initialize */
@@ -6069,7 +6146,7 @@ static bool player_birth_aux(void)
60696146 {
60706147 int col;
60716148
6072- col = 42;
6149+ col = 22;
60736150
60746151 if (autoroller || autochara)
60756152 {
@@ -6077,17 +6154,16 @@ static bool player_birth_aux(void)
60776154
60786155 /* Label count */
60796156 #ifdef JP
6080- put_str("回数 :", 10, col+13);
6157+ put_str("回数 :", 10, col+10);
60816158 #else
6082- put_str("Round:", 10, col+13);
6159+ put_str("Round:", 10, col+10);
60836160 #endif
60846161
6085-
60866162 /* Indicate the state */
60876163 #ifdef JP
6088- put_str("(ESCで停止)", 12, col+13);
6164+ put_str("(ESCで停止)", 13, col+13);
60896165 #else
6090- put_str("(Hit ESC to stop)", 12, col+13);
6166+ put_str("(Hit ESC to stop)", 13, col+13);
60916167 #endif
60926168 }
60936169
@@ -6109,35 +6185,48 @@ static bool player_birth_aux(void)
61096185 {
61106186 /* Label */
61116187 #ifdef JP
6112- put_str("最小値", 2, col+5);
6188+ put_str("最小値", 2, col+13);
61136189 #else
6114- put_str(" Limit", 2, col+5);
6190+ put_str(" Limit", 2, col+13);
61156191 #endif
61166192
6117-
61186193 /* Label */
61196194 #ifdef JP
6120- put_str("成功率", 2, col+13);
6195+ put_str("現在値", 2, col+24);
61216196 #else
6122- put_str(" Freq", 2, col+13);
6197+ put_str(" Roll", 2, col+24);
61236198 #endif
61246199
6125-
6126- /* Label */
6200+ /* Show prob. just below the round counter */
61276201 #ifdef JP
6128- put_str("現在値", 2, col+24);
6202+ if(autoroll_chance >= 1)
6203+ sprintf(buf, "確率 : 1/%8d00", autoroll_chance);
6204+ else if (autoroll_chance == -999)
6205+ sprintf(buf, "確率 : 不可能");
6206+ else
6207+ sprintf(buf, "確率 : 1/10000以上");
61296208 #else
6130- put_str(" Roll", 2, col+24);
6209+ if(autoroll_chance >= 1)
6210+ sprintf(buf, "Prob : 1/%8d00", autoroll_chance);
6211+ else if (autoroll_chance == -999)
6212+ sprintf(buf, "Prob : Impossible");
6213+ else
6214+ sprintf(buf, "Prob : >1/10000");
61316215 #endif
6216+ put_str(buf, 11, col+10);
61326217
6133-
6218+#ifdef JP
6219+ put_str("注意 : 体格等のオートローラを併用時は、上記確率より困難です。", 22, 5);
6220+#else
6221+ put_str("Note : Prob may be lower when you use the 'autochara' option.", 22, 5);
6222+#endif
61346223 /* Put the minimal stats */
61356224 for (i = 0; i < 6; i++)
61366225 {
61376226 int j, m;
61386227
61396228 /* Label stats */
6140- put_str(stat_names[i], 3+i, col);
6229+ put_str(stat_names[i], 3+i, col+8);
61416230
61426231 /* Race/Class bonus */
61436232 j = rp_ptr->r_adj[i] + cp_ptr->c_adj[i] + ap_ptr->a_adj[i];
@@ -6147,7 +6236,7 @@ static bool player_birth_aux(void)
61476236
61486237 /* Put the stat */
61496238 cnv_stat(m, buf);
6150- c_put_str(TERM_L_BLUE, buf, 3+i, col+5);
6239+ c_put_str(TERM_L_BLUE, buf, 3+i, col+13);
61516240 }
61526241 }
61536242
@@ -6163,17 +6252,10 @@ static bool player_birth_aux(void)
61636252 auto_round++;
61646253
61656254 /* Hack -- Prevent overflow */
6166- if (auto_round >= 1000000000L)
6255+ if (auto_round > 1000000000L)
61676256 {
61686257 auto_round = 1;
6169-
6170- if (autoroller)
6171- {
6172- for (i = 0; i < 6; i++)
6173- {
6174- stat_match[i] = 0;
6175- }
6176- }
6258+ auto_round2 ++;
61776259 }
61786260
61796261 if (autoroller)
@@ -6181,16 +6263,11 @@ static bool player_birth_aux(void)
61816263 /* Check and count acceptable stats */
61826264 for (i = 0; i < 6; i++)
61836265 {
6184- /* This stat is okay */
6185- if (p_ptr->stat_max[i] >= stat_limit[i])
6186- {
6187- stat_match[i]++;
6188- }
6189-
61906266 /* This stat is not okay */
6191- else
6267+ if (p_ptr->stat_max[i] < stat_limit[i])
61926268 {
61936269 accept = FALSE;
6270+ break;
61946271 }
61956272 }
61966273 }
@@ -6224,7 +6301,10 @@ static bool player_birth_aux(void)
62246301 birth_put_stats();
62256302
62266303 /* Dump round */
6227- put_str(format("%10ld", auto_round), 10, col+20);
6304+ if(auto_round2)
6305+ put_str(format("%ld%09ld", auto_round2, auto_round), 10, col+20);
6306+ else
6307+ put_str(format("%10ld", auto_round), 10, col+20);
62286308
62296309 #ifdef AUTOROLLER_DELAY
62306310 /* Delay 1/10 second */
Show on old repository browser