diff --git a/map_gen/maps/space_race/map.lua b/map_gen/maps/space_race/map.lua index 62b1b62e..2a955fa2 100644 --- a/map_gen/maps/space_race/map.lua +++ b/map_gen/maps/space_race/map.lua @@ -6,8 +6,9 @@ local Map_gen_presets = require 'resources.map_gen_settings' local table = require 'utils.table' local Random = require 'map_gen.shared.random' local Event = require 'utils.event' - -local cliffs = require 'map_gen.maps.space_race.cliff_generator' +local floor = math.floor +local perlin = require 'map_gen.shared.perlin_noise' +local math = require 'utils.math' local seed1 = 17000 local seed2 = seed1 * 2 @@ -32,38 +33,57 @@ local uranium_none = { RS.set_map_gen_settings({Map_gen_presets.oil_none, uranium_none}) -local width_1 = 256 -- Do not reduce this, it prevents artillary spam +local sand_width = 128 +local sand_width_inv = math.tau / sand_width -local wilderness_shallow_water = b.line_y(width_1) -wilderness_shallow_water = b.change_tile(wilderness_shallow_water, true, 'water-shallow') -- water-mud is also walkable +--perlin options +local noise_variance = 0.025 --The lower this number the smoother the curve is gonna be +local noise_level = 10 --Factor for the magnitude of the curve + +local sand_noise_level = noise_level * 0.9 + +-- Leave nil and they will be set based on the map seed. +local perlin_seed_1 = 17000 + +local width_1 = 256 + +local function sand_shape(x, y) + local p = perlin.noise(x * noise_variance, y * noise_variance, perlin_seed_1) * sand_noise_level + p = p + math.sin(x * sand_width_inv) * 2 + return p > y +end +local sand_shape_right = b.rotate(sand_shape, -math.pi/2) + +local beach = b.line_y(16) +local beach_right = b.subtract(beach, sand_shape_right) +beach_right = b.change_tile(beach_right, true, 'sand-1') + +beach_right = b.if_else(beach_right, beach) + + +local beach_left = b.flip_xy(beach_right) +beach_left = b.change_tile(beach_left, true, 'water-shallow') + +beach_left = b.translate(beach_left, -8, 0) +beach_right = b.translate(beach_right, 8, 0) + +local water_transition_right = b.add(beach_right, beach_left) +local water_transition_left = b.flip_xy(water_transition_right) + +water_transition_right = b.translate(water_transition_right, floor(width_1 / 2), 0) +water_transition_left = b.translate(water_transition_left, -floor(width_1 / 2), 0) + +local wilderness_shallow_water = b.line_y(width_1 - 32) +wilderness_shallow_water = b.change_tile(wilderness_shallow_water, true, 'water-shallow') -- water-mud is also walkable but doesn't have any tile transitions + +wilderness_shallow_water = b.any({water_transition_right, water_transition_left, wilderness_shallow_water}) local inf = function() return 100000000 end --- Remove vanilla ores from this area -local function no_ores(_, _, world, tile) - if not tile then - return - end - for _, e in ipairs(world.surface.find_entities_filtered({type = 'resource', area = {{world.x, world.y}, {world.x + 1, world.y + 1}}})) do - e.destroy() - end - return tile -end - -local function no_cliffs(_, _, world, tile) - if not tile then - return - end - for _, e in ipairs(world.surface.find_entities_filtered({name = 'cliff', area = {{world.x, world.y}, {world.x + 1, world.y + 1}}})) do - e.destroy() - end - return tile -end - local uranium_island = b.circle(10) -uranium_island = b.apply_effect(uranium_island, no_ores) +uranium_island = b.remove_map_gen_resources(uranium_island) local uranium_ore = b.resource(b.rectangle(2, 2), 'uranium-ore', inf, true) uranium_island = b.apply_entity(uranium_island, uranium_ore) @@ -146,35 +166,19 @@ local oil = b.grid_pattern_full_overlap(pattern, p_cols, p_rows, width_2, 64) local safe_zone = b.translate(b.circle(256), -(width_2 / 2 + width_3 / 2), 0) -local function no_biters(_, _, world, tile) - if not tile then - return - end - for _, e in ipairs(world.surface.find_entities_filtered({type = 'unit-spawner', area = {{world.x, world.y}, {world.x + 1, world.y + 1}}})) do - e.destroy() - end - for _, e in ipairs(world.surface.find_entities_filtered({type = 'turret', area = {{world.x, world.y}, {world.x + 1, world.y + 1}}})) do - e.destroy() - end - for _, e in ipairs(world.surface.find_entities_filtered({type = 'unit', area = {{world.x, world.y}, {world.x + 1, world.y + 1}}})) do - e.destroy() - end - return tile -end - -safe_zone = b.apply_effect(safe_zone, no_biters) +safe_zone = b.remove_map_gen_enemies(safe_zone) local landfill_water = b.circle(128) local no_cliff_rectangle = b.rectangle(150, 75) no_cliff_rectangle = b.translate(no_cliff_rectangle, -32, 0) -no_cliff_rectangle = b.apply_effect(no_cliff_rectangle, no_cliffs) +no_cliff_rectangle = b.remove_map_gen_entities_by_filter(no_cliff_rectangle, {name = 'cliff'}) landfill_water = b.add(no_cliff_rectangle, landfill_water) landfill_water = b.translate(landfill_water, -(width_2 / 2 + width_3 / 2), 0) -landfill_water = b.apply_effect(landfill_water, no_biters) +landfill_water = b.remove_map_gen_enemies(landfill_water) landfill_water = b.change_map_gen_collision_tile(landfill_water, 'water-tile', 'landfill') @@ -207,9 +211,9 @@ water = b.translate(water, -35, 0) start_resources = b.add(start_resources, water) -start_resources = b.translate(start_resources, -math.floor(width_2 / 2 + width_3 / 2 + 60), 0) +start_resources = b.translate(start_resources, -floor(width_2 / 2 + width_3 / 2 + 60), 0) start_resources = b.change_map_gen_collision_tile(start_resources, 'water-tile', 'landfill') -start_resources = b.apply_effect(start_resources, no_biters) +start_resources = b.remove_map_gen_enemies(start_resources) wilderness_land = b.add(start_resources, wilderness_land) @@ -217,7 +221,7 @@ local wilderness_land_left = b.translate(wilderness_land, -(width_1 + width_2) / local wilderness_land_right = b.translate(b.flip_x(wilderness_land), (width_1 + width_2) / 2, 0) local wilderness_ditch = b.line_y(width_3) wilderness_ditch = b.if_else(b.change_tile(b.translate(b.line_y(width_3 - 1), -1, 0), true, 'out-of-map'), wilderness_ditch) -wilderness_ditch = b.if_else(b.change_tile(b.rectangle(3, 17), true, 'landfill'), wilderness_ditch) +wilderness_ditch = b.if_else(b.change_tile(b.translate(b.rectangle(2, 17), -1, 0), true, 'landfill'), wilderness_ditch) local rocket_silo_shape = b.rectangle(9, 9) rocket_silo_shape = b.change_tile(rocket_silo_shape, true, 'landfill') wilderness_ditch = b.if_else(rocket_silo_shape, wilderness_ditch) diff --git a/map_gen/maps/space_race/scenario.lua b/map_gen/maps/space_race/scenario.lua index c03130f3..3445a271 100644 --- a/map_gen/maps/space_race/scenario.lua +++ b/map_gen/maps/space_race/scenario.lua @@ -67,7 +67,7 @@ local primitives = { Global.register( { - primitives = primitives, + primitives = primitives }, function(tbl) primitives = tbl.primitives @@ -123,17 +123,21 @@ Event.on_init( silo.minable = false local wall - wall = surface.create_entity{name = 'stone-wall', position = {x = 384.5, y = 18.5}, always_place = true, force = 'neutral'} + wall = surface.create_entity {name = 'stone-wall', position = {x = 384.5, y = 18.5}, always_place = true, force = 'neutral'} wall.destructible = false + wall.minable = false - wall = surface.create_entity{name = 'stone-wall', position = {x = 384.5, y = -17.5}, always_place = true, force = 'neutral'} + wall = surface.create_entity {name = 'stone-wall', position = {x = 384.5, y = -17.5}, always_place = true, force = 'neutral'} wall.destructible = false + wall.minable = false - wall = surface.create_entity{name = 'stone-wall', position = {x = -384.5, y = 18.5}, always_place = true, force = 'neutral'} + wall = surface.create_entity {name = 'stone-wall', position = {x = -384.5, y = 18.5}, always_place = true, force = 'neutral'} wall.destructible = false + wall.minable = false - wall = surface.create_entity{name = 'stone-wall', position = {x = -384.5, y = -17.5}, always_place = true, force = 'neutral'} + wall = surface.create_entity {name = 'stone-wall', position = {x = -384.5, y = -17.5}, always_place = true, force = 'neutral'} wall.destructible = false + wall.minable = false local gun_turret gun_turret = surface.create_entity {name = 'gun-turret', position = {x = 383, y = 0}, force = force_USSR} @@ -257,6 +261,24 @@ local function restore_character(player) end end +local tiles = {} + +local out_of_map_x = 388 +local out_of_map_height = 512 +local ignored_height = 18 +local insert = table.insert + +for i = -out_of_map_height / 2, out_of_map_height / 2, 1 do + if i < -ignored_height / 2 or i > ignored_height / 2 then + insert(tiles, {name = 'out-of-map', position = {x = out_of_map_x + 1, y = i}}) + insert(tiles, {name = 'out-of-map', position = {x = -(out_of_map_x + 1), y = i}}) + insert(tiles, {name = 'out-of-map', position = {x = out_of_map_x - 1, y = i}}) + insert(tiles, {name = 'out-of-map', position = {x = -(out_of_map_x - 1), y = i}}) + insert(tiles, {name = 'out-of-map', position = {x = out_of_map_x, y = i}}) + insert(tiles, {name = 'out-of-map', position = {x = -(out_of_map_x), y = i}}) + end +end + local function start_game() primitives.game_started = true primitives.started_tick = game.tick @@ -267,7 +289,9 @@ local function start_game() for _, player in pairs(primitives.force_USSR.players) do restore_character(player) end - cliff.generate_cliffs(RS.get_surface()) + local surface = RS.get_surface() + cliff.generate_cliffs(surface) + surface.set_tiles(tiles) end local function victory(force) @@ -413,10 +437,7 @@ local function check_ready_to_start() Event.add_removable_nth_tick(60, check_map_gen_is_done) end else - local message = primitives.force_USA.name .. - ' has ' .. - num_usa_players .. - ' players\n ' .. primitives.force_USSR.name .. ' has ' .. num_ussr_players .. ' players\n\n' .. players_needed - num_players .. ' more players needed to start!' + local message = primitives.force_USA.name .. ' has ' .. num_usa_players .. ' players\n ' .. primitives.force_USSR.name .. ' has ' .. num_ussr_players .. ' players\n\n' .. players_needed - num_players .. ' more players needed to start!' load_gui.show_gui_to_all(message) end end @@ -486,8 +507,8 @@ local function print_player_num(_, player) local force_USA = primitives.force_USA local force_USSR = primitives.force_USSR - player.print('West: ' .. #force_USA.connected_players ..' online /' .. #force_USA.players .. ' total') - player.print('East: ' .. #force_USSR.connected_players ..' online /' .. #force_USSR.players .. ' total') + player.print('West: ' .. #force_USA.connected_players .. ' online /' .. #force_USA.players .. ' total') + player.print('East: ' .. #force_USSR.connected_players .. ' online /' .. #force_USSR.players .. ' total') end Command.add('team_players', {description = 'Use to get number of players on both teams', capture_excess_arguments = false, allowed_by_server = false}, print_player_num)