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

Merge pull request #745 from plague006/apocalypse

Add apocalypse
This commit is contained in:
Matthew 2019-02-14 12:20:10 -05:00 committed by GitHub
commit 16c119096f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 198 additions and 44 deletions

View File

@ -3,6 +3,7 @@ local Token = require 'utils.token'
local Global = require 'utils.global' local Global = require 'utils.global'
local Rank = require 'features.rank_system' local Rank = require 'features.rank_system'
local Report = require 'features.report' local Report = require 'features.report'
local Apocalypse = require 'features.apocalypse'
local Utils = require 'utils.core' local Utils = require 'utils.core'
local Game = require 'utils.game' local Game = require 'utils.game'
local Event = require 'utils.event' local Event = require 'utils.event'
@ -485,3 +486,16 @@ Command.add(
}, },
revive_ghosts revive_ghosts
) )
-- Commands with no functions, only calls to other modules
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,
required_rank = Ranks.admin,
},
Apocalypse.begin_apocalypse
)

94
features/apocalypse.lua Normal file
View File

@ -0,0 +1,94 @@
local table = require 'utils.table'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Game = require 'utils.game'
local Toast = require 'features.gui.toast'
local RS = require 'map_gen.shared.redmew_surface'
local HailHydra = require 'map_gen.shared.hail_hydra'
local clear_table = table.clear_table
local Public = {}
local hydra_config = {
['behemoth-spitter'] = {['behemoth-spitter'] = 0.01},
['behemoth-biter'] = {['behemoth-biter'] = 0.01}
}
local biter_spawn_token =
Token.register(
function(data)
local surface = data.surface
local group = data.group
local p_spawn = data.p_spawn
local create_entity = surface.create_entity
local aliens = {
'behemoth-biter',
'behemoth-biter',
'behemoth-spitter',
'behemoth-spitter'
}
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}
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.')
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
if player and player.valid then
surface = player.surface
player_force = player.force
else
surface = RS.get_surface()
player_force = game.forces.player
end
local hydras = global.config.hail_hydra.hydras
clear_table(hydras)
for k, v in pairs(hydra_config) do
hydras[k] = v
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
}
)
end
return Public

View File

@ -3,7 +3,7 @@ local Global = require 'utils.global'
local Token = require 'utils.token' local Token = require 'utils.token'
local Command = require 'utils.command' local Command = require 'utils.command'
local Event = require 'utils.event' local Event = require 'utils.event'
local Ranks = require 'utils.ranks' local Ranks = require 'resources.ranks'
local random = math.random local random = math.random
local ceil = math.ceil local ceil = math.ceil
local floor = math.floor local floor = math.floor

View File

@ -1,6 +1,9 @@
-- Cut off a limb, and two more shall take its place! -- Cut off a limb, and two more shall take its place!
local Event = require 'utils.event' local Event = require 'utils.event'
local CreateParticles = require 'features.create_particles' local CreateParticles = require 'features.create_particles'
local Token = require 'utils.token'
local Global = require 'utils.global'
local random = math.random local random = math.random
local floor = math.floor local floor = math.floor
local ceil = math.ceil local ceil = math.ceil
@ -13,20 +16,38 @@ local config = global.config.hail_hydra
local evolution_scale = config.evolution_scale local evolution_scale = config.evolution_scale
local hydras = config.hydras local hydras = config.hydras
local primitives = {enabled = nil}
Global.register(
{
primitives = primitives
},
function(tbl)
primitives = tbl.primitives
end
)
local Public = {}
local function create_attack_command(position, target) local function create_attack_command(position, target)
local command = {type = attack_area, destination = position, radius = 10} local command = {type = attack_area, destination = position, radius = 10}
if target then if target then
command = {type = compound, structure_type = logical_or, commands = { command = {
type = compound,
structure_type = logical_or,
commands = {
{type = attack, target = target}, {type = attack, target = target},
command, command
}} }
}
end end
return command return command
end end
local on_died =
Event.add(defines.events.on_entity_died, function (event) Token.register(
function(event)
local entity = event.entity local entity = event.entity
local name = entity.name local name = entity.name
@ -77,4 +98,29 @@ Event.add(defines.events.on_entity_died, function (event)
end end
end end
end end
end) end
)
local function register_event()
if not primitives.enabled then
Event.add_removable(defines.events.on_entity_died, on_died)
primitives.enabled = true
end
end
if config.enabled then
register_event()
end
function Public.enable_hail_hydra()
register_event()
end
function Public.disable_hail_hydra()
if primitives.enabled then
Event.remove_removable(defines.events.on_entity_died, on_died)
primitives.enabled = nil
end
end
return Public