2019-10-28 18:38:36 +02:00
|
|
|
local Server = require 'utils.server'
|
|
|
|
|
|
|
|
local Public = {}
|
|
|
|
|
2019-10-07 16:40:52 +02:00
|
|
|
local function reset_forces(new_surface, old_surface)
|
2019-08-20 22:33:47 +02:00
|
|
|
for _, f in pairs(game.forces) do
|
2019-10-07 16:40:52 +02:00
|
|
|
local spawn = {x = game.forces.player.get_spawn_position(old_surface).x, y = game.forces.player.get_spawn_position(old_surface).y}
|
2019-08-20 22:33:47 +02:00
|
|
|
f.reset()
|
2019-08-23 14:41:32 +02:00
|
|
|
f.reset_evolution()
|
2019-10-07 16:40:52 +02:00
|
|
|
f.set_spawn_position(spawn, new_surface)
|
2019-08-20 22:33:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function teleport_players(surface)
|
|
|
|
for _, player in pairs(game.connected_players) do
|
|
|
|
local spawn = player.force.get_spawn_position(surface)
|
|
|
|
local chunk = {math.floor(spawn.x / 32), math.floor(spawn.y / 32)}
|
|
|
|
if not surface.is_chunk_generated(chunk) then
|
2019-10-07 16:40:52 +02:00
|
|
|
surface.request_to_generate_chunks(spawn, 1)
|
2019-08-20 22:33:47 +02:00
|
|
|
surface.force_generate_chunk_requests()
|
|
|
|
end
|
2019-09-08 00:22:17 +02:00
|
|
|
local pos = surface.find_non_colliding_position("character", spawn, 3, 0.5)
|
2019-08-20 22:33:47 +02:00
|
|
|
player.teleport(pos, surface)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function equip_players(player_starting_items)
|
|
|
|
for k, player in pairs(game.connected_players) do
|
|
|
|
if player.character then player.character.destroy() end
|
|
|
|
player.character = nil
|
|
|
|
player.set_controller({type=defines.controllers.god})
|
|
|
|
player.create_character()
|
|
|
|
for item, amount in pairs(player_starting_items) do
|
|
|
|
player.insert({name = item, count = amount})
|
|
|
|
end
|
2019-10-28 12:15:39 +02:00
|
|
|
update_player_modifiers(player)
|
2019-08-20 22:33:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-28 18:38:36 +02:00
|
|
|
function Public.soft_reset_map(old_surface, map_gen_settings, player_starting_items)
|
2019-08-20 22:33:47 +02:00
|
|
|
if not global.soft_reset_counter then global.soft_reset_counter = 0 end
|
|
|
|
if not global.original_surface_name then global.original_surface_name = old_surface.name end
|
|
|
|
global.soft_reset_counter = global.soft_reset_counter + 1
|
|
|
|
|
|
|
|
local new_surface = game.create_surface(global.original_surface_name .. "_" .. tostring(global.soft_reset_counter), map_gen_settings)
|
2019-10-07 16:40:52 +02:00
|
|
|
new_surface.request_to_generate_chunks({0,0}, 1)
|
2019-08-20 22:33:47 +02:00
|
|
|
new_surface.force_generate_chunk_requests()
|
|
|
|
|
2019-10-07 16:40:52 +02:00
|
|
|
reset_forces(new_surface, old_surface)
|
2019-08-20 22:33:47 +02:00
|
|
|
teleport_players(new_surface)
|
|
|
|
equip_players(player_starting_items)
|
|
|
|
|
|
|
|
game.delete_surface(old_surface)
|
|
|
|
|
2019-08-23 14:41:32 +02:00
|
|
|
local message = table.concat({">> Welcome to ", global.original_surface_name, "!"})
|
2019-08-20 22:33:47 +02:00
|
|
|
if global.soft_reset_counter > 1 then
|
2019-08-23 14:41:32 +02:00
|
|
|
message = table.concat({">> The world has been reshaped, welcome to ", global.original_surface_name, " number ", tostring(global.soft_reset_counter), "!"})
|
2019-08-20 22:33:47 +02:00
|
|
|
end
|
2019-08-23 14:41:32 +02:00
|
|
|
game.print(message, {r=0.98, g=0.66, b=0.22})
|
2019-10-28 18:38:36 +02:00
|
|
|
Server.to_discord_embed(message)
|
2019-08-20 22:33:47 +02:00
|
|
|
|
|
|
|
return new_surface
|
2019-10-28 18:38:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return Public
|