1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-13 13:49:33 +02:00

77 lines
2.1 KiB
Lua
Raw Normal View History

2020-04-01 17:10:29 +02:00
local math_floor = math.floor
local math_random = math.random
local table_insert = table.insert
local table_remove = table.remove
2024-01-28 20:42:28 +01:00
local NoiseVector = require 'utils.functions.noise_vector_path'
2020-04-01 17:10:29 +02:00
2021-03-24 20:14:55 +01:00
local function get_vector()
2021-03-24 16:46:00 +01:00
local x = 1000 - math_random(0, 2000)
local y = -1000 + math_random(0, 1100)
x = x * 0.001
y = y * 0.001
return { x, y }
2020-04-01 17:10:29 +02:00
end
local function can_draw_branch(surface, chunk_position)
2021-03-24 16:46:00 +01:00
for x = -3, 3, 1 do
for y = -3, 3, 1 do
if not surface.is_chunk_generated({ chunk_position[1] + x, chunk_position[2] + y }) then
2021-03-24 16:46:00 +01:00
return false
end
end
end
return true
2020-04-01 17:10:29 +02:00
end
local function draw_branch(surface, key)
local position = storage.tree_points[key][1]
local vector = storage.tree_points[key][3]
local size = storage.tree_points[key][4]
2021-03-24 16:46:00 +01:00
if surface.count_tiles_filtered({ name = 'green-refined-concrete', area = { { position.x - 32, position.y - 32 }, { position.x + 32, position.y + 32 } } }) > 960 then
table_remove(storage.tree_points, key)
2021-03-24 16:46:00 +01:00
return
end
2021-03-24 20:14:55 +01:00
local tiles = NoiseVector.noise_vector_tile_path(surface, 'green-refined-concrete', position, vector, size * 4, size * 0.25)
2020-04-01 17:10:29 +02:00
2021-03-24 16:46:00 +01:00
for i = #tiles - math_random(0, 3), #tiles, 1 do
table_insert(
storage.tree_points,
2021-03-24 16:46:00 +01:00
{
tiles[i].position,
{ math_floor(tiles[i].position.x / 32), math_floor(tiles[i].position.y / 32) },
2021-03-24 16:46:00 +01:00
get_vector(position),
math_random(8, 16)
}
)
end
table_remove(storage.tree_points, key)
2020-04-01 17:10:29 +02:00
end
local function on_init()
storage.chunks_charted = {}
storage.tree_points = {}
2021-03-24 16:46:00 +01:00
storage.tree_points[1] = { { x = 0, y = 0 }, { 0, 0 }, { 0, -1 }, 16 }
2021-03-24 16:46:00 +01:00
--position | chunk position | vector | size
2020-04-01 17:10:29 +02:00
end
local function tick()
2021-03-24 16:46:00 +01:00
local surface = game.surfaces[1]
for key, point in pairs(storage.tree_points) do
2021-03-24 16:46:00 +01:00
if can_draw_branch(surface, point[2]) then
draw_branch(surface, key)
end
end
game.print(#storage.tree_points)
2020-04-01 17:10:29 +02:00
end
2021-03-24 16:46:00 +01:00
local Event = require 'utils.event'
2020-04-01 17:10:29 +02:00
Event.on_init(on_init)
2021-03-24 16:46:00 +01:00
Event.on_nth_tick(120, tick)