P)rocedural generation of rooms

Hi! I'm new to Quest and trying to figure out how to procedurally generate a map.

I've found this link, which is very helpful: http://textadventures.co.uk/forum/quest/topic/3832/how-do-i-set-the-room-description#25752

It's for a 3D map, however. I've tried stripping out the z coordinates and changing the exit variables to only have 2 values (eg exit0-1 instead of exit0-10) but now the game is freezing on a blank page when I try to load it. I've narrowed down the problematic part of the code to be in the LayoutRooms function.

Here is my edited version - I'm probably missing something obvious when downgrading this to 2D. Any suggestions?

<function name="LayoutRooms">
          <![CDATA[
    // Create a list to hold the assigned room indices.
    assigned = NewList()
    // Layout the first room.
    room = game.rooms[0]
    currentroom = GetObject(room)
    currentroom.x = GetRandomInt(0, game.dimsx-1)
    currentroom.y = GetRandomInt(0, game.dimsy-1)
    // Mark this room's slot.
    list add (assigned, CoordsToIndex(currentroom.x, currentroom.y))
    // Layout the remaining rooms from here.
    for (i, 1, ListCount(game.rooms)-1) {
      room = game.rooms[i]
      newroom = GetObject(room)
      positioned = false
      while (not positioned) {
        // Select a random room to start from.
        room = game.rooms[GetRandomInt(0, i-1)]
        sourceroom = GetObject(room)
        // Select a random direction from this room.
        dirgood = false
        while (not dirgood) {
          dirx = GetRandomInt(-1, 1)
          diry = GetRandomInt(-1, 1)
          dirgood = dirx <> 0 or diry <> 0
        }
        //msg ("dir: " + dirx + ", " + diry)
        // See if we can position the room here.
        newroom.x = (sourceroom.x + dirx + game.dimsx) % game.dimsx
        newroom.y = (sourceroom.y + diry + game.dimsy) % game.dimsy
        index = CoordsToIndex(newroom.x, newroom.y)
        positioned = not index in assigned
      }
      // Remember this position is used.
      list add (assigned, index)
      // Create and assign the exits.
      exitname = "exit" + dirx + diry
      oppname = "exit" + -dirx + -diry
      msg("exitname = " + exitname + ", oppname = " + oppname)
      newexit = clone(GetObject(exitname))
      oppexit = clone(GetObject(oppname))
      newexit.parent = sourceroom
      newexit.to = newroom
      oppexit.parent = newroom
      oppexit.to = sourceroom
      //msg ("pos: " + newroom.x + ", " + newroom.y)
      currentroom = newroom
    }
  ]]></function>

Sorry for the typo in the post title. I'm trying to change it but getting an error "you can't post that here" so I'm guessing I'm hitting some sort of filter in the word "procedural"


Update: The final section is what's throwing up the issue.

Commenting out the line "list add (assigned, index)" will make the code almost work, but I'm ending up with multiple easts and wests.

You are in a room6.
You can go west or west.

> go west
Please choose which 'west' you mean:
1: west
2: west

So something wonky is happening when adding the value of the variable "index" to the list named "assigned", but that is needed to keep track of exits.


I'd like to know the answer too.


I see two possible issues. First, the function CoordsToIndex. I assume you've got it returning x + y*game.dimsx? That seems simple enough, so I doubt it's the problem.

Secondly, how large are you making the grid, and how many rooms are you putting into it? If there's a lot of rooms, it could take a long time to find empty spaces for them all by trial and error.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums