feat(marker): vejr (vent på tørvejr), påfyldning via AutoDrive LOAD+CP, beskeder i spillet; Start nu virker på bare marker
This commit is contained in:
@@ -31,12 +31,19 @@ end
|
||||
|
||||
-- Beslutning for én mark. assignments = sæt på marken ({phase, stage, helper}); kun sæt på det aktuelle
|
||||
-- trin tæller (en aflæsningsvogn på vej hjem fra høsten forstyrrer ikke kultiveringen).
|
||||
-- Svar: {action = "start"|"care"|"advance"|"dispatch"|"wait"|"none", role, count, helper, stage, care}.
|
||||
function ADFieldJobs.decide(field, info, assignments, now)
|
||||
-- env = {raining = bool}: vejrfølsomme trin (høst/slå/vend/riv/hø) sendes ikke ud i regn.
|
||||
-- Svar: {action = "start"|"care"|"advance"|"dispatch"|"wait"|"none", role, count, helper, stage, care, reason}.
|
||||
function ADFieldJobs.decide(field, info, assignments, now, env)
|
||||
local hasMarker = info ~= nil and info.markerId ~= nil
|
||||
local raining = env ~= nil and env.raining == true
|
||||
local kind = field.kind or (info ~= nil and info.kind) or "mowable"
|
||||
if field.stage == "ready" then
|
||||
if not ADFieldModel.shouldStart(field) then return {action = "none"} end
|
||||
if not hasMarker then return {action = "wait"} end
|
||||
local first = ADFieldModel.workStages(field.plan, info.kind, info.needs)[1]
|
||||
if raining and first ~= nil and ADFieldModel.isWeatherSensitive(first, field.plan, info.kind) then
|
||||
return {action = "wait", reason = "rain"}
|
||||
end
|
||||
return {action = "start"}
|
||||
end
|
||||
if not ADFieldModel.isWorking(field) then
|
||||
@@ -68,6 +75,9 @@ function ADFieldJobs.decide(field, info, assignments, now)
|
||||
end
|
||||
if not hasMarker then return {action = "wait"} end
|
||||
if (field.retryAt or 0) > now then return {action = "none"} end
|
||||
if raining and ADFieldModel.isWeatherSensitive(field.stage, field.plan, kind) then
|
||||
return {action = "wait", reason = "rain"}
|
||||
end
|
||||
return {action = "dispatch", role = ADFieldModel.roleFor(field.stage), count = ADFieldModel.maxRigs(field.stage, field.plan), helper = false}
|
||||
end
|
||||
-- hovedsættene arbejder: fyld op med hjælpere (aflæsningsvogne) en ad gangen
|
||||
@@ -166,6 +176,25 @@ function ADFieldJobs.stopField(adEnv, id)
|
||||
ADFieldJobs.log(id, "stoppet fra menuen")
|
||||
end
|
||||
|
||||
-- Besked i spillet (højre side). critical = rød. Samme tekst vises kun én gang i træk.
|
||||
function ADFieldJobs.notify(text, critical)
|
||||
if ADFieldJobs.lastNotice == text then return end
|
||||
ADFieldJobs.lastNotice = text
|
||||
pcall(function()
|
||||
local kind = critical and FSBaseMission.INGAME_NOTIFICATION_CRITICAL or FSBaseMission.INGAME_NOTIFICATION_OK
|
||||
g_currentMission:addIngameNotification(kind, "Smart Pickup: " .. text)
|
||||
end)
|
||||
end
|
||||
|
||||
-- Vejret lige nu (regn), læst en gang pr. tick.
|
||||
function ADFieldJobs.environment()
|
||||
local ok, raining = pcall(function()
|
||||
local weather = g_currentMission.environment.weather
|
||||
return weather ~= nil and weather.getIsRaining ~= nil and weather:getIsRaining() or false
|
||||
end)
|
||||
return {raining = ok and raining == true}
|
||||
end
|
||||
|
||||
-- Seneste beslutning pr. mark (GUI viser pleje-behov og grunde).
|
||||
ADFieldJobs.lastDecision = {}
|
||||
|
||||
@@ -174,7 +203,7 @@ local function stepField(adEnv, info)
|
||||
ADFieldJobs.setField(field)
|
||||
local assignments = ADFieldJobs.assignmentsFor(info.id)
|
||||
for _, done in ipairs(finishedFor(info.id)) do table.insert(assignments, done) end
|
||||
local decision = ADFieldJobs.decide(field, info, assignments, ADFieldJobs.now)
|
||||
local decision = ADFieldJobs.decide(field, info, assignments, ADFieldJobs.now, ADFieldJobs.environment())
|
||||
ADFieldJobs.lastDecision[info.id] = decision
|
||||
if decision.action == "start" then
|
||||
local started = ADFieldModel.start(field, info.kind, info.needs)
|
||||
@@ -192,7 +221,14 @@ local function stepField(adEnv, info)
|
||||
ADFieldJobs.forgetFinished(info.id)
|
||||
ADFieldWork.windDownHelpers(adEnv, info.id, field.stage)
|
||||
ADFieldJobs.log(info.id, "%s -> %s", field.stage, nextField.stage)
|
||||
if nextField.stage == "done" or (ADFieldModel.isCare(field.stage) and nextField.stage == "idle") then
|
||||
ADFieldJobs.notify(string.format("F%d %s", info.id, g_i18n ~= nil and g_i18n:getText("spu_field_notice_done") or "done"), false)
|
||||
end
|
||||
ADFieldJobs.save()
|
||||
elseif decision.action == "wait" and decision.reason == "rain" then
|
||||
if field.reason == nil or field.reason.key ~= "spu_field_reason_rain" then
|
||||
ADFieldJobs.note(info.id, {reason = {key = "spu_field_reason_rain"}})
|
||||
end
|
||||
elseif decision.action == "dispatch" then
|
||||
ADFieldWork.dispatch(adEnv, field, info, decision)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user