Esempio n. 1
0
 private void OnPartJointBreak(PartJoint p, float force)
 {
     if (HighLogic.LoadedScene == GameScenes.FLIGHT)
     {
         HandleVessel(p.Parent.vessel);
     }
 }
Esempio n. 2
0
        public void OnPartJointBreak(PartJoint partJoint, float breakForce)
        {
            if (partJoint.Target == null)
            {
                return;
            }
            if (partJoint.Target.PhysicsSignificance == 1)
            {
                return;
            }
            if (breakForce == float.PositiveInfinity || breakForce < 0)
            {
                Debug.Log("DestructionEffects: Not effect due to breaking force negative or infinity");
                return;
            }
            if (!ShouldFlamesBeAttached(partJoint))
            {
                return;
            }
            // if part has module missile turret  part.FindModuleImplementing<ModuleMissileTurret>())
            //  if (GameObject.FindModuleImplementing<ModuleMissileTurret>())
            // {
            //     return;
            //  }

            AttachFlames(partJoint);
        }
Esempio n. 3
0
 public void CheckCatastrophicBreach(PartJoint partJoint, float breakForce)
 {
     if (vessel.situation != Vessel.Situations.SPLASHED)
     {
         return;
     }
 }
Esempio n. 4
0
		void OnPartJointBreak(PartJoint j)
		{
			if(gameObject.activeInHierarchy)
			{
				StartCoroutine(DelayedCleanJammerListRoutine());
			}
		}
Esempio n. 5
0
    public static void DrawJoint(PartJoint joint)
    {
        if (joint == null)
        {
            return;
        }

        if (joint.Host == null || joint.Child == null || joint.Parent == null)
        {
            return;
        }

        Color col = joint.Host == joint.Child ? Color.blue : Color.red;

        if (jointMode == null)
        {
            jointMode = typeof(PartJoint).GetField("mode", BindingFlags.NonPublic | BindingFlags.Instance);
        }

        float node = ((AttachModes)jointMode.GetValue(joint)) == AttachModes.STACK ? 1 : 0.6f;

        GLStart();
        GL.Color(col * node);

        DrawLine(joint.Child.transform.position, joint.Parent.transform.position, col * node);

        GLEnd();
    }
Esempio n. 6
0
        private static void AttachFlames(PartJoint partJoint)
        {
            var modelUrl = DESettings.LegacyEffect ? LegacyFlameModelPath : NewFlameModelPath;

            var flameObject =
                (GameObject)
                Instantiate(
                    GameDatabase.Instance.GetModel(modelUrl),
                    partJoint.transform.position,
                    Quaternion.identity);

            flameObject.SetActive(true);
            flameObject.transform.parent = partJoint.Target.transform;
            flameObject.AddComponent <FlamingJointScript>();

            foreach (var pe in flameObject.GetComponentsInChildren <KSPParticleEmitter>())
            {
                if (!pe.useWorldSpace)
                {
                    continue;
                }

                var gpe = pe.gameObject.AddComponent <DeGaplessParticleEmitter>();
                gpe.Part = partJoint.Target;
                gpe.Emit = true;
            }
        }
Esempio n. 7
0
 public void onPartJointBreak(PartJoint joint)
 {
     using (PooledStringBuilder sb = this.getStringBuilder())
     {
         this.PartJointHelper(sb, joint);
     }
 }
        protected virtual void OnPartJointBreak(PartJoint p, float breakForce)
        {
            if (HighLogic.LoadedScene == GameScenes.EDITOR || p == null || p.Parent == null || p.Parent.vessel == null)
            {
                return;
            }

            LoggingUtil.LogVerbose(this, "OnPartJointBreak(" + p.Parent.vessel.id + ")");

            // Check if we need to make modifications based on undocking
            if (vesselInfo.ContainsKey(p.Parent.vessel.id) && vesselInfo[p.Parent.vessel.id].state == ParameterState.Complete)
            {
                ParamStrength strength = vesselInfo[p.Parent.vessel.id].strength;

                // Medium strengths indicates that we may need to lower to weak if the "strong"
                // part is lost
                if (strength == ParamStrength.MEDIUM)
                {
                    foreach (uint hash in p.Parent.vessel.GetHashes())
                    {
                        strength = !dockedVesselInfo.ContainsKey(hash) ? ParamStrength.WEAK : dockedVesselInfo[hash].Key > strength ? dockedVesselInfo[hash].Key : strength;
                    }

                    vesselInfo[p.Parent.vessel.id].strength = strength == ParamStrength.STRONG ? ParamStrength.MEDIUM : ParamStrength.WEAK;
                }
                else if (strength == ParamStrength.STRONG)
                {
                    // Save the sub vessel info
                    SaveSubVesselInfo(p.Parent.vessel, ParamStrength.STRONG, vesselInfo[p.Parent.vessel.id].completionTime);
                }
            }

            CheckVessel(p.Parent.vessel);
        }
