mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
Merge pull request #756 from plague006/fix/apocalypse_hail_hydra_desync
Fix/apocalypse hail hydra desync
This commit is contained in:
commit
3526ccf1e4
@ -503,9 +503,7 @@ Command.add(
|
||||
Command.add(
|
||||
'apocalypse',
|
||||
{
|
||||
description = "Calls for the endtimes. This really ends the map, so you must use '/apocalypse end this map'",
|
||||
arguments = {'confirmation'},
|
||||
capture_excess_arguments = true,
|
||||
description = "This really ends the map. When you first run it, the game will save. When run a second time, the apocalypse will begin.",
|
||||
required_rank = Ranks.admin,
|
||||
},
|
||||
Apocalypse.begin_apocalypse
|
||||
|
@ -1,26 +1,54 @@
|
||||
local table = require 'utils.table'
|
||||
local Task = require 'utils.task'
|
||||
local Token = require 'utils.token'
|
||||
local Game = require 'utils.game'
|
||||
local Global = require 'utils.global'
|
||||
local Toast = require 'features.gui.toast'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local HailHydra = require 'map_gen.shared.hail_hydra'
|
||||
local Color = require 'resources.color_presets'
|
||||
|
||||
local clear_table = table.clear_table
|
||||
|
||||
local Public = {}
|
||||
|
||||
local hydra_config = {
|
||||
-- Constants
|
||||
local hail_hydra_data = {
|
||||
['behemoth-spitter'] = {['behemoth-spitter'] = 0.01},
|
||||
['behemoth-biter'] = {['behemoth-biter'] = 0.01}
|
||||
}
|
||||
|
||||
-- Local var
|
||||
local Public = {}
|
||||
|
||||
-- Global vars
|
||||
local second_run = {}
|
||||
local primitives = {
|
||||
apocalypse_now = nil
|
||||
}
|
||||
|
||||
Global.register(
|
||||
{
|
||||
primitives = primitives,
|
||||
second_run = second_run
|
||||
},
|
||||
function(tbl)
|
||||
primitives = tbl.primitives
|
||||
second_run = tbl.second_run
|
||||
end
|
||||
)
|
||||
|
||||
local biter_spawn_token =
|
||||
Token.register(
|
||||
function(data)
|
||||
local surface = data.surface
|
||||
local group = data.group
|
||||
local p_spawn = data.p_spawn
|
||||
function()
|
||||
local surface
|
||||
local player_force
|
||||
local enemy_force = game.forces.enemy
|
||||
|
||||
surface = RS.get_surface()
|
||||
player_force = game.forces.player
|
||||
|
||||
HailHydra.set_hydras(hail_hydra_data)
|
||||
HailHydra.enable_hail_hydra()
|
||||
enemy_force.evolution_factor = 1
|
||||
|
||||
local p_spawn = player_force.get_spawn_position(surface)
|
||||
local group = surface.create_unit_group {position = p_spawn}
|
||||
|
||||
local create_entity = surface.create_entity
|
||||
|
||||
@ -34,61 +62,39 @@ local biter_spawn_token =
|
||||
for i = 1, #aliens do
|
||||
local spawn_pos = surface.find_non_colliding_position('behemoth-biter', p_spawn, 300, 1)
|
||||
if spawn_pos then
|
||||
local biter = create_entity {name = aliens[i], position = spawn_pos}
|
||||
local biter = create_entity({name = aliens[i], position = spawn_pos})
|
||||
group.add_member(biter)
|
||||
end
|
||||
end
|
||||
|
||||
group.set_command({type = defines.command.attack_area, destination = {0, 0}, radius = 500})
|
||||
Toast.toast_all_players(500, 'The end times are here. The four biters of the apocalypse have been summoned. Repent as the aliens take back what is theirs.')
|
||||
Toast.toast_all_players(500, {'apocalypse.toast_message'})
|
||||
end
|
||||
)
|
||||
|
||||
function Public.begin_apocalypse(args, player)
|
||||
if args.confirmation ~= 'end this map' then
|
||||
Game.player_print('You must use /apocalypse end this map')
|
||||
return
|
||||
end
|
||||
|
||||
if global.apocalypse_now then
|
||||
return
|
||||
end
|
||||
game.server_save('pre-apocalypse')
|
||||
global.apocalypse_now = true
|
||||
local surface
|
||||
local player_force
|
||||
local enemy_force = game.forces.enemy
|
||||
|
||||
--- Begins the apocalypse
|
||||
function Public.begin_apocalypse(_, player)
|
||||
local index
|
||||
if player and player.valid then
|
||||
surface = player.surface
|
||||
player_force = player.force
|
||||
else
|
||||
surface = RS.get_surface()
|
||||
player_force = game.forces.player
|
||||
index = player.index
|
||||
elseif not player then
|
||||
index = 0
|
||||
end
|
||||
|
||||
local hydras = global.config.hail_hydra.hydras
|
||||
clear_table(hydras)
|
||||
for k, v in pairs(hydra_config) do
|
||||
hydras[k] = v
|
||||
-- Check if the apocalypse is happening or if it's the first run of the command.
|
||||
if primitives.apocalypse_now then
|
||||
Game.player_print({'apocalypse.apocalypse_already_running'}, Color.yellow)
|
||||
return
|
||||
elseif not second_run[index] then
|
||||
second_run[index] = true
|
||||
game.server_save('pre-apocalypse-' .. index)
|
||||
Game.player_print({'apocalypse.run_twice'})
|
||||
return
|
||||
end
|
||||
HailHydra.enable_hail_hydra()
|
||||
enemy_force.evolution_factor = 1
|
||||
|
||||
local p_spawn = player_force.get_spawn_position(surface)
|
||||
local group = surface.create_unit_group {position = p_spawn}
|
||||
|
||||
game.print('The ground begins to rumble. It seems as if the world itself is coming to an end.')
|
||||
|
||||
Task.set_timeout(
|
||||
60,
|
||||
biter_spawn_token,
|
||||
{
|
||||
p_spawn = p_spawn,
|
||||
group = group,
|
||||
surface = surface
|
||||
}
|
||||
)
|
||||
primitives.apocalypse_now = true
|
||||
game.print({'apocalypse.apocalypse_begins'}, Color.pink)
|
||||
Task.set_timeout(15, biter_spawn_token, {})
|
||||
end
|
||||
|
||||
return Public
|
||||
|
@ -20,3 +20,9 @@ regular_remove_fail=__1__ is rank __2__ their regular status cannot be removed.
|
||||
|
||||
[redmew_commands]
|
||||
whois_formatter=__1__\n__2__\n__3__\n__4__\n__5__\n__6__\n__7__\n__8__\n__9__\n__10__\n__11__\n__12__\n__13__\n__14__\n__15__\n__16__\n
|
||||
|
||||
[apocalypse]
|
||||
run_twice=The game has been saved, run the command again to commence the apocalypse.
|
||||
apocalypse_begins=The ground begins to rumble. It seems as if the world itself is coming to an end.
|
||||
apocalypse_already_running=The apocalypse has already begun. There is nothing more to do in this world.
|
||||
toast_message=The end times are here. The four biters of the apocalypse have been summoned. Repent as the aliens take back what is theirs.
|
||||
|
@ -3,27 +3,36 @@ local Event = require 'utils.event'
|
||||
local CreateParticles = require 'features.create_particles'
|
||||
local Token = require 'utils.token'
|
||||
local Global = require 'utils.global'
|
||||
local table = require 'utils.table'
|
||||
|
||||
local random = math.random
|
||||
local floor = math.floor
|
||||
local ceil = math.ceil
|
||||
local pairs = pairs
|
||||
local clear_table = table.clear_table
|
||||
local compound = defines.command.compound
|
||||
local logical_or = defines.compound_command.logical_or
|
||||
local attack = defines.command.attack
|
||||
local attack_area = defines.command.attack_area
|
||||
local config = global.config.hail_hydra
|
||||
local evolution_scale = config.evolution_scale
|
||||
local hydras = config.hydras
|
||||
|
||||
local primitives = {enabled = nil}
|
||||
local spawn_table = {}
|
||||
for k, v in pairs(global.config.hail_hydra.hydras) do
|
||||
spawn_table[k] = v
|
||||
end
|
||||
|
||||
local primitives = {
|
||||
evolution_scale = global.config.hail_hydra.evolution_scale,
|
||||
enabled = nil
|
||||
}
|
||||
|
||||
Global.register(
|
||||
{
|
||||
primitives = primitives
|
||||
primitives = primitives,
|
||||
spawn_table = spawn_table
|
||||
},
|
||||
function(tbl)
|
||||
primitives = tbl.primitives
|
||||
spawn_table = tbl.spawn_table
|
||||
end
|
||||
)
|
||||
|
||||
@ -51,14 +60,14 @@ local on_died =
|
||||
local entity = event.entity
|
||||
local name = entity.name
|
||||
|
||||
local hydra = hydras[name]
|
||||
local hydra = spawn_table[name]
|
||||
if not hydra then
|
||||
return
|
||||
end
|
||||
|
||||
local position = entity.position
|
||||
local force = entity.force
|
||||
local evolution_factor = force.evolution_factor * evolution_scale
|
||||
local evolution_factor = force.evolution_factor * primitives.evolution_scale
|
||||
local cause = event.cause
|
||||
|
||||
local surface = entity.surface
|
||||
@ -108,14 +117,12 @@ local function register_event()
|
||||
end
|
||||
end
|
||||
|
||||
if config.enabled then
|
||||
register_event()
|
||||
end
|
||||
|
||||
--- Enables hail_hydra
|
||||
function Public.enable_hail_hydra()
|
||||
register_event()
|
||||
end
|
||||
|
||||
--- Disables hail_hydra
|
||||
function Public.disable_hail_hydra()
|
||||
if primitives.enabled then
|
||||
Event.remove_removable(defines.events.on_entity_died, on_died)
|
||||
@ -123,4 +130,31 @@ function Public.disable_hail_hydra()
|
||||
end
|
||||
end
|
||||
|
||||
--- Sets the evolution scale
|
||||
-- @param scale <number>
|
||||
function Public.set_evolution_scale(scale)
|
||||
primitives.evolution_scale = scale
|
||||
end
|
||||
|
||||
--- Sets the hydra spawning table
|
||||
-- @param hydras <table> see config.lua's hail_hydra section for example
|
||||
function Public.set_hydras(hydras)
|
||||
clear_table(spawn_table)
|
||||
for k, v in pairs(hydras) do
|
||||
spawn_table[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
--- Adds to/overwrites parts of the hydra spawning table
|
||||
-- @param hydras <table> see config.lua's hail_hydra section for example
|
||||
function Public.add_hydras(hydras)
|
||||
for k, v in pairs(hydras) do
|
||||
spawn_table[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
if global.config.hail_hydra.enabled then
|
||||
register_event()
|
||||
end
|
||||
|
||||
return Public
|
||||
|
Loading…
x
Reference in New Issue
Block a user