diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 1682e88a..d9fa884e 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,5 +1,5 @@ require("locale.gen_combined.grilledham_map_gen.builders") -require("locale.gen_shared.poisson") +require("locale.utils.poisson") local Thread = require "locale.utils.Thread" @@ -216,7 +216,7 @@ function check_decorative(tile, x, y) for _,e in ipairs(options) do name = e[1] high_roll = e[2] - if poison_rng_next(high_roll / 2 ) == 1 then + if poisson_rng_next(high_roll / 2 ) == 1 then table.insert(tile_decoratives, {name=name, amount=1, position={x,y}}) end end @@ -323,11 +323,10 @@ function check_entities(tile, x, y) for _,e in ipairs(options) do name = e[1] high_roll = e[2] - if poison_rng_next( high_roll / 2 ) == 1 then + if poisson_rng_next( high_roll / 2 ) == 1 then table.insert(tile_entity_list, {name=name, position={x,y}}) end end return tile_entity_list - end diff --git a/locale/gen_shared/poisson.lua b/locale/utils/poisson_rng.lua similarity index 79% rename from locale/gen_shared/poisson.lua rename to locale/utils/poisson_rng.lua index 7d9c1ac3..1a54e1b0 100644 --- a/locale/gen_shared/poisson.lua +++ b/locale/utils/poisson_rng.lua @@ -1,3 +1,5 @@ +--Author: Valansch + local function generate_pmf_chart(l) chart = {[0] = math.exp(-l)} for k=1,(l*2 + 1) do @@ -15,13 +17,14 @@ local function generate_poisson_set(l, n) --n defines the resolution table.insert(set,x) end end + set._n = #set return set end global.poisson_set = {} -function poison_rng_next(l) +function poisson_rng_next(l) if not global.poisson_set[l] then global.poisson_set[l] = generate_poisson_set(l, 1000) end - return global.poisson_set[l][math.random(1000)] + return global.poisson_set[l][math.random(global.poisson_set[l]._n)] end