Inheritance: PartModule, IPartCostModifier, IPartMassModifier
 public static void closeGUI()
 {
     module.closeGUI();
     module = null;
     containers = null;
     resourceEntries = null;
 }
Beispiel #2
0
        public void Start()
        {
            //TODO update resource volume for current setup
            SSTUVolumeContainer vc = part.GetComponent <SSTUVolumeContainer>();

            if (vc != null)
            {
            }
        }
Beispiel #3
0
 public bool isAvailable(SSTUVolumeContainer module)
 {
     if (string.IsNullOrEmpty(unlockName))
     {
         return(true);
     }
     return(PartUpgradeManager.Handler.IsUnlocked(unlockName));
     //return string.IsNullOrEmpty(unlockName)? true : module.upgradesApplied.Contains(unlockName);
 }
Beispiel #4
0
        public static void onContainerUpdated(SSTUVolumeContainer container)
        {
            int len = containerUpdatedCallbacks.Count;

            for (int i = 0; i < len; i++)
            {
                containerUpdatedCallbacks[i].Invoke(container);
            }
        }
        public void setFromContainer(SSTUVolumeContainer container)
        {
            ContainerDefinition highestVolume = container.highestVolumeContainer(data.name);

            if (container == null)
            {
                MonoBehaviour.print("ERROR: Could not locate volume container definition for resource: " + data.name);
            }
            setFromContainer(highestVolume.currentModifier);
        }
Beispiel #6
0
        public static bool onPartFuelVolumeUpdate(Part part, float liters)
        {
            updateKISPartVolume(part, liters);
            SSTUVolumeContainer vc = part.GetComponent <SSTUVolumeContainer>();

            if (vc != null)
            {
                vc.onVolumeUpdated(liters);
                return(true);
            }
            Type moduleFuelTank = null;

            if (isRFInstalled())
            {
                moduleFuelTank = Type.GetType("RealFuels.Tanks.ModuleFuelTanks,RealFuels");
                if (moduleFuelTank == null)
                {
                    MonoBehaviour.print("ERROR: Set to use RealFuels, and RealFuels is installed, but no RealFuels-ModuleFuelTank PartModule found.");
                    return(false);
                }
            }
            else if (isMFTInstalled())
            {
                moduleFuelTank = Type.GetType("RealFuels.Tanks.ModuleFuelTanks,modularFuelTanks");
                if (moduleFuelTank == null)
                {
                    MonoBehaviour.print("ERROR: Set to use ModularFuelTanks, and ModularFuelTanks is installed, but no ModularFuelTanks-ModuleFuelTank PartModule found.");
                    return(false);
                }
            }
            else
            {
                MonoBehaviour.print("ERROR: Config is for part: " + part + " is set to use RF/MFT, but neither RF nor MFT is installed, cannot update part volumes through them.  Please check your configs and/or patches for errors.");
                return(false);
            }
            PartModule pm = (PartModule)part.GetComponent(moduleFuelTank);

            if (pm == null)
            {
                MonoBehaviour.print("ERROR! Could not find ModuleFuelTank in part for RealFuels/MFT for type: " + moduleFuelTank);
                return(false);
            }
            MethodInfo mi           = moduleFuelTank.GetMethod("ChangeTotalVolume");
            double     volumeLiters = liters;

            mi.Invoke(pm, new System.Object[] { volumeLiters, false });
            MethodInfo mi2 = moduleFuelTank.GetMethod("CalculateMass");

            mi2.Invoke(pm, new System.Object[] { });
            updatePartResourceDisplay(part);
            String message = "SSTUModInterop - Set RF/MFT total tank volume to: " + volumeLiters + " Liters for part: " + part.name;

            MonoBehaviour.print(message);
            return(true);
        }
Beispiel #7
0
        private void updateResourceAmounts(float mult)
        {
            SSTUVolumeContainer vc = part.GetComponent <SSTUVolumeContainer>();

            if (vc != null)
            {
                vc.inflationMultiplier = mult;
            }
            //std call that will update volume container and/or realfuels interop
            SSTUModInterop.updateResourceVolume(part);
        }
Beispiel #8
0
 public void setResourceFillPercent(ContainerDefinition def, string resourceName, float newPercent, bool updateSymmetry = false)
 {
     def.setResourceFillPercent(resourceName, newPercent);
     if (updateSymmetry)
     {
         foreach (Part p in part.symmetryCounterparts)
         {
             SSTUVolumeContainer mod  = p.GetComponent <SSTUVolumeContainer>();
             ContainerDefinition def2 = mod.getContainer(def.name);
             mod.setResourceFillPercent(def2, resourceName, newPercent, false);
         }
     }
 }
