mwg API
    Preparing search index...

    Class FactionFog

    Unions the visible cells of several units for each faction and retains explored memory. The caller supplies visibility because board games differ in terrain, range, and blockers.

    Factions that share see through one another's eyes - one map for the group, what is lit now and what they remember having seen, which is what Wesnoth's share_vision means. Nothing shares until asked, and sharing is a property of the sides rather than of any unit, so it survives every sync.

    import { FactionFog } from '@datamoc/mw_games/board';

    const fog = new FactionFog(10, 10);

    const sources = [{ x: 2, y: 2 }];
    fog.sync('blue', sources, (source) => [
    source,
    { x: source.x + 1, y: source.y },
    ]);

    console.log(fog.isVisible('blue', 3, 2)); // true - lit by the scout right now
    console.log(fog.isVisible('blue', 5, 5)); // false - never seen

    fog.share(['blue', 'green']); // the two now see one map
    console.log(fog.isVisible('green', 3, 2)); // true - blue's scout is watching for both

    fog.sync('blue', [], () => []); // the scout moved away, nothing visible this turn
    console.log(fog.isVisible('green', 3, 2)); // false - no longer in sight, for either of them
    console.log(fog.isExplored('green', 3, 2)); // true - stays remembered, for both
    Index
    height: number
    width: number
    • Parameters

      • faction: string

      Returns readonly number[]

    • Parameters

      • faction: string
      • x: number
      • y: number

      Returns boolean

    • Parameters

      • faction: string
      • x: number
      • y: number

      Returns boolean

    • Mark cells explored without changing what is currently visible: the shroud-clearing half of sync, for effects (a revealed map, a scouted region) that lift the shroud where no unit stands watch.

      Parameters

      Returns void

    • One faction's sight as a predicate, ready to hand to anything that asks what a side can see - ai's score views, for one. It reads the shroud as it is when called, not as it was when the predicate was made, so a caller holding one across a sync sees the update, and it follows whatever share the faction later joins.

      Parameters

      • faction: string

      Returns (x: number, y: number) => boolean

    • Makes these factions see with one pair of eyes: each one's cells count as the others', both for what is visible now and for the shroud they remember.

      Calling it again widens the group rather than replacing it, so share(['blue', 'green']) after share(['green', 'teal']) leaves all three on one map. A side may also be told to share with itself, or with nobody at all, without harm.

      Parameters

      • factions: readonly string[]

      Returns void

    • Parameters

      • faction: string

      Returns readonly number[]