Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions GameData/DynamicBatteryStorage/DynamicBatteryStorageSettings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ DYNAMICBATTERYSTORAGE
name = Radiators
title = #LOC_DynamicBatteryStorage_UI_Category_Radiators
module = ModuleActiveRadiator
module = ModuleHeatPump
module = ModuleSystemHeatRadiator
module = ModuleSystemHeatExchanger
}
Expand All @@ -53,6 +54,7 @@ DYNAMICBATTERYSTORAGE
name = Converters
title = #LOC_DynamicBatteryStorage_UI_Category_Converters
module = ModuleResourceConverter
module = USI_Converter
module = ModuleSystemHeatConverter
module = SnackProcessor
module = SoilRecycler
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace DynamicBatteryStorage
{
/// <summary>
/// ModuleHeatPump derives from ModuleActiveRadiator and exposes its
/// ElectricCharge draw through the same resource handler.
/// </summary>
public class ModuleHeatPumpPowerHandler : ModuleActiveRadiatorPowerHandler
{
public ModuleHeatPumpPowerHandler(HandlerModuleData moduleData) : base(moduleData)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -37,6 +49,7 @@ protected override double GetValueEditor()
{
if (harvester != null)
{
UpdatePowerRate();
return -converterEcRate;
}
return 0d;
Expand All @@ -45,6 +58,7 @@ protected override double GetValueFlight()
{
if (harvester != null)
{
UpdatePowerRate();
if (harvester.IsActivated)
return converterEcRate * harvester.lastTimeFactor * -1.0d;
}
Expand Down