AutoAsparagus.ASPFuelLine.AddOnionFuelLines C# (CSharp) Method

AddOnionFuelLines() public static method

public static AddOnionFuelLines ( AvailablePart ap, int textureNum, string texturePath, string textureDisplayName, bool rainbow ) : void
ap AvailablePart
textureNum int
texturePath string
textureDisplayName string
rainbow bool
return void
        public static void AddOnionFuelLines(AvailablePart ap, int textureNum, string[] texturePath, string[] textureDisplayName, bool rainbow)
        {
            ASPConsoleStuff.AAprint ("=== AddOnionFuelLines ===");
            AutoAsparagus.badStartTank = null;
            AutoAsparagus.badDestTank = null;
            AutoAsparagus.blockingTanks = new List<Part> ();
            // Get all the parts of the ship
            EditorLogic editor = EditorLogic.fetch;
            ShipConstruct ship = editor.ship;
            List<Part> parts = ship.parts;
            parts [0].SetHighlight (false, true);

            // start a new list of fuel lines to connect
            //fuelSetsToConnect = new List<FuelSet>();

            // Find the symmetrical fuel tanks
            List<Part> tanks = ASPStaging.findFuelTanks (parts);
            List<Part> tanksToConnect = new List<Part> ();

            // get list of tanks to connect
            int safetyfactor = 10000;
            while (tanks.Count > 0) {
                safetyfactor = safetyfactor - 1;
                if (safetyfactor == 0) {
                    AutoAsparagus.osd ("Infinite loop in AddOnionFuelLines:tanks.Count, aborting :(");
                    AutoAsparagus.mystate = AutoAsparagus.ASPState.ERROR;
                    return;
                }
                Part p = tanks [0];
                bool connectTank = true;
                foreach (Part child in p.children) {
                    if (isFuelLine (child, ap.name)) {
                        ASPConsoleStuff.printPart ("Tank already has a fuel line", p);
                        connectTank = false;
                    }
                }
                if (connectTank) {
                    ASPConsoleStuff.printPart ("... will connect tank", p);
                    tanksToConnect.Add (p);
                }
                tanks.Remove (p);
            }
            safetyfactor = 10000;
            while (tanksToConnect.Count > 0) {
                safetyfactor = safetyfactor - 1;
                if (safetyfactor == 0) {
                    AutoAsparagus.osd ("Infinite loop in AddOnionFuelLines:tankstoConnect.Count, aborting :(");
                    AutoAsparagus.mystate = AutoAsparagus.ASPState.ERROR;
                    return;
                }
                ASPConsoleStuff.printPartList ("Tanks to connect", "tank", tanksToConnect);

                Part currentTank = tanksToConnect [0];
                // connect first part to parent fuel tank
                Part parentTank = findParentFuelTank (currentTank);
                if (parentTank == null) {
                    ASPConsoleStuff.printPart ("no parent fuel tank found found!  Not connecting", currentTank);
                } else {
                    string texturePathString = null;
                    string textureName = null;
                    if (texturePath != null) {
                        texturePathString = texturePath [textureNum];
                        textureName = textureDisplayName [textureNum];
                    }
                    AttachFuelLine (currentTank, parentTank, ap, textureNum, texturePathString, textureName);
                    if (rainbow) {
                        ASPConsoleStuff.AAprint ("oh, rainBOWs..." + textureNum.ToString ());
                        textureNum = textureNum + 1;
                        if (textureNum > (texturePath.Length - 1)) {
                            textureNum = 0;
                        }
                    }
                }
                tanksToConnect.Remove (currentTank);
            }

            //StageManager.Instance.SortIcons (true);
        }