Skip to content

Commit 6fedc9a

Browse files
Merge pull request #128 from post-kerbin-mining-corporation/dev
Release 0.8.1
2 parents 480a688 + 1bada27 commit 6fedc9a

12 files changed

Lines changed: 94 additions & 28 deletions
512 Bytes
Binary file not shown.

GameData/SystemHeat/Versioning/SystemHeat.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"MAJOR":0,
88
"MINOR":8,
9-
"PATCH":0,
9+
"PATCH":1,
1010
"BUILD":0
1111
},
1212
"KSP_VERSION":

SystemHeat/SystemHeat/HeatLoop.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ protected float CalculatePositiveFlux()
196196
return currentPosFlux;
197197
}
198198
/// <summary>
199-
/// Calculates the total positive flux of the loop
199+
/// Calculates the total negative flux of the loop
200200
/// </summary>
201201
protected float CalculateNegativeFlux()
202202
{
@@ -220,7 +220,7 @@ void SimulateIteration(float simTimeStep)
220220
// Calculate the loop net flux
221221
float currentNetFlux = CalculateNetFlux();
222222
PositiveFlux = CalculatePositiveFlux();
223-
NegativeFlux = CalculatePositiveFlux();
223+
NegativeFlux = CalculateNegativeFlux();
224224
float absFlux = Mathf.Abs(currentNetFlux);
225225

226226
AllocateFlux(PositiveFlux);

SystemHeat/SystemHeat/Modules/ModuleSystemHeatAsteroidHarvester.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ protected void GenerateHeatFlight()
104104
{
105105
if (base.ModuleIsActive())
106106
{
107-
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower, true);
107+
float fluxScale = 1f;
108+
if (base.lastTimeFactor == 0d)
109+
{
110+
fluxScale = 0f;
111+
}
112+
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower * fluxScale, true);
108113
}
109114
else
110115
{

SystemHeat/SystemHeat/Modules/ModuleSystemHeatBaseConverterAdapter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ void GenerateHeatFlight()
111111
{
112112
if (converterModule.ModuleIsActive())
113113
{
114-
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower, true);
114+
float fluxScale = 1f;
115+
if (converterModule.lastTimeFactor == 0d)
116+
{
117+
fluxScale = 0f;
118+
}
119+
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower * fluxScale, true);
115120
}
116121
else
117122
{

SystemHeat/SystemHeat/Modules/ModuleSystemHeatCometHarvester.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ protected void GenerateHeatEditor()
9191
{
9292
if (base.IsActivated)
9393
{
94-
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower, true);
94+
float fluxScale = 1f;
95+
if (base.lastTimeFactor == 0d)
96+
{
97+
fluxScale = 0f;
98+
}
99+
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower * fluxScale, true);
95100
}
96101
else
97102
{

SystemHeat/SystemHeat/Modules/ModuleSystemHeatConverter.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ModuleSystemHeatConverter : ModuleResourceConverter
2727

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

3232

3333
//
@@ -65,7 +65,7 @@ public override string GetInfo()
6565
return info;
6666
else
6767
return info.Substring(0, pos) + Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatConverter_PartInfoAdd",
68-
Utils.ToSI(systemPower,"F0"),
68+
Utils.ToSI(systemPower, "F0"),
6969
systemOutletTemperature.ToString("F0"),
7070
shutdownTemperature.ToString("F0")
7171
) + info.Substring(pos);
@@ -131,14 +131,19 @@ protected void GenerateHeatEditor()
131131

132132
protected void GenerateHeatFlight()
133133
{
134-
if (base.ModuleIsActive())
135-
{
136-
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower, true);
137-
}
138-
else
134+
if (base.ModuleIsActive())
135+
{
136+
float fluxScale = 1f;
137+
if (base.lastTimeFactor == 0d)
139138
{
140-
heatModule.AddFlux(moduleID, 0f, 0f, false);
139+
fluxScale = 0f;
141140
}
141+
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower * fluxScale, true);
142+
}
143+
else
144+
{
145+
heatModule.AddFlux(moduleID, 0f, 0f, false);
146+
}
142147
}
143148
protected void UpdateSystemHeatFlight()
144149
{
@@ -153,9 +158,9 @@ protected void UpdateSystemHeatFlight()
153158
3.0f,
154159
ScreenMessageStyle.UPPER_CENTER));
155160
ToggleResourceConverterAction(new KSPActionParam(0, KSPActionType.Activate));
156-
157-
Utils.Log("[ModuleSystemHeatConverter]: Overheated, shutdown fired", LogType.Modules);
158-
161+
162+
Utils.Log("[ModuleSystemHeatConverter]: Overheated, shutdown fired", LogType.Modules);
163+
159164
}
160165
base._recipe = ModuleUtils.RecalculateRatios(systemEfficiency.Evaluate(heatModule.currentLoopTemperature), inputs, outputs, inputList, outputList, base._recipe);
161166
}

SystemHeat/SystemHeat/Modules/ModuleSystemHeatFissionReactor.cs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ public class ModuleSystemHeatFissionReactor : PartModule, IContractObjectiveModu
9595
[KSPField(isPersistant = true)]
9696
public float CurrentElectricalGeneration = 0f;
9797

