Skip to content

Commit

Permalink
Merge pull request #128 from post-kerbin-mining-corporation/dev
Browse files Browse the repository at this point in the history
Release 0.8.1
  • Loading branch information
ChrisAdderley authored Dec 5, 2024
2 parents 480a688 + 1bada27 commit 6fedc9a
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 28 deletions.
Binary file modified GameData/SystemHeat/Plugin/SystemHeat.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion GameData/SystemHeat/Versioning/SystemHeat.version
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"MAJOR":0,
"MINOR":8,
"PATCH":0,
"PATCH":1,
"BUILD":0
},
"KSP_VERSION":
Expand Down
4 changes: 2 additions & 2 deletions SystemHeat/SystemHeat/HeatLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ protected float CalculatePositiveFlux()
return currentPosFlux;
}
/// <summary>
/// Calculates the total positive flux of the loop
/// Calculates the total negative flux of the loop
/// </summary>
protected float CalculateNegativeFlux()
{
Expand All @@ -220,7 +220,7 @@ void SimulateIteration(float simTimeStep)
// Calculate the loop net flux
float currentNetFlux = CalculateNetFlux();
PositiveFlux = CalculatePositiveFlux();
NegativeFlux = CalculatePositiveFlux();
NegativeFlux = CalculateNegativeFlux();
float absFlux = Mathf.Abs(currentNetFlux);

AllocateFlux(PositiveFlux);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ protected void GenerateHeatFlight()
{
if (base.ModuleIsActive())
{
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower, true);
float fluxScale = 1f;
if (base.lastTimeFactor == 0d)
{
fluxScale = 0f;
}
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower * fluxScale, true);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ void GenerateHeatFlight()
{
if (converterModule.ModuleIsActive())
{
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower, true);
float fluxScale = 1f;
if (converterModule.lastTimeFactor == 0d)
{
fluxScale = 0f;
}
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower * fluxScale, true);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ protected void GenerateHeatEditor()
{
if (base.IsActivated)
{
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower, true);
float fluxScale = 1f;
if (base.lastTimeFactor == 0d)
{
fluxScale = 0f;
}
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower * fluxScale, true);
}
else
{
Expand Down
27 changes: 16 additions & 11 deletions SystemHeat/SystemHeat/Modules/ModuleSystemHeatConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ModuleSystemHeatConverter : ModuleResourceConverter

// Map system outlet temperature (K) to heat generation (kW)
[KSPField(isPersistant = false)]
public float systemPower =0f;
public float systemPower = 0f;


//
Expand Down Expand Up @@ -65,7 +65,7 @@ public override string GetInfo()
return info;
else
return info.Substring(0, pos) + Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatConverter_PartInfoAdd",
Utils.ToSI(systemPower,"F0"),
Utils.ToSI(systemPower, "F0"),
systemOutletTemperature.ToString("F0"),
shutdownTemperature.ToString("F0")
) + info.Substring(pos);
Expand Down Expand Up @@ -131,14 +131,19 @@ protected void GenerateHeatEditor()

protected void GenerateHeatFlight()
{
if (base.ModuleIsActive())
{
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower, true);
}
else
if (base.ModuleIsActive())
{
float fluxScale = 1f;
if (base.lastTimeFactor == 0d)
{
heatModule.AddFlux(moduleID, 0f, 0f, false);
fluxScale = 0f;
}
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower * fluxScale, true);
}
else
{
heatModule.AddFlux(moduleID, 0f, 0f, false);
}
}
protected void UpdateSystemHeatFlight()
{
Expand All @@ -153,9 +158,9 @@ protected void UpdateSystemHeatFlight()
3.0f,
ScreenMessageStyle.UPPER_CENTER));
ToggleResourceConverterAction(new KSPActionParam(0, KSPActionType.Activate));
Utils.Log("[ModuleSystemHeatConverter]: Overheated, shutdown fired", LogType.Modules);

Utils.Log("[ModuleSystemHeatConverter]: Overheated, shutdown fired", LogType.Modules);

}
base._recipe = ModuleUtils.RecalculateRatios(systemEfficiency.Evaluate(heatModule.currentLoopTemperature), inputs, outputs, inputList, outputList, base._recipe);
}
Expand Down
51 changes: 42 additions & 9 deletions SystemHeat/SystemHeat/Modules/ModuleSystemHeatFissionReactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public class ModuleSystemHeatFissionReactor : PartModule, IContractObjectiveModu
[KSPField(isPersistant = true)]
public float CurrentElectricalGeneration = 0f;

/// <summary>
/// Amount of power that could generated by reactor
/// </summary>
[KSPField(isPersistant = true)]
public float MaxElectricalGeneration = 0f;


// Reactor Status string
[KSPField(isPersistant = false, guiActive = true, guiName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Field_GeneratorStatus", groupName = "fissionreactor", groupDisplayName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_UIGroup_Title")]
public string GeneratorStatus;
Expand Down Expand Up @@ -663,6 +670,7 @@ public virtual void FixedUpdate()
if (GeneratesElectricity)
{
CurrentElectricalGeneration = ElectricalGeneration.Evaluate(CurrentThrottle);
MaxElectricalGeneration = CurrentElectricalGeneration;
}

}
Expand Down Expand Up @@ -695,6 +703,7 @@ public virtual void FixedUpdate()
else
{
CurrentElectricalGeneration = 0f;
MaxElectricalGeneration = 0f;
}
}
}
Expand Down Expand Up @@ -783,21 +792,34 @@ private void HandleCore()
}
}

