Exemple #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
            }
        }
Exemple #2
0
        /// <summary>
        /// Calculates the spare room for the current resource on the vessel.
        /// </summary>
        /// <param name="resourceName"></param>
        /// <returns>Double, signifying the amount of spare room for the resource on the vessel.</returns>
        private double CalculateSpareRoom(CrustalResource resource)
        {
            double currentAmount;
            double maxAmount;

            part.GetConnectedResourceTotals(resource.Definition.id, out currentAmount, out maxAmount);

            resource.Amount    = currentAmount;
            resource.MaxAmount = maxAmount;
            resource.SpareRoom = maxAmount - currentAmount;

            return(resource.SpareRoom);
        }
        /// <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
            }
        }