Esempio n. 9
0
        void OnPartJointBreak(PartJoint pj, float value)
        {
            Part host;
            bool flag;

            if (pj.Host != part)
            {
                if (pj.Target == part)
                {
                    host = pj.Host;

                    if (nodeParts.Contains(host))
                    {
                        if (bottomNodePart != null)
                        {
                            RemoveJoints(host, bottomNodePart);
                        }

                        RemoveJoints(host, part);

                        flag = nodeParts.Remove(host);
                    }
                    else if (host == bottomNodePart)
                    {
                        foreach (Part p1 in nodeParts)
                        {
                            RemoveJoints(p1, bottomNodePart);
                        }

                        RemoveJoints(bottomNodePart, part);
                    }

                    return;
                }

                return;
            }

            host = pj.Target;

            if (nodeParts.Contains(host))
            {
                if (bottomNodePart != null)
                {
                    RemoveJoints(host, bottomNodePart);
                }

                RemoveJoints(host, part);

                flag = nodeParts.Remove(host);
            }
            else if (host == bottomNodePart)
            {
                foreach (Part p in nodeParts)
                {
                    RemoveJoints(p, bottomNodePart);
                }
                RemoveJoints(bottomNodePart, part);
            }
        }
Esempio n. 10
0
        public void OnPartJointBreak(PartJoint partJoint, float breakForce)
        {
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                return;
            }
            if (partJoint.Target == null)
            {
                return;
            }
            if (partJoint.Target.PhysicsSignificance == 1)
            {
                return;
            }

            if (vesselsAllowed.Count == 0)
            {
                return;
            }
            if (!vesselsAllowed.Contains(partJoint.Target.vessel))
            {
                return;
            }
            if (!ShouldFlamesBeAttached(partJoint))
            {
                return;
            }
            if (breakForce == 0 && !BDACheck.bdaAvailable)
            {
                return;
            }

            AttachFlames(partJoint);
        }
Esempio n. 11
0
 void OnPartJointBreak(PartJoint j, float breakForce)
 {
     if (gameObject.activeInHierarchy)
     {
         StartCoroutine(DelayedCleanJammerListRoutine());
     }
 }
Esempio n. 12
0
        private static void AttachFlames(PartJoint partJoint, bool attachToHost)
        {
            var modelUrl = DESettings.LegacyEffect ? LegacyFlameModelPath : NewFlameModelPath;

            // adjusted the function with this new varaible that is either the hos or the target part depending on parameters (done to avoid attaching flames to a destroyed part)
            Part flamingpart = partJoint.Target;

            if (attachToHost)
            {
                flamingpart = partJoint.Host;
            }

            var flameObject =
                (GameObject)
                Instantiate(
                    GameDatabase.Instance.GetModel(modelUrl),
                    partJoint.transform.position,
                    Quaternion.identity);

            flameObject.SetActive(true);
            flameObject.transform.parent = flamingpart.transform;
            flameObject.AddComponent <FlamingJointScript>();

            foreach (var pe in flameObject.GetComponentsInChildren <KSPParticleEmitter>())
            {
                if (!pe.useWorldSpace)
                {
                    continue;
                }

                var gpe = pe.gameObject.AddComponent <DeGaplessParticleEmitter>();
                gpe.Part = flamingpart;
                gpe.Emit = true;
            }
        }
Esempio n. 13
0
        public void partJointBreak(PartJoint joint, float breakForce)
        {
            // the lock got broken off of the part it was connected to.
            // Lock part should have two joints - one created during locking and one the lock is attached to some other
            // part. Let's deactivate lock in both cases
            if (Math.Abs(breakForce) < 0.01)
            {
                return;
            }
            printDebug($"broken PART joint; parent={joint.Parent.flightID}; owner={joint.Host.flightID}; our part id={part.flightID}; joint id={joint.GetInstanceID()}; joint={joint}; force={breakForce}");

            lockJoint.DestroyJoint();
            DestroyImmediate(cJoint);
            if (sJoint != null)
            {
                DestroyImmediate(sJoint);
            }

            cJoint           = null;
            sJoint           = null;
            jointJustCreated = false;
            part.attachNodes.Remove(attachNode);
            attachNode.owner = null;
            // Seems like we just got separated from the vessel.
            // Shut down actions taking into account that we might be still
            // connected to other lock part
            printDebug($"broken joint: {joint}, lock joint: {lockJoint}; part joint broken");
            lockFSM.processEvent(LockFSM.Event.Break);
        }
