fix(ejerskab): jord-bundne kortanlæg (boughtWithFarmland / ejer 15) er gårdens når jorden under dem er købt — Dakotas BGA500kw på jordlod 69 (v1.17.7.0)

This commit is contained in:
2026-09-24 04:57:12 +02:00
parent b603bd7765
commit c814557ae1
8 changed files with 84 additions and 13 deletions
+4
View File
@@ -50,7 +50,11 @@ local function getProductionPoint(placeable)
return placeable.spec_productionPoint ~= nil and placeable.spec_productionPoint.productionPoint or nil return placeable.spec_productionPoint ~= nil and placeable.spec_productionPoint.productionPoint or nil
end end
-- Fælles ejerregel (ADPrices): egen ejer eller jord-bundet kortanlæg på gårdens jord.
local function isOwnedBy(placeable, farmId) local function isOwnedBy(placeable, farmId)
if ADPrices ~= nil and ADPrices.isOwnedBy ~= nil then
return ADPrices.isOwnedBy(placeable, farmId)
end
if placeable.getOwnerFarmId ~= nil then if placeable.getOwnerFarmId ~= nil then
local ok, owner = pcall(placeable.getOwnerFarmId, placeable) local ok, owner = pcall(placeable.getOwnerFarmId, placeable)
return ok and owner == farmId return ok and owner == farmId
+38 -8
View File
@@ -84,19 +84,49 @@ function ADPrices.isSellingStation(station)
return true return true
end end
function ADPrices.isOwnedByPlayer(placeable) -- Placeable-ejeren (nil = ukendt).
local owner = nil local function getOwner(placeable)
if placeable.getOwnerFarmId ~= nil then if placeable.getOwnerFarmId ~= nil then
local ok, value = pcall(placeable.getOwnerFarmId, placeable) local ok, value = pcall(placeable.getOwnerFarmId, placeable)
if ok then owner = value end if ok then return value end
elseif placeable.ownerFarmId ~= nil then return nil
owner = placeable.ownerFarmId
end end
if owner == nil then return placeable.ownerFarmId
end
-- Ejeren af jorden under en placeable (nil = ukendt).
local function getLandOwner(placeable)
local manager = g_farmlandManager
if manager == nil or manager.getFarmlandIdAtWorldPosition == nil or manager.getFarmlandOwner == nil or placeable.rootNode == nil or getWorldTranslation == nil then
return nil
end
local ok, x, _, z = pcall(getWorldTranslation, placeable.rootNode)
if not ok or x == nil then return nil end
local okId, farmlandId = pcall(manager.getFarmlandIdAtWorldPosition, manager, x, z)
if not okId or farmlandId == nil then return nil end
local okOwner, owner = pcall(manager.getFarmlandOwner, manager, farmlandId)
return okOwner and owner or nil
end
-- Gårdens bygning? Ejer = farmId, ELLER et kortanlæg der følger jorden (boughtWithFarmland / ejer 15)
-- og jorden under det er gårdens — Dakotas BGA500kw står med ejer 15 selv på købt jord.
function ADPrices.isOwnedBy(placeable, farmId)
if placeable == nil then return false end
local owner = getOwner(placeable)
if owner == farmId then return true end
if placeable.boughtWithFarmland == true or owner == 15 then
return getLandOwner(placeable) == farmId
end
return false
end
-- Spillerens gård ejer placeablen; ukendt ejer = regnes som egen (afleveringer til egne anlæg er ikke salg).
function ADPrices.isOwnedByPlayer(placeable)
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
if getOwner(placeable) == nil then
return true return true
end end
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1 return ADPrices.isOwnedBy(placeable, farmId)
return owner == farmId
end end
local function getCurrentPeriod() local function getCurrentPeriod()
+12 -2
View File
@@ -63,6 +63,16 @@ local function getAutoDriveEnv()
return nil return nil
end end
-- Adgang til en station: spillets adgangstjek, eller stationens bygning er gårdens efter den fælles
-- ejerregel (jord-bundne kortanlæg som Dakotas BGA står med ejer 15 selv på gårdens jord).
function ADSmartPickup.canUseStation(farmId, station)
local access = g_currentMission ~= nil and g_currentMission.accessHandler or nil
if access == nil or access:canFarmAccess(farmId, station) then
return true
end
return station.owningPlaceable ~= nil and ADPrices ~= nil and ADPrices.isOwnedBy ~= nil and ADPrices.isOwnedBy(station.owningPlaceable, farmId)
end
function ADSmartPickup.getFarmId(vehicle) function ADSmartPickup.getFarmId(vehicle)
if vehicle.getOwnerFarmId ~= nil then if vehicle.getOwnerFarmId ~= nil then
local farmId = vehicle:getOwnerFarmId() local farmId = vehicle:getOwnerFarmId()
@@ -140,7 +150,7 @@ local function getClosestStation(adEnv, candidateStations, triggersField, nodeFi
local maxFallbackDistance = direction ~= nil and ADSmartPickup.MAX_FALLBACK_TRIGGER_DISTANCE or ADSmartPickup.MAX_MARKER_TO_TRIGGER_DISTANCE local maxFallbackDistance = direction ~= nil and ADSmartPickup.MAX_FALLBACK_TRIGGER_DISTANCE or ADSmartPickup.MAX_MARKER_TO_TRIGGER_DISTANCE
local best = {any = {distance = maxFallbackDistance}, behind = {distance = ADSmartPickup.MAX_MARKER_TO_TRIGGER_DISTANCE}} local best = {any = {distance = maxFallbackDistance}, behind = {distance = ADSmartPickup.MAX_MARKER_TO_TRIGGER_DISTANCE}}
for _, station in pairs(candidateStations) do for _, station in pairs(candidateStations) do
if g_currentMission.accessHandler:canFarmAccess(farmId, station) then if ADSmartPickup.canUseStation(farmId, station) then
local closest, closestBehind = getDistancesToTriggers(station[triggersField], nodeFields, wayPoint, direction) local closest, closestBehind = getDistancesToTriggers(station[triggersField], nodeFields, wayPoint, direction)
if closest < best.any.distance then if closest < best.any.distance then
best.any = {distance = closest, station = station} best.any = {distance = closest, station = station}
@@ -182,7 +192,7 @@ function ADSmartPickup.getLoadStationNearWayPointId(adEnv, wayPointId, farmId, m
end end
local best, bestDistance = nil, maxDistance or ADSmartPickup.MAX_MARKER_TO_TRIGGER_DISTANCE local best, bestDistance = nil, maxDistance or ADSmartPickup.MAX_MARKER_TO_TRIGGER_DISTANCE
for _, station in pairs(g_currentMission.storageSystem:getLoadingStations()) do for _, station in pairs(g_currentMission.storageSystem:getLoadingStations()) do
if g_currentMission.accessHandler:canFarmAccess(farmId, station) then if ADSmartPickup.canUseStation(farmId, station) then
local closest = getDistancesToTriggers(station.loadTriggers, LOAD_TRIGGER_NODE_FIELDS, wayPoint, nil) local closest = getDistancesToTriggers(station.loadTriggers, LOAD_TRIGGER_NODE_FIELDS, wayPoint, nil)
if closest < bestDistance then if closest < bestDistance then
best, bestDistance = station, closest best, bestDistance = station, closest
+4
View File
@@ -548,7 +548,11 @@ end
ADSources.RESERVE_HOURS = 24 ADSources.RESERVE_HOURS = 24
-- Fælles ejerregel (ADPrices): egen ejer eller jord-bundet kortanlæg på gårdens jord.
local function isOwnedBy(placeable, farmId) local function isOwnedBy(placeable, farmId)
if ADPrices ~= nil and ADPrices.isOwnedBy ~= nil then
return ADPrices.isOwnedBy(placeable, farmId)
end
if placeable.getOwnerFarmId ~= nil then if placeable.getOwnerFarmId ~= nil then
local ok, owner = pcall(placeable.getOwnerFarmId, placeable) local ok, owner = pcall(placeable.getOwnerFarmId, placeable)
return ok and owner == farmId return ok and owner == farmId
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107"> <modDesc descVersion="107">
<author>masterdraco</author> <author>masterdraco</author>
<version>1.17.6.0</version> <version>1.17.7.0</version>
<title> <title>
<en>AD Smart Pickup</en> <en>AD Smart Pickup</en>
</title> </title>
+3 -1
View File
@@ -1,6 +1,6 @@
# AD Smart Pickup — brugermanual # AD Smart Pickup — brugermanual
Version 1.17.6 · Farming Simulator 25 · tillæg til AutoDrive Version 1.17.7 · Farming Simulator 25 · tillæg til AutoDrive
*English version: [USER_MANUAL.md](USER_MANUAL.md)* *English version: [USER_MANUAL.md](USER_MANUAL.md)*
@@ -63,6 +63,8 @@ liste traktorer. Ældre versioner kaldte det et *run*, og ordet står stadig på
**Bygning.** En stald, fabrik, silo, et objektlager (palleskur) eller et salgssted. Du vælger **Bygning.** En stald, fabrik, silo, et objektlager (palleskur) eller et salgssted. Du vælger
bygninger, ikke markører. Moden finder selv den AutoDrive-markør, der hører til bygningens trigger. bygninger, ikke markører. Moden finder selv den AutoDrive-markør, der hører til bygningens trigger.
Kun gårdens egne bygninger vises. Kortets faste anlæg, der følger jorden, som Dakotas biogasanlæg,
regnes som gårdens, når jorden under dem er købt.
**Markør.** En AutoDrive-destination. Hver bygning skal have en markør inden for 40 m af sin læsse- **Markør.** En AutoDrive-destination. Hver bygning skal have en markør inden for 40 m af sin læsse-
eller aflæsningstrigger. En stald har tit flere, fx én ved mælketanken og én ved gyllebeholderen. eller aflæsningstrigger. En stald har tit flere, fx én ved mælketanken og én ved gyllebeholderen.
+3 -1
View File
@@ -1,6 +1,6 @@
# AD Smart Pickup — user manual # AD Smart Pickup — user manual
Version 1.17.6 · Farming Simulator 25 · add-on for AutoDrive Version 1.17.7 · Farming Simulator 25 · add-on for AutoDrive
*Dansk version: [BRUGERMANUAL.md](BRUGERMANUAL.md)* *Dansk version: [BRUGERMANUAL.md](BRUGERMANUAL.md)*
@@ -63,6 +63,8 @@ tractors. Older versions called it a *run*, and the word is still used on some b
**Building.** A barn, factory, silo, object storage (pallet shed) or selling point. You pick **Building.** A barn, factory, silo, object storage (pallet shed) or selling point. You pick
buildings, not markers. The mod finds the AutoDrive marker that belongs to the building's trigger. buildings, not markers. The mod finds the AutoDrive marker that belongs to the building's trigger.
Only the farm's own buildings are listed. Fixed map buildings that come with the land, such as
Dakota's biogas plant, count as the farm's once the land under them is bought.
**Marker.** An AutoDrive destination. Every building needs a marker within 40 m of its loading or **Marker.** An AutoDrive destination. Every building needs a marker within 40 m of its loading or
unloading trigger. A barn often has several, such as one at the milk tank and one at the slurry tank. unloading trigger. A barn often has several, such as one at the milk tank and one at the slurry tank.
+19
View File
@@ -83,5 +83,24 @@ check("P6 højeste procent", best.percent, 92)
check("P6 ved lighed højeste pris", best.price, 3) check("P6 ved lighed højeste pris", best.price, 3)
check("P6 tom -> nil", ADPrices.bestQuote({}), nil) check("P6 tom -> nil", ADPrices.bestQuote({}), nil)
-- P-land: kortanlæg der følger jorden (boughtWithFarmland) er gårdens, når jorden under dem er gårdens —
-- selv om placeable-ejeren står som 15 (Dakotas BGA500kw på jordlod 69)
getWorldTranslation = getWorldTranslation or function(node) return node.x, 0, node.z end
g_currentMission = g_currentMission or {}
g_currentMission.getFarmId = function() return 1 end
g_farmlandManager = {
getFarmlandIdAtWorldPosition = function(_, x, z) return x < 0 and 69 or 70 end,
getFarmlandOwner = function(_, id) return id == 69 and 1 or 0 end,
}
local bga = {rootNode = {x = -1600, z = -89}, boughtWithFarmland = true, spec_productionPoint = {}, getOwnerFarmId = function() return 15 end}
local bgaOther = {rootNode = {x = 1600, z = -89}, boughtWithFarmland = true, spec_productionPoint = {}, getOwnerFarmId = function() return 15 end}
local dairy = {rootNode = {x = -3173, z = -4028}, spec_productionPoint = {}, getOwnerFarmId = function() return 0 end}
check("P-land BGA på egen jord = egen", ADPrices.isOwnedBy(bga, 1), true)
check("P-land BGA på fremmed jord = ikke egen", ADPrices.isOwnedBy(bgaOther, 1), false)
check("P-land mejeri (ejer 0, ikke jord-bundet) = ikke egen", ADPrices.isOwnedBy(dairy, 1), false)
check("P-land egen ejer", ADPrices.isOwnedBy({getOwnerFarmId = function() return 1 end}, 1), true)
check("P-land BGA er ikke salgssted", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = true, owningPlaceable = bga}), false)
g_farmlandManager = nil
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1) os.exit(failures == 0 and 0 or 1)