1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Merge pull request #1131 from grilledham/danger_ore_restart

Danger ore: Add simple rocket launch condition and restart command.
This commit is contained in:
grilledham 2020-12-29 12:58:32 +00:00 committed by GitHub
commit b7ad574517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 258 additions and 69 deletions

View File

@ -4,6 +4,9 @@
[command_description]
reward=Gives a reward to a target player (removes if quantity is negative)
diggy_clear_void=Clears the void in a given area but still triggers all events Diggy would when clearing void.
restart=Restarts the map.
abort=Aborts a restart.
danger_ore_restart_condition_not_met=Not enough [item=satellite] have been launched to restart the map.
crash_site_restart=Restarts the crashsite scenario.
crash_site_restart_abort=Aborts the restart of the crashsite scenario.
crash_site_spy=Spend coins to send a fish to spy on the enemy for a short time.

View File

@ -169,3 +169,9 @@ entity_not_enough_ground_support=__1__ requires at least: __2__
anti_grief_kick_reason=Spilling too many items on the ground
anti_grief_jail_reason=You have spilled too many items on the ground, contact an admin
[danger_ores]
biters_disabled=Launching the first [item=satellite] has killed all the biters. Launch __1__ [item=satellite] to win the map.
win=Congratulations! The map has been won. Restart the map with /restart
satellite_launch=Launch another __1__ [item=satellite] to win the map.

View File

@ -26,7 +26,7 @@ local function spawn_builder(config)
end
local function tile_builder_factory(config)
local tile_builder_scale = config.tile_builder_scale or 1 / 64
local tile_builder_scale = config.tile_builder_scale or (1 / 64)
local seed = seed_provider()
return function(tiles)

View File

@ -0,0 +1,113 @@
local Command = require 'utils.command'
local Rank = require 'features.rank_system'
local Ranks = require 'resources.ranks'
local Global = require 'utils.global'
local Discord = require 'resources.discord'
local Server = require 'features.server'
local Popup = require 'features.gui.popup'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Core = require 'utils.core'
local ShareGlobals = require 'map_gen.maps.danger_ores.modules.shared_globals'
return function(config)
local default_name = config.scenario_name or 'terraforming-danger-ore'
local map_promotion_channel = Discord.channel_names.map_promotion
local danger_ore_role_mention = Discord.role_mentions.danger_ore
local server_player = {name = '<server>', print = print}
local global_data = {restarting = nil}
Global.register(global_data, function(tbl)
global_data = tbl
end)
local function double_print(str)
game.print(str)
print(str)
end
local callback
callback = Token.register(function(data)
if not global_data.restarting then
return
end
local state = data.state
if state == 0 then
Server.start_scenario(data.scenario_name)
double_print('restarting')
global_data.restarting = nil
return
elseif state == 1 then
Popup.all('\nServer restarting!\nInitiated by ' .. data.name .. '\n')
local time_string = Core.format_time(game.ticks_played)
Server.to_discord_named_raw(map_promotion_channel, danger_ore_role_mention
.. ' **Danger Ore has just restarted! Previous map lasted: ' .. time_string .. '!**')
end
double_print(state)
data.state = state - 1
Task.set_timeout_in_ticks(60, callback, data)
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
if not ShareGlobals.data.map_won then
player.print({'command_description.danger_ore_restart_condition_not_met'})
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 _, 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 = sanitised_scenario, state = 10})
end
local function abort(_, player)
player = player or server_player
if global_data.restarting then
global_data.restarting = nil
double_print('Restart aborted by ' .. player.name)
else
player.print('Cannot abort a restart that is not in progress.')
end
end
Command.add('abort',
{description = {'command_description.abort'}, required_rank = Ranks.admin, allowed_by_server = true}, abort)
Command.add('restart', {
description = {'command_description.restart'},
arguments = {'scenario_name'},
default_values = {scenario_name = default_name},
required_rank = Ranks.guest,
allowed_by_server = true
}, restart)
end

View File

@ -12,7 +12,7 @@ local ShareGlobals = require 'map_gen.maps.danger_ores.modules.shared_globals'
return function(config)
local recent_chunks = Queue.new() -- Keeps track of recently revealed chunks
local recent_chunks_max = config.recent_chunks_max or 10 -- Maximum number of chunks to track
local ticks_between_waves = config.ticks_between_waves or 60 * 30
local ticks_between_waves = config.ticks_between_waves or (60 * 30)
local enemy_factor = config.enemy_factor or 5
local max_enemies_per_wave_per_chunk = config.max_enemies_per_wave_per_chunk or 60

