2018-07-14 14:23:24 +02:00
|
|
|
local b = require 'map_gen.shared.builders'
|
|
|
|
local Event = require 'utils.event'
|
2018-11-06 14:08:33 +02:00
|
|
|
local Random = require 'map_gen.shared.random'
|
2019-01-15 15:27:48 +02:00
|
|
|
local table = require 'utils.table'
|
2019-01-16 22:33:32 +02:00
|
|
|
local RS = require 'map_gen.shared.redmew_surface'
|
|
|
|
local MGSP = require 'resources.map_gen_settings'
|
2019-02-02 02:05:12 +02:00
|
|
|
local RestrictEntities = require 'map_gen.shared.entity_placement_restriction'
|
|
|
|
local Popup = require 'features.gui.popup'
|
2019-01-16 22:33:32 +02:00
|
|
|
|
2019-02-02 07:01:35 +02:00
|
|
|
local config = global.config
|
|
|
|
|
2019-02-02 02:05:12 +02:00
|
|
|
local degrees = require 'utils.math'.degrees
|
2018-07-14 14:23:24 +02:00
|
|
|
|
2019-02-19 15:49:51 +02:00
|
|
|
local groundhog_mode = false -- Toggle to enable groundhogs
|
|
|
|
|
2019-02-01 23:05:20 +02:00
|
|
|
local seed = 210
|
2019-01-16 22:33:32 +02:00
|
|
|
RS.set_map_gen_settings(
|
|
|
|
{
|
|
|
|
MGSP.ore_oil_none,
|
|
|
|
MGSP.cliff_none
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2019-02-02 02:05:12 +02:00
|
|
|
RestrictEntities.add_banned(
|
|
|
|
{
|
|
|
|
'inserter',
|
|
|
|
'long-handed-inserter',
|
|
|
|
'fast-inserter',
|
|
|
|
'filter-inserter',
|
|
|
|
'stack-inserter',
|
|
|
|
'stack-filter-inserter',
|
|
|
|
'electric-mining-drill'
|
|
|
|
}
|
2018-07-14 14:23:24 +02:00
|
|
|
)
|
|
|
|
|
2019-02-02 07:01:35 +02:00
|
|
|
-- config changes
|
|
|
|
config.hail_hydra.enabled = true
|
|
|
|
config.autodeconstruct.enabled = false
|
|
|
|
config.redmew_qol.loaders = false
|
|
|
|
|
2018-07-14 14:23:24 +02:00
|
|
|
Event.add(
|
|
|
|
defines.events.on_research_finished,
|
|
|
|
function(event)
|
|
|
|
local effects = event.research.effects
|
|
|
|
local f = game.forces.player
|
|
|
|
|
2019-02-20 10:17:09 +02:00
|
|
|
for _, e in pairs(effects) do
|
2018-07-14 14:23:24 +02:00
|
|
|
local t = e.type
|
2019-02-01 23:05:20 +02:00
|
|
|
if t == 'stack-inserter-capacity-bonus' then
|
2018-07-14 14:23:24 +02:00
|
|
|
f.inserter_stack_size_bonus = f.inserter_stack_size_bonus + e.modifier
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2019-02-02 02:05:12 +02:00
|
|
|
Event.add(
|
|
|
|
RestrictEntities.events.on_restricted_entity_destroyed,
|
|
|
|
function(event)
|
|
|
|
local p = event.player
|
|
|
|
if not p or not p.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if not event.ghost then
|
|
|
|
Popup.player(p, [[
|
|
|
|
You don't know how to operate this item!
|
|
|
|
|
|
|
|
Advice: Only burner inserters and burner mining drills work in this prehistoric land
|
|
|
|
]], nil, nil, 'prehistoric_entity_warning')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2019-02-02 07:01:35 +02:00
|
|
|
-- Map
|
|
|
|
|
2018-07-14 14:23:24 +02:00
|
|
|
local dino1 = b.picture(require 'map_gen.data.presets.dino1')
|
|
|
|
local dino2 = b.picture(require 'map_gen.data.presets.dino2')
|
|
|
|
local dino4 = b.picture(require 'map_gen.data.presets.dino4')
|
|
|
|
local dino7 = b.picture(require 'map_gen.data.presets.dino7')
|
|
|
|
local dino9 = b.picture(require 'map_gen.data.presets.dino9')
|
|
|
|
local dino13 = b.picture(require 'map_gen.data.presets.dino13')
|
|
|
|
local dino14 = b.picture(require 'map_gen.data.presets.dino14')
|
|
|
|
local dino16 = b.picture(require 'map_gen.data.presets.dino16')
|
|
|
|
|
|
|
|
local dino17 = b.picture(require 'map_gen.data.presets.dino17')
|
|
|
|
local dino18 = b.picture(require 'map_gen.data.presets.dino18')
|
|
|
|
local dino19 = b.picture(require 'map_gen.data.presets.dino19')
|
|
|
|
local dino20 = b.picture(require 'map_gen.data.presets.dino20')
|
|
|
|
local dino21 = b.picture(require 'map_gen.data.presets.dino21')
|
|
|
|
local dino22 = b.picture(require 'map_gen.data.presets.dino22')
|
|
|
|
|
2019-02-20 10:17:09 +02:00
|
|
|
local land_dino_count = 8
|
|
|
|
local ore_dino_start = 9
|
|
|
|
local dinos = {dino1, dino2, dino4, dino7, dino9, dino13, dino14, dino16}
|
2019-02-19 15:49:51 +02:00
|
|
|
|
|
|
|
if groundhog_mode then
|
2019-02-20 10:17:09 +02:00
|
|
|
local groundhog1 = b.picture(b.decompress(require 'map_gen.data.presets.groundhog1'))
|
|
|
|
local groundhog2 = b.picture(b.decompress(require 'map_gen.data.presets.groundhog2'))
|
|
|
|
local groundhog3 = b.picture(b.decompress(require 'map_gen.data.presets.groundhog3'))
|
|
|
|
local groundhog4 = b.picture(b.decompress(require 'map_gen.data.presets.groundhog4'))
|
|
|
|
local groundhog5 = b.picture(b.decompress(require 'map_gen.data.presets.groundhog5'))
|
|
|
|
|
|
|
|
table.add_all(dinos, {groundhog1, groundhog2, groundhog3, groundhog4, groundhog5})
|
2019-02-19 15:49:51 +02:00
|
|
|
|
|
|
|
land_dino_count = 13
|
|
|
|
ore_dino_start = 14
|
|
|
|
end
|
2019-02-20 10:17:09 +02:00
|
|
|
|
|
|
|
table.add_all(dinos, {dino17, dino18, dino19, dino20, dino21, dino22})
|
|
|
|
|
2018-07-14 14:23:24 +02:00
|
|
|
local ore_dino_end = #dinos
|
|
|
|
|
2018-11-06 14:08:33 +02:00
|
|
|
local random = Random.new(seed, seed * 2)
|
2018-07-14 14:23:24 +02:00
|
|
|
|
|
|
|
local land_pattern = {}
|
|
|
|
for r = 1, 50 do
|
|
|
|
local row = {}
|
|
|
|
land_pattern[r] = row
|
|
|
|
for c = 1, 50 do
|
|
|
|
local x = random:next_int(-256, 256)
|
|
|
|
local y = random:next_int(-256, 256)
|
|
|
|
local d = random:next_int(0, 360)
|
|
|
|
local i = random:next_int(1, land_dino_count)
|
|
|
|
|
|
|
|
local shape = dinos[i]
|
|
|
|
shape = b.rotate(shape, degrees(d))
|
|
|
|
shape = b.translate(shape, x, y)
|
|
|
|
|
|
|
|
row[c] = shape
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function value(base, mult, pow)
|
|
|
|
return function(x, y)
|
|
|
|
local d = math.sqrt(x * x + y * y)
|
|
|
|
return base + mult * d ^ pow
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function non_transform(shape)
|
|
|
|
return b.scale(shape, 0.5)
|
|
|
|
end
|
|
|
|
|
2019-02-20 10:25:18 +02:00
|
|
|
local function uranium_transform(shape)
|
|
|
|
return b.scale(shape, 0.25)
|
|
|
|
end
|
|
|
|
|
2018-07-14 14:23:24 +02:00
|
|
|
local function oil_transform(shape)
|
|
|
|
shape = b.scale(shape, 0.25)
|
|
|
|
return b.throttle_world_xy(shape, 1, 4, 1, 4)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function empty_transform()
|
|
|
|
return b.empty_shape
|
|
|
|
end
|
|
|
|
|
|
|
|
local ores = {
|
2019-02-01 23:05:20 +02:00
|
|
|
{transform = non_transform, resource = 'iron-ore', value = value(300, 0.425, 1.1), weight = 16},
|
|
|
|
{transform = non_transform, resource = 'copper-ore', value = value(250, 0.425, 1.1), weight = 10},
|
|
|
|
{transform = non_transform, resource = 'stone', value = value(150, 0.2, 1.05), weight = 6},
|
|
|
|
{transform = non_transform, resource = 'coal', value = value(250, 0.25, 1.075), weight = 16},
|
2019-02-20 10:25:18 +02:00
|
|
|
{transform = uranium_transform, resource = 'uranium-ore', value = value(200, 0.3, 1.025), weight = 3},
|
2019-02-01 23:05:20 +02:00
|
|
|
{transform = oil_transform, resource = 'crude-oil', value = value(50000, 50, 1.025), weight = 10},
|
|
|
|
{transform = empty_transform, weight = 65}
|
2018-07-14 14:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local total_ore_weights = {}
|
|
|
|
local ore_t = 0
|
2019-02-20 10:17:09 +02:00
|
|
|
for _, v in pairs(ores) do
|
2018-07-14 14:23:24 +02:00
|
|
|
ore_t = ore_t + v.weight
|
|
|
|
table.insert(total_ore_weights, ore_t)
|
|
|
|
end
|
|
|
|
|
|
|
|
local ore_pattern = {}
|
|
|
|
|
|
|
|
for r = 1, 50 do
|
|
|
|
local row = {}
|
|
|
|
ore_pattern[r] = row
|
|
|
|
for c = 1, 50 do
|
|
|
|
local x = random:next_int(-32, 32)
|
|
|
|
local y = random:next_int(-32, 32)
|
|
|
|
local d = random:next_int(0, 360)
|
|
|
|
local i = random:next_int(ore_dino_start, ore_dino_end)
|
|
|
|
local shape = dinos[i]
|
|
|
|
|
|
|
|
local ore_data
|
|
|
|
i = random:next_int(1, ore_t)
|
2019-01-16 20:44:55 +02:00
|
|
|
local index = table.binary_search(total_ore_weights, i)
|
2018-07-14 14:23:24 +02:00
|
|
|
if (index < 0) then
|
|
|
|
index = bit32.bnot(index)
|
|
|
|
end
|
|
|
|
ore_data = ores[index]
|
|
|
|
|
|
|
|
shape = ore_data.transform(shape)
|
|
|
|
shape = b.rotate(shape, degrees(d))
|
|
|
|
shape = b.translate(shape, x, y)
|
|
|
|
local ore = b.resource(shape, ore_data.resource, ore_data.value)
|
|
|
|
|
|
|
|
row[c] = ore
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local map = b.grid_pattern_full_overlap(land_pattern, 50, 50, 640, 640)
|
|
|
|
map = b.change_tile(map, false, 'deepwater')
|
|
|
|
map = b.fish(map, 0.0025)
|
|
|
|
|
2019-01-16 20:44:55 +02:00
|
|
|
ores = b.grid_pattern_full_overlap(ore_pattern, 50, 50, 128, 128)
|
2018-07-14 14:23:24 +02:00
|
|
|
map = b.apply_entity(map, ores)
|
|
|
|
|
|
|
|
map = b.translate(map, -50, -160)
|
|
|
|
|
|
|
|
return map
|