public override void OnUpdate() { if (!pageActiveState || !JUtil.VesselIsInIVA(vessel)) { return; } currentTarget = FlightGlobals.fetch.VesselTarget; selectedCelestial = currentTarget as CelestialBody; selectedVessel = currentTarget as Vessel; selectedPort = currentTarget as ModuleDockingNode; selectedClaw = currentTarget as ModuleGrappleNode; if (selectedPort != null) { selectedVessel = selectedPort.vessel; } if (selectedClaw != null) { selectedVessel = selectedClaw.vessel; } if (vessel.parts.Count != partCount) { FindReferencePoints(); //UpdateUndockablesList(); } if (!UpdateCheck()) { return; } UpdateLists(); }
private void ArmGrapple(int index, TextMenu.Item ti) { ModuleGrappleNode thatClaw = null; foreach (PartModule thatModule in vessel.GetReferenceTransformPart().Modules) { thatClaw = thatModule as ModuleGrappleNode; if (thatClaw != null) { break; } } if (thatClaw != null) { try { ModuleAnimateGeneric clawAnimation = (vessel.GetReferenceTransformPart().Modules[thatClaw.deployAnimationController] as ModuleAnimateGeneric); if (clawAnimation != null) { clawAnimation.Toggle(); } } catch (Exception e) { JUtil.LogErrorMessage(this, "Exception trying to arm/disarm Grapple Node: {0}", e.Message); } } }
private bool CreateCameraObjects(string newCameraName = null) { if (!string.IsNullOrEmpty(newCameraName)) { isReferenceCamera = false; isReferenceClawCamera = false; clawModule = null; // First, we search our own part for this camera transform, // only then we search all other parts of the vessel. if (!LocateCamera(ourPart, newCameraName)) { foreach (Part thatpart in ourVessel.parts) { if (LocateCamera(thatpart, newCameraName)) { break; } } } } if (cameraTransform != null) { for (int i = 0; i < knownCameraNames.Length; ++i) { CameraSetup(i, knownCameraNames[i]); } enabled = true; //JUtil.LogMessage(this, "Switched to camera \"{0}\".", cameraTransform.name); return(true); } else { //JUtil.LogMessage(this, "Tried to switch to camera \"{0}\" but camera was not found.", newCameraName); return(false); } }
private void CreateCameraObjects(string newCameraName = null) { if (!string.IsNullOrEmpty(newCameraName)) { isReferenceCamera = false; isReferenceClawCamera = false; clawModule = null; // First, we search our own part for this camera transform, // only then we search all other parts of the vessel. if (!LocateCamera(ourPart, newCameraName)) { foreach (Part thatpart in ourVessel.parts) { if (LocateCamera(thatpart, newCameraName)) { break; } } } } if (cameraTransform != null) { CameraSetup(0, "Camera ScaledSpace"); // These two cameras are created by Visual Enhancements mod. // I'm still not completely satisfied with the look, but it's definitely an improvement. CameraSetup(1, "Camera VE Underlay"); CameraSetup(2, "Camera VE Overlay"); CameraSetup(3, "Camera 01"); CameraSetup(4, "Camera 00"); enabled = true; JUtil.LogMessage(this, "Switched to camera \"{0}\".", cameraTransform.name); return; } JUtil.LogMessage(this, "Tried to switch to camera \"{0}\" but camera was not found.", newCameraName); }
// Returns true if the reference part is a claw and the part can be // toggled (state is Ready or state is Disabled). Also updates the // top-menu state text. Returns whether or not to disable the menu // item. private bool UpdateReferencePartAsClaw() { ModuleGrappleNode thatClaw = null; Part referencePart = vessel.GetReferenceTransformPart(); if (referencePart != null) { foreach (PartModule thatModule in referencePart.Modules) { thatClaw = thatModule as ModuleGrappleNode; if (thatClaw != null) { break; } } } if (thatClaw != null && (thatClaw.state == "Ready" || thatClaw.state == "Disabled")) { grappleMenuItem.labelText = (thatClaw.state == "Disabled") ? "Arm Grapple" : "Disarm Grapple"; return(false); } else { return(true); } }
private void PointToReferenceCamera() { isReferenceCamera = true; referencePart = ourVessel.GetReferenceTransformPart(); ModuleDockingNode thatPort = null; ModuleGrappleNode thatClaw = null; foreach (PartModule thatModule in ourVessel.GetReferenceTransformPart().Modules) { thatPort = thatModule as ModuleDockingNode; thatClaw = thatModule as ModuleGrappleNode; if (thatPort != null || thatClaw != null) break; } if (thatPort != null || thatClaw != null) { if (thatPort != null) { cameraPart = thatPort.part; cameraTransform = ourVessel.ReferenceTransform.gameObject; isReferenceClawCamera = false; } else if (thatClaw != null) { // Mihara: Dirty hack to get around the fact that claws have their reference transform inside the structure. if (LocateCamera(ourVessel.GetReferenceTransformPart(), "ArticulatedCap")) { isReferenceClawCamera = true; clawModule = thatClaw; } else { JUtil.LogMessage(this, "Claw was not a stock part. Falling back to reference transform position..."); cameraPart = thatClaw.part; cameraTransform = ourVessel.ReferenceTransform.gameObject; } } CreateCameraObjects(); } }
private bool PointToReferenceCamera() { isReferenceCamera = true; referencePart = ourVessel.GetReferenceTransformPart(); ModuleDockingNode thatPort = null; ModuleGrappleNode thatClaw = null; if (referencePart != null) { foreach (PartModule thatModule in referencePart.Modules) { thatPort = thatModule as ModuleDockingNode; thatClaw = thatModule as ModuleGrappleNode; if (thatPort != null || thatClaw != null) { break; } } } if (thatPort != null) { if (!LocateCamera(referencePart, "dockingNode")) { cameraPart = thatPort.part; cameraTransform = ourVessel.ReferenceTransform.gameObject; isReferenceTransformCamera = true; } isReferenceClawCamera = false; return(CreateCameraObjects()); } else if (thatClaw != null) { // Mihara: Dirty hack to get around the fact that claws have their reference transform inside the structure. if (LocateCamera(referencePart, "ArticulatedCap")) { isReferenceClawCamera = true; clawModule = thatClaw; } else { JUtil.LogMessage(this, "Claw was not a stock part. Falling back to reference transform position..."); cameraPart = thatClaw.part; cameraTransform = ourVessel.ReferenceTransform.gameObject; } return(CreateCameraObjects()); } else { return(false); } }
void GetOtherPart(ModuleGrappleNode grapple, ConnectedPartSet cp) { // The claw is a very unfriendly part. All the important fields // private. AttachNode grappleNode = (AttachNode)grappleNodeField.GetValue(grapple); if (grappleNode != null && grappleNode.attachedPart != null) { var vi = grapple.vesselInfo; cp.Add(grappleNode.attachedPart, vi.name); } }
internal Part find_attached_part() { Part attached_part = null; ModuleGrappleNode module = this.part.FindModuleImplementing <ModuleGrappleNode>(); if (module.otherVesselInfo != null) { foreach (Part part in FlightGlobals.ActiveVessel.parts) { if (part.flightID == module.dockedPartUId) { attached_part = part; } } } return(attached_part); }
private bool CreateCameraObjects(string newCameraName = null) { if (!string.IsNullOrEmpty(newCameraName)) { isReferenceCamera = false; isReferenceClawCamera = false; clawModule = null; // First, we search our own part for this camera transform, // only then we search all other parts of the vessel. if (!LocateCamera(ourPart, newCameraName)) { foreach (Part thatpart in ourVessel.parts) { if (LocateCamera(thatpart, newCameraName)) break; } } } if (cameraTransform != null) { for (int i = 0; i < knownCameraNames.Length; ++i) { CameraSetup(i, knownCameraNames[i]); } enabled = true; //JUtil.LogMessage(this, "Switched to camera \"{0}\".", cameraTransform.name); return true; } else { //JUtil.LogMessage(this, "Tried to switch to camera \"{0}\" but camera was not found.", newCameraName); return false; } }
public override void OnUpdate() { if (!pageActiveState || !JUtil.VesselIsInIVA(vessel)) { return; } currentTarget = FlightGlobals.fetch.VesselTarget; selectedCelestial = currentTarget as CelestialBody; selectedVessel = currentTarget as Vessel; selectedPort = currentTarget as ModuleDockingNode; selectedClaw = currentTarget as ModuleGrappleNode; if (selectedPort != null) { selectedVessel = selectedPort.vessel; } if (selectedClaw != null) { selectedVessel = selectedClaw.vessel; } if (vessel.parts.Count != partCount) { FindReferencePoints(); //UpdateUndockablesList(); } if (!UpdateCheck()) return; UpdateLists(); }
/// <summary> /// Create a hash of the vessel. /// </summary> /// <param name="vessel">The vessel to hash</param> /// <returns>A list of hashes for this vessel</returns> public static IEnumerable <uint> GetHashes(this Vessel vessel) { if (vessel.state == Vessel.State.DEAD) { yield break; } // Create the protovessel if it isn't there if (vessel.protoVessel == null) { vessel.protoVessel = new ProtoVessel(vessel); } if (vessel.protoVessel.protoPartSnapshots == null) { yield break; } Queue <ProtoPartSnapshot> queue = new Queue <ProtoPartSnapshot>(); Dictionary <ProtoPartSnapshot, int> visited = new Dictionary <ProtoPartSnapshot, int>(); Dictionary <uint, uint> dockedParts = new Dictionary <uint, uint>(); Queue <ProtoPartSnapshot> otherVessel = new Queue <ProtoPartSnapshot>(); IEnumerable <ProtoPartSnapshot> parts = vessel.protoVessel.protoPartSnapshots; // Add the root if (vessel.protoVessel.protoPartSnapshots.Any()) { queue.Enqueue(vessel.protoVessel.protoPartSnapshots.First()); visited[queue.First()] = 1; } // Do a BFS of all parts. uint hash = 0; int count = 0; while (queue.Any() || otherVessel.Any()) { bool decoupler = false; // Start a new ship if (queue.Count == 0) { // Reset our hash if (count != 0) { yield return(hash); } count = 0; hash = 0; // Find an unhandled part to use as the new vessel while (otherVessel.Any()) { ProtoPartSnapshot px = otherVessel.Dequeue(); if (!visited.ContainsKey(px) || visited[px] != 2) { queue.Enqueue(px); break; } } dockedParts.Clear(); continue; } if (!queue.Any()) { break; } ProtoPartSnapshot p = queue.Dequeue(); // Check if this is for a new vessel if (dockedParts.ContainsKey(p.flightID)) { otherVessel.Enqueue(p); continue; } // Special handling of certain modules foreach (ProtoPartModuleSnapshot pm in p.modules) { if (pm.moduleName == "ModuleDecouple" || pm.moduleName == "ModuleDockingNode" || pm.moduleName == "ModuleGrappleNode") { // Just assume all parts can decouple from this, it's easier and // effectively the same thing decoupler = true; // Parent may be null if this is the root of the stack if (p.parent != null) { dockedParts[p.parent.flightID] = p.parent.flightID; } // Add all children as possible new vessels foreach (ProtoPartSnapshot child in parts.Where(childPart => childPart.parent == p)) { dockedParts[child.flightID] = child.flightID; } if (pm.moduleName == "ModuleGrappleNode") { ModuleGrappleNode grapple = pm.moduleRef as ModuleGrappleNode; ProtoPartSnapshot dockedPart = parts.Where(childPart => childPart.flightID == grapple.dockedPartUId).FirstOrDefault(); if (dockedPart != null) { otherVessel.Enqueue(dockedPart); } } } } // Go through our child parts foreach (ProtoPartSnapshot child in parts.Where(childPart => childPart.parent == p)) { if (!visited.ContainsKey(child)) { queue.Enqueue(child); visited[child] = 1; } } // Confirm if parent part has been visited if (p.parent != null && !visited.ContainsKey(p.parent)) { queue.Enqueue(p.parent); visited[p.parent] = 1; } // Add this part to the hash if (!decoupler) { count++; hash ^= p.flightID; } // We've processed this node visited[p] = 2; } // Return the last hash if (count != 0) { yield return(hash); } }
private void CreateCameraObjects(string newCameraName = null) { if (!string.IsNullOrEmpty(newCameraName)) { isReferenceCamera = false; isReferenceClawCamera = false; clawModule = null; // First, we search our own part for this camera transform, // only then we search all other parts of the vessel. if (!LocateCamera(ourPart, newCameraName)) { foreach (Part thatpart in ourVessel.parts) { if (LocateCamera(thatpart, newCameraName)) break; } } } if (cameraTransform != null) { CameraSetup(0, "Camera ScaledSpace"); // These two cameras are created by Visual Enhancements mod. // I'm still not completely satisfied with the look, but it's definitely an improvement. CameraSetup(1, "Camera VE Underlay"); CameraSetup(2, "Camera VE Overlay"); CameraSetup(3, "Camera 01"); CameraSetup(4, "Camera 00"); enabled = true; JUtil.LogMessage(this, "Switched to camera \"{0}\".", cameraTransform.name); return; } JUtil.LogMessage(this, "Tried to switch to camera \"{0}\" but camera was not found.", newCameraName); }