1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00
This commit is contained in:
grilledham 2018-05-10 20:42:38 +01:00
parent ab1aac16a5
commit 4868a090cd
3 changed files with 124 additions and 469 deletions

View File

@ -213,8 +213,11 @@ function Builders.translate(shape, x_offset, y_offset)
end
function Builders.scale(shape, x_scale, y_scale)
y_scale = y_scale or x_scale
x_scale = 1 / x_scale
y_scale = 1 / y_scale
return function(x, y, world)
return shape(x * x_scale, y * y_scale, world)
end
@ -296,7 +299,7 @@ function Builders.combine(shapes)
end
end
i, s = next(shapes, i)
i, s = next(shapes, i)
end
return tile
@ -515,7 +518,7 @@ end
function Builders.entity(shape, name)
return function(x, y, world)
if shape(x, y, world) then
return {name = name, position = {world.x, world.y}}
return {name = name}
end
end
end
@ -528,7 +531,6 @@ function Builders.resource(shape, resource_type, amount_function)
if shape(x, y, world) then
return {
name = resource_type,
position = {world.x, world.y},
amount = amount_function(world.x, world.y)
}
end
@ -1031,6 +1033,40 @@ function Builders.change_map_gen_collision_tile(shape, collides, new_tile)
end
end
local bad_tiles = {
["out-of-map"] = true,
["water"] = true,
["deepwater"] = true,
["water-green"] = true,
["deepwater-green"] = true
}
function Builders.overlay_tile_land(shape, tile_shape)
return function(x, y, world)
local function handle_tile(tile)
if type(tile) == "boolean" then
return tile and not world.surface.get_tile(world.x, world.y).collides_with("water-tile")
else
return not bad_tiles[tile]
end
end
local tile = shape(x, y, world)
if type(tile) == "table" then
if handle_tile(tile.tile) then
tile.tile = tile_shape(x, y, world) or tile.tile
end
else
if handle_tile(tile) then
tile = tile_shape(x, y, world) or tile
end
end
return tile
end
end
local water_tiles = {
["water"] = true,
["deepwater"] = true,
@ -1043,11 +1079,11 @@ function Builders.fish(shape, spawn_rate)
local function handle_tile(tile)
if type(tile) == "string" then
if water_tiles[tile] and spawn_rate >= math.random() then
return {name = "fish", position = {world.x, world.y}}
return {name = "fish"}
end
elseif tile then
if world.surface.get_tile(world.x, world.y).collides_with("water-tile") and spawn_rate >= math.random() then
return {name = "fish", position = {world.x, world.y}}
return {name = "fish"}
end
end
end

View File

@ -1,48 +1,51 @@
require("map_gen.shared.builders")
require("utils.poisson_rng")
local Task = require "utils.Task"
local Token = require "utils.global_token"
local shape
local place_decoratives = true
local function do_row(row, data)
local function do_tile(tile, x, y)
local function do_tile(tile, pos)
if not tile then
table.insert(data.tiles, {name = "out-of-map", position = {x, y}})
table.insert(data.tiles, {name = "out-of-map", position = pos})
elseif type(tile) == "string" then
table.insert(data.tiles, {name = tile, position = {x, y}})
table.insert(data.tiles, {name = tile, position = pos})
end
end
local y = data.top_y + row
local top_x = data.top_x
data.y = y
data.y = y
for x = top_x, top_x + 31 do
data.x = x
local pos = {data.x, data.y}
-- local coords need to be 'centered' to allow for correct rotation and scaling.
local tile = shape(x + 0.5, y + 0.5, data)
if type(tile) == "table" then
do_tile(tile.tile, x, y)
if type(tile) == "table" then
do_tile(tile.tile, pos)
local entities = tile.entities
if entities then
for _, entity in ipairs(entities) do
if not entity.position then
entity.position = pos
end
table.insert(data.entities, entity)
end
end
local decoratives = tile.decoratives
--[[ local decoratives = tile.decoratives
if decoratives then
for _, decorative in ipairs(decoratives) do
table.insert(data.decoratives, decorative)
end
end
end ]]
else
do_tile(tile, x, y)
do_tile(tile, pos)
end
end
end
@ -51,29 +54,41 @@ local function do_place_tiles(data)
data.surface.set_tiles(data.tiles, true)
end
local decoratives = {
"brown-asterisk",
"brown-carpet-grass",
"brown-fluff",
"brown-fluff-dry",
"brown-hairy-grass",
"garballo",
"garballo-mini-dry",
"green-asterisk",
"green-bush-mini",
"green-carpet-grass",
"green-hairy-grass",
"green-pita",
"green-pita-mini",
"green-small-grass",
"red-asterisk"
}
local function do_place_decoratives(data)
if not map_gen_decoratives then
if not place_decoratives then
return
end
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
data.surface.regenerate_decorative(decoratives, {{data.top_x / 32, data.top_y / 32}})
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)
local entity = surface.create_entity(e)
if e.callback then
local callback = Token.get(e.callback)
callback(entity)
end
end
end
end
@ -104,11 +119,11 @@ function map_gen_action(data)
data.state = 33
return true
elseif state == 33 then
do_place_decoratives(data)
do_place_entities(data)
data.state = 34
return true
elseif state == 34 then
do_place_entities(data)
do_place_decoratives(data)
data.state = 35
return true
elseif state == 35 then
@ -132,212 +147,6 @@ local function on_chunk(event)
Task.queue_task("map_gen_action", data, 36)
end
local decorative_options = {
["concrete"] = {},
["deepwater"] = {},
["deepwater-green"] = {
{"brown-carpet-grass", 100},
{"brown-cane-cluster", 500}
},
["dirt-3"] = {
{"brown-carpet-grass", 100},
{"brown-cane-cluster", 200},
{"sand-rock-small", 150}
},
["dirt-6"] = {
{"sand-rock-small", 150},
{"red-asterisk", 45},
{"red-desert-bush", 12},
{"rock-medium", 375}
},
["grass-1"] = {
{"green-carpet-grass-1", 3},
{"green-hairy-grass-1", 7},
{"green-bush-mini", 10},
{"green-pita", 6},
{"green-small-grass-1", 12},
{"green-asterisk", 25},
{"green-bush-mini", 7},
{"garballo", 20}
},
["grass-3"] = {
{"green-carpet-grass-1", 12},
{"green-hairy-grass-1", 28},
{"green-bush-mini", 40},
{"green-pita", 24},
{"green-small-grass-1", 48},
{"green-asterisk", 100},
{"green-bush-mini", 28}
},
["grass-2"] = {
{"green-hairy-grass-1", 56},
{"green-bush-mini", 80},
{"green-pita", 48},
{"green-small-grass-1", 96},
{"green-asterisk", 200},
{"green-bush-mini", 56},
{"brown-cane-cluster", 100},
{"brown-carpet-grass", 100}
},
["hazard-concrete-left"] = {},
["hazard-concrete-right"] = {},
["lab-dark-1"] = {},
["lab-dark-2"] = {},
["red-desert"] = {
{"brown-carpet-grass", 35},
{"orange-coral-mini", 45},
{"red-asterisk", 45},
{"red-desert-bush", 12},
{"rock-medium", 375},
{"sand-rock-small", 200},
{"sand-rock-small", 30}
},
["red-desert-dark"] = {
{"brown-carpet-grass", 70},
{"orange-coral-mini", 90},
{"red-asterisk", 90},
{"red-desert-bush", 35},
{"rock-medium", 375},
{"sand-rock-small", 200},
{"sand-rock-small", 150}
},
["sand-1"] = {
{"brown-carpet-grass", 35},
{"orange-coral-mini", 45},
{"red-asterisk", 45},
{"brown-asterisk", 45}
},
["sand-3"] = {
{"brown-carpet-grass", 35},
{"orange-coral-mini", 45},
{"brown-asterisk", 45}
},
["stone-path"] = {},
["water"] = {},
["water-green"] = {},
["out-of-map"] = {}
}
local function check_decorative(tile, x, y)
local options = decorative_options[tile]
local tile_decoratives = {}
for _, e in ipairs(options) do
name = e[1]
high_roll = e[2]
if poisson_rng_next(high_roll / 2) == 1 then
table.insert(tile_decoratives, {name = name, amount = 1, position = {x, y}})
end
end
return tile_decoratives
end
local entity_options = {
["concrete"] = {},
["deepwater"] = {},
["deepwater-green"] = {},
["water"] = {},
["water-green"] = {},
["dirt-3"] = {
{"tree-01", 500},
{"tree-06", 300},
{"tree-07", 800},
{"tree-09", 2000},
{"rock-big", 400}
},
["dirt-6"] = {
{"tree-06", 150},
{"tree-07", 400},
{"tree-09", 1000},
{"rock-big", 300}
},
["grass-1"] = {
{"tree-01", 150},
{"tree-04", 400},
{"tree-06", 400},
{"tree-07", 400},
{"tree-09", 1000},
{"rock-big", 400},
{"green-coral", 10000}
},
["grass-3"] = {
{"tree-02", 400},
{"tree-03", 400},
{"tree-04", 800},
{"tree-06", 300},
{"tree-07", 800},
{"tree-08", 400},
{"tree-09", 2000},
{"rock-big", 400}
},
["grass-2"] = {
{"tree-04", 800},
{"tree-06", 300},
{"tree-07", 400},
{"tree-09", 1000},
{"dry-tree", 1000},
{"rock-big", 200}
},
["hazard-concrete-left"] = {},
["hazard-concrete-right"] = {},
["lab-dark-1"] = {},
["lab-dark-2"] = {},
["red-desert"] = {
{"dry-tree", 400},
{"dry-hairy-tree", 400},
{"tree-06", 500},
{"tree-06", 500},
{"tree-01", 500},
{"tree-02", 500},
{"tree-03", 500},
{"sand-rock-big", 200},
{"sand-rock-big", 400},
{"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},
{"sand-rock-big", 200},
{"sand-rock-big", 400},
{"red-desert-rock-huge-02", 400}
},
["sand-1"] = {
{"dry-tree", 1000},
{"dry-hairy-tree", 1000},
{"dead-tree", 1000},
{"rock-big", 150}
},
["sand-3"] = {
{"dead-tree", 1000},
{"dry-tree", 1000},
{"dry-hairy-tree", 1000},
{"rock-big", 150}
},
["stone-path"] = {},
["out-of-map"] = {}
}
local 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]
if poisson_rng_next(high_roll / 2) == 1 then
table.insert(tile_entity_list, {name = name, position = {x, y}})
end
end
return tile_entity_list
end
local function init(s)
shape = s
return on_chunk

