// Signalled by master about locking. Set flags public void setSlaveLock(uint masterPartId) { printDebug($"setting slave lock by request from {masterPartId}"); isSlave = true; isMaster = false; pairLockPartId = masterPartId; otherLockPart = FlightGlobals.FindPartByID(masterPartId); otherLock = (LockMechanism)otherLockPart.Modules ["LockMechanism"]; lockFSM.state = LockFSM.State.Locking; defaultPostEventAction(); }
public static void update() { // for each part from previous frame foreach (var prev_p in prev_parts) { // get the part Part prev_part = FlightGlobals.FindPartByID(prev_p.Key); // if it still exist if (prev_part != null) { // note: when solar panels break (the stock mechanic), this throw exceptions inside KSP try { // reset highlight color prev_part.SetHighlightDefault(); // the new color change module overwrite our highlights and was disabled, re-enable it prev_part.FindModulesImplementing <ModuleColorChanger>().ForEach(k => k.enabled = true); } catch { } } } // for each part in this farme foreach (var p in parts) { // get the part Part part = FlightGlobals.FindPartByID(p.Key); // if it still exist if (part != null) { // note: when solar panels break (the stock mechanic), this throw exceptions inside KSP try { // set highlight color part.SetHighlightDefault(); part.SetHighlightType(Part.HighlightType.AlwaysOn); part.SetHighlightColor((Color)p.Value); part.SetHighlight(true, false); // the new color change module seem to overwrite our highlights, disable it part.FindModulesImplementing <ModuleColorChanger>().ForEach(k => k.enabled = false); } catch { } } } // clear previous parts, and remember current parts as previous Lib.Swap(ref prev_parts, ref parts); parts.Clear(); }
/// <inheritdoc/> public ILinkPeer FindLinkPeer(ILinkPeer srcPeer) { var host = srcPeer as PartModule; var tgtPart = FlightGlobals.FindPartByID(srcPeer.linkPartId); if (tgtPart == null) { HostedDebugLog.Warning(host, "Cannot find target part: partId=F{0}", srcPeer.linkPartId); return(null); } // In normal case we can lookup by the node name. ILinkPeer tgtPeer = null; if (!string.IsNullOrEmpty(srcPeer.linkNodeName)) { tgtPeer = tgtPart.Modules .OfType <ILinkPeer>() .FirstOrDefault(m => m.linkState == LinkState.Linked && m.linkPartId == srcPeer.part.flightID && m.linkNodeName == srcPeer.cfgAttachNodeName && m.cfgLinkType == srcPeer.cfgLinkType); } // Fallback case. Try guessing the target peer by less strict conditions. if (tgtPeer == null) { var candidates = tgtPart.Modules .OfType <ILinkPeer>() .Where(m => m.linkState == LinkState.Linked && m.linkPartId == srcPeer.part.flightID && m.cfgLinkType == srcPeer.cfgLinkType) .ToList(); if (candidates.Count == 1) { tgtPeer = candidates[0]; HostedDebugLog.Warning(host, "FALLBACK: Found a link: {0} => {1}", srcPeer, tgtPeer); } } if (tgtPeer == null) { HostedDebugLog.Warning( host, "Failed to find the link: targetPartId={0}, targetNode={1}", srcPeer.linkPartId, srcPeer.linkNodeName); } return(tgtPeer); }
public void DecoupleVessel() { vessel.Parts.Find(p => p.uid == uifs.vesselInfo.rootPartUId).Undock(uifs.vesselInfo); uifs.vesselInfo = null; Events[("DecoupleVessel")].active = false; //Staging.GenerateStagingSequence(vessel.rootPart); //Staging.RecalculateVesselStaging(vessel); //Staging.beginFlight(); //print(FlightGlobals.Vessels.Count); //FlightGlobals.ForceSetActiveVessel(FlightGlobals.Vessels[FlightGlobals.Vessels.Count - 1]); //FlightGlobals.ForceSetActiveVessel(vessel); //QuickSaveLoad.QuickSave(); //FlightGlobals.DontDestroyOnLoad(FlightGlobals.FindPartByID(uifs.vesselFlightID).vessel.gameObject); //HighLogic.LoadScene(GameScenes.FLIGHT); FlightGlobals.ForceSetActiveVessel(FlightGlobals.FindPartByID(uifs.vesselFlightID).vessel); }
// to be called as window refresh function void window_body(Panel p) { // outside the editor if (!Lib.IsEditor()) { // if part doesn't exist anymore if (FlightGlobals.FindPartByID(part.flightID) == null) { return; } } // inside the editor else { // if the part doesn't exist anymore (eg: removed, user hit undo) if (GetInstanceID() == 0) { return; } } // for each selected setup for (int selected_i = 0; selected_i < selected.Count; ++selected_i) { // find index in unlocked setups for (int setup_i = 0; setup_i < unlocked.Count; ++setup_i) { if (unlocked[setup_i].name == selected[selected_i]) { // commit panel render_panel(p, unlocked[setup_i], selected_i, setup_i); } } } // set metadata p.title(Lib.BuildString("Configure <color=#cccccc>", Lib.Ellipsis(title, Styles.ScaleStringLength(40)), "</color>")); p.width(Styles.ScaleWidthFloat(300.0f)); }
/// <inheritdoc/> public ILinkPeer FindLinkPeer(ILinkPeer srcPeer) { if (srcPeer.linkPartId == 0 || srcPeer.linkModuleIndex == -1) { DebugEx.Error("Bad target part definition [Part:(id=F{0}#Module:{1}]", srcPeer.linkPartId, srcPeer.linkModuleIndex); return(null); } var tgtPart = FlightGlobals.FindPartByID(srcPeer.linkPartId); if (tgtPart == null) { DebugEx.Error("Cannot find [Part:(id=F{0})]", srcPeer.linkPartId); return(null); } if (srcPeer.linkModuleIndex >= tgtPart.Modules.Count) { DebugEx.Error("The target part {0} doesn't have a module at index {1}", tgtPart, srcPeer.linkModuleIndex); return(null); } var tgtPeer = tgtPart.Modules[srcPeer.linkModuleIndex] as ILinkPeer; if (tgtPeer == null) { DebugEx.Error("The target module {0} is not a link peer", tgtPart.Modules[srcPeer.linkModuleIndex]); return(null); } if (!tgtPeer.isLinked || tgtPeer.linkPartId != srcPeer.part.flightID || tgtPeer.linkModuleIndex != srcPeer.part.Modules.IndexOf(srcPeer as PartModule)) { DebugEx.Error("Source module {0} cannot be linked with the target module {1}", srcPeer.part.Modules[tgtPeer.linkModuleIndex], tgtPart.Modules[srcPeer.linkModuleIndex]); return(null); } return(tgtPeer); }
// to be called as window refresh function void Window_Body(Panel p) { // outside the editor if (!Lib.IsEditor()) { // if part doesn't exist anymore if (FlightGlobals.FindPartByID(part.flightID) == null) { return; } } // inside the editor else { // if the part doesn't exist anymore (eg: removed, user hit undo) if (GetInstanceID() == 0) { return; } } // for each selected setup for (int selected_i = 0; selected_i < selected.Count; ++selected_i) { // find index in unlocked setups for (int setup_i = 0; setup_i < unlocked.Count; ++setup_i) { if (unlocked[setup_i].name == selected[selected_i]) { // commit panel Render_Panel(p, unlocked[setup_i], selected_i, setup_i); } } } // set metadata p.Title(Lib.BuildString("Configure <color=#cccccc>", title, "</color>")); }
public void offRails(Vessel v) { if (lockFSM.state == LockFSM.State.Locked && lockJoint == null && pairLockPartId != 0) { // If locked and there's no joint, we're restoring from save and joint // must be re-created printDebug("restoring joint; pair=" + pairLockPartId + "; isMaster=" + isMaster); otherLockPart = FlightGlobals.FindPartByID(pairLockPartId); if (otherLockPart != null) { // In case of genderless locking, get other part locking module if ((isMaster || isSlave) && otherLockPart.Modules.Contains("LockMechanism")) { otherLock = (LockMechanism)otherLockPart.Modules ["LockMechanism"]; } jointJustCreated = false; lockHasp(otherLockPart); } } defaultPostEventAction(); msgPosted = false; }
public void resolve() { resolved = false; Debug.Log("[SupplyChain] Resolving vessel reference for Tracking ID: " + this.trackingID.ToString()); foreach (Vessel v in FlightGlobals.Vessels) { if (v.id.Equals(linkedID)) { vesselRef = v; rootPartID = v.protoVessel.protoPartSnapshots[v.protoVessel.rootIndex].flightID; resolved = true; Debug.Log("[SupplyChain] Resolved reference with Vessel ID: " + linkedID.ToString()); return; } else { // try and match by root PartID. if (v.loaded) { if (v.rootPart.flightID == this.rootPartID) { vesselRef = v; linkedID = v.id; resolved = true; Debug.Log("[SupplyChain] Found vessel with Root Part ID: " + Convert.ToString(this.rootPartID)); } } else { if (v.protoVessel.protoPartSnapshots[v.protoVessel.rootIndex].flightID == this.rootPartID) { vesselRef = v; linkedID = v.id; resolved = true; Debug.Log("[SupplyChain] Found unloaded vessel with Root Part ID: " + Convert.ToString(this.rootPartID)); } } } if (resolved) { return; } } if (!resolved) { // find by root part ID. Part rp = FlightGlobals.FindPartByID(this.rootPartID); if (rp != null) { vesselRef = rp.vessel; linkedID = rp.vessel.id; resolved = true; Debug.Log("[SupplyChain] Resolved reference by searching for Part ID: " + Convert.ToString(this.rootPartID)); } } }