mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-05 15:05:57 +02:00
Merge pull request #1088 from Refactorio/Jayefuu-patch-1
Updated crash site /restart command so that auto trusted and regulars can call it when map is cleared
This commit is contained in:
commit
3e9b24fdf0
@ -1,4 +1,5 @@
|
||||
local Command = require 'utils.command'
|
||||
local Rank = require 'features.rank_system'
|
||||
local Task = require 'utils.task'
|
||||
local Token = require 'utils.token'
|
||||
local Server = require 'features.server'
|
||||
@ -6,6 +7,10 @@ local Popup = require 'features.gui.popup'
|
||||
local Global = require 'utils.global'
|
||||
local Ranks = require 'resources.ranks'
|
||||
|
||||
local Public = {}
|
||||
|
||||
function Public.control(config)
|
||||
|
||||
local server_player = {name = '<server>', print = print}
|
||||
|
||||
local global_data = {restarting = nil}
|
||||
@ -47,28 +52,60 @@ callback =
|
||||
end
|
||||
)
|
||||
|
||||
local entities_to_check = {
|
||||
'spitter-spawner','biter-spawner',
|
||||
'small-worm-turret', 'medium-worm-turret','big-worm-turret', 'behemoth-worm-turret',
|
||||
'small-spitter', 'medium-spitter', 'big-spitter', 'behemoth-spitter',
|
||||
'small-biter', 'medium-biter', 'big-biter', 'behemoth-biter',
|
||||
'gun-turret', 'laser-turret', 'artillery-turret', 'flamethrower-turret'
|
||||
}
|
||||
|
||||
local function map_cleared()
|
||||
local get_entity_count = game.forces["enemy"].get_entity_count
|
||||
for i = 1, #entities_to_check do
|
||||
local name = entities_to_check[i]
|
||||
if get_entity_count(name) > 0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function restart(args, player)
|
||||
player = player or server_player
|
||||
local sanitised_scenario = args.scenario_name
|
||||
|
||||
if global_data.restarting then
|
||||
player.print('Restart already in progress')
|
||||
return
|
||||
end
|
||||
|
||||
if player ~= server_player and Rank.less_than(player.name, Ranks.admin) then
|
||||
-- Check enemy count
|
||||
if not map_cleared() then
|
||||
player.print('All enemy spawners, worms, buildings, biters and spitters must be cleared for non-admin restart.')
|
||||
return
|
||||
end
|
||||
|
||||
-- Limit the ability of non-admins to call the restart function with arguments to change the scenario
|
||||
-- If not an admin, restart the same scenario always
|
||||
sanitised_scenario = config.scenario_name
|
||||
end
|
||||
|
||||
global_data.restarting = true
|
||||
|
||||
double_print('#################-Attention-#################')
|
||||
double_print('Server restart initiated by ' .. player.name)
|
||||
double_print('###########################################')
|
||||
|
||||
for k, v in pairs(game.players) do
|
||||
if v.admin then
|
||||
game.print('Abort restart with /abort')
|
||||
for _, p in pairs(game.players) do
|
||||
if p.admin then
|
||||
p.print('Abort restart with /abort')
|
||||
end
|
||||
end
|
||||
print('Abort restart with /abort')
|
||||
|
||||
Task.set_timeout_in_ticks(60, callback, {name = player.name, scenario_name = args.scenario_name, state = 10})
|
||||
Task.set_timeout_in_ticks(60, callback, {name = player.name, scenario_name = sanitised_scenario, state = 10})
|
||||
end
|
||||
|
||||
local function abort(_, player)
|
||||
@ -102,9 +139,7 @@ Command.add(
|
||||
abort
|
||||
)
|
||||
|
||||
local Public = {}
|
||||
|
||||
function Public.control(config)
|
||||
local default_name = config.scenario_name or 'crashsite'
|
||||
Command.add(
|
||||
'crash-site-restart',
|
||||
@ -124,7 +159,7 @@ function Public.control(config)
|
||||
description = {'command_description.crash_site_restart'},
|
||||
arguments = {'scenario_name'},
|
||||
default_values = {scenario_name = default_name},
|
||||
required_rank = Ranks.admin,
|
||||
required_rank = Ranks.auto_trusted,
|
||||
allowed_by_server = true
|
||||
},
|
||||
restart
|
||||
|
@ -17,6 +17,7 @@ local RedmewConfig = require 'config'
|
||||
local Cutscene = require 'map_gen.maps.crash_site.cutscene'
|
||||
|
||||
local degrees = math.degrees
|
||||
local cutscene_force_name = 'cutscene'
|
||||
|
||||
local default_map_gen_settings = {
|
||||
MGSP.grass_only,
|
||||
@ -140,7 +141,7 @@ local spawn_callback =
|
||||
)
|
||||
|
||||
local function cutscene_builder(name, x, y)
|
||||
return game.surfaces.cutscene.create_entity {name = name, position = {x, y}, force = game.forces.enemy}
|
||||
return game.surfaces.cutscene.create_entity {name = name, position = {x, y}, force = cutscene_force_name}
|
||||
end
|
||||
|
||||
local function cutscene_outpost()
|
||||
@ -838,6 +839,11 @@ local map
|
||||
Global.register_init(
|
||||
{},
|
||||
function(tbl)
|
||||
game.create_force(cutscene_force_name)
|
||||
local surface = game.surfaces[1]
|
||||
surface.map_gen_settings = {width = 2, height = 2}
|
||||
surface.clear()
|
||||
|
||||
local seed = RS.get_surface().map_gen_settings.seed
|
||||
tbl.outpost_seed = outpost_seed or seed
|
||||
tbl.ore_seed = ore_seed or seed
|
||||
|
Loading…
x
Reference in New Issue
Block a user