diff --git a/betterContracts.lua b/betterContracts.lua
index 453987f..03c896f 100644
--- a/betterContracts.lua
+++ b/betterContracts.lua
@@ -24,6 +24,8 @@
-- allow clear/new contracts button only for master user
-- lazyNPC / maxActive contracts now configurable
-- v.1.2.4.2 19.09.2022 [ModHub] recognize FS22_DynamicMissionVehicles
+-- v.1.2.4.3 10.10.2022 recognize FS22_LimeMission, RollerMission. Add lazyNPC switch for weed
+-- delete config.xml file template from mod directory
--=======================================================================================================
SC = {
FERTILIZER = 1, -- prices index
@@ -120,11 +122,14 @@ function BetterContracts:initialize()
addMapping("spray", SC.SPREAD)
addMapping("fertilize", SC.SPREAD)
addMapping("transport", SC.TRANSP)
- addMapping("supplyTransport", SC.SUPPLY)
- addMapping("deadwood", SC.OTHER)
- addMapping("treeTransport", SC.OTHER)
+ addMapping("supplyTransport", SC.SUPPLY) -- mod by GtX
+ addMapping("deadwood", SC.OTHER) -- Platinum DLC mission by Giants
+ addMapping("treeTransport", SC.OTHER) -- Platinum DLC mission by Giants
+ addMapping("roll", SC.SIMPLE) -- roller mission by tn4799
+ addMapping("lime", SC.SPREAD) -- lime mission by Mmtrx
+
self.harvest = {} -- harvest missions 1
- self.spread = {} -- sow, spray, fertilize 2
+ self.spread = {} -- sow, spray, fertilize, lime 2
self.simple = {} -- plow, cultivate, weed 3
self.mow_bale = {} -- mow/ bale 4
self.transp = {} -- transport 5
@@ -134,7 +139,7 @@ function BetterContracts:initialize()
self.fieldToMission = {} -- to find a contract from its field number
self.catHarvest = "BEETHARVESTING BEETVEHICLES CORNHEADERS COTTONVEHICLES CUTTERS POTATOHARVESTING POTATOVEHICLES SUGARCANEHARVESTING SUGARCANEVEHICLES"
self.catSpread = "fertilizerspreaders seeders planters sprayers sprayervehicles slurrytanks manurespreaders"
- self.catSimple = "CULTIVATORS DISCHARROWS PLOWS POWERHARROWS SUBSOILERS WEEDERS"
+ self.catSimple = "CULTIVATORS DISCHARROWS PLOWS POWERHARROWS SUBSOILERS WEEDERS ROLLERS"
self.isOn = false
self.numCont = 0 -- # of contracts in our tables
self.numHidden = 0 -- # of hidden (filtered) contracts
@@ -148,9 +153,11 @@ function BetterContracts:initialize()
}
self.npcProb = {
harvest = 1.0,
- plowCultivate = 0.3,
- sow = 0.3,
- fertilize = 0.3
+ plowCultivate = 0.5,
+ sow = 0.5,
+ fertilize = 0.9,
+ weed = 0.9,
+ lime = 0.9
}
self.npcType = {}
self.lazyNPC = false -- adjust NPC field work activity
@@ -195,8 +202,8 @@ function BetterContracts:initialize()
Utility.appendedFunction(InGameMenuContractsFrame, "startContract", startContract)
Utility.appendedFunction(InGameMenu, "updateButtonsPanel", updateButtonsPanel)
if self.debug then
- addConsoleCommand("printBetterContracts", "Print detail stats for all available missions.", "consoleCommandPrint", self)
- addConsoleCommand("gsFieldGenerateMission", "Force generating a new mission for given field", "consoleGenerateFieldMission", g_missionManager)
+ addConsoleCommand("bcprint", "Print detail stats for all available missions.", "consoleCommandPrint", self)
+ addConsoleCommand("bcFieldGenerateMission", "Force generating a new mission for given field", "consoleGenerateFieldMission", g_missionManager)
addConsoleCommand("gsMissionLoadAllVehicles", "Loading and unloading all field mission vehicles", "consoleLoadAllFieldMissionVehicles", g_missionManager)
addConsoleCommand("gsMissionHarvestField", "Harvest a field and print the liters", "consoleHarvestField", g_missionManager)
addConsoleCommand("gsMissionTestHarvests", "Run an expansive tests for harvest missions", "consoleHarvestTests", g_missionManager)
@@ -207,7 +214,8 @@ function checkOtherMods(self)
FS22_RefreshContracts = "needsRefreshContractsConflictsPrevention",
FS22_Contracts_Plus = "preventContractsPlus",
FS22_SupplyTransportContracts = "supplyTransport",
- FS22_DynamicMissionVehicles = "dynamicVehicles"
+ FS22_DynamicMissionVehicles = "dynamicVehicles",
+ FS22_LimeMission = "limeMission"
}
for mod, switch in pairs(mods) do
if g_modIsLoaded[mod] then
@@ -219,8 +227,22 @@ end
function readconfig(self)
-- check for config file in modSettings/
self.configFile = self.modSettings .. self.name..'.xml'
- if not fileExists(self.configFile) then -- copy initial config file to /modSettings
- copyFile(self.directory.."config.xml", self.configFile, true)
+ if not fileExists(self.configFile) then
+ -- create initial config file in /modSettings
+ local config = {
+ '',
+ '',
+ '',
+ ' ',
+ ' ',
+ '',
+ }
+ local f = createFile(self.configFile, FileAccess.WRITE)
+ for _, line in ipairs(config) do
+ fileWrite(f, line.."\n")
+ end
+ delete(f)
Logging.info("[%s] wrote initial config file %s", self.name, self.configFile)
end
-- read config parms:
@@ -237,6 +259,7 @@ function readconfig(self)
self.npcType.plowCultivate =Utils.getNoNil(getXMLBool(xmlFile, key.."#plowCultivate"), false)
self.npcType.sow = Utils.getNoNil(getXMLBool(xmlFile, key.."#sow"), false)
self.npcType.fertilize = Utils.getNoNil(getXMLBool(xmlFile, key.."#fertilize"), false)
+ self.npcType.weed = Utils.getNoNil(getXMLBool(xmlFile, key.."#weed"), false)
end
delete(xmlFile)
end
@@ -251,6 +274,11 @@ function BetterContracts:onSetMissionInfo(missionInfo, missionDynamicInfo)
Utility.overwrittenFunction(g_currentMission.inGameMenu, "onClickMenuExtra2", onClickMenuExtra2)
end
+function BetterContracts:onStartMission()
+ -- check mission vehicles
+ BetterContracts:validateMissionVehicles()
+end
+
function BetterContracts:onPostLoadMap(mapNode, mapFile)
-- adjust max missions
local fieldsAmount = TableUtility.count(g_fieldManager.fields)
@@ -293,6 +321,7 @@ function BetterContracts:onPostLoadMap(mapNode, mapFile)
Logging.warning("[%s] ignoring new mission type %s (id %s)", self.name,
g_missionManager.missionTypes[i].name, i)
end
+
-- load my gui xmls
if not self:loadGUI(true, self.directory .. "gui/") then
Logging.warning("'%s.Gui' failed to load! Supporting files are missing.", self.name)
@@ -314,7 +343,6 @@ function BetterContracts:onPostLoadMap(mapNode, mapFile)
local profit = rewd:clone(self.frCon.contractsList.cellDatabase.autoCell1)
profit.name = "profit"
profit:setPosition(-110/1920 *g_aspectScaleX, -12/1080 *g_aspectScaleY) --
- --profit:setTextColor(1, 1, 1, 1)
profit.textBold = false
profit:setVisible(false)
-- set controls for npcbox, sortbox and their elements:
@@ -342,19 +370,12 @@ function BetterContracts:onPostLoadMap(mapNode, mapFile)
return a[3] < b[3]
end)
self.fieldjobs[9] = {9,"transport", g_i18n:getText("bc_other")}
+
+ self.filterState = {}
-- initial state: show all types
- self.filterState = {
- mow_bale = true,
- cultivate = true,
- fertilize = true,
- harvest = true,
- plow = true,
- sow = true,
- spray = true,
- weed = true,
- transport = true,
- supplyTransport = true
- }
+ for i, type in ipairs(g_missionManager.missionTypes) do
+ self.filterState[type.name] = true
+ end
-- set controls for filterbox:
self.my.filterlayout = self.frCon.contractsContainer:getDescendantById("filterlayout")
self.my.hidden = self.frCon.contractsContainer:getDescendantById("hidden")
@@ -605,25 +626,25 @@ function abstractMissionNew(isServer, superf, isClient, customMt )
return self
end
function NPCHarvest(self, superf, field, allowUpdates)
- if not allowUpdates then
+ if not allowUpdates or BetterContracts.fieldToMission[field.fieldId] == nil then
superf(self, field, allowUpdates)
return
end
- local npc = BetterContracts.npcType
- local prob= BetterContracts.npcProb
- local fruitDesc, harvestReadyState, maxHarvestState, area, total
+ -- there is a mission offered for this field, and
+ local npc = BetterContracts.npcType
+ local prob = BetterContracts.npcProb
+ local limeMiss = BetterContracts.limeMission
+ local fruitDesc, harvestReadyState, maxHarvestState, area, total, withered
local x, z = FieldUtil.getMeasurementPositionOfField(field)
if field.fruitType ~= nil then
-
+ -- not an empty field
fruitDesc = g_fruitTypeManager:getFruitTypeByIndex(field.fruitType)
- -- leave a withered field for plow/ grubber missions
- --[[
- local withered = fruitDesc.witheredState
- if withered ~= nil then
- area, total = FieldUtil.getFruitArea(x - 1, z - 1, x + 1, z - 1, x - 1, z + 1, FieldUtil.FILTER_EMPTY, FieldUtil.FILTER_EMPTY, field.fruitType, withered, withered, 0, 0, 0, false)
- if area > 0.5*total and math.random() < 0.3 then return end
+
+ local witheredState = fruitDesc.witheredState
+ if witheredState ~= nil then
+ area, total = FieldUtil.getFruitArea(x - 1, z - 1, x + 1, z - 1, x - 1, z + 1, FieldUtil.FILTER_EMPTY, FieldUtil.FILTER_EMPTY, field.fruitType, witheredState, witheredState, 0, 0, 0, false)
+ withered = area > 0.5 * total
end
- ]]
if npc.harvest then
-- don't let NPCs harvest
harvestReadyState = fruitDesc.maxHarvestingGrowthState
@@ -633,18 +654,35 @@ function NPCHarvest(self, superf, field, allowUpdates)
maxHarvestState = FieldUtil.getMaxHarvestState(field, field.fruitType)
if maxHarvestState == harvestReadyState then return end
end
-
+ if npc.weed and not withered then
+ -- leave field with weeds for weeding/ spraying
+ local maxWeedState = FieldUtil.getMaxWeedState(field)
+ if maxWeedState >= 3 and math.random() < prob.weed then return
+ end
+ end
if npc.plowCultivate then
- -- leave a cut field for plow/ grubber mission
+ -- leave a cut field for plow/ grubber/ lime mission
area, total = FieldUtil.getFruitArea(x - 1, z - 1, x + 1, z - 1, x - 1, z + 1, FieldUtil.FILTER_EMPTY, FieldUtil.FILTER_EMPTY, field.fruitType, fruitDesc.cutState, fruitDesc.cutState, 0, 0, 0, false)
if area > 0.5 * total and
- g_currentMission.snowSystem.height < SnowSystem.MIN_LAYER_HEIGHT and
- math.random() < prob.plowCultivate then return end
+ g_currentMission.snowSystem.height < SnowSystem.MIN_LAYER_HEIGHT then
+ local limeFactor = FieldUtil.getLimeFactor(field)
+ if limeMiss and limeFactor == 0 and math.random() < prob.lime then return
+ elseif math.random() < prob.plowCultivate then return
+ end
+ end
+ end
+ if npc.fertilize and not withered then
+ local sprayFactor = FieldUtil.getSprayFactor(field)
+ if sprayFactor < 1 and math.random() < prob.fertilize then return
+ end
end
elseif npc.sow then
- -- leave empty (plowed/grubbered) field for sow mission
- if self:getFruitIndexForField(field) ~= nil and
- math.random() < prob.sow then return end
+ -- leave empty (plowed/grubbered) field for sow/ lime mission
+ local limeFactor = FieldUtil.getLimeFactor(field)
+ if limeMiss and limeFactor == 0 and math.random() < prob.lime then return
+ elseif self:getFruitIndexForField(field) ~= nil and
+ math.random() < prob.sow then return
+ end
end
superf(self, field, allowUpdates)
end
diff --git a/config.xml b/config.xml
deleted file mode 100644
index 3712716..0000000
--- a/config.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
diff --git a/gui/filterGui.xml b/gui/filterGui.xml
index e65fad8..a452407 100644
--- a/gui/filterGui.xml
+++ b/gui/filterGui.xml
@@ -39,5 +39,5 @@
-
+
diff --git a/l10n/l10n_ru.xml b/l10n/l10n_ru.xml
index e26dc12..1acdde3 100644
--- a/l10n/l10n_ru.xml
+++ b/l10n/l10n_ru.xml
@@ -13,9 +13,8 @@
-
-
-
+
+
diff --git a/modDesc.xml b/modDesc.xml
index 41823e2..bb305ef 100644
--- a/modDesc.xml
+++ b/modDesc.xml
@@ -1,7 +1,7 @@
Mmtrx
- 1.2.4.2
+ 1.2.4.3
Better Contracts
diff --git a/scripts/gui.lua b/scripts/gui.lua
index 39e5eb5..d3532a8 100644
--- a/scripts/gui.lua
+++ b/scripts/gui.lua
@@ -58,6 +58,9 @@ function BetterContracts:loadGUI(canLoad, guiPath)
layout:applyScreenAlignment()
layout:updateAbsolutePosition()
layout:invalidateLayout(true) -- adjust filter buttons
+ local hidden = cont:getDescendantById("hidden")
+ hidden:applyScreenAlignment()
+ hidden:updateAbsolutePosition()
delete(xmlFile)
else
canLoad = false
@@ -247,21 +250,16 @@ function filterList(typeId, show)
-- contracts list is already there. Needs some adjustments only
local self = BetterContracts
local frCon = self.frCon
- local mycats = {"harvest", "spread", "simple","mow_bale","transp", "supply"}
- local mycat = mycats[self.typeToCat[typeId]]
local type = g_missionManager:getMissionTypeById(typeId)
- local nofilter, multi
- debugPrint("*filterList - show: %s, mycat: %s, type.name %s",
- show, mycat, type.name)
+ local nofilter
+ debugPrint("*filterList - show %s: %s", type.name, show)
if show then
-- re-insert filtered contracts:
- for _, c in ipairs(self[mycat]) do
- nofilter = c.miss.status == AbstractMission.STATUS_RUNNING or
- c.miss.status == AbstractMission.STATUS_FINISHED
- -- harvest/mow/transp lists contain only one fieldjob type:
- multi = mycat=="simple" or mycat=="spread"
- if not nofilter and (not multi or c.miss.type == type) then
- table.insert(frCon.contracts, makeCon(c.miss))
+ for _, m in ipairs(g_missionManager:getMissionsList(g_currentMission:getFarmId())) do
+ nofilter = m.status == AbstractMission.STATUS_RUNNING or
+ m.status == AbstractMission.STATUS_FINISHED
+ if not nofilter and m.type == type then
+ table.insert(frCon.contracts, makeCon(m))
self.numHidden = self.numHidden -1
end
end
@@ -620,17 +618,20 @@ function onClickFilterButton(frCon, button)
debugPrint("*** Filter button %s: state %s, type %d %s", button.id,
button.pressed, typeId, type)
button.pressed = not button.pressed
- self.filterState[type] = button.pressed
local prof = "myFilterDynamicTextInactive"
if button.pressed then prof = "myFilterDynamicText" end
button.elements[1]:applyProfile(prof)
+ self.filterState[type] = button.pressed
filterList(typeId, button.pressed)
-- if button "Other" clicked:
- if self.supplyTransport and typeId == 9 then -- also handle type 10 supplyTransport:
- self.filterState.supplyTransport = button.pressed
- filterList(10, button.pressed)
+ if typeId == 9 then -- also handle all other mission types:
+ for i = 10, TableUtility.count(self.filterState) do
+ local name = g_missionManager:getMissionTypeById(i).name
+ self.filterState[name] = button.pressed
+ filterList(i, button.pressed)
+ end
end
end
function onClickSortButton(frCon, button)
diff --git a/scripts/missionVehicles.lua b/scripts/missionVehicles.lua
index dc219d8..5942da1 100644
--- a/scripts/missionVehicles.lua
+++ b/scripts/missionVehicles.lua
@@ -16,236 +16,243 @@
---@param missionManager MissionManager
---@param superFunc function
---@return boolean
-function BetterContracts.loadMissionVehicles(missionManager, superFunc, ...)
- local self = BetterContracts
- debugPrint("* %s loadMissionVehicles()", self.name)
- if superFunc(missionManager, ...) then
- if g_modIsLoaded["FS19_ThueringerHoehe_BG_Edition"] then
- debugPrint("[%s] %s map detected, loading mission vehicles created by %s", self.name, "FS19_ThueringerHoehe", "Lahmi")
- missionManager.missionVehicles = {}
- self:loadExtraMissionVehicles(self.directory .. "missionVehicles/FS19_ThueringerHoehe/baseGame.xml")
- else
- if self.debug then
- self:checkExtraMissionVehicles(self.directory .. "missionVehicles/baseGame.xml")
- end
- self:loadExtraMissionVehicles(self.directory .. "missionVehicles/baseGame.xml")
- -- self:loadExtraMissionVehicles(self.directory .. "missionVehicles/claasPack.xml")
- end
- local userdef = self.directory .. "missionVehicles/userDefined.xml"
- if fileExists(userdef) and self:checkExtraMissionVehicles(userdef) then
- -- check for other mod:
- if g_modIsLoaded.FS22_DynamicMissionVehicles then
- Logging.warning("[%s] userDefined.xml not loaded. Incompatible with FS22_DynamicMissionVehicles",
- self.name)
- else
- self:loadExtraMissionVehicles(userdef)
- end
- end
- self:validateMissionVehicles()
- return true
- end
- return false
+function BetterContracts.loadMissionVehicles(missionManager, superFunc, xmlFilename, baseDirectory)
+ -- this could be called multiple times: by mods, dlcs
+ local self = BetterContracts
+ debugPrint("* %s loadMissionVehicles(%s, %s)", self.name, xmlFilename, baseDirectory)
+ if superFunc(missionManager, xmlFilename, baseDirectory) then
+ --[[
+ if g_modIsLoaded["FS19_ThueringerHoehe_BG_Edition"] then
+ debugPrint("[%s] %s map detected, loading mission vehicles created by %s", self.name, "FS19_ThueringerHoehe", "Lahmi")
+ missionManager.missionVehicles = {}
+ self:loadExtraMissionVehicles(self.directory .. "missionVehicles/FS19_ThueringerHoehe/baseGame.xml")
+ else
+ ]]
+ if self.loadedVehicles then return true end
+
+ if self.debug then
+ self:checkExtraMissionVehicles(self.directory .. "missionVehicles/baseGame.xml")
+ end
+ self:loadExtraMissionVehicles(self.directory .. "missionVehicles/baseGame.xml")
+ -- self:loadExtraMissionVehicles(self.directory .. "missionVehicles/claasPack.xml")
+ self.loadedVehicles = true
+ --end
+ local userdef = self.directory .. "missionVehicles/userDefined.xml"
+ if fileExists(userdef) and self:checkExtraMissionVehicles(userdef) then
+ -- check for other mod:
+ if g_modIsLoaded.FS22_DynamicMissionVehicles then
+ Logging.warning("[%s] userDefined.xml not loaded. Incompatible with FS22_DynamicMissionVehicles",
+ self.name)
+ else
+ self:loadExtraMissionVehicles(userdef)
+ end
+ end
+ return true
+ end
+ return false
end
function BetterContracts:validateMissionVehicles()
- -- check if vehicle groups for each missiontype/fieldsize are defined
- local type
- for _,mt in ipairs(g_missionManager.missionTypes) do
- if mt.category == MissionManager.CATEGORY_FIELD or
- mt.category == MissionManager.CATEGORY_GRASS_FIELD then
- type = mt.name
- for _,f in ipairs({"small","medium","large"}) do
- if g_missionManager.missionVehicles[type][f] == nil or
- #g_missionManager.missionVehicles[type][f] == 0 then
- Logging.warning("[%s] No missionVehicles for %s missions on %s fields",
- self.name, type, f)
- end
- end
- end
- end
+ -- check if vehicle groups for each missiontype/fieldsize are defined
+ debugPrint("* %s validating Mission Vehicles..", self.name)
+ local type
+ for _,mt in ipairs(g_missionManager.missionTypes) do
+ if mt.category == MissionManager.CATEGORY_FIELD or
+ mt.category == MissionManager.CATEGORY_GRASS_FIELD then
+ type = mt.name
+ for _,f in ipairs({"small","medium","large"}) do
+ if g_missionManager.missionVehicles[type] == nil or
+ g_missionManager.missionVehicles[type][f] == nil or
+ #g_missionManager.missionVehicles[type][f] == 0 then
+ Logging.warning("[%s] No missionVehicles for %s missions on %s fields",
+ self.name, type, f)
+ end
+ end
+ end
+ end
end
function BetterContracts:checkExtraMissionVehicles(xmlFilename)
- -- check if all vehicles specified can be loaded
- local modName, modDirectory, filename, ignore
- local check = true
- local xmlFile = loadXMLFile("loadExtraMissionVehicles", xmlFilename)
- local i = 0
- while true do
- local baseKey = string.format("missionVehicles.mission(%d)", i)
- if hasXMLProperty(xmlFile, baseKey) then
- local missionType = getXMLString(xmlFile, baseKey .. "#type") or ""
- --self:loadExtraMissionVehicles_groups(xmlFile, baseKey, missionType, modDirectory)
- local j = 0
- while true do
- local groupKey = string.format("%s.group(%d)", baseKey, j)
- if hasXMLProperty(xmlFile, groupKey) then
- --self:loadExtraMissionVehicles_vehicles(xmlFile, groupKey, modDirectory)
- local k = 0
- while true do
- local vehicleKey = string.format("%s.vehicle(%d)", groupKey, k)
- if hasXMLProperty(xmlFile, vehicleKey) then
- local baseDirectory = nil
- local vfile = getXMLString(xmlFile, vehicleKey .. "#filename") or "missingFilename"
- ignore = false
- modName = getXMLString(xmlFile, vehicleKey .. "#requiredMod")
- if getXMLBool(xmlFile, vehicleKey .. "#isMod") then
- baseDirectory = modDirectory
- elseif modName~= nil then
- if g_modIsLoaded[modName]then
- baseDirectory = g_modNameToDirectory[modName]
- else
- Logging.warning("[%s] required Mod %s not found, ignoring mission vehicle %s",
- self.name, modName, vfile)
- ignore = true
- check = false
- end
- end
- if not ignore then
- filename = Utils.getFilename(vfile, baseDirectory)
- -- try to load from store item
- if g_storeManager.xmlFilenameToItem[string.lower(filename)] == nil then
- Logging.warning("**[%s] - could not get store item for '%s'",self.name,filename)
- check = false
- end
- end
- else
- break
- end
- k = k +1
- end
- else
- break
- end
- j = j +1
- end
- else
- break
- end
- i = i + 1
- end
- delete(xmlFile)
- return check
+ -- check if all vehicles specified can be loaded
+ local modName, modDirectory, filename, ignore
+ local check = true
+ local xmlFile = loadXMLFile("loadExtraMissionVehicles", xmlFilename)
+ local i = 0
+ while true do
+ local baseKey = string.format("missionVehicles.mission(%d)", i)
+ if hasXMLProperty(xmlFile, baseKey) then
+ local missionType = getXMLString(xmlFile, baseKey .. "#type") or ""
+ --self:loadExtraMissionVehicles_groups(xmlFile, baseKey, missionType, modDirectory)
+ local j = 0
+ while true do
+ local groupKey = string.format("%s.group(%d)", baseKey, j)
+ if hasXMLProperty(xmlFile, groupKey) then
+ --self:loadExtraMissionVehicles_vehicles(xmlFile, groupKey, modDirectory)
+ local k = 0
+ while true do
+ local vehicleKey = string.format("%s.vehicle(%d)", groupKey, k)
+ if hasXMLProperty(xmlFile, vehicleKey) then
+ local baseDirectory = nil
+ local vfile = getXMLString(xmlFile, vehicleKey .. "#filename") or "missingFilename"
+ ignore = false
+ modName = getXMLString(xmlFile, vehicleKey .. "#requiredMod")
+ if getXMLBool(xmlFile, vehicleKey .. "#isMod") then
+ baseDirectory = modDirectory
+ elseif modName~= nil then
+ if g_modIsLoaded[modName]then
+ baseDirectory = g_modNameToDirectory[modName]
+ else
+ Logging.warning("[%s] required Mod %s not found, ignoring mission vehicle %s",
+ self.name, modName, vfile)
+ ignore = true
+ check = false
+ end
+ end
+ if not ignore then
+ filename = Utils.getFilename(vfile, baseDirectory)
+ -- try to load from store item
+ if g_storeManager.xmlFilenameToItem[string.lower(filename)] == nil then
+ Logging.warning("**[%s] - could not get store item for '%s'",self.name,filename)
+ check = false
+ end
+ end
+ else
+ break
+ end
+ k = k +1
+ end
+ else
+ break
+ end
+ j = j +1
+ end
+ else
+ break
+ end
+ i = i + 1
+ end
+ delete(xmlFile)
+ return check
end
function BetterContracts:loadExtraMissionVehicles(xmlFilename)
- local xmlFile = loadXMLFile("loadExtraMissionVehicles", xmlFilename)
- local modDirectory = nil
- local requiredMod = getXMLString(xmlFile, "missionVehicles#requiredMod")
- local hasRequiredMod = false
- if requiredMod ~= nil and g_modIsLoaded[requiredMod] then
- modDirectory = g_modNameToDirectory[requiredMod]
- hasRequiredMod = true
- end
- local overwriteStd = Utils.getNoNil(getXMLBool(xmlFile, "missionVehicles#overwrite"), false)
- if overwriteStd then
- g_missionManager.missionVehicles = {}
- end
- if hasRequiredMod or requiredMod == nil then
- local index = 0
- while true do
- local baseKey = string.format("missionVehicles.mission(%d)", index)
- if hasXMLProperty(xmlFile, baseKey) then
- local missionType = getXMLString(xmlFile, baseKey .. "#type") or ""
- if missionType ~= "" then
- if g_missionManager.missionVehicles[missionType] == nil then
- g_missionManager.missionVehicles[missionType] = {}
- g_missionManager.missionVehicles[missionType].small = {}
- g_missionManager.missionVehicles[missionType].medium = {}
- g_missionManager.missionVehicles[missionType].large = {}
- end
- self:loadExtraMissionVehicles_groups(xmlFile, baseKey, missionType, modDirectory)
- end
- else
- break
- end
- index = index + 1
- end
- end
- delete(xmlFile)
+ local xmlFile = loadXMLFile("loadExtraMissionVehicles", xmlFilename)
+ local modDirectory = nil
+ local requiredMod = getXMLString(xmlFile, "missionVehicles#requiredMod")
+ local hasRequiredMod = false
+ if requiredMod ~= nil and g_modIsLoaded[requiredMod] then
+ modDirectory = g_modNameToDirectory[requiredMod]
+ hasRequiredMod = true
+ end
+ local overwriteStd = Utils.getNoNil(getXMLBool(xmlFile, "missionVehicles#overwrite"), false)
+ if overwriteStd then
+ g_missionManager.missionVehicles = {}
+ end
+ if hasRequiredMod or requiredMod == nil then
+ local index = 0
+ while true do
+ local baseKey = string.format("missionVehicles.mission(%d)", index)
+ if hasXMLProperty(xmlFile, baseKey) then
+ local missionType = getXMLString(xmlFile, baseKey .. "#type") or ""
+ if missionType ~= "" then
+ if g_missionManager.missionVehicles[missionType] == nil then
+ g_missionManager.missionVehicles[missionType] = {}
+ g_missionManager.missionVehicles[missionType].small = {}
+ g_missionManager.missionVehicles[missionType].medium = {}
+ g_missionManager.missionVehicles[missionType].large = {}
+ end
+ self:loadExtraMissionVehicles_groups(xmlFile, baseKey, missionType, modDirectory)
+ end
+ else
+ break
+ end
+ index = index + 1
+ end
+ end
+ delete(xmlFile)
end
function BetterContracts:loadExtraMissionVehicles_groups(xmlFile, baseKey, missionType, modDirectory)
- local index = 0
- while true do
- local groupKey = string.format("%s.group(%d)", baseKey, index)
- if hasXMLProperty(xmlFile, groupKey) then
- local group = {}
- local fieldSize = getXMLString(xmlFile, groupKey .. "#fieldSize") or "missingFieldSize"
- group.variant = getXMLString(xmlFile, groupKey .. "#variant")
- group.rewardScale = getXMLFloat(xmlFile, groupKey .. "#rewardScale") or 1
- if g_missionManager.missionVehicles[missionType][fieldSize] == nil then
- g_missionManager.missionVehicles[missionType][fieldSize] = {}
- end
- group.identifier = #g_missionManager.missionVehicles[missionType][fieldSize] + 1
- group.vehicles = self:loadExtraMissionVehicles_vehicles(xmlFile, groupKey, modDirectory)
- table.insert(g_missionManager.missionVehicles[missionType][fieldSize], group)
- else
- break
- end
- index = index + 1
- end
+ local index = 0
+ while true do
+ local groupKey = string.format("%s.group(%d)", baseKey, index)
+ if hasXMLProperty(xmlFile, groupKey) then
+ local group = {}
+ local fieldSize = getXMLString(xmlFile, groupKey .. "#fieldSize") or "missingFieldSize"
+ group.variant = getXMLString(xmlFile, groupKey .. "#variant")
+ group.rewardScale = getXMLFloat(xmlFile, groupKey .. "#rewardScale") or 1
+ if g_missionManager.missionVehicles[missionType][fieldSize] == nil then
+ g_missionManager.missionVehicles[missionType][fieldSize] = {}
+ end
+ group.identifier = #g_missionManager.missionVehicles[missionType][fieldSize] + 1
+ group.vehicles = self:loadExtraMissionVehicles_vehicles(xmlFile, groupKey, modDirectory)
+ table.insert(g_missionManager.missionVehicles[missionType][fieldSize], group)
+ else
+ break
+ end
+ index = index + 1
+ end
end
function BetterContracts:loadExtraMissionVehicles_vehicles(xmlFile, groupKey, modDirectory)
- local index = 0
- local vehicles = {}
- local modName, ignore
- while true do
- local vehicleKey = string.format("%s.vehicle(%d)", groupKey, index)
- if hasXMLProperty(xmlFile, vehicleKey) then
- local vehicle = {}
- local baseDirectory = nil
- local vfile = getXMLString(xmlFile, vehicleKey .. "#filename") or "missingFilename"
- ignore = false
- modName = getXMLString(xmlFile, vehicleKey .. "#requiredMod")
- if getXMLBool(xmlFile, vehicleKey .. "#isMod") then
- baseDirectory = modDirectory
- elseif modName~= nil then
- if g_modIsLoaded[modName]then
- baseDirectory = g_modNameToDirectory[modName]
- else
- Logging.warning("[%s] required Mod %s not found, ignoring mission vehicle %s",
- self.name, modName, vfile)
- ignore = true
- end
- end
- if not ignore then
- vehicle.filename = Utils.getFilename(vfile, baseDirectory)
- vehicle.configurations = self:loadExtraMissionVehicles_configurations(xmlFile, vehicleKey)
- table.insert(vehicles, vehicle)
- end
- else
- break
- end
- index = index + 1
- end
- return vehicles
+ local index = 0
+ local vehicles = {}
+ local modName, ignore
+ while true do
+ local vehicleKey = string.format("%s.vehicle(%d)", groupKey, index)
+ if hasXMLProperty(xmlFile, vehicleKey) then
+ local vehicle = {}
+ local baseDirectory = nil
+ local vfile = getXMLString(xmlFile, vehicleKey .. "#filename") or "missingFilename"
+ ignore = false
+ modName = getXMLString(xmlFile, vehicleKey .. "#requiredMod")
+ if getXMLBool(xmlFile, vehicleKey .. "#isMod") then
+ baseDirectory = modDirectory
+ elseif modName~= nil then
+ if g_modIsLoaded[modName]then
+ baseDirectory = g_modNameToDirectory[modName]
+ else
+ Logging.warning("[%s] required Mod %s not found, ignoring mission vehicle %s",
+ self.name, modName, vfile)
+ ignore = true
+ end
+ end
+ if not ignore then
+ vehicle.filename = Utils.getFilename(vfile, baseDirectory)
+ vehicle.configurations = self:loadExtraMissionVehicles_configurations(xmlFile, vehicleKey)
+ table.insert(vehicles, vehicle)
+ end
+ else
+ break
+ end
+ index = index + 1
+ end
+ return vehicles
end
function BetterContracts:loadExtraMissionVehicles_configurations(xmlFile, vehicleKey)
- local index = 0
- local configurations = {}
- while true do
- local configurationKey = string.format("%s.configuration(%d)", vehicleKey, index)
- if hasXMLProperty(xmlFile, configurationKey) then
- local ignore = false
- local name = getXMLString(xmlFile, configurationKey .. "#name") or "missingName"
- local id = getXMLInt(xmlFile, configurationKey .. "#id") or 1
- local modName = getXMLString(xmlFile, configurationKey .. "#requiredMod")
- if not g_configurationManager:getConfigurationDescByName(name) then
- Logging.warning("[%s] configuration %s not found, ignored",
- self.name, name)
- elseif modName~= nil and not g_modIsLoaded[modName] then
- Logging.warning("[%s] required Mod %s not found, ignoring '%s' configuration",
- self.name, modName, name)
- else
- configurations[name] = id
- end
- else
- break
- end
- index = index + 1
- end
- return configurations
+ local index = 0
+ local configurations = {}
+ while true do
+ local configurationKey = string.format("%s.configuration(%d)", vehicleKey, index)
+ if hasXMLProperty(xmlFile, configurationKey) then
+ local ignore = false
+ local name = getXMLString(xmlFile, configurationKey .. "#name") or "missingName"
+ local id = getXMLInt(xmlFile, configurationKey .. "#id") or 1
+ local modName = getXMLString(xmlFile, configurationKey .. "#requiredMod")
+ if not g_configurationManager:getConfigurationDescByName(name) then
+ Logging.warning("[%s] configuration %s not found, ignored",
+ self.name, name)
+ elseif modName~= nil and not g_modIsLoaded[modName] then
+ Logging.warning("[%s] required Mod %s not found, ignoring '%s' configuration",
+ self.name, modName, name)
+ else
+ configurations[name] = id
+ end
+ else
+ break
+ end
+ index = index + 1
+ end
+ return configurations
end
diff --git a/scripts/userint.lua b/scripts/userint.lua
index 12912ae..d51f71d 100644
--- a/scripts/userint.lua
+++ b/scripts/userint.lua
@@ -95,7 +95,7 @@ function BetterContracts:getFromVehicle(cat, m)
self.name, m.type.name, m.field.fieldId)
return false
end
- if cat == 4 then wwidth = 0 end -- init for search for biggest wwidth
+ if cat == SC.BALING then wwidth = 0 end -- init for search for biggest wwidth
for _, v in ipairs(m.vehiclesToLoad) do -- main loop over vehicles to load
vec = g_storeManager.xmlFilenameToItem[string.lower(v.filename)]
con = v.configurations
@@ -108,23 +108,25 @@ function BetterContracts:getFromVehicle(cat, m)
spr = string.sub(vec.xmlFilename, 15)
--- if grass mission, scan for mower with largest workwidth
- if cat == 4 then
+ if cat == SC.BALING then
if self:isMower(vtype) and tonumber(vec.specs.workingWidth) > wwidth then
wwidth = tonumber(vec.specs.workingWidth)
speed = vec.specs.speedLimit
end
- elseif cat == 2 and vtype == "SLURRYTANKS"
+ elseif cat == SC.SPREAD and vtype == "SLURRYTANKS"
and vec.functions[1] == g_i18n:getText("function_slurrySpreaderWithoutTool")
then -- skip this, it's a slurry barrel w/o spreader
- elseif cat == 1 and vtype == "BEETVEHICLES" then
+ elseif cat == SC.HARVEST and vtype == "BEETVEHICLES" then
if vec.name == "Rexor 6300 Platinum" then
wwidth, speed = 2.8, 10.
break
end
-- else skip this, it's a beet harvester that needs a header
- elseif cat == 1 and self:isHarvester(vtype) or cat == 2 and self:isSpreader(vtype) or cat == 3 and self:isSimple(vtype) then
+ elseif cat == SC.HARVEST and self:isHarvester(vtype)
+ or cat == SC.SPREAD and self:isSpreader(vtype)
+ or cat == SC.SIMPLE and self:isSimple(vtype) then
speed = vec.specs.speedLimit
wwidth = vec.specs.workingWidth
if wwidth == nil then
@@ -145,7 +147,7 @@ function BetterContracts:getFromVehicle(cat, m)
-- if no spreader / sprayer in a spreadmission (e.g. a manure vehicle offered)
if wwidth == nil then
speed, wwidth = 0, 0
- if cat ~= 2 then
+ if cat ~= SC.SPREAD then
Logging.warning("[%s]:getFromVehicle() could not find appropriate vehicle in mission %s. Last vehicle: %s %s",
self.name, m.id, vtype, spr)
end