/// <summary> /// Find the vessel that has the given comm node /// </summary> public Vessel findCorrespondingVessel(CommNode commNode) { cacheCommNetVessels(); return(commVessels.Find(x => CNCCommNetwork.AreSame(x.Comm, commNode)).Vessel); // more specific equal //IEqualityComparer<CommNode> comparer = commNode.Comparer; // a combination of third-party mods somehow affects CommNode's IEqualityComparer on two objects //return commVessels.Find(x => comparer.Equals(commNode, x.Comm)).Vessel; }
/// <summary> /// Find the ground station that has the given comm node /// </summary> public CNCCommNetHome findCorrespondingGroundStation(CommNode commNode) { return(groundStations.Find(x => CNCCommNetwork.AreSame(x.commNode, commNode))); }
/// <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()) }), CNCSettings.ScreenMessageDuration); } } } if (CommNetNetwork.Instance == null) { return; } if (this.useTSBehavior) { CNCCommNetUI.CustomMode = CNCCommNetUI.CustomModeTrackingStation; } else { CNCCommNetUI.CustomMode = CNCCommNetUI.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; bool pathLinkExist; switch (CNCCommNetUI.CustomMode) { case CNCCommNetUI.CustomDisplayMode.None: numLinks = 0; break; case CNCCommNetUI.CustomDisplayMode.FirstHop: if (cnvessel.ControlState != VesselControlState.Probe && cnvessel.ControlState != VesselControlState.Kerbal && path != null) { if (path.Count != 0) { path.First.GetPoints(this.points); numLinks = 1; break; } } numLinks = 0; break; case CNCCommNetUI.CustomDisplayMode.Path: if (cnvessel.ControlState != VesselControlState.Probe && cnvessel.ControlState != VesselControlState.Kerbal && path != null) { if (path.Count != 0) { path.GetPoints(this.points, true); numLinks = path.Count; break; } } numLinks = 0; break; case CNCCommNetUI.CustomDisplayMode.VesselLinks: numLinks = node.Count; node.GetLinkPoints(this.points); break; case CNCCommNetUI.CustomDisplayMode.Network: if (net.Links.Count == 0) { numLinks = 0; } else { //net.GetLinkPoints(this.points); //numLinks = net.Links.Count; //KSP 1.8: Likely shader changes led to stackup of 2 or more lines illustrating overall brighter line //Workaround: collect unqiue lines as path path = new CommPath(); path.Capacity = net.Links.Count; for (int i = 0; i < net.Links.Count; i++) { pathLinkExist = false; for (int overallpathIndex = 0; overallpathIndex < path.Count; overallpathIndex++) //check if path has this link already { if (CNCCommNetwork.AreSame(path[overallpathIndex].a, net.Links[i].a) && CNCCommNetwork.AreSame(path[overallpathIndex].b, net.Links[i].b)) { pathLinkExist = true; break; } } if (!pathLinkExist) { path.Add(net.Links[i]); } } path.GetPoints(this.points, true); numLinks = path.Count; } break; case CNCCommNetUI.CustomDisplayMode.MultiPaths: if (net.Links.Count == 0) { numLinks = 0; } else { path = new CommPath(); path.Capacity = net.Links.Count; for (int i = 0; i < net.Count; i++) { if (net[i].isControlSource) //is it ground station/remote-control pilot? { continue; } var thisPath = new CommPath(); net.FindHome(net[i], thisPath); for (int controlpathIndex = 0; controlpathIndex < thisPath.Count; controlpathIndex++) { pathLinkExist = false; for (int overallpathIndex = 0; overallpathIndex < path.Count; overallpathIndex++) //check if overall path has this link already { if (CNCCommNetwork.AreSame(path[overallpathIndex].a, thisPath[controlpathIndex].a) && CNCCommNetwork.AreSame(path[overallpathIndex].b, thisPath[controlpathIndex].b)) { pathLinkExist = true; break; } } if (!pathLinkExist) { path.Add(thisPath[controlpathIndex]); } } } 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 (CNCCommNetUI.CustomMode) { case CNCCommNetUI.CustomDisplayMode.FirstHop: { this.line.SetColor(colorBlending(getConstellationColor(path.First.a, path.First.b), this.colorLow, Mathf.Pow((float)path.First.signalStrength, this.colorLerpPower)), 0); break; } case CNCCommNetUI.CustomDisplayMode.Path: case CNCCommNetUI.CustomDisplayMode.MultiPaths: { for (int i = numLinks - 1; i >= 0; i--) { this.line.SetColor(colorBlending(getConstellationColor(path[i].a, path[i].b), this.colorLow, Mathf.Pow((float)path[i].signalStrength, this.colorLerpPower)), i); } break; } case CNCCommNetUI.CustomDisplayMode.VesselLinks: { CommLink[] links = new CommLink[node.Count]; node.Values.CopyTo(links, 0); for (int i = 0; i < links.Length; i++) { this.line.SetColor(colorBlending(getConstellationColor(links[i].a, links[i].b), this.colorLow, Mathf.Pow((float)links[i].GetSignalStrength(links[i].a != node, links[i].b != node), this.colorLerpPower)), i); } break; } case CNCCommNetUI.CustomDisplayMode.Network: { //for (int i = numLinks - 1; i >= 0; i--) //{ // this.line.SetColor(colorBlending(getConstellationColor(net.Links[i].a, net.Links[i].b), // this.colorLow, // Mathf.Pow((float) net.Links[i].GetBestSignal(), this.colorLerpPower)), // i); //} for (int i = numLinks - 1; i >= 0; i--) { this.line.SetColor(colorBlending(getConstellationColor(path[i].a, path[i].b), this.colorLow, Mathf.Pow((float)path[i].GetBestSignal(), this.colorLerpPower)), 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(); } }
/// <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()) }), CNCSettings.ScreenMessageDuration); } } } if (this.useTSBehavior) { CNCCommNetUI.CustomMode = CNCCommNetUI.CustomModeTrackingStation; } else { CNCCommNetUI.CustomMode = CNCCommNetUI.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; bool pathLinkExist; switch (CNCCommNetUI.CustomMode) { case CNCCommNetUI.CustomDisplayMode.None: numLinks = 0; break; case CNCCommNetUI.CustomDisplayMode.FirstHop: case CNCCommNetUI.CustomDisplayMode.Path: if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal || path.Count == 0) { numLinks = 0; } else { if (CNCCommNetUI.CustomMode == CNCCommNetUI.CustomDisplayMode.FirstHop) { path.First.GetPoints(this.points); numLinks = 1; } else { path.GetPoints(this.points, true); numLinks = path.Count; } } break; case CNCCommNetUI.CustomDisplayMode.VesselLinks: numLinks = node.Count; node.GetLinkPoints(this.points); break; case CNCCommNetUI.CustomDisplayMode.Network: if (net.Links.Count == 0) { numLinks = 0; } else { numLinks = net.Links.Count; net.GetLinkPoints(this.points); } break; case CNCCommNetUI.CustomDisplayMode.MultiPaths: if (net.Links.Count == 0) { numLinks = 0; } else { path = new CommPath(); path.Capacity = net.Links.Count; var vessels = CNCCommNetScenario.Instance.getCommNetVessels(); //TODO: replace it with CNM for (int i = 0; i < vessels.Count; i++) { vessels[i].computeUnloadedUpdate(); //network update is done only once for unloaded vessels so need to manually re-trigger every time //is vessel real/alive? if (!(vessels[i].ControlState == VesselControlState.Probe || vessels[i].ControlState == VesselControlState.Kerbal || vessels[i].ControlPath == null || vessels[i].ControlPath.Count == 0)) { //add each link in control path to overall path for (int controlpathIndex = 0; controlpathIndex < vessels[i].ControlPath.Count; controlpathIndex++) { pathLinkExist = false; for (int overallpathIndex = 0; overallpathIndex < path.Count; overallpathIndex++) //check if overall path has this link already { if (CNCCommNetwork.AreSame(path[overallpathIndex].a, vessels[i].ControlPath[controlpathIndex].a) && CNCCommNetwork.AreSame(path[overallpathIndex].b, vessels[i].ControlPath[controlpathIndex].b)) { pathLinkExist = true; break; } } if (!pathLinkExist) { path.Add(vessels[i].ControlPath[controlpathIndex]); //laziness wins //KSP techincally does not care if path is consisted of non-continuous links or not } } } } 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 (CNCCommNetUI.CustomMode) { case CNCCommNetUI.CustomDisplayMode.FirstHop: { this.line.SetColor(colorBlending(getConstellationColor(path.First.a, path.First.b), this.colorLow, Mathf.Pow((float)path.First.signalStrength, this.colorLerpPower)), 0); break; } case CNCCommNetUI.CustomDisplayMode.Path: case CNCCommNetUI.CustomDisplayMode.MultiPaths: { for (int i = numLinks - 1; i >= 0; i--) { this.line.SetColor(colorBlending(getConstellationColor(path[i].a, path[i].b), this.colorLow, Mathf.Pow((float)path[i].signalStrength, this.colorLerpPower)), i); } break; } case CNCCommNetUI.CustomDisplayMode.VesselLinks: { CommLink[] links = new CommLink[node.Count]; node.Values.CopyTo(links, 0); for (int i = 0; i < links.Length; i++) { this.line.SetColor(colorBlending(getConstellationColor(links[i].a, links[i].b), this.colorLow, Mathf.Pow((float)links[i].GetSignalStrength(links[i].a != node, links[i].b != node), this.colorLerpPower)), i); } break; } case CNCCommNetUI.CustomDisplayMode.Network: { for (int i = numLinks - 1; i >= 0; i--) { this.line.SetColor(colorBlending(getConstellationColor(net.Links[i].a, net.Links[i].b), this.colorLow, Mathf.Pow((float)net.Links[i].GetBestSignal(), this.colorLerpPower)), 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(); } }