Esempio n. 14
0
 private void CallbackPartJointWasLoaded(PartJoint partjoint)
 {
     Log.Info("CallbackPartJointWasLoaded");
     //this.newScene = true;
     //this.sceneReady = true;
     this.specialScene = true;
     //lastSceneUpdate = Time.realtimeSinceStartup;
 }
Esempio n. 15
0
 public void SetRootJoint(int _id)
 {
     if (_id >= 0 && _id < m_joints.Count)
     {
         //PartJoint tmp = m_rootJoint.connection;
         //Detach();
         rootJointId = _id;
         m_rootJoint = m_joints[_id];
     }
 }
Esempio n. 16
0
        /// <summary>Creates a stock-aloke joint between the unrealted parts.</summary>
        /// <remarks>The physical joints will be controlled by the module.</remarks>
        void CreateCustomJoint()
        {
            HostedDebugLog.Fine(
                this, "Create a stock-alike joint between: {0} <=> {1}", linkSource, linkTarget);
            var stockJoint = PartJoint.Create(linkSource.part, linkTarget.part,
                                              linkSource.coupleNode, linkTarget.coupleNode,
                                              AttachModes.STACK);

            SetCustomJoints(stockJoint.joints.ToArray());
        }
Esempio n. 17
0
        void AddPartJoint(Part p, Part pp, AttachNode pnode, AttachNode ppnode)
        {
            PartJoint partJoint = PartJoint.Create(p, pp, pnode, ppnode, 0);

            partJoint.SetBreakingForces(breakingForce, breakingForce);

            PartJoint partJoint1 = p.gameObject.AddComponent <PartJoint>();

            partJoint1 = partJoint;
        }
Esempio n. 18
0
        void AddPartJoint(Part p, Part pp, AttachNode pnode, AttachNode ppnode)
        {
            PartJoint partJoint = PartJoint.Create(p, pp, pnode, ppnode, 0);

            partJoint.SetBreakingForces(breakingForce, breakingForce);

            // This seems unlikely to be working as intended.
            PartJoint partJoint1 = p.gameObject.AddComponent <PartJoint>();

            partJoint1 = partJoint;
        }
Esempio n. 19
0
        public void OnPartJointBreak(PartJoint partJoint, float breakForce)
        {
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                return;
            }
            if (partJoint.Target == null)
            {
                return;
            }
            if (partJoint.Target.PhysicsSignificance == 1)
            {
                return;
            }

            if (vesselsAllowed.Count == 0)
            {
                return;
            }
            if (!vesselsAllowed.Contains(partJoint.Target.vessel))
            {
                return;
            }
            if (!ShouldFlamesBeAttached(partJoint))
            {
                return;
            }

            if (breakForce == 0)
            {
                // probably the BDa check is not required as I think the fix should work also in other situations
                if (!BDACheck.bdaAvailable)
                {
                    return;
                }

                // this checks if the joint connects a parent and a child (other cases are autostruts that we do not want)
                if (!(deadPartsParents.Contains(new KeyValuePair <uint, uint>(partJoint.Host.flightID, partJoint.Target.flightID)) || deadPartsParents.ContainsKey(partJoint.Target.flightID)))
                {
                    return;
                }
            }

            // added this check because if a part dies that has a still intact child there will be 2 partjoint breaks one where the target that is destroyed and one where the host is destroyed
            // also expanded attach flames with this new parameter (basically we avoid attaching flames to a destroyed object that could lead to exceptions
            bool attachToHost = false;

            if (deadPartsParents.ContainsKey(partJoint.Target.flightID))
            {
                attachToHost = true;
            }

            AttachFlames(partJoint, attachToHost);
        }
Esempio n. 20
0
        protected override void OnPartJointBreak(PartJoint p)
        {
            LoggingUtil.LogVerbose(this, "OnPartJointBreak: " + p);
            base.OnPartJointBreak(p);

            if (HighLogic.LoadedScene == GameScenes.EDITOR || p.Parent.vessel == null)
            {
                return;
            }

            CheckVessel(p.Parent.vessel);
        }
