예제 #1
0
    public River GEN_RIVER_TEST()
    {
        Vec2i start = new Vec2i(World.WorldSize / 2, World.WorldSize / 2);
        River r     = new River();

        r.SetFirstChunk(start, 10);
        int lastY = start.z;
        //Iterate 100 x points
        Vec2i last = start;

        for (int x = 0; x < 10; x++)
        {
            //r.AddChunk(new Vec2i(start.x + x + 1, start.z), 10);

            int   i    = Random.Range(0, 2);
            Vec2i dr   = new Vec2i(0, 1);
            Vec2i next = last + dr;
            r.AddChunk(next, 10);
            last = next;
            continue;

            int cx = start.x + (x + 1);
            //Find the dy at this point
            int dy = SimpleSinSum(x) - lastY;
            //If dy > 1, then we must seperate out
            if (Mathf.Abs(dy) > 1)
            {
                int sign = (int)Mathf.Sign(dy);
                for (int y = 0; y < Mathf.Abs(dy); y++)
                {
                    if (!r.AddChunk(new Vec2i(cx, lastY + y * sign), 10))
                    {
                        throw new System.Exception("Chunk not next to last one");
                    }
                }
            }
            else
            {
                //If it is not, then we can add it directly.
                if (!r.AddChunk(new Vec2i(cx, lastY + dy), 10))
                {
                    throw new System.Exception("Chunk not next to last one 2");
                }
            }
            lastY = lastY + dy;
        }
        Debug.Log("start point at " + start);

        return(r);
    }
예제 #2
0
    private River GenerateRiver(Vec2i start, Vec2i mainDirection, GenerationRandom genRan)
    {
        bool  shouldStop = false;
        River r          = new River();

        r.SetFirstChunk(start, 5);
        List <Vec2i> directions = new List <Vec2i>();

        directions.Add(mainDirection);
        directions.Add(mainDirection);
        directions.Add(mainDirection);
        directions.Add(mainDirection);
        directions.AddRange(PerpDir(mainDirection));
        Vec2i last = start;

        while (!shouldStop)
        {
            Vec2i next = last + genRan.RandomFromList <Vec2i>(directions);
            if (r.AddChunk(next, 5))
            {
                last = next;
                if (next.x < 0 || next.z < 0 || next.x >= World.WorldSize || next.z >= World.WorldSize)
                {
                    shouldStop = true;
                }
                else if (!GameGenerator.TerrainGenerator.ChunkBases[next.x, next.z].IsLand)
                {
                    shouldStop = true;
                }
            }
        }

        return(r);
    }
예제 #3
0
    private void GenerateWorld3()
    {
        World world = new World();

        //Create chunk bases
        ChunkBase[,] chunk_b = new ChunkBase[World.RegionSize, World.RegionSize];

        ChunkData[,] chunks = new ChunkData[World.RegionSize, World.RegionSize];



        River r = new River();



        r.SetFirstChunk(new Vec2i(2, 2), 6);
        r.AddChunk(new Vec2i(3, 2), 6);
        r.AddChunk(new Vec2i(4, 2), 6);
        r.AddChunk(new Vec2i(4, 3), 6);
        r.AddChunk(new Vec2i(5, 3), 6);

        /*
         * r.AddChunk(new Vec2i(3,2), 6);
         * r.AddChunk(new Vec2i(3, 3), 6);
         * r.AddChunk(new Vec2i(4, 3), 6);
         * r.AddChunk(new Vec2i(4, 2), 6);
         * r.AddChunk(new Vec2i(4, 1), 6);
         * r.AddChunk(new Vec2i(3, 1), 6);
         * r.AddChunk(new Vec2i(2, 1), 6);
         * r.AddChunk(new Vec2i(1, 1), 6);
         */
        /*
         * Vec2i last = new Vec2i(2, 2);
         * for(int i=0; i<10; i++)
         * {
         *  int t = (i % 8);
         *  int dx = 0;
         *  int dz = 0;
         *  if (t == 0 || t==1)
         *      dx = 1;
         *  else if (t == 2 || t == 3)
         *      dz = 1;
         *  else if (t == 3 || t == 5)
         *      dx = -1;
         *  else
         *      dz = -1;
         *  //int dx = (i % 2);
         *  //int dz = (i + 1) % 2;
         *  last = last + new Vec2i(dx, dz);
         *  r.AddChunk(last, 6);
         * }*/


        for (int rx = 0; rx < World.RegionSize; rx++)
        {
            for (int rz = 0; rz < World.RegionSize; rz++)
            {
                chunk_b[rx, rz] = new ChunkBase(new Vec2i(rx, rz), true);
            }
        }

        foreach (KeyValuePair <Vec2i, RiverNode> kvp in r.GenerateRiverNodes())
        {
            chunk_b[kvp.Key.x, kvp.Key.z].AddRiver(kvp.Value);
        }

        int[,] emptyLandChunk = new int[World.ChunkSize, World.ChunkSize];
        for (int x = 0; x < World.ChunkSize; x++)
        {
            for (int z = 0; z < World.ChunkSize; z++)
            {
                emptyLandChunk[x, z] = Tile.GRASS.ID;
            }
        }
        for (int rx = 0; rx < World.RegionSize; rx++)
        {
            for (int rz = 0; rz < World.RegionSize; rz++)
            {
                chunks[rx, rz] = GenerateChunk((int[, ])emptyLandChunk.Clone(), chunk_b[rx, rz]);
            }
        }

        ChunkRegion region = new ChunkRegion(0, 0, chunks);

        WorldManager.SetWorld(world);
        WorldManager.LoadedRegions[0, 0] = region;
        world.SetChunkBases(chunk_b);
        for (int rx = 0; rx < World.RegionSize - 1; rx++)
        {
            for (int rz = 0; rz < World.RegionSize - 1; rz++)
            {
                WorldManager.CRManager.LoadChunk(new Vec2i(rx, rz));
            }
        }
    }