diff --git a/GameData/DynamicBatteryStorage/DynamicBatteryStorageSettings.cfg b/GameData/DynamicBatteryStorage/DynamicBatteryStorageSettings.cfg index 522361a..4400aaf 100644 --- a/GameData/DynamicBatteryStorage/DynamicBatteryStorageSettings.cfg +++ b/GameData/DynamicBatteryStorage/DynamicBatteryStorageSettings.cfg @@ -45,6 +45,7 @@ DYNAMICBATTERYSTORAGE name = Radiators title = #LOC_DynamicBatteryStorage_UI_Category_Radiators module = ModuleActiveRadiator + module = ModuleHeatPump module = ModuleSystemHeatRadiator module = ModuleSystemHeatExchanger } @@ -53,6 +54,7 @@ DYNAMICBATTERYSTORAGE name = Converters title = #LOC_DynamicBatteryStorage_UI_Category_Converters module = ModuleResourceConverter + module = USI_Converter module = ModuleSystemHeatConverter module = SnackProcessor module = SoilRecycler @@ -307,6 +309,18 @@ DYNAMICBATTERYSTORAGE continuous = true } PARTMODULEHANDLER + { + name = ModuleHeatPump + handlerModuleName = ModuleHeatPumpPowerHandler + type = Power + visible = true + solarEfficiencyEffects = false + producer = false + consumer = true + simulated = true + continuous = true + } + PARTMODULEHANDLER { name = ModuleResourceConverter handlerModuleName = ModuleResourceConverterPowerHandler @@ -319,6 +333,18 @@ DYNAMICBATTERYSTORAGE continuous = true } PARTMODULEHANDLER + { + name = USI_Converter + handlerModuleName = ModuleResourceConverterPowerHandler + type = Power + visible = true + solarEfficiencyEffects = false + producer = false + consumer = true + simulated = true + continuous = true + } + PARTMODULEHANDLER { name = ModuleResourceConverter handlerModuleName = ModuleResourceConverterHeatHandler @@ -379,6 +405,18 @@ DYNAMICBATTERYSTORAGE continuous = true } PARTMODULEHANDLER + { + name = USI_Harvester + handlerModuleName = ModuleResourceHarvesterPowerHandler + type = Power + visible = true + solarEfficiencyEffects = false + producer = false + consumer = true + simulated = true + continuous = true + } + PARTMODULEHANDLER { name = ModuleResourceHarvester handlerModuleName = ModuleResourceHarvesterPowerHandler diff --git a/GameData/DynamicBatteryStorage/Plugins/DynamicBatteryStorage.dll b/GameData/DynamicBatteryStorage/Plugins/DynamicBatteryStorage.dll index 92a05a5..797c5c2 100644 Binary files a/GameData/DynamicBatteryStorage/Plugins/DynamicBatteryStorage.dll and b/GameData/DynamicBatteryStorage/Plugins/DynamicBatteryStorage.dll differ diff --git a/Source/DynamicBatteryStorage/Handlers/Stock/ModuleHeatPumpPowerHandler.cs b/Source/DynamicBatteryStorage/Handlers/Stock/ModuleHeatPumpPowerHandler.cs new file mode 100644 index 0000000..b8f5f29 --- /dev/null +++ b/Source/DynamicBatteryStorage/Handlers/Stock/ModuleHeatPumpPowerHandler.cs @@ -0,0 +1,12 @@ +namespace DynamicBatteryStorage +{ + /// + /// ModuleHeatPump derives from ModuleActiveRadiator and exposes its + /// ElectricCharge draw through the same resource handler. + /// + public class ModuleHeatPumpPowerHandler : ModuleActiveRadiatorPowerHandler + { + public ModuleHeatPumpPowerHandler(HandlerModuleData moduleData) : base(moduleData) + { } + } +} diff --git a/Source/DynamicBatteryStorage/Handlers/Stock/ModuleResourceConverterPowerHandler.cs b/Source/DynamicBatteryStorage/Handlers/Stock/ModuleResourceConverterPowerHandler.cs index e374ef1..0eec071 100644 --- a/Source/DynamicBatteryStorage/Handlers/Stock/ModuleResourceConverterPowerHandler.cs +++ b/Source/DynamicBatteryStorage/Handlers/Stock/ModuleResourceConverterPowerHandler.cs @@ -20,7 +20,23 @@ public override bool Initialize(PartModule pm) if (converter == null) return false; + return UpdatePowerRate(); + } + + // Some converter implementations, including MKS USI_Converter, apply or + // replace their recipe after the handler is initialized. Re-read the + // current recipe whenever the monitor calculates a value so editor + // planning follows the selected bay loadout. + private bool UpdatePowerRate() + { + if (converter == null || converter.inputList == null || converter.outputList == null) + return false; + bool toMonitor = false; + producer = false; + consumer = false; + converterEcRate = 0d; + for (int i = 0; i < converter.inputList.Count; i++) { if (converter.inputList[i].ResourceName == Settings.ELECTRICITY_RESOURCE_NAME) @@ -41,30 +57,36 @@ public override bool Initialize(PartModule pm) toMonitor = true; } } - return toMonitor; + // MKS applies USI_Converter recipes after handler discovery. Keep the + // handler even when the initial recipe is empty so later calculations + // can see the selected bay loadout. + return toMonitor || converter.GetType().Name == "USI_Converter"; } protected override double GetValueEditor() { - if (converter != null) - { - if (producer) - return converterEcRate; - else - return -converterEcRate; - } + if (!UpdatePowerRate()) + return 0d; + + if (producer) + return converterEcRate; + + if (consumer) + return -converterEcRate; + return 0d; } protected override double GetValueFlight() { - if (converter != null) - { - if (converter.IsActivated) - if (producer) - return converterEcRate * converter.lastTimeFactor; - else - return converterEcRate * converter.lastTimeFactor * -1.0d; - } + if (!UpdatePowerRate() || !converter.IsActivated) + return 0d; + + if (producer) + return converterEcRate * converter.lastTimeFactor; + + if (consumer) + return converterEcRate * converter.lastTimeFactor * -1.0d; + return 0d; } diff --git a/Source/DynamicBatteryStorage/Handlers/Stock/ModuleResourceHarvesterPowerHandler.cs b/Source/DynamicBatteryStorage/Handlers/Stock/ModuleResourceHarvesterPowerHandler.cs index 1a0768a..f3105b2 100644 --- a/Source/DynamicBatteryStorage/Handlers/Stock/ModuleResourceHarvesterPowerHandler.cs +++ b/Source/DynamicBatteryStorage/Handlers/Stock/ModuleResourceHarvesterPowerHandler.cs @@ -21,12 +21,24 @@ public override bool Initialize(PartModule pm) if (harvester == null) return false; + bool toMonitor = UpdatePowerRate(); + // MKS populates USI_Harvester inputList after handler initialization. + // Keep the handler alive so it can see the selected loadout later. + return toMonitor || harvester.GetType().Name == "USI_Harvester"; + } + + private bool UpdatePowerRate() + { + converterEcRate = 0.0d; + if (harvester == null || harvester.inputList == null) + return false; + bool toMonitor = false; for (int i = 0; i < harvester.inputList.Count; i++) { if (harvester.inputList[i].ResourceName == Settings.ELECTRICITY_RESOURCE_NAME) { - converterEcRate = harvester.inputList[i].Ratio; + converterEcRate += harvester.inputList[i].Ratio; toMonitor = true; } } @@ -37,6 +49,7 @@ protected override double GetValueEditor() { if (harvester != null) { + UpdatePowerRate(); return -converterEcRate; } return 0d; @@ -45,6 +58,7 @@ protected override double GetValueFlight() { if (harvester != null) { + UpdatePowerRate(); if (harvester.IsActivated) return converterEcRate * harvester.lastTimeFactor * -1.0d; }