2018-01-20 00:40:40 +02:00
|
|
|
require("map_gen.shared.builders")
|
2018-01-19 16:08:48 +02:00
|
|
|
require("utils.poisson_rng")
|
2017-11-15 12:53:49 +02:00
|
|
|
|
2018-01-19 16:08:48 +02:00
|
|
|
local Thread = require "utils.Thread"
|
2017-08-12 02:20:08 +02:00
|
|
|
|
2018-01-15 19:25:29 +02:00
|
|
|
map_gen_rows_per_tick = map_gen_rows_per_tick or 4
|
|
|
|
map_gen_rows_per_tick = math.min(32, math.max(1, map_gen_rows_per_tick))
|
|
|
|
|
|
|
|
local function do_row(row, data)
|
|
|
|
local y = data.top_y + row
|
|
|
|
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)
|
|
|
|
|
|
|
|
if type(tile) == "boolean" and not tile then
|
|
|
|
table.insert(data.tiles, {name = "out-of-map", position = {x, y}})
|
|
|
|
elseif type(tile) == "string" then
|
|
|
|
table.insert(data.tiles, {name = tile, position = {x, y}})
|
|
|
|
end
|
2017-11-12 15:11:06 +02:00
|
|
|
|
2018-01-15 19:25:29 +02:00
|
|
|
if map_gen_decoratives then
|
|
|
|
tile_decoratives = check_decorative(tile, x, y)
|
|
|
|
for _,tbl in ipairs(tile_decoratives) do
|
|
|
|
table.insert(data.decoratives, tbl)
|
|
|
|
end
|
2017-11-12 23:30:17 +02:00
|
|
|
|
2018-01-15 19:25:29 +02:00
|
|
|
tile_entities = check_entities(tile, x, y)
|
|
|
|
for _,entity in ipairs(tile_entities) do
|
|
|
|
table.insert(data.entities, entity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if entity then
|
|
|
|
table.insert(data.entities, entity)
|
|
|
|
end
|
|
|
|
end
|
2017-11-13 01:56:26 +02:00
|
|
|
end
|
2017-11-12 23:30:17 +02:00
|
|
|
|
2018-01-15 19:25:29 +02:00
|
|
|
local function do_place_tiles(data)
|
|
|
|
data.surface.set_tiles(data.tiles, true)
|
2017-11-13 01:56:26 +02:00
|
|
|
end
|
2017-11-12 23:30:17 +02:00
|
|
|
|
2018-01-15 19:25:29 +02:00
|
|
|
local function do_place_decoratives(data)
|
|
|
|
if not map_gen_decoratives then return end
|
2017-11-12 23:30:17 +02:00
|
|
|
|
2018-01-15 19:25:29 +02:00
|
|
|
for _, e in pairs(surface.find_entities_filtered{area=area, type="decorative"}) do
|
|
|
|
e.destroy()
|
|
|
|
end
|
|
|
|
for _, e in pairs(surface.find_entities_filtered{area=area, type="simple-entity"}) do
|
|
|
|
e.destroy()
|
|
|
|
end
|
|
|
|
|
|
|
|
local surface = data.surface
|
|
|
|
for _,d in pairs(data.decoratives) do
|
|
|
|
surface.create_decoratives{check_collision=false, decoratives={d}}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function do_place_entities(data)
|
|
|
|
local surface = data.surface
|
|
|
|
for _, e in ipairs(data.entities) do
|
|
|
|
if surface.can_place_entity(e) then
|
|
|
|
surface.create_entity(e)
|
|
|
|
end
|
|
|
|
end
|
2017-11-13 01:56:26 +02:00
|
|
|
end
|
2017-11-12 23:30:17 +02:00
|
|
|
|
2018-01-15 19:25:29 +02:00
|
|
|
local function run_chart_update(params)
|
2017-11-13 01:56:26 +02:00
|
|
|
local x = params.area.left_top.x / 32
|
|
|
|
local y = params.area.left_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} } )
|
|
|
|
end
|
|
|
|
end
|
2017-11-12 23:30:17 +02:00
|
|
|
|
2018-01-15 19:25:29 +02:00
|
|
|
function map_gen_action(data)
|
|
|
|
local state = data.state
|
|
|
|
if state < 32 then
|
|
|
|
local count = 1
|
|
|
|
repeat
|
|
|
|
do_row(state, data)
|
|
|
|
state = state + 1
|
|
|
|
count = count + 1
|
|
|
|
until state == 32 or count >= map_gen_rows_per_tick
|
|
|
|
data.state = state
|
|
|
|
return true
|
|
|
|
elseif state == 32 then
|
|
|
|
do_place_tiles(data)
|
|
|
|
data.state = 33
|
|
|
|
return true
|
|
|
|
elseif state == 33 then
|
|
|
|
do_place_decoratives(data)
|
|
|
|
data.state = 34
|
|
|
|
return true
|
|
|
|
elseif state == 34 then
|
|
|
|
do_place_entities(data)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-13 01:56:26 +02:00
|
|
|
function run_combined_module(event)
|
|
|
|
|
|
|
|
if MAP_GEN == nil then
|
|
|
|
game.print("MAP_GEN not set")
|
|
|
|
return
|
2017-11-12 23:30:17 +02:00
|
|
|
end
|
|
|
|
|
2017-11-13 01:56:26 +02:00
|
|
|
local area = event.area
|
|
|
|
local surface = event.surface
|
2018-01-15 19:25:29 +02:00
|
|
|
MAP_GEN_SURFACE = surface
|
|
|
|
|
|
|
|
local data =
|
|
|
|
{
|
|
|
|
state = 0,
|
|
|
|
top_x = area.left_top.x,
|
|
|
|
top_y = area.left_top.y ,
|
|
|
|
surface = surface,
|
|
|
|
tiles = {},
|
|
|
|
entities = {},
|
|
|
|
decoratives = {}
|
|
|
|
}
|
|
|
|
Thread.queue_action("map_gen_action", data)
|
2017-11-12 23:30:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local decorative_options = {
|
|
|
|
["concrete"] = {},
|
|
|
|
["deepwater"] = {},
|
2017-11-13 14:05:18 +02:00
|
|
|
["deepwater-green"] = {
|
2017-12-28 23:45:27 +02:00
|
|
|
{"brown-carpet-grass", 100},
|
2017-11-13 14:05:18 +02:00
|
|
|
{"brown-cane-cluster", 500},
|
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["dirt-3"] = {
|
2017-12-28 23:45:27 +02:00
|
|
|
{"brown-carpet-grass", 100},
|
2017-11-13 14:05:18 +02:00
|
|
|
{"brown-cane-cluster", 200},
|
2017-12-28 23:45:27 +02:00
|
|
|
{"sand-rock-small", 150},
|
2017-11-13 14:05:18 +02:00
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["dirt-6"] = {
|
2017-12-28 23:45:27 +02:00
|
|
|
{"sand-rock-small", 150},
|
2017-11-13 14:05:18 +02:00
|
|
|
{"red-asterisk", 45},
|
|
|
|
{"red-desert-bush", 12},
|
2017-12-28 23:45:27 +02:00
|
|
|
{"rock-medium", 375},
|
2017-11-13 14:05:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["grass-1"] = {
|
|
|
|
{"green-carpet-grass-1", 3},
|
|
|
|
{"green-hairy-grass-1", 7},
|
2017-11-12 23:30:17 +02:00
|
|
|
{"green-bush-mini", 10},
|
|
|
|
{"green-pita", 6},
|
2017-12-28 20:11:25 +02:00
|
|
|
{"green-small-grass-1", 12},
|
2017-11-12 23:30:17 +02:00
|
|
|
{"green-asterisk", 25},
|
|
|
|
{"green-bush-mini", 7},
|
2017-11-13 14:05:18 +02:00
|
|
|
{"garballo", 20},
|
2017-11-12 23:30:17 +02:00
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["grass-3"] = {
|
|
|
|
{"green-carpet-grass-1", 12},
|
|
|
|
{"green-hairy-grass-1", 28},
|
2017-11-13 01:56:26 +02:00
|
|
|
{"green-bush-mini", 40},
|
|
|
|
{"green-pita", 24},
|
2017-12-28 20:11:25 +02:00
|
|
|
{"green-small-grass-1", 48},
|
2017-11-13 01:56:26 +02:00
|
|
|
{"green-asterisk", 100},
|
|
|
|
{"green-bush-mini", 28},
|
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["grass-2"] = {
|
|
|
|
{"green-hairy-grass-1", 56},
|
2017-11-13 01:56:26 +02:00
|
|
|
{"green-bush-mini", 80},
|
|
|
|
{"green-pita", 48},
|
2017-12-28 20:11:25 +02:00
|
|
|
{"green-small-grass-1", 96},
|
2017-11-13 01:56:26 +02:00
|
|
|
{"green-asterisk", 200},
|
|
|
|
{"green-bush-mini", 56},
|
2017-11-13 14:05:18 +02:00
|
|
|
{"brown-cane-cluster", 100},
|
2017-12-28 23:45:27 +02:00
|
|
|
{"brown-carpet-grass", 100},
|
2017-11-13 01:56:26 +02:00
|
|
|
},
|
2017-11-12 23:30:17 +02:00
|
|
|
["hazard-concrete-left"] = {},
|
|
|
|
["hazard-concrete-right"] = {},
|
|
|
|
["lab-dark-1"] = {},
|
|
|
|
["lab-dark-2"] = {},
|
2017-11-13 01:56:26 +02:00
|
|
|
["red-desert"] = {
|
2017-12-28 23:45:27 +02:00
|
|
|
{"brown-carpet-grass", 35},
|
2017-11-13 01:56:26 +02:00
|
|
|
{"orange-coral-mini", 45},
|
|
|
|
{"red-asterisk", 45},
|
|
|
|
{"red-desert-bush", 12},
|
2017-12-28 23:45:27 +02:00
|
|
|
{"rock-medium", 375},
|
|
|
|
{"sand-rock-small", 200},
|
|
|
|
{"sand-rock-small", 30},
|
2017-11-13 01:56:26 +02:00
|
|
|
},
|
|
|
|
["red-desert-dark"] = {
|
2017-12-28 23:45:27 +02:00
|
|
|
{"brown-carpet-grass", 70},
|
2017-11-13 01:56:26 +02:00
|
|
|
{"orange-coral-mini", 90},
|
|
|
|
{"red-asterisk", 90},
|
|
|
|
{"red-desert-bush", 35},
|
2017-12-28 23:45:27 +02:00
|
|
|
{"rock-medium", 375},
|
|
|
|
{"sand-rock-small", 200},
|
|
|
|
{"sand-rock-small", 150},
|
2017-11-13 01:56:26 +02:00
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["sand-1"] = {
|
2017-12-28 23:45:27 +02:00
|
|
|
{"brown-carpet-grass", 35},
|
2017-11-13 14:05:18 +02:00
|
|
|
{"orange-coral-mini", 45},
|
|
|
|
{"red-asterisk", 45},
|
|
|
|
{"brown-asterisk", 45},
|
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["sand-3"] = {
|
2017-12-28 23:45:27 +02:00
|
|
|
{"brown-carpet-grass", 35},
|
2017-11-13 14:05:18 +02:00
|
|
|
{"orange-coral-mini", 45},
|
|
|
|
{"brown-asterisk", 45},
|
|
|
|
},
|
2017-11-12 23:30:17 +02:00
|
|
|
["stone-path"] = {},
|
|
|
|
["water"] = {},
|
|
|
|
["water-green"] = {},
|
|
|
|
["out-of-map"] = {},
|
|
|
|
}
|
|
|
|
|
2018-01-15 19:25:29 +02:00
|
|
|
local function check_decorative(tile, x, y)
|
2017-11-12 23:30:17 +02:00
|
|
|
local options = decorative_options[tile]
|
|
|
|
local tile_decoratives = {}
|
|
|
|
|
|
|
|
for _,e in ipairs(options) do
|
|
|
|
name = e[1]
|
|
|
|
high_roll = e[2]
|
2017-11-15 14:41:34 +02:00
|
|
|
if poisson_rng_next(high_roll / 2 ) == 1 then
|
2017-11-12 23:30:17 +02:00
|
|
|
table.insert(tile_decoratives, {name=name, amount=1, position={x,y}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return tile_decoratives
|
|
|
|
end
|
|
|
|
|
|
|
|
local entity_options = {
|
|
|
|
["concrete"] = {},
|
|
|
|
["deepwater"] = {},
|
|
|
|
["deepwater-green"] = {},
|
2017-11-13 14:05:18 +02:00
|
|
|
["water"] = {},
|
|
|
|
["water-green"] = {},
|
2017-12-28 20:11:25 +02:00
|
|
|
["dirt-3"] = {
|
2017-11-13 14:05:18 +02:00
|
|
|
{"tree-01", 500},
|
|
|
|
{"tree-06", 300},
|
|
|
|
{"tree-07", 800},
|
|
|
|
{"tree-09", 2000},
|
2017-12-28 23:53:39 +02:00
|
|
|
{"rock-big", 400},
|
2017-11-13 14:05:18 +02:00
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["dirt-6"] = {
|
2017-11-13 14:05:18 +02:00
|
|
|
{"tree-06", 150},
|
|
|
|
{"tree-07", 400},
|
|
|
|
{"tree-09", 1000},
|
2017-12-28 23:53:39 +02:00
|
|
|
{"rock-big", 300},
|
2017-11-13 14:05:18 +02:00
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["grass-1"] = {
|
2017-11-13 14:05:18 +02:00
|
|
|
{"tree-01", 150},
|
2017-11-12 23:30:17 +02:00
|
|
|
{"tree-04", 400},
|
2017-11-13 14:05:18 +02:00
|
|
|
{"tree-06", 400},
|
2017-11-12 23:30:17 +02:00
|
|
|
{"tree-07", 400},
|
|
|
|
{"tree-09", 1000},
|
2017-12-28 23:53:39 +02:00
|
|
|
{"rock-big", 400},
|
2017-11-12 23:30:17 +02:00
|
|
|
{"green-coral", 10000},
|
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["grass-3"] = {
|
2017-11-13 14:05:18 +02:00
|
|
|
{"tree-02", 400},
|
|
|
|
{"tree-03", 400},
|
|
|
|
{"tree-04", 800},
|
|
|
|
{"tree-06", 300},
|
|
|
|
{"tree-07", 800},
|
|
|
|
{"tree-08", 400},
|
|
|
|
{"tree-09", 2000},
|
2017-12-28 23:53:39 +02:00
|
|
|
{"rock-big", 400},
|
2017-11-13 14:05:18 +02:00
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["grass-2"] = {
|
2017-11-13 14:05:18 +02:00
|
|
|
{"tree-04", 800},
|
|
|
|
{"tree-06", 300},
|
|
|
|
{"tree-07", 400},
|
|
|
|
{"tree-09", 1000},
|
|
|
|
{"dry-tree", 1000},
|
2017-12-28 23:53:39 +02:00
|
|
|
{"rock-big", 200},
|
2017-11-13 14:05:18 +02:00
|
|
|
},
|
2017-11-12 23:30:17 +02:00
|
|
|
["hazard-concrete-left"] = {},
|
|
|
|
["hazard-concrete-right"] = {},
|
|
|
|
["lab-dark-1"] = {},
|
|
|
|
["lab-dark-2"] = {},
|
2017-11-13 01:56:26 +02:00
|
|
|
["red-desert"] = {
|
|
|
|
{"dry-tree", 400},
|
|
|
|
{"dry-hairy-tree", 400},
|
|
|
|
{"tree-06", 500},
|
|
|
|
{"tree-06", 500},
|
|
|
|
{"tree-01", 500},
|
|
|
|
{"tree-02", 500},
|
|
|
|
{"tree-03", 500},
|
2017-12-28 23:45:27 +02:00
|
|
|
{"sand-rock-big", 200},
|
|
|
|
{"sand-rock-big", 400},
|
2017-11-13 01:56:26 +02:00
|
|
|
{"red-desert-rock-huge-02", 400},
|
|
|
|
},
|
|
|
|
["red-desert-dark"] = {
|
|
|
|
{"dry-tree", 400},
|
|
|
|
{"dry-hairy-tree", 400},
|
|
|
|
{"tree-06", 500},
|
|
|
|
{"tree-06", 500},
|
|
|
|
{"tree-01", 500},
|
|
|
|
{"tree-02", 500},
|
|
|
|
{"tree-03", 500},
|
2017-12-28 23:45:27 +02:00
|
|
|
{"sand-rock-big", 200},
|
|
|
|
{"sand-rock-big", 400},
|
2017-11-13 01:56:26 +02:00
|
|
|
{"red-desert-rock-huge-02", 400},
|
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["sand-1"] = {
|
2017-11-13 14:05:18 +02:00
|
|
|
{"dry-tree", 1000},
|
|
|
|
{"dry-hairy-tree", 1000},
|
|
|
|
{"dead-tree", 1000},
|
2017-12-28 23:53:39 +02:00
|
|
|
{"rock-big", 150},
|
2017-11-13 14:05:18 +02:00
|
|
|
|
|
|
|
},
|
2017-12-28 20:11:25 +02:00
|
|
|
["sand-3"] = {
|
2017-11-13 14:05:18 +02:00
|
|
|
{"dead-tree", 1000},
|
|
|
|
{"dry-tree", 1000},
|
|
|
|
{"dry-hairy-tree", 1000},
|
2017-12-28 23:53:39 +02:00
|
|
|
{"rock-big", 150},
|
2017-11-13 14:05:18 +02:00
|
|
|
|
|
|
|
},
|
2017-11-12 23:30:17 +02:00
|
|
|
["stone-path"] = {},
|
|
|
|
["out-of-map"] = {},
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_entities(tile, x, y)
|
|
|
|
local options = entity_options[tile]
|
|
|
|
local tile_entity_list = {}
|
|
|
|
|
|
|
|
for _,e in ipairs(options) do
|
|
|
|
name = e[1]
|
|
|
|
high_roll = e[2]
|
2017-11-15 14:41:34 +02:00
|
|
|
if poisson_rng_next( high_roll / 2 ) == 1 then
|
2017-11-12 23:30:17 +02:00
|
|
|
table.insert(tile_entity_list, {name=name, position={x,y}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return tile_entity_list
|
2017-11-12 15:11:06 +02:00
|
|
|
end
|