diff --git a/upgrades.lua b/upgrades.lua index 09776c1..a401f9b 100644 --- a/upgrades.lua +++ b/upgrades.lua @@ -19,8 +19,31 @@ local S=minetest.get_translator("industrialtest") industrialtest.internal.applyUpgrade=function(meta,stack) local def=minetest.registered_items[stack:get_name()] if def.groups._industrialtest_upgradeSpeed then - local speed=meta:contains("industrialtest.speed") and meta:get_int("industrialtest.speed") or 1 + local speed=industrialtest.api.getMachineSpeed(meta) meta:set_int("industrialtest.speed",math.min(4,speed+def.groups._industrialtest_upgradeSpeed)) + elseif def.groups._industrialtest_upgradeTransformer then + local flows={ + industrialtest.api.lvPowerFlow, + industrialtest.api.mvPowerFlow, + industrialtest.api.hvPowerFlow, + industrialtest.api.evPowerFlow, + industrialtest.api.ivPowerFlow + } + local machineFlow=meta:get_int("industrialtest.powerFlow") + local upgradedFlow=machineFlow + for _,flow in ipairs(flows) do + if flow>machineFlow then + upgradedFlow=flow + break + end + end + meta:set_int("industrialtest.powerFlow",upgradedFlow) + local networks=industrialtest.api.isAttachedToNetwork(meta) + if networks then + for _,network in ipairs(networks) do + industrialtest.api.createNetworkMapForNode(network) + end + end end end @@ -29,6 +52,30 @@ industrialtest.internal.removeUpgrade=function(meta,stack) if def.groups._industrialtest_upgradeSpeed and meta:contains("industrialtest.speed") then local speed=meta:get_int("industrialtest.speed") meta:set_int("industrialtest.speed",math.max(1,speed-def.groups._industrialtest_upgradeSpeed)) + elseif def.groups._industrialtest_upgradeTransformer then + local flows={ + industrialtest.api.lvPowerFlow, + industrialtest.api.mvPowerFlow, + industrialtest.api.hvPowerFlow, + industrialtest.api.evPowerFlow, + industrialtest.api.ivPowerFlow + } + local machineFlow=meta:get_int("industrialtest.powerFlow") + local downgradedFlow=machineFlow + for i=#flows,1,-1 do + local flow=flows[i] + if flow