Skip to content

Commit

Permalink
Fixes and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisAdderley committed Dec 30, 2020
1 parent f5a1f7c commit 4b36b9b
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 27 deletions.
2 changes: 2 additions & 0 deletions GameData/SystemHeat/Localization/en-us.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ Localization
#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_Enable_Title = Enable Reactor
#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_DisableManual_Title = Disable Manual Control
#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_EnableManual_Title = Enable Manual Control
#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_EnableHibernate_Title = Enable Hibernation
#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_DisableHibernate_Title = Disable Hibernation
#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_ShowReactorControl = Toggle Reactor Control
#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_RepairReactor = Repair Reactor
Expand Down
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":3,
"PATCH":2,
"PATCH":3,
"BUILD":0
},
"KSP_VERSION":
Expand Down
1 change: 1 addition & 0 deletions SystemHeat/SystemHeat/HeatLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ void SimulateIteration(float simTimeStep)
float deltaTemperatureIdeal = NetFlux*1000f / (Volume * CoolantType.Density * CoolantType.HeatCapacity) * simTimeStep;



// Flux has be be higher than a tolerance threshold in order to do things
if (absFlux > SystemHeatSettings.AbsFluxThreshold)
{
Expand Down
113 changes: 96 additions & 17 deletions SystemHeat/SystemHeat/Modules/ModuleSystemHeatFissionReactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public class ModuleSystemHeatFissionReactor : PartModule
[KSPField(isPersistant = true)]
public bool Enabled = false;

[KSPField(isPersistant = true)]
public bool HibernateOnWarp = false;

[KSPField(isPersistant = true)]
public bool Hibernating = false;


// Sets user control to manual
[KSPField(isPersistant = true)]
public bool ManualControl = false;
Expand Down Expand Up @@ -163,18 +170,26 @@ public void EnableManual()
{
SetManualControl(true);
}
[KSPEvent(guiActive = true, guiActiveEditor = false, guiName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_DisableManual_Title", active = true, groupName = "fissionreactor", groupDisplayName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_UIGroup_Title", groupStartCollapsed = false)]
[KSPEvent(guiActive = false, guiActiveEditor = false, guiName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_DisableManual_Title", active = true, groupName = "fissionreactor", groupDisplayName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_UIGroup_Title", groupStartCollapsed = false)]
public void DisableManual()
{
SetManualControl(false);
}
/// Toggle control panel
[KSPEvent(guiActive = false, guiName = "Toggle Reactor Control", active = true, groupName = "fissionreactor", groupDisplayName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_UIGroup_Title")]
public void ShowReactorControl()
[KSPEvent(guiActive = true, guiActiveEditor = false, guiName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_EnableHibernate_Title", active = true, groupName = "fissionreactor", groupDisplayName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_UIGroup_Title", groupStartCollapsed = false)]
public void EnableHibernate()
{
HibernateOnWarp = true;
GameEvents.onPartPack.Add(new EventData<Part>.OnEvent(GoOnRails));
GameEvents.onPartUnpack.Add(new EventData<Part>.OnEvent(GoOffRails));
}
[KSPEvent(guiActive = true, guiActiveEditor = false, guiName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_Event_DisableHibernate_Title", active = true, groupName = "fissionreactor", groupDisplayName = "#LOC_SystemHeat_ModuleSystemHeatFissionReactor_UIGroup_Title", groupStartCollapsed = false)]
public void DisableHibernate()
{
/// TODO: UI DAMN
//ReactorUI.ToggleReactorWindow();
HibernateOnWarp = false;
GameEvents.onPartPack.Remove(GoOnRails);
GameEvents.onPartUnpack.Remove(GoOffRails);
}

// Try to fix the reactor
[KSPEvent(externalToEVAOnly = true, guiActiveUnfocused = true, unfocusedRange = 3.5f, guiName = "Repair Reactor")]
public void RepairReactor()
Expand All @@ -186,6 +201,11 @@ public void RepairReactor()
}
/// KSPACTIONS
/// ----------------------

[KSPAction("Toggle Hibernate")]
public void ToggleHibernateAction(KSPActionParam param)
{
}

[KSPAction("Enable Reactor")]
public void EnableAction(KSPActionParam param)
Expand All @@ -206,11 +226,6 @@ public void ToggleAction(KSPActionParam param)
else DisableReactor();
}

[KSPAction("Toggle Reactor Panel")]
public void TogglePanelAction(KSPActionParam param)
{
ShowReactorControl();
}

protected ModuleSystemHeat heatModule;
protected List<ResourceRatio> inputs;
Expand Down Expand Up @@ -243,6 +258,29 @@ public override string GetInfo()

}

public virtual void GoOnRails(Part p)
{

if (HibernateOnWarp && Enabled)
{
Hibernating = true;
ReactorDeactivated();
Utils.Log($"[ModuleSystemHeatFissionReactor] Reactor was on: Going on rails and hibernating reactor");
}
}
public virtual void GoOffRails(Part p)
{

if (HibernateOnWarp)
{
if (Hibernating)
{
ReactorActivated();
Hibernating = false;
Utils.Log($"[ModuleSystemHeatFissionReactor] Going off rails and resuming reactor");
}
}
}
public virtual void SetManualControl(bool state)
{
ManualControl = state;
Expand All @@ -269,7 +307,7 @@ public virtual void Start()
{
ConfigNode node = ModuleUtils.GetModuleConfigNode(part, moduleName);
if (node != null)
OnLoad(node);
OnLoad(node);
}

heatModule = ModuleUtils.FindHeatModule(this.part, systemHeatModuleID);
Expand Down Expand Up @@ -313,6 +351,12 @@ public virtual void Start()
if (HighLogic.LoadedSceneIsFlight)
{
GameEvents.OnVesselRollout.Add(new EventData<ShipConstruct>.OnEvent(OnVesselRollout));
if (HibernateOnWarp)
{
GameEvents.onPartPack.Add(new EventData<Part>.OnEvent(GoOnRails));
GameEvents.onPartUnpack.Add(new EventData<Part>.OnEvent(GoOffRails));
}

DoCatchup();
SetManualControl(ManualControl);

Expand All @@ -323,6 +367,9 @@ void OnDestroy()
{
// Clean up events when the item is destroyed
GameEvents.OnVesselRollout.Remove(OnVesselRollout);

GameEvents.onPartPack.Remove(GoOnRails);
GameEvents.onPartUnpack.Remove(GoOffRails);
}
/// <summary>
///
Expand Down Expand Up @@ -393,6 +440,11 @@ public void Update()
Events["DisableReactor"].active = Enabled;
Events["EnableReactor"].active = !Enabled;
}
if (Events["EnableHibernate"].active == HibernateOnWarp || Events["DisableHibernate"].active != HibernateOnWarp)
{
Events["DisableHibernate"].active = HibernateOnWarp;
Events["EnableHibernate"].active = !HibernateOnWarp;
}
}
}

Expand Down Expand Up @@ -532,6 +584,18 @@ private void HandleResourceActivities(float timeStep)
float fuelThrottle = CurrentReactorThrottle / 100f;

bool fuelCheckPassed = true;

// Check for full-ness
foreach (ResourceRatio ratio in outputs)
{
if (CheckFull(ratio.ResourceName, fuelThrottle * ratio.Ratio * timeStep))
{
ReactorDeactivated();
return;
}

}
// CHeck for fuel and consume
foreach (ResourceRatio ratio in inputs)
{
double amt = this.part.RequestResource(ratio.ResourceName, fuelThrottle * ratio.Ratio * timeStep, ratio.FlowMode);
Expand All @@ -543,18 +607,21 @@ private void HandleResourceActivities(float timeStep)
if (ratio.ResourceName == FuelName)
burnRate = ratio.Ratio;
}
// If fuel consumed, add waste
if (fuelCheckPassed)
{
foreach (ResourceRatio ratio in outputs)
{
double amt = this.part.RequestResource(ratio.ResourceName, -fuelThrottle * ratio.Ratio * timeStep, ratio.FlowMode);
}
}

if (GeneratesElectricity)
{
if (HighLogic.LoadedSceneIsEditor)
CurrentElectricalGeneration = ElectricalGeneration.Evaluate(CurrentReactorThrottle);
if (fuelCheckPassed)
{
foreach (ResourceRatio ratio in outputs)
{
double amt = this.part.RequestResource(ratio.ResourceName, -fuelThrottle * ratio.Ratio * timeStep, ratio.FlowMode);
}

CurrentElectricalGeneration = ElectricalGeneration.Evaluate(CurrentThrottle);
this.part.RequestResource(PartResourceLibrary.ElectricityHashcode, -CurrentElectricalGeneration * timeStep, ResourceFlowMode.ALL_VESSEL);

Expand All @@ -572,8 +639,20 @@ private void HandleResourceActivities(float timeStep)
burnRate);

}
public bool CheckFull(string nm, double eps)
{

if (this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(nm).id) != null)
if (this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(nm).id).amount + eps >=
this.part.Resources.Get(PartResourceLibrary.Instance.GetDefinition(nm).id).maxAmount)
return true;
else
return false;


