Skip to content

Commit

Permalink
Boiloff
Browse files Browse the repository at this point in the history
Changed config setting to hours.
Added rate adjustment and difficulty presets to settings.
Check ShieldedFromAirstream and reduce rate (assume shielding is  insulation).
Don't vent when engine is drawing from tank.
  • Loading branch information
jsolson committed Oct 8, 2016
1 parent 0bbe7ed commit da992a5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
CRYOGENICRESOURCE
{
name = LqdHydrogen
boiloffRate = 2
boiloffRate = 8
}
}
}
Expand All @@ -108,7 +108,7 @@
CRYOGENICRESOURCE
{
name = LqdHydrogen
boiloffRate = 2
boiloffRate = 8
}
}
}
Expand Down
Binary file modified Gamedata/Bluedog_DB/Plugins/BDB.dll
Binary file not shown.
43 changes: 28 additions & 15 deletions Source/VisualStudio/BDB/BDB/Boiloff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ModuleBdbBoiloff : PartModule
public string boiloffDisplay = "";

private List<CryoResourceItem> cryoResources;
private double dayLength;
private bool boiloffEnabled;
private double boiloffMultiplier;
private bool hasCryoResource = false;

public override void OnAwake()
Expand Down Expand Up @@ -73,12 +74,9 @@ public void Start()
{
if (HighLogic.LoadedSceneIsFlight)
{
CelestialBody homeBody = FlightGlobals.GetHomeBody();
double period = homeBody.orbit.period;
dayLength = homeBody.solarDayLength; // can this be zero?
double periodDays = period / dayLength;
Debug.LogFormat("Home body {0} year length: {1}, {2}", homeBody.bodyName, periodDays.ToString("0.0"), dayLength.ToString("0.00"));

boiloffEnabled = HighLogic.CurrentGame.Parameters.CustomParams<BdbCustomParams>().boiloffEnabled;
boiloffMultiplier = HighLogic.CurrentGame.Parameters.CustomParams<BdbCustomParams>().boiloffMultiplier;

foreach (CryoResourceItem item in cryoResources)
{
if (part.Resources.Contains(item.name))
Expand All @@ -93,7 +91,7 @@ public void Start()

public void Update()
{
if (HighLogic.LoadedSceneIsFlight && hasCryoResource && HighLogic.CurrentGame.Parameters.CustomParams<BdbCustomParams>().boiloffEnabled)
if (HighLogic.LoadedSceneIsFlight && hasCryoResource && boiloffEnabled)
{
double currentTime = Planetarium.GetUniversalTime();
if (lastUpdateTime < 0)
Expand All @@ -106,18 +104,32 @@ public void Update()
string s = "";
foreach (CryoResourceItem item in cryoResources)
{
double halfLife = item.boiloffRate * dayLength;

if (halfLife > 0 && part.Resources.Contains(item.name) && part.Resources[item.name].amount > 0)
double halfLife = item.boiloffRate / boiloffMultiplier * 60 * 60;
if (part.ShieldedFromAirstream)
{
halfLife *= 10; // We'll pretend shielding acts as insulation.
}
double resourceAmount = part.Resources[item.name].amount;
if (halfLife > 0 && resourceAmount > 0)
{
double amt0 = part.Resources[item.name].amount;
double amt0 = resourceAmount;
double amtT = amt0 * Math.Pow(0.5, deltaTime / halfLife);
double deltaAmount = amt0 - amtT;
part.RequestResource(item.name, deltaAmount, ResourceFlowMode.NO_FLOW);

double resourceConsumed = Math.Max(item.lastAmount - resourceAmount, 0); // Amount being drawn from tank, i.e. engine running.
deltaAmount = Math.Max(deltaAmount - resourceConsumed, 0);

if (deltaAmount > 0)
{
part.RequestResource(item.name, deltaAmount, ResourceFlowMode.NO_FLOW);
}
if (s != "")
{
s += ", ";
s += item.name + " " + (deltaAmount * (1 / deltaTime) * 60 * 60).ToString("0") + "/hr";
}
s += item.name + " " + (deltaAmount * (1 / deltaTime) * 60 * 60).ToString("0.0") + "/hr";
}
item.lastAmount = part.Resources[item.name].amount;
}
boiloffDisplay = s;
lastUpdateTime = currentTime;
Expand All @@ -135,7 +147,8 @@ class CryoResourceItem
{
public static string itemName = "CRYOGENICRESOURCE";
public string name = "";
public double boiloffRate = -1.0f;
public double boiloffRate = -1.0;
public double lastAmount = -1.0;

public CryoResourceItem()
{
Expand Down
4 changes: 2 additions & 2 deletions Source/VisualStudio/BDB/BDB/DecouplerAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void Start()
}
}

public void SetAninmation(float position, float speed = 0.0f)
public void SetAnimation(float position, float speed = 0.0f)
{
animPosition = position;
animSpeed = speed;
Expand Down Expand Up @@ -334,7 +334,7 @@ public bool IsMultipleCubesActive
{
get
{
throw new NotImplementedException();
return false;
}
}

Expand Down
17 changes: 15 additions & 2 deletions Source/VisualStudio/BDB/BDB/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,32 @@ public class BdbCustomParams : GameParameters.CustomParameterNode
public override bool HasPresets { get { return true; } }
[GameParameters.CustomParameterUI("Cryogenic Boiloff Enabled?", toolTip = "Set to enable boiloff of cryogenic fuel (liquid hydrogen).")]
public bool boiloffEnabled = true;
[GameParameters.CustomFloatParameterUI("Boiloff Rate", asPercentage = true)]
public double boiloffMultiplier = 0.5;

public override void SetDifficultyPreset(GameParameters.Preset preset)
{
Debug.Log("Setting difficulty preset");
switch (preset)
{
case GameParameters.Preset.Easy:
boiloffEnabled = false;
boiloffEnabled = true;
boiloffMultiplier = 0.25;
break;

case GameParameters.Preset.Normal:
boiloffEnabled = true;
boiloffMultiplier = 0.5;
break;

case GameParameters.Preset.Moderate:
boiloffEnabled = true;
boiloffMultiplier = 0.75;
break;

case GameParameters.Preset.Hard:
boiloffEnabled = true;
boiloffMultiplier = 1.0;
break;
}
}
Expand All @@ -48,7 +54,14 @@ public override bool Enabled(MemberInfo member, GameParameters parameters)

public override bool Interactible(MemberInfo member, GameParameters parameters)
{
return true;
if (HighLogic.fetch != null)
{
if (HighLogic.LoadedScene == GameScenes.MAINMENU || HighLogic.LoadedScene == GameScenes.SETTINGS || HighLogic.LoadedScene == GameScenes.SPACECENTER)
{
return (member.Name == "boiloffEnabled" || boiloffEnabled);
}
}
return false;
}

public override IList ValidValues(MemberInfo member)
Expand Down

0 comments on commit da992a5

Please sign in to comment.