diff --git a/cybersyn/scripts/factorio-api.lua b/cybersyn/scripts/factorio-api.lua index 005fbfc..bb710af 100644 --- a/cybersyn/scripts/factorio-api.lua +++ b/cybersyn/scripts/factorio-api.lua @@ -689,40 +689,8 @@ end function set_combinator_output(map_data, comb, signals) local out = map_data.to_output[comb.unit_number] if out.valid then - --out.get_or_create_control_behavior().parameters = signals - local constBehaviour = out.get_or_create_control_behavior() - - if constBehaviour.sections == nil or constBehaviour.sections_count == 0 then - constBehaviour.add_section() - end - - if constBehaviour.sections and constBehaviour.sections_count > 0 then - if constBehaviour.sections_count > 1 then - --only the default section, messy but whatever - local i = 1 - for _,v in pairs(constBehaviour.sections) do - if i ~= 1 then - constBehaviour.removeSection(i) - end - i = i + 1 - end - end - - local primarySection = constBehaviour.get_section(1) - local filters = {} - if signals ~= nil then - for _,v in pairs(signals) do - local filt = { - type = v.signal.type, - name = v.signal.name, - quality = nil, - comparator = nil - } - table.insert(filters, filt) - end - end - primarySection.filters = filters - end + -- out is a non-interactable, invisible combinator whiche means players cannot change the number of sections + out.get_or_create_control_behavior().get_section(1).filters = signals or {} end end @@ -757,7 +725,8 @@ function set_comb2(map_data, station) for item_name, count in pairs(deliveries) do local i = #signals + 1 local is_fluid = prototypes.item[item_name] == nil--NOTE: this is expensive - signals[i] = {index = i, signal = {type = is_fluid and "fluid" or "item", name = item_name}, count = sign*count} + -- FIXME: the circuit network can only carry exact qualities, so deliveries must provide each quality separately + signals[i] = {value = {type = is_fluid and "fluid" or "item", name = item_name, quality = "normal", comparator = "="}, min = sign*count} -- constant combinator cannot have quality = nil (any) end set_combinator_output(map_data, station.entity_comb2, signals) end diff --git a/cybersyn/scripts/global.lua b/cybersyn/scripts/global.lua index fd49746..4cdecbc 100644 --- a/cybersyn/scripts/global.lua +++ b/cybersyn/scripts/global.lua @@ -102,6 +102,7 @@ ---@class ManifestEntry ---@field public type string ---@field public name string +---@field public quality string ---@field public count int ---@class Economy diff --git a/cybersyn/scripts/layout.lua b/cybersyn/scripts/layout.lua index 5d44a4b..f9eab52 100644 --- a/cybersyn/scripts/layout.lua +++ b/cybersyn/scripts/layout.lua @@ -228,7 +228,8 @@ function set_p_wagon_combs(map_data, station, train) local count_to_fill = min(item_slots_capacity*stack_size, item_count) local slots_to_fill = ceil(count_to_fill/stack_size) - signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = sign*count_to_fill} + -- FIXME: quality any for now, should match the delivery + signals[i] = {value = {type = item.type, name = item.name}, min = sign*count_to_fill} item_count = item_count - count_to_fill item_slots_capacity = item_slots_capacity - slots_to_fill if comb then @@ -323,7 +324,8 @@ function set_r_wagon_combs(map_data, station, train) local stack = inv[stack_i] if stack.valid_for_read then local i = #signals + 1 - signals[i] = {index = i, signal = {type = "item", name = stack.name}, count = sign*stack.count} + -- FIXME item stacks have quality + signals[i] = {value = {type = "item", name = stack.name, quality = "normal", comparator = "="}, min = sign*stack.count} end end set_combinator_output(map_data, comb, signals) @@ -334,7 +336,8 @@ function set_r_wagon_combs(map_data, station, train) local inv = carriage.get_fluid_contents() for fluid_name, count in pairs(inv) do local i = #signals + 1 - signals[i] = {index = i, signal = {type = "fluid", name = fluid_name}, count = sign*floor(count)} + -- FIXME ? pump conditions can have quality (but why? fluids can only be produced at normal quality and pump filters ignore quality) + signals[i] = {value = {type = "fluid", name = fluid_name, quality = "normal", comparator = "="}, min = sign*floor(count)} end set_combinator_output(map_data, comb, signals) end @@ -388,10 +391,12 @@ function set_refueler_combs(map_data, refueler, train) if stack.valid_for_read then if comb then local i = #wagon_signals + 1 - wagon_signals[i] = {index = i, signal = {type = "item", name = stack.name}, count = stack.count} + -- FIXME fuel items can have quality which improves acceleration and top speed (but not fuel value) + wagon_signals[i] = {value = {type = "item", name = stack.name, quality = "normal", comparator = "="}, min = stack.count} end local j = #signals + 1 - signals[j] = {index = j, signal = {type = "item", name = stack.name}, count = stack.count} + -- FIXME fuel items can have quality which improves acceleration and top speed (but not fuel value) + signals[j] = {value = {type = "item", name = stack.name, quality = "normal", comparator = "="}, min = stack.count} end end if comb then @@ -650,27 +655,12 @@ end function update_stop_from_rail(map_data, rail, forbidden_entity, force) --NOTE: is this a correct way to figure out the direction? ---@type LuaEntity? - local rail_front = rail - ---@type LuaEntity? - local rail_back = rail - ---@type defines.rail_direction - for i = 1, 112 do - if rail_back then - local entity = rail_back.get_rail_segment_signal(defines_back, false) - if entity and entity.name == "train-stop" then - resolve_update_stop_from_rail(map_data, entity, forbidden_entity, force) - return - end - rail_back = rail_back.get_connected_rail({rail_direction = defines_back, rail_connection_direction = defines_straight}) - end - if rail_front then - local entity = rail_front.get_rail_segment_signal(defines_front, false) - if entity and entity.name == "train-stop" then - resolve_update_stop_from_rail(map_data, entity, forbidden_entity, force) - return - end - rail_front = rail_front.get_connected_rail({rail_direction = defines_front, rail_connection_direction = defines_straight}) - end + local stop = rail.get_rail_segment_stop(defines_front) + if not stop then + stop = rail.get_rail_segment_stop(defines_back) + end + if stop then + resolve_update_stop_from_rail(map_data, stop, forbidden_entity, force) end end diff --git a/cybersyn/scripts/train-events.lua b/cybersyn/scripts/train-events.lua index 05e61bd..97b7fce 100644 --- a/cybersyn/scripts/train-events.lua +++ b/cybersyn/scripts/train-events.lua @@ -13,7 +13,7 @@ local function set_comb1(map_data, station, manifest, sign) if manifest then local signals = {} for i, item in ipairs(manifest) do - signals[i] = {index = i, signal = {type = item.type, name = item.name}, count = sign*item.count} + signals[i] = {value = {type = item.type, name = item.name, quality = item.quality or "normal", comparator = "="}, min = sign*item.count} end set_combinator_output(map_data, comb, signals) else