mwg API
    Preparing search index...

    Class Blob

    A spreading volume field over a grid: a number per cell that creeps into its open neighbours and thins out over time. Fire, gas, caustic ooze, flood water - anything with a volume per cell.

    Deliberately dumber than a simulation: mwg holds the volumes and diffuses them, and the game decides what a volume means (reading cellsAbove each turn to burn, poison or corrode whoever stands there, or to drown whoever wades in). Per-creature timers (applyStatusEffect) already cover "this victim burns for 3 turns"; this covers the other half, "this place burns until it burns out".

    Renderer-free and module-free, so a game can lay volumes over any grid without pulling in a terrain or combat module.

    import { Blob } from '@datamoc/mwg/core';

    const fire = new Blob(20, 20);
    fire.seed(5, 5, 10); // a fireball lands

    // one turn of spreading; it hands back whatever it just burned out, so the ground under
    // the fire can turn to embers at the moment the flames leave it
    const burntOut = fire.spread((x, y) => x >= 0 && y >= 0 && x < 20 && y < 20, 0.25, 0.9);
    for (const cell of burntOut) console.log('burned out at', cell.x, cell.y);

    for (const cell of fire.cellsAbove(0.5)) console.log('burning at', cell.x, cell.y);

    fire.clear(5, 5); // someone douses that one tile
    Index
    height: number
    width: number
    • every cell holding at least minimum - the cells a game applies its effect on

      Parameters

      • minimum: number

      Returns { volume: number; x: number; y: number }[]

    • zeroes whatever sits on (x, y), leaving its neighbours alone; off-map is a no-op

      Parameters

      • x: number
      • y: number

      Returns void

    • adds amount to whatever is already on (x, y); off-map is a no-op

      Parameters

      • x: number
      • y: number
      • amount: number

      Returns void

    • One diffusion step: every cell shares spread of its volume equally among its open 4-neighbours (a cell with no open neighbour keeps it all), then every cell keeps only decay of what it ends up with. decay: 1 conserves volume and only moves it around; anything lower thins the effect out over time. open(x, y) decides whether the effect may cross into a cell, so the caller chooses what blocks it.

      Returns the cells this step emptied, in reading order: those holding a volume before the step and none after it. That is the moment a game turns the grass under a fire to embers, and reporting it here saves the game diffing cellsAbove between two steps to notice.

      Parameters

      • open: (x: number, y: number) => boolean
      • spread: number = 0.25
      • decay: number = 0.9

      Returns { x: number; y: number }[]

    • Returns { height: number; volume: number[]; width: number }

    • the total volume across the whole map - useful for "has it burned out yet"

      Returns number

    • how much effect sits on (x, y) right now; 0 off-map

      Parameters

      • x: number
      • y: number

      Returns number

    • Parameters

      • data: { height: number; volume: number[]; width: number }

      Returns Blob