mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-14 10:13:13 +02:00
clean up + change surface to local variable
This commit is contained in:
parent
43a0b0b1a5
commit
cc6af4fb67
@ -1,10 +1,9 @@
|
|||||||
|
|
||||||
-- helpers
|
-- helpers
|
||||||
|
|
||||||
tau = 2 * math.pi
|
tau = 2 * math.pi
|
||||||
deg_to_rad = tau / 360
|
deg_to_rad = tau / 360
|
||||||
function degrees(angle)
|
function degrees(angle)
|
||||||
return angle * deg_to_rad
|
return angle * deg_to_rad
|
||||||
end
|
end
|
||||||
|
|
||||||
-- shape builders
|
-- shape builders
|
||||||
@ -21,7 +20,7 @@ function path_builder(thickness, optional_thickness_height)
|
|||||||
local width = thickness / 2
|
local width = thickness / 2
|
||||||
local thickness2 = optional_thickness_height or thickness
|
local thickness2 = optional_thickness_height or thickness
|
||||||
local height = thickness2 / 2
|
local height = thickness2 / 2
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
return (x > -width and x <= width) or (y > -height and y <= height)
|
return (x > -width and x <= width) or (y > -height and y <= height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -32,8 +31,8 @@ function rectangle_builder(width, height)
|
|||||||
height = height / 2
|
height = height / 2
|
||||||
else
|
else
|
||||||
height = width
|
height = width
|
||||||
end
|
end
|
||||||
return function (x, y)
|
return function(x, y)
|
||||||
return x > -width and x <= width and y > -height and y <= height
|
return x > -width and x <= width and y > -height and y <= height
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -41,21 +40,21 @@ end
|
|||||||
function line_x_builder(thickness)
|
function line_x_builder(thickness)
|
||||||
thickness = thickness / 2
|
thickness = thickness / 2
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
return y > - thickness and y <= thickness
|
return y > -thickness and y <= thickness
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function line_y_builder(thickness)
|
function line_y_builder(thickness)
|
||||||
thickness = thickness / 2
|
thickness = thickness / 2
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
return x > - thickness and x <= thickness
|
return x > -thickness and x <= thickness
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function square_diamond_builder(size)
|
function square_diamond_builder(size)
|
||||||
size = size / 2
|
size = size / 2
|
||||||
return function (x, y)
|
return function(x, y)
|
||||||
return math.abs(x) + math.abs(y) <= size
|
return math.abs(x) + math.abs(y) <= size
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -63,7 +62,7 @@ local rot = math.sqrt(2) / 2 -- 45 degree rotation.
|
|||||||
function rectangle_diamond_builder(width, height)
|
function rectangle_diamond_builder(width, height)
|
||||||
width = width / 2
|
width = width / 2
|
||||||
height = height / 2
|
height = height / 2
|
||||||
return function (x, y)
|
return function(x, y)
|
||||||
local rot_x = rot * (x - y)
|
local rot_x = rot * (x - y)
|
||||||
local rot_y = rot * (x + y)
|
local rot_y = rot * (x + y)
|
||||||
return math.abs(rot_x) < width and math.abs(rot_y) < height
|
return math.abs(rot_x) < width and math.abs(rot_y) < height
|
||||||
@ -72,21 +71,20 @@ end
|
|||||||
|
|
||||||
function circle_builder(radius)
|
function circle_builder(radius)
|
||||||
local rr = radius * radius
|
local rr = radius * radius
|
||||||
return function (x, y)
|
return function(x, y)
|
||||||
return x * x + y * y < rr
|
return x * x + y * y < rr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function oval_builder(x_radius, y_radius)
|
function oval_builder(x_radius, y_radius)
|
||||||
local x_rr = x_radius * x_radius
|
local x_rr = x_radius * x_radius
|
||||||
local y_rr = y_radius * y_radius
|
local y_rr = y_radius * y_radius
|
||||||
return function (x, y)
|
return function(x, y)
|
||||||
return ((x * x) / x_rr + (y * y) / y_rr) < 1
|
return ((x * x) / x_rr + (y * y) / y_rr) < 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local tile_map =
|
local tile_map = {
|
||||||
{
|
|
||||||
[1] = false,
|
[1] = false,
|
||||||
[2] = true,
|
[2] = true,
|
||||||
[3] = "concrete",
|
[3] = "concrete",
|
||||||
@ -119,7 +117,7 @@ local tile_map =
|
|||||||
[30] = "sand-3",
|
[30] = "sand-3",
|
||||||
[31] = "stone-path",
|
[31] = "stone-path",
|
||||||
[32] = "water-green",
|
[32] = "water-green",
|
||||||
[33] = "water",
|
[33] = "water"
|
||||||
}
|
}
|
||||||
|
|
||||||
function decompress(pic)
|
function decompress(pic)
|
||||||
@ -162,7 +160,7 @@ function picture_builder(pic)
|
|||||||
local x2 = x + half_width
|
local x2 = x + half_width
|
||||||
local y2 = y + half_height
|
local y2 = y + half_height
|
||||||
|
|
||||||
if y2 > 0 and y2 <= height and x2 > 0 and x2 <= width then
|
if y2 > 0 and y2 <= height and x2 > 0 and x2 <= width then
|
||||||
local pixel = data[y2][x2]
|
local pixel = data[y2][x2]
|
||||||
return pixel
|
return pixel
|
||||||
else
|
else
|
||||||
@ -174,60 +172,62 @@ end
|
|||||||
-- transforms and shape helpers
|
-- transforms and shape helpers
|
||||||
|
|
||||||
function translate(builder, x_offset, y_offset)
|
function translate(builder, x_offset, y_offset)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
return builder(x - x_offset, y - y_offset, world_x, world_y)
|
return builder(x - x_offset, y - y_offset, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function scale(builder, x_scale, y_scale)
|
function scale(builder, x_scale, y_scale)
|
||||||
x_scale = 1 / x_scale
|
x_scale = 1 / x_scale
|
||||||
y_scale = 1 / y_scale
|
y_scale = 1 / y_scale
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
return builder(x * x_scale, y * y_scale, world_x, world_y)
|
return builder(x * x_scale, y * y_scale, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function rotate(builder, angle)
|
function rotate(builder, angle)
|
||||||
local qx = math.cos(angle)
|
local qx = math.cos(angle)
|
||||||
local qy = math.sin(angle)
|
local qy = math.sin(angle)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
local rot_x = qx * x - qy * y
|
local rot_x = qx * x - qy * y
|
||||||
local rot_y = qy * x + qx * y
|
local rot_y = qy * x + qx * y
|
||||||
return builder(rot_x, rot_y, world_x, world_y)
|
return builder(rot_x, rot_y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function scale_rotate_translate(builder, x_scale, y_scale, angle, x_offset, y_offset)
|
function scale_rotate_translate(builder, x_scale, y_scale, angle, x_offset, y_offset)
|
||||||
local transform = translate(rotate(scale(builder, x_scale, y_scale), angle), x_offset, y_offset)
|
local transform = translate(rotate(scale(builder, x_scale, y_scale), angle), x_offset, y_offset)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
return transform(x, y, world_x, world_y)
|
return transform(x, y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function flip_x(builder)
|
function flip_x(builder)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
return builder(-x, y, world_x, world_y)
|
return builder(-x, y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function flip_y(builder)
|
function flip_y(builder)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
return builder(x, -y, world_x, world_y)
|
return builder(x, -y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function flip_xy(builder)
|
function flip_xy(builder)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
return builder(-x, -y, world_x, world_y)
|
return builder(-x, -y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- For resource_module_builder it will return the first success.
|
-- For resource_module_builder it will return the first success.
|
||||||
function compound_or(builders)
|
function compound_or(builders)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
for _, v in ipairs(builders) do
|
for _, v in ipairs(builders) do
|
||||||
local tile, entity = v(x, y, world_x, world_y)
|
local tile, entity = v(x, y, world_x, world_y, surface)
|
||||||
if tile then return tile, entity end
|
if tile then
|
||||||
|
return tile, entity
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -235,25 +235,27 @@ end
|
|||||||
|
|
||||||
-- Wont work correctly with resource_module_builder becasues I don't know which one to return.
|
-- Wont work correctly with resource_module_builder becasues I don't know which one to return.
|
||||||
function compound_and(builders)
|
function compound_and(builders)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
for _, v in ipairs(builders) do
|
for _, v in ipairs(builders) do
|
||||||
if not v(x, y, world_x, world_y) then return false end
|
if not v(x, y, world_x, world_y, surface) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function invert(builder)
|
function invert(builder)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
local tile, entity = builder(x, y, world_x, world_y)
|
local tile, entity = builder(x, y, world_x, world_y, surface)
|
||||||
return not tile, entity
|
return not tile, entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function throttle_x(builder, x_in, x_size)
|
function throttle_x(builder, x_in, x_size)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
if x % x_size < x_in then
|
if x % x_size < x_in then
|
||||||
return builder(x, y, world_x, world_y)
|
return builder(x, y, world_x, world_y, surface)
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -261,9 +263,9 @@ function throttle_x(builder, x_in, x_size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function throttle_y(builder, y_in, y_size)
|
function throttle_y(builder, y_in, y_size)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
if y % y_size < y_in then
|
if y % y_size < y_in then
|
||||||
return builder(x, y, world_x, world_y)
|
return builder(x, y, world_x, world_y, surface)
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -271,9 +273,9 @@ function throttle_y(builder, y_in, y_size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function throttle_xy(builder, x_in, x_size, y_in, y_size)
|
function throttle_xy(builder, x_in, x_size, y_in, y_size)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
if x % x_size < x_in and y % y_size < y_in then
|
if x % x_size < x_in and y % y_size < y_in then
|
||||||
return builder(x, y, world_x, world_y)
|
return builder(x, y, world_x, world_y, surface)
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -281,9 +283,9 @@ function throttle_xy(builder, x_in, x_size, y_in, y_size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function throttle_xy(builder, x_in, x_size, y_in, y_size)
|
function throttle_xy(builder, x_in, x_size, y_in, y_size)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
if x % x_size < x_in and y % y_size < y_in then
|
if x % x_size < x_in and y % y_size < y_in then
|
||||||
return builder(x, y, world_x, world_y)
|
return builder(x, y, world_x, world_y, surface)
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -291,9 +293,9 @@ function throttle_xy(builder, x_in, x_size, y_in, y_size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function throttle_world_xy(builder, x_in, x_size, y_in, y_size)
|
function throttle_world_xy(builder, x_in, x_size, y_in, y_size)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
if world_x % x_size < x_in and world_y % y_size < y_in then
|
if world_x % x_size < x_in and world_y % y_size < y_in then
|
||||||
return builder(x, y, world_x, world_y)
|
return builder(x, y, world_x, world_y, surface)
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -301,83 +303,56 @@ function throttle_world_xy(builder, x_in, x_size, y_in, y_size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function choose(condition, true_shape, false_shape)
|
function choose(condition, true_shape, false_shape)
|
||||||
return function(local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
if condition(local_x, local_y, world_x, world_y) then
|
if condition(local_x, local_y, world_x, world_y, surface) then
|
||||||
return true_shape(local_x, local_y, world_x, world_y)
|
return true_shape(local_x, local_y, world_x, world_y, surface)
|
||||||
else
|
else
|
||||||
return false_shape(local_x, local_y, world_x, world_y)
|
return false_shape(local_x, local_y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function linear_grow(shape, size)
|
function linear_grow(shape, size)
|
||||||
local half_size = size / 2
|
local half_size = size / 2
|
||||||
return function (local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local t = math.ceil((local_y / size) + 0.5)
|
local t = math.ceil((local_y / size) + 0.5)
|
||||||
local n = math.ceil((math.sqrt(8 * t + 1) - 1) / 2)
|
local n = math.ceil((math.sqrt(8 * t + 1) - 1) / 2)
|
||||||
local t_upper = n * (n + 1) * 0.5
|
local t_upper = n * (n + 1) * 0.5
|
||||||
local t_lower = t_upper - n
|
local t_lower = t_upper - n
|
||||||
|
|
||||||
local y = (local_y - size * (t_lower + n / 2 - 0.5)) / n
|
local y = (local_y - size * (t_lower + n / 2 - 0.5)) / n
|
||||||
local x = local_x / n
|
local x = local_x / n
|
||||||
|
|
||||||
return shape(x, y, world_x, world_y)
|
return shape(x, y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function grow(in_shape, out_shape, size, offset)
|
function grow(in_shape, out_shape, size, offset)
|
||||||
local half_size = size / 2
|
local half_size = size / 2
|
||||||
return function(local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local tx = math.ceil(math.abs(local_x) / half_size)
|
local tx = math.ceil(math.abs(local_x) / half_size)
|
||||||
local ty = math.ceil(math.abs(local_y) / half_size)
|
local ty = math.ceil(math.abs(local_y) / half_size)
|
||||||
local t = math.max(tx, ty)
|
local t = math.max(tx, ty)
|
||||||
|
|
||||||
local tile, entity
|
local tile, entity
|
||||||
|
|
||||||
for i = t, 2.5 * t, 1 do
|
for i = t, 2.5 * t, 1 do
|
||||||
local out_t = 1 / (i - offset)
|
local out_t = 1 / (i - offset)
|
||||||
local in_t = 1 / i
|
local in_t = 1 / i
|
||||||
|
|
||||||
tile = out_shape(out_t * local_x, out_t * local_y, world_x, world_y)
|
tile = out_shape(out_t * local_x, out_t * local_y, world_x, world_y, surface)
|
||||||
if tile then
|
if tile then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
tile, entity = in_shape(in_t * local_x, in_t * local_y, world_x, world_y)
|
tile, entity = in_shape(in_t * local_x, in_t * local_y, world_x, world_y, surface)
|
||||||
if tile then
|
if tile then
|
||||||
return tile, entity
|
return tile, entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
end
|
||||||
--[[ local out_t = 1 / (t - offset)
|
|
||||||
local in_t = 1 / t
|
|
||||||
tile = out_shape(out_t * local_x, out_t * local_y, world_x, world_y)
|
|
||||||
if tile then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
--return in_shape(in_t * local_x, in_t * local_y, world_x, world_y)
|
|
||||||
|
|
||||||
tile, entity = in_shape(in_t * local_x, in_t * local_y, world_x, world_y)
|
|
||||||
if tile then
|
|
||||||
return tile, entity
|
|
||||||
end
|
|
||||||
|
|
||||||
out_t = 1 / (t + 1 - offset)
|
|
||||||
in_t = 1 / (t + 1)
|
|
||||||
tile = out_shape(out_t * local_x, out_t * local_y, world_x, world_y)
|
|
||||||
if tile then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
tile, entity = in_shape(in_t * local_x, in_t * local_y, world_x, world_y)
|
|
||||||
if tile then
|
|
||||||
return tile, entity
|
|
||||||
end
|
|
||||||
|
|
||||||
return false ]]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function project(shape, size, r)
|
function project(shape, size, r)
|
||||||
@ -385,20 +360,20 @@ function project(shape, size, r)
|
|||||||
local r2 = 1 / (r - 1)
|
local r2 = 1 / (r - 1)
|
||||||
local a = 1 / size
|
local a = 1 / size
|
||||||
|
|
||||||
return function(local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local offset = 0.5 * size
|
local offset = 0.5 * size
|
||||||
local sn = math.ceil(local_y + offset)
|
local sn = math.ceil(local_y + offset)
|
||||||
|
|
||||||
local n = math.ceil(math.log((r-1) * sn * a + 1) / ln_r - 1)
|
local n = math.ceil(math.log((r - 1) * sn * a + 1) / ln_r - 1)
|
||||||
local rn = r ^ n
|
local rn = r ^ n
|
||||||
local rn2 = 1 / rn
|
local rn2 = 1 / rn
|
||||||
local c = size * rn
|
local c = size * rn
|
||||||
|
|
||||||
local sn_upper = size * (r ^ (n + 1) - 1) * r2
|
local sn_upper = size * (r ^ (n + 1) - 1) * r2
|
||||||
local x = local_x * rn2
|
local x = local_x * rn2
|
||||||
local y = (local_y - (sn_upper - 0.5 * c ) + offset ) * rn2
|
local y = (local_y - (sn_upper - 0.5 * c) + offset) * rn2
|
||||||
|
|
||||||
return shape(x, y, world_x, world_y)
|
return shape(x, y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -408,23 +383,22 @@ function project_overlap(shape, size, r)
|
|||||||
local a = 1 / size
|
local a = 1 / size
|
||||||
local offset = 0.5 * size
|
local offset = 0.5 * size
|
||||||
|
|
||||||
return function(local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
|
local sn = math.ceil(local_y + offset)
|
||||||
|
|
||||||
local sn = math.ceil(local_y + offset)
|
local n = math.ceil(math.log((r - 1) * sn * a + 1) / ln_r - 1)
|
||||||
|
|
||||||
local n = math.ceil(math.log((r-1) * sn * a + 1) / ln_r - 1)
|
|
||||||
local rn = r ^ n
|
local rn = r ^ n
|
||||||
local rn2 = 1 / rn
|
local rn2 = 1 / rn
|
||||||
local c = size * rn
|
local c = size * rn
|
||||||
|
|
||||||
local sn_upper = size * (r ^ (n + 1) - 1) * r2
|
local sn_upper = size * (r ^ (n + 1) - 1) * r2
|
||||||
local x = local_x * rn2
|
local x = local_x * rn2
|
||||||
local y = (local_y - (sn_upper - 0.5 * c ) + offset ) * rn2
|
local y = (local_y - (sn_upper - 0.5 * c) + offset) * rn2
|
||||||
|
|
||||||
local tile
|
local tile
|
||||||
local entity
|
local entity
|
||||||
|
|
||||||
tile, entity = shape(x, y, world_x, world_y)
|
tile, entity = shape(x, y, world_x, world_y, surface)
|
||||||
if tile then
|
if tile then
|
||||||
return tile, entity
|
return tile, entity
|
||||||
end
|
end
|
||||||
@ -436,10 +410,12 @@ function project_overlap(shape, size, r)
|
|||||||
|
|
||||||
local sn_upper_above = sn_upper - c
|
local sn_upper_above = sn_upper - c
|
||||||
local x_above = local_x * rn2_above
|
local x_above = local_x * rn2_above
|
||||||
local y_above = (local_y - (sn_upper_above - 0.5 * c_above ) + offset ) * rn2_above
|
local y_above = (local_y - (sn_upper_above - 0.5 * c_above) + offset) * rn2_above
|
||||||
|
|
||||||
tile, entity = shape(x_above, y_above, world_x, world_y)
|
tile, entity = shape(x_above, y_above, world_x, world_y, surface)
|
||||||
if tile then return tile, entity end
|
if tile then
|
||||||
|
return tile, entity
|
||||||
|
end
|
||||||
|
|
||||||
local n_below = n + 1
|
local n_below = n + 1
|
||||||
local rn_below = rn * r
|
local rn_below = rn * r
|
||||||
@ -448,10 +424,9 @@ function project_overlap(shape, size, r)
|
|||||||
|
|
||||||
local sn_upper_below = sn_upper + c_below
|
local sn_upper_below = sn_upper + c_below
|
||||||
local x_below = local_x * rn2_below
|
local x_below = local_x * rn2_below
|
||||||
local y_below = (local_y - (sn_upper_below - 0.5 * c_below ) + offset ) * rn2_below
|
local y_below = (local_y - (sn_upper_below - 0.5 * c_below) + offset) * rn2_below
|
||||||
|
|
||||||
return shape(x_below, y_below, world_x, world_y)
|
|
||||||
|
|
||||||
|
return shape(x_below, y_below, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -459,11 +434,12 @@ end
|
|||||||
|
|
||||||
-- builder is the shape of the ore patch.
|
-- builder is the shape of the ore patch.
|
||||||
function resource_module_builder(builder, resource_type, amount_function)
|
function resource_module_builder(builder, resource_type, amount_function)
|
||||||
amount_function = amount_function or function(a, b) return 603 end
|
amount_function = amount_function or function(a, b)
|
||||||
return function(x, y, world_x, world_y)
|
return 603
|
||||||
if builder(x, y, world_x, world_y) then
|
end
|
||||||
return
|
return function(x, y, world_x, world_y, surface)
|
||||||
{
|
if builder(x, y, world_x, world_y, surface) then
|
||||||
|
return {
|
||||||
name = resource_type,
|
name = resource_type,
|
||||||
position = {world_x, world_y},
|
position = {world_x, world_y},
|
||||||
amount = amount_function(world_x, world_y)
|
amount = amount_function(world_x, world_y)
|
||||||
@ -475,10 +451,10 @@ function resource_module_builder(builder, resource_type, amount_function)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function builder_with_resource(land_builder, resource_module)
|
function builder_with_resource(land_builder, resource_module)
|
||||||
return function (x, y, world_x, world_y)
|
return function(x, y, world_x, world_y, surface)
|
||||||
local tile = land_builder(x, y)
|
local tile = land_builder(x, y, world_x, world_y, surface)
|
||||||
if tile then
|
if tile then
|
||||||
local entity = resource_module(x, y ,world_x, world_y)
|
local entity = resource_module(x, y, world_x, world_y, surface)
|
||||||
return tile, entity
|
return tile, entity
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
@ -489,9 +465,8 @@ end
|
|||||||
-- pattern builders.
|
-- pattern builders.
|
||||||
|
|
||||||
function single_pattern_builder(shape, width, height)
|
function single_pattern_builder(shape, width, height)
|
||||||
|
|
||||||
shape = shape or empty_builder
|
shape = shape or empty_builder
|
||||||
local half_width = width / 2
|
local half_width = width / 2
|
||||||
local half_height
|
local half_height
|
||||||
if height then
|
if height then
|
||||||
half_height = height / 2
|
half_height = height / 2
|
||||||
@ -499,18 +474,17 @@ function single_pattern_builder(shape, width, height)
|
|||||||
half_height = half_width
|
half_height = half_width
|
||||||
end
|
end
|
||||||
|
|
||||||
return function (local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local_y = ((local_y + half_height) % height) - half_height
|
local_y = ((local_y + half_height) % height) - half_height
|
||||||
local_x = ((local_x + half_width) % width) - half_width
|
local_x = ((local_x + half_width) % width) - half_width
|
||||||
|
|
||||||
return shape(local_x, local_y, world_x, world_y)
|
return shape(local_x, local_y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function single_pattern_overlap_builder(shape, width, height)
|
function single_pattern_overlap_builder(shape, width, height)
|
||||||
|
|
||||||
shape = shape or empty_builder
|
shape = shape or empty_builder
|
||||||
local half_width = width / 2
|
local half_width = width / 2
|
||||||
local half_height
|
local half_height
|
||||||
if height then
|
if height then
|
||||||
half_height = height / 2
|
half_height = height / 2
|
||||||
@ -518,48 +492,45 @@ function single_pattern_overlap_builder(shape, width, height)
|
|||||||
half_height = half_width
|
half_height = half_width
|
||||||
end
|
end
|
||||||
|
|
||||||
return function (local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local_y = ((local_y + half_height) % height) - half_height
|
local_y = ((local_y + half_height) % height) - half_height
|
||||||
local_x = ((local_x + half_width) % width) - half_width
|
local_x = ((local_x + half_width) % width) - half_width
|
||||||
|
|
||||||
return shape(local_x, local_y, world_x, world_y)
|
return shape(local_x, local_y, world_x, world_y, surface) or
|
||||||
or shape(local_x + width, local_y, world_x, world_y)
|
shape(local_x + width, local_y, world_x, world_y, surface) or
|
||||||
or shape(local_x - width, local_y, world_x, world_y)
|
shape(local_x - width, local_y, world_x, world_y, surface) or
|
||||||
or shape(local_x, local_y + height, world_x, world_y)
|
shape(local_x, local_y + height, world_x, world_y, surface) or
|
||||||
or shape(local_x, local_y - height, world_x, world_y)
|
shape(local_x, local_y - height, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function single_x_pattern_builder(shape, width)
|
function single_x_pattern_builder(shape, width)
|
||||||
|
|
||||||
shape = shape or empty_builder
|
shape = shape or empty_builder
|
||||||
local half_width = width / 2
|
local half_width = width / 2
|
||||||
|
|
||||||
return function (local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local_x = ((local_x + half_width) % width) - half_width
|
local_x = ((local_x + half_width) % width) - half_width
|
||||||
|
|
||||||
return shape(local_x, local_y, world_x, world_y)
|
return shape(local_x, local_y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function single_y_pattern_builder(shape, height)
|
function single_y_pattern_builder(shape, height)
|
||||||
|
shape = shape or empty_builder
|
||||||
shape = shape or empty_builder
|
|
||||||
local half_height = height / 2
|
local half_height = height / 2
|
||||||
|
|
||||||
return function (local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local_y = ((local_y + half_height) % height) - half_height
|
local_y = ((local_y + half_height) % height) - half_height
|
||||||
|
|
||||||
return shape(local_x, local_y, world_x, world_y)
|
return shape(local_x, local_y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function grid_pattern_builder(pattern, columns, rows, width, height)
|
function grid_pattern_builder(pattern, columns, rows, width, height)
|
||||||
|
local half_width = width / 2
|
||||||
local half_width = width / 2
|
|
||||||
local half_height = height / 2
|
local half_height = height / 2
|
||||||
|
|
||||||
return function (local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local local_y2 = ((local_y + half_height) % height) - half_height
|
local local_y2 = ((local_y + half_height) % height) - half_height
|
||||||
local row_pos = math.floor(local_y / height + 0.5)
|
local row_pos = math.floor(local_y / height + 0.5)
|
||||||
local row_i = row_pos % rows + 1
|
local row_i = row_pos % rows + 1
|
||||||
@ -570,26 +541,26 @@ function grid_pattern_builder(pattern, columns, rows, width, height)
|
|||||||
local col_i = col_pos % columns + 1
|
local col_i = col_pos % columns + 1
|
||||||
|
|
||||||
local shape = row[col_i] or empty_builder
|
local shape = row[col_i] or empty_builder
|
||||||
return shape(local_x2, local_y2, world_x, world_y)
|
return shape(local_x2, local_y2, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function segment_pattern_builder(pattern)
|
function segment_pattern_builder(pattern)
|
||||||
local count = #pattern
|
local count = #pattern
|
||||||
|
|
||||||
return function(local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local angle = math.atan2(-local_y , local_x)
|
local angle = math.atan2(-local_y, local_x)
|
||||||
local index = math.floor(angle / tau * count) % count + 1
|
local index = math.floor(angle / tau * count) % count + 1
|
||||||
local shape = pattern[index] or empty_builder
|
local shape = pattern[index] or empty_builder
|
||||||
return shape(local_x, local_y, world_x, world_y)
|
return shape(local_x, local_y, world_x, world_y, surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- tile converters
|
-- tile converters
|
||||||
|
|
||||||
function change_tile(builder, old_tile, new_tile)
|
function change_tile(builder, old_tile, new_tile)
|
||||||
return function (local_x, local_y, world_x, world_y )
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local tile, entity = builder(local_x, local_y, world_x, world_y)
|
local tile, entity = builder(local_x, local_y, world_x, world_y, surface)
|
||||||
if tile == old_tile then
|
if tile == old_tile then
|
||||||
tile = new_tile
|
tile = new_tile
|
||||||
end
|
end
|
||||||
@ -598,8 +569,8 @@ function change_tile(builder, old_tile, new_tile)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function change_collision_tile(builder, collides, new_tile)
|
function change_collision_tile(builder, collides, new_tile)
|
||||||
return function (local_x, local_y, world_x, world_y )
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local tile, entity = builder(local_x, local_y, world_x, world_y)
|
local tile, entity = builder(local_x, local_y, world_x, world_y, surface)
|
||||||
if tile.collides_with(collides) then
|
if tile.collides_with(collides) then
|
||||||
tile = new_tile
|
tile = new_tile
|
||||||
end
|
end
|
||||||
@ -609,10 +580,10 @@ end
|
|||||||
|
|
||||||
-- only changes tiles made by the factorio map generator.
|
-- only changes tiles made by the factorio map generator.
|
||||||
function change_map_gen_tile(builder, old_tile, new_tile)
|
function change_map_gen_tile(builder, old_tile, new_tile)
|
||||||
return function (local_x, local_y, world_x, world_y )
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local tile, entity = builder(local_x, local_y, world_x, world_y)
|
local tile, entity = builder(local_x, local_y, world_x, world_y, surface)
|
||||||
if type(tile) == "boolean" and tile then
|
if type(tile) == "boolean" and tile then
|
||||||
local gen_tile = MAP_GEN_SURFACE.get_tile(world_x, world_y).name
|
local gen_tile = surface.get_tile(world_x, world_y).name
|
||||||
if old_tile == gen_tile then
|
if old_tile == gen_tile then
|
||||||
tile = new_tile
|
tile = new_tile
|
||||||
end
|
end
|
||||||
@ -623,10 +594,10 @@ end
|
|||||||
|
|
||||||
-- only changes tiles made by the factorio map generator.
|
-- only changes tiles made by the factorio map generator.
|
||||||
function change_map_gen_collision_tile(builder, collides, new_tile)
|
function change_map_gen_collision_tile(builder, collides, new_tile)
|
||||||
return function (local_x, local_y, world_x, world_y )
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local tile, entity = builder(local_x, local_y, world_x, world_y)
|
local tile, entity = builder(local_x, local_y, world_x, world_y, surface)
|
||||||
if type(tile) == "boolean" and tile then
|
if type(tile) == "boolean" and tile then
|
||||||
local gen_tile = MAP_GEN_SURFACE.get_tile(world_x, world_y)
|
local gen_tile = surface.get_tile(world_x, world_y)
|
||||||
if gen_tile.collides_with(collides) then
|
if gen_tile.collides_with(collides) then
|
||||||
tile = new_tile
|
tile = new_tile
|
||||||
end
|
end
|
||||||
@ -636,20 +607,17 @@ function change_map_gen_collision_tile(builder, collides, new_tile)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function spawn_fish(builder, spawn_rate)
|
function spawn_fish(builder, spawn_rate)
|
||||||
return function (local_x, local_y, world_x, world_y )
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local tile, entity = builder(local_x, local_y, world_x, world_y)
|
local tile, entity = builder(local_x, local_y, world_x, world_y, surface)
|
||||||
if type(tile) == "string" then
|
if type(tile) == "string" then
|
||||||
if tile == "water" or tile == "deepwater" or tile == "water-green" or tile == "deepwater-green" then
|
if tile == "water" or tile == "deepwater" or tile == "water-green" or tile == "deepwater-green" then
|
||||||
if spawn_rate >= math.random() then
|
|
||||||
entity = {name = "fish", position = {world_x, world_y}}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif tile then
|
|
||||||
local gen_tile = MAP_GEN_SURFACE.get_tile(world_x, world_y)
|
|
||||||
if gen_tile == "water" or gen_tile == "deepwater" or gen_tile == "water-green" or gen_tile == "deepwater-green" then
|
|
||||||
if spawn_rate >= math.random() then
|
if spawn_rate >= math.random() then
|
||||||
entity = {name = "fish", position = {world_x, world_y}}
|
entity = {name = "fish", position = {world_x, world_y}}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
elseif tile then
|
||||||
|
if surface.get_tile(world_x, world_y).collides_with("water-tile") and spawn_rate >= math.random() then
|
||||||
|
entity = {name = "fish", position = {world_x, world_y}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return tile, entity
|
return tile, entity
|
||||||
@ -657,10 +625,9 @@ function spawn_fish(builder, spawn_rate)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function apply_effect(builder, func)
|
function apply_effect(builder, func)
|
||||||
return function(local_x, local_y, world_x, world_y)
|
return function(local_x, local_y, world_x, world_y, surface)
|
||||||
local tile, entity = builder(local_x, local_y, world_x, world_y)
|
local tile, entity = builder(local_x, local_y, world_x, world_y, surface)
|
||||||
tile, entity = func(local_x, local_y, world_x, world_y, tile, entity)
|
tile, entity = func(local_x, local_y, world_x, world_y, tile, entity, surface)
|
||||||
return tile, entity
|
return tile, entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,327 +6,330 @@ local Task = require "utils.Task"
|
|||||||
map_gen_rows_per_tick = map_gen_rows_per_tick or 4
|
map_gen_rows_per_tick = map_gen_rows_per_tick or 4
|
||||||
map_gen_rows_per_tick = math.min(32, math.max(1, map_gen_rows_per_tick))
|
map_gen_rows_per_tick = math.min(32, math.max(1, map_gen_rows_per_tick))
|
||||||
|
|
||||||
local function do_row(row, data)
|
local function do_row(row, data)
|
||||||
local y = data.top_y + row
|
local y = data.top_y + row
|
||||||
local top_x = data.top_x
|
local top_x = data.top_x
|
||||||
|
|
||||||
for x = top_x, top_x + 31 do
|
for x = top_x, top_x + 31 do
|
||||||
|
-- local coords need to be 'centered' to allow for correct rotation and scaling.
|
||||||
|
local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y, data.surface)
|
||||||
|
|
||||||
-- local coords need to be 'centered' to allow for correct rotation and scaling.
|
if type(tile) == "boolean" and not tile then
|
||||||
local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y)
|
table.insert(data.tiles, {name = "out-of-map", position = {x, y}})
|
||||||
|
elseif type(tile) == "string" then
|
||||||
|
table.insert(data.tiles, {name = tile, position = {x, y}})
|
||||||
|
end
|
||||||
|
|
||||||
if type(tile) == "boolean" and not tile then
|
if map_gen_decoratives then
|
||||||
table.insert(data.tiles, {name = "out-of-map", position = {x, y}})
|
tile_decoratives = check_decorative(tile, x, y)
|
||||||
elseif type(tile) == "string" then
|
for _, tbl in ipairs(tile_decoratives) do
|
||||||
table.insert(data.tiles, {name = tile, position = {x, y}})
|
table.insert(data.decoratives, tbl)
|
||||||
|
end
|
||||||
|
|
||||||
|
tile_entities = check_entities(tile, x, y)
|
||||||
|
for _, entity in ipairs(tile_entities) do
|
||||||
|
table.insert(data.entities, entity)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if entity then
|
||||||
|
table.insert(data.entities, entity)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if map_gen_decoratives then
|
|
||||||
tile_decoratives = check_decorative(tile, x, y)
|
|
||||||
for _,tbl in ipairs(tile_decoratives) do
|
|
||||||
table.insert(data.decoratives, tbl)
|
|
||||||
end
|
|
||||||
|
|
||||||
tile_entities = check_entities(tile, x, y)
|
|
||||||
for _,entity in ipairs(tile_entities) do
|
|
||||||
table.insert(data.entities, entity)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if entity then
|
|
||||||
table.insert(data.entities, entity)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_place_tiles(data)
|
local function do_place_tiles(data)
|
||||||
data.surface.set_tiles(data.tiles, true)
|
data.surface.set_tiles(data.tiles, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_place_decoratives(data)
|
local function do_place_decoratives(data)
|
||||||
if not map_gen_decoratives then return end
|
if not map_gen_decoratives then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
for _, e in pairs(surface.find_entities_filtered{area=area, type="decorative"}) do
|
for _, e in pairs(surface.find_entities_filtered {area = area, type = "decorative"}) do
|
||||||
e.destroy()
|
e.destroy()
|
||||||
end
|
end
|
||||||
for _, e in pairs(surface.find_entities_filtered{area=area, type="simple-entity"}) do
|
for _, e in pairs(surface.find_entities_filtered {area = area, type = "simple-entity"}) do
|
||||||
e.destroy()
|
e.destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
local surface = data.surface
|
local surface = data.surface
|
||||||
for _,d in pairs(data.decoratives) do
|
for _, d in pairs(data.decoratives) do
|
||||||
surface.create_decoratives{check_collision=false, decoratives={d}}
|
surface.create_decoratives {check_collision = false, decoratives = {d}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_place_entities(data)
|
local function do_place_entities(data)
|
||||||
local surface = data.surface
|
local surface = data.surface
|
||||||
for _, e in ipairs(data.entities) do
|
for _, e in ipairs(data.entities) do
|
||||||
if surface.can_place_entity(e) then
|
if surface.can_place_entity(e) then
|
||||||
surface.create_entity(e)
|
surface.create_entity(e)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function run_chart_update(params)
|
local function run_chart_update(params)
|
||||||
local x = params.area.left_top.x / 32
|
local x = data.top_x / 32
|
||||||
local y = params.area.left_top.y / 32
|
local y = data.top_y / 32
|
||||||
if game.forces.player.is_chunk_charted(params.surface, {x,y} ) then
|
if game.forces.player.is_chunk_charted(params.surface, {x, y}) then
|
||||||
-- Don't use full area, otherwise adjacent chunks get charted
|
-- Don't use full area, otherwise adjacent chunks get charted
|
||||||
game.forces.player.chart(params.surface, {{ params.area.left_top.x, params.area.left_top.y}, { params.area.left_top.x+30, params.area.left_top.y+30} } )
|
game.forces.player.chart(
|
||||||
end
|
params.surface,
|
||||||
|
{
|
||||||
|
{data.top_x, data.top_y},
|
||||||
|
{data.top_x + 1, data.top_y + 1}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function map_gen_action(data)
|
function map_gen_action(data)
|
||||||
local state = data.state
|
local state = data.state
|
||||||
if state < 32 then
|
if state < 32 then
|
||||||
do_row(state, data)
|
do_row(state, data)
|
||||||
data.state = state + 1
|
data.state = state + 1
|
||||||
return true
|
return true
|
||||||
elseif state == 32 then
|
elseif state == 32 then
|
||||||
do_place_tiles(data)
|
do_place_tiles(data)
|
||||||
data.state = 33
|
data.state = 33
|
||||||
return true
|
return true
|
||||||
elseif state == 33 then
|
elseif state == 33 then
|
||||||
do_place_decoratives(data)
|
do_place_decoratives(data)
|
||||||
data.state = 34
|
data.state = 34
|
||||||
return true
|
return true
|
||||||
elseif state == 34 then
|
elseif state == 34 then
|
||||||
do_place_entities(data)
|
do_place_entities(data)
|
||||||
return false
|
data.state = 35
|
||||||
end
|
return true
|
||||||
|
elseif state == 35 then
|
||||||
|
run_chart_update(data)
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function run_combined_module(event)
|
function run_combined_module(event)
|
||||||
|
if MAP_GEN == nil then
|
||||||
|
game.print("MAP_GEN not set")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if MAP_GEN == nil then
|
local area = event.area
|
||||||
game.print("MAP_GEN not set")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local area = event.area
|
local data = {
|
||||||
local surface = event.surface
|
state = 0,
|
||||||
MAP_GEN_SURFACE = surface
|
top_x = area.left_top.x,
|
||||||
|
top_y = area.left_top.y,
|
||||||
local data =
|
surface = event.surface,
|
||||||
{
|
tiles = {},
|
||||||
state = 0,
|
entities = {},
|
||||||
top_x = area.left_top.x,
|
decoratives = {}
|
||||||
top_y = area.left_top.y ,
|
}
|
||||||
surface = surface,
|
Task.queue_task("map_gen_action", data, 35)
|
||||||
tiles = {},
|
|
||||||
entities = {},
|
|
||||||
decoratives = {}
|
|
||||||
}
|
|
||||||
Task.queue_task("map_gen_action", data, 35)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local decorative_options = {
|
local decorative_options = {
|
||||||
["concrete"] = {},
|
["concrete"] = {},
|
||||||
["deepwater"] = {},
|
["deepwater"] = {},
|
||||||
["deepwater-green"] = {
|
["deepwater-green"] = {
|
||||||
{"brown-carpet-grass", 100},
|
{"brown-carpet-grass", 100},
|
||||||
{"brown-cane-cluster", 500},
|
{"brown-cane-cluster", 500}
|
||||||
},
|
},
|
||||||
["dirt-3"] = {
|
["dirt-3"] = {
|
||||||
{"brown-carpet-grass", 100},
|
{"brown-carpet-grass", 100},
|
||||||
{"brown-cane-cluster", 200},
|
{"brown-cane-cluster", 200},
|
||||||
{"sand-rock-small", 150},
|
{"sand-rock-small", 150}
|
||||||
},
|
},
|
||||||
["dirt-6"] = {
|
["dirt-6"] = {
|
||||||
{"sand-rock-small", 150},
|
{"sand-rock-small", 150},
|
||||||
{"red-asterisk", 45},
|
{"red-asterisk", 45},
|
||||||
{"red-desert-bush", 12},
|
{"red-desert-bush", 12},
|
||||||
{"rock-medium", 375},
|
{"rock-medium", 375}
|
||||||
|
},
|
||||||
|
["grass-1"] = {
|
||||||
},
|
{"green-carpet-grass-1", 3},
|
||||||
["grass-1"] = {
|
{"green-hairy-grass-1", 7},
|
||||||
{"green-carpet-grass-1", 3},
|
{"green-bush-mini", 10},
|
||||||
{"green-hairy-grass-1", 7},
|
{"green-pita", 6},
|
||||||
{"green-bush-mini", 10},
|
{"green-small-grass-1", 12},
|
||||||
{"green-pita", 6},
|
{"green-asterisk", 25},
|
||||||
{"green-small-grass-1", 12},
|
{"green-bush-mini", 7},
|
||||||
{"green-asterisk", 25},
|
{"garballo", 20}
|
||||||
{"green-bush-mini", 7},
|
},
|
||||||
{"garballo", 20},
|
["grass-3"] = {
|
||||||
},
|
{"green-carpet-grass-1", 12},
|
||||||
["grass-3"] = {
|
{"green-hairy-grass-1", 28},
|
||||||
{"green-carpet-grass-1", 12},
|
{"green-bush-mini", 40},
|
||||||
{"green-hairy-grass-1", 28},
|
{"green-pita", 24},
|
||||||
{"green-bush-mini", 40},
|
{"green-small-grass-1", 48},
|
||||||
{"green-pita", 24},
|
{"green-asterisk", 100},
|
||||||
{"green-small-grass-1", 48},
|
{"green-bush-mini", 28}
|
||||||
{"green-asterisk", 100},
|
},
|
||||||
{"green-bush-mini", 28},
|
["grass-2"] = {
|
||||||
},
|
{"green-hairy-grass-1", 56},
|
||||||
["grass-2"] = {
|
{"green-bush-mini", 80},
|
||||||
{"green-hairy-grass-1", 56},
|
{"green-pita", 48},
|
||||||
{"green-bush-mini", 80},
|
{"green-small-grass-1", 96},
|
||||||
{"green-pita", 48},
|
{"green-asterisk", 200},
|
||||||
{"green-small-grass-1", 96},
|
{"green-bush-mini", 56},
|
||||||
{"green-asterisk", 200},
|
{"brown-cane-cluster", 100},
|
||||||
{"green-bush-mini", 56},
|
{"brown-carpet-grass", 100}
|
||||||
{"brown-cane-cluster", 100},
|
},
|
||||||
{"brown-carpet-grass", 100},
|
["hazard-concrete-left"] = {},
|
||||||
},
|
["hazard-concrete-right"] = {},
|
||||||
["hazard-concrete-left"] = {},
|
["lab-dark-1"] = {},
|
||||||
["hazard-concrete-right"] = {},
|
["lab-dark-2"] = {},
|
||||||
["lab-dark-1"] = {},
|
["red-desert"] = {
|
||||||
["lab-dark-2"] = {},
|
{"brown-carpet-grass", 35},
|
||||||
["red-desert"] = {
|
{"orange-coral-mini", 45},
|
||||||
{"brown-carpet-grass", 35},
|
{"red-asterisk", 45},
|
||||||
{"orange-coral-mini", 45},
|
{"red-desert-bush", 12},
|
||||||
{"red-asterisk", 45},
|
{"rock-medium", 375},
|
||||||
{"red-desert-bush", 12},
|
{"sand-rock-small", 200},
|
||||||
{"rock-medium", 375},
|
{"sand-rock-small", 30}
|
||||||
{"sand-rock-small", 200},
|
},
|
||||||
{"sand-rock-small", 30},
|
["red-desert-dark"] = {
|
||||||
},
|
{"brown-carpet-grass", 70},
|
||||||
["red-desert-dark"] = {
|
{"orange-coral-mini", 90},
|
||||||
{"brown-carpet-grass", 70},
|
{"red-asterisk", 90},
|
||||||
{"orange-coral-mini", 90},
|
{"red-desert-bush", 35},
|
||||||
{"red-asterisk", 90},
|
{"rock-medium", 375},
|
||||||
{"red-desert-bush", 35},
|
{"sand-rock-small", 200},
|
||||||
{"rock-medium", 375},
|
{"sand-rock-small", 150}
|
||||||
{"sand-rock-small", 200},
|
},
|
||||||
{"sand-rock-small", 150},
|
["sand-1"] = {
|
||||||
},
|
{"brown-carpet-grass", 35},
|
||||||
["sand-1"] = {
|
{"orange-coral-mini", 45},
|
||||||
{"brown-carpet-grass", 35},
|
{"red-asterisk", 45},
|
||||||
{"orange-coral-mini", 45},
|
{"brown-asterisk", 45}
|
||||||
{"red-asterisk", 45},
|
},
|
||||||
{"brown-asterisk", 45},
|
["sand-3"] = {
|
||||||
},
|
{"brown-carpet-grass", 35},
|
||||||
["sand-3"] = {
|
{"orange-coral-mini", 45},
|
||||||
{"brown-carpet-grass", 35},
|
{"brown-asterisk", 45}
|
||||||
{"orange-coral-mini", 45},
|
},
|
||||||
{"brown-asterisk", 45},
|
["stone-path"] = {},
|
||||||
},
|
["water"] = {},
|
||||||
["stone-path"] = {},
|
["water-green"] = {},
|
||||||
["water"] = {},
|
["out-of-map"] = {}
|
||||||
["water-green"] = {},
|
|
||||||
["out-of-map"] = {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local function check_decorative(tile, x, y)
|
local function check_decorative(tile, x, y)
|
||||||
local options = decorative_options[tile]
|
local options = decorative_options[tile]
|
||||||
local tile_decoratives = {}
|
local tile_decoratives = {}
|
||||||
|
|
||||||
for _,e in ipairs(options) do
|
for _, e in ipairs(options) do
|
||||||
name = e[1]
|
name = e[1]
|
||||||
high_roll = e[2]
|
high_roll = e[2]
|
||||||
if poisson_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}})
|
table.insert(tile_decoratives, {name = name, amount = 1, position = {x, y}})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return tile_decoratives
|
return tile_decoratives
|
||||||
end
|
end
|
||||||
|
|
||||||
local entity_options = {
|
local entity_options = {
|
||||||
["concrete"] = {},
|
["concrete"] = {},
|
||||||
["deepwater"] = {},
|
["deepwater"] = {},
|
||||||
["deepwater-green"] = {},
|
["deepwater-green"] = {},
|
||||||
["water"] = {},
|
["water"] = {},
|
||||||
["water-green"] = {},
|
["water-green"] = {},
|
||||||
["dirt-3"] = {
|
["dirt-3"] = {
|
||||||
{"tree-01", 500},
|
{"tree-01", 500},
|
||||||
{"tree-06", 300},
|
{"tree-06", 300},
|
||||||
{"tree-07", 800},
|
{"tree-07", 800},
|
||||||
{"tree-09", 2000},
|
{"tree-09", 2000},
|
||||||
{"rock-big", 400},
|
{"rock-big", 400}
|
||||||
},
|
},
|
||||||
["dirt-6"] = {
|
["dirt-6"] = {
|
||||||
{"tree-06", 150},
|
{"tree-06", 150},
|
||||||
{"tree-07", 400},
|
{"tree-07", 400},
|
||||||
{"tree-09", 1000},
|
{"tree-09", 1000},
|
||||||
{"rock-big", 300},
|
{"rock-big", 300}
|
||||||
},
|
},
|
||||||
["grass-1"] = {
|
["grass-1"] = {
|
||||||
{"tree-01", 150},
|
{"tree-01", 150},
|
||||||
{"tree-04", 400},
|
{"tree-04", 400},
|
||||||
{"tree-06", 400},
|
{"tree-06", 400},
|
||||||
{"tree-07", 400},
|
{"tree-07", 400},
|
||||||
{"tree-09", 1000},
|
{"tree-09", 1000},
|
||||||
{"rock-big", 400},
|
{"rock-big", 400},
|
||||||
{"green-coral", 10000},
|
{"green-coral", 10000}
|
||||||
},
|
},
|
||||||
["grass-3"] = {
|
["grass-3"] = {
|
||||||
{"tree-02", 400},
|
{"tree-02", 400},
|
||||||
{"tree-03", 400},
|
{"tree-03", 400},
|
||||||
{"tree-04", 800},
|
{"tree-04", 800},
|
||||||
{"tree-06", 300},
|
{"tree-06", 300},
|
||||||
{"tree-07", 800},
|
{"tree-07", 800},
|
||||||
{"tree-08", 400},
|
{"tree-08", 400},
|
||||||
{"tree-09", 2000},
|
{"tree-09", 2000},
|
||||||
{"rock-big", 400},
|
{"rock-big", 400}
|
||||||
},
|
},
|
||||||
["grass-2"] = {
|
["grass-2"] = {
|
||||||
{"tree-04", 800},
|
{"tree-04", 800},
|
||||||
{"tree-06", 300},
|
{"tree-06", 300},
|
||||||
{"tree-07", 400},
|
{"tree-07", 400},
|
||||||
{"tree-09", 1000},
|
{"tree-09", 1000},
|
||||||
{"dry-tree", 1000},
|
{"dry-tree", 1000},
|
||||||
{"rock-big", 200},
|
{"rock-big", 200}
|
||||||
},
|
},
|
||||||
["hazard-concrete-left"] = {},
|
["hazard-concrete-left"] = {},
|
||||||
["hazard-concrete-right"] = {},
|
["hazard-concrete-right"] = {},
|
||||||
["lab-dark-1"] = {},
|
["lab-dark-1"] = {},
|
||||||
["lab-dark-2"] = {},
|
["lab-dark-2"] = {},
|
||||||
["red-desert"] = {
|
["red-desert"] = {
|
||||||
{"dry-tree", 400},
|
{"dry-tree", 400},
|
||||||
{"dry-hairy-tree", 400},
|
{"dry-hairy-tree", 400},
|
||||||
{"tree-06", 500},
|
{"tree-06", 500},
|
||||||
{"tree-06", 500},
|
{"tree-06", 500},
|
||||||
{"tree-01", 500},
|
{"tree-01", 500},
|
||||||
{"tree-02", 500},
|
{"tree-02", 500},
|
||||||
{"tree-03", 500},
|
{"tree-03", 500},
|
||||||
{"sand-rock-big", 200},
|
{"sand-rock-big", 200},
|
||||||
{"sand-rock-big", 400},
|
{"sand-rock-big", 400},
|
||||||
{"red-desert-rock-huge-02", 400},
|
{"red-desert-rock-huge-02", 400}
|
||||||
},
|
},
|
||||||
["red-desert-dark"] = {
|
["red-desert-dark"] = {
|
||||||
{"dry-tree", 400},
|
{"dry-tree", 400},
|
||||||
{"dry-hairy-tree", 400},
|
{"dry-hairy-tree", 400},
|
||||||
{"tree-06", 500},
|
{"tree-06", 500},
|
||||||
{"tree-06", 500},
|
{"tree-06", 500},
|
||||||
{"tree-01", 500},
|
{"tree-01", 500},
|
||||||
{"tree-02", 500},
|
{"tree-02", 500},
|
||||||
{"tree-03", 500},
|
{"tree-03", 500},
|
||||||
{"sand-rock-big", 200},
|
{"sand-rock-big", 200},
|
||||||
{"sand-rock-big", 400},
|
{"sand-rock-big", 400},
|
||||||
{"red-desert-rock-huge-02", 400},
|
{"red-desert-rock-huge-02", 400}
|
||||||
},
|
},
|
||||||
["sand-1"] = {
|
["sand-1"] = {
|
||||||
{"dry-tree", 1000},
|
{"dry-tree", 1000},
|
||||||
{"dry-hairy-tree", 1000},
|
{"dry-hairy-tree", 1000},
|
||||||
{"dead-tree", 1000},
|
{"dead-tree", 1000},
|
||||||
{"rock-big", 150},
|
{"rock-big", 150}
|
||||||
|
},
|
||||||
},
|
["sand-3"] = {
|
||||||
["sand-3"] = {
|
{"dead-tree", 1000},
|
||||||
{"dead-tree", 1000},
|
{"dry-tree", 1000},
|
||||||
{"dry-tree", 1000},
|
{"dry-hairy-tree", 1000},
|
||||||
{"dry-hairy-tree", 1000},
|
{"rock-big", 150}
|
||||||
{"rock-big", 150},
|
},
|
||||||
|
["stone-path"] = {},
|
||||||
},
|
["out-of-map"] = {}
|
||||||
["stone-path"] = {},
|
|
||||||
["out-of-map"] = {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_entities(tile, x, y)
|
function check_entities(tile, x, y)
|
||||||
local options = entity_options[tile]
|
local options = entity_options[tile]
|
||||||
local tile_entity_list = {}
|
local tile_entity_list = {}
|
||||||
|
|
||||||
for _,e in ipairs(options) do
|
for _, e in ipairs(options) do
|
||||||
name = e[1]
|
name = e[1]
|
||||||
high_roll = e[2]
|
high_roll = e[2]
|
||||||
if poisson_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}})
|
table.insert(tile_entity_list, {name = name, position = {x, y}})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return tile_entity_list
|
return tile_entity_list
|
||||||
end
|
end
|
||||||
|
@ -1,305 +1,297 @@
|
|||||||
require("map_gen.shared.builders")
|
require("map_gen.shared.builders")
|
||||||
require("utils.poisson_rng")
|
require("utils.poisson_rng")
|
||||||
|
|
||||||
local function do_row(row, data)
|
local function do_row(row, data)
|
||||||
local y = data.top_y + row
|
local y = data.top_y + row
|
||||||
local top_x = data.top_x
|
local top_x = data.top_x
|
||||||
|
|
||||||
for x = top_x, top_x + 31 do
|
for x = top_x, top_x + 31 do
|
||||||
|
-- local coords need to be 'centered' to allow for correct rotation and scaling.
|
||||||
|
local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y, data.surface)
|
||||||
|
|
||||||
-- local coords need to be 'centered' to allow for correct rotation and scaling.
|
if type(tile) == "boolean" and not tile then
|
||||||
local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y)
|
table.insert(data.tiles, {name = "out-of-map", position = {x, y}})
|
||||||
|
elseif type(tile) == "string" then
|
||||||
|
table.insert(data.tiles, {name = tile, position = {x, y}})
|
||||||
|
end
|
||||||
|
|
||||||
if type(tile) == "boolean" and not tile then
|
if map_gen_decoratives then
|
||||||
table.insert(data.tiles, {name = "out-of-map", position = {x, y}})
|
tile_decoratives = check_decorative(tile, x, y)
|
||||||
elseif type(tile) == "string" then
|
for _, tbl in ipairs(tile_decoratives) do
|
||||||
table.insert(data.tiles, {name = tile, position = {x, y}})
|
table.insert(data.decoratives, tbl)
|
||||||
|
end
|
||||||
|
|
||||||
|
tile_entities = check_entities(tile, x, y)
|
||||||
|
for _, entity in ipairs(tile_entities) do
|
||||||
|
table.insert(data.entities, entity)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if entity then
|
||||||
|
table.insert(data.entities, entity)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if map_gen_decoratives then
|
|
||||||
tile_decoratives = check_decorative(tile, x, y)
|
|
||||||
for _,tbl in ipairs(tile_decoratives) do
|
|
||||||
table.insert(data.decoratives, tbl)
|
|
||||||
end
|
|
||||||
|
|
||||||
tile_entities = check_entities(tile, x, y)
|
|
||||||
for _,entity in ipairs(tile_entities) do
|
|
||||||
table.insert(data.entities, entity)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if entity then
|
|
||||||
table.insert(data.entities, entity)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_place_tiles(data)
|
local function do_place_tiles(data)
|
||||||
data.surface.set_tiles(data.tiles, true)
|
data.surface.set_tiles(data.tiles, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_place_decoratives(data)
|
local function do_place_decoratives(data)
|
||||||
if not map_gen_decoratives then return end
|
if not map_gen_decoratives then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
for _, e in pairs(surface.find_entities_filtered{area=area, type="decorative"}) do
|
for _, e in pairs(surface.find_entities_filtered {area = area, type = "decorative"}) do
|
||||||
e.destroy()
|
e.destroy()
|
||||||
end
|
end
|
||||||
for _, e in pairs(surface.find_entities_filtered{area=area, type="simple-entity"}) do
|
for _, e in pairs(surface.find_entities_filtered {area = area, type = "simple-entity"}) do
|
||||||
e.destroy()
|
e.destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
local surface = data.surface
|
local surface = data.surface
|
||||||
for _,d in pairs(data.decoratives) do
|
for _, d in pairs(data.decoratives) do
|
||||||
surface.create_decoratives{check_collision=false, decoratives={d}}
|
surface.create_decoratives {check_collision = false, decoratives = {d}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_place_entities(data)
|
local function do_place_entities(data)
|
||||||
local surface = data.surface
|
local surface = data.surface
|
||||||
for _, e in ipairs(data.entities) do
|
for _, e in ipairs(data.entities) do
|
||||||
if surface.can_place_entity(e) then
|
if surface.can_place_entity(e) then
|
||||||
surface.create_entity(e)
|
surface.create_entity(e)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function run_combined_module(event)
|
function run_combined_module(event)
|
||||||
|
if MAP_GEN == nil then
|
||||||
|
game.print("MAP_GEN not set")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if MAP_GEN == nil then
|
local area = event.area
|
||||||
game.print("MAP_GEN not set")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local area = event.area
|
local data = {
|
||||||
local surface = event.surface
|
top_x = area.left_top.x,
|
||||||
MAP_GEN_SURFACE = surface
|
top_y = area.left_top.y,
|
||||||
|
surface = event.surface,
|
||||||
|
tiles = {},
|
||||||
|
entities = {},
|
||||||
|
decoratives = {}
|
||||||
|
}
|
||||||
|
|
||||||
local data =
|
for row = 0, 31 do
|
||||||
{
|
do_row(row, data)
|
||||||
top_x = area.left_top.x,
|
end
|
||||||
top_y = area.left_top.y ,
|
|
||||||
surface = surface,
|
|
||||||
tiles = {},
|
|
||||||
entities = {},
|
|
||||||
decoratives = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
for row = 0, 31 do
|
|
||||||
do_row(row, data)
|
|
||||||
end
|
|
||||||
|
|
||||||
do_place_tiles(data)
|
|
||||||
do_place_decoratives(data)
|
|
||||||
do_place_entities(data)
|
|
||||||
|
|
||||||
|
do_place_tiles(data)
|
||||||
|
do_place_decoratives(data)
|
||||||
|
do_place_entities(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
local decorative_options = {
|
local decorative_options = {
|
||||||
["concrete"] = {},
|
["concrete"] = {},
|
||||||
["deepwater"] = {},
|
["deepwater"] = {},
|
||||||
["deepwater-green"] = {
|
["deepwater-green"] = {
|
||||||
{"brown-carpet-grass", 100},
|
{"brown-carpet-grass", 100},
|
||||||
{"brown-cane-cluster", 500},
|
{"brown-cane-cluster", 500}
|
||||||
},
|
},
|
||||||
["dirt-3"] = {
|
["dirt-3"] = {
|
||||||
{"brown-carpet-grass", 100},
|
{"brown-carpet-grass", 100},
|
||||||
{"brown-cane-cluster", 200},
|
{"brown-cane-cluster", 200},
|
||||||
{"sand-rock-small", 150},
|
{"sand-rock-small", 150}
|
||||||
},
|
},
|
||||||
["dirt-6"] = {
|
["dirt-6"] = {
|
||||||
{"sand-rock-small", 150},
|
{"sand-rock-small", 150},
|
||||||
{"red-asterisk", 45},
|
{"red-asterisk", 45},
|
||||||
{"red-desert-bush", 12},
|
{"red-desert-bush", 12},
|
||||||
{"rock-medium", 375},
|
{"rock-medium", 375}
|
||||||
|
},
|
||||||
|
["grass-1"] = {
|
||||||
},
|
{"green-carpet-grass-1", 3},
|
||||||
["grass-1"] = {
|
{"green-hairy-grass-1", 7},
|
||||||
{"green-carpet-grass-1", 3},
|
{"green-bush-mini", 10},
|
||||||
{"green-hairy-grass-1", 7},
|
{"green-pita", 6},
|
||||||
{"green-bush-mini", 10},
|
{"green-small-grass-1", 12},
|
||||||
{"green-pita", 6},
|
{"green-asterisk", 25},
|
||||||
{"green-small-grass-1", 12},
|
{"green-bush-mini", 7},
|
||||||
{"green-asterisk", 25},
|
{"garballo", 20}
|
||||||
{"green-bush-mini", 7},
|
},
|
||||||
{"garballo", 20},
|
["grass-3"] = {
|
||||||
},
|
{"green-carpet-grass-1", 12},
|
||||||
["grass-3"] = {
|
{"green-hairy-grass-1", 28},
|
||||||
{"green-carpet-grass-1", 12},
|
{"green-bush-mini", 40},
|
||||||
{"green-hairy-grass-1", 28},
|
{"green-pita", 24},
|
||||||
{"green-bush-mini", 40},
|
{"green-small-grass-1", 48},
|
||||||
{"green-pita", 24},
|
{"green-asterisk", 100},
|
||||||
{"green-small-grass-1", 48},
|
{"green-bush-mini", 28}
|
||||||
{"green-asterisk", 100},
|
},
|
||||||
{"green-bush-mini", 28},
|
["grass-2"] = {
|
||||||
},
|
{"green-hairy-grass-1", 56},
|
||||||
["grass-2"] = {
|
{"green-bush-mini", 80},
|
||||||
{"green-hairy-grass-1", 56},
|
{"green-pita", 48},
|
||||||
{"green-bush-mini", 80},
|
{"green-small-grass-1", 96},
|
||||||
{"green-pita", 48},
|
{"green-asterisk", 200},
|
||||||
{"green-small-grass-1", 96},
|
{"green-bush-mini", 56},
|
||||||
{"green-asterisk", 200},
|
{"brown-cane-cluster", 100},
|
||||||
{"green-bush-mini", 56},
|
{"brown-carpet-grass", 100}
|
||||||
{"brown-cane-cluster", 100},
|
},
|
||||||
{"brown-carpet-grass", 100},
|
["hazard-concrete-left"] = {},
|
||||||
},
|
["hazard-concrete-right"] = {},
|
||||||
["hazard-concrete-left"] = {},
|
["lab-dark-1"] = {},
|
||||||
["hazard-concrete-right"] = {},
|
["lab-dark-2"] = {},
|
||||||
["lab-dark-1"] = {},
|
["red-desert"] = {
|
||||||
["lab-dark-2"] = {},
|
{"brown-carpet-grass", 35},
|
||||||
["red-desert"] = {
|
{"orange-coral-mini", 45},
|
||||||
{"brown-carpet-grass", 35},
|
{"red-asterisk", 45},
|
||||||
{"orange-coral-mini", 45},
|
{"red-desert-bush", 12},
|
||||||
{"red-asterisk", 45},
|
{"rock-medium", 375},
|
||||||
{"red-desert-bush", 12},
|
{"sand-rock-small", 200},
|
||||||
{"rock-medium", 375},
|
{"sand-rock-small", 30}
|
||||||
{"sand-rock-small", 200},
|
},
|
||||||
{"sand-rock-small", 30},
|
["red-desert-dark"] = {
|
||||||
},
|
{"brown-carpet-grass", 70},
|
||||||
["red-desert-dark"] = {
|
{"orange-coral-mini", 90},
|
||||||
{"brown-carpet-grass", 70},
|
{"red-asterisk", 90},
|
||||||
{"orange-coral-mini", 90},
|
{"red-desert-bush", 35},
|
||||||
{"red-asterisk", 90},
|
{"rock-medium", 375},
|
||||||
{"red-desert-bush", 35},
|
{"sand-rock-small", 200},
|
||||||
{"rock-medium", 375},
|
{"sand-rock-small", 150}
|
||||||
{"sand-rock-small", 200},
|
},
|
||||||
{"sand-rock-small", 150},
|
["sand-1"] = {
|
||||||
},
|
{"brown-carpet-grass", 35},
|
||||||
["sand-1"] = {
|
{"orange-coral-mini", 45},
|
||||||
{"brown-carpet-grass", 35},
|
{"red-asterisk", 45},
|
||||||
{"orange-coral-mini", 45},
|
{"brown-asterisk", 45}
|
||||||
{"red-asterisk", 45},
|
},
|
||||||
{"brown-asterisk", 45},
|
["sand-3"] = {
|
||||||
},
|
{"brown-carpet-grass", 35},
|
||||||
["sand-3"] = {
|
{"orange-coral-mini", 45},
|
||||||
{"brown-carpet-grass", 35},
|
{"brown-asterisk", 45}
|
||||||
{"orange-coral-mini", 45},
|
},
|
||||||
{"brown-asterisk", 45},
|
["stone-path"] = {},
|
||||||
},
|
["water"] = {},
|
||||||
["stone-path"] = {},
|
["water-green"] = {},
|
||||||
["water"] = {},
|
["out-of-map"] = {}
|
||||||
["water-green"] = {},
|
|
||||||
["out-of-map"] = {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local function check_decorative(tile, x, y)
|
local function check_decorative(tile, x, y)
|
||||||
local options = decorative_options[tile]
|
local options = decorative_options[tile]
|
||||||
local tile_decoratives = {}
|
local tile_decoratives = {}
|
||||||
|
|
||||||
for _,e in ipairs(options) do
|
for _, e in ipairs(options) do
|
||||||
name = e[1]
|
name = e[1]
|
||||||
high_roll = e[2]
|
high_roll = e[2]
|
||||||
if poisson_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}})
|
table.insert(tile_decoratives, {name = name, amount = 1, position = {x, y}})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return tile_decoratives
|
return tile_decoratives
|
||||||
end
|
end
|
||||||
|
|
||||||
local entity_options = {
|
local entity_options = {
|
||||||
["concrete"] = {},
|
["concrete"] = {},
|
||||||
["deepwater"] = {},
|
["deepwater"] = {},
|
||||||
["deepwater-green"] = {},
|
["deepwater-green"] = {},
|
||||||
["water"] = {},
|
["water"] = {},
|
||||||
["water-green"] = {},
|
["water-green"] = {},
|
||||||
["dirt-3"] = {
|
["dirt-3"] = {
|
||||||
{"tree-01", 500},
|
{"tree-01", 500},
|
||||||
{"tree-06", 300},
|
{"tree-06", 300},
|
||||||
{"tree-07", 800},
|
{"tree-07", 800},
|
||||||
{"tree-09", 2000},
|
{"tree-09", 2000},
|
||||||
{"rock-big", 400},
|
{"rock-big", 400}
|
||||||
},
|
},
|
||||||
["dirt-6"] = {
|
["dirt-6"] = {
|
||||||
{"tree-06", 150},
|
{"tree-06", 150},
|
||||||
{"tree-07", 400},
|
{"tree-07", 400},
|
||||||
{"tree-09", 1000},
|
{"tree-09", 1000},
|
||||||
{"rock-big", 300},
|
{"rock-big", 300}
|
||||||
},
|
},
|
||||||
["grass-1"] = {
|
["grass-1"] = {
|
||||||
{"tree-01", 150},
|
{"tree-01", 150},
|
||||||
{"tree-04", 400},
|
{"tree-04", 400},
|
||||||
{"tree-06", 400},
|
{"tree-06", 400},
|
||||||
{"tree-07", 400},
|
{"tree-07", 400},
|
||||||
{"tree-09", 1000},
|
{"tree-09", 1000},
|
||||||
{"rock-big", 400},
|
{"rock-big", 400},
|
||||||
{"green-coral", 10000},
|
{"green-coral", 10000}
|
||||||
},
|
},
|
||||||
["grass-3"] = {
|
["grass-3"] = {
|
||||||
{"tree-02", 400},
|
{"tree-02", 400},
|
||||||
{"tree-03", 400},
|
{"tree-03", 400},
|
||||||
{"tree-04", 800},
|
{"tree-04", 800},
|
||||||
{"tree-06", 300},
|
{"tree-06", 300},
|
||||||
{"tree-07", 800},
|
{"tree-07", 800},
|
||||||
{"tree-08", 400},
|
{"tree-08", 400},
|
||||||
{"tree-09", 2000},
|
{"tree-09", 2000},
|
||||||
{"rock-big", 400},
|
{"rock-big", 400}
|
||||||
},
|
},
|
||||||
["grass-2"] = {
|
["grass-2"] = {
|
||||||
{"tree-04", 800},
|
{"tree-04", 800},
|
||||||
{"tree-06", 300},
|
{"tree-06", 300},
|
||||||
{"tree-07", 400},
|
{"tree-07", 400},
|
||||||
{"tree-09", 1000},
|
{"tree-09", 1000},
|
||||||
{"dry-tree", 1000},
|
{"dry-tree", 1000},
|
||||||
{"rock-big", 200},
|
{"rock-big", 200}
|
||||||
},
|
},
|
||||||
["hazard-concrete-left"] = {},
|
["hazard-concrete-left"] = {},
|
||||||
["hazard-concrete-right"] = {},
|
["hazard-concrete-right"] = {},
|
||||||
["lab-dark-1"] = {},
|
["lab-dark-1"] = {},
|
||||||
["lab-dark-2"] = {},
|
["lab-dark-2"] = {},
|
||||||
["red-desert"] = {
|
["red-desert"] = {
|
||||||
{"dry-tree", 400},
|
{"dry-tree", 400},
|
||||||
{"dry-hairy-tree", 400},
|
{"dry-hairy-tree", 400},
|
||||||
{"tree-06", 500},
|
{"tree-06", 500},
|
||||||
{"tree-06", 500},
|
{"tree-06", 500},
|
||||||
{"tree-01", 500},
|
{"tree-01", 500},
|
||||||
{"tree-02", 500},
|
{"tree-02", 500},
|
||||||
{"tree-03", 500},
|
{"tree-03", 500},
|
||||||
{"sand-rock-big", 200},
|
{"sand-rock-big", 200},
|
||||||
{"sand-rock-big", 400},
|
{"sand-rock-big", 400},
|
||||||
{"red-desert-rock-huge-02", 400},
|
{"red-desert-rock-huge-02", 400}
|
||||||
},
|
},
|
||||||
["red-desert-dark"] = {
|
["red-desert-dark"] = {
|
||||||
{"dry-tree", 400},
|
{"dry-tree", 400},
|
||||||
{"dry-hairy-tree", 400},
|
{"dry-hairy-tree", 400},
|
||||||
{"tree-06", 500},
|
{"tree-06", 500},
|
||||||
{"tree-06", 500},
|
{"tree-06", 500},
|
||||||
{"tree-01", 500},
|
{"tree-01", 500},
|
||||||
{"tree-02", 500},
|
{"tree-02", 500},
|
||||||
{"tree-03", 500},
|
{"tree-03", 500},
|
||||||
{"sand-rock-big", 200},
|
{"sand-rock-big", 200},
|
||||||
{"sand-rock-big", 400},
|
{"sand-rock-big", 400},
|
||||||
{"red-desert-rock-huge-02", 400},
|
{"red-desert-rock-huge-02", 400}
|
||||||
},
|
},
|
||||||
["sand-1"] = {
|
["sand-1"] = {
|
||||||
{"dry-tree", 1000},
|
{"dry-tree", 1000},
|
||||||
{"dry-hairy-tree", 1000},
|
{"dry-hairy-tree", 1000},
|
||||||
{"dead-tree", 1000},
|
{"dead-tree", 1000},
|
||||||
{"rock-big", 150},
|
{"rock-big", 150}
|
||||||
|
},
|
||||||
},
|
["sand-3"] = {
|
||||||
["sand-3"] = {
|
{"dead-tree", 1000},
|
||||||
{"dead-tree", 1000},
|
{"dry-tree", 1000},
|
||||||
{"dry-tree", 1000},
|
{"dry-hairy-tree", 1000},
|
||||||
{"dry-hairy-tree", 1000},
|
{"rock-big", 150}
|
||||||
{"rock-big", 150},
|
},
|
||||||
|
["stone-path"] = {},
|
||||||
},
|
["out-of-map"] = {}
|
||||||
["stone-path"] = {},
|
|
||||||
["out-of-map"] = {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_entities(tile, x, y)
|
function check_entities(tile, x, y)
|
||||||
local options = entity_options[tile]
|
local options = entity_options[tile]
|
||||||
local tile_entity_list = {}
|
local tile_entity_list = {}
|
||||||
|
|
||||||
for _,e in ipairs(options) do
|
for _, e in ipairs(options) do
|
||||||
name = e[1]
|
name = e[1]
|
||||||
high_roll = e[2]
|
high_roll = e[2]
|
||||||
if poisson_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}})
|
table.insert(tile_entity_list, {name = name, position = {x, y}})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return tile_entity_list
|
return tile_entity_list
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user