#include "spell/spells-status.h"
#include "sv-definition/sv-weapon-types.h"
#include "system/player-type-definition.h"
+#include <array>
-/*! オートロール能力値の乱数分布 / emulate 5 + 1d3 + 1d4 + 1d5 by randint0(60) */
-short 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*/
+namespace {
+
+constexpr auto random_distribution = 60;
+
+/*! オートロール能力値の乱数分布 (1d3, 1d4, 1d5 を3 * 4 * 5 = 60個で表現) */
+constexpr std::array<short, random_distribution> auto_roller_distribution = {
+ {
+ 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 プレイヤーの能力値表現に基づいて加減算を行う。
void get_stats(PlayerType *player_ptr)
{
while (true) {
- int sum = 0;
- for (int i = 0; i < 2; i++) {
- auto tmp = randint0(60 * 60 * 60);
- for (int j = 0; j < 3; j++) {
- int stat = i * 3 + j;
-
- /* Extract 5 + 1d3 + 1d4 + 1d5 */
- auto val = rand3_4_5[tmp % 60];
-
+ auto sum = 0;
+ for (auto i = 0; i < 2; i++) {
+ auto tmp = randint0(random_distribution * random_distribution * random_distribution);
+ for (auto j = 0; j < 3; j++) {
+ auto stat = i * 3 + j;
+ auto val = auto_roller_distribution[tmp % random_distribution];
sum += val;
player_ptr->stat_cur[stat] = player_ptr->stat_max[stat] = val;
-
- tmp /= 60;
+ tmp /= random_distribution;
}
}