diff --git a/map_gen/maps/danger_ores/modules/main_ores_circles.lua b/map_gen/maps/danger_ores/modules/main_ores_circles.lua index 6e1e6824..867802aa 100644 --- a/map_gen/maps/danger_ores/modules/main_ores_circles.lua +++ b/map_gen/maps/danger_ores/modules/main_ores_circles.lua @@ -2,67 +2,50 @@ local Helper = require 'map_gen.maps.danger_ores.modules.helper' local b = require 'map_gen.shared.builders' local table = require 'utils.table' -local binary_search = table.binary_search -local bnot = bit32.bnot -local sqrt = math.sqrt -local floor = math.floor -local value = b.manhattan_value - return function(config) local main_ores = config.main_ores local main_ores_split_count = config.main_ores_split_count or 1 + local main_ores_rotate = config.main_ores_rotate or 0 local start_ore_shape = config.start_ore_shape + local circle_thickenss = config.circle_thickness or 16 main_ores = Helper.split_ore(main_ores, main_ores_split_count) - local function condition_factory(ore_name, ores) - local scale = config.circle_scale or 1 - --local randomize_scale = config.randomize_scale or false - local ore_table = {} - for _, ore_data in pairs(ores) do - table.insert(ore_table, {name = ore_data.name, weight = ore_data.weight}) - end - local weighted = b.prepare_weighted_array(ore_table) - return function(x, y, _) - local i = floor(sqrt(x * x + y * y) * scale) % weighted.total + 1 - local index = binary_search(weighted, i) - if index < 0 then - index = bnot(index) - end - return ore_table[index].name == ore_name - end - end - return function(tile_builder, ore_builder, spawn_shape, water_shape, random_gen) + local starting_ores_list = {} + local shapes = {} - if config.main_ores_shuffle_order then - table.shuffle_table(main_ores, random_gen) - end + for _, ore_data in pairs(main_ores) do + local ore_name = ore_data.name + local tiles = ore_data.tiles + local start_amount = ore_data.start + local ratios = ore_data.ratios + local ore_weight = ore_data.weight + local weighted = b.prepare_weighted_array(ratios) + local land = tile_builder(tiles) - local shapes = {} - local starting_ores_list = {} - 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 start_ore = b.apply_entity(land, b.resource(b.full_shape, ore_name, start_amount)) + start_ore = b.choose(start_ore_shape, start_ore, b.empty_shape) + starting_ores_list[#starting_ores_list + 1] = {shape = start_ore, weight = ore_weight} - table.insert(starting_ores_list, b.resource(start_ore_shape, ore_name, value(100, 0))) + local ore = ore_builder(ore_name, start_amount, ratios, weighted) + local shape = b.apply_entity(land, ore) + shapes[#shapes + 1] = {shape = shape, weight = ore_weight} + end - local ratios = ore_data.ratios - local weighted = b.prepare_weighted_array(ratios) - local amount = ore_data.start + if config.main_ores_shuffle_order then + table.shuffle_table(starting_ores_list, random_gen) + table.shuffle_table(shapes, random_gen) + end - local ore = ore_builder(ore_name, amount, ratios, weighted) - local condition = condition_factory(ore_name, main_ores) - local shape = b.choose(condition, b.apply_entity(land, ore), b.empty_shape) - table.insert(shapes, shape) - end + local starting_ores = b.segment_weighted_pattern(starting_ores_list) + local ores = b.ring_weighted_pattern(shapes, circle_thickenss) - local ores = b.any(shapes) + if main_ores_rotate ~= 0 then + -- Only makes sense to rotate starting ores as the main ores are a circle. + starting_ores = b.rotate(starting_ores, math.rad(main_ores_rotate)) + end - local starting_ores = b.change_map_gen_collision_tile(start_ore_shape, 'water-tile', 'grass-1') - starting_ores = b.apply_entity(starting_ores, b.segment_pattern(starting_ores_list)) - - return b.any {spawn_shape, starting_ores ,water_shape, ores} + return b.any {spawn_shape, water_shape, starting_ores, ores} end end diff --git a/map_gen/maps/danger_ores/presets/danger_ore_circles.lua b/map_gen/maps/danger_ores/presets/danger_ore_circles.lua index a0eda058..66b6e66e 100644 --- a/map_gen/maps/danger_ores/presets/danger_ore_circles.lua +++ b/map_gen/maps/danger_ores/presets/danger_ore_circles.lua @@ -109,7 +109,7 @@ local rocket_launched = require 'map_gen.maps.danger_ores.modules.rocket_launche rocket_launched({win_satellite_count = 500}) local restart_command = require 'map_gen.maps.danger_ores.modules.restart_command' -restart_command({scenario_name = 'danger-ore-gradient'}) +restart_command({scenario_name = 'danger-ore-circles'}) local container_dump = require 'map_gen.maps.danger_ores.modules.container_dump' container_dump({entity_name = 'coal'}) @@ -125,7 +125,7 @@ local config = { main_ores_builder = main_ores_builder, main_ores = main_ores_config, main_ores_shuffle_order = true, - main_ores_rotate = 0, + main_ores_rotate = 30, resource_patches = resource_patches, resource_patches_config = resource_patches_config, water = water, @@ -145,7 +145,7 @@ local config = { dense_patches_scale = 1 / 48, dense_patches_threshold = 0.55, dense_patches_multiplier = 25, - circle_scale = 1/16 -- regulates the width of each circle + circle_thickness = 16 -- Thickness of the rings at weight 1 } return map(config) diff --git a/map_gen/shared/builders.lua b/map_gen/shared/builders.lua index 78e7c053..44b3c08f 100644 --- a/map_gen/shared/builders.lua +++ b/map_gen/shared/builders.lua @@ -1517,6 +1517,44 @@ function Builders.segment_weighted_pattern(pattern) end end +function Builders.ring_pattern(pattern, thickness) + local count = #pattern + local scale = 1 / thickness + return function(x, y, world) + local d = sqrt(x * x + y * y) + local index = floor(d * scale) % count + 1 + local shape = pattern[index] or Builders.empty_shape + return shape(x, y, world) + end +end + +function Builders.ring_weighted_pattern(pattern, thickness) + local weights = Builders.prepare_weighted_array(pattern) + local total = weights.total + + --local count = #pattern + local scale = 1 / thickness + return function(x, y, world) + local d = sqrt(x * x + y * y) + local i = (d * scale) % 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 + local function rotate_cords(angle) local qx = cos(angle) local qy = sin(angle) diff --git a/scenario_templates/danger-ore-circle/map_selection.lua b/scenario_templates/danger-ore-circles/map_selection.lua similarity index 100% rename from scenario_templates/danger-ore-circle/map_selection.lua rename to scenario_templates/danger-ore-circles/map_selection.lua