示例#1
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (state == StartState.Editor || state == StartState.None)
            {
                return;
            }

            if (attachMode.Docked)
            {
                Part dockedPart = KAS_Shared.GetPartByID(this.vessel.id.ToString(), dockedPartID);
                if (dockedPart)
                {
                    KASModuleAttachCore dockedAttachModuleTmp = dockedPart.GetComponent <KASModuleAttachCore>();
                    if (dockedAttachModuleTmp)
                    {
                        KAS_Shared.DebugLog("OnLoad(Core) Re-set docking on " + dockedAttachModuleTmp.part.partInfo.title);
                        AttachDocked(dockedAttachModuleTmp);
                    }
                    else
                    {
                        KAS_Shared.DebugError("OnLoad(Core) Unable to get docked module !");
                        attachMode.Docked = false;
                    }
                }
                else
                {
                    KAS_Shared.DebugError("OnLoad(Core) Unable to get saved docked part !");
                    attachMode.Docked = false;
                }
            }

            if (attachMode.Coupled)
            {
                // Todo
            }

            if (attachMode.FixedJoint)
            {
                Part attachedPart = KAS_Shared.GetPartByID(FixedAttach.savedVesselID, FixedAttach.savedPartID);
                if (attachedPart)
                {
                    KAS_Shared.DebugLog("OnLoad(Core) Re-set fixed joint on " + attachedPart.partInfo.title);
                    AttachFixed(attachedPart, FixedAttach.savedBreakForce);
                }
                else
                {
                    KAS_Shared.DebugError("OnLoad(Core) Unable to get saved connected part of the fixed joint !");
                    attachMode.FixedJoint = false;
                }
            }
            if (attachMode.StaticJoint)
            {
                // Nothing to do (see OnVesselLoaded)
            }
            GameEvents.onVesselGoOffRails.Add(new EventData <Vessel> .OnEvent(this.OnVesselGoOffRails));
        }
示例#2
0
        public void Detach(AttachType attachType)
        {
            KAS_Shared.DebugLog("Detach(Base) Attach type is : " + attachMode);

            // Docked
            if (attachType == AttachType.Docked)
            {
                if (dockedAttachModule.part.parent == this.part)
                {
                    KAS_Shared.DebugLog("Detach(Base) Undocking " + dockedAttachModule.part.partInfo.title + " from " + dockedAttachModule.vessel.vesselName);
                    dockedAttachModule.part.Undock(dockedAttachModule.vesselInfo);
                }
                if (this.part.parent == dockedAttachModule.part)
                {
                    KAS_Shared.DebugLog("Detach(Base) Undocking " + this.part.partInfo.title + " from " + this.vessel.vesselName);
                    this.part.Undock(this.vesselInfo);
                }
                dockedAttachModule.dockedAttachModule = null;
                this.dockedAttachModule = null;
                attachMode.Docked       = false;
            }
            // Coupled
            if (attachType == AttachType.Coupled)
            {
                // Todo
                attachMode.Coupled = false;
            }
            // FixedJoint
            if (attachType == AttachType.FixedJoint)
            {
                KAS_Shared.DebugLog("Detach(Base) Removing fixed joint on " + this.part.partInfo.title);
                if (FixedAttach.fixedJoint)
                {
                    Destroy(FixedAttach.fixedJoint);
                }
                FixedAttach.fixedJoint    = null;
                FixedAttach.connectedPart = null;
                attachMode.FixedJoint     = false;
            }
            // StaticJoint
            if (attachType == AttachType.StaticJoint)
            {
                KAS_Shared.DebugLog("Detach(Base) Removing static rigidbody and fixed joint on " + this.part.partInfo.title);
                if (StaticAttach.fixedJoint)
                {
                    Destroy(StaticAttach.fixedJoint);
                }
                if (StaticAttach.connectedGameObject)
                {
                    Destroy(StaticAttach.connectedGameObject);
                }
                StaticAttach.fixedJoint          = null;
                StaticAttach.connectedGameObject = null;
                attachMode.StaticJoint           = false;
            }
        }
