feat: høstkontrakter — læs til kontraktens salgssted (1.62.209)
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
-- Kontrakter kører selv (brugerønske 9/10, "byg det hele" 10/10): accepterer spilleren en markkontrakt, sætter moden
|
||||
-- kontraktens mark til det tilsvarende trin (pløj, kultivér, så, ukrudt, gødning, slåning, sten), og markarbejdet
|
||||
-- sender et sæt — eller beder spilleren køre et, uden parkering/markør (ADPlayerTransport). Kun det ene trin; når
|
||||
-- kontrakten er færdig eller annulleret, stoppes sættene og marken glemmes. Høst (aflevering til kontraktens
|
||||
-- salgssted) er ikke med endnu. Indstillingen contracts: 1 = til, 0 = fra. Ren logik øverst, spil-adapter nederst.
|
||||
-- kontrakten er færdig eller annulleret, stoppes sættene og marken glemmes. Høst: tømmevognene kører læssene til
|
||||
-- kontraktens salgssted (dets AutoDrive-markører); uden F-markør kører spilleren mejetærskeren derud og tømmer selv.
|
||||
-- Indstillingen contracts: 1 = til, 0 = fra. Ren logik øverst, spil-adapter nederst.
|
||||
|
||||
ADContracts = {}
|
||||
|
||||
@@ -13,6 +14,7 @@ ADContracts.SCAN_MS = 5000
|
||||
ADContracts.STAGES = {
|
||||
plow = "plowing", cultivate = "cultivating", sow = "sowing", weed = "weeding", hoe = "weeding",
|
||||
herbicide = "weeding", fertilize = "fertilizing", mow = "mowing", stonepick = "stonePicking", roll = "rolling",
|
||||
harvest = "harvesting",
|
||||
}
|
||||
|
||||
function ADContracts.stageFor(typeName)
|
||||
@@ -21,11 +23,23 @@ function ADContracts.stageFor(typeName)
|
||||
return ADContracts.STAGES[key]
|
||||
end
|
||||
|
||||
-- entries = {{id, placeable}} (AutoDrive-markører og bygningen deres aflæsning hører til) -> id'er ved placeable
|
||||
function ADContracts.markersAt(entries, placeable)
|
||||
local ids = {}
|
||||
if placeable == nil then return ids end
|
||||
for _, entry in ipairs(entries or {}) do
|
||||
if entry.placeable == placeable then table.insert(ids, entry.id) end
|
||||
end
|
||||
return ids
|
||||
end
|
||||
|
||||
-- tracked/running = {[nøgle] = {fieldId, ...}} -> startede, afsluttede (lister {key, ...})
|
||||
function ADContracts.diff(tracked, running)
|
||||
local started, ended = {}, {}
|
||||
for key, entry in pairs(running or {}) do
|
||||
if (tracked or {})[key] == nil then table.insert(started, {key = key, fieldId = entry.fieldId, stage = entry.stage, fruit = entry.fruit}) end
|
||||
if (tracked or {})[key] == nil then
|
||||
table.insert(started, {key = key, fieldId = entry.fieldId, stage = entry.stage, fruit = entry.fruit, mission = entry.mission})
|
||||
end
|
||||
end
|
||||
for key, entry in pairs(tracked or {}) do
|
||||
if (running or {})[key] == nil then table.insert(ended, {key = key, fieldId = entry.fieldId}) end
|
||||
@@ -55,6 +69,37 @@ local function fieldIdOf(mission)
|
||||
return field.getId ~= nil and field:getId() or field.fieldId
|
||||
end
|
||||
|
||||
-- Høstkontraktens salgssted (placeable). Feltnavnet er ikke dokumenteret (HarvestMission.lua mangler i spilkilden):
|
||||
-- sellingStation, ellers første felt med en aflæsningsstation, ellers savegame-id'et. Returnerer placeable, hvor fundet.
|
||||
local function sellPlaceableOf(mission)
|
||||
local station = mission.sellingStation
|
||||
local where = "sellingStation"
|
||||
if station == nil then
|
||||
for key, value in pairs(mission) do
|
||||
if type(value) == "table" and value.owningPlaceable ~= nil and value.unloadTriggers ~= nil then
|
||||
station, where = value, tostring(key)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
local placeable = station ~= nil and station.owningPlaceable or nil
|
||||
local uniqueId = mission.sellingStationPlaceableUniqueId
|
||||
if placeable == nil and uniqueId ~= nil and g_currentMission.placeableSystem.getPlaceableByUniqueId ~= nil then
|
||||
placeable, where = g_currentMission.placeableSystem:getPlaceableByUniqueId(uniqueId), "sellingStationPlaceableUniqueId"
|
||||
end
|
||||
return placeable, where
|
||||
end
|
||||
|
||||
-- AutoDrive-markører hvis aflæsning hører til salgsstedet.
|
||||
local function sellMarkerIds(adEnv, placeable, farmId)
|
||||
local entries = {}
|
||||
for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers() or {}) do
|
||||
local okStation, station = pcall(ADSmartPickup.getUnloadStationAtWayPointId, adEnv, marker.id, farmId)
|
||||
table.insert(entries, {id = marker.id, placeable = okStation and station ~= nil and station.owningPlaceable or nil})
|
||||
end
|
||||
return ADContracts.markersAt(entries, placeable)
|
||||
end
|
||||
|
||||
local function fruitNameOf(mission)
|
||||
local index = mission.fruitTypeIndex or mission.fruitType
|
||||
if type(index) ~= "number" or g_fruitTypeManager == nil then return nil end
|
||||
@@ -70,23 +115,36 @@ local function runningContracts(farmId)
|
||||
if mission.farmId == farmId and mission.status == MissionStatus.RUNNING then
|
||||
local stage = ADContracts.stageFor(mission.type ~= nil and mission.type.name or nil)
|
||||
local fieldId = stage ~= nil and fieldIdOf(mission) or nil
|
||||
if fieldId ~= nil then running[missionKey(mission)] = {fieldId = fieldId, stage = stage, fruit = fruitNameOf(mission)} end
|
||||
if fieldId ~= nil then
|
||||
running[missionKey(mission)] = {fieldId = fieldId, stage = stage, fruit = fruitNameOf(mission), mission = mission}
|
||||
end
|
||||
end
|
||||
end
|
||||
return running
|
||||
end
|
||||
|
||||
local function start(entry)
|
||||
local function start(adEnv, entry)
|
||||
ADContracts.tracked[entry.key] = {fieldId = entry.fieldId}
|
||||
ADContracts.fieldIds[entry.fieldId] = true
|
||||
-- kun kontraktens trin: slået til, intet efterfølgende trin (ADFieldJobs: contract -> done efter trinnet)
|
||||
local field = ADFieldModel.with(ADFieldModel.newField(entry.fieldId), {stage = entry.stage, kind = "bare", contract = true,
|
||||
plan = {mode = "auto", sow = entry.stage == "sowing", sowFruit = entry.fruit or ""}})
|
||||
local harvest = entry.stage == "harvesting"
|
||||
local changes = {stage = entry.stage, kind = harvest and "harvest" or "bare", contract = true,
|
||||
plan = {mode = "auto", sow = entry.stage == "sowing", sowFruit = entry.fruit or "", straw = "chop"}}
|
||||
if harvest and entry.mission ~= nil then
|
||||
-- høst: læssene skal til kontraktens salgssted (ADFieldWork.chooseStore)
|
||||
local placeable, where = sellPlaceableOf(entry.mission)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
changes.contractSellIds = placeable ~= nil and sellMarkerIds(adEnv, placeable, farmId) or {}
|
||||
ADFieldJobs.log(entry.fieldId, "høstkontrakt: salgssted %s (fundet via %s), %d AutoDrive-markør(er) ved det",
|
||||
placeable ~= nil and tostring(placeable.getName ~= nil and placeable:getName() or "?") or "ikke fundet",
|
||||
tostring(where), #changes.contractSellIds)
|
||||
end
|
||||
local field = ADFieldModel.with(ADFieldModel.newField(entry.fieldId), changes)
|
||||
ADFieldJobs.setField(field)
|
||||
ADFields.ownedAt = nil -- scan kontraktmarken med det samme
|
||||
local text = string.format("Kontrakt på F%s: moden %s marken", tostring(entry.fieldId),
|
||||
({plowing = "pløjer", cultivating = "kultiverer", sowing = "sår", weeding = "renser", fertilizing = "gøder",
|
||||
mowing = "slår", stonePicking = "plukker sten på", rolling = "tromler"})[entry.stage] or "bearbejder")
|
||||
mowing = "slår", stonePicking = "plukker sten på", rolling = "tromler", harvesting = "høster"})[entry.stage] or "bearbejder")
|
||||
ADFieldJobs.log(entry.fieldId, "%s (%s)", text, tostring(entry.key))
|
||||
ADFieldJobs.notify(text, false)
|
||||
end
|
||||
@@ -119,6 +177,6 @@ function ADContracts.tick(adEnv, nowMs)
|
||||
for _, entry in ipairs(started) do
|
||||
-- egen mark (kontrakt på egen jord findes ikke i FS25, men for en sikkerheds skyld): rør ikke spillerens plan
|
||||
local own = ADFieldJobs.state.fields[entry.fieldId]
|
||||
if own == nil or own.contract then start(entry) end
|
||||
if own == nil or own.contract then start(adEnv, entry) end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user