From 64ea71db6e28820eaf2c8f7eedb6abbaa85af2f2 Mon Sep 17 00:00:00 2001 From: MewMew <=> Date: Thu, 14 Mar 2019 01:00:20 +0100 Subject: [PATCH] biter_battles_v2 update --- control.lua | 4 +- maps/biter_battles/biter_battles.lua | 13 ++++ maps/biter_battles_v2/biter_battles_v2.lua | 3 +- maps/biter_battles_v2/terrain.lua | 79 +++++++++++++++------- 4 files changed, 72 insertions(+), 27 deletions(-) diff --git a/control.lua b/control.lua index ae88af08..8e78002f 100644 --- a/control.lua +++ b/control.lua @@ -19,7 +19,7 @@ require "score" require "on_tick_schedule" ---- enable modules here ---- ---require "tools.cheat_mode" +require "tools.cheat_mode" --require "modules.hunger" --require "modules.area_unlocked_on_rotated_entity" --require "modules.fish_respawner" @@ -40,7 +40,7 @@ require "on_tick_schedule" ----------------------------- ---- enable maps here ---- -require "maps.biter_battles_v2.biter_battles_v2" +--require "maps.biter_battles_v2.biter_battles_v2" --require "maps.biter_battles" --require "maps.cave_miner" --require "maps.labyrinth" diff --git a/maps/biter_battles/biter_battles.lua b/maps/biter_battles/biter_battles.lua index 86a02f50..5cf378e2 100644 --- a/maps/biter_battles/biter_battles.lua +++ b/maps/biter_battles/biter_battles.lua @@ -1460,11 +1460,24 @@ local function on_player_built_tile(event) end end +local function on_robot_built_tile(event) + local surface = event.robot.surface + for _, t in pairs(event.tiles) do + local distance_to_center = math.sqrt(t.position.x ^ 2 + t.position.y ^ 2) + if generate_horizontal_river(surface, t.position) or distance_to_center < spawn_circle_size then + surface.set_tiles({{name = t.old_tile, position = t.position}}, true) + local inventory = event.robot.get_inventory(defines.inventory.robot_cargo) + inventory.insert({name = "landfill", count = 1}) + end + end +end + local function on_research_finished(event) --game.forces.north.recipes["flamethrower-turret"].enabled = false --game.forces.south.recipes["flamethrower-turret"].enabled = false end +event.add(defines.events.on_robot_built_tile, on_robot_built_tile) event.add(defines.events.on_chunk_generated, on_chunk_generated) event.add(defines.events.on_research_finished, on_research_finished) event.add(defines.events.on_built_entity, on_built_entity) diff --git a/maps/biter_battles_v2/biter_battles_v2.lua b/maps/biter_battles_v2/biter_battles_v2.lua index 17832848..9e97be99 100644 --- a/maps/biter_battles_v2/biter_battles_v2.lua +++ b/maps/biter_battles_v2/biter_battles_v2.lua @@ -25,7 +25,8 @@ local function init_surface(event) ["trees"] = {frequency = "0.8", size = "0.5", richness = "0.3"}, ["enemy-base"] = {frequency = "0.8", size = "1", richness = "0.4"} } - game.create_surface("biter_battles", map_gen_settings) + --game.create_surface("biter_battles", map_gen_settings) + end local function on_player_joined_game(event) diff --git a/maps/biter_battles_v2/terrain.lua b/maps/biter_battles_v2/terrain.lua index 2039202d..036ff487 100644 --- a/maps/biter_battles_v2/terrain.lua +++ b/maps/biter_battles_v2/terrain.lua @@ -2,7 +2,8 @@ local event = require 'utils.event' local math_random = math.random local simplex_noise = require 'utils.simplex_noise'.d2 -local biter_territory_starting_radius = 160 +local biter_territory_starting_radius = 256 +local spawn_circle_size = 30 local worms = { [1] = {"small-worm-turret"}, @@ -68,29 +69,28 @@ local function generate_biters(surface, pos, distance_to_center) end end -local function generate_horizontal_river(surface, pos, distance_to_center) - if pos.y < -32 then return end - if -14 > pos.y + (get_noise(1, pos) * 5) then return true end +local function generate_horizontal_river(surface, pos) + if pos.y < -32 then return false end + if -14 < pos.y + (get_noise(1, pos) * 5) then return true end + return false end -local function generate_circle_spawn(surface, pos, distance_to_center) +local function generate_circle_spawn(surface) + for x = -33, 33, 1 do + for y = -33, 33, 1 do + local distance_to_center = math.sqrt(x ^ 2 + y ^ 2) + local pos = {x = x, y = y} + local tile = false + if distance_to_center < spawn_circle_size then tile = "deepwater" end + if distance_to_center < 10 then tile = "refined-concrete" end + if distance_to_center < 7 then tile = "sand-1" end + if tile then surface.set_tiles({{name = tile, position = pos}}, true) end + end + end +end + +local function generate_silos() - if pos.y < -64 then return end - if pos.x > 64 then return end - if pos.x < -64 then return end - - if distance_to_center < 8 then - surface.set_tiles({{name = "sand-1", position = pos}}) - return - end - if distance_to_center < 12 then - surface.set_tiles({{name = "refined-concrete", position = pos}}) - return - end - if distance_to_center < 32 then - surface.set_tiles({{name = "deepwater", position = pos}}) - return - end end local function on_chunk_generated(event) @@ -107,12 +107,43 @@ local function on_chunk_generated(event) for y = 0, 31, 1 do local pos = {x = left_top_x + x, y = left_top_y + y} local distance_to_center = math.sqrt(pos.x ^ 2 + pos.y ^ 2) - if generate_horizontal_river(surface, pos) then surface.set_tiles({{name = "deepwater", position = pos}}) end - generate_circle_spawn(surface, pos, distance_to_center) - generate_biters(surface, pos, distance_to_center) + if generate_horizontal_river(surface, pos) then surface.set_tiles({{name = "deepwater", position = pos}}) end + generate_biters(surface, pos, distance_to_center) end end + if event.area.left_top.y == -256 and event.area.left_top.x == -256 then + generate_circle_spawn(surface) + generate_silos(surface) + global.terrain_generation_complete = true + end end +--Landfill Prevention +local function on_player_built_tile(event) + local player = game.players[event.player_index] + local surface = player.surface + for _, t in pairs(event.tiles) do + local distance_to_center = math.sqrt(t.position.x ^ 2 + t.position.y ^ 2) + if generate_horizontal_river(surface, t.position) or distance_to_center < spawn_circle_size then + surface.set_tiles({{name = t.old_tile, position = t.position}}, true) + player.insert({name = "landfill", count = 1}) + end + end +end + +local function on_robot_built_tile(event) + local surface = event.robot.surface + for _, t in pairs(event.tiles) do + local distance_to_center = math.sqrt(t.position.x ^ 2 + t.position.y ^ 2) + if generate_horizontal_river(surface, t.position) or distance_to_center < spawn_circle_size then + surface.set_tiles({{name = t.old_tile, position = t.position}}, true) + local inventory = event.robot.get_inventory(defines.inventory.robot_cargo) + inventory.insert({name = "landfill", count = 1}) + end + end +end + +event.add(defines.events.on_robot_built_tile, on_robot_built_tile) +event.add(defines.events.on_player_built_tile, on_player_built_tile) event.add(defines.events.on_chunk_generated, on_chunk_generated)