View File

@ -1,14 +1,14 @@
require("map_gen.shared.builders")
require("utils.poisson_rng")
local Token = require "utils.global_token"
local shape
local place_decoratives = true
local function do_row(row, data)
local function do_tile(tile, x, y)
local function do_tile(tile, pos)
if not tile then
table.insert(data.tiles, {name = "out-of-map", position = {x, y}})
table.insert(data.tiles, {name = "out-of-map", position = pos})
elseif type(tile) == "string" then
table.insert(data.tiles, {name = tile, position = {x, y}})
table.insert(data.tiles, {name = tile, position = pos})
end
end
@ -19,28 +19,32 @@ local function do_row(row, data)
for x = top_x, top_x + 31 do
data.x = x
local pos = {data.x, data.y}
-- local coords need to be 'centered' to allow for correct rotation and scaling.
local tile, entity = shape(x + 0.5, y + 0.5, data)
if type(tile) == "table" then
do_tile(tile.tile, x, y)
if type(tile) == "table" then
do_tile(tile.tile, pos)
local entities = tile.entities
if entities then
for _, entity in ipairs(entities) do
if not entity.position then
entity.position = pos
end
table.insert(data.entities, entity)
end
end
local decoratives = tile.decoratives
--[[ local decoratives = tile.decoratives
if decoratives then
for _, decorative in ipairs(decoratives) do
table.insert(data.decoratives, decorative)
end
end
end ]]
else
do_tile(tile, x, y)
do_tile(tile, pos)
end
end
end
@ -49,35 +53,47 @@ local function do_place_tiles(data)
data.surface.set_tiles(data.tiles, true)
end
local decoratives = {
"brown-asterisk",
"brown-carpet-grass",
"brown-fluff",
"brown-fluff-dry",
"brown-hairy-grass",
"garballo",
"garballo-mini-dry",
"green-asterisk",
"green-bush-mini",
"green-carpet-grass",
"green-hairy-grass",
"green-pita",
"green-pita-mini",
"green-small-grass",
"red-asterisk"
}
local function do_place_decoratives(data)
if not map_gen_decoratives then
if not place_decoratives then
return
end
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
data.surface.regenerate_decorative(decoratives, {{data.top_x / 32, data.top_y / 32}})
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)
local entity = surface.create_entity(e)
if e.callback then
local callback = Token.get(e.callback)
callback(entity)
end
end
end
end
local function on_chunk(event)
local area = event.area
local area = event.area
local data = {
top_x = area.left_top.x,
@ -93,214 +109,8 @@ local function on_chunk(event)
end
do_place_tiles(data)
do_place_entities(data)
do_place_decoratives(data)
do_place_entities(data)
end
local decorative_options = {
["concrete"] = {},
["deepwater"] = {},
["deepwater-green"] = {
{"brown-carpet-grass", 100},
{"brown-cane-cluster", 500}
},
["dirt-3"] = {
{"brown-carpet-grass", 100},
{"brown-cane-cluster", 200},
{"sand-rock-small", 150}
},
["dirt-6"] = {
{"sand-rock-small", 150},
{"red-asterisk", 45},
{"red-desert-bush", 12},
{"rock-medium", 375}
},
["grass-1"] = {
{"green-carpet-grass-1", 3},
{"green-hairy-grass-1", 7},
{"green-bush-mini", 10},
{"green-pita", 6},
{"green-small-grass-1", 12},
{"green-asterisk", 25},
{"green-bush-mini", 7},
{"garballo", 20}
},
["grass-3"] = {
{"green-carpet-grass-1", 12},
{"green-hairy-grass-1", 28},
{"green-bush-mini", 40},
{"green-pita", 24},
{"green-small-grass-1", 48},
{"green-asterisk", 100},
{"green-bush-mini", 28}
},
["grass-2"] = {
{"green-hairy-grass-1", 56},
{"green-bush-mini", 80},
{"green-pita", 48},
{"green-small-grass-1", 96},
{"green-asterisk", 200},
{"green-bush-mini", 56},
{"brown-cane-cluster", 100},
{"brown-carpet-grass", 100}
},
["hazard-concrete-left"] = {},
["hazard-concrete-right"] = {},
["lab-dark-1"] = {},
["lab-dark-2"] = {},
["red-desert"] = {
{"brown-carpet-grass", 35},
{"orange-coral-mini", 45},
{"red-asterisk", 45},
{"red-desert-bush", 12},
{"rock-medium", 375},
{"sand-rock-small", 200},
{"sand-rock-small", 30}
},
["red-desert-dark"] = {
{"brown-carpet-grass", 70},
{"orange-coral-mini", 90},
{"red-asterisk", 90},
{"red-desert-bush", 35},
{"rock-medium", 375},
{"sand-rock-small", 200},
{"sand-rock-small", 150}
},
["sand-1"] = {
{"brown-carpet-grass", 35},
{"orange-coral-mini", 45},
{"red-asterisk", 45},
{"brown-asterisk", 45}
},
["sand-3"] = {
{"brown-carpet-grass", 35},
{"orange-coral-mini", 45},
{"brown-asterisk", 45}
},
["stone-path"] = {},
["water"] = {},
["water-green"] = {},
["out-of-map"] = {}
}
local function check_decorative(tile, x, y)
local options = decorative_options[tile]
local tile_decoratives = {}
for _, e in ipairs(options) do
name = e[1]
high_roll = e[2]
if poisson_rng_next(high_roll / 2) == 1 then
table.insert(tile_decoratives, {name = name, amount = 1, position = {x, y}})
end
end
return tile_decoratives
end
local entity_options = {
["concrete"] = {},
["deepwater"] = {},
["deepwater-green"] = {},
["water"] = {},
["water-green"] = {},
["dirt-3"] = {
{"tree-01", 500},
{"tree-06", 300},
{"tree-07", 800},
{"tree-09", 2000},
{"rock-big", 400}
},
["dirt-6"] = {
{"tree-06", 150},
{"tree-07", 400},
{"tree-09", 1000},
{"rock-big", 300}
},
["grass-1"] = {
{"tree-01", 150},
{"tree-04", 400},
{"tree-06", 400},
{"tree-07", 400},
{"tree-09", 1000},
{"rock-big", 400},
{"green-coral", 10000}
},
["grass-3"] = {
{"tree-02", 400},
{"tree-03", 400},
{"tree-04", 800},
{"tree-06", 300},
{"tree-07", 800},
{"tree-08", 400},
{"tree-09", 2000},
{"rock-big", 400}
},
["grass-2"] = {
{"tree-04", 800},
{"tree-06", 300},
{"tree-07", 400},
{"tree-09", 1000},
{"dry-tree", 1000},
{"rock-big", 200}
},
["hazard-concrete-left"] = {},
["hazard-concrete-right"] = {},
["lab-dark-1"] = {},
["lab-dark-2"] = {},
["red-desert"] = {
{"dry-tree", 400},
{"dry-hairy-tree", 400},
{"tree-06", 500},
{"tree-06", 500},
{"tree-01", 500},
{"tree-02", 500},
{"tree-03", 500},
{"sand-rock-big", 200},
{"sand-rock-big", 400},
{"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},
{"sand-rock-big", 200},
{"sand-rock-big", 400},
{"red-desert-rock-huge-02", 400}
},
["sand-1"] = {
{"dry-tree", 1000},
{"dry-hairy-tree", 1000},
{"dead-tree", 1000},
{"rock-big", 150}
},
["sand-3"] = {
{"dead-tree", 1000},
{"dry-tree", 1000},
{"dry-hairy-tree", 1000},
{"rock-big", 150}
},
["stone-path"] = {},
["out-of-map"] = {}
}
local 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]
if poisson_rng_next(high_roll / 2) == 1 then
table.insert(tile_entity_list, {name = name, position = {x, y}})
end
end
return tile_entity_list
end
local function init(s)