示例#3
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (state == StartState.Editor || state == StartState.None)
            {
                return;
            }

            if (attachMode.Docked)
            {
                Part dockedPart = KAS_Shared.GetPartByID(this.vessel, dockedPartID);
                if (dockedPart && (dockedPart == part.parent || dockedPart.parent == part))
                {
                    KASModuleAttachCore dockedAttachModuleTmp = dockedPart.GetComponent <KASModuleAttachCore>();
                    if (dockedAttachModuleTmp == null)
                    {
                        KAS_Shared.DebugError("OnLoad(Core) Unable to get docked module !");
                        attachMode.Docked = false;
                    }
                    else if (dockedAttachModuleTmp.attachMode.Docked &&
                             dockedAttachModuleTmp.dockedPartID == part.flightID.ToString() &&
                             dockedAttachModuleTmp.vesselInfo != null)
                    {
                        KAS_Shared.DebugLog("OnLoad(Core) Part already docked to " + dockedAttachModuleTmp.part.partInfo.title);
                        this.dockedAttachModule = dockedAttachModuleTmp;
                        dockedAttachModuleTmp.dockedAttachModule = this;
                    }
                    else
                    {
                        KAS_Shared.DebugLog("OnLoad(Core) Re-set docking on " + dockedAttachModuleTmp.part.partInfo.title);
                        AttachDocked(dockedAttachModuleTmp);
                    }
                }
                else
                {
                    KAS_Shared.DebugError("OnLoad(Core) Unable to get saved docked part !");
                    attachMode.Docked = false;
                }
            }

            if (attachMode.Coupled)
            {
                // Todo
            }

            if (attachMode.FixedJoint)
            {
                StartCoroutine(WaitAndInitFixedAttach());
            }
            if (attachMode.StaticJoint)
            {
                // Nothing to do (see OnVesselLoaded)
            }
        }
示例#4
0
        protected virtual void OnPartDie()
        {
            if (attachMode.Docked)
            {
                if (dockedAttachModule && dockedAttachModule.dockedAttachModule == this)
                {
                    dockedAttachModule.attachMode.Docked  = false;
                    dockedAttachModule.dockedAttachModule = null;
                }

                attachMode.Docked  = false;
                dockedAttachModule = null;
            }
        }
        protected virtual void OnPartDie()
        {
            if (attachMode.Docked) {
              if (dockedAttachModule && dockedAttachModule.dockedAttachModule == this) {
            dockedAttachModule.attachMode.Docked = false;
            dockedAttachModule.dockedAttachModule = null;
              }

              attachMode.Docked = false;
              dockedAttachModule = null;
            }
        }
        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);
        }
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (state == StartState.Editor || state == StartState.None) {
              return;
            }

            if (attachMode.Docked) {
              Part dockedPart = KAS_Shared.GetPartByID(this.vessel, dockedPartID);
              if (dockedPart && (dockedPart == part.parent || dockedPart.parent == part)) {
            KASModuleAttachCore dockedAttachModuleTmp = dockedPart.GetComponent<KASModuleAttachCore>();
            if (dockedAttachModuleTmp == null) {
              KAS_Shared.DebugError("OnLoad(Core) Unable to get docked module!");
              attachMode.Docked = false;
            } else if (dockedAttachModuleTmp.attachMode.Docked
                   && dockedAttachModuleTmp.dockedPartID == part.flightID.ToString()
                   && dockedAttachModuleTmp.vesselInfo != null) {
              KAS_Shared.DebugLog(string.Format("OnLoad(Core) Part already docked to {0}",
                                            dockedAttachModuleTmp.part.partInfo.title));
              this.dockedAttachModule = dockedAttachModuleTmp;
              dockedAttachModuleTmp.dockedAttachModule = this;
            } else {
              KAS_Shared.DebugLog(string.Format(
              "OnLoad(Core) Re-set docking on {0}", dockedAttachModuleTmp.part.partInfo.title));
              AttachDocked(dockedAttachModuleTmp);
            }
              } else {
            KAS_Shared.DebugError("OnLoad(Core) Unable to get saved docked part!");
            attachMode.Docked = false;
              }
            }

            // TODO: attachMode.Coupled

            if (attachMode.FixedJoint) {
              StartCoroutine(WaitAndInitFixedAttach());
            }
            // Nothing to do on attachMode.StaticJoint (see OnVesselLoaded)
        }
        public void Detach(AttachType attachType)
        {
            KAS_Shared.DebugLog(string.Format(
            "Detach(Base) Attach mode is Docked:{0},Coupled:{1},FixedJoint:{2},StaticJoint:{3}",
            attachMode.Docked, attachMode.Coupled, attachMode.FixedJoint, attachMode.StaticJoint));
            KAS_Shared.DebugLog(string.Format("Detach(Base) Attach type is : {0}", attachType));

            // Docked
            if (attachType == AttachType.Docked) {
              if (dockedAttachModule.part.parent == this.part) {
            KAS_Shared.DebugLog(string.Format("Detach(Base) Undocking {0} from {1}",
                                          dockedAttachModule.part.partInfo.title,
                                          dockedAttachModule.vessel.vesselName));
            dockedAttachModule.UndockVessel();
              }
              if (this.part.parent == dockedAttachModule.part) {
            KAS_Shared.DebugLog(string.Format(
            "Detach(Base) Undocking {0} from {1}", part.partInfo.title, vessel.vesselName));
            this.UndockVessel();
              }
              if (dockedAttachModule.dockedAttachModule == this) {
            dockedAttachModule.dockedAttachModule = null;
            dockedAttachModule.dockedPartID = null;
            dockedAttachModule.attachMode.Docked = false;
              }
              dockedAttachModule = null;
              dockedPartID = null;
              attachMode.Docked = false;
            }
            // Coupled
            if (attachType == AttachType.Coupled) {
              // TODO???
              attachMode.Coupled = false;
            }
            // FixedJoint
            if (attachType == AttachType.FixedJoint) {
              KAS_Shared.DebugLog(string.Format(
              "Detach(Base) Removing fixed joint on {0}", FixedAttach.srcPart.partInfo.title));
              if (FixedAttach.fixedJoint) {
            Destroy(FixedAttach.fixedJoint);
              }
              SetCreateJointOnUnpack(false);
              FixedAttach.fixedJoint = null;
              FixedAttach.tgtPart = null;
              attachMode.FixedJoint = false;
            }
            // StaticJoint
            if (attachType == AttachType.StaticJoint) {
              KAS_Shared.DebugLog(string.Format(
              "Detach(Base) Removing static rigidbody and fixed joint on {0}", part.partInfo.title));
              if (StaticAttach.fixedJoint) {
            Destroy(StaticAttach.fixedJoint);
              }
              if (StaticAttach.connectedGameObject) {
            Destroy(StaticAttach.connectedGameObject);
              }
              StaticAttach.fixedJoint = null;
              StaticAttach.connectedGameObject = null;
              attachMode.StaticJoint = false;
            }
        }
