public static PartSim New(Part thePart, int id, double atmosphere, LogMsg log) { PartSim partSim = pool.Borrow(); partSim.part = thePart; partSim.centerOfMass = thePart.transform.TransformPoint(thePart.CoMOffset); partSim.partId = id; partSim.name = partSim.part.partInfo.name; if (log != null) { log.buf.AppendLine("Create PartSim for " + partSim.name); } partSim.parent = null; partSim.parentAttach = partSim.part.attachMode; partSim.fuelCrossFeed = partSim.part.fuelCrossFeed; partSim.noCrossFeedNodeKey = partSim.part.NoCrossFeedNodeKey; partSim.decoupledInStage = partSim.DecoupledInStage(partSim.part); partSim.isFuelLine = partSim.part.HasModule <CModuleFuelLine>(); partSim.isFuelTank = partSim.part is FuelTank; partSim.isSepratron = partSim.IsSepratron(); partSim.isFairing = partSim.IsFairing(partSim.part); partSim.inverseStage = partSim.part.inverseStage; //MonoBehaviour.print("inverseStage = " + inverseStage); partSim.baseCost = partSim.part.GetCostDry(); if (log != null) { log.buf.AppendLine("Parent part = " + (partSim.part.parent == null ? "null" : partSim.part.parent.partInfo.name)); log.buf.AppendLine("physicalSignificance = " + partSim.part.physicalSignificance); log.buf.AppendLine("PhysicsSignificance = " + partSim.part.PhysicsSignificance); } // Work out if the part should have no physical significance // The root part is never "no physics" partSim.isNoPhysics = partSim.part.physicalSignificance == Part.PhysicalSignificance.NONE || partSim.part.PhysicsSignificance == 1; if (partSim.part.HasModule <LaunchClamp>()) { partSim.realMass = 0d; if (log != null) { log.buf.AppendLine("Ignoring mass of launch clamp"); } } else { partSim.realMass = partSim.part.mass; if (log != null) { log.buf.AppendLine("Using part.mass of " + partSim.part.mass); } } if (partSim.isFairing) { partSim.fairingMass = partSim.part.GetModuleMass((float)partSim.realMass); } for (int i = 0; i < partSim.part.Resources.Count; i++) { PartResource resource = partSim.part.Resources[i]; // Make sure it isn't NaN as this messes up the part mass and hence most of the values // This can happen if a resource capacity is 0 and tweakable if (!Double.IsNaN(resource.amount)) { if (log != null) { log.buf.AppendLine(resource.resourceName + " = " + resource.amount); } partSim.resources.Add(resource.info.id, resource.amount); partSim.resourceFlowStates.Add(resource.info.id, resource.flowState ? 1 : 0); } else { if (log != null) { log.buf.AppendLine(resource.resourceName + " is NaN. Skipping."); } } } partSim.hasVessel = (partSim.part.vessel != null); partSim.isLanded = partSim.hasVessel && partSim.part.vessel.Landed; if (partSim.hasVessel) { partSim.vesselName = partSim.part.vessel.vesselName; partSim.vesselType = partSim.part.vesselType; } partSim.initialVesselName = partSim.part.initialVesselName; partSim.hasMultiModeEngine = partSim.part.HasModule <MultiModeEngine>(); partSim.hasModuleEngines = partSim.part.HasModule <ModuleEngines>(); partSim.isEngine = partSim.hasMultiModeEngine || partSim.hasModuleEngines; if (log != null) { log.buf.AppendLine("Created " + partSim.name + ". Decoupled in stage " + partSim.decoupledInStage); } return(partSim); }