From c672e1f6b790eafd241b2d4eb6d49be43073e7cc Mon Sep 17 00:00:00 2001 From: NathanKell Date: Tue, 7 Nov 2023 23:17:54 -0800 Subject: [PATCH] Use ROUtils --- Source/Engines/ModuleEnginesRF.cs | 52 ++++--------------------------- Source/RealFuels.csproj | 4 +++ Source/Tanks/ModuleFuelTanks.cs | 7 ++--- Source/Tanks/TankWindow.cs | 5 +-- Source/assembly/AssemblyInfoRF.cs | 5 +-- 5 files changed, 19 insertions(+), 54 deletions(-) diff --git a/Source/Engines/ModuleEnginesRF.cs b/Source/Engines/ModuleEnginesRF.cs index 2651cfdc..3fb435d7 100644 --- a/Source/Engines/ModuleEnginesRF.cs +++ b/Source/Engines/ModuleEnginesRF.cs @@ -4,6 +4,7 @@ using SolverEngines; using System.Linq; using KSP.Localization; +using ROUtils; namespace RealFuels { @@ -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()}" + @@ -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 += $"- {KSPUtil.PrintModuleName(p.name)}: {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}"); // $"Variance: {localVaryIsp:P2} Isp, {localVaryFlow:P1} flow, {localVaryMixture:P2} MR (stddev).\n" output += Localizer.Format("#RF_EngineRF_GetInfo4", $"{localResidualsThresholdBase:P1}"); // $"Residuals: min {localResidualsThresholdBase:P1} of propellant.\n" diff --git a/Source/RealFuels.csproj b/Source/RealFuels.csproj index fccb6a45..227cf569 100644 --- a/Source/RealFuels.csproj +++ b/Source/RealFuels.csproj @@ -41,6 +41,10 @@ False + + ..\..\..\..\..\..\Games\R112\GameData\ROUtils\Plugins\ROUtils.dll + False + False ..\..\SolverEngines\SolverEngines\obj\Release\SolverEngines.dll diff --git a/Source/Tanks/ModuleFuelTanks.cs b/Source/Tanks/ModuleFuelTanks.cs index c51a7f29..208b980a 100644 --- a/Source/Tanks/ModuleFuelTanks.cs +++ b/Source/Tanks/ModuleFuelTanks.cs @@ -7,6 +7,7 @@ using KSP.UI.Screens; using System.Reflection; using KSP.Localization; +using ROUtils; // ReSharper disable InconsistentNaming, CompareOfFloatsByEqualityOperator @@ -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 = ""; @@ -819,7 +818,7 @@ public void CalculateMass () double resourceMass = part.Resources.Cast ().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 (); } diff --git a/Source/Tanks/TankWindow.cs b/Source/Tanks/TankWindow.cs index 226f4fe4..091d705f 100644 --- a/Source/Tanks/TankWindow.cs +++ b/Source/Tanks/TankWindow.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using ROUtils; using KSP.UI.Screens; using System.Linq; @@ -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; diff --git a/Source/assembly/AssemblyInfoRF.cs b/Source/assembly/AssemblyInfoRF.cs index 2c488aea..da14f9c2 100644 --- a/Source/assembly/AssemblyInfoRF.cs +++ b/Source/assembly/AssemblyInfoRF.cs @@ -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.1.0")] +[assembly: KSPAssembly("RealFuels", 15, 8, 1)] #endif // The following attributes are used to specify the signing key for the assembly, @@ -34,3 +34,4 @@ //[assembly: AssemblyDelaySign(false)] //[assembly: AssemblyKeyFile("")] [assembly: KSPAssemblyDependency("SolverEngines", 3, 13)] +[assembly: KSPAssemblyDependency("ROUtils", 1, 0, 1)] \ No newline at end of file