Esempio n. 21
0
        public void CheckCatastrophicBreach(PartJoint partJoint, float breakForce)
        {
            if (vessel.situation != Vessel.Situations.SPLASHED)
            {
                return;
            }

            //if (hull)
            //{
            // ScreenMessages.PostScreenMessage("Catastrophic Hull Damage", 30.0f, ScreenMessageStyle.UPPER_CENTER);
            //}
        }
        protected virtual void OnPartJointBreak(PartJoint p)
        {
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                return;
            }

            if (GetAssociatedKeys(p.Parent.vessel).Any())
            {
                lastBreak = p.Parent.vessel;
            }
        }
Esempio n. 23
0
        private IEnumerator finalizeUnlock(bool broken)
        {
            printDebug("finalize unlock; master: " + isMaster + "; slave: " + isSlave + "; broken: " + broken);
            if (!broken)
            {
                yield return(new WaitForSeconds(unlockSound.audio.clip.length));
            }

            if ((isSlave || isMaster) && otherLock.lockFSM.state != LockFSM.State.Unlocking)
            {
                StartCoroutine(otherLock.finalizeUnlock(true));
            }

            if (lockFSM.state == LockFSM.State.Unlocking)
            {
                // Process Unlocked event before destroying joint
                lockFSM.processEvent(LockFSM.Event.Release);
            }

            if (lockJoint != null)
            {
                printDebug($"destroying lock joint");
                lockJoint.DestroyJoint();
                part.attachNodes.Remove(attachNode);
                DestroyImmediate(cJoint);

                if (attachNode != null)
                {
                    //part.attachNodes.Remove (attachNode);
                    attachNode.owner = null;
                }
                //DestroyImmediate (lockJoint);
                printDebug(String.Format("Done destroying: attachNode={0}, partJoint={1}",
                                         attachNode, lockJoint));
            }

            printDebug($"sJoint: {sJoint}");
            if (sJoint != null)
            {
                DestroyImmediate(sJoint);
            }

            //lockJoint = null;
            attachNode       = null;
            cJoint           = null;
            sJoint           = null;
            lockJoint        = null;
            isMaster         = false;
            isSlave          = false;
            pairLockPartId   = 0;
            jointJustCreated = false;
        }
Esempio n. 24
0
        private void PerformWeld(WeldingData wData, bool compress, bool fixRotation)
        {
            var nodeA = NodeUtilities.GetLinkingNode(wData.LinkedPartA, wData.DockingPortA);
            var nodeB = NodeUtilities.GetLinkingNode(wData.LinkedPartB, wData.DockingPortB);

            var offset   = GetOffset(wData);
            var rotation = GetRotation(wData);

            if (fixRotation)
            {
                wData.LinkedPartB.transform.Rotate(rotation, Space.Self);
            }

            NodeUtilities.DetachPart(wData.DockingPortA);
            NodeUtilities.DetachPart(wData.DockingPortB);

            NodeUtilities.SwapLinks(
                wData.LinkedPartA,
                wData.DockingPortA,
                wData.LinkedPartB);
            NodeUtilities.SwapLinks(
                wData.LinkedPartB,
                wData.DockingPortB,
                wData.LinkedPartA);

            wData.DockingPortB.SetCollisionIgnores();
            wData.DockingPortA.SetCollisionIgnores();

            NodeUtilities.SpawnStructures(wData.LinkedPartA, nodeA);
            NodeUtilities.SpawnStructures(wData.LinkedPartB, nodeB);


            if (compress)
            {
                NodeUtilities.MovePart(wData.LinkedPartB, offset);
            }



            PartJoint newJoint = PartJoint.Create(
                wData.LinkedPartB,
                wData.LinkedPartA,
                nodeB,
                nodeA,
                AttachModes.STACK);

            wData.LinkedPartB.attachJoint = newJoint;

            SoftExplode(wData.DockingPortA);
            SoftExplode(wData.DockingPortB);
        }
