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

connected dots updates

This commit is contained in:
grilledham 2018-08-28 13:31:23 +01:00
parent f1de5536c4
commit fcefd2d17a
5 changed files with 299 additions and 48 deletions

View File

@ -1,4 +1,4 @@
_DEBUG = false
_DEBUG = true
MARKET_ITEM = 'coin'
global.scenario = {}

View File

@ -0,0 +1,39 @@
local Event = require 'utils.event'
global.allowed_landfill_tiles = {}
Event.add(
defines.events.on_player_built_tile,
function(event)
local item_name = event.item.name
if item_name ~= 'landfill' then
return
end
local allowed = global.allowed_landfill_tiles
local new_tiles = {}
for _, tile in ipairs(event.tiles) do
local name = tile.old_tile.name
if not allowed[name] then
tile.name = name
table.insert(new_tiles, tile)
end
end
local count = #new_tiles
if count == 0 then
return
end
local surface = game.surfaces[event.surface_index]
surface.set_tiles(new_tiles)
local player = game.players[event.player_index]
player.insert {name = item_name, count = count}
end
)
return function(allowed_set)
global.allowed_landfill_tiles = allowed_set
end

View File

@ -1,92 +1,299 @@
local b = require "map_gen.shared.builders"
local b = require 'map_gen.shared.builders'
local Random = require 'map_gen.shared.random'
local function no_resources(x, y, world, tile)
for _, e in ipairs(world.surface.find_entities_filtered({type = "resource", area = {{world.x, world.y}, {world.x + 1, world.y + 1}}})) do
e.destroy()
end
return tile
end
local ore_seed1 = 11000
local ore_seed2 = ore_seed1 * 2
local ore_blocks = 100
local ore_block_size = 32
local function less_resources(x, y, world, tile)
for _, e in ipairs(world.surface.find_entities_filtered({type = "resource", area = {{world.x, world.y}, {world.x + 1, world.y + 1}}})) do
if e.name == "crude-oil" then
-- e.amount = .995 * e.amount
else
e.amount = 0.33 * e.amount
end
end
return tile
end
local random_ore = Random.new(ore_seed1, ore_seed2)
local function no_enemies(x, y, world, tile)
for _, e in ipairs(world.surface.find_entities_filtered({force = "enemy", position = {world.x, world.y}})) do
for _, e in ipairs(world.surface.find_entities_filtered({force = 'enemy', position = {world.x, world.y}})) do
e.destroy()
end
return tile
end
local small_ore_patch = b.circle(12)
local medium_ore_patch = b.circle(24)
local big_ore_patch = b.subtract(b.circle(36), b.circle(16))
local ore_patches = {
{shape = small_ore_patch, weight = 3},
{shape = medium_ore_patch, weight = 2},
{shape = big_ore_patch, weight = 1}
}
local total_ore_patch_weights = {}
local square_t = 0
for _, v in ipairs(ore_patches) do
square_t = square_t + v.weight
table.insert(total_ore_patch_weights, square_t)
end
value = b.exponential_value
local function non_transform(shape)
return shape
end
local function uranium_transform(shape)
return b.scale(shape, 0.5)
end
local function oil_transform(shape)
shape = b.scale(shape, 0.5)
return b.throttle_world_xy(shape, 1, 4, 1, 4)
end
local function empty_transform()
return b.empty_shape
end
local ores = {
{transform = non_transform, resource = 'iron-ore', value = value(250, 0.4, 1.1), weight = 16},
{transform = non_transform, resource = 'copper-ore', value = value(200, 0.4, 1.1), weight = 10},
{transform = non_transform, resource = 'stone', value = value(125, 0.2, 1.05), weight = 3},
{transform = non_transform, resource = 'coal', value = value(200, 0.3, 1.075), weight = 5},
{transform = uranium_transform, resource = 'uranium-ore', value = value(100, 0.3, 1.025), weight = 3},
{transform = oil_transform, resource = 'crude-oil', value = value(100000, 50, 1.05), weight = 6},
{transform = empty_transform, weight = 300}
}
local total_ore_weights = {}
local ore_t = 0
for _, v in ipairs(ores) do
ore_t = ore_t + v.weight
table.insert(total_ore_weights, ore_t)
end
local function do_resources()
local pattern = {}
for r = 1, ore_blocks do
local row = {}
pattern[r] = row
for c = 1, ore_blocks do
local shape
local i = random_ore:next_int(1, square_t)
local index = table.binary_search(total_ore_patch_weights, i)
if (index < 0) then
index = bit32.bnot(index)
end
shape = ore_patches[index].shape
local ore_data
i = random_ore:next_int(1, ore_t)
index = table.binary_search(total_ore_weights, i)
if (index < 0) then
index = bit32.bnot(index)
end
ore_data = ores[index]
shape = ore_data.transform(shape)
local ore = b.resource(shape, ore_data.resource, ore_data.value)
row[c] = ore
end
end
local ore_shape = b.grid_pattern_full_overlap(pattern, ore_blocks, ore_blocks, ore_block_size, ore_block_size)
return ore_shape
end
local map_ores = do_resources()
local worm_names = {
'small-worm-turret',
'medium-worm-turret',
'big-worm-turret'
}
local max_worm_chance = 1 / 128
local worm_chance_factor = 1 / (192 * 512)
local function worms(_, _, world)
local wx, wy = world.x, world.y
local d = math.sqrt(wx * wx + wy * wy)
local worm_chance = d - 160
if worm_chance > 0 then
worm_chance = worm_chance * worm_chance_factor
worm_chance = math.min(worm_chance, max_worm_chance)
if math.random() < worm_chance then
if d < 256 then
return {name = 'small-worm-turret'}
else
local max_lvl
local min_lvl
if d < 512 then
max_lvl = 2
min_lvl = 1
else
max_lvl = 3
min_lvl = 2
end
local lvl = math.random() ^ (512 / d) * max_lvl
lvl = math.ceil(lvl)
lvl = math.clamp(lvl, min_lvl, 3)
return {name = worm_names[lvl]}
end
end
end
end
local h_track = {
b.line_x(2),
b.translate(b.line_x(2), 0, -3),
b.translate(b.line_x(2), 0, 3),
b.rectangle(2, 10)
}
h_track = b.any(h_track)
h_track = b.single_x_pattern(h_track, 15)
h_track = b.change_tile(h_track, true, 'water')
local v_track = {
b.line_y(2),
b.translate(b.line_y(2), -3, 0),
b.translate(b.line_y(2), 3, 0),
b.rectangle(10, 2)
}
v_track = b.any(v_track)
v_track = b.single_y_pattern(v_track, 15)
v_track = b.change_tile(v_track, true, 'water')
local d_track = {
b.line_x(2),
b.translate(b.line_x(3), 0, -3),
b.translate(b.line_x(3), 0, 3),
b.rectangle(1, 10)
}
d_track = b.any(d_track)
d_track = b.single_x_pattern(d_track, 15)
d_track = b.change_tile(d_track, true, 'water')
local small_dot = b.circle(96)
local mediumn_dot = b.circle(128)
local big_dot = b.circle(160)
local arms = b.path(48)
arms = b.change_tile(arms, true, "water")
local h_arm = b.line_x(48)
h_arm = b.change_tile(h_arm, true, 'deepwater')
h_arm = b.any {h_track, h_arm}
local arms2 = b.rotate(arms, degrees(45))
local v_arm = b.line_y(48)
v_arm = b.change_tile(v_arm, true, 'deepwater')
v_arm = b.any {v_track, v_arm}
local shape = b.any{b.translate(arms2, 480, 0), b.translate(arms2, -480, 0), mediumn_dot, arms}
shape = b.apply_effect(shape, no_resources)
--shape = b.apply_effect(shape, less_resources)
local arms = b.any {h_arm, v_arm}
local d1_arm = b.line_x(48)
d1_arm = b.change_tile(d1_arm, true, 'deepwater')
d1_arm = b.any {d_track, d1_arm}
d1_arm = b.rotate(d1_arm, degrees(45))
local d2_arm = b.line_x(48)
d2_arm = b.change_tile(d2_arm, true, 'deepwater')
d2_arm = b.any {d_track, d2_arm}
d2_arm = b.rotate(d2_arm, degrees(-45))
local arms2 = b.any {d1_arm, d2_arm}
local shape = b.any {b.translate(arms2, 480, 0), b.translate(arms2, -480, 0), mediumn_dot, arms}
shape = b.apply_effect(shape, no_enemies)
local shape2 = b.all{big_dot, b.invert(small_dot)}
shape2 = b.choose(big_dot, shape2, b.any{arms, b.rotate(arms, degrees(45))})
--shape2 = b.apply_effect(shape2, less_resources)
local start = b.apply_effect(mediumn_dot, no_resources)
local shape2 = b.all {big_dot, b.invert(small_dot)}
shape2 = b.choose(big_dot, shape2, b.any {arms, arms2})
local iron = b.circle(16)
iron = b.translate(iron, 0, -96)
--iron = b.rotate(iron, degrees(0))
iron = b.resource(iron, "iron-ore", function(x, y) return 700 end)
iron =
b.resource(
iron,
'iron-ore',
function(x, y)
return 700
end
)
local copper = b.circle(12)
copper = b.translate(copper, 0, -96)
copper = b.rotate(copper, degrees(72))
copper = b.resource(copper, "copper-ore", function(x, y) return 600 end)
copper =
b.resource(
copper,
'copper-ore',
function(x, y)
return 600
end
)
local stone = b.circle(8)
stone = b.translate(stone, 0, -96)
stone = b.rotate(stone, degrees(144))
stone = b.resource(stone, "stone", function(x, y) return 1500 end)
stone =
b.resource(
stone,
'stone',
function(x, y)
return 1500
end
)
local coal = b.circle(10)
coal = b.translate(coal, 0, -96)
coal = b.rotate(coal, degrees(216))
coal = b.resource(coal, "coal", function(x, y) return 850 end)
coal =
b.resource(
coal,
'coal',
function(x, y)
return 850
end
)
local oil = b.circle(5)
oil = b.throttle_xy(oil, 1, 3, 1, 3)
oil = b.translate(oil, 0, -96)
oil = b.rotate(oil, degrees(288))
oil = b.resource(oil, "crude-oil", function(x, y) return 60000 end)
oil =
b.resource(
oil,
'crude-oil',
function(x, y)
return 60000
end
)
start = b.apply_entity(mediumn_dot, b.any{iron, copper, stone, coal, oil})
start = b.apply_entity(mediumn_dot, b.any {iron, copper, stone, coal, oil})
start = b.apply_effect(start, no_resources)
local pattern = {
{shape, b.empty_shape},
{b.empty_shape, shape}
}
local shape_islands = b.grid_pattern(pattern, 2, 2, 480, 480)
local pattern =
{
{shape, shape2},
{shape2, shape}
}
local pattern2 = {
{b.empty_shape, shape2},
{shape2, b.empty_shape}
}
local shape2_islands = b.grid_pattern(pattern2, 2, 2, 480, 480)
shape2_islands = b.apply_entity(shape2_islands, map_ores)
shape2_islands = b.apply_entity(shape2_islands, worms)
local map = b.if_else(shape_islands, shape2_islands)
local map = b.grid_pattern(pattern, 2, 2, 480, 480)
map = b.choose(mediumn_dot, start, map)
map = b.change_map_gen_collision_tile(map, "water-tile", "grass-1")
map = b.change_map_gen_collision_tile(map, 'water-tile', 'grass-1')
map = b.fish(map, 0.0025)
return map

View File

@ -6,6 +6,8 @@ function degrees(angle)
return angle * deg_to_rad
end
local Builders = {}
local function add_entity(tile, entity)
if type(tile) == 'table' then
if tile.entities then
@ -23,7 +25,9 @@ local function add_entity(tile, entity)
return tile
end
local Builders = {}
function Builders.add_entity(tile, entity)
return add_entity(tile, entity)
end
-- shape builders
function Builders.empty_shape()

View File

@ -128,6 +128,7 @@ miscs = {}
--table.insert(miscs, require("map_gen.misc.rail_grid")) -- used for map_gen.presets.UK
--require ('map_gen.misc.change_landfill_tile')('sand-1')
--require ('map_gen.misc.danger_ore_banned_entities')
--require ('map_gen.misc.restrict_landfill_tile')({['water'] = true})
if #entity_modules > 0 then
shape = shape or b.full_shape