From 3e327d7461033dea5e08a2f930d59746b37f0658 Mon Sep 17 00:00:00 2001 From: Shad0wlife Date: Thu, 27 Jun 2024 18:44:19 +0200 Subject: [PATCH] Make the mod compatible with old mod saves 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. --- UpgradableFactories.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/UpgradableFactories.lua b/UpgradableFactories.lua index 795c87d..99e6189 100644 --- a/UpgradableFactories.lua +++ b/UpgradableFactories.lua @@ -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