Skip to content

Commit

Permalink
Further resilence improvements
Browse files Browse the repository at this point in the history
Check presence of rotation data before access

Bump version to 2.5.0.5
  • Loading branch information
bodzio528 committed Dec 8, 2023
1 parent 3fd4279 commit 62f6c06
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build
build.*
build.sh

# Compiled Lua sources
luac.out
Expand Down
7 changes: 5 additions & 2 deletions CropRotation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ end

function CropRotation.inj_densityMapUtil_updateSowingArea(superFunc, fruitIndex, startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, fieldGroundType, angle, growthState, blockedSprayTypeIndex)
local fruitDesc = g_fruitTypeManager:getFruitTypeByIndex(fruitIndex)
if fruitDesc and fruitDesc.rotation.enabled then
if fruitDesc and fruitDesc.rotation and fruitDesc.rotation.enabled then
local modifiers = g_cropRotation.modifiers

local terrainSize = g_currentMission.terrainSize or 1024
Expand Down Expand Up @@ -1089,7 +1089,10 @@ function CropRotation:getRotationYieldMultiplier(prevIndex, lastIndex, currentIn
end

function CropRotation:getRotationReturnPeriodMultiplier(prev, last, current)
local returnPeriod = current.rotation.returnPeriod
local returnPeriod = 3
if current.rotation then
returnPeriod = current.rotation.returnPeriod
end

-- monoculture
local result = 0.0 - ((current.index == last and current.index == prev) and 0.05 or 0)
Expand Down
13 changes: 6 additions & 7 deletions CropRotationData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function CropRotationData:process(crops, overwrite, cropsXmlFileName)
self.crModule.log:debug("CropRotationData:process()")

if overwrite then
self.crModule.log:debug('CropRotationData:process(): overwrite crop rotation matrix by discarding entries created so far')
self.crModule.log:debug('CropRotationData:process(): overwrite crop rotation matrix (discard entries created so far)')
self.matrix = {}
end

Expand Down Expand Up @@ -179,20 +179,19 @@ end
----------------------------------------------------------------------

function CropRotationData:postLoad()
self.crModule.log:debug("CropRotationData:postLoad(): list fruits in rotation ...")
self.crModule.log:info("CropRotationData:postLoad(): list fruits in rotation ...")

for fruitIndex, fruitType in pairs(self.fruitTypeManager:getFruitTypes()) do
if fruitType.rotation ~= nil then
if fruitType.rotation.enabled then
self.crModule.log:debug(string.format("ENABLED fruit(%d): %s RP=%d", fruitIndex, fruitType.name, fruitType.rotation.returnPeriod))
self.crModule.log:info(string.format("ENABLED fruit(%d): %s RP=%d", fruitIndex, fruitType.name, fruitType.rotation.returnPeriod))
else
self.crModule.log:debug(string.format("DISABLED fruit(%d): %s", fruitIndex, fruitType.name))
self.crModule.log:info(string.format("DISABLED fruit(%d): %s", fruitIndex, fruitType.name))
end
else
local s = string.format("INVALID fruit(%d): %s", fruitIndex, fruitType.name)
self.crModule.log:warning(s)
self.crModule.log:warning(string.format("INVALID fruit(%d): %s", fruitIndex, fruitType.name))
end
end

self.crModule.log:debug("CropRotationData:postLoad(): ... done")
self.crModule.log:info("CropRotationData:postLoad(): ... done")
end
3 changes: 1 addition & 2 deletions gui/InGameMenuCropRotationPlanner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function InGameMenuCropRotationPlanner:initialize()
self.fruitIndexToCropIndexMap = {}

for i, fruitDesc in pairs(g_fruitTypeManager:getFruitTypes()) do
if fruitDesc ~= nil and fruitDesc.rotation ~= nil then
if fruitDesc and fruitDesc.rotation then
if fruitDesc.rotation.enabled then
table.insert(self.cropIndexToFruitIndexMap, {index = i})
self.fruitIndexToCropIndexMap[i] = #self.cropIndexToFruitIndexMap
Expand Down Expand Up @@ -81,7 +81,6 @@ function InGameMenuCropRotationPlanner:initialize()
end
end
end

end

self:updateRotation()
Expand Down
5 changes: 4 additions & 1 deletion 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="75">
<author>Bodzio528</author>
<version>2.5.0.4</version>
<version>2.5.0.5</version>
<title>
<en>Crop Rotation</en>
<de>Fruchtfolge</de>
Expand All @@ -25,6 +25,9 @@ Key features:
- detailed in-game help menu (with pictures!)
- crop rotation planner to visualize potential yield
Changelog 2.5.0.5:
- fixed issue with mod loading stuck at 95%
Changelog 2.5.0.2:
- added premium expansion crops to rotation table: carrot, beetroot and parsnip
Expand Down

0 comments on commit 62f6c06

Please sign in to comment.