Esempio n. 25
0
    public void Detach(bool makeJoint)
    {
        if (!detached)
        {
            detached       = true;
            tr.parent      = null;
            rb             = gameObject.AddComponent <Rigidbody>();
            rb.mass        = mass;
            rb.drag        = drag;
            rb.angularDrag = angularDrag;

            if (parentBody)
            {
                parentBody.mass   -= mass;
                rb.velocity        = parentBody.GetPointVelocity(tr.position);
                rb.angularVelocity = parentBody.angularVelocity;

                //Pick a random hinge joint to use
                if (makeJoint && joints.Length > 0)
                {
                    PartJoint chosenJoint = joints[Mathf.RoundToInt(Random.Range(0, joints.Length))];
                    initialAnchor   = chosenJoint.hingeAnchor;
                    displacedAnchor = initialAnchor;

                    hinge = gameObject.AddComponent <HingeJoint>();
                    hinge.autoConfigureConnectedAnchor = false;
                    hinge.connectedBody   = parentBody;
                    hinge.anchor          = chosenJoint.hingeAnchor;
                    hinge.axis            = chosenJoint.hingeAxis;
                    hinge.connectedAnchor = initialPos + chosenJoint.hingeAnchor;
                    hinge.enableCollision = false;
                    hinge.useLimits       = chosenJoint.useLimits;

                    JointLimits limits = new JointLimits();
                    limits.min        = chosenJoint.minLimit;
                    limits.max        = chosenJoint.maxLimit;
                    limits.bounciness = chosenJoint.bounciness;
                    hinge.limits      = limits;
                    hinge.useSpring   = chosenJoint.useSpring;

                    JointSpring spring = new JointSpring();
                    spring.targetPosition = chosenJoint.springTargetPosition;
                    spring.spring         = chosenJoint.springForce;
                    spring.damper         = chosenJoint.springDamper;
                    hinge.spring          = spring;
                    hinge.breakForce      = breakForce;
                    hinge.breakTorque     = breakForce;
                }
            }
        }
    }
Esempio n. 26
0
    PartJoint GetNearestJoint(Vector3 _position)
    {
        PartJoint joint = null;

        foreach (PartJoint j in GetAllJointInRadius(_position, 2.0f))
        {
            if (joint == null || (j.transform.position - _position).sqrMagnitude < (joint.transform.position - _position).sqrMagnitude)
            {
                joint = j;
            }
        }

        return(joint);
    }
Esempio n. 27
0
        protected virtual void OnPartJointBreak(PartJoint p)
        {
            LoggingUtil.LogVerbose(this, "OnPartJointBreak: " + p.Parent.vessel.id);
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                return;
            }

            if (GetAssociatedKeys(p.Parent.vessel).Any())
            {
                lastBreak = p.Parent.vessel;
            }
            vesselModifiedCallCount = 0;
        }
        protected virtual void OnPartJointBreak(PartJoint p)
        {
            if (HighLogic.LoadedScene == GameScenes.EDITOR || p.Parent.vessel == null)
            {
                return;
            }

            // Check if we need to make modifications based on undocking
            if (vesselInfo.ContainsKey(p.Parent.vessel.id) && vesselInfo[p.Parent.vessel.id].state == ParameterState.Complete)
            {
                ParamStrength?strength = vesselInfo[p.Parent.vessel.id].strength;

                // Medium strengths indicates that we may need to lower to weak if the "strong"
                // part is lost
                if (strength == ParamStrength.MEDIUM)
                {
                    strength = null;
                    foreach (uint hash in p.Parent.vessel.GetHashes())
                    {
                        if (dockedVesselInfo.ContainsKey(hash))
                        {
                            if (strength == null || strength == dockedVesselInfo[hash].Key)
                            {
                                dockedVesselInfo[hash] = dockedVesselInfo[hash];
                            }
                            else
                            {
                                strength = ParamStrength.MEDIUM;
                            }
                        }
                    }

                    // Shouldn't still be null...
                    if (strength == null)
                    {
                        LoggingUtil.LogWarning(this.GetType(), "Unexpected value when undocking!  Raise a GitHub issue!");
                        strength = ParamStrength.WEAK;
                    }

                    vesselInfo[p.Parent.vessel.id].strength = (ParamStrength)strength;
                }
                else if (strength == ParamStrength.STRONG)
                {
                    // Save the sub vessel info
                    SaveSubVesselInfo(p.Parent.vessel, ParamStrength.STRONG, vesselInfo[p.Parent.vessel.id].completionTime);
                }
            }

            CheckVessel(p.Parent.vessel);
        }
Esempio n. 29
0
    public int GetJointID(PartJoint _joint)
    {
        int jointId = -1;

        for (int i = 0; i < m_joints.Count; i++)
        {
            if (m_joints[i] == _joint)
            {
                jointId = i;
                break;
            }
        }
        return(jointId);
    }
Esempio n. 30
0
        internal void PartJointHelper(PooledStringBuilder sb, PartJoint joint)
        {
            sb.Append("PartJoint: ");
            if (joint != null)
            {
                sb.Append(joint);
                this.appendPartAncestry(sb, joint.Host);
            }
            else
            {
                sb.Append("null");
            }

            Debug.Log(sb.ToString());
        }
        private static bool ShouldFlamesBeAttached(PartJoint partJoint)
        {
            if (IsPartHostTypeAJointBreakerTrigger(partJoint.Host.name.ToLower()))
            {
                return false;
            }
            var part = partJoint.Target;
            if (part.partInfo.title.Contains("Wing") || part.partInfo.title.Contains("Fuselage")
                || part.FindModuleImplementing<ModuleEngines>() || part.FindModuleImplementing<ModuleEnginesFX>())
            {
                return true;
            }

            return part.Resources.Cast<PartResource>().Any(resource => resource.resourceName.Contains("Fuel") || resource.resourceName.Contains("Ox"));
        }
