feat(lagre): vælg bygning -> statistik pr. vare: værdi nu/ved toppris, gårdens beholdning i døgn, forbrug og produktion pr. døgn (v1.15.0.0)
This commit is contained in:
@@ -624,6 +624,92 @@ function ADSources.getFarmDemand(adEnv, fillType, farmId, excludedPlaceables)
|
||||
return {liters = total, consumers = consumers}
|
||||
end
|
||||
|
||||
-- ---- forbrug og produktion pr. døgn (fanen Lagre) ----
|
||||
|
||||
local function addRate(rates, fillType, field, liters)
|
||||
if fillType == nil or liters == nil or liters <= 0 then return end
|
||||
rates[fillType] = rates[fillType] or {consumption = 0, production = 0}
|
||||
rates[fillType][field] = rates[fillType][field] + liters
|
||||
end
|
||||
|
||||
local function addFactoryRates(rates, placeable)
|
||||
local productionPoint = getProductionPoint(placeable)
|
||||
for _, production in ipairs(productionPoint ~= nil and productionPoint.productions or {}) do
|
||||
if isProductionWanted(productionPoint, production) then
|
||||
local perDay = (production.cyclesPerMinute or ((production.cyclesPerHour or 0) / 60)) * 1440
|
||||
for _, input in ipairs(production.inputs or {}) do addRate(rates, input.type, "consumption", (input.amount or 0) * perDay) end
|
||||
for _, output in ipairs(production.outputs or {}) do addRate(rates, output.type, "production", (output.amount or 0) * perDay) end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function getFoodWeights(placeable)
|
||||
local foodSpec = placeable.spec_husbandryFood
|
||||
local system = g_currentMission ~= nil and g_currentMission.animalFoodSystem or nil
|
||||
local weights = {}
|
||||
local food = system ~= nil and system.getAnimalFood ~= nil and foodSpec ~= nil and system:getAnimalFood(foodSpec.animalTypeIndex) or nil
|
||||
for _, group in pairs(food ~= nil and food.groups or {}) do
|
||||
local weight = tonumber(group.productionWeight) or tonumber(group.eatWeight) or 1
|
||||
for _, fillType in pairs(group.fillTypes or {}) do weights[fillType] = math.max(weights[fillType] or 0, weight) end
|
||||
end
|
||||
return weights
|
||||
end
|
||||
|
||||
local function addHusbandryRates(rates, placeable)
|
||||
local food, straw, water = placeable.spec_husbandryFood, placeable.spec_husbandryStraw, placeable.spec_husbandryWater
|
||||
local byName = function(name) return g_fillTypeManager ~= nil and g_fillTypeManager.getFillTypeIndexByName ~= nil and g_fillTypeManager:getFillTypeIndexByName(name) or nil end
|
||||
local nameToIndex = function(name)
|
||||
local index = byName(name)
|
||||
if index == nil and g_fillTypeManager ~= nil then
|
||||
for i = 1, 256 do if g_fillTypeManager:getFillTypeNameByIndex(i) == name then return i end end
|
||||
end
|
||||
return index
|
||||
end
|
||||
if food ~= nil and (food.litersPerHour or 0) > 0 then
|
||||
for fillType, liters in pairs(ADStorageStats.splitTroughConsumption(food.litersPerHour * 24, food.fillLevels, getFoodWeights(placeable))) do
|
||||
addRate(rates, fillType, "consumption", liters)
|
||||
end
|
||||
end
|
||||
if straw ~= nil and (straw.inputLitersPerHour or 0) > 0 then
|
||||
addRate(rates, nameToIndex("STRAW"), "consumption", straw.inputLitersPerHour * 24)
|
||||
end
|
||||
if water ~= nil and not water.automaticWaterSupply and (water.litersPerHour or 0) > 0 then
|
||||
addRate(rates, nameToIndex("WATER"), "consumption", water.litersPerHour * 24)
|
||||
end
|
||||
end
|
||||
|
||||
-- {[fillType] = {consumption, production}} i liter pr. døgn for gårdens fabrikker og stalde.
|
||||
function ADSources.getFarmRates(adEnv, farmId)
|
||||
local placeables = g_currentMission ~= nil and g_currentMission.placeableSystem ~= nil and g_currentMission.placeableSystem.placeables or {}
|
||||
local rates = {}
|
||||
for _, placeable in pairs(placeables) do
|
||||
if isOwnedBy(placeable, farmId) then
|
||||
if getProductionPoint(placeable) ~= nil then
|
||||
addFactoryRates(rates, placeable)
|
||||
elseif placeable.getHusbandryFillLevel ~= nil then
|
||||
addHusbandryRates(rates, placeable)
|
||||
end
|
||||
end
|
||||
end
|
||||
return rates
|
||||
end
|
||||
|
||||
-- Bedste pris lige nu blandt alle spillets salgssteder der tager varen (uanset markør/vejnet):
|
||||
-- {price, top} pr. liter; top = prisen ved årets højeste periode. nil når ingen tager varen.
|
||||
function ADSources.getMarketQuote(fillType)
|
||||
local storage = g_currentMission ~= nil and g_currentMission.storageSystem or nil
|
||||
local best = nil
|
||||
for _, station in pairs(storage ~= nil and storage:getUnloadingStations() or {}) do
|
||||
if ADPrices.isSellingStation(station) and ADSources.stationAccepts(station, fillType) then
|
||||
local quote = ADPrices.getQuote(station, fillType)
|
||||
if quote ~= nil and (best == nil or quote.price > best.price) then
|
||||
best = {price = quote.price, top = quote.top}
|
||||
end
|
||||
end
|
||||
end
|
||||
return best
|
||||
end
|
||||
|
||||
-- ---- inventar: alt gården har liggende, pr. bygning ----
|
||||
|
||||
local function addEntry(entries, fillType, level, capacity, extra)
|
||||
|
||||
Reference in New Issue
Block a user