Beispiel #9
0
        public void Start()
        {
            //TODO update resource volume for current setup
            SSTUVolumeContainer vc = part.GetComponent <SSTUVolumeContainer>();

            if (vc != null)
            {
                //TODO
                //really, the VC needs to poll other modules for a given interface, or method, or ??
                // and use the volume returned by that for each container index to determine
                // actual volume for each container
            }
        }
Beispiel #10
0
 public void addPresetRatios(ContainerDefinition container, ContainerFuelPreset preset, bool updateSymmetry)
 {
     container.addPresetRatios(preset);
     if (updateSymmetry)
     {
         foreach (Part p in part.symmetryCounterparts)
         {
             SSTUVolumeContainer symmetryModule          = p.GetComponent <SSTUVolumeContainer>();
             ContainerDefinition symmetryModuleContainer = symmetryModule.getContainer(container.name);
             ContainerFuelPreset symmetryModulePreset    = symmetryModuleContainer.internalGetFuelPreset(preset.name);
             symmetryModule.addPresetRatios(symmetryModuleContainer, symmetryModulePreset, false);
         }
     }
 }
Beispiel #11
0
 public void subtractPresetRatios(ContainerDefinition container, ContainerFuelPreset preset, bool updateSymmetry)
 {
     container.subtractPresetRatios(preset);
     if (updateSymmetry)
     {
         foreach (Part p in part.symmetryCounterparts)
         {
             SSTUVolumeContainer mod     = p.GetComponent <SSTUVolumeContainer>();
             ContainerDefinition def2    = mod.getContainer(container.name);
             ContainerFuelPreset preset2 = def2.internalGetFuelPreset(preset.name);
             mod.subtractPresetRatios(def2, preset2, false);
         }
     }
 }
Beispiel #12
0
        private void updateResourceAmounts(float mult)
        {
            SSTUVolumeContainer vc = part.GetComponent <SSTUVolumeContainer>();

            if (vc != null)
            {
                vc.inflationMultiplier = mult;
                vc.recalcVolume();
            }
            else
            {
                SSTUModInterop.updateResourceVolume(part);//call out to RF to update volume; it will obviously lack the inflation multiplier data
            }
        }
Beispiel #13
0
        public void containerTypeUpdated(ContainerDefinition container, ContainerModifier newType, bool updateSymmetry = false)
        {
            container.setModifier(newType);
            updatePartStats();

            if (updateSymmetry)
            {
                foreach (Part p in part.symmetryCounterparts)
                {
                    SSTUVolumeContainer mod  = p.GetComponent <SSTUVolumeContainer>();
                    ContainerDefinition def2 = mod.getContainer(container.name);
                    ContainerModifier   mod2 = def2.internalGetModifier(newType.name);
                    mod.containerTypeUpdated(def2, mod2, false);
                }
            }
        }
        /// <summary>
        /// Updates the min/max quantities of resource in the part based on the current 'totalFuelVolume' field and currently set fuel type
        /// </summary>
        private void updateContainerVolume()
        {
            SSTUVolumeContainer vc = part.GetComponent <SSTUVolumeContainer>();

            if (vc != null)
            {
                float   tankPercent = 100 - supportPercent;
                float   monoPercent = supportPercent;
                float[] pcts        = new float[2];
                pcts[0] = tankPercent * 0.01f;
                pcts[1] = monoPercent * 0.01f;
                vc.setContainerPercents(pcts, totalTankVolume * 1000f);
            }
            else
            {
                //real-fuels handling....
                SSTUModInterop.onPartFuelVolumeUpdate(part, totalTankVolume * 1000f);
            }
        }