98+
/// <summary>
99+
/// Amount of power that could generated by reactor
100+
/// </summary>
101+
[KSPField(isPersistant = true)]
102+
public float MaxElectricalGeneration = 0f;
103+
104+
98105
// Reactor Status string
99106
[KSPField(isPersistant = false, guiActive = true, guiName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Field_GeneratorStatus", groupName = "fissionreactor", groupDisplayName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_UIGroup_Title")]
100107
public string GeneratorStatus;
@@ -663,6 +670,7 @@ public virtual void FixedUpdate()
663670
if (GeneratesElectricity)
664671
{
665672
CurrentElectricalGeneration = ElectricalGeneration.Evaluate(CurrentThrottle);
673+
MaxElectricalGeneration = CurrentElectricalGeneration;
666674
}
667675

668676
}
@@ -695,6 +703,7 @@ public virtual void FixedUpdate()
695703
else
696704
{
697705
CurrentElectricalGeneration = 0f;
706+
MaxElectricalGeneration = 0f;
698707
}
699708
}
700709
}
@@ -783,21 +792,34 @@ private void HandleCore()
783792
}
784793
}
785794

795+
private double[] ecDeltas = new double[60];
786796
protected virtual float CalculateGoalThrottle(float timeStep)
787797
{
788-
double shipEC = 0d;
789-
double shipMaxEC = 0d;
790-
// Determine need for power
791-
part.GetConnectedResourceTotals(PartResourceLibrary.ElectricityHashcode, out shipEC, out shipMaxEC, true);
792798

793-
float maxGeneration = ElectricalGeneration.Evaluate(100f) * CoreIntegrity / 100f;
799+
// Determine need for power this frame
800+
part.GetConnectedResourceTotals(PartResourceLibrary.ElectricityHashcode, out double shipEC, out double shipMaxEC, true);
801+
double[] ecDeltas2 = new double[10];
802+
for (int i = 1; i < ecDeltas2.Length; i++)
803+
{
804+
ecDeltas2[i] = ecDeltas[i - 1];
805+
}
806+
ecDeltas = ecDeltas2;
807+
ecDeltas[0] = shipMaxEC - shipEC;
808+
809+
double weightedAvgNeed = 0d;
810+
for (int i = 0; i < ecDeltas.Length; i++)
811+
{
812+
weightedAvgNeed += ecDeltas[i];
813+
}
814+
weightedAvgNeed /= (double)ecDeltas.Length;
815+
816+
float maxGeneration = ElectricalGeneration.Evaluate(100f) * CoreIntegrity / 100f * timeStep;
794817
float minGeneration = ElectricalGeneration.Evaluate(MinimumThrottle) * timeStep;
795-
float idealGeneration = Mathf.Min(maxGeneration * timeStep, (float)(shipMaxEC - shipEC));
818+
float idealGeneration = Mathf.Min(maxGeneration, (float)weightedAvgNeed * 1.05f);
796819
float powerToGenerate = Mathf.Max(minGeneration, idealGeneration);
797820

798-
return (powerToGenerate / timeStep) / maxGeneration * 100f;
821+
return (powerToGenerate / maxGeneration) * 100f;
799822
}
800-
801823
public virtual string GetContractObjectiveType()
802824
{
803825
return "Generator";
@@ -814,7 +836,9 @@ private void HandleResourceActivities(float timeStep)
814836
{
815837

816838
if (!ManualControl)
839+
{
817840
CurrentReactorThrottle = CalculateGoalThrottle(timeStep);
841+
}
818842

819843
fuelCheckPassed = true;
820844
burnRate = 0d;
@@ -858,7 +882,7 @@ private void HandleResourceActivities(float timeStep)
858882
}
859883
}
860884
if (ratio.ResourceName == FuelName)
861-
{
885+
{
862886
burnRate = fuelThrottle * ratio.Ratio;
863887
}
864888
}
@@ -876,10 +900,19 @@ private void HandleResourceActivities(float timeStep)
876900
if (HighLogic.LoadedSceneIsEditor)
877901
{
878902
CurrentElectricalGeneration = ElectricalGeneration.Evaluate(CurrentReactorThrottle);
903+
MaxElectricalGeneration = CurrentElectricalGeneration;
879904
}
880905
if (fuelCheckPassed)
881906
{
882907
CurrentElectricalGeneration = ElectricalGeneration.Evaluate(CurrentThrottle);
908+
if (ManualControl)
909+
{
910+
MaxElectricalGeneration = CurrentElectricalGeneration;
911+
}
912+
else
913+
{
914+
MaxElectricalGeneration = ElectricalGeneration.Evaluate(100f) * CoreIntegrity / 100f;
915+
}
883916
this.part.RequestResource(PartResourceLibrary.ElectricityHashcode, -CurrentElectricalGeneration * timeStep, ResourceFlowMode.ALL_VESSEL);
884917
}
885918
}

SystemHeat/SystemHeat/Modules/ModuleSystemHeatHarvester.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ protected void GenerateHeatFlight()
118118
{
119119
if (base.ModuleIsActive())
120120
{
121-
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower, true);
121+
float fluxScale = 1f;
122+
if (base.lastTimeFactor == 0d)
123+
{
124+
fluxScale = 0f;
125+
}
126+
heatModule.AddFlux(moduleID, systemOutletTemperature, systemPower * fluxScale, true);
122127
}
123128
else
124129
{

SystemHeat/SystemHeat/SystemHeat.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public static void Load()
165165

166166
settingsNode.TryGetValue("SimulationRateEditor", ref SimulationRateEditor);
167167
settingsNode.TryGetValue("AbsFluxThreshold", ref AbsFluxThreshold);
168+
settingsNode.TryGetValue("HeatLoopDecayCoefficient", ref HeatLoopDecayCoefficient);
168169

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

0 commit comments

Comments
 (0)