Tuesday, November 22, 2016

Javascript World Generation

My fingers are aching after spending the past 3 days converting my fractal world generation code to Javascript.  My vision is to produce a D&D world editor in Javascript with the following features:

  • Intelligent terrain generation.
  • Editing tools to "raise" and "lower" parts of the map with the mouse to shape the terrain.
  • Try different, randomized weather patterns to see how they modify the terrain.
  • Control the temperature and moisture levels of the world, get desert or jungle worlds.
This is the first step in my grand plan to create the ultimate DM's toolbox online.  Imaging having civilizations, cities, dungeons, all generated on the map for you as a starting point for a new campaign.  And then have the ability to add and track new information as the campaign progresses.  Need a new city?  Click a button and have a randomized city appear, leveraging the community-driven random tables of dmmuse.com.  

It feels good to have this much code working smoothly in Javascript/HTML5 canvas in such short order!

Here's some sample output of my Javascript world generator, I hope to get it running in a live page soon.

The mini-map.  Note that desert areas appear in a more washed out color, and swampy areas (lower right) appear in a swampy greenish.

A portion of the wetlands that appear in the lower right of this generated world.  I can imagine the tribes of heathen lizardfolk and bullywugs just looking at this!

Thursday, October 1, 2015

DMMuse.com Dungeon Generation Primer

DMMuse.com is a site where I publish random generators and tools for D&D.  Currently I've been working on a Dungeon Generator.  What makes the DMMuse.com Dungeon Generator different is its ability to accept content contributions from anyone.  This article describes how to add content to the generator.  The more people that add content, the fresher the generated dungeons will be for everyone!

Generator Syntax

Adding content to the Dungeon Generator involves adding new entries to various "tables" hosted at DMMuse.com.  When you add an entry to a table, you can optionally use DMMuse.com "generator syntax".  This is a powerful set of markup that lets you randomize and vary your entry's text each time that it's generated.  The full scope of the generator syntax is explained on this help page at DMMuse.com.

Dungeon Rooms

The Dungeon Generator works by first collecting a group of random room descriptions, and then building out a map to match those descriptions.  The room descriptions themselves come from a DMMuse.com table called Dungeon Rooms.

The entries in Dungeon Rooms follow a few conventions.  They start by the name of the room, in bold, followed by a comma, and then the room description.  To make text bold in an entry, enclose it in HTML bold tags - <b> and </b>.

Here's an example Dungeon Rooms entry:

<b>Empty Room</b>, not much to see here.

The entry can include a number of optional tags.  The first tag tells the Dungeon Generator to use a specific room shape template when generating the map for the room.  For example, to tell the Generator to always make the room square, do this:

<b>Square Room</b>, will always be square. template=square

The following is a list of shape templates that are currently available.  Check back, I will update this article as more shape templates are added:

cavern, circle, oval, shaft, small, square, warrens

The "decor" tag tells the Generator to add a piece of visual decoration to the room.  A few pieces of decor are available, more will be added in the future:

chasm, fountain, moat, water

The "inject" tag injects monsters into the dungeon room entry.  The tag should specify the name of the (D&D e5) monster, followed by a comma, followed by the number of monsters.  You can use dice notation when specifying this number.  For example, to add 1d6 orcs to a room:

<b>Orc Room</b>, they attack! inject=orc,1d6

Because of the way the Generator parses text, monster names that contain spaces can be problematic. For this reason, replace any spaces in a monster name with asterisks (*).  The Generate will replace these asterisks with spaces when it parses the text.

<b>Elemental Cavern</b>, a large natural cavern. inject=air*elemental,1d3

Dungeon Dressing

In addition to the rooms themselves, the Dungeon Generator adds pieces of dungeon dressing.  These are simple things like sounds, smells, scratches on the walls, or discarded gear, that add interest.  You can contribute dungeon dressing to DMMuse.com by adding entries to the Dungeon Dressing table.


The Dungeon Generator supports optional themes.  The user can select select one or more themes to add distinct flavor to the generated dungeon.  Themes are implemented by adding entries to two DMMuse.com tables, Dungeon Theme Flair, and Dungeon Theme Bosses, and by adding themed rooms to the Dungeon Rooms table itself.

To add a specially-themed dungeon room, use the "theme" tag at the end of the entry.  Below is a list of themes that DMMuse.com currently supports:

earth, darkness, kobold

To add a new kobold-themed rule, for example, add something like this to Dungeon Rooms:

<b>Kobold Room</b>, several of the [@PersonalityTraits] critters are here. theme=kobold inject=kobold,2d6

Dungeon Theme Flair items are special entries that can appear in dungeon rooms when the specified theme was selected.  Unlike other entries, you should preface the Dungeon Theme Flair entry with one of the following things ...


"Contains" entries are like pieces of dungeon dressing that correspond to the theme.  "Trap" entries are traps that are specific to the theme.  And "Monster" entries are monsters that might be used if the theme is selected.  Place the names of the monsters themselves in HTML bold tags.

