mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-07 13:31:40 +02:00
big rewrites
This commit is contained in:
parent
bd55ede971
commit
f5920adb9d
@ -45,13 +45,20 @@ local function create_spectate_confirmation(player)
|
||||
frame.add({type = "button", name = "cancel_spectate", caption = "Cancel"})
|
||||
end
|
||||
|
||||
function Public.rejoin_question(player)
|
||||
if player.gui.center.rejoin_question_frame then return end
|
||||
local frame = player.gui.center.add({type = "frame", name = "rejoin_question_frame", caption = "Rejoin the game?"})
|
||||
frame.style.font = "default"
|
||||
frame.style.font_color = {r = 0.3, g = 0.65, b = 0.3}
|
||||
frame.add({type = "button", name = "confirm_rejoin", caption = "Rejoin"})
|
||||
frame.add({type = "button", name = "cancel_rejoin", caption = "Cancel"})
|
||||
function Public.rejoin_question(hatchery)
|
||||
if game.tick % 60 ~= 0 then return end
|
||||
for _, player in pairs(game.forces.spectator.players) do
|
||||
if not player.gui.center.rejoin_question_frame then
|
||||
local frame = player.gui.center.add({type = "frame", name = "rejoin_question_frame", caption = "Rejoin the game?"})
|
||||
frame.style.font = "default"
|
||||
frame.style.font_color = {r = 0.3, g = 0.65, b = 0.3}
|
||||
frame.add({type = "button", name = "confirm_rejoin", caption = "Rejoin"})
|
||||
frame.add({type = "button", name = "cancel_rejoin", caption = "Cancel"})
|
||||
end
|
||||
end
|
||||
hatchery.reset_counter = hatchery.reset_counter + 1
|
||||
game.print("Biter Hatchery round #" .. hatchery.reset_counter .. " has begun!", {180, 0, 250})
|
||||
hatchery.gamestate = "game_in_progress"
|
||||
end
|
||||
|
||||
local function on_gui_click(event)
|
||||
@ -63,8 +70,8 @@ local function on_gui_click(event)
|
||||
if event.element.name == "confirm_rejoin" then
|
||||
player.gui.center["rejoin_question_frame"].destroy()
|
||||
Team.assign_force_to_player(player)
|
||||
Team.teleport_player_to_active_surface(player)
|
||||
Team.put_player_into_random_team(player)
|
||||
Team.teleport_player_to_spawn(player)
|
||||
Team.add_player_to_team(player)
|
||||
game.print(player.name .. " has rejoined the game!")
|
||||
return
|
||||
end
|
||||
|
@ -8,23 +8,19 @@ local Gui = require "maps.biter_hatchery.gui"
|
||||
require "maps.biter_hatchery.share_chat"
|
||||
local Team = require "maps.biter_hatchery.team"
|
||||
local Unit_health_booster = require "modules.biter_health_booster"
|
||||
local Reset = require "functions.soft_reset"
|
||||
local Map = require "modules.map_info"
|
||||
local math_random = math.random
|
||||
local Global = require 'utils.global'
|
||||
local Public = {}
|
||||
|
||||
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 math_random = math.random
|
||||
|
||||
local hatchery = {}
|
||||
Global.register(
|
||||
hatchery,
|
||||
function(tbl)
|
||||
hatchery = tbl
|
||||
end
|
||||
)
|
||||
|
||||
local m = 2
|
||||
local health_boost_food_values = {
|
||||
@ -54,41 +50,6 @@ for x = worm_turret_spawn_radius * -1, 0, 1 do
|
||||
end
|
||||
end
|
||||
|
||||
function Public.reset_map()
|
||||
Terrain.create_mirror_surface()
|
||||
|
||||
if not global.active_surface_index then
|
||||
global.active_surface_index = game.create_surface("biter_hatchery", map_gen_settings).index
|
||||
else
|
||||
global.active_surface_index = Reset.soft_reset_map(game.surfaces[global.active_surface_index], map_gen_settings, Team.starting_items).index
|
||||
end
|
||||
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
|
||||
surface.request_to_generate_chunks({0,0}, 8)
|
||||
surface.force_generate_chunk_requests()
|
||||
game.forces.spectator.set_spawn_position({0, -128}, surface)
|
||||
game.forces.west.set_spawn_position({-210, 0}, surface)
|
||||
game.forces.east.set_spawn_position({210, 0}, surface)
|
||||
|
||||
Team.set_force_attributes()
|
||||
Team.assign_random_force_to_active_players()
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
Team.teleport_player_to_active_surface(player)
|
||||
end
|
||||
|
||||
for _, player in pairs(game.forces.spectator.connected_players) do
|
||||
player.character.destroy()
|
||||
Team.set_player_to_spectator(player)
|
||||
end
|
||||
for _, player in pairs(game.forces.spectator.players) do
|
||||
Gui.rejoin_question(player)
|
||||
end
|
||||
|
||||
game.reset_time_played()
|
||||
end
|
||||
|
||||
local function spawn_worm_turret(surface, force_name, food_item)
|
||||
local r_max = surface.count_entities_filtered({type = "turret", force = force_name}) + 1
|
||||
if r_max > 256 then return end
|
||||
@ -161,7 +122,7 @@ local function eat_food_from_belt(belt)
|
||||
end
|
||||
|
||||
local function nom()
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
local surface = game.surfaces.nauvis
|
||||
for key, force in pairs(global.map_forces) do
|
||||
if not force.hatchery then return end
|
||||
force.hatchery.health = force.hatchery.health + 1
|
||||
@ -195,7 +156,7 @@ local function alert_bubble(force_name, entity)
|
||||
end
|
||||
|
||||
local function send_unit_groups()
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
local surface = game.surfaces.nauvis
|
||||
for key, force in pairs(global.map_forces) do
|
||||
local units = get_units(key)
|
||||
if #units > 0 then
|
||||
@ -241,7 +202,7 @@ local function on_player_changed_position(event)
|
||||
if player.position.x > -4 and player.position.x < 4 then
|
||||
if not border_teleport[player.force.name] then return end
|
||||
if player.character.driving then player.character.driving = false end
|
||||
player.teleport({player.position.x + border_teleport[player.force.name], player.position.y}, game.surfaces[global.active_surface_index])
|
||||
player.teleport({player.position.x + border_teleport[player.force.name], player.position.y}, game.surfaces.nauvis)
|
||||
end
|
||||
end
|
||||
|
||||
@ -290,7 +251,6 @@ local function on_entity_died(event)
|
||||
game.forces.spectator.play_sound{path="utility/game_won", volume_modifier=0.85}
|
||||
|
||||
global.game_reset_tick = game.tick + 7200
|
||||
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
|
||||
@ -304,48 +264,19 @@ end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
local surface = game.surfaces.nauvis
|
||||
|
||||
Gui.unit_health_buttons(player)
|
||||
Gui.spectate_button(player)
|
||||
Gui.update_health_boost_buttons(player)
|
||||
|
||||
if player.surface.index ~= global.active_surface_index then
|
||||
if player.force.name == "spectator" then
|
||||
Team.set_player_to_spectator(player)
|
||||
Team.teleport_player_to_active_surface(player)
|
||||
return
|
||||
end
|
||||
if player.force.name == "player" then
|
||||
Team.assign_force_to_player(player)
|
||||
Team.teleport_player_to_active_surface(player)
|
||||
Team.put_player_into_random_team(player)
|
||||
Team.add_player_to_team(player)
|
||||
Team.teleport_player_to_spawn(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function tick()
|
||||
local game_tick = game.tick
|
||||
if game_tick % 240 == 0 then
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
local west = game.forces.west
|
||||
local east = game.forces.east
|
||||
local area = {{-320, -161}, {319, 160}}
|
||||
west.chart(surface, area)
|
||||
east.chart(surface, area)
|
||||
local r = 64
|
||||
for _, player in pairs(west.connected_players) do east.chart(surface, {{player.position.x - r, player.position.y - r}, {player.position.x + r, player.position.y + r}}) end
|
||||
for _, player in pairs(east.connected_players) do west.chart(surface, {{player.position.x - r, player.position.y - r}, {player.position.x + r, player.position.y + r}}) end
|
||||
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
|
||||
return
|
||||
end
|
||||
nom()
|
||||
end
|
||||
|
||||
--Construction Robot Restriction
|
||||
local robot_build_restriction = {
|
||||
["east"] = function(x)
|
||||
@ -394,17 +325,75 @@ local function on_player_used_spider_remote(event)
|
||||
vehicle.autopilot_destination = nil
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
--Disable Nauvis
|
||||
local surface = game.surfaces[1]
|
||||
local map_gen_settings = surface.map_gen_settings
|
||||
map_gen_settings.height = 3
|
||||
map_gen_settings.width = 3
|
||||
surface.map_gen_settings = map_gen_settings
|
||||
for chunk in surface.get_chunks() do
|
||||
surface.delete_chunk({chunk.x, chunk.y})
|
||||
local function game_in_progress(hatchery)
|
||||
local game_tick = game.tick
|
||||
if game_tick % 30 ~= 0 then return end
|
||||
if game_tick % 240 == 0 then
|
||||
local surface = game.surfaces.nauvis
|
||||
local west = game.forces.west
|
||||
local east = game.forces.east
|
||||
local area = {{-320, -161}, {319, 160}}
|
||||
west.chart(surface, area)
|
||||
east.chart(surface, area)
|
||||
local r = 64
|
||||
for _, player in pairs(west.connected_players) do east.chart(surface, {{player.position.x - r, player.position.y - r}, {player.position.x + r, player.position.y + r}}) end
|
||||
for _, player in pairs(east.connected_players) do west.chart(surface, {{player.position.x - r, player.position.y - r}, {player.position.x + r, player.position.y + r}}) end
|
||||
end
|
||||
if global.game_reset_tick then
|
||||
if global.game_reset_tick < game_tick then
|
||||
global.game_reset_tick = nil
|
||||
hatchery.gamestate = "init"
|
||||
end
|
||||
return
|
||||
end
|
||||
if game_tick % 1200 == 0 then send_unit_groups() end
|
||||
nom()
|
||||
end
|
||||
|
||||
local function on_chunk_generated(event)
|
||||
local surface = event.surface
|
||||
if event.surface.index ~= 1 then return end
|
||||
|
||||
local left_top = event.area.left_top
|
||||
|
||||
if Terrain.is_out_of_map_chunk(left_top) then
|
||||
Terrain.out_of_map(surface, left_top)
|
||||
return
|
||||
end
|
||||
|
||||
if left_top.x < 0 then
|
||||
table.insert(hatchery.mirror_queue, {{left_top.x, left_top.y}, 1})
|
||||
Terrain.out_of_map(surface, left_top)
|
||||
return
|
||||
end
|
||||
|
||||
surface.request_to_generate_chunks({x = ((left_top.x * -1) - 32) + 16, y = left_top.y + 16}, 0)
|
||||
Terrain.out_of_map_area(surface, left_top)
|
||||
Terrain.combat_area(event)
|
||||
end
|
||||
|
||||
local gamestates = {
|
||||
["init"] = Team.init,
|
||||
["reset_nauvis"] = Terrain.reset_nauvis,
|
||||
["prepare_east"] = Terrain.prepare_east,
|
||||
["prepare_west"] = Terrain.prepare_west,
|
||||
["draw_team_nests"] = Terrain.draw_team_nests,
|
||||
["draw_border_beams"] = Terrain.draw_border_beams,
|
||||
["spawn_players"] = Team.spawn_players,
|
||||
["rejoin_question"] = Gui.rejoin_question,
|
||||
["game_in_progress"] = game_in_progress,
|
||||
}
|
||||
|
||||
local function on_tick()
|
||||
Terrain.mirror_queue(hatchery)
|
||||
gamestates[hatchery.gamestate](hatchery)
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
hatchery.gamestate = "init"
|
||||
hatchery.reset_counter = 0
|
||||
hatchery.mirror_queue = {}
|
||||
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.open_blueprint_library_gui, false)
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint_string, false)
|
||||
|
||||
@ -439,15 +428,16 @@ local function on_init()
|
||||
T.sub_caption_color = {r = 0, g = 250, b = 150}
|
||||
|
||||
Team.create_forces()
|
||||
Public.reset_map()
|
||||
Team.reset_forces()
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_init(on_init)
|
||||
event.on_nth_tick(30, tick)
|
||||
event.add(defines.events.on_player_used_spider_remote, on_player_used_spider_remote)
|
||||
event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
||||
event.add(defines.events.on_entity_died, on_entity_died)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
||||
event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||
local Event = require 'utils.event'
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
Event.add(defines.events.on_player_used_spider_remote, on_player_used_spider_remote)
|
||||
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
||||
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
@ -1,33 +1,40 @@
|
||||
local Public = {}
|
||||
local math_random = math.random
|
||||
|
||||
Public.starting_items = {['iron-plate'] = 32, ['iron-gear-wheel'] = 16, ['stone'] = 25, ['pistol'] = 1, ['firearm-magazine'] = 16}
|
||||
local starting_items = {['iron-plate'] = 32, ['iron-gear-wheel'] = 16, ['stone'] = 20, ['pistol'] = 1, ['firearm-magazine'] = 16}
|
||||
|
||||
function Public.set_force_attributes()
|
||||
game.forces.west.set_friend("spectator", true)
|
||||
game.forces.east.set_friend("spectator", true)
|
||||
game.forces.spectator.set_friend("west", true)
|
||||
game.forces.spectator.set_friend("east", true)
|
||||
|
||||
for _, force_name in pairs({"west", "east"}) do
|
||||
game.forces[force_name].share_chart = true
|
||||
game.forces[force_name].research_queue_enabled = true
|
||||
game.forces[force_name].technologies["artillery"].enabled = false
|
||||
game.forces[force_name].technologies["artillery-shell-range-1"].enabled = false
|
||||
game.forces[force_name].technologies["artillery-shell-speed-1"].enabled = false
|
||||
game.forces[force_name].technologies["land-mine"].enabled = false
|
||||
function Public.reset_forces()
|
||||
for _, force_name in pairs({"west", "east"}) do
|
||||
global.map_forces[force_name].unit_health_boost = 1
|
||||
global.map_forces[force_name].unit_count = 0
|
||||
global.map_forces[force_name].units = {}
|
||||
global.map_forces[force_name].max_unit_count = 1280
|
||||
global.map_forces[force_name].player_count = 0
|
||||
end
|
||||
global.map_forces[force_name].player_count = 0
|
||||
local force = game.forces[force_name]
|
||||
force.reset()
|
||||
force.share_chart = true
|
||||
force.research_queue_enabled = true
|
||||
force.technologies["artillery"].enabled = false
|
||||
force.technologies["artillery-shell-range-1"].enabled = false
|
||||
force.technologies["artillery-shell-speed-1"].enabled = false
|
||||
force.technologies["land-mine"].enabled = false
|
||||
end
|
||||
game.forces.west.set_friend("spectator", true)
|
||||
game.forces.east.set_friend("spectator", true)
|
||||
game.forces.west.set_spawn_position({-210, 0}, game.surfaces.nauvis)
|
||||
game.forces.east.set_spawn_position({210, 0}, game.surfaces.nauvis)
|
||||
end
|
||||
|
||||
function Public.create_forces()
|
||||
game.create_force("west")
|
||||
game.create_force("east")
|
||||
game.create_force("spectator")
|
||||
game.forces.spectator.set_friend("west", true)
|
||||
game.forces.spectator.set_friend("east", true)
|
||||
for _, force_name in pairs({"west", "east"}) do
|
||||
global.map_forces[force_name].max_unit_count = 1280
|
||||
end
|
||||
local surface = game.surfaces.nauvis
|
||||
game.forces.spectator.set_spawn_position({0, -128}, surface)
|
||||
end
|
||||
|
||||
function Public.assign_random_force_to_active_players()
|
||||
@ -63,8 +70,8 @@ function Public.assign_force_to_player(player)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.teleport_player_to_active_surface(player)
|
||||
local surface = game.surfaces[global.active_surface_index]
|
||||
function Public.teleport_player_to_spawn(player)
|
||||
local surface = game.surfaces.nauvis
|
||||
local position
|
||||
if player.force.name == "spectator" then
|
||||
position = player.force.get_spawn_position(surface)
|
||||
@ -76,27 +83,77 @@ function Public.teleport_player_to_active_surface(player)
|
||||
player.teleport(position, surface)
|
||||
end
|
||||
|
||||
function Public.put_player_into_random_team(player)
|
||||
function Public.add_player_to_team(player)
|
||||
if player.character then
|
||||
if player.character.valid then
|
||||
player.character.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
player.character = nil
|
||||
player.set_controller({type=defines.controllers.god})
|
||||
player.create_character()
|
||||
for item, amount in pairs(Public.starting_items) do
|
||||
for item, amount in pairs(starting_items) do
|
||||
player.insert({name = item, count = amount})
|
||||
end
|
||||
global.map_forces[player.force.name].player_count = global.map_forces[player.force.name].player_count + 1
|
||||
end
|
||||
|
||||
function Public.set_player_to_spectator(player)
|
||||
if player.character then player.character.die() end
|
||||
if player.character and player.character.valid then player.character.die() end
|
||||
player.force = game.forces.spectator
|
||||
player.character = nil
|
||||
player.spectator = true
|
||||
player.set_controller({type=defines.controllers.spectator})
|
||||
end
|
||||
|
||||
function Public.spawn_players(hatchery)
|
||||
if game.tick % 60 ~= 0 then return end
|
||||
game.print("spawning characters", {150, 150, 150})
|
||||
local surface = game.surfaces.nauvis
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.force.name ~= "spectator" then
|
||||
Public.assign_force_to_player(player)
|
||||
Public.add_player_to_team(player)
|
||||
Public.teleport_player_to_spawn(player)
|
||||
end
|
||||
end
|
||||
hatchery.gamestate = "rejoin_question"
|
||||
end
|
||||
|
||||
function Public.init(hatchery)
|
||||
game.reset_time_played()
|
||||
Public.reset_forces()
|
||||
|
||||
local players = {}
|
||||
for _, player in pairs(game.players) do table.insert(players, player.index) end
|
||||
|
||||
for k, player_index in pairs(players) do
|
||||
local player = game.players[player_index]
|
||||
if player.force.name == "spectator" then
|
||||
Public.teleport_player_to_spawn(player)
|
||||
table.remove(players, k)
|
||||
end
|
||||
end
|
||||
|
||||
for k, player_index in pairs(players) do
|
||||
local player = game.players[player_index]
|
||||
if not player.connected then
|
||||
player.force = game.forces.player
|
||||
table.remove(players, k)
|
||||
end
|
||||
end
|
||||
|
||||
for k, player_index in pairs(players) do
|
||||
local player = game.players[player_index]
|
||||
if player.character and player.character.valid then player.character.destroy() end
|
||||
player.character = nil
|
||||
player.spectator = true
|
||||
player.set_controller({type=defines.controllers.spectator})
|
||||
player.force = game.forces.player
|
||||
Public.teleport_player_to_spawn(player)
|
||||
end
|
||||
|
||||
hatchery.gamestate = "reset_nauvis"
|
||||
end
|
||||
|
||||
return Public
|
@ -17,36 +17,6 @@ local function get_replacement_tile(surface, position)
|
||||
return "landfill"
|
||||
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"})
|
||||
for _, p in pairs({{x * -1 + 6, 0}, {x * -1 + 3, 6}, {x * -1 + 3, -5}}) do
|
||||
surface.create_entity({name = "small-worm-turret", position = p, force = "west"})
|
||||
surface.create_decoratives{check_collision = false, decoratives = {{name = "enemy-decal", position = p, amount = 1}}}
|
||||
end
|
||||
e.active = false
|
||||
global.map_forces.west.hatchery = e
|
||||
global.map_forces.east.target = e
|
||||
surface.create_decoratives{check_collision = false, decoratives = {{name = "enemy-decal", position = e.position, amount = 3}}}
|
||||
|
||||
local e = surface.create_entity({name = "biter-spawner", position = {x, 0}, force = "east"})
|
||||
for _, p in pairs({{x - 6, 0}, {x - 3, 6}, {x - 3, -5}}) do
|
||||
surface.create_entity({name = "small-worm-turret", position = p, force = "east"})
|
||||
surface.create_decoratives{check_collision = false, decoratives = {{name = "enemy-decal", position = p, amount = 1}}}
|
||||
end
|
||||
|
||||
e.active = false
|
||||
global.map_forces.east.hatchery = e
|
||||
global.map_forces.west.target = e
|
||||
surface.create_decoratives{check_collision = false, decoratives = {{name = "enemy-decal", position = e.position, amount = 3}}}
|
||||
end
|
||||
|
||||
local function create_border_beams(surface)
|
||||
surface.create_entity({name = "electric-beam", position = {4, -96}, source = {4, -96}, target = {4,96}})
|
||||
surface.create_entity({name = "electric-beam", position = {-4, -96}, source = {-4, -96}, target = {-4,96}})
|
||||
end
|
||||
|
||||
local function draw_spawn_ore(surface, position)
|
||||
local ores = {"copper-ore", "iron-ore", "coal", "stone"}
|
||||
table.shuffle_table(ores)
|
||||
@ -80,16 +50,15 @@ local function draw_spawn_ore(surface, position)
|
||||
end
|
||||
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 = 1
|
||||
map_gen_settings.starting_area = 1
|
||||
map_gen_settings.terrain_segmentation = 2
|
||||
map_gen_settings.cliff_settings = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}
|
||||
map_gen_settings.autoplace_controls = {
|
||||
function Public.reset_nauvis(hatchery)
|
||||
local surface = game.surfaces.nauvis
|
||||
local mgs = surface.map_gen_settings
|
||||
mgs.seed = math_random(1, 99999999)
|
||||
mgs.water = 1
|
||||
mgs.starting_area = 1
|
||||
mgs.terrain_segmentation = 2
|
||||
mgs.cliff_settings = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}
|
||||
mgs.autoplace_controls = {
|
||||
["coal"] = {frequency = 8, size = 0.7, richness = 0.5,},
|
||||
["stone"] = {frequency = 8, size = 0.7, richness = 0.5,},
|
||||
["copper-ore"] = {frequency = 8, size = 0.7, richness = 0.75,},
|
||||
@ -98,16 +67,23 @@ function Public.create_mirror_surface()
|
||||
["crude-oil"] = {frequency = 5, size = 1, richness = 1,},
|
||||
["trees"] = {frequency = math.random(4, 32) * 0.1, size = math.random(4, 16) * 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
|
||||
|
||||
surface.request_to_generate_chunks({x, 0}, 5)
|
||||
surface.force_generate_chunk_requests()
|
||||
|
||||
draw_spawn_ore(surface, {x = 240, y = 0})
|
||||
}
|
||||
surface.map_gen_settings = mgs
|
||||
surface.clear(false)
|
||||
for chunk in surface.get_chunks() do
|
||||
surface.delete_chunk({chunk.x, chunk.y})
|
||||
end
|
||||
hatchery.gamestate = "prepare_east"
|
||||
end
|
||||
|
||||
function Public.prepare_east(hatchery)
|
||||
if game.tick % 60 ~= 0 then return end
|
||||
game.print("preparing east", {150, 150, 150})
|
||||
local surface = game.surfaces.nauvis
|
||||
surface.request_to_generate_chunks({hatchery_position.x, 0}, 7)
|
||||
|
||||
if not surface.is_chunk_generated({13, 0}) then return end
|
||||
|
||||
local r = 32
|
||||
local seed = surface.map_gen_settings.seed
|
||||
for x = r * -1, r, 1 do
|
||||
@ -121,55 +97,138 @@ function Public.create_mirror_surface()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
draw_spawn_ore(surface, {x = 240, y = 0})
|
||||
|
||||
for chunk in surface.get_chunks() do
|
||||
if chunk.x < 0 then surface.delete_chunk({chunk.x, chunk.y}) end
|
||||
end
|
||||
hatchery.mirror_queue = {}
|
||||
hatchery.gamestate = "prepare_west"
|
||||
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({x = mirror_left_top.x + 16, y = mirror_left_top.y + 16}, 0)
|
||||
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
|
||||
function Public.prepare_west(hatchery)
|
||||
if game.tick % 60 ~= 0 then return end
|
||||
game.print("preparing west " .. #hatchery.mirror_queue, {150, 150, 150})
|
||||
local surface = game.surfaces.nauvis
|
||||
surface.request_to_generate_chunks({hatchery_position.x * -1, 0}, 7)
|
||||
surface.force_generate_chunk_requests()
|
||||
if #hatchery.mirror_queue > 0 then return end
|
||||
hatchery.gamestate = "draw_team_nests"
|
||||
end
|
||||
|
||||
local function combat_area(event)
|
||||
function Public.draw_team_nests(hatchery)
|
||||
if game.tick % 60 ~= 0 then return end
|
||||
game.print("placing nests", {150, 150, 150})
|
||||
local surface = game.surfaces.nauvis
|
||||
local x = hatchery_position.x
|
||||
|
||||
local e = surface.create_entity({name = "biter-spawner", position = {x * -1, 0}, force = "west"})
|
||||
for _, p in pairs({{x * -1 + 6, 0}, {x * -1 + 3, 6}, {x * -1 + 3, -5}}) do
|
||||
surface.create_entity({name = "small-worm-turret", position = p, force = "west"})
|
||||
surface.create_decoratives{check_collision = false, decoratives = {{name = "enemy-decal", position = p, amount = 1}}}
|
||||
end
|
||||
e.active = false
|
||||
global.map_forces.west.hatchery = e
|
||||
global.map_forces.east.target = e
|
||||
surface.create_decoratives{check_collision = false, decoratives = {{name = "enemy-decal", position = e.position, amount = 3}}}
|
||||
|
||||
local e = surface.create_entity({name = "biter-spawner", position = {x, 0}, force = "east"})
|
||||
for _, p in pairs({{x - 6, 0}, {x - 3, 6}, {x - 3, -5}}) do
|
||||
surface.create_entity({name = "small-worm-turret", position = p, force = "east"})
|
||||
surface.create_decoratives{check_collision = false, decoratives = {{name = "enemy-decal", position = p, amount = 1}}}
|
||||
end
|
||||
|
||||
e.active = false
|
||||
global.map_forces.east.hatchery = e
|
||||
global.map_forces.west.target = e
|
||||
surface.create_decoratives{check_collision = false, decoratives = {{name = "enemy-decal", position = e.position, amount = 3}}}
|
||||
|
||||
hatchery.gamestate = "draw_border_beams"
|
||||
end
|
||||
|
||||
function Public.draw_border_beams(hatchery)
|
||||
if game.tick % 60 ~= 0 then return end
|
||||
local surface = game.surfaces.nauvis
|
||||
surface.create_entity({name = "electric-beam", position = {4, -96}, source = {4, -96}, target = {4,96}})
|
||||
surface.create_entity({name = "electric-beam", position = {-4, -96}, source = {-4, -96}, target = {-4,96}})
|
||||
hatchery.gamestate = "spawn_players"
|
||||
end
|
||||
|
||||
function Public.combat_area(event)
|
||||
local surface = event.surface
|
||||
local left_top = event.area.left_top
|
||||
local seed = surface.map_gen_settings.seed
|
||||
|
||||
if left_top.x >= 256 or left_top.y < -192 or left_top.y > 192 then return end
|
||||
for _, tile in pairs(surface.find_tiles_filtered({area = event.area, name = {"water", "deepwater"}})) do
|
||||
if tile.position.x + math_abs(GetNoise("cave_rivers", {x = 0, y = tile.position.y}, seed) * 64) < 224 then
|
||||
if math_abs(GetNoise("n5", tile.position, seed)) < 0.25 then
|
||||
surface.set_tiles({{name = get_replacement_tile(surface, tile.position), position = tile.position}}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if left_top.x ~= 0 then return end
|
||||
if left_top.y >= 96 then return end
|
||||
if left_top.y < -96 then return end
|
||||
|
||||
for _, tile in pairs(surface.find_tiles_filtered({area = event.area})) do
|
||||
if tile.position.x >= -4 and tile.position.x < 4 then
|
||||
if tile.position.x < 4 then
|
||||
surface.set_tiles({{name = "water-shallow", position = tile.position}}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function is_out_of_map_chunk(p)
|
||||
if p.y < 96 and p.y >= -96 then return end
|
||||
if p.x * 0.5 + 32 >= math_abs(p.y) then return end
|
||||
if p.x * -0.5 + 32 > math_abs(p.y) then return end
|
||||
return true
|
||||
local function mirror_tiles(east_left_top)
|
||||
local surface = game.surfaces.nauvis
|
||||
|
||||
surface.request_to_generate_chunks({x = east_left_top.x + 16, y = east_left_top.y + 16}, 0)
|
||||
surface.force_generate_chunk_requests()
|
||||
|
||||
local mirror_area = {{east_left_top.x, east_left_top.y}, {east_left_top.x + 32, east_left_top.y + 32}}
|
||||
|
||||
for _, tile in pairs(surface.find_tiles_filtered({area = mirror_area})) do
|
||||
surface.set_tiles({{name = tile.name, position = {x = tile.position.x * -1 - 1, y = tile.position.y}}}, true)
|
||||
end
|
||||
end
|
||||
|
||||
local function mirror_entities(east_left_top)
|
||||
local surface = game.surfaces.nauvis
|
||||
local mirror_area = {{east_left_top.x, east_left_top.y}, {east_left_top.x + 32, east_left_top.y + 32}}
|
||||
for _, entity in pairs(surface.find_entities_filtered({area = mirror_area})) do
|
||||
if surface.can_place_entity({name = entity.name, position = {x = entity.position.x * -1, y = entity.position.y}}) then
|
||||
entity.clone({position = {x = entity.position.x * -1, y = entity.position.y}, surface = surface, force = "neutral"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function mirror_decoratives(east_left_top)
|
||||
local surface = game.surfaces.nauvis
|
||||
local mirror_area = {{east_left_top.x, east_left_top.y}, {east_left_top.x + 32, east_left_top.y + 32}}
|
||||
for _, decorative in pairs(surface.find_decoratives_filtered{area = mirror_area}) do
|
||||
surface.create_decoratives{
|
||||
check_collision = false,
|
||||
decoratives = {{name = decorative.decorative.name, position = {x = decorative.position.x * -1 - 1, y = decorative.position.y}, amount = decorative.amount}}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local mirror_functions = {
|
||||
[1] = mirror_tiles,
|
||||
[2] = mirror_entities,
|
||||
[3] = mirror_decoratives,
|
||||
}
|
||||
|
||||
function Public.mirror_queue(hatchery)
|
||||
local mirror_queue = hatchery.mirror_queue
|
||||
local chunk = mirror_queue[1]
|
||||
if not chunk then return end
|
||||
mirror_functions[chunk[2]]({x = chunk[1][1] * -1 - 32, y = chunk[1][2]})
|
||||
mirror_queue[1][2] = mirror_queue[1][2] + 1
|
||||
if not mirror_functions[mirror_queue[1][2]] then
|
||||
table.remove(hatchery.mirror_queue, 1)
|
||||
end
|
||||
end
|
||||
|
||||
local function is_out_of_map(p)
|
||||
@ -179,68 +238,38 @@ local function is_out_of_map(p)
|
||||
return true
|
||||
end
|
||||
|
||||
local function out_of_map_area(event)
|
||||
local surface = event.surface
|
||||
local left_top = event.area.left_top
|
||||
function Public.is_out_of_map_chunk(p)
|
||||
if p.y < 96 and p.y >= -96 then return end
|
||||
if p.x * 0.5 + 32 >= math_abs(p.y) then return end
|
||||
if p.x * -0.5 + 32 > math_abs(p.y) then return end
|
||||
return true
|
||||
end
|
||||
|
||||
function Public.out_of_map_area(surface, left_top)
|
||||
local tiles = {}
|
||||
local i = 1
|
||||
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)
|
||||
tiles[i] = {name = "out-of-map", position = {x = left_top.x + x, y = left_top.y + y}}
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, true)
|
||||
end
|
||||
|
||||
local function modify_source_surface(event)
|
||||
local surface = event.surface
|
||||
local left_top = event.area.left_top
|
||||
if left_top.x >= 256 or left_top.x < 0 or left_top.y < -192 or left_top.y > 192 then return end
|
||||
local seed = surface.map_gen_settings.seed
|
||||
for _, tile in pairs(surface.find_tiles_filtered({area = event.area, name = {"water", "deepwater"}})) do
|
||||
if tile.position.x + math_abs(GetNoise("cave_rivers", {x = 0, y = tile.position.y}, seed) * 64) < 224 then
|
||||
if math_abs(GetNoise("n5", tile.position, seed)) < 0.25 then
|
||||
surface.set_tiles({{name = get_replacement_tile(surface, tile.position), position = tile.position}}, true)
|
||||
end
|
||||
function Public.out_of_map(surface, left_top)
|
||||
local tiles = {}
|
||||
local i = 1
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
tiles[i] = {name = "out-of-map", position = {x = left_top.x + x, y = left_top.y + y}}
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, true)
|
||||
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 modify_source_surface(event) return end
|
||||
|
||||
local left_top = event.area.left_top
|
||||
|
||||
if not is_out_of_map_chunk(left_top) then
|
||||
if left_top.x >= 0 then
|
||||
mirror_chunk(event, source_surface, 1)
|
||||
else
|
||||
mirror_chunk(event, source_surface, -1)
|
||||
end
|
||||
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 == 256 and left_top.y == 256 then
|
||||
create_nests(event.surface)
|
||||
create_border_beams(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)
|
||||
|
||||
return Public
|
Loading…
x
Reference in New Issue
Block a user