mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-11-06 09:09:26 +02:00
updated to new module system
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
local Task = require "utils.Task"
|
||||
local Token = require "utils.global_token"
|
||||
local Task = require 'utils.Task'
|
||||
local Token = require 'utils.global_token'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local shape
|
||||
local place_decoratives = true
|
||||
local regen_decoratives
|
||||
|
||||
local function do_row(row, data)
|
||||
local function do_tile(tile, pos)
|
||||
if not tile then
|
||||
table.insert(data.tiles, {name = "out-of-map", position = pos})
|
||||
elseif type(tile) == "string" then
|
||||
table.insert(data.tiles, {name = 'out-of-map', position = pos})
|
||||
elseif type(tile) == 'string' then
|
||||
table.insert(data.tiles, {name = tile, position = pos})
|
||||
end
|
||||
end
|
||||
@@ -25,7 +26,13 @@ local function do_row(row, data)
|
||||
-- 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
|
||||
if type(tile) == 'table' then
|
||||
--[[ local decoratives = tile.decoratives
|
||||
if decoratives then
|
||||
for _, decorative in ipairs(decoratives) do
|
||||
table.insert(data.decoratives, decorative)
|
||||
end
|
||||
end ]]
|
||||
do_tile(tile.tile, pos)
|
||||
|
||||
local entities = tile.entities
|
||||
@@ -37,13 +44,6 @@ local function do_row(row, data)
|
||||
table.insert(data.entities, entity)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ local decoratives = tile.decoratives
|
||||
if decoratives then
|
||||
for _, decorative in ipairs(decoratives) do
|
||||
table.insert(data.decoratives, decorative)
|
||||
end
|
||||
end ]]
|
||||
else
|
||||
do_tile(tile, pos)
|
||||
end
|
||||
@@ -55,29 +55,27 @@ local function do_place_tiles(data)
|
||||
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"
|
||||
'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 place_decoratives then
|
||||
return
|
||||
if regen_decoratives then
|
||||
data.surface.regenerate_decorative(decoratives, {{data.top_x / 32, data.top_y / 32}})
|
||||
end
|
||||
|
||||
data.surface.regenerate_decorative(decoratives, {{data.top_x / 32, data.top_y / 32}})
|
||||
end
|
||||
|
||||
local function do_place_entities(data)
|
||||
@@ -144,12 +142,14 @@ local function on_chunk(event)
|
||||
entities = {},
|
||||
decoratives = {}
|
||||
}
|
||||
Task.queue_task("map_gen_action", data, 36)
|
||||
Task.queue_task('map_gen_action', data, 36)
|
||||
end
|
||||
|
||||
local function init(s)
|
||||
shape = s
|
||||
return on_chunk
|
||||
local function init(args)
|
||||
shape = args.shape
|
||||
regen_decoratives = args.regen_decoratives or false
|
||||
|
||||
Event.add(defines.events.on_chunk_generated, on_chunk)
|
||||
end
|
||||
|
||||
return init
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
local Token = require "utils.global_token"
|
||||
local Token = require 'utils.global_token'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local shape
|
||||
local place_decoratives = true
|
||||
local regen_decoratives
|
||||
|
||||
local function do_row(row, data)
|
||||
local function do_tile(tile, pos)
|
||||
if not tile then
|
||||
table.insert(data.tiles, {name = "out-of-map", position = pos})
|
||||
elseif type(tile) == "string" then
|
||||
table.insert(data.tiles, {name = 'out-of-map', position = pos})
|
||||
elseif type(tile) == 'string' then
|
||||
table.insert(data.tiles, {name = tile, position = pos})
|
||||
end
|
||||
end
|
||||
@@ -22,9 +23,15 @@ local function do_row(row, data)
|
||||
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)
|
||||
local tile = shape(x + 0.5, y + 0.5, data)
|
||||
|
||||
if type(tile) == "table" then
|
||||
if type(tile) == 'table' then
|
||||
--[[ local decoratives = tile.decoratives
|
||||
if decoratives then
|
||||
for _, decorative in ipairs(decoratives) do
|
||||
table.insert(data.decoratives, decorative)
|
||||
end
|
||||
end ]]
|
||||
do_tile(tile.tile, pos)
|
||||
|
||||
local entities = tile.entities
|
||||
@@ -36,13 +43,6 @@ local function do_row(row, data)
|
||||
table.insert(data.entities, entity)
|
||||
end
|
||||
end
|
||||
|
||||
--[[ local decoratives = tile.decoratives
|
||||
if decoratives then
|
||||
for _, decorative in ipairs(decoratives) do
|
||||
table.insert(data.decoratives, decorative)
|
||||
end
|
||||
end ]]
|
||||
else
|
||||
do_tile(tile, pos)
|
||||
end
|
||||
@@ -54,29 +54,27 @@ local function do_place_tiles(data)
|
||||
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"
|
||||
'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 place_decoratives then
|
||||
return
|
||||
if regen_decoratives then
|
||||
data.surface.regenerate_decorative(decoratives, {{data.top_x / 32, data.top_y / 32}})
|
||||
end
|
||||
|
||||
data.surface.regenerate_decorative(decoratives, {{data.top_x / 32, data.top_y / 32}})
|
||||
end
|
||||
|
||||
local function do_place_entities(data)
|
||||
@@ -113,9 +111,11 @@ local function on_chunk(event)
|
||||
do_place_decoratives(data)
|
||||
end
|
||||
|
||||
local function init(s)
|
||||
shape = s
|
||||
return on_chunk
|
||||
local function init(args)
|
||||
shape = args.shape
|
||||
regen_decoratives = args.regen_decoratives
|
||||
|
||||
Event.add(defines.events.on_chunk_generated, on_chunk)
|
||||
end
|
||||
|
||||
return init
|
||||
|
||||
@@ -1,64 +1,25 @@
|
||||
|
||||
require "map_gen.shared.perlin_noise"
|
||||
local Event = require "utils.event"
|
||||
|
||||
local tree_to_place = {"dry-tree","dry-hairy-tree","tree-06","tree-06","tree-01","tree-02","tree-03"}
|
||||
|
||||
function run_terrain_module(event)
|
||||
if not global.terrain_seed_A then global.terrain_seed_A = math.random(10,10000) end
|
||||
if not global.terrain_seed_B then global.terrain_seed_B = math.random(10,10000) end
|
||||
|
||||
local area = event.area
|
||||
local surface = event.surface
|
||||
local tiles = {}
|
||||
local tileswater = {}
|
||||
|
||||
local entities = surface.find_entities(area)
|
||||
for _, entity in pairs(entities) do
|
||||
if (run_ores_module ~= nil and entity.type == "resource") then
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
|
||||
local top_left = area.left_top --make a more direct reference
|
||||
|
||||
for x = top_left.x-1, top_left.x + 32 do
|
||||
for y = top_left.y-1, top_left.y + 32 do
|
||||
--local pos_x = top_left.x + x
|
||||
--local pos_y = top_left.y + y
|
||||
local tile = surface.get_tile(x,y)
|
||||
|
||||
if tile.name ~= "out-of-map" then
|
||||
|
||||
--local tile_to_insert = "grass-3"
|
||||
|
||||
local wiggle = 50 + perlin:noise((x*0.005),(y*0.005),global.terrain_seed_A + 71) * 60
|
||||
local terrain_A = perlin:noise((x*0.005),(y*0.005),global.terrain_seed_A + 19) * wiggle --For determining where water is
|
||||
local terrain_sqr = terrain_A * terrain_A --we can use this again to mess with other layers as well
|
||||
|
||||
|
||||
if terrain_sqr < 50 then --Main water areas
|
||||
--local deep = (terrain_sqr < 20) and true or false
|
||||
terrain_A = perlin:noise((x*0.01),(y*0.01),global.terrain_seed_A + 31) * 90 + (wiggle * -0.2) --we only gen this when we consider placing water
|
||||
--terrain_A = simplex_2d((x*0.01),(y*0.01),global.terrain_seed_A + 31) * 90 + (wiggle * -0.2) --we only gen this when we consider placing water
|
||||
|
||||
if terrain_A * terrain_A > 40 then --creates random bridges over the water by overlapping with another noise layer
|
||||
table.insert(tiles, {name = "water", position = {x,y}})
|
||||
end
|
||||
elseif terrain_sqr > 70 then
|
||||
|
||||
if run_ores_module ~= nil then
|
||||
run_ores_module_setup()
|
||||
if x > top_left.x-1 and x < top_left.x+32 and y > top_left.y-1 and y < top_left.y+32 then
|
||||
run_ores_module_tile(surface,x,y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
surface.set_tiles(tiles,true)
|
||||
--surface.set_tiles(tileswater,true)
|
||||
local function init()
|
||||
global.terrain_seed_A = math.random(10, 10000)
|
||||
global.terrain_seed_B = math.random(10, 10000)
|
||||
end
|
||||
|
||||
Event.on_init(init)
|
||||
|
||||
return function(x, y, world)
|
||||
local wiggle = 50 + perlin:noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 71) * 60
|
||||
local terrain_A = perlin:noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 19) * wiggle --For determining where water is
|
||||
local terrain_sqr = terrain_A * terrain_A --we can use this again to mess with other layers as well
|
||||
|
||||
if terrain_sqr < 50 then --Main water areas
|
||||
terrain_A = perlin:noise((x * 0.01), (y * 0.01), global.terrain_seed_A + 31) * 90 + (wiggle * -0.2) --we only gen this when we consider placing water
|
||||
|
||||
if terrain_A * terrain_A > 40 then --creates random bridges over the water by overlapping with another noise layer
|
||||
return "water"
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -92,12 +92,12 @@ local entity_modules = {
|
||||
--require "map_gen.misc.wreck_items",
|
||||
--require "map_gen.ores.neko_crazy_ores",
|
||||
--require "map_gen.ores.fluffy_rainbows",
|
||||
--require "map_gen.ores.harmonic_gen",
|
||||
--require "map_gen.ores.harmonic_gen",
|
||||
--require "map_gen.ores.resource_clustertruck"
|
||||
}
|
||||
|
||||
local terrain_modules ={
|
||||
--require "map_gen.misc.tris_chunk_grid",
|
||||
--require "map_gen.misc.tris_chunk_grid",
|
||||
}
|
||||
|
||||
--everything else. You may use more than one of these, but beware they might not be compatible
|
||||
@@ -105,6 +105,8 @@ miscs = {}
|
||||
--require "map_gen.misc.rusky_pvp"
|
||||
--table.insert(miscs, require("map_gen.misc.rail_grid")) -- used for map_gen.presets.UK
|
||||
|
||||
local regen_decoratives = false
|
||||
|
||||
if #entity_modules > 0 then
|
||||
shape = shape or b.full_shape
|
||||
|
||||
@@ -120,11 +122,8 @@ if #terrain_modules > 0 then
|
||||
end
|
||||
|
||||
if shape then
|
||||
local gen = require "map_gen.shared.generate"
|
||||
--local gen = require "map_gen.shared.generate_not_threaded"
|
||||
|
||||
gen = gen(shape)
|
||||
Event.add(defines.events.on_chunk_generated, gen)
|
||||
require ("map_gen.shared.generate")({shape = shape, regen_decoratives = regen_decoratives})
|
||||
--require ("map_gen.shared.generate_not_threaded")({shape = shape, regen_decoratives = regen_decoratives})
|
||||
end
|
||||
|
||||
--[[ local on_chunk_generated = function(event)
|
||||
|
||||
Reference in New Issue
Block a user