示例#9
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (state == StartState.Editor || state == StartState.None) return;

            if (attachMode.Docked)
            {
                Part dockedPart = KAS_Shared.GetPartByID(this.vessel.id.ToString(), dockedPartID);
                if (dockedPart && (dockedPart == part.parent || dockedPart.parent == part))
                {
                    KASModuleAttachCore dockedAttachModuleTmp = dockedPart.GetComponent<KASModuleAttachCore>();
                    if (dockedAttachModuleTmp == null)
                    {
                        KAS_Shared.DebugError("OnLoad(Core) Unable to get docked module !");
                        attachMode.Docked = false;
                    }
                    else if (dockedAttachModuleTmp.attachMode.Docked &&
                             dockedAttachModuleTmp.dockedPartID == part.flightID.ToString() &&
                             dockedAttachModuleTmp.vesselInfo != null)
                    {
                        KAS_Shared.DebugLog("OnLoad(Core) Part already docked to " + dockedAttachModuleTmp.part.partInfo.title);
                        this.dockedAttachModule = dockedAttachModuleTmp;
                        dockedAttachModuleTmp.dockedAttachModule = this;
                    }
                    else
                    {
                        KAS_Shared.DebugLog("OnLoad(Core) Re-set docking on " + dockedAttachModuleTmp.part.partInfo.title);
                        AttachDocked(dockedAttachModuleTmp);
                    }
                }
                else
                {
                    KAS_Shared.DebugError("OnLoad(Core) Unable to get saved docked part !");
                    attachMode.Docked = false;
                }
            }

            if (attachMode.Coupled)
            {
                // Todo
            }

            if (attachMode.FixedJoint)
            {

                Part attachedPart = KAS_Shared.GetPartByID(FixedAttach.savedVesselID, FixedAttach.savedPartID);
                if (attachedPart)
                {
                    KAS_Shared.DebugLog("OnLoad(Core) Re-set fixed joint on " + attachedPart.partInfo.title);
                    AttachFixed(attachedPart, FixedAttach.savedBreakForce);
                }
                else
                {
                    KAS_Shared.DebugError("OnLoad(Core) Unable to get saved connected part of the fixed joint !");
                    attachMode.FixedJoint = false;
                }
            }
            if (attachMode.StaticJoint)
            {
                // Nothing to do (see OnVesselLoaded)
            }
        }
