#!/usr/bin/env python3
"""Generate the figures of the world chapter, docs/world/.

The figures are original schematic drawings. From your own DOS START.EXE
(data-segment image at file offset 0x2e360) the script reads:

- the initial wall properties of references 0 to 24 at data-segment offset
  0x2268 (docs/executable/data/WALLS_AND_DOORS.md#d-2268), for the door figure;
- the door-forcing chances at 0x5a2d (data/WALLS_AND_DOORS.md#d-5a2d), for the forcing chart.

The level-connection figure transcribes the level changes of the original
scripts, decoded from the 16 INF files and listed in
docs/world/LEVEL_CHANGES.md; the coordinate figure follows the conventions of
docs/world/COORDINATES.md. No game graphics are used.

Usage:
    python3 scripts/world/make_world_figures.py [START.EXE] [output_directory]

The defaults are data/originals/eob2/START.EXE and docs/world/img/.
"""
import hashlib
import math
import sys
from html import escape
from pathlib import Path

ROOT = Path(__file__).resolve().parents[2]
EXE = Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT / 'data/originals/eob2/START.EXE'
OUT = Path(sys.argv[2]) if len(sys.argv) > 2 else ROOT / 'docs/world/img'
SHA256 = '2bb5edf06d966a4dbf40dd4866733a9ce37e47c5ace052615df4b6b69d4cb8b4'

d = EXE.read_bytes()
if hashlib.sha256(d).hexdigest() != SHA256:
    sys.exit(f'{EXE}: unexpected SHA-256; this script reads the DOS START.EXE listed in docs/files/INVENTORY.md')
DS = 0x2e360
WALL_FLAGS = list(d[DS + 0x2268:DS + 0x2268 + 25])
FORCE = [int.from_bytes(d[DS + 0x5a2d + 2 * i:DS + 0x5a2f + 2 * i], 'little') for i in range(19)]
PASSAGE, SMALL, MONSTER, DOOR, OPEN_END, CLOSED_END = 0x01, 0x02, 0x04, 0x08, 0x10, 0x20

FONT = "system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif"
SURF, BORDER, INK, INK2, MUTED, GRID = '#fcfcfb', '#dddcd7', '#0b0b0b', '#52514e', '#8a8984', '#eeede9'
BLUE, LIGHT, ORANGE, SHADE, GREEN, RED = '#2a78d6', '#dbe8f8', '#eb6834', '#f1f0ec', '#2f8f5b', '#c0392b'


def text(x, y, s, size=12, fill=INK, weight=None, anchor='start'):
    w = ' font-weight="bold"' if weight else ''
    return (f'<text x="{x:.1f}" y="{y:.1f}" font-size="{size}" fill="{fill}"{w} '
            f'text-anchor="{anchor}" dominant-baseline="central">{escape(s)}</text>')


def frame(W, H, title, desc):
    return [f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}" width="{W}" height="{H}" '
            f'role="img" font-family="{FONT}">',
            f'<title>{escape(title)}</title>', f'<desc>{escape(desc)}</desc>',
            f'<rect x="0.5" y="0.5" width="{W-1}" height="{H-1}" rx="10" fill="{SURF}" stroke="{BORDER}"/>']


def write(name, parts):
    parts.append('</svg>')
    OUT.mkdir(parents=True, exist_ok=True)
    (OUT / name).write_text('\n'.join(parts) + '\n', encoding='utf-8')
    print(OUT / name)


def arrowhead(x1, y1, x2, y2, colour, size=7):
    a = math.atan2(y2 - y1, x2 - x1)
    p1 = (x2 - size * math.cos(a - 0.4), y2 - size * math.sin(a - 0.4))
    p2 = (x2 - size * math.cos(a + 0.4), y2 - size * math.sin(a + 0.4))
    return f'<path d="M{x2:.1f},{y2:.1f} L{p1[0]:.1f},{p1[1]:.1f} L{p2[0]:.1f},{p2[1]:.1f} Z" fill="{colour}"/>'


