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
end
-- Fælles ejerregel (ADPrices): egen ejer eller jord-bundet kortanlæg på gårdens jord.
local function isOwnedBy(placeable, farmId)
if ADPrices ~= nil and ADPrices.isOwnedBy ~= nil then
return ADPrices.isOwnedBy(placeable, farmId)
end
if placeable.getOwnerFarmId ~= nil then
local ok, owner = pcall(placeable.getOwnerFarmId, placeable)
return ok and owner == farmId
+38 -8
View File
@@ -84,19 +84,49 @@ function ADPrices.isSellingStation(station)
return true
end
function ADPrices.isOwnedByPlayer(placeable)
local owner = nil
-- Placeable-ejeren (nil = ukendt).
local function getOwner(placeable)
if placeable.getOwnerFarmId ~= nil then
local ok, value = pcall(placeable.getOwnerFarmId, placeable)
if ok then owner = value end
elseif placeable.ownerFarmId ~= nil then
owner = placeable.ownerFarmId
if ok then return value end
return nil
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
end
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
return owner == farmId
return ADPrices.isOwnedBy(placeable, farmId)
end
local function getCurrentPeriod()
+12 -2
View File
@@ -63,6 +63,16 @@ local function getAutoDriveEnv()
return nil
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)
if vehicle.getOwnerFarmId ~= nil then
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 best = {any = {distance = maxFallbackDistance}, behind = {distance = ADSmartPickup.MAX_MARKER_TO_TRIGGER_DISTANCE}}
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)
if closest < best.any.distance then
best.any = {distance = closest, station = station}
@@ -182,7 +192,7 @@ function ADSmartPickup.getLoadStationNearWayPointId(adEnv, wayPointId, farmId, m
end
local best, bestDistance = nil, maxDistance or ADSmartPickup.MAX_MARKER_TO_TRIGGER_DISTANCE
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)
if closest < bestDistance then
best, bestDistance = station, closest
+4
View File
@@ -548,7 +548,11 @@ end
ADSources.RESERVE_HOURS = 24
-- Fælles ejerregel (ADPrices): egen ejer eller jord-bundet kortanlæg på gårdens jord.
local function isOwnedBy(placeable, farmId)
if ADPrices ~= nil and ADPrices.isOwnedBy ~= nil then
return ADPrices.isOwnedBy(placeable, farmId)
end
if placeable.getOwnerFarmId ~= nil then
local ok, owner = pcall(placeable.getOwnerFarmId, placeable)
return ok and owner == farmId
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107">
<author>masterdraco</author>
<version>1.17.6.0</version>
<version>1.17.7.0</version>
<title>
<en>AD Smart Pickup</en>
</title>