Don't forget to append the appropriate "theme" tag at the end of these entries.  And note, unlike the other entries, these don't have periods at the end.  An example of each Dungeon Theme Flair is presented below:

Contains: a lone kobold egg, hatching theme=kobold

Trap: a jar of green slime breaks and shatters, triggered by [@TrapTriggers] theme=kobold

Monster: [2d6+2] <b>kobolds</b>, [1d4] of them riding <b>giant lizards</b> theme=kobold

The final piece of customization you can provide to a theme is a boss monster, represented by entries in the Dungeon Theme Bosses table.  Use HTML bold tags to enclose monster names, and explore the DMMuse.com random name generation capability to add a unique name to bosses.  Read more about random names in the Generator Syntax help page.

Here's an example kobold boss.  Note the "theme" tag at the end, don't forget this:

[RandomName;kobold] is the [king|head|ruler] of the tribe, a <b>kobold</b> "great wyrm" of some [stature|renown|intelligence] theme=kobold

There you have it!  Hopefully some of you will start adding your own entries, keeping the Dungeon Generator's results always fresh and surprising!

Wednesday, September 23, 2015

Rendering Dungeons

Been working on rendering the randomly generated dungeons in a more game-friendly format.  The 24-pixel tiling is looking pretty good.  I've got basic doors placed and rendered.  A next step will be adding some variety to the doors, to get secret doors, locked doors, iron-bound doors, bricked-up doorways, etc.  I want to also start keying these to a "difficulty level" input parameter.  The difficulty will also eventually drive things like trap placement and monsters.

Monday, September 21, 2015

Procedural Dungeons

Taking a small break from wilderness generation, on to the dungeons that will eventually be populating that wilderness.  Here's a sample 20 room dungeon layout based on a new algorithm that I just completed.

The dungeon generation library features a modular architecture based on room and passage "carvers".  The "carvers" create room and passage shapes in a variety of styles.  Since the system is modular, it will be easy to create specific environments, like caverns, mines, etc.

The next task here is to scan for door placement and render this in a format that's more usable for gaming.  Ultimately I see this as the basis for a DMMuse themed dungeon generator.

Saturday, September 19, 2015

A Slicker Presentation

With the bulk of the terrain generation under my belt, I spent some time working on the visual presentation of the hex map.  I feel that the maps were looking too clunky and cluttered, with too many terrain icons.  Since I had a fully detailed elevation map at my disposal, why not use that to create nice looking gradient terrain hexes, rather than relying on terrain icons to represent everything?  I kept terrain icons for areas of high mountains and heavy forests, but the nice gradient of hex colors now presents a pleasing aesthetic to the map.

Oh, I also cleaned up river generation a bit more.  My prior algo was producing some truly crazy and maze like rivers.  While they looked interesting, they were decidedly not natural looking.  This algo uses the previous one to determine an ultimate destination for the river, but then lets the river move naturally toward that destination, while introducing some subtle, meandering variations.

I'm starting to collect my thoughts on the next steps, which will involve placing cultures and their artifacts (settlements, dungeons, ruins, etc) on the map!

Friday, September 18, 2015

Better Rivers

I cranked up the World Generator after a long hiatus, and promptly improved the river generation.  I had to first re-factor the generator to understand that it was creating a hex map instead of a 2D grid.  I then changed the river generation to render rivers along the center of hexes, rather than along hex-sides.

The rivers start at a high-elevation point on the map, then use a very simple algorithm to determine their flow.  I just pick the next hex of the river to be the neighbor hex with the lowest elevation, excluding any hexes already used for the particular river being generated.  The result are rivers that meander nicely, mimicking the winding rivers we find in nature.

Monday, January 12, 2015

Hex Terrain Mapping Complete

Wetlands Added

The terrain mapping for my fractal world generation is now complete, with the addition of swamps and an occasional fungal forest.  I decided to take the simple approach to swamps, and set a terrain hex to swamp if its moisture level was close to the high end, and the ground was level.  Fungal forests can appear in these same conditions, but can quickly grow to cover over much of the surrounding terrain, so they add somewhat of a wildcard to the mix.

Sample World

Here's the randomly seeded world #1482326029 (yes, you can regenerate the same world by supplying the seed value) in snapshot.  I went with 40% land and a size of 768x300 hexes.  This world happened to have a good range of terrains, from ultra-lush jungles and swamps to arid deserts.  I'll highlight a couple area of note.

Fertile Delta

Here a river flows between two mountain ranges, creating a fertile area of lush forests and jungles amidst a generally arid desert environment.

Fungal Forest

There happened to be only one fungal forest generated on this world, in the red box below.  This bizarre terrain could form the basis of quests to retrieve rare spell components.

Campaign Start?

I've often used islands as a starting point for campaigns.  Their limited geographic area established handy constraints for low level parties.  Once the potential adventures on the island are resolved, its time to board a ship and head for new shores.  The generator produces worlds with many realistic islands and archipelagos to pick from.

What's Next

Next steps will be laying the groundwork for introducing cultures/races into the world, the birth of settlements, conflicts, expansion, etc.