Skip to content

Commit

Permalink
Add a new condition to caravans that allows comparing a circuit to a …
Browse files Browse the repository at this point in the history
…static value (#292)

Co-authored-by: Daniel Meltzer <[email protected]>
  • Loading branch information
mnemonicly and Daniel Meltzer authored Jan 16, 2025
1 parent 4bbb369 commit e772ebb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions locale/en/caravan.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion scripts/caravan/caravan-gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions scripts/caravan/caravan-prototypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ local caravan_actions = {
"empty-inventory",
"item-count",
"inverse-item-count",
"circuit-condition"
"circuit-condition",
"circuit-condition-static"
},
["character"] = {
"time-passed",
Expand Down Expand Up @@ -48,7 +49,8 @@ local caravan_actions = {
},
["electric-pole"] = {
"time-passed",
"circuit-condition"
"circuit-condition",
"circuit-condition-static"
},
["default"] = {
"time-passed"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions scripts/caravan/caravan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e772ebb

Please sign in to comment.