fix: fremrulning finder staldenes fodertrug (1.62.367)
This commit is contained in:
@@ -62,30 +62,64 @@ local function triggerAccepts(trigger, fillType)
|
||||
return trigger.fillTypes == nil or trigger.fillTypes[fillType] == true
|
||||
end
|
||||
|
||||
-- Alle aflæsningstriggere moden må bruge: siloers/fabrikkers (storageSystem) og staldenes fodertrug — trugene ligger
|
||||
-- ikke i storageSystem, men i staldens spec_husbandryFood.feedingTroughs (in-game 19/10: 'Sheep Food' stod 8 m før
|
||||
-- fårestaldens trug, og fremrulningen så slet ikke truget). Stalden skal være gårdens efter samme regel som siloerne
|
||||
-- (adgangstjek, ellers ADPrices.isOwnedBy — kortanlæg med ejer 15), og et fuldt trug tæller ikke (review 19/10).
|
||||
-- fillType: kun trug med plads til varen (nil = alle). -> {trigger, ...}
|
||||
local function penUsable(farmId, placeable)
|
||||
local access = g_currentMission ~= nil and g_currentMission.accessHandler or nil
|
||||
if access ~= nil and access:canFarmAccess(farmId, placeable) then return true end
|
||||
return ADPrices ~= nil and ADPrices.isOwnedBy ~= nil and ADPrices.isOwnedBy(placeable, farmId) == true
|
||||
end
|
||||
|
||||
local function troughHasRoom(trigger, fillType)
|
||||
local target = trigger.target
|
||||
if fillType == nil or target == nil or target.getFreeCapacity == nil then return true end
|
||||
local ok, free = pcall(target.getFreeCapacity, target, fillType)
|
||||
return not ok or free == nil or free > 0
|
||||
end
|
||||
|
||||
function ADUnloadRoll.candidateTriggers(farmId, fillType)
|
||||
local list = {}
|
||||
local storage = g_currentMission ~= nil and g_currentMission.storageSystem or nil
|
||||
for _, station in pairs(storage ~= nil and storage:getUnloadingStations() or {}) do
|
||||
if ADSmartPickup == nil or ADSmartPickup.canUseStation == nil or ADSmartPickup.canUseStation(farmId, station) then
|
||||
for _, trigger in pairs(station.unloadTriggers or {}) do table.insert(list, trigger) end
|
||||
end
|
||||
end
|
||||
local placeables = g_currentMission ~= nil and g_currentMission.placeableSystem ~= nil and g_currentMission.placeableSystem.placeables or {}
|
||||
for _, placeable in ipairs(placeables) do
|
||||
local food = placeable.spec_husbandryFood
|
||||
if farmId ~= nil and food ~= nil and food.feedingTroughs ~= nil and penUsable(farmId, placeable) then
|
||||
for _, trigger in ipairs(food.feedingTroughs) do
|
||||
if troughHasRoom(trigger, fillType) then table.insert(list, trigger) end
|
||||
end
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
-- Triggere foran de fulde vognes tippesteder, i traktorens rum. -> {{x, z}}
|
||||
local function offsetsFor(adEnv, vehicle)
|
||||
local offsets = {}
|
||||
local storage = g_currentMission ~= nil and g_currentMission.storageSystem or nil
|
||||
if storage == nil or vehicle.rootNode == nil then return offsets end
|
||||
local farmId = vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() or nil
|
||||
if vehicle.rootNode == nil then return offsets end
|
||||
local farmId = ADSmartPickup ~= nil and ADSmartPickup.getFarmId ~= nil and ADSmartPickup.getFarmId(vehicle)
|
||||
or (vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() or nil)
|
||||
for _, unit in ipairs(adEnv.AutoDrive.getAllDischargeableUnits(vehicle) or {}) do
|
||||
local object = unit.object
|
||||
local level = object ~= nil and object.getFillUnitFillLevel ~= nil and object:getFillUnitFillLevel(unit.fillUnitIndex) or 0
|
||||
local dischargeNode = level >= ADUnloadRoll.MIN_FILL and object.getCurrentDischargeNode ~= nil and object:getCurrentDischargeNode() or nil
|
||||
if dischargeNode ~= nil and dischargeNode.node ~= nil then
|
||||
local fillType = object:getFillUnitFillType(unit.fillUnitIndex)
|
||||
local nx, ny, nz = getWorldTranslation(dischargeNode.node)
|
||||
for _, station in pairs(storage:getUnloadingStations()) do
|
||||
if ADSmartPickup == nil or ADSmartPickup.canUseStation == nil or ADSmartPickup.canUseStation(farmId, station) then
|
||||
for _, trigger in pairs(station.unloadTriggers or {}) do
|
||||
local node = trigger.exactFillRootNode
|
||||
if node ~= nil and triggerAccepts(trigger, fillType) then
|
||||
local tx, _, tz = getWorldTranslation(node)
|
||||
if math.sqrt((tx - nx) ^ 2 + (tz - nz) ^ 2) <= ADUnloadRoll.SEARCH_RADIUS then
|
||||
local x, _, z = worldDirectionToLocal(vehicle.rootNode, tx - nx, 0, tz - nz)
|
||||
table.insert(offsets, {x = x, z = z})
|
||||
end
|
||||
end
|
||||
local nx, _, nz = getWorldTranslation(dischargeNode.node)
|
||||
for _, trigger in ipairs(ADUnloadRoll.candidateTriggers(farmId, fillType)) do
|
||||
local node = trigger.exactFillRootNode
|
||||
if node ~= nil and triggerAccepts(trigger, fillType) then
|
||||
local tx, _, tz = getWorldTranslation(node)
|
||||
if math.sqrt((tx - nx) ^ 2 + (tz - nz) ^ 2) <= ADUnloadRoll.SEARCH_RADIUS then
|
||||
local x, _, z = worldDirectionToLocal(vehicle.rootNode, tx - nx, 0, tz - nz)
|
||||
table.insert(offsets, {x = x, z = z})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.366.0</version>
|
||||
<version>1.62.367.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user