Ejemplo n.º 1
0
    public override void generate(System.Random rnd, LayerData layerData, MapAccessor accessor)
    {
        if (layerData.generateCaves)
        {
            int[,] map = this.makeCaves(rnd, layerData.lakeType, accessor.size);

            // Set tiles.
            for (int x = 0; x < accessor.size; x++)
            {
                for (int y = 0; y < accessor.size; y++)
                {
                    int      id   = map[x, y];
                    CellData cell = null;

                    if (id == 0)
                    {
                        cell = Main.instance.tileRegistry.getAir();
                    }
                    else if (id == 2)
                    {
                        cell = layerData.lakeType == EnumLakeType.WATER ? this.waterTile : this.lavaTile;
                    }

                    if (cell != null)
                    {
                        accessor.setCell(x, y, cell);
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    private void makeVein(System.Random rnd, CellData oreCell, OreSettings setting, MapAccessor accessor, int i1, int j1)
    {
        int chunkX = rnd.Next(0, 16); // Don't start on edge cells.
        int chunkY = rnd.Next(0, 16);

        int size = rnd.Next(setting.size.x, setting.size.y + 1);

        Rotation lastDir = null;

        for (int i = 0; i < size; i++)
        {
            int x = (i1 * 16) + chunkX;
            int y = (j1 * 16) + chunkY;

            CellData c = accessor.getCell(x, y);
            if (c is CellDataMineable)
            {
                accessor.setCell(x, y, oreCell);
            }

            Rotation r = Rotation.ALL[rnd.Next(0, Rotation.ALL.Length)];

            if (lastDir != null && lastDir == r)
            {
                r = r.opposite();
            }

            chunkX += r.vector.x;
            chunkY += r.vector.y;
        }
    }
Ejemplo n.º 3
0
    //[SerializeField, Min(0)]
    //private int oblongScale;

    public override void generate(System.Random rnd, LayerData layerData, MapAccessor accessor)
    {
        if (!layerData.generateBlockerRocks)
        {
            return;
        }

        int rockCount = rnd.Next(this.rockCount.x, this.rockCount.y + 1);

        for (int i = 0; i < rockCount; i++)
        {
            int x = rnd.Next(1, accessor.size - 1);
            int y = rnd.Next(1, accessor.size - 1);

            // Pick the size.
            int width  = rnd.Next(this.rockSize.x, this.rockSize.y + 1);
            int height = rnd.Next(this.rockSize.x, this.rockSize.y + 1);
            //int height = width + rnd.Next(-this.oblongScale, this.oblongScale + 1);
            //if(rnd.Next(0, 2) == 0) {
            //    // Swap width and height
            //    int temp = width;
            //    width = height;
            //    height = temp;
            //}

            // Place Cells.
            for (int x1 = 0; x1 < width; x1++)
            {
                for (int y1 = 0; y1 < height; y1++)
                {
                    int cellX = x + x1;
                    int cellY = y + y1;

                    // Randomly skip corners
                    if ((
                            (x1 == 0 && y1 == 0) ||
                            (x1 == 0 && y1 == height - 1) ||
                            (x1 == width - 1 && y1 == height - 1) ||
                            (x1 == width - 1 && y1 == 0))

                        && rnd.Next(0, 3) == 0)
                    {
                        continue;
                    }

                    if (accessor.getCell(cellX, cellY) != Main.instance.tileRegistry.getAir())
                    {
                        accessor.setCell(cellX, cellY, this.blockerRockCell);
                    }
                }
            }
        }
    }
Ejemplo n.º 4
0
    public override void generate(System.Random rnd, LayerData layerData, MapAccessor accessor)
    {
        int end = accessor.size - 1;

        for (int x = 0; x < accessor.size; x++)
        {
            for (int y = 0; y < accessor.size; y++)
            {
                if (x == 0 || y == 0 || x == end || y == end)
                {
                    accessor.setCell(x, y, this._bedrock);
                }
            }
        }
    }
Ejemplo n.º 5
0
    public override void generate(System.Random rnd, LayerData layerData, MapAccessor accessor)
    {
        int chunkCount = accessor.size / 16;

        for (int chunkPosX = 0; chunkPosX < chunkCount; chunkPosX++)
        {
            for (int chunkPosY = 0; chunkPosY < chunkCount; chunkPosY++)
            {
                foreach (OreSettings setting in layerData.oreSpawnSettings)
                {
                    if (setting != null && setting.cell != null)
                    {
                        for (int i = 0; i < setting.veinsPerChunk; i++)
                        {
                            this.makeVein(rnd, setting.cell, setting, accessor, chunkPosX, chunkPosY);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 6
0
 public override void generate(System.Random rnd, LayerData layerData, MapAccessor accessor)
 {
     if (this._skull == null)
     {
         Debug.LogWarning("Skull not set for world generation feature FeatureRareSkull");
     }
     else
     {
         // Try up to 1000 times to place the skull.
         for (int i = 0; i < 1000; i++)
         {
             int x = Random.Range(0, accessor.size);
             int y = Random.Range(32, accessor.size); // Don't let it be near the bottom and in a starting plot.
             if (accessor.getCell(x, y) is CellDataMineable)
             {
                 accessor.setCell(x, y, this._skull);
                 break;
             }
         }
     }
 }
Ejemplo n.º 7
0
    public override void generate(System.Random rnd, LayerData layerData, MapAccessor accessor)
    {
        if (accessor.depth == 0)
        {
            int pipeCount = 3;

            Rotation pipeState = Rotation.UP;
            for (int i = 0; i < pipeCount; i++)
            {
                int x = Random.Range(0, accessor.size);

                Position pipePos = new Position(x, accessor.size - 1, 0);

                if (accessor.getCell(pipePos.x, pipePos.y) == this._pipe)
                {
                    continue; // don't start a pipe on top of another one
                }

                bool direction        = true;
                int  straightDistance = 0;
                int  SAFETY           = 0;
                while (true)
                {
                    SAFETY++;

                    straightDistance++;

                    accessor.setCell(pipePos.x, pipePos.y, this._pipe);
                    accessor.setRot(pipePos.x, pipePos.y, pipeState);

                    if (straightDistance > 10 || (straightDistance > 4 && Random.value < 0.25))
                    {
                        direction        = !direction;
                        straightDistance = 0;
                    }

                    if (direction)
                    {
                        pipePos = pipePos.add(0, -1);
                    }
                    else
                    {
                        pipePos = pipePos.add(x <= (accessor.size / 2) ? -1 : 1, 0);
                    }

                    if (!accessor.inBounds(pipePos.x, pipePos.y))
                    {
                        break;
                    }

                    if (SAFETY > 500)
                    {
                        print("safety break");
                        break;
                    }
                }

                pipeState = pipeState.clockwise();
            }
        }
    }
Ejemplo n.º 8
0
 public abstract void generate(System.Random rnd, LayerData layerData, MapAccessor accessor);
Ejemplo n.º 9
0
    /// <summary>
    /// Fully generates the Layer at the passed depth and places it
    /// into the World's storage.
    /// </summary>
    public void generateLayer(World world, int depth)
    {
        int layerSeed = world.seed * (depth + 1);

        MapAccessor accessor  = new MapAccessor(world.mapSize, depth);
        LayerData   layerData = this.getLayerFromDepth(depth);


        // Fill the map with the Layer's fill cell.
        for (int x = 0; x < accessor.size; x++)
        {
            for (int y = 0; y < accessor.size; y++)
            {
                accessor.setCell(x, y, layerData.getFillCell(world, x, y));
            }
        }


        // Generate all of the features.
        foreach (FeatureBase feature in this.features)
        {
            feature.generate(new System.Random(layerSeed), layerData, accessor);
        }


        Layer layer = new Layer(world, depth);


        // Apply the accessor to the Layer.
        for (int x = 0; x < accessor.size; x++)
        {
            for (int y = 0; y < accessor.size; y++)
            {
                Rotation r = accessor.getRot(x, y);
                layer.setCell(
                    x,
                    y,
                    accessor.getCell(x, y),
                    r == null ? Rotation.UP : r,
                    false);
            }
        }


        // Generate the hardness map and apply it.
        float[,] noise = NoisemapGenerator.computeNoiseMap(
            this._noiseSettings,
            world.seed,
            world.mapSize,
            depth);
        for (int x = 0; x < world.mapSize; x++)
        {
            for (int y = 0; y < world.mapSize; y++)
            {
                float n        = noise[x, y];
                int   hardness = n < 0.333f ? 0 : (n < 0.666f ? 1 : 2);
                layer.setHardness(x, y, hardness);
            }
        }


        world.storage.setLayer(layer, depth);


        // Generate all of the structures that belong on this Layer
        Random.InitState(layerSeed);

        foreach (StructureBase structure in layerData.structures)
        {
            if (structure != null)
            {
                structure.generate(world, depth);
            }
        }
    }