1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/map_gen/presets/crash_site.lua

760 lines
25 KiB
Lua
Raw Normal View History

2018-07-20 23:01:34 +02:00
require 'map_gen.presets.crash_site.blueprint_extractor'
require 'map_gen.presets.crash_site.entity_died_events'
require 'map_gen.presets.crash_site.weapon_balance'
2019-01-17 01:55:19 +02:00
require 'map_gen.presets.crash_site.commands'
2018-07-14 11:33:06 +02:00
2018-07-13 12:47:38 +02:00
local b = require 'map_gen.shared.builders'
2018-07-20 23:01:34 +02:00
local Global = require('utils.global')
2018-07-13 12:47:38 +02:00
local Random = require 'map_gen.shared.random'
local OutpostBuilder = require 'map_gen.presets.crash_site.outpost_builder'
local math = require 'utils.math'
2018-11-06 14:08:33 +02:00
local degrees = math.degrees
2018-11-11 09:20:07 +02:00
local ScenarioInfo = require 'features.gui.info'
local table = require 'utils.table'
local RS = require 'map_gen.shared.redmew_surface'
local MGSP = require 'resources.map_gen_settings'
RS.set_map_gen_settings(
{
MGSP.grass_only,
{
terrain_segmentation = 'normal',
water = 'normal'
},
MGSP.starting_area_very_low,
MGSP.ore_oil_none,
MGSP.enemy_none,
MGSP.cliff_none
}
)
2018-11-11 04:35:58 +02:00
-- Comment out this block if you're getting scenario info from another source.
ScenarioInfo.set_map_name('Crashsite')
ScenarioInfo.set_map_description('Capture outposts and defend against the biters.')
ScenarioInfo.add_map_extra_info(
2019-01-10 16:34:28 +02:00
'- Outposts have enemy turrets defending them.\n- Outposts have loot and provide a steady stream of resources.\n- Outpost markets with different resources and at prices.\n- Capturing outposts increases evolution.\n- Reduced damage by all player weapons, turrets, and ammo.\n- Biters have more health and deal more damage.\n- Biters and spitters spawn on death of entities.'
)
2018-07-13 12:47:38 +02:00
2019-01-13 14:34:37 +02:00
global.config.market.enabled = false
2019-01-11 17:31:32 +02:00
-- leave seeds nil to have them filled in based on teh map seed.
local outpost_seed = nil --91000
local ore_seed = nil --92000
2018-07-20 23:01:34 +02:00
2018-07-24 01:45:38 +02:00
local small_iron_plate_factory = require 'map_gen.presets.crash_site.outpost_data.small_iron_plate_factory'
local medium_iron_plate_factory = require 'map_gen.presets.crash_site.outpost_data.medium_iron_plate_factory'
local big_iron_plate_factory = require 'map_gen.presets.crash_site.outpost_data.big_iron_plate_factory'
2018-07-27 01:36:25 +02:00
local small_copper_plate_factory = require 'map_gen.presets.crash_site.outpost_data.small_copper_plate_factory'
local medium_copper_plate_factory = require 'map_gen.presets.crash_site.outpost_data.medium_copper_plate_factory'
local big_copper_plate_factory = require 'map_gen.presets.crash_site.outpost_data.big_copper_plate_factory'
2018-08-01 17:35:48 +02:00
local small_stone_factory = require 'map_gen.presets.crash_site.outpost_data.small_stone_factory'
local medium_stone_factory = require 'map_gen.presets.crash_site.outpost_data.medium_stone_factory'
local big_stone_factory = require 'map_gen.presets.crash_site.outpost_data.big_stone_factory'
2018-07-27 01:36:25 +02:00
local small_gear_factory = require 'map_gen.presets.crash_site.outpost_data.small_gear_factory'
local medium_gear_factory = require 'map_gen.presets.crash_site.outpost_data.medium_gear_factory'
local big_gear_factory = require 'map_gen.presets.crash_site.outpost_data.big_gear_factory'
2018-07-24 01:45:38 +02:00
local small_circuit_factory = require 'map_gen.presets.crash_site.outpost_data.small_circuit_factory'
local medium_circuit_factory = require 'map_gen.presets.crash_site.outpost_data.medium_circuit_factory'
local big_circuit_factory = require 'map_gen.presets.crash_site.outpost_data.big_circuit_factory'
2018-07-27 01:36:25 +02:00
local small_ammo_factory = require 'map_gen.presets.crash_site.outpost_data.small_ammo_factory'
local medium_ammo_factory = require 'map_gen.presets.crash_site.outpost_data.medium_ammo_factory'
local big_ammo_factory = require 'map_gen.presets.crash_site.outpost_data.big_ammo_factory'
2018-08-01 17:35:48 +02:00
local small_weapon_factory = require 'map_gen.presets.crash_site.outpost_data.small_weapon_factory'
local medium_weapon_factory = require 'map_gen.presets.crash_site.outpost_data.medium_weapon_factory'
local big_weapon_factory = require 'map_gen.presets.crash_site.outpost_data.big_weapon_factory'
2018-07-27 01:36:25 +02:00
local small_science_factory = require 'map_gen.presets.crash_site.outpost_data.small_science_factory'
local medium_science_factory = require 'map_gen.presets.crash_site.outpost_data.medium_science_factory'
local big_science_factory = require 'map_gen.presets.crash_site.outpost_data.big_science_factory'
2018-07-28 14:04:14 +02:00
local small_oil_refinery = require 'map_gen.presets.crash_site.outpost_data.small_oil_refinery'
local medium_oil_refinery = require 'map_gen.presets.crash_site.outpost_data.medium_oil_refinery'
local big_oil_refinery = require 'map_gen.presets.crash_site.outpost_data.big_oil_refinery'
local small_chemical_factory = require 'map_gen.presets.crash_site.outpost_data.small_chemical_factory'
local medium_chemical_factory = require 'map_gen.presets.crash_site.outpost_data.medium_chemical_factory'
local big_chemical_factory = require 'map_gen.presets.crash_site.outpost_data.big_chemical_factory'
2018-08-04 00:26:44 +02:00
local small_power_factory = require 'map_gen.presets.crash_site.outpost_data.small_power_factory'
2018-08-01 17:35:48 +02:00
local medium_power_factory = require 'map_gen.presets.crash_site.outpost_data.medium_power_factory'
2018-08-04 00:26:44 +02:00
local big_power_factory = require 'map_gen.presets.crash_site.outpost_data.big_power_factory'
2018-08-02 18:10:47 +02:00
local thin_walls = require 'map_gen.presets.crash_site.outpost_data.thin_walls'
2018-07-28 14:04:14 +02:00
2019-01-10 16:34:28 +02:00
local mini_t1_ammo_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t1_ammo_factory'
local mini_t2_ammo_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t2_ammo_factory'
local mini_t1_weapon_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t1_weapon_factory'
local mini_t2_weapon_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t2_weapon_factory'
local mini_t2_logistics_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t2_logistics_factory'
local mini_t3_logistics_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t3_logistics_factory'
local mini_t1_science_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t1_science_factory'
local mini_t2_science_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t2_science_factory'
local mini_t3_science_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t3_science_factory'
local mini_t1_module_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t1_module_factory'
local mini_t2_module_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t2_module_factory'
local mini_t3_module_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t3_module_factory'
local mini_t1_robotics_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t1_robotics_factory'
local mini_t1_production_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t1_production_factory'
local mini_t2_energy_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t2_energy_factory'
local mini_t1_train_factory = require 'map_gen.presets.crash_site.outpost_data.mini_t1_train_factory'
local function init()
local outpost_random = Random.new(outpost_seed, outpost_seed * 2)
2018-07-28 14:04:14 +02:00
local outpost_builder = OutpostBuilder.new(outpost_random)
2018-07-28 14:04:14 +02:00
local stage1a = {
small_iron_plate_factory,
small_gear_factory,
small_copper_plate_factory,
small_stone_factory
}
2018-07-28 14:04:14 +02:00
local stage1a_pos = {
{4, 5},
{5, 4},
{5, 6},
{6, 5}
}
2018-07-28 14:04:14 +02:00
local stage1b = {
small_circuit_factory,
small_science_factory,
small_oil_refinery,
small_chemical_factory,
small_power_factory
}
2018-07-28 14:04:14 +02:00
local stage1b_pos = {
{4, 4},
{4, 6},
{6, 4},
{6, 6},
{3, 5},
{5, 3},
{5, 7},
{7, 5}
}
2018-08-02 18:10:47 +02:00
local stage2 = {
medium_iron_plate_factory,
medium_copper_plate_factory,
medium_stone_factory,
medium_gear_factory,
medium_circuit_factory,
small_ammo_factory,
small_ammo_factory,
small_weapon_factory,
small_science_factory,
medium_science_factory,
medium_oil_refinery,
medium_chemical_factory,
medium_power_factory
}
2018-07-28 14:04:14 +02:00
local stage2_pos = {
{2, 5},
{5, 2},
{5, 8},
{8, 5},
{3, 3},
{3, 4},
{3, 6},
{3, 7},
{4, 3},
{4, 7},
{6, 3},
{6, 7},
{7, 3},
{7, 4},
{7, 6},
{7, 7}
}
2018-07-28 14:04:14 +02:00
local stage3 = {
big_iron_plate_factory,
big_copper_plate_factory,
big_stone_factory,
big_gear_factory,
big_circuit_factory,
medium_ammo_factory,
medium_ammo_factory,
medium_weapon_factory,
medium_science_factory,
big_science_factory,
big_oil_refinery,
big_chemical_factory,
big_power_factory
}
2018-07-28 14:04:14 +02:00
local stage4 = {
big_iron_plate_factory,
big_copper_plate_factory,
big_gear_factory,
big_circuit_factory,
big_ammo_factory,
big_ammo_factory,
big_ammo_factory,
big_weapon_factory,
big_weapon_factory,
big_weapon_factory,
big_science_factory,
big_oil_refinery,
big_chemical_factory
}
2018-07-28 14:04:14 +02:00
2019-01-10 16:34:28 +02:00
local mini1 = {
mini_t1_ammo_factory,
mini_t1_ammo_factory,
mini_t1_weapon_factory,
mini_t1_weapon_factory,
mini_t2_logistics_factory,
mini_t2_logistics_factory,
mini_t1_science_factory,
mini_t1_science_factory,
mini_t1_module_factory,
mini_t1_production_factory,
mini_t2_energy_factory,
mini_t1_train_factory
}
local mini2 = {
mini_t2_ammo_factory,
mini_t2_ammo_factory,
mini_t2_weapon_factory,
mini_t2_weapon_factory,
mini_t3_logistics_factory,
mini_t3_logistics_factory,
mini_t2_science_factory,
mini_t2_science_factory,
mini_t2_module_factory,
mini_t1_robotics_factory,
mini_t2_energy_factory,
mini_t1_train_factory
}
local mini3 = {
mini_t2_ammo_factory,
mini_t2_ammo_factory,
mini_t2_weapon_factory,
mini_t2_weapon_factory,
mini_t3_science_factory,
mini_t3_module_factory,
mini_t1_robotics_factory
}
local function fast_remove(tbl, index)
local count = #tbl
if index > count then
return
elseif index < count then
tbl[index] = tbl[count]
2018-07-28 14:04:14 +02:00
end
tbl[count] = nil
2018-07-28 14:04:14 +02:00
end
local function itertor_builder(arr, random)
local copy = {}
2018-07-28 14:04:14 +02:00
return function()
if #copy == 0 then
for i = 1, #arr do
copy[i] = arr[i]
end
end
local i = random:next_int(1, #copy)
local res = copy[i]
fast_remove(copy, i)
return res
end
2018-07-28 14:04:14 +02:00
end
local stage1a_iter = itertor_builder(stage1a, outpost_random)
local stage1b_iter = itertor_builder(stage1b, outpost_random)
local stage2_iter = itertor_builder(stage2, outpost_random)
local stage3_iter = itertor_builder(stage3, outpost_random)
local stage4_iter = itertor_builder(stage4, outpost_random)
2019-01-10 16:34:28 +02:00
local mini1_iter = itertor_builder(mini1, outpost_random)
local mini2_iter = itertor_builder(mini2, outpost_random)
local mini3_iter = itertor_builder(mini3, outpost_random)
local start_outpost = outpost_builder:do_outpost(thin_walls)
start_outpost = b.change_tile(start_outpost, false, true)
start_outpost = b.change_map_gen_collision_tile(start_outpost, 'water-tile', 'grass-1')
2019-01-10 16:34:28 +02:00
local start_patch = b.circle(9)
local start_iron_patch =
b.resource(
2019-01-11 17:31:32 +02:00
b.translate(start_patch, -30, -30),
'iron-ore',
function()
return 1500
end
)
local start_copper_patch =
b.resource(
2019-01-11 17:31:32 +02:00
b.translate(start_patch, 30, -30),
'copper-ore',
function()
return 1200
end
)
local start_stone_patch =
b.resource(
2019-01-11 17:31:32 +02:00
b.translate(start_patch, 30, 30),
'stone',
function()
return 900
end
)
local start_coal_patch =
b.resource(
2019-01-11 17:31:32 +02:00
b.translate(start_patch, -30, 30),
'coal',
function()
return 1350
end
)
2018-07-28 14:04:14 +02:00
local start_resources = b.any({start_iron_patch, start_copper_patch, start_stone_patch, start_coal_patch})
start_outpost = b.apply_entity(start_outpost, start_resources)
local water_corner =
b.any {
b.translate(b.rectangle(6, 16), -6, 0),
b.translate(b.rectangle(16, 6), 0, -6)
}
water_corner = b.change_tile(water_corner, true, 'water')
2019-01-10 16:34:28 +02:00
water_corner = b.translate(water_corner, -54, -54)
start_outpost =
b.any {
water_corner,
b.rotate(water_corner, degrees(90)),
b.rotate(water_corner, degrees(180)),
b.rotate(water_corner, degrees(270)),
start_outpost
}
2018-07-28 14:04:14 +02:00
2019-01-10 16:34:28 +02:00
local outpost_offset = 59
local grid_block_size = 180
local grid_number_of_blocks = 9
local mini_outpost_offset = 36
local mini_grid_block_size = 96
local mini_grid_number_of_blocks = 21
local pattern = {}
2018-08-01 17:35:48 +02:00
2019-01-10 16:34:28 +02:00
for r = 1, grid_number_of_blocks do
local row = {}
pattern[r] = row
end
2018-07-28 14:04:14 +02:00
pattern[5][5] = start_outpost
2018-08-02 18:10:47 +02:00
local half_total_size = grid_block_size * 0.5 * 8
2018-08-02 18:10:47 +02:00
for _, pos in ipairs(stage1a_pos) do
local r, c = pos[1], pos[2]
2018-08-02 18:10:47 +02:00
local row = pattern[r]
2018-08-02 18:10:47 +02:00
local template = stage1a_iter()
local shape = outpost_builder:do_outpost(template)
2018-08-04 00:26:44 +02:00
local x = outpost_random:next_int(-outpost_offset, outpost_offset)
local y = outpost_random:next_int(-outpost_offset, outpost_offset)
shape = b.translate(shape, x, y)
2018-07-28 14:04:14 +02:00
row[c] = shape
end
2018-07-28 14:04:14 +02:00
for _, pos in ipairs(stage1b_pos) do
local r, c = pos[1], pos[2]
2018-08-04 00:26:44 +02:00
local row = pattern[r]
2018-07-28 14:04:14 +02:00
local template = stage1b_iter()
local shape = outpost_builder:do_outpost(template)
2018-08-04 00:26:44 +02:00
local x = outpost_random:next_int(-outpost_offset, outpost_offset)
local y = outpost_random:next_int(-outpost_offset, outpost_offset)
shape = b.translate(shape, x, y)
2018-07-28 14:04:14 +02:00
row[c] = shape
end
2018-07-28 14:04:14 +02:00
for _, pos in ipairs(stage2_pos) do
local r, c = pos[1], pos[2]
2018-08-04 00:26:44 +02:00
local row = pattern[r]
2018-07-28 14:04:14 +02:00
local template = stage2_iter()
local shape = outpost_builder:do_outpost(template)
2018-08-02 14:51:42 +02:00
local x = outpost_random:next_int(-outpost_offset, outpost_offset)
local y = outpost_random:next_int(-outpost_offset, outpost_offset)
shape = b.translate(shape, x, y)
2018-08-02 14:51:42 +02:00
row[c] = shape
end
for r = 2, 8 do
local row = pattern[r]
for c = 2, 8 do
if not row[c] then
local template = stage3_iter()
local shape = outpost_builder:do_outpost(template)
local x = outpost_random:next_int(-outpost_offset, outpost_offset)
local y = outpost_random:next_int(-outpost_offset, outpost_offset)
shape = b.translate(shape, x, y)
row[c] = shape
end
2018-08-02 14:51:42 +02:00
end
end
for r = 1, grid_number_of_blocks do
local row = pattern[r]
for c = 1, grid_number_of_blocks do
if not row[c] then
local template = stage4_iter()
local shape = outpost_builder:do_outpost(template)
2018-07-28 14:04:14 +02:00
local x = outpost_random:next_int(-outpost_offset, outpost_offset)
local y = outpost_random:next_int(-outpost_offset, outpost_offset)
shape = b.translate(shape, x, y)
2018-07-28 14:04:14 +02:00
row[c] = shape
end
2018-07-28 14:04:14 +02:00
end
end
2019-01-10 16:34:28 +02:00
local mini_pattern = {}
for r = 1, mini_grid_number_of_blocks do
mini_pattern[r] = {}
end
for r = 11, 11 do
local row = mini_pattern[r]
for c = 11, 11 do
row[c] = b.empty_shape
end
end
for r = 8, 14 do
local row = mini_pattern[r]
for c = 8, 14 do
if not row[c] then
local template = mini1_iter()
local shape = outpost_builder:do_outpost(template)
local x = outpost_random:next_int(-mini_outpost_offset, mini_outpost_offset)
local y = outpost_random:next_int(-mini_outpost_offset, mini_outpost_offset)
shape = b.translate(shape, x, y)
row[c] = shape
end
end
end
for r = 6, 16 do
local row = mini_pattern[r]
for c = 6, 16 do
if not row[c] then
local template = mini2_iter()
local shape = outpost_builder:do_outpost(template)
local x = outpost_random:next_int(-mini_outpost_offset, mini_outpost_offset)
local y = outpost_random:next_int(-mini_outpost_offset, mini_outpost_offset)
shape = b.translate(shape, x, y)
row[c] = shape
end
end
end
for r = 1, mini_grid_number_of_blocks do
local row = mini_pattern[r]
for c = 1, mini_grid_number_of_blocks do
if not row[c] then
local template = mini3_iter()
local shape = outpost_builder:do_outpost(template)
local x = outpost_random:next_int(-mini_outpost_offset, mini_outpost_offset)
local y = outpost_random:next_int(-mini_outpost_offset, mini_outpost_offset)
shape = b.translate(shape, x, y)
row[c] = shape
end
end
end
local outposts =
b.grid_pattern(pattern, grid_number_of_blocks, grid_number_of_blocks, grid_block_size, grid_block_size)
local mini_outposts =
b.grid_pattern(
mini_pattern,
mini_grid_number_of_blocks,
mini_grid_number_of_blocks,
mini_grid_block_size,
mini_grid_block_size
)
local offset = -180 -- (grid_block_size ) * 0.5
mini_outposts = b.translate(mini_outposts, offset, offset)
outposts = b.if_else(outposts, mini_outposts)
--outposts = mini_outposts
2018-07-28 14:04:14 +02:00
local spawners = {
'biter-spawner',
'spitter-spawner'
}
2018-07-28 14:04:14 +02:00
local worms = {
'small-worm-turret',
'medium-worm-turret',
'big-worm-turret'
}
2018-07-28 14:04:14 +02:00
local max_spawner_chance = 1 / 256
local spawner_chance_factor = 1 / (256 * 512)
2019-01-10 16:34:28 +02:00
local max_worm_chance = 1 / 64
local worm_chance_factor = 1 / (40 * 512)
2018-07-28 14:04:14 +02:00
--local scale_factor = 1 / 32
2018-07-28 14:04:14 +02:00
local function enemy(_, _, world)
local wx, wy = world.x, world.y
2018-10-16 17:42:40 +02:00
local d = math.sqrt(wx * wx + wy * wy)
2018-07-28 14:04:14 +02:00
--[[ if Perlin.noise(x * scale_factor, y * scale_factor, enemy_seed) < 0 then
2018-07-30 17:42:14 +02:00
return nil
end ]]
2019-01-10 16:34:28 +02:00
local spawner_chance = d - 120
2018-07-30 17:42:14 +02:00
if spawner_chance > 0 then
spawner_chance = spawner_chance * spawner_chance_factor
spawner_chance = math.min(spawner_chance, max_spawner_chance)
2018-07-30 17:42:14 +02:00
if math.random() < spawner_chance then
return {name = spawners[math.random(2)]}
end
2018-07-28 14:04:14 +02:00
end
2018-07-30 17:42:14 +02:00
2019-01-10 16:34:28 +02:00
local worm_chance = d - 120
2018-07-30 17:42:14 +02:00
if worm_chance > 0 then
worm_chance = worm_chance * worm_chance_factor
worm_chance = math.min(worm_chance, max_worm_chance)
2018-07-30 17:42:14 +02:00
if math.random() < worm_chance then
2018-10-16 17:42:40 +02:00
if d < 256 then
return {name = 'small-worm-turret'}
2018-07-30 17:42:14 +02:00
else
local max_lvl
local min_lvl
2018-10-16 17:42:40 +02:00
if d < 512 then
max_lvl = 2
min_lvl = 1
else
max_lvl = 3
min_lvl = 2
end
2018-10-16 17:42:40 +02:00
local lvl = math.random() ^ (384 / d) * max_lvl
lvl = math.ceil(lvl)
--local lvl = math.floor(d / 256) + 1
lvl = math.clamp(lvl, min_lvl, 3)
return {name = worms[lvl]}
2018-07-30 17:42:14 +02:00
end
end
end
end
2018-07-28 14:04:14 +02:00
local enemy_shape = b.apply_entity(b.full_shape, enemy)
2018-07-28 14:04:14 +02:00
2019-01-11 01:10:54 +02:00
local ores_patch = b.circle(13)
local function value(base, mult, pow)
return function(x, y)
2018-10-02 21:58:22 +02:00
local d_sq = x * x + y * y
return base + mult * d_sq ^ (pow / 2) -- d^pow
end
2018-07-28 14:04:14 +02:00
end
local function non_transform(shape)
return shape
end
2018-07-28 14:04:14 +02:00
local function uranium_transform(shape)
return b.scale(shape, 0.5)
end
2018-07-28 14:04:14 +02:00
local function oil_transform(shape)
2019-01-10 16:34:28 +02:00
shape = b.scale(shape, 0.75)
shape = b.throttle_world_xy(shape, 1, 5, 1, 5)
return shape
end
2018-07-28 14:04:14 +02:00
local ores = {
2019-01-10 16:43:18 +02:00
{weight = 275},
{transform = non_transform, resource = 'iron-ore', value = value(500, 0.75, 1.1), weight = 16},
{transform = non_transform, resource = 'copper-ore', value = value(400, 0.75, 1.1), weight = 10},
{transform = non_transform, resource = 'stone', value = value(250, 0.3, 1.05), weight = 5},
{transform = non_transform, resource = 'coal', value = value(400, 0.8, 1.075), weight = 8},
{transform = uranium_transform, resource = 'uranium-ore', value = value(200, 0.3, 1.025), weight = 3},
{transform = oil_transform, resource = 'crude-oil', value = value(180000, 50, 1.025), weight = 6}
}
2018-07-28 14:04:14 +02:00
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 random_ore = Random.new(ore_seed, ore_seed * 2)
local ore_pattern = {}
for r = 1, 50 do
local row = {}
ore_pattern[r] = row
for c = 1, 50 do
local i = random_ore:next_int(1, ore_t)
2018-10-16 17:42:40 +02:00
local index = table.binary_search(total_ore_weights, i)
if (index < 0) then
index = bit32.bnot(index)
end
local ore_data = ores[index]
2018-07-28 14:04:14 +02:00
local transform = ore_data.transform
if not transform then
row[c] = b.no_entity
else
local ore_shape = transform(ores_patch)
2018-07-28 14:04:14 +02:00
local x = random_ore:next_int(-24, 24)
local y = random_ore:next_int(-24, 24)
ore_shape = b.translate(ore_shape, x, y)
2018-07-28 14:04:14 +02:00
local ore = b.resource(ore_shape, ore_data.resource, ore_data.value)
row[c] = ore
end
2018-07-28 14:04:14 +02:00
end
2018-07-13 12:47:38 +02:00
end
2019-01-10 16:34:28 +02:00
local ore_grid = b.grid_pattern_full_overlap(ore_pattern, 35, 35, 56, 56)
ore_grid = b.choose(b.rectangle(126), b.no_entity, ore_grid)
local map = b.if_else(outposts, enemy_shape)
2019-01-10 16:34:28 +02:00
map = b.if_else(map, b.full_shape)
map = b.translate(map, -half_total_size, -half_total_size)
map = b.apply_entity(map, ore_grid)
local market = {
callback = outpost_builder.market_set_items_callback,
data = {
2019-01-10 16:34:28 +02:00
market_name = 'Spawn',
{name = 'raw-wood', price = 1},
{name = 'iron-plate', price = 2},
{name = 'stone', price = 2},
{name = 'coal', price = 1.25},
{name = 'raw-fish', price = 4},
{name = 'firearm-magazine', price = 5},
2019-01-10 16:34:28 +02:00
{name = 'science-pack-1', price = 10},
{name = 'science-pack-2', price = 25},
{name = 'military-science-pack', price = 50},
{name = 'science-pack-3', price = 75},
{name = 'production-science-pack', price = 100},
{name = 'high-tech-science-pack', price = 125},
2019-01-14 13:10:34 +02:00
{
price = 100,
name = 'small-plane',
name_label = 'Train Immunity (1x use)',
description = 'Each small plane in your inventory will save you from being killed by a train once.'
}
}
2018-07-28 14:04:14 +02:00
}
local factory = {
callback = outpost_builder.magic_item_crafting_callback,
data = {
output = {min_rate = 0.5 / 60, distance_factor = 0, item = 'coin'}
}
2018-07-26 02:00:05 +02:00
}
local spawn = {
size = 2,
[1] = {
market = market,
[15] = {entity = {name = 'market', callback = 'market'}}
},
[2] = {
force = 'player',
factory = factory,
[15] = {entity = {name = 'electric-furnace', callback = 'factory'}}
}
2018-07-20 23:01:34 +02:00
}
2018-07-28 14:04:14 +02:00
local spawn_shape = outpost_builder.to_shape(spawn)
spawn_shape = b.change_tile(spawn_shape, false, 'stone-path')
2018-07-20 23:01:34 +02:00
map = b.choose(b.rectangle(16, 16), spawn_shape, map)
2018-07-13 12:47:38 +02:00
2019-01-11 17:50:00 +02:00
local bounds = b.rectangle(grid_block_size * (grid_number_of_blocks) + 1)
map = b.choose(bounds, map, b.empty_shape)
2018-08-01 17:35:48 +02:00
return map
end
2018-07-30 17:42:14 +02:00
local map
Global.register_init(
{},
function(tbl)
local seed = RS.get_surface().map_gen_settings.seed
tbl.outpost_seed = outpost_seed or seed
tbl.ore_seed = ore_seed or seed
2019-01-13 14:34:37 +02:00
global.config.market.enable = false
end,
function(tbl)
outpost_seed = tbl.outpost_seed
ore_seed = tbl.ore_seed
map = init()
end
)
2018-07-30 17:42:14 +02:00
2019-01-10 16:34:28 +02:00
--[[ local Event = require 'utils.event'
Event.add(
defines.events.on_player_joined_game,
function(event)
game.players[event.player_index].character = nil
end
) ]]
return function(x, y, world)
return map(x, y, world)
end