Skip to content

Commit

Permalink
Merge pull request #124 from post-kerbin-mining-corporation/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
ChrisAdderley authored Oct 7, 2021
2 parents f3f4521 + 0e13cc7 commit 2bb56a9
Show file tree
Hide file tree
Showing 9 changed files with 421 additions and 243 deletions.
Binary file modified GameData/CryoTanks/Plugins/SimpleBoiloff.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions GameData/CryoTanks/Versioning/CryoTanks.version
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
{
"MAJOR":1,
"MINOR":6,
"PATCH":1,
"PATCH":2,
"BUILD":0
},
"KSP_VERSION":
{
"MAJOR":1,
"MINOR":12,
"PATCH":1
"PATCH":2
},
"KSP_VERSION_MIN":{
"MAJOR":1,
Expand Down
Binary file added Source/.vs/SimpleBoiloff/v16/.suo
Binary file not shown.
140 changes: 140 additions & 0 deletions Source/BoiloffFuel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;

namespace SimpleBoiloff
{
/// <summary>
/// Represents a fuel resource on a part that boils off
/// </summary>
[System.Serializable]
public class BoiloffFuel
{
/// <summary>
/// Fuel name
/// </summary>
public string fuelName;

/// <summary>
/// Boiloff rate in %/hr
/// </summary>
public float boiloffRate;

/// <summary>
/// Cooling cost in EC/1000u
/// </summary>
public float coolingCost;

public PartResource resource;
public List<ResourceRatio> outputs;
public float boiloffRateSeconds = 0f;

public bool fuelPresent = false;
int id = -1;
Part part;

/// <summary>
/// Constructor
/// </summary>
/// <param name="node"></param>
/// <param name="p"></param>
public BoiloffFuel(ConfigNode node, Part p)
{
part = p;
node.TryGetValue("FuelName", ref fuelName);
node.TryGetValue("BoiloffRate", ref boiloffRate);
node.TryGetValue("CoolingCost", ref coolingCost);


ConfigNode[] outNodes = node.GetNodes("OUTPUT_RESOURCE");

if (outNodes.Length > 0 || outputs == null)
outputs = new List<ResourceRatio>();
{
for (int i = 0; i < outNodes.Length; i++)
{
ResourceRatio r = new ResourceRatio();
r.Load(outNodes[i]);
outputs.Add(r);
}
}
}

/// <summary>
/// Initialize the fuel
/// </summary>
public void Initialize()
{
id = PartResourceLibrary.Instance.GetDefinition(fuelName).id;
resource = part.Resources.Get(id);
boiloffRateSeconds = boiloffRate / 100f / 3600f;
fuelPresent = true;
}

/// <summary>
/// Returns the max amount of the fuel on the part
/// </summary>
/// <returns></returns>
public double FuelAmountMax()
{
if (fuelPresent)
return resource.maxAmount;
return 0d;
}

/// <summary>
/// Returns the amount of the fuel on the part
/// </summary>
/// <returns></returns>
public double FuelAmount()
{
if (fuelPresent)
return resource.amount;
return 0d;
}

/// <summary>
/// Returns the cost to cool the fuel
/// </summary>
/// <returns></returns>
public float FuelCoolingCost()
{
if (fuelPresent)
return coolingCost;
return 0f;
}

/// <summary>
/// Returns the cost to cool fuel not considering current contents
/// </summary>
/// <returns></returns>
public float FuelConfiguredCoolingCost()
{
return coolingCost;
}

/// <summary>
/// Appplies boiloff, given a time interval and a scale
/// </summary>
/// <param name="seconds"></param>
/// <param name="scale"></param>
public void Boiloff(double seconds, double scale)
{
if (fuelPresent)
{
double toBoil = resource.amount * (1.0 - Math.Pow(1.0 - boiloffRateSeconds, seconds)) * scale;

double boilResult = part.RequestResource(resource.info.id, toBoil, ResourceFlowMode.NO_FLOW);

/// Generate outputs
if (outputs.Count > 0)
{
for (int i = 0; i < outputs.Count; i++)
{
part.RequestResource(outputs[i].ResourceName, -boilResult * outputs[i].Ratio, outputs[i].FlowMode);
}
}
}
}
}

}
Loading

0 comments on commit 2bb56a9

Please sign in to comment.