示例#1
0
    public TileObject CreateResource(Biome tileBiome)
    {
        BiomeResources        biomeResources = Resources.Find((res) => res.Biome == tileBiome);
        List <ResourceWeight> resourceList   = biomeResources.Resources;

        return(SelectedWeightedResource(resourceList));
    }
示例#2
0
        public static float GetAbundance(double latitude, double longitude, string resourceName, int bodyId, int resourceType = 0, double altitude = 0)
        {
            try
            {
                var northing = Utilities.Deg2Rad(latitude);
                var easting  = Utilities.Deg2Rad(longitude);

                var body  = FlightGlobals.Bodies.FirstOrDefault(b => b.flightGlobalsIndex == bodyId);
                var biome = GetBiome(northing, easting, body);
                var seed  = RegolithScenario.Instance.gameSettings.seed;
                seed *= (bodyId + 1);
                seed += resourceName.Length * resourceName.Substring(1).ToCharArray().First();
                seed += body.bodyName.Length * body.bodyName.Substring(1).ToCharArray().First();

                if (biome != null)
                {
                    seed += Convert.ToInt32(biome.mapColor.grayscale * 4096) * (resourceType + 1);
                }
                //First - we need to determine our data set for randomization.
                //Is there biome data?
                DistributionData distro = null;
                var biomeName           = "UNKNOWN";
                if (biome != null)
                {
                    biomeName = biome.name;
                }
                var biomeConfigs = BiomeResources.Where(
                    r => r.PlanetName == body.bodyName &&
                    r.BiomeName == biomeName &&
                    r.ResourceName == resourceName &&
                    r.ResourceType == resourceType).ToList();
                var planetConfigs =
                    PlanetaryResources.Where(
                        r => r.PlanetName == body.bodyName &&
                        r.ResourceName == resourceName &&
                        r.ResourceType == resourceType).ToList();
                var globalConfigs =
                    GlobalResources.Where(
                        r => r.ResourceName == resourceName &&
                        r.ResourceType == resourceType).ToList();
                //Extrapolate based on matching overrides
                if (biomeConfigs.Any())
                {
                    distro = GetBestResourceData(biomeConfigs);
                    seed  *= 2;
                }
                else if (planetConfigs.Any())
                {
                    distro = GetBestResourceData(planetConfigs);
                    seed  *= 3;
                }
                else if (globalConfigs.Any())
                {
                    distro = GetBestResourceData(globalConfigs);
                    seed  *= 4;
                }
                else
                {
                    return(0f);
                }
                var rand = new Random(seed);
                //Our Simplex noise:
                var noiseSeed = new int[8];
                for (int ns = 0; ns < 8; ns++)
                {
                    noiseSeed[ns] = rand.Next();
                }
                var spx    = new NoiseGenerator(noiseSeed);
                var noiseX = (float)northing;
                var noiseY = (float)easting;
                var noiseZ = (rand.Next(100)) / 100f;
                var noise  = spx.noise(noiseX, noiseY, noiseZ);

                var presenceRoll = rand.Next(100);
                var isPresent    = (presenceRoll <= distro.PresenceChance);
                if (!isPresent)
                {
                    return(0f);
                }

                //Abundance begins with a starting range.
                var min = (int)(distro.MinAbundance * 1000);
                var max = (int)(distro.MaxAbundance * 1000);
                //In case someone is silly
                if (min > max)
                {
                    max = min + 1;
                }
                var ab = rand.Next(min, max);
                //Start with lower abundance
                float lowAbundance = ab / 1000f;
                //Our upper bound uses our variance.
                float highAbuncance = lowAbundance + (lowAbundance * distro.Variance / 100);
                //Default is average
                var abundance = (lowAbundance + highAbuncance) / 2;


                //Applies to all but interplanetary
                if (resourceType <= 2)
                {
                    //Otherwise, it's a function of noise.
                    abundance = lowAbundance + (noise * (highAbuncance - lowAbundance));
                }
                //Altitude band - only applies to atmospheric and interplanetary
                if (resourceType >= 2 && distro.HasVariableAltitude())
                {
                    var rad   = body.Radius;
                    var ideal = ((rad * distro.MinAltitude) + (rad * distro.MaxAltitude)) / 2;
                    //print("REGO: IDEAL = " + ideal);
                    var range     = rand.Next((int)(rad * distro.MinRange), (int)(rad * distro.MaxRange));
                    var diff      = Math.Abs(ideal - altitude);
                    var rangePerc = diff / range;
                    var modifier  = 1d - rangePerc;
                    abundance *= (float)modifier;
                }


                if (abundance <= Utilities.FLOAT_TOLERANCE)
                {
                    return(0f);
                }

                //Return it as a float not a percent
                return(abundance / 100);
            }
            catch (Exception e)
            {
                print("[REGO] - Error in - RegolithResourceMap_GetAbundance - " + e.Message);
                return(0f);
            }
        }