private static Part makeFuelLineChain(List<Part> tanksToConnect, Part startTank, AvailablePart ap, int textureNum, string texturePath, string textureDisplayName, int numberOfTanks)
{
Part currentTank = startTank;
tanksToConnect.Remove (startTank);
ASPConsoleStuff.printPart ("=== makeFuelLineChain, starting at", currentTank);
if (currentTank == null) {
ASPConsoleStuff.print ("makeFuelLineChain passed a null part!");
return null;
}
// 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 {
if (!AttachFuelLine (currentTank, parentTank, ap, textureNum, texturePath, textureDisplayName)) {
tanksToConnect = new List<Part> ();
return null;
}
}
// Decide on fuel line chain length (not including fuel line to parent fuel tank we just did)
// 10-way symmetry will have (10-2)/2 = 4 for each side
// 8-way symmetry will have (8-2)/2 = 3 for each side
// 6-way symmetry will have (6-2)/2 = 2 for each side
// 4-way symmetry will have (4-2)/2 = 1 for each side
// 2-way symmetry will have (2-2)/2 = 0 for each side (we will just connect the tanks to the central tank)
int tanksToDropAtOnce = 2;
int[] primes = new int[] {
17,
13,
11,
7,
5,
3,
2,
};
foreach (int prime in primes) {
ASPConsoleStuff.AAprint ("Testing prime " + prime.ToString ());
if ((numberOfTanks % prime) == 0) {
tanksToDropAtOnce = prime;
}
}
int chainLength = (numberOfTanks / tanksToDropAtOnce - 1);
ASPConsoleStuff.AAprint ("Fuel line chain length: " + chainLength.ToString () + ", dropping " + tanksToDropAtOnce.ToString () + " tanks at once (from " + numberOfTanks.ToString () + " tanks)");
// Now connect chainLength number of tanks to the first part
int currentChainLength = chainLength;
Part lastTank = currentTank;
Part nextTank = null;
int safetyfactor = 10000;
while (currentChainLength > 0) {
safetyfactor = safetyfactor - 1;
if (safetyfactor == 0) {
AutoAsparagus.osd ("Infinite loop in makeFuelLineChain, aborting :(");
AutoAsparagus.mystate = AutoAsparagus.ASPState.ERROR;
return null;
}
ASPConsoleStuff.printPart ("connecting chain link #" + currentChainLength.ToString (), currentTank);
nextTank = nearestNeighborWithoutFuelLine (currentTank, ap.name, tanksToConnect);
if (nextTank == null) {
ASPConsoleStuff.printPart ("no nearestNeighborWithoutFuelLine found! Not connecting", currentTank);
} else {
// we're working backwards, away from central tank, so we connect the new tank to the existing one
if (!AttachFuelLine (nextTank, currentTank, ap, textureNum, texturePath, textureDisplayName)) {
tanksToConnect = new List<Part> ();
return null;
}
lastTank = nextTank;
currentTank = nextTank;
tanksToConnect.Remove (currentTank);
}
currentChainLength = currentChainLength - 1;
}
// return the tank for the next chain
ASPConsoleStuff.printPart ("lastTank=", lastTank);
nextTank = nearestNeighborWithoutFuelLine (lastTank, ap.name, tanksToConnect);
ASPConsoleStuff.printPart ("Should start next chain with", nextTank);
return nextTank;
}