mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
changes to builder signatures
This commit is contained in:
parent
094bfe8928
commit
abc221427f
@ -5,16 +5,16 @@ map_gen_rows_per_tick = 8 -- Inclusive integer between 1 and 32. Used for map_ge
|
||||
--require "map_gen.shared.generate_not_threaded"
|
||||
require "map_gen.shared.generate"
|
||||
|
||||
local function no_resources(x, y, world_x, world_y, tile, surface)
|
||||
for _, e in ipairs(surface.find_entities_filtered({type = "resource", area = {{world_x, world_y}, {world_x + 1, world_y + 1}}})) do
|
||||
local function no_resources(x, y, world, tile)
|
||||
for _, e in ipairs(world.surface.find_entities_filtered({type = "resource", area = {{world.x, world.y}, {world.x + 1, world.y + 1}}})) do
|
||||
e.destroy()
|
||||
end
|
||||
|
||||
return tile
|
||||
end
|
||||
|
||||
local function less_resources(x, y, world_x, world_y, tile, surface)
|
||||
for _, e in ipairs(surface.find_entities_filtered({type = "resource", area = {{world_x, world_y}, {world_x + 1, world_y + 1}}})) do
|
||||
local function less_resources(x, y, world, tile)
|
||||
for _, e in ipairs(world.surface.find_entities_filtered({type = "resource", area = {{world.x, world.y}, {world.x + 1, world.y + 1}}})) do
|
||||
if e.name == "crude-oil" then
|
||||
-- e.amount = .995 * e.amount
|
||||
else
|
||||
@ -25,8 +25,8 @@ local function less_resources(x, y, world_x, world_y, tile, surface)
|
||||
return tile
|
||||
end
|
||||
|
||||
local function no_enemies(x, y, world_x, world_y, tile, surface)
|
||||
for _, e in ipairs(surface.find_entities_filtered({force = "enemy", position = {world_x, world_y}})) do
|
||||
local function no_enemies(x, y, world, tile)
|
||||
for _, e in ipairs(world.surface.find_entities_filtered({force = "enemy", position = {world.x, world.y}})) do
|
||||
e.destroy()
|
||||
end
|
||||
|
||||
|
@ -8,8 +8,8 @@ local function value(base, mult)
|
||||
end
|
||||
end
|
||||
|
||||
local function no_resources(x, y, world_x, world_y, tile, surface)
|
||||
for _, e in ipairs(surface.find_entities_filtered({ type = "resource", area = {{world_x, world_y }, {world_x + 1, world_y + 1 } } })) do
|
||||
local function no_resources(x, y, world, tile)
|
||||
for _, e in ipairs(world.surface.find_entities_filtered({ type = "resource", area = {{world.x, world.y }, {world.x + 1, world.y + 1 } } })) do
|
||||
e.destroy()
|
||||
end
|
||||
|
||||
|
@ -54,19 +54,19 @@ end
|
||||
|
||||
local init = false
|
||||
local safe_distance = 480
|
||||
local function effect(x, y, world_x, world_y, tile, surface)
|
||||
local function effect(x, y, world, tile)
|
||||
|
||||
if not init then
|
||||
init = true
|
||||
game.forces["player"].chart(surface, {{-32, -32}, {31, 31}})
|
||||
game.forces["player"].chart(world.surface, {{-32, -32}, {31, 31}})
|
||||
end
|
||||
|
||||
if world_x == 0 and world_y == 0 then
|
||||
for _, e in ipairs(surface.find_entities({{-5, -5}, {5, 5}})) do
|
||||
if world.x == 0 and world.y == 0 then
|
||||
for _, e in ipairs(world.surface.find_entities({{-5, -5}, {5, 5}})) do
|
||||
e.destroy()
|
||||
end
|
||||
|
||||
local e = surface.create_entity({name = "rocket-silo", position = {0, 0}, force = "player"})
|
||||
local e = world.surface.create_entity({name = "rocket-silo", position = {0, 0}, force = "player"})
|
||||
e.destructible = false
|
||||
e.minable = false
|
||||
end
|
||||
|
@ -196,74 +196,76 @@ function picture_builder(pic)
|
||||
|
||||
if y2 > 0 and y2 <= height and x2 > 0 and x2 <= width then
|
||||
return data[y2][x2]
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- transforms and shape helpers
|
||||
function translate(builder, x_offset, y_offset)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
return builder(x - x_offset, y - y_offset, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
return builder(x - x_offset, y - y_offset, world)
|
||||
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, surface)
|
||||
return builder(x * x_scale, y * y_scale, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
return builder(x * x_scale, y * y_scale, world)
|
||||
end
|
||||
end
|
||||
|
||||
function rotate(builder, angle)
|
||||
local qx = math.cos(angle)
|
||||
local qy = math.sin(angle)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
local rot_x = qx * x - qy * y
|
||||
local rot_y = qy * x + qx * y
|
||||
return builder(rot_x, rot_y, world_x, world_y, surface)
|
||||
return builder(rot_x, rot_y, world)
|
||||
end
|
||||
end
|
||||
|
||||
function flip_x(builder)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
return builder(-x, y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
return builder(-x, y, world)
|
||||
end
|
||||
end
|
||||
|
||||
function flip_y(builder)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
return builder(x, -y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
return builder(x, -y, world)
|
||||
end
|
||||
end
|
||||
|
||||
function flip_xy(builder)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
return builder(-x, -y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
return builder(-x, -y, world)
|
||||
end
|
||||
end
|
||||
|
||||
-- For resource_module_builder it will return the first success.
|
||||
function compound_or(builders)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
for _, v in ipairs(builders) do
|
||||
local tile = v(x, y, world_x, world_y, surface)
|
||||
local tile = v(x, y, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
end
|
||||
return nil
|
||||
return false
|
||||
end
|
||||
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, surface)
|
||||
return function(x, y, world)
|
||||
local tile
|
||||
for _, v in ipairs(builders) do
|
||||
tile = v(x, y, world_x, world_y, surface)
|
||||
tile = v(x, y, world)
|
||||
if not tile then
|
||||
return nil
|
||||
return false
|
||||
end
|
||||
end
|
||||
return tile
|
||||
@ -271,110 +273,109 @@ function compound_and(builders)
|
||||
end
|
||||
|
||||
function invert(builder)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
local tile = builder(x, y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
local tile = builder(x, y, world)
|
||||
return not tile
|
||||
end
|
||||
end
|
||||
|
||||
function throttle_x(builder, x_in, x_size)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
if x % x_size < x_in then
|
||||
return builder(x, y, world_x, world_y, surface)
|
||||
return builder(x, y, world)
|
||||
else
|
||||
return nil
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function throttle_y(builder, y_in, y_size)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
if y % y_size < y_in then
|
||||
return builder(x, y, world_x, world_y, surface)
|
||||
return builder(x, y, world)
|
||||
else
|
||||
return nil
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function throttle_xy(builder, x_in, x_size, y_in, y_size)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
if x % x_size < x_in and y % y_size < y_in then
|
||||
return builder(x, y, world_x, world_y, surface)
|
||||
return builder(x, y, world)
|
||||
else
|
||||
return nil
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function throttle_xy(builder, x_in, x_size, y_in, y_size)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
if x % x_size < x_in and y % y_size < y_in then
|
||||
return builder(x, y, world_x, world_y, surface)
|
||||
return builder(x, y, world)
|
||||
else
|
||||
return nil
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function throttle_world_xy(builder, x_in, x_size, y_in, y_size)
|
||||
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, surface)
|
||||
return function(x, y, world)
|
||||
if world.x % x_size < x_in and world.y % y_size < y_in then
|
||||
return builder(x, y, world)
|
||||
else
|
||||
return nil
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function choose(condition, true_shape, false_shape)
|
||||
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)
|
||||
return function(x, y, world)
|
||||
if condition(x, y, world) then
|
||||
return true_shape(x, y, world)
|
||||
else
|
||||
return false_shape(local_x, local_y, world_x, world_y, surface)
|
||||
return false_shape(x, y, world)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function shape_or_else(shape, else_shape)
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
return shape(local_x, local_y, world_x, world_y, surface) or
|
||||
else_shape(local_x, local_y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
return shape(x, y, world) or else_shape(x, y, world)
|
||||
end
|
||||
end
|
||||
|
||||
function linear_grow(shape, size)
|
||||
local half_size = size / 2
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
local t = math.ceil((local_y / size) + 0.5)
|
||||
return function(x, y, world)
|
||||
local t = math.ceil((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 x = local_x / n
|
||||
local y = (y - size * (t_lower + n / 2 - 0.5)) / n
|
||||
local x = x / n
|
||||
|
||||
return shape(x, y, world_x, world_y, surface)
|
||||
return shape(x, y, world)
|
||||
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, surface)
|
||||
local tx = math.ceil(math.abs(local_x) / half_size)
|
||||
local ty = math.ceil(math.abs(local_y) / half_size)
|
||||
return function(x, y, world)
|
||||
local tx = math.ceil(math.abs(x) / half_size)
|
||||
local ty = math.ceil(math.abs(y) / half_size)
|
||||
local t = math.max(tx, ty)
|
||||
|
||||
for i = t, 2.5 * t, 1 do
|
||||
local out_t = 1 / (i - offset)
|
||||
local in_t = 1 / i
|
||||
|
||||
if out_shape(out_t * local_x, out_t * local_y, world_x, world_y, surface) then
|
||||
if out_shape(out_t * x, out_t * y, world) then
|
||||
return nil
|
||||
end
|
||||
|
||||
local tile = in_shape(in_t * local_x, in_t * local_y, world_x, world_y, surface)
|
||||
local tile = in_shape(in_t * x, in_t * y, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
@ -389,9 +390,9 @@ function project(shape, size, r)
|
||||
local r2 = 1 / (r - 1)
|
||||
local a = 1 / size
|
||||
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
local offset = 0.5 * size
|
||||
local sn = math.ceil(local_y + offset)
|
||||
local sn = math.ceil(y + offset)
|
||||
|
||||
local n = math.ceil(math.log((r - 1) * sn * a + 1) / ln_r - 1)
|
||||
local rn = r ^ n
|
||||
@ -399,10 +400,10 @@ function project(shape, size, r)
|
||||
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 x = x * rn2
|
||||
local y = (y - (sn_upper - 0.5 * c) + offset) * rn2
|
||||
|
||||
return shape(x, y, world_x, world_y, surface)
|
||||
return shape(x, y, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -412,8 +413,8 @@ 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, surface)
|
||||
local sn = math.ceil(local_y + offset)
|
||||
return function(x, y, world)
|
||||
local sn = math.ceil(y + offset)
|
||||
|
||||
local n = math.ceil(math.log((r - 1) * sn * a + 1) / ln_r - 1)
|
||||
local rn = r ^ n
|
||||
@ -421,12 +422,12 @@ function project_overlap(shape, size, r)
|
||||
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 x = x * rn2
|
||||
local y = (y - (sn_upper - 0.5 * c) + offset) * rn2
|
||||
|
||||
local tile
|
||||
|
||||
tile = shape(x, y, world_x, world_y, surface)
|
||||
tile = shape(x, y, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
@ -437,10 +438,10 @@ function project_overlap(shape, size, r)
|
||||
local c_above = size * rn_above
|
||||
|
||||
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 x_above = x * rn2_above
|
||||
local y_above = (y - (sn_upper_above - 0.5 * c_above) + offset) * rn2_above
|
||||
|
||||
tile = shape(x_above, y_above, world_x, world_y, surface)
|
||||
tile = shape(x_above, y_above, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
@ -451,10 +452,10 @@ function project_overlap(shape, size, r)
|
||||
local c_below = size * rn_below
|
||||
|
||||
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
|
||||
local x_below = x * rn2_below
|
||||
local y_below = (y - (sn_upper_below - 0.5 * c_below) + offset) * rn2_below
|
||||
|
||||
return shape(x_below, y_below, world_x, world_y, surface)
|
||||
return shape(x_below, y_below, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -464,34 +465,38 @@ function resource_module_builder(builder, resource_type, amount_function)
|
||||
amount_function = amount_function or function(a, b)
|
||||
return 404
|
||||
end
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
if builder(x, y, world_x, world_y, surface) then
|
||||
return function(x, y, world)
|
||||
if builder(x, y, world) then
|
||||
return {
|
||||
name = resource_type,
|
||||
position = {world_x, world_y},
|
||||
amount = amount_function(world_x, world_y)
|
||||
position = {world.x, world.y},
|
||||
amount = amount_function(world.x, world.y)
|
||||
}
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function builder_with_resource(land_builder, resource_module)
|
||||
return function(x, y, world_x, world_y, surface)
|
||||
local tile = land_builder(x, y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
local tile = land_builder(x, y, world)
|
||||
if tile then
|
||||
local entity = resource_module(x, y, world_x, world_y, surface)
|
||||
return {
|
||||
local entity = resource_module(x, y, world)
|
||||
if entity then
|
||||
if type(tile) == "table" then
|
||||
add_entity(tile, entity)
|
||||
else
|
||||
tile = {
|
||||
tile = tile,
|
||||
entities = {entity}
|
||||
}
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return tile
|
||||
end
|
||||
end
|
||||
|
||||
-- pattern builders.
|
||||
function single_pattern_builder(shape, width, height)
|
||||
shape = shape or empty_builder
|
||||
@ -503,11 +508,11 @@ function single_pattern_builder(shape, width, height)
|
||||
half_height = half_width
|
||||
end
|
||||
|
||||
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 function(x, y, world)
|
||||
y = ((y + half_height) % height) - half_height
|
||||
x = ((x + half_width) % width) - half_width
|
||||
|
||||
return shape(local_x, local_y, world_x, world_y, surface)
|
||||
return shape(x, y, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -521,15 +526,13 @@ function single_pattern_overlap_builder(shape, width, height)
|
||||
half_height = half_width
|
||||
end
|
||||
|
||||
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 function(x, y, world)
|
||||
y = ((y + half_height) % height) - half_height
|
||||
x = ((x + half_width) % width) - half_width
|
||||
|
||||
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)
|
||||
return shape(x, y, world) or shape(x + width, y, world) or shape(x - width, y, world) or
|
||||
shape(x, y + height, world) or
|
||||
shape(x, y - height, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -537,10 +540,10 @@ function single_x_pattern_builder(shape, width)
|
||||
shape = shape or empty_builder
|
||||
local half_width = width / 2
|
||||
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
local_x = ((local_x + half_width) % width) - half_width
|
||||
return function(x, y, world)
|
||||
x = ((x + half_width) % width) - half_width
|
||||
|
||||
return shape(local_x, local_y, world_x, world_y, surface)
|
||||
return shape(x, y, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -548,10 +551,10 @@ function single_y_pattern_builder(shape, height)
|
||||
shape = shape or empty_builder
|
||||
local half_height = height / 2
|
||||
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
local_y = ((local_y + half_height) % height) - half_height
|
||||
return function(x, y, world)
|
||||
y = ((y + half_height) % height) - half_height
|
||||
|
||||
return shape(local_x, local_y, world_x, world_y, surface)
|
||||
return shape(x, y, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -559,18 +562,18 @@ function grid_pattern_builder(pattern, columns, rows, width, height)
|
||||
local half_width = width / 2
|
||||
local half_height = height / 2
|
||||
|
||||
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)
|
||||
return function(x, y, world)
|
||||
local y2 = ((y + half_height) % height) - half_height
|
||||
local row_pos = math.floor(y / height + 0.5)
|
||||
local row_i = row_pos % rows + 1
|
||||
local row = pattern[row_i] or {}
|
||||
|
||||
local local_x2 = ((local_x + half_width) % width) - half_width
|
||||
local col_pos = math.floor(local_x / width + 0.5)
|
||||
local x2 = ((x + half_width) % width) - half_width
|
||||
local col_pos = math.floor(x / width + 0.5)
|
||||
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, surface)
|
||||
return shape(x2, y2, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -578,19 +581,19 @@ function grid_pattern_overlap_builder(pattern, columns, rows, width, height)
|
||||
local half_width = width / 2
|
||||
local half_height = height / 2
|
||||
|
||||
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)
|
||||
return function(x, y, world)
|
||||
local y2 = ((y + half_height) % height) - half_height
|
||||
local row_pos = math.floor(y / height + 0.5)
|
||||
local row_i = row_pos % rows + 1
|
||||
local row = pattern[row_i] or {}
|
||||
|
||||
local local_x2 = ((local_x + half_width) % width) - half_width
|
||||
local col_pos = math.floor(local_x / width + 0.5)
|
||||
local x2 = ((x + half_width) % width) - half_width
|
||||
local col_pos = math.floor(x / width + 0.5)
|
||||
local col_i = col_pos % columns + 1
|
||||
|
||||
local shape = row[col_i] or empty_builder
|
||||
|
||||
local tile = shape(local_x2, local_y2, world_x, world_y, surface)
|
||||
local tile = shape(x2, y2, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
@ -598,14 +601,14 @@ function grid_pattern_overlap_builder(pattern, columns, rows, width, height)
|
||||
-- edges
|
||||
local col_i_left = (col_pos - 1) % columns + 1
|
||||
shape = row[col_i_left] or empty_builder
|
||||
tile = shape(local_x2 + width, local_y2, world_x, world_y, surface)
|
||||
tile = shape(x2 + width, y2, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
local col_i_right = (col_pos + 1) % columns + 1
|
||||
shape = row[col_i_right] or empty_builder
|
||||
tile = shape(local_x2 - width, local_y2, world_x, world_y, surface)
|
||||
tile = shape(x2 - width, y2, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
@ -613,7 +616,7 @@ function grid_pattern_overlap_builder(pattern, columns, rows, width, height)
|
||||
local row_i_up = (row_pos - 1) % rows + 1
|
||||
local row_up = pattern[row_i_up] or {}
|
||||
shape = row_up[col_i] or empty_builder
|
||||
tile = shape(local_x2, local_y2 + height, world_x, world_y, surface)
|
||||
tile = shape(x2, y2 + height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
@ -621,7 +624,7 @@ function grid_pattern_overlap_builder(pattern, columns, rows, width, height)
|
||||
local row_i_down = (row_pos + 1) % rows + 1
|
||||
local row_down = pattern[row_i_down] or {}
|
||||
shape = row_down[col_i] or empty_builder
|
||||
return shape(local_x2, local_y2 - height, world_x, world_y, surface)
|
||||
return shape(x2, y2 - height, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -629,14 +632,14 @@ function grid_pattern_full_overlap_builder(pattern, columns, rows, width, height
|
||||
local half_width = width / 2
|
||||
local half_height = height / 2
|
||||
|
||||
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)
|
||||
return function(x, y, world)
|
||||
local y2 = ((y + half_height) % height) - half_height
|
||||
local row_pos = math.floor(y / height + 0.5)
|
||||
local row_i = row_pos % rows + 1
|
||||
local row = pattern[row_i] or {}
|
||||
|
||||
local local_x2 = ((local_x + half_width) % width) - half_width
|
||||
local col_pos = math.floor(local_x / width + 0.5)
|
||||
local x2 = ((x + half_width) % width) - half_width
|
||||
local col_pos = math.floor(x / width + 0.5)
|
||||
local col_i = col_pos % columns + 1
|
||||
|
||||
local row_i_up = (row_pos - 1) % rows + 1
|
||||
@ -649,66 +652,66 @@ function grid_pattern_full_overlap_builder(pattern, columns, rows, width, height
|
||||
|
||||
-- start from top left, move left to right then down
|
||||
local shape = row_up[col_i_left] or empty_builder
|
||||
local tile = shape(local_x2 + width, local_y2 + height, world_x, world_y, surface)
|
||||
local tile = shape(x2 + width, y2 + height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row_up[col_i] or empty_builder
|
||||
tile = shape(local_x2, local_y2 + height, world_x, world_y, surface)
|
||||
tile = shape(x2, y2 + height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row_up[col_i_right] or empty_builder
|
||||
tile = shape(local_x2 - width, local_y2 + height, world_x, world_y, surface)
|
||||
tile = shape(x2 - width, y2 + height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row[col_i_left] or empty_builder
|
||||
tile = shape(local_x2 + width, local_y2, world_x, world_y, surface)
|
||||
tile = shape(x2 + width, y2, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
local shape = row[col_i] or empty_builder
|
||||
tile = shape(local_x2, local_y2, world_x, world_y, surface)
|
||||
tile = shape(x2, y2, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row[col_i_right] or empty_builder
|
||||
tile = shape(local_x2 - width, local_y2, world_x, world_y, surface)
|
||||
tile = shape(x2 - width, y2, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row_down[col_i_left] or empty_builder
|
||||
tile = shape(local_x2 + width, local_y2 - height, world_x, world_y, surface)
|
||||
tile = shape(x2 + width, y2 - height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row_down[col_i] or empty_builder
|
||||
tile = shape(local_x2, local_y2 - height, world_x, world_y, surface)
|
||||
tile = shape(x2, y2 - height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row_down[col_i_right] or empty_builder
|
||||
return shape(local_x2 - width, local_y2 - height, world_x, world_y, surface)
|
||||
return shape(x2 - width, y2 - height, world)
|
||||
end
|
||||
end
|
||||
|
||||
function segment_pattern_builder(pattern)
|
||||
local count = #pattern
|
||||
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
local angle = math.atan2(-local_y, local_x)
|
||||
return function(x, y, world)
|
||||
local angle = math.atan2(-y, 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, surface)
|
||||
return shape(x, y, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -716,18 +719,18 @@ function pyramid_builder(pattern, columns, rows, width, height)
|
||||
local half_width = width / 2
|
||||
local half_height = height / 2
|
||||
|
||||
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)
|
||||
return function(x, y, world)
|
||||
local y2 = ((y + half_height) % height) - half_height
|
||||
local row_pos = math.floor(y / height + 0.5)
|
||||
local row_i = row_pos % rows + 1
|
||||
local row = pattern[row_i] or {}
|
||||
|
||||
if row_pos % 2 ~= 0 then
|
||||
local_x = local_x - half_width
|
||||
x = x - half_width
|
||||
end
|
||||
|
||||
local local_x2 = ((local_x + half_width) % width) - half_width
|
||||
local col_pos = math.floor(local_x / width + 0.5)
|
||||
local x2 = ((x + half_width) % width) - half_width
|
||||
local col_pos = math.floor(x / width + 0.5)
|
||||
local col_i = col_pos % columns + 1
|
||||
|
||||
if col_pos > row_pos / 2 or -col_pos > (row_pos + 1) / 2 then
|
||||
@ -735,7 +738,7 @@ function pyramid_builder(pattern, columns, rows, width, height)
|
||||
end
|
||||
|
||||
local shape = row[col_i] or empty_builder
|
||||
return shape(local_x2, local_y2, world_x, world_y, surface)
|
||||
return shape(x2, y2, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -743,27 +746,27 @@ function pyramid_inner_overlap_builder(pattern, columns, rows, width, height)
|
||||
local half_width = width / 2
|
||||
local half_height = height / 2
|
||||
|
||||
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)
|
||||
return function(x, y, world)
|
||||
local y2 = ((y + half_height) % height) - half_height
|
||||
local row_pos = math.floor(y / height + 0.5)
|
||||
local row_i = row_pos % rows + 1
|
||||
local row = pattern[row_i] or {}
|
||||
|
||||
local x_odd
|
||||
local x_even
|
||||
if row_pos % 2 == 0 then
|
||||
x_even = local_x
|
||||
x_odd = local_x - half_width
|
||||
x_even = x
|
||||
x_odd = x - half_width
|
||||
else
|
||||
x_even = local_x - half_width
|
||||
x_odd = local_x
|
||||
local_x = local_x - half_width
|
||||
x_even = x - half_width
|
||||
x_odd = x
|
||||
x = x - half_width
|
||||
end
|
||||
|
||||
x_even = ((x_even + half_width) % width) - half_width
|
||||
x_odd = ((x_odd + half_width) % width) - half_width
|
||||
|
||||
local col_pos = math.floor(local_x / width + 0.5)
|
||||
local col_pos = math.floor(x / width + 0.5)
|
||||
|
||||
local offset = 1
|
||||
local offset_odd = 0
|
||||
@ -792,55 +795,55 @@ function pyramid_inner_overlap_builder(pattern, columns, rows, width, height)
|
||||
|
||||
-- start from top left, move left to right then down
|
||||
local shape = row_up[col_i_left] or empty_builder
|
||||
local tile = shape(x_even + width, local_y2 + height, world_x, world_y, surface)
|
||||
local tile = shape(x_even + width, y2 + height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row_up[col_i_odd] or empty_builder
|
||||
tile = shape(x_odd, local_y2 + height, world_x, world_y, surface)
|
||||
tile = shape(x_odd, y2 + height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row_up[col_i_right] or empty_builder
|
||||
tile = shape(x_even - width, local_y2 + height, world_x, world_y, surface)
|
||||
tile = shape(x_even - width, y2 + height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row[col_i_left] or empty_builder
|
||||
tile = shape(x_even + width, local_y2, world_x, world_y, surface)
|
||||
tile = shape(x_even + width, y2, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
local shape = row[col_i] or empty_builder
|
||||
tile = shape(x_even, local_y2, world_x, world_y, surface)
|
||||
tile = shape(x_even, y2, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row[col_i_right] or empty_builder
|
||||
tile = shape(x_even - width, local_y2, world_x, world_y, surface)
|
||||
tile = shape(x_even - width, y2, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row_down[col_i_left] or empty_builder
|
||||
tile = shape(x_even + width, local_y2 - height, world_x, world_y, surface)
|
||||
tile = shape(x_even + width, y2 - height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row_down[col_i_odd] or empty_builder
|
||||
tile = shape(x_odd, local_y2 - height, world_x, world_y, surface)
|
||||
tile = shape(x_odd, y2 - height, world)
|
||||
if tile then
|
||||
return tile
|
||||
end
|
||||
|
||||
shape = row_down[col_i_right] or empty_builder
|
||||
return shape(x_even - width, local_y2 - height, world_x, world_y, surface)
|
||||
return shape(x_even - width, y2 - height, world)
|
||||
end
|
||||
end
|
||||
|
||||
@ -848,45 +851,46 @@ function grid_pattern_offset_builder(pattern, columns, rows, width, height)
|
||||
local half_width = width / 2
|
||||
local half_height = height / 2
|
||||
|
||||
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)
|
||||
return function(x, y, world)
|
||||
local y2 = ((y + half_height) % height) - half_height
|
||||
local row_pos = math.floor(y / height + 0.5)
|
||||
local row_i = row_pos % rows + 1
|
||||
local row = pattern[row_i] or {}
|
||||
|
||||
local local_x2 = ((local_x + half_width) % width) - half_width
|
||||
local col_pos = math.floor(local_x / width + 0.5)
|
||||
local x2 = ((x + half_width) % width) - half_width
|
||||
local col_pos = math.floor(x / width + 0.5)
|
||||
local col_i = col_pos % columns + 1
|
||||
|
||||
local local_y2 = local_y2 + height * math.floor((row_pos + 1) / rows)
|
||||
local local_x2 = local_x2 + width * math.floor((col_pos + 1) / columns)
|
||||
local y2 = y2 + height * math.floor((row_pos + 1) / rows)
|
||||
local x2 = x2 + width * math.floor((col_pos + 1) / columns)
|
||||
|
||||
local shape = row[col_i] or empty_builder
|
||||
return shape(local_x2, local_y2, world_x, world_y, surface)
|
||||
return shape(x2, y2, world)
|
||||
end
|
||||
end
|
||||
|
||||
-- tile converters
|
||||
function change_tile(builder, old_tile, new_tile)
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
local tile = builder(local_x, local_y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
local tile = builder(x, y, world)
|
||||
|
||||
if type(tile) == "table" then
|
||||
if tile.tile == old_tile then
|
||||
tile.tile = new_tile
|
||||
return tile
|
||||
end
|
||||
else
|
||||
if tile == old_tile then
|
||||
return new_tile
|
||||
tile = new_tile
|
||||
end
|
||||
end
|
||||
|
||||
return tile
|
||||
end
|
||||
end
|
||||
|
||||
function change_collision_tile(builder, collides, new_tile)
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
local tile = builder(local_x, local_y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
local tile = builder(x, y, world)
|
||||
|
||||
if type(tile) == "table" then
|
||||
if tile.tile.collides_with(collides) then
|
||||
@ -898,41 +902,42 @@ function change_collision_tile(builder, collides, new_tile)
|
||||
return new_tile
|
||||
end
|
||||
end
|
||||
|
||||
return tile
|
||||
end
|
||||
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, surface)
|
||||
local tile = builder(local_x, local_y, world_x, world_y, surface)
|
||||
|
||||
if type(tile) == "table" then
|
||||
if type(tile.tile) == "boolean" and tile.tile then
|
||||
local gen_tile = surface.get_tile(world_x, world_y).name
|
||||
if old_tile == gen_tile then
|
||||
tile.tile = new_tile
|
||||
return tile
|
||||
end
|
||||
end
|
||||
else
|
||||
return function(x, y, world)
|
||||
local function handle_tile(tile)
|
||||
if type(tile) == "boolean" and tile then
|
||||
local gen_tile = surface.get_tile(world_x, world_y).name
|
||||
if old_tile == gen_tile then
|
||||
local gen_tile = world.surface.get_tile(world.x, world.y).name
|
||||
if gen_tile == old_tile then
|
||||
return new_tile
|
||||
end
|
||||
end
|
||||
return tile
|
||||
end
|
||||
|
||||
local tile = builder(x, y, world)
|
||||
|
||||
if type(tile) == "table" then
|
||||
tile.tile = handle_tile(tile.tile)
|
||||
else
|
||||
tile = handle_tile(tile)
|
||||
end
|
||||
|
||||
return tile
|
||||
end
|
||||
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, surface)
|
||||
local tile = builder(local_x, local_y, world_x, world_y, surface)
|
||||
|
||||
return function(x, y, world)
|
||||
local function handle_tile(tile)
|
||||
if type(tile) == "boolean" and tile then
|
||||
local gen_tile = surface.get_tile(world_x, world_y)
|
||||
local gen_tile = world.surface.get_tile(world.x, world.y)
|
||||
if gen_tile.collides_with(collides) then
|
||||
return new_tile
|
||||
end
|
||||
@ -940,6 +945,8 @@ function change_map_gen_collision_tile(builder, collides, new_tile)
|
||||
return tile
|
||||
end
|
||||
|
||||
local tile = builder(x, y, world)
|
||||
|
||||
if type(tile) == "table" then
|
||||
tile.tile = handle_tile(tile.tile)
|
||||
else
|
||||
@ -958,22 +965,20 @@ local water_tiles = {
|
||||
}
|
||||
|
||||
function spawn_fish(builder, spawn_rate)
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
return function(x, y, world)
|
||||
local function handle_tile(tile)
|
||||
if type(tile) == "string" then
|
||||
if water_tiles[tile] and spawn_rate >= math.random() then
|
||||
return {name = "fish", position = {world_x, world_y}}
|
||||
return {name = "fish", position = {world.x, world.y}}
|
||||
end
|
||||
elseif tile then
|
||||
if surface.get_tile(world_x, world_y).collides_with("water-tile") and spawn_rate >= math.random() then
|
||||
return {name = "fish", position = {world_x, world_y}}
|
||||
if world.surface.get_tile(world.x, world.y).collides_with("water-tile") and spawn_rate >= math.random() then
|
||||
return {name = "fish", position = {world.x, world.y}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
local tile = builder(local_x, local_y, world_x, world_y, surface)
|
||||
local tile = builder(x, y, world)
|
||||
|
||||
if type(tile) == "table" then
|
||||
local entity = handle_tile(tile.tile)
|
||||
@ -994,20 +999,19 @@ function spawn_fish(builder, spawn_rate)
|
||||
end
|
||||
end
|
||||
|
||||
--todo change to entiy_module_builder
|
||||
function spawn_entity(builder, name)
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
if builder(local_x, local_y, world_x, world_y, surface) then
|
||||
return {name = name, position = {world_x, world_y}}
|
||||
else
|
||||
return nil
|
||||
return function(x, y, world)
|
||||
if builder(x, y, world) then
|
||||
return {name = name, position = {world.x, world.y}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function apply_effect(builder, func)
|
||||
return function(local_x, local_y, world_x, world_y, surface)
|
||||
local tile = builder(local_x, local_y, world_x, world_y, surface)
|
||||
return func(local_x, local_y, world_x, world_y, tile, surface)
|
||||
return function(x, y, world)
|
||||
local tile = builder(x, y, world)
|
||||
return func(x, y, world, tile)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -18,9 +18,13 @@ local function do_row(row, data)
|
||||
local y = data.top_y + row
|
||||
local top_x = data.top_x
|
||||
|
||||
data.y = y
|
||||
|
||||
for x = top_x, top_x + 31 do
|
||||
data.x = x
|
||||
|
||||
-- local coords need to be 'centered' to allow for correct rotation and scaling.
|
||||
local tile = MAP_GEN(x + 0.5, y + 0.5, x, y, data.surface)
|
||||
local tile = MAP_GEN(x + 0.5, y + 0.5, data)
|
||||
|
||||
if type(tile) == "table" then
|
||||
do_tile(tile.tile, x, y)
|
||||
|
@ -2,33 +2,43 @@ 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
|
||||
|
||||
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 function do_tile(tile, x, y)
|
||||
if 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 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
|
||||
local y = data.top_y + row
|
||||
local top_x = data.top_x
|
||||
|
||||
data.y = y
|
||||
|
||||
for x = top_x, top_x + 31 do
|
||||
data.x = x
|
||||
|
||||
-- local coords need to be 'centered' to allow for correct rotation and scaling.
|
||||
local tile, entity = MAP_GEN(x + 0.5, y + 0.5, data)
|
||||
|
||||
if type(tile) == "table" then
|
||||
do_tile(tile.tile, x, y)
|
||||
|
||||
local entities = tile.entities
|
||||
if entities then
|
||||
for _, entity in ipairs(entities) do
|
||||
table.insert(data.entities, entity)
|
||||
end
|
||||
end
|
||||
|
||||
if entity then
|
||||
table.insert(data.entities, entity)
|
||||
local decoratives = tile.decoratives
|
||||
if decoratives then
|
||||
for _, decorative in ipairs(decoratives) do
|
||||
table.insert(data.decoratives, decorative)
|
||||
end
|
||||
end
|
||||
else
|
||||
do_tile(tile, x, y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user