Example #1
0
    void AddSingleStair(int xIndex, int yIndex, int layerPos, HexType[,,] tiles)
    {
        if (tiles[layerPos, yIndex, xIndex] != HexType.None || layerPos % 2 == 1)
        {
            bool left     = HexHelp.CheckDirRaw(xIndex - 1, yIndex, layerPos, tiles);
            bool right    = HexHelp.CheckDirRaw(xIndex + 1, yIndex, layerPos, tiles);
            bool top      = HexHelp.CheckDirRaw(xIndex, yIndex + 1, layerPos, tiles);
            bool bottom   = HexHelp.CheckDirRaw(xIndex, yIndex - 1, layerPos, tiles);
            int  adjacent = 0;
            if (left)
            {
                adjacent++;
            }
            if (right)
            {
                adjacent++;
            }
            if (bottom)
            {
                adjacent++;
            }
            if (top)
            {
                adjacent++;
            }

            bool hasBelow = HexHelp.CheckBelow(xIndex, yIndex, layerPos, tiles);
            bool hasAbove = HexHelp.CheckAbove(xIndex, yIndex, layerPos, tiles);

            if (hasBelow && !hasAbove && adjacent == 1 && Random.value <= stairChance)
            {
                //
                if (top && HexHelp.CheckDirRaw(xIndex, yIndex - 1, layerPos - 1, tiles))
                {
                    tiles[layerPos, yIndex, xIndex] = HexType.Stairs0;
                }

                else if (left && HexHelp.CheckDirRaw(xIndex + 1, yIndex, layerPos - 1, tiles))
                {
                    tiles[layerPos, yIndex, xIndex] = HexType.Stairs90;
                }

                else if (bottom && HexHelp.CheckDirRaw(xIndex, yIndex + 1, layerPos - 1, tiles))
                {
                    tiles[layerPos, yIndex, xIndex] = HexType.Stairs180;
                }

                else if (right && HexHelp.CheckDirRaw(xIndex - 1, yIndex, layerPos - 1, tiles))
                {
                    tiles[layerPos, yIndex, xIndex] = HexType.Stairs270;
                }
            }
        }
    }
Example #2
0
    void DrawBaseHexes()
    {
        int numLayers = iStats.layerStats.Count;

        //numLayers = Mathf.Min (iStats.layerStats.Count, 3);
        for (int layer = 0; layer < numLayers; layer++)
        {
            for (int y = 0; y < size; y++)
            {
                for (int x = 0; x < size; x++)
                {
                    HexType thisType = tiles[layer, y, x];
                    if (thisType == HexType.Earth)
                    {
                        bool emptyBelow = !HexHelp.CheckBelow(x, y, layer, tiles);
                        bool emptyAbove = !HexHelp.CheckAbove(x, y, layer, tiles);
                        int  prefabNum  = (int)HexDraw.middle;
                        if (emptyBelow && emptyAbove)
                        {
                            prefabNum = (int)HexDraw.both;
                        }
                        else if (emptyBelow && !emptyAbove)
                        {
                            prefabNum = (int)HexDraw.bottom;
                        }
                        else if (emptyAbove && !emptyBelow)
                        {
                            prefabNum = (int)HexDraw.top;
                        }

                        float height = 2 * layer + baseHeightStats.GetAt(x, y) - baseHeightStats.GetAvgHeight();
                        GenerateSingleHex(x, y, height, prefabNum);
                    }
                }
            }
        }
    }