Outdoor generators: the cell grid, borders, placements and the act layouts
Purpose
Section titled “Purpose”A DrlgType 3 level is a grid of 8 × 8-tile cells. The outdoor generator of the level’s act fills four cell grids:
which cells are border, seam, road, waypoint or shrine cells, and which preset (LvlPrest Def, with its file index)
covers which cells. drlg/overview step 8 then turns every cell into an outdoor room or an embedded preset.
This spec covers everything OutdoorLevelBuild runs between allocating the grids and OutdoorRoomsCreate: the level
outline and its seams, the border pass, the placement primitives and the per-Def file rotation, the waypoint and
shrine marks, the border stamps (LvlSub tag_type 2), and the generator of each act. It also covers Act III’s jungle
layout, which runs at act creation on the act seed and gives Act III its level rectangles and links, and the fill of an
out room’s grids at its room prepare (§ M), where Act I’s roads become road tiles. Every draw is listed
with its seed, in order. The level seed is the one drlg/overview step 2 re-seeds; the act seed is that of
rng/seeds step 3. Primitives (Step, Range, RangeB) are those of rng. The act
link builder that places the other acts’ outdoor levels, and the warp points built from the rooms’ flags, are in
warps.md.
Entry points
Section titled “Entry points”| When | Function | Tag |
|---|---|---|
Outdoor level record created; no draw (in 2500 logged creations the level seed after the create dispatch is Init(base + id)) |
OutdoorLevelCreate |
[C] |
Outdoor level built, from LevelInit after the re-seed |
— | [C] |
| Act III created: the jungle layout and the Kurast stack on the act seed | ActLinkAct3 → JungleLayout |
[C] |
| Cells become rooms (boundary of this spec) | OutdoorRoomsCreate, drlg/overview step 8 |
[C] |
-
[I] The outdoor record
OutdoorLevelCreateallocates is 0x268 bytes; the size rests on the code read only. -
[C] The generator’s output is reproduced bit-exactly: 522 outdoor windows of 29 levels (2–7, 17, 41–46, 76–83, 104–106, 108, 110–112, 117), each in 4 to 11 map seeds and in normal, nightmare and hell, Acts I–IV in classic and expansion games. Every level-seed step inside the window (1443544), the final def grid, grid0 and cell grid, the seed after the window, the preset anchors with their file indices and the out rooms match, 0 mismatches.
-
[C] Level 39 (Moo Moo Farm) is reached and reproduced: the cow portal opened from the cube in a single-player Normal game on stock data (the transmute, its gates and its oracles: items/cube § L), and predicts its outdoor window (two windows, server and client) with 0 mismatches,
gen: 8778 checksover the session.
Inputs
Section titled “Inputs”Tables
Section titled “Tables”| Anchor | Used for |
|---|---|
Levels.txt:SizeX, Levels.txt:SizeY |
the level size the link builder starts from; level 76’s size for the three jungles, 79–83’s for the Kurast stack (§ J) |
Levels.txt:OffsetX, Levels.txt:OffsetY |
level 75’s position (Act III’s anchor, § J1); level 117’s position |
Levels.txt:Vis0, Levels.txt:Warp0 |
Vis0..7/Warp0..7: a slot with Vis ≠ 0 and Warp −1 is a walkable seam, an empty slot (Vis 0, Warp −1) none (§ C1); slot k gives the warp-slot flag 0x10 << k (§ E1) |
Levels.txt:LevelType |
the border style (§ E2) |
LvlPrest.txt:Files |
the operand of the file rotation (§ D2) |
LvlPrest.txt:SizeX, LvlPrest.txt:SizeY |
a preset’s footprint in cells, SizeX ÷ 8 × SizeY ÷ 8 (§ D1) |
LvlSub.txt:Type, LvlSub.txt:File |
the border-stamp records of a Type and their DS1 groups (§ G) |
LvlSub.txt:BordType, LvlSub.txt:GridSize |
how a border-stamp record stamps, and its cell scale (§ G) |
Which LvlPrest records each act places is surveyed in LvlPrest § Outdoor presets
and § Outdoor placement; the outdoor levels, their sizes and
the sizes the link picks overwrite are in Levels § Outdoor survey;
the border-stamp records are in LvlSub § Border stamps.
Runtime state
Section titled “Runtime state”| State | Type | Owner offset | Source |
|---|---|---|---|
level seed L.seed |
Seed |
level +0x1C4 |
re-seeded by LevelInit (drlg/overview step 2) |
| level id | u32 |
level +0x1D0 |
leveldefs |
level rectangle L.rect {x, y, w, h} (tiles) |
i32 |
level +0x1C |
warps.md § C; Act III from § J1 |
| file-rotation counters | list of {def, Files, c}, prepended |
level +0x1CC |
§ D2; emptied by LevelUnload before each build (drlg/overview step note 9) |
outdoor record O |
0x268 bytes | level +0x14 |
OutdoorLevelCreate |
outdoor flags O.flags |
u32 |
O+0x00 |
Act I: LinkOutdoorFlags at act creation (§ H); Act IV: g_LinkPickOutdoorFlag on level 104; Act I also sets 0x20, 0x40 itself |
| def grid, grid0, cell grid, grid3 | cw × ch u32 each |
O+0x04, O+0x18, O+0x2C, O+0x40 |
§ B |
cw, ch |
i32 |
O+0x5C, O+0x60 |
§ A |
| vertex ring | list of 0x14-byte vertices | O+0x64 |
§ C |
| Act I road lists | six vertex lists; endpoint arrays of 0x14-byte entries | O+0x68..+0x7C; O+0x80, +0xF8, +0x170, +0x1E8, count +0x260 |
§ H6 |
| level adjacency list | sorted nodes {nbr, side, isPreset, +0xC, &nbr.rect, next} |
O+0x264 |
LevelBorderAdj at act creation (§ C1) |
| act seed | Seed |
act +0x000 |
rng/seeds step 3 (Act III jungle layout, § J1) |
| Act III gate bit | u32 |
act +0x474 |
the Act III act-seed bit of rng/seeds step 3 (§ J5) |
jungle Def array, clearing count |
pointer; i32 |
level +0x1BC, +0x1B8 |
§ J1 (levels 76–78) |
| difficulty | u32 0..2 |
act +0x450 |
game; read only for Levels sizes |
- [C]
O.flagsbits0x4,0x8,0x10,0x80,0x100,0x200and0x400of the Act I levels are set at act creation byLinkOutdoorFlagsfrom table, matched against the sides the link builder chose; the act inputs of every logged window match the model. - [C] On Act IV, level 104’s flags carry from the Outer Steppes link pick.
Constants
Section titled “Constants”| Name | Value | Tag |
|---|---|---|
| occupied mask | 0x1B81 (cell bits 0, 7, 8, 9, 11, 12) |
[C] |
The generators read about thirty constant tables from Game.exe’s .data. They are code constants, not game data, and each is written out in full in the section that uses it. All of them are [C]: the reference model reads exactly these values from the exe and reproduces with them. Several are read through a displaced base, or overlap a neighbour; the section says which entries are read.
| Table | Shape | Section |
|---|---|---|
g_BorderDirIdx |
i32[3][3] |
§ E2a |
g_BorderDefs, g_BorderDefsA5 |
i32[13][4], i32[12][2] |
§ E2a |
g_BorderCornerIdx |
i32[9][9] |
§ E3 |
g_A2SeamPairDefs |
i32[5][2] |
§ E2a |
g_OutSideProbe |
i32[4][2] |
§ E1 |
g_OutShrineFlag |
i32[4] |
§ F2 |
g_OutNbrDx, g_OutNbrDy |
i8[8] each |
§ D6 |
g_LinkOutdoorFlags |
15 × i32[6] |
§ H0 |
g_A1RiverIdx |
i32[12][2] used |
§ H3 |
g_A1HubDx, g_A1HubDy |
i32[4] each |
§ H6c |
g_A1SearchDx, g_A1SearchDy, g_A1SearchTurns |
i8[4], i8[4], u8[4][4] |
§ H6d |
g_DirOctant |
i32[25][3], column 0 read |
§ H6d |
g_A1JitterDx, g_A1JitterDy |
i32[4] each |
§ H6e |
g_GridOps |
6 operations | § M1 |
g_RoadCodes |
u8[256] |
§ M2 |
g_A2CliffLayouts, g_A2KingTombCliff |
i32[8][5][4], i32[9][4] |
§ I3 |
g_JungleSideDefs, g_JungleClearingDefs |
i32[16][4], i32 by v >> 4 |
§ J2 |
g_JungleClearingOff, g_JungleClearingPerm |
i32[3], i32[6][3] |
§ J4 |
g_A4MesaBase, g_A4PitsBase |
i32[3] each |
§ K1 |
g_A4DiabloGrid |
i32[25] |
§ K2 |
g_A5RavineStep, g_A5CaveEntries, g_A5SubDefMap, g_A5PlaceTable |
i32[12][2], i32[3][5], i32[10][5], i32[15][7] |
§ L |
Algorithm
Section titled “Algorithm”Notation: L the level, O its outdoor record. A cell is (x, y), x the column (0 ..< cw), y the row
(0 ..< ch). cell(x, y), def(x, y) and grid0(x, y) are the three grids of § B. Step(s) advances seed s once and
returns its new low word (u32); a level draw is a Step of L.seed, an act draw a Step of the act seed.
Range(s, n) and RangeB(s, n) are the guarded range of rng: n < 1 gives 0 with no draw, otherwise
one Step, then the low word & (n − 1) for a power of two or unsigned mod n. With no seed named, the seed is
L.seed. ÷ is signed division truncating toward zero, % the signed C remainder. Place(x, y, def, file) is
OutPresetPlace with borderFlag 0 (§ D1); file = −1 means “from the rotation” (§ D2).
A. The window
Section titled “A. The window”A1. OutdoorLevelBuild(L): [C] O.+0x54 ← 0; O.+0x58 ← 0 cw: i32 ← L.w ÷ 8; ch: i32 ← L.h ÷ 8 def grid, grid0, cell grid, grid3 ← cw × ch u32, zeroed VertexRingBuild(L); OutVertsToCells(O.ring) ; § C, no draw ── window start: L.seed as LevelInit re-seeded it ── a: u32 ← (L.id = 134) ? 1 : DRLG_ActFromLevelId(L.id) ; 0-based act index OutdoorAct[a](L) ; § H (0) … § L (4) ── window end ── OutdoorRoomsCreate(L) ; drlg/overview step 8- [C] Nothing before the act switch draws: the seed entering the act generator is the re-seeded level seed, and the window’s level-seed steps are exactly the act generator’s.
- [C] The dispatch by level:
| Act index | Levels |
|---|---|
| 0 | 2–7, 17, 39 |
| 1 | 41–46, 134 |
| 2 | 76–83 |
| 3 | 104–106, 108 |
| 4 | 110–112, 117 |
(OutdoorLevelBuild; level 39; level 134 [I])
- [C] No generator branches on difficulty, expansion or player count: one model with no such input reproduces all three
difficulties and, on Acts I–IV, classic and expansion games. Act III’s jungle sizes come from
LevelsSizeX/Y[difficulty], which are equal in all three difficulties. - [C] The generators write the def grid, grid0 and the cell grid in place. No generator writes grid3;
OutdoorRoomsCreatepasses it on. UnderOutdoorLevelBuildevery+0x40operand is grid3’s allocation, a LvlPrestFilesread or C runtime code, andOutdoorRoomsCreatereads grid3 through the grid getter. - [C] The level size is the one the link builder wrote, which for four levels is not the
Levelssize: Blood Moor (2) is 56 × 96 or 96 × 56 (its link pick), and the Barricade-type levels 111, 112 and 117 are 64 × 160 or 160 × 64 (one act-seed-copy bit each), so 8 × 20 or 20 × 8 cells.
B. The cell grid and its bits
Section titled “B. The cell grid and its bits”| Grid | Content |
|---|---|
def grid O+0x04 |
the preset Def at its anchor cell (its top-left), 0 elsewhere |
grid0 O+0x18 |
the room flags of the cell: an out room’s +0x28, an embedded preset’s flags |
cell grid O+0x2C |
the bits below |
grid3 O+0x40 |
not written by the generators |
| Cell bit | Meaning | Set by | Read by |
|---|---|---|---|
0x1 |
border or seam cell | OutSeamMark, the border pass, OutPresetPlace with borderFlag for Def 4–15 and 364–375, the Act V ring |
OutCornerFlood, the occupied mask |
0x2 |
typed (cliff) seam or border | OutSeamMark, the border pass |
Act I river test |
0x80 |
road | Act I roads | PlaceNear, the occupied mask |
0x100 |
covered: no room | OutCellCover, OutCornerFlood |
OutdoorRoomsCreate, the occupied mask |
0x200 |
preset footprint | OutPresetPlace |
OutdoorRoomsCreate, the occupied mask |
0x400 |
seam opening | the border pass (act index 0, 3, 4), the Act V ring | OutCellNotOpening, Act V gates, OutWaypointPlace (level 3) |
0x800 |
waypoint | OutWaypointPlace |
the occupied mask |
0x1000 |
shrine | OutShrinesPlace |
the occupied mask |
0xF0000 |
preset file index (bits 16–19) | OutPresetPlace, the seam opening |
OutdoorRoomsCreate → the instance’s file index |
| grid0 bit | Meaning | Set by |
|---|---|---|
0x10 << k |
warp slot k: the cell borders the level named by Visk |
OutSeamMark (§ E1) |
0x1000 << r |
shrine record r of SubShrine |
OutShrinesPlace (§ F2) |
0x10000, 0x20000 |
waypoint record 0, 1 of SubWaypoint |
OutWaypointPlace (§ F1) |
- [C] The cell, def and grid0 bits above are what the generators leave: the three final grids match cell for cell in every window of the run (55676 cells per grid).
- [C] A placement fits only on cells with none of the occupied-mask bits (
0x1B81). - [C] Out-room flags.
OutRoomCreatesets an out room’s+0x28to its grid0 cell| 0x80000, and| 0x40000as well on the client copy. So the shrine, waypoint and warp-slot bits are room bits: the room prepare runs theSubShrineandSubWaypointpasses from them (room-tiles.md step 5), and the warp points of a level with out rooms follow from them. 6092 out-room flags were checked at the warp-point build (1000 with a shrine bit, 150 with a warp slot, 134 with a waypoint). - [C] No outdoor generator writes cell bits 20–25: the final cell grid of all 528 windows logged with it (30 levels,
56 204 cells) has them clear, while 5772 grid0 cells carry a warp-slot bit. The warp slot of an outdoor seam room is the
grid0 flag
0x10 << k; a warp inside an embedded preset comes from its DS1 cells.
C. The level outline
Section titled “C. The level outline”[C] The adjacency list (O+0x264) is built at act creation by LevelBorderAdj:
one node per Vis slot that names a level (Vis ≠ 0) and has no warp (Warp −1). The vertex ring is the level rectangle’s outline with an extra vertex
wherever a seam starts or ends.
C1. LevelBorderAdj(L) → per Vis slot k in 0 … 7 [C] with Vis[k] ≠ 0 and Warp[k] = −1: ; Vis tested first: an empty slot (Vis 0, Warp −1) makes no node n ← { nbr: level Vis[k], side: RectAdjDir(L.rect, nbr.rect) ; 0 W, 1 N, 2 E, 3 S isPreset: nbr's DrlgType = 2, +0xC: 0, rect: &nbr.rect } LevelAdjInsert(n, O.adj) ; C2's compare, with a quirk (step notes)C2. order (LevelAdjLess): side ascending; then W by y ascending, [C] N by x descending, E by y descending, S by x ascending ; a reimplementation keeps the list in this full order (step notes)
C3. VertexRingBuild(L): [C] r ← L.rect with w − 1, h − 1; each neighbour rect likewise ; inclusive while building, restored after ring: v0 (r.x, r.y + r.h) → v1 (r.x, r.y) → v2 (r.x + r.w, r.y) → v3 (r.x + r.w, r.y + r.h) → v0 ; W side going up, then N, E, S VertexRingSeams(ring, r, O.adj) ; C4 every vertex −= (L.x, L.y) ; level-relative tilesC4. VertexRingSeams, per node n in list order, q ← n.rect: [C] side 0: start v0, edge from v0.y (s) to v1.y (e), c ← −1, a ← q.y + q.h, b ← q.y side 1: start v1, edge from v1.x to v2.x, c ← +1, a ← q.x, b ← q.x + q.w side 2: start v2, edge from v2.y to v3.y, c ← +1, a ← q.y, b ← q.y + q.h side 3: start v3, edge from v3.x to v0.x, c ← −1, a ← q.x + q.w, b ← q.x p ← start if a·c ≤ s·c: if s·c > b·c: next node ; ends before the edge starts else: if a·c > e·c: next node; p ← insert a vertex after p at a VertexMarkSeam(p, n.isPreset) ; p.flags |= 1; if isPreset: p.flags |= 2 if b·c < e·c: insert a vertex after p at b ; the seam ends inside the edgeC5. OutVertsToCells(ring): every vertex ÷ 8 (signed); [C] a vertex equal to its successor is merged into it (flags or-ed) ; which of the two survives, and its type: Open questions (no stock case in Acts I, II, IV, V)-
C1. [C] An empty slot makes no node.
LevelBorderAdjskips a slot whoseVisis 0 (test eax, eax; je) before it testsWarp= −1. An empty slot (Vis0,Warp−1) is the stateLevelLinkSetlooks for when it adds a link, so a test ofWarpalone also matches every empty slot. The logs separate the two readings: the model with theVistest scores the run with 0 mismatches, and the same model without it makes 948 extra nodes and scores 22 600 mismatches of 513 215 checks. -
[C] A vertex’s flag bit 0 means the segment to the next vertex borders a walkable neighbour; bit 1 means that neighbour is a preset level (a town). The vertex
type(byte+8) is 0 from this builder; Act I’s cliff mark sets 1 (§ H1a). -
[C]
VertexMarkSeam(v, isPreset)(EAXthe vertex, one stack argument) is the only writer of these two bits here:v.flags |= 1, thenv.flags |= 2whenisPresetis non-zero; its caller isVertexRingSeams. -
[I] A vertex merge in
OutVertsToCellshappened in no logged window. It needs an adjacency overlap of exactly 8 tiles along an edge, or a level size or neighbour origin off the 8-tile grid. In Acts I, II, IV and V no layout the link builder can give meets that condition: enumerates each of the builder’s draws over the bits it is masked with, a superset of the layouts any map seed gives, and finds 0 such seams on the three difficulties (the smallest overlap is 24 tiles). The link model is confirmed by its run and the merge rule is a code reading, so this bound is a reading too. Act III is not covered: its jungle layout takes ranged draws and restarts, so levels 76–83 keep the sample of the offline scan (0 of 52 200 windows over every outdoor level of the five acts, map seeds 1–600, three difficulties), and whether stock data reaches the merge there is an open question. -
[C] C2 states the compare
LevelAdjLessand the order the ring reads:VertexRingSeams(C4) takes the nodes in list order and each acts on its own side’s edge, so only the order within a side reaches the ring, and every logged ring is reproduced. -
[I] How
LevelAdjInsertplaces a node. Into an empty list, the node becomes the list. Into a list of one node it compares the new node with the head: before the head whenLevelAdjLess(new, head), after it otherwise. Into a list of two or more nodes it does not compare with the head, so a node that sorts before the head is not put before it; a node that does not sort before the head goes where C2 puts it. Where a node that sorts before the head goes instead is not read yet (Open questions). -
[I] A reimplementation keeps the list in C2’s full order. Of the act link model’s 177 inserts, 19 go into a list of two or more nodes; in 5 the new node sorts before the head, and in all 5 the head is on another side, so the within-side order is the same either way; the same run with a full compare gives 0 mismatches. Example: a list holding nodes on sides 1 and 3 receives a side-2 node; it does not sort before the side-1 head, so it goes between the two, which is C2’s order.
D. Placement primitives
Section titled “D. Placement primitives”D1. OutPresetPlace(L, x, y, def, file, borderFlag): [C] w: i32 ← LvlPrest[def].SizeX ÷ 8; h: i32 ← LvlPrest[def].SizeY ÷ 8 if file = −1: file ← OutPresetFileRotate(L, def) ; D2, before any cell is written for yy in y ..< y + h: ; rows outer for xx in x ..< x + w: cell(xx, yy) ← (cell & ~0xF0000) | (file << 16) | 0x200 if borderFlag and (4 ≤ def ≤ 15 or 364 ≤ def ≤ 375): cell(xx, yy) |= 0x1 def(xx, yy) ← 0 def(x, y) ← def ; the anchor
D2. OutPresetFileRotate(L, def) → i32: [C] node ← the node of def in L[+0x1CC] if none: ; first use of def in this build files: i32 ← LvlPrest[def].Files node ← prepend { def, files, c: RangeB(L.seed, files) } ; level draw iff files ≥ 1 node.c ← (node.c + 1) % node.files ; signed; every use, the first included return node.c
D3. OutPresetFits(L, x, y, def, pad, sides) → bool: [C] footprint ← D1's w × h at (x, y) (def 0: 1 × 1), grown by pad on each side in sides (1 N, 2 E, 4 S, 8 W) true iff every footprint cell is inside the grid and (cell & 0x1B81) = 0
D4. Shuffle(N, W') → list: [C] list[i] ← (i % W', i ÷ W') for i in 0 ..< N repeat N times: a ← Range(L.seed, N); b ← Range(L.seed, N); swap list[a], list[b] ; 2N level draws
D5. PlaceRandom(L, def, file, pad, sides) → bool: [C] N: i32 ← (cw − 2)·(ch − 2); if N = 0: return false ; no draw list ← Shuffle(N, cw − 2) for (x, y) in list: if OutPresetFits(x + 1, y + 1, def, pad, sides): Place(x + 1, y + 1, def, file); return true return false ; silent unless the caller tests it
D6. PlaceNear(L, def, file) → bool: [C] N ← (cw − 2)·(ch − 2); if N = 0: return false list ← Shuffle(N, cw − 2) for (x, y) in list with cell(x + 1, y + 1) & 0x80: ; road cells for k in 0 ..< 8 (W, N, S, E, NW, SE, NE, SW): (px, py) ← (x + 1 + g_OutNbrDx[k], y + 1 + g_OutNbrDy[k]) ; i8, sign-extended ; g_OutNbrDx = −1, 0, 0, +1, −1, +1, +1, −1; g_OutNbrDy = 0, −1, +1, 0, −1, +1, −1, +1 if OutPresetFits(px, py, def, 0, 0xF): Place(px, py, def, file); return true return PlaceRandom(L, def, file, 0, 0xF) ; a second shuffle
D7. PlaceFar(L, rect, def, file, pad, sides) → bool: [C] ox ← Range(L.seed, cw − 2); oy ← Range(L.seed, ch − 2) ; 2 level draws best ← none for r in 0 ... ch − 2: y ← (r + oy) % (ch − 2) + 1 ; inclusive bounds for c in 0 ... cw − 2: x ← (c + ox) % (cw − 2) + 1 if OutPresetFits(x, y, def, pad, sides): a ← |8x + L.x + 4 − (rect.x + rect.w ÷ 2)|; b ← |8y + L.y + 4 − (rect.y + rect.h ÷ 2)| d ← (a > b ? b + 2a : a + 2b) ÷ 2 if d > best.d: best ← (x, y, d) ; the first strict maximum if best: Place(best.x, best.y, def, file); return true return false
D8. OutCellClear(x, y): def(x, y) ← 0; cell(x, y) ← 0. [C] OutCellCover(x, y): def(x, y) ← 0; cell(x, y) ← 0x100. OutCellNotOpening(x, y): (cell & 0x400) = 0. OutCellFree(x, y): (cell & 0x1B81) = 0.- [C] The neighbour offsets of D6 are the two
i8[8]tablesg_OutNbrDxandg_OutNbrDy, in the order W, N, S, E, NW, SE, NE, SW (values in D6). - [C] D2 is the commonest level-seed draw of the window. The first use of a
DefdrawsRangeB(Files)even whenFilesis 1, and the index used is one past the drawn value:(RangeB + 1) % Files. EveryDefrotates; there is noDef-range test. - [I] A
DefwithFiles0 placed withfile = −1would divide by zero in D2. - [C]
PlaceRandomdraws its2Neven when nothing fits; then one rotation draw when a placedDefwithfile = −1is new to the build. - [I]
PlaceFar’s inclusive bounds visit rowoyand columnoxtwice. The second visit can never change the result, ties included, because the best cell is replaced only on a strictly greater distance; a reimplementation may use exclusive bounds.
E. Seams and the border pass
Section titled “E. Seams and the border pass”E1. OutSeamMark(L): for each ring vertex v with v.flags & 1: [C] f: u32 ← SeamWarpFlag(L, v) grid0 |= f on every cell of the segment v … v.next (end included) cell |= (v.type ≠ 0 ? 3 : 1) on the same cells SeamWarpFlag(L, v) → u32: [C] (x, y) ← v's cell side: i32 ← x = 0 ? (y = 0 ? 1 : 0) : y = 0 ? 1 + (x = cw − 1) : x = cw − 1 ? 2 + (y = ch − 1) : y = ch − 1 ? 3 : none → return 0 (dx, dy) ← g_OutSideProbe[side] ; W (−4, +4), N (+4, −4), E (+12, +4), S (+4, +12) probe ← (8x + L.x + dx, 8y + L.y + dy) ; level tiles, 4 tiles outside the vertex cell n ← the adjacency node of that side whose rect contains probe; none → return 0 return 0x10 << (the first k with Vis[k] = n.nbr.id) ; a node with +0xC ≠ 0 gives 0-
[C]
g_OutSideProbeisi32[4][2]{dx, dy}by side 0 W, 1 N, 2 E, 3 S, with the values in E1. A corner vertex takes the side of the segment that leaves it in ring order: by the rule in E1, (0, 0) is N, (cw − 1, 0) E, (cw − 1, ch − 1) S and (0, ch − 1) W. -
[I] Adjacency node
+0xCis written once, to 0, byLevelAdjAdd; neither the insert nor any reader of the list writes it. SoSeamWarpFlag’s+0xCtest always passes, and E1’s “a node with+0xC≠ 0 gives 0” has no case.
E2. OutBorderBuild(L): [C] act ← DRLG_ActFromLevelId(L.id) style(t) ← LevelType 2: (t ≠ 0 ? 0 : 1); 16: 2; 27: 3; 31: 4 + (L.id = 117); else −1 for v in the ring from its head (v0), each vertex once; n ← v.next: d ← sign(n − v) per axis; cv: u32 ← (v.type ≠ 0) ? 3 : 1; e ← BorderEdgeDef(d, style(v.type)) ; E2a if not (v.flags & 2): ; not a town seam for each cell c from v + d to n inclusive: Place(c, e, −1); cell(c) |= cv if (v.flags & 1) and not (v.flags & 2): ; seam with an outdoor level m ← min(v, n) + (len · |d|) ÷ 2 ; the segment's mid cell act 0 or 4: cell(m) ← (cell(m) & ~0xF0000) | (L.id = 17 ? 0x40400 : 0x30400) act 3: cell(m) ← (cell(m) & ~0xF0000) | 0x30400 act 1: k ← dx + 2·dy + 2; Place(m, g_A2SeamPairDefs[k][0], −1); Place(m + |d|, g_A2SeamPairDefs[k][1], −1) act 2: nothing t ← v.type or n.type; if t ≠ 0: cv |= 2 c ← BorderCornerDef(in code of v → n, out code of n → n.next, style(t)) ; E3 if c = 0: nothing ; no piece, no cell bit else: if c = 19: c ← (v.type = 1) ? (n.type = 1 ? 19 : 20) : 21 Place(n, c, −1); cell(n) |= cv OutCornerFlood(L) ; E4- [C] The border pass’s only level-seed draws are D2’s first uses: one
RangeB(Files)per distinct borderDef, in first-use order along the ring from v0 (the bottom-left corner, going up the W side). Its callers are Act I, Act II and Act IV except level 108; Act V lays its own ring (§ L2), and Act III none. - [C] The seam opening is a direct cell write after the piece is placed: index 3 (the
…ofiles ofWild Border 1–4andMesa Border 1–4), or 4 on level 17 (Bord1oe), and bit0x400. It overrides the index the rotation gave that cell, but the rotation draw was made. - [C] A corner piece replaces the edge piece placed at
n; both uses count in the rotation. - [C] The corner exceptions. A
BorderCornerDefresult of 0 places nothing and sets no cell bit. A result of 19 (the cliff style’s row 6) becomes 19 whenv.typeandn.typeare both 1, 20 whenv.typeis 1 andn.typeis not, and 21 whenv.typeis 0 (the cliff style then came fromn.type). The corner is placed atnwith file −1.
E2a. Edge pieces and the style tables
Section titled “E2a. Edge pieces and the style tables”BorderEdgeDef(dx, dy, style) → i32: [C] di: i32 ← g_BorderDirIdx[dx + 3·dy] ; centre-based: dx, dy ∈ −1..1 return style ≥ 4 ? g_BorderDefsA5[2·di + style − 4] ; row 1 + di of the table below : g_BorderDefs[4·(di + 1) + style]-
[C]
g_BorderDirIdx(i32[3][3], centre) maps a ring segment’s unit step to its direction indexdi:(−1, 0)(moving W, the S side) → 0;(0, −1)(moving N, the W side) → 1;(+1, 0)(moving E, the N side) → 2;(0, +1)(moving S, the E side) → 3. The other five entries are −1 and are never read: ring segments are axis-aligned and non-empty. -
[C] The style table.
g_BorderDefs(i32[13][4], styles 0–3) andg_BorderDefsA5(i32[12][2], styles 4–5) read as one table of rows 1–12. Row 0 ofg_BorderDefs(0x2000, 0x4000, 0x8000, 0) is the tail ofg_OutShrineFlagand is never read as aDef; row r ofg_BorderDefsA5is row r + 1 below. The edge piece of directiondiis row1 + di; the corner piece of corner indexk(E3) is rowk.Row style 0 cliff 1 wild 2 desert 3 mesa 4 Barricade 5 Barricade snow 1 (edge, moving W) 0 4 364 799 881 957 2 (edge, moving N) 16 5 365 800 882 958 3 (edge, moving E) 17 6 366 801 883 959 4 (edge, moving S) 0 7 367 802 884 960 5 18 8 368 803 885 961 6 19 9 369 804 886 962 7 22 10 370 805 887 963 8 0 11 371 806 888 964 9 0 12 372 807 889 965 10 23 13 373 808 890 966 11 0 14 374 809 891 967 12 0 15 375 810 892 968 -
[C] The Act II seam pairs,
g_A2SeamPairDefs(i32[5][2], byk = dx + 2·dy + 2of the seam segment’s unit step): k 0 (moving N, the W side)373, 372; k 1 (moving W, the S side)372, 375; k 20, 0(never read); k 3 (moving E, the N side)373, 374; k 4 (moving S, the E side)374, 375. The first goes at the mid cellm, the second atm + (|dx|, |dy|), both with file −1.
E3. BorderCornerDef(inCode, outCode, style) → i32: [C] code(seg from vertex p, unit step (dx, dy)): ; the caller passes (a, b), the callee adds ±2 (a, b) ← (p.flags & 2) ? (dx, dy) : (2dx, 2dy) ; OutBorderBuild; Act V always doubles (§ L2) return e(a) + b, e(z) = z < 0 ? z − 2 : z > 0 ? z + 2 : 0 ; plain: W −4, E +4, N −2, S +2 ; from a preset-seam vertex: W −3, E +3, N −1, S +1 inCode ← code(v → n); outCode ← code(n → n.next) k: i32 ← g_BorderCornerIdx[inCode + 9·outCode] ; centre; both codes −4..4 if k = −1: return 0 return style ≥ 4 ? g_BorderDefsA5[2k + style − 6] : g_BorderDefs[4k + style] ; row k of E2a's table-
[C]
g_BorderCornerIdx(i32[9][9], read asg_BorderCornerIdx[in + 9·out], 4 bytes an entry). Rows are the out code, columns the in code;·is −1 (no corner piece).out \ in −4 −3 −2 −1 0 +1 +2 +3 +4 −4 1 9 9 · · 1 8 · · −3 12 · · · · 12 4 · · −2 5 2 2 10 · · · · 10 −1 1 9 9 · · · · · · 0 · · · · · · · · · +1 · · · · · · 11 11 3 +2 12 · · · · 12 4 4 7 +3 · · 2 10 · · · · 10 +4 · · 6 3 · · 11 11 3 The four corners of a plain rectangle: SW (in W −4, out N −2) → row 5, NW (in N −2, out E +4) → row 6, NE (in E +4, out S +2) → row 7, SE (in S +2, out W −4) → row 8. A vertex inserted mid-edge by a seam keeps the direction (in N, out N → row 2: the edge piece again). Rows 9–12 and the ±3/±1 codes serve the seam ends next to a preset (town) neighbour.
E4. OutCornerFlood(L): [C] for (xFar, yFar, dx, dy) in ((0, 0, +1, +1), (1, 0, −1, +1), (0, 1, +1, −1), (1, 1, −1, −1)): ; NW, NE, SW, SE x0: i32 ← xFar ? cw − 1 : 0; y: i32 ← yFar ? ch − 1 : 0 while (cell(x0, y) & 1) = 0: ; rows, from the corner inward x: i32 ← x0 while (cell(x, y) & 1) = 0: cell(x, y) |= 0x100; x ← x + dx y ← y + dy- [C] E4 has no bounds test: each pass stops on a bit-0 cell, which the ring guarantees.
F. Waypoint and shrines
Section titled “F. Waypoint and shrines”F1. OutWaypointPlace(L): [C] if L.id = 3: ; Cold Plains, no draw f ← 0x10 << (the first k with Vis[k] = 2) ; the Blood Moor seam first (x, y), rows outer, with (grid0 & f) and (cell & 0x400): clamp (x, y) into 1 … cw − 2 × 1 … ch − 2 grid0 |= 0x20000; cell |= 0x800; return ; waypoint record 1 ; no such cell: on to the shuffle below (read from the code, step note F1) N ← (cw − 2)·(ch − 2); if N = 0: return list ← Shuffle(N, cw − 2) ; 2N level draws first (x, y) in list with OutCellFree(x + 1, y + 1): grid0 |= 0x10000; cell |= 0x800 ; waypoint record 0F2. OutShrinesPlace(L, count = 5): [C] r: u32 ← Step(L.seed) & 3 ; always, before the shuffle N ← (cw − 2)·(ch − 2); if N = 0: return list ← Shuffle(N, cw − 2) ; 2N level draws for (x, y) in list while count > 0, with OutCellFree(x + 1, y + 1): grid0 |= g_OutShrineFlag[r]; cell |= 0x1000; r ← (r + 1) & 3; count ← count − 1 ; g_OutShrineFlag = 0x1000, 0x2000, 0x4000, 0x8000-
[C] Neither pass places a preset. They mark cells, and the out room made there runs the
SubWaypointorSubShrineLvlSubpass with the marked record (room-tiles.md step 5). Every call site passescount5. -
[C]
g_OutShrineFlag(i32[4]) holds the grid0 bit of shrine record r:0x1000 << r. -
[I] A waypoint pass that finds no free cell happened in no logged window, and in none of the 52 200 windows of the offline scan; whether stock data can reach it is an open question.
-
[C] Frigid Highlands (111) gets its waypoint from no outdoor pass: the
To Siegepreset (Def880) holds a waypoint unit, and the DS1 scan sets0x30000on its room.
G. Border stamps
Section titled “G. Border stamps”[C] The five LvlSub records with BordType ≠ −1 (Type 0 Border - Cliffs, 1 - Middle, 2 - Corner, 3 - Border, 12
Barricade) are not rolled per room. The outdoor generators apply every record of a Type to the cell grid on the level
seed. A record’s DS1 holds groups; a group is a rewrite rule whose variant 0 is the pattern to match and whose
variant v + 1 is the replacement.
G1. OutBorderSubApply(L, Type, baseDef): [C] context: baseDef, wildcard −1, Type, the tests OutCellNotOpening and OutPresetFits, and the writers OutCellClear, OutCellCover, OutPresetPlace for rec ← LVLSUB_GetRecordByType(Type) while rec.Type = Type, rec ← rec + 1: LvlSubLoadDs1(rec); BorderSubRecord(rec) ; G2G2. BorderSubRecord(rec): [C] groups ← the DS1's group count; if groups = 0: return if wildcard = −1: wildcard ← 62 s ← (rec.BordType = 0) ? RangeB(L.seed, groups) : 0 ; level draw iff BordType 0 for i in 0 ..< groups: ok ← BorderSubGroup(rec, G[(s + i) % groups]) ; G3 if ok and rec.BordType = 0: returnG3. BorderSubGroup(rec, g) → bool: [C] GS ← rec.GridSize; off ← (Type = 1 and (O.flags & 0xC)) ? −1 : 1 nx ← cw − g.w·GS + off; ny ← ch − g.h·GS + 1; N ← nx·ny; if N = 0: return false skip22 ← Type = 1 and 2 ≤ L.id ≤ 7 and nx < 6 and ny < 6 list ← Shuffle(N, nx) ; 2N level draws for (px, py) in list: if skip22 and (px, py) = (2, 2): continue if BorderSubFits(px, py, g, rec): ; G4 v ← Range(L.seed, g.variants) ; level draw BorderSubStamp(px, py, g, rec, variant v + 1) ; G4 if rec.BordType ≤ 1: return true ; BordType 2: keep stamping return false-
G4. [C] Match and stamp. Positions snap down to multiples of
GS, and group cell(gx, gy)covers outdoor cell(px + GS·gx, py + GS·gy). The match reads variant 0: a wall cell with bit 0 names the border piecebaseDef + ((W >> 8) & 0xFF) − 1(63 means any), which must be the cell’sDefand must not be a seam opening; a floor cell withF & 2must be free. The stamp writes variantv + 1: wall pieces are placed with file 0 andborderFlag1 (no rotation draw), floor cells withF & 2are cleared to open cells (OutCellClear), and the others are covered (OutCellCover). -
G4. [C] Where a variant is. The variants of a group sit side by side in the DS1 at a stride of
g.w + 1cells: variant 0 is the group’s own rectangle and variantv + 1starts(g.w + 1)·(v + 1)cells to its right (the source column G3 handsBorderSubStamp). -
G4. [I] “63 means any” and G2’s
wildcard ← 62are one rule. Sub-index 63 givesbaseDef + 63 − 1 = baseDef + 62, that isbaseDef + wildcard, the value the context’s wildcard (G2) names; such a cell matches anyDef. A reimplementation tests the computed piece againstbaseDef + 62, or the sub-index against 63, not against a bare 62. -
G4. Four points of the match and the stamp are not read yet and are listed under Open questions: the DS1 layer read, a sub-index-63 cell in a replacement variant, which cells “the others” are, and
N < 0in G3. -
[C]
BordType: 0 = oneRangeB(groups)picks the start group, and the record stops after its first stamp; 1 = every group is tried and stamped at most once; 2 = every group is stamped at every matching position. Stock:Border - Cliffs1,- Middle0,- Corner1,- Border2,Barricade2.GridSize: 1, and 2 forBarricade. -
[C] No mask and no
Prob,Trials,MaxorDt1Maskis read for these records. The call sites, in order: Act I levels 2–7Type0, then 1 and 2, then 3 (base 4, § H1); Act IIType2, 1, 3 (base 364); Act IV 104–106Type1, 2, 3 (base 799); Act VType12 with its own context (§ L5); level 39Type0–3 (base 4). (OutdoorAct1,OutA2BorderSubs,OutdoorAct4,BarricadeLvlSub; level 39)
H. Act I
Section titled “H. Act I”Levels 2–7 (the wilderness), 17 (Burial Grounds, Levels “Graveyard”) and 39 (Moo Moo Farm, reproduced: see Entry points).
H0. [C] The Act I outdoor flags (LinkOutdoorFlags, at act creation, no draw). For each Act I link entry i whose
level L has DrlgType 3, every row of g_LinkOutdoorFlags (15 rows of i32[6] {level, not1, not2, dirI, dirNext, flag}) with (level = L.id or level = 0) and L.id ≠ not1 and L.id ≠ not2 and B.dir[i] = dirI and
B.dir[i + 1] = dirNext ORs flag into O.flags; B.dir are the sides the link builder chose. The O.flags of every logged window match.
| Rows | level |
not1, not2 |
(dirI, dirNext) → flag |
|---|---|---|---|
| 0–1 | 0 (any) | 2, 3 | (1, 0), (2, 3) → 0x4 |
| 2–3 | 0 (any) | 3, 17 | (2, 1), (3, 0) → 0x8 |
| 4–5 | 0 (any) | 3, 17 | (1, 1), (3, 3) → 0x10 |
| 6–9 | 2 | 0, 0 | (0, 0), (2, 2), (3, 0), (3, 2) → 0x8 |
| 10–11 | 2 | 0, 0 | (0, 1), (1, 1) → 0x400 |
| 12 | 2 | 0, 0 | (2, 1) → 0x200 |
| 13 | 2 | 0, 0 | (2, 2) → 0x80 |
| 14 | 2 | 0, 0 | (3, 2) → 0x100 |
[C] Rows 6–14 store 0 in both not1 and not2: L is an Act I level of DrlgType 3, never level 0 (Null), so they exclude nothing, and each of these rows applies to level 2 whenever its two sides match (for level 2 with B.dir[i] = 0 and B.dir[i + 1] = 0, row 6 ORs 0x8). § 16.3 prints these cells as ”—”; the values are the table’s as the reference model reads it, the read every § 16 table rests on.
The last row’s flag (256) is also entry 0 of g_JungleClearingDefs (§ J2), where it is never read.
H1. OutdoorAct1(L): [C] if L.id ∉ {2, 3, 17}: A1CliffMark(L) ; H1a; no draw OutSeamMark(L); OutBorderBuild(L) ; § E if 2 ≤ L.id ≤ 7: OutBorderSubApply(L, 0, 4); A1RiverEastAndCave(L) ; § G, H2 OutBorderSubApply(L, 1, 4); OutBorderSubApply(L, 2, 4); A1RiverMidTransCave(L) ; H4 OutBorderSubApply(L, 3, 4); A1Paths(L) ; H6 if L.id = 39: OutBorderSubApply(L, 0, 4) … OutBorderSubApply(L, 3, 4) ; [C] if 3 ≤ L.id ≤ 6: OutWaypointPlace(L) ; § F1 if 2 ≤ L.id ≤ 7: OutShrinesPlace(L, 5) ; § F2 A1Areas(L) ; H7H1a. A1CliffMark(L): [C] ; the vertex ring of § C (head O.ring = v0); seam(v) ⇔ (v.flags & 1) ≠ 0, the segment v → v.next ; up = y decreasing, down = y increasing; every compare signed i32 head ← O.ring; prev ← the vertex whose next is head; v ← head; done ← false loop: n0 ← v.next start ← not seam(prev) and not seam(v) and ((prev.y > v.y and v.x < n0.x) ; A: came in going up, goes out right or (prev.x > v.x and v.y > n0.y)) ; B: came in going left, goes out up w ← v if start: last ← none loop: if w = head: done ← true ; set before the exit tests n ← w.next if n.y > w.y or n.x < w.x or seam(w) or seam(n): leave ; a down or left segment, or a seam at either end nn ← n.next if not seam(n) and ((w.x < n.x and n.y < nn.y) ; n turns right-then-down or (n.y < w.y and n.x < nn.x)): ; n turns up-then-right last ← w w ← n if w = v: leave ; back at the run's start if last ≠ none: for q from v along next up to last, last included: q.type ← 1 O.flags |= 0x20 v ← w.next ; the vertex where the run stopped is not tested if done: return prev ← w if v = head: return- H1a. [I] Exits no logged walk takes. No run stopped on a left-going segment or back at its own start, and the
seam(w)test cannot fire (wisv, excluded by the start test, or the previousn, which passed theseam(n)test). On § C’s ring (W side up, N side right, E side down, S side left, seam vertices only on the sides) the only starts arev0(B) andv1(A), and a run meets the E side’s down segment before any left-going one, so those exits need a ring this builder does not make.
H2. A1RiverEastAndCave(L): [C] if (O.flags & 0xC) and A1RiverColumnClear(cw − 2): A1RiverPlace(cw − 2) ; H3 if (O.flags & 0x20) and not (O.flags & 0x40): ; a cave in a cliff piece r ← Step(L.seed) ; level draw scan rows outer if (r & 1) = 0, else columns outer (the bounds cw and ch swapped) first cell with def 16 → Place(25 Cave Left, −1); with def 17 → Place(24 Cave Right, −1) O.flags |= 0x40; none found → fatal error if (O.flags & 0x1C) and not (O.flags & 0x40): ; a corner cave r ← Step(L.seed) & 3 ; level draw x ← (r & 1) ? 3 : cw − ((O.flags & 0x10) ? 4 : 5); y ← (r >> 1) ? 3 : ch − 4 Place(x, y, 51 + (L.id = 2), −1); O.flags |= 0x40 ; no fit test; 52 is the Den of Evil entranceH3. A1RiverPlace(L, x): [C] for y in 0 ..< ch: for (col, def) in ((x, 26 River Upper), (x + 1, 27 River Lower)): p ← def(col, y); c ← cell(col, y) idx ← p = 0 ? (c & 0x100 ? 0 : 3) : (p = 7 and (c & 0xF0000) = 0x30000) ? 3 : g_A1RiverIdx[p][def − 26] Place(col, y, def, idx) ; replaces the border piece; explicit index, no draw if O.flags & 0x14: A1BridgePlace(L, x) A1RiverColumnClear(x): no cliff bit (bit 1) in columns x and x + 1. A1BridgePlace(L, x): [C] s ← Range(L.seed, ch − 2) ; level draw first y = (k + s) % (ch − 2) + 1 (k = 0, 1, …) with free cells beside it and index 3 in both river cells: ; "beside": Open questions Place(x, y, 28, 1); Place(x + 1, y, 28, 2 + ((O.flags & 4) ≠ 0))H4. A1RiverMidTransCave(L): [C] if (O.flags & 0x10) and A1RiverColumnClear(cw ÷ 2 − 1): A1RiverPlace(cw ÷ 2 − 1) town transitions (explicit indices, no draw): 0x80: Place(0, 0, 3, 1); 0x100: Place(cw − 7, 0, 3, 2); 0x200: Place(0, 1, 2, 1); 0x400: Place(0, ch − 6, 2, 1) if not (O.flags & 0x40): L.id = 2: ok ← PlaceFar(L, rect of level 1, 52 DOE Entrance, −1, pad 1, sides 0xF) ; 2 draws + rotation else: ok ← PlaceRandom(L, 51 Cave Entrance, −1, pad 1, sides 0xF) ; 2N draws + rotation not ok → fatal error; O.flags |= 0x40-
[C] The river index table
g_A1RiverIdxis read asg_A1RiverIdx[p][0]for the 26 piece andg_A1RiverIdx[p][1]for the 27 piece (8 bytes a row),pthe borderDefin the cell. Only rowsp4–15 are read (i32[12][2]): rows 0–3 would overlap the King Tomb table, butp= 0 takes the covered rule and no river column holdsDef1–3. Forp= 7 at the seam opening (file bits0x30000) both pieces take 3.border Defp4 5 6 7 8 9 10 11 12 13 14 15 26 River Upper 2 0 1 3 0 0 1 2 2 1 3 3 27 River Lower 2 3 1 0 2 1 0 0 3 3 1 2 -
[I] A
Defabove 15 in a river column would read past the table into the road-code bytes;A1RiverColumnClearkeeps the cliff pieces out, and no logged window had one. -
[C]
O.flagsselects the river columns (0xCeast,0x10middle), the bridge (0x14), the corner cave and level 2’s town transitions. -
[C]
BridgeFindon the non-square Blood Moor: every Blood Moor is 12×7 or 7×12 cells, and the ones with flag0x10are 12×7, so the row boundcw − 1= 11 runs past the 7 rows and the bridge (Def28, file 1) always stands in a row the loop reaches first. Map seed 45 (two windows) matched the bridge hub and every road draw; the offline scan set flag0x10in 564 of 1 800 Blood Moor windows, all 12×7. -
[C] The cliff-cave scan with columns outer (
r & 1= 1) matched in 6 windows on square 10×10 levels, and the rows-outer scan in 2. -
[I] The swapped bounds of that scan would differ from the plain scan only on a non-square level, and that half has no stock case. Of levels 2–7 only the Blood Moor is non-square in cells, and its flag
0x20(a cliff run) stays clear.OutdoorAct1skipsA1CliffMarkfor levels 2, 3 and 17; its OR is the only bare-register OR of0x20into a dword, andLinkOutdoorFlagsORs other values. Between that skip and the test nothing writesO+0x00: the callee closure ofOutSeamMark,OutBorderBuild,OutBorderSubApplyandA1RiverEastAndCave(46 functions, the indirect calls resolved by hand) writes only the level seed and rotation list, stack slots, the BorderSub context, the LvlSub record’s grid view, allocations and grid cells. Only an out-of-range grid index landing onOcould reach it, and nothing on the path computes one. The scan agrees:0x20clear in all 1 800 Blood Moor windows.
H6. Roads
Section titled “H6. Roads”H6. A1Paths(L): [C] n: i32 ← A1PathEndpoints(L) ; H6a, no draw: A[], Bp[] A1PathHub(L, n) ; H6c, no draw: D[], C[] for i in 0 ..< n: path ← A1PathSearch(cell(Bp[i]), cell(C[i])) ; H6d, no draw if found: cell |= 0x80 on every cell of the path inside the grid ; GridPointsOr A1PathJitter(L, i, path) ; H6e: 1 + 2·(cells − 2) level draws ; not found: no jitter call, so no draw for this road (step note) cell(p) = ((p.x − L.x) ÷ 8, (p.y − L.y) ÷ 8) ; tile point → cellPoints {x, y, dir} are in map tiles, the frame of L.rect. The endpoint arrays are 0x14-byte entries (x, y, dir a
u8 at +8): A at O+0x80 (raw), Bp at O+0xF8 (snapped), C at O+0x170 (the snapped hub), D at O+0x1E8
(the raw hub), and the count at O+0x260. [C]
H6a. A1PathEndpoints(L) → i32: [C] n: i32 ← 0 for node in O.adj (list order, § C2): r ← node.nbr.rect if node.nbr.id = 1: ; Rogue Encampment A[n] ← by node.side: 0 (r.x + 59, r.y + 19); 1 (r.x + 29, r.y + 35); 2 (r.x + 4, r.y + 22); 3 (r.x + 29, r.y + 3) A[n].dir ← node.side; n ← n + 1 else if node.nbr.id = 26: ; Monastery Gate A[n] ← (r.x + 27, r.y + 13), dir 1; n ← n + 1 for x in 0 ..< cw: for y in 0 ..< ch: ; columns outer d: i32 ← def(x, y); f: u32 ← (cell(x, y) >> 16) & 0xF; dir: i32 ← 4 if d = 4 and f = 3: dir ← 3 ; the seam openings elif d = 5 and f = 3: dir ← 0 elif d = 6 and f = 3: dir ← 1 elif d = 7 and f = 3: dir ← 2 elif d = 24: dir ← 1 ; Cave Right elif d = 25: dir ← 0 ; Cave Left elif d = 28 and f = 1 and x = cw − 2: dir ← 2 ; the east river's bridge elif d = 51 or d = 52: dir ← (f ≠ 0) ? 1 : 0 ; the caves if dir ≠ 4: A[n] ← (L.x + 3 + 8x, L.y + 3 + 8y, dir); n ← n + 1 for i in 0 ..< n: Bp[i] ← Snap(L, A[i]) return n
H6b. Snap(L, p) → point: [C] rx: i32 ← p.x − L.x; ry: i32 ← p.y − L.y dir 0: rx ← (rx ÷ 8)·8 + 11; dir 1: ry ← (ry ÷ 8)·8 + 11 dir 2: rx ← (rx ÷ 8)·8 − 5; dir 3: ry ← (ry ÷ 8)·8 − 5; dir 4: unchanged return (rx + L.x, ry + L.y, p.dir)- [C] The endpoint arrays have no bound check: six entries fit before
O+0xF8.
H6c. A1PathHub(L, n): [C] (bx, by): i32 ← (−1, −1) if O.flags & 0x10: ; the middle river (bx, by) ← A1BridgeFind(cw ÷ 2 − 1): the column and the first y in 1 … cw − 2 (sic: the bound is cw) with def = 28 and file index 1; (−1, −1) when none if bx ≠ −1: X: i32 ← L.x + 3 + 8·bx; Y: i32 ← L.y + 3 + 8·by for i in 0 ..< n: D[i] ← (A[i].x > X) ? (X + 8, Y, dir 0) : (X, Y, dir 2) else if n > 0: if n = 1: (cx, cy) ← (cw ÷ 2, ch ÷ 2) else: cx: i32 ← Σi (A[i].x − L.x) ÷ (8n); cy: i32 ← Σi (A[i].y − L.y) ÷ (8n) ; i32 sums, one division for r in 0 ..< 8: for j in 0 ..< 4: ; r outer; j: W, S, N, E (hx, hy) ← (cx + g_A1HubDx[j]·r, cy + g_A1HubDy[j]·r) if 0 ≤ hx < cw and 0 ≤ hy < ch and OutCellFree(hx, hy): leave both loops ; none found: (hx, hy) keep the last point tried (r 7, j 3) D[0] ← (L.x + 3 + 8hx, L.y + 3 + 8hy, dir 4); D[i] ← D[0] for every i ≥ 1 for i in 0 ..< n: C[i] ← Snap(L, D[i]) ; g_A1HubDx = −1, 0, 0, +1; g_A1HubDy = 0, +1, −1, 0 (i32[4] each)H6d. A1PathSearch(s, t) → path or none: [C] h(x, y): i32 ← min(a, b) + 2·max(a, b), a ← |x − t.x|, b ← |y − t.y| if |s.x − t.x| + |s.y − t.y| ≤ 1: return [s, t] ; the trivial path h0: i32 ← h(s); bound: i32 ← h0 + h0 ÷ 2; top: i32 ← bound + 35 do: pool ← one node, root ← {f h0, h h0, g 0, pos s, tried −1, row 0, ptr 0, dir DirOf(s), parent none, child none} node ← SearchStep(root, bound); bound ← bound + 5 if pool count > 899: return none ; exhausted: no road if node: return node, node.parent, …, root ; head = target end while bound < top return none
SearchStep(node, bound) → node or none: loop: if node.pos = t: return node np ← node.pos + (g_A1SearchDx[node.dir], g_A1SearchDy[node.dir]) open: bool ← np = t or (np inside the grid and (cell(np) & 0x200) = 0 and np not on node's parent chain) if open and (f: i32 ← h(np) + node.g + 2) ≤ bound: c ← node.child, or else a new pool node (the pool full at 900 → return none) linked as node.child, c.parent ← node td ← DirOf(np); c.row ← (node.dir − td) & 3; c.ptr ← 0 c.f ← f; c.h ← h(np); c.g ← node.g + 2; c.pos ← np; c.tried ← 0 c.dir ← (g_A1SearchTurns[c.row][0] + td) & 3 node ← c; continue node ← Backtrack(node); if none: return none
Backtrack(n) → node or none: if n.tried < 4: n.ptr ← n.ptr + 1; n.dir ← (g_A1SearchTurns[n.row][n.ptr] + n.dir) & 3 n.tried ← n.tried + 1 while n.tried = 3: if n = root: return none n ← n.parent; n.ptr ← n.ptr + 1; n.dir ← (g_A1SearchTurns[n.row][n.ptr] + n.dir) & 3; n.tried ← n.tried + 1 return n
DirOf(p) → i32: ; toward t (dx, dy): i32 ← t − p ; DirFromDelta: if |dx| ≥ 2·|dy|: dy ← (dy < 0) ? −1 : dy & 1 else if |dy| ≥ 2·|dx|: dx ← (dx < 0) ? −1 : dx & 1 dx ← clamp(dx, −2, 2); dy ← clamp(dy, −2, 2) return (g_DirOctant[5·dx + dy + 12][0] ÷ 2) & 3-
[C] The search tables. Moves are 4-neighbour by
dir:g_A1SearchDx(i8[4], bytes01 00 FF 00)+1, 0, −1, 0andg_A1SearchDy(bytes00 01 00 FF)0, +1, 0, −1, both read sign-extended, so dir 0 E, 1 S, 2 W, 3 N, the orderg_DirOctantgives ((+1, 0)→ 0); the model reads the four bytes from the exe and every road cell of every Act I window matches (which corrects § 16.3’s−1, 0, +1, 0).g_A1SearchTurns(u8[4][4], increments added todir): row 00 1 2 3, row 10 1 1 1, row 23 2 1 2, row 30 3 2 1. So the root (tried −1) triesd, d+1, d+3, d+2, and a child of rowrtries three directions: row 0td, td+1, td+3; row 1td, td+1, td+2; row 2td+3, td+1, td+2; row 3td, td+3, td+1(mod 4). The root’sptrreaches 4 only after its last try. -
[C]
g_DirOctant(i32[25][3]; only column 0 is read here), by5·dx + dy + 12afterDirFromDelta’s clamp. The clamp step is skipped when the second rule setsdxto −1, which is in range anyway.dx \ dy −2 −1 0 +1 +2 −2 5 4 4 4 3 −1 6 5 4 3 2 0 6 6 6 2 2 +1 6 7 0 1 2 +2 7 0 0 0 1 -
[C] Every move costs 2. The code computes
x = nx or y = ny ? 2 : 3, and a 4-neighbour move always takes the 2. Preset footprints (0x200) block; the target is always open. Every road cell of every Act I window matches.
H6e. A1PathJitter(L, i, path): [C] r: u32 ← Step(L.seed) & 3 ; level draw, before the path test if no path: return ; not taken: H6 calls only with a found path if D[i].dir ≠ 4: prepend a vertex (D[i].x, D[i].y) ; a bridge hub: its raw point the target-cell vertex ← (C[i].x, C[i].y) for each vertex v after the target-cell vertex that has a successor: ; the interior cells, target → start s1: u32 ← Step(L.seed); s2: u32 ← Step(L.seed) ; 2 level draws v.x ← L.x + 8·v.x + 3 + ((s1 & 1) + 2)·g_A1JitterDx[r] v.y ← L.y + 8·v.y + 3 + ((s2 & 1) + 2)·g_A1JitterDy[r] r ← (r + 1) & 3 the last vertex (the start cell) ← (Bp[i].x, Bp[i].y); append a vertex (A[i].x, A[i].y) polyline i ← the list, stored at O+0x68 + 4i ; map tiles ; g_A1JitterDx = +1, 0, −1, 0; g_A1JitterDy = 0, +1, 0, −1 (i32[4] each)-
[C] Each interior point moves 2 or 3 tiles along one axis, the axis rotating E, S, W, N from the drawn
r. The trivial path[s, t]has no interior vertex and draws only the firstStep. The jitter’s draws were checked one by one, and its points through the road tiles of every logged Act I out room (§ M; the 2026-10-15 addendum to the run). -
H6. [C] A failed search makes no draw.
A1PathscallsA1PathJitteronly for a found path (§ 8, Roads: “a found path marks its cells0x80, then the jitter draws”; § 16.3, “after a found path”). H6e’s first draw and its no-path return are the callee’s own order: itsStep & 3precedes its own path test, and that test is never false whenA1Pathscalls it. So a road whose search fails costs no draw, and H6 and H6e agree. The case was reached: in map seed 45’s Black Marsh one road’s search returns none (2 windows), and the model, which makes no draw for that road, matched every later level draw of both windows (the remaining roads’ jitter, then the waypoint and shrine passes of level 6): one extraStepwould have shifted them all. -
[I] Roads with 5 or 6 endpoints have no stock case: an Act I road set has at most 4.
A1PathEndpointscounts one endpoint per adjacency node to level 1 or 26, one per seam opening, cave cell and east-river bridge cell. Node endpoints and openings together are at most the nodes: a node to level 1 or 26 (a preset) gets no opening,OutBorderBuildmarks one opening per other seam vertex, and its own border pieces go in with file −1, soOutPresetFileRotategives them index(c + 1) mod Files, which is 0, 1 or 2 for Defs 4–7 (Files3) and never the opening index 3; stamps place file 0, and every explicit index beforeA1Pathsis on another Def. Caves are at most 1 (each placement is gated on and setsO.flags & 0x40) and the bridge at most 1, none on level 3. That bounds the count at 4 on levels 2, 3, 6 and 7 and 3 on levels 4 and 5; the scan gives 3, 4, 2, 2, 3 and 3 on levels 2–7. An exhausted search pool has no stock case either. The nodes in use form one chain, at most the depth reached plus one, and a child costs 2, so depth ≤ bound / 2.A1PathSearchis called only for levels 2–7, whose grids are at most 12 cells a side, soh0≤ 39, the depth ≤ 44 and at most 45 pool nodes are used against 900. Neither case happened in a logged window or in the 52 200 windows of the offline scan. -
[C] The road tiles are made later, at the room prepare of each out room, from these polylines (§ M), outside the level window and with no draw.
H7. Areas
Section titled “H7. Areas”H7. [C] Areas (A1Areas, after the waypoint and shrines). Near(d) = PlaceNear(d, −1); Rand(d) = PlaceRandom(d, −1, 0, 0xF). Failures are silent. (A1Areas, A1PlaceOneOrTwo; level 39)
H7a. OneOrTwo(d, s): [C] r ← Step(L.seed) ; level draw if (r & 3) = 0: Near(d); Near(d); return ; no further draw, whatever s is Near(d) if s = 0: return if (Step(L.seed) & 1) ≠ 0: Near(49 Cottages 3) ; level draw, else branch only- H7a. [C] The
sstep belongs to the else branch only. The(r & 3) = 0branch placesdtwice and returns, so anOneOrTwo(d, 1)call makes oneStepon that branch and two on the other. A reading with thesstep after both branches adds aStepto every(r & 3) = 0call withs= 1. The run’s level-seed steps separate the readings: levels 3–7 make 100 calls withs= 1 (20 windows each), 26 of them took the(r & 3) = 0branch, and every step matches with the else-only reading (74 took the else branch, 34 of those placingNear(49)).
| Level | Sequence |
|---|---|
| 2 Blood Moor | Near(46), OneOrTwo(47, 0), Rand(29), Rand(30) |
| 3 Cold Plains | OneOrTwo(48, 1), Rand(44), Rand(29), Rand(30) |
| 4 Stony Field | Near(160), Near(45), Rand(162), OneOrTwo(47, 1), OneOrTwo(42, 0), Rand(31) |
| 5 Dark Wood | Rand(161), Rand(41), Rand(40), OneOrTwo(48, 1), OneOrTwo(43, 0), Rand(29), Rand(30) |
| 6 Black Marsh | Rand(163), Rand(38), Rand(39), OneOrTwo(47, 1), OneOrTwo(42, 0), Rand(29), Rand(30) |
| 7 Tamoe Highland | OneOrTwo(48, 1), OneOrTwo(43, 0), Rand(31) |
| 17 Burial Grounds | Place(1, 1, 108, −1): no fit test, one rotation draw |
| 39 Moo Moo Farm | Rand(50), Rand(46), Rand(31), Rand(38), Rand(39), Rand(29), Rand(30) |
Act I draw sequence (level seed, in order; every Place with file −1 adds D2’s first-use draw when its Def is new):
- Border pass: one
RangeB(Files)per distinct edge and cornerDef, in ring order from v0 (§ E2). - Levels 2–7:
Type0 stamps (§ G: oneRangeB(groups)forBordType0,2Nper group tried, oneRange(variants)per stamp). - Levels 2–7, H2: the east river’s bridge
Range(ch − 2)(if it has one); the cliff cave’sStepand itsDef’s first use; the corner cave’sStepand first use. - Levels 2–7:
Type1, thenType2 stamps. - Levels 2–7, H4: the middle river’s bridge
Range(ch − 2); the cave entrance (PlaceFar2 draws on level 2, elsePlaceRandom2N) and its first use. - Levels 2–7:
Type3 stamps; then the roads’ jitter,1 + 2·(vertices − 2)per found path (H6). - Levels 3–6: the waypoint shuffle,
2N(none on level 3, which uses the seam rule). - Levels 2–7: the shrines’
Step & 3, then2N. - The areas of H7, in table order: each
Nearis2N, plus2Nmore when it falls back toPlaceRandom; eachRand2N; eachOneOrTwooneStep, plus one more whensis 1 and the first gave(r & 3)≠ 0 (H7a); each placed newDefone first-use draw.
All of 1–9 [C] (OutdoorAct1: every step checked one by one).
I. Act II
Section titled “I. Act II”Levels 41–46 and 134 (134 not reached: see Entry points).
I1. OutdoorAct2(L): [C] OutSeamMark(L); OutBorderBuild(L) ; § E (act 1: the seam pairs) 41: TownTransition (I6): 362 at (cw − 1, 0), or 363 at (0, ch − 1) when Lut Gholein is on side 3 BorderSubs; SpecialArea(388); OutShrinesPlace(5) PlaceList({395, 411, 401, 402, 399, 398, 403}, 7, perFile 0) 42: Cliff; BorderSubs; SpecialArea(388); OutWaypointPlace; OutShrinesPlace(5); Fills2 43: Cliff; BorderSubs; SpecialArea(390); PlaceList({396, 397}, 2, 0); OutWaypointPlace; OutShrinesPlace(5); Fills3 44: Cliff; BorderSubs; SpecialArea(412); PlaceList({413, 408, 409, 410}, 4, 0); OutWaypointPlace; OutShrinesPlace(5); Fills4 45: SpecialArea(389) ; nothing else 46: KingTombCliff (I3, fixed indices, then Place(4, 4, 394, −1)); BorderSubs; OutShrinesPlace(5); FillsValley 134: Place(4, 4, 394, −1); BorderSubs; FillsValley; OutShrinesPlace(5) ; [I]; fills before shrinesI2. BorderSubs (OutA2BorderSubs): OutBorderSubApply(L, 2, 364); (L, 1, 364); (L, 3, 364). [C]I3. Cliff (OutA2Cliff): [C] k: u32 ← Step(L.seed) & 7 ; level draw for each entry {def, file, x, y} of g_A2CliffLayouts[k], in row order (5 entries): Place(x, y, def, file) ; no fit test; file −1 takes the rotation KingTombCliff (OutA2KingTombCliff, level 46): [C] for each entry {def, file, x, y} of g_A2KingTombCliff (9 entries): Place(x, y, def, file) ; no file −1: no draw Place(4, 4, 394, −1) ; 394's first use drawsI4. PlaceList(defs, n, perFile): [C] k ← Range(L.seed, n) ; drawn for n = 1 too repeat n times: if perFile: for i in 0 ..< Files(defs[k]): PlaceRandom(defs[k], i, 0, 0xF) else: PlaceRandom(defs[k], −1, 0, 0xF) k ← (k + 1) % nI5. SpecialArea (OutA2SpecialArea): [C] def ← by L.id: 41 → 388, 42 → 388, 43 → 390, 44 → 412, 45 → 389 ; jump table other level, or PlaceRandom(def, −1, pad 0, sides 0xF) = false → fatal error (string 0xAA), exitI6. TownTransition (OutA2TownTransition, level 41): [C] node ← the first adjacency node (O.adj order) whose neighbour is level 40 (Lut Gholein); none → nothing node.side = 3: OutPresetPlace(0, ch − 1, 363, −1) else: OutPresetPlace(cw − 1, 0, 362, −1) ; direct placement: no fit test, no pad or sides-
[C] The cliff layouts,
g_A2CliffLayouts(i32[8][5][4]{def, file, x, y}, 0x50 bytes per layout). An entry is writtendef/file@(x, y);·is file −1 (from the rotation). k 0–2 are a horizontal cliff on row 4, k 3–4 an L with the 16 × 16 corner 382 at (4, 4), k 5–7 a vertical cliff on column 4. All eight layouts were reached.k pieces in placing order 0 376/1@(0,4), 378/·@(2,4), 377/·@(4,4), 377/·@(6,4), 376/2@(8,4) 1 376/1@(0,4), 377/·@(2,4), 378/·@(4,4), 377/·@(6,4), 376/2@(8,4) 2 376/1@(0,4), 377/·@(2,4), 377/·@(4,4), 378/·@(6,4), 376/2@(8,4) 3 376/2@(8,4), 377/·@(6,4), 382/·@(4,4), 381/·@(4,6), 379/2@(4,8) 4 376/2@(8,4), 378/·@(6,4), 382/·@(4,4), 380/·@(4,6), 379/2@(4,8) 5 379/1@(4,0), 381/·@(4,2), 380/·@(4,4), 380/·@(4,6), 379/2@(4,8) 6 379/1@(4,0), 380/·@(4,2), 381/·@(4,4), 380/·@(4,6), 379/2@(4,8) 7 379/1@(4,0), 380/·@(4,2), 380/·@(4,4), 381/·@(4,6), 379/2@(4,8) -
[C] The King Tomb cliff of level 46,
g_A2KingTombCliff(i32[9][4], same layout), in placing order:384/0@(8,0),383/2@(6,0),383/1@(4,0),383/0@(2,0),387/0@(0,0),385/0@(0,2),385/1@(0,4),385/2@(0,6),386/0@(0,8). No entry passes file −1, so the cliff makes no draw. -
[C] The fill lists, each a
PlaceListwithperFile0 followed by lists withperFile1:Fills2{395, 411, 400, 398}then{404–407}per file;Fills3{411, 399, 398, 403}then{395}per file twice;Fills4{395, 400, 398, 404, 405}then{411}per file twice;FillsValley{401, 402, 406, 407, 403}then{392, 393}per file. -
[C] No waypoint pass runs on 41, 45 or 46: the model makes none there and reproduces all 52 of their windows, every level-seed step included, where a waypoint pass would draw.
-
[I] No waypoint pass runs on 134, and 45 has no shrine pass. A failed
SpecialAreais fatal; every other failed placement is silent. Level 134 and the fatal branch have no stock case.
Act II draw sequence (in order; plus D2’s first-use draws for every new Def placed with file −1):
- Border pass first uses, the seam pairs’ included (§ E2).
- Levels 42–44: the cliff’s
Step & 7. - The three stamp
Types 2, 1, 3 (levels 41–44, 46, 134). SpecialArea’s placement draws (levels 41–45; on 45 aPlaceRandom,2Nand a first use, worked example 2).- Levels 43, 44:
PlaceList:Range(n), then2Nper placement. - Levels 42–44: the waypoint
2N. Then the shrinesStep & 3and2N(not on 45; on 134 after the fills). - The fill lists: per
PlaceListoneRange(n)and2Nper placement (on 41 its single list comes after the shrines).
All of 1–7 [C] (OutdoorAct2; level 134 [I]).
J. Act III
Section titled “J. Act III”Levels 76–78 (the jungles: Spider Forest, Great Marsh, Flayer Jungle; Levels “Jungle 1–3”), 79–82 (Lower Kurast,
Kurast Bazaar, Upper Kurast, Kurast Causeway; “Kurast 1–4”) and 83 (Travincal). [C] Their rectangles and links come from
the jungle layout, made at act creation on the act seed; each level’s window then fills it from the Def array the
layout left.
J1. ActLinkAct3(act): [C] T ← level 75 at its Levels offset L78 ← JungleLayout(T) ; J2, act draws KurastStack(L78) ; J3, no draw LevelSeamsByTouch(75, 83); LevelBorderAdj(75 … 83) ; warps.md § A, § CJ2. JungleLayout(T): [C] A ← the act seed itself (act +0x000), not a copy W, H: i32 ← Levels[76].SizeX, SizeY [difficulty]; nx ← W ÷ 32; ny ← H ÷ 32 ; 64 × 192: 2 × 6 J2a. the three rectangles rec[0] ← {T.x, T.y − H, W, H, dir 0, no parent}; n: i32 ← 1 ; jungle 1, directly north of the town minx ← T.x; miny ← T.y − H; maxx ← T.x + W; maxy ← T.y while n < 3: k: i32 ← Range(A, n) ; act draw d: u32 ← Step(A) % 5 ; act draw, unsigned R ← JungleRectRel(rec[k], W, H, d) if R overlaps any rec (RectGapTest(rec[m], R, 0) = 0 for some m): continue ; new k and d ; RectGapTest(A, B, 0) = 0 ⇔ gx < 0 and gy < 0 (step note) append R to rec[k].kids (more than 3 → fatal 0x63E); rec[n] ← R; n ← n + 1 minx ← min(minx, R.x); miny ← min(miny, R.y); maxx ← max(maxx, R.x + R.w) ; maxy is not updated if (maxx − minx) % 32 ≠ 0 or (maxy − miny) % 32 ≠ 0: fatal 0x64D / 0x64E gw: i32 ← (maxx − minx) ÷ 32 + 2; gh: i32 ← (maxy − miny) ÷ 32 + 2 ; 32-tile cells, 1-cell margin J2b. restart: ; also the target of J2d's test owner, order, marks, res ← 0 on all gw × gh cells for j in 0 ..< 3 (creation order): R ← rec[j] cx0: i32 ← (R.x − minx) ÷ 32 + 1; cy0: i32 ← (R.y − miny) ÷ 32 + 1; bottom ← cy0 + ny − 1 s: i32 ← (j = 0) ? Step(A) & 1 : (R.dir odd ? 1 : 0) ; act draw for j = 0: entry column side(s) ← s ? −1 : +1 ; toward the other column retry: R's nx × ny cells: owner ← j + 1; order, marks, res ← 0 col: i32 ← cx0 + s ; s as the previous try left it if j ≠ 0: marks(col, bottom) ← 1; marks(col + side(s), bottom) ← 2 for K in R.kids (attach order), by K.dir: ; the link cells to the children 0 → marks(cx0, cy0) ← 1; 1 → marks(cx0, cy0 + 3) ← 1; 2 → marks(cx0 + 1, cy0 + 3) ← 1 3 → marks(cx0, cy0 + 1) ← 1; 4 → marks(cx0 + 1, cy0 + 1) ← 1 cnt: i32 ← (j ≠ 0) ? 1 : 0; run: i32 ← 0; row: i32 ← bottom; num: i32 ← 100·(j + 1) while row ≥ cy0: ; the path, bottom row up order(col, row) ← num; num ← num + 1 if run ≠ 0 and row ≠ cy0 and Step(A) % 3 = 0: ; act draw, only when both tests pass run ← 0; col ← col + side(s); s ← s ^ 1 ; a sideways move, same row else: run ← run + 1; o ← (col + side(s), row) ; the other column if run > 1 and row > 1 and marks(o) = 0: marks(o) ← 2; cnt ← cnt + 1 ; dead-end candidate; row is absolute row ← row − 1 if cnt < 2: goto retry while cnt > 3: ; trim t: i32 ← Range(A, cnt) ; act draw the t-th (0-based) cell of R with marks 2, rows outer then columns: marks ← 0; cnt ← cnt − 1 J2c. exit masks ; W 1, E 2, S 4, N 8; neighbours U (N), D (S), Rt (E), Lf (W) for every grid cell c, rows outer, columns inner: m: u32 ← 0 if marks(c) = 1: ; a link to a child or to the parent best: i32 ← INT_MAX for (nb, bit) in (U, 8), (D, 4), (Rt, 2), (Lf, 1): if order(nb) ≠ 0 and order(nb) < best and owner(nb) = owner(c): m ← bit; best ← order(nb) ; replaces m the chosen neighbour gets the opposite bit in res (8 → res(U) |= 4, 4 → res(D) |= 8, 2 → res(Rt) |= 1, 1 → res(Lf) |= 2) for each neighbour nb with marks(nb) = 1 and owner(nb) ≠ owner(c): m |= its bit if order(c) ≠ 0: for each neighbour nb with |order(c) − order(nb)| = 1: m |= its bit res(c) |= m J2d. clearings ; one act draw per grid cell, margin included for every grid cell c, rows outer, columns inner: r: u32 ← Step(A) & 3 ; act draw v: u32 ← res(c); zero: bool ← (v = 0) if marks(c) = 2: ; a dead-end candidate nb ← (U, D, Rt, Lf); bit ← (0x80, 0x40, 0x20, 0x10) ; the clearing side N, S, E, W first q of ((i + r) & 3 for i in 0 ..< 4) with owner(nb[q]) = owner(c) and 0 < res(nb[q]) < 15: v |= bit[q] if v = 0: goto restart ; no path cell beside it if zero: found ← false first q (same rotation) with owner(nb[q]) ≠ owner(c) and marks(nb[q]) = 2: v |= bit[q]; found ← true t1: u32 ← Step(A) & 1 ; act draw, always on this branch r ← Step(A) & 3 ; act draw, always on this branch if t1 ≠ 0 and not found: first q of ((i + r) & 3) with 0 < res(nb[q]) < 15 and (v & bit[q]) = 0: v |= bit[q] if v & 0x80: res(U) |= 0x40; if v & 0x40: res(D) |= 0x80 if v & 0x20: res(Rt) |= 0x10; if v & 0x10: res(Lf) |= 0x20 marks(c) ← 0 res(c) |= v J2e. Defs for every cell: v ← res; low ← v & 15 low = 0: Def ← (v ≥ 16) ? g_JungleClearingDefs[v >> 4] : 0 ; 0 from the table → fatal 0x799 low ≠ 0 and v < 16: Def ← 529 + low ; 530–544 low ≠ 0 and v ≥ 16: d: i32 ← low for (b, col) in (0x10, 0), (0x20, 1), (0x40, 2), (0x80, 3): if v & b: d ← g_JungleSideDefs[d][col] d = 0 → fatal 0x78C; Def ← d ; 545–572 R.defs ← R's nx·ny cells, rows outer; R.clr ← the count of its Defs > 574 bubble-sort rec by y descending (stable) → levels 76, 77, 78 each L: L[+0x1BC] ← its defs; L[+0x1B8] ← its clr
JungleRectRel(parent, w, h, d) → rect: [C] (dx, dy) ← d 0: (0, −h); 1: (−w, q1); 2: (+w, q1); 3: (−w, q2); 4: (+w, q2) q1 ← −h ÷ 3 (the code: hi32(h · 0x55555555) − h, >> 1, plus its sign bit); q2 ← (−2h) ÷ 3 (signed, magic 0x55555556) return {parent.x + dx, parent.y + dy, w, h, dir d} ; h = 192 (the only size): q1 −64, q2 −128-
J2a. [C] The overlap test.
RectGapTest(A, B, 0)isRectGapwithout its outputs: with the per-axis gapsgx ← (A.x < B.x) ? B.x − A.w − A.x : A.x − B.w − B.xandgylikewise ony,h, it returns 0 exactly whengx < 0andgy < 0, so two jungles overlap only when both gaps are negative, and jungles that share an edge (a gap of 0) do not. It is the overlap of maze.md B2, notRectTouch’st = 0mode of warps.md C3. (RectGapTest,RectGap,JungleLayout, The validators) -
[C]
g_JungleSideDefs(i32[16][4]): row = the cell’s path exit mask, column = the clearing side bit W0x10, E0x20, S0x40, N0x80. Rows 0 and 15 are all 0.mask W E S N mask W E S N 1 W 0 545 546 547 8 N 561 562 563 0 2 E 548 0 549 550 9 N+W 0 564 565 0 3 E+W 0 0 551 552 10 N+E 566 0 567 0 4 S 553 554 0 555 11 N+E+W 0 0 568 0 5 S+W 0 556 0 557 12 N+S 569 570 0 0 6 S+E 558 0 0 559 13 N+S+W 0 571 0 0 7 S+E+W 0 0 0 560 14 N+S+E 572 0 0 0 -
[C]
g_JungleClearingDefs, read asg_JungleClearingDefs[v >> 4](4 bytes an entry);v >> 4is the clearing’s own sides (W 1, E 2, S 4, N 8): 1 → 575, 2 → 576, 3 → 577, 4 → 578, 5 → 579, 6 → 580, 7 → 0, 8 → 581, 9 → 582, 10 → 583, 11 → 0, 12 → 584. Entry 0 is the last flag ofg_LinkOutdoorFlags(never read here, sincev ≥ 16), and entries 13–15 are row 0 ofg_JungleSideDefs. Entries 7, 11 and 13–15 are 0, so a clearing with three or four sides is fatal (0x799). -
[I] The side lookup of J2e has no bound: a second side bit on one cell would index a row
d≥ 545, past the table. No logged layout had one (everyLNKSlist and Act III window of the run matches).
J3. KurastStack(L78): [C] acc: i32 ← 0 for id in 79, 80, 81, 82, 83: (w, h) ← Levels[id].SizeX, SizeY [difficulty]; acc ← acc − h rect(id) ← (L78.x + L78.w ÷ 2 − w ÷ 2, L78.y + acc, w, h) ; signed ÷; no draw-
[C] Jungle 1 is directly north of the town; the other two attach to random earlier jungles, so the three form a chain or a fork, and a jungle can be a dead end. The layout’s act-seed steps are its own: 119 for map seed 12345.
-
[C] The jungle restart and the path retry were reached in layouts whose Act III windows match.
J4. OutdoorAct3(L): OutSeamMark(L); OutJungleCells(L); OutKurastLevel(L); OutTravincal(L) ; each tests the id [C] OutJungleCells (76 … 78): [C] r: i32 ← Range(L.seed, L[+0x1B8] = 3 ? 6 : 2) ; always the first draw e: i32 ← 0; k: i32 ← 0 for each block row j (ny = 6 rows of 4 cells): 76, last row: Place(0, 4j, 573 Jungle Head, file (defs[nx·ny − 1] = 0 ? 1 : 0)); e ← e + 2 78, row 0: Place(0, 0, 574 Jungle Tail, file (defs[1] = 0 ? 1 : 0)); e ← e + 2 else for each block column i (nx = 2): d: i32 ← defs[e]; e ← e + 1; idx: i32 ← −1 if d > 574: ; a clearing d ← d + g_JungleClearingOff[L.id] ; read as [ + 4·L.id]: 76 → 0, 77 → 10, 78 → 20 idx ← g_JungleClearingPerm[r][k]; k ← k + 1 ; more than 3 clearings → fatal 0x47 if d ≠ 0: Place(4i, 4j, d, idx) ; −1 takes the rotation- [C] Each clearing of a jungle level gets a distinct file of its three through permutation row
r. Level 76 takes the Webby clearings 575–584, 77 the Boggy 585–594, 78 the Pygmy 595–604. - [C] The clearing tables. The offset table is read by
L.idfrom a base 76 entries (304 bytes) beforeg_JungleClearingOff, asg_JungleClearingOff[L.id − 76], so its data are the threei32for levels 76, 77, 78:0, 10, 20.g_JungleClearingPerm(i32[6][3], read as[k + 3r]) has the rows0 1 2,1 0 2,0 2 1,1 2 0,2 0 1,2 1 0;risRange(6)with three clearings, elseRange(2)(rows 0–1), andkcounts the clearings in placing order.
J5. OutKurastLevel (79 … 82): [C] ; RingSlums, RingBurbs, RingMetro: J5a 79: RingSlums; PlaceRandom(631, 0); Fill(618, 618, 4); Fill(616, 617, 0); Fill(615, 615, 0) 80: RingBurbs; Place(3, 3, 629, 0); Place(cw − 4, 3, 629, 1); PlaceRandom(630, 0); PlaceRandom(630, 1); PlaceRandom(631, 0); Fill(635 …); Fill(633, 634); Fill(632) 81: RingMetro; Place(3, ch − 4, 646, 0); Place(cw − 4, ch − 4, 646, 1); PlaceRandom(647, 0); PlaceRandom(647, 1); PlaceRandom(631, 0); Fill(651 …); Fill(649, 650); Fill(648) 82: Place(0, 0, 652, 0) ; the bridge, explicit index: no draw ; the arguments 80 and 81 leave out, OutFillRandom's shuffle width and fit test, and ; PlaceRandom(631, 0)'s pad and sides are not read yet: Open questions Fill = OutFillRandom(lo, hi, max): [C] list ← the shuffle of all cw·ch cells ; 2·cw·ch level draws for each cell: d ← lo + Range(L.seed, hi − lo + 1) ; drawn also when hi = lo if OutPresetFits: Place(d, −1); stop after max placements when max > 0J6. OutTravincal (83): Place 653 at (0, 0), 654 (2, 0), 655 (6, 0), 656 (0, 4), 657 (2, 4), 658 (6, 4), all file −1. [C]J5a. The Kurast rings: every piece file −1, no fit test. [C] b: u32 ← act[+0x474]; mid: i32 ← (cw − 1) ÷ 2; P(x, y, d) = Place(x, y, d, −1) RingSlums (79): gate ← b ? 1 : cw − 2 for x in 1 ... cw − 2: P(x, 0, 605 + 8·(x = gate)) ; north row, 613 the gate x ← 1; while x < cw − 1: P(x, ch − 1, 606 + 8·(x = mid)); x ← x + 1 + (x = mid) ; 614 the 16-wide south gate for y in 1 ... ch − 2: P(cw − 1, y, 607); P(0, y, 608) P(0, 0, 610); P(cw − 1, 0, 609); P(0, ch − 1, 612); P(cw − 1, ch − 1, 611) RingBurbs (80): (ng, sg) ← b ? (cw − 2, 1) : (1, cw − 2) for x in 1 ... cw − 2: P(x, 0, 619 + 8·(x = ng)); P(x, ch − 1, 620 + 8·(x = sg)) for y in 1 ... ch − 2: P(cw − 1, y, 621); P(0, y, 622) P(0, 0, 624); P(cw − 1, 0, 623); P(0, ch − 1, 626); P(cw − 1, ch − 1, 625) RingMetro (81): sg ← b ? cw − 2 : 1 x ← 1; while x < cw − 1: P(x, 0, 636 + 8·(x = mid)); x ← x + 1 + (x = mid) ; 644 the 16-wide north gate for x in 1 ... cw − 2: P(x, ch − 1, 637 + 8·(x = sg)) for y in 1 ... ch − 2: P(cw − 1, y, 638); P(0, y, 639) P(0, 0, 641); P(cw − 1, 0, 640); P(0, ch − 1, 643); P(cw − 1, ch − 1, 642)- [C] The Kurast rings (79 pieces 605–614, 80 619–628, 81 636–645) depend on the Act III act-seed bit at act
+0x474: 79’s north gate is atx = 1orcw − 2, and 80 and 81 swap their gate sides on it.mid = (cw − 1) ÷ 2places the 16-wide south gate of 79 and north gate of 81. Every first use of a ringDefdraws its rotation, in J5a’s order. Level 82 has no ring. All three rings were reached (79 20, 80 18, 81 18 windows).
Act III draw sequence:
- At act creation, on the act seed: the jungle layout of J2 (rect picks, entry columns, path steps, dead-end trims, clearing steps), in that order per jungle, with restarts.
- Levels 76–78:
Range(6 or 2), then a first-use draw for every newDefplaced with file −1 (the clearings, the Head and the Tail take explicit indices). - Levels 79–81: the ring’s placements, then per
PlaceRandom2N, then perFill2·cw·chplus oneRangeper cell visited, plus first uses. - Level 82: no draw. Level 83: the six first uses.
All of 1–4 [C].
K. Act IV
Section titled “K. Act IV”Levels 104–106 (Outer Steppes, Plains of Despair, City of the Damned: Levels “Mesa 1–3”) and 108 (Chaos Sanctuary,
“Diablo 1”).
K1. OutdoorAct4(L): [C] OutSeamMark(L) if L.id = 108: DiabloGrid(L); return ; K2 OutBorderBuild(L) FortressTransition: O.flags & (1 << 22) → Place(0, 1, 798, −1); O.flags & (1 << 23) → Place(0, 4, 798, −1) OutBorderSubApply(L, 1, 799); (L, 2, 799); (L, 3, 799) MesaFills: ; all PlaceRandom(·, −1, 0, 0xF); failures ignored if L.id = 106: PlaceRandom(811) a: i32 ← g_A4MesaBase[L.id − 104]; p: i32 ← g_A4PitsBase[L.id − 104] ; 104, 105, 106: a 812, 817, 823; p 828, 832, 832 PlaceRandom(a); PlaceRandom(a + 1) ×2; (a + 2) ×2; (a + 3) ×2; if L.id = 105: PlaceRandom(822); (a + 4) ×4 PlaceRandom(p); (p + 1) ×2; (p + 2) ×2; (p + 3) ×4K2. DiabloGrid(L): for i in 0 ..< 25: Place((i % 5)·3, (i ÷ 5)·3, g_A4DiabloGrid[i], −1) ; i = 5·row + column [C]- [C] The Mesa bases
g_A4MesaBase(i32[3])812, 817, 823andg_A4PitsBase(i32[3])828, 832, 832, byL.id − 104. - [C] Level 108’s grid
g_A4DiabloGrid(i32[25],i= 5·row + column, block(3·column, 3·row)) is 836 (Lava X) everywhere except 861 ati7 (N arm, block (2, 1)), 858 at 11 (W, (1, 2)), 862 at 12 (Heart, (2, 2)), 859 at 13 (E, (3, 2)), 860 at 17 (S, (2, 3)) and 857 at 22 (Entry, (2, 4)). The window makes exactly the 7 first-use draws, in grid order: 836, 861, 858, 862, 859, 860, 857. - [C] Records 852–856 (
Lava Warp,Forge,Bridge) are placed by no outdoor code: no immediate 852–856 in the 543 functions under the generators, none near the data they name,LevelId0 on all five records, and none in thedefsgrids of the 532 logged outdoor windows. Level 107, which holds 852–854, is a maze.
Act IV draw sequence: (1) border pass first uses; (2) the Fortress Transition’s first use; (3) stamps of Type 1, 2, 3;
(4) the Mesa fills in K1’s order, 2N each plus first uses. Level 108: the 7 first uses only. [C]
L. Act V
Section titled “L. Act V”Levels 110 (Bloody Foothills, Levels “Siege 1”), 111 (Frigid Highlands, “Barricade 1”), 112 (Arreat Plateau,
“Barricade 2”) and 117 (Frozen Tundra, “Barricade Snow”). Act V is expansion only.
L1. OutdoorAct5(L): [C] if L.id = 110: SiegeStrips(L); return ; no seam mark, no draw OutSeamMark(L); BarricadeBorderRing(L); BarricadeRavine(L); BarricadeGates(L); BarricadeCaveEntries(L) if L.id = 111: BarricadeToSiege(L) ; Place(cw − 2, ch − 4, 880, −1); Place(cw − 2, ch − 6, 896, −1) BarricadeLvlSub(L); BarricadePrisons(L) (111 only); BarricadeTablePlace(L) SiegeStrips: Place(28 − 2k, 0, 865 + k, 0) for k in 0 ..< 15 ; explicit index 0- [C] Level 110 makes no level-seed draw in its window:
To Town865 is at the east end (column 28) andTo Barricade879 at column 0, all with index 0.
L2. BarricadeBorderRing(L): [C] s: i32 ← 4 + (L.id = 117) ; style 4 dirt, 5 snow for v in the ring from its head; n ← v.next: (dx, dy) ← VertexDir(v); (dx2, dy2) ← VertexDir(n) ; unit steps v → n, n → n.next e ← BorderEdgeDef(dx, dy, s) ; § E2a if not (v.flags & 2): (x, y) ← (v.x & ~1, v.y & ~1) while (x, y) ≠ (n.x & ~1, n.y & ~1): x ← x + 2dx; y ← y + 2dy; Place(x, y, e, −1); cell(x, y) |= 1 ; the anchor cell only if v.flags & 1: ; any seam, preset or not gx ← (max(v.x, n.x) − 4·|dx|) & ~1; gy ← (max(v.y, n.y) − 4·|dy|) & ~1 cell(gx, gy) |= 0x400; cell(gx + 2·|dx|, gy + 2·|dy|) |= 0x400 ; two blocks, 4 cells before the far end c ← BorderCornerDef(e(2dx) + 2dy, e(2dx2) + 2dy2, s) ; § E3, always the doubled form if c ≠ 0: Place(n.x & ~1, n.y & ~1, c, −1); that cell |= 1 if L.id = 111: cell(cw − 2, ch − 4) |= 0x400; cell(cw − 2, ch − 3) |= 0x400- L2. [C] Ring. Pieces are 16 × 16 (2 × 2 cells) on even cells (
& ~1clears bit 0). Per ring segment, edge pieces 881–884 (+76 on snow) run from the vertex to the next, then the corner 885–888 at the turn replaces the last edge piece; both uses count for the rotation. Only a piece’s anchor cell gets bit 0.
L3. BarricadeRavine(L): [C] o: i32 ← (L.id = 117) ? 76 : 0 (x, y) ← (cw − 2, 0) ; the NE corner block while (x, y) ≠ (0, ch − 2): k: i32 ← def(x, y) − (881 + o) ; a ring piece, row k + 1 of § E2a: 0 … 11 Place(x, y, 893 + o + k, −1) x ← x + 2·g_A5RavineStep[k].dx; y ← y + 2·g_A5RavineStep[k].dy Place(cw − 2, 0, 906 + o, −1); Place(0, ch − 2, 905 + o, −1) ; the NE and SW ends-
L3. [C]
g_A5RavineStep(i32[12][2]{dx, dy}, byk): each ring piece’s outgoing direction. k 0(−1, 0), 1(0, −1), 2(+1, 0), 3(0, +1), 4(0, −1), 5(+1, 0), 6(0, +1), 7(−1, 0), 8(−1, 0), 9(0, −1), 10(+1, 0), 11(0, +1). The walk runs down the east column and along the bottom row; every ravine piece takes file −1, so each new ravineDefdraws its first use. -
L4. [C] Gates. Each edge’s first
0x400cell gets one gate, file −1: 909 top, 908 bottom, 910 left, 907 right. -
L4. Which row or column is each edge, and the direction each is scanned in, are not read yet (Open questions).
-
L4. [C] Caves,
g_A5CaveEntries(i32[3][5]{level, file, far, defTall, defWide}):(112, 0, 0, 913, 914),(117, 0, 1, 983, 984),(117, 0, 0, 985, 986). For each row of the level, in table order: a wide level (L.h < L.w) getsPlace(far ? cw − 2 : 0, 2, defWide, file), a tall onePlace(2, far ? ch − 2 : 0, defTall, file). No fit test, no draw. -
L5. [C] Stamps.
Type12 (Barricade,BordType2,GridSize2) through G1’s record loop with base 0, the Act V match callback andDefmap: DS1 main index 48 names the border or ravine piece expected, 49 the Barricade piece 915–930 (987–1002 on snow) it becomes; sub 31 of main 48 is the wildcard −5. -
L5. Whether the Act V match callback also refuses a seam opening, as G4’s match does, is not read yet (Open questions).
-
L5. [C] The stamp
Defmap,g_A5SubDefMap(i32[10][5]{main, subLo, subHi, defDirt, defSnow}). For a DS1 wall cell withmain = (W >> 20) & 0x3Fandsub = (W >> 8) & 0xFF, main 48 or 49, the first row with thatmainandsubLo ≤ sub ≤ subHigives(L.id = 117 ? defSnow : defDirt) − subLo + sub. No matching row, or anothermain, is a fatal error.Row main sub defDirt defSnow gives (dirt) 0 49 1–16 915 987 915–930 1 49 31–46 915 987 915–930 2 48 1 883 959 883 3 48 2–3 881 957 881–882 4 48 4 884 960 884 5 48 5 895 971 895 6 48 6–7 893 969 893–894 7 48 8 896 972 896 8 48 30 0 0 0 9 48 31 −5 −5 −5, the wildcard -
L6. [C] Prisons (111). While fewer than 3 and up to 90 attempts:
x ← 2·Range(L.seed, cw ÷ 2),y ← 2·Range(L.seed, ch ÷ 2); a Barricade 1–8 piece (915–922) there becomesDef + 16(931–938, file −1). Then two moreRangedraws, always, start a full scan for the rest. Fewer than 3 is a fatal error. -
L6. The fallback scan’s order is not read yet (Open questions).
-
[C] The prisons’ fallback scan places prisons in Frigid Highlands for map seed 312: 2 by the scan in each of the two windows, every draw matched.
-
L7. [C] Table,
g_A5PlaceTable(i32[15][7]{level, defTall, defWide, file, unused, count, required}; column 4 is not read). For each row of the level, in table order:Def ← L.w < L.h ? defTall : defWide, thencount×PlaceRandom(Def, file, pad 0, sides 0xF); ifcount ≤ 0or the last call failed, and the row isrequired, error 0x219 and exit. So only the last call of arequiredrow is tested.Level rows defTall/defWide file ×countin table order (✓ required)111 955/956 0 ×1 ✓; 944/947 · ×1; 942/945 · ×4; 943/946 · ×4 112 955/956 0 ×1 ✓; 953/953 · ×1 ✓; 941 · ×1; 939 · ×1; 940 · ×5 117 955/956 1 ×1 ✓; 954/954 · ×1 ✓; 948 · ×4; 949 · ×4; 950 · ×4; 951 · ×3 ·is file −1; a singleDefis the same for tall and wide. The table’s own order is the portals of 111, 112, 117 (rows 0–2), the waypoints of 112 and 117 (3–4), then the fills of 111, 112 and 117 (5–14); the unused column holds 25, 25, 25, 25, 25, 10, 20, 20, 10, 8, 15, 9, 9, 9, 5.
Act V draw sequence (levels 111, 112, 117): (1) the ring’s first uses (edges and corners, dirt or snow); (2) the
ravine pieces’ first uses, in walk order, then the two ends’; (3) the gates’ first uses; (4) 111: the To Siege pieces’
first uses; (5) Type 12 stamps (2N per group, Range(variants) per stamp, every matching position); (6) 111: the
prisons’ Range pairs, the two extra Ranges and the prisons’ first uses; (7) the table rows, 2N per PlaceRandom
plus first uses. The caves make no draw. Level 110: none. [C]
M. The out-room grids at the room prepare (and the Act I road tiles)
Section titled “M. The out-room grids at the room prepare (and the Act I road tiles)”This step runs outside the level window: it is the first part of the room prepare of every out room (room type 1), when room-tiles.md step 5 prepares the room, before its first LvlSub pass. It makes no draw. Since the room-tiles model runs on the grids this section predicts, in every log that carries the outdoor lines; only its own run’s logs, which have none, still take them from the log.
M2. OutRoomRoadGrid(L, R): [C] G ← GridAlloc(OR+0x3C, w + 3, h + 3) ; zeroed; G(X, Y) is tile (R.x − 1 + X, R.y − 1 + Y) RoadRasterize: rect ← {R.x − 1, R.y − 1, w + 3, h + 3} for i in 0 ..< O[+0x260]: for each segment p → p.next of polyline i (§ H6e): GridLineOp(G, p, rect, value 1, op or, width 2) ; M3 RoadCodes: for X in 1 ... w + 1: for Y in h + 1 down to 1: ; columns outer, rows bottom-up (a sliding 3 × 3 window) if G(X, Y) = 0: continue m: u32 ← [G(X+1, Y−1)]<<7 | [G(X+1, Y)]<<6 | [G(X+1, Y+1)]<<5 | [G(X, Y−1)]<<4 | [G(X, Y+1)]<<3 | [G(X−1, Y−1)]<<2 | [G(X−1, Y)]<<1 | [G(X−1, Y+1)] if m ≠ 0 and (b: u8 ← g_RoadCodes[m]) ≠ 0: floor(X − 1, Y − 1) ← (b << 8) | 0x82 ; op 3 (set)- [C]
[ ]is 1 for a non-zero cell. The mask bits name the neighbours of the centre: 7 NE, 6 E, 5 SE, 4 N, 3 S, 2 NW, 1 W, 0 SW.
M3. GridLineOp(G, p, rect, value, op, n): [C] ; the segment p → p.next; ECX grid, EDX vertex, stack: rect, value, op, width n (x, y): i32 ← p; dx: i32 ← p.next.x − x; dy: i32 ← p.next.y − y sx ← dx < 0 ? −1 : 1; sy ← dy < 0 ? −1 : 1; ax ← |dx|; ay ← |dy|; err: i32 ← 0 Put(px, py): if rect.x ≤ px < rect.x + rect.w and rect.y ≤ py < rect.y + rect.h: G(px − rect.x, py − rect.y) ← op(G(px − rect.x, py − rect.y), value) if ax < ay: ; y-major: the width runs along +x for k in 0 ..< n: Put(x + k, y) repeat ay times: y ← y + sy; err ← err + ax; if err > ay: x ← x + sx; err ← err − ay for k in 0 ..< n: Put(x + k, y) else: ; x-major: the width runs along +y for k in 0 ..< n: Put(x, y + k) repeat ax times: x ← x + sx; err ← err + ay; if err > ax: y ← y + sy; err ← err − ax for k in 0 ..< n: Put(x, y + k)-
[C] Both ends of a segment are drawn, and the minor axis steps when the error exceeds the whole major length, not half of it.
-
[C]
g_RoadCodes(u8[256], by the maskm; 0 writes nothing).m codes, m + 0 … m + 15 0–15 0 0 16 16 0 0 16 16 14 14 6 19 14 14 6 19 16–31 15 15 5 5 15 15 21 21 8 8 10 38 8 8 40 20 32–47 as 0–15 48–63 as 16–31 64–79 13 13 7 7 13 13 13 7 4 4 11 37 4 4 11 43 80–95 3 3 12 12 3 3 39 39 9 9 2 43 9 9 44 26 96–111 13 13 7 7 13 13 13 7 23 23 41 17 23 23 41 17 112–127 3 3 12 12 3 3 39 39 42 42 46 42 42 42 33 31 128–143 as 0–15 144–159 15 15 5 5 15 15 21 21 8 8 10 38 8 8 35 20 160–175 as 0–15 176–191 as 16–31 192–207 13 13 7 7 13 13 13 7 4 4 11 37 4 4 11 37 208–223 18 18 35 35 18 18 22 22 36 36 45 34 36 36 28 29 224–239 as 96–111 240–255 18 18 35 35 18 18 22 22 24 24 25 32 24 24 30 1 -
[C] Checked. From the latest outdoor model of each level, the reference model predicts the three grids of every type-1 room at its first
LvlSubpass, in the 38 logs that carry both the outdoor window and the room-prepare lines: all 2712 out rooms (Acts I, II, III and V; 744 with road tiles) match cell for cell, 352204 checks, 0 mismatches (the 2026-10-15 addendum to the run). -
[C] Fed to the room-tiles model. runs the room-tiles passes on these predicted grids in the 40 logs with outdoor and
LvlSublines (the 38 plus two later objects logs): 2884 type-1 rooms, 12 974 activations, 434 721 room-tiles checks, 0 mismatches.
Outputs
Section titled “Outputs”-
[C] The three grids of § B (def grid, grid0, cell grid) and
O.flags, whichOutdoorRoomsCreate(drlg/overview step 8) turns into rooms, rows outer: a0x200cell with a non-zero def-grid entry makes the embedded preset (its file index overwritten by bits 16–19, itsflagsfrom grid0), another0x200cell or a0x100cell makes nothing, and any other cell makes one 8 × 8 out room whose+0x28is grid0| 0x80000. 22422 preset anchors and 7376 out rooms were checked. -
[C] The level seed after the window.
-
[C] At act creation, Act III’s level rectangles (75–83), the jungle
Defarrays and clearing counts of 76–78, itsLevelLinkslist and its adjacency lists (§ J1), and the act seed after the jungle layout. -
[C] On Act I levels 2–7, the road polylines at
O+0x68(§ H6e), which the room prepare rasterises (§ M). -
[C] At each out room’s prepare, its orientation, wall and floor grids before the first
LvlSubpass (§ M).
Worked example
Section titled “Worked example”Seeds are low:high, hex. All; Files values are the LvlPrest operands the run’s instances showed. [C] The window starts at the re-seeded Init(base + id), whose high word is 0000029A (666).
1. Burial Grounds (level 17), map seed 3103, classic normal. Rect (1136, 968, 40, 48), 5 × 6 cells, O.flags 0. Seed in 3CD4C686:0000029A. Act I on level 17: no cliff mark, the seam mark, the border pass, then Place(1, 1, 108, −1) (H7). The seam with the neighbour runs along the bottom row.
| # | Draw | Low word after | Files |
Effect |
|---|---|---|---|---|
| 1 | RangeB(3), W edge Def 5 |
870C27B8 |
3 | mod 3 = 1 → c 2: (0, 4) index 2, (0, 3) 0, (0, 2) 1, (0, 1) 2, (0, 0) overwritten |
| 2 | RangeB(1), corner Def 9 at (0, 0) |
C46159C3 |
1 | index 0 |
| 3 | RangeB(3), N edge Def 6 |
448D8B46 |
3 | mod 3 = 1: (1, 0) index 2, (2, 0) 0, (3, 0) 1 |
| 4 | RangeB(1), corner Def 10 at (4, 0) |
65502E62 |
1 | |
| 5 | RangeB(3), E edge Def 7 |
A12E9953 |
3 | mod 3 = 2 → c 0: (4, 1) index 0, (4, 2) 1, (4, 3) 2, (4, 4) 0 |
| 6 | RangeB(1), corner Def 11 at (4, 5) |
5D8E7562 |
1 | |
| 7 | RangeB(3), S edge Def 4 |
C1ADC517 |
3 | mod 3 = 1: (3, 5) index 2; the opening at (1, 5) |
| 8 | RangeB(1), corner Def 8 at (0, 5) |
E6652864 |
1 | |
| 9 | RangeB(1), Def 108 at (1, 1) |
28B0827C |
1 | index 0; 24 × 32: cells (1 … 3, 1 … 4) |
Seed out 28B0827C:60189741. The final cell at (1, 5) is 0x40601: index 4, the opening 0x400, footprint 0x200,
border 0x1. grid0 holds the warp-slot flag 0x40 (slot 2) on cells (0 … 2, 5), the seam segment. Every cell is border
or footprint, so OutdoorRoomsCreate makes no out room here, only the embedded presets. [C]
2. Valley of Snakes (level 45, Levels “Desert 5”), same game. Rect (872, 744, 32, 32), 4 × 4 cells. Seed in
3CD4C6A2:0000029A, 19 draws, seed out CD6C4C8F:3E5692E2. Every border Def here has Files 1 (index 0).
| # | Draw | Effect |
|---|---|---|
| 1 | first use of the W edge piece | placed at (0, 2), (0, 1), (0, 0), and every one of them overwritten below: it is not in the final grid |
| 2–3 | first uses of the seam pair 373, 372 | the W side is a seam with an outdoor level (grid0 0x10, slot 0): 373 at the mid cell (0, 1), 372 at (0, 2) |
| 4–10 | first uses of corner 369, N edge 366, corner 370, E edge 367, corner 371, S edge 364, corner 368 | ring order from v0 |
| 11–18 | SpecialArea(389): PlaceRandom shuffle, N = 4, four swaps of Range(4) pairs: (3, 2), (2, 3), (1, 1), (3, 3) |
the list ends as it started, [(0,0), (1,0), (0,1), (1,1)]: 389 (16 × 16) fits at (1, 1) |
| 19 | first use of 389 | index 0 |
[C] The low words of draws 11–18 are 29D0C97F, 359DFD8E, 1A78E0D6, F55E662F,
7483A7B9, 71158971, 6AE1371F, 95757C5F.
3. Chaos Sanctuary (level 108), same game. Rect (1500, 1000, 120, 120), 15 × 15 cells. Seed in 3CD4C6E1:0000029A.
| # | Def (block) |
Files |
Low word after | Index |
|---|---|---|---|---|
| 1 | 836 (0, 0) | 1 | 7BA19DBF |
0 (all 19 blocks) |
| 2 | 861 (2, 1) | 2 | 3D331D4C |
lo & 1 = 0 → 1 |
| 3 | 858 (1, 2) | 2 | 2D291BB7 |
1 → 0 |
| 4 | 862 (2, 2) | 1 | 2F49E619 |
0 |
| 5 | 859 (3, 2) | 2 | 59782E0C |
0 → 1 |
| 6 | 860 (2, 3) | 2 | 1C637668 |
0 → 1 |
| 7 | 857 (2, 4) | 1 | 94E5C6A5 |
0 |
Seed out 94E5C6A5:0BD73402. [C]
4. Spider Forest (level 76), map seed 3103, classic normal. Rect (1000, 808, 64, 192), 8 × 24 cells, three
clearings. Seed in 3CD4C6C1:0000029A, 7 draws, seed out C0C6D42A:0D2F6FCB. Draw 1 is Range(6) (three clearings);
draws 2–7 are the first uses of the six jungle Defs placed with file −1 (533, 538, 544, 552, 559, 569; 569 is
used twice). The blocks, west
column then east, from the north row: (578, 533), (552, 544), (576, 569), (580, 569), (559, 538), and the Jungle Head 573
over the whole last row. The clearings 578, 576 and 580 take indices 1, 2 and 0 from the permutation, with no draw. [C]
5. Draw counts per window (test vectors: seed into and out of the window, the number of level draws, cells and the final O.flags). Map seed 3101, expansion normal, server copy:
| Level | Rect | Cells | O.flags |
Seed in | Seed out | Draws |
|---|---|---|---|---|---|---|
| 2 | (1064, 1120, 96, 56) | 12 × 7 | 0x148 |
6747A4ED:0000029A |
D450AAF1:2607E4A5 |
3724 |
| 3 | (984, 1080, 80, 80) | 10 × 10 | 0x40 |
6747A4EE:0000029A |
257339BC:15E46021 |
5127 |
| 17 | (968, 1160, 40, 48) | 5 × 6 | 0 | 6747A4FC:0000029A |
8705C99A:0822B921 |
9 |
| 41 | (1000, 920, 80, 80) | 10 × 10 | 0 | 6747A514:0000029A |
4474724A:5BC5999C |
4029 |
| 45 | (1048, 824, 32, 32) | 4 × 4 | 0 | 6747A518:0000029A |
019AA0B7:34226D3E |
19 |
| 76 | (1000, 808, 64, 192) | 8 × 24 | 0 | 6747A537:0000029A |
E7209ACB:59A4DDDC |
8 |
| 79 | (1056, 616, 80, 64) | 10 × 8 | 0 | 6747A53A:0000029A |
A386D481:560F0233 |
776 |
| 82 | (1072, 472, 48, 16) | 6 × 2 | 0 | 6747A53D:0000029A |
6747A53D:0000029A |
0 |
| 83 | (1064, 408, 64, 64) | 8 × 8 | 0 | 6747A53E:0000029A |
61201543:63DBC94E |
6 |
| 104 | (1032, 992, 80, 64) | 10 × 8 | — | 6747A553:0000029A |
48730D9A:0FB784FE |
3953 |
| 108 | (1500, 1000, 120, 120) | 15 × 15 | 0 | 6747A557:0000029A |
AB0C034D:31784D68 |
7 |
| 110 | (760, 1000, 240, 48) | 30 × 6 | 0 | 6747A559:0000029A |
6747A559:0000029A |
0 |
| 111 | (696, 872, 64, 160) | 8 × 20 | 0 | 6747A55A:0000029A |
E645993C:40AF44A9 |
2376 |
| 117 | (2000, 1896, 64, 160) | 8 × 20 | 0 | 6747A560:0000029A |
5AFE4F8E:69787FC5 |
3802 |
[C] Levels 82 and 110 draw nothing (an explicit
index, and the Siege strips); 83’s six draws are the six Travincal first uses (J6); 108’s seven are example 3’s; 76’s eight
are the Range(6 or 2) and seven first uses. Blood Moor is 12 × 7 cells (its link pick), and 111 and 117 are 8 × 20
(their link picks).
Reimplementation notes
Section titled “Reimplementation notes”-
Every first use draws,
Files1 included, and the first index is one past the draw:(RangeB(Files) + 1) % Files. Reset the counters at every build. [C] -
A piece that is overwritten still drew. The border pass places edge pieces where corners, seam pairs, rivers and openings later go; their first uses count (example 2). [C]
-
A failed placement still shuffles.
PlaceRandom,PlaceNearand the waypoint and shrine passes make their2Ndraws whether or not a cell fits;PlaceNearmakes4Nwhen it falls back. [C] -
Range(1)draws inPlaceListand inOutFillRandom(hi = lo). [C] -
The shrine draw comes first, before the shuffle and even when there is no interior. [C]
-
The seam opening is a cell write, not a rotation index. Index 3 (4 on level 17) goes into bits 16–19 after the piece is placed. [C]
-
Use the link builder’s size. Blood Moor and the Barricade levels are not their
Levelssize. [C] -
Act III’s jungle layout steps the act seed itself, not the link builder’s copy, at act creation; Act III’s level windows then start from their re-seeded level seeds like every other act. [C]
-
Conditional draws in the jungle walk. The path’s
Step(A) % 3is drawn only whenrun ≠ 0and the row is not the top one (C short-circuit); on J2d’s unpaired branch both further steps are drawn whatever the first gives. [C] -
The road search’s step cost is always 2, although the code holds a 3 for a diagonal step that its 4-neighbour moves never take. [C]
-
Signed arithmetic.
cw,ch, the footprints and the mid cell use signed÷; the rotation uses signed%. [C] -
An empty link slot is not a seam.
LevelBorderAdjmakes an adjacency node only forVis≠ 0 andWarp−1; an empty slot also hasWarp−1. [C] -
OneOrTwo’s second draw is on one branch only. The(r & 3) = 0branch places twice and returns; only the other branch draws forNear(49)whensis 1. [C]
Evidence
Section titled “Evidence”- § 3 and § 5: the act link builder that gives the level rects, the adjacency lists and the outdoor flags; the warp points from the out rooms’ flags.
- Reference model: replays the run (the worked examples included). It is a check of this spec, not a source: every statement above cites the code, the data or a run.
- drlg/overview steps 2, 7, 8; warps.md § A–C, § E; room-tiles.md step 5; rng/seeds; rng.