Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Caravan circuit improvments #292

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading