diff --git a/changelog.txt b/changelog.txt index da36ecb..d37b5dc 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 2.0.3 +Date: 2024-12-29 + Changes: + - Added "/bz-regenerate" command for regenerating ore patches, especially useful when adding to an existing game +--------------------------------------------------------------------------------------------------- Version: 2.0.2 Date: 2024-12-28 Changes: diff --git a/control-util.lua b/control-util.lua index 55c6b0b..344b781 100644 --- a/control-util.lua +++ b/control-util.lua @@ -2,6 +2,7 @@ local me = require("me") local util = {} util.me = me +local regenerate_command = "bz-regenerate" function decode(data) if type(data) == "string" then return data end @@ -95,6 +96,62 @@ function util.warptorio2_expansion_helper() end end +local usage = [[ +Usage: /bz-regenerate all +or /bz-regenerate [ ] + planet must be an internal name like nauvis + resource must be an internal name like lead-ore or titanium-ore + frequency, size, and richness are optional, but all or none must be provided, and each should be a number between 0.166 and 6, where 1 is default setting. +Regenerates ore patches. If frequency/size/richness are provided, the planet will use those settings from now on, as well. + - Separate arguments with spaces, do not use < >, [ ], quotes or other symbols + - This action can take a while for larger maps! + - Ores can sometimes overlap on regeneration. +]] +function util.add_regenerate_command_handler() + script.on_event(defines.events.on_console_command, regenerate_ore) + + if not commands.commands[regenerate_command] then + commands.add_command( regenerate_command, usage, function() end) + end +end + +function regenerate_ore(event) + if event.command == regenerate_command then + local params = {} + for w in event.parameters:gmatch("%S+") do table.insert(params, w) end + if #params == 1 and params[1] == "all" then + for _, resource in pairs(me.resources) do + game.print("Regenerating "..resource) + game.regenerate_entity(resource) + end + return + end + if not (#params == 2 or #params == 5) then + game.print(usage) + return + end + local planet = params[1] + for _, resource in pairs(me.resources) do + if not game.surfaces[planet] then + game.print("Could not find surface for "..planet..". May not exist, or may not yet be explored.") + return + end + if resource == params[2] then + if #params == 5 then + local settings = {frequency=params[3], size=params[4], richness=params[5]} + local map_gen_settings = game.surfaces[planet].map_gen_settings + map_gen_settings.autoplace_controls[resource] = settings + map_gen_settings.autoplace_settings.entity.settings[resource] = settings + game.surfaces[planet].map_gen_settings = map_gen_settings + game.print("Set "..resource.." on "..planet.." to "..serpent.line(settings)) + end + game.print("Regenerating "..resource) + game.surfaces[planet].regenerate_entity(resource) + end + end + end +end + function util.ore_fix() ore_fix("nauvis") if game.surfaces.tenebris then diff --git a/control.lua b/control.lua index 3382c29..938132a 100644 --- a/control.lua +++ b/control.lua @@ -1,3 +1,4 @@ local util = require("control-util") script.on_configuration_changed(util.ore_fix) +util.add_regenerate_command_handler() diff --git a/info.json b/info.json index 1becdee..c112740 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "bzlead", - "version": "2.0.2", + "version": "2.0.3", "factorio_version": "2.0", "title": "Lead", "author": "Brevven",