Ejemplo n.º 1
0
 private static void RepairClearDocking(KmlPartDock dock1, KmlPartDock dock2)
 {
     try
     {
         KmlNode module = dock1.GetChildNode("MODULE", "ModuleDockingNode");
         module.GetAttrib("state").Value = "Ready";
         //module.GetAttrib("dockUId").Value = "";
         KmlNode events = module.GetChildNode("EVENTS");
         events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
         events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
         if (dock2 != null)
         {
             module = dock2.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value = "Ready";
             //module.GetAttrib("dockUId").Value = "";
             events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
         }
         System.Windows.MessageBox.Show("Successfully reset docking to ready. Please save and reload to see the rebuilt part structure.");
         // TODO KmlPartDock:RepairClearDocking(): Refresh structure without save / reload
     }
     catch (NullReferenceException)
     {
         System.Windows.MessageBox.Show("Couldn't reset docking node, there are sub-nodes missing.\n" +
                                        "You should copy a MODULE node from a functional state 'Ready' part.\n");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// This method is called by KmlPart.BuildAttachmentStructure() after a complete vessel is read and all parts exist,
        /// so we can build KmlPart references from the index or UId information got from reading this part anlone.
        /// </summary>
        /// <param name="dock">The part identified as KmlPartDock</param>
        /// <param name="other">The other docked KmlPart (could be KmlPartDock also)</param>
        public static void BuildDockStructure(KmlPartDock dock, KmlPart other)
        {
            if (dock.DockUid == other.Uid)
            {
                dock.DockedPart = other;
            }
            else
            {
                Syntax.Warning(dock, "Dock part is attached to (UId " + dock.DockUid + ") but supposed to be attached to: " + other.ToString() + " (UId " + other.Uid + ")");
                dock.NeedsRepair = true;
            }

            if (dock.DockType == DockTypes.Dock && dock.DockState.ToLower() == "docked (docker)")
            {
                KmlNode module = dock.GetChildNode("MODULE", "ModuleDockingNode");
                if (module == null)
                {
                    Syntax.Warning(dock, "Dock sub-node MODULE with name = 'ModuleDockingNode' is missing. Please copy one from functional dock part or older save file");
                    dock.NeedsRepair = true;
                }
                else if (module.GetChildNode("DOCKEDVESSEL") == null)
                {
                    Syntax.Warning(dock, "Dock sub-sub-node DOCKEDVESSEL is missing");
                    dock.NeedsRepair = true;
                }
            }
            else if (dock.DockType == DockTypes.Grapple && dock.DockState.ToLower() == "grappled")
            {
                KmlNode module = dock.GetChildNode("MODULE", "ModuleGrappleNode");
                if (module == null)
                {
                    Syntax.Warning(dock, "Grapple sub-node MODULE with name = 'ModuleGrappleNode' is missing. Please copy one from functional dock part or older save file");
                    dock.NeedsRepair = true;
                }
                else
                {
                    if (module.GetChildNode("DOCKEDVESSEL") == null)
                    {
                        Syntax.Warning(dock, "Grapple sub-sub-node DOCKEDVESSEL is missing");
                        dock.NeedsRepair = true;
                    }
                    if (module.GetChildNode("DOCKEDVESSEL_other") == null)
                    {
                        Syntax.Warning(dock, "Grapple sub-sub-node DOCKEDVESSEL_other is missing");
                        dock.NeedsRepair = true;
                    }
                }
            }
            else if (dock.DockType == DockTypes.KasCPort)
            {
                KmlNode module = dock.GetChildNode("MODULE", "KASModuleStrut");
                if (module == null)
                {
                    Syntax.Warning(dock, "KAS CPort sub-node MODULE with name = 'KASModuleStrut' is missing. Please copy one from functional CPort part or older save file");
                    dock.NeedsRepair = true;
                }
            }
        }
Ejemplo n.º 3
0
 private static void RepairDockerDockee(KmlPartDock docker, KmlPartDock dockee)
 {
     if (docker.ParentPart == dockee || dockee.ParentPart == docker)
     {
         bool dockerOk = false;
         bool dockeeOk = false;
         try
         {
             KmlNode module = docker.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value   = "Docked (docker)";
             module.GetAttrib("dockUId").Value = dockee.Uid;
             KmlNode events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "True";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
             if (module.GetChildNode("DOCKEDVESSEL") == null)
             {
                 System.Windows.MessageBox.Show("Couldn't find sub-node DOCKEDVESSEL, you should try to copy it from older save files.");
             }
             else
             {
                 dockerOk = true;
             }
         }
         catch (NullReferenceException)
         {
             System.Windows.MessageBox.Show("Couldn't fix docker node, there are sub-nodes missing.\n" +
                                            "You should copy a MODULE node from a functional 'Docked (docker)' part.\n" +
                                            "Docker should be: " + docker);
         }
         try
         {
             KmlNode module = dockee.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value   = "Docked (dockee)";
             module.GetAttrib("dockUId").Value = docker.Uid;
             KmlNode events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
             dockeeOk = true;
         }
         catch (NullReferenceException)
         {
             System.Windows.MessageBox.Show("Couldn't fix dockee node, there are sub-nodes missing.\n" +
                                            "You should copy a MODULE node from a functional 'Docked (dockee)' part.\n" +
                                            "Dockee should be: " + dockee);
         }
         if (dockerOk && dockeeOk)
         {
             System.Windows.MessageBox.Show("Successfully repaired docker-dockee. Please save and reload to see the rebuilt part structure.");
             // TODO KmlPartDock:RepairDockerDockee(): Refresh structure without save / reload
         }
     }
     else
     {
         RepairSameVesselChoose(docker, dockee);
     }
 }
Ejemplo n.º 4
0
 private static void RepairSameVesselDockee(KmlPartDock same, KmlPartDock dockee)
 {
     if (same.ParentPart == dockee || dockee.ParentPart == same)
     {
         RepairDependingWhosParent(same, dockee);
     }
     else
     {
         bool sameOk   = false;
         bool dockeeOk = false;
         try
         {
             KmlNode module = same.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value   = "Docked (same vessel)";
             module.GetAttrib("dockUId").Value = dockee.Uid;
             KmlNode events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "True";
             sameOk = true;
         }
         catch (NullReferenceException)
         {
             System.Windows.MessageBox.Show("Couldn't fix same vessel docking node, there are sub-nodes missing.\n" +
                                            "You should copy a MODULE node from a functional 'Docked (same vessel)' part.\n" +
                                            "Same vessel dock should be: " + same);
         }
         try
         {
             KmlNode module = dockee.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value   = "Docked (dockee)";
             module.GetAttrib("dockUId").Value = same.Uid;
             KmlNode events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
             dockeeOk = true;
         }
         catch (NullReferenceException)
         {
             System.Windows.MessageBox.Show("Couldn't fix dockee node, there are sub-nodes missing.\n" +
                                            "You should copy a MODULE node from a functional 'Docked (dockee)' part.\n" +
                                            "Dockee should be: " + dockee);
         }
         if (sameOk && dockeeOk)
         {
             System.Windows.MessageBox.Show("Successfully repaired same vessel docking. Please save and reload to see the rebuilt part structure.");
             // TODO KmlPartDock:RepairDockerDockee(): Refresh structure without save / reload
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Serach all child nodes of sourceNode for a certain tag.
 /// Does not search recursive.
 /// </summary>
 /// <param name="sourceNode">The node to search in its chgild nodes</param>
 /// <param name="tag">The tag of the KmlNode to search for</param>
 /// <returns>The found KmlNode or null if no such is found</returns>
 public static KmlNode GetChildNodeFrom(KmlNode sourceNode, string tag)
 {
     if (sourceNode != null)
     {
         return(sourceNode.GetChildNode(tag));
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 6
0
 private static void RepairClearDocking(KmlPartDock dock1, KmlPartDock dock2)
 {
     try
     {
         KmlNode module = dock1.GetChildNode("MODULE", "ModuleDockingNode");
         module.GetAttrib("state").Value = "Ready";
         //module.GetAttrib("dockUId").Value = "";
         KmlNode events = module.GetChildNode("EVENTS");
         events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
         events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
         Syntax.Info(dock1, "Successfully reset docking to ready");
     }
     catch (NullReferenceException)
     {
         Syntax.Warning(dock1, "Couldn't reset docking node, there are sub-nodes missing.\n" +
                        "You should copy a MODULE node from a functional state 'Ready' part.\n");
     }
     if (dock2 != null)
     {
         try
         {
             KmlNode module = dock2.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value = "Ready";
             //module.GetAttrib("dockUId").Value = "";
             KmlNode events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
             Syntax.Info(dock2, "Successfully reset docking to ready");
         }
         catch (NullReferenceException)
         {
             Syntax.Warning(dock2, "Couldn't reset docking node, there are sub-nodes missing.\n" +
                            "You should copy a MODULE node from a functional state 'Ready' part\n");
         }
     }
     if (dock1.Parent is KmlVessel)
     {
         BuildAttachmentStructure((dock1.Parent as KmlVessel).Parts);
     }
 }
Ejemplo n.º 7
0
        private static void RepairGrappling(KmlPartDock grapple, KmlPart part)
        {
            int grappleIndex = -1;
            int partIndex    = -1;

            if (grapple.Parent == null || !(grapple.Parent is KmlVessel))
            {
                System.Windows.MessageBox.Show("Could not search for connected parts, parent vessel is not valid");
            }
            else
            {
                bool      dockedVesselOk = true;
                KmlVessel vessel         = (KmlVessel)grapple.Parent;
                grappleIndex = vessel.Parts.IndexOf(grapple);
                partIndex    = vessel.Parts.IndexOf(part);
                try
                {
                    KmlNode module = grapple.GetChildNode("MODULE", "ModuleGrappleNode");
                    module.GetAttrib("state").Value   = "Grappled";
                    module.GetAttrib("dockUId").Value = part.Uid;
                    KmlNode events = module.GetChildNode("EVENTS");
                    events.GetChildNode("Release").GetAttrib("active").Value           = "True";
                    events.GetChildNode("ReleaseSameVessel").GetAttrib("active").Value = "False";
                    if (module.GetChildNode("DOCKEDVESSEL") == null)
                    {
                        System.Windows.MessageBox.Show("Couldn't find sub-node DOCKEDVESSEL, you should try to copy it from older save file.");
                        dockedVesselOk = false;
                    }
                    if (module.GetChildNode("DOCKEDVESSEL_other") == null)
                    {
                        System.Windows.MessageBox.Show("Couldn't find sub-node DOCKEDVESSEL_other, you should try to copy it from older save file.");
                        dockedVesselOk = false;
                    }
                    module = grapple.GetChildNode("MODULE", "ModuleAnimateGeneric");
                    module.GetAttrib("animSwitch").Value = "False";
                    module.GetAttrib("animTime").Value   = "1";
                    events = module.GetChildNode("EVENTS");
                    KmlNode toggle = events.GetChildNode("Toggle");
                    toggle.GetAttrib("active").Value  = "False";
                    toggle.GetAttrib("guiName").Value = "Disarm";
                    if (part.ParentPart == grapple)
                    {
                        RepairGrappleAttachment(part, grappleIndex);
                    }
                    else if (grapple.ParentPart == part)
                    {
                        RepairGrappleAttachment(grapple, partIndex);
                    }
                    else
                    {
                        // TODO KmlPartDock:RepairGrappling(): Is there a 'Grappled (same vessel)'?
                    }
                    if (dockedVesselOk)
                    {
                        // Maybe RepairGrappleAttachment()  will cause a message to save and reload
                        System.Windows.MessageBox.Show("Successfully repaired grappling. Please save and reload to see the rebuilt part structure.");
                        // TODO KmlPartDock:RepairGrappling(): Refresh structure without save / reload
                    }
                }
                catch (NullReferenceException)
                {
                    System.Windows.MessageBox.Show("Couldn't fix grappling node, there are sub-nodes missing.\n" +
                                                   "You should copy a MODULE node from a functional state 'Grappled' part.\n" +
                                                   "grappled part should be: " + part);
                }
            }
        }