Exemplo n.º 1
0
 public void regenerateJoints(Vessel vessel)
 {
     if (trackedJoints.ContainsKey(vessel))
     {
         clearJoints(vessel);
     }
     addNewVesselToDict(vessel);
     foreach (FlightJointTracker joint in ReCouplerUtils.Generate_Flight(vessel))
     {
         trackedJoints[vessel].Add(joint);
     }
 }
Exemplo n.º 2
0
            public bool Couple(Vessel ownerVessel = null)
            {
                try
                {
                    int owner;
                    if (parts[1].vessel == FlightGlobals.ActiveVessel ||
                        (parts[0].vessel != FlightGlobals.ActiveVessel &&
                         (parts[1].vessel == ownerVessel ||
                          (parts[1].vessel.Parts.Count > parts[0].vessel.Parts.Count && parts[0].vessel != ownerVessel))))
                    {
                        owner = 1;
                    }
                    else
                    {
                        owner = 0;
                    }

                    ownerVessel = parts[owner].vessel;

                    AttachNode targetNode = owner == 0 ? nodes[0] : nodes[1];
                    AttachNode coupleNode = owner == 0 ? nodes[1] : nodes[0];
                    Part       targetPart = owner == 0 ? parts[0] : parts[1];
                    Part       couplePart = owner == 0 ? parts[1] : parts[0];

                    log.debug("Coupling " + couplePart.name + " to " + targetPart.name + ".");

                    if (ownerVessel == FlightGlobals.ActiveVessel)
                    {
                        // Save camera information here.
                    }
                    ReCouplerUtils.CoupleParts(coupleNode, targetNode);
                    if (ownerVessel == FlightGlobals.ActiveVessel)
                    {
                        // Restore camera information here
                    }

                    //targetPart.vessel.currentStage = KSP.UI.Screens.StageManager.RecalculateVesselStaging(targetPart.vessel);
                    ownerVessel.currentStage = KSP.UI.Screens.StageManager.RecalculateVesselStaging(ownerVessel) + 1;

                    if (!isTrackingDockingPorts)
                    {
                        this.Destroy();
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    log.error("Error in coupling: " + ex);
                    return(false);
                }
            }
Exemplo n.º 3
0
 public void PostDecouplerCheck()
 {
     for (int i = parts.Count - 1; i >= 0; i--)
     {
         try
         {
             if (parts[i].vessel != parents[i].part.vessel && ParentStillValid(parents[i]))
             {
                 log.debug("Coupling part to parent.");
                 ReCouplerUtils.CoupleParts(parts[i], parents[i].part, parents[i].nodeTo, parents[i].node);
             }
         }
         catch (Exception ex)
         {
             log.error("Error in PostDecouplerCheck: " + ex);
         }
     }
 }
Exemplo n.º 4
0
        public void GenerateFromShipConstruct(ShipConstruct ship, bool forbidAdding = false)
        {
            openNodes.Clear();
            GenerateJoints(ship);

            foreach (EditorJointTracker joint in ReCouplerUtils.Generate_Editor(ship, openNodes))
            {
                if (forbidAdding)
                {
                    ReCouplerGUI.Instance.partPairsToIgnore.Add(joint.parts.ToArray());
                    joint.Destroy();
                }
                else
                {
                    hiddenNodes.Add(joint);
                }
            }
        }
Exemplo n.º 5
0
        IEnumerator DelayedUpdate(int time)
        {
            yield return(new WaitForFixedUpdate());

            log.debug("Running DelayedUpdate: " + Planetarium.GetUniversalTime());
            List <Vessel> vessels = trackedJoints.Keys.ToList();

            for (int i = vessels.Count - 1; i >= 0; i--)
            {
                updateVessel(vessels[i]);
                bool combinedAny = false;
                FlightJointTracker jt;
                for (int j = trackedJoints[vessels[i]].Count - 1; j >= 0; j--)
                {
                    jt = trackedJoints[vessels[i]][j];

                    if (jt.parts[0] == null || jt.parts[1] == null)
                    {
                        log.debug("Removing a null joint.");
                        jt.Destroy();
                        trackedJoints[vessels[i]].Remove(jt);
                        continue;
                    }
                    if (!jt.linkCreated)
                    {
                        log.debug("A joint must have broken.");
                        jt.Destroy();
                        trackedJoints[vessels[i]].Remove(jt);
                        continue;
                    }
                    else if (jt.isTrackingDockingPorts)
                    {
                        ModuleDockingNode fromNode, toNode;
                        ReCouplerUtils.hasDockingPort(jt.nodes[0], out fromNode);
                        ReCouplerUtils.hasDockingPort(jt.nodes[1], out toNode);

                        /*if (dockingNode.state != dockingNode.st_docked_dockee.name &&
                         *  dockingNode.state != dockingNode.st_docked_docker.name &&
                         *  dockingNode.state != dockingNode.st_docker_sameVessel.name &&
                         *  dockingNode.state != dockingNode.st_preattached.name)*/
                        if ((fromNode != null && fromNode.otherNode != toNode) && (toNode != null && toNode.otherNode != fromNode))
                        {
                            log.debug("A joint must have undocked.");
                            trackedJoints[vessels[i]].Remove(jt);
                            continue;
                        }
                    }

                    if (jt.parts[0].vessel != jt.parts[1].vessel)
                    {
                        log.debug("Vessel tree split, but should be re-combined.");
                        log.debug(jt.parts[0].name + " / " + jt.parts[1].name);
                        log.debug(jt.parts[0].vessel + " / " + jt.parts[1].vessel);
                        // The vessel split at the official tree, but isn't split at this joint.

                        if (jt.Couple(ownerVessel: vessels[i]))
                        {
                            log.debug("Removing joint since it is now a real, coupled joint.");
                            log.debug("Parent0: " + jt.parts[0].parent.name + " Parent1: " + jt.parts[1].parent.name);
                            trackedJoints[vessels[i]].Remove(jt);
                        }
                        else
                        {
                            log.error("Could not couple parts!");
                        }

                        combinedAny = true;
                        continue;
                    }
                    else if (jt.parts[0].vessel != vessels[i] && jt.parts[1].vessel != vessels[i])
                    {
                        log.debug("Removing joint between " + jt.parts[0].name + " and " + jt.parts[1].name + " because they are no longer part of this vessel.");
                        if (jt.parts[0].vessel == jt.parts[1].vessel)
                        {
                            log.debug("Adding them to vessel " + jt.parts[0].vessel.vesselName + " instead.");
                            if (!trackedJoints.ContainsKey(jt.parts[0].vessel))
                            {
                                addNewVesselToDict(jt.parts[0].vessel);
                            }
                            trackedJoints[jt.parts[0].vessel].Add(jt);
                            jt.combineCrossfeedSets();
                        }
                        else
                        {
                            jt.Destroy();
                        }
                        trackedJoints[vessels[i]].Remove(jt);
                        continue;
                    }
                }

                if (combinedAny)
                {
                    for (int j = trackedJoints[vessels[i]].Count - 1; j >= 0; j--)
                    {
                        trackedJoints[vessels[i]][j].combineCrossfeedSets();
                    }
                }
            }
            checkActiveVessels();
            delayedUpdates.Remove(time);
        }
Exemplo n.º 6
0
        /*public void OnEditorPartDeleted(Part part)
         * {
         *  reConstruct();
         * }*/

        public void OnEditorPartEvent(ConstructionEventType constEvent, Part part)
        {
            List <Part> partsInvolved = new List <Part> {
                part
            };

            partsInvolved.AddRange(part.FindChildParts <Part>(true).ToList());

            /*foreach (Part p in part.symmetryCounterparts)
             * {
             *  partsInvolved.Add(p);
             *  partsInvolved.AddRange(p.FindChildParts<Part>(true).ToList());
             * }*/

            if (constEvent == ConstructionEventType.PartAttached ||
                constEvent == ConstructionEventType.PartOffset ||
                constEvent == ConstructionEventType.PartRotated)
            {
                /*for (int p = 0; p < partsInvolved.Count; p++)
                 * {
                 *  foreach (EditorJointTracker jt in ReCouplerUtils.checkPartNodes(partsInvolved[p], openNodes, ReCouplerUtils.JointType.EditorJointTracker))
                 *  {
                 *      hiddenNodes.Add(jt);
                 *  }
                 * }*/

                ResetAndRebuild();
            }
            else if (constEvent == ConstructionEventType.PartDetached)
            {
                for (int i = ReCouplerGUI.Instance.partPairsToIgnore.Count - 1; i >= 0; i--)
                {
                    for (int j = ReCouplerGUI.Instance.partPairsToIgnore[i].Length - 1; j >= 0; j--)
                    {
                        if (!EditorLogic.fetch.ship.parts.Contains(ReCouplerGUI.Instance.partPairsToIgnore[i][j]))
                        {
                            ReCouplerGUI.Instance.partPairsToIgnore.RemoveAt(i);
                            break;
                        }
                    }
                }
                ResetAndRebuild();
            }

            /*else if (constEvent == ConstructionEventType.PartDetached)
             * {
             *  List<EditorJointTracker> jointsInvolved;
             *  for (int p = 0; p < partsInvolved.Count; p++)
             *  {
             *      jointsInvolved = hiddenNodes.FindAll(jt => jt.parts.Contains(partsInvolved[p]));
             *      for (int i = jointsInvolved.Count - 1; i >= 0; i--)
             *      {
             *          jointsInvolved[i].Destroy();
             *          hiddenNodes.Remove(jointsInvolved[i]);
             *      }
             *  }
             * }
             * else if (constEvent == ConstructionEventType.PartOffset || constEvent == ConstructionEventType.PartRotated)
             * {
             *  List<EditorJointTracker> jointsInvolved;
             *  for (int p = 0; p < partsInvolved.Count; p++)
             *  {
             *      jointsInvolved = hiddenNodes.FindAll(jt => jt.parts.Contains(partsInvolved[p]));
             *      for (int i = jointsInvolved.Count - 1; i >= 0; i--)
             *      {
             *          jointsInvolved[i].Destroy();
             *          hiddenNodes.Remove(jointsInvolved[i]);
             *      }
             *  }
             *
             *  for (int p = 0; p < partsInvolved.Count; p++)
             *  {
             *      foreach (EditorJointTracker jt in ReCouplerUtils.checkPartNodes(partsInvolved[p], openNodes, ReCouplerUtils.JointType.EditorJointTracker))
             *      {
             *          hiddenNodes.Add(jt);
             *      }
             *  }
             * }*/
            else if (constEvent == ConstructionEventType.PartCopied)
            {
                for (int i = partsInvolved.Count - 1; i >= 0; i--)
                {
                    List <AttachNode> problemNodes = ReCouplerUtils.findProblemNodes(partsInvolved[i]);
                    for (int j = problemNodes.Count - 1; j >= 0; j--)
                    {
                        problemNodes[j].attachedPart = null;
                    }
                }
            }

            /*else if (constEvent == ConstructionEventType.PartDeleted)
             * {
             *  List<EditorJointTracker> jointsInvolved;
             *  for (int p = 0; p < partsInvolved.Count; p++)
             *  {
             *      jointsInvolved = hiddenNodes.FindAll(jt => jt.parts.Contains(partsInvolved[p]));
             *      for (int i = jointsInvolved.Count - 1; i >= 0; i--)
             *      {
             *          jointsInvolved[i].Destroy();
             *          hiddenNodes.Remove(jointsInvolved[i]);
             *      }
             *  }
             * }*/
        }