Skip to content

Commit

Permalink
Use ROUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanKell committed Nov 8, 2023
1 parent b9eb40b commit b49aff7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 54 deletions.
52 changes: 6 additions & 46 deletions Source/Engines/ModuleEnginesRF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SolverEngines;
using System.Linq;
using KSP.Localization;
using ROUtils;

namespace RealFuels
{
Expand Down Expand Up @@ -886,23 +887,7 @@ public string GetUllageIgnition()
return output;
}

protected static bool _needCheckRO = true;
protected static System.Reflection.MethodInfo _roPrintRate = null;
protected static System.Reflection.MethodInfo _ROPrintRate
{
get
{
if (_needCheckRO)
{
_needCheckRO = false;
Type ruiType = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.name == "RealismOverhaul")?.assembly.GetType("RealismOverhaul.ResourceUnits");
if (ruiType != null)
_roPrintRate = ruiType.GetMethod("PrintRate");
}
return _roPrintRate;
}
}


public override string GetInfo()
{
string output = $"{GetThrustInfo()}" +
Expand All @@ -922,37 +907,12 @@ public override string GetInfo()
foreach (Propellant p in propellants)
{
float unitsSec = getMaxFuelFlow(p);
if (_ROPrintRate == null)
{
string units = (p.name == "ElectricCharge") ? "kW" : "L";
string rate = (p.name == "ElectricCharge") ? string.Empty : "/s";
string sUse = $"{unitsSec:G4}{units}{rate}";
if (PartResourceLibrary.Instance?.GetDefinition(p.id) is PartResourceDefinition def && def.density > 0)
{
double tons = unitsSec * def.density;
massFlow += tons;
sUse += $" ({tons * 1000d:G4} kg{rate})";
}
output += $"- <b>{KSPUtil.PrintModuleName(p.name)}</b>: {Localizer.Format("#RF_EngineRF_maximumUses", sUse)}.\n"; // {sUse} maximum
}
else
{
// we manually add flow mode later
string rate = (string)_ROPrintRate.Invoke(null, new object[] { (double)unitsSec, p.id, true, null, p, true, 3, false });
if (PartResourceLibrary.Instance?.GetDefinition(p.id) is PartResourceDefinition def && def.density > 0)
{
double tons = unitsSec * def.density;
massFlow += tons;
}
output += rate;
}
output += p.GetFlowModeDescription();
massFlow += unitsSec * p.resourceDef.density;
output += ResourceUnits.PrintRate(unitsSec, p.id, true, null, p, true);
}
if (massFlow > 0d)
{
string totalMassRate = massFlow < 1d ? KSPUtil.PrintSI(massFlow * 1000d * 1000d, "g") : KSPUtil.PrintSI(massFlow, "t");
output += Localizer.Format("#autoLOC_900654") + " " + Localizer.Format("#autoLOC_6001048", totalMassRate) + "\n";
}
output += Localizer.Format("#autoLOC_900654") + " " + Localizer.Format(ResourceUnits.PerSecLocString, ResourceUnits.PrintMass(massFlow)) + "\n";

output += Localizer.Format("#RF_EngineRF_GetInfo3", $"{localVaryIsp:P2}", $"{localVaryFlow:P1}", $"{localVaryMixture:P2}"); // $"<b>Variance: </b>{localVaryIsp:P2} Isp, {localVaryFlow:P1} flow, {localVaryMixture:P2} MR (stddev).\n"
output += Localizer.Format("#RF_EngineRF_GetInfo4", $"{localResidualsThresholdBase:P1}"); // $"<b>Residuals: min </b>{localResidualsThresholdBase:P1} of propellant.\n"

Expand Down
4 changes: 4 additions & 0 deletions Source/RealFuels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<Reference Include="Assembly-CSharp">
<Private>False</Private>
</Reference>
<Reference Include="ROUtils">
<HintPath>..\..\..\..\..\..\Games\R112\GameData\ROUtils\Plugins\ROUtils.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SolverEngines">
<Private>False</Private>
<HintPath>..\..\SolverEngines\SolverEngines\obj\Release\SolverEngines.dll</HintPath>
Expand Down
7 changes: 3 additions & 4 deletions Source/Tanks/ModuleFuelTanks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using KSP.UI.Screens;
using System.Reflection;
using KSP.Localization;
using ROUtils;

// ReSharper disable InconsistentNaming, CompareOfFloatsByEqualityOperator

Expand Down Expand Up @@ -731,9 +732,7 @@ public void ChangeVolumeRatio (double ratio, bool propagate = false)
public float baseCostPV;
public float basemassConst;
public float baseCostConst;

public static string FormatMass(float mass) => mass < 1.0f ? KSPUtil.PrintSI(mass * 1e6, "g", 4) : KSPUtil.PrintSI(mass, "t", 4);


private void ParseBaseMass (ConfigNode node)
{
string baseMass = "";
Expand Down Expand Up @@ -819,7 +818,7 @@ public void CalculateMass ()
double resourceMass = part.Resources.Cast<PartResource> ().Sum (partResource => partResource.maxAmount* partResource.info.density);

double wetMass = mass + resourceMass;
massDisplay = Localizer.Format("#RF_FuelTank_volumeDisplayinfo2", FormatMass(mass), FormatMass((float)wetMass)); // "Dry: " + FormatMass (mass) + " / Wet: " + FormatMass ((float)wetMass)
massDisplay = Localizer.Format("#RF_FuelTank_volumeDisplayinfo2", ResourceUnits.PrintMass(mass), ResourceUnits.PrintMass(wetMass)); // "Dry: " + FormatMass (mass) + " / Wet: " + FormatMass ((float)wetMass)

UpdateTweakableMenu ();
}
Expand Down
5 changes: 3 additions & 2 deletions Source/Tanks/TankWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ROUtils;

using KSP.UI.Screens;
using System.Linq;
Expand Down Expand Up @@ -73,8 +74,8 @@ private void EnsureFreshAddLabelCache()
if (tank_module.AvailableVolume != oldAvailableVolume || tank_module.type != oldTankType){
foreach (FuelTank tank in tank_module.tanksDict.Values) {
double maxVol = tank_module.AvailableVolume * tank.utilization;
string maxVolStr = KSPUtil.PrintSI(maxVol, "L");
string label = $"{Localizer.GetStringByTag("#RF_TankWindow_Max")}: " + maxVolStr + " (+" + ModuleFuelTanks.FormatMass((float)(tank_module.AvailableVolume * tank.mass)) + " )"; // Max
string maxVolStr = ResourceUnits.PrintAmount(maxVol, tank.resource.info.id);
string label = $"{Localizer.GetStringByTag("#RF_TankWindow_Max")}: " + maxVolStr + " (+" + ResourceUnits.PrintMass(tank_module.AvailableVolume * tank.mass) + " )"; // Max
addLabelCache[tank.name] = label;
}
oldAvailableVolume = tank_module.AvailableVolume;
Expand Down
5 changes: 3 additions & 2 deletions Source/assembly/AssemblyInfoRF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
[assembly: AssemblyFileVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")]
[assembly: KSPAssembly("RealFuels", @MAJOR@, @MINOR@, @PATCH@)]
#else
[assembly: AssemblyFileVersion("15.7.0.0")]
[assembly: KSPAssembly("RealFuels", 15, 7, 0)]
[assembly: AssemblyFileVersion("15.8.0.0")]
[assembly: KSPAssembly("RealFuels", 15, 8, 0)]
#endif

// The following attributes are used to specify the signing key for the assembly,
Expand All @@ -34,3 +34,4 @@
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
[assembly: KSPAssemblyDependency("SolverEngines", 3, 13)]
[assembly: KSPAssemblyDependency("ROUtils", 1, 0, 1)]

0 comments on commit b49aff7

Please sign in to comment.