From ed8aefc86736d58a13806db5b8bf30929f393991 Mon Sep 17 00:00:00 2001 From: MewMew Date: Wed, 6 Nov 2019 12:36:31 +0100 Subject: [PATCH] mirror terrain --- maps/biter_hatchery/gui.lua | 4 +- maps/biter_hatchery/main.lua | 101 ++++++++------------- maps/biter_hatchery/team.lua | 7 ++ maps/biter_hatchery/terrain.lua | 150 ++++++++++++++++++++++++++++---- modules/map_score.lua | 4 +- 5 files changed, 181 insertions(+), 85 deletions(-) diff --git a/maps/biter_hatchery/gui.lua b/maps/biter_hatchery/gui.lua index b895e2f7..bc24727b 100644 --- a/maps/biter_hatchery/gui.lua +++ b/maps/biter_hatchery/gui.lua @@ -16,13 +16,13 @@ end function Public.unit_health_buttons(player) if player.gui.top.health_boost_west then return end - local button = player.gui.top.add({type = "sprite-button", name = "health_boost_west", caption = 1, tooltip = "Health increase of west side biters."}) + local button = player.gui.top.add({type = "sprite-button", name = "health_boost_west", caption = 1, tooltip = "Health modfier of west side biters.\nIncreases by feeding."}) button.style.font = "heading-1" button.style.font_color = {r = 0, g = 180, b = 0} button.style.minimal_height = 38 button.style.minimal_width = 78 button.style.padding = 2 - local button = player.gui.top.add({type = "sprite-button", name = "health_boost_east", caption = 1, tooltip = "Health increase of east side biters."}) + local button = player.gui.top.add({type = "sprite-button", name = "health_boost_east", caption = 1, tooltip = "Health modfier of east side biters.\nIncreases by feeding."}) button.style.font = "heading-1" button.style.font_color = {r = 180, g = 180, b = 0} button.style.minimal_height = 38 diff --git a/maps/biter_hatchery/main.lua b/maps/biter_hatchery/main.lua index e2c8e7b9..796cb6ba 100644 --- a/maps/biter_hatchery/main.lua +++ b/maps/biter_hatchery/main.lua @@ -4,7 +4,6 @@ local Tabs = require 'comfy_panel.main' local Map_score = require "modules.map_score" local Unit_health_booster = require "modules.biter_health_booster" local unit_raffle = require "maps.biter_hatchery.raffle_tables" -local map_functions = require "tools.map_functions" local Terrain = require "maps.biter_hatchery.terrain" local Gui = require "maps.biter_hatchery.gui" require "maps.biter_hatchery.share_chat" @@ -14,7 +13,20 @@ local Map = require "modules.map_info" local math_random = math.random local Public = {} -local m = 4 +local map_gen_settings = { + ["seed"] = 1, + ["water"] = 1, + ["starting_area"] = 1, + ["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}, + ["default_enable_all_autoplace_controls"] = false, + ["autoplace_settings"] = { + ["entity"] = {treat_missing_as_default = false}, + ["tile"] = {treat_missing_as_default = false}, + ["decorative"] = {treat_missing_as_default = false}, + }, + } + +local m = 3 local health_boost_food_values = { ["automation-science-pack"] = 0.000001 * m, ["logistic-science-pack"] = 0.0000025 * m, @@ -42,37 +54,8 @@ for x = worm_turret_spawn_radius * -1, 0, 1 do end end -local function draw_spawn_ores(surface) - local x = global.map_forces.west.hatchery.position.x - 64 - map_functions.draw_smoothed_out_ore_circle({x = x, y = 32}, "iron-ore", surface, 15, 2500) - map_functions.draw_smoothed_out_ore_circle({x = x, y = -32}, "copper-ore", surface, 15, 2500) - map_functions.draw_smoothed_out_ore_circle({x = x, y = 0}, "coal", surface, 15, 1500) - map_functions.draw_smoothed_out_ore_circle({x = x, y = 64}, "stone", surface, 15, 1500) - - local x = global.map_forces.east.hatchery.position.x + 64 - map_functions.draw_smoothed_out_ore_circle({x = x, y = 32}, "copper-ore", surface, 15, 2500) - map_functions.draw_smoothed_out_ore_circle({x = x, y = -32}, "iron-ore", surface, 15, 2500) - map_functions.draw_smoothed_out_ore_circle({x = x, y = 0}, "coal", surface, 15, 1500) - map_functions.draw_smoothed_out_ore_circle({x = x, y = -64}, "stone", surface, 15, 1500) -end - function Public.reset_map() - local map_gen_settings = {} - map_gen_settings.seed = math_random(1, 10000000) - map_gen_settings.water = 0.2 - map_gen_settings.starting_area = 1 - map_gen_settings.terrain_segmentation = 10 - map_gen_settings.cliff_settings = {cliff_elevation_interval = math_random(16, 48), cliff_elevation_0 = math_random(16, 48)} - map_gen_settings.autoplace_controls = { - ["coal"] = {frequency = 100, size = 0.5, richness = 0.5,}, - ["stone"] = {frequency = 100, size = 0.5, richness = 0.5,}, - ["copper-ore"] = {frequency = 200, size = 0.6, richness = 0.5,}, - ["iron-ore"] = {frequency = 200, size = 0.6, richness = 0.5,}, - ["uranium-ore"] = {frequency = 50, size = 0.5, richness = 0.5,}, - ["crude-oil"] = {frequency = 50, size = 0.5, richness = 0.5,}, - ["trees"] = {frequency = math_random(5, 10) * 0.1, size = math_random(5, 10) * 0.1, richness = math_random(3, 10) * 0.1}, - ["enemy-base"] = {frequency = 0, size = 0, richness = 0} - } + Terrain.create_mirror_surface() if not global.active_surface_index then global.active_surface_index = game.create_surface("biter_hatchery", map_gen_settings).index @@ -81,32 +64,12 @@ function Public.reset_map() end local surface = game.surfaces[global.active_surface_index] + surface.request_to_generate_chunks({0,0}, 10) surface.force_generate_chunk_requests() - - game.forces.west.set_spawn_position({-160, 0}, surface) - game.forces.east.set_spawn_position({160, 0}, surface) - - local e = surface.create_entity({name = "biter-spawner", position = {-160, 0}, force = "west"}) - surface.create_entity({name = "small-worm-turret", position = {-155, 0}, force = "west"}) - e.active = false - global.map_forces.west.hatchery = e - global.map_forces.east.target = e - - local e = surface.create_entity({name = "biter-spawner", position = {160, 0}, force = "east"}) - surface.create_entity({name = "small-worm-turret", position = {155, 0}, force = "east"}) - e.active = false - global.map_forces.east.hatchery = e - global.map_forces.west.target = e - - global.map_forces.east.unit_health_boost = 1 - global.map_forces.west.unit_health_boost = 1 - global.map_forces.east.unit_count = 0 - global.map_forces.west.unit_count = 0 - global.map_forces.east.max_unit_count = 1024 - global.map_forces.west.max_unit_count = 1024 - - draw_spawn_ores(surface) + game.forces.spectator.set_spawn_position({0, 128}, surface) + game.forces.west.set_spawn_position({-200, 0}, surface) + game.forces.east.set_spawn_position({200, 0}, surface) RPG.rpg_reset_all_players() @@ -114,7 +77,6 @@ function Public.reset_map() Team.assign_random_force_to_active_players() for _, player in pairs(game.connected_players) do - if player.gui.left.biter_hatchery_game_won then player.gui.left.biter_hatchery_game_won.destroy() end Team.teleport_player_to_active_surface(player) end @@ -199,6 +161,7 @@ end local function nom() local surface = game.surfaces[global.active_surface_index] for key, force in pairs(global.map_forces) do + if not force.hatchery then return end force.hatchery.health = force.hatchery.health + 1 local belts = get_belts(force.hatchery) for _, belt in pairs(belts) do @@ -283,8 +246,10 @@ local function on_entity_died(event) player.play_sound{path="utility/game_lost", volume_modifier=0.85} end for _, player in pairs(game.forces.west.connected_players) do - player.play_sound{path="utility/game_won", volume_modifier=0.85} - Map_score.set_score(player, Map_score.get_score(player) + 1) + player.play_sound{path="utility/game_won", volume_modifier=0.85} + --if #entity.force.players > 0 then + Map_score.set_score(player, Map_score.get_score(player) + 1) + --end end else game.print("West lost their Hatchery.", {100, 100, 100}) @@ -294,7 +259,9 @@ local function on_entity_died(event) end for _, player in pairs(game.forces.east.connected_players) do player.play_sound{path="utility/game_won", volume_modifier=0.85} - Map_score.set_score(player, Map_score.get_score(player) + 1) + --if #entity.force.players > 0 then + Map_score.set_score(player, Map_score.get_score(player) + 1) + --end end end @@ -304,7 +271,9 @@ local function on_entity_died(event) for _, player in pairs(game.forces.spectator.connected_players) do player.play_sound{path="utility/game_won", volume_modifier=0.85} end + global.game_reset_tick = game.tick + 1800 + game.delete_surface("mirror_terrain") for _, player in pairs(game.connected_players) do for _, child in pairs(player.gui.left.children) do child.destroy() end @@ -321,8 +290,6 @@ local function on_player_joined_game(event) Gui.unit_health_buttons(player) Gui.update_health_boost_buttons(player) - if player.gui.left.biter_hatchery_game_won then player.gui.left.biter_hatchery_game_won.destroy() end - if player.surface.index ~= global.active_surface_index then if player.force.name == "spectator" then Team.set_player_to_spectator(player) @@ -338,16 +305,16 @@ end local function tick() local game_tick = game.tick if game_tick % 240 == 0 then - local area = {{-256, -97}, {255, 96}} + local area = {{-320, -161}, {319, 160}} game.forces.west.chart(game.surfaces[global.active_surface_index], area) - game.forces.east.chart(game.surfaces[global.active_surface_index], area) + game.forces.east.chart(game.surfaces[global.active_surface_index], area) end if game_tick % 1200 == 0 then send_unit_groups() end if global.game_reset_tick then if global.game_reset_tick < game_tick then global.game_reset_tick = nil Public.reset_map() - end + end return end nom() @@ -380,7 +347,9 @@ local function on_entity_damaged(event) local cause = event.cause if cause then if cause.valid then - if cause.type == "unit" then return end + if cause.type == "unit" then + if math_random(1,5) == 1 then return end + end end end entity.health = entity.health + event.final_damage_amount diff --git a/maps/biter_hatchery/team.lua b/maps/biter_hatchery/team.lua index 77231655..0bbad564 100644 --- a/maps/biter_hatchery/team.lua +++ b/maps/biter_hatchery/team.lua @@ -20,6 +20,13 @@ function Public.set_force_attributes() game.forces.east.technologies["artillery"].enabled = false game.forces.east.technologies["artillery-shell-range-1"].enabled = false game.forces.east.technologies["artillery-shell-speed-1"].enabled = false + + global.map_forces.east.unit_health_boost = 1 + global.map_forces.west.unit_health_boost = 1 + global.map_forces.east.unit_count = 0 + global.map_forces.west.unit_count = 0 + global.map_forces.east.max_unit_count = 1024 + global.map_forces.west.max_unit_count = 1024 end function Public.create_forces() diff --git a/maps/biter_hatchery/terrain.lua b/maps/biter_hatchery/terrain.lua index 48332031..8d55e999 100644 --- a/maps/biter_hatchery/terrain.lua +++ b/maps/biter_hatchery/terrain.lua @@ -1,4 +1,9 @@ local math_abs = math.abs +local math_random = math.random +local Map_functions = require "tools.map_functions" +local Public = {} + +local hatchery_position = {x = 192, y = 0} local function get_replacement_tile(surface, position) for i = 1, 128, 1 do @@ -12,6 +17,98 @@ local function get_replacement_tile(surface, position) return "grass-1" end +local function create_nests(surface) + local x = hatchery_position.x + + local e = surface.create_entity({name = "biter-spawner", position = {x * -1, 0}, force = "west"}) + surface.create_entity({name = "small-worm-turret", position = {x * -1 + 6, 0}, force = "west"}) + e.active = false + global.map_forces.west.hatchery = e + global.map_forces.east.target = e + + local e = surface.create_entity({name = "biter-spawner", position = {x, 0}, force = "east"}) + surface.create_entity({name = "small-worm-turret", position = {x - 6, 0}, force = "east"}) + e.active = false + global.map_forces.east.hatchery = e + global.map_forces.west.target = e +end + +function Public.create_mirror_surface() + if game.surfaces["mirror_terrain"] then return end + + local map_gen_settings = {} + map_gen_settings.seed = math_random(1, 99999999) + map_gen_settings.water = 0.2 + map_gen_settings.starting_area = 1 + map_gen_settings.terrain_segmentation = 8 + map_gen_settings.cliff_settings = {cliff_elevation_interval = 0, cliff_elevation_0 = 0} + map_gen_settings.autoplace_controls = { + ["coal"] = {frequency = 5, size = 0.7, richness = 0.5,}, + ["stone"] = {frequency = 5, size = 0.7, richness = 0.5,}, + ["copper-ore"] = {frequency = 10, size = 0.7, richness = 0.75,}, + ["iron-ore"] = {frequency = 10, size = 0.7, richness = 1,}, + ["uranium-ore"] = {frequency = 5, size = 0.5, richness = 0.5,}, + ["crude-oil"] = {frequency = 10, size = 1, richness = 1,}, + ["trees"] = {frequency = math_random(5, 12) * 0.1, size = math_random(5, 12) * 0.1, richness = math_random(1, 10) * 0.1}, + ["enemy-base"] = {frequency = 0, size = 0, richness = 0} + } + local surface = game.create_surface("mirror_terrain", map_gen_settings) + + local x = hatchery_position.x - 16 + local offset = 38 + + surface.request_to_generate_chunks({x, 0}, 5) + surface.force_generate_chunk_requests() + + local positions = {{x = x, y = offset}, {x = x, y = offset * -1}, {x = x, y = offset * -2}, {x = x, y = offset * 2}} + table.shuffle_table(positions) + + for key, ore in pairs({"copper-ore", "iron-ore", "coal", "stone"}) do + Map_functions.draw_smoothed_out_ore_circle(surface.find_non_colliding_position("coal", positions[key], 128, 1), ore, surface, 15, 2500) + end + + local r = 32 + for x = r * -1, r, 1 do + for y = r * -1, r, 1 do + local p = {x = hatchery_position.x + x, y = hatchery_position.y + y} + if math.sqrt(x ^ 2 + y ^ 2) < r then + local tile = surface.get_tile(p) + if tile.name == "water" or tile.name == "deepwater" then + surface.set_tiles({{name = "landfill", position = p}}, true) + end + end + end + end +end + +local function mirror_chunk(event, source_surface, x_modifier) + local surface = event.surface + local left_top = event.area.left_top + local offset = 0 + if x_modifier == -1 then offset = 32 end + local mirror_left_top = {x = left_top.x * x_modifier - offset, y = left_top.y} + + source_surface.request_to_generate_chunks(mirror_left_top, 1) + source_surface.force_generate_chunk_requests() + + local mirror_area = {{mirror_left_top.x, mirror_left_top.y}, {mirror_left_top.x + 32, mirror_left_top.y + 32}} + + for _, tile in pairs(source_surface.find_tiles_filtered({area = mirror_area})) do + surface.set_tiles({{name = tile.name, position = {x = tile.position.x * x_modifier, y = tile.position.y}}}, true) + end + for _, entity in pairs(source_surface.find_entities_filtered({area = mirror_area})) do + if surface.can_place_entity({name = entity.name, position = {x = entity.position.x * x_modifier, y = entity.position.y}}) then + entity.clone({position = {x = entity.position.x * x_modifier, y = entity.position.y}, surface = surface, force = "neutral"}) + end + end + for _, decorative in pairs(source_surface.find_decoratives_filtered{area = mirror_area}) do + surface.create_decoratives{ + check_collision=false, + decoratives={{name = decorative.decorative.name, position = {x = decorative.position.x * x_modifier, y = decorative.position.y}, amount = decorative.amount}} + } + end +end + local function combat_area(event) local surface = event.surface local left_top = event.area.left_top @@ -19,17 +116,23 @@ local function combat_area(event) if left_top.y >= 96 then return end if left_top.y < -96 then return end + local replacement_tile = "landfill" + local tile = surface.get_tile({8,0}) + if tile then replacement_tile = tile.name end + for _, tile in pairs(surface.find_tiles_filtered({area = event.area})) do - if tile.name == "water" or tile.name == "deepwater" then - surface.set_tiles({{name = get_replacement_tile(surface, tile.position), position = tile.position}}, true) - end - if tile.position.x >= -4 and tile.position.x <= 4 then + --if tile.name == "water" or tile.name == "deepwater" then + --surface.set_tiles({{name = replacement_tile, position = tile.position}}, true) + --end + if tile.position.x >= -4 and tile.position.x < 4 then surface.set_tiles({{name = "water-shallow", position = tile.position}}, true) end end + --[[ for _, entity in pairs(surface.find_entities_filtered({type = {"resource", "cliff"}, area = event.area})) do entity.destroy() - end + end + ]] end local function is_out_of_map(p) @@ -42,29 +145,46 @@ end local function out_of_map_area(event) local surface = event.surface local left_top = event.area.left_top - for x = 0, 31, 1 do - for y = 0, 31, 1 do + for x = -1, 32, 1 do + for y = -1, 32, 1 do local p = {x = left_top.x + x, y = left_top.y + y} - if is_out_of_map(p) then surface.set_tiles({{name = "out-of-map", position = p}}, true) end + if is_out_of_map(p) then + surface.set_tiles({{name = "out-of-map", position = p}}, true) + end end end end local function on_chunk_generated(event) + local source_surface = game.surfaces["mirror_terrain"] + if not source_surface then return end + if not source_surface.valid then return end + if event.surface.index == source_surface.index then return end + local left_top = event.area.left_top + + if left_top.x >= 0 then + mirror_chunk(event, source_surface, 1) + else + mirror_chunk(event, source_surface, -1) + end out_of_map_area(event) - + if left_top.x >= -192 and left_top.x < 192 then combat_area(event) end - - if left_top.x > 512 then return end - if left_top.x < -512 then return end - if left_top.y > 512 then return end - if left_top.y < -512 then return end + + if left_top.x == 256 and left_top.y == 256 then create_nests(event.surface) end + + if left_top.x > 320 then return end + if left_top.x < -320 then return end + if left_top.y > 320 then return end + if left_top.y < -320 then return end game.forces.west.chart(event.surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}}) game.forces.east.chart(event.surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}}) end local event = require 'utils.event' -event.add(defines.events.on_chunk_generated, on_chunk_generated) \ No newline at end of file +event.add(defines.events.on_chunk_generated, on_chunk_generated) + +return Public \ No newline at end of file diff --git a/modules/map_score.lua b/modules/map_score.lua index 445c0f8f..100f9d45 100644 --- a/modules/map_score.lua +++ b/modules/map_score.lua @@ -34,8 +34,8 @@ local score_list = (function (player, frame) local scroll_pane = frame.add { type = "scroll-pane", name = "scroll_pane", direction = "vertical", horizontal_scroll_policy = "never", vertical_scroll_policy = "auto"} scroll_pane.style.minimal_width = 780 - scroll_pane.style.maximal_height = 320 - scroll_pane.style.minimal_height = 320 + scroll_pane.style.maximal_height = 360 + scroll_pane.style.minimal_height = 360 local t = scroll_pane.add {type = "table", column_count = 3}