void CleaupAfterRelease() { craftRoot = null; vesselInfo = null; buildCost = null; builtStuff = null; state = State.Idle; }
public ElementValue(DockedVesselInfo dockedVesselInfo, SharedObjects shared) { this.dockedVesselInfo = dockedVesselInfo; this.shared = shared; parts = new List<global::Part>(); InitializeSuffixes(); }
public ElementValue(DockedVesselInfo dockedVesselInfo, SharedObjects shared) { this.dockedVesselInfo = dockedVesselInfo; this.shared = shared; parts = new List <global::Part>(); InitializeSuffixes(); }
/// <summary>Updates the vessel info on the part if it has the relevant module.</summary> /// <param name="v">The vessel to capture the info for.</param> static DockedVesselInfo GetVesselInfo(Vessel v) { var vesselInfo = new DockedVesselInfo(); vesselInfo.name = v.vesselName; vesselInfo.vesselType = v.vesselType; vesselInfo.rootPartUId = v.rootPart.flightID; return(vesselInfo); }
public static void CoupleParts(Part srcPart, Part trgPart, AttachNode sourceNode, AttachNode targetNode = null) { Vessel srcVessel = srcPart.vessel; Vessel trgVessel = trgPart.vessel; DockedVesselInfo vesselInfo = new DockedVesselInfo(); vesselInfo.name = srcVessel.vesselName; vesselInfo.vesselType = srcVessel.vesselType; vesselInfo.rootPartUId = srcVessel.rootPart.flightID; GameEvents.onActiveJointNeedUpdate.Fire(srcVessel); GameEvents.onActiveJointNeedUpdate.Fire(trgVessel); sourceNode.attachedPart = trgPart; sourceNode.attachedPartId = trgPart.flightID; if (sourceNode.id != "srfAttach") { srcPart.attachMode = AttachModes.STACK; if (targetNode != null) { targetNode.attachedPart = srcPart; } else { log.warning("Target node is null."); } } else { srcPart.attachMode = AttachModes.SRF_ATTACH; } srcPart.Couple(trgPart); // Depending on how active vessel has updated do either force active or make active. Note, that // active vessel can be EVA kerbal, in which case nothing needs to be adjusted. // FYI: This logic was taken from ModuleDockingNode.DockToVessel. if (srcVessel == FlightGlobals.ActiveVessel) { FlightGlobals.ForceSetActiveVessel(sourceNode.owner.vessel); // Use actual vessel. } else if (sourceNode.owner.vessel == FlightGlobals.ActiveVessel) { sourceNode.owner.vessel.MakeActive(); } GameEvents.onVesselWasModified.Fire(sourceNode.owner.vessel); ModuleDockingNode sourcePort, targetPort; if (hasDockingPort(sourceNode, out sourcePort)) { CoupleDockingPortWithPart(sourcePort); } if (hasDockingPort(targetNode, out targetPort)) { CoupleDockingPortWithPart(targetPort); } }
public void Load(ConfigNode node) { if (node.HasValue("filename")) { filename = node.GetValue("filename"); } if (node.HasValue("flagname")) { flagname = node.GetValue("flagname"); } if (node.HasNode("CraftConfig")) { craftConfig = node.GetNode("CraftConfig"); } if (node.HasNode("BuildCost")) { var bc = node.GetNode("BuildCost"); buildCost = new CostReport(); buildCost.Load(bc); } if (node.HasNode("BuiltStuff")) { var bs = node.GetNode("BuiltStuff"); builtStuff = new CostReport(); builtStuff.Load(bs); } if (node.HasValue("state")) { var s = node.GetValue("state"); state = (State)Enum.Parse(typeof(State), s); if (state == State.Dewarping) { // The game got saved while the Dewarping state was still // active. Rather than restarting the dewarp coroutine, // Just jump straight to the Complete state. state = State.Complete; } } if (node.HasValue("paused")) { var s = node.GetValue("paused"); bool p = false; bool.TryParse(s, out p); paused = p; } if (node.HasValue("KACalarmID")) { KACalarmID = node.GetValue("KACalarmID"); } if (node.HasNode("DockedVesselInfo")) { ConfigNode vi = node.GetNode("DockedVesselInfo"); vesselInfo = new DockedVesselInfo(); vesselInfo.Load(vi); } }
/// <summary>Updates the vessel info on the part if it has the relevant module.</summary> /// <param name="v">The vessel to capture the info for.</param> static DockedVesselInfo GetVesselInfo(Vessel v) { var vesselInfo = new DockedVesselInfo { name = v.vesselName, vesselType = v.vesselType, rootPartUId = v.rootPart.flightID }; return(vesselInfo); }
public void UndockStart(Part part, DockedVesselInfo dockedInfo) { if (VesselCommon.IsSpectating || System.IgnoreEvents) { return; } if (!LockSystem.LockQuery.UpdateLockBelongsToPlayer(part.vessel.id, SettingsSystem.CurrentSettings.PlayerName)) { return; } LunaLog.Log($"Detected undock! Part: {part.partName} Vessel: {part.vessel.id}"); }
private void CoupleWithCraft(Vessel craftVessel) { craftRoot = craftVessel.rootPart; vesselInfo = new DockedVesselInfo(); vesselInfo.name = craftVessel.vesselName; vesselInfo.vesselType = craftVessel.vesselType; vesselInfo.rootPartUId = craftRoot.flightID; craftRoot.Couple(builder.part); if (builder.vessel != FlightGlobals.ActiveVessel) { FlightGlobals.ForceSetActiveVessel(builder.vessel); } }
public void ReleaseVessel() { if (craftRoot != null) { craftRoot.Undock(vesselInfo); var vesselCount = FlightGlobals.Vessels.Count; Vessel vsl = FlightGlobals.Vessels[vesselCount - 1]; FlightGlobals.ForceSetActiveVessel(vsl); } craftConfig = null; vesselInfo = null; buildCost = null; builtStuff = null; state = State.Idle; }
public void PartUndocked(Part part, DockedVesselInfo dockedInfo, Vessel originalVessel) { if (VesselCommon.IsSpectating) { return; } if (!LockSystem.LockQuery.UpdateLockBelongsToPlayer(originalVessel.id, SettingsSystem.CurrentSettings.PlayerName)) { return; } System.MessageSender.SendVesselMessage(part.vessel); //As this method can be called several times in a short period (when staging) we delay the sending of the final vessel System.DelayedSendVesselMessage(originalVessel.id, 0.5f); }
//failsafe in case DockedVesselInfo is lost void restore_docking_info(Part docked_part) { if (this_vessel == null) { this_vessel = new DockedVesselInfo(); this_vessel.name = vessel.vesselName; this_vessel.vesselType = vessel.vesselType; this_vessel.rootPartUId = part.flightID; } if (docked_vessel == null && docked_part != null) { docked_vessel = new DockedVesselInfo(); docked_vessel.name = Vessel.AutoRename(vessel, vessel.vesselName); docked_vessel.vesselType = vessel.vesselType; docked_vessel.rootPartUId = docked_part.flightID; } }
/// <summary> /// Builds the first element in the queue /// </summary> /// <param name="vessel">The vessel that you want to crawl for elements</param> /// <param name="elements">The final element list, is it included here to have the root element added</param> /// <param name="shared">the ever present shared object</param> /// <returns>a queue with a starting entry</returns> private static Queue <ElementPair> InitQueue(Vessel vessel, Dictionary <uint, ElementValue> elements, SharedObjects shared) { var toReturn = new Queue <ElementPair>(); var rootUid = vessel.rootPart.flightID; var rootInfo = new DockedVesselInfo { name = vessel.vesselName, rootPartUId = rootUid, vesselType = vessel.vesselType }; var rootElement = new ElementValue(rootInfo, shared); elements.Add(rootUid, rootElement); toReturn.Enqueue(new ElementPair(rootElement, vessel.rootPart)); return(toReturn); }
/// <summary>Restores the name and type of the vessels of the former coupled parts.</summary> /// <remarks> /// The source and target parts need to be separated, but the logical link still need to exist. /// On restore the vessel info will be cleared on the module. Alas, when the link is broken /// extrenally, the root vessel part cannot be properly restored. /// </remarks> void RestorePartialVesselInfo(ILinkSource source, ILinkTarget target, bool weDecouple) { AsyncCall.CallOnEndOfFrame(this, () => { var vesselInfo = weDecouple ? persistedSrcVesselInfo : persistedTgtVesselInfo; var childPart = weDecouple ? source.part : target.part; if (childPart.vessel.vesselType != vesselInfo.vesselType || childPart.vessel.vesselName != vesselInfo.name) { HostedDebugLog.Warning(this, "Partially restoring vessel info on {0}: type={1}, name={2}", childPart, vesselInfo.vesselType, vesselInfo.name); childPart.vessel.vesselType = vesselInfo.vesselType; childPart.vessel.vesselName = vesselInfo.name; } persistedSrcVesselInfo = null; persistedTgtVesselInfo = null; }); }
/// <summary> /// Decouples the source and the target parts turning them into the separate vessels. /// </summary> /// <seealso cref="CoupleParts"/> void DecoupleParts() { if (!isCoupled) { HostedDebugLog.Error(this, "Cannot decouple - bad link/part state"); return; } selfDecoupledAction = true; // Protect the action to not let the link auto-broken. KASAPI.LinkUtils.DecoupleParts( linkSource.part, linkTarget.part, vesselInfo1: persistedSrcVesselInfo, vesselInfo2: persistedTgtVesselInfo); selfDecoupledAction = false; persistedSrcVesselInfo = null; persistedTgtVesselInfo = null; DelegateCouplingRole(linkTarget.part); SetCustomJoints(null); }
private static void WorkQueue(Queue <ElementPair> queue, Dictionary <uint, ElementValue> elements, SharedObjects shared) { var visitedFlightIds = new HashSet <uint>(); while (queue.Any()) { ElementPair pair = queue.Dequeue(); if (AlreadyVisited(pair.Part, visitedFlightIds)) { continue; } var dockingNodes = pair.Part.Modules.OfType <ModuleDockingNode>().ToList(); if (dockingNodes.Any()) { foreach (var dockingNode in dockingNodes) { ElementValue element; if (dockingNode.vesselInfo == null) { element = pair.Element; } else { DockedVesselInfo info = dockingNode.vesselInfo; if (!elements.TryGetValue(info.rootPartUId, out element)) { element = new ElementValue(info, shared); elements.Add(info.rootPartUId, element); } } element.AddPart(pair.Part); EnqueueChildren(queue, element, pair.Part); } } else { pair.Element.AddPart(pair.Part); EnqueueChildren(queue, pair.Element, pair.Part); } } }
public void UndockComplete(Part part, DockedVesselInfo dockedInfo, Vessel originalVessel) { if (VesselCommon.IsSpectating || System.IgnoreEvents) { return; } if (!LockSystem.LockQuery.UpdateLockBelongsToPlayer(originalVessel.id, SettingsSystem.CurrentSettings.PlayerName)) { return; } LockSystem.Singleton.AcquireUnloadedUpdateLock(part.vessel.id, true, true); LockSystem.Singleton.AcquireUpdateLock(part.vessel.id, true, true); VesselPositionSystem.Singleton.MessageSender.SendVesselPositionUpdate(part.vessel, true); LunaLog.Log($"Undock complete! Part: {part} Vessel: {originalVessel.id}"); System.MessageSender.SendVesselUndock(originalVessel, part.flightID, dockedInfo, part.vessel.id); }
public void SendVesselUndock(Vessel vessel, uint partFlightId, DockedVesselInfo dockedInfo, Guid newVesselId) { if (vessel == null) { return; } var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <VesselUndockMsgData>(); msgData.GameTime = TimeSyncSystem.UniversalTime; msgData.VesselId = vessel.id; msgData.PartFlightId = partFlightId; msgData.NewVesselId = newVesselId; msgData.DockedInfoName = dockedInfo.name; msgData.DockedInfoRootPartUId = dockedInfo.rootPartUId; msgData.DockedInfoVesselType = (int)dockedInfo.vesselType; SendMessage(msgData); }
public override void OnLoad(ConfigNode node) { flagname = node.GetValue("flagname"); if (node.HasValue("baseMass")) { float.TryParse(node.GetValue("baseMass"), out base_mass); } else { base_mass = part.mass; } craftConfig = node.GetNode("CraftConfig"); if (node.HasNode("BuildCost")) { var bc = node.GetNode("BuildCost"); buildCost = new BuildCost.CostReport(); buildCost.Load(bc); } if (node.HasNode("BuiltStuff")) { var bs = node.GetNode("BuiltStuff"); builtStuff = new BuildCost.CostReport(); builtStuff.Load(bs); } if (node.HasValue("state")) { var s = node.GetValue("state"); state = (State)Enum.Parse(typeof(State), s); } if (node.HasValue("paused")) { var s = node.GetValue("paused"); bool p = false; bool.TryParse(s, out p); paused = p; } if (node.HasNode("DockedVesselInfo")) { ConfigNode vi = node.GetNode("DockedVesselInfo"); vesselInfo = new DockedVesselInfo(); vesselInfo.Load(vi); } }
internal List <Part> GetDockedVesselParts(DockedVesselInfo vesselInfo) { List <Part> vesselpartList = new List <Part>(); try { if (vesselInfo != null) { Part vesselRoot = (from p in Vessel.parts where p.flightID == vesselInfo.rootPartUId select p).SingleOrDefault(); if (vesselRoot != null) { //vesselpartList = (from p in Vessel.parts where p.launchID == vesselRoot.launchID select p).ToList(); GetChildren(vesselRoot, ref vesselpartList); } } } catch (Exception ex) { SmUtils.LogMessage($"Error in GetSelectedVesselParts().\r\nError: {ex}", SmUtils.LogType.Error, true); vesselpartList = new List <Part>(); } return(vesselpartList); }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (node.HasNode("FIXEDATTACH")) { ConfigNode FxNode = node.GetNode("FIXEDATTACH"); KAS_Shared.DebugLog("OnLoad(Core) Loading fixed joint info from save..."); if (FxNode.HasValue("srcPartID") && FxNode.HasValue("srcVesselID") && FxNode.HasValue("tgtPartID") && FxNode.HasValue("tgtVesselID") && FxNode.HasValue("breakForce")) { FixedAttach.savedSrcPartID = FxNode.GetValue("srcPartID").ToString(); FixedAttach.savedSrcVesselID = FxNode.GetValue("srcVesselID").ToString(); FixedAttach.savedTgtPartID = FxNode.GetValue("tgtPartID").ToString(); FixedAttach.savedTgtVesselID = FxNode.GetValue("tgtVesselID").ToString(); FixedAttach.savedBreakForce = float.Parse(FxNode.GetValue("breakForce")); attachMode.FixedJoint = true; } else { KAS_Shared.DebugWarning("OnLoad(Core) Missing node value(s)!"); } } if (node.HasNode("DOCKEDVESSEL") && node.HasValue("dockedPartID")) { KAS_Shared.DebugLog("OnLoad(Core) Loading docked info from save..."); vesselInfo = new DockedVesselInfo(); vesselInfo.Load(node.GetNode("DOCKEDVESSEL")); dockedPartID = node.GetValue("dockedPartID").ToString(); attachMode.Docked = true; } if (node.HasValue("StaticJoint")) { attachMode.StaticJoint = true; } }
public void AttachDocked(KASModuleAttachCore otherAttachModule, Vessel forceDominant = null) { // Don't overwrite vesselInfo on redundant calls if (this.part.vessel == otherAttachModule.part.vessel && attachMode.Docked && dockedAttachModule == otherAttachModule && otherAttachModule.attachMode.Docked && otherAttachModule.dockedAttachModule == this && this.vesselInfo != null && otherAttachModule.vesselInfo != null) { KAS_Shared.DebugWarning("DockTo(Core) Parts already docked, nothing to do at all"); return; } // Save vessel Info this.vesselInfo = new DockedVesselInfo(); this.vesselInfo.name = this.vessel.vesselName; this.vesselInfo.vesselType = this.vessel.vesselType; this.vesselInfo.rootPartUId = this.vessel.rootPart.flightID; this.dockedAttachModule = otherAttachModule; this.dockedPartID = otherAttachModule.part.flightID.ToString(); otherAttachModule.vesselInfo = new DockedVesselInfo(); otherAttachModule.vesselInfo.name = otherAttachModule.vessel.vesselName; otherAttachModule.vesselInfo.vesselType = otherAttachModule.vessel.vesselType; otherAttachModule.vesselInfo.rootPartUId = otherAttachModule.vessel.rootPart.flightID; otherAttachModule.dockedAttachModule = this; otherAttachModule.dockedPartID = this.part.flightID.ToString(); // Set reference attachMode.Docked = otherAttachModule.attachMode.Docked = true; // Stop if already docked if (otherAttachModule.part.parent == this.part || this.part.parent == otherAttachModule.part) { KAS_Shared.DebugWarning("DockTo(Core) Parts already docked, nothing more to do"); return; } // This results in a somewhat wrong state, but it's better to not make it even more wrong if (otherAttachModule.part.vessel == this.part.vessel) { KAS_Shared.DebugWarning("DockTo(Core) BUG: Parts belong to the same vessel, doing nothing"); return; } // Reset vessels position and rotation for returning all parts to their original position and rotation before coupling this.vessel.SetPosition(this.vessel.transform.position, true); this.vessel.SetRotation(this.vessel.transform.rotation); otherAttachModule.vessel.SetPosition(otherAttachModule.vessel.transform.position, true); otherAttachModule.vessel.SetRotation(otherAttachModule.vessel.transform.rotation); // Couple depending of mass Vessel dominantVessel = GetDominantVessel(this.vessel, otherAttachModule.vessel); if (forceDominant == this.vessel || forceDominant == otherAttachModule.vessel) { dominantVessel = forceDominant; } KAS_Shared.DebugLog("DockTo(Core) Master vessel is " + dominantVessel.vesselName); if (dominantVessel == this.vessel) { KAS_Shared.DebugLog("DockTo(Core) Docking " + otherAttachModule.part.partInfo.title + " from " + otherAttachModule.vessel.vesselName + " with " + this.part.partInfo.title + " from " + this.vessel.vesselName); if (FlightGlobals.ActiveVessel == otherAttachModule.part.vessel) { KAS_Shared.DebugLog("DockTo(Core) Switching focus to " + this.part.vessel.vesselName); FlightGlobals.ForceSetActiveVessel(this.part.vessel); FlightInputHandler.ResumeVesselCtrlState(this.part.vessel); } otherAttachModule.part.Couple(this.part); } else { KAS_Shared.DebugLog("DockTo(Core) Docking " + this.part.partInfo.title + " from " + this.vessel.vesselName + " with " + otherAttachModule.part.partInfo.title + " from " + otherAttachModule.vessel.vesselName); if (FlightGlobals.ActiveVessel == this.part.vessel) { KAS_Shared.DebugLog("DockTo(Core) Switching focus to " + otherAttachModule.part.vessel.vesselName); FlightGlobals.ForceSetActiveVessel(otherAttachModule.part.vessel); FlightInputHandler.ResumeVesselCtrlState(otherAttachModule.part.vessel); } this.part.Couple(otherAttachModule.part); } GameEvents.onVesselWasModified.Fire(this.part.vessel); }
public void AttachDocked(KASModuleAttachCore otherAttachModule, Vessel forceDominant = null) { // Don't overwrite vesselInfo on redundant calls if (part.vessel == otherAttachModule.part.vessel && attachMode.Docked && dockedAttachModule == otherAttachModule && otherAttachModule.attachMode.Docked && otherAttachModule.dockedAttachModule == this && vesselInfo != null && otherAttachModule.vesselInfo != null) { KAS_Shared.DebugWarning("DockTo(Core) Parts already docked, nothing to do at all"); return; } // Save vessel Info vesselInfo = new DockedVesselInfo(); vesselInfo.name = vessel.vesselName; vesselInfo.vesselType = vessel.vesselType; vesselInfo.rootPartUId = vessel.rootPart.flightID; dockedAttachModule = otherAttachModule; dockedPartID = otherAttachModule.part.flightID.ToString(); otherAttachModule.vesselInfo = new DockedVesselInfo(); otherAttachModule.vesselInfo.name = otherAttachModule.vessel.vesselName; otherAttachModule.vesselInfo.vesselType = otherAttachModule.vessel.vesselType; otherAttachModule.vesselInfo.rootPartUId = otherAttachModule.vessel.rootPart.flightID; otherAttachModule.dockedAttachModule = this; otherAttachModule.dockedPartID = part.flightID.ToString(); // Set reference attachMode.Docked = true; otherAttachModule.attachMode.Docked = true; // Stop if already docked if (otherAttachModule.part.parent == part || part.parent == otherAttachModule.part) { KAS_Shared.DebugWarning("DockTo(Core) Parts already docked, nothing more to do"); return; } // This results in a somewhat wrong state, but it's better to not make it even more wrong. if (otherAttachModule.part.vessel == part.vessel) { KAS_Shared.DebugWarning("DockTo(Core) BUG: Parts belong to the same vessel, doing nothing"); return; } // Reset vessels position and rotation for returning all parts to their original position and // rotation before coupling vessel.SetPosition(vessel.transform.position, true); vessel.SetRotation(vessel.transform.rotation); otherAttachModule.vessel.SetPosition(otherAttachModule.vessel.transform.position, true); otherAttachModule.vessel.SetRotation(otherAttachModule.vessel.transform.rotation); // Couple depending of mass Vessel dominantVessel = GetDominantVessel(this.vessel, otherAttachModule.vessel); if (forceDominant == this.vessel || forceDominant == otherAttachModule.vessel) { dominantVessel = forceDominant; } KAS_Shared.DebugLog(string.Format("DockTo(Core) Master vessel is {0}", dominantVessel.vesselName)); if (dominantVessel == this.vessel) { KAS_Shared.DebugLog(string.Format("DockTo(Core) Docking {0} from {1} with {2} from {3}", otherAttachModule.part.partInfo.title, otherAttachModule.vessel.vesselName, part.partInfo.title, vessel.vesselName)); if (FlightGlobals.ActiveVessel == otherAttachModule.part.vessel) { KAS_Shared.DebugLog(string.Format("DockTo(Core) Switching focus to {0}", this.part.vessel.vesselName)); FlightGlobals.ForceSetActiveVessel(this.part.vessel); FlightInputHandler.ResumeVesselCtrlState(this.part.vessel); } otherAttachModule.part.Couple(this.part); } else { KAS_Shared.DebugLog(string.Format("DockTo(Core) Docking {0} from {1} with {2} from {3}", part.partInfo.title, vessel.vesselName, otherAttachModule.part.partInfo.title, otherAttachModule.vessel.vesselName)); if (FlightGlobals.ActiveVessel == part.vessel) { KAS_Shared.DebugLog(string.Format("DockTo(Core) Switching focus to {0}", otherAttachModule.part.vessel.vesselName)); FlightGlobals.ForceSetActiveVessel(otherAttachModule.part.vessel); FlightInputHandler.ResumeVesselCtrlState(otherAttachModule.part.vessel); } part.Couple(otherAttachModule.part); } GameEvents.onVesselWasModified.Fire(this.part.vessel); }
internal List<Part> GetDockedVesselParts(DockedVesselInfo vesselInfo) { List<Part> vesselpartList = new List<Part>(); try { if (vesselInfo != null) { Part vesselRoot = (from p in Vessel.parts where p.flightID == vesselInfo.rootPartUId select p).SingleOrDefault(); if (vesselRoot != null) { vesselpartList = (from p in Vessel.parts where p.launchID == vesselRoot.launchID select p).ToList(); } } } catch (Exception ex) { Utilities.LogMessage(string.Format("Error in GetSelectedVesselParts().\r\nError: {0}", ex), Utilities.LogType.Error, true); vesselpartList = new List<Part>(); } return vesselpartList; }
private static void PrefixUndock(Part __instance, DockedVesselInfo newVesselInfo, ref Vessel __state) { __state = __instance.vessel; PartEvent.onPartUndocking.Fire(__instance, newVesselInfo); }
void CleaupAfterRelease () { craftRoot = null; craftConfig = null; vesselInfo = null; buildCost = null; builtStuff = null; state = State.Idle; }
private void CoupleWithCraft () { craftRoot = craftVessel.rootPart; vesselInfo = new DockedVesselInfo (); vesselInfo.name = craftVessel.vesselName; vesselInfo.vesselType = craftVessel.vesselType; vesselInfo.rootPartUId = craftRoot.flightID; craftRoot.Couple (builder.part); if (builder.vessel != FlightGlobals.ActiveVessel) { FlightGlobals.ForceSetActiveVessel (builder.vessel); } }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); //node and value names are compatible with ModuleGrappleNode //deprecated config conversion var vinfo = node.GetNode("THISVESSEL") ?? node.GetNode("DOCKEDVESSEL"); if (vinfo != null) { this_vessel = new DockedVesselInfo(); this_vessel.Load(vinfo); } //deprecated config conversion vinfo = node.GetNode("DOCKEDVESSEL_Other") ?? node.GetNode("DOCKEDVESSEL"); if (vinfo != null) { docked_vessel = new DockedVesselInfo(); docked_vessel.Load(vinfo); } if (node.HasValue("dockUId")) { dockedPartUId = uint.Parse(node.GetValue("dockUId")); } GrappleRangeSqr = GrappleRange * GrappleRange; DockRangeSqr = DockRange * DockRange; //load grapple attach node if (HighLogic.LoadedSceneIsFlight) { grappleNode = new AttachNode(); grappleNode.size = 1; grappleNode.id = "grapple"; grappleNode.rigid = true; grappleNode.ResourceXFeed = true; grappleNode.attachMethod = AttachNodeMethod.FIXED_JOINT; grappleNode.breakingForce = grappleNode.breakingTorque = float.PositiveInfinity; } if (node.HasValue("grapplePos")) { grapplePos = KSPUtil.ParseVector3(node.GetValue("grapplePos")); } if (node.HasValue("grappleOrt")) { grappleOrt = KSPUtil.ParseVector3(node.GetValue("grappleOrt")); } if (node.HasValue("grappleOrt2")) { grappleOrt2 = KSPUtil.ParseVector3(node.GetValue("grappleOrt2")); } //deprecated config conversion if (node.HasValue("Fixed")) { if (bool.Parse(node.GetValue("Fixed"))) { state = State.Fixed; } else if (dockedPartUId > 0) { state = State.Docked; } else { armAnimator = part.GetAnimator <MultiAnimator>(ArmAnimatorID); if (armAnimator != null && armAnimator.State == AnimatorState.Opened) { state = State.Armed; } else { state = State.Idle; } } } }
public override void OnLoad(ConfigNode node) { flagname = node.GetValue ("flagname"); if (node.HasValue ("baseMass")) { float.TryParse (node.GetValue ("baseMass"), out base_mass); } else { base_mass = part.mass; } craftConfig = node.GetNode ("CraftConfig"); if (node.HasNode ("BuildCost")) { var bc = node.GetNode ("BuildCost"); buildCost = new BuildCost.CostReport (); buildCost.Load (bc); } if (node.HasNode ("BuiltStuff")) { var bs = node.GetNode ("BuiltStuff"); builtStuff = new BuildCost.CostReport (); builtStuff.Load (bs); } if (node.HasValue ("state")) { var s = node.GetValue ("state"); state = (State) Enum.Parse (typeof (State), s); } if (node.HasValue ("paused")) { var s = node.GetValue ("paused"); bool p = false; bool.TryParse (s, out p); paused = p; } if (node.HasNode ("DockedVesselInfo")) { ConfigNode vi = node.GetNode ("DockedVesselInfo"); vesselInfo = new DockedVesselInfo (); vesselInfo.Load (vi); } }
internal ModDockedVessel(DockedVesselInfo vesselInfo) { VesselInfo = vesselInfo; _vesselParts = SMAddon.SmVessel.GetDockedVesselParts(VesselInfo); }
private void ProcessUnDock(bool undockByUnlink = false) { if (HighLogic.LoadedSceneIsEditor || (!this.IsLinked && !undockByUnlink) || !this.IsConnectionOrigin || this.IsTargetOnly || (this.IsOwnVesselConnected && !this.IsDocked) || (this.IsFreeAttached ? this.FreeAttachPart == null : this.Target == null) || !this.IsDocked) { OSD.PostMessage("Can't undock"); return; } var vi = new DockedVesselInfo { name = this.DockingVesselName, rootPartUId = this.DockingVesselId, vesselType = (VesselType) Enum.Parse(typeof(VesselType), this.DockingVesselTypeString) }; this.IsDocked = false; if (this.IsFreeAttached) { this.FreeAttachPart.Undock(vi); } else { this.Target.part.Undock(vi); } this.UpdateGui(); OSD.PostMessage("Undocked"); }
private void CoupleWithCraft() { Part craftRoot = m_Vessel.rootPart; vesselInfo = new DockedVesselInfo(); vesselInfo.name = m_Vessel.vesselName; vesselInfo.vesselType = m_Vessel.vesselType; vesselInfo.rootPartUId = craftRoot.flightID; craftRoot.Couple(m_ConstructionPort.part); if (m_ConstructionPort.vessel != FlightGlobals.ActiveVessel) { FlightGlobals.ForceSetActiveVessel(m_ConstructionPort.vessel); } }
private static IEnumerator PlaceNewPart(RaycastResult raycast) { var activeVessel = FlightGlobals.ActiveVessel; NewSpawnedPart.transform.position = raycast.Hit.point; NewSpawnedPart.rigidbody.velocity = raycast.HittedPart.rigidbody.velocity; NewSpawnedPart.rigidbody.angularVelocity = raycast.HittedPart.rigidbody.angularVelocity; yield return(new WaitForSeconds(0.1f)); NewSpawnedPart.transform.rotation = raycast.HittedPart.transform.rotation; NewSpawnedPart.transform.position = raycast.Hit.point; NewSpawnedPart.transform.LookAt(Mode == AddonMode.AttachKerbalHook ? CurrentKerbalTargeter.transform.position : CurrentTargeter.transform.position); NewSpawnedPart.transform.rotation = Quaternion.FromToRotation(NewSpawnedPart.transform.up, raycast.Hit.normal) * NewSpawnedPart.transform.rotation; yield return(new WaitForFixedUpdate()); var targetModuleName = Config.Instance.ModuleActiveStrutFreeAttachTarget; if (!NewSpawnedPart.Modules.Contains(targetModuleName)) { Debug.Log("[IRAS][ERR] spawned part contains no target module. Panic!!"); NewSpawnedPart.decouple(); Destroy(NewSpawnedPart); } var module = NewSpawnedPart.Modules[Config.Instance.ModuleActiveStrutFreeAttachTarget]; if (raycast.HittedPart.vessel != activeVessel) { if (module != null) { var targetModule = module as ModuleActiveStrutFreeAttachTarget; if (targetModule != null) { var dockingVesselName = activeVessel.GetName(); var dockingVesselType = activeVessel.vesselType; var dockingVesselId = activeVessel.rootPart.flightID; var vesselInfo = new DockedVesselInfo { name = dockingVesselName, vesselType = dockingVesselType, rootPartUId = dockingVesselId }; targetModule.part.Couple(activeVessel.rootPart); targetModule.part.Undock(vesselInfo); } } } NewSpawnedPart.transform.position = raycast.Hit.point; if (module != null) { var targetModule = module as ModuleActiveStrutFreeAttachTarget; if (targetModule != null) { targetModule.CreateJointToParent(raycast.HittedPart); } } yield return(new WaitForFixedUpdate()); yield return(new WaitForSeconds(0.1f)); yield return(new WaitForFixedUpdate()); if (Mode == AddonMode.AttachKerbalHook) { CurrentKerbalTargeter.PlaceHook(NewSpawnedPart); } else { CurrentTargeter.PlaceFreeAttach(NewSpawnedPart); } partPlacementInProgress = false; NewSpawnedPart = null; }
public void DockToPart(Part other) { this.Log("Docking to vessel: {}", other.vessel.vesselName); var old_vessel = vessel; contacts.Clear(); dockedPartUId = other.flightID; // save this vessel info this_vessel = new DockedVesselInfo(); this_vessel.name = vessel.vesselName; this_vessel.vesselType = vessel.vesselType; this_vessel.rootPartUId = vessel.rootPart.flightID; // save other vessel info docked_vessel = new DockedVesselInfo(); docked_vessel.name = other.vessel.vesselName; docked_vessel.vesselType = other.vessel.vesselType; docked_vessel.rootPartUId = other.vessel.rootPart.flightID; // reset vessels' position and rotation vessel.SetPosition(vessel.transform.position, true); vessel.SetRotation(vessel.transform.rotation); other.vessel.SetPosition(other.vessel.transform.position, true); other.vessel.SetRotation(other.vessel.transform.rotation); vessel.IgnoreGForces(10); other.vessel.IgnoreGForces(10); grapplePos = Vector3.zero; setup_grapple_node(other, part); PartJoint joint; if (Vessel.GetDominantVessel(vessel, other.vessel) == vessel) { other.Couple(part); joint = other.attachJoint; } else { part.Couple(other); joint = part.attachJoint; } joint.SetUnbreakable(true, true); // add fuel lookups part.fuelLookupTargets.Add(other); other.fuelLookupTargets.Add(part); GameEvents.onPartFuelLookupStateChange.Fire(new GameEvents.HostedFromToAction <bool, Part>(true, other, part)); // switch vessel if needed if (old_vessel == FlightGlobals.ActiveVessel) { FlightGlobals.ForceSetActiveVessel(vessel); FlightInputHandler.SetNeutralControls(); } else if (vessel == FlightGlobals.ActiveVessel) { vessel.MakeActive(); FlightInputHandler.SetNeutralControls(); } // untarget docked vessels if (FlightGlobals.fetch.VesselTarget != null) { if (FlightGlobals.fetch.VesselTarget.GetVessel() == other.vessel) { FlightGlobals.fetch.SetVesselTarget(null, false); } } if (vessel.targetObject != null) { if (vessel.targetObject.GetVessel() == other.vessel) { vessel.targetObject = null; } } if (other.vessel.targetObject != null) { if (other.vessel.targetObject.GetVessel() == part.vessel) { other.vessel.targetObject = null; } } // update state and part menu state = State.Docked; update_part_menu(); GameEvents.onVesselWasModified.Fire(vessel); }
public void ReleaseVessel() { if (craftRoot != null) { craftRoot.Undock (vesselInfo); var vesselCount = FlightGlobals.Vessels.Count; Vessel vsl = FlightGlobals.Vessels[vesselCount - 1]; FlightGlobals.ForceSetActiveVessel (vsl); } craftConfig = null; vesselInfo = null; buildCost = null; builtStuff = null; state = State.Idle; }
/// <summary> /// Builds the first element in the queue /// </summary> /// <param name="vessel">The vessel that you want to crawl for elements</param> /// <param name="elements">The final element list, is it included here to have the root element added</param> /// <param name="shared">the ever present shared object</param> /// <returns>a queue with a starting entry</returns> private static Queue<ElementPair> InitQueue(Vessel vessel, Dictionary<uint, ElementValue> elements, SharedObjects shared) { var toReturn = new Queue<ElementPair>(); var rootUid = vessel.rootPart.flightID; var rootInfo = new DockedVesselInfo { name = vessel.vesselName, rootPartUId = rootUid, vesselType = vessel.vesselType }; var rootElement = new ElementValue(rootInfo, shared); elements.Add(rootUid, rootElement); toReturn.Enqueue(new ElementPair(rootElement, vessel.rootPart)); return toReturn; }
public void AttachDocked(KASModuleAttachCore otherAttachModule) { // Save vessel Info this.vesselInfo = new DockedVesselInfo(); this.vesselInfo.name = this.vessel.vesselName; this.vesselInfo.vesselType = this.vessel.vesselType; this.vesselInfo.rootPartUId = this.vessel.rootPart.flightID; this.dockedAttachModule = otherAttachModule; otherAttachModule.vesselInfo = new DockedVesselInfo(); otherAttachModule.vesselInfo.name = otherAttachModule.vessel.vesselName; otherAttachModule.vesselInfo.vesselType = otherAttachModule.vessel.vesselType; otherAttachModule.vesselInfo.rootPartUId = otherAttachModule.vessel.rootPart.flightID; otherAttachModule.dockedAttachModule = this; // Set reference attachMode.Docked = true; // Stop if already docked if (otherAttachModule.part.parent == this.part || this.part.parent == otherAttachModule.part) { KAS_Shared.DebugWarning("DockTo(Core) Parts already docked, nothing more to do"); return; } // Reset vessels position and rotation for returning all parts to their original position and rotation before coupling this.vessel.SetPosition(this.vessel.transform.position, true); this.vessel.SetRotation(this.vessel.transform.rotation); otherAttachModule.vessel.SetPosition(otherAttachModule.vessel.transform.position, true); otherAttachModule.vessel.SetRotation(otherAttachModule.vessel.transform.rotation); // Couple depending of mass Vessel dominantVessel = GetDominantVessel(this.vessel, otherAttachModule.vessel); KAS_Shared.DebugLog("DockTo(Core) Master vessel is " + dominantVessel.vesselName); if (dominantVessel == this.vessel) { KAS_Shared.DebugLog("DockTo(Core) Docking " + otherAttachModule.part.partInfo.title + " from " + otherAttachModule.vessel.vesselName + " with " + this.part.partInfo.title + " from " + this.vessel.vesselName); if (FlightGlobals.ActiveVessel == otherAttachModule.part.vessel) { KAS_Shared.DebugLog("DockTo(Core) Switching focus to " + this.part.vessel.vesselName); FlightGlobals.ForceSetActiveVessel(this.part.vessel); } otherAttachModule.part.Couple(this.part); } else { KAS_Shared.DebugLog("DockTo(Core) Docking " + this.part.partInfo.title + " from " + this.vessel.vesselName + " with " + otherAttachModule.part.partInfo.title + " from " + otherAttachModule.vessel.vesselName); if (FlightGlobals.ActiveVessel == this.part.vessel) { KAS_Shared.DebugLog("DockTo(Core) Switching focus to " + otherAttachModule.part.vessel.vesselName); FlightGlobals.ForceSetActiveVessel(otherAttachModule.part.vessel); } this.part.Couple(otherAttachModule.part); } this.vessel.ctrlState = new FlightCtrlState(); FlightInputHandler.SetNeutralControls(); GameEvents.onVesselWasModified.Fire(this.part.vessel); }
public void Load (ConfigNode node) { filename = node.GetValue ("filename"); flagname = node.GetValue ("flagname"); craftConfig = node.GetNode ("CraftConfig"); if (node.HasNode ("BuildCost")) { var bc = node.GetNode ("BuildCost"); buildCost = new CostReport (); buildCost.Load (bc); } if (node.HasNode ("BuiltStuff")) { var bs = node.GetNode ("BuiltStuff"); builtStuff = new CostReport (); builtStuff.Load (bs); } if (node.HasValue ("state")) { var s = node.GetValue ("state"); state = (State) Enum.Parse (typeof (State), s); if (state == State.Dewarping) { // The game got saved while the Dewarping state was still // active. Rather than restarting the dewarp coroutine, // Just jump straight to the Complete state. state = State.Complete; } } if (node.HasValue ("paused")) { var s = node.GetValue ("paused"); bool p = false; bool.TryParse (s, out p); paused = p; } KACalarmID = node.GetValue ("KACalarmID"); if (node.HasNode ("DockedVesselInfo")) { ConfigNode vi = node.GetNode ("DockedVesselInfo"); vesselInfo = new DockedVesselInfo (); vesselInfo.Load (vi); } }
public extern void Undock(DockedVesselInfo newVesselInfo);
// https://github.com/taniwha-qf/Extraplanetary-Launchpads/blob/master/Source/BuildControl.cs private void CoupleWithCraft(Vessel otherVessel) { Part otherVesselRootPart; DockedVesselInfo otherDockedVessel = new DockedVesselInfo(); otherDockedVessel.name = otherVessel.vesselName; otherDockedVessel.vesselType = otherVessel.vesselType; otherDockedVessel.rootPartUId = otherVessel.rootPart.flightID; //otherVesselRootPart = otherVessel.rootPart; otherVessel.rootPart.Couple(this.part); otherDockedVesselRootPartUid = otherVessel.rootPart.flightID; //if (builder.vessel != FlightGlobals.ActiveVessel) //{ // FlightGlobals.ForceSetActiveVessel(builder.vessel); //} }
private static void PostfixUndock(Part __instance, DockedVesselInfo newVesselInfo, ref Vessel __state) { PartEvent.onPartUndocked.Fire(__instance, newVesselInfo, __state); }
internal ModDockedVessel(DockedVesselInfo vesselInfo) { this.VesselInfo = vesselInfo; _vesselParts = SMAddon.smController.GetDockedVesselParts(_vesselInfo); }
/// <inheritdoc/> public Part DecoupleParts(Part part1, Part part2, DockedVesselInfo vesselInfo1 = null, DockedVesselInfo vesselInfo2 = null) { Part partToDecouple; DockedVesselInfo vesselInfo; if (part1.parent == part2) { DebugEx.Fine("Decouple {0} from {1}", part1, part2); partToDecouple = part1; vesselInfo = vesselInfo1; } else if (part2.parent == part1) { DebugEx.Fine("Decouple {0} from {1}", part2, part1); partToDecouple = part2; vesselInfo = vesselInfo2; } else { DebugEx.Warning("Cannot decouple {0} <=> {1} - not coupled!", part1, part2); return(null); } if (vesselInfo != null) { // Simulate the IActivateOnDecouple behaviour since Undock() doesn't do it. var srcAttachNode = partToDecouple.FindAttachNodeByPart(partToDecouple.parent); if (srcAttachNode != null) { srcAttachNode.attachedPart = null; partToDecouple.FindModulesImplementing <IActivateOnDecouple>() .ForEach(m => m.DecoupleAction(srcAttachNode.id, true)); } if (partToDecouple.parent != null) { var tgtAttachNode = partToDecouple.parent.FindAttachNodeByPart(partToDecouple); if (tgtAttachNode != null) { tgtAttachNode.attachedPart = null; partToDecouple.parent.FindModulesImplementing <IActivateOnDecouple>() .ForEach(m => m.DecoupleAction(tgtAttachNode.id, false)); } } // Decouple and restore the name and hierarchy on the decoupled assembly. var vesselInfoCfg = new ConfigNode(); vesselInfo.Save(vesselInfoCfg); DebugEx.Fine("Restore vessel info:\n{0}", vesselInfoCfg); partToDecouple.Undock(vesselInfo); } else { // Do simple decouple event which will screw the decoupled vessel root part. DebugEx.Warning("No vessel info found! Just decoupling"); partToDecouple.decouple(); } part1.vessel.CycleAllAutoStrut(); part2.vessel.CycleAllAutoStrut(); return(partToDecouple); }
public void ReleaseVessel() { TransferResources (); if (craftRoot != null) { craftRoot.Undock (vesselInfo); var vesselCount = FlightGlobals.Vessels.Count; Vessel vsl = FlightGlobals.Vessels[vesselCount - 1]; FlightGlobals.ForceSetActiveVessel (vsl); builder.part.StartCoroutine (FixAirstreamShielding (vsl)); } craftConfig = null; vesselInfo = null; buildCost = null; builtStuff = null; state = State.Idle; }