diff --git a/game/data/font/VeraMoBd.ttf b/game/data/font/VeraMoBd.ttf new file mode 100644 index 0000000000000000000000000000000000000000..9be6547ed61cbea68f354fc49651bc3645c822fa Binary files /dev/null and b/game/data/font/VeraMoBd.ttf differ diff --git a/game/engine/Tiles.lua b/game/engine/Tiles.lua index d6c0b00621c2db7827f617dc281f44200d78183f..6ae0b953dd394c9d3ce6ebb6331787362310778b 100644 --- a/game/engine/Tiles.lua +++ b/game/engine/Tiles.lua @@ -10,7 +10,7 @@ use_images = true function _M:init(w, h, fontname, fontsize, texture) self.texture = texture self.w, self.h = w, h - self.font = core.display.newFont(fontname or "/data/font/VeraMono.ttf", fontsize or 14) + self.font = core.display.newFont(fontname or "/data/font/VeraMoBd.ttf", fontsize or 14) self.repo = {} end diff --git a/game/engine/generator/map/Static.lua b/game/engine/generator/map/Static.lua index 6258ada1d1cc56b881c8b4f0d9783b309f573ab9..55c13a7232b12b1cf33d5f5c8bc4a41029a99fc4 100644 --- a/game/engine/generator/map/Static.lua +++ b/game/engine/generator/map/Static.lua @@ -52,7 +52,6 @@ function _M:resolve(typ, c) if type(res) == "function" then return self.grid_list[res()] elseif type(res) == "table" and res.__CLASSNAME then - print("res", res.display) return res elseif type(res) == "table" then return self.grid_list[res[rng.range(1, #res)]] diff --git a/game/engine/resolvers.lua b/game/engine/resolvers.lua index f2b3fb2881cc70be8a25d6853aa70ac3e245fa82..d1dfce2951cbe0479707053af1c135422c36c9db 100644 --- a/game/engine/resolvers.lua +++ b/game/engine/resolvers.lua @@ -9,6 +9,15 @@ function resolvers.calc.rngrange(t) return rng.range(t[1], t[2]) end +--- Average random +function resolvers.rngavg(x, y) + return {__resolver="rngavg", x, y} +end +function resolvers.calc.rngavg(t) + return rng.avg(t[1], t[2]) +end + +--- Random around level function resolvers.rngavg(x, y) return {__resolver="rngavg", x, y} end diff --git a/game/engine/utils.lua b/game/engine/utils.lua index 6e417da37b73b45b697a82e9b4c134dc8f1d85a6..d7b4c2f1bfd9023d93a18975d8985731e59ed4f2 100644 --- a/game/engine/utils.lua +++ b/game/engine/utils.lua @@ -267,3 +267,21 @@ function util.showMainMenu() game = Menu.new() game:run() end + +function rng.mbonus(max, level, max_level) + if level > max_level - 1 then level = max_level - 1 end + + local bonus = (max * level) / max_level + local extra = (max * level) % max_level + if rng.range(0, max_level - 1) < extra then bonus = bonus + 1 end + + local stand = max / 4 + extra = max % 4 + if rng.range(0, 3) < extra then stand = stand + 1 end + + local val = rng.normal(bonus, stand) + if val < 0 then val = 0 end + if val > max then val = max end + + return val +end diff --git a/game/modules/tome/data/general/egos.lua b/game/modules/tome/data/general/egos.lua index 4cd504528547d632743dc61c6ed96be4d5a03def..26bb20e48c9f35a5755db00375d7deaf4a5025ca 100644 --- a/game/modules/tome/data/general/egos.lua +++ b/game/modules/tome/data/general/egos.lua @@ -11,6 +11,6 @@ newEntity{ level_range = {1, 10}, rarity = 3, wielder = { - hit = 4, + combat_atk = 4, }, } diff --git a/game/modules/tome/data/maps/towns/bree.lua b/game/modules/tome/data/maps/towns/bree.lua index b5ebbcf9d5ad873d6eea6a7a792339f770c05cb0..164b26dfd76ae36edb70597649afe84ae10e2660 100644 --- a/game/modules/tome/data/maps/towns/bree.lua +++ b/game/modules/tome/data/maps/towns/bree.lua @@ -1,4 +1,15 @@ +quickEntity('S', {name='brick roof top', display='#', color=colors.RED, block_move=true, block_sight=true}) +quickEntity('s', {name='brick roof', display='#', color=colors.RED, block_move=true, block_sight=true}) +quickEntity('t', {name='brick roof chimney', display='#', color=colors.LIGHT_RED, block_move=true, block_sight=true}) +quickEntity('#', {name='wall', display='#', color=colors.WHITE, block_move=true, block_sight=true}) +quickEntity('C', {name='dark pit', display='#', color=colors.LIGHT_DARK, block_move=true, block_sight=true}) +quickEntity('T', {name='tree', display='#', color=colors.LIGHT_GREEN, block_move=true, block_sight=true}) quickEntity(' ', {name='forest', display='#', color=colors.GREEN, block_move=true, block_sight=true}) +quickEntity('V', {name='river', display='~', color=colors.BLUE, block_move=true,}) +quickEntity('O', {name='cooblestone road', display='.', color=colors.WHITE}) +quickEntity('.', {name='road', display='.', color=colors.WHITE}) +quickEntity(',', {name='dirt', display='.', color=colors.LIGHT_UMBER}) +quickEntity('-', {name='grass', display='.', color=colors.LIGHT_GREEN}) startx = 131 starty = 33 diff --git a/src/core_lua.c b/src/core_lua.c index 632a948d3992d49b60c995deda5dce5fbb742489..acd3325f8d3af265d501405c04cd4cfc2548a29e 100644 --- a/src/core_lua.c +++ b/src/core_lua.c @@ -755,6 +755,131 @@ static int rng_percent(lua_State *L) return 1; } +/* + * The number of entries in the "randnor_table" + */ +#define RANDNOR_NUM 256 + +/* + * The standard deviation of the "randnor_table" + */ +#define RANDNOR_STD 64 + +/* + * The normal distribution table for the "randnor()" function (below) + */ +static int randnor_table[RANDNOR_NUM] = +{ + 206, 613, 1022, 1430, 1838, 2245, 2652, 3058, + 3463, 3867, 4271, 4673, 5075, 5475, 5874, 6271, + 6667, 7061, 7454, 7845, 8234, 8621, 9006, 9389, + 9770, 10148, 10524, 10898, 11269, 11638, 12004, 12367, + 12727, 13085, 13440, 13792, 14140, 14486, 14828, 15168, + 15504, 15836, 16166, 16492, 16814, 17133, 17449, 17761, + 18069, 18374, 18675, 18972, 19266, 19556, 19842, 20124, + 20403, 20678, 20949, 21216, 21479, 21738, 21994, 22245, + + 22493, 22737, 22977, 23213, 23446, 23674, 23899, 24120, + 24336, 24550, 24759, 24965, 25166, 25365, 25559, 25750, + 25937, 26120, 26300, 26476, 26649, 26818, 26983, 27146, + 27304, 27460, 27612, 27760, 27906, 28048, 28187, 28323, + 28455, 28585, 28711, 28835, 28955, 29073, 29188, 29299, + 29409, 29515, 29619, 29720, 29818, 29914, 30007, 30098, + 30186, 30272, 30356, 30437, 30516, 30593, 30668, 30740, + 30810, 30879, 30945, 31010, 31072, 31133, 31192, 31249, + + 31304, 31358, 31410, 31460, 31509, 31556, 31601, 31646, + 31688, 31730, 31770, 31808, 31846, 31882, 31917, 31950, + 31983, 32014, 32044, 32074, 32102, 32129, 32155, 32180, + 32205, 32228, 32251, 32273, 32294, 32314, 32333, 32352, + 32370, 32387, 32404, 32420, 32435, 32450, 32464, 32477, + 32490, 32503, 32515, 32526, 32537, 32548, 32558, 32568, + 32577, 32586, 32595, 32603, 32611, 32618, 32625, 32632, + 32639, 32645, 32651, 32657, 32662, 32667, 32672, 32677, + + 32682, 32686, 32690, 32694, 32698, 32702, 32705, 32708, + 32711, 32714, 32717, 32720, 32722, 32725, 32727, 32729, + 32731, 32733, 32735, 32737, 32739, 32740, 32742, 32743, + 32745, 32746, 32747, 32748, 32749, 32750, 32751, 32752, + 32753, 32754, 32755, 32756, 32757, 32757, 32758, 32758, + 32759, 32760, 32760, 32761, 32761, 32761, 32762, 32762, + 32763, 32763, 32763, 32764, 32764, 32764, 32764, 32765, + 32765, 32765, 32765, 32766, 32766, 32766, 32766, 32767, +}; + + +/* + * Generate a random integer number of NORMAL distribution + * + * The table above is used to generate a psuedo-normal distribution, + * in a manner which is much faster than calling a transcendental + * function to calculate a true normal distribution. + * + * Basically, entry 64*N in the table above represents the number of + * times out of 32767 that a random variable with normal distribution + * will fall within N standard deviations of the mean. That is, about + * 68 percent of the time for N=1 and 95 percent of the time for N=2. + * + * The table above contains a "faked" final entry which allows us to + * pretend that all values in a normal distribution are strictly less + * than four standard deviations away from the mean. This results in + * "conservative" distribution of approximately 1/32768 values. + * + * Note that the binary search takes up to 16 quick iterations. + */ +static int rng_normal(lua_State *L) +{ + int mean = luaL_checknumber(L, 1); + int stand = luaL_checknumber(L, 2); + int tmp; + int offset; + + int low = 0; + int high = RANDNOR_NUM; + + /* Paranoia */ + if (stand < 1) + { + lua_pushnumber(L, mean); + return 1; + } + + /* Roll for probability */ + tmp = (int)rand_div(32768); + + /* Binary Search */ + while (low < high) + { + long mid = (low + high) >> 1; + + /* Move right if forced */ + if (randnor_table[mid] < tmp) + { + low = mid + 1; + } + + /* Move left otherwise */ + else + { + high = mid; + } + } + + /* Convert the index into an offset */ + offset = (long)stand * (long)low / RANDNOR_STD; + + /* One half should be negative */ + if (rand_div(100) < 50) + { + lua_pushnumber(L, mean - offset); + return 1; + } + + /* One half should be positive */ + lua_pushnumber(L, mean + offset); + return 1; +} + static const struct luaL_reg rnglib[] = { {"__call", rng_call}, @@ -764,6 +889,7 @@ static const struct luaL_reg rnglib[] = {"seed", rng_seed}, {"chance", rng_chance}, {"percent", rng_percent}, + {"normal", rng_normal}, {NULL, NULL}, };