private double[] ecDeltas = new double[60];
protected virtual float CalculateGoalThrottle(float timeStep)
{
double shipEC = 0d;
double shipMaxEC = 0d;
// Determine need for power
part.GetConnectedResourceTotals(PartResourceLibrary.ElectricityHashcode, out shipEC, out shipMaxEC, true);

float maxGeneration = ElectricalGeneration.Evaluate(100f) * CoreIntegrity / 100f;
// Determine need for power this frame
part.GetConnectedResourceTotals(PartResourceLibrary.ElectricityHashcode, out double shipEC, out double shipMaxEC, true);
double[] ecDeltas2 = new double[10];
for (int i = 1; i < ecDeltas2.Length; i++)
{
ecDeltas2[i] = ecDeltas[i - 1];
}
ecDeltas = ecDeltas2;
ecDeltas[0] = shipMaxEC - shipEC;

double weightedAvgNeed = 0d;
for (int i = 0; i < ecDeltas.Length; i++)
{
weightedAvgNeed += ecDeltas[i];
}
weightedAvgNeed /= (double)ecDeltas.Length;

float maxGeneration = ElectricalGeneration.Evaluate(100f) * CoreIntegrity / 100f * timeStep;
float minGeneration = ElectricalGeneration.Evaluate(MinimumThrottle) * timeStep;
float idealGeneration = Mathf.Min(maxGeneration * timeStep, (float)(shipMaxEC - shipEC));
float idealGeneration = Mathf.Min(maxGeneration, (float)weightedAvgNeed * 1.05f);
float powerToGenerate = Mathf.Max(minGeneration, idealGeneration);

return (powerToGenerate / timeStep) / maxGeneration * 100f;
return (powerToGenerate / maxGeneration) * 100f;
}

public virtual string GetContractObjectiveType()
{
return "Generator";
Expand All @@ -814,7 +836,9 @@ private void HandleResourceActivities(float timeStep)
{

if (!ManualControl)
{
CurrentReactorThrottle = CalculateGoalThrottle(timeStep);
}

fuelCheckPassed = true;
burnRate = 0d;
Expand Down Expand Up @@ -858,7 +882,7 @@ private void HandleResourceActivities(float timeStep)
}
}
if (ratio.ResourceName == FuelName)
{
{
burnRate = fuelThrottle * ratio.Ratio;
}
}
Expand All @@ -876,10 +900,19 @@ private void HandleResourceActivities(float timeStep)
if (HighLogic.LoadedSceneIsEditor)
{
CurrentElectricalGeneration = ElectricalGeneration.Evaluate(CurrentReactorThrottle);
MaxElectricalGeneration = CurrentElectricalGeneration;
}
if (fuelCheckPassed)
{
CurrentElectricalGeneration = ElectricalGeneration.Evaluate(CurrentThrottle);
if (ManualControl)
{
MaxElectricalGeneration = CurrentElectricalGeneration;
}
else
{
MaxElectricalGeneration = ElectricalGeneration.Evaluate(100f) * CoreIntegrity / 100f;
}
this.part.RequestResource(PartResourceLibrary.ElectricityHashcode, -CurrentElectricalGeneration * timeStep, ResourceFlowMode.ALL_VESSEL);
}
}
Expand Down
7 changes: 6 additions & 1 deletion SystemHeat/SystemHeat/Modules/ModuleSystemHeatHarvester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ protected void GenerateHeatFlight()
{
if (base.ModuleIsActive())
{
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower, true);
float fluxScale = 1f;
if (base.lastTimeFactor == 0d)
{
fluxScale = 0f;
}
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower * fluxScale, true);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions SystemHeat/SystemHeat/SystemHeat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public static void Load()

settingsNode.TryGetValue("SimulationRateEditor", ref SimulationRateEditor);
settingsNode.TryGetValue("AbsFluxThreshold", ref AbsFluxThreshold);
settingsNode.TryGetValue("HeatLoopDecayCoefficient", ref HeatLoopDecayCoefficient);

settingsNode.TryGetValue("UIScrollSensitivity", ref UISrollSensitivity);

Expand Down
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v0.8.1
------
- Fixed an issue which would cause the heat loop animation in the overlay not to play if there was a loop with only negative fluxes (#125)
- Behavior of things based on stock Converter code (converters, drills, harvesters) should now be more consistent
- Tweaked reporting of Fission Reactor power generation (related to DBS bug)
- Added configurable HeatLoopDecayCoefficient to Settings.cfg

v0.8.0
------
- Updates to zn-ch localization
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
================
SystemHeat 0.8.0
SystemHeat 0.8.1
================

A mod for Kerbal Space Program, intended to provide a better experience for heat management, particularly geared towards resource extraction, high energy engines, and nuclear reactors.
Expand Down

0 comments on commit 6fedc9a

Please sign in to comment.