protected void GetCommandPath() { try { path = RTGlobals.network.GetCommandPath(Rnode); } catch { RTGlobals.network = new RelayNetwork(); this.path = RTGlobals.network.GetCommandPath(Rnode); } if (RTGlobals.listComsats) { HashSet <string> contactsTMP = new HashSet <string>(); foreach (RelayNode other in RTGlobals.network.all) { if (RTGlobals.network.inContactWith(Rnode, other)) { contactsTMP.Add(other.ID); } } contacts = contactsTMP; } }
public RelayPath GetCommandPath(RelayNode start) { double compare = double.MaxValue; RelayPath output = null; foreach (RelayNode node in commandStations) { if (!start.Equals(node) && node.HasCommand) { RelayPath tmp = findShortestRelayPath(start, node); if (tmp != null && tmp.Length < compare) { output = tmp; compare = tmp.Length; } } } return(output); }
void WindowGUI(int windowID) { Color savedColor = GUI.color; Color savedContentColor = GUI.contentColor; bool CrewControl = vessel.GetCrewCount() > 0; GUIStyle Alarm = new GUIStyle(GUI.skin.label); Alarm.fontStyle = FontStyle.Bold; Alarm.normal.textColor = Color.red; if (!powered) { GUI.DragWindow(); string alarmMessage = "Out of power"; if (AlarmTime < Time.time) { AlarmTime = Time.time + 1; alarmShow = !alarmShow; } if (alarmShow) { alarmMessage += " !"; } GUILayout.Label(alarmMessage, Alarm); return; } try { if (InContact) { if (GUILayout.Button("Path length: " + RTUtils.length(path.Length) + "m, delay: " + RTUtils.time(path.ControlDelay) + (RTGlobals.AdvInfo ? "\nRelay path: " + path.ToString() : ""), GUI.skin.label, GUILayout.ExpandWidth(true))) { RTGlobals.AdvInfo = !RTGlobals.AdvInfo; } } else { string alarmMessage = "Out of contact"; if (AlarmTime < Time.time) { AlarmTime = Time.time + 1; alarmShow = !alarmShow; } if (alarmShow) { alarmMessage += " !"; } GUILayout.Label(alarmMessage, Alarm); } } catch (NullReferenceException) { RTGlobals.network = new RelayNetwork(); path = RTGlobals.network.GetCommandPath(Rnode); } GUI.color = savedColor; GUILayout.BeginHorizontal(); RTGlobals.listComsats = GUILayout.Toggle(RTGlobals.listComsats, "List comsats", GUI.skin.button, GUILayout.Height(20)); if (!CrewControl && !(MechJeb && InContact)) { GUI.contentColor = Color.red; } localControl = GUILayout.Toggle(localControl, (!CrewControl && MechJeb) ? "MechJeb Control" : "Local Control", GUI.skin.button, GUILayout.Height(20)); if (!CrewControl && !(MechJeb && InContact)) { localControl = false; GUI.contentColor = savedContentColor; } RTGlobals.showPathInMapView = GUILayout.Toggle(RTGlobals.showPathInMapView, "Show path on map", GUI.skin.button, GUILayout.Height(20)); RTGlobals.showFC = GUILayout.Toggle(RTGlobals.showFC, "Flight Computer", GUI.skin.button, GUILayout.Height(20)); GUILayout.EndHorizontal(); if (RTGlobals.listComsats) { if (!LCoLF) { Thread thread = new Thread(new ThreadStart(GetCommandPath)); thread.Start(); LCoLF = true; } if (!InControl) { GUI.contentColor = Color.red; } if (GUILayout.Button(Rnode.descript, new GUIStyle(GUI.skin.button)) && InControl) { settings.Open(Rnode); } if (!InControl) { GUI.contentColor = savedContentColor; } RTGlobals.comsatListScroll = GUILayout.BeginScrollView(RTGlobals.comsatListScroll, false, true); //compiles a list of comsat vessels that are in the current RelayNetwork, Coloring the ones in the current RelayPath green. if (InContact || Rnode.HasCommand) { foreach (RelayNode node in RTGlobals.network.all) { if (!node.Equals(Rnode) && node.Vessel != null) { GUILayout.BeginHorizontal(); bool connection = InContactWith(node); if (!connection) { if (GUI.contentColor != Color.red) { GUI.contentColor = Color.red; } } else if (InContact && path.nodes.Contains(node)) { if (GUI.contentColor != Color.green) { GUI.contentColor = Color.green; } } else if (GUI.contentColor != Color.white) { GUI.contentColor = Color.white; } if (GUILayout.Button(node.descript, new GUIStyle(GUI.skin.button), GUILayout.Height(50.0F)) && connection) { settings.Open(node); } if ((InContact || Rnode.HasCommand) && connection && node.Vessel.loaded && (RTGlobals.extPack ? Vector3d.Distance(vessel.transform.position, node.Vessel.transform.position) < 2000 : !node.Vessel.packed)) { if (GUILayout.Button("Ctrl", new GUIStyle(GUI.skin.button), GUILayout.Width(50.0F), GUILayout.Height(50.0F))) { bool isThere = false; int ATid = this.flightComputerGUI.ATTITUDE_ID + 1, THid = this.flightComputerGUI.THROTTLE_ID + 1; GUIcontainer remove = new GUIcontainer(); foreach (GUIcontainer c in this.otherGUI) { if (c.gui == RTGlobals.coreList[node.Vessel].flightComputerGUI) { isThere = true; remove = c; break; } ATid = c.ATTITUDE_ID + 1; THid = c.THROTTLE_ID + 1; } if (isThere) { otherGUI.Remove(remove); if (RTGlobals.extPack && otherGUI.Count == 0 && RTGlobals.Manager != null) { RTGlobals.Manager.distantLandedPartPackThreshold = 350; RTGlobals.Manager.distantLandedPartUnpackThreshold = 200; RTGlobals.Manager.distantPartPackThreshold = 5000; RTGlobals.Manager.distantPartUnpackThreshold = 200; } } else { otherGUI.Add(new GUIcontainer(RTGlobals.coreList[node.Vessel].flightComputerGUI, ATid, THid)); } } } GUILayout.EndHorizontal(); } } } else { GUI.contentColor = Color.red; foreach (RelayNode node in RTGlobals.network.all) { if (!node.Equals(Rnode) && node.Vessel != null) { GUILayout.Label(node.descript, new GUIStyle(GUI.skin.button)); } } } GUI.color = savedColor; GUI.contentColor = savedContentColor; GUILayout.EndScrollView(); } GUI.DragWindow(); }
RelayPath findShortestRelayPath(RelayNode start, RelayNode goal) { HashSet<RelayNode> closedSet = new HashSet<RelayNode>(); HashSet<RelayNode> openSet = new HashSet<RelayNode>(); Dictionary<RelayNode, RelayNode> cameFrom = new Dictionary<RelayNode, RelayNode>(); Dictionary<RelayNode, double> gScore = new Dictionary<RelayNode, double>(); Dictionary<RelayNode, double> hScore = new Dictionary<RelayNode, double>(); Dictionary<RelayNode, double> fScore = new Dictionary<RelayNode, double>(); openSet.Add(start); double startBaseHeuristic = (start.Position - goal.Position).magnitude; gScore[start] = 0.0; hScore[start] = startBaseHeuristic; fScore[start] = startBaseHeuristic; HashSet<RelayNode> neighbors = new HashSet<RelayNode>(all); neighbors.Add(start); neighbors.Add(goal); RelayPath path = null; while (openSet.Count > 0) { RelayNode current = null; double currentBestScore = double.MaxValue; foreach (KeyValuePair<RelayNode, double> pair in fScore) { if (openSet.Contains(pair.Key) && pair.Value < currentBestScore) { current = pair.Key; currentBestScore = pair.Value; } } if (current == goal) { path = new RelayPath(reconstructPath(cameFrom, goal)); break; } openSet.Remove(current); closedSet.Add(current); foreach (RelayNode neighbor in neighbors) { if (!closedSet.Contains(neighbor) && inRange(neighbor, current) && lineOfSight(neighbor, current)) { //double tentGScore = gScore[current] - (neighbor.Position - current.Position).magnitude; double tentGScore = gScore[current] + (neighbor.Position - current.Position).magnitude; bool tentIsBetter = false; if (!openSet.Contains(neighbor)) { openSet.Add(neighbor); hScore[neighbor] = (neighbor.Position - goal.Position).magnitude; tentIsBetter = true; } else if (tentGScore < gScore[neighbor]) { tentIsBetter = true; } if (tentIsBetter) { cameFrom[neighbor] = current; gScore[neighbor] = tentGScore; fScore[neighbor] = tentGScore + hScore[neighbor]; } } } } return path; }
void WindowGUI(int windowID) { Color savedColor = GUI.color; Color savedContentColor = GUI.contentColor; bool CrewControl = vessel.GetCrewCount() > 0; GUIStyle Alarm = new GUIStyle(GUI.skin.label); Alarm.fontStyle = FontStyle.Bold; Alarm.normal.textColor = Color.red; if (!powered) { GUI.DragWindow(); string alarmMessage = "Out of power"; if (AlarmTime < Time.time) { AlarmTime = Time.time + 1; alarmShow = !alarmShow; } if (alarmShow) alarmMessage += " !"; GUILayout.Label(alarmMessage, Alarm); return; } try { if (InContact) { if (GUILayout.Button("Path length: " + RTUtils.length(path.Length) + "m, delay: " + RTUtils.time(path.ControlDelay) + (RTGlobals.AdvInfo ? "\nRelay path: " + path.ToString() : ""), GUI.skin.label, GUILayout.ExpandWidth(true))) { RTGlobals.AdvInfo = !RTGlobals.AdvInfo; } } else { string alarmMessage = "Out of contact"; if (AlarmTime < Time.time) { AlarmTime = Time.time + 1; alarmShow = !alarmShow; } if (alarmShow) alarmMessage += " !"; GUILayout.Label(alarmMessage, Alarm); } } catch (NullReferenceException) { RTGlobals.network = new RelayNetwork(); path = RTGlobals.network.GetCommandPath(Rnode); } GUI.color = savedColor; GUILayout.BeginHorizontal(); RTGlobals.listComsats = GUILayout.Toggle(RTGlobals.listComsats, "List comsats", GUI.skin.button, GUILayout.Height(20)); if (!CrewControl && !(MechJeb && InContact)) GUI.contentColor = Color.red; localControl = GUILayout.Toggle(localControl, (!CrewControl && MechJeb) ? "MechJeb Control" : "Local Control", GUI.skin.button, GUILayout.Height(20)); if (!CrewControl && !(MechJeb && InContact)) { localControl = false; GUI.contentColor = savedContentColor; } RTGlobals.showPathInMapView = GUILayout.Toggle(RTGlobals.showPathInMapView, "Show path on map", GUI.skin.button, GUILayout.Height(20)); RTGlobals.showFC = GUILayout.Toggle(RTGlobals.showFC, "Flight Computer", GUI.skin.button, GUILayout.Height(20)); GUILayout.EndHorizontal(); if (RTGlobals.listComsats) { if (!LCoLF) { Thread thread = new Thread(new ThreadStart(GetCommandPath)); thread.Start(); LCoLF = true; } if (!InControl) GUI.contentColor = Color.red; if (GUILayout.Button(Rnode.descript, new GUIStyle(GUI.skin.button)) && InControl) { settings.Open(Rnode); } if (!InControl) GUI.contentColor = savedContentColor; RTGlobals.comsatListScroll = GUILayout.BeginScrollView(RTGlobals.comsatListScroll, false, true); //compiles a list of comsat vessels that are in the current RelayNetwork, Coloring the ones in the current RelayPath green. if (InContact || Rnode.HasCommand) foreach (RelayNode node in RTGlobals.network.all) { if (!node.Equals(Rnode) && node.Vessel != null) { GUILayout.BeginHorizontal(); bool connection = InContactWith(node); if (!connection) { if (GUI.contentColor != Color.red) GUI.contentColor = Color.red; } else if (InContact && path.nodes.Contains(node)) { if (GUI.contentColor != Color.green) GUI.contentColor = Color.green; } else if (GUI.contentColor != Color.white) GUI.contentColor = Color.white; if (GUILayout.Button(node.descript, new GUIStyle(GUI.skin.button), GUILayout.Height(50.0F)) && connection) { settings.Open(node); } if ((InContact || Rnode.HasCommand) && connection && node.Vessel.loaded && (RTGlobals.extPack ? Vector3d.Distance(vessel.transform.position, node.Vessel.transform.position) < 2000 : !node.Vessel.packed)) { if (GUILayout.Button("Ctrl", new GUIStyle(GUI.skin.button), GUILayout.Width(50.0F), GUILayout.Height(50.0F))) { bool isThere = false; int ATid = this.flightComputerGUI.ATTITUDE_ID + 1, THid = this.flightComputerGUI.THROTTLE_ID + 1; GUIcontainer remove = new GUIcontainer(); foreach (GUIcontainer c in this.otherGUI) { if (c.gui == RTGlobals.coreList[node.Vessel].flightComputerGUI) { isThere = true; remove = c; break; } ATid = c.ATTITUDE_ID + 1; THid = c.THROTTLE_ID + 1; } if (isThere) { otherGUI.Remove(remove); if (RTGlobals.extPack && otherGUI.Count == 0 && RTGlobals.Manager != null) { RTGlobals.Manager.distantLandedPartPackThreshold = 350; RTGlobals.Manager.distantLandedPartUnpackThreshold = 200; RTGlobals.Manager.distantPartPackThreshold = 5000; RTGlobals.Manager.distantPartUnpackThreshold = 200; } } else { otherGUI.Add(new GUIcontainer(RTGlobals.coreList[node.Vessel].flightComputerGUI, ATid, THid)); } } } GUILayout.EndHorizontal(); } } else { GUI.contentColor = Color.red; foreach (RelayNode node in RTGlobals.network.all) { if (!node.Equals(Rnode) && node.Vessel != null) { GUILayout.Label(node.descript, new GUIStyle(GUI.skin.button)); } } } GUI.color = savedColor; GUI.contentColor = savedContentColor; GUILayout.EndScrollView(); } GUI.DragWindow(); }
protected void GetCommandPath() { try { path = RTGlobals.network.GetCommandPath(Rnode); } catch { RTGlobals.network = new RelayNetwork(); this.path = RTGlobals.network.GetCommandPath(Rnode); } if (RTGlobals.listComsats) { HashSet<string> contactsTMP = new HashSet<string>(); foreach (RelayNode other in RTGlobals.network.all) if (RTGlobals.network.inContactWith(Rnode, other)) contactsTMP.Add(other.ID); contacts = contactsTMP; } }
RelayPath findShortestRelayPath(RelayNode start, RelayNode goal) { HashSet <RelayNode> closedSet = new HashSet <RelayNode>(); HashSet <RelayNode> openSet = new HashSet <RelayNode>(); Dictionary <RelayNode, RelayNode> cameFrom = new Dictionary <RelayNode, RelayNode>(); Dictionary <RelayNode, double> gScore = new Dictionary <RelayNode, double>(); Dictionary <RelayNode, double> hScore = new Dictionary <RelayNode, double>(); Dictionary <RelayNode, double> fScore = new Dictionary <RelayNode, double>(); openSet.Add(start); double startBaseHeuristic = (start.Position - goal.Position).magnitude; gScore[start] = 0.0; hScore[start] = startBaseHeuristic; fScore[start] = startBaseHeuristic; HashSet <RelayNode> neighbors = new HashSet <RelayNode>(all); neighbors.Add(start); neighbors.Add(goal); RelayPath path = null; while (openSet.Count > 0) { RelayNode current = null; double currentBestScore = double.MaxValue; foreach (KeyValuePair <RelayNode, double> pair in fScore) { if (openSet.Contains(pair.Key) && pair.Value < currentBestScore) { current = pair.Key; currentBestScore = pair.Value; } } if (current == goal) { path = new RelayPath(reconstructPath(cameFrom, goal)); break; } openSet.Remove(current); closedSet.Add(current); foreach (RelayNode neighbor in neighbors) { if (!closedSet.Contains(neighbor) && inRange(neighbor, current) && lineOfSight(neighbor, current)) { //double tentGScore = gScore[current] - (neighbor.Position - current.Position).magnitude; double tentGScore = gScore[current] + (neighbor.Position - current.Position).magnitude; bool tentIsBetter = false; if (!openSet.Contains(neighbor)) { openSet.Add(neighbor); hScore[neighbor] = (neighbor.Position - goal.Position).magnitude; tentIsBetter = true; } else if (tentGScore < gScore[neighbor]) { tentIsBetter = true; } if (tentIsBetter) { cameFrom[neighbor] = current; gScore[neighbor] = tentGScore; fScore[neighbor] = tentGScore + hScore[neighbor]; } } } } return(path); }