return false;
}

#region Repair
public bool TryRepairReactor()
{
Expand Down
22 changes: 14 additions & 8 deletions SystemHeat/SystemHeat/Modules/ModuleSystemHeatRadiator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SystemHeat
/// <summary>
/// The connection between a stock ModuleActiveRadiator and the SystemHeat system
/// </summary>
public class ModuleSystemHeatRadiator: ModuleActiveRadiator
public class ModuleSystemHeatRadiator : ModuleActiveRadiator
{
// This should be unique on the part and identifies the module
[KSPField(isPersistant = false)]
Expand Down Expand Up @@ -52,11 +52,11 @@ public override string GetModuleDisplayName()
public override string GetInfo()
{
// Need to update this to strip the CoreHeat stuff from it
string message = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatRadiator_PartInfo",
temperatureCurve.Curve.keys[0].time.ToString("F0"),
string message = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatRadiator_PartInfo",
temperatureCurve.Curve.keys[0].time.ToString("F0"),
temperatureCurve.Evaluate(temperatureCurve.Curve.keys[0].time).ToString("F0"),
temperatureCurve.Evaluate(temperatureCurve.Curve.keys[temperatureCurve.Curve.keys.Length - 1].time).ToString("F0"),
temperatureCurve.Curve.keys[temperatureCurve.Curve.keys.Length-1].time.ToString("F0")
temperatureCurve.Curve.keys[temperatureCurve.Curve.keys.Length - 1].time.ToString("F0")
);
message += base.GetInfo();
return message;
Expand All @@ -74,8 +74,11 @@ public override void FixedUpdate()
if (base.IsCooling)
{
float flux = -temperatureCurve.Evaluate(heatModule.LoopTemperature);
heatModule.AddFlux(moduleID, 0f, flux);
RadiatorEfficiency = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatRadiator_RadiatorEfficiency_Running",
if (heatModule.LoopTemperature >= heatModule.nominalLoopTemperature)
heatModule.AddFlux(moduleID, 0f, flux);
else
heatModule.AddFlux(moduleID, 0f, 0f);
RadiatorEfficiency = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatRadiator_RadiatorEfficiency_Running",
(-flux / temperatureCurve.Evaluate(temperatureCurve.Curve.keys[temperatureCurve.Curve.keys.Length - 1].time) * 100f).ToString("F0"));
}
else
Expand All @@ -89,10 +92,13 @@ public override void FixedUpdate()
if (HighLogic.LoadedSceneIsEditor)
{
float flux = -1.0f * temperatureCurve.Evaluate(heatModule.LoopTemperature);
heatModule.AddFlux(moduleID, 0f, flux);
if (heatModule.LoopTemperature >= heatModule.nominalLoopTemperature)
heatModule.AddFlux(moduleID, 0f, flux);
else
heatModule.AddFlux(moduleID, 0f, 0f);

//Utils.Log($"BLAH {heatModule.LoopTemperature} {flux} {temperatureCurve.Evaluate(heatModule.LoopTemperature)}");
RadiatorEfficiency = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatRadiator_RadiatorEfficiency_Running",
RadiatorEfficiency = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatRadiator_RadiatorEfficiency_Running",
((-temperatureCurve.Evaluate(heatModule.LoopTemperature) / temperatureCurve.Evaluate(temperatureCurve.Curve.keys[temperatureCurve.Curve.keys.Length - 1].time)) * 100f).ToString("F0"));
}
}
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.3.3
------
- Fixed fission reactors still generating power/working when they were full of waste
- Fixed fission reactors that didn't generate electricity not generating waste
- Added Hibernate On Warp control to fission reactors: if activated, an enabled reactor will turn off when the ship goes on rails. It will reactivate when the ship goes off rails.
- Fixed a bug in loop integration that could cause strange behaviour below norminal temperatures

v0.3.2
------
- Heat Control radiator names are now adjusted when installed to match their SystemHeat capacities
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.3.2
SystemHeat 0.3.3
================

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 4b36b9b

Please sign in to comment.