Skip to content

Commit

Permalink
properly fix #37
Browse files Browse the repository at this point in the history
the previous revision would only work if roller crimping data had been initialized before triggering weed suppression for the first time.
  • Loading branch information
Timmeey86 committed Jul 6, 2024
1 parent e025788 commit cdc2bc2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"editor.renderWhitespace": "all",
"Lua.diagnostics.globals": [
"g_currentMission",
"FieldDensityMap",
Expand Down
6 changes: 3 additions & 3 deletions modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="80">
<author>Farmsim Tim (timmeey86)</author>
<version>1.0.1.6</version>
<version>1.0.1.7</version>
<title>
<en>Conservation Agriculture</en>
<de>Regenerative Landwirschaft</de>
Expand Down Expand Up @@ -46,7 +46,7 @@ If you do find issues or weird behaviour, please create an issue at https://gith
Special thanks to Matthias, FS Gentleman and Cookie Cat for help and ideas provided to make this mod possible.
Changelog:
v1.0.1.6:
v1.0.1.7:
- Fixed an issue where weed suppression would cause lua errors on mod maps with incomplete fruit types
v1.0.1.4:
Expand Down Expand Up @@ -116,7 +116,7 @@ Wenn du Probleme oder seltsames Verhalten feststellst, berichte das Problem bitt
Besonderen Dank an Matthias, FS Gentleman und Cookie Cat für Tips und Ideen, durch die diese Mod möglich wurde.
Changelog:
v1.0.1.6:
v1.0.1.7:
- Ein Problem wurde behoben, bei dem die Unkrautunterdrückung auf Karten mit unvollständigen Fruchtdefinitionen zu Lua Fehlern führte.
v1.0.1.4:
Expand Down
19 changes: 12 additions & 7 deletions scripts/settings/RollerCrimpingData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function RollerCrimpingData.new()
return self
end

---Initializes forage data based on the provided table of fruit types
---Initializes forage data based on the provided table of fruit types. This is an internal function, do not call it outside of this class
---@param fruitTypes table @Provides information about growth states of fruit types
function RollerCrimpingData:init(fruitTypes)
function RollerCrimpingData:internalInit(fruitTypes)
self.forageableStatesPerFruit = {}
for index, fruitDescription in pairs(fruitTypes) do
-- For grains and anything else not specially handled: allow from "half grown" (rounded down) to the last state before "ready to harvest"
Expand Down Expand Up @@ -43,15 +43,20 @@ function RollerCrimpingData:init(fruitTypes)
end
end

---Provides fast lookup of the growth states which allow roller crimping
---@param fruitTypeIndex integer @The index of the fruit type in the global list of fruit types
---@return table @A pair of minimum and maximum growth states indexed by "min" and "max"
function RollerCrimpingData:getForageableStates(fruitTypeIndex)
---Performs a one time initialization of this class. It is safe to call this method more than once
function RollerCrimpingData:initializeIfNecessary()
if not self.isInitialized then
-- Perform a one-time initialization the first time it is required. This makes sure mods which come much later in the alphabet have
-- already registered all their fruit types
self:init(g_fruitTypeManager:getFruitTypes())
self:internalInit(g_fruitTypeManager:getFruitTypes())
self.isInitialized = true
end
end

---Provides fast lookup of the growth states which allow roller crimping
---@param fruitTypeIndex integer @The index of the fruit type in the global list of fruit types
---@return table @A pair of minimum and maximum growth states indexed by "min" and "max"
function RollerCrimpingData:getForageableStates(fruitTypeIndex)
self:initializeIfNecessary()
return self.forageableStatesPerFruit[fruitTypeIndex] or { min = nil, max = nil }
end
9 changes: 5 additions & 4 deletions scripts/specializations/CoverCropUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,13 @@ function CoverCropUtils.mulchAndFertilizeCoverCrops(implement, workArea, groundS
FruitType.POPLAR
}
-- Avoid mod conflicts with mods which add fruit types without adding density maps
local wheatFruitType = g_fruitTypeManager:getFruitTypeByName("WHEAT")
g_rollerCrimpingData:initializeIfNecessary()
local wheatFruitType = g_fruitTypeManager:getFruitTypeByName("WHEAT")
for _, desc in pairs(g_fruitTypeManager:getFruitTypes()) do
-- Note about the fourth check: SwathingAddon sets the wheat density map for all fruit types which don't have a density map, but we still need to ignore such fruit types
-- => We ignore them if they use the wheat density map but are in fact a different fruit type
-- Note about the fourth check: SwathingAddon sets the wheat density map for all fruit types which don't have a density map, but we still need to ignore such fruit types
-- => We ignore them if they use the wheat density map but are in fact a different fruit type
if desc.terrainDataPlaneId == nil or desc.startStateChannel == nil or desc.numStateChannels == nil
or (desc.terrainDataPlaneId == wheatFruitType.terrainDataPlaneId and desc.index ~= wheatFruitType.index) then
or (desc.terrainDataPlaneId == wheatFruitType.terrainDataPlaneId and desc.index ~= wheatFruitType.index) then
excludedFruitTypes[desc.index] = true
end

Expand Down

0 comments on commit cdc2bc2

Please sign in to comment.