2019-02-07 07:37:34 +02:00
|
|
|
local Task = require 'utils.task'
|
|
|
|
local Token = require 'utils.token'
|
2019-02-14 19:16:05 +02:00
|
|
|
local Game = require 'utils.game'
|
2019-02-15 02:19:32 +02:00
|
|
|
local Global = require 'utils.global'
|
2019-02-17 04:24:28 +02:00
|
|
|
local Command = require 'utils.command'
|
2019-02-07 07:37:34 +02:00
|
|
|
local Toast = require 'features.gui.toast'
|
|
|
|
local RS = require 'map_gen.shared.redmew_surface'
|
|
|
|
local HailHydra = require 'map_gen.shared.hail_hydra'
|
2019-02-15 02:19:32 +02:00
|
|
|
local Color = require 'resources.color_presets'
|
2019-02-17 04:24:28 +02:00
|
|
|
local Ranks = require 'resources.ranks'
|
2019-02-07 07:37:34 +02:00
|
|
|
|
2019-02-15 02:19:32 +02:00
|
|
|
-- Constants
|
2019-02-15 02:02:39 +02:00
|
|
|
local hail_hydra_data = {
|
2019-02-07 07:37:34 +02:00
|
|
|
['behemoth-spitter'] = {['behemoth-spitter'] = 0.01},
|
|
|
|
['behemoth-biter'] = {['behemoth-biter'] = 0.01}
|
|
|
|
}
|
|
|
|
|
2019-02-15 02:19:32 +02:00
|
|
|
-- 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
|
|
|
|
)
|
|
|
|
|
2019-02-07 07:37:34 +02:00
|
|
|
local biter_spawn_token =
|
|
|
|
Token.register(
|
2019-02-15 02:02:39 +02:00
|
|
|
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)
|
2019-02-23 17:20:38 +02:00
|
|
|
HailHydra.set_evolution_scale(1)
|
2019-02-15 02:02:39 +02:00
|
|
|
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}
|
2019-02-07 07:37:34 +02:00
|
|
|
|
|
|
|
local create_entity = surface.create_entity
|
|
|
|
|
2019-02-08 21:19:50 +02:00
|
|
|
local aliens = {
|
|
|
|
'behemoth-biter',
|
|
|
|
'behemoth-biter',
|
|
|
|
'behemoth-spitter',
|
|
|
|
'behemoth-spitter'
|
|
|
|
}
|
|
|
|
|
|
|
|
for i = 1, #aliens do
|
2019-02-07 07:37:34 +02:00
|
|
|
local spawn_pos = surface.find_non_colliding_position('behemoth-biter', p_spawn, 300, 1)
|
|
|
|
if spawn_pos then
|
2019-02-15 02:02:39 +02:00
|
|
|
local biter = create_entity({name = aliens[i], position = spawn_pos})
|
2019-02-07 07:37:34 +02:00
|
|
|
group.add_member(biter)
|
|
|
|
end
|
|
|
|
end
|
2019-02-08 21:19:50 +02:00
|
|
|
|
2019-02-07 07:37:34 +02:00
|
|
|
group.set_command({type = defines.command.attack_area, destination = {0, 0}, radius = 500})
|
2019-02-15 02:19:32 +02:00
|
|
|
Toast.toast_all_players(500, {'apocalypse.toast_message'})
|
2019-02-07 07:37:34 +02:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2019-02-15 02:19:32 +02:00
|
|
|
--- Begins the apocalypse
|
|
|
|
function Public.begin_apocalypse(_, player)
|
|
|
|
local index
|
|
|
|
if player and player.valid then
|
|
|
|
index = player.index
|
|
|
|
elseif not player then
|
|
|
|
index = 0
|
2019-02-14 19:16:05 +02:00
|
|
|
end
|
|
|
|
|
2019-02-16 23:44:25 +02:00
|
|
|
-- 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
|
2019-02-15 02:19:32 +02:00
|
|
|
second_run[index] = true
|
|
|
|
game.server_save('pre-apocalypse-' .. index)
|
|
|
|
Game.player_print({'apocalypse.run_twice'})
|
2019-02-07 07:37:34 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-02-15 02:19:32 +02:00
|
|
|
primitives.apocalypse_now = true
|
|
|
|
game.print({'apocalypse.apocalypse_begins'}, Color.pink)
|
2019-02-16 23:44:25 +02:00
|
|
|
Task.set_timeout(15, biter_spawn_token, {})
|
2019-02-07 07:37:34 +02:00
|
|
|
end
|
|
|
|
|
2019-02-17 04:24:28 +02:00
|
|
|
Command.add(
|
|
|
|
'apocalypse',
|
|
|
|
{
|
2019-03-04 00:13:56 +02:00
|
|
|
description = {'command_description.apocalypse'},
|
|
|
|
required_rank = Ranks.admin
|
2019-02-17 04:24:28 +02:00
|
|
|
},
|
|
|
|
Public.begin_apocalypse
|
|
|
|
)
|
|
|
|
|
2019-02-08 22:19:30 +02:00
|
|
|
return Public
|