2021-03-24 20:14:55 +01:00
|
|
|
local Event = require 'utils.event'
|
2018-09-28 16:47:45 +02:00
|
|
|
|
2021-03-24 20:14:55 +01:00
|
|
|
local function on_tick()
|
2024-09-24 19:37:11 +02:00
|
|
|
if storage.map_pregeneration_is_active then
|
2021-03-24 16:46:00 +01:00
|
|
|
if game.tick % 600 == 0 then
|
|
|
|
|
local r = 1
|
2024-09-24 19:37:11 +02:00
|
|
|
for x = 1, storage.chunk_radius, 1 do
|
|
|
|
|
if game.forces.map_pregen.is_chunk_charted(game.players[1].surface, { x, x }) then
|
2021-03-24 16:46:00 +01:00
|
|
|
r = x
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-09-24 19:37:11 +02:00
|
|
|
game.print('Map chunks are generating... current radius ' .. r, { r = 0.22, g = 0.99, b = 0.99 })
|
|
|
|
|
if game.forces.map_pregen.is_chunk_charted(game.players[1].surface, { storage.chunk_radius, storage.chunk_radius }) then
|
|
|
|
|
game.print('Map generation done!', { r = 0.22, g = 0.99, b = 0.99 })
|
2021-03-24 16:46:00 +01:00
|
|
|
|
|
|
|
|
game.players[1].force = game.forces['player']
|
2024-09-24 19:37:11 +02:00
|
|
|
storage.map_pregeneration_is_active = nil
|
2021-03-24 16:46:00 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-09-28 16:47:45 +02:00
|
|
|
end
|
|
|
|
|
|
2021-03-24 20:14:55 +01:00
|
|
|
local function map_pregen(chunk_radius)
|
2021-03-24 16:46:00 +01:00
|
|
|
if chunk_radius then
|
2024-09-24 19:37:11 +02:00
|
|
|
storage.chunk_radius = chunk_radius
|
2021-03-24 16:46:00 +01:00
|
|
|
else
|
2024-09-24 19:37:11 +02:00
|
|
|
storage.chunk_radius = 32
|
2021-03-24 16:46:00 +01:00
|
|
|
end
|
2024-09-24 19:37:11 +02:00
|
|
|
local radius = storage.chunk_radius * 32
|
2021-03-24 16:46:00 +01:00
|
|
|
if not game.forces.map_pregen then
|
|
|
|
|
game.create_force('map_pregen')
|
|
|
|
|
end
|
|
|
|
|
game.players[1].force = game.forces['map_pregen']
|
2024-09-24 19:37:11 +02:00
|
|
|
game.forces.map_pregen.chart(game.players[1].surface, { { x = -1 * radius, y = -1 * radius }, { x = radius, y = radius } })
|
|
|
|
|
storage.map_pregeneration_is_active = true
|
2018-09-28 16:47:45 +02:00
|
|
|
end
|
|
|
|
|
|
2021-03-24 20:14:55 +01:00
|
|
|
Event.add(defines.events.on_tick, on_tick)
|
|
|
|
|
|
|
|
|
|
return map_pregen
|