From 528f5404bcf523a37a7748009a3cbbf5424df2ce Mon Sep 17 00:00:00 2001 From: MewMew Date: Sat, 4 Apr 2020 00:40:04 +0200 Subject: [PATCH] update --- control.lua | 3 +- functions/random_room.lua | 51 ++++++++++++++++----- maps/dungeons.lua | 93 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 131 insertions(+), 16 deletions(-) diff --git a/control.lua b/control.lua index 58e591ff..80c37a58 100644 --- a/control.lua +++ b/control.lua @@ -63,7 +63,6 @@ require "modules.autostash" --require "modules.biter_reanimator" --require "modules.wave_defense.main" --require "modules.fjei.main" ---require "utils.one_dimensional_noise" ----------------------------- ---- enable maps here ---- (maps higher up in the list may be more actually playable) @@ -106,6 +105,7 @@ require "modules.autostash" --require "maps.spiral_troopers" --require "maps.refactor-io" --require "maps.desert_oasis" +--require "maps.dungeons" --require "maps.lost_desert" --require "maps.stoneblock" --require "maps.wave_defense" @@ -131,6 +131,7 @@ require "modules.autostash" --require "terrain_layouts.biters_and_resources_east" --require "terrain_layouts.scrap_01" --require "terrain_layouts.watery_world" +--require "terrain_layouts.tree_01" ------ if _DUMP_ENV then diff --git a/functions/random_room.lua b/functions/random_room.lua index 4465f25c..dfbdb5fd 100644 --- a/functions/random_room.lua +++ b/functions/random_room.lua @@ -39,6 +39,8 @@ local function build_room(surface, position, vector, room_center_position, room_ table_insert(t, surface.get_tile({left_top.x + room_radius * 2, left_top.y + room_radius * 2})) table_insert(t, surface.get_tile({right_bottom.x - (room_radius * 2), right_bottom.y - (room_radius * 2)})) + room.center = room_center_position + return room end @@ -92,6 +94,28 @@ local function get_room_tiles(surface, position, room_radius) end end +local function is_bridge_valid(surface, vector, room) + local bridge_tiles = room.path_tiles + local scan_vector + if vector[1] == 0 then + scan_vector = {1, 0} + else + scan_vector = {0, 1} + end + + for _, tile in pairs(bridge_tiles) do + for d = -5, 5, 1 do + local p = {tile.position.x + scan_vector[1] * d, tile.position.y + scan_vector[2] * d} + local tile = surface.get_tile(p) + if not tile.collides_with("resource-layer") then + return + end + end + end + + return true +end + local function build_bridge(surface, position) local vectors = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}} table_shuffle_table(vectors) @@ -101,9 +125,9 @@ local function build_bridge(surface, position) room.room_border_tiles = {} room.room_tiles = {} - local a = room_spacing * 2 - - for _, v in pairs(vectors) do + local a = room_spacing * 3 + + for _, v in pairs(vectors) do for d = 1, a, 1 do local p = {position.x + v[1] * d, position.y + v[2] * d} local tile = surface.get_tile(p) @@ -113,19 +137,26 @@ local function build_bridge(surface, position) table_insert(room.path_tiles, tile) if d == a then room.path_tiles = {} end end - if room.path_tiles[1] then return room end - end + if room.path_tiles[1] then + if is_bridge_valid(surface, v, room) then + return room + else + room.path_tiles = {} + end + end + end + end function Public.get_room(surface, position) local room_sizes = {} - for i = 1, 13, 1 do + for i = 1, 9, 1 do room_sizes[i] = i + 1 end table_shuffle_table(room_sizes) local last_size = room_sizes[1] - for i = 1, 13, 1 do + for i = 1, #room_sizes, 1 do if room_sizes[i] <= last_size then last_size = room_sizes[i] local room = get_room_tiles(surface, position, last_size) @@ -134,9 +165,7 @@ function Public.get_room(surface, position) end end end - - if math_random(1, 2) == 1 then return end - + local room = build_bridge(surface, position) if room then return room end end @@ -151,7 +180,7 @@ function Public.draw_random_room(surface, position) for _, tile in pairs(room.room_border_tiles) do surface.set_tiles({{name = "dirt-7", position = tile.position}}, true) - if math_random(1, 8) == 1 then + if math_random(1, 2) == 1 then surface.create_entity({name = "rock-big", position = tile.position}) end end diff --git a/maps/dungeons.lua b/maps/dungeons.lua index 61629469..74e63d15 100644 --- a/maps/dungeons.lua +++ b/maps/dungeons.lua @@ -1,9 +1,33 @@ --lost-- mewmew made this -- local Rooms = require "functions.random_room" +require "modules.mineable_wreckage_yields_scrap" + +local table_shuffle_table = table.shuffle_table local table_insert = table.insert +local table_remove = table.remove local math_random = math.random +local ores = {"iron-ore", "iron-ore", "iron-ore", "iron-ore", "copper-ore", "copper-ore", "copper-ore","coal", "coal","stone", "stone","uranium-ore"} +local trees = {"dead-dry-hairy-tree", "dead-grey-trunk", "dead-tree-desert", "dry-hairy-tree", "dry-tree"} +local size_of_trees = #trees + +local tile_sets = { + {"dirt-3", "dirt-7", "dirt-5"}, + {"dirt-3", "dirt-7", "dirt-5"}, + {"dirt-3", "dirt-7", "dirt-5"}, + {"dirt-3", "dirt-7", "dirt-5"}, + {"dirt-3", "dirt-7", "dirt-5"}, + {"dirt-3", "dirt-7", "dirt-5"}, + {"dirt-3", "dirt-7", "dirt-5"}, + {"lab-white", "lab-dark-2", "lab-dark-1"}, + {"red-desert-1", "red-desert-3", "red-desert-2"}, + {"grass-1", "grass-3", "grass-2"}, + {"sand-2", "sand-1", "sand-3"}, + {"concrete", "refined-concrete", "stone-path"}, +} +local size_of_tile_sets = #tile_sets + local disabled_for_deconstruction = { ["fish"] = true, ["rock-huge"] = true, @@ -12,9 +36,60 @@ local disabled_for_deconstruction = { ["mineable-wreckage"] = true } -local function on_chunk_generated(event) - local left_top = event.area.left_top +local function expand(surface, room) + local tile_set = tile_sets[math_random(1, size_of_tile_sets)] + for _, tile in pairs(room.path_tiles) do + surface.set_tiles({{name = tile_set[1], position = tile.position}}, true) + end + + if #room.room_border_tiles > 1 then table_shuffle_table(room.room_border_tiles) end + for key, tile in pairs(room.room_border_tiles) do + surface.set_tiles({{name = tile_set[2], position = tile.position}}, true) + if key < 5 then + surface.create_entity({name = "rock-big", position = tile.position}) + end + end + + if #room.room_tiles > 1 then table_shuffle_table(room.room_tiles) end + for key, tile in pairs(room.room_tiles) do + surface.set_tiles({{name = tile_set[3], position = tile.position}}, true) + if math_random(1, 64) == 1 then + surface.create_entity({name = ores[math_random(1, #ores)], position = tile.position, amount = math_random(100, 20000)}) + else + if math_random(1, 128) == 1 then + surface.create_entity({name = trees[math_random(1, size_of_trees)], position = tile.position}) + end + end + if key % 128 == 1 and math_random(1, 2) == 1 then + surface.create_entity({name = "biter-spawner", position = tile.position}) + end + if key % 128 == 1 and math_random(1, 3) == 1 then + surface.create_entity({name = "small-worm-turret", position = tile.position}) + end + if math_random(1, 64) == 1 then + surface.create_entity({name = "mineable-wreckage", position = tile.position}) + end + if math_random(1, 256) == 1 then + surface.create_entity({name = "rock-huge", position = tile.position}) + end + end + + if room.center then + if math_random(1, 16) == 1 then + for x = -1, 1, 1 do + for y = -1, 1, 1 do + local p = {room.center.x + x, room.center.y + y} + surface.set_tiles({{name = "water", position = p}}) + surface.create_entity({name = "fish", position = p}) + end + end + else + if math_random(1, 16) == 1 then + surface.create_entity({name = "crude-oil", position = room.center, amount = math_random(200000, 400000)}) + end + end + end end local function on_player_joined_game(event) @@ -22,15 +97,22 @@ local function on_player_joined_game(event) local surface = game.surfaces["dungeons"] if player.online_time == 0 then player.teleport(surface.find_non_colliding_position("character", {0, 0}, 50, 0.5), surface) + player.insert({name = "raw-fish", count = 10}) end end local function on_player_mined_entity(event) local entity = event.entity if not entity.valid then return end + + if entity.name ~= "rock-big" then return end + local surface = entity.surface - Rooms.draw_random_room(surface, entity.position) + local room = Rooms.get_room(surface, entity.position) + if room then + expand(surface, room) + end end local function on_marked_for_deconstruction(event) @@ -58,11 +140,14 @@ local function on_init() surface.delete_chunk({chunk.x, chunk.y}) end - game.forces.player.manual_mining_speed_modifier = 10 + --game.forces.player.manual_mining_speed_modifier = 10 + + global.terrain_work = {} end local Event = require 'utils.event' Event.on_init(on_init) +Event.add(defines.events.on_tick, on_tick) Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction) Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)