1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-05 15:06:02 +02:00

fixed minor issues with 0.17 and 0.18

This commit is contained in:
Gerkiz 2020-07-07 16:31:01 +02:00
parent 76e62404d2
commit 29561ec862
6 changed files with 168 additions and 86 deletions

@ -2,6 +2,7 @@ require 'utils.data_stages'
_LIFECYCLE = _STAGE.control -- Control stage
_DEBUG = false
_DUMP_ENV = false
local branch_version = '0.18.35'
require 'utils.server'
require 'utils.server_commands'
@ -154,9 +155,11 @@ end
local function on_init()
game.forces.player.research_queue_enabled = true
local default = game.permissions.get_group('Default')
default.set_allows_action(defines.input_action.flush_opened_entity_fluid, false)
default.set_allows_action(defines.input_action.flush_opened_entity_specific_fluid, false)
if game.active_mods.base >= branch_version then
local default = game.permissions.get_group('Default')
default.set_allows_action(defines.input_action.flush_opened_entity_fluid, false)
default.set_allows_action(defines.input_action.flush_opened_entity_specific_fluid, false)
end
end
local loaded = _G.package.loaded

@ -11,11 +11,13 @@ require 'modules.biters_yield_coins'
require 'modules.dangerous_goods'
require 'modules.custom_death_messages'
local branch_version = '0.18.35'
local Terrain = require 'maps.fish_defender.terrain'
local Unit_health_booster = require 'modules.biter_health_booster'
local Difficulty = require 'modules.difficulty_vote'
local Map = require 'modules.map_info'
local event = require 'utils.event'
local Event = require 'utils.event'
local Reset = require 'functions.soft_reset'
local Server = require 'utils.server'
local Poll = require 'comfy_panel.poll'
@ -192,7 +194,7 @@ local function on_gui_click(event)
end
end
local function on_market_item_purchased(event)
local function on_market_item_purchased()
update_fd_stats()
end
@ -503,7 +505,7 @@ end
local function wake_up_the_biters(surface)
local market = FDT.get('market')
if not market then
if not market or not market.valid then
return
end
@ -587,7 +589,7 @@ local function biter_attack_wave()
local Diff = Difficulty.get()
local this = FDT.get()
if not this.market then
if not this.market or not this.market.valid then
return
end
if this.wave_grace_period then
@ -884,10 +886,20 @@ end
local function market_kill_visuals()
local market = FDT.get('market')
local surface = FDT.get('active_surface')
if not surface or not surface.valid then
return
end
if not market or not market.valid then
return
end
local m = 32
local m2 = m * 0.005
for i = 1, 1024, 1 do
market.surface.create_particle(
surface.create_particle(
{
name = 'branch-particle',
position = market.position,
@ -901,7 +913,7 @@ local function market_kill_visuals()
for x = -5, 5, 0.5 do
for y = -5, 5, 0.5 do
if math_random(1, 2) == 1 then
market.surface.create_trivial_smoke(
surface.create_trivial_smoke(
{
name = 'smoke-fast',
position = {market.position.x + (x * 0.35), market.position.y + (y * 0.35)}
@ -909,7 +921,7 @@ local function market_kill_visuals()
)
end
if math_random(1, 3) == 1 then
market.surface.create_trivial_smoke(
surface.create_trivial_smoke(
{
name = 'train-smoke',
position = {market.position.x + (x * 0.35), market.position.y + (y * 0.35)}
@ -918,7 +930,7 @@ local function market_kill_visuals()
end
end
end
market.surface.spill_item_stack(market.position, {name = 'raw-fish', count = 1024}, true)
surface.spill_item_stack(market.position, {name = 'raw-fish', count = 1024}, true)
end
local biter_splash_damage = {
@ -1126,15 +1138,13 @@ local function on_robot_built_entity(event)
end
local function on_init()
local Diff = Difficulty.get()
local get_score = Score.get_table()
local this = FDT.get()
FDT.reset_table()
Poll.reset()
local get_score = Score.get_table()
local this = FDT.get()
Diff.difficulty_poll_closing_timeout = this.wave_grace_period
Difficulty.reset_difficulty_poll()
Difficulty.set_poll_closing_timeout = game.tick + 36000
get_score.score_table = {}
local map_gen_settings = {}
@ -1172,9 +1182,6 @@ local function on_init()
game.map_settings.enemy_evolution.pollution_factor = 0
game.map_settings.pollution.enabled = false
Difficulty.reset_difficulty_poll()
Difficulty.set_poll_closing_timeout(game.tick + 35 * 60 * 60)
game.forces['player'].technologies['atomic-bomb'].enabled = false
--game.forces["player"].technologies["landfill"].enabled = false
@ -1189,7 +1196,9 @@ local function on_init()
game.map_settings.enemy_expansion.enabled = false
game.forces['player'].technologies['artillery'].researched = false
game.reset_time_played()
if game.active_mods.base >= branch_version then
game.reset_time_played()
end
local T = Map.Pop_info()
T.localised_category = 'fish_defender'
@ -1324,18 +1333,18 @@ local function on_player_respawned(event)
player.character.destructible = false
end
event.add(defines.events.on_gui_click, on_gui_click)
event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
event.add(defines.events.on_player_respawned, on_player_respawned)
event.add(defines.events.on_built_entity, on_built_entity)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_player_changed_position, on_player_changed_position)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
event.add(defines.events.on_research_finished, on_research_finished)
event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
event.add(defines.events.on_tick, on_tick)
event.on_init(on_init)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
Event.add(defines.events.on_player_respawned, on_player_respawned)
Event.add(defines.events.on_built_entity, on_built_entity)
Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
Event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
Event.add(defines.events.on_tick, on_tick)
Event.on_init(on_init)
return on_init

@ -29,15 +29,9 @@ local special_descriptions = {
['laser-pointer'] = 'Unlock Laser Pointer - The biters are on a quest to slay the red (artillery) dot.'
}
function place_fish_market(surface, position)
local market = surface.create_entity({name = 'market', position = position, force = 'player'})
market.minable = false
return market
end
local function refresh_market_offers()
local this = FDT.get()
if not this.market then
if not this.market or not this.market.valid then
return
end
for i = 1, 100, 1 do

@ -193,18 +193,32 @@ local function set_difficulty()
this.difficulty_vote_value = this.difficulties[new_index].value
end
function Public.reset_difficulty_poll()
this.difficulty_vote_value = 1
this.difficulty_vote_index = 1
this.difficulty_player_votes = {}
this.difficulty_poll_closing_timeout = game.tick + 54000
for _, p in pairs(game.connected_players) do
if p.gui.center['difficulty_poll'] then
p.gui.center['difficulty_poll'].destroy()
function Public.reset_difficulty_poll(tbl)
if tbl then
this.difficulty_vote_value = tbl.difficulty_vote_value or 1
this.difficulty_vote_index = tbl.difficulty_vote_index or 1
this.difficulty_player_votes = {}
this.difficulty_poll_closing_timeout = tbl.difficulty_poll_closing_timeout or game.tick + 54000
for _, p in pairs(game.connected_players) do
if p.gui.center['difficulty_poll'] then
p.gui.center['difficulty_poll'].destroy()
end
poll_difficulty(p)
end
poll_difficulty(p)
Public.difficulty_gui()
else
this.difficulty_vote_value = 1
this.difficulty_vote_index = 1
this.difficulty_player_votes = {}
this.difficulty_poll_closing_timeout = game.tick + 54000
for _, p in pairs(game.connected_players) do
if p.gui.center['difficulty_poll'] then
p.gui.center['difficulty_poll'].destroy()
end
poll_difficulty(p)
end
Public.difficulty_gui()
end
Public.difficulty_gui()
end
local function on_player_joined_game(event)

@ -20,10 +20,10 @@ local ticks_to_minutes = 1 / minutes_to_ticks
local ticks_to_hours = 1 / hours_to_ticks
-- local vars
local Module = {}
local Public = {}
--- Measures distance between pos1 and pos2
function Module.distance(pos1, pos2)
function Public.distance(pos1, pos2)
local dx = pos2.x - pos1.x
local dy = pos2.y - pos1.y
return sqrt(dx * dx + dy * dy)
@ -33,7 +33,7 @@ end
-- @param msg <string|table> table if locale is used
-- @param player <LuaPlayer> the player not to send the message to
-- @param color <table> the color to use for the message, defaults to white
function Module.print_except(msg, player, color)
function Public.print_except(msg, player, color)
if not color then
color = Color.white
end
@ -47,8 +47,8 @@ end
--- Prints a message to all online admins
-- @param msg <string|table> table if locale is used
-- @param source <LuaPlayer|string|nil> string must be the name of a player, nil for server_commands.
function Module.print_admins(msg, source)
-- @param source <LuaPlayer|string|nil> string must be the name of a player, nil for server.
function Public.print_admins(msg, source)
local source_name
local chat_color
if source then
@ -63,7 +63,7 @@ function Module.print_admins(msg, source)
source_name = 'Server'
chat_color = Color.yellow
end
local formatted_msg = {'utils_core.print_admins',prefix, source_name, msg}
local formatted_msg = {'utils_core.print_admins', prefix, source_name, msg}
log(formatted_msg)
for _, p in pairs(game.connected_players) do
if p.admin then
@ -73,14 +73,14 @@ function Module.print_admins(msg, source)
end
--- Returns a valid string with the name of the actor of a command.
function Module.get_actor()
function Public.get_actor()
if game.player then
return game.player.name
end
return '<server>'
end
function Module.cast_bool(var)
function Public.cast_bool(var)
if var then
return true
else
@ -88,13 +88,21 @@ function Module.cast_bool(var)
end
end
function Module.find_entities_by_last_user(player, surface, filters)
function Public.find_entities_by_last_user(player, surface, filters)
if type(player) == 'string' or not player then
error("bad argument #1 to '" .. debug.getinfo(1, 'n').name .. "' (number or LuaPlayer expected, got " .. type(player) .. ')', 1)
error(
"bad argument #1 to '" ..
debug.getinfo(1, 'n').name .. "' (number or LuaPlayer expected, got " .. type(player) .. ')',
1
)
return
end
if type(surface) ~= 'table' and type(surface) ~= 'number' then
error("bad argument #2 to '" .. debug.getinfo(1, 'n').name .. "' (number or LuaSurface expected, got " .. type(surface) .. ')', 1)
error(
"bad argument #2 to '" ..
debug.getinfo(1, 'n').name .. "' (number or LuaSurface expected, got " .. type(surface) .. ')',
1
)
return
end
local entities = {}
@ -103,7 +111,7 @@ function Module.find_entities_by_last_user(player, surface, filters)
surface = game.surfaces[surface]
end
if type(player) == 'number' then
player = Game.get_player_by_index(player)
player = game.get_player(player)
end
filter.force = player.force.name
for _, e in pairs(surface.find_entities_filtered(filter)) do
@ -114,7 +122,7 @@ function Module.find_entities_by_last_user(player, surface, filters)
return entities
end
function Module.ternary(c, t, f)
function Public.ternary(c, t, f)
if c then
return t
else
@ -123,7 +131,7 @@ function Module.ternary(c, t, f)
end
--- Takes a time in ticks and returns a string with the time in format "x hour(s) x minute(s)"
function Module.format_time(ticks)
function Public.format_time(ticks)
local result = {}
local hours = floor(ticks * ticks_to_hours)
@ -150,7 +158,7 @@ end
--- Prints a message letting the player know they cannot run a command
-- @param name string name of the command
function Module.cant_run(name)
function Public.cant_run(name)
Game.player_print("Can't run command (" .. name .. ') - insufficient permission.')
end
@ -158,7 +166,7 @@ end
-- @param actor string with the actor's name (usually acquired by calling get_actor)
-- @param command the command's name as table element
-- @param parameters the command's parameters as a table (optional)
function Module.log_command(actor, command, parameters)
function Public.log_command(actor, command, parameters)
local action = concat {'[Admin-Command] ', actor, ' used: ', command}
if parameters then
action = concat {action, ' ', parameters}
@ -166,7 +174,7 @@ function Module.log_command(actor, command, parameters)
log(action)
end
function Module.comma_value(n) -- credit http://richard.warburton.it
function Public.comma_value(n) -- credit http://richard.warburton.it
local left, num, right = match(n, '^([^%d]*%d)(%d*)(.-)$')
return left .. (num:reverse():gsub('(%d%d%d)', '%1,'):reverse()) .. right
end
@ -175,7 +183,7 @@ end
-- @param arg the variable to check
-- @param arg_types the type as a table of sings
-- @return boolean
function Module.verify_mult_types(arg, arg_types)
function Public.verify_mult_types(arg, arg_types)
for _, arg_type in pairs(arg_types) do
if type(arg) == arg_type then
return true
@ -185,7 +193,7 @@ function Module.verify_mult_types(arg, arg_types)
end
--- Returns a random RGB color as a table
function Module.random_RGB()
function Public.random_RGB()
return {r = random(0, 255), g = random(0, 255), b = random(0, 255)}
end
@ -194,7 +202,7 @@ end
-- @param key string
-- @param value nil|boolean|number|string|table to set the element to
-- @return value
function Module.set_and_return(tbl, key, value)
function Public.set_and_return(tbl, key, value)
tbl[key] = value
return value
end
@ -202,24 +210,59 @@ end
--- Takes msg and prints it to all players. Also prints to the log and discord
-- @param msg <string> The message to print
-- @param warning_prefix <string> The name of the module/warning
function Module.action_warning(warning_prefix, msg)
function Public.action_warning(warning_prefix, msg)
game.print(prefix .. msg, Color.yellow)
msg = format('%s %s', warning_prefix, msg)
log(msg)
Server.to_discord_bold(msg)
end
--- Takes msg and prints it to the log and discord.
-- @param msg <string> The message to print
-- @param warning_prefix <string> The name of the module/warning
function Public.action_to_discord(warning_prefix, msg)
msg = format('%s %s', warning_prefix, msg)
log(msg)
Server.to_discord_bold(msg)
end
--- Takes msg and prints it to all players except provided player. Also prints to the log and discord
-- @param msg <string> The message to print
-- @param warning_prefix <string> The name of the module/warning
-- @param player <LuaPlayer> the player not to send the message to
function Module.silent_action_warning(warning_prefix, msg, player)
Module.print_except(prefix .. msg, player, Color.yellow)
function Public.silent_action_warning(warning_prefix, msg, player)
Public.print_except(prefix .. msg, player, Color.yellow)
msg = format('%s %s', warning_prefix, msg)
log(msg)
Server.to_discord_bold(msg)
end
--- Takes a string, number, or LuaPlayer and returns a valid LuaPlayer or nil.
-- Intended for commands as there are extra checks in place.
-- @param <string|number|LuaPlayer>
-- @return <LuaPlayer|nil> <string|nil> <number|nil> the LuaPlayer, their name, and their index
function Public.validate_player(player_ident)
local data_type = type(player_ident)
local player
if data_type == 'table' and player_ident.valid then
local is_player = player_ident.is_player()
if is_player then
player = player_ident
end
elseif data_type == 'number' or data_type == 'string' then
player = game.get_player(player_ident)
else
return
end
if not player or not player.valid then
return
end
return player, player.name, player.index
end
-- add utility functions that exist in base factorio/util
require 'util'
@ -229,16 +272,16 @@ require 'util'
-- @param direction <defines.direction> north, east, south, west
-- @param distance <number>
-- @return <table> modified position
Module.move_position = util.moveposition
Public.move_position = util.moveposition
--- Takes a direction and gives you the opposite
-- @param direction <defines.direction> north, east, south, west, northeast, northwest, southeast, southwest
-- @return <number> representing the direction
Module.opposite_direction = util.oppositedirection
Public.opposite_direction = util.oppositedirection
--- Takes the string of a module and returns whether is it available or not
-- @param name <string> the name of the module (ex. 'utils.core')
-- @return <boolean>
Module.is_module_available = util.ismoduleavailable
Public.is_module_available = util.ismoduleavailable
return Module
return Public

@ -66,6 +66,14 @@ local jail = function(target_player, player)
target_player ..
' has been jailed automatically since they have griefed. ' .. jail_messages[math.random(1, #jail_messages)]
end
if
game.players[target_player].character and game.players[target_player].character.valid and
game.players[target_player].character.driving
then
game.players[target_player].character.driving = false
end
game.print(message, {r = 0.98, g = 0.66, b = 0.22})
Server.to_discord_embed(
table.concat {
@ -138,7 +146,7 @@ local update_jailed =
function Public.try_dl_data(key)
key = tostring(key)
local secs = Server.get_current_time()
if secs == nil then
if not secs then
return
else
try_get_data(jailed_data_set, key, is_jailed)
@ -155,8 +163,14 @@ function Public.try_ul_data(key, value, player)
value = value,
player = player or nil
}
if secs == nil then
return
if not secs then
if value then
jail(key, player)
return
else
free(key, player)
return
end
else
Task.set_timeout_in_ticks(1, update_jailed, data)
end
@ -191,9 +205,14 @@ Event.add(
defines.events.on_player_joined_game,
function(event)
local player = game.get_player(event.player_index)
if not player then
local secs = Server.get_current_time()
if not secs then
return
end
if not player or player.valid then
return
end
if game.is_multiplayer() then
Public.try_dl_data(player.name)
end
@ -224,16 +243,16 @@ Event.add(
local player = game.players[event.player_index]
p = player.print
if player.name == griefer then
return p("You can't select yourself!", {r = 1, g = 0.5, b = 0.1})
end
if not trusted[player.name] then
if not player.admin then
p("You're not admin nor are you trusted enough to run this command!", {r = 1, g = 0.5, b = 0.1})
return
end
end
if player.name == griefer then
return p("You can't select yourself!", {r = 1, g = 0.5, b = 0.1})
end
if cmd == 'jail' then
Public.try_ul_data(griefer, true, player.name)
return