public void RemoveAttachedParts(HashSet <PartSim> partSims) { // Loop through the attached parts for (int i = 0; i < this.attachNodes.Count; i++) { AttachNodeSim attachSim = this.attachNodes[i]; // If the part is in the set then "remove" it by clearing the PartSim reference if (partSims.Contains(attachSim.attachedPartSim)) { attachSim.attachedPartSim = null; } } // Loop through the fuel targets (fuel line sources) for (int i = 0; i < this.fuelTargets.Count; i++) { PartSim fuelTargetSim = this.fuelTargets[i]; // If the part is in the set then "remove" it by clearing the PartSim reference if (fuelTargetSim != null && partSims.Contains(fuelTargetSim)) { this.fuelTargets[i] = null; } } // Loop through the surface attached fuel targets (surface attached parts for new flow modes) for (int i = 0; i < this.surfaceMountFuelTargets.Count; i++) { PartSim fuelTargetSim = this.surfaceMountFuelTargets[i]; // If the part is in the set then "remove" it by clearing the PartSim reference if (fuelTargetSim != null && partSims.Contains(fuelTargetSim)) { this.surfaceMountFuelTargets[i] = null; } } }
public static AttachNodeSim New(PartSim partSim, String newId, AttachNode.NodeType newNodeType) { AttachNodeSim nodeSim = pool.Borrow(); nodeSim.attachedPartSim = partSim; nodeSim.nodeType = newNodeType; nodeSim.id = newId; return(nodeSim); }
static private void Reset(AttachNodeSim attachNodeSim) { attachNodeSim.attachedPartSim = null; }
public void SetupAttachNodes(Dictionary <Part, PartSim> partSimLookup, LogMsg log) { if (log != null) { log.AppendLine("SetupAttachNodes for ", name, ":", partId); } attachNodes.Clear(); for (int i = 0; i < part.attachNodes.Count; ++i) { AttachNode attachNode = part.attachNodes[i]; if (log != null) { log.AppendLine("AttachNode ", attachNode.id, " = ", (attachNode.attachedPart != null ? attachNode.attachedPart.partInfo.name : "null")); } if (attachNode.attachedPart != null && attachNode.id != "Strut") { PartSim attachedSim; if (partSimLookup.TryGetValue(attachNode.attachedPart, out attachedSim)) { if (log != null) { log.AppendLine("Adding attached node ", attachedSim.name, ":", attachedSim.partId); } attachNodes.Add(AttachNodeSim.New(attachedSim, attachNode.id, attachNode.nodeType)); } else { if (log != null) { log.AppendLine("No PartSim for attached part (", attachNode.attachedPart.partInfo.name, ")"); } } } } for (int i = 0; i < part.fuelLookupTargets.Count; ++i) { Part p = part.fuelLookupTargets[i]; if (p != null) { PartSim targetSim; if (partSimLookup.TryGetValue(p, out targetSim)) { if (log != null) { log.AppendLine("Fuel target: ", targetSim.name, ":", targetSim.partId); } fuelTargets.Add(targetSim); } else { if (log != null) { log.AppendLine("No PartSim for fuel target (", p.name, ")"); } } } } }
public void GetSourceSet_Internal(int type, bool includeSurfaceMountedParts, List <PartSim> allParts, HashSet <PartSim> visited, HashSet <PartSim> allSources, bool checkMax, ref int priMax, LogMsg log, String indent) { if (log != null) { log.Append(indent, "GetSourceSet_Internal(", ResourceContainer.GetResourceName(type), ") for ") .AppendLine(name, ":", partId); indent += " "; } // Rule 1: Each part can be only visited once, If it is visited for second time in particular search it returns as is. if (visited.Contains(this)) { if (log != null) { log.Append(indent, "Nothing added, already visited (", name, ":") .AppendLine(partId + ")"); } return; } if (log != null) { log.AppendLine(indent, "Adding this to visited"); } visited.Add(this); // Rule 2: Part performs scan on start of every fuel pipe ending in it. This scan is done in order in which pipes were installed. // Then it makes an union of fuel tank sets each pipe scan returned. If the resulting list is not empty, it is returned as result. //MonoBehaviour.print("for each fuel line"); int lastCount = allSources.Count; for (int i = 0; i < this.fuelTargets.Count; i++) { PartSim partSim = this.fuelTargets[i]; if (partSim != null) { if (visited.Contains(partSim)) { if (log != null) { log.Append(indent, "Fuel target already visited, skipping (", partSim.name, ":") .AppendLine(partSim.partId, ")"); } } else { if (log != null) { log.Append(indent, "Adding fuel target as source (", partSim.name, ":") .AppendLine(partSim.partId, ")"); } partSim.GetSourceSet_Internal(type, includeSurfaceMountedParts, allParts, visited, allSources, checkMax, ref priMax, log, indent); } } } if (fuelCrossFeed) { if (includeSurfaceMountedParts) { // check surface mounted fuel targets for (int i = 0; i < surfaceMountFuelTargets.Count; i++) { PartSim partSim = this.surfaceMountFuelTargets[i]; if (partSim != null) { if (visited.Contains(partSim)) { if (log != null) { log.Append(indent, "Surface part already visited, skipping (", partSim.name, ":") .AppendLine(partSim.partId, ")"); } } else { if (log != null) { log.Append(indent, "Adding surface part as source (", partSim.name, ":") .AppendLine(partSim.partId, ")"); } partSim.GetSourceSet_Internal(type, includeSurfaceMountedParts, allParts, visited, allSources, checkMax, ref priMax, log, indent); } } } } lastCount = allSources.Count; //MonoBehaviour.print("for each attach node"); for (int i = 0; i < this.attachNodes.Count; i++) { AttachNodeSim attachSim = this.attachNodes[i]; if (attachSim.attachedPartSim != null) { if (attachSim.nodeType == AttachNode.NodeType.Stack) { if ((string.IsNullOrEmpty(noCrossFeedNodeKey) == false && attachSim.id.Contains(noCrossFeedNodeKey)) == false) { if (visited.Contains(attachSim.attachedPartSim)) { if (log != null) { log.Append(indent, "Attached part already visited, skipping (", attachSim.attachedPartSim.name, ":") .AppendLine(attachSim.attachedPartSim.partId, ")"); } } else { bool flg = true; if (attachSim.attachedPartSim.isEnginePlate) //y u make me do dis. { foreach (AttachNodeSim att in attachSim.attachedPartSim.attachNodes) { if (att.attachedPartSim == this && att.id == "bottom") { flg = false; } } } if (flg) { if (log != null) { log.Append(indent, "Adding attached part as source (", attachSim.attachedPartSim.name, ":") .AppendLine(attachSim.attachedPartSim.partId, ")"); } attachSim.attachedPartSim.GetSourceSet_Internal(type, includeSurfaceMountedParts, allParts, visited, allSources, checkMax, ref priMax, log, indent); } } } } } } } // If the part is fuel container for searched type of fuel (i.e. it has capability to contain that type of fuel and the fuel // type was not disabled) and it contains fuel, it adds itself. if (checkMax ? (maxResources.HasType(type)) : (resources.HasType(type) && resourceFlowStates[type] > 0.0)) { if (checkMax ? (maxResources[type] > SimManager.RESOURCE_MIN) : (resources[type] > resRequestRemainingThreshold)) { // Get the priority of this tank int pri = GetResourcePriority(); if (pri > priMax) { // This tank is higher priority than the previously added ones so we clear the sources // and set the priMax to this priority allSources.Clear(); priMax = pri; } // If this is the correct priority then add this to the sources if (pri == priMax) { if (log != null) { log.Append(indent, "Adding enabled tank as source (", name, ":") .AppendLine(partId, ")"); } allSources.Add(this); } } } else { if (log != null) { log.Append(indent, "Not fuel tank or disabled. HasType = ", resources.HasType(type)) .AppendLine(" FlowState = " + resourceFlowStates[type]); } } }