Auto Resource Redux


Automatic resource distribution between machines - for RTS like/combat focused gameplay

Overhaul
7 months ago
1.1
525
Logistics Cheats

g UPS fix for mixed fluid temperatures

3 months ago

Adding math.ceil() in functions storage.count and storage. remove improved FPS by 10 in a medium PY base.
Mixed fluid temperatures were decimalated and creating many extraneous entries from weighted average function.
Mods are unlikely to care for decimal temperature values in the use case.
Ceiling is superior to floor as fluids should be hotter to be more usable in mixed case events, ie. most mods want something hotter only a few want something cold such as bob's coolant or Py's neutron flow, both of which can be dealt with by known loop chill systems for the specific feature.
Altered Code

function Storage.count_available_fluid_in_temperature_range(storage, storage_key, min_temp, max_temp, use_reserved)
local fluid = storage.items[storage_key] or {}
local amount_reserved = storage.reservations[storage_key] or 0
if use_reserved and amount_reserved <= 0 then
amount_reserved = DEFAULT_FLUID_RESERVATION
Storage.set_item_limit_and_reservation(storage, storage_key, storage.last_entity, nil, amount_reserved)
end
min_temp = math.floor(min_temp or -math.huge)
max_temp = math.floor(max_temp or math.huge)
local total = 0

for temperature, amount in pairs(fluid) do
temperature = math.ceil(temperature)
if temperature >= min_temp and temperature <= max_temp then
total = total + math.max(0, amount - amount_reserved)
end
end
return total
end

function Storage.remove_fluid_in_temperature_range(
storage, storage_key,
min_temp, max_temp,
amount_to_remove,
use_reserved
)
local fluid = storage.items[storage_key]
if not fluid then
return 0, 0
end
min_temp = math.floor(min_temp or -math.huge)
max_temp = math.floor(max_temp or math.huge)
local total_to_remove = math.ceil(amount_to_remove)
local total_removed = 0
local new_temperature = 0
local amount_reserved = use_reserved and 0 or (storage.reservations[storage_key] or 0)
for temperature, stored_amount in pairs(fluid) do
if temperature >= min_temp and temperature <= max_temp and stored_amount > amount_reserved then
amount_to_remove = math.min(stored_amount - amount_reserved, total_to_remove)
fluid[temperature] = math.max(0, stored_amount - amount_to_remove)
new_temperature = math.ceil(Util.weighted_average(new_temperature, total_removed, temperature, amount_to_remove))
total_removed = total_removed + amount_to_remove
total_to_remove = total_to_remove - amount_to_remove
if total_to_remove <= 0 then
break
end
end
end
storage.items[storage_key] = fluid
return total_removed, new_temperature
end

return Storage

New response