public void CalculateMass()
        {
            if (tankList == null || !massDirty)
            {
                return;
            }
            massDirty = false;

            double basemass = basemassConst + basemassPV * volume;

            if (basemass >= 0)
            {
                double tankDryMass = tankList
                                     .Where(fuel => fuel.maxAmount > 0 && fuel.utilization > 0)
                                     .Sum(fuel => (float)fuel.maxAmount * fuel.mass / fuel.utilization);

                mass = (float)(basemass + tankDryMass) * MassMult;

                if (part.mass != mass)
                {
                    part.mass = mass;
                    MassChanged(mass);
                    // compute massDelta based on prefab, if available.
                    if ((object)(part.partInfo) != null)
                    {
                        if ((object)(part.partInfo.partPrefab) != null)
                        {
                            massDelta = part.mass - part.partInfo.partPrefab.mass;
                        }
                    }
                }
            }
            else
            {
                mass = part.mass;                 // display dry mass even in this case.
            }

            if (isEditor)
            {
                UsedVolume = tankList
                             .Where(fuel => fuel.maxAmount > 0 && fuel.utilization > 0)
                             .Sum(fuel => fuel.maxAmount / fuel.utilization);

                SIPrefix pfx = volume.GetSIPrefix();
                Func <double, string> formatter = pfx.GetFormatter(volume);
                volumeDisplay = "Avail: " + formatter(AvailableVolume) + pfx.PrefixString() + MFSSettings.unitLabel + " / Tot: " + formatter(volume) + pfx.PrefixString() + MFSSettings.unitLabel;

                double resourceMass = part.Resources.Cast <PartResource> ().Sum(r => r.maxAmount * r.info.density);

                double wetMass = mass + resourceMass;
                massDisplay = "Dry: " + FormatMass(mass) + " / Wet: " + FormatMass((float)wetMass);

                UpdateTweakableMenu();
            }
        }
        public override void UpdateItem()
        {
            base.UpdateItem();

            SIPrefix prefix = (resource.maxAmount).GetSIPrefix();
            // ReSharper disable once InconsistentNaming
            Func <double, string> Formatter = prefix.GetFormatter(resource.maxAmount, sigFigs: 4);

            resourceMax.Text  = Formatter(resource.maxAmount) + " " + prefix.PrefixString();
            resourceAmnt.Text = Formatter(resource.amount);

            oldSliderValue = slider.Value = (float)(resource.amount / resource.maxAmount);
        }
Example #3
0
 internal static string FormatSI(this SIPrefix pfx, double value, int sigFigs = 3, int exponent = 0, string unit = null)
 {
     return(string.Format("{0}{1}{2}", pfx.GetFormatter(value, sigFigs, exponent)(value), pfx.PrefixString(), unit));
 }