Random level generator

Discuss programming topics for any language, any source base. If it is programming related but doesn't fit in one of the below categories, it goes here.
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Random level generator

Post by JasonX »

I just finished a small random dungeon generator after reading some articles and getting inspired by bio-algorithms. I have my not-so-useful grid of . for clear areas and # for walls. I wanted to use that information to create brushes but have no idea where to start. I read the MAP format specification and created two little prefabs (clear area and wall) but i can't position the brush correctly in the world. Always getting messed up. I'm also not sure what's the best approach.

Does any of you guys have suggestions on how i should approach this? Thanks in advance! :lol:
andrewj
Posts: 133
Joined: Mon Aug 30, 2010 3:29 pm
Location: Australia

Re: Random level generator

Post by andrewj »

Prefabs seem like a complication, just write a solid brush for a solid spot and two brushes (floor and ceiling) for a clear spot.

The following code to write a cuboid brush into a file may be helpful:

Code: Select all

void T_WriteBrush(brush_c *B)
{
    fprintf(text_fp, "  {\n");

    int lx = VX(B->x);
    int ly = VY(B->y);
    int lz = B->low;

    int hx = lx + 64;
    int hy = ly + 64;
    int hz = B->high;

    // East
    fprintf(text_fp, "    ( %d %d %d ) ( %d %d %d ) ( %d %d %d ) %s 0 0 0 1 1\n",
            hx, ly, lz,  hx, ly, hz,  hx, hy, lz, B->tex_name);

    // South
    fprintf(text_fp, "    ( %d %d %d ) ( %d %d %d ) ( %d %d %d ) %s 0 0 0 1 1\n",
            lx, ly, lz,  lx, ly, hz,  hx, ly, lz, B->tex_name);

    // West
    fprintf(text_fp, "    ( %d %d %d ) ( %d %d %d ) ( %d %d %d ) %s 0 0 0 1 1\n",
            lx, hy, lz,  lx, hy, hz,  lx, ly, lz, B->tex_name);

    // North
    fprintf(text_fp, "    ( %d %d %d ) ( %d %d %d ) ( %d %d %d ) %s 0 0 0 1 1\n",
            hx, hy, lz,  hx, hy, hz,  lx, hy, lz, B->tex_name);

    // Top
    fprintf(text_fp, "    ( %d %d %d ) ( %d %d %d ) ( %d %d %d ) %s 0 0 0 1 1\n",
            lx, ly, hz,  lx, hy, hz,  hx, ly, hz, B->tex_name);

    // Bottom
    fprintf(text_fp, "    ( %d %d %d ) ( %d %d %d ) ( %d %d %d ) %s 0 0 0 1 1\n",
            lx, ly, lz,  hx, ly, lz,  lx, hy, lz, B->tex_name);

    fprintf(text_fp, "  }\n");
}
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Random level generator

Post by JasonX »

I see that, but how do i position this cuboids in the world? I'm iterating and printing my . and # sequentially, inside my grid. But brushes are different.
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Random level generator

Post by qbism »

Could you change or convert your output to a BMP image?
BMP2MAP http://user.txcyber.com/~si_slick/bmp2map/
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Random level generator

Post by JasonX »

I'm not really looking into getting a problem solved, but actually learning more about the MAP format and creating brushes based on my algorithm output. So, BMP2MAP isn't really useful. Thanks anyway! :D
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Random level generator

Post by qbism »

Ahh, the old-fashioned way.
andrewj
Posts: 133
Joined: Mon Aug 30, 2010 3:29 pm
Location: Australia

Re: Random level generator

Post by andrewj »

JasonX wrote:I see that, but how do i position this cuboids in the world?
In the code I posted, there are six coordinate variables:
lx : low x coordinate
ly : low y
lz : low z coordinate (bottom of cuboid)

hx : high x coordinate
hy : high y
hz : high z (top of cuboid)
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Random level generator

Post by JasonX »

I see, so i should increment each cuboid x/y position by it's size (64 units for example)?
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Random level generator

Post by frag.machine »

I am playing with the idea of random ambients, too, however I took the route of of BSP models:

Image
Image
Image
Image

I am trying to create an hybrid of Minecraft and Diablo dungeons. The idea is to have a single, persistent "world" map with a huge number of interconnected virtual environments. Something that will work in a similar way to TES:O or FO, only random.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: Random level generator

Post by ceriux »

that looks pretty awesome, do you think there will ever be anything playable?
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Random level generator

Post by JasonX »

It looks great, man. But what do you mean by route of BSP models? Randomly generating a path and positioning BSP models along this path accordingly in real time?
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Random level generator

Post by frag.machine »

JasonX wrote:It looks great, man. But what do you mean by route of BSP models? Randomly generating a path and positioning BSP models along this path accordingly in real time?
Yup. The mod has only one single map (world.bsp) formed by huge rooms. One have a sky (for outdoor sections), other is partially filed with water (the sewer screenshot), other have lava (for vulcanic caves) and so on. To compose the map itself, I cooked 256x256x512 .bsp "base blocks" (with baked lightmaps, so they look a bit better) and aligning them together in a random but coherent and functional way (at least most of the time, heh - there are bugs everywhere at this stage). The maps you see in the screenshot are hardcoded in the QuakeC (just for testing), but the idea is to have some kind of persistence layer so it can generate a huge random map, every time a new, uncharted section is visited, store it and create a big, persistent and totally random world that can be later revisited. The closer Quake will get of Minecraft, I supose. :D

@ceriux: well, it's not "playable" ATM. You can walk around in four different (and boring) ambients, grab some crates and treasure chests (no loot yet, just the messages), and punch a dummy entity into the cave test area :). I am trying to create a whole new mod almost from scratch, and it will take time.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Random level generator

Post by JasonX »

frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Random level generator

Post by frag.machine »

JasonX wrote:Similar to this maybe? http://forums.inside3d.com/viewtopic.php?t=1621
Yes, albeit a bit more simple in look (at least right now).
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Re: Random level generator

Post by qbism »

Arkage's cube mod "chasm" might be interesting
http://forums.inside3d.com/viewtopic.php?f=2&t=3069
Post Reply