public static string DumpLink(CommLink link) { return(string.Format("A/B/Both CanRelay: {0}/{1}/{2}\n", link.aCanRelay, link.bCanRelay, link.bothRelay) + string.Format("StrengthAR/BR/RR: {0}/{1}/{2}\n", link.strengthAR, link.strengthBR, link.strengthRR) + string.Format("Best signal: {0}", link.GetBestSignal()) + string.Format(" Cost: {0}\n", link.cost) + string.Format("Start: {0}\n", link.start) + string.Format("End: {0}\n", link.end) + string.Format("GetSignalStrength(start) / (end) / (no relays) / (both relays): {0}/{1}/{2}/{3}\n", link.GetSignalStrength(link.start), link.GetSignalStrength(link.end), link.GetSignalStrength(false, false), link.GetSignalStrength(true, true)) + string.Format("signalStrength: {0}", link.signalStrength)); /* Some sample results: * [LOG 13:25:45.815] [RealAntennasCommNetwork] [Trace] Link: Kerbin: Mesa South -to- RA-1-CS16 : 150727254.72 (Green) * [LOG 13:25:45.815] [RealAntennasCommNetwork] [Trace] A/B/Both CanRelay: True/False/False * StrengthAR/BR/RR: 0.609718471365098/0/0 * Best signal: 0.609718471365098 Cost: 150727254.721891 * Start: Node: Kerbin: Mesa South Links=3 : Home Control MultiHop : RealAntennas Gain:40dBi TxP:60dBm BW:10000KHz Draw:60dBm Coding:12dB * End: Node: RA-1-CS16 Links=6 : : RealAntennas Gain:6dBi TxP:30dBm BW:10000KHz Draw:33dBm Coding:1dB * GetSignalStrength(start): 0 * GetSignalStrength(end): 0.609718471365098 * GetSignalStrength(no relays): 0 * * Note the different Strength fields based on A/B/Both Relay state. So... there can be a notion of direction? */ }
/// <summary> /// Overrode UpdateDisplay() fully and add own customisations /// </summary> private void updateCustomisedView() { if (FlightGlobals.ActiveVessel == null) { this.useTSBehavior = true; } else { this.useTSBehavior = false; this.vessel = FlightGlobals.ActiveVessel; } if (this.vessel == null || this.vessel.connection == null || this.vessel.connection.Comm.Net == null) //revert to default display mode if saved mode is inconsistent in current situation { this.useTSBehavior = true; if (CustomModeTrackingStation != CustomDisplayMode.None) { if (CustomModeTrackingStation != CustomDisplayMode.Network && CustomModeTrackingStation != CustomDisplayMode.MultiPaths) { CustomModeTrackingStation = CustomDisplayMode.Network; ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_118264", new string[] { Localizer.Format(CustomModeTrackingStation.displayDescription()) }), 5f); } } } if (this.useTSBehavior) { CNVCommNetUI.CustomMode = CNVCommNetUI.CustomModeTrackingStation; } else { CNVCommNetUI.CustomMode = CNVCommNetUI.CustomModeFlightMap; } CommNetwork net = CommNetNetwork.Instance.CommNet; CommNetVessel cnvessel = null; CommNode node = null; CommPath path = null; if (this.vessel != null && this.vessel.connection != null && this.vessel.connection.Comm.Net != null) { cnvessel = this.vessel.connection; node = cnvessel.Comm; path = cnvessel.ControlPath; } //work out which links to display int count = this.points.Count;//save previous value int numLinks = 0; switch (CNVCommNetUI.CustomMode) { case CNVCommNetUI.CustomDisplayMode.None: numLinks = 0; break; case CNVCommNetUI.CustomDisplayMode.FirstHop: case CNVCommNetUI.CustomDisplayMode.Path: if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal || path.Count == 0) { numLinks = 0; } else { if (CNVCommNetUI.CustomMode == CNVCommNetUI.CustomDisplayMode.FirstHop) { path.First.GetPoints(this.points); numLinks = 1; } else { path.GetPoints(this.points, true); numLinks = path.Count; } } break; case CNVCommNetUI.CustomDisplayMode.VesselLinks: numLinks = node.Count; node.GetLinkPoints(this.points); break; case CNVCommNetUI.CustomDisplayMode.Network: if (net.Links.Count == 0) { numLinks = 0; } else { numLinks = net.Links.Count; net.GetLinkPoints(this.points); } break; case CNVCommNetUI.CustomDisplayMode.MultiPaths: if (net.Links.Count == 0) { numLinks = 0; } else { CommPath newPath = new CommPath(); var nodes = net; var vessels = FlightGlobals.fetch.vessels; for (int i = 0; i < vessels.Count; i++) { var commnetvessel = vessels[i].connection; if (commnetvessel == null) // like flag { continue; } SetPrivatePropertyValue <CommNetVessel>(commnetvessel, "unloadedDoOnce", true); //network update is done only once for unloaded vessels so need to manually re-trigger every time //don't want to override CommNetVessel to just set the boolean flag if (!(commnetvessel.ControlState == VesselControlState.Probe || commnetvessel.ControlState == VesselControlState.Kerbal || commnetvessel.ControlPath == null || commnetvessel.ControlPath.Count == 0)) { for (int pathIndex = 0; pathIndex < commnetvessel.ControlPath.Count; pathIndex++) { var link = commnetvessel.ControlPath[pathIndex]; if (newPath.Find(x => x.a.precisePosition == link.a.precisePosition && x.b.precisePosition == link.b.precisePosition) == null) //not found in list of links to be displayed { newPath.Add(link); //laziness wins //KSP techincally does not care if path is consisted of non-continuous links or not } } } } path = newPath; path.GetPoints(this.points, true); numLinks = path.Count; } break; }// end of switch //check if nothing to display if (numLinks == 0) { if (this.line != null) { this.line.active = false; } this.points.Clear(); return; } if (this.line != null) { this.line.active = true; } else { this.refreshLines = true; } ScaledSpace.LocalToScaledSpace(this.points); //seem very important if (this.refreshLines || MapView.Draw3DLines != this.draw3dLines || count != this.points.Count || this.line == null) { this.CreateLine(ref this.line, this.points);//seems it is multiple separate lines not single continuous line this.draw3dLines = MapView.Draw3DLines; this.refreshLines = false; } //paint the links switch (CNVCommNetUI.CustomMode) { case CNVCommNetUI.CustomDisplayMode.FirstHop: { float lvl = Mathf.Pow((float)path.First.signalStrength, this.colorLerpPower); if (this.swapHighLow) { this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), 0); } else { this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), 0); } break; } case CNVCommNetUI.CustomDisplayMode.Path: case CNVCommNetUI.CustomDisplayMode.MultiPaths: { int linkIndex = numLinks; for (int i = linkIndex - 1; i >= 0; i--) { float lvl = Mathf.Pow((float)path[i].signalStrength, this.colorLerpPower); if (this.swapHighLow) { this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), i); } else { this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), i); } } break; } case CNVCommNetUI.CustomDisplayMode.VesselLinks: { var itr = node.Values.GetEnumerator(); int linkIndex = 0; while (itr.MoveNext()) { CommLink link = itr.Current; float lvl = Mathf.Pow((float)link.GetSignalStrength(link.a != node, link.b != node), this.colorLerpPower); if (this.swapHighLow) { this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), linkIndex++); } else { this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), linkIndex++); } } break; } case CNVCommNetUI.CustomDisplayMode.Network: { for (int i = numLinks - 1; i >= 0; i--) { CommLink commLink = net.Links[i]; float lvl = Mathf.Pow((float)net.Links[i].GetBestSignal(), this.colorLerpPower); if (this.swapHighLow) { this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), i); } else { this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), i); } } break; } } // end of switch if (this.draw3dLines) { this.line.SetWidth(this.lineWidth3D); this.line.Draw3D(); } else { this.line.SetWidth(this.lineWidth2D); this.line.Draw(); } }
// Render the CommNet presentation // This method has been created to modify line color private void UpdateView() { CommNetwork net = CommNetNetwork.Instance.CommNet; CommNetVessel cnvessel = null; CommNode node = null; CommPath path = null; if (vessel != null && vessel.connection != null && vessel.connection.Comm.Net != null) { cnvessel = vessel.connection; node = cnvessel.Comm; path = cnvessel.ControlPath; } // Work out how many connections to paint int numLinks = 0; int count = points.Count; switch (Mode) { case DisplayMode.None: { numLinks = 0; break; } case DisplayMode.FirstHop: { if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal || path == null || path.Count == 0) { numLinks = 0; } else { path.First.GetPoints(points); numLinks = 1; } break; } case DisplayMode.Path: { if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal || path == null || path.Count == 0) { numLinks = 0; } else { path.GetPoints(points, true); numLinks = path.Count; } break; } case DisplayMode.VesselLinks: { numLinks = node.Count; node.GetLinkPoints(points); break; } case DisplayMode.Network: { if (net.Links.Count == 0) { numLinks = 0; } else { numLinks = net.Links.Count; net.GetLinkPoints(points); } break; } } // Check if nothing to draw if (numLinks == 0) { if (line != null) { line.active = false; } points.Clear(); return; } else { // TODO: I'm not sure if I need the commented part below. //if (line != null) line.active = true; //else refreshLines = true; //ScaledSpace.LocalToScaledSpace(points); //if (refreshLines || MapView.Draw3DLines != draw3dLines || (count != points.Count || line == null)) //{ // CreateLine(ref line, points); // draw3dLines = MapView.Draw3DLines; // refreshLines = false; //} //paint eligible connections // Sample to create a customHighColor : // Color customHighColor = getConstellationColor(path.First.a, path.First.b); // If want custom color, alter colorHigh for customHighColor switch (Mode) { case DisplayMode.FirstHop: { float lvl = Mathf.Pow((float)path.First.signalStrength, colorLerpPower); if (swapHighLow) { line.SetColor(Color.Lerp(colorHigh, colorLow, lvl), 0); } else { line.SetColor(Color.Lerp(colorLow, colorHigh, lvl), 0); } break; } case DisplayMode.Path: { int linkIndex = numLinks; for (int i = linkIndex - 1; i >= 0; i--) { float lvl = Mathf.Pow((float)path[i].signalStrength, colorLerpPower); if (swapHighLow) { line.SetColor(Color.Lerp(colorHigh, colorLow, lvl), i); } else { line.SetColor(Color.Lerp(colorLow, colorHigh, lvl), i); } } break; } case DisplayMode.VesselLinks: { var itr = node.Values.GetEnumerator(); int linkIndex = 0; while (itr.MoveNext()) { CommLink link = itr.Current; float lvl = Mathf.Pow((float)link.GetSignalStrength(link.a != node, link.b != node), colorLerpPower); if (swapHighLow) { line.SetColor(Color.Lerp(colorHigh, colorLow, lvl), linkIndex++); } else { line.SetColor(Color.Lerp(colorLow, colorHigh, lvl), linkIndex++); } } break; } case DisplayMode.Network: { int linkIndex = numLinks; while (linkIndex-- > 0) { CommLink commLink = net.Links[linkIndex]; float t2 = Mathf.Pow((float)net.Links[linkIndex].GetBestSignal(), colorLerpPower); if (swapHighLow) { line.SetColor(Color.Lerp(colorHigh, colorLow, t2), linkIndex); } else { line.SetColor(Color.Lerp(colorLow, colorHigh, t2), linkIndex); } } break; } } } }