From d19a800303c63e2ff43d915938d60212c0164f06 Mon Sep 17 00:00:00 2001 From: jodokus31 <33641866+jodokus31@users.noreply.github.com> Date: Sat, 14 Jan 2023 00:40:21 +0100 Subject: [PATCH 1/7] Only deconstruct, if item fits into inventory Fix nil access in on_runtime_mod_setting_changed --- changelog.txt | 7 +++++++ control.lua | 39 +++++++++++++++++++++++++++++++++++---- info.json | 2 +- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/changelog.txt b/changelog.txt index 672ba72..009b089 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,11 @@ --------------------------------------------------------------------------------------------------- +Version: 0.5.4 +Date: 2023-01-13 + Bugfixes: + - Fix that on_runtime_mod_setting_changed can be called with event.player_index == nil + Changes: + - Only deconstruct (mining) entity or tile, if the item fits into players inventory. +--------------------------------------------------------------------------------------------------- Version: 0.5.3 Date: 2022-10-30 Bugfixes: diff --git a/control.lua b/control.lua index fc3ea76..6366a59 100644 --- a/control.lua +++ b/control.lua @@ -360,6 +360,25 @@ local function try_upgrade(entity, player, state) end end +local function can_insert_into_players_inventory(player, entity) + local can_insert = false + if entity.prototype and entity.prototype.mineable_properties and entity.prototype.mineable_properties.minable then + can_insert = true + if entity.prototype.mineable_properties.products then + for i, p in pairs(entity.prototype.mineable_properties.products) do + if p.type == "item" and p.amount then + if not player.can_insert {name=p.name, count=math.floor(p.amount)} then + can_insert = false + break + end + end + end + end + end + return can_insert +end + + local function try_deconstruct_tile(entity, player, state) if not force_match(entity, player, true) then return false @@ -367,7 +386,10 @@ local function try_deconstruct_tile(entity, player, state) if entity.to_be_deconstructed(player.force.name) then local position = entity.position - return player.mine_tile(entity.surface.get_tile(position.x, position.y)) + local tile = entity.surface.get_tile(position.x, position.y) + if can_insert_into_players_inventory(player, tile) then + return player.mine_tile(tile) + end end return false end @@ -376,7 +398,10 @@ local function try_deconstruct_entity(entity, player, state) if not force_match(entity, player, true) then return false end - return player.mine_entity(entity) + + if can_insert_into_players_inventory(player, entity) then + return player.mine_entity(entity, false) + end end local build_actions = @@ -589,8 +614,6 @@ end script.on_nth_tick(cycle_length_in_ticks, update_cycle) script.on_event(defines.events.on_runtime_mod_setting_changed, function(event) - local state = get_player_state(event.player_index) - if event.setting == "autobuild-cycle-length-in-ticks" then --unregister with old value script.on_nth_tick(cycle_length_in_ticks, nil) @@ -602,16 +625,24 @@ script.on_event(defines.events.on_runtime_mod_setting_changed, function(event) HelpFunctions.log_level = settings.global[event.setting].value elseif event.setting == "autobuild-actions-per-cycle" then + local state = get_player_state(event.player_index) state.actions_per_cycle = settings.get_player_settings(event.player_index)[event.setting].value + elseif event.setting == "autobuild-idle-cycles-before-recheck" then + local state = get_player_state(event.player_index) state.idle_cycles_before_recheck = settings.get_player_settings(event.player_index)[event.setting].value + elseif event.setting == "autobuild-visual-area-opacity" or event.setting == "autobuild-enable-visual-area" then + local state = get_player_state(event.player_index) state.enable_visual_area = settings.get_player_settings(event.player_index)["autobuild-enable-visual-area"].value state.visual_area_opacity = settings.get_player_settings(event.player_index)["autobuild-visual-area-opacity"].value local player = game.players[event.player_index] change_visual_area(player, state, state.visual_area_opacity) + elseif event.setting == "autobuild-ignore-other-robots" then + local state = get_player_state(event.player_index) state.ignore_other_robots = settings.get_player_settings(event.player_index)[event.setting].value + end end) \ No newline at end of file diff --git a/info.json b/info.json index 1bb8588..afbc9ba 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "autobuild", - "version": "0.5.3", + "version": "0.5.4", "factorio_version": "1.1", "title": "Autobuild", "author": "Therax", From 46b3538d23715c7bf57f2196bf4cd1c298b34a38 Mon Sep 17 00:00:00 2001 From: Factorio Mods Helper Date: Tue, 24 Jan 2023 20:31:46 +0000 Subject: [PATCH 2/7] Update translations from Crowdin --- locale/de/autobuild.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/locale/de/autobuild.cfg b/locale/de/autobuild.cfg index 4d90183..52a07dd 100644 --- a/locale/de/autobuild.cfg +++ b/locale/de/autobuild.cfg @@ -20,6 +20,7 @@ autobuild-log-level=Debug-Log-Level autobuild-actions-per-cycle=Bauvorgänge pro Zyklus autobuild-idle-cycles-before-recheck=Leerlauf-Überprüfungs Zyklen autobuild-visual-area-opacity=Deckkraft des visuellen Bereiches +autobuild-ignore-other-robots=Andere Roboter ignorieren und alles bauen [mod-setting-description] autobuild-cycle-length-in-ticks=Wie viele Ticks sind ein Bauzyklus. Erhöht die Anzahl der Konstruktionsaktionen. Könnte die Performance verschlechtern, wenn zu niedrig @@ -27,6 +28,7 @@ autobuild-log-level=Debug Log Level (0 nichts, 5 alles, oder werte dazwischen) autobuild-actions-per-cycle=Wie viele Bauvorgänge werden in einem Zyklus durchgeführt. Erhöht die Anzahl der Gesamtbau-Aktionen. Kann Performance verschlechtern, wenn zu hoch autobuild-idle-cycles-before-recheck=Anzahl der Zyklen, bis die Baubewerber neu berechnet werden, z. B. nach einer Konstruktionspause (5 Sek. ohne Bau), benötigt es max. diese Anzahl an Zyklen, um die Konstruktion fortzusetzen. Könnte unproduktive Performance verschlechtern, wenn zu niedrig +autobuild-enable-visual-area=Visuellen Baubereich aktivieren. Deaktivieren um den visuellen Baubereich zu verbergen autobuild-visual-area-opacity=Deckkraft des visuellen Bereiches From 5376822aba095a2f47a5821b9be9be7dc88955e0 Mon Sep 17 00:00:00 2001 From: Factorio Mods Helper Date: Sat, 11 Feb 2023 22:28:57 +0000 Subject: [PATCH 3/7] Update translations from Crowdin --- locale/uk/autobuild.cfg | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 locale/uk/autobuild.cfg diff --git a/locale/uk/autobuild.cfg b/locale/uk/autobuild.cfg new file mode 100644 index 0000000..9b1881a --- /dev/null +++ b/locale/uk/autobuild.cfg @@ -0,0 +1,36 @@ +[controls] +autobuild-custominput-toggle-construction=Увімкнути автоматичну побудову +autobuild-custominput-toggle-tiles=Увімкнути автоматичну побудову плиток + +[autobuild-shortcut] +autobuild-shortcut-toggle-construction=Увімкнути автоматичну побудову + +[autobuild-message] +construction-enabled=Автоматичну побудову увімкнено. +construction-disabled=Автоматичне будівництво відключено. +deconstruction-enabled=Увімкнено автоматичну деконструкцію. +deconstruction-disabled=Автоматичну деконструкцію вимкнено. +tiles-enabled=Увімкнено автоматичну побудову плиток. +tiles-disabled=Автоматичну побудову тайлів вимкнено. + +[mod-setting-name] +autobuild-cycle-length-in-ticks=Тривалість циклу побудови в тиках +autobuild-log-level=Рівень журналу налагодження + +autobuild-actions-per-cycle=Побудова дій за цикл +autobuild-idle-cycles-before-recheck=Холості цикли повторних перевірок +autobuild-enable-visual-area=Увімкнути візуальну область будівлі +autobuild-visual-area-opacity=Непрозорість візуальної області +autobuild-ignore-other-robots=Ігнорувати інших роботів і будувати все + +[mod-setting-description] +autobuild-cycle-length-in-ticks=Скільки тиків становить один цикл побудови. Збільшує кількість загальних будівельних дій. Може знизити продуктивність, якщо занадто низький +autobuild-log-level=Рівень журналу налагодження (0 - нічого, 5 - все, або проміжні значення) + +autobuild-actions-per-cycle=Скільки будівельних дій виконується за один цикл. Збільшує загальну кількість будівельних дій. Може знижувати продуктивність, якщо занадто велике значення +autobuild-idle-cycles-before-recheck=Кількість циклів до повторної перевірки кандидатів на збірку. наприклад, після паузи у збірці (5 секунд без збірки), потрібно максимум стільки циклів, щоб відновити збірку. Може знизити продуктивність на холостому ходу, якщо занадто низька +autobuild-enable-visual-area=Увімкнути візуальну зону забудови. Зніміть прапорець, щоб приховати візуальну область будівлі +autobuild-visual-area-opacity=Непрозорість візуальної області +autobuild-ignore-other-robots=Не поважайте завдання, вже призначені іншим роботам, і все одно будуйте/зруйнуйте/модернізуйте. + + From 2fc49ad9a587037c0dac298760ff7d912cd9c6c8 Mon Sep 17 00:00:00 2001 From: Factorio Mods Helper Date: Sat, 4 Mar 2023 22:29:28 +0000 Subject: [PATCH 4/7] Update translations from Crowdin --- locale/ru/autobuild.cfg | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/locale/ru/autobuild.cfg b/locale/ru/autobuild.cfg index a9f3e0e..e65942d 100644 --- a/locale/ru/autobuild.cfg +++ b/locale/ru/autobuild.cfg @@ -1,16 +1,36 @@ [controls] autobuild-custominput-toggle-construction=Переключить автоматическое конструирование +autobuild-custominput-toggle-tiles=Переключить автоматическую постройку плит [autobuild-shortcut] autobuild-shortcut-toggle-construction=Переключить автоматическое конструирование [autobuild-message] +construction-enabled=Автоматическое конструирование включено. +construction-disabled=Автоматическое конструирование выключено. +deconstruction-enabled=Автоматический снос включен. +deconstruction-disabled=Автоматический снос выключен. +tiles-enabled=Автоматическая постройка плит включена. +tiles-disabled=Автоматическая постройка плит выключена. [mod-setting-name] +autobuild-cycle-length-in-ticks=Длина цикла постройки в тиках autobuild-log-level=Уровень отладочного журнала +autobuild-actions-per-cycle=Действий стройки за цикл +autobuild-idle-cycles-before-recheck=Циклы перепроверки в режиме ожидания +autobuild-enable-visual-area=Включить визуальную область постройки +autobuild-visual-area-opacity=Прозрачность визуальной области +autobuild-ignore-other-robots=Игнорировать других роботов и строить всё [mod-setting-description] - +autobuild-cycle-length-in-ticks=Сколько тиков длится один цикл постройки. Увеличивает количество общих действий постройки. Может снизить производительность, если слишком мало +autobuild-log-level=Уровень отладочного журнала (0 - ничего, 5 - всё, или значения между) + +autobuild-actions-per-cycle=Сколько действий постройки выполняется за один цикл. Увеличивает количество общих действий постройки. Может снизить производительность, если слишком высоко +autobuild-idle-cycles-before-recheck=Количество циклов до перепроверки кандидатов на постройку. Например, после паузы строительства (5 сек. без постройки) принимает максимум. Это количество циклов для возобновления строительства. Может снизить производительность, если слишком мало +autobuild-enable-visual-area=Включить визуальную область постройки. Выключите, чтобы скрыть визуальную область постройки +autobuild-visual-area-opacity=Прозрачность визуальной области +autobuild-ignore-other-robots=Игнорировать задачи, уже назначенные на других роботов, и строить/сносить/улучшать в любом случае. From 713045abeca2620ebfe8fce3220e011c8b580234 Mon Sep 17 00:00:00 2001 From: jodokus31 <33641866+jodokus31@users.noreply.github.com> Date: Fri, 21 Apr 2023 15:31:49 +0200 Subject: [PATCH 5/7] Support jetpack mod --- changelog.txt | 5 +++++ control.lua | 32 ++++++++++++++++++++++++++++++++ info.json | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 009b089..6184ba4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.5.5 +Date: 2023-04-21 + Changes: + - Support Jetpack mod, that the visual construction area doesn't get cleared on jetpack de/-activation +--------------------------------------------------------------------------------------------------- Version: 0.5.4 Date: 2023-01-13 Bugfixes: diff --git a/control.lua b/control.lua index 6366a59..df307a0 100644 --- a/control.lua +++ b/control.lua @@ -32,6 +32,11 @@ local function change_visual_area(player, state, opacity) state.visual_area_id = nil end + -- player.print("enable_visual_area ".. (state.enable_visual_area and "true" or "false")) + -- player.print("opacity ".. (opacity or "nil")) + -- player.print("player.character "..serpent.block(player.character)) + -- player.print("build_distance "..(state.build_distance or "nil")) + if not state.enable_visual_area then return end if not opacity or opacity <= 0 then return end if not player.character then return end @@ -52,6 +57,33 @@ local function change_visual_area(player, state, opacity) }) end +-- on_character_swapped_event +-- params: event +-- new_unit_number +-- old_unit_number +-- new_character +-- old_character +function on_character_swapped_event(event) + -- attach visual area to the new character + local player = event and event.new_character and event.new_character.player + if not player then return end + if not player.index then return end + + local state = get_player_state(player.index) + if not state.visual_area_id then return end + if not state.build_distance then return end + + local radius = state.build_distance + 0.5 + local target = rendering.get_left_top(state.visual_area_id) + if target and target.entity and target.entity.unit_number == event.old_unit_number then + rendering.set_corners(state.visual_area_id, + event.new_character, { -radius, -radius }, + event.new_character, { radius, radius }) + end +end + +remote.add_interface("autobuild", { on_character_swapped = on_character_swapped_event } ) + local function on_load() player_state = global.player_state end diff --git a/info.json b/info.json index afbc9ba..5bb2b19 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "autobuild", - "version": "0.5.4", + "version": "0.5.5", "factorio_version": "1.1", "title": "Autobuild", "author": "Therax", From d981002050492e62628069732cb72522bb04a410 Mon Sep 17 00:00:00 2001 From: jodokus31 <33641866+jodokus31@users.noreply.github.com> Date: Tue, 30 May 2023 18:37:50 +0200 Subject: [PATCH 6/7] Add setting to allow to build while in combat --- changelog.txt | 5 +++++ control.lua | 11 ++++++++++- info.json | 2 +- locale/de/autobuild.cfg | 7 +++++++ locale/en/autobuild.cfg | 2 ++ settings.lua | 9 +++++++++ 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index 6184ba4..714664f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.5.6 +Date: 2023-05-30 + Changes: + - Add setting to allow Autobuild to keep building, even when in combat +--------------------------------------------------------------------------------------------------- Version: 0.5.5 Date: 2023-04-21 Changes: diff --git a/control.lua b/control.lua index df307a0..e78141b 100644 --- a/control.lua +++ b/control.lua @@ -18,6 +18,8 @@ local function get_player_state(player_index) state.enable_visual_area = settings.get_player_settings(player_index)["autobuild-enable-visual-area"].value state.visual_area_opacity = settings.get_player_settings(player_index)["autobuild-visual-area-opacity"].value state.ignore_other_robots = settings.get_player_settings(player_index)["autobuild-ignore-other-robots"].value + state.build_while_in_combat = settings.get_player_settings(player_index)["autobuild-build-while-in-combat"].value + state.last_successful_build_tick = 0 player_state[player_index] = state @@ -615,7 +617,10 @@ local function handle_player_update(player) return end - if player.in_combat then return end + if not state.build_while_in_combat and player.in_combat then + -- don't build while in combat only when setting is enabled + return + end if needs_recheck(player, state) then -- player has moved @@ -674,6 +679,10 @@ script.on_event(defines.events.on_runtime_mod_setting_changed, function(event) elseif event.setting == "autobuild-ignore-other-robots" then local state = get_player_state(event.player_index) state.ignore_other_robots = settings.get_player_settings(event.player_index)[event.setting].value + + elseif event.setting == "autobuild-build-while-in-combat" then + local state = get_player_state(event.player_index) + state.build_while_in_combat = settings.get_player_settings(event.player_index)[event.setting].value end diff --git a/info.json b/info.json index 5bb2b19..6bae110 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "autobuild", - "version": "0.5.5", + "version": "0.5.6", "factorio_version": "1.1", "title": "Autobuild", "author": "Therax", diff --git a/locale/de/autobuild.cfg b/locale/de/autobuild.cfg index 4d90183..2e6150f 100644 --- a/locale/de/autobuild.cfg +++ b/locale/de/autobuild.cfg @@ -13,13 +13,17 @@ deconstruction-disabled=Automatische Dekonstruktion deaktiviert. tiles-enabled=Automatisches Konstruieren von Kacheln aktiviert. tiles-disabled=Automatisches Konstruieren von Kacheln deaktiviert. + [mod-setting-name] autobuild-cycle-length-in-ticks=Bauzykluslänge in Ticks autobuild-log-level=Debug-Log-Level autobuild-actions-per-cycle=Bauvorgänge pro Zyklus autobuild-idle-cycles-before-recheck=Leerlauf-Überprüfungs Zyklen +autobuild-enable-visual-area=Aktiviere den visuellen Bereich autobuild-visual-area-opacity=Deckkraft des visuellen Bereiches +autobuild-ignore-other-robots=Ignoriere andere Bots und baue alles selbst +autobuild-build-while-in-combat=Baue weiter trotz Kampfhandlungen [mod-setting-description] autobuild-cycle-length-in-ticks=Wie viele Ticks sind ein Bauzyklus. Erhöht die Anzahl der Konstruktionsaktionen. Könnte die Performance verschlechtern, wenn zu niedrig @@ -27,6 +31,9 @@ autobuild-log-level=Debug Log Level (0 nichts, 5 alles, oder werte dazwischen) autobuild-actions-per-cycle=Wie viele Bauvorgänge werden in einem Zyklus durchgeführt. Erhöht die Anzahl der Gesamtbau-Aktionen. Kann Performance verschlechtern, wenn zu hoch autobuild-idle-cycles-before-recheck=Anzahl der Zyklen, bis die Baubewerber neu berechnet werden, z. B. nach einer Konstruktionspause (5 Sek. ohne Bau), benötigt es max. diese Anzahl an Zyklen, um die Konstruktion fortzusetzen. Könnte unproduktive Performance verschlechtern, wenn zu niedrig +autobuild-enable-visual-area=Aktiviere den visuellen Bereich. Enable Visual building area. Den Haken rausnehmen, um den visuellen Bereich zu verstecken. autobuild-visual-area-opacity=Deckkraft des visuellen Bereiches +autobuild-ignore-other-robots=Respektiert nicht, dass Tasks einem Bot aus dem Netzwerk zugewiesen sind und baue trotzdem. +autobuild-build-while-in-combat=Aktiviere, wenn während Kampfhandlungen weiter gebaut werden soll. Anscheinend ist man auch im Kampfmodus, wenn man die Grapping Gun von SE verwendet hat. diff --git a/locale/en/autobuild.cfg b/locale/en/autobuild.cfg index b2a796e..90cf270 100644 --- a/locale/en/autobuild.cfg +++ b/locale/en/autobuild.cfg @@ -22,6 +22,7 @@ autobuild-idle-cycles-before-recheck=Idle recheck cycles autobuild-enable-visual-area=Enable Visual building area autobuild-visual-area-opacity=Visual area opacity autobuild-ignore-other-robots=Ignore other robots and build everything +autobuild-build-while-in-combat=Keep building while in combat [mod-setting-description] autobuild-cycle-length-in-ticks=How many ticks is one building cycle. Increases amount of overall building actions. Might tank performance, if too low @@ -32,3 +33,4 @@ autobuild-idle-cycles-before-recheck=Amount of cycles until building candidates autobuild-enable-visual-area=Enable Visual building area. Uncheck to hide visual building area autobuild-visual-area-opacity=Visual area opacity autobuild-ignore-other-robots=Do not respect tasks already assigned to other robots and build/deconstruct/upgrade anyway. +autobuild-build-while-in-combat=Enable, when you want to keep building, while in combat. Obviously, using the grappling gun from SE also counts as being in combat diff --git a/settings.lua b/settings.lua index 6e45833..a8f8a7a 100644 --- a/settings.lua +++ b/settings.lua @@ -63,6 +63,15 @@ table.insert(settings, default_value = false, }) +table.insert(settings, + { + type = "bool-setting", + name = "autobuild-build-while-in-combat", + order = "eb", + setting_type = "runtime-per-user", + default_value = false, + }) + table.insert(settings, { type = "int-setting", From 80d929888e3918d5830730c977025ce65d75afa8 Mon Sep 17 00:00:00 2001 From: jodokus31 <33641866+jodokus31@users.noreply.github.com> Date: Tue, 30 May 2023 19:17:50 +0200 Subject: [PATCH 7/7] Fix single tile loaders upgrade with belts --- changelog.txt | 2 ++ control.lua | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index 714664f..f6251c8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,8 @@ Version: 0.5.6 Date: 2023-05-30 Changes: - Add setting to allow Autobuild to keep building, even when in combat + Bugfixes: + - Fix that belts can be upgraded with a single tile loaders or vice versa --------------------------------------------------------------------------------------------------- Version: 0.5.5 Date: 2023-04-21 diff --git a/control.lua b/control.lua index e78141b..3453c90 100644 --- a/control.lua +++ b/control.lua @@ -327,7 +327,7 @@ local function try_upgrade_with_stack(entity, target_name, player, stack_to_plac return false end - local entity = entity.surface.create_entity{ + local new_entity = entity.surface.create_entity{ name = target_name, position = entity.position, direction = entity.direction, @@ -335,13 +335,16 @@ local function try_upgrade_with_stack(entity, target_name, player, stack_to_plac fast_replace = true, player = player, type = entity.type:find("loader") and entity.loader_type or - entity.type == "underground-belt" and entity.belt_to_ground_type, + entity.type == "underground-belt" and entity.belt_to_ground_type or + nil, raise_built = true, } - if entity then + + if new_entity then player.remove_item(stack_to_place) return true end + return false end