Skip to content

Commit

Permalink
Actually store the utilizations alongside the propellants in FuelInfo…
Browse files Browse the repository at this point in the history
… objects.
  • Loading branch information
NathanKell committed Jul 16, 2021
1 parent f5beb31 commit 0c0deb9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Source/Tanks/FuelInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal class FuelInfo
{
public string names;
public readonly List<Propellant> propellants;
public readonly List<double> volumeMults;
public readonly double efficiency;
public readonly double ratioFactor;

Expand All @@ -26,12 +27,13 @@ public string Label
{
get {
string label = "";
foreach (Propellant tfuel in propellants) {
for (int i = 0; i < propellants.Count; ++i) {
Propellant tfuel = propellants[i];
if (PartResourceLibrary.Instance.GetDefinition (tfuel.name).resourceTransferMode != ResourceTransferMode.NONE && !IgnoreFuel (tfuel.name)) {
if (label.Length > 0) {
label += " / ";
}
label += Math.Round (100000 * tfuel.ratio / efficiency, 0)*0.001 + "% " + tfuel.name;
label += Math.Round (100000 * tfuel.ratio * volumeMults[i] / efficiency, 0)*0.001 + "% " + tfuel.name;
}
}
return label;
Expand All @@ -47,8 +49,10 @@ public FuelInfo (List<Propellant> props, ModuleFuelTanks tank, string title)
ratioFactor = 0.0;
efficiency = 0.0;
propellants = props;
volumeMults = new List<double>(props.Count);

foreach (Propellant tfuel in propellants) {
for (int i = 0; i < propellants.Count; ++i) {
Propellant tfuel = propellants[i];
if (PartResourceLibrary.Instance.GetDefinition (tfuel.name) == null) {
Debug.LogError ("Unknown RESOURCE {" + tfuel.name + "}");
ratioFactor = 0.0;
Expand All @@ -57,8 +61,10 @@ public FuelInfo (List<Propellant> props, ModuleFuelTanks tank, string title)
if (PartResourceLibrary.Instance.GetDefinition (tfuel.name).resourceTransferMode != ResourceTransferMode.NONE) {
FuelTank t;
if (tank.tankList.TryGet (tfuel.name, out t)) {
efficiency += tfuel.ratio/t.utilization;
double volumeMultiplier = 1d / t.utilization;
efficiency += tfuel.ratio * volumeMultiplier;
ratioFactor += tfuel.ratio;
volumeMults.Add(volumeMultiplier);
} else if (!IgnoreFuel (tfuel.name)) {
ratioFactor = 0.0;
break;
Expand Down

0 comments on commit 0c0deb9

Please sign in to comment.