// Adapted from KIS by IgorZ // See https://github.com/ihsoft/KIS/blob/master/Source/KIS_Shared.cs#L1005-L1039 // This method is in the public domain. /// <summary>Couples docking port with a part at its reference attach node.</summary> /// <remarks>Both parts must be already connected and the attach nodes correctly set.</remarks> /// <param name="dockingNode">Port to couple.</param> /// <returns><c>true</c> if coupling was successful.</returns> public static bool CoupleDockingPortWithPart(ModuleDockingNode dockingNode) { Part tgtPart = dockingNode.referenceNode.attachedPart; if (tgtPart == null) { log.error("Node's part " + dockingNode.part.name + " is not attached to anything thru the reference node"); return(false); } if (dockingNode.state != dockingNode.st_ready.name) { log.debug("Hard reset docking node " + dockingNode.part.name + " from state " + dockingNode.state + " to " + dockingNode.st_ready.name); dockingNode.dockedPartUId = 0; dockingNode.dockingNodeModuleIndex = 0; // Target part lived in real world for some time, so its state may be anything. // Do a hard reset. dockingNode.fsm.StartFSM(dockingNode.st_ready.name); } var initState = dockingNode.lateFSMStart(PartModule.StartState.None); // Make sure part init catched the new state. while (initState.MoveNext()) { // Do nothing. Just wait. } if (dockingNode.fsm.currentStateName != dockingNode.st_preattached.name) { log.warning("Node on " + dockingNode.part.name + " is unexpected state " + dockingNode.fsm.currentStateName); return(false); } log.debug("Successfully set docking node " + dockingNode.part + " to state " + dockingNode.fsm.currentStateName + " with part " + tgtPart.name); return(true); }
public static bool CoupleDockingPortWithPart(ModuleDockingNode dockingNode) { var tgtPart = dockingNode.referenceNode.attachedPart; if (tgtPart == null) { Debug.Log("[ModuleMissileRearm]: Node's part {0} is not attached to anything thru the reference node" + dockingNode.part); return(false); } if (dockingNode.state != dockingNode.st_ready.name) { Debug.Log("[ModuleMissileRearm]: Hard reset docking node {0} from state '{1}' to '{2}'" + dockingNode.part + dockingNode.state + dockingNode.st_ready.name); dockingNode.dockedPartUId = 0; dockingNode.dockingNodeModuleIndex = 0; // Target part lived in real world for some time, so its state may be anything. // Do a hard reset. dockingNode.fsm.StartFSM(dockingNode.st_ready.name); } var initState = dockingNode.lateFSMStart(PartModule.StartState.None); // Make sure part init catched the new state. while (initState.MoveNext()) { // Do nothing. Just wait. } if (dockingNode.fsm.currentStateName != dockingNode.st_preattached.name) { Debug.Log("[ModuleMissileRearm]: Node on {0} is unexpected state '{1}'" + dockingNode.part + dockingNode.fsm.currentStateName); return(false); } Debug.Log("[ModuleMissileRearm]: Successfully set docking node {0} to state {1} with part {2}" + dockingNode.part + dockingNode.fsm.currentStateName + tgtPart); return(true); }