Example #1
0
    /// <summary>
    /// Places a roof over the specified building.
    /// The roof will only cover the tile specified by 'roofTileID'. If this is null,
    /// then a roof over the total building will be created
    /// </summary>
    /// <param name="vox"></param>
    /// <param name="build"></param>
    /// <param name="roofTileID"></param>
    public static void AddRoof(GenerationRandom genRan, BuildingVoxels vox, Building build, Voxel roofVox, int roofStartY = 5, Tile roofTileReplace = null)
    {
        if (roofTileReplace == null)
        {
            Vec2i dir = genRan.RandomQuadDirection();
            dir.x = Mathf.Abs(dir.x);
            dir.z = Mathf.Abs(dir.z);

            Vec2i start   = new Vec2i(build.Width / 2 * dir.x, build.Height / 2 * dir.z);
            Vec2i end     = start + new Vec2i(dir.z * build.Width, dir.x * build.Height);
            LineI t       = new LineI(start, end);
            float maxDist = Mathf.Max(t.Distance(new Vec2i(0, 0)), t.Distance(new Vec2i(build.Width - 1, 0)),
                                      t.Distance(new Vec2i(0, build.Height - 1)), t.Distance(new Vec2i(build.Width - 1, build.Height - 1)));

            int   maxHeight = genRan.RandomInt(4, 6);
            float scale     = maxHeight / (maxDist + 1);
            //float scale = 0.7f;

            for (int x = 0; x < build.Width; x++)
            {
                for (int z = 0; z < build.Height; z++)
                {
                    int height = (int)Mathf.Clamp((maxDist - t.Distance(new Vec2i(x, z)) + 1) * scale, 1, World.ChunkHeight - 1);
                    for (int y = 0; y < height; y++)
                    {
                        vox.AddVoxel(x, Mathf.Clamp(roofStartY + y, 0, World.ChunkHeight - 1), z, roofVox);
                    }
                }
            }
        }
    }
Example #2
0
    private void GeneratePathBranch(List <Vec2i> nodes, int width = 3, int remIt = 5)
    {
        if (nodes.Count == 0)
        {
            return;
        }

        Vec2i start = GenerationRandom.RandomFromList(nodes);
        Vec2i dir   = GenerationRandom.RandomQuadDirection();
        Vec2i perp  = Vec2i.GetPerpendicularDirection(dir);


        Vec2i test = start + dir * NodeSize;

        int nodeX = test.x / NodeSize;
        int nodeZ = test.z / NodeSize;

        if (!InNodeBounds(nodeX, nodeZ))
        {
            remIt--;
            if (remIt <= 0)
            {
                return;
            }
            //nodes.Remove(start);
            GeneratePathBranch(nodes, remIt);
            return;
        }
        //Check if node is outside of main map
        if (nodeX >= MapNodeSize - 1 || nodeZ >= MapNodeSize - 1 || NodeMap[nodeX, nodeZ])
        {
            remIt--;
            if (remIt <= 0)
            {
                return;
            }
            //nodes.Remove(start);
            GeneratePathBranch(nodes, remIt);
            return;
        }
        int length = GenerationRandom.RandomInt(3, 7) * NodeSize;

        AddPath(start, dir, length, width, NodeMap, nodes, NodeSize);
    }