public override bool Generate(CubeWorld world)
        {
            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            Random rnd = new Random();

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    for (int y = fromY; y < toY; y++)
                    {
                        TilePosition pos = new TilePosition(x, y, z);
                        if (tileManager.GetTileType(pos) == TileDefinition.EMPTY_TILE_TYPE)
                        {
                            int n = rnd.Next(0, probabilityRange);
                            foreach (TileTypeProbability s in probabilities)
                            {
                                if (n < s.probability)
                                {
                                    tileManager.SetTileType(pos, s.tileType);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #2
0
        public override bool Generate(CubeWorld world)
        {
            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    int y = tileManager.GetTopPosition(x, z);

                    if (tileManager.GetTileType(new TilePosition(x, y, z)) != TileDefinition.EMPTY_TILE_TYPE)
                    {
                        y++;
                    }

                    if (y >= fromY)
                    {
                        for (int i = y; i < toY; i++)
                        {
                            tileManager.SetTileType(new TilePosition(x, i, z), waterTileType);
                        }
                    }
                }
            }

            return(true);
        }
        public override bool Generate(CubeWorld world)
        {
            Random random = new Random();

            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius  = minRadiusRV.EvaluateInt(world);
            int maxRadius  = maxRadiusRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            for (int i = 0; i < iterations; i++)
            {
                int cx = random.Next(maxRadius + 1, tileManager.sizeX - maxRadius - 1);
                int cz = random.Next(maxRadius + 1, tileManager.sizeZ - maxRadius - 1);

                int radius = random.Next(minRadius, maxRadius);

                int sum = 0;

                for (int x = cx - radius; x < cx + radius; x++)
                {
                    for (int z = cz - radius; z < cz + radius; z++)
                    {
                        sum += tileManager.GetTopPosition(x, z);
                    }
                }

                int avg = sum / (radius * 2 * radius * 2);

                for (int x = cx - radius; x < cx + radius; x++)
                {
                    for (int z = cz - radius; z < cz + radius; z++)
                    {
                        int y = tileManager.GetTopPosition(x, z);

                        if (avg - y < -1 || avg - y > 1)
                        {
                            if (y > avg)
                            {
                                //Remove tiles
                                for (int dy = avg + 1; dy <= y; dy++)
                                {
                                    tileManager.SetTileType(new TilePosition(x, dy, z), 0);
                                }
                            }
                            else if (y < avg)
                            {
                                //Add tiles
                                for (int dy = y; dy <= avg; dy++)
                                {
                                    tileManager.SetTileType(new TilePosition(x, dy, z), tileType);
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
        public override bool Generate(CubeWorld world)
        {
            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius  = minRadiusRV.EvaluateInt(world);
            int maxRadius  = maxRadiusRV.EvaluateInt(world);
            int minDepth   = minDepthRV.EvaluateInt(world);
            int maxDepth   = maxDepthRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            Random random = new Random();

            for (int i = 0; i < iterations; i++)
            {
                int cx = random.Next(maxRadius + 1, tileManager.sizeX - maxRadius - 1);
                int cz = random.Next(maxRadius + 1, tileManager.sizeZ - maxRadius - 1);

                int radiusX = random.Next(minRadius, maxRadius);
                int radiusZ = random.Next(minRadius, maxRadius);

                int depth = random.Next(minDepth, maxDepth);

                int sum = 0;

                for (int x = cx - radiusX; x < cx + radiusX; x++)
                {
                    for (int z = cz - radiusZ; z < cz + radiusZ; z++)
                    {
                        sum += tileManager.GetTopPosition(x, z);
                    }
                }

                int avg = sum / (radiusX * 2 * radiusZ * 2);

                if (avg - depth > 1)
                {
                    for (int x = cx - radiusX; x < cx + radiusX; x++)
                    {
                        for (int z = cz - radiusZ; z < cz + radiusZ; z++)
                        {
                            int y = tileManager.GetTopPosition(x, z);

                            if (y > avg - depth)
                            {
                                //Remove tiles
                                for (int dy = (avg - depth) + 1; dy <= y; dy++)
                                {
                                    tileManager.SetTileType(new TilePosition(x, dy, z), 0);
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #5
0
        public override bool Generate(CubeWorld world)
        {
            if (offInitialized == false)
            {
                Random rnd = new Random();
                offX           = rnd.Next(0, 9999999);
                offY           = rnd.Next(0, 9999999);
                offInitialized = true;
            }

            TileManager tileManager = world.tileManager;

            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            int cutY = (int)(fromY + (toY - fromY) * 0.9f);
            int midY = fromY + (toY - fromY) / 2;

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    float d = FBM(x + offX, z + offY, octaves, 0.5f, freq, 1.0f / octaves, 2.0f);
                    //float d = MultiFractal(x, z, octaves, 0.5f, freq, 1.0f, 2.0f, 1.0f);

                    int y = midY + (int)(d * (toY - fromY));

                    //This line below can be used to make calderas
                    //if (y > cutY)
                    //    y = cutY - (y - cutY);

                    if (y > cutY)
                    {
                        y = cutY;
                    }
                    else if (y < fromY - 1)
                    {
                        y = fromY - 1;
                    }

                    while (y >= fromY)
                    {
                        tileManager.SetTileType(new TilePosition(x, y--, z), tileType);
                    }
                }
            }


            return(true);
        }
        public override bool Generate(CubeWorld world)
        {
            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius  = minRadiusRV.EvaluateInt(world);
            int maxRadius  = maxRadiusRV.EvaluateInt(world);
            int fromY      = fromYRV.EvaluateInt(world);
            int toY        = toYRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            Random random = new Random();

            for (int i = 0; i < iterations; i++)
            {
                int cx = random.Next(maxRadius + 1, tileManager.sizeX - maxRadius - 1);
                int cy = random.Next(maxRadius + 1, tileManager.sizeY - maxRadius - 1);
                int cz = random.Next(maxRadius + 1, tileManager.sizeZ - maxRadius - 1);

                int radiusX = random.Next(minRadius, maxRadius);
                int radiusY = random.Next(minRadius, maxRadius);
                int radiusZ = random.Next(minRadius, maxRadius);

                for (int x = cx - radiusX; x < cx + radiusX; x++)
                {
                    for (int z = cz - radiusZ; z < cz + radiusZ; z++)
                    {
                        for (int y = cy - radiusY; y < cy + radiusY; y++)
                        {
                            if (y >= fromY && y < toY)
                            {
                                if (random.NextDouble() > 0.25)
                                {
                                    if (allowEmptyAbove || y == tileManager.sizeY || tileManager.GetTileType(new TilePosition(x, y + 1, z)) != TileDefinition.EMPTY_TILE_TYPE)
                                    {
                                        if (tileManager.GetTileType(new TilePosition(x, y, z)) == overTile)
                                        {
                                            tileManager.SetTileType(new TilePosition(x, y, z), tileType);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #7
0
        public override bool Generate(CubeWorld world)
        {
            int trees = generator.Next(minRV.EvaluateInt(world), maxRV.EvaluateInt(world));

            TileManager tileManager = world.tileManager;

            for (int i = 0; i < trees; i++)
            {
                int x = generator.Next(maxLeavesRadius * 2, tileManager.sizeX - maxLeavesRadius * 2);
                int z = generator.Next(maxLeavesRadius * 2, tileManager.sizeZ - maxLeavesRadius * 2);

                PlantTree(x, z, world);
            }

            return(true);
        }
        public override bool Generate(CubeWorld world)
        {
            TileManager tileManager = world.tileManager;

            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            width  = tileManager.sizeX;
            height = tileManager.sizeZ;

            map = new float[width + 1, height + 1];

            //StartMidpointDisplacment();
            //Assign the four corners of the intial grid random color values
            //These will end up being the colors of the four corners of the applet.

            float c1, c2, c3, c4;

            c1 = (float)rnd.NextDouble();
            c2 = (float)rnd.NextDouble();
            c3 = (float)rnd.NextDouble();
            c4 = (float)rnd.NextDouble();

            DivideGrid(0, 0, width, height, c1, c2, c3, c4);

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    float d = map[x, z];

                    int y = fromY + (int)(d * (toY - fromY));

                    while (y >= fromY)
                    {
                        tileManager.SetTileType(new TilePosition(x, y--, z), tileType);
                    }
                }
            }

            return(true);
        }
        public override bool Generate(CubeWorld world)
        {
            TileManager tileManager = world.tileManager;

            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            //C3DPerlinNoise.Init();
            int seed = new Random().Next();

            int cutY = (int)(fromY + (toY - fromY) * 0.7f);

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    float d = GetRandomHeight(x, z, 1.0f, freq, 1.0f, 0.5f, octaves, seed);

                    int y = (int)(fromY + d * (toY - fromY)) - 1;

                    if (y > cutY)
                    {
                        y = cutY;
                    }
                    else if (y < fromY - 1)
                    {
                        y = fromY - 1;
                    }

                    while (y >= fromY)
                    {
                        tileManager.SetTileType(new TilePosition(x, y--, z), tileType);
                    }
                }
            }

            NoiseInitialized = false;

            return(true);
        }
Beispiel #10
0
        public override bool Generate(CubeWorld world)
        {
            int drops = generator.Next(minDropsRV.EvaluateInt(world), maxDropsRV.EvaluateInt(world));

            TileManager tileManager = world.tileManager;

            for (int i = 0; i < drops; i++)
            {
                int x = generator.Next(2, tileManager.sizeX - 2);
                int z = generator.Next(2, tileManager.sizeZ - 2);
                sidesToCheck = generator.Next(3, 10);

                int particles = generator.Next(minParticlesRV.EvaluateInt(world), maxParticlesRV.EvaluateInt(world));

                for (int j = 0; j < particles; j++)
                {
                    DropParticle(x, z, world);
                }
            }

            return(true);
        }
        public override bool Generate(CubeWorld world)
        {
            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    for (int y = fromY; y < toY; y++)
                    {
                        TilePosition pos = new TilePosition(x, y, z);
                        if (tileManager.GetTileType(pos) == TileDefinition.EMPTY_TILE_TYPE)
                        {
                            tileManager.SetTileType(pos, tileType);
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #12
0
        public override bool Generate(CubeWorld world)
        {
            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius  = minRadiusRV.EvaluateInt(world);
            int maxRadius  = maxRadiusRV.EvaluateInt(world);
            int minDepth   = minDepthRV.EvaluateInt(world);
            int maxDepth   = maxDepthRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            Random random = new Random();

            for (int i = 0; i < iterations; i++)
            {
                int startX = random.Next(maxRadius + 1, tileManager.sizeX - maxRadius - 1);
                int startZ = random.Next(maxRadius + 1, tileManager.sizeZ - maxRadius - 1);
                int startY = tileManager.GetTopPosition(startX, startZ);

                int radius = minRadius;

                int dx = random.Next(32) - 16;
                int dy = -random.Next(8);
                int dz = random.Next(32) - 16;

                int xf = startX << 4;
                int yf = startY << 4;
                int zf = startZ << 4;

                int depth = random.Next(minDepth, maxDepth);

                for (int d = 0; d < depth; d++)
                {
                    radius += random.Next(3) - 1;

                    if (radius > maxRadius)
                    {
                        radius = maxRadius;
                    }
                    else if (radius < minRadius)
                    {
                        radius = minRadius;
                    }

                    TilePosition center = new TilePosition(xf >> 4, yf >> 4, zf >> 4);

                    if (tileManager.IsValidTile(center - new TilePosition(radius + 1, radius + 1, radius + 1)) &&
                        tileManager.IsValidTile(center + new TilePosition(radius + 1, radius + 1, radius + 1)))
                    {
                        for (int x = center.x - radius; x <= center.x + radius; x++)
                        {
                            for (int y = center.y - radius; y <= center.y + radius; y++)
                            {
                                for (int z = center.z - radius; z <= center.z + radius; z++)
                                {
                                    tileManager.SetTileType(new TilePosition(x, y, z), 0);
                                }
                            }
                        }
                    }
                    else
                    {
                        break;
                    }

                    if (random.Next(0, 100) > 85)
                    {
                        dx = random.Next(32) - 16;
                        dy = -random.Next(8);
                        dz = random.Next(32) - 16;
                    }

                    xf += dx;
                    yf += dy;
                    zf += dz;
                }
            }

            return(true);
        }
Beispiel #13
0
        public override bool Generate(CubeWorld world)
        {
            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius  = minRadiusRV.EvaluateInt(world);
            int maxRadius  = maxRadiusRV.EvaluateInt(world);
            int fromY      = fromYRV.EvaluateInt(world);
            int toY        = toYRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            Random random = new Random();

            for (int i = 0; i < iterations; i++)
            {
                TilePosition center = new TilePosition(
                    random.Next(maxRadius + 1, world.sizeX - maxRadius - 1),
                    random.Next(fromY, toY),
                    random.Next(maxRadius + 1, world.sizeZ - maxRadius - 1));

                TilePosition radius = new TilePosition(
                    random.Next(minRadius, maxRadius),
                    random.Next(minRadius, maxRadius),
                    random.Next(minRadius, maxRadius));

                TilePosition position = new TilePosition();

                int axis = random.Next(3);

                for (int a1 = center[axis] - radius[axis]; a1 <= center[axis] + radius[axis]; a1++)
                {
                    position[axis] = a1;

                    int axis2 = (axis + random.Next(2) + 1) % 3;
                    int axis3;
                    if (axis == 0 && axis2 == 2 || axis == 2 && axis2 == 0)
                    {
                        axis3 = 1;
                    }
                    else if (axis == 0 && axis2 == 1 || axis == 1 && axis2 == 0)
                    {
                        axis3 = 2;
                    }
                    else
                    {
                        axis3 = 0;
                    }

                    radius[axis2] += random.Next(5) - 2;

                    if (radius[axis2] < minRadius)
                    {
                        radius[axis2] = minRadius;
                    }
                    else if (radius[axis2] > maxRadius)
                    {
                        radius[axis2] = maxRadius;
                    }

                    for (int a2 = center[axis2] - radius[axis2]; a2 <= center[axis2] + radius[axis2]; a2++)
                    {
                        position[axis2] = a2;

                        radius[axis3] += random.Next(5) - 2;

                        if (radius[axis3] < minRadius)
                        {
                            radius[axis3] = minRadius;
                        }
                        else if (radius[axis3] > maxRadius)
                        {
                            radius[axis3] = maxRadius;
                        }

                        for (int a3 = center[axis3] - radius[axis3]; a3 <= center[axis3] + radius[axis3]; a3++)
                        {
                            position[axis3] = a3;

                            if (position[1] < fromY)
                            {
                                position[1] = fromY;
                            }
                            else if (position[1] > toY)
                            {
                                position[1] = toY;
                            }

                            tileManager.SetTileType(position, 0);
                        }
                    }
                }
            }

            return(true);
        }