# ------------------------------------------------------------- level connections
SETS = {'forest': '#d9ead3', 'dung': '#ece4d6', 'mezz': '#dbe8f8', 'silver': '#e9e9ef', 'crimson': '#f6dcd8'}
LEVELS = {  # level: (x, y, graphics set)
    4: (90, 100, 'forest'), 7: (430, 100, 'silver'), 8: (600, 100, 'silver'),
    5: (260, 170, 'mezz'), 9: (600, 190, 'silver'),
    1: (90, 260, 'dung'), 6: (260, 280, 'mezz'), 15: (430, 230, 'crimson'), 16: (600, 290, 'crimson'),
    2: (90, 370, 'dung'), 10: (260, 390, 'mezz'), 14: (600, 390, 'mezz'),
    3: (90, 480, 'dung'), 11: (260, 490, 'mezz'), 12: (430, 490, 'mezz'), 13: (600, 490, 'mezz'),
}
PORTALS = (430, 380)
STAIRS = [(4, 5, 2), (4, 1, 2), (1, 5, 2), (1, 2, 2), (2, 3, 2), (5, 6, 2), (5, 7, 2), (7, 8, 2), (8, 9, 2),
          (9, 5, 1), (6, 10, 2), (6, 15, 2), (15, 16, 1), (10, 11, 2), (11, 12, 2), (12, 13, 2), (12, 14, 2)]
PITS = [(1, 2), (11, 10), (12, 11), (13, 14), (14, 11)]


def levels():
    W, H = 700, 590
    bw, bh = 96, 40
    desc = ('The sixteen levels and the level changes of the original scripts. Each level is coloured by its '
            'graphics set: forest for level 4; dung for levels 1, 2 and 3; mezz for 5, 6 and 10 to 14; silver for '
            '7, 8 and 9; crimson for 15 and 16. Solid lines are stairs, entrances and scenes, both ways unless '
            'an arrow shows one way: 4 with 5 and 1; 1 with 5 and 2; 2 with 3; 5 with 6 and 7; 7 with 8; 8 with '
            '9; 9 to 5; 6 with 10 and 15; 15 to 16; 10 with 11; 11 with 12; 12 with 13 and 14. Dotted arrows '
            'are pits: 1 to 2, 11 to 10, 12 to 11, 13 to 14 and 14 to 11. Thick orange lines are portals: '
            'levels 3, 6 and 14 lead to one another and to 16.')
    out = frame(W, H, 'How the levels connect', desc)
    out.append(text(20, 26, 'How the levels connect', 14, weight=True))
    out.append(text(20, 46, 'Level changes made by the original scripts; colours show the graphics set.', 12, INK2))

    def centre(n):
        return LEVELS[n][0], LEVELS[n][1]

    def edge_points(a, b, offset=0.0):
        (x1, y1), (x2, y2) = a, b
        dx, dy = x2 - x1, y2 - y1
        length = math.hypot(dx, dy)
        nx, ny = -dy / length * offset, dx / length * offset
        # clip to the boxes
        def clip(x, y, tx, ty):
            ddx, ddy = tx - x, ty - y
            sx = (bw / 2 + 4) / abs(ddx) if ddx else 1e9
            sy = (bh / 2 + 4) / abs(ddy) if ddy else 1e9
            s = min(sx, sy)
            return x + ddx * s, y + ddy * s
        p = clip(x1, y1, x2, y2)
        q = clip(x2, y2, x1, y1)
        return p[0] + nx, p[1] + ny, q[0] + nx, q[1] + ny

    # portals first, under everything
    for n in (3, 6, 14):
        x1, y1, x2, y2 = edge_points(centre(n), PORTALS)
        out.append(f'<line x1="{x1:.1f}" y1="{y1:.1f}" x2="{x2:.1f}" y2="{y2:.1f}" stroke="{ORANGE}" stroke-width="4" stroke-opacity="0.75"/>')
    x1, y1, x2, y2 = edge_points(PORTALS, centre(16))
    out.append(f'<line x1="{x1:.1f}" y1="{y1:.1f}" x2="{x2:.1f}" y2="{y2:.1f}" stroke="{ORANGE}" stroke-width="4" stroke-opacity="0.75"/>')
    out.append(arrowhead(x1, y1, x2, y2, ORANGE, 11))
    for a, b, ways in STAIRS:
        x1, y1, x2, y2 = edge_points(centre(a), centre(b))
        out.append(f'<line x1="{x1:.1f}" y1="{y1:.1f}" x2="{x2:.1f}" y2="{y2:.1f}" stroke="{INK2}" stroke-width="1.6"/>')
        out.append(arrowhead(x1, y1, x2, y2, INK2))
        if ways == 2:
            out.append(arrowhead(x2, y2, x1, y1, INK2))
    for a, b in PITS:
        x1, y1, x2, y2 = edge_points(centre(a), centre(b), offset=9)
        out.append(f'<line x1="{x1:.1f}" y1="{y1:.1f}" x2="{x2:.1f}" y2="{y2:.1f}" stroke="{BLUE}" stroke-width="1.6" stroke-dasharray="4 3"/>')
        out.append(arrowhead(x1, y1, x2, y2, BLUE))
    px, py = PORTALS
    out.append(f'<rect x="{px-44}" y="{py-15}" width="88" height="30" rx="15" fill="{SURF}" stroke="{ORANGE}" stroke-width="2"/>')
    out.append(text(px, py, 'Portals', 12, ORANGE, True, 'middle'))
    for n, (x, y, s) in LEVELS.items():
        out.append(f'<rect x="{x-bw/2}" y="{y-bh/2}" width="{bw}" height="{bh}" rx="8" fill="{SETS[s]}" stroke="{INK2}" stroke-width="1.2"/>')
        out.append(text(x, y - 7, f'Level {n}', 13, INK, True, 'middle'))
        out.append(text(x, y + 9, s, 11, INK2, anchor='middle'))
    # legend
    ly = H - 30
    out.append(f'<line x1="20" y1="{ly}" x2="48" y2="{ly}" stroke="{INK2}" stroke-width="1.6"/>')
    out.append(text(54, ly, 'Stairs, entrances, scenes', 12))
    out.append(f'<line x1="240" y1="{ly}" x2="268" y2="{ly}" stroke="{BLUE}" stroke-width="1.6" stroke-dasharray="4 3"/>')
    out.append(text(274, ly, 'Pits', 12))
    out.append(f'<line x1="330" y1="{ly}" x2="358" y2="{ly}" stroke="{ORANGE}" stroke-width="4" stroke-opacity="0.75"/>')
    out.append(text(364, ly, 'Portals (portal keys)', 12))
    write('world-levels.svg', out)


# ------------------------------------------------------------- coordinates
def coordinates():
    W, H = 700, 330
    desc = ('Left: the top-left corner of a level grid. Columns are counted from 00 eastward and rows from 00 '
            'southward, so [00:00] is the north-west corner; the block [01:02] has index 2 × 32 + 1 = 65. North is '
            'the row above (index − 32), east the next column (index + 1). Right: one block. Its four faces are '
            'numbered by direction, 0 north, 1 east, 2 south, 3 west; the face between two blocks is stored in '
            'each of them. Its floor has four item positions, 0 and 1 on the north side, 2 and 3 on the south '
            'side, west first.')
    out = frame(W, H, 'Blocks, directions and positions', desc)
    out.append(text(20, 26, 'Blocks, directions and positions', 14, weight=True))
    out.append(text(20, 46, 'A level is a grid of 32 × 32 blocks, written [column:row].', 12, INK2))
    gx, gy, c = 70, 100, 44
    for col in range(5):
        out.append(text(gx + col * c + c / 2, gy - 14, f'{col:02d}', 11, INK2, anchor='middle'))
    for row in range(4):
        out.append(text(gx - 16, gy + row * c + c / 2, f'{row:02d}', 11, INK2, anchor='middle'))
    for row in range(4):
        for col in range(5):
            hi = (col, row) == (1, 2)
            out.append(f'<rect x="{gx+col*c}" y="{gy+row*c}" width="{c}" height="{c}" '
                       f'fill="{BLUE if hi else SHADE}" stroke="{BORDER}"/>')
            if hi:
                out.append(text(gx + col * c + c / 2, gy + row * c + c / 2, '65', 12, '#ffffff', True, 'middle'))
    out.append(text(gx, gy + 4 * c + 22, '[01:02] = 2 × 32 + 1 = index 65', 12, INK))
    out.append(text(gx, gy + 4 * c + 42, '[00:00] is the north-west corner', 12, INK2))
    # compass
    cx, cy = gx + 5 * c + 40, gy + 30
    out.append(f'<line x1="{cx}" y1="{cy+18}" x2="{cx}" y2="{cy-18}" stroke="{INK2}" stroke-width="2"/>')
    out.append(f'<path d="M{cx-5},{cy-12} L{cx},{cy-22} L{cx+5},{cy-12} Z" fill="{INK2}"/>')
    out.append(text(cx, cy - 32, 'N (0)', 11, INK2, True, 'middle'))
    out.append(text(cx + 30, cy, 'E (1)', 11, INK2, anchor='middle'))
    out.append(text(cx, cy + 32, 'S (2)', 11, INK2, anchor='middle'))
    out.append(text(cx - 30, cy, 'W (3)', 11, INK2, anchor='middle'))
    # one block
    bx, by, s = 430, 90, 170
    out.append(f'<rect x="{bx}" y="{by}" width="{s}" height="{s}" fill="{SURF}" stroke="{INK2}" stroke-width="1"/>')
    for k, (x1, y1, x2, y2, lx, ly, lab) in enumerate([
        (bx, by, bx + s, by, bx + s / 2, by - 12, 'face 0, north'),
        (bx + s, by, bx + s, by + s, bx + s + 12, by + s / 2, 'face 1, east'),
        (bx, by + s, bx + s, by + s, bx + s / 2, by + s + 14, 'face 2, south'),
        (bx, by, bx, by + s, bx - 12, by + s / 2, 'face 3, west')]):
        out.append(f'<line x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}" stroke="{ORANGE}" stroke-width="5"/>')
        anchor = 'middle' if k in (0, 2) else ('start' if k == 1 else 'end')
        out.append(text(lx, ly, lab, 11, ORANGE, True, anchor))
    m = 14
    for i, (qx, qy) in enumerate([(0, 0), (1, 0), (0, 1), (1, 1)]):
        x = bx + m + qx * (s / 2 - m / 2)
        y = by + m + qy * (s / 2 - m / 2)
        out.append(f'<rect x="{x:.1f}" y="{y:.1f}" width="{s/2-1.5*m:.1f}" height="{s/2-1.5*m:.1f}" rx="6" fill="{LIGHT}"/>')
        out.append(text(x + (s / 2 - 1.5 * m) / 2, y + (s / 2 - 1.5 * m) / 2, str(i), 15, BLUE, True, 'middle'))
    out.append(text(bx + s / 2, by + s + 36, 'Floor positions 0 to 3, where items lie', 12, INK, anchor='middle'))
    out.append(text(bx + s / 2, by + s + 54, 'A face between two blocks is stored in each', 12, INK2, anchor='middle'))
    write('world-coordinates.svg', out)


# ------------------------------------------------------------- doors
def doors():
    W, H = 700, 360
    group = list(range(3, 8))
    flags = [WALL_FLAGS[r] for r in group]
    desc = ('A door is a group of five wall references, from closed to open. In the executable\'s table, '
            'references 3 to 7 are: 3, the closed endpoint, which nothing passes; 4, 5 and 6, partly open, which '
            'nothing passes; 7, the open endpoint, which the party, small projectiles and monsters pass. Opening '
            'advances the reference one step per door update until the open endpoint, closing moves it back to '
            'the closed endpoint. References 3 to 7 and 8 to 12 use the level\'s first door graphic, 13 to 17 and '
            '18 to 22 its second; the other three groups have the same properties.')
    out = frame(W, H, 'A door is five wall references', desc)
    out.append(text(20, 26, 'A door is five wall references', 14, weight=True))
    out.append(text(20, 46, 'Each door update moves both faces of the door\'s block one reference along.', 12, INK2))
    x0, y0, cw, ch, gap = 25, 90, 122, 120, 10
    rows = [('Party', PASSAGE), ('Small projectiles', SMALL), ('Monsters', MONSTER)]
    for i, (ref, f) in enumerate(zip(group, flags)):
        x = x0 + i * (cw + gap)
        endpoint = 'closed endpoint' if f & CLOSED_END else ('open endpoint' if f & OPEN_END else 'partly open')
        out.append(f'<rect x="{x}" y="{y0}" width="{cw}" height="{ch}" rx="8" fill="{LIGHT if f & OPEN_END else SHADE}" stroke="{BLUE if f & (OPEN_END | CLOSED_END) else BORDER}" stroke-width="1.5"/>')
        out.append(text(x + cw / 2, y0 + 18, f'Reference {ref}', 12, INK, True, 'middle'))
        out.append(text(x + cw / 2, y0 + 36, endpoint, 11, INK2, anchor='middle'))
        # door leaf: shrinking bar
        open_frac = i / 4
        out.append(f'<rect x="{x+14}" y="{y0+50}" width="{cw-28}" height="12" fill="none" stroke="{INK2}"/>')
        out.append(f'<rect x="{x+14}" y="{y0+50}" width="{(cw-28)*(1-open_frac):.1f}" height="12" fill="{INK2}"/>')
        for k, (label, bit) in enumerate(rows):
            yy = y0 + 76 + k * 15
            ok = bool(f & bit)
            out.append(text(x + 14, yy, ('✓ ' if ok else '✗ ') + label, 11, GREEN if ok else RED))
    ay = y0 + ch + 28
    out.append(f'<line x1="{x0}" y1="{ay}" x2="{x0 + 5*cw + 4*gap}" y2="{ay}" stroke="{BLUE}" stroke-width="2"/>')
    out.append(arrowhead(x0, ay, x0 + 5 * cw + 4 * gap, ay, BLUE, 10))
    out.append(text(x0 + (5 * cw + 4 * gap) / 2, ay - 12, 'opening: one step per door update', 12, BLUE, True, 'middle'))
    ay2 = ay + 36
    out.append(f'<line x1="{x0 + 5*cw + 4*gap}" y1="{ay2}" x2="{x0}" y2="{ay2}" stroke="{ORANGE}" stroke-width="2"/>')
    out.append(arrowhead(x0 + 5 * cw + 4 * gap, ay2, x0, ay2, ORANGE, 10))
    out.append(text(x0 + (5 * cw + 4 * gap) / 2, ay2 + 14, 'closing', 12, ORANGE, True, 'middle'))
    out.append(text(20, H - 22, 'References 3–7 and 8–12 use the first door graphic, 13–17 and 18–22 the second.', 12, INK2))
    write('world-doors.svg', out)


# ------------------------------------------------------------- forcing a door
def forcing():
    W, H = 700, 300
    x0, x1, y0, y1 = 60, 680, 80, 240
    n = len(FORCE)
    bw = (x1 - x0) / n
    Y = lambda v: y1 - (y1 - y0) * v / 20
    desc = ('The chance to force a stuck door by the best strength in the party, from 0 to 18 and more: 1d20 must '
            'be at most ' + ', '.join(str(v) for v in FORCE) + ', that is from 5 % at strength 0 or 1 to 60 % at 18 '
            'and more.')
    out = frame(W, H, 'Chance to force a stuck door', desc)
    out.append(text(20, 26, 'Chance to force a stuck door', 14, weight=True))
    out.append(text(20, 46, 'By the highest strength among the characters who can try; 1d20 must be at most the bar.', 12, INK2))
    for v in (0, 5, 10, 15, 20):
        out.append(f'<line x1="{x0}" y1="{Y(v):.1f}" x2="{x1}" y2="{Y(v):.1f}" stroke="{GRID}"/>')
        out.append(text(x0 - 8, Y(v), f'{v * 5} %', 10, INK2, anchor='end'))
    for i, v in enumerate(FORCE):
        x = x0 + i * bw
        out.append(f'<rect x="{x+3:.1f}" y="{Y(v):.1f}" width="{bw-6:.1f}" height="{y1-Y(v):.1f}" rx="2" fill="{BLUE}"/>')
        out.append(text(x + bw / 2, Y(v) - 9, str(v), 10, INK2, anchor='middle'))
        out.append(text(x + bw / 2, y1 + 14, str(i) if i < 18 else '18+', 10, INK2, anchor='middle'))
    out.append(text((x0 + x1) / 2, y1 + 34, 'Strength', 11, INK2, anchor='middle'))
    write('world-force-chance.svg', out)


# ------------------------------------------------------------- sublevels
def sublevels():
    W, H = 700, 280
    cols = [
        ('Carried over', 'the level record', ['Walls', 'The 30 monster slots', 'Temporary walls'], BLUE),
        ('From the new record', 'sublevel record of the INF file', ['Resources and doors', 'Monster images and types',
                                                                   'Wall mappings, decorations', 'Step limit and timers'], ORANGE),
        ('Read again', 'shared by both records', ['Scripts', 'Cell bindings'], MUTED),
    ]
    desc = ('What a change of sublevel keeps and what it takes from the new record. Carried over through the '
            'level record: the walls, the 30 monster slots and the temporary walls. From the new sublevel record: '
            'resources and doors, monster images and types, wall mappings and decorations, the step limit and the '
            'timers. Read again and shared by both records: the scripts and the cell bindings.')
    out = frame(W, H, 'What a change of sublevel keeps', desc)
    out.append(text(20, 26, 'What a change of sublevel keeps', 14, weight=True))
    out.append(text(20, 46, 'Changing sublevel is a level change to the same level number.', 12, INK2))
    cw, gap, x0, y0 = 210, 15, 20, 70
    for i, (title, sub, items, colour) in enumerate(cols):
        x = x0 + i * (cw + gap)
        out.append(f'<rect x="{x}" y="{y0}" width="{cw}" height="{H-y0-20}" rx="10" fill="{SHADE}" stroke="{colour}" stroke-width="1.5"/>')
        out.append(text(x + 14, y0 + 20, title, 13, colour, True))
        out.append(text(x + 14, y0 + 38, sub, 11, INK2))
        for k, item in enumerate(items):
            yy = y0 + 56 + k * 34
            out.append(f'<rect x="{x+12}" y="{yy}" width="{cw-24}" height="26" rx="6" fill="{SURF}" stroke="{BORDER}"/>')
            out.append(text(x + 24, yy + 13, item, 12))
    write('world-sublevels.svg', out)


# ------------------------------------------------------------- decision chains
def flows():
    """The decision chains of the world pages; they transcribe the text of those pages."""
    sys.path[:0] = [str(Path(__file__).resolve().parent), str(ROOT / 'scripts/common')]
    import flowcharts
    flowcharts.chain(
        OUT / 'world-level-change.svg', 'Changing level',
        'The old level is stored before the new one is read.',
        'The steps of a level change. A script asks for another level; the game settles the current level, '
        "with flying objects landing and doors finishing their move, writes its record to LEVELS.TMP, then "
        "loads the new level's INF file and sublevel. If a record exists for the new level, its walls, "
        'monsters and temporary walls come from it; otherwise the walls come from the map and the monsters '
        'from the INF file. In both cases the party is then placed.',
        [('step', 'A script asks for another level'),
         ('step', 'Settle the level: objects land,\ndoors finish'),
         ('step', 'Write its record to LEVELS.TMP'),
         ('step', "Load the new level's INF file\nand sublevel"),
         ('ask', 'Is there a record for this level?', 'yes', 'Walls, monsters and temporary\nwalls from it', 'no'),
         ('step', 'Walls from the map, monsters\nfrom the INF file'),
         ('step', 'In both cases: place the party')])
    flowcharts.chain(
        OUT / 'world-step.svg', 'One step of the party',
        'A step either moves the party one block or is refused with a message.',
        'What happens when the party steps in a direction. The game looks at the block ahead in that '
        'direction. If its face toward the party is a temporary wall, the wall is removed. Then, if that face '
        "lets the party pass and no monster is in the block, the party moves: monsters may notice it, the "
        "leave and enter events run and the step counter goes up by one. Otherwise the game prints \"Can't go "
        'that way" and plays sound 29.',
        [('step', 'Step in a direction: the block ahead'),
         ('ask', 'Is its face toward the party\na temporary wall?', 'yes', 'The temporary wall is removed',
          'in both cases'),
         ('ask', 'Does the face let the party pass,\nwith no monster in the block?', 'no',
          '"Can\'t go that way", sound 29', 'yes'),
         ('step', 'Move the party: monsters may notice it,\nleave and enter events, one more step')])


if __name__ == '__main__':
    assert FORCE == [1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10, 11, 12], FORCE
    assert WALL_FLAGS[3:8] == [0xa8, 0x88, 0x88, 0x88, 0x9f], [hex(v) for v in WALL_FLAGS[3:8]]
    assert WALL_FLAGS[3:8] == WALL_FLAGS[8:13] == WALL_FLAGS[13:18] == WALL_FLAGS[18:23]
    levels()
    coordinates()
    doors()
    forcing()
    sublevels()
    flows()
