Ejemplo n.º 1
0
        /// <summary>
        /// Gets the resource content percentage on the current planet.
        /// Takes a CrustalResource as a parameter.
        /// Returns boolean true if the data was gotten without trouble and also returns a double with the percentage.
        /// </summary>
        /// <param name="currentResource">A CrustalResource we want to get the percentage for.</param>
        /// <param name="globalPercentage">An output parameter, returns the resource content percentage on the current planet.</param>
        /// <returns></returns>
        private CrustalResourceAbundance GetResourceAbundance(CrustalResource currentResource)
        {
            var abundance = new CrustalResourceAbundance()
            {
                Resource = currentResource
            };

            if (currentResource != null)
            {
                try
                {
                    abundance.Local = GetAbundance(new AbundanceRequest()
                    {
                        ResourceType = HarvestTypes.Planetary,
                        ResourceName = currentResource.ResourceName,
                        BodyId       = FlightGlobals.currentMainBody.flightGlobalsIndex,
                        Latitude     = FlightGlobals.ship_latitude,
                        Longitude    = FlightGlobals.ship_longitude,
                        CheckForLock = false
                    });
                }
                catch (Exception)
                {
                    Console.WriteLine("[KSPI]: UniversalCrustExtractor - Error while retrieving crustal resource percentage for " + currentResource.ResourceName + " from CrustalResourceHandler. Setting to zero.");
                    return(null); // if the percentage was not gotten correctly, we want to know, so return false
                }

                return(abundance); // if we got here, the percentage-getting went well, so return true
            }
            else
            {
                Console.WriteLine("[KSPI]: UniversalCrustExtractor - Error while calculating percentage, resource null. Setting to zero.");
                return(null); // resource was null, we want to know that we should disregard it, so return false
            }
        }
        /// <summary>
        /// Gets the resource content percentage on the current planet.
        /// Takes a CrustalResource as a parameter.
        /// Returns boolean true if the data was gotten without trouble and also returns a double with the percentage.
        /// </summary>
        /// <param name="currentResource">A CrustalResource we want to get the percentage for.</param>
        /// <param name="globalPercentage">An output parameter, returns the resource content percentage on the current planet.</param>
        /// <returns></returns>
        private CrustalResourceAbundance GetResourceAbundance(CrustalResource currentResource)
        {
            var abundance = new CrustalResourceAbundance()
            {
                Resource = currentResource
            };

            if (currentResource != null)
            {
                var definition = PartResourceLibrary.Instance.GetDefinition(currentResource.ResourceName);
                try
                {
                    abundance.GlobalWithVariance = GetAbundance(new AbundanceRequest()
                    {
                        ResourceType = HarvestTypes.Planetary,
                        ResourceName = currentResource.ResourceName,
                        BodyId       = FlightGlobals.currentMainBody.flightGlobalsIndex,
                        CheckForLock = false
                    });

                    abundance.GlobalWithoutVariance = GetAbundance(new AbundanceRequest()
                    {
                        ResourceType    = HarvestTypes.Planetary,
                        ResourceName    = currentResource.ResourceName,
                        BodyId          = FlightGlobals.currentMainBody.flightGlobalsIndex,
                        CheckForLock    = false,
                        ExcludeVariance = true,
                    });

                    abundance.Local = GetAbundance(new AbundanceRequest()
                    {
                        ResourceType = HarvestTypes.Planetary,
                        ResourceName = currentResource.ResourceName,
                        BodyId       = FlightGlobals.currentMainBody.flightGlobalsIndex,
                        Latitude     = FlightGlobals.ship_latitude,
                        Longitude    = FlightGlobals.ship_longitude,
                        CheckForLock = false
                    });

                    var biome_attribute = part.vessel.mainBody.BiomeMap.GetAtt(FlightGlobals.ship_latitude, FlightGlobals.ship_longitude);
                    if (biome_attribute != null)
                    {
                        abundance.Biome = GetAbundance(new AbundanceRequest()
                        {
                            ResourceType = HarvestTypes.Planetary,
                            ResourceName = currentResource.ResourceName,
                            BodyId       = FlightGlobals.currentMainBody.flightGlobalsIndex,
                            BiomeName    = biome_attribute.name,
                            CheckForLock = false
                        });
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("[KSPI] - UniversalCrustExtractor - Error while retrieving crustal resource percentage for " + currentResource.ResourceName + " from CrustalResourceHandler. Setting to zero.");
                    return(null); // if the percentage was not gotten correctly, we want to know, so return false
                }

                return(abundance); // if we got here, the percentage-getting went well, so return true
            }
            else
            {
                Console.WriteLine("[KSPI] - UniversalCrustExtractor - Error while calculating percentage, resource null. Setting to zero.");
                return(null); // resource was null, we want to know that we should disregard it, so return false
            }
        }