コード例 #1
0
ファイル: ClassTester.cs プロジェクト: hueblerw/CavemanWorld
    public void EquationCreationTest()
    {
        SingleValueLayer.WORLDX = 50;
        SingleValueLayer.WORLDZ = 50;
        // Test initialize what is needed for the test
        EquationLayer    testEquation   = new EquationLayer("TemperatureEquations", "Semi-static");
        SingleValueLayer testhighTemp   = new SingleValueLayer("HighTemp", "Semi-static", 0);
        SingleValueLayer testlowTemp    = new SingleValueLayer("LowTemp", "Semi-static", 0);
        SingleValueLayer testtempMidpt  = new SingleValueLayer("TempMidpoint", "Semi-static", 1);
        SingleValueLayer testvariance   = new SingleValueLayer("Variance", "Semi-static", 1);
        string           filePathPrefix = @"C:\Users\William\Documents\World Generator Maps\CavemanWorld\DynamicCavemanWorld\Assets\Resources\CSV\";

        testhighTemp.readCSVFile(filePathPrefix + "HighTempNiceMapA.csv");
        testlowTemp.readCSVFile(filePathPrefix + "LowTempNiceMapA.csv");
        testtempMidpt.readCSVFile(filePathPrefix + "MidptNiceMapA.csv");
        testvariance.readCSVFile(filePathPrefix + "VarianceNiceMapA.csv");
        testEquation.createEquations(testhighTemp, testlowTemp, testtempMidpt, testvariance);

        // Test conditions
        // Basic correct info
        Assert.AreEqual(50 * 50, testEquation.worldArray.Length);
        Assert.AreEqual(100, testhighTemp.worldArray[0, 0]);
        Assert.AreEqual(1, testlowTemp.worldArray[0, 0]);
        Assert.AreEqual((float)20.4, testtempMidpt.worldArray[0, 0]);
        Assert.AreEqual((float)8.0, testvariance.worldArray[0, 0]);
        // Check for correct X-Z axes
        Assert.AreEqual(98, testhighTemp.worldArray[2, 1]);
        Assert.AreEqual(-5, testlowTemp.worldArray[2, 1]);
        Assert.AreEqual((float)26.6, testtempMidpt.worldArray[2, 1]);
        Assert.AreEqual((float)9.8, testvariance.worldArray[2, 1]);
    }
コード例 #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));
    }
コード例 #3
0
ファイル: WorldView.cs プロジェクト: hueblerw/CavemanWorld
    public static Mesh BuildMesh(SingleValueLayer elevationVerticesLayer)
    {
        // Set some constants
        float[,] elevations = elevationVerticesLayer.worldArray;
        int numOfTilesX = SingleValueLayer.WORLDX;
        int numOfTilesZ = SingleValueLayer.WORLDZ;
        int numOfTiles  = numOfTilesX * numOfTilesZ;
        int numVertices = (numOfTilesX + 1) * (numOfTilesZ + 1);

        // Convert to mesh data
        Vector3[] vertices  = new Vector3[numVertices];
        int[]     triangles = new int[2 * numOfTiles * 3];
        Vector3[] normals   = new Vector3[numVertices];
        Vector2[] uv        = new Vector2[numVertices];

        // Create the vertices and the normals generically
        int x, z;
        int squareIndex, triOffset;

        for (z = 0; z < numOfTilesZ + 1; z++)
        {
            for (x = 0; x < numOfTilesX + 1; x++)
            {
                vertices[z * (numOfTilesX + 1) + x] = new Vector3(x * tileSize, elevations[x, z] * heightScale, z * tileSize);
                normals[z * (numOfTilesX + 1) + x]  = Vector3.up;
                uv[z * (numOfTilesX + 1) + x]       = new Vector2((float)x / (numOfTilesX + 1), (float)z / (numOfTilesZ + 1));
            }
        }
        // Create the triangle generically
        for (z = 0; z < numOfTilesZ; z++)
        {
            for (x = 0; x < numOfTilesX; x++)
            {
                squareIndex = z * numOfTilesX + x;
                triOffset   = squareIndex * 6;
                // first triangle
                triangles[triOffset]     = z * (numOfTilesX + 1) + x + 0;
                triangles[triOffset + 2] = z * (numOfTilesX + 1) + x + (numOfTilesX + 1) + 1;
                triangles[triOffset + 1] = z * (numOfTilesX + 1) + x + (numOfTilesX + 1) + 0;;
                // second triangle
                triangles[triOffset + 3] = z * (numOfTilesX + 1) + x + 0;
                triangles[triOffset + 5] = z * (numOfTilesX + 1) + x + 1;
                triangles[triOffset + 4] = z * (numOfTilesX + 1) + x + (numOfTilesX + 1) + 1;;
            }
        }

        // Create a new mesh and populate it with the data from the elevation layer
        Mesh world = new Mesh();

        world.vertices  = vertices;
        world.triangles = triangles;
        world.normals   = normals;
        world.uv        = uv;

        // Return our mesh to the controller
        return(world);
    }
