1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-30 23:17:53 +02:00
added command module for biter battles, to reload and restart scenario
added changes to fish_defender_v2
This commit is contained in:
Gerkiz 2020-11-06 10:26:15 +01:00
parent 0143e1ae5e
commit 58c5c21a28
10 changed files with 176 additions and 169 deletions

View File

@ -0,0 +1,78 @@
local Server = require 'utils.server'
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
commands.add_command(
'scenario',
'Usable only for admins - controls the scenario!',
function(cmd)
local p
local player = game.player
if not player or not player.valid then
p = log
else
p = player.print
if not player.admin then
return
end
end
local param = cmd.parameter
if param == 'restart' or param == 'shutdown' or param == 'restartnow' then
goto continue
else
p('[ERROR] Arguments are:\nrestart\nshutdown\nrestartnow')
return
end
::continue::
if not global.reset_are_you_sure then
global.reset_are_you_sure = true
p('[WARNING] This command will disable the soft-reset feature, run this command again if you really want to do this!')
return
end
if param == 'restart' then
if global.restart then
global.reset_are_you_sure = nil
global.restart = false
global.soft_reset = true
p('[SUCCESS] Soft-reset is enabled.')
return
else
global.reset_are_you_sure = nil
global.restart = true
global.soft_reset = false
if global.shutdown then
global.shutdown = false
end
p('[WARNING] Soft-reset is disabled! Server will restart from scenario.')
return
end
elseif param == 'restartnow' then
global.reset_are_you_sure = nil
p(player.name .. ' has restarted the game.')
Server.start_scenario('Biter_Battles')
return
elseif param == 'shutdown' then
if global.shutdown then
global.reset_are_you_sure = nil
global.shutdown = false
global.soft_reset = true
p('[SUCCESS] Soft-reset is enabled.')
return
else
global.reset_are_you_sure = nil
global.shutdown = true
global.soft_reset = false
if global.restart then
global.restart = false
end
p('[WARNING] Soft-reset is disabled! Server will shutdown.')
return
end
end
end
)

View File

@ -226,18 +226,38 @@ function Public.server_restart()
if global.server_restart_timer == 150 then return end
if global.server_restart_timer == 10 then game.delete_surface(game.surfaces.bb_source) return end
if global.server_restart_timer == 5 then Init.source_surface() return end
if global.server_restart_timer == 0 then
if global.restart then
if not global.announced_message then
local message = 'Soft-reset is disabled! Server will restart from scenario to load new changes.'
game.print(message, {r = 0.22, g = 0.88, b = 0.22})
Server.to_discord_bold(table.concat {'*** ', message, ' ***'})
Server.start_scenario('Biter_Battles')
global.announced_message = true
return
end
end
if global.shutdown then
if not global.announced_message then
local message = 'Soft-reset is disabled! Server will shutdown. Most likely because of updates.'
game.print(message, {r = 0.22, g = 0.88, b = 0.22})
Server.to_discord_bold(table.concat {'*** ', message, ' ***'})
Server.stop_scenario()
global.announced_message = true
return
end
end
game.print("Map is restarting!", {r=0.22, g=0.88, b=0.22})
local message = 'Map is restarting! '
Server.to_discord_bold(table.concat{'*** ', message, ' ***'})
Init.tables()
Init.forces()
Init.load_spawn()
for _, player in pairs(game.players) do
Functions.init_player(player)
for _, e in pairs(player.gui.left.children) do e.destroy() end
for _, e in pairs(player.gui.left.children) do e.destroy() end
Gui.create_main_gui(player)
end
game.surfaces.biter_battles.clear(true)

View File

@ -11,6 +11,7 @@ local Team_manager = require "maps.biter_battles_v2.team_manager"
local Terrain = require "maps.biter_battles_v2.terrain"
require "maps.biter_battles_v2.sciencelogs_tab"
require 'maps.biter_battles_v2.commands'
require "modules.spawners_contain_biters"
require "modules.mineable_wreckage_yields_scrap"

View File