Esempio n. 32
0
        void onPartJointBreak(PartJoint joint, float force)
        {
            if (state != State.Fixed || !IsDocked)
            {
                return;
            }
            var dockedPart = vessel[dockedPartUId];

            if (joint.Parent == part && joint.Child == dockedPart ||
                joint.Parent == dockedPart && joint.Child == part)
            {
                state = State.Broken;
                StartCoroutine(CallbackUtil.DelayedCallback(3, part.explode));
            }
        }
        public void OnPartJointBreak(PartJoint partJoint)
        {
            if (partJoint.Target == null)
            {
                return;
            }
            if (partJoint.Target.PhysicsSignificance == 1)
            {
                return;
            }
            if (!ShouldFlamesBeAttached(partJoint))
            {
                return;
            }

            AttachFlames(partJoint);
        }
        public static List<ConfigurableJoint> GetJointListFromAttachJoint(PartJoint partJoint)
        {
            FieldInfo[] fields = partJoint.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            List<ConfigurableJoint> jointList = new List<ConfigurableJoint>();
            Type jointListType = jointList.GetType();

            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo field = fields[i];
                if (field.FieldType == jointListType)
                {
                    return (List<ConfigurableJoint>)field.GetValue(partJoint);

                }
            }

            return null;
        }
        private static void AttachFlames(PartJoint partJoint)
        {
            var flameObject2 =
                (GameObject)
                Instantiate(
                    GameDatabase.Instance.GetModel("DestructionEffects/Models/FlameEffect/model"),
                    partJoint.transform.position,
                    Quaternion.identity);

            flameObject2.SetActive(true);
            flameObject2.transform.parent = partJoint.Target.transform;
            flameObject2.AddComponent<FlamingJointScript>();

            foreach (var pe in flameObject2.GetComponentsInChildren<KSPParticleEmitter>())
            {
                if (!pe.useWorldSpace) continue;
                var gpe = pe.gameObject.AddComponent<DeGaplessParticleEmitter>();
                gpe.Part = partJoint.Target;
                gpe.Emit = true;
            }
        }
        protected override void OnPartJointBreak(PartJoint pj, float breakForce)
        {
            LoggingUtil.LogVerbose(this, "OnPartJointBreak");

            // Special docking port handling, because they don't fire an event if cross-feed is enabled
            // (the OnUndock event is only good is cross-feed is off)
            int dockingPortCount = 0;
            for (int i = 0; i < 2; i++)
            {
                Part p = i == 0 ? pj.Parent : pj.Child;
                foreach (PartModule pm in p.Modules)
                {
                    if (pm.moduleName.StartsWith("ModuleDocking"))
                    {
                        dockingPortCount++;
                        break;
                    }
                }
            }

            // This is a confirmation, add the first vessel id to staged
            if (dockingPortCount == 2)
            {
                staged.Add(pj.Parent.vessel);
                lastUndockTime = UnityEngine.Time.fixedTime;
            }
            // Need to check for a stage seperation
            else
            {
                possibleStages.Clear();
                possibleStages.Add(pj.Parent.vessel);
                lastPartJointTime = UnityEngine.Time.fixedTime;
            }

            // Vessel check happens here
            base.OnPartJointBreak(pj, breakForce);
        }
 public void onPartJointBreak(PartJoint joint)
 {
     this.PartJointHelper(this.getStringBuilder(), joint);
 }
 private void _manageAttachNode(float breakForce)
 {
     if (!this.IsConnectionOrigin || this.IsTargetOnly || this._jointAttachNode != null || !HighLogic.LoadedSceneIsFlight)
     {
         return;
     }
     try
     {
         var targetPart = this.IsFreeAttached ? this.FreeAttachPart : this.Target.part;
         if (targetPart == null)
         {
             return;
         }
         var freeAttachedHitPoint = this.IsFreeAttached ? this._convertFreeAttachRayHitPointToStrutTarget()[0] : Vector3.zero;
         var normDir = (this.Origin.position - (this.IsFreeAttached ? freeAttachedHitPoint : this.Target.Origin.position)).normalized;
         this._jointAttachNode = new AttachNode {id = Guid.NewGuid().ToString(), attachedPart = targetPart};
         this._jointAttachNode.breakingForce = this._jointAttachNode.breakingTorque = breakForce;
         this._jointAttachNode.position = targetPart.partTransform.InverseTransformPoint(this.IsFreeAttached ? freeAttachedHitPoint : targetPart.partTransform.position);
         this._jointAttachNode.orientation = targetPart.partTransform.InverseTransformDirection(normDir);
         this._jointAttachNode.size = 1;
         this._jointAttachNode.ResourceXFeed = false;
         this._jointAttachNode.attachMethod = AttachNodeMethod.FIXED_JOINT;
         this.part.attachNodes.Add(this._jointAttachNode);
         this._jointAttachNode.owner = this.part;
         this._partJoint = PartJoint.Create(this.part, this.IsFreeAttached ? targetPart : (targetPart.parent ?? targetPart), this._jointAttachNode, null, AttachModes.SRF_ATTACH);
     }
     catch (Exception e)
     {
         this._jointAttachNode = null;
         Debug.Log("[AS] failed to create attachjoint: " + e.Message + " " + e.StackTrace);
     }
 }
 public void DestroyJoint()
 {
     try
     {
         if (this._partJoint != null)
         {
             this._partJoint.DestroyJoint();
             this.part.attachNodes.Remove(this._jointAttachNode);
             this._jointAttachNode.owner = null;
         }
         DestroyImmediate(this._partJoint);
     }
     catch (Exception)
     {
         //ahem...
     }
     DestroyImmediate(this._joint);
     this._partJoint = null;
     this._jointAttachNode = null;
     this._joint = null;
     this.LinkType = LinkType.None;
     if (this.IsDocked)
     {
         this.ProcessUnDock(true);
     }
 }
        protected virtual void OnPartJointBreak(PartJoint p, float breakForce)
        {
            LoggingUtil.LogVerbose(this, "OnPartJointBreak: " + p.Parent.vessel.id);
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                return;
            }

            if (GetAssociatedKeys(p.Parent.vessel).Any())
            {
                lastBreak = p.Parent.vessel;
            }
            vesselModifiedCallCount = 0;
        }
