From ad8d586e1df17acb2489528c470eb2ef78a24bb2 Mon Sep 17 00:00:00 2001 From: Decker MMIV Date: Sat, 9 Aug 2014 13:11:39 +0200 Subject: [PATCH] Added setMapProperty() #17. Look in 'SampleModMap - Additions.LUA' for how to use. Other/more settings will be added later. --- v1/ChangeLog.txt | 14 ++- .../SampleModMap - Additions.lua | 12 ++ v1/ReadMe.TXT | 4 +- v1/SoilManagement/fmcGrowthControl.LUA | 62 ++++++----- v1/SoilManagement/fmcSettings.lua | 105 ++++++++++++++++++ v1/SoilManagement/fmcSoilMod.lua | 28 +++++ v1/SoilManagement/modDesc.xml | 2 +- 7 files changed, 195 insertions(+), 32 deletions(-) create mode 100644 v1/SoilManagement/fmcSettings.lua diff --git a/v1/ChangeLog.txt b/v1/ChangeLog.txt index 943c2a3..5ffb5a6 100644 --- a/v1/ChangeLog.txt +++ b/v1/ChangeLog.txt @@ -11,13 +11,19 @@ Fixes: Enhancements: -- Some settings now stored in the careerSavegame.XML file, so they should be "easier" to change. - These are; delayGrowthCycle, reduceWindrows, removeSprayMoisture, disableWithering, fertilizerSynthetic. +- Some settings now stored in the CareerSavegame.XML file, so they should be "easier" to change. + These are; delayGrowthCycle, reduceWindrows, removeSprayMoisture & disableWithering. They are found in the section of the careerSavegame.XML file. - +- SoilMod will provide default values for the above mentioned settings. However it is also + possible for map-author to change these. Look for 'setMapProperty' in the supplied + 'SampleModMap - Additions.LUA' script. + Additions: -- (NOT YET) Plugin support for other mods, so they can "add" their own effects. +- Plugin support for other mods, so they can "add" their own effects. + Documentation with examples is yet to be provided. For now, mod-authors/scripters should + take a look at 'fmcSoilModPlugins.LUA', as SoilMod itself is using its own plugin facility. +- Czech translation by KingFrame & Albi. ============================ diff --git a/v1/Instructions and files to embed into your map-mod/SampleModMap - Additions.lua b/v1/Instructions and files to embed into your map-mod/SampleModMap - Additions.lua index a71be4a..05b35fc 100644 --- a/v1/Instructions and files to embed into your map-mod/SampleModMap - Additions.lua +++ b/v1/Instructions and files to embed into your map-mod/SampleModMap - Additions.lua @@ -130,6 +130,18 @@ function SampleModMap:loadMap01Finished(node, arguments) -- fmcSoilMod.setFruit_FertilizerBoost_HerbicideAffected("pumpkin" ,"fertilizer3" ,"herbicide2") end -- + if fmcSoilMod.setMapProperty ~= nil then + -- Some of SoilMod's map-properties can be overwritten by the map-mod itself. + -- These properties can, after the first save, also be changed manually by + -- editing the file; .../savegame#/CareerSavegame.XML - Look for the section . + + -- <> + -- fmcSoilMod.setMapProperty("reduceWindrows", true) -- (boolean) If windrows/swath should be reduced by 1 height-level during growth-cycle + -- fmcSoilMod.setMapProperty("removeSprayMoisture", true) -- (boolean) If spray-moisture should be removed (vaporised) during growth-cycle + -- fmcSoilMod.setMapProperty("disableWithering", false) -- (boolean) If crop withering should be disabled + -- fmcSoilMod.setMapProperty("delayGrowthCycle#days", 0) -- (integer) How many in-game days to skip before activating growth-cycle again + end + -- fmcSoilMod.postInit_loadMapFinished() end --## SoilMod - End ############################################################ diff --git a/v1/ReadMe.TXT b/v1/ReadMe.TXT index 2c5fee3..94008c0 100644 --- a/v1/ReadMe.TXT +++ b/v1/ReadMe.TXT @@ -158,4 +158,6 @@ Keep the original download link! Credits: Script: Decker_MMIV. Graphics: KaosKnite, JakobT, GIANTS, Decker_MMIV and others. -Translations: JakobT, Gonimy_Vetrom, VAHA. +Translation 'DE': JakobT. +Translation 'RU': Gonimy_Vetrom, VAHA. +Translation 'CZ': KingFrame, Albi. diff --git a/v1/SoilManagement/fmcGrowthControl.LUA b/v1/SoilManagement/fmcGrowthControl.LUA index d426d61..8caa0a2 100644 --- a/v1/SoilManagement/fmcGrowthControl.LUA +++ b/v1/SoilManagement/fmcGrowthControl.LUA @@ -108,17 +108,19 @@ FSCareerMissionInfo.saveToXML = Utils.prependedFunction(FSCareerMissionInfo.save setXMLInt( self.xmlFile, self.xmlKey..".customGrowthControl#cell2" ,fmcGrowthControl.weedCell) -- - setXMLInt( self.xmlFile, self.xmlKey..".modSoilManagement.delayGrowthCycle#days" ,fmcGrowthControl.delayGrowthCycleDays) - setXMLInt( self.xmlFile, self.xmlKey..".modSoilManagement.updateDelayMs#value" ,fmcGrowthControl.updateDelayMs) - setXMLBool(self.xmlFile, self.xmlKey..".modSoilManagement.reduceWindrows#value" ,fmcGrowthControl.reduceWindrows) - setXMLBool(self.xmlFile, self.xmlKey..".modSoilManagement.removeSprayMoisture#value" ,fmcGrowthControl.removeSprayMoisture) - setXMLBool(self.xmlFile, self.xmlKey..".modSoilManagement.disableWithering#value" ,fmcGrowthControl.disableWithering) - - setXMLString(self.xmlFile, self.xmlKey..".modSoilManagement.delayGrowthCycle#description" ,"integer, how many in-game days to skip before activating growth-cycle again (default=0)") - setXMLString(self.xmlFile, self.xmlKey..".modSoilManagement.updateDelayMs#description" ,"milliseconds, delay between update-of-squares during growth-cycle. Lower values=quicker but cause more lag in multiplayer (default=62)") - setXMLString(self.xmlFile, self.xmlKey..".modSoilManagement.reduceWindrows#description" ,"boolean, if windrows/swath/straw should be reduced by 1 during growth-cycle (default=true)") - setXMLString(self.xmlFile, self.xmlKey..".modSoilManagement.removeSprayMoisture#description" ,"boolean, if spray-moisture should be removed (vaporised) during growth-cycle (default=true)") - setXMLString(self.xmlFile, self.xmlKey..".modSoilManagement.disableWithering#description" ,"boolean, if crop withering should be disabled (default=false)") + fmcSettings.onSaveCareerSavegame(self.xmlFile, self.xmlKey..".modSoilManagement") + + --setXMLInt( self.xmlFile, self.xmlKey..".modSoilManagement.delayGrowthCycle#days" ,fmcGrowthControl.delayGrowthCycleDays) + --setXMLInt( self.xmlFile, self.xmlKey..".modSoilManagement.updateDelayMs#value" ,fmcGrowthControl.updateDelayMs) + --setXMLBool(self.xmlFile, self.xmlKey..".modSoilManagement.reduceWindrows#value" ,fmcGrowthControl.reduceWindrows) + --setXMLBool(self.xmlFile, self.xmlKey..".modSoilManagement.removeSprayMoisture#value" ,fmcGrowthControl.removeSprayMoisture) + --setXMLBool(self.xmlFile, self.xmlKey..".modSoilManagement.disableWithering#value" ,fmcGrowthControl.disableWithering) + -- + --setXMLString(self.xmlFile, self.xmlKey..".modSoilManagement.delayGrowthCycle#description" ,"integer, how many in-game days to skip before activating growth-cycle again (default=0)") + --setXMLString(self.xmlFile, self.xmlKey..".modSoilManagement.updateDelayMs#description" ,"milliseconds, delay between update-of-squares during growth-cycle. Lower values=quicker but cause more lag in multiplayer (default=62)") + --setXMLString(self.xmlFile, self.xmlKey..".modSoilManagement.reduceWindrows#description" ,"boolean, if windrows/swath/straw should be reduced by 1 during growth-cycle (default=true)") + --setXMLString(self.xmlFile, self.xmlKey..".modSoilManagement.removeSprayMoisture#description" ,"boolean, if spray-moisture should be removed (vaporised) during growth-cycle (default=true)") + --setXMLString(self.xmlFile, self.xmlKey..".modSoilManagement.disableWithering#description" ,"boolean, if crop withering should be disabled (default=false)") -- setXMLInt(self.xmlFile, self.xmlKey..".modSoilManagement.fertilizerSynthetic#firstGrowthState" ,fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState) @@ -222,14 +224,22 @@ function fmcGrowthControl:update(dt) fmcGrowthControl.cellSquaresMethod = Utils.getNoNil(getXMLInt( xmlFile, xmlKey..".customGrowthControl#method") ,0) fmcGrowthControl.weedCell = Utils.getNoNil(getXMLInt( xmlFile, xmlKey..".customGrowthControl#cell2") ,0) - fmcGrowthControl.delayGrowthCycleDays = Utils.getNoNil(getXMLInt( xmlFile, xmlKey..".modSoilManagement.delayGrowthCycle#days") ,fmcGrowthControl.delayGrowthCycleDays) - fmcGrowthControl.updateDelayMs = Utils.getNoNil(getXMLInt( xmlFile, xmlKey..".modSoilManagement.updateDelayMs#value") ,fmcGrowthControl.updateDelayMs) - fmcGrowthControl.reduceWindrows = Utils.getNoNil(getXMLBool(xmlFile, xmlKey..".modSoilManagement.reduceWindrows#value") ,fmcGrowthControl.reduceWindrows) - fmcGrowthControl.removeSprayMoisture = Utils.getNoNil(getXMLBool(xmlFile, xmlKey..".modSoilManagement.removeSprayMoisture#value") ,fmcGrowthControl.removeSprayMoisture) - fmcGrowthControl.disableWithering = Utils.getNoNil(getXMLBool(xmlFile, xmlKey..".modSoilManagement.disableWithering#value") ,fmcGrowthControl.disableWithering) + fmcSettings.onLoadCareerSavegame(xmlFile, xmlKey..".modSoilManagement") + + fmcGrowthControl.delayGrowthCycleDays = fmcSettings.getKeyValue("delayGrowthCycle#days", fmcGrowthControl.delayGrowthCycleDays) + fmcGrowthControl.updateDelayMs = fmcSettings.getKeyValue("updateDelayMs", fmcGrowthControl.updateDelayMs ) + fmcGrowthControl.reduceWindrows = fmcSettings.getKeyValue("reduceWindrows", fmcGrowthControl.reduceWindrows ) + fmcGrowthControl.removeSprayMoisture = fmcSettings.getKeyValue("removeSprayMoisture", fmcGrowthControl.removeSprayMoisture ) + fmcGrowthControl.disableWithering = fmcSettings.getKeyValue("disableWithering", fmcGrowthControl.disableWithering ) + + --fmcGrowthControl.delayGrowthCycleDays = Utils.getNoNil(getXMLInt( xmlFile, xmlKey..".modSoilManagement.delayGrowthCycle#days") ,fmcGrowthControl.delayGrowthCycleDays) + --fmcGrowthControl.updateDelayMs = Utils.getNoNil(getXMLInt( xmlFile, xmlKey..".modSoilManagement.updateDelayMs#value") ,fmcGrowthControl.updateDelayMs) + --fmcGrowthControl.reduceWindrows = Utils.getNoNil(getXMLBool(xmlFile, xmlKey..".modSoilManagement.reduceWindrows#value") ,fmcGrowthControl.reduceWindrows) + --fmcGrowthControl.removeSprayMoisture = Utils.getNoNil(getXMLBool(xmlFile, xmlKey..".modSoilManagement.removeSprayMoisture#value") ,fmcGrowthControl.removeSprayMoisture) + --fmcGrowthControl.disableWithering = Utils.getNoNil(getXMLBool(xmlFile, xmlKey..".modSoilManagement.disableWithering#value") ,fmcGrowthControl.disableWithering) - fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState = Utils.getNoNil(getXMLInt( xmlFile, xmlKey..".modSoilManagement.fertilizerSynthetic#firstGrowthState") ,fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState) - fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState = Utils.getNoNil(getXMLInt( xmlFile, xmlKey..".modSoilManagement.fertilizerSynthetic#lastGrowthState") ,fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState) + --fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState = Utils.getNoNil(getXMLInt( xmlFile, xmlKey..".modSoilManagement.fertilizerSynthetic#firstGrowthState") ,fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState) + --fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState = Utils.getNoNil(getXMLInt( xmlFile, xmlKey..".modSoilManagement.fertilizerSynthetic#lastGrowthState") ,fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState) delete(xmlFile); @@ -240,11 +250,11 @@ function fmcGrowthControl:update(dt) fmcGrowthControl.updateDelayMs = math.max(10, fmcGrowthControl.updateDelayMs) fmcGrowthControl.delayGrowthCycleDays = math.max(0, fmcGrowthControl.delayGrowthCycleDays) - -- Growth state ranges allowed: 0-4 (0=nothing, 1=seeded, 4=third growth state) - fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState = math.max(0, fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState) - fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState = math.max(0, fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState) - fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState = math.min(fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState, 4) - fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState = math.min(fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState, fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState) + ---- Growth state ranges allowed: 0-4 (0=nothing, 1=seeded, 4=third growth state) + --fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState = math.max(0, fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState) + --fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState = math.max(0, fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState) + --fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState = math.min(fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState, 4) + --fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState = math.min(fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState, fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState) log("fmcGrowthControl -", " lastUpdateDay=", fmcGrowthControl.lastUpdateDay, @@ -258,9 +268,9 @@ function fmcGrowthControl:update(dt) ", reduceWindrows=", fmcGrowthControl.reduceWindrows, ", removeSprayMoisture=", fmcGrowthControl.removeSprayMoisture, ", disableWithering=", fmcGrowthControl.disableWithering, - ", delayGrowthCycleDays=", fmcGrowthControl.delayGrowthCycleDays, - ", fertSyntFirst=", fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState, - ", fertSyntLast=", fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState + ", delayGrowthCycleDays=", fmcGrowthControl.delayGrowthCycleDays + --", fertSyntFirst=", fmcModifyFSUtils.fertilizerSynthetic_spray_firstGrowthState, + --", fertSyntLast=", fmcModifyFSUtils.fertilizerSynthetic_spray_lastGrowthState ) end diff --git a/v1/SoilManagement/fmcSettings.lua b/v1/SoilManagement/fmcSettings.lua new file mode 100644 index 0000000..007974d --- /dev/null +++ b/v1/SoilManagement/fmcSettings.lua @@ -0,0 +1,105 @@ +-- +-- The Soil Management and Growth Control Project +-- +-- @author Decker_MMIV - fs-uk.com, forum.farming-simulator.com, modhoster.com +-- @date 2014-08-xx +-- + +fmcSettings = {} +fmcSettings.keyValueDesc = {} + +local function extractKeyAndValueName(keyValueName) + local key, valueName = unpack(Utils.splitString("#", keyValueName)) + if valueName == nil then + valueName = "value" + end + return key, valueName +end + +-- +function fmcSettings.setKeyValueDesc(keyValueName, value, description) + local key, valueName = extractKeyAndValueName(keyValueName) + if fmcSettings.keyValueDesc[key] == nil then + fmcSettings.keyValueDesc[key] = { + valueNameValues={} + } + end + fmcSettings.keyValueDesc[key].valueNameValues[valueName] = value; + if description ~= nil then + fmcSettings.keyValueDesc[key].desc = tostring(description) + end +end + +-- +function fmcSettings.updateKeyValueDesc(keyValueName, value) + local key, valueName = extractKeyAndValueName(keyValueName) + if fmcSettings.keyValueDesc[key] ~= nil then + if fmcSettings.keyValueDesc[key].valueNameValues[valueName] ~= nil then + fmcSettings.keyValueDesc[key].valueNameValues[valueName] = value + return true + end + end + return false +end + +-- +function fmcSettings.getKeyValue(keyValueName, defaultValue) + local key, valueName = extractKeyAndValueName(keyValueName) + if fmcSettings.keyValueDesc[key] ~= nil and fmcSettings.keyValueDesc[key].valueNameValues[valueName] ~= nil then + return fmcSettings.keyValueDesc[key].valueNameValues[valueName]; + end + return defaultValue +end + +-- +function fmcSettings.onLoadCareerSavegame(xmlFile, rootXmlKey) + -- + for key,valueDesc in pairs(fmcSettings.keyValueDesc) do + local xmlKey = rootXmlKey.."."..key + + for valueName,value in pairs(valueDesc.valueNameValues) do + local xmlKeyName = xmlKey.."#"..valueName + + if type(value)=="boolean" then + value = Utils.getNoNil(getXMLBool(xmlFile, xmlKeyName), value) + elseif type(value)=="number" then + value = Utils.getNoNil(getXMLInt(xmlFile, xmlKeyName), value) + else + value = Utils.getNoNil(getXMLString(xmlFile, xmlKeyName), value) + end + + --log(xmlKeyName,"=",value) + if valueDesc.valueNameValues[valueName] ~= value then + local shortKeyName = key .. (valueName~="value" and "#"..valueName or "") + logInfo("Map-property '", shortKeyName, "' changed value from '", valueDesc.valueNameValues[valueName], "' to '", value, "'") + valueDesc.valueNameValues[valueName] = value + end + end + end +end + +-- +function fmcSettings.onSaveCareerSavegame(xmlFile, rootXmlKey) + -- + for key,valueDesc in pairs(fmcSettings.keyValueDesc) do + local xmlKey = rootXmlKey.."."..key + + for valueName,value in pairs(valueDesc.valueNameValues) do + if value ~= nil then + local xmlKeyName = xmlKey.."#"..valueName + + if type(value)=="boolean" then + setXMLBool(xmlFile, xmlKeyName, value) + elseif type(value)=="number" then + setXMLInt(xmlFile, xmlKeyName, value) + else + setXMLString(xmlFile, xmlKeyName, tostring(value)) + end + end + end + + if valueDesc.desc ~= nil then + setXMLString(xmlFile, xmlKey.."#description" ,valueDesc.desc) + end + end +end diff --git a/v1/SoilManagement/fmcSoilMod.lua b/v1/SoilManagement/fmcSoilMod.lua index bb421f0..2375ba5 100644 --- a/v1/SoilManagement/fmcSoilMod.lua +++ b/v1/SoilManagement/fmcSoilMod.lua @@ -67,6 +67,7 @@ function logInfo(...) end -- +source(g_currentModDirectory .. 'fmcSettings.lua') source(g_currentModDirectory .. 'fmcFilltypes.lua') source(g_currentModDirectory .. 'fmcModifyFSUtils.lua') source(g_currentModDirectory .. 'fmcModifySprayers.lua') @@ -79,6 +80,19 @@ function fmcSoilMod.setup_map_new(mapFilltypeOverlaysDirectory) fmcSoilMod.enabled = false fmcFilltypes.setup(mapFilltypeOverlaysDirectory, fmcSoilMod.simplisticMode) fmcFilltypes.setupFruitFertilizerBoostHerbicideAffected() + + -- Set SoilMod default value-settings. + -- These can be changed by the map-author in the SampleModMap.LUA script, or in CareerSavegame.XML by the player + -- NOTE! It is only the _server_ that knows the correct values of these. + fmcSettings.setKeyValueDesc("updateDelayMs", math.floor(1000/16), "milliseconds, delay between update-of-squares during growth-cycle. Lower values=quicker but cause more lag in multiplayer (default=62)") + fmcSettings.setKeyValueDesc("reduceWindrows", true, "boolean, if windrows/swath should be reduced by 1 height-level during growth-cycle (default=true)") + fmcSettings.setKeyValueDesc("removeSprayMoisture", true, "boolean, if spray-moisture should be removed (vaporised) during growth-cycle (default=true)") + fmcSettings.setKeyValueDesc("disableWithering", false, "boolean, if crop withering should be disabled (default=false)") + fmcSettings.setKeyValueDesc("delayGrowthCycle#days", 0, "integer, how many in-game days to skip before activating growth-cycle again (default=0)") + + -- TODO: How to make these available client-side? + --fmcSettings.setKeyValueDesc("fertilizerSynthetic#firstGrowthState", 2, "integer, Growth state range is 0-4 (defaults first=2, last=4)") + --fmcSettings.setKeyValueDesc("fertilizerSynthetic#lastGrowthState", 4, nil) end -- @@ -131,6 +145,20 @@ function fmcSoilMod.draw() end -- +function fmcSoilMod.setMapProperty(keyName, value) + -- Only server is allowed to update the map-properties + if g_currentMission == nil or not g_currentMission:getIsServer() then + return false + end + -- + if not fmcSettings.updateKeyValueDesc(keyName, value) then + logInfo("WARNING! Can not set map-property with key-name: '",keyName,"'") + return false + end + logInfo("Map-property '", keyName, "' updated to value '", fmcSettings.getKeyValue(keyName), "'") + return true +end + function fmcSoilMod.setFruit_FertilizerBoost_HerbicideAffected(fruitName, fertilizerName, herbicideName) if fmcSoilMod.simplisticMode then -- Not used in 'simplistic mode'. diff --git a/v1/SoilManagement/modDesc.xml b/v1/SoilManagement/modDesc.xml index abdf17b..6bc6e0f 100644 --- a/v1/SoilManagement/modDesc.xml +++ b/v1/SoilManagement/modDesc.xml @@ -2,7 +2,7 @@ Freelance Modding Crew JakobT, Gonimy_Vetrom, VAHA, KingFrame, Albi - 1.1.12 + 1.1.13 <en>Soil Management and Growth Control</en>