1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-03-03 14:53:01 +02:00

beach map

This commit is contained in:
grilledham 2018-06-07 16:41:43 +01:00
parent f1c5b89332
commit 091cfc567c
2 changed files with 102 additions and 4 deletions

83
map_gen/presets/beach.lua Normal file
View File

@ -0,0 +1,83 @@
local b = require 'map_gen.shared.builders'
local sand_width = 64
local sand_width_inv = tau / sand_width
local function sand_shape(x, y)
local h = 6 * math.sin(0.9 * x * sand_width_inv)
h = h + 3 * math.sin(0.7 * x * sand_width_inv)
h = h + math.sin(0.33 * x * sand_width_inv)
return y < h
end
sand_shape = b.change_tile(sand_shape, true, 'sand-1')
local value = b.manhattan_value
local ores = {
{b.resource(b.full_shape, 'iron-ore', value(250, 1)), 6},
{b.resource(b.full_shape, 'copper-ore', value(250, 1)), 4},
{b.resource(b.full_shape, 'stone', value(250, 1)), 1},
{b.resource(b.full_shape, 'coal', value(250, 1)), 1}
}
uranium_ore = b.resource(b.full_shape, 'uranium-ore', value(50, 0.25))
local total_weights = {}
local t = 0
for _, v in ipairs(ores) do
t = t + v[2]
table.insert(total_weights, t)
end
local function do_ores(x, y, world)
if (x > 512 or x < -512) and (math.floor(x / 32) % 16 == 0) then
return uranium_ore(x, y, world)
else
local i = math.random(t)
local index = table.binary_search(total_weights, i)
if (index < 0) then
index = bit32.bnot(index)
end
local ore = ores[index][1]
return ore(x, y, world)
end
end
sand_shape = b.apply_entity(sand_shape, do_ores)
local water_width = 64
local water_width_inv = tau / water_width
local function water_shape(x, y)
local h = 6 * math.sin(1.1 * x * water_width_inv)
h = h + 3 * math.sin(0.74 * x * water_width_inv)
h = h + math.sin(0.3 * x * water_width_inv)
return y < h
end
water_shape = b.change_tile(water_shape, true, 'water')
local oil = b.resource(b.full_shape, 'crude-oil', value(500000, 2500))
local function do_oil(x, y, world)
if math.random(16384) == 1 then
local e = oil(x, y, world)
e.always_place = true
return e
end
end
water_shape = b.apply_entity(water_shape, do_oil)
grass = b.tile('grass-1')
local bounds = b.line_x(320)
local map = b.any {b.translate(water_shape, 64, -32), sand_shape, grass}
map = b.choose(bounds, map, b.empty_shape)
return map

View File

@ -8,7 +8,7 @@ in this file and your run_*type*_module(event) function will be called.
local b = require 'map_gen.shared.builders'
local shape = nil
local regen_decoratives = false
local regen_decoratives = true
local tiles_per_tick = 32
--combined--
@ -55,7 +55,7 @@ local tiles_per_tick = 32
--shape = require "map_gen.presets.hearts"
--shape = require "map_gen.presets.women"
--shape = require "map_gen.presets.fractal_balls"
shape = require "map_gen.presets.fruit_loops"
--shape = require "map_gen.presets.fruit_loops"
--shape = require "map_gen.presets.fish_islands"
--shape = require "map_gen.presets.ContraSpiral"
--shape = require "map_gen.presets.cookies"
@ -63,6 +63,7 @@ shape = require "map_gen.presets.fruit_loops"
--shape = require "map_gen.presets.honeycomb"
--shape = require "map_gen.presets.line_and_trees"
--shape = require "map_gen.presets.square_spiral"
shape = require "map_gen.presets.beach"
--shape = require "map_gen.presets.test"
--shapes--
@ -130,6 +131,20 @@ if shape then
['nauvis'] = shape,
}
require('map_gen.shared.generate')({surfaces = surfaces, regen_decoratives = regen_decoratives, tiles_per_tick = tiles_per_tick})
--require ("map_gen.shared.generate_not_threaded")({surfaces = surfaces, regen_decoratives = regen_decoratives})
--require('map_gen.shared.generate')({surfaces = surfaces, regen_decoratives = regen_decoratives, tiles_per_tick = tiles_per_tick})
require ("map_gen.shared.generate_not_threaded")({surfaces = surfaces, regen_decoratives = regen_decoratives})
end
Event.add(
defines.events.on_player_built_tile,
function(event)
if event.item.name == 'landfill' then
local tiles = event.tiles
for i = 1, #tiles do
tiles[i].name = 'sand-1'
end
local surface = game.surfaces[event.surface_index]
surface.set_tiles(tiles)
end
end
)