diff --git a/locale/en/config.cfg b/locale/en/config.cfg index 5d31872..f9fb984 100644 --- a/locale/en/config.cfg +++ b/locale/en/config.cfg @@ -5,6 +5,7 @@ network-chest-provider=Network Provider Chest network-loader=Network Loader network-tank=Network Tank network-sensor=Network Sensor +network-limit-sensor=Network Limit Sensor [item-name] network-chest=Network Chest @@ -13,6 +14,7 @@ network-chest-provider=Network Provider Chest network-loader=Network Loader network-tank=Network Tank network-sensor=Network Sensor +network-limit-sensor=Network Limit Sensor [item-description] network-chest=A chest used to access the network. diff --git a/src/GlobalState.lua b/src/GlobalState.lua index aa40b4f..7192a94 100644 --- a/src/GlobalState.lua +++ b/src/GlobalState.lua @@ -135,7 +135,7 @@ end -- scan existing tanks and chests and use the max "give" limit as the item limit function M.limit_scan(item) local limits = global.mod.item_limits - local unlimited = 5000000000 -- "5G" + local unlimited = 2000000000 -- "2G" for _, info in pairs(global.mod.chests) do if info.requests ~= nil then @@ -200,9 +200,13 @@ function M.set_limit(item_name, value) -- don't use get_limit() local old_value = global.mod.item_limits[item_name] value = tonumber(value) - if value ~= nil and value ~= old_value then - global.mod.item_limits[item_name] = value - return true + if value ~= nil then + -- some game code paths use a int32 for the item count + value = math.min(value, 2000000000) + if value ~= old_value then + global.mod.item_limits[item_name] = value + return true + end end end return false @@ -483,6 +487,13 @@ function M.register_tank_entity(entity, config) if global.mod.tanks[entity.unit_number] ~= nil then return end + if config == nil then + config = { + type = "give", + limit = 0, + no_limit = true, + } + end Queue.push(global.mod.scan_queue, entity.unit_number) global.mod.tanks[entity.unit_number] = { diff --git a/src/NetworkChest.lua b/src/NetworkChest.lua index 183e234..bb9ecbb 100644 --- a/src/NetworkChest.lua +++ b/src/NetworkChest.lua @@ -899,8 +899,8 @@ end local function update_tank(info) local status = GlobalState.UPDATE_STATUS.NOT_UPDATED local type = info.config.type - local limit = info.config.limit - local buffer = info.config.buffer + local limit = info.config.limit or 5000 + local buffer = info.config.buffer or 1000 local fluid = info.config.fluid local temp = info.config.temperature local no_limit = (info.config.no_limit == true) diff --git a/src/NetworkSensor.lua b/src/NetworkSensor.lua index 1a14398..e2c64cf 100644 --- a/src/NetworkSensor.lua +++ b/src/NetworkSensor.lua @@ -24,6 +24,48 @@ function M.get_parameters() count = count, }) end + for fluid_name, fluid_temps in pairs(GlobalState.get_fluids()) do + if game.fluid_prototypes[fluid_name] ~= nil then + local max_temp + local max_count + for temp, count in pairs(fluid_temps) do + if max_temp == nil or max_temp < temp then + max_temp = temp + max_count = count + end + end + if max_count ~= nil then + table.insert(params, { + signal = { type = "fluid", name = fluid_name }, + count = max_count, + }) + end + end + end + -- have to set the index after sorting + table.sort(params, compare_control_params) + for index, param in ipairs(params) do + param.index = index + end + return params +end + +function M.get_limit_parameters() + local params = {} + for item, count in pairs(GlobalState.get_limits()) do + local name, temp = GlobalState.fluid_temp_key_decode(item) + if temp == nil then + table.insert(params, { + signal = { type = "item", name = name }, + count = math.min(count, 2000000000), + }) + else + table.insert(params, { + signal = { type = "fluid", name = name }, + count = math.min(count, 2000000000), + }) + end + end -- have to set the index after sorting table.sort(params, compare_control_params) for index, param in ipairs(params) do @@ -34,16 +76,24 @@ end function M.service_sensors() local params + local params_limit local to_del = {} -- all sensors get the same parameters, so handle them all in one tick for unit_number, entity in pairs(GlobalState.sensor_get_list()) do if entity.valid then local cb = entity.get_control_behavior() if cb ~= nil then - if params == nil then - params = M.get_parameters() + if entity.name == "network-sensor" then + if params == nil then + params = M.get_parameters() + end + cb.parameters = params + else + if params_limit == nil then + params_limit = M.get_limit_parameters() + end + cb.parameters = params_limit end - cb.parameters = params end else table.insert(to_del, unit_number) @@ -56,7 +106,7 @@ end function M.register_entity(event) local entity = event.created_entity or event.entity or event.destination - if entity ~= nil and entity.name == "network-sensor" then + if entity ~= nil and (entity.name == "network-sensor" or entity.name == "network-limit-sensor") then GlobalState.sensor_add(entity) end end diff --git a/src/UiNetworkShortages.lua b/src/UiNetworkShortages.lua index a06e2dc..a6827dc 100644 --- a/src/UiNetworkShortages.lua +++ b/src/UiNetworkShortages.lua @@ -158,7 +158,7 @@ function NetLimits:refresh() total_count = total_count + item.count end - self.elems.title.caption = string.format("Network Shortages - %s types, %s total", total_items, total_count) + self.elems.title.caption = string.format("Network Shortages - %.0f types, %.0f total", total_items, total_count) end return M diff --git a/src/prototypes/network-sensor.lua b/src/prototypes/network-sensor.lua index b28ad6a..a8ccf13 100644 --- a/src/prototypes/network-sensor.lua +++ b/src/prototypes/network-sensor.lua @@ -1,23 +1,28 @@ -local name = "network-sensor" -local override_item_name = "constant-combinator" -local override_prototype = "constant-combinator" -local entity = table.deepcopy(data.raw[override_prototype][override_item_name]) -entity.name = name -entity.minable.result = name --- Need enough to hold every item we might build --- We could scan in data-final-fixes to get a more accurate count, but that is ~1700 items. -entity.item_slot_count = 1000 +local function extend_one(name) + local override_item_name = "constant-combinator" + local override_prototype = "constant-combinator" -local item = table.deepcopy(data.raw["item"][override_item_name]) -item.name = name -item.place_result = name -item.order = item.order .. "2" + local entity = table.deepcopy(data.raw[override_prototype][override_item_name]) + entity.name = name + entity.minable.result = name + -- Need enough to hold every item we might build + -- We could scan in data-final-fixes to get a more accurate count, but that is ~1700 items. + entity.item_slot_count = 1000 -local recipe = table.deepcopy(data.raw["recipe"][override_item_name]) -recipe.name = name -recipe.result = name -recipe.enabled = true + local item = table.deepcopy(data.raw["item"][override_item_name]) + item.name = name + item.place_result = name + item.order = item.order .. name -data:extend({ entity, item, recipe }) + local recipe = table.deepcopy(data.raw["recipe"][override_item_name]) + recipe.name = name + recipe.result = name + recipe.enabled = true + + data:extend({ entity, item, recipe }) +end + +extend_one("network-sensor") +extend_one("network-limit-sensor")