Ejemplo n.º 1
0
        private static void AddMissingResource(string resourname, int refBody, List <CrustalResource> bodyCrustalComposition)
        {
            // verify it is a defined resource
            PartResourceDefinition definition = PartResourceLibrary.Instance.GetDefinition(resourname);

            if (definition == null)
            {
                Debug.LogWarning("[KSPI] - AddMissingResource : Failed to find resource definition for '" + resourname + "'");
                return;
            }

            // skip it already registred or used as a Synonym
            if (bodyCrustalComposition.Any(m => m.ResourceName == definition.name || m.DisplayName == definition.displayName || m.Synonyms.Contains(definition.name)))
            {
                Debug.Log("[KSPI] - AddMissingResource : Already found existing composition for '" + resourname + "'");
                return;
            }

            // retreive abundance
            var abundance = GetAbundance(definition.name, refBody);

            if (abundance <= 0)
            {
                Debug.LogWarning("[KSPI] - AddMissingResource : Abundance for resource '" + resourname + "' was " + abundance);
                //return;
            }

            // create Crustalresource from definition and abundance
            var CrustalResource = new CrustalResource(definition, abundance);

            // add to Crustal composition
            Debug.Log("[KSPI] - AddMissingResource : add resource '" + resourname + "'");
            bodyCrustalComposition.Add(CrustalResource);
        }
Ejemplo n.º 2
0
        public static double getCrustalResourceContent(int refBody, string resourcename)
        {
            List <CrustalResource> bodyCrustalComposition = GetCrustalCompositionForBody(refBody);

            CrustalResource resource = bodyCrustalComposition.FirstOrDefault(oor => oor.ResourceName == resourcename);

            return(resource != null ? resource.ResourceAbundance : 0);
        }
Ejemplo n.º 3
0
        private static void AddResource(int refBody, List <CrustalResource> bodyCrustalComposition, string outputResourname, string inputResource1, string inputResource2, string inputResource3, string displayname)
        {
            var abundances = new[] { GetAbundance(inputResource1, refBody), GetAbundance(inputResource2, refBody), GetAbundance(inputResource2, refBody) };

            var CrustalResource = new CrustalResource(outputResourname, abundances.Max(), displayname, new[] { inputResource1, inputResource2, inputResource3 });

            if (CrustalResource.ResourceAbundance > 0)
            {
                var existingResource = bodyCrustalComposition.FirstOrDefault(a => a.ResourceName == outputResourname);
                if (existingResource != null)
                {
                    Debug.Log("[KSPI] - replaced resource " + outputResourname + " with stock defined abundance " + CrustalResource.ResourceAbundance);
                    bodyCrustalComposition.Remove(existingResource);
                }
                bodyCrustalComposition.Add(CrustalResource);
            }
        }
Ejemplo n.º 4
0
        private static void AddResource(string outputResourname, string displayname, int refBody, List <CrustalResource> bodyCrustalComposition, string[] variants)
        {
            var abundances = new[] { GetAbundance(outputResourname, refBody) }.Concat(variants.Select(m => GetAbundance(m, refBody)));

            var CrustalResource = new CrustalResource(outputResourname, abundances.Max(), displayname, variants);

            if (CrustalResource.ResourceAbundance > 0)
            {
                var existingResource = bodyCrustalComposition.FirstOrDefault(a => a.ResourceName == outputResourname);
                if (existingResource != null)
                {
                    Debug.Log("[KSPI] - replaced resource " + outputResourname + " with stock defined abundance " + CrustalResource.ResourceAbundance);
                    bodyCrustalComposition.Remove(existingResource);
                }
                bodyCrustalComposition.Add(CrustalResource);
            }
        }