diff --git a/CHANGELOG.md b/CHANGELOG.md index 22854ae..4ceb0a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ står i [docs/BRUGERMANUAL.md](docs/BRUGERMANUAL.md) (dansk) og [docs/USER_MANUA ## 1.62 — Kæder slås selv til +- **1.62.135** Kørslernes kilder og mål gemmes nu også med markørens NAVN (runs.xml: sourceNames/targetNames). Sletter eller flytter spilleren vejpunkter i AutoDrive, omnummereres alle senere punkter, og et gemt id peger på et tilfældigt punkt; modden følger nu navnet og logger "markøren er flyttet (vejpunkt a -> b) — fulgt". In-game 10/10: æg-runden mistede alle 7 kilder, Milk Run 2, "gra&s to Hay" sit mål, mens vejnettet blev rettet live. - **1.62.134** Genindlæsning: et puljesæt (traktor med puljeredskab), hvis gemte Courseplay-kursus ikke hører til en mark i gang med dets rolle, genstartes ikke længere, men sendes hjem. In-game 10/10: 6230 TTV 5 med læssevogn fra F13 (færdig kl. 21:19) blev genstartet ved hver genindlæsning og kørte det gamle kursus over F11 under såning. - **1.62.133** Marksilo: en vogn med last, der efter en genindlæsning holder ved et Wait-punkt (lageret var fuldt før gemningen, og ventetilstanden gik tabt), sendes nu videre til et lager med plads. In-game 10/10: 6230 TTV 7 stod ved Sheep Wait 3 med 52.000 l TMR. - **1.62.132** Ny konsolkommando `spuForgetCourses ` (uden argument: alle marker): glemmer de gemte Courseplay-kurser, så næste start beregner nyt. Til marker, der har fået bygninger: formen ændres ikke, så kurset blev genbrugt og gik gennem bygningerne (in-game 9/10). diff --git a/FS25_ADSmartPickup/adRuns.lua b/FS25_ADSmartPickup/adRuns.lua index 8fec3a6..3faf3b0 100644 --- a/FS25_ADSmartPickup/adRuns.lua +++ b/FS25_ADSmartPickup/adRuns.lua @@ -92,6 +92,7 @@ local function copyRun(run) name = run.name, kind = run.kind, sourceWayPointIds = copyList(run.sourceWayPointIds), + sourceNames = copyList(run.sourceNames), sourceBuildingIds = copyList(run.sourceBuildingIds), targetBuildingIds = copyList(run.targetBuildingIds), storeBuildingIds = copyList(run.storeBuildingIds), @@ -103,6 +104,7 @@ local function copyRun(run) collectRound = run.collectRound, targetWayPointId = run.targetWayPointId, targetWayPointIds = copyList(run.targetWayPointIds), + targetNames = copyList(run.targetNames), ingredientMode = run.ingredientMode, ingredients = copyList(run.ingredients), waitPoolGroup = run.waitPoolGroup, @@ -145,6 +147,7 @@ function ADRuns.createRun(store, name, kind) name = name, kind = ADRuns.KINDS[kind] and kind or "supply", sourceWayPointIds = {}, + sourceNames = {}, sourceBuildingIds = {}, targetBuildingIds = {}, storeBuildingIds = {}, @@ -156,6 +159,7 @@ function ADRuns.createRun(store, name, kind) collectRound = false, targetWayPointId = nil, targetWayPointIds = {}, + targetNames = {}, ingredientMode = "auto", ingredients = {}, waitPoolGroup = "", @@ -207,6 +211,10 @@ function ADRuns.updateRun(store, runId, changes) run.targetWayPointIds = {changes.targetWayPointId} end run.targetWayPointId = run.targetWayPointIds[1] + if changes.targetNames ~= nil then run.targetNames = copyList(changes.targetNames) + elseif changes.targetWayPointIds ~= nil or changes.targetWayPointId ~= nil then run.targetNames = {} end + if changes.sourceNames ~= nil then run.sourceNames = copyList(changes.sourceNames) + elseif changes.sourceWayPointIds ~= nil then run.sourceNames = {} end if ADRuns.INGREDIENT_MODES[changes.ingredientMode] then run.ingredientMode = changes.ingredientMode end if changes.ingredients ~= nil then run.ingredients = copyList(changes.ingredients) end if changes.waitPoolGroup ~= nil then run.waitPoolGroup = changes.waitPoolGroup end @@ -435,6 +443,34 @@ function ADRuns.parseIngredients(text) end -- Flade poster (kun strenge/tal) til XML-laget, i store'ens rækkefølge. +-- Markørnavne gemt ved siden af vejpunkt-id'erne ("a|b|c" -> liste). AutoDrive omnummererer alle senere vejpunkter, +-- når spilleren sletter et, så et gemt id kan pege på et tilfældigt punkt (in-game 10/10: æg-runden mistede alle +-- 7 kilder, mælk 2, græs-til-hø sit mål, mens spilleren rettede vejnettet). +function ADRuns.splitNames(text) + local names = {} + for token in string.gmatch(tostring(text or ""), "[^|]+") do table.insert(names, token) end + return names +end + +-- ids + names (parallelle lister) -> nye ids: står markøren med det gemte navn ikke længere på id'et, følges navnet. +-- idOfName(name) -> id | nil; nameOfId(id) -> navn | nil. -> nye ids, flytninger {{name, from, to}} +function ADRuns.remapByName(ids, names, idOfName, nameOfId) + local result, moves = {}, {} + for index, id in ipairs(ids or {}) do + local wanted = names ~= nil and names[index] or nil + local newId = id + if wanted ~= nil and wanted ~= "" and nameOfId(id) ~= wanted then + local found = idOfName(wanted) + if found ~= nil and found ~= id then + newId = found + table.insert(moves, {name = wanted, from = id, to = found}) + end + end + table.insert(result, newId) + end + return result, moves +end + function ADRuns.toRecords(store) local records = {} for index, run in ipairs(store.runs) do @@ -451,6 +487,8 @@ function ADRuns.toRecords(store) vehicleIds = copyList(run.vehicleIds), kind = run.kind, sources = table.concat(run.sourceWayPointIds or {}, " "), + sourceNames = table.concat(run.sourceNames or {}, "|"), + targetNames = table.concat(run.targetNames or {}, "|"), sourceBuildings = table.concat(run.sourceBuildingIds or {}, " "), targetBuildings = table.concat(run.targetBuildingIds or {}, " "), storeBuildings = table.concat(run.storeBuildingIds or {}, " "), @@ -500,6 +538,8 @@ function ADRuns.fromRecords(records) name = record.name, kind = ADRuns.KINDS[record.kind] and record.kind or "supply", sourceWayPointIds = sources, + sourceNames = ADRuns.splitNames(record.sourceNames), + targetNames = ADRuns.splitNames(record.targetNames), sourceBuildingIds = parseIds(record.sourceBuildings), targetBuildingIds = parseIds(record.targetBuildings), storeBuildingIds = parseIds(record.storeBuildings), diff --git a/FS25_ADSmartPickup/adRunsController.lua b/FS25_ADSmartPickup/adRunsController.lua index bc9dbee..e60ed70 100644 --- a/FS25_ADSmartPickup/adRunsController.lua +++ b/FS25_ADSmartPickup/adRunsController.lua @@ -483,6 +483,21 @@ function ADRunsController.resolveMarkers(adEnv, run) local role = run.kind == "outbound" and "load" or "unload" local buildingIds = run.kind == "outbound" and run.sourceBuildingIds or run.targetBuildingIds local existing = run.kind == "outbound" and run.sourceWayPointIds or ADRunsController.getRunTargets(run) + -- gemte markørnavne følges, når AutoDrive har omnummereret vejpunkterne (spilleren sletter/flytter punkter live) + local graph = adEnv.ADGraphManager + local storedNames = run.kind == "outbound" and run.sourceNames or run.targetNames + if storedNames ~= nil and #storedNames > 0 and graph ~= nil and graph.getMapMarkerByWayPointId ~= nil then + local byName = {} + for _, marker in pairs(graph:getMapMarkers() or {}) do + if marker.name ~= nil and byName[marker.name] == nil then byName[marker.name] = marker.id end + end + local moves + existing, moves = ADRuns.remapByName(existing, storedNames, function(name) return byName[name] end, + function(id) local marker = graph:getMapMarkerByWayPointId(id) return marker ~= nil and marker.name or nil end) + for _, move in ipairs(moves) do + Logging.info(ADRunsController.LOG_PREFIX .. "run '%s': markøren '%s' er flyttet (vejpunkt %d -> %d) — fulgt", tostring(run.name), tostring(move.name), move.from, move.to) + end + end local resolved, seen = {}, {} for _, buildingId in ipairs(buildingIds or {}) do local building = ADBuildings.find(adEnv, farmId, buildingId) @@ -533,12 +548,20 @@ function ADRunsController.resolveMarkers(adEnv, run) if #pruned > 0 then Logging.info(ADRunsController.LOG_PREFIX .. "run '%s': gamle markører fjernet (ingen kilde eller dublet af valgt bygning): %s", tostring(run.name), table.concat(pruned, " ")) end - if not listEquals(resolved, existing or {}) then - local changes = run.kind == "outbound" and {sourceWayPointIds = resolved} or {targetWayPointIds = resolved} + -- navnene gemmes sammen med id'erne, så de kan følges efter en omnummerering + local names = {} + for _, wayPointId in ipairs(resolved) do + local marker = graph ~= nil and graph.getMapMarkerByWayPointId ~= nil and graph:getMapMarkerByWayPointId(wayPointId) or nil + table.insert(names, marker ~= nil and tostring(marker.name) or "") + end + local current = run.kind == "outbound" and run.sourceWayPointIds or ADRunsController.getRunTargets(run) + if not listEquals(resolved, current or {}) or not listEquals(names, storedNames or {}) then + local changes = run.kind == "outbound" and {sourceWayPointIds = resolved, sourceNames = names} or {targetWayPointIds = resolved, targetNames = names} ADRunsController.store = ADRuns.updateRun(ADRunsController.store, run.id, changes) local updated = ADRuns.getRun(ADRunsController.store, run.id) if updated ~= nil then run.sourceWayPointIds, run.targetWayPointIds, run.targetWayPointId = updated.sourceWayPointIds, updated.targetWayPointIds, updated.targetWayPointId + run.sourceNames, run.targetNames = updated.sourceNames, updated.targetNames end end return {missing = missing} diff --git a/FS25_ADSmartPickup/adRunsStorage.lua b/FS25_ADSmartPickup/adRunsStorage.lua index 2fc8afe..69063b4 100644 --- a/FS25_ADSmartPickup/adRunsStorage.lua +++ b/FS25_ADSmartPickup/adRunsStorage.lua @@ -39,6 +39,9 @@ function ADRunsStorage.writeRecords(xmlFile, records) -- v2: udkørsel xmlFile:setString(key .. "#kind", record.kind or "supply") xmlFile:setString(key .. "#sources", record.sources or "") + -- v4: markørnavne (følger markøren, når AutoDrive omnummererer vejpunkter) + xmlFile:setString(key .. "#sourceNames", record.sourceNames or "") + xmlFile:setString(key .. "#targetNames", record.targetNames or "") -- v3: bygninger (flow-tavlen) xmlFile:setString(key .. "#sourceBuildings", record.sourceBuildings or "") xmlFile:setString(key .. "#targetBuildings", record.targetBuildings or "") @@ -75,6 +78,8 @@ function ADRunsStorage.readRecords(xmlFile) returnBelow = xmlFile:getInt(key .. "#returnBelow"), kind = xmlFile:getString(key .. "#kind"), sources = xmlFile:getString(key .. "#sources"), + sourceNames = xmlFile:getString(key .. "#sourceNames"), + targetNames = xmlFile:getString(key .. "#targetNames"), sourceBuildings = xmlFile:getString(key .. "#sourceBuildings"), targetBuildings = xmlFile:getString(key .. "#targetBuildings"), storeBuildings = xmlFile:getString(key .. "#storeBuildings"), diff --git a/FS25_ADSmartPickup/modDesc.xml b/FS25_ADSmartPickup/modDesc.xml index 7025dea..a558c0d 100644 --- a/FS25_ADSmartPickup/modDesc.xml +++ b/FS25_ADSmartPickup/modDesc.xml @@ -1,7 +1,7 @@ masterdraco - 1.62.134.0 + 1.62.135.0 <en>AD Smart Pickup</en>