View File

@ -0,0 +1,90 @@
local Event = require 'utils.event'
local RS = require 'map_gen.shared.redmew_surface'
local Server = require 'features.server'
local ShareGlobals = require 'map_gen.maps.danger_ores.modules.shared_globals'
return function(config)
ShareGlobals.data.biters_disabled = false
ShareGlobals.data.map_won = false
local win_satellite_count = config.win_satellite_count or 1000
local function disable_biters()
if ShareGlobals.data.biters_disabled then
return
end
ShareGlobals.data.biters_disabled = true
game.forces.enemy.kill_all_units()
for _, enemy_entity in pairs(RS.get_surface().find_entities_filtered({force = 'enemy'})) do
enemy_entity.destroy()
end
local message = table.concat {
'Launching the first satellite has killed all the biters. ',
'Launch ',
win_satellite_count,
' satellites to win the map.'
}
game.print({'danger_ores.biters_disabled', win_satellite_count})
Server.to_discord_bold(message)
end
local function win()
if ShareGlobals.data.map_won then
return
end
ShareGlobals.data.map_won = true
local message = 'Congratulations! The map has been won. Restart the map with /restart'
game.print({'danger_ores.win'})
Server.to_discord_bold(message)
end
local function print_satellite_message(count)
local remaining_count = win_satellite_count - count
if remaining_count <= 0 then
return
end
local message = table.concat {'Launch another ', remaining_count, ' satellites to win the map.'}
game.print({'danger_ores.satellite_launch', remaining_count})
Server.to_discord_bold(message)
end
local function rocket_launched(event)
if ShareGlobals.data.map_won then
return
end
local entity = event.rocket
if not entity or not entity.valid or not entity.force == 'player' then
return
end
local inventory = entity.get_inventory(defines.inventory.rocket)
if not inventory or not inventory.valid then
return
end
local satellite_count = game.forces.player.get_item_launched('satellite')
if satellite_count == 0 then
return
end
if satellite_count == 1 then
disable_biters()
end
if satellite_count == win_satellite_count then
win()
return
end
if (satellite_count % 50) == 0 then
print_satellite_message(satellite_count)
end
end
Event.add(defines.events.on_rocket_launched, rocket_launched)
end

View File

