mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-03 14:53:01 +02:00
clean up + change surface to local variable
This commit is contained in:
parent
43a0b0b1a5
commit
cc6af4fb67
@ -1,4 +1,3 @@
|
||||
|
||||
-- helpers
|
||||
|
||||
tau = 2 * math.pi
|
||||
@ -85,8 +84,7 @@ function oval_builder(x_radius, y_radius)
|
||||
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)
|
||||
@ -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,18 +303,18 @@ 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
|
||||
@ -321,13 +323,13 @@ function linear_grow(shape, size)
|
||||
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)
|
||||
@ -338,45 +340,18 @@ function grow(in_shape, out_shape, size, offset)
|
||||
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
|
||||
|
||||
@ -385,7 +360,7 @@ 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)
|
||||
|
||||
@ -398,7 +373,7 @@ function project(shape, size, r)
|
||||
local x = local_x * 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,8 +383,7 @@ 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 n = math.ceil(math.log((r - 1) * sn * a + 1) / ln_r - 1)
|
||||
@ -424,7 +398,7 @@ function project_overlap(shape, size, r)
|
||||
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
|
||||
@ -438,8 +412,10 @@ function project_overlap(shape, size, r)
|
||||
local x_above = local_x * 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
|
||||
@ -450,8 +426,7 @@ function project_overlap(shape, size, r)
|
||||
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)
|
||||
|
||||
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,7 +465,6 @@ end
|
||||
-- pattern builders.
|
||||
|
||||
function single_pattern_builder(shape, width, height)
|
||||
|
||||
shape = shape or empty_builder
|
||||
local half_width = width / 2
|
||||
local half_height
|
||||
@ -499,16 +474,15 @@ 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_height
|
||||
@ -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
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
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_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)
|
||||
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)
|
||||
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,8 +607,8 @@ 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
|
||||
@ -645,22 +616,18 @@ function spawn_fish(builder, spawn_rate)
|
||||
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 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
|
||||
return tile, entity
|
||||
end
|
||||
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
|
||||
|
||||
|
@ -11,9 +11,8 @@ local function do_row(row, data)
|
||||
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)
|
||||
local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y, data.surface)
|
||||
|
||||
if type(tile) == "boolean" and not tile then
|
||||
table.insert(data.tiles, {name = "out-of-map", position = {x, y}})
|
||||
@ -44,7 +43,9 @@ local function do_place_tiles(data)
|
||||
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()
|
||||
@ -69,11 +70,17 @@ local function do_place_entities(data)
|
||||
end
|
||||
|
||||
local function run_chart_update(params)
|
||||
local x = params.area.left_top.x / 32
|
||||
local y = params.area.left_top.y / 32
|
||||
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, {{ 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(
|
||||
params.surface,
|
||||
{
|
||||
{data.top_x, data.top_y},
|
||||
{data.top_x + 1, data.top_y + 1}
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@ -93,27 +100,27 @@ function map_gen_action(data)
|
||||
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
|
||||
|
||||
local area = event.area
|
||||
local surface = event.surface
|
||||
MAP_GEN_SURFACE = surface
|
||||
|
||||
local data =
|
||||
{
|
||||
local data = {
|
||||
state = 0,
|
||||
top_x = area.left_top.x,
|
||||
top_y = area.left_top.y,
|
||||
surface = surface,
|
||||
surface = event.surface,
|
||||
tiles = {},
|
||||
entities = {},
|
||||
decoratives = {}
|
||||
@ -126,20 +133,18 @@ local decorative_options = {
|
||||
["deepwater"] = {},
|
||||
["deepwater-green"] = {
|
||||
{"brown-carpet-grass", 100},
|
||||
{"brown-cane-cluster", 500},
|
||||
{"brown-cane-cluster", 500}
|
||||
},
|
||||
["dirt-3"] = {
|
||||
{"brown-carpet-grass", 100},
|
||||
{"brown-cane-cluster", 200},
|
||||
{"sand-rock-small", 150},
|
||||
{"sand-rock-small", 150}
|
||||
},
|
||||
["dirt-6"] = {
|
||||
{"sand-rock-small", 150},
|
||||
{"red-asterisk", 45},
|
||||
{"red-desert-bush", 12},
|
||||
{"rock-medium", 375},
|
||||
|
||||
|
||||
{"rock-medium", 375}
|
||||
},
|
||||
["grass-1"] = {
|
||||
{"green-carpet-grass-1", 3},
|
||||
@ -149,7 +154,7 @@ local decorative_options = {
|
||||
{"green-small-grass-1", 12},
|
||||
{"green-asterisk", 25},
|
||||
{"green-bush-mini", 7},
|
||||
{"garballo", 20},
|
||||
{"garballo", 20}
|
||||
},
|
||||
["grass-3"] = {
|
||||
{"green-carpet-grass-1", 12},
|
||||
@ -158,7 +163,7 @@ local decorative_options = {
|
||||
{"green-pita", 24},
|
||||
{"green-small-grass-1", 48},
|
||||
{"green-asterisk", 100},
|
||||
{"green-bush-mini", 28},
|
||||
{"green-bush-mini", 28}
|
||||
},
|
||||
["grass-2"] = {
|
||||
{"green-hairy-grass-1", 56},
|
||||
@ -168,7 +173,7 @@ local decorative_options = {
|
||||
{"green-asterisk", 200},
|
||||
{"green-bush-mini", 56},
|
||||
{"brown-cane-cluster", 100},
|
||||
{"brown-carpet-grass", 100},
|
||||
{"brown-carpet-grass", 100}
|
||||
},
|
||||
["hazard-concrete-left"] = {},
|
||||
["hazard-concrete-right"] = {},
|
||||
@ -181,7 +186,7 @@ local decorative_options = {
|
||||
{"red-desert-bush", 12},
|
||||
{"rock-medium", 375},
|
||||
{"sand-rock-small", 200},
|
||||
{"sand-rock-small", 30},
|
||||
{"sand-rock-small", 30}
|
||||
},
|
||||
["red-desert-dark"] = {
|
||||
{"brown-carpet-grass", 70},
|
||||
@ -190,23 +195,23 @@ local decorative_options = {
|
||||
{"red-desert-bush", 35},
|
||||
{"rock-medium", 375},
|
||||
{"sand-rock-small", 200},
|
||||
{"sand-rock-small", 150},
|
||||
{"sand-rock-small", 150}
|
||||
},
|
||||
["sand-1"] = {
|
||||
{"brown-carpet-grass", 35},
|
||||
{"orange-coral-mini", 45},
|
||||
{"red-asterisk", 45},
|
||||
{"brown-asterisk", 45},
|
||||
{"brown-asterisk", 45}
|
||||
},
|
||||
["sand-3"] = {
|
||||
{"brown-carpet-grass", 35},
|
||||
{"orange-coral-mini", 45},
|
||||
{"brown-asterisk", 45},
|
||||
{"brown-asterisk", 45}
|
||||
},
|
||||
["stone-path"] = {},
|
||||
["water"] = {},
|
||||
["water-green"] = {},
|
||||
["out-of-map"] = {},
|
||||
["out-of-map"] = {}
|
||||
}
|
||||
|
||||
local function check_decorative(tile, x, y)
|
||||
@ -235,13 +240,13 @@ local entity_options = {
|
||||
{"tree-06", 300},
|
||||
{"tree-07", 800},
|
||||
{"tree-09", 2000},
|
||||
{"rock-big", 400},
|
||||
{"rock-big", 400}
|
||||
},
|
||||
["dirt-6"] = {
|
||||
{"tree-06", 150},
|
||||
{"tree-07", 400},
|
||||
{"tree-09", 1000},
|
||||
{"rock-big", 300},
|
||||
{"rock-big", 300}
|
||||
},
|
||||
["grass-1"] = {
|
||||
{"tree-01", 150},
|
||||
@ -250,7 +255,7 @@ local entity_options = {
|
||||
{"tree-07", 400},
|
||||
{"tree-09", 1000},
|
||||
{"rock-big", 400},
|
||||
{"green-coral", 10000},
|
||||
{"green-coral", 10000}
|
||||
},
|
||||
["grass-3"] = {
|
||||
{"tree-02", 400},
|
||||
@ -260,7 +265,7 @@ local entity_options = {
|
||||
{"tree-07", 800},
|
||||
{"tree-08", 400},
|
||||
{"tree-09", 2000},
|
||||
{"rock-big", 400},
|
||||
{"rock-big", 400}
|
||||
},
|
||||
["grass-2"] = {
|
||||
{"tree-04", 800},
|
||||
@ -268,7 +273,7 @@ local entity_options = {
|
||||
{"tree-07", 400},
|
||||
{"tree-09", 1000},
|
||||
{"dry-tree", 1000},
|
||||
{"rock-big", 200},
|
||||
{"rock-big", 200}
|
||||
},
|
||||
["hazard-concrete-left"] = {},
|
||||
["hazard-concrete-right"] = {},
|
||||
@ -284,7 +289,7 @@ local entity_options = {
|
||||
{"tree-03", 500},
|
||||
{"sand-rock-big", 200},
|
||||
{"sand-rock-big", 400},
|
||||
{"red-desert-rock-huge-02", 400},
|
||||
{"red-desert-rock-huge-02", 400}
|
||||
},
|
||||
["red-desert-dark"] = {
|
||||
{"dry-tree", 400},
|
||||
@ -296,24 +301,22 @@ local entity_options = {
|
||||
{"tree-03", 500},
|
||||
{"sand-rock-big", 200},
|
||||
{"sand-rock-big", 400},
|
||||
{"red-desert-rock-huge-02", 400},
|
||||
{"red-desert-rock-huge-02", 400}
|
||||
},
|
||||
["sand-1"] = {
|
||||
{"dry-tree", 1000},
|
||||
{"dry-hairy-tree", 1000},
|
||||
{"dead-tree", 1000},
|
||||
{"rock-big", 150},
|
||||
|
||||
{"rock-big", 150}
|
||||
},
|
||||
["sand-3"] = {
|
||||
{"dead-tree", 1000},
|
||||
{"dry-tree", 1000},
|
||||
{"dry-hairy-tree", 1000},
|
||||
{"rock-big", 150},
|
||||
|
||||
{"rock-big", 150}
|
||||
},
|
||||
["stone-path"] = {},
|
||||
["out-of-map"] = {},
|
||||
["out-of-map"] = {}
|
||||
}
|
||||
|
||||
function check_entities(tile, x, y)
|
||||
|
@ -6,9 +6,8 @@ local function do_row(row, data)
|
||||
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)
|
||||
local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y, data.surface)
|
||||
|
||||
if type(tile) == "boolean" and not tile then
|
||||
table.insert(data.tiles, {name = "out-of-map", position = {x, y}})
|
||||
@ -39,7 +38,9 @@ local function do_place_tiles(data)
|
||||
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()
|
||||
@ -64,21 +65,17 @@ local function do_place_entities(data)
|
||||
end
|
||||
|
||||
function run_combined_module(event)
|
||||
|
||||
if MAP_GEN == nil then
|
||||
game.print("MAP_GEN not set")
|
||||
return
|
||||
end
|
||||
|
||||
local area = event.area
|
||||
local surface = event.surface
|
||||
MAP_GEN_SURFACE = surface
|
||||
|
||||
local data =
|
||||
{
|
||||
local data = {
|
||||
top_x = area.left_top.x,
|
||||
top_y = area.left_top.y,
|
||||
surface = surface,
|
||||
surface = event.surface,
|
||||
tiles = {},
|
||||
entities = {},
|
||||
decoratives = {}
|
||||
@ -91,7 +88,6 @@ function run_combined_module(event)
|
||||
do_place_tiles(data)
|
||||
do_place_decoratives(data)
|
||||
do_place_entities(data)
|
||||
|
||||
end
|
||||
|
||||
local decorative_options = {
|
||||
@ -99,20 +95,18 @@ local decorative_options = {
|
||||
["deepwater"] = {},
|
||||
["deepwater-green"] = {
|
||||
{"brown-carpet-grass", 100},
|
||||
{"brown-cane-cluster", 500},
|
||||
{"brown-cane-cluster", 500}
|
||||
},
|
||||
["dirt-3"] = {
|
||||
{"brown-carpet-grass", 100},
|
||||
{"brown-cane-cluster", 200},
|
||||
{"sand-rock-small", 150},
|
||||
{"sand-rock-small", 150}
|
||||
},
|
||||
["dirt-6"] = {
|
||||
{"sand-rock-small", 150},
|
||||
{"red-asterisk", 45},
|
||||
{"red-desert-bush", 12},
|
||||
{"rock-medium", 375},
|
||||
|
||||
|
||||
{"rock-medium", 375}
|
||||
},
|
||||
["grass-1"] = {
|
||||
{"green-carpet-grass-1", 3},
|
||||
@ -122,7 +116,7 @@ local decorative_options = {
|
||||
{"green-small-grass-1", 12},
|
||||
{"green-asterisk", 25},
|
||||
{"green-bush-mini", 7},
|
||||
{"garballo", 20},
|
||||
{"garballo", 20}
|
||||
},
|
||||
["grass-3"] = {
|
||||
{"green-carpet-grass-1", 12},
|
||||
@ -131,7 +125,7 @@ local decorative_options = {
|
||||
{"green-pita", 24},
|
||||
{"green-small-grass-1", 48},
|
||||
{"green-asterisk", 100},
|
||||
{"green-bush-mini", 28},
|
||||
{"green-bush-mini", 28}
|
||||
},
|
||||
["grass-2"] = {
|
||||
{"green-hairy-grass-1", 56},
|
||||
@ -141,7 +135,7 @@ local decorative_options = {
|
||||
{"green-asterisk", 200},
|
||||
{"green-bush-mini", 56},
|
||||
{"brown-cane-cluster", 100},
|
||||
{"brown-carpet-grass", 100},
|
||||
{"brown-carpet-grass", 100}
|
||||
},
|
||||
["hazard-concrete-left"] = {},
|
||||
["hazard-concrete-right"] = {},
|
||||
@ -154,7 +148,7 @@ local decorative_options = {
|
||||
{"red-desert-bush", 12},
|
||||
{"rock-medium", 375},
|
||||
{"sand-rock-small", 200},
|
||||
{"sand-rock-small", 30},
|
||||
{"sand-rock-small", 30}
|
||||
},
|
||||
["red-desert-dark"] = {
|
||||
{"brown-carpet-grass", 70},
|
||||
@ -163,23 +157,23 @@ local decorative_options = {
|
||||
{"red-desert-bush", 35},
|
||||
{"rock-medium", 375},
|
||||
{"sand-rock-small", 200},
|
||||
{"sand-rock-small", 150},
|
||||
{"sand-rock-small", 150}
|
||||
},
|
||||
["sand-1"] = {
|
||||
{"brown-carpet-grass", 35},
|
||||
{"orange-coral-mini", 45},
|
||||
{"red-asterisk", 45},
|
||||
{"brown-asterisk", 45},
|
||||
{"brown-asterisk", 45}
|
||||
},
|
||||
["sand-3"] = {
|
||||
{"brown-carpet-grass", 35},
|
||||
{"orange-coral-mini", 45},
|
||||
{"brown-asterisk", 45},
|
||||
{"brown-asterisk", 45}
|
||||
},
|
||||
["stone-path"] = {},
|
||||
["water"] = {},
|
||||
["water-green"] = {},
|
||||
["out-of-map"] = {},
|
||||
["out-of-map"] = {}
|
||||
}
|
||||
|
||||
local function check_decorative(tile, x, y)
|
||||
@ -208,13 +202,13 @@ local entity_options = {
|
||||
{"tree-06", 300},
|
||||
{"tree-07", 800},
|
||||
{"tree-09", 2000},
|
||||
{"rock-big", 400},
|
||||
{"rock-big", 400}
|
||||
},
|
||||
["dirt-6"] = {
|
||||
{"tree-06", 150},
|
||||
{"tree-07", 400},
|
||||
{"tree-09", 1000},
|
||||
{"rock-big", 300},
|
||||
{"rock-big", 300}
|
||||
},
|
||||
["grass-1"] = {
|
||||
{"tree-01", 150},
|
||||
@ -223,7 +217,7 @@ local entity_options = {
|
||||
{"tree-07", 400},
|
||||
{"tree-09", 1000},
|
||||
{"rock-big", 400},
|
||||
{"green-coral", 10000},
|
||||
{"green-coral", 10000}
|
||||
},
|
||||
["grass-3"] = {
|
||||
{"tree-02", 400},
|
||||
@ -233,7 +227,7 @@ local entity_options = {
|
||||
{"tree-07", 800},
|
||||
{"tree-08", 400},
|
||||
{"tree-09", 2000},
|
||||
{"rock-big", 400},
|
||||
{"rock-big", 400}
|
||||
},
|
||||
["grass-2"] = {
|
||||
{"tree-04", 800},
|
||||
@ -241,7 +235,7 @@ local entity_options = {
|
||||
{"tree-07", 400},
|
||||
{"tree-09", 1000},
|
||||
{"dry-tree", 1000},
|
||||
{"rock-big", 200},
|
||||
{"rock-big", 200}
|
||||
},
|
||||
["hazard-concrete-left"] = {},
|
||||
["hazard-concrete-right"] = {},
|
||||
@ -257,7 +251,7 @@ local entity_options = {
|
||||
{"tree-03", 500},
|
||||
{"sand-rock-big", 200},
|
||||
{"sand-rock-big", 400},
|
||||
{"red-desert-rock-huge-02", 400},
|
||||
{"red-desert-rock-huge-02", 400}
|
||||
},
|
||||
["red-desert-dark"] = {
|
||||
{"dry-tree", 400},
|
||||
@ -269,24 +263,22 @@ local entity_options = {
|
||||
{"tree-03", 500},
|
||||
{"sand-rock-big", 200},
|
||||
{"sand-rock-big", 400},
|
||||
{"red-desert-rock-huge-02", 400},
|
||||
{"red-desert-rock-huge-02", 400}
|
||||
},
|
||||
["sand-1"] = {
|
||||
{"dry-tree", 1000},
|
||||
{"dry-hairy-tree", 1000},
|
||||
{"dead-tree", 1000},
|
||||
{"rock-big", 150},
|
||||
|
||||
{"rock-big", 150}
|
||||
},
|
||||
["sand-3"] = {
|
||||
{"dead-tree", 1000},
|
||||
{"dry-tree", 1000},
|
||||
{"dry-hairy-tree", 1000},
|
||||
{"rock-big", 150},
|
||||
|
||||
{"rock-big", 150}
|
||||
},
|
||||
["stone-path"] = {},
|
||||
["out-of-map"] = {},
|
||||
["out-of-map"] = {}
|
||||
}
|
||||
|
||||
function check_entities(tile, x, y)
|
||||
|
Loading…
x
Reference in New Issue
Block a user