mwg API
    Preparing search index...

    Interface CavePassage

    Caves: chambers grown as blobs, joined by winding passages.

    The counterpart to generateDungeon's rooms-and-corridors: where a dungeon reads as built architecture, a cave reads as carved rock. Chambers grow from a centre by absorbing frontier cells until they hold size cells (jagged is the chance a step picks any frontier cell instead of the one nearest the centre, so 0 gives a round room and 100 a splatter); passages are biased random walks between chamber centres (windiness the chance of a random step instead of the one closing in on the target, width how many cells wide); chance rolls whether a passage exists at all. Every chamber centre and every mustBeClear coordinate is force-joined to the first chamber, so a generated cave is always fully connected whatever the rolls did.

    Seeded through the framework Random stack: the same seed produces the same cave on every machine, the same contract generateDungeon already carries. A game that owns its stream (a SimulationRuntime's, say) passes it as random instead and the cave draws from that, advancing it, with no seed involved.

    shape: 'hex' carves the same cave on a hex grid (odd-q offset coordinates, the Level convention): six neighbours instead of four, chambers growing and passages closing in by hex distance, so a chamber is round on screen rather than a skewed diamond. The result's level carries the shape, so Pathfinder and FieldOfView walk it as hexes.

    import { generateCave } from '@datamoc/mwg/roguelike';

    const cave = generateCave({
    width: 40,
    height: 25,
    seed: 7,
    chambers: [
    { id: 'entrance', xRange: [2, 8], yRange: [2, 8], size: 12, passages: [] },
    { id: 'depths', xRange: [30, 37], yRange: [17, 22], size: 20, jagged: 60, passages: [] },
    ],
    });
    console.log(cave.chambers[0].cells.length); // 12
    interface CavePassage {
        chance?: number;
        to: string;
        width?: number;
        windiness?: number;
    }
    Index
    chance?: number

    0-100, the chance the passage is walked at all; defaults to 100

    to: string

    the chamber id this passage runs to

    width?: number

    cells wide; defaults to 1

    windiness?: number

    0-100, the chance a walk step wanders instead of closing in; defaults to 0