Beispiel #15
0
        public static void openGUI(SSTUVolumeContainer container, ContainerDefinition[] modContainers)
        {
            containerIndex = 0;
            module         = container;
            int len = modContainers.Length;
            List <ContainerDefinition> availContainers = new List <ContainerDefinition>();

            for (int i = 0; i < len; i++)
            {
                if (modContainers[i].guiAvailable)// && modContainers[i].rawVolume > 0)
                {
                    availContainers.Add(modContainers[i]);
                }
            }
            containers = availContainers.ToArray();
            id         = module.GetInstanceID();
            statId     = id + 1;
            len        = containers.Length;
            //if nothing is available to adjust, do not open the window
            if (len <= 0)
            {
                closeGUI();
                return;
            }
            resourceEntries = new VolumeRatioEntry[len][];
            string[] names;
            PartResourceDefinition def;

            for (int i = 0; i < len; i++)
            {
                names = containers[i].getResourceNames();
                int len2 = names.Length;
                resourceEntries[i] = new VolumeRatioEntry[len2];
                for (int k = 0; k < len2; k++)
                {
                    def = PartResourceLibrary.Instance.GetDefinition(names[k]);
                    resourceEntries[i][k] = new VolumeRatioEntry(containers[i], names[k], def.displayName, containers[i].getResourceUnitRatio(names[k]));
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Updates the associated VolumeContainer with any changes to part volume from this module
        /// </summary>
        private void updateContainerVolume()
        {
            float liters = calcTotalVolume();
            SSTUVolumeContainer container = part.GetComponent <SSTUVolumeContainer>();

            if (container == null)
            {
                SSTUModInterop.onPartFuelVolumeUpdate(part, liters);
                return;
            }
            int len = container.numberOfContainers;

            float[] percents = new float[len];
            float   total    = liters;
            float   val;

            for (int i = 0; i < len; i++)
            {
                val         = calcVolume(i);
                percents[i] = val / total;
            }
            container.setContainerPercents(percents, total);
        }
Beispiel #17
0
        public static void updateContainerFuelType(FuelTypeISP fuelType, Part part, int containerIndex)
        {
            if (containerIndex < 0)
            {
                return;
            }
            SSTUVolumeContainer vc = part.GetComponent <SSTUVolumeContainer>();

            if (vc == null)
            {
                SSTULog.error("Could not update fuel type - no SSTUVolumeContainer found in part");
                return;
            }
            if (containerIndex < vc.numberOfContainers)
            {
                vc.setFuelPreset(containerIndex, fuelType.fuelPreset, false);
                vc.recalcVolume();
            }
            else
            {
                SSTULog.error("Could not update fuel type - not enough containers in SSTUVolumeContainer for index: " + containerIndex + " only found: " + vc.numberOfContainers);
            }
        }
 public static void openGUI(SSTUVolumeContainer container, ContainerDefinition[] modContainers)
 {
     containerIndex = 0;
     module = container;
     int len = modContainers.Length;
     List<ContainerDefinition> availContainers = new List<ContainerDefinition>();
     for (int i = 0; i < len; i++)
     {
         if (modContainers[i].guiAvailable && modContainers[i].containerPercent > 0)
         {
             availContainers.Add(modContainers[i]);
         }
     }
     containers = availContainers.ToArray();
     id = module.GetInstanceID();
     statId = id + 1;
     len = containers.Length;
     if (len <= 0)
     {
         closeGUI();
         return;
     }
     resourceEntries = new VolumeRatioEntry[len][];
     string[] names;
     PartResourceDefinition def;
     for (int i = 0; i < len; i++)
     {
         names = containers[i].getResourceNames();
         int len2 = names.Length;
         resourceEntries[i] = new VolumeRatioEntry[len2];
         for (int k = 0; k < len2; k++)
         {
             def = PartResourceLibrary.Instance.GetDefinition(names[k]);
             resourceEntries[i][k] = new VolumeRatioEntry(containers[i], names[k], def.title, containers[i].getResourceUnitRatio(names[k]));
         }
     }
 }
Beispiel #19
0
        public static void openGUI(SSTUVolumeContainer container, ContainerDefinition[] modContainers)
        {
            containerIndex = 0;
            module         = container;
            int len = modContainers.Length;
            List <ContainerDefinition> availContainers = new List <ContainerDefinition>();

            for (int i = 0; i < len; i++)
            {
                if (modContainers[i].guiAvailable && modContainers[i].containerPercent > 0)
                {
                    availContainers.Add(modContainers[i]);
                }
            }
            containers = availContainers.ToArray();
            id         = module.GetInstanceID();
            statId     = id + 1;
            len        = containers.Length;
            if (len <= 0)
            {
                closeGUI();
                return;
            }
            resourceEntries = new VolumeRatioEntry[len][];
            string[] names;
            for (int i = 0; i < len; i++)
            {
                names = containers[i].getResourceNames();
                int len2 = names.Length;
                resourceEntries[i] = new VolumeRatioEntry[len2];
                for (int k = 0; k < len2; k++)
                {
                    resourceEntries[i][k] = new VolumeRatioEntry(containers[i], names[k], containers[i].getResourceUnitRatio(names[k]));
                }
            }
        }
Beispiel #20
0
 private void onContainerUpdated(SSTUVolumeContainer vc)
 {
     if (!inflated)
     {
         updateResourceAmounts(deflationMult);
     }
 }
 public void setFromContainer(SSTUVolumeContainer container)
 {
     ContainerDefinition highestVolume = container.highestVolumeContainer(data.name);
     if (container == null)
     {
         MonoBehaviour.print("ERROR: Could not locate volume container definition for resource: " + data.name);
     }
     setFromContainer(highestVolume.currentModifier);
 }
Beispiel #22
0
 public static void onContainerUpdated(SSTUVolumeContainer container)
 {
     int len = containerUpdatedCallbacks.Count;
     for (int i = 0; i < len; i++)
     {
         containerUpdatedCallbacks[i].Invoke(container);
     }
 }
Beispiel #23
0
        public ContainerDefinition(SSTUVolumeContainer module, ConfigNode node)
        {
            this.module            = module;
            name                   = node.GetStringValue("name", name);
            availableResources     = node.GetStringValues("resource");
            resourceSets           = node.GetStringValues("resourceSet");
            tankModifierNames      = node.GetStringValues("modifier");
            configVolume           = volume = node.GetFloatValue("volume", 0);
            tankageVolume          = node.GetFloatValue("tankageVolume");
            tankageMass            = node.GetFloatValue("tankageMass");
            costPerDryTon          = node.GetFloatValue("dryCost", 700f);
            massPerEmptyCubicMeter = node.GetFloatValue("emptyMass", 0.05f);
            defaultFuelPreset      = node.GetStringValue("defaultFuelPreset");
            defaultResources       = node.GetStringValue("defaultResources");
            defaultModifier        = node.GetStringValue("defaultModifier", "standard");
            ecHasMass              = node.GetBoolValue("ecHasMass", ecHasMass);
            ecHasCost              = node.GetBoolValue("ecHasCost", ecHasCost);
            guiAvailable           = node.GetBoolValue("guiAvailable", guiAvailable);
            useStaticVolume        = node.GetBoolValue("useStaticVolume", useStaticVolume);

            if (availableResources.Length == 0 && resourceSets.Length == 0)
            {
                resourceSets = new string[] { "generic" };
            }                                                                                                             //validate that there is some sort of resource reference; generic is a special type for all pumpable resources
            if (tankModifierNames == null || tankModifierNames.Length == 0)
            {
                tankModifierNames = VolumeContainerLoader.getAllModifierNames();
            }                                                                                                                                   //validate that there is at least one modifier type

            //load available container modifiers
            modifiers = VolumeContainerLoader.getModifiersByName(tankModifierNames);

            //setup applicable resources
            List <string> resourceNames = new List <string>();
            int           len           = availableResources.Length;

            for (int i = 0; i < len; i++)
            {
                if (!resourceNames.Contains(availableResources[i]))
                {
                    resourceNames.Add(availableResources[i]);
                }
                else
                {
                    MonoBehaviour.print("ERROR:  Duplicate resource detected for name: " + availableResources[i] + " while loading data for part: " + module.part);
                }
            }
            len = resourceSets.Length;
            int resLen;
            ContainerResourceSet set;

            for (int i = 0; i < len; i++)
            {
                set = VolumeContainerLoader.getResourceSet(resourceSets[i]);
                if (set == null)
                {
                    continue;
                }
                resLen = set.availableResources.Length;
                for (int k = 0; k < resLen; k++)
                {
                    resourceNames.AddUnique(set.availableResources[k]);
                }
            }

            //validate vs part resource library, make sure they are all valid resource entries
            PartResourceLibrary    prl = PartResourceLibrary.Instance;
            PartResourceDefinition prd;

            len = resourceNames.Count;
            for (int i = len - 1; i >= 0; i--)//inverted loop to allow for removal by index while traversing
            {
                prd = prl.GetDefinition(resourceNames[i]);
                if (prd == null)
                {
                    MonoBehaviour.print("ERROR: Could not find resource definition for: " + resourceNames[i] + " while loading data for part: " + module.part + " -- resource removed from VolumeContainer");
                    resourceNames.RemoveAt(i);
                }
            }

            //sort and turn into an array
            resourceNames.Sort();//basic alpha sort...
            applicableResources = resourceNames.ToArray();

            if (string.IsNullOrEmpty(defaultFuelPreset) && string.IsNullOrEmpty(defaultResources) && applicableResources.Length > 0)
            {
                defaultResources = applicableResources[0] + ",1";
            }

            //setup volume data
            len = applicableResources.Length;
            subContainerData = new SubContainerDefinition[len];
            for (int i = 0; i < len; i++)
            {
                subContainerData[i] = new SubContainerDefinition(this, applicableResources[i]);
                if (subContainersByName.ContainsKey(subContainerData[i].name))
                {
                    MonoBehaviour.print("ERROR:  Duplicate resoruce detected for name: " + subContainerData[i].name + " while loading data for part: " + module.part);
                }
                else
                {
                    subContainersByName.Add(subContainerData[i].name, subContainerData[i]);
                }
            }

            //setup preset data
            List <ContainerFuelPreset> usablePresets = new List <ContainerFuelPreset>();

            ContainerFuelPreset[] presets = VolumeContainerLoader.getPresets();
            len = presets.Length;
            for (int i = 0; i < len; i++)
            {
                if (presets[i].applicable(applicableResources))
                {
                    usablePresets.Add(presets[i]);
                }
            }
            fuelPresets         = usablePresets.ToArray();
            currentModifierName = defaultModifier;
            internalInitializeDefaults();
        }
Beispiel #24
0
        public ContainerDefinition(SSTUVolumeContainer module, ConfigNode node, float tankTotalVolume)
        {
            this.module        = module;
            name               = node.GetStringValue("name", name);
            availableResources = node.GetStringValues("resource");
            resourceSets       = node.GetStringValues("resourceSet");
            tankModifierNames  = node.GetStringValues("modifier");
            setContainerPercent(node.GetFloatValue("percent", 1));
            tankageVolume          = node.GetFloatValue("tankageVolume");
            tankageMass            = node.GetFloatValue("tankageMass");
            costPerDryTon          = node.GetFloatValue("dryCost", 700f);
            massPerEmptyCubicMeter = node.GetFloatValue("emptyMass", 0.05f);
            defaultFuelPreset      = node.GetStringValue("defaultFuelPreset");
            defaultResources       = node.GetStringValue("defaultResources");
            defaultModifier        = node.GetStringValue("defaultModifier", "standard");
            ecHasMass    = node.GetBoolValue("ecHasMass", ecHasMass);
            ecHasCost    = node.GetBoolValue("ecHasCost", ecHasCost);
            guiAvailable = node.GetBoolValue("guiAvailable", guiAvailable);

            if (availableResources.Length == 0 && resourceSets.Length == 0)
            {
                resourceSets = new string[] { "generic" };
            }                                                                                                             //validate that there is some sort of resource reference; generic is a special type for all pumpable resources
            if (tankModifierNames == null || tankModifierNames.Length == 0)
            {
                tankModifierNames = VolumeContainerLoader.getAllModifierNames();
            }                                                                                                                                   //validate that there is at least one modifier type

            //load available container modifiers
            modifiers = VolumeContainerLoader.getModifiersByName(tankModifierNames);

            //setup applicable resources
            List <string> resourceNames = new List <string>();

            resourceNames.AddRange(availableResources);
            int len = resourceSets.Length;
            int resLen;
            ContainerResourceSet set;

            for (int i = 0; i < len; i++)
            {
                set = VolumeContainerLoader.getResourceSet(resourceSets[i]);
                if (set == null)
                {
                    continue;
                }
                resLen = set.availableResources.Length;
                for (int k = 0; k < resLen; k++)
                {
                    resourceNames.AddUnique(set.availableResources[k]);
                }
            }
            resourceNames.Sort();//basic alpha sort...
            applicableResources = resourceNames.ToArray();

            if (string.IsNullOrEmpty(defaultFuelPreset) && string.IsNullOrEmpty(defaultResources) && applicableResources.Length > 0)
            {
                defaultResources = applicableResources[0] + ",1";
            }

            //setup volume data
            len = applicableResources.Length;
            subContainerData = new SubContainerDefinition[len];
            for (int i = 0; i < len; i++)
            {
                subContainerData[i] = new SubContainerDefinition(this, applicableResources[i]);
                subContainersByName.Add(subContainerData[i].name, subContainerData[i]);
            }

            //setup preset data
            List <ContainerFuelPreset> usablePresets = new List <ContainerFuelPreset>();

            ContainerFuelPreset[] presets = VolumeContainerLoader.getPresets();
            len = presets.Length;
            for (int i = 0; i < len; i++)
            {
                if (presets[i].applicable(applicableResources))
                {
                    usablePresets.Add(presets[i]);
                }
            }
            fuelPresets         = usablePresets.ToArray();
            currentModifierName = defaultModifier;
            currentRawVolume    = tankTotalVolume * percentOfTankVolume;
            internalInitializeDefaults();
        }