Esempio n. 41
0
 void OnPartJointBreak(PartJoint j)
 {
     if(!part)
     {
         GameEvents.onPartJointBreak.Remove(OnPartJointBreak);
     }
     RefreshModules();
     UpdateList();
 }
Esempio n. 42
0
		void OnPartJointBreak(PartJoint j)
		{
			if(!part)
			{
				GameEvents.onPartJointBreak.Remove(OnPartJointBreak);
			}

			if((j.Parent && j.Parent.vessel == vessel) || (j.Child && j.Child.vessel == vessel))
			{
				RefreshModules();
				UpdateList();
			}
		}
Esempio n. 43
0
		private void CallbackPartJointWasLoaded (PartJoint partjoint)
		{
			Log.Info ("CallbackPartJointWasLoaded");
			//this.newScene = true;
			//this.sceneReady = true;
			this.specialScene = true;
			//lastSceneUpdate = Time.realtimeSinceStartup;
		}
 protected override void OnPartJointBreak(PartJoint p, float breakForce)
 {
     base.OnPartJointBreak(p, breakForce);
     CheckVessel(FlightGlobals.ActiveVessel);
 }
 protected override void OnPartJointBreak(PartJoint p)
 {
     base.OnPartJointBreak(p);
     CheckVessel(FlightGlobals.ActiveVessel);
 }
        protected virtual void OnPartJointBreak(PartJoint p)
        {
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                return;
            }

            if (GetAssociatedKeys(p.Parent.vessel).Any())
            {
                lastBreak = p.Parent.vessel;
            }
        }
 public void OnJointBreak(PartJoint partJoint)
 {
     OnJointBreak(partJoint.Parent);
 }
Esempio n. 48
0
        protected override void OnPartJointBreak(PartJoint p)
        {
            LoggingUtil.LogVerbose(this, "OnPartJointBreak: " + p);
            base.OnPartJointBreak(p);

            if (HighLogic.LoadedScene == GameScenes.EDITOR || p.Parent.vessel == null)
            {
                return;
            }

            CheckVessel(p.Parent.vessel);
        }
        internal void PartJointHelper(StringBuilder sb, PartJoint joint)
        {
            sb.Append("PartJoint: ");
            if (joint != null)
            {
                sb.Append(joint);
                this.appendPartAncestry(sb, joint.Host);
            }
            else
            {
                sb.Append("null");
            }

            Debug.Log(sb.ToString());

            Tools.PutStringBuilder(sb);
        }
