2019-11-04 04:36:47 +02:00
|
|
|
local math_abs = math.abs
|
|
|
|
|
2019-11-03 20:34:36 +02:00
|
|
|
local function get_replacement_tile(surface, position)
|
|
|
|
for i = 1, 128, 1 do
|
|
|
|
local vectors = {{0, i}, {0, i * -1}, {i, 0}, {i * -1, 0}}
|
|
|
|
table.shuffle_table(vectors)
|
|
|
|
for k, v in pairs(vectors) do
|
|
|
|
local tile = surface.get_tile(position.x + v[1], position.y + v[2])
|
|
|
|
if not tile.collides_with("resource-layer") then return tile.name end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return "grass-1"
|
|
|
|
end
|
|
|
|
|
|
|
|
local function combat_area(event)
|
|
|
|
local surface = event.surface
|
2019-11-04 04:36:47 +02:00
|
|
|
local left_top = event.area.left_top
|
|
|
|
|
|
|
|
if left_top.y >= 96 then return end
|
|
|
|
if left_top.y < -96 then return end
|
|
|
|
|
2019-11-03 20:34:36 +02:00
|
|
|
for _, tile in pairs(surface.find_tiles_filtered({area = event.area})) do
|
|
|
|
if tile.name == "water" or tile.name == "deepwater" then
|
|
|
|
surface.set_tiles({{name = get_replacement_tile(surface, tile.position), position = tile.position}}, true)
|
|
|
|
end
|
|
|
|
if tile.position.x >= -4 and tile.position.x <= 4 then
|
|
|
|
surface.set_tiles({{name = "water-shallow", position = tile.position}}, true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for _, entity in pairs(surface.find_entities_filtered({type = {"resource", "cliff"}, area = event.area})) do
|
|
|
|
entity.destroy()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-04 04:36:47 +02:00
|
|
|
local function is_out_of_map(p)
|
|
|
|
if p.y < 96 and p.y >= -96 then return end
|
2019-11-04 04:53:23 +02:00
|
|
|
if p.x * 0.5 >= math_abs(p.y) then return end
|
2019-11-04 04:36:47 +02:00
|
|
|
if p.x * -0.5 > math_abs(p.y) then return end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function out_of_map_area(event)
|
|
|
|
local surface = event.surface
|
|
|
|
local left_top = event.area.left_top
|
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
|
|
|
local p = {x = left_top.x + x, y = left_top.y + y}
|
|
|
|
if is_out_of_map(p) then surface.set_tiles({{name = "out-of-map", position = p}}, true) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-03 19:57:36 +02:00
|
|
|
local function on_chunk_generated(event)
|
|
|
|
local left_top = event.area.left_top
|
|
|
|
|
2019-11-04 04:36:47 +02:00
|
|
|
out_of_map_area(event)
|
|
|
|
|
2019-11-03 21:29:19 +02:00
|
|
|
if left_top.x >= -192 and left_top.x < 192 then combat_area(event) end
|
2019-11-03 20:34:36 +02:00
|
|
|
|
2019-11-03 19:57:36 +02:00
|
|
|
if left_top.x > 512 then return end
|
|
|
|
if left_top.x < -512 then return end
|
|
|
|
if left_top.y > 512 then return end
|
|
|
|
if left_top.y < -512 then return end
|
|
|
|
|
|
|
|
game.forces.west.chart(event.surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}})
|
|
|
|
game.forces.east.chart(event.surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}})
|
|
|
|
end
|
|
|
|
|
|
|
|
local event = require 'utils.event'
|
|
|
|
event.add(defines.events.on_chunk_generated, on_chunk_generated)
|