From 7a0036c4a746ef52ef49058b11fb89a15619d8ca Mon Sep 17 00:00:00 2001 From: James Gillham Date: Sun, 1 Aug 2021 14:57:12 +0100 Subject: [PATCH 1/2] Add danger_ore_one_direction. --- .../config/vanilla_ores_one_direction.lua | 76 ++++++++ .../modules/main_ores_one_direction.lua | 43 +++++ map_gen/maps/danger_ores/modules/map.lua | 67 +++---- .../maps/danger_ores/modules/terraforming.lua | 26 ++- .../presets/danger_ore_one_direction.lua | 180 ++++++++++++++++++ map_gen/shared/builders.lua | 25 +++ .../map_selection.lua | 1 + 7 files changed, 371 insertions(+), 47 deletions(-) create mode 100644 map_gen/maps/danger_ores/config/vanilla_ores_one_direction.lua create mode 100644 map_gen/maps/danger_ores/modules/main_ores_one_direction.lua create mode 100644 map_gen/maps/danger_ores/presets/danger_ore_one_direction.lua create mode 100644 scenario_templates/danger-ore-one-direction/map_selection.lua diff --git a/map_gen/maps/danger_ores/config/vanilla_ores_one_direction.lua b/map_gen/maps/danger_ores/config/vanilla_ores_one_direction.lua new file mode 100644 index 00000000..8cd04860 --- /dev/null +++ b/map_gen/maps/danger_ores/config/vanilla_ores_one_direction.lua @@ -0,0 +1,76 @@ +local b = require 'map_gen.shared.builders' +local start_value = b.euclidean_value(0, 0.35) +local value = b.exponential_value(0, 0.15, 1.1) + +return { + { + name = 'copper-ore', + ['tiles'] = { + [1] = 'red-desert-0', + [2] = 'red-desert-1', + [3] = 'red-desert-2', + [4] = 'red-desert-3' + }, + ['start'] = start_value, + ['weight'] = 1, + ['ratios'] = { + {resource = b.resource(b.full_shape, 'iron-ore', value), weight = 15}, + {resource = b.resource(b.full_shape, 'copper-ore', value), weight = 70}, + {resource = b.resource(b.full_shape, 'stone', value), weight = 10}, + {resource = b.resource(b.full_shape, 'coal', value), weight = 5} + } + }, + { + name = 'coal', + ['tiles'] = { + [1] = 'dirt-1', + [2] = 'dirt-2', + [3] = 'dirt-3', + [4] = 'dirt-4', + [5] = 'dirt-5', + [6] = 'dirt-6', + [7] = 'dirt-7' + }, + ['start'] = start_value, + ['weight'] = 1, + ['ratios'] = { + {resource = b.resource(b.full_shape, 'iron-ore', value), weight = 18}, + {resource = b.resource(b.full_shape, 'copper-ore', value), weight = 9}, + {resource = b.resource(b.full_shape, 'stone', value), weight = 8}, + {resource = b.resource(b.full_shape, 'coal', value), weight = 65} + } + }, + { + name = 'iron-ore', + ['tiles'] = { + [1] = 'grass-1', + [2] = 'grass-2', + [3] = 'grass-3', + [4] = 'grass-4' + }, + ['start'] = start_value, + ['weight'] = 1, + ['ratios'] = { + {resource = b.resource(b.full_shape, 'iron-ore', value), weight = 75}, + {resource = b.resource(b.full_shape, 'copper-ore', value), weight = 13}, + {resource = b.resource(b.full_shape, 'stone', value), weight = 7}, + {resource = b.resource(b.full_shape, 'coal', value), weight = 5} + } + }, + --[[ { + name = 'stone', + ['tiles'] = { + [1] = 'sand-1', + [2] = 'sand-2', + [3] = 'sand-3' + }, + ['start'] = start_value, + ['weight'] = 1, + ['ratios'] = { + {resource = b.resource(b.full_shape, 'iron-ore', value), weight = 25}, + {resource = b.resource(b.full_shape, 'copper-ore', value), weight = 10}, + {resource = b.resource(b.full_shape, 'stone', value), weight = 60}, + {resource = b.resource(b.full_shape, 'coal', value), weight = 5} + } + } ]] +} diff --git a/map_gen/maps/danger_ores/modules/main_ores_one_direction.lua b/map_gen/maps/danger_ores/modules/main_ores_one_direction.lua new file mode 100644 index 00000000..795f232e --- /dev/null +++ b/map_gen/maps/danger_ores/modules/main_ores_one_direction.lua @@ -0,0 +1,43 @@ +local Helper = require 'map_gen.maps.danger_ores.modules.helper' +local b = require 'map_gen.shared.builders' +local table = require 'utils.table' + +return function(config) + local main_ores = config.main_ores + local shuffle_order = config.main_ores_shuffle_order + local main_ores_rotate = config.main_ores_rotate or 0 + local main_ores_split_count = config.main_ores_split_count or 1 + + main_ores = Helper.split_ore(main_ores, main_ores_split_count) + + return function(tile_builder, ore_builder, spawn_shape, water_shape, random_gen) + local shapes = {} + + for _, ore_data in pairs(main_ores) do + local ore_name = ore_data.name + local tiles = ore_data.tiles + local land = tile_builder(tiles) + + local ratios = ore_data.ratios + local weighted = b.prepare_weighted_array(ratios) + local amount = ore_data.start + + local ore = ore_builder(ore_name, amount, ratios, weighted) + + local shape = b.apply_entity(land, ore) + shapes[#shapes + 1] = {shape = shape, weight = ore_data.weight} + end + + if shuffle_order then + table.shuffle_table(shapes, random_gen) + end + + local ores = b.grid_y_no_repeat_weighted_pattern(shapes, 32) + + if main_ores_rotate ~= 0 then + ores = b.rotate(ores, math.rad(main_ores_rotate)) + end + + return b.any {spawn_shape, water_shape, ores} + end +end diff --git a/map_gen/maps/danger_ores/modules/map.lua b/map_gen/maps/danger_ores/modules/map.lua index b963ac77..06698044 100644 --- a/map_gen/maps/danger_ores/modules/map.lua +++ b/map_gen/maps/danger_ores/modules/map.lua @@ -90,43 +90,44 @@ return function(config) end local map - Global.register_init( - {}, - function(tbl) - tbl.seed = RS.get_surface().map_gen_settings.seed - tbl.random = game.create_random_generator(tbl.seed) - end, - function(tbl) - local spawn_shape = spawn_builder(config) - local water_shape = (config.water or empty_builder)(config) - local tile_builder = tile_builder_factory(config) - local trees_shape = (config.trees or no_op)(config) - local enemy_shape = (config.enemy or no_op)(config) - local fish_spawn_rate = config.fish_spawn_rate - local main_ores_builder = (config.main_ores_builder or deafult_main_ores_builder)(config) + Global.register_init({}, function(tbl) + tbl.seed = RS.get_surface().map_gen_settings.seed + tbl.random = game.create_random_generator(tbl.seed) + end, function(tbl) + local spawn_shape = spawn_builder(config) + local water_shape = (config.water or empty_builder)(config) + local tile_builder = tile_builder_factory(config) + local trees_shape = (config.trees or no_op)(config) + local enemy_shape = (config.enemy or no_op)(config) + local fish_spawn_rate = config.fish_spawn_rate + local main_ores_builder = (config.main_ores_builder or deafult_main_ores_builder)(config) + local post_map_func = config.post_map_func - start_ore_shape = config.start_ore_shape or b.circle(68) - resource_patches = (config.resource_patches or no_op)(config) or b.empty_shape - no_resource_patch_shape = config.no_resource_patch_shape or b.empty_shape - dense_patches = (config.dense_patches or no_op)(config) or no_op + start_ore_shape = config.start_ore_shape or b.circle(68) + resource_patches = (config.resource_patches or no_op)(config) or b.empty_shape + no_resource_patch_shape = config.no_resource_patch_shape or b.empty_shape + dense_patches = (config.dense_patches or no_op)(config) or no_op - local random_gen = tbl.random - random_gen.re_seed(tbl.seed) - map = main_ores_builder(tile_builder, ore_builder, spawn_shape, water_shape, random_gen) + local random_gen = tbl.random + random_gen.re_seed(tbl.seed) + map = main_ores_builder(tile_builder, ore_builder, spawn_shape, water_shape, random_gen) - if enemy_shape then - map = b.apply_entity(map, enemy_shape) - end - - if trees_shape then - map = b.apply_entity(map, trees_shape) - end - - if fish_spawn_rate then - map = b.fish(map, fish_spawn_rate) - end + if enemy_shape then + map = b.apply_entity(map, enemy_shape) end - ) + + if trees_shape then + map = b.apply_entity(map, trees_shape) + end + + if fish_spawn_rate then + map = b.fish(map, fish_spawn_rate) + end + + if post_map_func then + map = post_map_func(map) + end + end) return function(x, y, world) return map(x, y, world) diff --git a/map_gen/maps/danger_ores/modules/terraforming.lua b/map_gen/maps/danger_ores/modules/terraforming.lua index e0f424a4..451c726f 100644 --- a/map_gen/maps/danger_ores/modules/terraforming.lua +++ b/map_gen/maps/danger_ores/modules/terraforming.lua @@ -14,6 +14,7 @@ return function(config) Generate.enable_register_events = false local start_size = config.start_size + local outer_bounds = config.bounds or b.full_shape local pollution_data = { min_pollution = config.min_pollution or 400, @@ -26,17 +27,13 @@ return function(config) local chunk_list = {index = 1} local surface - Global.register_init( - {chunk_list = chunk_list, pollution_data = pollution_data}, - function(tbl) - tbl.surface = RS.get_surface() - end, - function(tbl) - chunk_list = tbl.chunk_list - pollution_data = tbl.pollution_data - surface = tbl.surface - end - ) + Global.register_init({chunk_list = chunk_list, pollution_data = pollution_data}, function(tbl) + tbl.surface = RS.get_surface() + end, function(tbl) + chunk_list = tbl.chunk_list + pollution_data = tbl.pollution_data + surface = tbl.surface + end) local bounds = b.rectangle(start_size, start_size) @@ -59,7 +56,9 @@ return function(config) end surface.set_tiles(tiles, true) - chunk_list[#chunk_list + 1] = {left_top = left_top, id = nil} + if (outer_bounds(x + 0.5, y + 0.5)) then + chunk_list[#chunk_list + 1] = {left_top = left_top, id = nil} + end end end @@ -102,8 +101,7 @@ return function(config) local id = data.id if not id then - data.id = - rendering.draw_text { + data.id = rendering.draw_text { text = text, surface = surface, target = {x + 16, y + 16}, diff --git a/map_gen/maps/danger_ores/presets/danger_ore_one_direction.lua b/map_gen/maps/danger_ores/presets/danger_ore_one_direction.lua new file mode 100644 index 00000000..3af61392 --- /dev/null +++ b/map_gen/maps/danger_ores/presets/danger_ore_one_direction.lua @@ -0,0 +1,180 @@ +local RS = require 'map_gen.shared.redmew_surface' +local MGSP = require 'resources.map_gen_settings' +local Event = require 'utils.event' +local b = require 'map_gen.shared.builders' +local Config = require 'config' + +local ScenarioInfo = require 'features.gui.info' +ScenarioInfo.set_map_name('Danger Ore One Direction') +ScenarioInfo.set_map_description([[ +Clear the ore to expand the base, +focus mining efforts on specific sectors to ensure +proper material ratios, expand the map with pollution! +]]) +ScenarioInfo.add_map_extra_info([[ +This map is split in three sectors [item=iron-ore] [item=copper-ore] [item=coal]. +Each sector has a main resource and the other resources at a lower ratio. + +You may not build the factory on ore patches. Exceptions: + [item=burner-mining-drill] [item=electric-mining-drill] [item=pumpjack] [item=small-electric-pole] [item=medium-electric-pole] [item=big-electric-pole] [item=substation] [item=car] [item=tank] [item=spidertron] [item=locomotive] [item=cargo-wagon] [item=fluid-wagon] [item=artillery-wagon] + [item=transport-belt] [item=fast-transport-belt] [item=express-transport-belt] [item=underground-belt] [item=fast-underground-belt] [item=express-underground-belt] [item=rail] [item=rail-signal] [item=rail-chain-signal] [item=train-stop] + +The map size is restricted to the pollution generated. A significant amount of +pollution must affect a section of the map before it is revealed. Pollution +does not affect biter evolution.]]) + +ScenarioInfo.set_new_info([[ +2019-04-24: + - Stone ore density reduced by 1/2 + - Ore quadrants randomized + - Increased time factor of biter evolution from 5 to 7 + - Added win conditions (+5% evolution every 5 rockets until 100%, +100 rockets until biters are wiped) + +2019-03-30: + - Uranium ore patch threshold increased slightly + - Bug fix: Cars and tanks can now be placed onto ore! + - Starting minimum pollution to expand map set to 650 + View current pollution via Debug Settings [F4] show-pollution-values, + then open map and turn on pollution via the red box. + - Starting water at spawn increased from radius 8 to radius 16 circle. + +2019-03-27: + - Ore arranged into quadrants to allow for more controlled resource gathering. + +2020-09-02: + - Destroyed chests dump their content as coal ore. + +2020-12-28: + - Changed win condition. First satellite kills all biters, launch 500 to win the map. + +2021-04-06: + - Rail signals and train stations now allowed on ore. +]]) + +local map = require 'map_gen.maps.danger_ores.modules.map' +local main_ores_config = require 'map_gen.maps.danger_ores.config.vanilla_ores_one_direction' +local resource_patches = require 'map_gen.maps.danger_ores.modules.resource_patches' +local resource_patches_config = require 'map_gen.maps.danger_ores.config.vanilla_resource_patches' +-- local water = require 'map_gen.maps.danger_ores.modules.water' +local trees = require 'map_gen.maps.danger_ores.modules.trees' +local enemy = require 'map_gen.maps.danger_ores.modules.enemy' +-- local dense_patches = require 'map_gen.maps.danger_ores.modules.dense_patches' + +local banned_entities = require 'map_gen.maps.danger_ores.modules.banned_entities' +local allowed_entities = require 'map_gen.maps.danger_ores.config.vanilla_allowed_entities' +banned_entities(allowed_entities) + +RS.set_map_gen_settings({ + MGSP.grass_only, + MGSP.enable_water, + {terrain_segmentation = 'normal', water = 'normal'}, + MGSP.starting_area_very_low, + MGSP.ore_oil_none, + MGSP.enemy_none, + MGSP.cliff_none, + MGSP.tree_none, + {height = 32 * 3} +}) + +Config.market.enabled = false +Config.player_rewards.enabled = false +Config.player_create.starting_items = {} +Config.dump_offline_inventories = { + enabled = true, + offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team +} +Config.paint.enabled = false + +Event.on_init(function() + game.draw_resource_selection = false + game.forces.player.technologies['mining-productivity-1'].enabled = false + game.forces.player.technologies['mining-productivity-2'].enabled = false + game.forces.player.technologies['mining-productivity-3'].enabled = false + game.forces.player.technologies['mining-productivity-4'].enabled = false + + game.difficulty_settings.technology_price_multiplier = 25 + game.forces.player.technologies.logistics.researched = true + game.forces.player.technologies.automation.researched = true + + game.map_settings.enemy_evolution.time_factor = 0.000007 -- default 0.000004 + game.map_settings.enemy_evolution.destroy_factor = 0.000010 -- default 0.002 + game.map_settings.enemy_evolution.pollution_factor = 0.000000 -- Pollution has no affect on evolution default 0.0000009 + + game.forces.player.manual_mining_speed_modifier = 1 + + RS.get_surface().always_day = true +end) + +local function terraforming_bounds(x, y) + return x > -64 and y > -64 and y < 64 +end + +local terraforming = require 'map_gen.maps.danger_ores.modules.terraforming' +terraforming({ + start_size = 8 * 32, + min_pollution = 100, + max_pollution = 16000, + pollution_increment = 4, + bounds = terraforming_bounds +}) + +local rocket_launched = require 'map_gen.maps.danger_ores.modules.rocket_launched_simple' +rocket_launched({win_satellite_count = 500}) + +local restart_command = require 'map_gen.maps.danger_ores.modules.restart_command' +restart_command({scenario_name = 'terraforming-danger-ore'}) + +local container_dump = require 'map_gen.maps.danger_ores.modules.container_dump' +container_dump({entity_name = 'coal'}) + +local concrete_on_landfill = require 'map_gen.maps.danger_ores.modules.concrete_on_landfill' +concrete_on_landfill({tile = 'blue-refined-concrete'}) + +local main_ores_builder = require 'map_gen.maps.danger_ores.modules.main_ores_one_direction' + +local function post_map_func(map) + local function map_bounds(x, y) + return x > -44 and y > -48 and y < 48 + end + + local function water_bounds(x, y) + return x > -46 and y > -50 and y < 50 + end + + local water_border = b.tile('water') + water_border = b.choose(water_bounds, water_border, b.empty_shape) + + return b.choose(map_bounds, map, water_border) +end + +local config = { + spawn_shape = b.rectangle(72), + start_ore_shape = b.rectangle(88), + post_map_func = post_map_func, + main_ores_builder = main_ores_builder, + no_resource_patch_shape = b.rectangle(160), + main_ores = main_ores_config, + main_ores_shuffle_order = true, + -- main_ores_rotate = 30, + resource_patches = resource_patches, + resource_patches_config = resource_patches_config, + -- water = water, + water_scale = 1 / 96, + water_threshold = 0.4, + deepwater_threshold = 0.45, + trees = trees, + trees_scale = 1 / 64, + trees_threshold = 0.4, + trees_chance = 0.875, + enemy = enemy, + enemy_factor = 10 / (768 * 32), + enemy_max_chance = 1 / 6, + enemy_scale_factor = 32, + fish_spawn_rate = 0.025, + -- dense_patches = dense_patches, + dense_patches_scale = 1 / 48, + dense_patches_threshold = 0.55, + dense_patches_multiplier = 25 +} + +return map(config) diff --git a/map_gen/shared/builders.lua b/map_gen/shared/builders.lua index ea99735b..33c3675c 100644 --- a/map_gen/shared/builders.lua +++ b/map_gen/shared/builders.lua @@ -1170,6 +1170,31 @@ function Builders.grid_y_pattern(pattern, rows, height) end end +function Builders.grid_y_no_repeat_weighted_pattern(pattern, height) + local weights = Builders.prepare_weighted_array(pattern) + local total = weights.total + local scale = 1 / height + + return function(x, y, world) + local i = ((y * scale) -0.5) % total + + local index = binary_search(weights, i) + if index < 0 then + index = bnot(index) + end + + local data = pattern[index] + local shape + if data then + shape = data.shape + end + + shape = shape or Builders.empty_shape + + return shape(x, y, world) + end +end + --- Docs: https://github.com/Refactorio/RedMew/wiki/Using-the-Builders#buildersgrid_pattern function Builders.grid_pattern(pattern, columns, rows, width, height) local half_width = width / 2 diff --git a/scenario_templates/danger-ore-one-direction/map_selection.lua b/scenario_templates/danger-ore-one-direction/map_selection.lua new file mode 100644 index 00000000..2c8b1148 --- /dev/null +++ b/scenario_templates/danger-ore-one-direction/map_selection.lua @@ -0,0 +1 @@ +return require 'map_gen.maps.danger_ores.presets.danger_ore_one_direction' \ No newline at end of file From 9e967b3eb7cd925b6fc0b55254657181ecb506ae Mon Sep 17 00:00:00 2001 From: James Gillham Date: Sun, 1 Aug 2021 15:03:57 +0100 Subject: [PATCH 2/2] Fix luacheck. --- map_gen/maps/danger_ores/presets/danger_ore_one_direction.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/map_gen/maps/danger_ores/presets/danger_ore_one_direction.lua b/map_gen/maps/danger_ores/presets/danger_ore_one_direction.lua index 3af61392..20cd71fe 100644 --- a/map_gen/maps/danger_ores/presets/danger_ore_one_direction.lua +++ b/map_gen/maps/danger_ores/presets/danger_ore_one_direction.lua @@ -132,7 +132,7 @@ concrete_on_landfill({tile = 'blue-refined-concrete'}) local main_ores_builder = require 'map_gen.maps.danger_ores.modules.main_ores_one_direction' -local function post_map_func(map) +local function post_map_func(map_shape) local function map_bounds(x, y) return x > -44 and y > -48 and y < 48 end @@ -144,7 +144,7 @@ local function post_map_func(map) local water_border = b.tile('water') water_border = b.choose(water_bounds, water_border, b.empty_shape) - return b.choose(map_bounds, map, water_border) + return b.choose(map_bounds, map_shape, water_border) end local config = {