--- a/KerbalEngineer/VesselSimulator/PartSim.cs +++ b/KerbalEngineer/VesselSimulator/PartSim.cs @@ -42,6 +42,7 @@ public int decoupledInStage; public bool fuelCrossFeed; public List fuelTargets = new List(); + public List surfaceMountFuelTargets = new List(); public bool hasModuleEngines; public bool hasMultiModeEngine; @@ -416,11 +417,7 @@ mass += resources.GetResourceMass(resources.Types[i]); } - if (hasVessel == false && isFairing && currentStage > inverseStage) - { - mass += fairingMass; - } - else if (hasVessel && isFairing && currentStage <= inverseStage) + if (isFairing && currentStage <= inverseStage) { mass -= fairingMass; } @@ -451,7 +448,7 @@ // All functions below this point must not rely on the part member (it may be null) // - public void GetSourceSet(int type, List allParts, HashSet visited, HashSet allSources, LogMsg log, String indent) + public void GetSourceSet(int type, bool includeSurfaceMountedParts, List allParts, HashSet visited, HashSet allSources, LogMsg log, String indent) { if (log != null) { @@ -489,7 +486,29 @@ { if (log != null) log.buf.AppendLine(indent + "Adding fuel target as source (" + partSim.name + ":" + partSim.partId + ")"); - partSim.GetSourceSet(type, allParts, visited, allSources, log, indent); + partSim.GetSourceSet(type, includeSurfaceMountedParts, allParts, visited, allSources, log, indent); + } + } + } + + // check surface mounted fuel targets + if (includeSurfaceMountedParts) + { + for (int i = 0; i < surfaceMountFuelTargets.Count; i++) + { + PartSim partSim = this.surfaceMountFuelTargets[i]; + if (partSim != null) + { + if (visited.Contains(partSim)) + { + if (log != null) log.buf.AppendLine(indent + "Fuel target already visited, skipping (" + partSim.name + ":" + partSim.partId + ")"); + } + else + { + if (log != null) log.buf.AppendLine(indent + "Adding fuel target as source (" + partSim.name + ":" + partSim.partId + ")"); + + partSim.GetSourceSet(type, true, allParts, visited, allSources, log, indent); + } } } } @@ -519,9 +538,7 @@ { if (attachSim.nodeType == AttachNode.NodeType.Stack) { - if ( - !(this.noCrossFeedNodeKey != null && this.noCrossFeedNodeKey.Length > 0 && - attachSim.id.Contains(this.noCrossFeedNodeKey))) + if ((string.IsNullOrEmpty(noCrossFeedNodeKey) == false && attachSim.id.Contains(noCrossFeedNodeKey)) == false) { if (visited.Contains(attachSim.attachedPartSim)) { @@ -531,7 +548,7 @@ { if (log != null) log.buf.AppendLine(indent + "Adding attached part as source (" + attachSim.attachedPartSim.name + ":" + attachSim.attachedPartSim.partId + ")"); - attachSim.attachedPartSim.GetSourceSet(type, allParts, visited, allSources, log, indent); + attachSim.attachedPartSim.GetSourceSet(type, includeSurfaceMountedParts, allParts, visited, allSources, log, indent); } } } @@ -549,7 +566,7 @@ // type was not disabled [Experiment]) and it contains fuel, it returns itself. // Rule 6: 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) but it does not contain the requested fuel, it returns empty list. [Experiment] - if (resources.HasType(type) && resourceFlowStates[type] != 0) + if (resources.HasType(type) && resourceFlowStates[type] > 0.0) { if (resources[type] > SimManager.RESOURCE_MIN) { @@ -578,7 +595,7 @@ else { lastCount = allSources.Count; - this.parent.GetSourceSet(type, allParts, visited, allSources, log, indent); + this.parent.GetSourceSet(type, includeSurfaceMountedParts, allParts, visited, allSources, log, indent); if (allSources.Count > lastCount) { if (log != null) log.buf.AppendLine(indent + "Returning " + (allSources.Count - lastCount) + " parent sources (" + this.name + ":" + this.partId + ")"); @@ -681,6 +698,11 @@ if (partSimLookup.TryGetValue(part.parent, out parent)) { if (log != null) log.buf.AppendLine("Parent part is " + parent.name + ":" + parent.partId); + if (part.attachMode == AttachModes.SRF_ATTACH && part.attachRules.srfAttach && part.fuelCrossFeed && part.parent.fuelCrossFeed) + { + if (log != null) log.buf.AppendLine("Added " + name + " to " + parent.name + " surface mounted fuel targets."); + parent.surfaceMountFuelTargets.Add(this); + } } else {