示例#10
0
        public void Detach(AttachType attachType)
        {
            KAS_Shared.DebugLog("Detach(Base) Attach type is : " + attachMode);

            // Docked
            if (attachType == AttachType.Docked)
            {
                if (dockedAttachModule.part.parent == this.part)
                {
                    KAS_Shared.DebugLog("Detach(Base) Undocking " + dockedAttachModule.part.partInfo.title + " from " + dockedAttachModule.vessel.vesselName);
                    dockedAttachModule.part.Undock(dockedAttachModule.vesselInfo);
                }
                if (this.part.parent == dockedAttachModule.part)
                {
                    KAS_Shared.DebugLog("Detach(Base) Undocking " + this.part.partInfo.title + " from " + this.vessel.vesselName);
                    this.part.Undock(this.vesselInfo);
                }
                if (dockedAttachModule.dockedAttachModule == this)
                {
                    dockedAttachModule.dockedAttachModule = null;
                    dockedAttachModule.dockedPartID = null;
                    dockedAttachModule.attachMode.Docked = false;
                }
                this.dockedAttachModule = null;
                this.dockedPartID = null;
                attachMode.Docked = false;
            }
            // Coupled
            if (attachType == AttachType.Coupled)
            {
                // Todo
                attachMode.Coupled = false;
            }
            // FixedJoint
            if (attachType == AttachType.FixedJoint)
            {
                KAS_Shared.DebugLog("Detach(Base) Removing fixed joint on " + this.part.partInfo.title);
                if (FixedAttach.fixedJoint) Destroy(FixedAttach.fixedJoint);
                SetCreateJointOnUnpack(false);
                FixedAttach.fixedJoint = null;
                FixedAttach.connectedPart = null;
                attachMode.FixedJoint = false;
            }
            // StaticJoint
            if (attachType == AttachType.StaticJoint)
            {
                KAS_Shared.DebugLog("Detach(Base) Removing static rigidbody and fixed joint on " + this.part.partInfo.title);
                if (StaticAttach.fixedJoint) Destroy(StaticAttach.fixedJoint);
                if (StaticAttach.connectedGameObject) Destroy(StaticAttach.connectedGameObject);
                StaticAttach.fixedJoint = null;
                StaticAttach.connectedGameObject = null;
                attachMode.StaticJoint = false;
            }
        }
示例#11
0
        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);
        }
