Example #1
0
        ///<summary>
        ///returns the amount of a given resource for a body and place
        /// takes the args <body> <geocoordinates> and <resource-string> in any order
        ///</summary>
        public ScalarDoubleValue GetResourceByName(params Structure[] args)
        {
            if (args.Length != 3)
            {
                return(null);
            }
            BodyTarget     body       = args.Where(s => s.GetType() == typeof(BodyTarget)).Cast <BodyTarget>().First();
            GeoCoordinates coordinate = args.Where(s => s.GetType() == typeof(GeoCoordinates)).Cast <GeoCoordinates>().First();
            StringValue    s_type     = args.Where(s => s.GetType() == typeof(StringValue)).Cast <StringValue>().First();

            if (resourceNames == null)
            {
                resourceNames = ResourceMap.Instance.FetchAllResourceNames(HarvestTypes.Planetary);
            }

            var resourceName = resourceNames.FirstOrDefault(name => string.Equals(name, s_type, StringComparison.InvariantCultureIgnoreCase));

            if (resourceName == null)
            {
                throw new kOS.Safe.Exceptions.KOSException("invalid resource type");
            }

            if ((SCANWrapper.IsCovered(coordinate.Longitude, coordinate.Latitude, body.Body, "ResourceHiRes")) || ((HasKerbNet("Resource") && (IsInKerbNetFoV(body.Body, coordinate.Longitude, coordinate.Latitude)))))
            {
                float amount   = 0f;
                var   aRequest = new AbundanceRequest
                {
                    Latitude        = coordinate.Latitude,
                    Longitude       = coordinate.Longitude,
                    BodyId          = body.Body.flightGlobalsIndex,
                    ResourceName    = resourceName,
                    ResourceType    = HarvestTypes.Planetary,
                    Altitude        = 0,
                    CheckForLock    = SCANWrapper.GetResourceBiomeLock(),
                    BiomeName       = ScienceUtil.GetExperimentBiome(body.Body, coordinate.Latitude, coordinate.Longitude),
                    ExcludeVariance = false,
                };

                amount = ResourceMap.Instance.GetAbundance(aRequest);
                return(amount);
            }
            else
            {
                return(-1.0);
            }
        }
Example #2
0
        ///<summary>
        ///returns the amount of a given resource for a body and place
        /// takes the args <body> <geocoordinates> and <resource-string> in any order
        ///</summary>
        public ScalarDoubleValue GetResourceByName(params Structure[] args)
        {
            if (args.Length != 3)
            {
                return(null);
            }
            BodyTarget body = args.Where(s => s.GetType() == typeof(BodyTarget)).Cast <BodyTarget>().First();
            //            BodyTarget body = args[0] as BodyTarget;
            GeoCoordinates coordinate = args.Where(s => s.GetType() == typeof(GeoCoordinates)).Cast <GeoCoordinates>().First();
            StringValue    s_type     = args.Where(s => s.GetType() == typeof(StringValue)).Cast <StringValue>().First();

            if ((SCANWrapper.IsCovered(coordinate.Longitude, coordinate.Latitude, body.Body, s_type)) || ((HasKerbNet("Resource") && (IsInKerbNetFoV(body.Body, coordinate.Longitude, coordinate.Latitude)))))

            {
                float amount   = 0f;
                var   aRequest = new AbundanceRequest
                {
                    Latitude        = coordinate.Latitude,
                    Longitude       = coordinate.Longitude,
                    BodyId          = body.Body.flightGlobalsIndex,
                    ResourceName    = s_type,
                    ResourceType    = HarvestTypes.Planetary,
                    Altitude        = 0,
                    CheckForLock    = SCANWrapper.GetResourceBiomeLock(),
                    BiomeName       = ScienceUtil.GetExperimentBiome(body.Body, coordinate.Latitude, coordinate.Longitude),
                    ExcludeVariance = false,
                };

                amount = ResourceMap.Instance.GetAbundance(aRequest);
                return(amount);
            }
            else
            {
                return(-1.0);
            }
        }