コード例 #4
0
    // World Array Initializer

    public void createEquations(SingleValueLayer highTemp, SingleValueLayer lowTemp, SingleValueLayer tempMidpt, SingleValueLayer variance)
    {
        // Basically, loop through the creation of each individual equation
        TempEquation temporary;

        TempEquation[,] tempArray = new TempEquation[EquationLayer.WORLDX, EquationLayer.WORLDZ];
        for (int x = 0; x < WORLDX; x++)
        {
            for (int z = 0; z < WORLDZ; z++)
            {
                temporary       = new TempEquation((int)highTemp.worldArray[x, z], (int)lowTemp.worldArray[x, z], tempMidpt.worldArray[x, z], variance.worldArray[x, z]);
                tempArray[x, z] = temporary;
            }
        }
        this.worldArray = tempArray;
    }
コード例 #5
0
    // Choose a downstream flow
    public void ChooseDownstream(SingleValueLayer elevation, System.Random randy)
    {
        float         myElevation = elevation.worldArray[x, z];
        List <string> options     = Support.getDirectionAsStringBelow(false, x, z, SingleValueLayer.WORLDX, SingleValueLayer.WORLDZ, myElevation, elevation.worldArray);

        if (options.Count == 0)
        {
            downstream = null;
            type       = "lake";
        }
        else
        {
            string choice = options[randy.Next(0, options.Count)];
            downstream = new Direction(choice);
            type       = "river";
        }
    }
コード例 #6
0
ファイル: ClassTester.cs プロジェクト: hueblerw/CavemanWorld
    public void SVLayerTest()
    {
        // Test all the SingleLayer Values can be initialized
        SingleValueLayer.WORLDX = 50;
        SingleValueLayer.WORLDZ = 50;
        SingleValueLayer elevation = new SingleValueLayer("Elevation", "Semi-static", 1);
        string           filePath  = @"C:\Users\William\Documents\World Generator Maps\CavemanWorld\DynamicCavemanWorld\Assets\Resources\CSV\ElevationNiceMapA.csv";

        elevation.readCSVFile(filePath);

        Assert.AreEqual("Elevation", elevation.layerName);
        Assert.AreEqual("Semi-static", elevation.getType());
        Assert.AreEqual(1, elevation.getRounding());
        Assert.AreEqual(50, SingleValueLayer.WORLDX);
        Assert.AreEqual(50, SingleValueLayer.WORLDZ);
        Assert.AreEqual((float)-2.7, elevation.worldArray[1, 0]);
        Assert.AreEqual((float)-0.6, elevation.worldArray[0, 1]);
    }
コード例 #7
0
ファイル: World.cs プロジェクト: hueblerw/CavemanWorld
    // Create the HillPercentage Layer
    private SingleValueLayer CalculateHillPercentage()
    {
        // Initialize a new layer
        float            diff;
        SingleValueLayer hillPer = new SingleValueLayer("Hill Percentage", "Semi-static", 4);

        // Stash the max elevation difference
        maxNetDiff();
        // Calculate the hill %'s for the whole world
        for (int x = 0; x < WorldX; x++)
        {
            for (int z = 0; z < WorldZ; z++)
            {
                diff = netDiff(x, z);
                hillPer.worldArray[x, z] = (float)Math.Round(diff / maxElevationDifference, 4);
            }
        }
        return(hillPer);
    }
