Skip to content

Commit

Permalink
Make the mod compatible with old mod saves
Browse files Browse the repository at this point in the history
The mod previously used the x and y coordinates, which was changed to x and z to properly locate buildings, but old saves don't have the z coordinate, so it gets loaded as nil and results in the savegame not loading.

This change attempts to still load these entries with the x and y coordinate, and the mod save will be fixed when the game is next saved.
  • Loading branch information
Shad0wlife committed Jun 27, 2024
1 parent f233ba3 commit 3e327d7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions UpgradableFactories.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ local function getProductionPointFromPosition(pos, farmId)

if g_currentMission.productionChainManager.farmIds[farmId] ~= nil then
for _,prod in pairs(g_currentMission.productionChainManager.farmIds[farmId].productionPoints) do
if MathUtil.getPointPointDistanceSquared(pos.x, pos.z, prod.owningPlaceable.position.x, prod.owningPlaceable.position.z) < 0.0001 then
return prod
if pos.z ~= nil then
if MathUtil.getPointPointDistanceSquared(pos.x, pos.z, prod.owningPlaceable.position.x, prod.owningPlaceable.position.z) < 0.0001 then
return prod
end
else
-- Old data using y coordinate (height) instead of z, compatibility code for old saves
if MathUtil.getPointPointDistanceSquared(pos.x, pos.y, prod.owningPlaceable.position.x, prod.owningPlaceable.position.y) < 0.0001 then
return prod
end
end
end
end
Expand Down

0 comments on commit 3e327d7

Please sign in to comment.