From be16ba2e1f1f72c91360d712a9ab8bc9b7d9b401 Mon Sep 17 00:00:00 2001 From: Daniel Meltzer Date: Fri, 10 Jan 2025 16:02:31 -0800 Subject: [PATCH] Add a new condition to caravans that allows comparing a circuit to a static value --- changelog.txt | 1 + locale/en/caravan.cfg | 1 + scripts/caravan/caravan-gui.lua | 14 +++++++++++++- scripts/caravan/caravan-prototypes.lua | 19 +++++++++++++++++-- scripts/caravan/caravan.lua | 11 +++++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index 7b3efc3cd..64e34dcce 100644 --- a/changelog.txt +++ b/changelog.txt @@ -8,6 +8,7 @@ Date: 2025-1-2 - All caravans can use all caravan outpost types - Added a bhoddos to uranium ore phytomining recipe - Xeno raising recipes 1-4 are now properly assigned to the corresponding technologies + - Caravans now can compare a circuit condition to a static value. TURD: - Composter TURD path 2 no longer generates methanol. Now it instead generates coalbed gas. Resolves https://github.com/pyanodon/pybugreports/issues/757 - Redid bioreactor TURD entirely. diff --git a/locale/en/caravan.cfg b/locale/en/caravan.cfg index eb77d3749..af1005598 100644 --- a/locale/en/caravan.cfg +++ b/locale/en/caravan.cfg @@ -47,6 +47,7 @@ item-count=Until caravan has exactly N items inverse-item-count=Until target has exactly N items detonate=Detonate circuit-condition=Circuit condition +circuit-condition-static=Circuit condition with static value empty-autotrash=Collect all autotrash traveling=Traveling diff --git a/scripts/caravan/caravan-gui.lua b/scripts/caravan/caravan-gui.lua index 1f574a5c6..693ed4b30 100644 --- a/scripts/caravan/caravan-gui.lua +++ b/scripts/caravan/caravan-gui.lua @@ -95,9 +95,21 @@ function Caravan.build_schedule_gui(gui, caravan_data) action_frame.add {type = "label", caption = "="} local circuit_condition_left = action_frame.add { type = "choose-elem-button", name = "py_circuit_condition_left", style = "train_schedule_item_select_button", - tags = tags, elem_type = "signal" + tags = tags, elem_type = "signal" } circuit_condition_left.elem_value = action.circuit_condition_left + elseif action.type == "circuit-condition-static" then + action_frame.add {type = "empty-widget", style = "py_empty_widget"} + local circuit_condition_right = action_frame.add { + type = "choose-elem-button", name = "py_circuit_condition_right", style = "train_schedule_item_select_button", + tags = tags, elem_type = "signal" + } + circuit_condition_right.elem_value = action.circuit_condition_right + action_frame.add {type = "label", caption = "="} + local value = action_frame.add {type = "textfield", name = "py_value_condition_left", style = "py_compact_slider_value_textfield", tags = tags, text = action.circuit_condition_left} + value.numeric = true + value.allow_decimal = false + value.allow_negative = true else action_frame.add {type = "empty-widget", style = "py_empty_widget"} end diff --git a/scripts/caravan/caravan-prototypes.lua b/scripts/caravan/caravan-prototypes.lua index 376ea94de..402b36c1c 100644 --- a/scripts/caravan/caravan-prototypes.lua +++ b/scripts/caravan/caravan-prototypes.lua @@ -6,7 +6,8 @@ local caravan_actions = { "empty-inventory", "item-count", "inverse-item-count", - "circuit-condition" + "circuit-condition", + "circuit-condition-static" }, ["character"] = { "time-passed", @@ -48,7 +49,8 @@ local caravan_actions = { }, ["electric-pole"] = { "time-passed", - "circuit-condition" + "circuit-condition", + "circuit-condition-static" }, ["default"] = { "time-passed" @@ -340,7 +342,20 @@ Caravan.actions = { if not right or not left then return false end return evaluate_signal(outpost, right) == evaluate_signal(outpost, left) + end, + + ["circuit-condition-static"] = function(caravan_data, schedule, action) + local outpost = schedule.entity + if not outpost or not outpost.valid then return true end + + local right = action.circuit_condition_right + local left = action.circuit_condition_left + if not right or not left then return false end + + return evaluate_signal(outpost, right) == left end + + } Caravan.free_actions = { -- actions that don't use fuel diff --git a/scripts/caravan/caravan.lua b/scripts/caravan/caravan.lua index e5581510c..53cb64e12 100644 --- a/scripts/caravan/caravan.lua +++ b/scripts/caravan/caravan.lua @@ -517,6 +517,17 @@ gui_events[defines.events.on_gui_elem_changed]["py_circuit_condition_left"] = fu action.circuit_condition_left = element.elem_value end +gui_events[defines.events.on_gui_text_changed]["py_value_condition_left"] = function(event) + local element = event.element + local tags = element.tags + local caravan_data = storage.caravans[tags.unit_number] + local action = caravan_data.schedule[tags.schedule_id].actions[tags.action_id] + local value = tonumber(element.text) + action.circuit_condition_left = value + +end + + gui_events[defines.events.on_gui_text_changed]["py_time_passed_text"] = function(event) local element = event.element local tags = element.tags