Esempio n. 50
0
 private void OnPartJointBreak(PartJoint p, float force)
 {
     if (HighLogic.LoadedScene == GameScenes.FLIGHT)
     {
         HandleVessel(p.Parent.vessel);
     }
 }
        protected override void OnPartJointBreak(PartJoint p, float breakForce)
        {
            base.OnPartJointBreak(p, breakForce);

            Vessel v = p.Parent.vessel;
            LoggingUtil.LogVerbose(this, "OnPartJointBreak: " + v.id);
            if (v.vesselType == VesselType.Debris)
            {
                return;
            }

            // Check if this is one of our vessels
            IEnumerable<string> vesselIterator;
            if (vessels.Count != 0)
            {
                vesselIterator = vessels;
            }
            else if (Parent is VesselParameterGroup && ((VesselParameterGroup)Parent).VesselList.Any())
            {
                vesselIterator = ((VesselParameterGroup)Parent).VesselList;
            }
            else
            {
                return;
            }

            // Add the vessel when created
            IEnumerable<string> keys = ContractVesselTracker.Instance.GetAssociatedKeys(v);
            foreach (string vessel in vesselIterator)
            {
                if (keys.Contains(vessel))
                {
                    lastVesselAdd = Time.fixedTime;
                    brokenVessels.AddUnique(v);
                    addNextVessel = true;
                    return;
                }
            }
        }
        protected virtual void OnPartJointBreak(PartJoint p)
        {
            if (HighLogic.LoadedScene == GameScenes.EDITOR || p.Parent.vessel == null)
            {
                return;
            }

            // Check if we need to make modifications based on undocking
            if (vesselInfo.ContainsKey(p.Parent.vessel.id) && vesselInfo[p.Parent.vessel.id].state == ParameterState.Complete)
            {
                ParamStrength? strength = vesselInfo[p.Parent.vessel.id].strength;

                // Medium strengths indicates that we may need to lower to weak if the "strong"
                // part is lost
                if (strength == ParamStrength.MEDIUM)
                {
                    strength = null;
                    foreach (uint hash in p.Parent.vessel.GetHashes())
                    {
                        if (dockedVesselInfo.ContainsKey(hash))
                        {
                            if (strength == null || strength == dockedVesselInfo[hash].Key)
                            {
                                dockedVesselInfo[hash] = dockedVesselInfo[hash];
                            }
                            else
                            {
                                strength = ParamStrength.MEDIUM;
                            }
                        }
                    }

                    // Shouldn't still be null...
                    if (strength == null)
                    {
                        LoggingUtil.LogWarning(this.GetType(), "Unexpected value when undocking!  Raise a GitHub issue!");
                        strength = ParamStrength.WEAK;
                    }

                    vesselInfo[p.Parent.vessel.id].strength = (ParamStrength)strength;
                }
                else if (strength == ParamStrength.STRONG)
                {
                    // Save the sub vessel info
                    SaveSubVesselInfo(p.Parent.vessel, ParamStrength.STRONG, vesselInfo[p.Parent.vessel.id].completionTime);
                }
            }

            CheckVessel(p.Parent.vessel);
        }
        protected virtual void OnPartJointBreak(PartJoint p, float breakForce)
        {
            if (HighLogic.LoadedScene == GameScenes.EDITOR || p.Parent.vessel == null)
            {
                return;
            }

            LoggingUtil.LogVerbose(this, "OnPartJointBreak(" + p.Parent.vessel.id + ")");

            // Check if we need to make modifications based on undocking
            if (vesselInfo.ContainsKey(p.Parent.vessel.id) && vesselInfo[p.Parent.vessel.id].state == ParameterState.Complete)
            {
                ParamStrength strength = vesselInfo[p.Parent.vessel.id].strength;

                // Medium strengths indicates that we may need to lower to weak if the "strong"
                // part is lost
                if (strength == ParamStrength.MEDIUM)
                {
                    foreach (uint hash in p.Parent.vessel.GetHashes())
                    {
                        strength = !dockedVesselInfo.ContainsKey(hash) ? ParamStrength.WEAK : dockedVesselInfo[hash].Key > strength ? dockedVesselInfo[hash].Key : strength;
                    }

                    vesselInfo[p.Parent.vessel.id].strength = strength == ParamStrength.STRONG ? ParamStrength.MEDIUM : ParamStrength.WEAK;
                }
                else if (strength == ParamStrength.STRONG)
                {
                    // Save the sub vessel info
                    SaveSubVesselInfo(p.Parent.vessel, ParamStrength.STRONG, vesselInfo[p.Parent.vessel.id].completionTime);
                }
            }

            CheckVessel(p.Parent.vessel);
        }