コード例 #8
0
ファイル: ClassTester.cs プロジェクト: hueblerw/CavemanWorld
    public void DirectionTest()
    {
        // Check the Direction methods work correctly
        Direction upwards    = new Direction("up");
        Direction downwards  = new Direction("down");
        Direction leftwards  = new Direction("left");
        Direction rightwards = new Direction("right");
        // Direction none = null;
        int x = 1;
        int z = 2;

        int[] coor = new int[2];
        coor[0] = 2;
        coor[1] = 2;
        SingleValueLayer.WORLDX = 50;
        SingleValueLayer.WORLDZ = 50;
        SingleValueLayer ele      = new SingleValueLayer("ele", "Testing", 1);
        string           filePath = @"C:\Users\William\Documents\World Generator Maps\CavemanWorld\DynamicCavemanWorld\Assets\Resources\CSV\ElevationNiceMapA.csv";

        ele.readCSVFile(filePath);

        // Check it assigns properly
        Assert.AreEqual(upwards.direction, "up");
        Assert.AreEqual(downwards.direction, "down");
        Assert.AreEqual(leftwards.direction, "left");
        Assert.AreEqual(rightwards.direction, "right");
        // Check the get coordinate as array thingy
        Assert.AreEqual(rightwards.getCoordinateArray(x, z), coor);
        Assert.AreEqual(upwards.getCoordinateArray(x, z)[1], 1);
        Assert.AreEqual(leftwards.getCoordinateArray(x, z)[0], 0);
        Assert.AreEqual(downwards.getCoordinateArray(x, z)[1], 3);
        // Check the to string method works properly
        Assert.AreEqual(upwards.ToString(), "up");
        Assert.AreEqual(downwards.ToString(), "down");
        Assert.AreEqual(leftwards.ToString(), "left");
        Assert.AreEqual(rightwards.ToString(), "right");
        // Assert.AreEqual(none.ToString(), "none");
        // Check the get float from direction feature
        Assert.AreEqual(-3.5f, (float)Math.Round(upwards.getFloatAtCoordinates(x, z, ele.worldArray), 1));
        Assert.AreEqual(-0.5f, (float)Math.Round(downwards.getFloatAtCoordinates(x, z, ele.worldArray), 1));
        Assert.AreEqual(-0.6f, (float)Math.Round(leftwards.getFloatAtCoordinates(x, z, ele.worldArray), 1));
        Assert.AreEqual(-1.6f, (float)Math.Round(rightwards.getFloatAtCoordinates(x, z, ele.worldArray), 1));
    }
コード例 #9
0
ファイル: World.cs プロジェクト: hueblerw/CavemanWorld
    // Create the Ocean Percentage Layer
    private SingleValueLayer CalculateOceanPercentage()
    {
        // Initialize a new layer
        SingleValueLayer oceanPer = new SingleValueLayer("Ocean Percentage", "Semi-static", 4);

        // Find the vertexes, sum th abs of all negative values and divide by sum of abs of all values.
        float[,] vertexArray = elevationVertices.worldArray;
        float[] corners;
        float   sumOfNegatives;
        float   sumOfAll;

        for (int x = 0; x < WorldX; x++)
        {
            for (int z = 0; z < WorldZ; z++)
            {
                corners                   = Support.CellsAroundVertex(x + 1, z + 1, WorldX, WorldZ, vertexArray);
                sumOfNegatives            = FindAbsOfNegatives(corners);
                sumOfAll                  = FindAbsSum(corners);
                oceanPer.worldArray[x, z] = sumOfNegatives / sumOfAll;
            }
        }

        return(oceanPer);
    }
コード例 #10
0
ファイル: World.cs プロジェクト: hueblerw/CavemanWorld
    // 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!");
    }