Skip to content

Commit

Permalink
Added setMapProperty()
Browse files Browse the repository at this point in the history
#17. Look in 'SampleModMap - Additions.LUA' for how to use.
Other/more settings will be added later.
  • Loading branch information
DeckerMMIV committed Aug 9, 2014
1 parent 1d23dec commit ad8d586
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 32 deletions.
14 changes: 10 additions & 4 deletions v1/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <modSoilManagement> 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.


============================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <modSoilManagement>.

-- <<Examples>>
-- 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 ############################################################
Expand Down
4 changes: 3 additions & 1 deletion v1/ReadMe.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -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.
62 changes: 36 additions & 26 deletions v1/SoilManagement/fmcGrowthControl.LUA
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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,
Expand All @@ -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

Expand Down
105 changes: 105 additions & 0 deletions v1/SoilManagement/fmcSettings.lua
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions v1/SoilManagement/fmcSoilMod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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

--
Expand Down Expand Up @@ -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'.
Expand Down
2 changes: 1 addition & 1 deletion v1/SoilManagement/modDesc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modDesc descVersion="12">
<author>Freelance Modding Crew</author>
<contributors>JakobT, Gonimy_Vetrom, VAHA, KingFrame, Albi</contributors>
<version>1.1.12</version>
<version>1.1.13</version>

<title>
<en>Soil Management and Growth Control</en>
Expand Down

0 comments on commit ad8d586

Please sign in to comment.