fix(review): palle/bulk pr. kilde, pallefabrikker uden læssestation, hold-omdirigering, last ved Start, tomme kilder udelukkes, færre rutetjek, advarsler huskes, paller kun Fra/Salg
This commit is contained in:
@@ -34,24 +34,68 @@ local function getPlaceableName(placeable, fallback)
|
||||
return fallback
|
||||
end
|
||||
|
||||
-- Pallevarer har en pallefil i spillets fillType-definition (halmkurve, mel, brød ...).
|
||||
-- Varer der KAN stå på paller (spillets fillType-definition: isPalletType eller pallefil).
|
||||
-- Sukker og mel er palletyper, men læsses som bulk ved en fabrik med læssestation — så om
|
||||
-- varen er palle eller bulk afgøres pr. kilde i isPalletAt, ikke her.
|
||||
function ADSources.isPalletFillType(fillType)
|
||||
local desc = g_fillTypeManager ~= nil and g_fillTypeManager.getFillTypeByIndex ~= nil and g_fillTypeManager:getFillTypeByIndex(fillType) or nil
|
||||
return desc ~= nil and desc.palletFilename ~= nil
|
||||
return desc ~= nil and (desc.isPalletType == true or desc.palletFilename ~= nil)
|
||||
end
|
||||
|
||||
local function stationSupports(station, fillType)
|
||||
if station == nil then
|
||||
return false
|
||||
end
|
||||
if station.supportedFillTypes ~= nil then
|
||||
return station.supportedFillTypes[fillType] == true
|
||||
end
|
||||
if station.getIsFillTypeSupported ~= nil then
|
||||
local ok, value = pcall(station.getIsFillTypeSupported, station, fillType)
|
||||
return ok and value == true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Palle eller bulk ved DENNE kilde: silo = bulk; objektlager = palle; fabrik = bulk hvis
|
||||
-- markørens læssestation udleverer varen, ellers palle hvis varen er en palletype.
|
||||
function ADSources.isPalletAt(source, fillType)
|
||||
if source.kind == "silo" then
|
||||
return false
|
||||
elseif source.kind == "objectStorage" then
|
||||
return true
|
||||
end
|
||||
if stationSupports(source.station, fillType) then
|
||||
return false
|
||||
end
|
||||
return ADSources.isPalletFillType(fillType)
|
||||
end
|
||||
|
||||
local function getProductionPoint(placeable)
|
||||
return placeable ~= nil and placeable.spec_productionPoint ~= nil and placeable.spec_productionPoint.productionPoint or nil
|
||||
end
|
||||
|
||||
-- Nærmeste objektlager inden for MAX_DISTANCE af waypointet, som farmen må bruge.
|
||||
local function findObjectStorageNear(wayPoint, farmId)
|
||||
-- Placeable'ns "nærmeste punkt" for kildegenkendelse: pallespawnerens første plads (fabrik)
|
||||
-- eller rodnoden.
|
||||
local function getPlaceableAnchor(placeable)
|
||||
local productionPoint = getProductionPoint(placeable)
|
||||
local spawner = productionPoint ~= nil and productionPoint.palletSpawner or nil
|
||||
local place = spawner ~= nil and spawner.spawnPlaces ~= nil and spawner.spawnPlaces[1] or nil
|
||||
local node = place ~= nil and place.startNode or placeable.rootNode
|
||||
local x, z = getNodePosition(node)
|
||||
if x == nil and node ~= placeable.rootNode then
|
||||
x, z = getNodePosition(placeable.rootNode)
|
||||
end
|
||||
return x, z
|
||||
end
|
||||
|
||||
-- Nærmeste placeable inden for MAX_DISTANCE af waypointet som farmen må bruge og predicate godkender.
|
||||
local function findPlaceableNear(wayPoint, farmId, predicate)
|
||||
local placeables = g_currentMission ~= nil and g_currentMission.placeableSystem ~= nil and g_currentMission.placeableSystem.placeables or {}
|
||||
local access = g_currentMission ~= nil and g_currentMission.accessHandler or nil
|
||||
local best, bestDistance = nil, ADSources.MAX_DISTANCE * ADSources.MAX_DISTANCE
|
||||
for _, placeable in pairs(placeables) do
|
||||
if placeable.spec_objectStorage ~= nil and (access == nil or access:canFarmAccess(farmId, placeable)) then
|
||||
local x, z = getNodePosition(placeable.rootNode)
|
||||
if predicate(placeable) and (access == nil or access:canFarmAccess(farmId, placeable)) then
|
||||
local x, z = getPlaceableAnchor(placeable)
|
||||
if x ~= nil then
|
||||
local d = distance2(wayPoint.x, wayPoint.z, x, z)
|
||||
if d < bestDistance then
|
||||
@@ -63,6 +107,14 @@ local function findObjectStorageNear(wayPoint, farmId)
|
||||
return best
|
||||
end
|
||||
|
||||
local function isObjectStorage(placeable)
|
||||
return placeable.spec_objectStorage ~= nil
|
||||
end
|
||||
|
||||
local function isProductionPoint(placeable)
|
||||
return getProductionPoint(placeable) ~= nil
|
||||
end
|
||||
|
||||
-- {kind = "factory"|"silo"|"objectStorage", placeable, station|nil, wayPointId, name} eller nil.
|
||||
function ADSources.identify(adEnv, wayPointId, farmId)
|
||||
local wayPoint = adEnv.ADGraphManager:getWayPointById(wayPointId)
|
||||
@@ -79,7 +131,13 @@ function ADSources.identify(adEnv, wayPointId, farmId)
|
||||
if placeable ~= nil and placeable.spec_silo ~= nil then
|
||||
return {kind = "silo", placeable = placeable, station = station, wayPointId = wayPointId, name = getPlaceableName(placeable, markerName)}
|
||||
end
|
||||
local storage = findObjectStorageNear(wayPoint, farmId)
|
||||
-- Rene pallefabrikker (halmvarer, bageri ...) har ingen læssestation: find dem på afstand
|
||||
-- til pallespawneren; dernæst objektlagre.
|
||||
local factory = findPlaceableNear(wayPoint, farmId, isProductionPoint)
|
||||
if factory ~= nil then
|
||||
return {kind = "factory", placeable = factory, station = nil, wayPointId = wayPointId, name = getPlaceableName(factory, markerName)}
|
||||
end
|
||||
local storage = findPlaceableNear(wayPoint, farmId, isObjectStorage)
|
||||
if storage ~= nil then
|
||||
return {kind = "objectStorage", placeable = storage, station = nil, wayPointId = wayPointId, name = getPlaceableName(storage, markerName)}
|
||||
end
|
||||
@@ -143,7 +201,7 @@ local function getFactoryProducts(source, farmId)
|
||||
seen[fillType] = true
|
||||
local level = storage ~= nil and storage.getFillLevel ~= nil and (storage:getFillLevel(fillType) or 0) or 0
|
||||
local capacity = storage ~= nil and storage.getCapacity ~= nil and (storage:getCapacity(fillType) or 0) or 0
|
||||
local isPallet = ADSources.isPalletFillType(fillType)
|
||||
local isPallet = ADSources.isPalletAt(source, fillType)
|
||||
local available = level + (isPallet and getPalletsNearSpawner(source.placeable, fillType, farmId) or 0)
|
||||
table.insert(products, newProduct(fillType, available, level, capacity, isPallet))
|
||||
end
|
||||
@@ -165,7 +223,7 @@ local function getSiloProducts(source)
|
||||
end
|
||||
local products = {}
|
||||
for fillType, level in pairs(levels) do
|
||||
table.insert(products, newProduct(fillType, level, level, capacities[fillType] or 0, ADSources.isPalletFillType(fillType)))
|
||||
table.insert(products, newProduct(fillType, level, level, capacities[fillType] or 0, false))
|
||||
end
|
||||
table.sort(products, function(a, b) return a.fillType < b.fillType end)
|
||||
return products
|
||||
|
||||
Reference in New Issue
Block a user