mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
danger ore map
This commit is contained in:
parent
98acba7e6f
commit
39d5134611
@ -9,7 +9,7 @@ require 'nuke_control'
|
||||
require 'follow'
|
||||
require 'autodeconstruct'
|
||||
require 'corpse_util'
|
||||
--require 'infinite_storage_chest'
|
||||
require 'infinite_storage_chest'
|
||||
require 'fish_market'
|
||||
require 'reactor_meltdown'
|
||||
require 'map_layout'
|
||||
|
@ -22,9 +22,7 @@ local function built_entity(event)
|
||||
return
|
||||
end
|
||||
|
||||
local pos = entity.position
|
||||
|
||||
chests[pos.x .. ',' .. pos.y] = {entity = entity, storage = {}}
|
||||
chests[entity.unit_number] = {entity = entity, storage = {}}
|
||||
end
|
||||
|
||||
local function mined_entity(event)
|
||||
@ -33,9 +31,7 @@ local function mined_entity(event)
|
||||
return
|
||||
end
|
||||
|
||||
local pos = entity.position
|
||||
|
||||
chests[pos.x .. ',' .. pos.y] = nil
|
||||
chests[entity.unit_number] = nil
|
||||
end
|
||||
|
||||
local function get_stack_size(name)
|
||||
@ -187,8 +183,7 @@ local function gui_opened(event)
|
||||
return
|
||||
end
|
||||
|
||||
local pos = entity.position
|
||||
local chest = chests[pos.x .. ',' .. pos.y]
|
||||
local chest = chests[entity.unit_number]
|
||||
|
||||
if not chest then
|
||||
return
|
||||
@ -214,6 +209,26 @@ Event.add(defines.events.on_robot_mined_entity, mined_entity)
|
||||
Event.add(defines.events.on_tick, tick)
|
||||
Event.add(defines.events.on_gui_opened, gui_opened)
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_died,
|
||||
function(event)
|
||||
local player = game.players[event.player_index or 0]
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local element = player.gui.center
|
||||
|
||||
if element and element.valid then
|
||||
element = element[chest_gui_frame_name]
|
||||
if element and element.valid then
|
||||
element.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Gui.on_custom_close(
|
||||
chest_gui_frame_name,
|
||||
function(event)
|
||||
@ -222,4 +237,4 @@ Gui.on_custom_close(
|
||||
)
|
||||
|
||||
local market_items = require 'resources.market_items'
|
||||
table.insert(market_items, {price = {{'raw-fish', 100}}, offer = {type = 'give-item', item = 'infinity-chest'}})
|
||||
table.insert(market_items, {price = {{'coin', 100}}, offer = {type = 'give-item', item = 'infinity-chest'}})
|
||||
|
55
map_gen/misc/danger_ore_banned_entities.lua
Normal file
55
map_gen/misc/danger_ore_banned_entities.lua
Normal file
@ -0,0 +1,55 @@
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local allowed_entites = {
|
||||
['transport-belt'] = true,
|
||||
['fast-transport-belt'] = true,
|
||||
['express-transport-belt'] = true,
|
||||
['underground-belt'] = true,
|
||||
['fast-underground-belt'] = true,
|
||||
['express-underground-belt'] = true,
|
||||
['small-electric-pole'] = true,
|
||||
['medium-electric-pole'] = true,
|
||||
['big-electric-pole'] = true,
|
||||
['substation'] = true,
|
||||
['electric-mining-drill'] = true,
|
||||
['burner-mining-drill'] = true,
|
||||
['pumpjack'] = true,
|
||||
}
|
||||
|
||||
Event.add(
|
||||
defines.events.on_built_entity,
|
||||
function(event)
|
||||
local entity = event.created_entity
|
||||
if not entity or not entity.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local name = entity.name
|
||||
local ghost = false
|
||||
if name == 'entity-ghost' then
|
||||
name = entity.ghost_name
|
||||
ghost = true
|
||||
end
|
||||
|
||||
if allowed_entites[name] then
|
||||
return
|
||||
end
|
||||
|
||||
local surface = entity.surface
|
||||
local count = surface.count_entities_filtered {area = entity.bounding_box, type = 'resource', limit = 1}
|
||||
|
||||
if count == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local p = game.players[event.player_index]
|
||||
if not p or not p.valid then
|
||||
return
|
||||
end
|
||||
|
||||
entity.destroy()
|
||||
if not ghost then
|
||||
p.insert {name = name}
|
||||
end
|
||||
end
|
||||
)
|
156
map_gen/presets/danger_ores.lua
Normal file
156
map_gen/presets/danger_ores.lua
Normal file
@ -0,0 +1,156 @@
|
||||
local b = require 'map_gen.shared.builders'
|
||||
local Perlin = require 'map_gen.shared.perlin_noise'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local oil_seed
|
||||
local uranium_seed
|
||||
local density_seed
|
||||
|
||||
local oil_scale = 1 / 64
|
||||
local oil_threshold = 0.6
|
||||
|
||||
local uranium_scale = 1 / 128
|
||||
local uranium_threshold = 0.65
|
||||
|
||||
local density_scale = 1 / 48
|
||||
local density_threshold = 0.5
|
||||
local density_multiplier = 50
|
||||
|
||||
Global.register_init(
|
||||
{},
|
||||
function(tbl)
|
||||
tbl.seed = game.surfaces[1].map_gen_settings.seed
|
||||
end,
|
||||
function(tbl)
|
||||
local seed = tbl.seed
|
||||
oil_seed = seed
|
||||
uranium_seed = seed * 2
|
||||
density_seed = seed * 3
|
||||
end
|
||||
)
|
||||
|
||||
local value = b.euclidean_value
|
||||
|
||||
local oil_shape = b.throttle_world_xy(b.full_shape, 1, 4, 1, 4)
|
||||
local oil_resource = b.resource(oil_shape, 'crude-oil', value(100000, 50))
|
||||
|
||||
local uranium_resource = b.resource(b.full_shape, 'uranium-ore', value(200, 1))
|
||||
|
||||
local ores = {
|
||||
{resource = b.resource(b.full_shape, 'iron-ore', value(25, 0.5)), weight = 6},
|
||||
{resource = b.resource(b.full_shape, 'copper-ore', value(25, 0.5)), weight = 4},
|
||||
{resource = b.resource(b.full_shape, 'stone', value(25, 0.5)), weight = 1},
|
||||
{resource = b.resource(b.full_shape, 'coal', value(25, 0.5)), weight = 2}
|
||||
}
|
||||
|
||||
local weighted_ores = b.prepare_weighted_array(ores)
|
||||
local total_ores = weighted_ores.total
|
||||
|
||||
local spawn_zone = b.circle(64)
|
||||
|
||||
local ore_circle = b.circle(68)
|
||||
local start_ores = {
|
||||
b.resource(ore_circle, 'iron-ore', value(500, 0)),
|
||||
b.resource(ore_circle, 'copper-ore', value(250, 0)),
|
||||
b.resource(ore_circle, 'coal', value(500, 0)),
|
||||
b.resource(ore_circle, 'stone', value(250, 0))
|
||||
}
|
||||
|
||||
local start_segment = b.segment_pattern(start_ores)
|
||||
|
||||
local function ore(x, y, world)
|
||||
if spawn_zone(x, y) then
|
||||
return
|
||||
end
|
||||
|
||||
local start_ore = start_segment(x, y, world)
|
||||
if start_ore then
|
||||
return start_ore
|
||||
end
|
||||
|
||||
local oil_x, oil_y = x * oil_scale, y * oil_scale
|
||||
|
||||
local oil_noise = Perlin.noise(oil_x, oil_y, oil_seed)
|
||||
if oil_noise > oil_threshold then
|
||||
return oil_resource(x, y, world)
|
||||
end
|
||||
|
||||
local uranium_x, uranium_y = x * uranium_scale, y * uranium_scale
|
||||
local uranium_noise = Perlin.noise(uranium_x, uranium_y, uranium_seed)
|
||||
if uranium_noise > uranium_threshold then
|
||||
return uranium_resource(x, y, world)
|
||||
end
|
||||
|
||||
local i = math.random() * total_ores
|
||||
local index = table.binary_search(weighted_ores, i)
|
||||
if (index < 0) then
|
||||
index = bit32.bnot(index)
|
||||
end
|
||||
|
||||
local resource = ores[index].resource
|
||||
|
||||
local entity = resource(x, y, world)
|
||||
local density_x, density_y = x * density_scale, y * density_scale
|
||||
local density_noise = Perlin.noise(density_x, density_y, density_seed)
|
||||
|
||||
if density_noise > density_threshold then
|
||||
entity.amount = entity.amount * density_multiplier
|
||||
end
|
||||
entity.enable_tree_removal = false
|
||||
return entity
|
||||
end
|
||||
|
||||
local worms = {
|
||||
'small-worm-turret',
|
||||
'medium-worm-turret',
|
||||
'big-worm-turret'
|
||||
}
|
||||
|
||||
local max_worm_chance = 1 / 384
|
||||
local worm_chance_factor = 1 / (384 * 512)
|
||||
|
||||
local function enemy(_, _, world)
|
||||
local wx, wy = world.x, world.y
|
||||
local d = math.sqrt(wx * wx + wy * wy)
|
||||
|
||||
local worm_chance = d - 128
|
||||
|
||||
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 < 384 then
|
||||
return {name = 'small-worm-turret'}
|
||||
else
|
||||
local max_lvl
|
||||
local min_lvl
|
||||
if d < 768 then
|
||||
max_lvl = 2
|
||||
min_lvl = 1
|
||||
else
|
||||
max_lvl = 3
|
||||
min_lvl = 2
|
||||
end
|
||||
local lvl = math.random() ^ (768 / d) * max_lvl
|
||||
lvl = math.ceil(lvl)
|
||||
lvl = math.clamp(lvl, min_lvl, 3)
|
||||
return {name = worms[lvl]}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local water = b.circle(8)
|
||||
water = b.change_tile(water, true, 'water')
|
||||
water = b.any {b.rectangle(16, 4), b.rectangle(4, 16), water}
|
||||
|
||||
local start = b.if_else(water, b.full_shape)
|
||||
start = b.change_map_gen_collision_tile(start, 'water-tile', 'grass-1')
|
||||
|
||||
local map = b.choose(ore_circle, start, b.full_shape)
|
||||
|
||||
map = b.apply_entity(map, ore)
|
||||
map = b.apply_entity(map, enemy)
|
||||
|
||||
return map
|
@ -1294,4 +1294,18 @@ function Builders.euclidean_value(base, mult)
|
||||
end
|
||||
end
|
||||
|
||||
function Builders.prepare_weighted_array(array)
|
||||
local total = 0
|
||||
local weights = {}
|
||||
|
||||
for _, v in ipairs(array) do
|
||||
total = total + v.weight
|
||||
table.insert(weights, total)
|
||||
end
|
||||
|
||||
weights.total = total
|
||||
|
||||
return weights
|
||||
end
|
||||
|
||||
return Builders
|
||||
|
@ -72,6 +72,7 @@ local tiles_per_tick = 32
|
||||
--shape = require "map_gen.presets.crash_site"
|
||||
--shape = require "map_gen.presets.dino_island"
|
||||
--shape = require "map_gen.presets.toxic_jungle"
|
||||
shape = require "map_gen.presets.danger_ores"
|
||||
--shape = require "map_gen.presets.test"
|
||||
|
||||
--shapes--
|
||||
@ -121,6 +122,7 @@ miscs = {}
|
||||
--require "map_gen.misc.rusky_pvp"
|
||||
--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')
|
||||
|
||||
if #entity_modules > 0 then
|
||||
shape = shape or b.full_shape
|
||||
@ -141,6 +143,6 @@ 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user