@ -1,11 +1,10 @@
local Server = require 'utils.server'
local FDT = require 'maps.fish_defender_v2.table'
local Task = require 'utils.task'
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
commands.add_command(
'fishy_commands',
'scenario',
'Usable only for admins - controls the scenario!',
function(cmd)
local p
@ -36,9 +35,7 @@ commands.add_command(
if not this.reset_are_you_sure then
this.reset_are_you_sure = true
p(
'[WARNING] This command will disable the soft-reset feature, run this command again if you really want to do this!'
)
p('[WARNING] This command will disable the soft-reset feature, run this command again if you really want to do this!')
return
end
@ -62,7 +59,7 @@ commands.add_command(
elseif param == 'restartnow' then
this.reset_are_you_sure = nil
p(player.name .. ' has restarted the game.')
Server.start_scenario('Fish_Defender_v2')
Server.start_scenario('Fish_Defender')
return
elseif param == 'shutdown' then
if this.shutdown then
@ -94,55 +91,3 @@ commands.add_command(
end
end
)
commands.add_command(
'set_queue_speed',
'Usable only for admins - sets the queue speed of this map!',
function(cmd)
local p
local player = game.player
local param = tonumber(cmd.parameter)
if player then
if player ~= nil then
p = player.print
if not player.admin then
p("[ERROR] You're not admin!", Color.fail)
return
end
if not param then
return
end
p('Queue speed set to: ' .. param)
Task.set_queue_speed(param)
else
p = log
p('Queue speed set to: ' .. param)
Task.set_queue_speed(param)
end
end
end
)
commands.add_command(
'get_queue_speed',
'Usable only for admins - gets the queue speed of this map!',
function()
local p
local player = game.player
if player then
if player ~= nil then
p = player.print
if not player.admin then
p("[ERROR] You're not admin!", Color.fail)
return
end
p(Task.get_queue_speed())
else
p = log
p(Task.get_queue_speed())
end
end
end
)

View File

@ -10,7 +10,6 @@ require 'maps.fish_defender_v2.on_entity_damaged'
require 'modules.rocket_launch_always_yields_science'
require 'modules.launch_fish_to_win'
require 'modules.biters_yield_coins'
require 'modules.dangerous_goods'
require 'modules.custom_death_messages'
local Unit_health_booster = require 'modules.biter_health_booster'
@ -29,6 +28,7 @@ local insert = table.insert
local enable_start_grace_period = true
local Public = {}
local random = math.random
local starting_items = {
['pistol'] = 1,
@ -324,9 +324,10 @@ local function get_biter_initial_pool()
end
end
local function fish_eye(surface, position)
local function fish_eye(this, surface, position)
surface.request_to_generate_chunks(position, 2)
surface.force_generate_chunk_requests()
for x = -48, 48, 1 do
for y = -48, 48, 1 do
local p = {x = position.x + x, y = position.y + y}
@ -348,6 +349,7 @@ local function fish_eye(surface, position)
end
end
end
this.fish_eye = true
end
local function get_biter_pool()
@ -382,17 +384,11 @@ local function spawn_biter(pos, biter_pool)
end
local function get_y_coord_raffle_table()
local this = FDT.get()
local t = {}
--for y = -96, 96, 8 do -- fish
for y = -96, 240, 8 do -- cat
if this.wave_count <= 80 then
y = 0
end
for y = -96, 96, 8 do
t[#t + 1] = y
end
shuffle(t)
table.shuffle_table(t)
return t
end
@ -540,8 +536,8 @@ local function wake_up_the_biters(surface)
break
end
local x = units[i].position.x
if x > 256 then
x = 256
if x > 300 then
x = 300
end
local y = units[i].position.y
if y > 96 or y < -96 then
@ -692,11 +688,11 @@ local function biter_attack_wave()
local unit_groups = {}
if this.wave_count > 50 and math_random(1, 8) == 1 then
for i = 1, 10, 1 do
unit_groups[i] = surface.create_unit_group({position = {x = 256, y = y_raffle[i]}})
unit_groups[i] = surface.create_unit_group({position = {x = 300, y = y_raffle[i]}})
end
else
for i = 1, get_number_of_attack_groups(), 1 do
unit_groups[i] = surface.create_unit_group({position = {x = 256, y = y_raffle[i]}})
unit_groups[i] = surface.create_unit_group({position = {x = 300, y = y_raffle[i]}})
end
end
@ -1169,7 +1165,7 @@ local function on_player_changed_position(event)
return
end
if player.position.x >= 160 then
if player.position.x >= 254 then
player.teleport({player.position.x - 1, 0}, surface)
if player.character then
@ -1355,38 +1351,6 @@ function Public.reset_game()
surface.peaceful_mode = false
--[[ local radius = 200
--local pos = {x = 419, y = -308} -- fish
local pos = {x = -27, y = -308} -- cat
game.forces.player.chart(
surface,
{
{pos.x - radius - 100, pos.y - radius - 40},
{pos.x + radius + 250, pos.y + radius}
}
)
radius = 50
-- pos = {x = -1575, y = 2}
-- pos = {x = -1246, y = 74} -- fish
pos = {x = -748, y = -309} -- cat
game.forces.player.chart(
surface,
{
{pos.x - radius, pos.y - radius},
{pos.x + radius, pos.y + radius}
}
) ]]
local r = 200
local p = {x = -131, y = 5}
game.forces.player.chart(
surface,
{
{p.x - r - 100, p.y - r},
{p.x + r + 400, p.y + r}
}
)
game.map_settings.enemy_expansion.enabled = false
game.map_settings.enemy_evolution.destroy_factor = 0
game.map_settings.enemy_evolution.time_factor = 0
@ -1411,8 +1375,6 @@ function Public.reset_game()
game.forces.player.technologies['spidertron'].researched = false
game.reset_time_played()
fish_eye(surface, {x = -1667, y = -50})
if not global.catplanet_goals then
global.catplanet_goals = {
{goal = 0, rank = false, achieved = true},
@ -1491,8 +1453,6 @@ function Public.reset_game()
{goal = 10000000, rank = 'Blue Screen', color = {r = 100, g = 100, b = 245}, msg = '....', msg2 = '....', achieved = false}
}
end
this.spawn_area_generated = false
end
function Public.on_init()
@ -1511,7 +1471,8 @@ local function on_tick()
if not surface or not surface.valid then
return
end
if game.tick % 30 == 0 then
local tick = game.tick
if tick % 30 == 0 then
has_the_game_ended()
if this.market then
for _, player in pairs(game.connected_players) do
@ -1520,7 +1481,7 @@ local function on_tick()
end
end
end
if game.tick % 180 == 0 then
if tick % 180 == 0 then
if surface then
game.forces.player.chart(surface, {{-160, -130}, {160, 179}})
if Diff.difficulty_vote_index then
@ -1528,16 +1489,31 @@ local function on_tick()
end
end
end
end
if this.wave_count >= this.wave_limit then
if this.market and this.market.valid then
this.market.die()
game.print('Game wave limit reached! Game will soft-reset shortly.', {r = 0.22, g = 0.88, b = 0.22})
if this.wave_count >= this.wave_limit then
if this.market and this.market.valid then
this.market.die()
game.print('Game wave limit reached! Game will soft-reset shortly.', {r = 0.22, g = 0.88, b = 0.22})
end
end
if not this.spawn_area_generated then
if tick % 2 == 0 then
local players = game.connected_players
for i = 1, #players do
local player = players[i]
if (player.character and player.character.valid) then
player.character.rotate()
end
end
end
end
if this.spawn_area_generated and not this.fish_eye then
fish_eye(this, surface, {x = -1667, y = -50})
end
end
if game.tick % this.wave_interval == this.wave_interval - 1 then
if tick % this.wave_interval == this.wave_interval - 1 then
if surface.peaceful_mode == true then
return
end

View File

@ -218,17 +218,7 @@ local function slot_upgrade(player, offer_index)
player.name .. ' has bought a ' .. slot_upgrade_offers[offer_index][2] .. ' slot for ' .. price .. ' coins!',
{r = 0.22, g = 0.77, b = 0.44}
)
if
(slot_upgrade_offers[offer_index][2] < 10) or
((slot_upgrade_offers[offer_index][2] < 50) and ((slot_upgrade_offers[offer_index][2] % 5) == 0)) or
((slot_upgrade_offers[offer_index][2] % 25) == 0)
then
Server.to_discord_bold(
table.concat {
'*** ' .. player.name .. ' has bought a ' .. slot_upgrade_offers[offer_index][2] .. ' slot for ' .. price .. ' coins! ***'
}
)
end
refresh_market_offers()
end

View File

@ -20,6 +20,8 @@ function Public.reset_table()
this.shutdown = false
this.announced_message = false
this.force_chunk = false
this.fish_eye = false
this.chunk_load_tick = game.tick + 500
-- @end
this.game_has_ended = false
this.game_reset = false

View File

@ -35,7 +35,7 @@ local function is_enemy_territory(p)
return false
end
--if p.x - 64 < p.y then return false end
if p.x < 160 then
if p.x < 256 then
return false
end
if p.x > 1024 then
@ -58,7 +58,7 @@ local function place_fish_market(surface, position)
end
local function enemy_territory(surface, left_top)
if left_top.x < 160 then
if left_top.x < 256 then
return
end
if left_top.x > 750 then
@ -67,13 +67,13 @@ local function enemy_territory(surface, left_top)
if left_top.y > 766 then
return
end
if left_top.y < -160 then
if left_top.y < -256 then
return
end
local area = {{left_top.x, left_top.y}, {left_top.x + 32, left_top.y + 32}}
if left_top.x > 256 then
if left_top.x > 300 then
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
@ -142,36 +142,30 @@ local function generate_spawn_area(this, surface)
return
end
surface.request_to_generate_chunks({x = 0, y = 0}, 7)
surface.request_to_generate_chunks({x = 160, y = 0}, 4)
surface.request_to_generate_chunks({0, 0}, 8)
if not surface.is_chunk_generated({-7, 0}) then
return
end
if not surface.is_chunk_generated({5, 0}) then
if this.chunk_load_tick > game.tick then
return
end
local spawn_position_x = -128
surface.create_entity({name = 'electric-beam', position = {160, -132}, source = {160, -132}, target = {160, 179}}) -- fish
surface.create_entity({name = 'electric-beam', position = {254, -143}, source = {254, -143}, target = {254, 193}}) -- fish
--surface.create_entity({name = 'electric-beam', position = {160, -101}, source = {160, -101}, target = {160, 248}}) -- fish
--surface.create_entity({name = 'electric-beam', position = {160, -88}, source = {160, -88}, target = {160, 185}})
for _, tile in pairs(surface.find_tiles_filtered({name = {'water', 'deepwater'}, area = {{-160, -160}, {160, 160}}})) do
for _, tile in pairs(surface.find_tiles_filtered({name = {'water', 'deepwater'}, area = {{-300, -256}, {300, 300}}})) do
local noise = math_abs(simplex_noise(tile.position.x * 0.02, tile.position.y * 0.02, game.surfaces[1].map_gen_settings.seed) * 16)
if tile.position.x > -160 + noise then
surface.set_tiles({{name = get_replacement_tile(surface, tile.position), position = {tile.position.x, tile.position.y}}}, true)
end
end
for _, entity in pairs(
surface.find_entities_filtered({type = {'resource', 'cliff'}, area = {{spawn_position_x - 32, -256}, {160, 256}}})
) do
for _, entity in pairs(surface.find_entities_filtered({type = {'resource', 'cliff'}, area = {{-300, -256}, {300, 300}}})) do
if
entity.position.x >
spawn_position_x - 32 +
math_abs(simplex_noise(entity.position.x * 0.02, entity.position.y * 0.02, game.surfaces[1].map_gen_settings.seed) * 16)
-300 +
math_abs(simplex_noise(entity.position.x * 0.02, entity.position.y * 0.02, game.surfaces[1].map_gen_settings.seed) * 32)
then
entity.destroy()
end
@ -258,6 +252,17 @@ local function generate_spawn_area(this, surface)
local spawn_pos = surface.find_non_colliding_position('character', {spawn_position_x + 1, 4}, 50, 1)
player.teleport(spawn_pos, surface)
end
local rr = 200
local p = {x = -131, y = 5}
game.forces.player.chart(
surface,
{
{p.x - rr - 100, p.y - rr},
{p.x + rr + 400, p.y + rr}
}
)
this.spawn_area_generated = true
end

View File

@ -844,15 +844,14 @@ local function get_connected_rolling_stock(entity, direction, carriages)
end
function Public.construct_train(icw, locomotive, carriages)
local locomotive_carriages = locomotive.train.carriages
for i, carriage in pairs(locomotive_carriages) do
for i, carriage in pairs(carriages) do
if carriage == locomotive then
local stock = get_connected_rolling_stock(locomotive, defines.rail_direction.front, locomotive_carriages)
if stock ~= locomotive_carriages[i - 1] then
local stock = get_connected_rolling_stock(locomotive, defines.rail_direction.front, carriages)
if stock ~= carriages[i - 1] then
local n = 1
local m = #locomotive_carriages
local m = #carriages
while (n < m) do
locomotive_carriages[n], locomotive_carriages[m] = locomotive_carriages[m], locomotive_carriages[n]
carriages[n], carriages[m] = carriages[m], carriages[n]
n = n + 1
m = m - 1
end
@ -893,9 +892,6 @@ function Public.reconstruct_all_trains(icw)
Public.create_wagon_room(icw, wagon)
end
local carriages = wagon.entity.train.carriages
local locomotive_carriages = locomotive.train.carriages
WPT.set().carriages = locomotive_carriages
Public.construct_train(icw, locomotive, carriages)
end

View File

@ -86,8 +86,8 @@ function Public.set_difficulties(...)
end
end
function Public.set_poll_closing_timeout(...)
this.difficulty_poll_closing_timeout = ...
function Public.set_poll_closing_timeout(value)
this.difficulty_poll_closing_timeout = value
end
function Public.get(key)
@ -105,8 +105,7 @@ function Public.difficulty_gui()
if player.gui.top['difficulty_gui'] then
player.gui.top['difficulty_gui'].caption = this.difficulties[this.difficulty_vote_index].name
player.gui.top['difficulty_gui'].tooltip = this.button_tooltip or tooltip
player.gui.top['difficulty_gui'].style.font_color =
this.difficulties[this.difficulty_vote_index].print_color
player.gui.top['difficulty_gui'].style.font_color = this.difficulties[this.difficulty_vote_index].print_color
else
local b =
player.gui.top.add {
@ -165,8 +164,7 @@ local function poll_difficulty(player)
{
type = 'button',
name = 'close',
caption = 'Close (' ..
math.floor((this.difficulty_poll_closing_timeout - game.tick) / 3600) .. ' minutes left)'
caption = 'Close (' .. math.floor((this.difficulty_poll_closing_timeout - game.tick) / 3600) .. ' minutes left)'
}
)
b.style.font_color = {r = 0.66, g = 0.0, b = 0.66}
@ -187,8 +185,7 @@ local function set_difficulty()
a = a / vote_count
local new_index = math.round(a, 0)
if this.difficulty_vote_index ~= new_index then
local message =
table.concat({'>> Map difficulty has changed to ', this.difficulties[new_index].name, ' difficulty!'})
local message = table.concat({'>> Map difficulty has changed to ', this.difficulties[new_index].name, ' difficulty!'})
game.print(message, this.difficulties[new_index].print_color)
Server.to_discord_embed(message)
end
@ -281,10 +278,7 @@ local function on_gui_click(event)
return
end
local i = tonumber(event.element.name)
game.print(
player.name .. ' has voted for ' .. this.difficulties[i].name .. ' difficulty!',
this.difficulties[i].print_color
)
game.print(player.name .. ' has voted for ' .. this.difficulties[i].name .. ' difficulty!', this.difficulties[i].print_color)
this.difficulty_player_votes[player.name] = i
set_difficulty()
Public.difficulty_gui()