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