From a1237d8cfdd25bf511c80359a9d5e72c2a871e15 Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Fri, 26 Jul 2019 23:55:33 +0200 Subject: [PATCH 1/7] Added CLI script for deleting players from playerManager --- cluster_rcon.js => CLI tools/cluster_rcon.js | 12 ++++++++++-- CLI tools/delete_player.js | 19 +++++++++++++++++++ package.json | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) rename cluster_rcon.js => CLI tools/cluster_rcon.js (79%) create mode 100644 CLI tools/delete_player.js diff --git a/cluster_rcon.js b/CLI tools/cluster_rcon.js similarity index 79% rename from cluster_rcon.js rename to CLI tools/cluster_rcon.js index bfffde5b..b62e6638 100644 --- a/cluster_rcon.js +++ b/CLI tools/cluster_rcon.js @@ -1,5 +1,13 @@ const needle = require("needle"); -const config = require("./config.json"); +const cli = require("cli"); +const config = require("./../config.json"); + +let options = cli.parse() +cli.setUsage(`node cluster_rcon.js /c game.player.force = "player"`) +if(process.argv.length < 3){ + cli.getUsage() + process.exit(1) +} const masterIP = `${config.masterIP}:${config.masterPort}`; const token = config.masterAuthToken @@ -30,4 +38,4 @@ let killBiters = `/silent-command local surface=game.surfaces[1] for key, entity // console.log(resp.body) // }); // }, 1000*60*5); -})(); \ No newline at end of file +})(); diff --git a/CLI tools/delete_player.js b/CLI tools/delete_player.js new file mode 100644 index 00000000..1043935e --- /dev/null +++ b/CLI tools/delete_player.js @@ -0,0 +1,19 @@ +const needle = require("needle") +const config = require("./../config.json") +const cli = require("cli") + +let options = cli.parse({ + name: ["n", "Name of the player to delete, case sensitive", "string"], + token: [false, "Factorio auth token", "string", config.masterAuthToken] +}) +if(!options.name){ + cli.getUsage() + process.exit(1) +} + +needle.post(config.masterIP+":"+config.masterPort+"/api/playerManager/deletePlayer", { + name: options.name, + token: options.token +}, (err, resp) => { + console.log(resp.body) +}); diff --git a/package.json b/package.json index 9e8d861f..3fce3b94 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "bcryptjs": "^2.4.3", "body-parser": "^1.18.2", "cache-require-paths": "^0.3.0", + "cli": "^1.0.1", "cli-interact": "^0.1.9", "codecov": "^3.0.1", "compression": "^1.7.2", From c95d9f946428d99c6e00d11e96553be66014548b Mon Sep 17 00:00:00 2001 From: Arvids Godjuks Date: Sat, 27 Jul 2019 22:59:23 +0300 Subject: [PATCH 2/7] Added "Doomsday" scenario (#184) * Added doomsday scenario --- scenarios/doomsday/control.lua | 149 +++++++++++++++ scenarios/doomsday/doomsday.lua | 251 ++++++++++++++++++++++++++ scenarios/doomsday/gui.lua | 266 +++++++++++++++++++++++++++ scenarios/doomsday/pdnc.lua | 309 ++++++++++++++++++++++++++++++++ 4 files changed, 975 insertions(+) create mode 100644 scenarios/doomsday/control.lua create mode 100644 scenarios/doomsday/doomsday.lua create mode 100644 scenarios/doomsday/gui.lua create mode 100644 scenarios/doomsday/pdnc.lua diff --git a/scenarios/doomsday/control.lua b/scenarios/doomsday/control.lua new file mode 100644 index 00000000..5bbfcde5 --- /dev/null +++ b/scenarios/doomsday/control.lua @@ -0,0 +1,149 @@ +--[[ +HUGE SHOUTOUT TO HORNWITSER FOR WRITING THIS SEXY AS MODLOADER <3 +and for not getting mad when i coppyed it :) +]] + +local modules = { + require("pdnc"), + require("doomsday"), + require("gui"), +} + +script.on_init(function() + for i,mod in ipairs(modules) do + if mod.on_init then + mod.on_init() + end + end +end) + +script.on_load(function() + for i,mod in ipairs(modules) do + if mod.on_load then + mod.on_load() + end + end +end) + +script.on_configuration_changed(function(data) + for i,mod in ipairs(modules) do + if mod.on_configuration_changed then + mod.on_configuration_changed(data) + end + end +end) + +local function register_tick_handlers() + local ticks = {} + for i,mod in ipairs(modules) do + print(mod.on_nth_ticks) + if mod.on_nth_ticks then + mod_ticks = mod.on_nth_ticks + for t,f in pairs(mod_ticks) do + if not ticks[t] then + ticks[t] = {} + end + + table.insert(ticks[t], f) + end + end + end + + for t,fs in pairs(ticks) do + script.on_nth_tick(t, function(event_data) + for i,f in ipairs(fs) do + f(event_data) + end + end) + end +end +register_tick_handlers() + +local function register_events() + local events = {} + for i,mod in ipairs(modules) do + if mod.get_events then + mod_events = mod.get_events() + for e,f in pairs(mod_events) do + if not events[e] then + events[e] = {} + end + + table.insert(events[e], f) + end + end + end + + for e,fs in pairs(events) do + script.on_event(e, function(event_data) + for i,f in ipairs(fs) do + f(event_data) + end + end) + end +end +register_events() + +for i,mod in ipairs(modules) do + if mod.add_remote_interfaces then + mod.add_remote_interfaces() + end +end + +for i,mod in ipairs(modules) do + if mod.add_commands then + mod.add_commands() + end +end + + +--[[ + +-- This is a example of what to put at the end of your code, ie doomsday.lua +-- replace all the EXAMPLE 's with any name you want, they have to be all the same +-- replace tick with number if ticks and function with the function name to call +-- everywhere there is a blank space is where you put stuff in + + + +local EXAMPLE_init = {} + +local script_events = { + --place the here what you would normaly use Event.register for + -- Event.register(defines.events.on_player_created, testfunction) + -- is the same as + -- [defines.events.on_player_created] = testfunction, + -- where testfunction is | local function testfunction() { } + --[Event] = function, + --put stuff here + +} + +EXAMPLE_init.on_nth_ticks = { + --place the here what you would normaly use + --[tick] = function, + --put stuff here + +} + +EXAMPLE_init.on_init = function() -- this runs when Event.core_events.init + log("EXAMPLE init") + --put stuff here + + global.EXAMPLE_data = global.EXAMPLE_data or script_data -- NO TOUCHY + +end + +EXAMPLE_init.on_load = function() -- this runs when Event.core_events.load + log("EXAMPLE load") + --put stuff here + + script_data = global.EXAMPLE_data or script_data -- NO TOUCHY +end + +EXAMPLE_init.get_events = function() + return script_events +end + +return EXAMPLE_init +]] \ No newline at end of file diff --git a/scenarios/doomsday/doomsday.lua b/scenarios/doomsday/doomsday.lua new file mode 100644 index 00000000..0cea7c69 --- /dev/null +++ b/scenarios/doomsday/doomsday.lua @@ -0,0 +1,251 @@ +-- doomsday module. Requires the programmable day-night cycle (pdnc) module to work. +-- made by Zr4g0n +-- this module currently has issues with the event module and 'on nth tick'. +require("pdnc") --is this the best way to do this? +global.doomsday_enabled = true +global.doomsday = global.doomsday or {} -- used to check if this exists. +global.doomsday_start = 8.75 -- in ingame days. Use n.75 to make sure doomsday is at midnight. +global.doomsday_pollution = 20 -- amount to be applied per tick +global.doomsday_surface = 1 +global.doomsday_enable_players_online_compensator = false +global.doomsday_current_fuzzy_playercount = 1.5 -- start assuming 1.5 players! :V +global.doomsday_use_early_death = false +global.doomsday_early_death_has_happened = false +global.doomsday_use_different_spawn = false +global.doomsday_different_spawn = {x = -2000, y = -500} +global.doomsday_has_happened = false + +function doomsday_status() + stats = { + "Time Left: " .. doomsday_time_left(), + "global.doomsday_start: " .. global.doomsday_start, + "global.doomsday_pollution: " .. global.doomsday_pollution, + "global.doomsday_surface: " .. global.doomsday_surface, + "global.doomsday_enabled: " .. pdnc_bool_to_string(global.doomsday_enabled), + "global.doomsday_enable_players_online_compensator: " .. pdnc_bool_to_string(global.doomsday_enable_players_online_compensator), + "global.doomsday_current_fuzzy_playercount: " .. global.doomsday_current_fuzzy_playercount, + "global.doomsday_use_early_death: " .. pdnc_bool_to_string(global.doomsday_use_early_death), + "global.doomsday_early_death_has_happened: " .. pdnc_bool_to_string(global.doomsday_early_death_has_happened), + "global.doomsday_use_different_spawn: " .. pdnc_bool_to_string(global.doomsday_use_different_spawn), + "global.doomsday_different_spawn: x = " .. global.doomsday_different_spawn.x .. ", y = " .. global.doomsday_different_spawn.y, + "doomsday_has_happened: " .. pdnc_bool_to_string(global.doomsday_has_happened), + } + return stats +end + +function doomsday_console_status() + --logs to console, used for debuging + log("Time Left: " .. doomsday_time_left()) + log("global.doomsday_start: " .. global.doomsday_start) + log("global.doomsday_pollution: " .. global.doomsday_pollution) + log("global.doomsday_surface: " .. global.doomsday_surface) + log("global.doomsday_enabled: " .. pdnc_bool_to_string(global.doomsday_enabled)) + log("global.doomsday_enable_players_online_compensator: " .. pdnc_bool_to_string(global.doomsday_enable_players_online_compensator)) + log("global.doomsday_current_fuzzy_playercount: " .. global.doomsday_current_fuzzy_playercount) + log("global.doomsday_use_early_death: " .. pdnc_bool_to_string(global.doomsday_use_early_death)) + log("global.doomsday_early_death_has_happened: " .. pdnc_bool_to_string(global.doomsday_early_death_has_happened)) + log("global.doomsday_use_different_spawn: " .. pdnc_bool_to_string(global.doomsday_use_different_spawn)) + log("global.doomsday_different_spawn: x = " .. global.doomsday_different_spawn.x .. ", y = " .. global.doomsday_different_spawn.y) + log("doomsday_has_happened: " .. pdnc_bool_to_string(global.doomsday_has_happened)) + return stats +end + +function doomsday_toggle() + global.doomsday_enabled = not global.doomsday_enabled + doomsday_status() +end + +function doomsday_setup() + if global.doomsday_use_different_spawn then + doomsday_activate_different_spawn() + end +end + +function doomsday_early_death() + local radius = 512 + local pollution = 2500 + doomsday_pollute(radius*0.66,pollution,12) + doomsday_pollute(radius*1.00,pollution,24) + doomsday_pollute(radius*1.50,pollution,36) + global.doomsday_early_death_has_happened = true +end + +function doomsday_activate_different_spawn() + game.forces["player"].set_spawn_position(global.doomsday_different_spawn, game.surfaces[global.doomsday_surface]) +end + +function doomsday_core() + local current_time = game.tick / game.surfaces[global.doomsday_surface].ticks_per_day + local x = current_time * 6.2831853 --2pi + local returnvalue = 0 + if(global.doomsday_enable_players_online_compensator)then + doomsday_players_online_compensator() + end + + if global.doomsday_use_early_death + and (current_time > 1) + and not global.doomsday_early_death_has_happened then + doomsday_early_death() + end + + local x = current_time * 6.2831853 --2pi + local returnvalue = 0 + if (current_time < global.doomsday_start) then + returnvalue = math.pow(pdnc_c_boxy(x), (1 + current_time / 4)) + -- days become darker over time towards n^6.125 + elseif (current_time < global.doomsday_start + 1) then + returnvalue = doomsday_pollution_zero_hour(current_time) + if not global.doomsday_has_happened then + global.doomsday_has_happened = true + log("Doomsday activated at tick: " .. game.tick) + end + else + global.pdnc_enable_brightness_limit = true + returnvalue = math.pow(pdnc_c_boxy(x), 6.125)--*0.5 + end + return pdnc_scaler(returnvalue) +end + +function doomsday_pollution_zero_hour(current_time) + local radius = 128 --make global + local pollution = global.doomsday_pollution -- total pollution applied per tick + local nodes = 5 -- the number of nodes to spread + doomsday_pollute(radius*0.66,pollution,nodes*0.66) + doomsday_pollute(radius*1.00,pollution,nodes*1.00) + doomsday_pollute(radius*1.50,pollution,nodes*1.50) + return math.pow(((global.doomsday_start + 1) - current_time), 7) +end + + +function doomsday_normal_curve(x) + return (1+ ((math.sin(x) + (0.111 * math.sin(3 * x))) * 1.124859392575928))/2 + -- magic numbers to make it scale to (-1, 1) +end + +function doomsday_pollute(radius,pollution,nodes) -- spawn a ring of pollution based on radius, amount of pollution and number of points in the ring. + local p = global.pdnc_stepsize * pollution -- needed to make it 'step size independant' + p = p / nodes + local position = {x = 0.0, y = 0.0} + if global.doomsday_use_different_spawn then + position = global.doomsday_different_spawn + end + --game.surfaces[global.doomsday_surface].pollute(position, p) --circle + center point + local step = (math.pi * 2) / (nodes - 1) + for i=0, (nodes - 1) do + position = {x = math.sin(step*i)*radius, y = math.cos(step*i)*radius} + game.surfaces[global.doomsday_surface].pollute(position, p) + end +end + +function doomsday_time_left() + if (global.doomsday_start > 0)then + local ticks_until_doomsday = game.surfaces[global.doomsday_surface].ticks_per_day * global.doomsday_start + local ticks = ticks_until_doomsday - game.tick + if (ticks >= 0) then + local seconds = math.floor(ticks/ 60) + local minutes = math.floor(seconds / 60) + local hours = math.floor(minutes / 60) + local days = math.floor(hours / 24) + return(string.format("-" .. "%d:%02d:%02d:%02d", hours, minutes % 60, seconds % 60, ticks % 60)) + else + ticks = ticks * -1 + local seconds = math.floor(ticks / 60) + local minutes = math.floor(seconds / 60) + local hours = math.floor(minutes / 60) + local days = math.floor(hours / 24) + return(string.format("%d:%02d:%02d:%02d", hours, minutes % 60, seconds % 60, ticks % 60) .. " ago...") + end + else + return("Nothing to see here, move along! No doomsday here, nope!") + end +end + +function doomsday_time_left_with_ticks() + local tick = (((game.surfaces[global.doomsday_surface].ticks_per_day * global.doomsday_start) - game.tick)%60) + return doomsday_time_left() .. ":" .. string.format("%02d", tick) +end + +function doomsday_players_online_compensator() + local target = #game.connected_players + local current = global.doomsday_current_fuzzy_playercount + local step_size = 0.02 -- (at 21 ticks per iteration, that's 17.5sec per player change. + + if(current < 0)then + game.print("Error; 'current' number of players' is less than 0!") + end + if(target < 0)then + game.print("Error; 'number of players' is less than 0!") + end + + if(current == target) then + -- do nothing, this should be most of the time + elseif ( current < target) then + current = current + step_size + elseif ( current > target) then + current = current - step_size + else + -- do nothing? + end + local modifier = 20/(0.1 * current * current + 6) -- Nice, smooth curve that should hopefully give boost equal to the playercount! + game.forces.player.character_running_speed_modifier = modifier + global.doomsday_current_fuzzy_playercount = current +end + +--[[ +function reduce_brightness(n) + global.pdnc_max_brightness = 1 - ((global.pdnc_current_time / global.pdnc_doomsday_start)*n) + if(global.pdnc_max_brightness < n) then + global.pdnc_max_brightness = n + end +end +]] + + + +-- This is a example of what to put at the end of your code, ie doomsday.lua +-- replaze EXAMPLE with any name you want +-- replace tick with number if ticks and function with the function name to call +-- everywhere there is a blank space is where you put stuff in + +local doomsday_init = {} + +local script_events = { + --place the here what you would normaly use Event.register for + -- Event.register(defines.events.on_player_created, testfunction) + -- is the same as + -- [defines.events.on_player_created] = testfunction, + -- where testfunction is | local functuin testfunction() { } + --[Event] = function, + --put stuff here + +} + +doomsday_init.on_nth_ticks = { + --place the here what you would normaly use + --[tick] = function, + --put stuff here + --[60] = doomsday_console_status, -- prints status to console ever second + +} + +doomsday_init.on_init = function() -- this runs when Event.core_events.init + log("doomsday init") + --put stuff here + doomsday_setup() + global.doomsday_data = global.doomsday_data or script_data -- NO TOUCHY +end + +doomsday_init.on_load = function() -- this runs when Event.core_events.load + log("doomsday load") + --put stuff here + script_data = global.doomsday_data or script_data -- NO TOUCHY +end + +doomsday_init.get_events = function() + return script_events +end + +return doomsday_init + +--Event.register(-global.pdnc_stepsize, doomsday_pdnc_program) --intentionally using the PDNC stepsize so the functions sync this can be skipped, since it's called from pdnc! +--Event.register(Event.core_events.init, doomsday_setup) diff --git a/scenarios/doomsday/gui.lua b/scenarios/doomsday/gui.lua new file mode 100644 index 00000000..07da7e2d --- /dev/null +++ b/scenarios/doomsday/gui.lua @@ -0,0 +1,266 @@ +local mod_gui = require 'mod-gui' + +-- ADDS DOOMSDAY STATS BUTTON +local function gui_update_DOOM(player) + local gui = mod_gui.get_frame_flow(player) + local frame = gui.doomsday_stats + if not frame then + return + end + + frame.clear() + for i,stat in ipairs(doomsday_status()) do + frame.add{ + type = "label", + caption = stat + } + end +end + +local function toggle_frame_DOOM(player) + local gui = mod_gui.get_frame_flow(player) + local frame = gui.doomsday_stats + + if frame then + frame.destroy() + return + end + + frame = gui.add{ + type = "frame", + name = "doomsday_stats", + direction = "vertical", + caption = "Doomsday stats", + style = mod_gui.frame_style, + } + + frame.style.horizontally_stretchable = false + frame.style.vertically_stretchable = false + gui_update_DOOM(player) +end + +local function get_sprite_button_DOOM(player) + local button_flow = mod_gui.get_button_flow(player) + button_DOOM = button_flow.doomsday_stats_button + + if button_DOOM then + button_DOOM.destroy() + end + + if player.admin then + button_DOOM = button_flow.add{ + type = "sprite-button", + name = "doomsday_stats_button", + sprite = "item/raw-fish", + style = mod_gui.button_style, + tooltip = "Show debug stats for doomsday", + } + end +end + +--ADDS PDNC STATS BUTTON +local function gui_update_PDNC(player) + local gui = mod_gui.get_frame_flow(player) + local frame_PDNC = gui.PDNC_stats + if not frame_PDNC then + return + end + + frame_PDNC.clear() + for i,stat in ipairs(pdnc_extended_status()) do + frame_PDNC.add{ + type = "label", + caption = stat + } + end +end + +local function toggle_frame_PDNC(player) + local gui = mod_gui.get_frame_flow(player) + local frame_PDNC = gui.PDNC_stats + + if frame_PDNC then + frame_PDNC.destroy() + return + end + + frame_PDNC = gui.add{ + type = "frame", + name = "PDNC_stats", + direction = "vertical", + caption = "PDNC stats", + style = mod_gui.frame_style, + } + + frame_PDNC.style.horizontally_stretchable = false + frame_PDNC.style.vertically_stretchable = false + gui_update_PDNC(player) +end + +local function get_sprite_button_PDNC(player) + local button_flow = mod_gui.get_button_flow(player) + local button_PDNC = button_flow.PDNC_stats_button + + if button_PDNC then + button_PDNC.destroy() + end + + if player.admin then + button_PDNC = button_flow.add{ + type = "sprite-button", + name = "PDNC_stats_button", + sprite = "item/raw-fish", + style = mod_gui.button_style, + tooltip = "Show debug stats for PDNC", + } + end +end + +-- ADDS DOOMSDAY TIME LEFT COUNTER +local function gui_update_counter(player) + local gui = player.gui.screen --mod_gui.get_frame_flow(player) + local frame_counter = gui.doomsday_counter + if not frame_counter then + return + end + + frame_counter.clear() + frame_counter.add{ + type = "label", + caption = doomsday_time_left() + } + frame_counter.location = {player.display_resolution.width/2 - 59, 10} + frame_counter.visible = true +end + +local function toggle_frame_counter(player) + --local player = player + local gui = player.gui.screen --mod_gui.get_frame_flow(player) + local frame_counter = gui.doomsday_counter + -- if frame_counter then + -- frame_counter.destroy() + -- return + -- end + + frame_counter = gui.add{ + type = "frame", + name = "doomsday_counter", + direction = "horizontal", + --caption = "Doomsday counter", + style = mod_gui.frame_style, + } + + --frame_counter.style.horizontally_stretchable = false + frame_counter.style.vertically_stretchable = false + frame_counter.visible = false + gui_update_counter(player) +end + +local function update_buttons(event) + local player = game.players[event.player_index] + if not (player and player.valid) then + return + end + + get_sprite_button_DOOM(player) + get_sprite_button_PDNC(player) + + -- Make sure the frames are not visible to players + if not player.admin then + local gui = mod_gui.get_frame_flow(player) + local frame_PDNC = gui.PDNC_stats + + if frame_PDNC then + frame_PDNC.destroy() + end + + local frame_DOOM = gui.doomsday_stats + + if frame_DOOM then + frame_DOOM.destroy() + end + end +end + +-- ON GUI CLICK AND OTHERS +local function on_gui_click(event) + local gui = event.element + local player = game.players[event.player_index] + if not (player and player.valid and gui and gui.valid) then + return + end + + if gui.name == "doomsday_stats_button" then + toggle_frame_DOOM(player) + end + if gui.name == "PDNC_stats_button" then + toggle_frame_PDNC(player) + end +end + +local function on_player_created(event) + local player = game.players[event.player_index] + if not (player and player.valid) then + return + end + + update_buttons(event) + toggle_frame_counter(player) +end + +local function gui_update_all() + for _, player in pairs(game.players) do + if player and player.valid then + gui_update_DOOM(player) + gui_update_PDNC(player) + gui_update_counter(player) + end + end +end + +local function on_gui_tick(event) + gui_update_all() +end + +local doomsdaygui_init = {} +local script_events = { + --place the here what you would normaly use Event.register for + -- Event.register(defines.events.on_player_created, testfunction) + -- is the same as + -- [defines.events.on_player_created] = testfunction, + -- where testfunction is | local functuin testfunction() { } + --[Event] = function, + --put stuff here + [defines.events.on_gui_click] = on_gui_click, + [defines.events.on_player_created] = on_player_created, + [defines.events.on_player_promoted] = update_buttons, + [defines.events.on_player_demoted] = update_buttons, +} + +doomsdaygui_init.on_nth_ticks = { + --place the here what you would normaly use + --[tick] = function, + --put stuff here + [1] = on_gui_tick, +} + +doomsdaygui_init.on_init = function() -- this runs when Event.core_events.init + log("doomsdaygui init") + --put stuff here + + global.doomsdaygui_data = global.doomsdaygui_data or script_data -- NO TOUCHY + +end + +doomsdaygui_init.on_load = function() -- this runs when Event.core_events.load + log("doomsdaygui load") + --put stuff here + + script_data = global.doomsdaygui_data or script_data -- NO TOUCHY +end + +doomsdaygui_init.get_events = function() + return script_events +end + +return doomsdaygui_init \ No newline at end of file diff --git a/scenarios/doomsday/pdnc.lua b/scenarios/doomsday/pdnc.lua new file mode 100644 index 00000000..d37b19fa --- /dev/null +++ b/scenarios/doomsday/pdnc.lua @@ -0,0 +1,309 @@ +-- Third itteration of programmable day-night cycle for Factorio +-- Developed by Zr4g0n with help +-- Features needed: +-- Set 'maximum brightness' from rocket launches cluster wide +-- Set 'time until doomsday' to any time, in minutes. +-- Set 'evolution target' to any number [0.0, 1.0] +-- Changing day-night cycle based on days +-- Handle 'next time' elegantly + +-- lamps enable darkness: [0.595 - 0.425] scaled to [0.0 - 0.85] range from [0.0 - 1.0] range +global.pdnc = global.pdnc or {} +global.pdnc_enabled = true +global.pdnc_stepsize = 53 -- also used for script.on_nth_tick. Cannot be changed at runtime! +global.pdnc_surface = 1 +global.pdnc_current_time = 0 +global.pdnc_current_point = {x = 0, y = 1.0} +global.pdnc_last_point = {x = -1, y = 0.0} +global.pdnc_max_brightness = 0.5 -- for clusterio +global.pdnc_debug = false +global.pdnc_enable_brightness_limit = false +global.pdnc_enable_rocket_darkness = false +global.pdnc_rockets_launched = 0 +global.pdnc_rockets_launched_step_size = 0.025 +global.pdnc_rockets_launched_smooth = 0 +global.pdnc_min_per_day = 15.0 + +function pdnc_setup() + --game.surfaces[global.pdnc_surface].ticks_per_day = pdnc_min_to_ticks(10.0) + doomsday_setup() +end + +-- Returns true if the player is an admin +function check_admin(ctx) + local player = game.players[ctx.player_index] + if not player.admin then + player.print("Only admins can use /"..ctx.name) + return false + end + return true +end + +function pdnc_toggle_debug(ctx) + if not check_admin(ctx) then return end + global.pdnc_debug = not global.pdnc_debug + pdnc_print_status(ctx) +end + +function pdnc_toggle(ctx) + if not check_admin(ctx) then return end + global.pdnc_enabled = not global.pdnc_enabled + pdnc_print_status(ctx) +end + +function pdnc_print_status(ctx) + local player = game.players[ctx.player_index] + if(global.pdnc_enabled)then + player.print("PDNC is enabled") + else + player.print("PDNC is disabled") + end + + if(global.pdnc_debug)then + player.print("PDNC debug is enabled") + pdnc_extended_status() + else + player.print("PDNC debug is disabled") + end +end + +function pdnc_extended_status() + stats = { + "global.pdnc_stepsize: " .. global.pdnc_stepsize, + "global.pdnc_surface: " .. global.pdnc_surface, + "global.pdnc_current_time: " .. global.pdnc_current_time, + "global.pdnc_max_brightness: " .. global.pdnc_max_brightness, + "global.pdnc_enable_brightness_limit: " .. pdnc_bool_to_string(global.pdnc_enable_brightness_limit), + "global.pdnc_enable_rocket_darkness: " .. pdnc_bool_to_string(global.pdnc_enable_rocket_darkness), + "global.pdnc_rockets_launched: " .. global.pdnc_rockets_launched, + "global.pdnc_rockets_launched_step_size: " .. global.pdnc_rockets_launched_step_size, + "global.pdnc_rockets_launched_smooth: " .. global.pdnc_rockets_launched_smooth, + "ticks per day: " .. game.surfaces[global.pdnc_surface].ticks_per_day, + "current tick: " .. game.tick, + } + return stats +end + +function pdnc_bool_to_string(b) + if(b)then + return "true" + else + return "false" + end +end + +function pdnc_core() + if(global.pdnc_enabled)then + doomsday_core() + local current_surface = game.surfaces[global.pdnc_surface] + pdnc_freeze_check(current_surface) + current_surface.ticks_per_day = pdnc_min_to_ticks(global.pdnc_min_per_day) -- move this somewhere else; doesn't need to run every nth tick! + global.pdnc_current_time = game.tick / current_surface.ticks_per_day + + -- get current Y coordinate. X = 0 always. + local current_point = {x = global.pdnc_current_time, y = pdnc_program(global.pdnc_current_time)} + -- get next Y coordinate, X = 'step size' + local next_point = {x = (global.pdnc_current_time + (global.pdnc_stepsize/current_surface.ticks_per_day)), y = pdnc_program(global.pdnc_current_time + (global.pdnc_stepsize/current_surface.ticks_per_day))} + + local top_point = pdnc_intersection_top(current_point, next_point) + local bot_point = pdnc_intersection_bot(current_point, next_point) + + -- the order is dusk - evening - morning - dawn. They *must* be in that order and they cannot be equal + if(top_point < bot_point) then -- dusk -> evening + pdnc_cleanup_last_tick(current_surface) + current_surface.evening = bot_point - current_point.x + current_surface.dusk = top_point - current_point.x + elseif(top_point > bot_point) then -- morning -> dawn + pdnc_cleanup_last_tick(current_surface) + current_surface.morning = bot_point - current_point.x + current_surface.dawn = top_point - current_point.x + elseif(top_point == bot_point) then + pdnc_debug_message("PDNC: Top and bot point equal") + -- no cleanup is done here + -- if the points are equal, use last value until not equal + -- this should never be reached unless the pdnc_program() is broken. + else + pdnc_debug_message("Top and bot not different nor equal. probably a NaN error") + pdnc_debug_message("bot_point: " .. bot_point) + pdnc_debug_message("top_point: " .. top_point) + -- this should never be reached. + end + else + end +end + +function pdnc_cleanup_last_tick(current_surface) + current_surface.daytime = 0 + -- must be in this spesific order to + -- preserve the order at all times + -- dusk < evening < morning < dawn. + -- DO NOT CHANGE THE ORDER! + current_surface.dusk = -999999999999 + current_surface.dawn = 999999999999 + current_surface.evening = -999999999998 + current_surface.morning = 999999999998 +end + +function pdnc_disable_and_reset(ctx) + if not check_admin(ctx) then return end + local current_surface = game.surfaces[global.pdnc_surface] + pdnc_cleanup_last_tick(current_surface) + -- DO NOT CHANGE THIS ORDER! + current_surface.evening = 0.45 + current_surface.morning = 0.55 + current_surface.dusk = 0.25 + current_surface.dawn = 0.75 + current_surface.ticks_per_day = 25000 + global.pdnc_enabled = false + pdnc_debug_message("PDNC Programable Day-Night Cycle disabled, normal day-night cycle enabled") +end + +function pdnc_freeze_check(current_surface) + if(current_surface.freeze_daytime)then + current_surface.freeze_daytime = false + game.print("Can't use freeze_daytime while programmable day-night cycle is active; time has been unfrozen") + end +end + +function pdnc_program(x) + return pdnc_scaler(pdnc_c_boxy(x*6.28318530717958647692)) -- that's Tau, aka 2xPi +end + +function pdnc_c_boxy(x) + return pdnc_normalize((math.sin(x) + (0.111 * math.sin(3 * x))) * 1.124859392575928) + -- magic numbers to make it scale to (-1, 1) +end + +function pdnc_normalize(n) + return (n + 1)/2 +end + +function pdnc_scaler(r) -- a bit messy, but simplifies a lot elsewhere + if(pdnc_check_valid(r, "pdnc_scaler"))then + + local a = 1 + local b = 1 + + if(global.pdnc_enable_brightness_limit) then + a = global.pdnc_max_brightness + end + + if(global.pdnc_enable_rocket_darkness) then + b = 1 - pdnc_rocket_launch_darkness() + end + + return r * 0.85 * a * b -- 0 -> 0.85 is the 'brightness range' of factorio + end +end + +function pdnc_intersection (s1, e1, s2, e2) + local d = (s1.x - e1.x) * (s2.y - e2.y) - (s1.y - e1.y) * (s2.x - e2.x) + local a = s1.x * e1.y - s1.y * e1.x + local b = s2.x * e2.y - s2.y * e2.x + local x = (a * (s2.x - e2.x) - (s1.x - e1.x) * b) / d + --local y = (a * (s2.y - e2.y) - (s1.y - e1.y) * b) / d + return x--, y +end + +function pdnc_intersection_top (s2, e2) + local s1, e1 = {x = -999999999, y = 0.85}, {x = 999999999, y = 0.85} + return pdnc_intersection (s1, e1, s2, e2) +end + +function pdnc_intersection_bot (s2, e2) + local s1, e1 = {x = -999999999, y = 0.0}, {x = 999999999, y = 0.0} + return pdnc_intersection (s1, e1, s2, e2) +end + +function pdnc_set_max_brightness(n) + if(pdnc_check_valid(n, "pdnc_set_max_brightness")) then + global.pdnc_max_brightness = n + pdnc_debug_message("global.pdnc_max_brightness set to " .. global.pdnc_max_brightness) + end +end + +function pdnc_min_to_ticks(m) + return 60*60*m +end + +function pdnc_rocket_launch_counter() + global.pdnc_rockets_launched = 1 + global.pdnc_rockets_launched +end + +function pdnc_rocket_launch_darkness() + if (global.pdnc_rockets_launched_smooth < global.pdnc_rockets_launched)then + global.pdnc_rockets_launched_smooth = global.pdnc_rockets_launched_step_size + global.pdnc_rockets_launched_smooth + end + return (1 - (50/(global.pdnc_rockets_launched_smooth+50))) +end + +function pdnc_check_valid(n, s) + if (n == nil) then + pdnc_debug_message(s .. " set to nil! Set to 1.0 instead") + return false + elseif (n < 0) then + pdnc_debug_message(s .. " cannot be " .. n .. " limited to 0.0 instead") + return false + elseif (n > 1) then + pdnc_debug_message(s .. " cannot be " .. n .. " limited to 1.0 instead") + return false + elseif (n ~= n) then + pdnc_debug_message(s .. " cannot be " .. n .. " since it's not a valid number!") + else return true + end +end + +function pdnc_debug_message(s) + if(global.pdnc_debug) then + game.print(s) + end +end + + +local PDNC_init = {} + +local script_events = { + --place the here what you would normaly use Event.register for + -- Event.register(defines.events.on_player_created, testfunction) + -- is the same as + -- [defines.events.on_player_created] = testfunction, + -- where testfunction is | local functuin testfunction() { } + --[Event] = function, + --put stuff here + +} + +PDNC_init.on_nth_ticks = { + --place the here what you would normaly use + --[tick] = function, + --put stuff here + [global.pdnc_stepsize] = pdnc_core, +} + +PDNC_init.add_commands = function() + commands.add_command("pdnc", "gives PDNC's status", pdnc_print_status) + commands.add_command("pdnc_toggle", "toggles pdnc", pdnc_toggle) + commands.add_command("pdnc_toggle_debug", "toggles pdnc debug mode", pdnc_toggle_debug) + commands.add_command("pdnc_disable_and_reset", "Disabled pdnc and resets the dnc to the vanilla default", pdnc_disable_and_reset) +end + +PDNC_init.on_init = function() -- this runs when Event.core_events.init + log("PDNC init") + --put stuff here + global.PDNC_data = global.PDNC_data or script_data -- NO TOUCHY + +end + +PDNC_init.on_load = function() -- this runs when Event.core_events.load + log("PDNC load") + + --put stuff here + + script_data = global.PDNC_data or script_data -- NO TOUCHY +end + +PDNC_init.get_events = function() + return script_events +end + +return PDNC_init From a00183e94c00eeb997d4d7bb8f5981759919c5b8 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 28 Jul 2019 14:42:44 +0200 Subject: [PATCH 3/7] Switch to rcon-client fork (#183) Switch to using fork of rcon-client where the commands and the responses are not converted to ASCII before being sent over the wire. Should fix the issue with Russian text showing up as garbled letters in the chat as well as the issue with train schedules using >= and <= conditions. If rcon-client upstream is updated with the utf8 patch this commit can be reverted with the version the patch was included in. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3fce3b94..307c4ef8 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "node-factorio-api": "^0.3.1-alpha", "node-forge": "^0.7.1", "prom-client": "^10.2.3", - "rcon-client": "^3.1.6", + "rcon-client": "git+https://gitlab.com/Hornwitser/rcon-client.git", "request": "^2.83.0", "right-pad": "^1.0.1", "rmdir-sync": "^1.0.1", From 042230dc2c106b4ecf626e424f728a359a10087d Mon Sep 17 00:00:00 2001 From: Sander Homan Date: Mon, 29 Jul 2019 20:31:42 +0200 Subject: [PATCH 4/7] Fix notifying about the same research being finished This is just a bandaid to fix a symptom. The underlying cause is still there, but at least it shouldn't spam the players anymore. --- sharedPlugins/researchSync/enableResearch.lua | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sharedPlugins/researchSync/enableResearch.lua b/sharedPlugins/researchSync/enableResearch.lua index 4e5af42a..f83a1e93 100644 --- a/sharedPlugins/researchSync/enableResearch.lua +++ b/sharedPlugins/researchSync/enableResearch.lua @@ -1,10 +1,5 @@ -if game.forces['player'].technologies['{tech_name}'] then - if 1 == {tech_infinite} then - game.forces['player'].technologies['{tech_name}'].level = {tech_level} - else - game.forces['player'].technologies['{tech_name}'].researched = true - end +local function updateTech() script.raise_event(defines.events.on_research_finished, {research=game.forces['player'].technologies['{tech_name}'], by_script=true}) if {notify} then if 1 == {tech_infinite} then @@ -15,3 +10,17 @@ if game.forces['player'].technologies['{tech_name}'] then game.play_sound({path="utility/research_completed"}) end end + +if game.forces['player'].technologies['{tech_name}'] then + if 1 == {tech_infinite} then + if (game.forces['player'].technologies['{tech_name}'].level ~= level) then + game.forces['player'].technologies['{tech_name}'].level = {tech_level} + updateTech() + end + else + if not game.forces['player'].technologies['{tech_name}'].researched then + game.forces['player'].technologies['{tech_name}'].researched = true + updateTech() + end + end +end From 9d1e60aa03d5668abac2b30e8781653d95f285dc Mon Sep 17 00:00:00 2001 From: psihius Date: Tue, 30 Jul 2019 11:49:24 +0200 Subject: [PATCH 5/7] Remove Doomsday scenario, should be reworked as dynamic plugin. See `doomsday-save-point` for scenario code --- scenarios/doomsday/control.lua | 149 --------------- scenarios/doomsday/doomsday.lua | 251 -------------------------- scenarios/doomsday/gui.lua | 266 --------------------------- scenarios/doomsday/pdnc.lua | 309 -------------------------------- 4 files changed, 975 deletions(-) delete mode 100644 scenarios/doomsday/control.lua delete mode 100644 scenarios/doomsday/doomsday.lua delete mode 100644 scenarios/doomsday/gui.lua delete mode 100644 scenarios/doomsday/pdnc.lua diff --git a/scenarios/doomsday/control.lua b/scenarios/doomsday/control.lua deleted file mode 100644 index 5bbfcde5..00000000 --- a/scenarios/doomsday/control.lua +++ /dev/null @@ -1,149 +0,0 @@ ---[[ -HUGE SHOUTOUT TO HORNWITSER FOR WRITING THIS SEXY AS MODLOADER <3 -and for not getting mad when i coppyed it :) -]] - -local modules = { - require("pdnc"), - require("doomsday"), - require("gui"), -} - -script.on_init(function() - for i,mod in ipairs(modules) do - if mod.on_init then - mod.on_init() - end - end -end) - -script.on_load(function() - for i,mod in ipairs(modules) do - if mod.on_load then - mod.on_load() - end - end -end) - -script.on_configuration_changed(function(data) - for i,mod in ipairs(modules) do - if mod.on_configuration_changed then - mod.on_configuration_changed(data) - end - end -end) - -local function register_tick_handlers() - local ticks = {} - for i,mod in ipairs(modules) do - print(mod.on_nth_ticks) - if mod.on_nth_ticks then - mod_ticks = mod.on_nth_ticks - for t,f in pairs(mod_ticks) do - if not ticks[t] then - ticks[t] = {} - end - - table.insert(ticks[t], f) - end - end - end - - for t,fs in pairs(ticks) do - script.on_nth_tick(t, function(event_data) - for i,f in ipairs(fs) do - f(event_data) - end - end) - end -end -register_tick_handlers() - -local function register_events() - local events = {} - for i,mod in ipairs(modules) do - if mod.get_events then - mod_events = mod.get_events() - for e,f in pairs(mod_events) do - if not events[e] then - events[e] = {} - end - - table.insert(events[e], f) - end - end - end - - for e,fs in pairs(events) do - script.on_event(e, function(event_data) - for i,f in ipairs(fs) do - f(event_data) - end - end) - end -end -register_events() - -for i,mod in ipairs(modules) do - if mod.add_remote_interfaces then - mod.add_remote_interfaces() - end -end - -for i,mod in ipairs(modules) do - if mod.add_commands then - mod.add_commands() - end -end - - ---[[ - --- This is a example of what to put at the end of your code, ie doomsday.lua --- replace all the EXAMPLE 's with any name you want, they have to be all the same --- replace tick with number if ticks and function with the function name to call --- everywhere there is a blank space is where you put stuff in - - - -local EXAMPLE_init = {} - -local script_events = { - --place the here what you would normaly use Event.register for - -- Event.register(defines.events.on_player_created, testfunction) - -- is the same as - -- [defines.events.on_player_created] = testfunction, - -- where testfunction is | local function testfunction() { } - --[Event] = function, - --put stuff here - -} - -EXAMPLE_init.on_nth_ticks = { - --place the here what you would normaly use - --[tick] = function, - --put stuff here - -} - -EXAMPLE_init.on_init = function() -- this runs when Event.core_events.init - log("EXAMPLE init") - --put stuff here - - global.EXAMPLE_data = global.EXAMPLE_data or script_data -- NO TOUCHY - -end - -EXAMPLE_init.on_load = function() -- this runs when Event.core_events.load - log("EXAMPLE load") - --put stuff here - - script_data = global.EXAMPLE_data or script_data -- NO TOUCHY -end - -EXAMPLE_init.get_events = function() - return script_events -end - -return EXAMPLE_init -]] \ No newline at end of file diff --git a/scenarios/doomsday/doomsday.lua b/scenarios/doomsday/doomsday.lua deleted file mode 100644 index 0cea7c69..00000000 --- a/scenarios/doomsday/doomsday.lua +++ /dev/null @@ -1,251 +0,0 @@ --- doomsday module. Requires the programmable day-night cycle (pdnc) module to work. --- made by Zr4g0n --- this module currently has issues with the event module and 'on nth tick'. -require("pdnc") --is this the best way to do this? -global.doomsday_enabled = true -global.doomsday = global.doomsday or {} -- used to check if this exists. -global.doomsday_start = 8.75 -- in ingame days. Use n.75 to make sure doomsday is at midnight. -global.doomsday_pollution = 20 -- amount to be applied per tick -global.doomsday_surface = 1 -global.doomsday_enable_players_online_compensator = false -global.doomsday_current_fuzzy_playercount = 1.5 -- start assuming 1.5 players! :V -global.doomsday_use_early_death = false -global.doomsday_early_death_has_happened = false -global.doomsday_use_different_spawn = false -global.doomsday_different_spawn = {x = -2000, y = -500} -global.doomsday_has_happened = false - -function doomsday_status() - stats = { - "Time Left: " .. doomsday_time_left(), - "global.doomsday_start: " .. global.doomsday_start, - "global.doomsday_pollution: " .. global.doomsday_pollution, - "global.doomsday_surface: " .. global.doomsday_surface, - "global.doomsday_enabled: " .. pdnc_bool_to_string(global.doomsday_enabled), - "global.doomsday_enable_players_online_compensator: " .. pdnc_bool_to_string(global.doomsday_enable_players_online_compensator), - "global.doomsday_current_fuzzy_playercount: " .. global.doomsday_current_fuzzy_playercount, - "global.doomsday_use_early_death: " .. pdnc_bool_to_string(global.doomsday_use_early_death), - "global.doomsday_early_death_has_happened: " .. pdnc_bool_to_string(global.doomsday_early_death_has_happened), - "global.doomsday_use_different_spawn: " .. pdnc_bool_to_string(global.doomsday_use_different_spawn), - "global.doomsday_different_spawn: x = " .. global.doomsday_different_spawn.x .. ", y = " .. global.doomsday_different_spawn.y, - "doomsday_has_happened: " .. pdnc_bool_to_string(global.doomsday_has_happened), - } - return stats -end - -function doomsday_console_status() - --logs to console, used for debuging - log("Time Left: " .. doomsday_time_left()) - log("global.doomsday_start: " .. global.doomsday_start) - log("global.doomsday_pollution: " .. global.doomsday_pollution) - log("global.doomsday_surface: " .. global.doomsday_surface) - log("global.doomsday_enabled: " .. pdnc_bool_to_string(global.doomsday_enabled)) - log("global.doomsday_enable_players_online_compensator: " .. pdnc_bool_to_string(global.doomsday_enable_players_online_compensator)) - log("global.doomsday_current_fuzzy_playercount: " .. global.doomsday_current_fuzzy_playercount) - log("global.doomsday_use_early_death: " .. pdnc_bool_to_string(global.doomsday_use_early_death)) - log("global.doomsday_early_death_has_happened: " .. pdnc_bool_to_string(global.doomsday_early_death_has_happened)) - log("global.doomsday_use_different_spawn: " .. pdnc_bool_to_string(global.doomsday_use_different_spawn)) - log("global.doomsday_different_spawn: x = " .. global.doomsday_different_spawn.x .. ", y = " .. global.doomsday_different_spawn.y) - log("doomsday_has_happened: " .. pdnc_bool_to_string(global.doomsday_has_happened)) - return stats -end - -function doomsday_toggle() - global.doomsday_enabled = not global.doomsday_enabled - doomsday_status() -end - -function doomsday_setup() - if global.doomsday_use_different_spawn then - doomsday_activate_different_spawn() - end -end - -function doomsday_early_death() - local radius = 512 - local pollution = 2500 - doomsday_pollute(radius*0.66,pollution,12) - doomsday_pollute(radius*1.00,pollution,24) - doomsday_pollute(radius*1.50,pollution,36) - global.doomsday_early_death_has_happened = true -end - -function doomsday_activate_different_spawn() - game.forces["player"].set_spawn_position(global.doomsday_different_spawn, game.surfaces[global.doomsday_surface]) -end - -function doomsday_core() - local current_time = game.tick / game.surfaces[global.doomsday_surface].ticks_per_day - local x = current_time * 6.2831853 --2pi - local returnvalue = 0 - if(global.doomsday_enable_players_online_compensator)then - doomsday_players_online_compensator() - end - - if global.doomsday_use_early_death - and (current_time > 1) - and not global.doomsday_early_death_has_happened then - doomsday_early_death() - end - - local x = current_time * 6.2831853 --2pi - local returnvalue = 0 - if (current_time < global.doomsday_start) then - returnvalue = math.pow(pdnc_c_boxy(x), (1 + current_time / 4)) - -- days become darker over time towards n^6.125 - elseif (current_time < global.doomsday_start + 1) then - returnvalue = doomsday_pollution_zero_hour(current_time) - if not global.doomsday_has_happened then - global.doomsday_has_happened = true - log("Doomsday activated at tick: " .. game.tick) - end - else - global.pdnc_enable_brightness_limit = true - returnvalue = math.pow(pdnc_c_boxy(x), 6.125)--*0.5 - end - return pdnc_scaler(returnvalue) -end - -function doomsday_pollution_zero_hour(current_time) - local radius = 128 --make global - local pollution = global.doomsday_pollution -- total pollution applied per tick - local nodes = 5 -- the number of nodes to spread - doomsday_pollute(radius*0.66,pollution,nodes*0.66) - doomsday_pollute(radius*1.00,pollution,nodes*1.00) - doomsday_pollute(radius*1.50,pollution,nodes*1.50) - return math.pow(((global.doomsday_start + 1) - current_time), 7) -end - - -function doomsday_normal_curve(x) - return (1+ ((math.sin(x) + (0.111 * math.sin(3 * x))) * 1.124859392575928))/2 - -- magic numbers to make it scale to (-1, 1) -end - -function doomsday_pollute(radius,pollution,nodes) -- spawn a ring of pollution based on radius, amount of pollution and number of points in the ring. - local p = global.pdnc_stepsize * pollution -- needed to make it 'step size independant' - p = p / nodes - local position = {x = 0.0, y = 0.0} - if global.doomsday_use_different_spawn then - position = global.doomsday_different_spawn - end - --game.surfaces[global.doomsday_surface].pollute(position, p) --circle + center point - local step = (math.pi * 2) / (nodes - 1) - for i=0, (nodes - 1) do - position = {x = math.sin(step*i)*radius, y = math.cos(step*i)*radius} - game.surfaces[global.doomsday_surface].pollute(position, p) - end -end - -function doomsday_time_left() - if (global.doomsday_start > 0)then - local ticks_until_doomsday = game.surfaces[global.doomsday_surface].ticks_per_day * global.doomsday_start - local ticks = ticks_until_doomsday - game.tick - if (ticks >= 0) then - local seconds = math.floor(ticks/ 60) - local minutes = math.floor(seconds / 60) - local hours = math.floor(minutes / 60) - local days = math.floor(hours / 24) - return(string.format("-" .. "%d:%02d:%02d:%02d", hours, minutes % 60, seconds % 60, ticks % 60)) - else - ticks = ticks * -1 - local seconds = math.floor(ticks / 60) - local minutes = math.floor(seconds / 60) - local hours = math.floor(minutes / 60) - local days = math.floor(hours / 24) - return(string.format("%d:%02d:%02d:%02d", hours, minutes % 60, seconds % 60, ticks % 60) .. " ago...") - end - else - return("Nothing to see here, move along! No doomsday here, nope!") - end -end - -function doomsday_time_left_with_ticks() - local tick = (((game.surfaces[global.doomsday_surface].ticks_per_day * global.doomsday_start) - game.tick)%60) - return doomsday_time_left() .. ":" .. string.format("%02d", tick) -end - -function doomsday_players_online_compensator() - local target = #game.connected_players - local current = global.doomsday_current_fuzzy_playercount - local step_size = 0.02 -- (at 21 ticks per iteration, that's 17.5sec per player change. - - if(current < 0)then - game.print("Error; 'current' number of players' is less than 0!") - end - if(target < 0)then - game.print("Error; 'number of players' is less than 0!") - end - - if(current == target) then - -- do nothing, this should be most of the time - elseif ( current < target) then - current = current + step_size - elseif ( current > target) then - current = current - step_size - else - -- do nothing? - end - local modifier = 20/(0.1 * current * current + 6) -- Nice, smooth curve that should hopefully give boost equal to the playercount! - game.forces.player.character_running_speed_modifier = modifier - global.doomsday_current_fuzzy_playercount = current -end - ---[[ -function reduce_brightness(n) - global.pdnc_max_brightness = 1 - ((global.pdnc_current_time / global.pdnc_doomsday_start)*n) - if(global.pdnc_max_brightness < n) then - global.pdnc_max_brightness = n - end -end -]] - - - --- This is a example of what to put at the end of your code, ie doomsday.lua --- replaze EXAMPLE with any name you want --- replace tick with number if ticks and function with the function name to call --- everywhere there is a blank space is where you put stuff in - -local doomsday_init = {} - -local script_events = { - --place the here what you would normaly use Event.register for - -- Event.register(defines.events.on_player_created, testfunction) - -- is the same as - -- [defines.events.on_player_created] = testfunction, - -- where testfunction is | local functuin testfunction() { } - --[Event] = function, - --put stuff here - -} - -doomsday_init.on_nth_ticks = { - --place the here what you would normaly use - --[tick] = function, - --put stuff here - --[60] = doomsday_console_status, -- prints status to console ever second - -} - -doomsday_init.on_init = function() -- this runs when Event.core_events.init - log("doomsday init") - --put stuff here - doomsday_setup() - global.doomsday_data = global.doomsday_data or script_data -- NO TOUCHY -end - -doomsday_init.on_load = function() -- this runs when Event.core_events.load - log("doomsday load") - --put stuff here - script_data = global.doomsday_data or script_data -- NO TOUCHY -end - -doomsday_init.get_events = function() - return script_events -end - -return doomsday_init - ---Event.register(-global.pdnc_stepsize, doomsday_pdnc_program) --intentionally using the PDNC stepsize so the functions sync this can be skipped, since it's called from pdnc! ---Event.register(Event.core_events.init, doomsday_setup) diff --git a/scenarios/doomsday/gui.lua b/scenarios/doomsday/gui.lua deleted file mode 100644 index 07da7e2d..00000000 --- a/scenarios/doomsday/gui.lua +++ /dev/null @@ -1,266 +0,0 @@ -local mod_gui = require 'mod-gui' - --- ADDS DOOMSDAY STATS BUTTON -local function gui_update_DOOM(player) - local gui = mod_gui.get_frame_flow(player) - local frame = gui.doomsday_stats - if not frame then - return - end - - frame.clear() - for i,stat in ipairs(doomsday_status()) do - frame.add{ - type = "label", - caption = stat - } - end -end - -local function toggle_frame_DOOM(player) - local gui = mod_gui.get_frame_flow(player) - local frame = gui.doomsday_stats - - if frame then - frame.destroy() - return - end - - frame = gui.add{ - type = "frame", - name = "doomsday_stats", - direction = "vertical", - caption = "Doomsday stats", - style = mod_gui.frame_style, - } - - frame.style.horizontally_stretchable = false - frame.style.vertically_stretchable = false - gui_update_DOOM(player) -end - -local function get_sprite_button_DOOM(player) - local button_flow = mod_gui.get_button_flow(player) - button_DOOM = button_flow.doomsday_stats_button - - if button_DOOM then - button_DOOM.destroy() - end - - if player.admin then - button_DOOM = button_flow.add{ - type = "sprite-button", - name = "doomsday_stats_button", - sprite = "item/raw-fish", - style = mod_gui.button_style, - tooltip = "Show debug stats for doomsday", - } - end -end - ---ADDS PDNC STATS BUTTON -local function gui_update_PDNC(player) - local gui = mod_gui.get_frame_flow(player) - local frame_PDNC = gui.PDNC_stats - if not frame_PDNC then - return - end - - frame_PDNC.clear() - for i,stat in ipairs(pdnc_extended_status()) do - frame_PDNC.add{ - type = "label", - caption = stat - } - end -end - -local function toggle_frame_PDNC(player) - local gui = mod_gui.get_frame_flow(player) - local frame_PDNC = gui.PDNC_stats - - if frame_PDNC then - frame_PDNC.destroy() - return - end - - frame_PDNC = gui.add{ - type = "frame", - name = "PDNC_stats", - direction = "vertical", - caption = "PDNC stats", - style = mod_gui.frame_style, - } - - frame_PDNC.style.horizontally_stretchable = false - frame_PDNC.style.vertically_stretchable = false - gui_update_PDNC(player) -end - -local function get_sprite_button_PDNC(player) - local button_flow = mod_gui.get_button_flow(player) - local button_PDNC = button_flow.PDNC_stats_button - - if button_PDNC then - button_PDNC.destroy() - end - - if player.admin then - button_PDNC = button_flow.add{ - type = "sprite-button", - name = "PDNC_stats_button", - sprite = "item/raw-fish", - style = mod_gui.button_style, - tooltip = "Show debug stats for PDNC", - } - end -end - --- ADDS DOOMSDAY TIME LEFT COUNTER -local function gui_update_counter(player) - local gui = player.gui.screen --mod_gui.get_frame_flow(player) - local frame_counter = gui.doomsday_counter - if not frame_counter then - return - end - - frame_counter.clear() - frame_counter.add{ - type = "label", - caption = doomsday_time_left() - } - frame_counter.location = {player.display_resolution.width/2 - 59, 10} - frame_counter.visible = true -end - -local function toggle_frame_counter(player) - --local player = player - local gui = player.gui.screen --mod_gui.get_frame_flow(player) - local frame_counter = gui.doomsday_counter - -- if frame_counter then - -- frame_counter.destroy() - -- return - -- end - - frame_counter = gui.add{ - type = "frame", - name = "doomsday_counter", - direction = "horizontal", - --caption = "Doomsday counter", - style = mod_gui.frame_style, - } - - --frame_counter.style.horizontally_stretchable = false - frame_counter.style.vertically_stretchable = false - frame_counter.visible = false - gui_update_counter(player) -end - -local function update_buttons(event) - local player = game.players[event.player_index] - if not (player and player.valid) then - return - end - - get_sprite_button_DOOM(player) - get_sprite_button_PDNC(player) - - -- Make sure the frames are not visible to players - if not player.admin then - local gui = mod_gui.get_frame_flow(player) - local frame_PDNC = gui.PDNC_stats - - if frame_PDNC then - frame_PDNC.destroy() - end - - local frame_DOOM = gui.doomsday_stats - - if frame_DOOM then - frame_DOOM.destroy() - end - end -end - --- ON GUI CLICK AND OTHERS -local function on_gui_click(event) - local gui = event.element - local player = game.players[event.player_index] - if not (player and player.valid and gui and gui.valid) then - return - end - - if gui.name == "doomsday_stats_button" then - toggle_frame_DOOM(player) - end - if gui.name == "PDNC_stats_button" then - toggle_frame_PDNC(player) - end -end - -local function on_player_created(event) - local player = game.players[event.player_index] - if not (player and player.valid) then - return - end - - update_buttons(event) - toggle_frame_counter(player) -end - -local function gui_update_all() - for _, player in pairs(game.players) do - if player and player.valid then - gui_update_DOOM(player) - gui_update_PDNC(player) - gui_update_counter(player) - end - end -end - -local function on_gui_tick(event) - gui_update_all() -end - -local doomsdaygui_init = {} -local script_events = { - --place the here what you would normaly use Event.register for - -- Event.register(defines.events.on_player_created, testfunction) - -- is the same as - -- [defines.events.on_player_created] = testfunction, - -- where testfunction is | local functuin testfunction() { } - --[Event] = function, - --put stuff here - [defines.events.on_gui_click] = on_gui_click, - [defines.events.on_player_created] = on_player_created, - [defines.events.on_player_promoted] = update_buttons, - [defines.events.on_player_demoted] = update_buttons, -} - -doomsdaygui_init.on_nth_ticks = { - --place the here what you would normaly use - --[tick] = function, - --put stuff here - [1] = on_gui_tick, -} - -doomsdaygui_init.on_init = function() -- this runs when Event.core_events.init - log("doomsdaygui init") - --put stuff here - - global.doomsdaygui_data = global.doomsdaygui_data or script_data -- NO TOUCHY - -end - -doomsdaygui_init.on_load = function() -- this runs when Event.core_events.load - log("doomsdaygui load") - --put stuff here - - script_data = global.doomsdaygui_data or script_data -- NO TOUCHY -end - -doomsdaygui_init.get_events = function() - return script_events -end - -return doomsdaygui_init \ No newline at end of file diff --git a/scenarios/doomsday/pdnc.lua b/scenarios/doomsday/pdnc.lua deleted file mode 100644 index d37b19fa..00000000 --- a/scenarios/doomsday/pdnc.lua +++ /dev/null @@ -1,309 +0,0 @@ --- Third itteration of programmable day-night cycle for Factorio --- Developed by Zr4g0n with help --- Features needed: --- Set 'maximum brightness' from rocket launches cluster wide --- Set 'time until doomsday' to any time, in minutes. --- Set 'evolution target' to any number [0.0, 1.0] --- Changing day-night cycle based on days --- Handle 'next time' elegantly - --- lamps enable darkness: [0.595 - 0.425] scaled to [0.0 - 0.85] range from [0.0 - 1.0] range -global.pdnc = global.pdnc or {} -global.pdnc_enabled = true -global.pdnc_stepsize = 53 -- also used for script.on_nth_tick. Cannot be changed at runtime! -global.pdnc_surface = 1 -global.pdnc_current_time = 0 -global.pdnc_current_point = {x = 0, y = 1.0} -global.pdnc_last_point = {x = -1, y = 0.0} -global.pdnc_max_brightness = 0.5 -- for clusterio -global.pdnc_debug = false -global.pdnc_enable_brightness_limit = false -global.pdnc_enable_rocket_darkness = false -global.pdnc_rockets_launched = 0 -global.pdnc_rockets_launched_step_size = 0.025 -global.pdnc_rockets_launched_smooth = 0 -global.pdnc_min_per_day = 15.0 - -function pdnc_setup() - --game.surfaces[global.pdnc_surface].ticks_per_day = pdnc_min_to_ticks(10.0) - doomsday_setup() -end - --- Returns true if the player is an admin -function check_admin(ctx) - local player = game.players[ctx.player_index] - if not player.admin then - player.print("Only admins can use /"..ctx.name) - return false - end - return true -end - -function pdnc_toggle_debug(ctx) - if not check_admin(ctx) then return end - global.pdnc_debug = not global.pdnc_debug - pdnc_print_status(ctx) -end - -function pdnc_toggle(ctx) - if not check_admin(ctx) then return end - global.pdnc_enabled = not global.pdnc_enabled - pdnc_print_status(ctx) -end - -function pdnc_print_status(ctx) - local player = game.players[ctx.player_index] - if(global.pdnc_enabled)then - player.print("PDNC is enabled") - else - player.print("PDNC is disabled") - end - - if(global.pdnc_debug)then - player.print("PDNC debug is enabled") - pdnc_extended_status() - else - player.print("PDNC debug is disabled") - end -end - -function pdnc_extended_status() - stats = { - "global.pdnc_stepsize: " .. global.pdnc_stepsize, - "global.pdnc_surface: " .. global.pdnc_surface, - "global.pdnc_current_time: " .. global.pdnc_current_time, - "global.pdnc_max_brightness: " .. global.pdnc_max_brightness, - "global.pdnc_enable_brightness_limit: " .. pdnc_bool_to_string(global.pdnc_enable_brightness_limit), - "global.pdnc_enable_rocket_darkness: " .. pdnc_bool_to_string(global.pdnc_enable_rocket_darkness), - "global.pdnc_rockets_launched: " .. global.pdnc_rockets_launched, - "global.pdnc_rockets_launched_step_size: " .. global.pdnc_rockets_launched_step_size, - "global.pdnc_rockets_launched_smooth: " .. global.pdnc_rockets_launched_smooth, - "ticks per day: " .. game.surfaces[global.pdnc_surface].ticks_per_day, - "current tick: " .. game.tick, - } - return stats -end - -function pdnc_bool_to_string(b) - if(b)then - return "true" - else - return "false" - end -end - -function pdnc_core() - if(global.pdnc_enabled)then - doomsday_core() - local current_surface = game.surfaces[global.pdnc_surface] - pdnc_freeze_check(current_surface) - current_surface.ticks_per_day = pdnc_min_to_ticks(global.pdnc_min_per_day) -- move this somewhere else; doesn't need to run every nth tick! - global.pdnc_current_time = game.tick / current_surface.ticks_per_day - - -- get current Y coordinate. X = 0 always. - local current_point = {x = global.pdnc_current_time, y = pdnc_program(global.pdnc_current_time)} - -- get next Y coordinate, X = 'step size' - local next_point = {x = (global.pdnc_current_time + (global.pdnc_stepsize/current_surface.ticks_per_day)), y = pdnc_program(global.pdnc_current_time + (global.pdnc_stepsize/current_surface.ticks_per_day))} - - local top_point = pdnc_intersection_top(current_point, next_point) - local bot_point = pdnc_intersection_bot(current_point, next_point) - - -- the order is dusk - evening - morning - dawn. They *must* be in that order and they cannot be equal - if(top_point < bot_point) then -- dusk -> evening - pdnc_cleanup_last_tick(current_surface) - current_surface.evening = bot_point - current_point.x - current_surface.dusk = top_point - current_point.x - elseif(top_point > bot_point) then -- morning -> dawn - pdnc_cleanup_last_tick(current_surface) - current_surface.morning = bot_point - current_point.x - current_surface.dawn = top_point - current_point.x - elseif(top_point == bot_point) then - pdnc_debug_message("PDNC: Top and bot point equal") - -- no cleanup is done here - -- if the points are equal, use last value until not equal - -- this should never be reached unless the pdnc_program() is broken. - else - pdnc_debug_message("Top and bot not different nor equal. probably a NaN error") - pdnc_debug_message("bot_point: " .. bot_point) - pdnc_debug_message("top_point: " .. top_point) - -- this should never be reached. - end - else - end -end - -function pdnc_cleanup_last_tick(current_surface) - current_surface.daytime = 0 - -- must be in this spesific order to - -- preserve the order at all times - -- dusk < evening < morning < dawn. - -- DO NOT CHANGE THE ORDER! - current_surface.dusk = -999999999999 - current_surface.dawn = 999999999999 - current_surface.evening = -999999999998 - current_surface.morning = 999999999998 -end - -function pdnc_disable_and_reset(ctx) - if not check_admin(ctx) then return end - local current_surface = game.surfaces[global.pdnc_surface] - pdnc_cleanup_last_tick(current_surface) - -- DO NOT CHANGE THIS ORDER! - current_surface.evening = 0.45 - current_surface.morning = 0.55 - current_surface.dusk = 0.25 - current_surface.dawn = 0.75 - current_surface.ticks_per_day = 25000 - global.pdnc_enabled = false - pdnc_debug_message("PDNC Programable Day-Night Cycle disabled, normal day-night cycle enabled") -end - -function pdnc_freeze_check(current_surface) - if(current_surface.freeze_daytime)then - current_surface.freeze_daytime = false - game.print("Can't use freeze_daytime while programmable day-night cycle is active; time has been unfrozen") - end -end - -function pdnc_program(x) - return pdnc_scaler(pdnc_c_boxy(x*6.28318530717958647692)) -- that's Tau, aka 2xPi -end - -function pdnc_c_boxy(x) - return pdnc_normalize((math.sin(x) + (0.111 * math.sin(3 * x))) * 1.124859392575928) - -- magic numbers to make it scale to (-1, 1) -end - -function pdnc_normalize(n) - return (n + 1)/2 -end - -function pdnc_scaler(r) -- a bit messy, but simplifies a lot elsewhere - if(pdnc_check_valid(r, "pdnc_scaler"))then - - local a = 1 - local b = 1 - - if(global.pdnc_enable_brightness_limit) then - a = global.pdnc_max_brightness - end - - if(global.pdnc_enable_rocket_darkness) then - b = 1 - pdnc_rocket_launch_darkness() - end - - return r * 0.85 * a * b -- 0 -> 0.85 is the 'brightness range' of factorio - end -end - -function pdnc_intersection (s1, e1, s2, e2) - local d = (s1.x - e1.x) * (s2.y - e2.y) - (s1.y - e1.y) * (s2.x - e2.x) - local a = s1.x * e1.y - s1.y * e1.x - local b = s2.x * e2.y - s2.y * e2.x - local x = (a * (s2.x - e2.x) - (s1.x - e1.x) * b) / d - --local y = (a * (s2.y - e2.y) - (s1.y - e1.y) * b) / d - return x--, y -end - -function pdnc_intersection_top (s2, e2) - local s1, e1 = {x = -999999999, y = 0.85}, {x = 999999999, y = 0.85} - return pdnc_intersection (s1, e1, s2, e2) -end - -function pdnc_intersection_bot (s2, e2) - local s1, e1 = {x = -999999999, y = 0.0}, {x = 999999999, y = 0.0} - return pdnc_intersection (s1, e1, s2, e2) -end - -function pdnc_set_max_brightness(n) - if(pdnc_check_valid(n, "pdnc_set_max_brightness")) then - global.pdnc_max_brightness = n - pdnc_debug_message("global.pdnc_max_brightness set to " .. global.pdnc_max_brightness) - end -end - -function pdnc_min_to_ticks(m) - return 60*60*m -end - -function pdnc_rocket_launch_counter() - global.pdnc_rockets_launched = 1 + global.pdnc_rockets_launched -end - -function pdnc_rocket_launch_darkness() - if (global.pdnc_rockets_launched_smooth < global.pdnc_rockets_launched)then - global.pdnc_rockets_launched_smooth = global.pdnc_rockets_launched_step_size + global.pdnc_rockets_launched_smooth - end - return (1 - (50/(global.pdnc_rockets_launched_smooth+50))) -end - -function pdnc_check_valid(n, s) - if (n == nil) then - pdnc_debug_message(s .. " set to nil! Set to 1.0 instead") - return false - elseif (n < 0) then - pdnc_debug_message(s .. " cannot be " .. n .. " limited to 0.0 instead") - return false - elseif (n > 1) then - pdnc_debug_message(s .. " cannot be " .. n .. " limited to 1.0 instead") - return false - elseif (n ~= n) then - pdnc_debug_message(s .. " cannot be " .. n .. " since it's not a valid number!") - else return true - end -end - -function pdnc_debug_message(s) - if(global.pdnc_debug) then - game.print(s) - end -end - - -local PDNC_init = {} - -local script_events = { - --place the here what you would normaly use Event.register for - -- Event.register(defines.events.on_player_created, testfunction) - -- is the same as - -- [defines.events.on_player_created] = testfunction, - -- where testfunction is | local functuin testfunction() { } - --[Event] = function, - --put stuff here - -} - -PDNC_init.on_nth_ticks = { - --place the here what you would normaly use - --[tick] = function, - --put stuff here - [global.pdnc_stepsize] = pdnc_core, -} - -PDNC_init.add_commands = function() - commands.add_command("pdnc", "gives PDNC's status", pdnc_print_status) - commands.add_command("pdnc_toggle", "toggles pdnc", pdnc_toggle) - commands.add_command("pdnc_toggle_debug", "toggles pdnc debug mode", pdnc_toggle_debug) - commands.add_command("pdnc_disable_and_reset", "Disabled pdnc and resets the dnc to the vanilla default", pdnc_disable_and_reset) -end - -PDNC_init.on_init = function() -- this runs when Event.core_events.init - log("PDNC init") - --put stuff here - global.PDNC_data = global.PDNC_data or script_data -- NO TOUCHY - -end - -PDNC_init.on_load = function() -- this runs when Event.core_events.load - log("PDNC load") - - --put stuff here - - script_data = global.PDNC_data or script_data -- NO TOUCHY -end - -PDNC_init.get_events = function() - return script_events -end - -return PDNC_init From 5fd3a6b188c8c8bd4b0b537bba4c12533ec6dc66 Mon Sep 17 00:00:00 2001 From: Sander Homan Date: Tue, 30 Jul 2019 14:03:56 +0200 Subject: [PATCH 6/7] Switch to rcon-client git dep with dep build output in it --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 307c4ef8..2a8e1cff 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "node-factorio-api": "^0.3.1-alpha", "node-forge": "^0.7.1", "prom-client": "^10.2.3", - "rcon-client": "git+https://gitlab.com/Hornwitser/rcon-client.git", + "rcon-client": "git+https://gitlab.com/Zerot/rcon-client.git", "request": "^2.83.0", "right-pad": "^1.0.1", "rmdir-sync": "^1.0.1", From a13d4c680557e75704e6d0328c9be4187d5e00fe Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 30 Jul 2019 15:28:43 +0200 Subject: [PATCH 7/7] Use published version of rcon-client-fork (#188) Switch to a version of rcon-client-fork that's published on npm. Avoids having to put build files in the git repo. --- client.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client.js b/client.js index 9f4427b6..56b970b8 100644 --- a/client.js +++ b/client.js @@ -6,7 +6,7 @@ const path = require('path'); const syncRequest = require('sync-request'); const request = require("request"); const ncp = require('ncp').ncp; -const Rcon = require('rcon-client').Rcon; +const Rcon = require('rcon-client-fork').Rcon; const hashFiles = require('hash-files'); const _ = require('underscore'); const deepmerge = require("deepmerge"); diff --git a/package.json b/package.json index 2a8e1cff..b900e060 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "node-factorio-api": "^0.3.1-alpha", "node-forge": "^0.7.1", "prom-client": "^10.2.3", - "rcon-client": "git+https://gitlab.com/Zerot/rcon-client.git", + "rcon-client-fork": "^3.2.0", "request": "^2.83.0", "right-pad": "^1.0.1", "rmdir-sync": "^1.0.1",