From e4c0a62f8a076334c7f99c4bb3bea251bced2966 Mon Sep 17 00:00:00 2001 From: KSP-TaxiService Date: Mon, 26 Jul 2021 22:21:10 +0800 Subject: [PATCH] Fix bug of valid connection displayed in wrong constellation colour --- .../CommNetLayer/CNCCommNetUI.cs | 11 ++++++++ .../CommNetLayer/CNCCommNetVessel.cs | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/CommNetConstellation/CommNetLayer/CNCCommNetUI.cs b/src/CommNetConstellation/CommNetLayer/CNCCommNetUI.cs index ecae431..0fc6069 100644 --- a/src/CommNetConstellation/CommNetLayer/CNCCommNetUI.cs +++ b/src/CommNetConstellation/CommNetLayer/CNCCommNetUI.cs @@ -170,6 +170,17 @@ private Color getConstellationColor(CommNode a, CommNode b) continue; } + //ensure connection can be established on this frequency (eg 1<->1 not 1<->2) + if (a.isHome != true && b.isHome != true) //skip if either A or B CommNet Home (always relay) + { + var vesselA = (a.GetVessel().connection as IModularCommNetVessel).GetModuleOfType(); + var vesselB = (b.GetVessel().connection as IModularCommNetVessel).GetModuleOfType(); + if (!vesselA.isConnectionEligible(vesselB, commonFreqs[i])) + { + continue; + } + } + thisRange = CNCCommNetScenario.RangeModel.GetMaximumRange(CNCCommNetScenario.Instance.getCommPower(a, commonFreqs[i]), CNCCommNetScenario.Instance.getCommPower(b, commonFreqs[i])); if(thisRange > longestRange) { diff --git a/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs b/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs index 3815d61..d7a1a84 100644 --- a/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs +++ b/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs @@ -92,6 +92,8 @@ public enum FrequencyListOperation protected bool stageActivated = false; public bool IsCommandable = true; + public List Antennas { get { return vesselAntennas; } } + /// /// Retrieve the CNC data from the vessel, in addition of stock network joining /// @@ -893,5 +895,30 @@ protected void groundSciencePartStateChange(ModuleGroundSciencePart sciencePart) this.rebuildFreqList(true); } } + + /// + /// Check if this and target vessels can establish connection of specific frequency + /// + public bool isConnectionEligible(CNCCommNetVessel otherVessel, short targetFreq) + { + for(int i = 0; i < this.vesselAntennas.Count; i++) + { + if(this.vesselAntennas[i].frequency == targetFreq) + { + for(int j = 0; j < otherVessel.Antennas.Count; j++) + { + if (otherVessel.Antennas[j].frequency == targetFreq) + { + if(this.vesselAntennas[i].antennaType == AntennaType.RELAY || otherVessel.Antennas[j].antennaType == AntennaType.RELAY) + { + return true; + } + } + } + } + } + + return false; //cannot connect to each other + } } }