1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00

Refactor generate_circle_spawn

This commit is contained in:
Matthias Neumayer 2019-12-30 19:46:09 +01:00
parent 3cf61967aa
commit 4ca41abc08

View File

@ -145,25 +145,7 @@ function is_horizontal_border_river(pos)
return false return false
end end
local function generate_circle_spawn(event) local function generate_inner_spawn_circle(pos, distance_to_center, surface)
if global.bb_spawn_generated then return end
local surface = event.surface
local left_top_x = event.area.left_top.x
local left_top_y = event.area.left_top.y
if left_top_x < -320 then return end
if left_top_x > 320 then return end
if left_top_y < -320 then return end
local r = 116
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top_x + x, y = left_top_y + y}
local distance_to_center = math.sqrt(pos.x ^ 2 + pos.y ^ 2)
local noise = get_noise(2, pos) * 15
local tile = false local tile = false
if distance_to_center < spawn_circle_size then if distance_to_center < spawn_circle_size then
tile = "deepwater" tile = "deepwater"
@ -171,6 +153,12 @@ local function generate_circle_spawn(event)
end end
if distance_to_center < 9.5 then tile = "refined-concrete" end if distance_to_center < 9.5 then tile = "refined-concrete" end
if distance_to_center < 7 then tile = "sand-1" end if distance_to_center < 7 then tile = "sand-1" end
if tile then surface.set_tiles({{name = tile, position = pos}}, true) end
end
local function generate_starting_area(pos, distance_to_center, surface)
local r = 116
local noise = get_noise(2, pos) * 15
if distance_to_center + noise < r - 10 and distance_to_center > spawn_circle_size and not is_horizontal_border_river(pos) then if distance_to_center + noise < r - 10 and distance_to_center > spawn_circle_size and not is_horizontal_border_river(pos) then
local tile_name = surface.get_tile(pos).name local tile_name = surface.get_tile(pos).name
@ -217,6 +205,30 @@ local function generate_circle_spawn(event)
end end
end end
end end
end
local function generate_circle_spawn(event)
if global.bb_spawn_generated then return end
local surface = event.surface
local left_top_x = event.area.left_top.x
local left_top_y = event.area.left_top.y
if left_top_x < -320 then return end
if left_top_x > 320 then return end
if left_top_y < -320 then return end
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top_x + x, y = left_top_y + y}
local distance_to_center = math.sqrt(pos.x ^ 2 + pos.y ^ 2)
if distance_to_center < spawn_circle_size then
generate_inner_spawn_circle(pos, distance_to_center, surface)
else
generate_starting_area(pos, distance_to_center, surface)
end
end end
end end