From e773be220b9b1d42aeadb4619425489c13a90b7b Mon Sep 17 00:00:00 2001 From: MewMew Date: Fri, 9 Aug 2019 18:01:07 +0200 Subject: [PATCH] new map --- control.lua | 4 +- functions/maze.lua | 28 ++++++----- maps/maze_challenge.lua | 107 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 13 deletions(-) create mode 100644 maps/maze_challenge.lua diff --git a/control.lua b/control.lua index 52a72e82..4a5d8b4c 100644 --- a/control.lua +++ b/control.lua @@ -6,6 +6,7 @@ _DUMP_ENV = false server_commands = require 'utils.server' require "utils.server_commands" require "utils.utils" +require "utils.table" require "utils.corpse_util" --disable for hunger games require "utils.color_data" require "utils.session_data" @@ -60,8 +61,9 @@ require "modules.floaty_chat" --require "maps.fish_defender.fish_defender" --require "maps.wave_of_death.WoD" --require "maps.stone_maze.main" +require "maps.maze_challenge" --require "maps.cave_miner" -require "maps.rocky_waste" +--require "maps.rocky_waste" --require "maps.labyrinth" --require "maps.junkyard" --require "maps.spooky_forest" diff --git a/functions/maze.lua b/functions/maze.lua index c452a199..17d20d66 100644 --- a/functions/maze.lua +++ b/functions/maze.lua @@ -4,33 +4,37 @@ local function coord_string(x, y) return str end -local function draw_cell(surface, cell, cell_size, wall_entity_name) +local function draw_cell(surface, cell, cell_size, wall_entity_name, force_name) local r = math.floor(cell_size * 0.5) + local entities = {} if cell.north then for x = r * -1, r, 1 do - surface.create_entity({position = {cell.position.x + x, cell.position.y - r}, name = wall_entity_name}) + entities[#entities + 1] = {position = {cell.position.x + x, cell.position.y - r}, name = wall_entity_name, force = force_name} end end if cell.south then for x = r * -1, r, 1 do - surface.create_entity({position = {cell.position.x + x, cell.position.y + r}, name = wall_entity_name}) + entities[#entities + 1] = {position = {cell.position.x + x, cell.position.y + r}, name = wall_entity_name, force = force_name} end end if cell.east then for y = r * -1, r, 1 do - surface.create_entity({position = {cell.position.x + r, cell.position.y + y}, name = wall_entity_name}) + entities[#entities + 1] = {position = {cell.position.x + r, cell.position.y + y}, name = wall_entity_name, force = force_name} end end if cell.west then for y = r * -1, r, 1 do - surface.create_entity({position = {cell.position.x - r, cell.position.y - y}, name = wall_entity_name}) + entities[#entities + 1] = {position = {cell.position.x - r, cell.position.y - y}, name = wall_entity_name, force = force_name} end end + for _, e in pairs(entities) do + surface.create_entity(e) + end end -local function draw_maze(surface, position, size, cell_size, wall_entity_name) +local function draw_maze(surface, position, size, cell_size, wall_entity_name, force_name) for _, cell in pairs(maze_cells) do - draw_cell(surface, cell, cell_size, wall_entity_name) + draw_cell(surface, cell, cell_size, wall_entity_name, force_name) end end @@ -106,7 +110,7 @@ local function expand(size) end end -function create_maze(surface, position, size, cell_size, wall_entity_name) +function create_maze(surface, position, size, cell_size, wall_entity_name, force_name) if not surface then game.print("No surface given.") return end if not position then game.print("No position given.") return end if not size then game.print("No size given.") return end @@ -130,11 +134,11 @@ function create_maze(surface, position, size, cell_size, wall_entity_name) end end - maze_cells[coord_string(size, size)].occupied = true - maze_cells[coord_string(size, size)].south = false - maze_cells[coord_string(size * -1, size * -1)].north = false + maze_cells[coord_string(size * -1, 0)].occupied = true + maze_cells[coord_string(size * -1, 0)].west = false + maze_cells[coord_string(size, 0)].east = false expand(size) - draw_maze(surface, position, size, cell_size, wall_entity_name) + draw_maze(surface, position, size, cell_size, wall_entity_name, force_name) end \ No newline at end of file diff --git a/maps/maze_challenge.lua b/maps/maze_challenge.lua new file mode 100644 index 00000000..1435f392 --- /dev/null +++ b/maps/maze_challenge.lua @@ -0,0 +1,107 @@ +require "functions.maze" + +local event = require 'utils.event' + +local function init_surface() + if game.surfaces["maze_challenge"] then return game.surfaces["maze_challenge"] end + + local map_gen_settings = {} + map_gen_settings.water = "0" + map_gen_settings.starting_area = "2.5" + map_gen_settings.cliff_settings = {cliff_elevation_interval = 0, cliff_elevation_0 = 0} + map_gen_settings.autoplace_controls = { + ["coal"] = {frequency = "0", size = "7", richness = "1"}, + ["stone"] = {frequency = "0", size = "2.0", richness = "0.5"}, + ["iron-ore"] = {frequency = "0", size = "2.0", richness = "0.5"}, + ["copper-ore"] = {frequency = "0", size = "2.0", richness = "0.5"}, + ["uranium-ore"] = {frequency = "0", size = "1", richness = "0.5"}, + ["crude-oil"] = {frequency = "0", size = "1", richness = "1"}, + ["trees"] = {frequency = "0", size = "0.75", richness = "1"}, + ["enemy-base"] = {frequency = "0", size = "1", richness = "1"} + } + + game.map_settings.enemy_expansion.enabled = false + game.difficulty_settings.technology_price_multiplier = 2 + + local surface = game.create_surface("maze_challenge", map_gen_settings) + surface.request_to_generate_chunks({x = 0, y = 0}, 2) + surface.force_generate_chunk_requests() + surface.daytime = 0.7 + surface.freeze_daytime = 1 + + game.forces["player"].set_spawn_position({0,0},game.surfaces["maze_challenge"]) + + global.maze_size = 3 + global.grid_size = 3 + + return surface +end + +local function maze(event) + --local position = event.area.left_top + local position = {x = event.position.x * 32, y = event.position.y * 32} + + if position.y ~= 0 then return end + if position.x < 32 then return end + + --local surface = event.surface + local surface = game.surfaces[event.surface_index] + + local r = global.maze_size * global.grid_size * 0.8 + if surface.count_entities_filtered({force = "enemy", area = {{position.x - r, position.y - r}, {position.x + r, position.y + r}}}) ~= 0 then return end + + surface.request_to_generate_chunks(position, math.ceil(global.maze_size / global.grid_size)) + surface.force_generate_chunk_requests() + + for x = global.maze_size * - 1 * (global.grid_size - 1), global.maze_size * (global.grid_size - 1), 1 do + for y = global.maze_size * - 1 * (global.grid_size - 1), global.maze_size * (global.grid_size - 1), 1 do + surface.set_tiles({{name = "sand-1", position = {position.x + x, position.y + y}}}, true) + end + end + + create_maze(surface, position, global.maze_size, global.grid_size, "stone-wall", "enemy") + global.maze_size = global.maze_size + 1 + + for _, e in pairs(surface.find_entities_filtered({force = "player", name = "character", area = {{position.x - r, position.y - r}, {position.x + r, position.y + r}}})) do + e.player.teleport(surface.find_non_colliding_position("rocket-silo", position, 1024, 1), "maze_challenge") + end +end + +local function on_player_joined_game(event) + local surface = init_surface() + local player = game.players[event.player_index] + + if player.online_time == 0 then + player.teleport({0,0}, "maze_challenge") + player.insert({name = 'car', count = 1}) + player.insert({name = 'small-lamp', count = 1}) + end +end + +local function on_chunk_generated(event) + for _, e in pairs(event.surface.find_entities_filtered({area = event.area, force = "neutral"})) do + e.destroy() + end + + for _, t in pairs(event.surface.find_tiles_filtered({area = event.area})) do + if t.position.y < -3 or t.position.y > 3 then + event.surface.set_tiles({{name = "out-of-map", position = t.position}}, true) + else + if t.name == "water" or t.name == "deepwater" then + event.surface.set_tiles({{name = "sand-1", position = t.position}}, true) + end + end + end +end + +local function on_chunk_charted(event) + if not global.chunks_charted then global.chunks_charted = {} end + local position = event.position + if global.chunks_charted[tostring(position.x) .. tostring(position.y)] then return end + global.chunks_charted[tostring(position.x) .. tostring(position.y)] = true + maze(event) +end + +event.add(defines.events.on_chunk_charted, on_chunk_charted) +event.add(defines.events.on_chunk_generated, on_chunk_generated) +event.add(defines.events.on_player_joined_game, on_player_joined_game) \ No newline at end of file