1
0
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:
Matthew 2019-02-16 16:48:41 -05:00 committed by GitHub
commit 3526ccf1e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 66 deletions

View File

@ -503,9 +503,7 @@ Command.add(
Command.add( Command.add(
'apocalypse', 'apocalypse',
{ {
description = "Calls for the endtimes. This really ends the map, so you must use '/apocalypse end this map'", description = "This really ends the map. When you first run it, the game will save. When run a second time, the apocalypse will begin.",
arguments = {'confirmation'},
capture_excess_arguments = true,
required_rank = Ranks.admin, required_rank = Ranks.admin,
}, },
Apocalypse.begin_apocalypse Apocalypse.begin_apocalypse

View File

@ -1,26 +1,54 @@
local table = require 'utils.table'
local Task = require 'utils.task' local Task = require 'utils.task'
local Token = require 'utils.token' local Token = require 'utils.token'
local Game = require 'utils.game' local Game = require 'utils.game'
local Global = require 'utils.global'
local Toast = require 'features.gui.toast' local Toast = require 'features.gui.toast'
local RS = require 'map_gen.shared.redmew_surface' local RS = require 'map_gen.shared.redmew_surface'
local HailHydra = require 'map_gen.shared.hail_hydra' local HailHydra = require 'map_gen.shared.hail_hydra'
local Color = require 'resources.color_presets'
local clear_table = table.clear_table -- Constants
local hail_hydra_data = {
local Public = {}
local hydra_config = {
['behemoth-spitter'] = {['behemoth-spitter'] = 0.01}, ['behemoth-spitter'] = {['behemoth-spitter'] = 0.01},
['behemoth-biter'] = {['behemoth-biter'] = 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 = local biter_spawn_token =
Token.register( Token.register(
function(data) function()
local surface = data.surface local surface
local group = data.group local player_force
local p_spawn = data.p_spawn 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 local create_entity = surface.create_entity
@ -34,61 +62,39 @@ local biter_spawn_token =
for i = 1, #aliens do for i = 1, #aliens do
local spawn_pos = surface.find_non_colliding_position('behemoth-biter', p_spawn, 300, 1) local spawn_pos = surface.find_non_colliding_position('behemoth-biter', p_spawn, 300, 1)
if spawn_pos then 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) group.add_member(biter)
end end
end end
group.set_command({type = defines.command.attack_area, destination = {0, 0}, radius = 500}) 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 end
) )
function Public.begin_apocalypse(args, player) --- Begins the apocalypse
if args.confirmation ~= 'end this map' then function Public.begin_apocalypse(_, player)
Game.player_print('You must use /apocalypse end this map') local index
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
if player and player.valid then if player and player.valid then
surface = player.surface index = player.index
player_force = player.force elseif not player then
else index = 0
surface = RS.get_surface()
player_force = game.forces.player
end end
local hydras = global.config.hail_hydra.hydras -- Check if the apocalypse is happening or if it's the first run of the command.
clear_table(hydras) if primitives.apocalypse_now then
for k, v in pairs(hydra_config) do Game.player_print({'apocalypse.apocalypse_already_running'}, Color.yellow)
hydras[k] = v 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 end
HailHydra.enable_hail_hydra()
enemy_force.evolution_factor = 1
local p_spawn = player_force.get_spawn_position(surface) primitives.apocalypse_now = true
local group = surface.create_unit_group {position = p_spawn} game.print({'apocalypse.apocalypse_begins'}, Color.pink)
Task.set_timeout(15, biter_spawn_token, {})
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
}
)
end end
return Public return Public

View File

@ -20,3 +20,9 @@ regular_remove_fail=__1__ is rank __2__ their regular status cannot be removed.
[redmew_commands] [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 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.

View File

@ -3,27 +3,36 @@ local Event = require 'utils.event'
local CreateParticles = require 'features.create_particles' local CreateParticles = require 'features.create_particles'
local Token = require 'utils.token' local Token = require 'utils.token'
local Global = require 'utils.global' local Global = require 'utils.global'
local table = require 'utils.table'
local random = math.random local random = math.random
local floor = math.floor local floor = math.floor
local ceil = math.ceil local ceil = math.ceil
local pairs = pairs local pairs = pairs
local clear_table = table.clear_table
local compound = defines.command.compound local compound = defines.command.compound
local logical_or = defines.compound_command.logical_or local logical_or = defines.compound_command.logical_or
local attack = defines.command.attack local attack = defines.command.attack
local attack_area = defines.command.attack_area 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( Global.register(
{ {
primitives = primitives primitives = primitives,
spawn_table = spawn_table
}, },
function(tbl) function(tbl)
primitives = tbl.primitives primitives = tbl.primitives
spawn_table = tbl.spawn_table
end end
) )
@ -51,14 +60,14 @@ local on_died =
local entity = event.entity local entity = event.entity
local name = entity.name local name = entity.name
local hydra = hydras[name] local hydra = spawn_table[name]
if not hydra then if not hydra then
return return
end end
local position = entity.position local position = entity.position
local force = entity.force 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 cause = event.cause
local surface = entity.surface local surface = entity.surface
@ -108,14 +117,12 @@ local function register_event()
end end
end end
if config.enabled then --- Enables hail_hydra
register_event()
end
function Public.enable_hail_hydra() function Public.enable_hail_hydra()
register_event() register_event()
end end
--- Disables hail_hydra
function Public.disable_hail_hydra() function Public.disable_hail_hydra()
if primitives.enabled then if primitives.enabled then
Event.remove_removable(defines.events.on_entity_died, on_died) Event.remove_removable(defines.events.on_entity_died, on_died)
@ -123,4 +130,31 @@ function Public.disable_hail_hydra()
end end
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 return Public