mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-30 04:30:58 +02:00
commit
c5306625fb
@ -12,6 +12,7 @@ local Global = require 'utils.global'
|
||||
local Game = require 'utils.game'
|
||||
local CreateParticles = require 'features.create_particles'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local table = require 'utils.table'
|
||||
|
||||
local random = math.random
|
||||
local floor = math.floor
|
||||
@ -24,6 +25,7 @@ local raise_event = script.raise_event
|
||||
local set_timeout = Task.set_timeout
|
||||
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||
local ceiling_crumble = CreateParticles.ceiling_crumble
|
||||
local clear_table = table.clear_table
|
||||
local collapse_rocks = Template.diggy_rocks
|
||||
local collapse_rocks_size = #collapse_rocks
|
||||
|
||||
@ -51,6 +53,7 @@ local ring_value = 0
|
||||
local enable_stress_grid = 0
|
||||
local stress_map_add
|
||||
local mask_disc_blur
|
||||
local mask_init
|
||||
local stress_map_check_stress_in_threshold
|
||||
local support_beam_entities
|
||||
local on_surface_created
|
||||
@ -512,7 +515,7 @@ on_surface_created = function(event)
|
||||
local index = event.surface_index
|
||||
|
||||
if stress_map_storage[index] then
|
||||
table.clear_table(stress_map_storage[index])
|
||||
clear_table(stress_map_storage[index])
|
||||
else
|
||||
stress_map_storage[index] = {}
|
||||
end
|
||||
@ -579,7 +582,7 @@ DiggyCaveCollapse.stress_map_add = stress_map_add
|
||||
-- MASK
|
||||
--
|
||||
|
||||
function mask_init(config)
|
||||
mask_init = function(config) -- luacheck: ignore 431 (intentional upvalue shadow)
|
||||
n = config.mask_size
|
||||
local ring_weights = config.mask_relative_ring_weights
|
||||
|
||||
|
@ -61,6 +61,8 @@ local function generate_nihil(event)
|
||||
event.surface.set_tiles(tiles)
|
||||
end
|
||||
|
||||
--[[
|
||||
Nothihng calls run_combined_module and I'm not sure what to do with it since it seems to want an event to trigger it
|
||||
function run_combined_module(event)
|
||||
init()
|
||||
if event.surface.name == 'Zerus' then
|
||||
@ -69,6 +71,7 @@ function run_combined_module(event)
|
||||
generate_nihil(event)
|
||||
end
|
||||
end
|
||||
]]
|
||||
|
||||
local function teleport_nearby_players(portal)
|
||||
for _, player_character in pairs(portal.source.find_entities_filtered {area = {{portal.position.x - global.portal_radius, portal.position.y - global.portal_radius}, {portal.position.x + global.portal_radius, portal.position.y + global.portal_radius}}, name = 'player', type = 'player'}) do
|
||||
|
@ -23,7 +23,7 @@ return function(x, y, world)
|
||||
return
|
||||
end
|
||||
|
||||
local distance_bonus = 100 + 0.4 * d ^ 1.2
|
||||
local distance_bonus = 100 + 0.4 * d_sq ^ 2.4 -- d ^ 1.2
|
||||
|
||||
local wiggle = 100 + perlin.noise((x * 0.005), (y * 0.005), global.ores_seed_A + 41) * 60
|
||||
local Ores_A = perlin.noise((x * 0.01), (y * 0.01), global.ores_seed_B + 57) * wiggle
|
||||
|
@ -26,7 +26,7 @@ local resource_density_factor = 500
|
||||
--Warning: Do not exceed the total number of cells in the maze, or it will break!
|
||||
|
||||
--DO NOT TOUCH BELOW THIS LINE--
|
||||
|
||||
local _ -- garbage collection var
|
||||
local bor = bit32.bor
|
||||
local bxor = bit32.bxor
|
||||
local band = bit32.band
|
||||
@ -132,7 +132,7 @@ local function get_maze(x, y, seed, width, height)
|
||||
value = rshift(value, 16)
|
||||
maze_data[1][value % height + 1] = band(maze_data[1][value % height + 1], 2)
|
||||
|
||||
maze_seed, value = get_random_maze_val(maze_seed)
|
||||
_, value = get_random_maze_val(maze_seed)
|
||||
maze_data[width + 1] = {0, 0}
|
||||
maze_data[width + 1][1] = value % width + 1
|
||||
value = rshift(value, 16)
|
||||
|
@ -2,10 +2,11 @@ local thickness = 72 -- change this to change the spiral thickness.
|
||||
|
||||
local inv_pi = 1 / math.pi
|
||||
local thickness2 = thickness * 2
|
||||
local sqrt = math.sqrt
|
||||
|
||||
return function(x, y)
|
||||
local d_sq = x * x + y * y
|
||||
if d_sq < 16384 then --d < 128
|
||||
local d = sqrt(x * x + y * y)
|
||||
if d < 128 then
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -1,178 +1,113 @@
|
||||
local perlin = require 'map_gen.shared.perlin_noise'
|
||||
local simplex = require 'map_gen.shared.simplex_noise'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local seed_a
|
||||
local seed_b
|
||||
|
||||
Global.register_init(
|
||||
{},
|
||||
function(tbl)
|
||||
tbl.seed_a = math.random(10, 10000)
|
||||
tbl.seed_b = math.random(10, 10000)
|
||||
end,
|
||||
function(tbl)
|
||||
seed_a = tbl.seed_a
|
||||
seed_b = tbl.seed_b
|
||||
end
|
||||
)
|
||||
|
||||
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)
|
||||
local types = {'simple-entity', 'tree'}
|
||||
|
||||
local function run_terrain_module(x, y, world)
|
||||
local surface = world.surface
|
||||
|
||||
local wx, wy = world.x, world.y
|
||||
local pos = {wx, wy}
|
||||
|
||||
local area = {pos, {wx + 1, wy + 1}}
|
||||
local es = surface.find_entities_filtered({area = area, type = types})
|
||||
for i = 1, #es do
|
||||
es[i].destroy()
|
||||
end
|
||||
|
||||
local area = event.area
|
||||
local surface = event.surface
|
||||
local tiles = {}
|
||||
local tileswater = {}
|
||||
local tile_to_insert = 'grass-3'
|
||||
|
||||
local entities = surface.find_entities(area)
|
||||
for _, entity in pairs(entities) do
|
||||
--if entity.type == "simple-entity" or entity.type == "resource" or entity.type == "tree" then
|
||||
if entity.type == 'simple-entity' or entity.type == 'tree' then
|
||||
--end
|
||||
entity.destroy()
|
||||
elseif (run_ores_module ~= nil and entity.type == 'resource') then
|
||||
entity.destroy()
|
||||
local wiggle = 50 + perlin.noise((x * 0.005), (y * 0.005), seed_a + 71) * 60
|
||||
local terrain_A = perlin.noise((x * 0.005), (y * 0.005), 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
|
||||
local terrain_D = 10 + perlin.noise((x * 0.001), (y * 0.001), seed_a + 5) * wiggle --terrain layer
|
||||
|
||||
if terrain_sqr < 50 then --Main water areas
|
||||
terrain_A = perlin.noise((x * 0.01), (y * 0.01), 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
|
||||
tile_to_insert = 'water'
|
||||
else
|
||||
if terrain_D >= 20 then
|
||||
tile_to_insert = 'sand-1'
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif terrain_sqr > 70 then
|
||||
wiggle = 100 + perlin.noise((x * 0.01), (y * 0.01), seed_b + 41) * 60
|
||||
local terrain_C = perlin.noise((x * 0.02), (y * 0.02), seed_a + 13) * wiggle --tree layer
|
||||
|
||||
local top_left = area.left_top --make a more direct reference
|
||||
if terrain_D < 20 then
|
||||
if terrain_C < 4 then --we set grass-1 around near forest areas
|
||||
tile_to_insert = 'grass-1'
|
||||
|
||||
--do it only per chunk, cause cheaper than every square, and who care anyway.
|
||||
--local distance_bonus = 200 + math.sqrt(top_left.x*top_left.x + top_left.y*top_left.y) * 0.2
|
||||
|
||||
--for x = 0, 31, 1 do
|
||||
-- for y = 0, 31, 1 do
|
||||
|
||||
--game.print(top_left.x .."-" ..top_left.y .. " to " .. area.right_bottom.x .. "-" .. area.right_bottom.y)
|
||||
|
||||
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
|
||||
local terrain_D = 10 + perlin.noise((x * 0.001), (y * 0.001), global.terrain_seed_A + 5) * wiggle --terrain layer
|
||||
|
||||
--local wiggle = 50 + Simplex.d2((x*0.005),(y*0.005),global.terrain_seed_A + 71) * 60
|
||||
--local terrain_A = Simplex.d2((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
|
||||
--local terrain_D = 10 + Simplex.d2((x*0.001),(y*0.001),global.terrain_seed_A + 5) * wiggle --terrain layer
|
||||
|
||||
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.d2((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(tileswater, {name = "water", position = {x,y}})
|
||||
--table.insert(tileswater, {name = "water", position = {x+1,y}})
|
||||
--table.insert(tileswater, {name = "water", position = {x,y+1}})
|
||||
--table.insert(tileswater, {name = "water", position = {x+1,y+1}})
|
||||
tile_to_insert = 'water'
|
||||
else
|
||||
if terrain_D >= 20 then
|
||||
tile_to_insert = 'sand-1'
|
||||
end
|
||||
end
|
||||
elseif terrain_sqr > 70 then
|
||||
wiggle = 100 + perlin.noise((x * 0.01), (y * 0.01), global.terrain_seed_B + 41) * 60
|
||||
local terrain_C = perlin.noise((x * 0.02), (y * 0.02), global.terrain_seed_A + 13) * wiggle --tree layer
|
||||
|
||||
--wiggle = 100 + Simplex.d2((x*0.01),(y*0.01),global.terrain_seed_B + 41) * 60
|
||||
--local terrain_C = Simplex.d2((x*0.02),(y*0.02),global.terrain_seed_A + 13) * wiggle --tree layer
|
||||
|
||||
--if surface.can_place_entity {name="stone", position={x,y}} then
|
||||
-- surface.create_entity {name="stone", position={x,y}, amount=math.floor(terrain_sqr)}
|
||||
--end
|
||||
|
||||
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
|
||||
|
||||
--if terrain_B > 35 then --we place ores
|
||||
-- local a = 5
|
||||
--
|
||||
-- if terrain_B < 76 then a = math.floor(terrain_B*0.75 + terrain_C*0.5) % 4 + 1 end --if its not super high we place normal ores
|
||||
--
|
||||
-- local res_amount = distance_bonus + terrain_sqr * 0.1
|
||||
-- res_amount = math.floor(res_amount * random_dense[a])
|
||||
--
|
||||
-- if surface.can_place_entity {name=random_ores[a], position={pos_x,pos_y}} then
|
||||
-- surface.create_entity {name=random_ores[a], position={pos_x,pos_y}, amount=res_amount}
|
||||
-- end
|
||||
--end
|
||||
|
||||
--wiggle = 100 + perlin.noise((pos_x*0.02),(pos_y*0.02),global.terrain_seed_B + 71) * 60
|
||||
|
||||
if terrain_D < 20 then
|
||||
if terrain_C < 4 then --we set grass-1 around near forest areas
|
||||
tile_to_insert = 'grass-1'
|
||||
|
||||
if terrain_C < -20 and math.random(1, 3) == 1 then --dense trees
|
||||
local treenum = math.random(3, 7)
|
||||
if surface.can_place_entity {name = tree_to_place[treenum], position = {x, y}} then
|
||||
surface.create_entity {name = tree_to_place[treenum], position = {x, y}}
|
||||
end
|
||||
else
|
||||
if terrain_C < 0 and math.random(1, 7) == 1 then --less dense trees
|
||||
local treenum = math.random(3, 5)
|
||||
if surface.can_place_entity {name = tree_to_place[treenum], position = {x, y}} then
|
||||
surface.create_entity {name = tree_to_place[treenum], position = {x, y}}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if terrain_D < 30 then
|
||||
tile_to_insert = 'sand-1'
|
||||
|
||||
if terrain_C < -20 and math.random(1, 7) == 1 then --dense trees
|
||||
local treenum = math.random(1, 3)
|
||||
if surface.can_place_entity {name = tree_to_place[treenum], position = {x, y}} then
|
||||
surface.create_entity {name = tree_to_place[treenum], position = {x, y}}
|
||||
end
|
||||
elseif terrain_C < 0 and math.random(1, 13) == 1 then --less dense trees
|
||||
local treenum = math.random(1, 2)
|
||||
if surface.can_place_entity {name = tree_to_place[treenum], position = {x, y}} then
|
||||
surface.create_entity {name = tree_to_place[treenum], position = {x, y}}
|
||||
end
|
||||
end
|
||||
else
|
||||
--if terrain_C > 40 and math.random(1,200) == 1 and surface.can_place_entity {name="crude-oil", position={pos_x,pos_y}} then
|
||||
-- surface.create_entity {name="crude-oil", position={pos_x,pos_y}, amount = math.random(20000,60000) +distance_bonus* 2000 }
|
||||
--end
|
||||
tile_to_insert = 'sand-3'
|
||||
end
|
||||
end
|
||||
|
||||
if
|
||||
math.floor(terrain_D) % 5 == 1 and math.random(1, 70) == 1 and
|
||||
surface.can_place_entity {name = 'rock-big', position = {x, y}}
|
||||
then
|
||||
surface.create_entity {name = 'rock-big', position = {x, y}}
|
||||
if terrain_C < -20 and math.random(1, 3) == 1 then --dense trees
|
||||
local treenum = math.random(3, 7)
|
||||
if surface.can_place_entity {name = tree_to_place[treenum], position = pos} then
|
||||
surface.create_entity {name = tree_to_place[treenum], position = pos}
|
||||
end
|
||||
else
|
||||
if terrain_D >= 20 then
|
||||
if terrain_D < 30 then
|
||||
tile_to_insert = 'sand-1'
|
||||
else
|
||||
tile_to_insert = 'sand-3'
|
||||
if terrain_C < 0 and math.random(1, 7) == 1 then --less dense trees
|
||||
local treenum = math.random(3, 5)
|
||||
if surface.can_place_entity {name = tree_to_place[treenum], position = pos} then
|
||||
surface.create_entity {name = tree_to_place[treenum], position = pos}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if terrain_D < 30 then
|
||||
tile_to_insert = 'sand-1'
|
||||
|
||||
--if tile_to_insert == "water" then
|
||||
--table.insert(tileswater, {name = tile_to_insert, position = {x,y}})
|
||||
--else
|
||||
table.insert(tiles, {name = tile_to_insert, position = {x, y}})
|
||||
--end
|
||||
if terrain_C < -20 and math.random(1, 7) == 1 then --dense trees
|
||||
local treenum = math.random(1, 3)
|
||||
if surface.can_place_entity {name = tree_to_place[treenum], position = pos} then
|
||||
surface.create_entity {name = tree_to_place[treenum], position = pos}
|
||||
end
|
||||
elseif terrain_C < 0 and math.random(1, 13) == 1 then --less dense trees
|
||||
local treenum = math.random(1, 2)
|
||||
if surface.can_place_entity {name = tree_to_place[treenum], position = pos} then
|
||||
surface.create_entity {name = tree_to_place[treenum], position = pos}
|
||||
end
|
||||
end
|
||||
else
|
||||
tile_to_insert = 'sand-3'
|
||||
end
|
||||
end
|
||||
|
||||
if
|
||||
math.floor(terrain_D) % 5 == 1 and math.random(1, 70) == 1 and
|
||||
surface.can_place_entity {name = 'rock-big', position = pos}
|
||||
then
|
||||
surface.create_entity {name = 'rock-big', position = pos}
|
||||
end
|
||||
else
|
||||
if terrain_D >= 20 then
|
||||
if terrain_D < 30 then
|
||||
tile_to_insert = 'sand-1'
|
||||
else
|
||||
tile_to_insert = 'sand-3'
|
||||
end
|
||||
end
|
||||
end
|
||||
--game.print("break end")
|
||||
--game.print(lowest .. " to " .. highest)
|
||||
|
||||
surface.set_tiles(tiles, true)
|
||||
--surface.set_tiles(tileswater,true)
|
||||
return tile_to_insert
|
||||
end
|
||||
|
||||
return run_terrain_module
|
||||
|
@ -1,20 +1,25 @@
|
||||
local perlin = require 'map_gen.shared.perlin_noise'
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local function init()
|
||||
global.terrain_seed_A = math.random(10, 10000)
|
||||
global.terrain_seed_B = math.random(10, 10000)
|
||||
end
|
||||
local seed
|
||||
|
||||
Event.on_init(init)
|
||||
Global.register_init(
|
||||
{},
|
||||
function(tbl)
|
||||
tbl.seed = math.random(10, 10000)
|
||||
end,
|
||||
function(tbl)
|
||||
seed = tbl.seed
|
||||
end
|
||||
)
|
||||
|
||||
return function(x, y)
|
||||
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 wiggle = 50 + perlin.noise((x * 0.005), (y * 0.005), seed + 71) * 60
|
||||
local terrain_A = perlin.noise((x * 0.005), (y * 0.005), seed + 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
|
||||
terrain_A = perlin.noise((x * 0.01), (y * 0.01), seed + 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'
|
||||
|
@ -112,8 +112,8 @@ local tiles_per_tick = 32
|
||||
--shape = require "map_gen.shape.pacman"
|
||||
|
||||
--terrain--
|
||||
--require "map_gen.terrain.neko_bridged_rivers"
|
||||
--require "map_gen.terrain.neko_river_overlay"
|
||||
--shape = require "map_gen.terrain.neko_bridged_rivers"
|
||||
--shape = require "map_gen.terrain.neko_river_overlay"
|
||||
|
||||
-- modules that only return max one entity per tile
|
||||
local entity_modules = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user