@ -5,15 +5,12 @@ local b = require 'map_gen.shared.builders'
local ScenarioInfo = require 'features.gui.info'
ScenarioInfo.set_map_name('Terraforming Danger Ore')
ScenarioInfo.set_map_description(
[[
ScenarioInfo.set_map_description([[
Clear the ore to expand the base,
focus mining efforts on specific quadrants to ensure
proper material ratios, expand the map with pollution!
]]
)
ScenarioInfo.add_map_extra_info(
[[
]])
ScenarioInfo.add_map_extra_info([[
This map is split in four quadrants. Each quadrant has a main resource.
[item=iron-ore] north, [item=copper-ore] south, [item=coal] east, [item=stone] west
@ -23,18 +20,14 @@ You may not build the factory on ore patches. Exceptions:
The map size is restricted to the pollution generated. A significant amount of
pollution must affect a section of the map before it is revealed. Pollution
does not affect biter evolution.]]
)
does not affect biter evolution.]])
ScenarioInfo.set_map_description(
[[
ScenarioInfo.set_map_description([[
Clear the ore to expand the base,
focus mining efforts on specific quadrants to ensure
proper material ratios, expand the map with pollution!
]]
)
ScenarioInfo.set_new_info(
[[
]])
ScenarioInfo.set_new_info([[
2019-04-24:
- Stone ore density reduced by 1/2
- Ore quadrants randomized
@ -52,10 +45,12 @@ ScenarioInfo.set_new_info(
2019-03-27:
- Ore arranged into quadrants to allow for more controlled resource gathering.
2020-09-02
2020-09-02:
- Destroyed chests dump their content as coal ore.
]]
)
2020-12-28:
- Changed win condition. First satellite kills all biters, launch 1000 to win the map.
]])
local map = require 'map_gen.maps.danger_ores.modules.map'
local main_ores_config = require 'map_gen.maps.danger_ores.config.vanilla_ores'
@ -70,62 +65,43 @@ local banned_entities = require 'map_gen.maps.danger_ores.modules.banned_entitie
local allowed_entities = require 'map_gen.maps.danger_ores.config.vanilla_allowed_entities'
banned_entities(allowed_entities)
RS.set_map_gen_settings(
{
MGSP.grass_only,
MGSP.enable_water,
{
terrain_segmentation = 'normal',
water = 'normal'
},
MGSP.starting_area_very_low,
MGSP.ore_oil_none,
MGSP.enemy_none,
MGSP.cliff_none,
MGSP.tree_none
}
)
RS.set_map_gen_settings({
MGSP.grass_only,
MGSP.enable_water,
{terrain_segmentation = 'normal', water = 'normal'},
MGSP.starting_area_very_low,
MGSP.ore_oil_none,
MGSP.enemy_none,
MGSP.cliff_none,
MGSP.tree_none
})
Event.on_init(
function()
game.draw_resource_selection = false
game.forces.player.technologies['mining-productivity-1'].enabled = false
game.forces.player.technologies['mining-productivity-2'].enabled = false
game.forces.player.technologies['mining-productivity-3'].enabled = false
game.forces.player.technologies['mining-productivity-4'].enabled = false
Event.on_init(function()
game.draw_resource_selection = false
game.forces.player.technologies['mining-productivity-1'].enabled = false
game.forces.player.technologies['mining-productivity-2'].enabled = false
game.forces.player.technologies['mining-productivity-3'].enabled = false
game.forces.player.technologies['mining-productivity-4'].enabled = false
game.difficulty_settings.technology_price_multiplier = 25
game.forces.player.technologies.logistics.researched = true
game.forces.player.technologies.automation.researched = true
game.difficulty_settings.technology_price_multiplier = 25
game.forces.player.technologies.logistics.researched = true
game.forces.player.technologies.automation.researched = true
game.map_settings.enemy_evolution.time_factor = 0.000007 -- default 0.000004
game.map_settings.enemy_evolution.destroy_factor = 0.000010 -- default 0.002
game.map_settings.enemy_evolution.pollution_factor = 0.000000 -- Pollution has no affect on evolution default 0.0000009
game.map_settings.enemy_evolution.time_factor = 0.000007 -- default 0.000004
game.map_settings.enemy_evolution.destroy_factor = 0.000010 -- default 0.002
game.map_settings.enemy_evolution.pollution_factor = 0.000000 -- Pollution has no affect on evolution default 0.0000009
RS.get_surface().always_day = true
end
)
RS.get_surface().always_day = true
end)
local terraforming = require 'map_gen.maps.danger_ores.modules.terraforming'
terraforming(
{
start_size = 8 * 32,
min_pollution = 300,
max_pollution = 5000,
pollution_increment = 2.5
}
)
terraforming({start_size = 8 * 32, min_pollution = 300, max_pollution = 6000, pollution_increment = 2.5})
local rocket_launched = require 'map_gen.maps.danger_ores.modules.rocket_launched'
rocket_launched(
{
recent_chunks_max = 10,
ticks_between_waves = 60 * 30,
enemy_factor = 3,
max_enemies_per_wave_per_chunk = 60,
extra_rockets = 100
}
)
local rocket_launched = require 'map_gen.maps.danger_ores.modules.rocket_launched_simple'
rocket_launched({win_satellite_count = 1000})
local restart_command = require 'map_gen.maps.danger_ores.modules.restart_command'
restart_command({scenario_name = 'terraforming-danger-ore'})
local container_dump = require 'map_gen.maps.danger_ores.modules.container_dump'
container_dump({entity_name = 'coal'})
@ -134,7 +110,7 @@ local config = {
spawn_shape = b.circle(64),
start_ore_shape = b.circle(68),
main_ores = main_ores_config,
--main_ores_shuffle_order = true,
main_ores_shuffle_order = true,
main_ores_rotate = 45,
resource_patches = resource_patches,
resource_patches_config = resource_patches_config,

View File

@ -13,6 +13,7 @@ return {
role_mentions = {
test = '<@&593534612051984431>',
crash_site = '<@&762441731194748958>',
danger_ore = '<@&793231011144007730>',
moderator = '<@&454192594633883658>'
}
}