/BoneGen

Herringbone Wang Tile dungeon generators

Primary LanguageLuaThe UnlicenseUnlicense

BoneGen

Herringbone Wang Tile dungeon generators

The original work done by Sean T. Barrett on Herringbone Wang Tile dungeon generation produces some very high-quality dungeons, but the C library he graciously made available is hard to integrate into non-C/C++ applications. Here, I modified the STB source to output JSON instead of a bitmap, and used that JSON in a C# loader (then a Java loader). The plan is to keep porting, using the JSON in similar ways in different languages. A variant is used for Lua, which actually doesn't depend on any JSON library because I made another change to the STB source to generate Lua source code, and it's loaded easily by the Lua generator at runtime.

How to Use

The library works primarily by generating 2D char arrays to use as dungeons.

In Java

You can use a slightly-augmented version of this dungeon generator via Cuttlebone, which is on Maven Central and can be fetched with Maven, Gradle, Scala's SBT, Clojure's Leiningen, or similar tools using the instructions on that page. Cuttlebone also features Field of View code from Eben Howard's fantastic library SquidLib, but with the graphical display code removed to maximize portability. Cuttlebone's one dependency is Google GSON, a JSON parser lib. An example:

import squid.squidgrid.map.styled.*;
public class Example
{
    public static void main( String[] args )
    {
        DungeonGen dg = new DungeonGen();
        for(TilesetType tt : TilesetType.values())
        {
            dg.generate(tt, 80, 80);
            dg.wallWrap();
            System.out.println(dg + "\n");
        }
    }
}

In CSharp

It isn't available on NuGet yet, but there's a download available in the Releases section of this project. Usage is similar to Cuttlebone's DungeonGen, but it doesn't store the char[,] for later (yet, that should be a feature soon). BoneGen in C# has one dependency, JSON.NET. An example:

using BoneGen;
namespace MyStuff
{
    public class Example
    {
        public static void Main(string[] args)
        {
            int height = 80, width = 80;
            BoneGen bg = new BoneGen();
            char[,] dungeon = BoneGen.WallWrap(bg.Generate(TilesetType.DEFAULT_DUNGEON, height, width));
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Console.Write(dungeon[y, x]);
                }
            }
        }
    }
}

In Lua

The Lua library depends on the LuaJIT-supplied bit library, which can also be used on Lua 5.1 or 5.2 (it's available here, and you will need it if you aren't using LuaJIT). The only other code you need is in the Lua/bonegen/ folder, including the entire styles subfolder. It isn't organized into a module because I have no idea how Lua games would want it set up, and because I don't use Lua very much. Feel free to edit it or even submit a pull request if you organize it better! I would really appreciate it!

-- load bonegen.lua somehow first.
local donjon = wall_wrap(generate("default_dungeon", 60, 60, os.time()))
show2d(donjon)

License

Released into the public domain with the Unlicense (see LICENSE file in this directory).

Sample output

Using the TilesetType ROUND_ROOMS_DIAGONAL_CORRIDORS:

################################################################################
########..............############......############....############...........#
########...............##########.......############.....############..........#
########...............#########..........##########.....###########...........#
########...............########.............#########.....#########............#
#######.................######...............########.....#########............#
#.####.....##....#......#####.....#####.......########....#########.....#....#.#
#........##########.......#.....#######........#######.....#######......########
#.......#############..........#######..........######........#.......##########
#.......##############........########.....##....######..............###########
##......##############.......#########....####.....####............#############
###....###############......#########.....#####.....##.............#############
###.....##############.....#########.....######...................##############
####....##############....##########....########...................#############
#####....############....##########....##########..................#############
######....##########.....#########....############.................#############
#######....#######.........#####.....##############................###########.#
########....#####...........###.......##############...................######..#
########......##.............#.........#############......................##...#
#####..........#.............#.........#############.............###.......#...#
###....................................#############............#####..........#
##.....................................############......#....##########.......#
#...........##..........................##########......##################.....#
#............##...............#..........##....#.......####################....#
#............##...............##......................#####################....#
#............###.............########.................######################...#
#............###.............#########...............############.....######...#
##..........#####...........###########.............###########.........#####..#
##..........######.........###########..............##########...........#####.#
###........#########.....#############..............#########.............######
#####....############....#############..............#########.............######
######################....############..............########...............#####
######################.....############.............########...............#####
########.....#########.....###########..............########...............#####
######........#########.....#########................#######...............###.#
#####..........########.....#########................#######...............###.#
#####...........########....#########.....#....#......#####.................#..#
#####......#.....#######.....#######......########.....##......................#
#.##.......###....######........#.......###########..........#...........#.....#
#.........#####....######..............#############........###.........###....#
#......#########.....####............###############.......######......#####...#
#......##########.....##.............################.....########.....######..#
#.....###########...................#################....#########....##########
#......###########...................###############....##########....##########
#......############..................##############....##########....###########
#......#############.................#############....#########.....############
#......##############..................##########....########.........##########
#.....################....................#######...########...........#########
#.....################......................####....#######.............########
#......###############.......................###....#######.............########
#......###############............####..............######................######
#.#......############......#....##########...........#####.................#####
#####......#########......##################..........####..................##.#
######.....##....#.......###########...######.........####.....................#
#######.................##########.......#####........####...............#.....#
########................#########.........####........#####.............###....#
########...............#########...........####......######.............####...#
#########.............##########...........#####....########...........######..#
########..............#########.............#####....########.........########.#
########..............#########.............######....#########.....############
########..............#########.............#######....#########....############
########................########...........#########....#########....###########
#####....................#######...........##########...#########.....##########
####.......................######...........#########....#######......##########
##..........................######..........######.......######........#########
#..................####......#####.....##....###.........####...........########
#..................#####......###....#####....#...........##............########
#....###............######..........#######...............#.............########
#..#####............########........########............................########
########............#########......##########................#..........########
########............##########.....##########...............##..........########
#########..........############......########..............####........#########
#########..........#############......#######..............#####......##########
######...............#############....########............########....##########
#####....###....##....#############....#######............#######....###########
####....###########....#############....#######..........#######....############
###.....############....#...#########....#######........#######....#############
###....#############..........#######....#########....########........##########
##.....##############..........######....####################.............######
################################################################################

Using the TilesetType DEFAULT_DUNGEON:

################################################################################
#....########......##.......######..#####.......####.......###############.....#
#.....######................######......#........###..........############.....#
#......####............##...#..............#......##...........#####...#####...#
#.......##....###......##..................#..#...##...........####.....####...#
#.##....##....####.....##.......#####......#.....###............##.......###...#
#.##....##....#####....##.......#................###.....................###...#
####...####...###########..##...#............#..####.......##............###...#
####...####...#########.....#####......##......#####.......##........##........#
####..######..#########.....########...###.....#####..#########.....###........#
####..######..############..########...#####..######..#########.....############
#..#.....##..................#######...#####.....##......######......###########
#..#......#.......................##...#####...............###.............#####
#..#......#..#########..###.......######.#####.............###....#........#...#
#..####...#..##..........##..###..######..####.......##.....#.....##..###..#...#
#.....#......##..........##..###..##.......###........###.........##..#........#
#.....#......###..#########..###...........###..........##........###.#........#
#..####......................###......##...###...........##......######........#
#........##..................#######..###........###.....####....######........#
#........#####..######..############..###........###.....#####..#########.....##
############.....#####......########..################..######......#####.....##
###########........###.............#..#############........###..............####
#........##........###.............#.........######........#................#..#
#.........#........###.........#...#.........#....#..####..#......###########..#
######....####.....###....######...#..#####..#....#.....#..#..##...............#
#............##....###....#....#####..###...............#..#..##...............#
#.............###.........#....#......###...............#.........##############
#.........#...............#...........###.........#.....#......................#
#........##........#####..#...........###........############..................#
######..######.....#####..######......#####.....################..#####..#######
######..##############.....#####..#########.....###........##......#####......##
######..###........##........###................###........###.....#####......##
#....#.............##......................................####..##########...##
#....#......##..#...#..##..........##..####..................##..#...#....#....#
#.#..#..##..##..#...#..###........##......#########..............#...#....#....#
#.......##......#......####......##..........######..............#...#....####.#
#.#.....##......#......#####....##............#####.......................####.#
#....#..###.##..###.#########...#....##........####...........#................#
#....#..#####.....###.......#####....#####......###........####..#######.......#
##..#########.....###........###.....#####......########..#####......###.....###
##......#####.....####..##...###.....#####..#########.....#####......#####..####
##......#.........###....##..###.......##...........#.....#########..##........#
##......#................##..#####.....##...........#..........####..##........#
##......#..####...........#..#...##....####..########..#.......####...#..####..#
###....##..####...........#..#....##...##.....#........#....#...###...#..#..#..#
####..###..####...........#........##..##.....#........#....#...###......#..#..#
#..........#.............##.........#......#..#....#........##..###......#..#..#
#..........#.......##....##..#......#......#..#....#......####........####..#..#
####..######..########..##...###....#..#####..#....#......####.......##.....####
####..######..############..#####......###....######......########..###........#
##.....#####.....#######....#####......###.....#####......#####.....###..#.....#
#......####........#.........###....#..##........##.......#..##.....###..#.....#
#......#..#........#................#..##.........#...#####..#...........#...###
#......#..#........................##..##.........#...#......#...........#...#.#
#####..#...........................##..#######....#..........#..##...#...#...#.#
#..........................###....##.........#....#..........#..#...##...#####.#
#............................#...###.........#........#......#.....###.........#
#####...........#....#.......######....##.............####...#....#####........#
###########.....#....#.......######....##........###.....#...#...######.......##
#############...######.....#########..##############.....#####..#########.....##
#..#########.....#####..#########.....################..######......#####.....##
#...##########..######..#....#..#.....################.....##...........##.....#
#....########....#####..#....#..#...........##########.....##...........###....#
#.......#####....#####..#....#..#...........##.....######..##....#####..###....#
#.......######..######..#....#..#......#....##......##.....##....#####..###....#
#....#..........######..###..#..#......#....##.......#.....##....###....###....#
#....#.......................#..#####..#.....#.......#..#........###....###....#
#....#..#####................#.........##...............#........###....##.....#
#....#..########..####.......#.........##........##.....#####.....#######......#
######..#####......###.....#####..#########.....###.....######.....#####......##
####....#####......#####..######......#####.....################...#####..######
#........####......#####..#####.......#..##.....###........#####.....###..#...##
#...........#......#####..#...#...#####..#.................######.....##..#...##
#...........############..#...#...#......#.................#######....##..#...##
#.................######..#...#..........#..##...###..###..#######....##..#...##
#......###.............#..#...#..........#..#...####..###......###....##..#...##
#........#..#..........#..#.......#......#.....####....##.......##.............#
##.......####....####..#..#.......####...#....#####.....#####...##.............#
##.......####....####..#..#..###.....#...#...######......#####...#...#####..####
################################################################################