Skip to content

Dungeon Generation

Carmina16 edited this page Mar 8, 2018 · 4 revisions

Named dungeon seed

Each main quest dungeon and 14 province dungeons in each province have their seed:

getLocSeed(province, dunId) <-
   X, Y <- getDungeonXY(province, dunId) # 16 last entries in CITYDATA.0x
   seed <- (Y << 16) + X + province
   return (~rol32(seed, 5)) & 0xFFFFFFFF

Main quest dungeons

Main quest dungeons have unique MIF files. Their names are generated as follows:

s <- String(seed)
mif <- s[:8] + ".MIF"

Other dungeons

SEED, W, H are the seed and width/height set for the particular dungeon. X coordinate increases to the left.

srand(SEED)
depth <- 1 + rnd() mod 2
if isArtifactDungeon() then depth <- 4

newSeed <- getRandomSeed()
transitions <- []
for i <- 0 to depth - 1
   do
      tY <- rnd() mod H
      tX <- rnd() mod W
      trBlock <- 10 * tY + tX
   while trBlock == transitions[-1] # the last element, need to handle the case of i==0
   transitions.append(trBlock)

for i <- 0 to depth - 1
   srand(newSeed + i)
   tileset <- rnd() mod 4
   dY <- 0
   for row <- 0 to H - 1
      dX <- 0
      for col <- 0 to W - 1
         block <- tileset * 8 + rnd() mod 8
         get a 'block' level from RANDOM1.MIF and paste in into level 'i' at dX, dY
         dX <- dX + 32
      dY <- dY + 32

draw a wall of 0x7800 blocks around each level
for each item in 'transitions', put up and down voxels in corresponding blocks

The local offset to possible up/down voxel position is (probably) 10, 10. The concrete voxel values should be taken from the INF file for RANDOM1.MIF.

Named dungeons

The 14 named dungeons in each province have the width of 2 blocks and height of 1.

Wilderness dungeons

Wilderness dungeons use the following seed and have the width and height of 2 blocks.

getWildernessSeed(cityId, wildBlockX, wildBlockY) <-
   gX, gY <- getGlobalXY(cityId)  # see 'Travel' article
   baseSeed <- ((gX << 16) + gY) * (cityId >> 5) # province
   return (baseSeed + ( ((wildBlockY << 6) + wildBlockX) & 0xFFFF) ) & 0xFFFFFFFF
Clone this wiki locally