To what extent is procedural generation possible?

Ask about mapping, UDMF, using DoomBuilder/editor of choice, etc, here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

To what extent is procedural generation possible?

Postby G3Kappa » Tue May 14, 2019 2:18 pm

I'm working on a hefty mod with a friend, and I was wondering whether it was possible to have levels with a randomized layout. If it helps in setting the tone, I'm new to modding Doom but I've been programming for a long time.

Anyway, I stumbled upon a few tools, namely Oblige and WadC. From what I understand maps must be compiled, and these tools can be used or invoked from a batch script to generate maps procedurally and compile them.
But that's still far from generating a level at run-time.

I was about to give up, then I stumbled upon this thread by @Nash: viewtopic.php?t=25592. Despite the 2016 revival, the repo has been removed from Github and I'm left with nothing but speculation. Did Nash actually manage to generate levels at run-time? Did anyone else?

My goal is to generate a bunch of interconnected rooms, so I have no need for exceedingly complex geometry. A bunch of rectangular rooms and corridors are fine. Furthermore, since the rooms are going to be prefabs, I don't even need complex procedural generation or map editing techniques. ZDoom has come very far over the years, so maybe this is possible now through ACS? I'm willing to try anything here :?
User avatar
Joined: 14 May 2019

Re: To what extent is procedural generation possible?

Postby Empyre » Tue May 14, 2019 3:28 pm

Here is a Zandronum project that does something similar to what you are describing:
User avatar
The Ultimate Shining Example of Humility
Joined: 05 Apr 2007
Location: Garland, TX, USA

Re: To what extent is procedural generation possible?

Postby Caligari87 » Tue May 14, 2019 3:39 pm

The most you can "procedurally generate" at runtime as far as actual map geometry is some predefined generic structures, such as a grid of sectors for example.

For "building" maps out of prefab rooms, you can place all your rooms in the map and then handle transitions between them with line portals and/or silent teleports, depending on your needs and how cleverly you can hide the "seams".

Some examples I know of, there's probably more:

User avatar
I'm just here for the community
User Accounts Assistant
Joined: 26 Feb 2004
Location: Salt Lake City, Utah, USA
Discord: Caligari87#3089

Re: To what extent is procedural generation possible?

Postby gramps » Wed May 15, 2019 2:21 am

I've managed to link up prefab areas using an approach similar to Wang tiles, where portals on each edge of an area define an edge of a tile. I've built a small zscript library to help with this; it handles generating the dungeon at runtime, linking up the portals, rotating map geometry, actors, floor and ceiling flats, and so on. It's somewhat configurable, as far as tile size, required number of areas for a valid dungeon, etc. The configuration file uses the same syntax as mapinfo.

There are a few issues with this currently. Savegames don't work well in the current gzdoom version, because the part of the gzdoom that allows level manipulation at map init time doesn't have access to anything in the savegame. This could be mitigated on the modder's end by carefully managing savegames, by using hubs and teleporting the player to a static, safe map to save the game, and back into the dungeon on loading. But this can be foiled by players saving the game manually, or autosaves, which there are currently no way to disable on a per-map basis (or at all).

Also, the level manipulation currently available in gzdoom is limited. You can move map geometry around, but you can't add new geometry. This means the tiles themselves need to be placed, they can't be used as templates to create copies of. But that's not a huge problem, it's easy enough to create multiple copies in the editor. Hopefully support for this kind of thing will improve as the need arises.

If you're interested in using the library or getting ideas from it, create an account and send me a private message and I'll send you a link to the github repo and help you get started with it.
Joined: 18 Oct 2018

Re: To what extent is procedural generation possible?

Postby G3Kappa » Wed May 15, 2019 10:09 am

Hey, I'm OP and I made an account (forgot to activate it before posting hehe)

First off, thank you all for your great advice. Right now I'm experimenting with teleporters: I make a map with a bunch of room layouts, and connect each door line to a teleporter destination like this.
All teleporters are given a TID that represents the pool of the room they originate from, so that for example you can have a pool for normal rooms, a pool for secret rooms, and a pool for boss rooms. (Think Gungeon while we're at it)

Then I set up a WorldLoaded event handler and iterate all lines with a special tag that indicates whether they're an entrance line or an exit line. The idea is to build the layout by connecting each pair of doors properly by only using some of the available combinations, but not all. This way, I don't even need to care about the orientation of each room, since the player will be teleported and re-oriented appropriately. This completely screws up the automap but then again I can make a minimap of sorts on the HUD if that ever becomes an issue.

A pressing problem is that I can't iterate the actual teleporter destinations, as they are things and not actors and so LevelLocals.CreateActorIterator doesn't work. My previous attempts of building teleporters by only using lines have failed, but I might have messed something up. I'm going to have a deep look at the mods you've linked and report back. Meanwhile, got any ideas?

EDIT: Okay, Line_SetPortal works and it's awesome because it's also a visual portal. I think I can figure it out on my own from this point on, but I'm also interested in what you had to say @gramps. I might drop you a PM later, when my account actually has the rights to do so lol

EDIT2: I'm getting this to work, but I'm still having a few issues. Gotta dive into LevelCompatibility.
User avatar
Joined: 14 May 2019

Re: To what extent is procedural generation possible?

Postby G3Kappa » Thu May 16, 2019 1:32 am

Get a load of this pathetically compressed webm!

Thanks to you guys, and especially to gramps who also helped me in private, I managed to get this damn thing working. In the end, I refactored my previous event handler code to subclass LevelCompatibility, which is where map-altering logic belongs.
I scrapped the idea of entrance and exit lines and teleporter destinations, and managed to simplify it to a single line for each door with an UDMF property that specifies what pool this door can be connected to. So that, for example, you can have a room with three doors of pool "REGULAR" and one door of pool "ITEM", then a room with a single door of pool "ITEM", and they'll get linked up.

One thing that kind of bothered me was that ZScript has only rudimentary data structures, and I had to implement a rudimentary dictionary to compensate. Nothing big, but support for a few basic data structures would go a long way towards helping with procedural generation.
User avatar
Joined: 14 May 2019

Return to Mapping

Who is online

Users browsing this forum: No registered users and 1 guest