mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-14 10:13:13 +02:00
Moved poisson rng to utils, fixed a potential nil reference and fixed poison typo
This commit is contained in:
parent
23a78b468e
commit
10d1b0ebe3
@ -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
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user