From 379cbd3750c1a118d3692bbdedac09a81455b6d7 Mon Sep 17 00:00:00 2001 From: MewMew Date: Sat, 4 Apr 2020 04:55:05 +0200 Subject: [PATCH] wip update --- control.lua | 2 +- .../{random_room.lua => room_generator.lua} | 2 +- maps/dungeons/biome_dirtlands.lua | 78 ++++++++++++ maps/dungeons/biome_glitch.lua | 70 +++++++++++ maps/dungeons/biome_grasslands.lua | 74 +++++++++++ maps/{dungeons.lua => dungeons/main.lua} | 117 ++++++------------ 6 files changed, 263 insertions(+), 80 deletions(-) rename functions/{random_room.lua => room_generator.lua} (99%) create mode 100644 maps/dungeons/biome_dirtlands.lua create mode 100644 maps/dungeons/biome_glitch.lua create mode 100644 maps/dungeons/biome_grasslands.lua rename maps/{dungeons.lua => dungeons/main.lua} (52%) diff --git a/control.lua b/control.lua index 80c37a58..a887411e 100644 --- a/control.lua +++ b/control.lua @@ -105,7 +105,7 @@ require "modules.autostash" --require "maps.spiral_troopers" --require "maps.refactor-io" --require "maps.desert_oasis" ---require "maps.dungeons" +--require "maps.dungeons.main" --require "maps.lost_desert" --require "maps.stoneblock" --require "maps.wave_defense" diff --git a/functions/random_room.lua b/functions/room_generator.lua similarity index 99% rename from functions/random_room.lua rename to functions/room_generator.lua index dfbdb5fd..b11e5a63 100644 --- a/functions/random_room.lua +++ b/functions/room_generator.lua @@ -150,7 +150,7 @@ end function Public.get_room(surface, position) local room_sizes = {} - for i = 1, 9, 1 do + for i = 1, 11, 1 do room_sizes[i] = i + 1 end table_shuffle_table(room_sizes) diff --git a/maps/dungeons/biome_dirtlands.lua b/maps/dungeons/biome_dirtlands.lua new file mode 100644 index 00000000..333d6afc --- /dev/null +++ b/maps/dungeons/biome_dirtlands.lua @@ -0,0 +1,78 @@ +local table_shuffle_table = table.shuffle_table +local table_insert = table.insert +local table_remove = table.remove +local math_random = math.random +local math_abs = math.abs + +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 worms = {} +for _ = 1, 64, 1 do table_insert(worms, "small") end +for _ = 1, 8, 1 do table_insert(worms, "medium") end +for _ = 1, 4, 1 do table_insert(worms, "big") end +for _ = 1, 1, 1 do table_insert(worms, "behemoth") end +local size_of_worms = #worms + +local function dirtlands(surface, room) + local path_tile = "dirt-" .. math_random(1, 3) + for _, tile in pairs(room.path_tiles) do + surface.set_tiles({{name = path_tile, 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 = "dirt-4", position = tile.position}}, true) + if key < 6 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 = "dirt-7", 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 == 0 and math_random(1, 2) == 1 then + surface.create_entity({name = "biter-spawner", position = tile.position}) + end + if math_random(1, 256) == 1 then + local turret_name = worms[math_random(1, size_of_worms)] .. "-worm-turret" + surface.create_entity({name = turret_name, position = tile.position}) + end + if math_random(1, 512) == 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}}) + if math_random(1, 4) == 1 then + surface.create_entity({name = "fish", position = p}) + end + 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 + if math_random(1, 2) == 1 then + surface.create_entity({name = "biter-spawner", position = room.center}) + end + end + end +end + +return dirtlands \ No newline at end of file diff --git a/maps/dungeons/biome_glitch.lua b/maps/dungeons/biome_glitch.lua new file mode 100644 index 00000000..3e49955f --- /dev/null +++ b/maps/dungeons/biome_glitch.lua @@ -0,0 +1,70 @@ +local table_shuffle_table = table.shuffle_table +local table_insert = table.insert +local table_remove = table.remove +local math_random = math.random +local math_abs = math.abs + +local ores = {"iron-ore", "iron-ore", "iron-ore", "iron-ore", "copper-ore", "copper-ore", "copper-ore","coal", "coal", "stone", "stone","uranium-ore"} +local worms = {} +for _ = 1, 64, 1 do table_insert(worms, "small") end +for _ = 1, 8, 1 do table_insert(worms, "medium") end +for _ = 1, 4, 1 do table_insert(worms, "big") end +for _ = 1, 1, 1 do table_insert(worms, "behemoth") end +local size_of_worms = #worms + +local function grasslands(surface, room) + for _, tile in pairs(room.path_tiles) do + surface.set_tiles({{name = "lab-white", position = tile.position}}, true) + end + + if not room.room_border_tiles[1] then return end + + table_shuffle_table(room.room_border_tiles) + for key, tile in pairs(room.room_border_tiles) do + surface.set_tiles({{name = "lab-dark-2", position = tile.position}}, true) + if key < 7 then + surface.create_entity({name = "rock-big", position = tile.position}) + end + end + + table_shuffle_table(room.room_tiles) + for key, tile in pairs(room.room_tiles) do + surface.set_tiles({{name = "lab-dark-1", position = tile.position}}, true) + if math_random(1, 8) == 1 then + surface.create_entity({name = ores[math_random(1, #ores)], position = tile.position, amount = math_random(100, 20000)}) + end + if key % 32 == 0 and math_random(1, 2) == 1 then + surface.create_entity({name = "biter-spawner", position = tile.position}) + end + if math_random(1, 64) == 1 then + local turret_name = worms[math_random(1, size_of_worms)] .. "-worm-turret" + surface.create_entity({name = turret_name, position = tile.position}) + end + if math_random(1, 2048) == 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}}) + if math_random(1, 4) == 1 then + surface.create_entity({name = "fish", position = p}) + end + end + end + else + if math_random(1, 8) == 1 then + surface.create_entity({name = "crude-oil", position = room.center, amount = math_random(200000, 400000)}) + end + if math_random(1, 2) == 1 then + surface.create_entity({name = "biter-spawner", position = room.center}) + end + end + end +end + +return grasslands \ No newline at end of file diff --git a/maps/dungeons/biome_grasslands.lua b/maps/dungeons/biome_grasslands.lua new file mode 100644 index 00000000..c98bbe66 --- /dev/null +++ b/maps/dungeons/biome_grasslands.lua @@ -0,0 +1,74 @@ +local table_shuffle_table = table.shuffle_table +local table_insert = table.insert +local table_remove = table.remove +local math_random = math.random +local math_abs = math.abs +local math_sqrt = math.sqrt + +local ores = {"iron-ore", "iron-ore", "iron-ore", "iron-ore", "copper-ore", "copper-ore", "copper-ore","coal", "coal", "stone", "stone"} +local trees = {"tree-01", "tree-02", "tree-03", "tree-04", "tree-05"} +local size_of_trees = #trees +local worms = {} +for _ = 1, 64, 1 do table_insert(worms, "small") end +for _ = 1, 8, 1 do table_insert(worms, "medium") end +for _ = 1, 4, 1 do table_insert(worms, "big") end +for _ = 1, 1, 1 do table_insert(worms, "behemoth") end +local size_of_worms = #worms + +local function grasslands(surface, room) + for _, tile in pairs(room.path_tiles) do + surface.set_tiles({{name = "grass-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 = "grass-3", position = tile.position}}, true) + if key < 9 then + surface.create_entity({name = "rock-big", position = tile.position}) + else + if math_random(1, 8) == 1 then + surface.create_entity({name = trees[math_random(1, size_of_trees)], position = tile.position}) + end + 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 = "grass-2", 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, 24) == 1 then + surface.create_entity({name = trees[math_random(1, size_of_trees)], position = tile.position}) + end + end + if math_random(1, 320) == 1 then + local turret_name = worms[math_random(1, size_of_worms)] .. "-worm-turret" + surface.create_entity({name = turret_name, position = tile.position}) + end + if math_random(1, 1024) == 1 then + surface.create_entity({name = "rock-huge", position = tile.position}) + end + end + + if room.center then + if math_random(1, 7) == 1 then + local r = math_floor(math_sqrt(#room.room_tiles)) + 1 + for x = r * -1, r, 1 do + for y = r * -1, r, 1 do + local p = {room.center.x + x, room.center.y + y} + surface.set_tiles({{name = "water", position = p}}) + if math_random(1, 4) == 1 then + surface.create_entity({name = "fish", position = p}) + end + end + end + else + if math_random(1, 2) == 1 then + surface.create_entity({name = "biter-spawner", position = room.center}) + end + end + end +end + +return grasslands \ No newline at end of file diff --git a/maps/dungeons.lua b/maps/dungeons/main.lua similarity index 52% rename from maps/dungeons.lua rename to maps/dungeons/main.lua index 8ca11e52..d9c1f5e8 100644 --- a/maps/dungeons.lua +++ b/maps/dungeons/main.lua @@ -1,33 +1,28 @@ ---lost-- mewmew made this -- +-- Deep dark dungeons by mewmew -- -local Rooms = require "functions.random_room" require "modules.mineable_wreckage_yields_scrap" +local Room_generator = require "functions.room_generator" + +local Biomes = {} +Biomes.dirtlands = require "maps.dungeons.biome_dirtlands" +Biomes.grasslands = require "maps.dungeons.biome_grasslands" +Biomes.glitch = require "maps.dungeons.biome_glitch" + +local Get_noise = require "utils.get_noise" + local table_shuffle_table = table.shuffle_table local table_insert = table.insert local table_remove = table.remove local math_random = math.random local math_abs = math.abs -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, @@ -37,60 +32,24 @@ local disabled_for_deconstruction = { ["mineable-wreckage"] = true } -local function expand(surface, room) - local tile_set = tile_sets[math_random(1, size_of_tile_sets)] +local function get_biome(position) + local seed = game.surfaces[1].map_gen_settings.seed + local seed_addition = 100000 - for _, tile in pairs(room.path_tiles) do - surface.set_tiles({{name = tile_set[1], position = tile.position}}, true) - end + if Get_noise("cave_ponds", position, seed + seed_addition) > 0.25 then return "grasslands" end + if Get_noise("cave_ponds", position, seed + seed_addition * 2) > 0.5 then return "glitch" 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 + return "dirtlands" +end + +local function expand(surface, position) + local room = Room_generator.get_room(surface, position) + if not room then return end + local name = get_biome(position) + Biomes[name](surface, room) - 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 + if not room.room_tiles[1] then return end + global.dungeons.depth = global.dungeons.depth + 1 end local function on_chunk_generated(event) @@ -105,6 +64,14 @@ local function on_chunk_generated(event) if math_abs(position.x) > 2 or math_abs(position.y) > 2 then tiles[i] = {name = "out-of-map", position = position} i = i + 1 + else + if math_abs(position.x) > 1 or math_abs(position.y) > 1 then + tiles[i] = {name = "black-refined-concrete", position = position} + i = i + 1 + else + tiles[i] = {name = "purple-refined-concrete", position = position} + i = i + 1 + end end end end @@ -129,16 +96,9 @@ end local function on_player_mined_entity(event) local entity = event.entity - if not entity.valid then return end - + if not entity.valid then return end if entity.name ~= "rock-big" then return end - - local surface = entity.surface - - local room = Rooms.get_room(surface, entity.position) - if room then - expand(surface, room) - end + expand(entity.surface, entity.position) end local function on_marked_for_deconstruction(event) @@ -173,9 +133,10 @@ 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 = 20 - global.terrain_work = {} + global.dungeons = {} + global.dungeons.depth = 0 end local Event = require 'utils.event'