diff --git a/src/RealAntennasProject/Antenna/Encoder.cs b/src/RealAntennasProject/Antenna/Encoder.cs index 71e94ac..d33a4a2 100644 --- a/src/RealAntennasProject/Antenna/Encoder.cs +++ b/src/RealAntennasProject/Antenna/Encoder.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using UnityEngine; namespace RealAntennas.Antenna @@ -30,6 +31,10 @@ public Encoder(string name, int techLevel, float rate, float minEbN0) public Encoder BestMatching(in Encoder other) => TechLevel > other.TechLevel ? other : this; public static Encoder BestMatching(in Encoder a, in Encoder b) => a.BestMatching(b); + public static Encoder GetFromName(string name) + { + return !string.IsNullOrEmpty(name) ? All[name] : null; + } public static Encoder GetFromTechLevel(int level) { Encoder best = null; diff --git a/src/RealAntennasProject/RealAntenna.cs b/src/RealAntennasProject/RealAntenna.cs index fe6ed17..bac4083 100644 --- a/src/RealAntennasProject/RealAntenna.cs +++ b/src/RealAntennasProject/RealAntenna.cs @@ -27,8 +27,9 @@ public class RealAntenna public virtual double Bandwidth => DataRate; // RF bandwidth required. public virtual float AMWTemp { get; set; } public virtual float Beamwidth => Physics.Beamwidth(Gain); + public virtual string EncoderOverride { get; set; } - public Antenna.Encoder Encoder => Antenna.Encoder.GetFromTechLevel(TechLevelInfo.Level); + public Antenna.Encoder Encoder => Antenna.Encoder.GetFromName(EncoderOverride) ?? Antenna.Encoder.GetFromTechLevel(TechLevelInfo.Level); public virtual float RequiredCI => Encoder.RequiredEbN0; public ModuleRealAntenna Parent { get; internal set; } @@ -96,6 +97,7 @@ public RealAntenna(RealAntenna orig) Parent = orig.Parent; ParentNode = orig.ParentNode; ParentSnapshot = orig.ParentSnapshot; + EncoderOverride = orig.EncoderOverride; } public virtual bool Compatible(RealAntenna other) => RFBand == other.RFBand; @@ -119,6 +121,7 @@ public virtual void LoadFromConfigNode(ConfigNode config) Target = Targeting.AntennaTarget.LoadFromConfig(config.GetNode("TARGET"), this); else if (Shape != AntennaShape.Omni && (ParentNode == null || !ParentNode.isHome) && !(Target?.Validate() == true) && HighLogic.LoadedSceneHasPlanetarium) Target = Targeting.AntennaTarget.LoadFromConfig(SetDefaultTarget(), this); + EncoderOverride = (config.HasValue("EncoderOverride")) ? config.GetValue("EncoderOverride") : null; } public virtual void ProcessUpgrades(float tsLevel, ConfigNode node) @@ -147,6 +150,7 @@ public virtual void UpgradeFromConfigNode(ConfigNode config) if (config.TryGetValue("SymbolRate", ref d)) SymbolRate = d; if (config.TryGetValue("AMWTemp", ref f)) AMWTemp = f; if (config.TryGetValue("RFBand", ref s)) RFBand = Antenna.BandInfo.All[s]; + if (config.TryGetValue("EncoderOverride", ref s)) EncoderOverride = s; } public virtual ConfigNode SetDefaultTarget()