示例#12
0
        public void Detach(AttachType attachType)
        {
            KAS_Shared.DebugLog(string.Format(
                                    "Detach(Base) Attach mode is Docked:{0},Coupled:{1},FixedJoint:{2},StaticJoint:{3}",
                                    attachMode.Docked, attachMode.Coupled, attachMode.FixedJoint, attachMode.StaticJoint));
            KAS_Shared.DebugLog(string.Format("Detach(Base) Attach type is : {0}", attachType));

            // Docked
            if (attachType == AttachType.Docked)
            {
                if (dockedAttachModule.part.parent == this.part)
                {
                    KAS_Shared.DebugLog(string.Format("Detach(Base) Undocking {0} from {1}",
                                                      dockedAttachModule.part.partInfo.title,
                                                      dockedAttachModule.vessel.vesselName));
                    dockedAttachModule.UndockVessel();
                }
                if (this.part.parent == dockedAttachModule.part)
                {
                    KAS_Shared.DebugLog(string.Format(
                                            "Detach(Base) Undocking {0} from {1}", part.partInfo.title, vessel.vesselName));
                    this.UndockVessel();
                }
                if (dockedAttachModule.dockedAttachModule == this)
                {
                    dockedAttachModule.dockedAttachModule = null;
                    dockedAttachModule.dockedPartID       = null;
                    dockedAttachModule.attachMode.Docked  = false;
                }
                dockedAttachModule = null;
                dockedPartID       = null;
                attachMode.Docked  = false;
            }
            // Coupled
            if (attachType == AttachType.Coupled)
            {
                // TODO???
                attachMode.Coupled = false;
            }
            // FixedJoint
            if (attachType == AttachType.FixedJoint)
            {
                KAS_Shared.DebugLog(string.Format(
                                        "Detach(Base) Removing fixed joint on {0}", FixedAttach.srcPart.partInfo.title));
                if (FixedAttach.fixedJoint)
                {
                    Destroy(FixedAttach.fixedJoint);
                }
                SetCreateJointOnUnpack(false);
                FixedAttach.fixedJoint = null;
                FixedAttach.tgtPart    = null;
                attachMode.FixedJoint  = false;
            }
            // StaticJoint
            if (attachType == AttachType.StaticJoint)
            {
                KAS_Shared.DebugLog(string.Format(
                                        "Detach(Base) Removing static rigidbody and fixed joint on {0}", part.partInfo.title));
                if (StaticAttach.fixedJoint)
                {
                    Destroy(StaticAttach.fixedJoint);
                }
                if (StaticAttach.connectedGameObject)
                {
                    Destroy(StaticAttach.connectedGameObject);
                }
                StaticAttach.fixedJoint          = null;
                StaticAttach.connectedGameObject = null;
                attachMode.StaticJoint           = false;
            }
        }
示例#13
0
        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);
        }
示例#14
0
        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);
        }
示例#15
0
        public void Detach(AttachType attachType)
        {
            KAS_Shared.DebugLog("Detach(Base) Attach mode is Docked:" + attachMode.Docked
                                + ",Coupled:" + attachMode.Coupled
                                + ",FixedJoint:" + attachMode.FixedJoint
                                + ",StaticJoint:" + attachMode.StaticJoint);
            KAS_Shared.DebugLog("Detach(Base) Attach type is : " + attachType);

            // Docked
            if (attachType == AttachType.Docked)
            {
                if (dockedAttachModule.part.parent == this.part)
                {
                    KAS_Shared.DebugLog("Detach(Base) Undocking " + dockedAttachModule.part.partInfo.title
                                        + " from " + dockedAttachModule.vessel.vesselName);
                    dockedAttachModule.UndockVessel();
                }
                if (this.part.parent == dockedAttachModule.part)
                {
                    KAS_Shared.DebugLog("Detach(Base) Undocking " + this.part.partInfo.title
                                        + " from " + this.vessel.vesselName);
                    this.UndockVessel();
                }
                if (dockedAttachModule.dockedAttachModule == this)
                {
                    dockedAttachModule.dockedAttachModule = null;
                    dockedAttachModule.dockedPartID       = null;
                    dockedAttachModule.attachMode.Docked  = false;
                }
                this.dockedAttachModule = null;
                this.dockedPartID       = null;
                attachMode.Docked       = false;
            }
            // Coupled
            if (attachType == AttachType.Coupled)
            {
                // Todo
                attachMode.Coupled = false;
            }
            // FixedJoint
            if (attachType == AttachType.FixedJoint)
            {
                KAS_Shared.DebugLog("Detach(Base) Removing fixed joint on "
                                    + FixedAttach.srcPart.partInfo.title);
                if (FixedAttach.fixedJoint)
                {
                    Destroy(FixedAttach.fixedJoint);
                }
                SetCreateJointOnUnpack(false);
                FixedAttach.fixedJoint = null;
                FixedAttach.tgtPart    = null;
                attachMode.FixedJoint  = false;
            }
            // StaticJoint
            if (attachType == AttachType.StaticJoint)
            {
                KAS_Shared.DebugLog("Detach(Base) Removing static rigidbody and fixed joint on "
                                    + this.part.partInfo.title);
                if (StaticAttach.fixedJoint)
                {
                    Destroy(StaticAttach.fixedJoint);
                }
                if (StaticAttach.connectedGameObject)
                {
                    Destroy(StaticAttach.connectedGameObject);
                }
                StaticAttach.fixedJoint          = null;
                StaticAttach.connectedGameObject = null;
                attachMode.StaticJoint           = false;
            }
        }