Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }