Ejemplo n.º 1
0
    // Get The Seed total for this habitat for the year
    public double getSeeds(int x, int z, DailyLayer rainfall, IntDayList temps, DailyLayer surfaceWater)
    {
        double totalSeeds = grazing.getSeeds(x, z, quality, percentOcean, typePercents, rainfall, temps, surfaceWater);

        totalSeeds += forest.getSeeds(typePercents, quality);
        return(Math.Round(totalSeeds * FORAGECONSTANT, 2));
    }
Ejemplo n.º 2
0
    public void TestYearlyRainfallLayer()
    {
        HumidityLayer testEquation   = new HumidityLayer("HumidityTests", 6, 1);
        string        filePathPrefix = @"C:\Users\William\Documents\World Generator Maps\CavemanWorld\DynamicCavemanWorld\Assets\Resources\CSV\";

        testEquation.readCSVFiles(filePathPrefix);
        DailyLayer       rainfall      = testEquation.GenerateWorldsYearOfRain();
        SingleValueLayer rainfallTotal = new SingleValueLayer("Yearly Rain Total", "Yearly", 1);

        rainfallTotal.worldArray = rainfall.findYearTotalArray();
        int positivecount = 0;
        int excesscount   = 0;

        for (int a = 0; a < 50; a++)
        {
            for (int b = 0; b < 50; b++)
            {
                if (rainfallTotal.worldArray[a, b] >= 0)
                {
                    positivecount++;
                }
                if (rainfallTotal.worldArray[a, b] > 150)
                {
                    excesscount++;
                }
            }
        }

        Assert.AreEqual(50 * 50, rainfallTotal.worldArray.Length);
        Assert.AreEqual(50 * 50, positivecount);
        Assert.AreEqual(0, excesscount);

        Debug.Log(printArray(rainfallTotal.worldArray));
    }
Ejemplo n.º 3
0
    // World Rainfall Generation Methods
    public DailyLayer GenerateWorldsYearOfRain()
    {
        DailyLayer yearsRainfall = new DailyLayer("Rainfall", 1);

        float[,] stormArray = new float[WORLDX, WORLDZ];
        float decay = 0f;

        System.Random randy = new System.Random();

        // Run 120 times
        for (int day = 0; day < 120; day++)
        {
            // Debug.Log(day + "-" + WORLDX + ", " + WORLDZ);
            stormArray = GenerateStormCenters(day, randy);
            // Begin to loop until a storm didn't sucessfully spread
            decay  = 0f;
            spread = true;
            while (spread)
            {
                spread     = false;
                stormArray = SpreadStorms(stormArray, day, decay);
                // Debug.Log("spread: " + spread);
                decay += DECAY_CONST;
            }
            // Add it to the rainfall daily layer
            yearsRainfall.addWorldDay(day, stormArray);
        }

        return(yearsRainfall);
    }
Ejemplo n.º 4
0
    // Get last 5 Days of Rain
    private double Last5DaysOfRain(int day, int x, int z, DailyLayer rainfall, DailyLayer surfaceWater)
    {
        double last5Rain = 0.0;

        for (int d = day; d > 0 && d > day - 5; d--)
        {
            last5Rain += rainfall.worldArray[d][x, z] + surfaceWater.worldArray[day][x, z] * (Habitat.RIVERWATERINGCONSTANT / 2.0);
        }

        return(last5Rain);
    }
Ejemplo n.º 5
0
 public void TempAndRainNewYear()
 {
     // Create Temperatures
     CreateYearsTemps();
     // Create Rainfall
     rainfall = humidity.GenerateWorldsYearOfRain();
     rainfallTotal.worldArray = rainfall.findYearTotalArray();
     // Sort Into Snowfall
     snow = SortSnowDayByTemps(temps, rainfall);
     // Calculate River Flow
     CalculateRiverYear();
 }
Ejemplo n.º 6
0
    public void DailyLayerTest()
    {
        // Test all the SingleLayer Values can be initialized
        SingleValueLayer.WORLDX = 50;
        SingleValueLayer.WORLDZ = 50;
        DailyLayer rainfall = new DailyLayer("Rainfall", 1);

        Assert.AreEqual("Rainfall", rainfall.layerName);
        Assert.AreEqual("Daily", rainfall.getType());
        Assert.AreEqual(1, rainfall.getRounding());
        Assert.AreEqual(120, rainfall.worldArray.Length);
        Assert.AreEqual(50, DailyLayer.WORLDX);
        Assert.AreEqual(50, DailyLayer.WORLDZ);
    }
Ejemplo n.º 7
0
 // Return an array containing totals of each crop for the entire year.
 public double[] SumCropsForYear(int x, int z, double oceanPer, DailyLayer rainfall, IntDayList temps, DailyLayer rivers)
 {
     double[] cropSum = new double[NUM_OF_CROPS];
     double[] cropDay = new double[NUM_OF_CROPS];
     for (int d = 0; d < 120; d++)
     {
         cropDay = ReturnCurrentCropArray(d, x, z, oceanPer, rainfall, temps, rivers);
         for (int i = 0; i < NUM_OF_CROPS; i++)
         {
             cropSum[i] += cropDay[i];
         }
     }
     return(cropSum);
 }
Ejemplo n.º 8
0
    public void YearOfRainTest()
    {
        // Test the Storm Generation method
        HumidityLayer testEquation   = new HumidityLayer("HumidityTests", 6, 1);
        string        filePathPrefix = @"C:\Users\William\Documents\World Generator Maps\CavemanWorld\DynamicCavemanWorld\Assets\Resources\CSV\";

        testEquation.readCSVFiles(filePathPrefix);
        DailyLayer rainfall      = testEquation.GenerateWorldsYearOfRain();
        int        zerocount     = 0;
        int        positivecount = 0;

        System.Random randy = new System.Random();
        int           x     = randy.Next(0, 50);
        int           z     = randy.Next(0, 50);
        int           daye  = randy.Next(0, 120);

        // Make sure all numbers are legal
        for (int a = 0; a < 50; a++)
        {
            for (int b = 0; b < 50; b++)
            {
                for (int i = 0; i < 120; i++)
                {
                    if (rainfall.worldArray[i][a, b] == 0.0f)
                    {
                        zerocount++;
                    }
                    else if (rainfall.worldArray[i][a, b] > 0.0f)
                    {
                        positivecount++;
                    }
                }
            }
        }

        // Debug.Log("0: " + zerocount + " / +: " + positivecount);
        Assert.AreEqual(120 * 50 * 50, zerocount + positivecount);
        Assert.AreNotSame(120 * 50 * 50, zerocount);
        Assert.GreaterOrEqual(testEquation.CalculateHumidityFromBase(daye, x, z), 0.0f);
        Assert.LessOrEqual(testEquation.CalculateHumidityFromBase(daye, x, z), 10.0f);

        // Print the first day of rain.

        for (int day = 10; day < 30; day++)
        {
            Debug.Log("Day " + day);
            Debug.Log(printArray(rainfall.worldArray[day]));
        }
    }
Ejemplo n.º 9
0
    // Determine if starting on today the previous days have a suitable rainfall sum.
    private bool DayRainAllowCrop(int day, int x, int z, DailyLayer rain, DailyLayer rivers)
    {
        // can grow ONLY if the rainfall is within the ideal rainfall range
        double sum        = 0;
        double surfaceSum = 0;

        if (day - growthPeriod > 0)
        {
            int startGrowthDay = day - growthPeriod;
            // Sum the rainfall in the crops growing period
            for (int d = day; d > startGrowthDay; d--)
            {
                sum        += rain.worldArray[d][x, z];
                surfaceSum += rivers.worldArray[d][x, z] * Habitat.RIVERWATERINGCONSTANT;
            }
            // If that sum is in the acceptable range set the rainSum variable and return true, else return false.
            // Ideally if any value in the range of values from sum to sum + surfacewaterSum is between minWater and maxWater
            // Return true and rainSum set and percentGrowable set.
            // Else return false
            if ((sum > minWater && sum < maxWater) || (sum < minWater && (sum + surfaceSum) > minWater))
            {
                // Set the rainSum with the midpoint of the trapezoid of possible return values.
                rainSum = Average(Math.Min(sum + surfaceSum, maxWater), Math.Max(sum, minWater));
                // Set the percent Growable as the percent of the tile that actually is in the acceptable water range.
                if (surfaceSum == 0)
                {
                    percentGrowable = 1.0;
                }
                else
                {
                    percentGrowable = (Math.Min(sum + surfaceSum, maxWater) - Math.Max(sum, minWater)) / surfaceSum;
                }
                // return true because stuff grows here
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 10
0
    // Sorts the days it snows from the days it rains
    private DailyLayer SortSnowDayByTemps(IntDayList[,] temps, DailyLayer rainfall)
    {
        DailyLayer snowfall = new DailyLayer("snow", 1);

        for (int day = 0; day < 120; day++)
        {
            for (int x = 0; x < WorldX; x++)
            {
                for (int z = 0; z < WorldZ; z++)
                {
                    if (temps[x, z].getDaysTemp(day) <= 32)
                    {
                        snowfall.worldArray[day][x, z] = rainfall.worldArray[day][x, z];
                        rainfall.worldArray[day][x, z] = 0f;
                    }
                }
            }
        }

        return(snowfall);
    }
Ejemplo n.º 11
0
    // NOTE ***************
    // So far the crops can't grow early in the year because for that they need access to information from the previous year.
    // Implementation of that will be a bit tricky so I am saving it for later.
    // Also, these represent the number of new crops that grew today.  A scavenger would have access to the last x days worth of crops.
    // Calculate how much of a crop is present upon request
    public double[] ReturnCurrentCropArray(int day, int x, int z, double oceanPer, DailyLayer rainfall, IntDayList temps, DailyLayer rivers)
    {
        double[] currentCrops = new double[NUM_OF_CROPS];
        percentGrowable = 1.0;
        // For each of the crops
        // If he crop can grow in the region return the crops store the crops returned value in the current crop array for today.
        for (int i = 0; i < NUM_OF_CROPS; i++)
        {
            SwitchVariables(i);
            if (DayTempAllowCrop(day, temps) && DayRainAllowCrop(day, x, z, rainfall, rivers))
            {
                // Debug.Log("Crops Allowed!");
                double cropMultiplier = (1.0 / ((80 - growthPeriod) * 100.0)) * 400.0 * (1.0 - oceanPer);
                // Calculate the crop quality
                currentCrops[i] = cropQuality(day, temps) * cropMultiplier * humanFoodUnits * percentGrowable;
                // Debug.Log(x + ", " + z + " / " + cropQuality(day, temps) + " / " + percentGrowable + " / " + humanFoodUnits);
            }
        }

        return(currentCrops);
    }
Ejemplo n.º 12
0
    // Return the grazing available for this square today.
    public double getGrazing(int day, int x, int z, int quality, double oceanPer, double[] habitatPercents, DailyLayer rainfall, IntDayList temps, DailyLayer surfaceWater)
    {
        // Get the % of terrain that has grass
        double grassPercent  = 0.0;
        double desertPercent = 0.0;

        for (int i = 0; i < 9; i += 4)
        {
            grassPercent  += habitatPercents[2 + i];
            desertPercent += habitatPercents[1 + i];
        }
        double last5Rain = Last5DaysOfRain(day, x, z, rainfall, surfaceWater);
        // Calculate the grass mass.
        double grass = getGrass(quality, oceanPer, grassPercent, desertPercent, last5Rain, temps.getDaysTemp(day));
        // Calculate the grazing available
        double grazing = grass * GRASSCALORIECONTENT;

        return(grazing);
    }
Ejemplo n.º 13
0
    // Mineral Layers
    // public MineralLayer surfaceStone;
    // public MineralLayer surfaceIron;
    // public MineralLayer surfaceMinerals;
    // public MineralLayer miningStone;
    // public MineralLayer miningIron;
    // public MineralLayer miningMinerals;

    // Constructor
    public World(int x, int z, bool random)
    {
        // Initialize the variables
        WorldX = x;
        WorldZ = z;
        SingleValueLayer.WORLDX = WorldX;
        SingleValueLayer.WORLDZ = WorldZ;
        this.elevation          = new SingleValueLayer("Elevation", "Semi-static", 1);
        this.elevationVertices  = new SingleValueLayer("ElevationVertices", "Semi-static", 1);
        this.highTemp           = new SingleValueLayer("HighTemp", "Semi-static", 0);
        this.lowTemp            = new SingleValueLayer("LowTemp", "Semi-static", 0);
        this.tempMidpt          = new SingleValueLayer("TempMidpoint", "Semi-static", 1);
        this.variance           = new SingleValueLayer("Variance", "Semi-static", 1);
        this.tempEquations      = new EquationLayer("TemperatureEquations", "Semi-static");
        this.temps    = new IntDayList[WorldX, WorldZ];
        this.humidity = new HumidityLayer("HumidityLayer", 6, 1);

        if (!random)
        {
            string filePathPrefix = @"CSV\";
            elevation.readCSVFile(filePathPrefix + "ElevationNiceMapA");
            // Debug.Log("**************************************");
            highTemp.readCSVFile(filePathPrefix + "HighTempNiceMapA");
            lowTemp.readCSVFile(filePathPrefix + "LowTempNiceMapA");
            tempMidpt.readCSVFile(filePathPrefix + "MidptNiceMapA");
            variance.readCSVFile(filePathPrefix + "VarianceNiceMapA");
            humidity.readCSVFiles(filePathPrefix);
        }
        else
        {
            DataGenerator generator = new DataGenerator(WorldX, WorldZ);
            Debug.Log(x + ", " + z);
            // Generate elevation layer
            elevation.worldArray = generator.CreateElevationLayer();
            // Generate temperature info
            float[][,] temporaryTemps = generator.CreateTemperatureLayers(4);
            highTemp.worldArray       = temporaryTemps[0];
            lowTemp.worldArray        = temporaryTemps[1];
            tempMidpt.worldArray      = generator.CreateStandardFloatLayer(20.2, 40.6, 4.0);
            variance.worldArray       = generator.CreateStandardFloatLayer(1.0, 16.0, 2.0);
            // Generate rain info
            for (int i = 0; i < 6; i++)
            {
                humidity.worldArray[i] = generator.CreateStandardFloatLayer(0.0, 10.0, 1.0);
            }
        }

        // Elevation info
        ConvertElevationToVertices();
        hillPer  = CalculateHillPercentage();
        oceanPer = CalculateOceanPercentage();
        Debug.Log("Elevation Models Complete!");
        // Temperature info
        tempEquations.createEquations(highTemp, lowTemp, tempMidpt, variance);
        // Calculate Years worth of temperature data
        // CreateYearsTemps();
        Debug.Log("Temperature Models Complete!");
        // Rainfall info
        rainfall      = humidity.GenerateWorldsYearOfRain();
        rainfallTotal = new SingleValueLayer("Yearly Rain Total", "Yearly", 1);
        // rainfallTotal.worldArray = rainfall.findYearTotalArray();
        Debug.Log("Rainfall Models Complete!");
        // Rivers info
        // Initialize Water Stats
        riverStats = new ObjectLayer("River Stats", "Semi-static");
        PopulateRivers();
        Debug.Log("Rivers Populated!");
        ResetStaticRiverLayers();
        ResetLastDayLayer();
        // Calculate Habitat Layer - ** for that we need 20 years of time run forward at initialization **
        HabitatInitialization();
        // When done initializing the habitats calculate a new year
        TempAndRainNewYear();
        Debug.Log("Habitats Created!");
    }
Ejemplo n.º 14
0
 // Print that grew the last X days
 public string PrintLastXDaysOfCrops(int today, int range, int x, int z, double oceanPer, DailyLayer rainfall, IntDayList temps, DailyLayer rivers)
 {
     // get a sum of last X days crop arrays
     double[] sumArray = new double[NUM_OF_CROPS];
     double[] cropArray;
     for (int d = today; d > 0 && d > (today - range); d--)
     {
         cropArray = ReturnCurrentCropArray(today, x, z, oceanPer, rainfall, temps, rivers);
         for (int i = 0; i < NUM_OF_CROPS; i++)
         {
             if (cropArray[i] != 0.0)
             {
                 sumArray[i] += cropArray[i];
             }
         }
     }
     return(CreateCropArrayPrintString(sumArray));
 }
Ejemplo n.º 15
0
 // Print the Current Crop Array
 public string PrintCurrentCropArray(int day, int x, int z, double oceanPer, DailyLayer rainfall, IntDayList temps, DailyLayer rivers)
 {
     // get today's crop array
     double[] cropArray = ReturnCurrentCropArray(day, x, z, oceanPer, rainfall, temps, rivers);
     return(CreateCropArrayPrintString(cropArray));
 }
Ejemplo n.º 16
0
    // Return the year's total foragable grazing.
    // Used by the game and herds to determine food availability
    public double YearsGrazingForage(int x, int z, int quality, double oceanPer, double[] habitatPercents, DailyLayer rainfall, IntDayList temps, DailyLayer surfaceWater)
    {
        double sum = 0.0;

        for (int d = 0; d < 120; d++)
        {
            sum += getGrazing(d, x, z, quality, oceanPer, habitatPercents, rainfall, temps, surfaceWater);
        }
        return(Math.Round((sum * Habitat.FORAGECONSTANT), 2));
    }
Ejemplo n.º 17
0
    // Returns the seeds produced by the grazing
    public double getSeeds(int x, int z, int quality, double oceanPer, double[] habitatPercents, DailyLayer rainfall, IntDayList temps, DailyLayer surfaceWater)
    {
        double seeds = (YearsGrazingForage(x, z, quality, oceanPer, habitatPercents, rainfall, temps, surfaceWater) / Habitat.FORAGECONSTANT) / GRASSCALORIECONTENT;

        return(seeds * Habitat.SEEDCONSTANT);
    }
Ejemplo n.º 18
0
 // Print the Year's Crop Array
 public string PrintYearsCropArray(int x, int z, double oceanPer, DailyLayer rainfall, IntDayList temps, DailyLayer rivers)
 {
     // get year's crop array
     double[] cropArray = SumCropsForYear(x, z, oceanPer, rainfall, temps, rivers);
     return(CreateCropArrayPrintString(cropArray));
 }