示例#1
0
 private void SetSingleActivationInfo()
 {
     if (PartExtensions.HasModule <ModuleAnimateGeneric>(selectedPart, m => m.isOneShot))
     {
         infoItems.Add(PartInfoItem.Create("Single Activation"));
     }
 }
示例#2
0
 private void SetSasInfo()
 {
     if (PartExtensions.HasModule <ModuleSAS>(selectedPart))
     {
         infoItems.Add(PartInfoItem.Create("SAS Equiped"));
     }
 }
示例#3
0
 private void SetScienceContainerInfo()
 {
     if (PartExtensions.HasModule <ModuleScienceContainer>(selectedPart))
     {
         infoItems.Add(PartInfoItem.Create("Science Container"));
     }
 }
示例#4
0
        public static PartSim New(Part p, int id, double atmosphere, LogMsg log)
        {
            PartSim partSim = pool.Borrow();

            partSim.part         = p;
            partSim.centerOfMass = p.transform.TransformPoint(p.CoMOffset);
            partSim.partId       = id;
            partSim.name         = p.partInfo.name;

            if (log != null)
            {
                log.AppendLine("Create PartSim for ", partSim.name);
            }

            partSim.parent             = null;
            partSim.parentAttach       = p.attachMode;
            partSim.fuelCrossFeed      = p.fuelCrossFeed;
            partSim.noCrossFeedNodeKey = p.NoCrossFeedNodeKey;
            partSim.isEnginePlate      = IsEnginePlate(p);
            if (partSim.isEnginePlate)
            {
                partSim.noCrossFeedNodeKey = "bottom"; //sadly this only works in one direction.
            }
            partSim.decoupledInStage = partSim.DecoupledInStage(p);
            partSim.isFuelLine       = PartExtensions.HasModule <CModuleFuelLine>(p);
            partSim.isRCS            = PartExtensions.HasModule <ModuleRCS>(p) || PartExtensions.HasModule <ModuleRCSFX>(p); //I don't think it checks inheritance.
            partSim.isSepratron      = PartExtensions.IsSepratron(p);
            partSim.inverseStage     = p.inverseStage;
            if (log != null)
            {
                log.AppendLine("inverseStage = ", partSim.inverseStage);
            }
            partSim.resPriorityOffset = p.resourcePriorityOffset;
            partSim.resPriorityUseParentInverseStage = p.resourcePriorityUseParentInverseStage;
            partSim.resRequestRemainingThreshold     = p.resourceRequestRemainingThreshold;

            partSim.baseCost = PartExtensions.GetCostDry(p);

            if (log != null)
            {
                log.AppendLine("Parent part = ", (p.parent == null ? "null" : p.parent.partInfo.name))
                .AppendLine("physicalSignificance = ", p.physicalSignificance)
                .AppendLine("PhysicsSignificance = ", p.PhysicsSignificance);
            }

            // Work out if the part should have no physical significance
            // The root part is never "no physics"
            partSim.isNoPhysics = p.physicalSignificance == Part.PhysicalSignificance.NONE ||
                                  p.PhysicsSignificance == 1;

            if (PartExtensions.HasModule <LaunchClamp>(p))
            {
                partSim.realMass = 0d;
                if (log != null)
                {
                    log.AppendLine("Ignoring mass of launch clamp");
                }
            }
            else
            {
                partSim.crewMassOffset = PartExtensions.getCrewAdjustment(p);
                partSim.realMass       = p.mass + partSim.crewMassOffset;

                if (log != null)
                {
                    log.AppendLine("Using part.mass of " + partSim.realMass);
                }
            }

            partSim.postStageMassAdjust = 0f;
            if (log != null)
            {
                log.AppendLine("Calculating postStageMassAdjust, prefabMass = ", p.prefabMass);
            }
            int count = p.Modules.Count;

            for (int i = 0; i < count; i++)
            {
                if (log != null)
                {
                    log.AppendLine("Module: ", p.Modules[i].moduleName);
                }
                IPartMassModifier partMassModifier = p.Modules[i] as IPartMassModifier;
                if (partMassModifier != null)
                {
                    if (log != null)
                    {
                        log.AppendLine("ChangeWhen = ", partMassModifier.GetModuleMassChangeWhen());
                    }
                    if (partMassModifier.GetModuleMassChangeWhen() == ModifierChangeWhen.STAGED)
                    {
                        float preStage  = partMassModifier.GetModuleMass(p.prefabMass, ModifierStagingSituation.UNSTAGED);
                        float postStage = partMassModifier.GetModuleMass(p.prefabMass, ModifierStagingSituation.STAGED);
                        if (log != null)
                        {
                            log.AppendLine("preStage = ", preStage, "   postStage = ", postStage);
                        }
                        partSim.postStageMassAdjust += (postStage - preStage);
                    }
                }
            }

            if (log != null)
            {
                log.AppendLine("postStageMassAdjust = ", partSim.postStageMassAdjust);
            }
            if (log != null)
            {
                log.AppendLine("crewMassOffset = ", partSim.crewMassOffset);
            }

            for (int i = 0; i < p.Resources.Count; i++)
            {
                PartResource resource = p.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.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.AppendLine(resource.resourceName, " is NaN. Skipping.");
                    }
                }
            }

            partSim.hasVessel = (p.vessel != null);
            partSim.isLanded  = partSim.hasVessel && p.vessel.Landed;
            if (partSim.hasVessel)
            {
                partSim.vesselName = p.vessel.vesselName;
                partSim.vesselType = p.vesselType;
            }
            partSim.initialVesselName = p.initialVesselName;

            partSim.hasMultiModeEngine = PartExtensions.HasModule <MultiModeEngine>(p);
            partSim.hasModuleEngines   = PartExtensions.HasModule <ModuleEngines>(p);

            partSim.isEngine = partSim.hasMultiModeEngine || partSim.hasModuleEngines;

            if (log != null)
            {
                log.AppendLine("Created ", partSim.name, ". Decoupled in stage ", partSim.decoupledInStage);
            }

            return(partSim);
        }