{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.shardsofstone.com/schemas/v1/trigger-script.json",
  "$comment": "GENERATED by tools/generate_modding_reference.ts. Do not edit by hand.",
  "title": "TriggerScript",
  "description": "A Shards of Stone trigger script: global variables, regions, functions, hashtables and triggers. Every node is discriminated on `k`.",
  "type": "object",
  "required": [
    "version",
    "vars",
    "regions",
    "triggers"
  ],
  "properties": {
    "version": {
      "type": "integer",
      "minimum": 1,
      "maximum": 1,
      "description": "Always 1."
    },
    "vars": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/VarDecl"
      },
      "description": "Global variables, initialised in order on map init."
    },
    "regions": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/RegionDef"
      },
      "description": "Named tile rectangles (RegionDef[])."
    },
    "triggers": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/TriggerDef"
      },
      "description": "Triggers (TriggerDef[]), evaluated in array order."
    },
    "saveCodeSalt": {
      "type": "string",
      "description": "Binds save codes to this map; defaults to the map name."
    },
    "functions": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/FunctionDef"
      },
      "description": "User-defined functions (FunctionDef[])."
    },
    "hashtables": {
      "type": "array",
      "maxItems": 64,
      "items": {
        "$ref": "#/definitions/HashtableDecl"
      },
      "description": "Declared hashtables (HashtableDecl[])."
    },
    "chain": {
      "$ref": "#/definitions/ZoneChainSpec",
      "description": "Zone chain: the maps this one can travel to, and the state that travels with the player."
    }
  },
  "additionalProperties": false,
  "definitions": {
    "Action": {
      "description": "An action, discriminated on `k`.",
      "oneOf": [
        {
          "$ref": "#/definitions/Action.if"
        },
        {
          "$ref": "#/definitions/Action.while"
        },
        {
          "$ref": "#/definitions/Action.forEachUnit"
        },
        {
          "$ref": "#/definitions/Action.forEachInt"
        },
        {
          "$ref": "#/definitions/Action.wait"
        },
        {
          "$ref": "#/definitions/Action.setVar"
        },
        {
          "$ref": "#/definitions/Action.addVar"
        },
        {
          "$ref": "#/definitions/Action.setEventDamage"
        },
        {
          "$ref": "#/definitions/Action.raiseEvent"
        },
        {
          "$ref": "#/definitions/Action.enableTrigger"
        },
        {
          "$ref": "#/definitions/Action.runTrigger"
        },
        {
          "$ref": "#/definitions/Action.stopTrigger"
        },
        {
          "$ref": "#/definitions/Action.comment"
        },
        {
          "$ref": "#/definitions/Action.cityZone"
        },
        {
          "$ref": "#/definitions/Action.cityPlaceService"
        },
        {
          "$ref": "#/definitions/Action.citySetTax"
        },
        {
          "$ref": "#/definitions/Action.cityDisaster"
        },
        {
          "$ref": "#/definitions/Action.setTerrain"
        },
        {
          "$ref": "#/definitions/Action.overlayDefine"
        },
        {
          "$ref": "#/definitions/Action.overlayFill"
        },
        {
          "$ref": "#/definitions/Action.overlayClear"
        },
        {
          "$ref": "#/definitions/Action.callFunction"
        },
        {
          "$ref": "#/definitions/Action.return"
        },
        {
          "$ref": "#/definitions/Action.hashtableSet"
        },
        {
          "$ref": "#/definitions/Action.hashtableRemove"
        },
        {
          "$ref": "#/definitions/Action.hashtableClear"
        },
        {
          "$ref": "#/definitions/Action.createUnits"
        },
        {
          "$ref": "#/definitions/Action.removeUnit"
        },
        {
          "$ref": "#/definitions/Action.killUnit"
        },
        {
          "$ref": "#/definitions/Action.setUnitHp"
        },
        {
          "$ref": "#/definitions/Action.setUnitMana"
        },
        {
          "$ref": "#/definitions/Action.setUnitOwner"
        },
        {
          "$ref": "#/definitions/Action.setUnitInvulnerable"
        },
        {
          "$ref": "#/definitions/Action.setUnitProp"
        },
        {
          "$ref": "#/definitions/Action.heroAddXp"
        },
        {
          "$ref": "#/definitions/Action.heroSetLevel"
        },
        {
          "$ref": "#/definitions/Action.heroRevive"
        },
        {
          "$ref": "#/definitions/Action.itemCreate"
        },
        {
          "$ref": "#/definitions/Action.itemGive"
        },
        {
          "$ref": "#/definitions/Action.itemRemove"
        },
        {
          "$ref": "#/definitions/Action.faceUnit"
        },
        {
          "$ref": "#/definitions/Action.moveUnit"
        },
        {
          "$ref": "#/definitions/Action.addUnitToGroup"
        },
        {
          "$ref": "#/definitions/Action.removeUnitFromGroup"
        },
        {
          "$ref": "#/definitions/Action.clearGroup"
        },
        {
          "$ref": "#/definitions/Action.playAnimation"
        },
        {
          "$ref": "#/definitions/Action.boardTransport"
        },
        {
          "$ref": "#/definitions/Action.order"
        },
        {
          "$ref": "#/definitions/Action.setResource"
        },
        {
          "$ref": "#/definitions/Action.addResource"
        },
        {
          "$ref": "#/definitions/Action.setAlliance"
        },
        {
          "$ref": "#/definitions/Action.setBuildableRegion"
        },
        {
          "$ref": "#/definitions/Action.setTechAllowed"
        },
        {
          "$ref": "#/definitions/Action.setPopCap"
        },
        {
          "$ref": "#/definitions/Action.revealArea"
        },
        {
          "$ref": "#/definitions/Action.victory"
        },
        {
          "$ref": "#/definitions/Action.defeat"
        },
        {
          "$ref": "#/definitions/Action.startTimer"
        },
        {
          "$ref": "#/definitions/Action.pauseTimer"
        },
        {
          "$ref": "#/definitions/Action.resumeTimer"
        },
        {
          "$ref": "#/definitions/Action.stopTimer"
        },
        {
          "$ref": "#/definitions/Action.showText"
        },
        {
          "$ref": "#/definitions/Action.clearText"
        },
        {
          "$ref": "#/definitions/Action.setCounter"
        },
        {
          "$ref": "#/definitions/Action.removeCounter"
        },
        {
          "$ref": "#/definitions/Action.setLeaderboardTitle"
        },
        {
          "$ref": "#/definitions/Action.setLeaderboardRow"
        },
        {
          "$ref": "#/definitions/Action.removeLeaderboardRow"
        },
        {
          "$ref": "#/definitions/Action.clearLeaderboard"
        },
        {
          "$ref": "#/definitions/Action.showDialog"
        },
        {
          "$ref": "#/definitions/Action.hideDialog"
        },
        {
          "$ref": "#/definitions/Action.ping"
        },
        {
          "$ref": "#/definitions/Action.playSound"
        },
        {
          "$ref": "#/definitions/Action.playCutscene"
        },
        {
          "$ref": "#/definitions/Action.stopCutscene"
        },
        {
          "$ref": "#/definitions/Action.fadeScreen"
        },
        {
          "$ref": "#/definitions/Action.cameraPan"
        },
        {
          "$ref": "#/definitions/Action.cameraSetZoom"
        },
        {
          "$ref": "#/definitions/Action.cameraLock"
        },
        {
          "$ref": "#/definitions/Action.cameraUnlock"
        },
        {
          "$ref": "#/definitions/Action.cameraSetBounds"
        },
        {
          "$ref": "#/definitions/Action.cameraShake"
        },
        {
          "$ref": "#/definitions/Action.cameraReset"
        },
        {
          "$ref": "#/definitions/Action.hitStop"
        },
        {
          "$ref": "#/definitions/Action.applyImpulse"
        },
        {
          "$ref": "#/definitions/Action.knockback"
        },
        {
          "$ref": "#/definitions/Action.setUnitKinematics"
        },
        {
          "$ref": "#/definitions/Action.generateSaveCode"
        },
        {
          "$ref": "#/definitions/Action.createUIFrame"
        },
        {
          "$ref": "#/definitions/Action.updateUIFrame"
        },
        {
          "$ref": "#/definitions/Action.destroyUIFrame"
        },
        {
          "$ref": "#/definitions/Action.clearUIFrames"
        },
        {
          "$ref": "#/definitions/Action.setQuest"
        },
        {
          "$ref": "#/definitions/Action.clearQuests"
        },
        {
          "$ref": "#/definitions/Action.setTimeOfDay"
        },
        {
          "$ref": "#/definitions/Action.addBuff"
        },
        {
          "$ref": "#/definitions/Action.removeBuff"
        },
        {
          "$ref": "#/definitions/Action.addAbility"
        },
        {
          "$ref": "#/definitions/Action.removeAbility"
        },
        {
          "$ref": "#/definitions/Action.playSoundAt"
        },
        {
          "$ref": "#/definitions/Action.playMusic"
        },
        {
          "$ref": "#/definitions/Action.stopMusic"
        },
        {
          "$ref": "#/definitions/Action.floatingText"
        },
        {
          "$ref": "#/definitions/Action.playEffect"
        },
        {
          "$ref": "#/definitions/Action.multiboardSet"
        },
        {
          "$ref": "#/definitions/Action.multiboardCell"
        },
        {
          "$ref": "#/definitions/Action.multiboardRemove"
        },
        {
          "$ref": "#/definitions/Action.timerWindowShow"
        },
        {
          "$ref": "#/definitions/Action.timerWindowHide"
        },
        {
          "$ref": "#/definitions/Action.setObjective"
        },
        {
          "$ref": "#/definitions/Action.travelToZone"
        }
      ]
    },
    "Action.addAbility": {
      "title": "Add ability",
      "description": "Give a unit a spell it can cast. A unit with no caster slot gets one. Granting a spell it already has does nothing, so this is safe to call every tick. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "spellId"
      ],
      "properties": {
        "k": {
          "const": "addAbility"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "spellId": {
          "type": "string",
          "description": "Spell id to grant."
        }
      },
      "additionalProperties": false
    },
    "Action.addBuff": {
      "title": "Add buff",
      "description": "Put a stat buff on a unit. The same buff id REFRESHES rather than stacks: duration, source and stat are overwritten, and the modifier is overwritten only when the new one is at least as strong — the engine's own rule, not a second one. A duration of -1 is permanent. NOTE: trigger buffs are hashed and lockstep-safe but are NOT saved — like every spell-applied buff, they are dropped by save/load. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "buffId",
        "stat",
        "modifier",
        "durationTicks"
      ],
      "properties": {
        "k": {
          "const": "addBuff"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "buffId": {
          "type": "string",
          "description": "Your id for this buff. Re-using it refreshes the existing one; `remove buff` and `unit has buff` take the same id."
        },
        "stat": {
          "type": "string",
          "enum": [
            "damage",
            "damagePct",
            "siegeDamage",
            "armor",
            "attackSpeed",
            "lifesteal",
            "damageMirror",
            "thorns",
            "critChance",
            "dodgeChance",
            "blockChance",
            "blockValue",
            "parryChance",
            "hitBonus",
            "blind",
            "speed",
            "speedPct",
            "maxHpPct",
            "hpRegen",
            "manaRegen",
            "poison",
            "spellPower",
            "sightRadius",
            "productionSpeed",
            "gatherRatePct"
          ],
          "description": "What it modifies. Only these are read by the engine — any other name would be stored and ignored."
        },
        "modifier": {
          "$ref": "#/definitions/Expr",
          "description": "How much to add. Negative debuffs. A non-finite value makes the action do nothing."
        },
        "durationTicks": {
          "$ref": "#/definitions/Expr",
          "description": "How long, in ticks (20 = 1 second). -1 is permanent; 0 or less otherwise does nothing."
        }
      },
      "additionalProperties": false
    },
    "Action.addResource": {
      "title": "Add resource",
      "description": "Add to a player's resource stock (rounded, ≥ 0).",
      "type": "object",
      "required": [
        "k",
        "player",
        "resource",
        "delta"
      ],
      "properties": {
        "k": {
          "const": "addResource"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "resource": {
          "type": "string",
          "enum": [
            "gold",
            "lumber",
            "stone",
            "oil"
          ],
          "description": "Resource kind."
        },
        "delta": {
          "$ref": "#/definitions/Expr",
          "description": "Amount to add (negative subtracts)."
        }
      },
      "additionalProperties": false
    },
    "Action.addUnitToGroup": {
      "title": "Add unit to group",
      "description": "Add a unit to a unitGroup variable.",
      "type": "object",
      "required": [
        "k",
        "varName",
        "unit"
      ],
      "properties": {
        "k": {
          "const": "addUnitToGroup"
        },
        "varName": {
          "type": "string",
          "minLength": 1,
          "description": "An already-declared unitGroup variable; this does not create one."
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        }
      },
      "additionalProperties": false
    },
    "Action.addVar": {
      "title": "Add to variable",
      "description": "Add a number to a numeric variable.",
      "type": "object",
      "required": [
        "k",
        "name",
        "delta"
      ],
      "properties": {
        "k": {
          "const": "addVar"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Variable name. The variable must already exist — this does NOT declare one."
        },
        "index": {
          "$ref": "#/definitions/Expr",
          "description": "Element index for an array."
        },
        "delta": {
          "$ref": "#/definitions/Expr",
          "description": "Amount to add."
        }
      },
      "additionalProperties": false
    },
    "Action.applyImpulse": {
      "title": "Apply impulse",
      "description": "Give a unit a kinematic velocity.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "vx",
        "vy"
      ],
      "properties": {
        "k": {
          "const": "applyImpulse"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "vx": {
          "$ref": "#/definitions/Expr",
          "description": "Velocity X (tiles/tick)."
        },
        "vy": {
          "$ref": "#/definitions/Expr",
          "description": "Velocity Y (tiles/tick)."
        },
        "friction": {
          "$ref": "#/definitions/Expr",
          "description": "Per-tick velocity multiplier."
        },
        "bounce": {
          "$ref": "#/definitions/Expr",
          "description": "Restitution on collision."
        },
        "ticks": {
          "$ref": "#/definitions/Expr",
          "description": "Maximum duration in ticks."
        }
      },
      "additionalProperties": false
    },
    "Action.boardTransport": {
      "title": "Board transport",
      "description": "Issue ordinary boarding inside the tick. The unit walks into reach before the transport system boards it; owner, capacity and terrain rules still apply. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "units",
        "transport"
      ],
      "properties": {
        "k": {
          "const": "boardTransport"
        },
        "units": {
          "$ref": "#/definitions/Expr",
          "description": "Original units to board."
        },
        "transport": {
          "$ref": "#/definitions/Expr",
          "description": "Original transport."
        }
      },
      "additionalProperties": false
    },
    "Action.callFunction": {
      "title": "Call function",
      "description": "Call a user-defined function as a statement, optionally storing its return value.",
      "type": "object",
      "required": [
        "k",
        "fn"
      ],
      "properties": {
        "k": {
          "const": "callFunction"
        },
        "fn": {
          "type": "string",
          "minLength": 1,
          "description": "Function name."
        },
        "args": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Expr"
          },
          "description": "Arguments, one per parameter, in order."
        },
        "intoVar": {
          "type": "string",
          "minLength": 1,
          "description": "Variable receiving the return value (function must declare `returns`). It must ALREADY exist — declared in `vars`, or a local, parameter or loop variable in scope. Unlike a loop variable, this does NOT declare one, and an undeclared name is an error."
        },
        "intoIndex": {
          "$ref": "#/definitions/Expr",
          "description": "Element index when intoVar is an array."
        }
      },
      "additionalProperties": false
    },
    "Action.cameraLock": {
      "title": "Lock camera",
      "description": "Lock the camera to a unit or a point.",
      "type": "object",
      "required": [
        "k",
        "players"
      ],
      "properties": {
        "k": {
          "const": "cameraLock"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "Unit to follow."
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Point to hold."
        }
      },
      "additionalProperties": false
    },
    "Action.cameraPan": {
      "title": "Pan camera",
      "description": "Pan the camera to a point over a duration.",
      "type": "object",
      "required": [
        "k",
        "players",
        "to"
      ],
      "properties": {
        "k": {
          "const": "cameraPan"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "to": {
          "$ref": "#/definitions/Expr",
          "description": "Target tile."
        },
        "durationTicks": {
          "type": "integer",
          "minimum": 0,
          "description": "Pan duration in ticks."
        }
      },
      "additionalProperties": false
    },
    "Action.cameraReset": {
      "title": "Reset camera",
      "description": "Clear locks, bounds and zoom overrides.",
      "type": "object",
      "required": [
        "k",
        "players"
      ],
      "properties": {
        "k": {
          "const": "cameraReset"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.cameraSetBounds": {
      "title": "Camera bounds",
      "description": "Confine the camera to a region, or null to clear.",
      "type": "object",
      "required": [
        "k",
        "players",
        "region"
      ],
      "properties": {
        "k": {
          "const": "cameraSetBounds"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "region": {
          "type": [
            "string",
            "null"
          ],
          "description": "Region id, or null."
        }
      },
      "additionalProperties": false
    },
    "Action.cameraSetZoom": {
      "title": "Set camera zoom",
      "description": "Change the camera zoom.",
      "type": "object",
      "required": [
        "k",
        "players",
        "zoom"
      ],
      "properties": {
        "k": {
          "const": "cameraSetZoom"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "zoom": {
          "$ref": "#/definitions/Expr",
          "description": "Zoom factor."
        },
        "durationTicks": {
          "type": "integer",
          "minimum": 0,
          "description": "Transition in ticks."
        }
      },
      "additionalProperties": false
    },
    "Action.cameraShake": {
      "title": "Shake camera",
      "description": "Shake the camera.",
      "type": "object",
      "required": [
        "k",
        "players",
        "intensity"
      ],
      "properties": {
        "k": {
          "const": "cameraShake"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "intensity": {
          "$ref": "#/definitions/Expr",
          "description": "Shake intensity."
        },
        "durationTicks": {
          "type": "integer",
          "minimum": 0,
          "description": "Duration in ticks."
        }
      },
      "additionalProperties": false
    },
    "Action.cameraUnlock": {
      "title": "Unlock camera",
      "description": "Release a camera lock.",
      "type": "object",
      "required": [
        "k",
        "players"
      ],
      "properties": {
        "k": {
          "const": "cameraUnlock"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.cityDisaster": {
      "title": "City: raise a disaster",
      "description": "Set a built home, shop, works or farm alight (fire), or start a plague outbreak in a home (plague). The city's own rules then run: a fire watch puts the fire out, healers cure the plague, otherwise they spread. A lot that cannot take it (a plot, a service, already burning) is left alone. In a match without city rules (rules.city) it does nothing. Needs map format 6.",
      "type": "object",
      "required": [
        "k",
        "lot",
        "kind"
      ],
      "properties": {
        "k": {
          "const": "cityDisaster"
        },
        "lot": {
          "$ref": "#/definitions/Expr",
          "description": "The lot id (from a city event, or the script API)."
        },
        "kind": {
          "type": "string",
          "enum": [
            "fire",
            "plague"
          ],
          "description": "fire or plague."
        }
      },
      "additionalProperties": false
    },
    "Action.cityPlaceService": {
      "title": "City: place a service",
      "description": "Place a service for a seat with its top-left at a tile, as the HUD does: the ground must be free and touch the seat's road, and the seat pays its price (refused, and nothing happens, without the gold). In a match without city rules (rules.city) it does nothing. Needs map format 6.",
      "type": "object",
      "required": [
        "k",
        "player",
        "service",
        "at"
      ],
      "properties": {
        "k": {
          "const": "cityPlaceService"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "service": {
          "type": "string",
          "enum": [
            "water",
            "safety",
            "faith",
            "fire",
            "health",
            "learning",
            "entertainment",
            "market",
            "park",
            "academy"
          ],
          "description": "The service."
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Its top-left tile."
        }
      },
      "additionalProperties": false
    },
    "Action.citySetTax": {
      "title": "City: set tax",
      "description": "Set a seat's tax rate, percent, held to the map's ceiling (20 unless rules.city.tuning.taxes.maxPercent says otherwise). In a match without city rules (rules.city) it does nothing. Needs map format 6.",
      "type": "object",
      "required": [
        "k",
        "player",
        "percent"
      ],
      "properties": {
        "k": {
          "const": "citySetTax"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "percent": {
          "$ref": "#/definitions/Expr",
          "description": "Tax percent."
        }
      },
      "additionalProperties": false
    },
    "Action.cityZone": {
      "title": "City: fill a region with plots",
      "description": "Fill area for a seat, as the Fill area brush does: plots of mixed sizes (those its hall has opened, up to the density) along every road frontage in the region, for homes, shops, works or farmland; none clears plots nobody has built on. A map with rules.city.layout 'zones' paints the tiles instead, and only tiles within reach of the seat's roads take paint. In a match without city rules (rules.city) it does nothing. Needs map format 6.",
      "type": "object",
      "required": [
        "k",
        "player",
        "region",
        "zone"
      ],
      "properties": {
        "k": {
          "const": "cityZone"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "description": "The region to zone."
        },
        "zone": {
          "type": "string",
          "enum": [
            "residential",
            "commercial",
            "industrial",
            "farm",
            "none"
          ],
          "description": "The zone."
        },
        "density": {
          "type": "integer",
          "minimum": 1,
          "maximum": 3,
          "description": "Highest level a lot may reach, 1..3 (absent: 3)."
        }
      },
      "additionalProperties": false
    },
    "Action.clearGroup": {
      "title": "Clear group",
      "description": "Empty a unitGroup variable.",
      "type": "object",
      "required": [
        "k",
        "varName"
      ],
      "properties": {
        "k": {
          "const": "clearGroup"
        },
        "varName": {
          "type": "string",
          "minLength": 1,
          "description": "An already-declared unitGroup variable; this does not create one."
        }
      },
      "additionalProperties": false
    },
    "Action.clearLeaderboard": {
      "title": "Clear leaderboard",
      "description": "Remove every row and the title.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "clearLeaderboard"
        }
      },
      "additionalProperties": false
    },
    "Action.clearQuests": {
      "title": "Clear quests",
      "description": "Remove every quest.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "clearQuests"
        }
      },
      "additionalProperties": false
    },
    "Action.clearText": {
      "title": "Clear text",
      "description": "Clear banners for these seats (null = all).",
      "type": "object",
      "required": [
        "k",
        "players"
      ],
      "properties": {
        "k": {
          "const": "clearText"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.clearUIFrames": {
      "title": "Clear UI frames",
      "description": "Remove every frame.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "clearUIFrames"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null`/absent for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.comment": {
      "title": "Comment",
      "description": "Does nothing; documents the script.",
      "type": "object",
      "required": [
        "k",
        "text"
      ],
      "properties": {
        "k": {
          "const": "comment"
        },
        "text": {
          "type": "string",
          "description": "Comment text."
        }
      },
      "additionalProperties": false
    },
    "Action.createUIFrame": {
      "title": "Create UI frame",
      "description": "Create or replace a declarative HUD frame.",
      "type": "object",
      "required": [
        "k",
        "frameId",
        "anchor",
        "x",
        "y",
        "width",
        "height"
      ],
      "properties": {
        "k": {
          "const": "createUIFrame"
        },
        "frameId": {
          "type": "string",
          "minLength": 1,
          "description": "Frame id."
        },
        "anchor": {
          "type": "string",
          "enum": [
            "top_left",
            "top_center",
            "top_right",
            "center_left",
            "center",
            "center_right",
            "bottom_left",
            "bottom_center",
            "bottom_right"
          ],
          "description": "Screen anchor."
        },
        "x": {
          "$ref": "#/definitions/Expr",
          "description": "X offset from the anchor (px)."
        },
        "y": {
          "$ref": "#/definitions/Expr",
          "description": "Y offset from the anchor (px)."
        },
        "width": {
          "$ref": "#/definitions/Expr",
          "description": "Width (px)."
        },
        "height": {
          "$ref": "#/definitions/Expr",
          "description": "Height (px)."
        },
        "title": {
          "$ref": "#/definitions/Text",
          "description": "Title template."
        },
        "text": {
          "$ref": "#/definitions/Text",
          "description": "Body template."
        },
        "progress": {
          "$ref": "#/definitions/Expr",
          "description": "Progress bar fill 0..1."
        },
        "progressColor": {
          "type": "string",
          "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$",
          "description": "Progress bar colour."
        },
        "style": {
          "$ref": "#/definitions/UIFrameStyle",
          "description": "Visual style overrides."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null`/absent for everyone."
        },
        "visible": {
          "type": "boolean",
          "description": "Visible (default true)."
        },
        "clickable": {
          "type": "boolean",
          "description": "Let this panel be CLICKED. Off by default, and a panel that leaves it off is invisible to the mouse — clicks, drags and wheel zoom pass straight through it to the map, exactly as every panel has always behaved. Turn it on for a panel that is a button, and a click on it fires `uiFrameClicked` for the seat that clicked. A clickable panel still sits UNDER the game's own HUD, so it can never swallow a click meant for a HUD control; and a click only counts if the panel is visible and shown to that seat, which the engine checks on every client."
        }
      },
      "additionalProperties": false
    },
    "Action.createUnits": {
      "title": "Create units",
      "description": "Spawn N units (max 500) for a player at a point.",
      "type": "object",
      "required": [
        "k",
        "unitTypeId",
        "count",
        "player",
        "at"
      ],
      "properties": {
        "k": {
          "const": "createUnits"
        },
        "unitTypeId": {
          "type": "string",
          "description": "Unit type id (base game or a defOverrides clone)."
        },
        "count": {
          "$ref": "#/definitions/Expr",
          "description": "How many."
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Spawn tile."
        },
        "facing": {
          "$ref": "#/definitions/Expr",
          "description": "Facing in degrees."
        },
        "intoVar": {
          "type": "string",
          "minLength": 1,
          "description": "unitGroup variable receiving the created ids. It must ALREADY exist — declared in `vars`, or a local, parameter or loop variable in scope. Unlike a loop variable, this does NOT declare one, and an undeclared name is an error."
        }
      },
      "additionalProperties": false
    },
    "Action.defeat": {
      "title": "Defeat",
      "description": "Declare a seat defeated.",
      "type": "object",
      "required": [
        "k",
        "player"
      ],
      "properties": {
        "k": {
          "const": "defeat"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        }
      },
      "additionalProperties": false
    },
    "Action.destroyUIFrame": {
      "title": "Destroy UI frame",
      "description": "Remove a frame.",
      "type": "object",
      "required": [
        "k",
        "frameId"
      ],
      "properties": {
        "k": {
          "const": "destroyUIFrame"
        },
        "frameId": {
          "type": "string",
          "minLength": 1,
          "description": "Frame id."
        }
      },
      "additionalProperties": false
    },
    "Action.enableTrigger": {
      "title": "Enable/disable trigger",
      "description": "Turn a trigger on or off.",
      "type": "object",
      "required": [
        "k",
        "triggerId",
        "on"
      ],
      "properties": {
        "k": {
          "const": "enableTrigger"
        },
        "triggerId": {
          "type": "string",
          "minLength": 1,
          "description": "Trigger id."
        },
        "on": {
          "type": "boolean",
          "description": "Enabled."
        }
      },
      "additionalProperties": false
    },
    "Action.faceUnit": {
      "title": "Face unit toward point",
      "description": "Turn a living stationary unit toward a tile using its ordinary turn rate. Does not move it, cancel orders or turn structures. Missing, dead, moving or coincident targets do nothing. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "toward"
      ],
      "properties": {
        "k": {
          "const": "faceUnit"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "toward": {
          "$ref": "#/definitions/Expr",
          "description": "Tile to face. Evaluated only for an eligible stationary unit."
        }
      },
      "additionalProperties": false
    },
    "Action.fadeScreen": {
      "title": "Fade screen",
      "description": "Fade screen in or out with color and duration.",
      "type": "object",
      "required": [
        "k",
        "players",
        "type"
      ],
      "properties": {
        "k": {
          "const": "fadeScreen"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "type": {
          "type": "string",
          "enum": [
            "in",
            "out"
          ],
          "description": "Fade type: in or out."
        },
        "colorHex": {
          "type": "string",
          "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$",
          "description": "Fade colour (default #000000)."
        },
        "durationTicks": {
          "type": "integer",
          "minimum": 1,
          "description": "Transition duration in ticks (default 20 = 1 sec)."
        }
      },
      "additionalProperties": false
    },
    "Action.floatingText": {
      "title": "Floating text",
      "description": "A word that floats up off a tile and fades — the same thing the game draws for \"+10 gold\" and \"Level 3!\". HIDDEN BY FOG: a viewer who cannot see the tile does not see the word, because a word floating over an enemy hero would report where the enemy hero is. Use `show text` for a banner that must always be read. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "at",
        "text",
        "players"
      ],
      "properties": {
        "k": {
          "const": "floatingText"
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Tile it floats off — a point, or a unit whose tile is used."
        },
        "text": {
          "$ref": "#/definitions/Text",
          "description": "Text template (a bare string is accepted)."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "colorHex": {
          "type": "string",
          "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$",
          "description": "Colour (default #ffffff)."
        }
      },
      "additionalProperties": false
    },
    "Action.forEachInt": {
      "title": "For each integer",
      "description": "Run the body for each integer from..to inclusive (at most 10000).",
      "type": "object",
      "required": [
        "k",
        "varName",
        "from",
        "to",
        "body"
      ],
      "properties": {
        "k": {
          "const": "forEachInt"
        },
        "varName": {
          "type": "string",
          "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
          "description": "Loop variable; an undeclared name becomes a local."
        },
        "from": {
          "$ref": "#/definitions/Expr",
          "description": "First value."
        },
        "to": {
          "$ref": "#/definitions/Expr",
          "description": "Last value (inclusive)."
        },
        "body": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Action"
          },
          "description": "Loop body."
        }
      },
      "additionalProperties": false
    },
    "Action.forEachUnit": {
      "title": "For each unit",
      "description": "Run the body once per unit of a group (snapshotted and sorted before the first iteration).",
      "type": "object",
      "required": [
        "k",
        "group",
        "varName",
        "body"
      ],
      "properties": {
        "k": {
          "const": "forEachUnit"
        },
        "group": {
          "$ref": "#/definitions/Expr",
          "description": "Group to iterate."
        },
        "varName": {
          "type": "string",
          "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
          "description": "Loop variable receiving each unit id; an undeclared name becomes a local."
        },
        "body": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Action"
          },
          "description": "Loop body."
        }
      },
      "additionalProperties": false
    },
    "Action.generateSaveCode": {
      "title": "Generate save code",
      "description": "Encode named values into a tamper-evident code bound to this map, stored in a string variable.",
      "type": "object",
      "required": [
        "k",
        "player",
        "toVar",
        "data"
      ],
      "properties": {
        "k": {
          "const": "generateSaveCode"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "toVar": {
          "type": "string",
          "minLength": 1,
          "description": "An already-declared string variable to receive the code; this does not create one."
        },
        "data": {
          "type": "object",
          "propertyNames": {
            "minLength": 1
          },
          "additionalProperties": {
            "$ref": "#/definitions/Expr"
          },
          "description": "Field name → value expression."
        }
      },
      "additionalProperties": false
    },
    "Action.hashtableClear": {
      "title": "Hashtable clear",
      "description": "Remove every entry, or only those under key1.",
      "type": "object",
      "required": [
        "k",
        "table"
      ],
      "properties": {
        "k": {
          "const": "hashtableClear"
        },
        "table": {
          "type": "string",
          "minLength": 1,
          "description": "Hashtable name."
        },
        "key1": {
          "$ref": "#/definitions/Expr",
          "description": "Parent key to flush; absent = whole table."
        }
      },
      "additionalProperties": false
    },
    "Action.hashtableRemove": {
      "title": "Hashtable remove",
      "description": "Remove the value under (key1, key2).",
      "type": "object",
      "required": [
        "k",
        "table",
        "key1",
        "key2"
      ],
      "properties": {
        "k": {
          "const": "hashtableRemove"
        },
        "table": {
          "type": "string",
          "minLength": 1,
          "description": "Hashtable name."
        },
        "key1": {
          "$ref": "#/definitions/Expr",
          "description": "Parent key."
        },
        "key2": {
          "$ref": "#/definitions/Expr",
          "description": "Child key."
        }
      },
      "additionalProperties": false
    },
    "Action.hashtableSet": {
      "title": "Hashtable set",
      "description": "Store a value under (key1, key2). New keys past the table cap are dropped.",
      "type": "object",
      "required": [
        "k",
        "table",
        "key1",
        "key2",
        "value"
      ],
      "properties": {
        "k": {
          "const": "hashtableSet"
        },
        "table": {
          "type": "string",
          "minLength": 1,
          "description": "Hashtable name."
        },
        "key1": {
          "$ref": "#/definitions/Expr",
          "description": "Parent key (int or string)."
        },
        "key2": {
          "$ref": "#/definitions/Expr",
          "description": "Child key (int or string)."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "Value (coerced to the table type)."
        }
      },
      "additionalProperties": false
    },
    "Action.heroAddXp": {
      "title": "Give hero XP",
      "description": "Grant XP to ONE hero and resolve every level it crosses, inside this action. A reviving hero is skipped. Safe to call from a `heroLevels` trigger: trigger signals are drained at the top of the next tick, so the level-up has already finished and there is no mid-level-up state to reason about. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "amount"
      ],
      "properties": {
        "k": {
          "const": "heroAddXp"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "amount": {
          "$ref": "#/definitions/Expr",
          "description": "XP to grant. Zero or negative does nothing."
        }
      },
      "additionalProperties": false
    },
    "Action.heroRevive": {
      "title": "Revive hero",
      "description": "Finish a hero's revival now: clear the countdown, restore health and mana to full, and optionally move it. IT CANNOT RESURRECT A HERO WHOSE ENTITY IS GONE - a dead hero is destroyed and its progress banked, and respawning one is not exposed to triggers. Use it on a hero that still exists: one counting down a revive, or one left at zero HP. On a hero already up and whole it does nothing. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit"
      ],
      "properties": {
        "k": {
          "const": "heroRevive"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Tile to put the hero on. Absent leaves it where it is."
        }
      },
      "additionalProperties": false
    },
    "Action.heroSetLevel": {
      "title": "Set hero level",
      "description": "Raise a hero TO a level. It grants the XP rather than writing the level, so the hero gets every point of growth the levels are worth and is indistinguishable from one that earned them. LOWERING IS A NO-OP, not an approximation: the engine records the level but not the deltas used to reach it. The target is clamped to the match's level cap first, so asking for a million costs the same as asking for the cap. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "level"
      ],
      "properties": {
        "k": {
          "const": "heroSetLevel"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "level": {
          "$ref": "#/definitions/Expr",
          "description": "Level to reach. Clamped to the match level cap; a level at or below the current one does nothing."
        }
      },
      "additionalProperties": false
    },
    "Action.hideDialog": {
      "title": "Hide dialog",
      "description": "Close a dialog.",
      "type": "object",
      "required": [
        "k",
        "dialogId"
      ],
      "properties": {
        "k": {
          "const": "hideDialog"
        },
        "dialogId": {
          "type": "string",
          "minLength": 1,
          "description": "Dialog id."
        }
      },
      "additionalProperties": false
    },
    "Action.hitStop": {
      "title": "Hit stop",
      "description": "Hold the picture for a beat on a heavy blow: animation, particles and spell effects slow almost to a stop, then carry on. Drawing only: the match keeps running underneath, so it is safe in multiplayer and never changes a result. Back-to-back holds join into one, a third of a second at most.",
      "type": "object",
      "required": [
        "k",
        "players"
      ],
      "properties": {
        "k": {
          "const": "hitStop"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "durationTicks": {
          "type": "integer",
          "minimum": 1,
          "maximum": 5,
          "description": "How long the hold lasts, in ticks (default 2, a tenth of a second; 1 to 5)."
        },
        "timeScale": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "How fast the picture moves during the hold, 0 (still) to 1 (default 0.08)."
        }
      },
      "additionalProperties": false
    },
    "Action.if": {
      "title": "If / then / else",
      "description": "Run `then` when cond is true, else `else`.",
      "type": "object",
      "required": [
        "k",
        "cond",
        "then"
      ],
      "properties": {
        "k": {
          "const": "if"
        },
        "cond": {
          "$ref": "#/definitions/Expr",
          "description": "Condition."
        },
        "then": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Action"
          },
          "description": "Actions when true."
        },
        "else": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Action"
          },
          "description": "Actions when false."
        }
      },
      "additionalProperties": false
    },
    "Action.itemCreate": {
      "title": "Create item on ground",
      "description": "Put an item on the ground. The tile is a request: the engine walks an expanding ring for a free walkable tile, and an item asked for on deep water floats there instead of being dragged ashore. It hands back NO handle, so a map cannot refer to the item it made. An unknown item id creates nothing. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "itemId",
        "at"
      ],
      "properties": {
        "k": {
          "const": "itemCreate"
        },
        "itemId": {
          "type": "string",
          "description": "Item id to create."
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Tile to create it on."
        }
      },
      "additionalProperties": false
    },
    "Action.itemGive": {
      "title": "Give item to unit",
      "description": "Put an item in a unit's BACKPACK. It does not auto-equip - equipping applies stat effects and set bonuses, which is a different request. Consumables stack to the item's cap. When the bag is full the remainder lands on the ground at the unit's feet rather than vanishing. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "itemId"
      ],
      "properties": {
        "k": {
          "const": "itemGive"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "itemId": {
          "type": "string",
          "description": "Item id to give."
        },
        "count": {
          "$ref": "#/definitions/Expr",
          "description": "How many (default 1)."
        }
      },
      "additionalProperties": false
    },
    "Action.itemRemove": {
      "title": "Remove item from unit",
      "description": "Take an item out of a unit's BACKPACK. Equipped gear is not touched: pulling gear off has to reverse its stat effects and recompute the set bonus. Removes across stacks, lowest slot first. Asking for more than the unit holds removes what it holds. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "itemId"
      ],
      "properties": {
        "k": {
          "const": "itemRemove"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "itemId": {
          "type": "string",
          "description": "Item id to remove."
        },
        "count": {
          "$ref": "#/definitions/Expr",
          "description": "How many (default 1)."
        }
      },
      "additionalProperties": false
    },
    "Action.killUnit": {
      "title": "Kill unit",
      "description": "Kill a unit through the normal death path.",
      "type": "object",
      "required": [
        "k",
        "unit"
      ],
      "properties": {
        "k": {
          "const": "killUnit"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        }
      },
      "additionalProperties": false
    },
    "Action.knockback": {
      "title": "Knock back",
      "description": "Shove a unit straight away from a point, the way a charge knocks a unit back: it slides tile by tile and stops at the first wall, cliff edge or unit in its way. The way is the nearest of the eight compass directions. A building, a dead unit, a unit already sliding, or a point on top of the unit does nothing. Needs map format 7.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "from",
        "tiles"
      ],
      "properties": {
        "k": {
          "const": "knockback"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "from": {
          "$ref": "#/definitions/Expr",
          "description": "The tile it is shoved away from: a blast's centre, the hitter."
        },
        "tiles": {
          "$ref": "#/definitions/Expr",
          "description": "How far, in tiles (1 to 8)."
        },
        "ticksPerTile": {
          "type": "integer",
          "minimum": 1,
          "maximum": 20,
          "description": "Ticks each tile of the slide takes (default 6; 1 to 20)."
        },
        "ease": {
          "type": "string",
          "enum": [
            "out",
            "linear"
          ],
          "description": "'out' (default): fast off the blow, slowing into the landing. 'linear': an even slide."
        }
      },
      "additionalProperties": false
    },
    "Action.moveUnit": {
      "title": "Move unit instantly",
      "description": "Teleport a unit to a tile.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "to"
      ],
      "properties": {
        "k": {
          "const": "moveUnit"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "to": {
          "$ref": "#/definitions/Expr",
          "description": "Destination tile."
        }
      },
      "additionalProperties": false
    },
    "Action.multiboardCell": {
      "title": "Set a multiboard cell",
      "description": "Write one cell. Rows and columns are 0-BASED. Does nothing when the board does not exist or the cell falls outside the grid it declared — both of which the map validator reports, because at runtime an unwritten cell and a cell written to a board that is not there look identical. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "boardId",
        "row",
        "col",
        "text"
      ],
      "properties": {
        "k": {
          "const": "multiboardCell"
        },
        "boardId": {
          "type": "string",
          "description": "Board id, as `create or replace a multiboard` named it."
        },
        "row": {
          "$ref": "#/definitions/Expr",
          "description": "0-based row."
        },
        "col": {
          "$ref": "#/definitions/Expr",
          "description": "0-based column."
        },
        "text": {
          "$ref": "#/definitions/Text",
          "description": "Cell text template."
        }
      },
      "additionalProperties": false
    },
    "Action.multiboardRemove": {
      "title": "Remove a multiboard",
      "description": "Take the board off screen and forget every cell in it. Removing one that is not there does nothing. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "boardId"
      ],
      "properties": {
        "k": {
          "const": "multiboardRemove"
        },
        "boardId": {
          "type": "string",
          "description": "Board id."
        }
      },
      "additionalProperties": false
    },
    "Action.multiboardSet": {
      "title": "Create or replace a multiboard",
      "description": "A titled grid of text — the multi-column scoreboard the leaderboard cannot be. REPLACES rather than merges: calling this again on the same board id resets its size, title, audience and every cell, so use `set multiboard cell` to change one number. Rows and columns past the engine grid cap are clamped, and boards past the board cap are refused. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "boardId",
        "title",
        "rows",
        "cols",
        "players"
      ],
      "properties": {
        "k": {
          "const": "multiboardSet"
        },
        "boardId": {
          "type": "string",
          "description": "Your id for this board. Re-using it replaces the board; the cell and remove actions take the same id."
        },
        "title": {
          "$ref": "#/definitions/Text",
          "description": "Title template. Empty text hides the header."
        },
        "rows": {
          "$ref": "#/definitions/Expr",
          "description": "Rows the grid declares."
        },
        "cols": {
          "$ref": "#/definitions/Expr",
          "description": "Columns the grid declares."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.order": {
      "title": "Order units",
      "description": "Issue an order to a group, applied inside the tick (never through lockstep).",
      "type": "object",
      "required": [
        "k",
        "units",
        "order"
      ],
      "properties": {
        "k": {
          "const": "order"
        },
        "units": {
          "$ref": "#/definitions/Expr",
          "description": "Units to order (a single unit also works)."
        },
        "order": {
          "type": "string",
          "enum": [
            "move",
            "attack_move",
            "attack",
            "stop",
            "hold",
            "patrol",
            "follow"
          ],
          "description": "Order kind."
        },
        "to": {
          "$ref": "#/definitions/Expr",
          "description": "Target tile for move / attack_move / patrol."
        },
        "target": {
          "$ref": "#/definitions/Expr",
          "description": "Target unit for attack / follow."
        },
        "queue": {
          "type": "boolean",
          "description": "Queue after current orders."
        }
      },
      "additionalProperties": false
    },
    "Action.overlayClear": {
      "title": "Overlay: clear a layer",
      "description": "Empty every tile of a layer. It stays defined, and stays in the overlay frame. Needs map format 6.",
      "type": "object",
      "required": [
        "k",
        "id"
      ],
      "properties": {
        "k": {
          "const": "overlayClear"
        },
        "id": {
          "type": "string",
          "description": "Layer id."
        }
      },
      "additionalProperties": false
    },
    "Action.overlayDefine": {
      "title": "Overlay: define a layer",
      "description": "Define a map layer players can switch on in the HUD's overlay frame: a label, a legend line, and 2 to 6 colours from low to high. Values painted onto it run from `min` (the first colour) to `max` (the last). Up to 8 layers; defining one again keeps what was painted. View-only: nothing in the game reads it back, so it never changes the match. With `show` it turns on for every player now. Needs map format 6.",
      "type": "object",
      "required": [
        "k",
        "id",
        "name",
        "colors"
      ],
      "properties": {
        "k": {
          "const": "overlayDefine"
        },
        "id": {
          "type": "string",
          "description": "Layer id: 1 to 32 letters, digits, _ or -."
        },
        "name": {
          "type": "string",
          "description": "Its label in the HUD."
        },
        "legend": {
          "type": "string",
          "description": "One line saying what the colours mean."
        },
        "colors": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "2 to 6 colours, low to high, as '#rrggbb'."
        },
        "min": {
          "type": "number",
          "description": "The value drawn as the first colour (default 0)."
        },
        "max": {
          "type": "number",
          "description": "The value drawn as the last colour (default 100)."
        },
        "opacity": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100,
          "description": "How opaque, percent (default 60)."
        },
        "show": {
          "type": "boolean",
          "description": "Turn it on for every player now."
        }
      },
      "additionalProperties": false
    },
    "Action.overlayFill": {
      "title": "Overlay: paint a region",
      "description": "Paint one value over a region of a layer. A value that is not a number empties the tiles. Paint a gradient by painting several regions, or use the script API's `overlay.paint` for a value per tile. Needs map format 6.",
      "type": "object",
      "required": [
        "k",
        "id",
        "region",
        "value"
      ],
      "properties": {
        "k": {
          "const": "overlayFill"
        },
        "id": {
          "type": "string",
          "description": "Layer id."
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "description": "The region to paint."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "The value (between the layer's min and max)."
        }
      },
      "additionalProperties": false
    },
    "Action.pauseTimer": {
      "title": "Pause timer",
      "description": "Pause a timer.",
      "type": "object",
      "required": [
        "k",
        "timer"
      ],
      "properties": {
        "k": {
          "const": "pauseTimer"
        },
        "timer": {
          "type": "string",
          "minLength": 1,
          "description": "Timer name."
        }
      },
      "additionalProperties": false
    },
    "Action.ping": {
      "title": "Ping minimap",
      "description": "Ping a tile on the minimap.",
      "type": "object",
      "required": [
        "k",
        "players",
        "at"
      ],
      "properties": {
        "k": {
          "const": "ping"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Tile to ping."
        },
        "colorHex": {
          "type": "string",
          "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$",
          "description": "Colour (default #ffcc00)."
        },
        "durationTicks": {
          "type": "integer",
          "minimum": 1,
          "description": "Duration in ticks (default 60)."
        }
      },
      "additionalProperties": false
    },
    "Action.playAnimation": {
      "title": "Play animation",
      "description": "Request a finite saved cinematic pose on a stationary living unit. Movement, death and scene completion release it; missing model clips do not perform.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "animation"
      ],
      "properties": {
        "k": {
          "const": "playAnimation"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "animation": {
          "type": "string",
          "description": "Canonical clip slot: idle, attack, gather, build, special_1/2/3, sleep or sitting. cast aliases special_1. There is no invented talk or living death clip."
        },
        "loop": {
          "type": "boolean",
          "description": "Whether to loop the animation."
        },
        "durationTicks": {
          "type": "integer",
          "minimum": 1,
          "description": "Finite pose window (default 20 ticks, capped at 1200). Loops retain normal clip speed; one-shots fit this window."
        }
      },
      "additionalProperties": false
    },
    "Action.playCutscene": {
      "title": "Play cutscene",
      "description": "Start a map scene for these seats; the sim records only the start.",
      "type": "object",
      "required": [
        "k",
        "sceneId",
        "players"
      ],
      "properties": {
        "k": {
          "const": "playCutscene"
        },
        "sceneId": {
          "type": "string",
          "description": "Scene id."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.playEffect": {
      "title": "Play a visual effect",
      "description": "A spell's visual effect at a tile, with NONE of its gameplay: no damage, no mana, no cooldown, no caster. Effects are named by SPELL ID because that is the vocabulary the engine's own effect pipeline reads, so every shipped spell's look is available and a typo is an error rather than a silent nothing. Hidden by fog, like every other effect in the game. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "spellId",
        "at",
        "players"
      ],
      "properties": {
        "k": {
          "const": "playEffect"
        },
        "spellId": {
          "type": "string",
          "description": "Spell whose visual to play. Its gameplay is NOT run — only its look."
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Tile to play it at — a point, or a unit whose tile is used."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.playMusic": {
      "title": "Play music",
      "description": "Start a soundtrack for these seats, replacing whatever is playing and stopping the automatic battle shuffler. Music keys are a different list from sound ids — the picker offers the shipped soundtrack. A track the client has not loaded is fetched and then played, so it starts a moment late the first time rather than not at all. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "musicId",
        "players"
      ],
      "properties": {
        "k": {
          "const": "playMusic"
        },
        "musicId": {
          "type": "string",
          "description": "Soundtrack key."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.playSound": {
      "title": "Play sound",
      "description": "Play a sound effect (base game or map custom sound).",
      "type": "object",
      "required": [
        "k",
        "soundId",
        "players"
      ],
      "properties": {
        "k": {
          "const": "playSound"
        },
        "soundId": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$",
          "description": "Sound id: any shipped sound effect, or a custom sound this map registers. The bare name only — no directory and no extension, so `dwarf_ack_1`, not `voice/dwarf_ack_1.mp3`."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.playSoundAt": {
      "title": "Play sound at a place",
      "description": "A sound effect at a tile: panned and quietened by distance, and HIDDEN BY FOG — a listener who cannot see the place does not hear it, because a sound is information. Use `play sound` instead for a UI cue that should always play at full volume. WARNING: the FIRST play of a sound the client has not loaded yet is SILENT — it starts the download and returns, and plays from the next request on. Only about a quarter of the sound library is preloaded, so a once-only dramatic cue may play nothing at all. Play it somewhere harmless earlier in the map, or use a sound the match has already made. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "soundId",
        "at",
        "players"
      ],
      "properties": {
        "k": {
          "const": "playSoundAt"
        },
        "soundId": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$",
          "description": "Sound to play (base game or map custom sound)."
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Tile to play it at — a point, or a unit whose tile is used."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "reachTiles": {
          "$ref": "#/definitions/Expr",
          "description": "Widen the fog test by this many tiles, for something whose noise carries further than its centre. Default 0."
        }
      },
      "additionalProperties": false
    },
    "Action.raiseEvent": {
      "title": "Raise custom event",
      "description": "Fire the `custom` event of this name later in the same tick.",
      "type": "object",
      "required": [
        "k",
        "name"
      ],
      "properties": {
        "k": {
          "const": "raiseEvent"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Event name."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "Event value payload."
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "Event text payload (default: the name)."
        }
      },
      "additionalProperties": false
    },
    "Action.removeAbility": {
      "title": "Remove ability",
      "description": "Take a spell away from a unit. Removing one it does not have does nothing. This does not silence: a cast already in flight resolves. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "spellId"
      ],
      "properties": {
        "k": {
          "const": "removeAbility"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "spellId": {
          "type": "string",
          "description": "Spell id to remove."
        }
      },
      "additionalProperties": false
    },
    "Action.removeBuff": {
      "title": "Remove buff",
      "description": "Take one buff off a unit, matching the WHOLE id. Aura buffs are left alone: `AuraSystem` re-stamps those every tick, so removing one would come straight back and read as a broken action. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "buffId"
      ],
      "properties": {
        "k": {
          "const": "removeBuff"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "buffId": {
          "type": "string",
          "description": "Buff id to remove."
        }
      },
      "additionalProperties": false
    },
    "Action.removeCounter": {
      "title": "Remove counter",
      "description": "Remove a counter.",
      "type": "object",
      "required": [
        "k",
        "id"
      ],
      "properties": {
        "k": {
          "const": "removeCounter"
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Counter id."
        }
      },
      "additionalProperties": false
    },
    "Action.removeLeaderboardRow": {
      "title": "Remove leaderboard row",
      "description": "Remove a leaderboard row.",
      "type": "object",
      "required": [
        "k",
        "rowId"
      ],
      "properties": {
        "k": {
          "const": "removeLeaderboardRow"
        },
        "rowId": {
          "type": "string",
          "minLength": 1,
          "description": "Row id."
        }
      },
      "additionalProperties": false
    },
    "Action.removeUnit": {
      "title": "Remove unit",
      "description": "Remove a unit outright — no death, corpse or bounty.",
      "type": "object",
      "required": [
        "k",
        "unit"
      ],
      "properties": {
        "k": {
          "const": "removeUnit"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        }
      },
      "additionalProperties": false
    },
    "Action.removeUnitFromGroup": {
      "title": "Remove unit from group",
      "description": "Remove a unit from a unitGroup variable.",
      "type": "object",
      "required": [
        "k",
        "varName",
        "unit"
      ],
      "properties": {
        "k": {
          "const": "removeUnitFromGroup"
        },
        "varName": {
          "type": "string",
          "minLength": 1,
          "description": "An already-declared unitGroup variable; this does not create one."
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        }
      },
      "additionalProperties": false
    },
    "Action.resumeTimer": {
      "title": "Resume timer",
      "description": "Resume a paused timer.",
      "type": "object",
      "required": [
        "k",
        "timer"
      ],
      "properties": {
        "k": {
          "const": "resumeTimer"
        },
        "timer": {
          "type": "string",
          "minLength": 1,
          "description": "Timer name."
        }
      },
      "additionalProperties": false
    },
    "Action.return": {
      "title": "Return",
      "description": "Leave the current function, yielding `value`. At trigger level (no value allowed) it stops the trigger.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "return"
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "Return value (functions with a return type)."
        }
      },
      "additionalProperties": false
    },
    "Action.revealArea": {
      "title": "Reveal an area",
      "description": "Lift the fog on a disc of map for ONE seat, for a while. It works the way the Reveal spell works — it drops an invisible watcher that sees for you — so the ground stays EXPLORED afterwards (dimmed, remembered) even though the live vision goes away when the timer runs out, and anything standing inside it can be targeted while it lasts. Its teammates see through it too, exactly as they see through your scout. A radius of 0..64 tiles and a duration of 1..12000 ticks (10 minutes); leave the duration out for 100 ticks (5 seconds). There is no permanent reveal and no way to take vision AWAY — for a whole-map reveal, use the map's fog rule instead of a trigger. Each call costs one of the per-tick spawn budget, so a loop revealing a thousand tiles stops at the budget rather than freezing the match. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "player",
        "at",
        "radius"
      ],
      "properties": {
        "k": {
          "const": "revealArea"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Centre tile."
        },
        "radius": {
          "$ref": "#/definitions/Expr",
          "description": "Radius in tiles (0..64)."
        },
        "durationTicks": {
          "type": "integer",
          "minimum": 1,
          "maximum": 12000,
          "description": "How long the reveal lasts, in ticks (default 100 = 5 seconds, max 12000)."
        }
      },
      "additionalProperties": false
    },
    "Action.runTrigger": {
      "title": "Run trigger",
      "description": "Run another trigger's actions inline in this event context.",
      "type": "object",
      "required": [
        "k",
        "triggerId"
      ],
      "properties": {
        "k": {
          "const": "runTrigger"
        },
        "triggerId": {
          "type": "string",
          "minLength": 1,
          "description": "Trigger id."
        },
        "checkConditions": {
          "type": "boolean",
          "description": "Evaluate its conditions first (and count it as fired)."
        }
      },
      "additionalProperties": false
    },
    "Action.setAlliance": {
      "title": "Set alliance",
      "description": "Ally B to A's team, or put B back on its own team.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b",
        "allied"
      ],
      "properties": {
        "k": {
          "const": "setAlliance"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        },
        "allied": {
          "type": "boolean",
          "description": "Allied."
        }
      },
      "additionalProperties": false
    },
    "Action.setBuildableRegion": {
      "title": "Restrict building",
      "description": "Limit where a seat may build: a list of regions, [] for nowhere, or null to restore the default.",
      "type": "object",
      "required": [
        "k",
        "player",
        "regions"
      ],
      "properties": {
        "k": {
          "const": "setBuildableRegion"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "regions": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string",
            "minLength": 1
          },
          "description": "Region ids, or null."
        }
      },
      "additionalProperties": false
    },
    "Action.setCounter": {
      "title": "Set counter",
      "description": "Create or update an on-screen counter.",
      "type": "object",
      "required": [
        "k",
        "id",
        "label",
        "value"
      ],
      "properties": {
        "k": {
          "const": "setCounter"
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Counter id."
        },
        "label": {
          "$ref": "#/definitions/Text",
          "description": "Label template."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "Value."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null`/absent for everyone."
        },
        "order": {
          "type": "integer",
          "description": "Sort position."
        }
      },
      "additionalProperties": false
    },
    "Action.setEventDamage": {
      "title": "Set event damage",
      "description": "Replace the damage this hit is about to do. Only works in a trigger with a \"unit is about to take damage\" (unitDamaging) event — the validator refuses it anywhere else, because anywhere else it would silently do nothing. A result that is not a finite number leaves the damage UNCHANGED rather than zeroing it, so a broken formula reads as \"my armour does nothing\" instead of as accidental invulnerability; otherwise it is clamped to 0..1000000000. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "amount"
      ],
      "properties": {
        "k": {
          "const": "setEventDamage"
        },
        "amount": {
          "$ref": "#/definitions/Expr",
          "description": "The new damage amount. Read the old one with \"event damage\"."
        }
      },
      "additionalProperties": false
    },
    "Action.setLeaderboardRow": {
      "title": "Leaderboard row",
      "description": "Create or update a leaderboard row.",
      "type": "object",
      "required": [
        "k",
        "rowId",
        "label",
        "value"
      ],
      "properties": {
        "k": {
          "const": "setLeaderboardRow"
        },
        "rowId": {
          "type": "string",
          "minLength": 1,
          "description": "Row id."
        },
        "label": {
          "$ref": "#/definitions/Text",
          "description": "Label template."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "Value."
        },
        "order": {
          "type": "integer",
          "description": "Sort position."
        }
      },
      "additionalProperties": false
    },
    "Action.setLeaderboardTitle": {
      "title": "Leaderboard title",
      "description": "Set the leaderboard title (\"\" hides it).",
      "type": "object",
      "required": [
        "k",
        "title"
      ],
      "properties": {
        "k": {
          "const": "setLeaderboardTitle"
        },
        "title": {
          "$ref": "#/definitions/Text",
          "description": "Title template."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null`/absent for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.setObjective": {
      "title": "Set a campaign objective",
      "description": "Complete, fail or advance ONE campaign mission objective. This is the campaign's own objective list — the one that decides whether a mission is won — and NOT `set quest`, which writes the trigger layer's quest log and works in every mode. Outside a campaign mission it does nothing at all, which the map validator reports. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "objectiveId",
        "state"
      ],
      "properties": {
        "k": {
          "const": "setObjective"
        },
        "objectiveId": {
          "type": "string",
          "description": "The objective's id, as the mission defines it."
        },
        "state": {
          "type": "string",
          "enum": [
            "completed",
            "failed",
            "progress"
          ],
          "description": "What to do to it."
        },
        "amount": {
          "$ref": "#/definitions/Expr",
          "description": "Progress amount, for `progress` only. Absent counts as 1. Reaching the objective's target completes it."
        }
      },
      "additionalProperties": false
    },
    "Action.setPopCap": {
      "title": "Set population cap",
      "description": "Set a seat's population cap outright, or LEAVE `value` OUT to clear it and hand the seat back to the cap its buildings provide. It is a SEPARATE number from the building total, not a write to it: farms and town halls keep adding and removing their own capacity underneath, so destroying a farm never eats into an authored cap and clearing the cap restores exactly the right number with no recount. Clamped to 0..5000, and 0 is a real cap meaning \"this seat trains nothing\". A value that is not a finite number CLEARS the cap rather than writing it, so a broken formula reads as \"my trigger did nothing\" instead of as an unlimited army. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "player"
      ],
      "properties": {
        "k": {
          "const": "setPopCap"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "The cap. ABSENT clears the authored cap and returns the seat to its building-derived one."
        }
      },
      "additionalProperties": false
    },
    "Action.setQuest": {
      "title": "Set quest",
      "description": "Create or update a quest-log entry.",
      "type": "object",
      "required": [
        "k",
        "questId",
        "title",
        "description",
        "state"
      ],
      "properties": {
        "k": {
          "const": "setQuest"
        },
        "questId": {
          "type": "string",
          "minLength": 1,
          "description": "Quest id."
        },
        "title": {
          "$ref": "#/definitions/Text",
          "description": "Title template."
        },
        "description": {
          "$ref": "#/definitions/Text",
          "description": "Description template."
        },
        "state": {
          "type": "string",
          "enum": [
            "active",
            "completed",
            "failed"
          ],
          "description": "Quest state."
        },
        "icon": {
          "type": "string",
          "description": "Icon key."
        },
        "order": {
          "type": "integer",
          "description": "Sort position."
        }
      },
      "additionalProperties": false
    },
    "Action.setResource": {
      "title": "Set resource",
      "description": "Set a player's resource stock (rounded, ≥ 0).",
      "type": "object",
      "required": [
        "k",
        "player",
        "resource",
        "value"
      ],
      "properties": {
        "k": {
          "const": "setResource"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "resource": {
          "type": "string",
          "enum": [
            "gold",
            "lumber",
            "stone",
            "oil"
          ],
          "description": "Resource kind."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "New amount."
        }
      },
      "additionalProperties": false
    },
    "Action.setTechAllowed": {
      "title": "Allow or forbid a research",
      "description": "Allow or forbid ONE upgrade for ONE seat, mid-match. Forbidding it greys the button out AND refuses the order at the lockstep door, so a forged command spends nothing — the rule is one shared predicate, not a check in the menu. It does NOT remove a research the seat has already completed, and it does not stop one already in the queue; it stops the next order. The lobby's own disabled-research list still applies on top: this can only ever take a research away, never hand back one the match rules removed. Allowing an upgrade that was never forbidden does nothing. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "player",
        "upgradeId",
        "allowed"
      ],
      "properties": {
        "k": {
          "const": "setTechAllowed"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "upgradeId": {
          "type": "string",
          "description": "Upgrade id."
        },
        "allowed": {
          "type": "boolean",
          "description": "True allows it (the default state), false forbids it."
        }
      },
      "additionalProperties": false
    },
    "Action.setTerrain": {
      "title": "Set terrain",
      "description": "Turn a region's tiles to grass, dirt, shallow water, lava or shallow lava during play: a flood, a drained marsh, a lava flow, an arena that shrinks into the magma. Only grass, dirt, stumps, shallow water and lava change; trees, ore, rock, deep water, the sky and cliffs never do. Land, water and lava never swap under a building, a city lot or a ship, and lava never touches water. Shallow lava is walkable and burns; deep lava is a wall. Pathing, the minimap and the ground follow at once, and a city's ground on its next step. At most 4,096 tiles a region. Cliff height and pathing blockers cannot change. Needs map format 6.",
      "type": "object",
      "required": [
        "k",
        "region",
        "terrain"
      ],
      "properties": {
        "k": {
          "const": "setTerrain"
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "description": "The region."
        },
        "terrain": {
          "type": "string",
          "enum": [
            "grass",
            "dirt",
            "shallowWater",
            "lava",
            "shallowLava"
          ],
          "description": "The terrain."
        }
      },
      "additionalProperties": false
    },
    "Action.setTimeOfDay": {
      "title": "Set Time of Day",
      "description": "Sets the Day/Night cycle time of day (0..1) and progression speed.",
      "type": "object",
      "required": [
        "k",
        "progress"
      ],
      "properties": {
        "k": {
          "const": "setTimeOfDay"
        },
        "progress": {
          "$ref": "#/definitions/Expr",
          "description": "Time of day from 0 (dawn) to 1 (next dawn)."
        },
        "speed": {
          "$ref": "#/definitions/Expr",
          "description": "Speed multiplier for day/night progression (0 = pause)."
        }
      },
      "additionalProperties": false
    },
    "Action.setUnitHp": {
      "title": "Set unit HP",
      "description": "Set HP (clamped to 0..max).",
      "type": "object",
      "required": [
        "k",
        "unit",
        "value"
      ],
      "properties": {
        "k": {
          "const": "setUnitHp"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "HP or percentage."
        },
        "percent": {
          "type": "boolean",
          "description": "Treat value as a percentage of max HP."
        }
      },
      "additionalProperties": false
    },
    "Action.setUnitInvulnerable": {
      "title": "Set invulnerable",
      "description": "Toggle invulnerability.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "on"
      ],
      "properties": {
        "k": {
          "const": "setUnitInvulnerable"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "on": {
          "type": "boolean",
          "description": "Invulnerable."
        }
      },
      "additionalProperties": false
    },
    "Action.setUnitKinematics": {
      "title": "Set kinematics",
      "description": "Tune kinematic parameters of a unit.",
      "type": "object",
      "required": [
        "k",
        "unit"
      ],
      "properties": {
        "k": {
          "const": "setUnitKinematics"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "friction": {
          "$ref": "#/definitions/Expr",
          "description": "Per-tick velocity multiplier."
        },
        "bounce": {
          "$ref": "#/definitions/Expr",
          "description": "Restitution on collision."
        },
        "minSpeedCutoff": {
          "$ref": "#/definitions/Expr",
          "description": "Speed below which motion stops."
        }
      },
      "additionalProperties": false
    },
    "Action.setUnitMana": {
      "title": "Set unit mana",
      "description": "Set mana (clamped).",
      "type": "object",
      "required": [
        "k",
        "unit",
        "value"
      ],
      "properties": {
        "k": {
          "const": "setUnitMana"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "Mana."
        }
      },
      "additionalProperties": false
    },
    "Action.setUnitOwner": {
      "title": "Change owner",
      "description": "Give a unit to another seat.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "player"
      ],
      "properties": {
        "k": {
          "const": "setUnitOwner"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        }
      },
      "additionalProperties": false
    },
    "Action.setUnitProp": {
      "title": "Set unit stat",
      "description": "Write one live combat or movement stat. It does NOT cover hp, mana, owner or invulnerability - those have their own actions, and a second way to write them would drift. `maxHp` and `maxMana` move the CURRENT value by the same amount, so a buffed unit is not left at 40/900; lowering a max clamps the current down. Values clamp at 0, and attackSpeed / moveSpeed at a small positive floor (0 attacks per second is a division, 0 speed is a unit that never finishes a path). `sightRadius` writes the fog revealer and does nothing on a unit that has none, because giving fog vision to something that had none is a bigger decision than setting a number. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "prop",
        "value"
      ],
      "properties": {
        "k": {
          "const": "setUnitProp"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "prop": {
          "type": "string",
          "enum": [
            "damage",
            "range",
            "attackSpeed",
            "maxHp",
            "armor",
            "magicResist",
            "moveSpeed",
            "maxMana",
            "manaRegen",
            "sightRadius"
          ],
          "description": "Stat to write. `attackSpeed` is ATTACKS PER SECOND, not a cooldown in seconds - there is no attackCooldown field on a unit."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "New value."
        }
      },
      "additionalProperties": false
    },
    "Action.setVar": {
      "title": "Set variable",
      "description": "Write a variable (local, parameter, loop or global). Writing a global with a new value raises variableChanges.",
      "type": "object",
      "required": [
        "k",
        "name",
        "value"
      ],
      "properties": {
        "k": {
          "const": "setVar"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Variable name. The variable must already exist — an assignment does NOT declare one."
        },
        "index": {
          "$ref": "#/definitions/Expr",
          "description": "Element index for an array."
        },
        "value": {
          "$ref": "#/definitions/Expr",
          "description": "New value (coerced to the variable type)."
        }
      },
      "additionalProperties": false
    },
    "Action.showDialog": {
      "title": "Show dialog",
      "description": "Open a modal dialog; clicks fire dialogButton.",
      "type": "object",
      "required": [
        "k",
        "dialogId",
        "title",
        "body",
        "buttons",
        "players"
      ],
      "properties": {
        "k": {
          "const": "showDialog"
        },
        "dialogId": {
          "type": "string",
          "minLength": 1,
          "description": "Dialog id."
        },
        "title": {
          "$ref": "#/definitions/Text",
          "description": "Title template."
        },
        "body": {
          "$ref": "#/definitions/Text",
          "description": "Body template."
        },
        "buttons": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/definitions/Text"
          },
          "description": "Button labels (at least one)."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.showText": {
      "title": "Show text",
      "description": "Show a text banner, resolved in the sim.",
      "type": "object",
      "required": [
        "k",
        "players",
        "text"
      ],
      "properties": {
        "k": {
          "const": "showText"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        },
        "text": {
          "$ref": "#/definitions/Text",
          "description": "Text template (a bare string is accepted)."
        },
        "durationTicks": {
          "type": "integer",
          "minimum": 1,
          "description": "Display time in ticks (default 100)."
        }
      },
      "additionalProperties": false
    },
    "Action.startTimer": {
      "title": "Start timer",
      "description": "Start (or restart) a named timer.",
      "type": "object",
      "required": [
        "k",
        "timer",
        "ticks"
      ],
      "properties": {
        "k": {
          "const": "startTimer"
        },
        "timer": {
          "type": "string",
          "minLength": 1,
          "description": "Timer name."
        },
        "ticks": {
          "$ref": "#/definitions/Expr",
          "description": "Duration in ticks (≥ 1)."
        },
        "periodic": {
          "type": "boolean",
          "description": "Restart on expiry."
        }
      },
      "additionalProperties": false
    },
    "Action.stopCutscene": {
      "title": "Stop cutscene",
      "description": "End running cutscenes for these seats.",
      "type": "object",
      "required": [
        "k",
        "players"
      ],
      "properties": {
        "k": {
          "const": "stopCutscene"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.stopMusic": {
      "title": "Stop music",
      "description": "Silence the soundtrack for these seats. KNOWN LIMITATION: after a `play music` this is exactly what it says. On its own, with the automatic battle shuffler still running, the music stops now and the shuffler starts its next track when the current one would have ended. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "players"
      ],
      "properties": {
        "k": {
          "const": "stopMusic"
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.stopTimer": {
      "title": "Stop timer",
      "description": "Stop and delete a timer.",
      "type": "object",
      "required": [
        "k",
        "timer"
      ],
      "properties": {
        "k": {
          "const": "stopTimer"
        },
        "timer": {
          "type": "string",
          "minLength": 1,
          "description": "Timer name."
        }
      },
      "additionalProperties": false
    },
    "Action.stopTrigger": {
      "title": "Stop trigger",
      "description": "Abandon the rest of this trigger. Not allowed inside functions (use return).",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "stopTrigger"
        }
      },
      "additionalProperties": false
    },
    "Action.timerWindowHide": {
      "title": "Hide a timer window",
      "description": "Take a timer window off screen. The timer keeps running — this is presentation only, and `stop timer` is what stops the clock. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "timer"
      ],
      "properties": {
        "k": {
          "const": "timerWindowHide"
        },
        "timer": {
          "type": "string",
          "minLength": 1,
          "description": "Timer name."
        }
      },
      "additionalProperties": false
    },
    "Action.timerWindowShow": {
      "title": "Show a timer window",
      "description": "Put a named timer's countdown on screen with a title beside it. The window holds only the title and the audience — the clock itself is the timer, so the two can never drift apart. Showing a window for a timer nothing ever starts is a blank countdown, which the map validator reports. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "timer",
        "title",
        "players"
      ],
      "properties": {
        "k": {
          "const": "timerWindowShow"
        },
        "timer": {
          "type": "string",
          "minLength": 1,
          "description": "Timer name, as `start timer` named it."
        },
        "title": {
          "$ref": "#/definitions/Text",
          "description": "Title template shown beside the countdown."
        },
        "players": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          },
          "description": "Seats that see this, or `null` for everyone."
        }
      },
      "additionalProperties": false
    },
    "Action.travelToZone": {
      "title": "Travel to zone",
      "description": "Send the match to another ZONE: a different map, played as part of the same chain, carrying whatever the chain's carry-over list nominates (trigger variables, quests, each seat's resources, hero progress). The zone must be declared in the map's chain table. SINGLE-PLAYER ONLY — a zone hop replaces the map, and multiplayer hashes the terrain every turn, so the engine refuses the hop in a multiplayer match rather than letting it half-work. The zone must also declare `respawn: true`: a zone is REBUILT from its map file every time you enter it, so enemies come back and a building you destroyed is whole again. `respawn: false` (\"remember this zone as I left it\") is refused, because per-zone persistence is not built yet and quietly regenerating the zone instead would make the map lie to you. Nothing happens inside the action itself — it asks for the hop, the rest of the trigger still runs, and the match is replaced a moment later. Two gateways firing on the same tick: the first one wins. Needs map format 3.",
      "type": "object",
      "required": [
        "k",
        "zone"
      ],
      "properties": {
        "k": {
          "const": "travelToZone"
        },
        "zone": {
          "type": "string",
          "description": "Zone id to travel to, as declared in the map's chain table."
        },
        "entryRegion": {
          "type": "string",
          "description": "Region in the destination to arrive at. Overrides the zone's own default; leave empty to use it."
        }
      },
      "additionalProperties": false
    },
    "Action.updateUIFrame": {
      "title": "Update UI frame",
      "description": "Update fields of an existing frame.",
      "type": "object",
      "required": [
        "k",
        "frameId"
      ],
      "properties": {
        "k": {
          "const": "updateUIFrame"
        },
        "frameId": {
          "type": "string",
          "minLength": 1,
          "description": "Frame id."
        },
        "title": {
          "$ref": "#/definitions/Text",
          "description": "Title template."
        },
        "text": {
          "$ref": "#/definitions/Text",
          "description": "Body template."
        },
        "progress": {
          "$ref": "#/definitions/Expr",
          "description": "Progress 0..1."
        },
        "progressColor": {
          "type": "string",
          "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$",
          "description": "Progress bar colour."
        },
        "visible": {
          "type": "boolean",
          "description": "Visible."
        },
        "clickable": {
          "type": "boolean",
          "description": "Arm or disarm this panel as a button. Let this panel be CLICKED. Off by default, and a panel that leaves it off is invisible to the mouse — clicks, drags and wheel zoom pass straight through it to the map, exactly as every panel has always behaved. Turn it on for a panel that is a button, and a click on it fires `uiFrameClicked` for the seat that clicked. A clickable panel still sits UNDER the game's own HUD, so it can never swallow a click meant for a HUD control; and a click only counts if the panel is visible and shown to that seat, which the engine checks on every client."
        }
      },
      "additionalProperties": false
    },
    "Action.victory": {
      "title": "Victory",
      "description": "Declare a seat victorious.",
      "type": "object",
      "required": [
        "k",
        "player"
      ],
      "properties": {
        "k": {
          "const": "victory"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        }
      },
      "additionalProperties": false
    },
    "Action.wait": {
      "title": "Wait",
      "description": "Suspend this trigger for N ticks (min 1) and resume at the next action. Locals and loop state survive, including across save/load. Not allowed inside functions.",
      "type": "object",
      "required": [
        "k",
        "ticks"
      ],
      "properties": {
        "k": {
          "const": "wait"
        },
        "ticks": {
          "$ref": "#/definitions/Expr",
          "description": "Ticks to wait."
        }
      },
      "additionalProperties": false
    },
    "Action.while": {
      "title": "While",
      "description": "Repeat the body while cond holds, at most maxIterations (hard cap 10000) times per run.",
      "type": "object",
      "required": [
        "k",
        "cond",
        "body"
      ],
      "properties": {
        "k": {
          "const": "while"
        },
        "cond": {
          "$ref": "#/definitions/Expr",
          "description": "Loop condition, checked before each iteration."
        },
        "body": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Action"
          },
          "description": "Loop body."
        },
        "maxIterations": {
          "type": "integer",
          "minimum": 1,
          "maximum": 10000,
          "description": "Iteration cap (≤ 10000)."
        }
      },
      "additionalProperties": false
    },
    "CarryOverSpec": {
      "description": "What the author says survives a hop. Absent means \"carry nothing of that kind\"; the bag is opt-in throughout, because the failure mode of carrying too much (a stale quest, a resource the next zone meant to grant) is silent and the failure mode of carrying too little is visible in one playtest.",
      "type": "object",
      "properties": {
        "vars": {
          "description": "Trigger variable names carried verbatim. `'*'` carries every variable.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "quests": {
          "description": "Quest ids carried from `TriggerState.quests`. `'*'` carries every quest.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "resources": {
          "description": "Carry each seat's gold/lumber/stone/oil/arcane.",
          "type": "boolean"
        },
        "heroes": {
          "description": "Hero persist keys carried. `'*'` carries every hero that has one.",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "Event": {
      "description": "A trigger event, discriminated on `k`.",
      "oneOf": [
        {
          "$ref": "#/definitions/Event.mapInit"
        },
        {
          "$ref": "#/definitions/Event.periodic"
        },
        {
          "$ref": "#/definitions/Event.atTick"
        },
        {
          "$ref": "#/definitions/Event.timerExpires"
        },
        {
          "$ref": "#/definitions/Event.unitEntersRegion"
        },
        {
          "$ref": "#/definitions/Event.unitLeavesRegion"
        },
        {
          "$ref": "#/definitions/Event.unitDies"
        },
        {
          "$ref": "#/definitions/Event.unitTrained"
        },
        {
          "$ref": "#/definitions/Event.buildingComplete"
        },
        {
          "$ref": "#/definitions/Event.unitAttacked"
        },
        {
          "$ref": "#/definitions/Event.heroLevels"
        },
        {
          "$ref": "#/definitions/Event.itemPickedUp"
        },
        {
          "$ref": "#/definitions/Event.itemUsed"
        },
        {
          "$ref": "#/definitions/Event.itemPurchased"
        },
        {
          "$ref": "#/definitions/Event.itemSold"
        },
        {
          "$ref": "#/definitions/Event.itemDropped"
        },
        {
          "$ref": "#/definitions/Event.abilityCastStart"
        },
        {
          "$ref": "#/definitions/Event.abilityCastEffect"
        },
        {
          "$ref": "#/definitions/Event.abilityCastFinished"
        },
        {
          "$ref": "#/definitions/Event.abilityCastCancelled"
        },
        {
          "$ref": "#/definitions/Event.orderIssued"
        },
        {
          "$ref": "#/definitions/Event.playerEliminated"
        },
        {
          "$ref": "#/definitions/Event.playerLeaves"
        },
        {
          "$ref": "#/definitions/Event.upgradeComplete"
        },
        {
          "$ref": "#/definitions/Event.variableChanges"
        },
        {
          "$ref": "#/definitions/Event.dialogButton"
        },
        {
          "$ref": "#/definitions/Event.playerChats"
        },
        {
          "$ref": "#/definitions/Event.playerKeyPress"
        },
        {
          "$ref": "#/definitions/Event.projectileHits"
        },
        {
          "$ref": "#/definitions/Event.custom"
        },
        {
          "$ref": "#/definitions/Event.cutsceneFinished"
        },
        {
          "$ref": "#/definitions/Event.unitDamaging"
        },
        {
          "$ref": "#/definitions/Event.unitDamaged"
        },
        {
          "$ref": "#/definitions/Event.uiFrameClicked"
        },
        {
          "$ref": "#/definitions/Event.cityLotBuilt"
        },
        {
          "$ref": "#/definitions/Event.cityLotLevelled"
        },
        {
          "$ref": "#/definitions/Event.cityLotBurnt"
        },
        {
          "$ref": "#/definitions/Event.cityTierReached"
        },
        {
          "$ref": "#/definitions/Event.cityLeanSeason"
        }
      ]
    },
    "Event.abilityCastCancelled": {
      "title": "Cast cancelled",
      "description": "Fires when a cast in progress is interrupted. Event text = the reason: `move`, `death`, `damage`, `invalid` or `superseded`. A cast REFUSED before it started (no mana, on cooldown, out of range, silenced, no line of sight) fires NOTHING, not even this. Sleep also strips a cast without firing it. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "abilityCastCancelled"
        },
        "spellId": {
          "type": "string",
          "description": "Only this spell id; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.abilityCastEffect": {
      "title": "Cast resolves",
      "description": "Fires when the spell's effect actually resolves — the one to hang a consequence on. Event unit = caster, other unit = target unit, player = the caster's seat, `eventSpellId` = the spell, `eventTargetPoint` = the target tile. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "abilityCastEffect"
        },
        "spellId": {
          "type": "string",
          "description": "Only this spell id; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.abilityCastFinished": {
      "title": "Cast finishes",
      "description": "Fires once when a cast ends normally. Exactly-once per cast for both instant and cast-bar spells. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "abilityCastFinished"
        },
        "spellId": {
          "type": "string",
          "description": "Only this spell id; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.abilityCastStart": {
      "title": "Cast starts",
      "description": "Fires once when a cast is committed, after every cost and range check has passed. Event unit = caster, other unit = target unit (0 if none), value = wind-up length in ticks, `eventSpellId` = the spell, `eventTargetPoint` = the target tile. An ordinary RTS or AI cast has NO wind-up (only a possessed hero or a spell with `rtsCastBar` does), so start, effect and finished all land on the same tick. Boss telegraphs use a separate engine and fire none of these. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "abilityCastStart"
        },
        "spellId": {
          "type": "string",
          "description": "Only this spell id; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.atTick": {
      "title": "At tick",
      "description": "Fires once on an exact tick.",
      "type": "object",
      "required": [
        "k",
        "tick"
      ],
      "properties": {
        "k": {
          "const": "atTick"
        },
        "tick": {
          "type": "integer",
          "minimum": 0,
          "description": "Tick number."
        }
      },
      "additionalProperties": false
    },
    "Event.buildingComplete": {
      "title": "Building completes",
      "description": "Fires when construction finishes.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "buildingComplete"
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Event.cityLeanSeason": {
      "title": "City season turns",
      "description": "Fires when the year turns: the lean season's warning goes out (warning), the lean season begins (lean), or it ends (plenty). The year is the same for every seat. Event text = the turn, value = the year (0 the first). Nothing fires where seasons are off (rules.city.seasons false). Needs map format 6.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "cityLeanSeason"
        },
        "phase": {
          "type": "string",
          "enum": [
            "warning",
            "lean",
            "plenty"
          ],
          "description": "Only this turn; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.cityLotBuilt": {
      "title": "City lot built",
      "description": "Fires when a lot finishes building: a home, shop, works or farm, or a service. Event player = its seat, value = the lot id, text = its zone (residential, commercial, industrial, farmland) or its service (water, market...). Needs map format 6.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "cityLotBuilt"
        },
        "player": {
          "type": "integer",
          "description": "Only this seat; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.cityLotBurnt": {
      "title": "City lot burnt down",
      "description": "Fires when a fire burns a lot down (it stands damaged until it rebuilds). Event player = its seat, value = the lot id. Needs map format 6.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "cityLotBurnt"
        },
        "player": {
          "type": "integer",
          "description": "Only this seat; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.cityLotLevelled": {
      "title": "City lot levelled",
      "description": "Fires when a built lot rises a level (to 2 or 3). Event player = its seat, value = the lot id. Needs map format 6.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "cityLotLevelled"
        },
        "player": {
          "type": "integer",
          "description": "Only this seat; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.cityTierReached": {
      "title": "City tier reached",
      "description": "Fires when a seat's city reaches a new settlement tier (1 village, 2 town, 3 city, 4 capital, 5 Concord). Event player = the seat, value = the tier. Needs map format 6.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "cityTierReached"
        },
        "player": {
          "type": "integer",
          "description": "Only this seat; absent = any."
        },
        "tier": {
          "type": "integer",
          "minimum": 1,
          "maximum": 5,
          "description": "Only this tier; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.custom": {
      "title": "Custom event",
      "description": "Fires when `raiseEvent` raises this name (same tick, capped cascade).",
      "type": "object",
      "required": [
        "k",
        "name"
      ],
      "properties": {
        "k": {
          "const": "custom"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Event name."
        }
      },
      "additionalProperties": false
    },
    "Event.cutsceneFinished": {
      "title": "Cutscene finished",
      "description": "Fires when a cutscene ends. Event value: 0 played out, 1 skipped by every human viewer, 2 replaced by another scene, 3 stopped by a trigger.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "cutsceneFinished"
        },
        "sceneId": {
          "type": "string",
          "description": "Only this scene."
        }
      },
      "additionalProperties": false
    },
    "Event.dialogButton": {
      "title": "Dialog button clicked",
      "description": "Fires when a player clicks a trigger dialog button (arrives through lockstep); event value = button index.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "dialogButton"
        },
        "dialogId": {
          "type": "string",
          "minLength": 1,
          "description": "Only this dialog."
        },
        "buttonIndex": {
          "type": "integer",
          "minimum": 0,
          "description": "Only this 0-based button."
        }
      },
      "additionalProperties": false
    },
    "Event.heroLevels": {
      "title": "Hero levels up",
      "description": "Fires when a hero gains a level; event value = new level.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "heroLevels"
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Event.itemDropped": {
      "title": "Item dropped",
      "description": "Fires when a hero drops an item, from the backpack or off the paper doll. A hero DEATH drop fires it too, once per item. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "itemDropped"
        },
        "itemId": {
          "type": "string",
          "description": "Only this item id; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.itemPickedUp": {
      "title": "Item picked up",
      "description": "Fires when a hero picks up an item. NOTE: buying does not fire it — watch `itemPurchased` as well if you mean \"the hero now holds one\".",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "itemPickedUp"
        },
        "itemId": {
          "type": "string",
          "description": "Only this item id; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.itemPurchased": {
      "title": "Item purchased",
      "description": "Fires when a hero buys an item from a shop. Gambling-den rolls do NOT fire it. Event unit = the hero, text = the item id. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "itemPurchased"
        },
        "itemId": {
          "type": "string",
          "description": "Only this item id; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.itemSold": {
      "title": "Item sold",
      "description": "Fires when a hero sells an item. Event value = 1 if sold for XP, 0 if sold for gold. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "itemSold"
        },
        "itemId": {
          "type": "string",
          "description": "Only this item id; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.itemUsed": {
      "title": "Item used",
      "description": "Fires when a hero consumes or activates an item — a potion, a scroll, a town portal, an active. Event unit = the hero, text = the item id. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "itemUsed"
        },
        "itemId": {
          "type": "string",
          "description": "Only this item id; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.mapInit": {
      "title": "Map initialisation",
      "description": "Fires once on the first tick, after every global initialiser.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "mapInit"
        }
      },
      "additionalProperties": false
    },
    "Event.orderIssued": {
      "title": "Order issued",
      "description": "Fires once when a unit or selection is ordered. COVERS every player order (right-click, drag, minimap, HUD, hotkey, queued waypoints), every trigger `order` action, and orders arriving by lockstep, replay, cinematic, possession or a mode's bot. DOES NOT cover the heuristic AI or the LLM commander, which write movement directly instead of issuing commands — so on an AI seat this is near-silent and must not be used to police AI behaviour. Event unit = the LOWEST entity id ordered, other unit = target unit (0 if none), value = how many units the order addressed, text = the order kind, `eventTargetPoint` = the target tile ((-1,-1) for stop/hold). ONE signal per order, not one per unit. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "orderIssued"
        },
        "order": {
          "type": "string",
          "enum": [
            "move",
            "attack_move",
            "attack",
            "stop",
            "hold",
            "patrol",
            "follow"
          ],
          "description": "Only this order kind; absent = any."
        },
        "player": {
          "type": "integer",
          "description": "Only orders from this seat; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.periodic": {
      "title": "Every N ticks",
      "description": "Fires when (tick − offset) is a multiple of everyTicks, from tick `offsetTicks` on.",
      "type": "object",
      "required": [
        "k",
        "everyTicks"
      ],
      "properties": {
        "k": {
          "const": "periodic"
        },
        "everyTicks": {
          "type": "integer",
          "minimum": 1,
          "description": "Period in ticks (20 = 1 second)."
        },
        "offsetTicks": {
          "type": "integer",
          "description": "Phase offset in ticks."
        }
      },
      "additionalProperties": false
    },
    "Event.playerChats": {
      "title": "Player chats",
      "description": "Fires when a seated player sends an all-chat line (team chat and whispers never fire it); event text = the line.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "playerChats"
        },
        "pattern": {
          "type": "string",
          "description": "Text to match; absent = any message."
        },
        "matchMode": {
          "type": "string",
          "enum": [
            "exact",
            "prefix",
            "contains"
          ],
          "description": "How `pattern` matches (default exact)."
        },
        "player": {
          "type": "integer",
          "description": "Only this seat."
        }
      },
      "additionalProperties": false
    },
    "Event.playerEliminated": {
      "title": "Player eliminated",
      "description": "Fires when a seat is eliminated.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "playerEliminated"
        },
        "player": {
          "type": "integer",
          "description": "Only this seat; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.playerKeyPress": {
      "title": "Player presses key",
      "description": "Fires when a player presses or releases a key (through lockstep); event text = key, value = 1 down / 0 up, event target point = the tile under their pointer when the key went down.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "playerKeyPress"
        },
        "key": {
          "type": "string",
          "description": "Key name, e.g. 'w', 'Space', 'ArrowUp'."
        },
        "state": {
          "type": "string",
          "enum": [
            "down",
            "up"
          ],
          "description": "down or up (absent = both)."
        },
        "player": {
          "type": "integer",
          "description": "Only this seat."
        }
      },
      "additionalProperties": false
    },
    "Event.playerLeaves": {
      "title": "Player leaves",
      "description": "Fires on the tick a seat's human leaves the match, under any leaver policy. NOT the same as elimination and neither implies the other: a leaver under `abandon` keeps a living base, and an eliminated player usually stays to watch. Event player = the seat that left. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "playerLeaves"
        },
        "player": {
          "type": "integer",
          "description": "Only this seat; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.projectileHits": {
      "title": "Projectile hits",
      "description": "Fires when a projectile strikes its target or a bomb detonates. Event unit = target, other unit = shooter, value = damage.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "projectileHits"
        },
        "tag": {
          "type": "string",
          "description": "Match the shooter's authored tag, the spell id, the shooter's unit type or the projectile type."
        }
      },
      "additionalProperties": false
    },
    "Event.timerExpires": {
      "title": "Timer expires",
      "description": "Fires when a named timer reaches zero.",
      "type": "object",
      "required": [
        "k",
        "timer"
      ],
      "properties": {
        "k": {
          "const": "timerExpires"
        },
        "timer": {
          "type": "string",
          "minLength": 1,
          "description": "Timer name."
        }
      },
      "additionalProperties": false
    },
    "Event.uiFrameClicked": {
      "title": "UI frame clicked",
      "description": "Fires when a player clicks one of your own HUD frames (arrives through lockstep, like a dialog button). Event player = the seat that clicked, text = the frame id. A click only counts when that seat can really see that frame right now — a frame that was destroyed, hidden, or shown to somebody else fires nothing, however the click arrived. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "uiFrameClicked"
        },
        "frameId": {
          "type": "string",
          "minLength": 1,
          "description": "Only this frame; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.unitAttacked": {
      "title": "Unit attacked",
      "description": "Fires when a unit takes an attack; event value = damage, other unit = attacker.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "unitAttacked"
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Event.unitDamaged": {
      "title": "Unit has taken damage",
      "description": "Fires immediately after the hp is written, for every source of damage. Event damage = the amount that actually landed. Use it to react — a bloodlust stack, a retaliation, \"the boss enrages below half\". The victim of a killing blow is still alive with 0 hp here, so read hp rather than alive. \"set event damage\" does nothing on this event; there is nothing left to change. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "unitDamaged"
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Event.unitDamaging": {
      "title": "Unit is about to take damage",
      "description": "Fires between armour and the hp write, for EVERY source of damage in the game — melee, projectiles, spells, burns, thorns, lava, a collapsing bridge. Unit = the victim, other unit = the dealer (0 for the environment), event damage = the amount about to land. This is the one event whose amount you can change: use \"set event damage\" for a custom armour system, a shield that absorbs part of a hit, or a damage-type table. Triggers fire in authored order and each sees the previous one's result. \"wait\" is not allowed in a trigger with this event, because the hit is only half resolved. Needs map format 3.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "unitDamaging"
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Event.unitDies": {
      "title": "Unit dies",
      "description": "Fires when a unit or building dies. The filter is matched against the unit as it was at death (`aliveOnly` is ignored); event unit = the dead unit, other unit = killer.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "unitDies"
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Event.unitEntersRegion": {
      "title": "Unit enters region",
      "description": "Fires for each unit whose tile moved into the region this tick. Units that start inside do not count.",
      "type": "object",
      "required": [
        "k",
        "region"
      ],
      "properties": {
        "k": {
          "const": "unitEntersRegion"
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "description": "Region id."
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Event.unitLeavesRegion": {
      "title": "Unit leaves region",
      "description": "Fires for each unit that left the region this tick — including by dying or being removed (matched against its last snapshot).",
      "type": "object",
      "required": [
        "k",
        "region"
      ],
      "properties": {
        "k": {
          "const": "unitLeavesRegion"
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "description": "Region id."
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Event.unitTrained": {
      "title": "Unit trained",
      "description": "Fires when production completes a unit.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "unitTrained"
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Event.upgradeComplete": {
      "title": "Upgrade completes",
      "description": "Fires when research completes; event text = upgrade id.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "upgradeComplete"
        },
        "upgradeId": {
          "type": "string",
          "description": "Only this upgrade; absent = any."
        }
      },
      "additionalProperties": false
    },
    "Event.variableChanges": {
      "title": "Variable changes",
      "description": "Fires (in the cascade phase) when a GLOBAL variable is written with a different value.",
      "type": "object",
      "required": [
        "k",
        "name"
      ],
      "properties": {
        "k": {
          "const": "variableChanges"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Global variable name."
        }
      },
      "additionalProperties": false
    },
    "Expr": {
      "description": "An expression node, discriminated on `k`. A bare number, string or boolean is accepted wherever an expression is expected.",
      "oneOf": [
        {
          "type": "number",
          "description": "Literal shorthand: an integer becomes {\"k\":\"int\"}, any other number {\"k\":\"real\"}."
        },
        {
          "type": "string",
          "description": "Literal shorthand: always a text literal {\"k\":\"str\"} — use {\"k\":\"var\",\"name\":…} for a variable."
        },
        {
          "type": "boolean",
          "description": "Literal shorthand for {\"k\":\"bool\"}."
        },
        {
          "$ref": "#/definitions/Expr.int"
        },
        {
          "$ref": "#/definitions/Expr.real"
        },
        {
          "$ref": "#/definitions/Expr.bool"
        },
        {
          "$ref": "#/definitions/Expr.str"
        },
        {
          "$ref": "#/definitions/Expr.point"
        },
        {
          "$ref": "#/definitions/Expr.nullUnit"
        },
        {
          "$ref": "#/definitions/Expr.var"
        },
        {
          "$ref": "#/definitions/Expr.add"
        },
        {
          "$ref": "#/definitions/Expr.sub"
        },
        {
          "$ref": "#/definitions/Expr.mul"
        },
        {
          "$ref": "#/definitions/Expr.div"
        },
        {
          "$ref": "#/definitions/Expr.mod"
        },
        {
          "$ref": "#/definitions/Expr.neg"
        },
        {
          "$ref": "#/definitions/Expr.abs"
        },
        {
          "$ref": "#/definitions/Expr.min"
        },
        {
          "$ref": "#/definitions/Expr.max"
        },
        {
          "$ref": "#/definitions/Expr.clamp"
        },
        {
          "$ref": "#/definitions/Expr.trunc"
        },
        {
          "$ref": "#/definitions/Expr.floor"
        },
        {
          "$ref": "#/definitions/Expr.ceil"
        },
        {
          "$ref": "#/definitions/Expr.round"
        },
        {
          "$ref": "#/definitions/Expr.sqrt"
        },
        {
          "$ref": "#/definitions/Expr.pow"
        },
        {
          "$ref": "#/definitions/Expr.sign"
        },
        {
          "$ref": "#/definitions/Expr.lerp"
        },
        {
          "$ref": "#/definitions/Expr.sin"
        },
        {
          "$ref": "#/definitions/Expr.cos"
        },
        {
          "$ref": "#/definitions/Expr.tan"
        },
        {
          "$ref": "#/definitions/Expr.atan2"
        },
        {
          "$ref": "#/definitions/Expr.asin"
        },
        {
          "$ref": "#/definitions/Expr.acos"
        },
        {
          "$ref": "#/definitions/Expr.exp"
        },
        {
          "$ref": "#/definitions/Expr.log"
        },
        {
          "$ref": "#/definitions/Expr.eq"
        },
        {
          "$ref": "#/definitions/Expr.ne"
        },
        {
          "$ref": "#/definitions/Expr.lt"
        },
        {
          "$ref": "#/definitions/Expr.le"
        },
        {
          "$ref": "#/definitions/Expr.gt"
        },
        {
          "$ref": "#/definitions/Expr.ge"
        },
        {
          "$ref": "#/definitions/Expr.and"
        },
        {
          "$ref": "#/definitions/Expr.or"
        },
        {
          "$ref": "#/definitions/Expr.not"
        },
        {
          "$ref": "#/definitions/Expr.tick"
        },
        {
          "$ref": "#/definitions/Expr.rand"
        },
        {
          "$ref": "#/definitions/Expr.randReal"
        },
        {
          "$ref": "#/definitions/Expr.playerResource"
        },
        {
          "$ref": "#/definitions/Expr.playerPop"
        },
        {
          "$ref": "#/definitions/Expr.playerMaxPop"
        },
        {
          "$ref": "#/definitions/Expr.playerAlive"
        },
        {
          "$ref": "#/definitions/Expr.playerTeam"
        },
        {
          "$ref": "#/definitions/Expr.playerHasUpgrade"
        },
        {
          "$ref": "#/definitions/Expr.isAllied"
        },
        {
          "$ref": "#/definitions/Expr.isEnemy"
        },
        {
          "$ref": "#/definitions/Expr.playerName"
        },
        {
          "$ref": "#/definitions/Expr.playerIsHuman"
        },
        {
          "$ref": "#/definitions/Expr.playerCount"
        },
        {
          "$ref": "#/definitions/Expr.isPointVisibleTo"
        },
        {
          "$ref": "#/definitions/Expr.cityStat"
        },
        {
          "$ref": "#/definitions/Expr.cityCoverageAt"
        },
        {
          "$ref": "#/definitions/Expr.unitProp"
        },
        {
          "$ref": "#/definitions/Expr.unitAboard"
        },
        {
          "$ref": "#/definitions/Expr.unitPoint"
        },
        {
          "$ref": "#/definitions/Expr.entityByAid"
        },
        {
          "$ref": "#/definitions/Expr.unitsInRegion"
        },
        {
          "$ref": "#/definitions/Expr.unitsWithTag"
        },
        {
          "$ref": "#/definitions/Expr.unitsOfPlayer"
        },
        {
          "$ref": "#/definitions/Expr.unitsOfType"
        },
        {
          "$ref": "#/definitions/Expr.heroHasItem"
        },
        {
          "$ref": "#/definitions/Expr.heroItemCount"
        },
        {
          "$ref": "#/definitions/Expr.unitHasBuff"
        },
        {
          "$ref": "#/definitions/Expr.groupCount"
        },
        {
          "$ref": "#/definitions/Expr.groupAt"
        },
        {
          "$ref": "#/definitions/Expr.groupRandom"
        },
        {
          "$ref": "#/definitions/Expr.groupUnion"
        },
        {
          "$ref": "#/definitions/Expr.groupDiff"
        },
        {
          "$ref": "#/definitions/Expr.groupHas"
        },
        {
          "$ref": "#/definitions/Expr.groupEmpty"
        },
        {
          "$ref": "#/definitions/Expr.unitsInRadius"
        },
        {
          "$ref": "#/definitions/Expr.closestUnit"
        },
        {
          "$ref": "#/definitions/Expr.groupSortBy"
        },
        {
          "$ref": "#/definitions/Expr.groupPickN"
        },
        {
          "$ref": "#/definitions/Expr.groupFilter"
        },
        {
          "$ref": "#/definitions/Expr.distance"
        },
        {
          "$ref": "#/definitions/Expr.pointX"
        },
        {
          "$ref": "#/definitions/Expr.pointY"
        },
        {
          "$ref": "#/definitions/Expr.regionCenter"
        },
        {
          "$ref": "#/definitions/Expr.randomPointInRegion"
        },
        {
          "$ref": "#/definitions/Expr.pointInRegion"
        },
        {
          "$ref": "#/definitions/Expr.offsetPoint"
        },
        {
          "$ref": "#/definitions/Expr.polarOffset"
        },
        {
          "$ref": "#/definitions/Expr.angleBetween"
        },
        {
          "$ref": "#/definitions/Expr.eventUnit"
        },
        {
          "$ref": "#/definitions/Expr.eventOtherUnit"
        },
        {
          "$ref": "#/definitions/Expr.eventPlayer"
        },
        {
          "$ref": "#/definitions/Expr.eventValue"
        },
        {
          "$ref": "#/definitions/Expr.eventString"
        },
        {
          "$ref": "#/definitions/Expr.eventDamage"
        },
        {
          "$ref": "#/definitions/Expr.eventDamageType"
        },
        {
          "$ref": "#/definitions/Expr.eventDamageKind"
        },
        {
          "$ref": "#/definitions/Expr.eventSpellId"
        },
        {
          "$ref": "#/definitions/Expr.eventTargetPoint"
        },
        {
          "$ref": "#/definitions/Expr.counter"
        },
        {
          "$ref": "#/definitions/Expr.timerRemaining"
        },
        {
          "$ref": "#/definitions/Expr.timerRunning"
        },
        {
          "$ref": "#/definitions/Expr.triggerFireCount"
        },
        {
          "$ref": "#/definitions/Expr.concat"
        },
        {
          "$ref": "#/definitions/Expr.toStr"
        },
        {
          "$ref": "#/definitions/Expr.subStr"
        },
        {
          "$ref": "#/definitions/Expr.strLen"
        },
        {
          "$ref": "#/definitions/Expr.strFind"
        },
        {
          "$ref": "#/definitions/Expr.strReplace"
        },
        {
          "$ref": "#/definitions/Expr.strSplitPart"
        },
        {
          "$ref": "#/definitions/Expr.strSplitCount"
        },
        {
          "$ref": "#/definitions/Expr.strUpper"
        },
        {
          "$ref": "#/definitions/Expr.strLower"
        },
        {
          "$ref": "#/definitions/Expr.strTrimAscii"
        },
        {
          "$ref": "#/definitions/Expr.strToInt"
        },
        {
          "$ref": "#/definitions/Expr.strToReal"
        },
        {
          "$ref": "#/definitions/Expr.formatTicks"
        },
        {
          "$ref": "#/definitions/Expr.unitVelocity"
        },
        {
          "$ref": "#/definitions/Expr.hashString"
        },
        {
          "$ref": "#/definitions/Expr.verifySaveCode"
        },
        {
          "$ref": "#/definitions/Expr.call"
        },
        {
          "$ref": "#/definitions/Expr.hashtableGet"
        },
        {
          "$ref": "#/definitions/Expr.hashtableHas"
        },
        {
          "$ref": "#/definitions/Expr.hashtableCount"
        }
      ]
    },
    "Expr.abs": {
      "title": "Absolute value",
      "description": "Absolute value. Returns number.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "abs"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.acos": {
      "title": "Arc cosine",
      "description": "Angle in radians whose cosine is A. Outside -1..1 yields 0, never NaN. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "acos"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.add": {
      "title": "A + B",
      "description": "Sum. If either side is a string the two are concatenated. Returns number.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "add"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.and": {
      "title": "A and B",
      "description": "Logical AND. Short-circuits: B is not evaluated when A is false. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "and"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.angleBetween": {
      "title": "Bearing from A to B",
      "description": "Direction from A to B in radians, -pi..pi. Either side may be a unit or a point. Due west is +pi, not -pi, so compare bearings with a tolerance rather than for equality. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "angleBetween"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.asin": {
      "title": "Arc sine",
      "description": "Angle in radians whose sine is A. Outside -1..1 yields 0, never NaN. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "asin"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.atan2": {
      "title": "Angle of a vector",
      "description": "Direction of the vector (X, Y) in radians, -pi..pi. Y comes first, as it does in every atan2. Due west is +pi, not -pi. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "y",
        "x"
      ],
      "properties": {
        "k": {
          "const": "atan2"
        },
        "y": {
          "$ref": "#/definitions/Expr",
          "description": "Vertical component."
        },
        "x": {
          "$ref": "#/definitions/Expr",
          "description": "Horizontal component."
        }
      },
      "additionalProperties": false
    },
    "Expr.bool": {
      "title": "Boolean",
      "description": "true or false. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "v"
      ],
      "properties": {
        "k": {
          "const": "bool"
        },
        "v": {
          "type": "boolean",
          "description": "The value."
        }
      },
      "additionalProperties": false
    },
    "Expr.call": {
      "title": "Call function",
      "description": "Call a user-defined function that declares a return type and yield its return value. Arguments are evaluated left to right and coerced to the parameter types. Recursion past the depth cap yields the zero value. Returns any.",
      "type": "object",
      "required": [
        "k",
        "fn"
      ],
      "properties": {
        "k": {
          "const": "call"
        },
        "fn": {
          "type": "string",
          "minLength": 1,
          "description": "Function name."
        },
        "args": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Expr"
          },
          "description": "Arguments, one per parameter, in order."
        }
      },
      "additionalProperties": false
    },
    "Expr.ceil": {
      "title": "Ceiling",
      "description": "Smallest integer at or above A. Needs map format 3. Returns int.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "ceil"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.cityCoverageAt": {
      "title": "City coverage at tile",
      "description": "How strongly one service reaches a tile, 0..255 (a lot counts a need as met from 1). As of the city's last step. 0 off the map or without a city. Needs map format 6. Returns int.",
      "type": "object",
      "required": [
        "k",
        "at",
        "service"
      ],
      "properties": {
        "k": {
          "const": "cityCoverageAt"
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "The tile."
        },
        "service": {
          "type": "string",
          "enum": [
            "water",
            "safety",
            "faith",
            "fire",
            "health",
            "learning",
            "entertainment",
            "market",
            "park",
            "academy"
          ],
          "description": "The service."
        }
      },
      "additionalProperties": false
    },
    "Expr.cityStat": {
      "title": "City statistic",
      "description": "One number from a seat's city: population, jobs, lots, settlement tier (0 hamlet .. 5 Concord), hall tier (0 none .. 3 castle), tax percent, income and upkeep a game minute, demand per zone (-100..100), the share of homes fed (percent), harmony (percent, 100 neutral), blight and crime (0..255), lots burning, homes in a plague outbreak. As of the city's last step (once a second). 0 without a city. Needs map format 6. Returns int.",
      "type": "object",
      "required": [
        "k",
        "player",
        "stat"
      ],
      "properties": {
        "k": {
          "const": "cityStat"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "stat": {
          "type": "string",
          "enum": [
            "population",
            "jobs",
            "lots",
            "tier",
            "hallTier",
            "taxPercent",
            "income",
            "upkeep",
            "demandResidential",
            "demandCommercial",
            "demandIndustrial",
            "foodPercent",
            "harmony",
            "blight",
            "crime",
            "burning",
            "plague"
          ],
          "description": "Which number."
        }
      },
      "additionalProperties": false
    },
    "Expr.clamp": {
      "title": "Clamp",
      "description": "A limited to [lo, hi]; reversed bounds are swapped. Returns number.",
      "type": "object",
      "required": [
        "k",
        "a",
        "lo",
        "hi"
      ],
      "properties": {
        "k": {
          "const": "clamp"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Value to clamp."
        },
        "lo": {
          "$ref": "#/definitions/Expr",
          "description": "Lower bound."
        },
        "hi": {
          "$ref": "#/definitions/Expr",
          "description": "Upper bound."
        }
      },
      "additionalProperties": false
    },
    "Expr.closestUnit": {
      "title": "Closest unit",
      "description": "The nearest matching unit to a point or unit, or no unit. A tie goes to the lowest entity id, so the answer never depends on iteration order. Needs map format 3. Returns unit.",
      "type": "object",
      "required": [
        "k",
        "at"
      ],
      "properties": {
        "k": {
          "const": "closestUnit"
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Where to measure from — a point, or a unit whose tile is used."
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        },
        "maxRadius": {
          "$ref": "#/definitions/Expr",
          "description": "Ignore anything further than this many tiles; absent = search the whole map."
        }
      },
      "additionalProperties": false
    },
    "Expr.concat": {
      "title": "Concatenate",
      "description": "A joined with B as strings. Returns string.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "concat"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.cos": {
      "title": "Cosine",
      "description": "Cosine of an angle in radians. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "cos"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Angle in RADIANS. Multiply by 57.29577951308232 for the degrees `createUnits.facing` wants."
        }
      },
      "additionalProperties": false
    },
    "Expr.counter": {
      "title": "Counter value",
      "description": "Current value of an on-screen counter. Returns number.",
      "type": "object",
      "required": [
        "k",
        "id"
      ],
      "properties": {
        "k": {
          "const": "counter"
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Counter id."
        }
      },
      "additionalProperties": false
    },
    "Expr.distance": {
      "title": "Distance",
      "description": "Euclidean tile distance; either side may be a unit or a point. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "distance"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.div": {
      "title": "A ÷ B",
      "description": "Quotient. Division by zero yields 0 — never Infinity or NaN. Returns number.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "div"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.entityByAid": {
      "title": "Unit by authored id",
      "description": "The placed entity carrying this authored id, or no unit. Returns unit.",
      "type": "object",
      "required": [
        "k",
        "aid"
      ],
      "properties": {
        "k": {
          "const": "entityByAid"
        },
        "aid": {
          "type": "string",
          "description": "Authored id from the entity inspector."
        }
      },
      "additionalProperties": false
    },
    "Expr.eq": {
      "title": "A = B",
      "description": "Equality. Strings compare by code unit; groups element-wise; points by x then y. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "eq"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.eventDamage": {
      "title": "Event damage",
      "description": "The damage amount as it stands right now. Inside \"unit is about to take damage\" that is after every earlier trigger's \"set event damage\", so armour triggers compose; inside \"unit has taken damage\" it is the amount that landed. 0 on any other event. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "eventDamage"
        }
      },
      "additionalProperties": false
    },
    "Expr.eventDamageKind": {
      "title": "Event damage kind",
      "description": "Which door the damage came through: melee, projectile, spell, burn, thorns, cleave, and the rest. This is the axis a damage-type table or a \"spell damage only\" shield switches on. Empty on a non-damage event. Needs map format 3. Returns string.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "eventDamageKind"
        }
      },
      "additionalProperties": false
    },
    "Expr.eventDamageType": {
      "title": "Event damage element",
      "description": "The element the damage site tracks — physical, fire, and so on — or empty where it tracks none (a lava tile, a collapsing bridge). A different axis from the damage kind: a projectile can be fire and a spell can be physical. Needs map format 3. Returns string.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "eventDamageType"
        }
      },
      "additionalProperties": false
    },
    "Expr.eventOtherUnit": {
      "title": "Other unit",
      "description": "The killer for unitDies, the attacker for unitAttacked, the shooter for projectileHits. Returns unit.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "eventOtherUnit"
        }
      },
      "additionalProperties": false
    },
    "Expr.eventPlayer": {
      "title": "Triggering player",
      "description": "The seat the event is about, or -1. Returns player.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "eventPlayer"
        }
      },
      "additionalProperties": false
    },
    "Expr.eventSpellId": {
      "title": "Event spell",
      "description": "The spell id of an `abilityCast*` event; '' on every other event. A separate node from `eventString`, which on a cancelled cast carries the cancel REASON. Needs map format 3. Returns string.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "eventSpellId"
        }
      },
      "additionalProperties": false
    },
    "Expr.eventString": {
      "title": "Event text",
      "description": "String payload: upgrade id, item id, chat text, custom event name. Returns string.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "eventString"
        }
      },
      "additionalProperties": false
    },
    "Expr.eventTargetPoint": {
      "title": "Event target point",
      "description": "The target TILE of an `abilityCast*` or `orderIssued` event, or the tile under the pointer when a `playerKeyPress` key went down. (-1, -1) when the event had no ground target — a unit-targeted cast, a stop / hold order, a key released, or the pointer off the ground. Tile 0,0 is a legal map corner, so 0 could not be the sentinel. Needs map format 3. Returns point.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "eventTargetPoint"
        }
      },
      "additionalProperties": false
    },
    "Expr.eventUnit": {
      "title": "Triggering unit",
      "description": "The unit the event is about (entered, died, trained, was attacked…). No unit when the event has none. Returns unit.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "eventUnit"
        }
      },
      "additionalProperties": false
    },
    "Expr.eventValue": {
      "title": "Event value",
      "description": "Numeric payload: dialog button index, hero level, damage, raised value. Returns number.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "eventValue"
        }
      },
      "additionalProperties": false
    },
    "Expr.exp": {
      "title": "e to the power A",
      "description": "e raised to A. A non-finite result yields 0. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "exp"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.floor": {
      "title": "Floor",
      "description": "Largest integer at or below A. Needs map format 3. Returns int.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "floor"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.formatTicks": {
      "title": "Ticks as a clock",
      "description": "Ticks rendered as a clock. 20 ticks is one second; negatives clamp to 0. Minutes are not capped at 59, so an hour of \"mm:ss\" is \"60:00\". Needs map format 3. Returns string.",
      "type": "object",
      "required": [
        "k",
        "ticks"
      ],
      "properties": {
        "k": {
          "const": "formatTicks"
        },
        "ticks": {
          "$ref": "#/definitions/Expr",
          "description": "Tick count."
        },
        "format": {
          "type": "string",
          "enum": [
            "mm:ss",
            "m:ss",
            "h:mm:ss",
            "ss.t"
          ],
          "description": "Layout (default mm:ss)."
        }
      },
      "additionalProperties": false
    },
    "Expr.ge": {
      "title": "A ≥ B",
      "description": "Greater than or equal. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "ge"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.groupAt": {
      "title": "Unit at index",
      "description": "0-based element of the sorted group; out of range gives no unit. Returns unit.",
      "type": "object",
      "required": [
        "k",
        "group",
        "index"
      ],
      "properties": {
        "k": {
          "const": "groupAt"
        },
        "group": {
          "$ref": "#/definitions/Expr",
          "description": "The group."
        },
        "index": {
          "$ref": "#/definitions/Expr",
          "description": "0-based index."
        }
      },
      "additionalProperties": false
    },
    "Expr.groupCount": {
      "title": "Group size",
      "description": "Number of units in a group. Returns int.",
      "type": "object",
      "required": [
        "k",
        "group"
      ],
      "properties": {
        "k": {
          "const": "groupCount"
        },
        "group": {
          "$ref": "#/definitions/Expr",
          "description": "The group."
        }
      },
      "additionalProperties": false
    },
    "Expr.groupDiff": {
      "title": "Group difference",
      "description": "Members of A not in B. Returns unitGroup.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "groupDiff"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.groupEmpty": {
      "title": "Empty group",
      "description": "A group with no units. Returns unitGroup.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "groupEmpty"
        }
      },
      "additionalProperties": false
    },
    "Expr.groupFilter": {
      "title": "Group matching a filter",
      "description": "Members of the group that match the filter. The one way to narrow a group you already hold without rebuilding it from the world. Needs map format 3. Returns unitGroup.",
      "type": "object",
      "required": [
        "k",
        "group",
        "filter"
      ],
      "properties": {
        "k": {
          "const": "groupFilter"
        },
        "group": {
          "$ref": "#/definitions/Expr",
          "description": "The group."
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Expr.groupHas": {
      "title": "Group contains",
      "description": "True when the unit is in the group. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "group",
        "unit"
      ],
      "properties": {
        "k": {
          "const": "groupHas"
        },
        "group": {
          "$ref": "#/definitions/Expr",
          "description": "The group."
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        }
      },
      "additionalProperties": false
    },
    "Expr.groupPickN": {
      "title": "N random units of group",
      "description": "At most N random members, sorted. Consumes exactly min(N, group size) PRNG draws — both numbers are hashed sim state, so every client draws the same count. Needs map format 3. Returns unitGroup.",
      "type": "object",
      "required": [
        "k",
        "group",
        "n"
      ],
      "properties": {
        "k": {
          "const": "groupPickN"
        },
        "group": {
          "$ref": "#/definitions/Expr",
          "description": "The group."
        },
        "n": {
          "$ref": "#/definitions/Expr",
          "description": "How many to pick. 0 or less gives an empty group."
        }
      },
      "additionalProperties": false
    },
    "Expr.groupRandom": {
      "title": "Random unit of group",
      "description": "A random member (one PRNG draw, even for an empty group). Returns unit.",
      "type": "object",
      "required": [
        "k",
        "group"
      ],
      "properties": {
        "k": {
          "const": "groupRandom"
        },
        "group": {
          "$ref": "#/definitions/Expr",
          "description": "The group."
        }
      },
      "additionalProperties": false
    },
    "Expr.groupSortBy": {
      "title": "Group in order",
      "description": "The group reordered. Ties always break on the LOWEST entity id, in both directions — so 'desc' reverses the keys but is not exactly the reverse of 'asc' when two units share a key, and \"the weakest\" and \"the strongest\" pick the same one of a tied pair. The result is NOT id-sorted, so storing it in a unitGroup variable loses the order (variables are canonicalised on write) — use it inline, with `forEachUnit` or `groupAt`. Needs map format 3. Returns unitGroup.",
      "type": "object",
      "required": [
        "k",
        "group",
        "by"
      ],
      "properties": {
        "k": {
          "const": "groupSortBy"
        },
        "group": {
          "$ref": "#/definitions/Expr",
          "description": "The group."
        },
        "by": {
          "type": "string",
          "enum": [
            "hp",
            "maxHp",
            "hpPercent",
            "mana",
            "maxMana",
            "level",
            "xp",
            "kills",
            "x",
            "y",
            "distance",
            "id"
          ],
          "description": "What to order on."
        },
        "order": {
          "type": "string",
          "enum": [
            "asc",
            "desc"
          ],
          "description": "'asc' (default) or 'desc'."
        },
        "from": {
          "$ref": "#/definitions/Expr",
          "description": "Reference point for by: 'distance'; absent measures from tile (0, 0)."
        }
      },
      "additionalProperties": false
    },
    "Expr.groupUnion": {
      "title": "Group union",
      "description": "Members of A or B. Returns unitGroup.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "groupUnion"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.gt": {
      "title": "A > B",
      "description": "Greater than. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "gt"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.hashString": {
      "title": "Hash text",
      "description": "Deterministic 32-bit FNV-1a hash. Returns int.",
      "type": "object",
      "required": [
        "k",
        "text"
      ],
      "properties": {
        "k": {
          "const": "hashString"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "The text."
        }
      },
      "additionalProperties": false
    },
    "Expr.hashtableCount": {
      "title": "Hashtable size",
      "description": "Number of entries in the table, or under one parent key when key1 is set. Returns int.",
      "type": "object",
      "required": [
        "k",
        "table"
      ],
      "properties": {
        "k": {
          "const": "hashtableCount"
        },
        "table": {
          "type": "string",
          "minLength": 1,
          "description": "Hashtable name."
        },
        "key1": {
          "$ref": "#/definitions/Expr",
          "description": "Parent key to count children of."
        }
      },
      "additionalProperties": false
    },
    "Expr.hashtableGet": {
      "title": "Hashtable value",
      "description": "Value stored under (key1, key2), or the zero value of the table type. Keys are integers or strings. Returns any.",
      "type": "object",
      "required": [
        "k",
        "table",
        "key1",
        "key2"
      ],
      "properties": {
        "k": {
          "const": "hashtableGet"
        },
        "table": {
          "type": "string",
          "minLength": 1,
          "description": "Hashtable name."
        },
        "key1": {
          "$ref": "#/definitions/Expr",
          "description": "Parent key (int or string)."
        },
        "key2": {
          "$ref": "#/definitions/Expr",
          "description": "Child key (int or string)."
        }
      },
      "additionalProperties": false
    },
    "Expr.hashtableHas": {
      "title": "Hashtable has key",
      "description": "True when a value is stored under (key1, key2). Returns bool.",
      "type": "object",
      "required": [
        "k",
        "table",
        "key1",
        "key2"
      ],
      "properties": {
        "k": {
          "const": "hashtableHas"
        },
        "table": {
          "type": "string",
          "minLength": 1,
          "description": "Hashtable name."
        },
        "key1": {
          "$ref": "#/definitions/Expr",
          "description": "Parent key."
        },
        "key2": {
          "$ref": "#/definitions/Expr",
          "description": "Child key."
        }
      },
      "additionalProperties": false
    },
    "Expr.heroHasItem": {
      "title": "Unit has item",
      "description": "True when the unit holds this item in its BACKPACK or has it EQUIPPED. Both halves, because \"does he have the crown\" does not mean \"in his bag but not on his head\". Needs map format 3. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "itemId"
      ],
      "properties": {
        "k": {
          "const": "heroHasItem"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "itemId": {
          "type": "string",
          "description": "Item id to look for."
        }
      },
      "additionalProperties": false
    },
    "Expr.heroItemCount": {
      "title": "Unit item count",
      "description": "How many of this item the unit holds: backpack stack counts summed, plus one for each equipped copy. Needs map format 3. Returns int.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "itemId"
      ],
      "properties": {
        "k": {
          "const": "heroItemCount"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "itemId": {
          "type": "string",
          "description": "Item id to count."
        }
      },
      "additionalProperties": false
    },
    "Expr.int": {
      "title": "Integer",
      "description": "An integer literal. Non-integers are truncated. Returns int.",
      "type": "object",
      "required": [
        "k",
        "v"
      ],
      "properties": {
        "k": {
          "const": "int"
        },
        "v": {
          "type": "number",
          "description": "The value."
        }
      },
      "additionalProperties": false
    },
    "Expr.isAllied": {
      "title": "Players are allied",
      "description": "True when seats A and B are on the same team. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "isAllied"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.isEnemy": {
      "title": "Players are enemies",
      "description": "True when seats A and B are not allied. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "isEnemy"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.isPointVisibleTo": {
      "title": "Seat can see tile",
      "description": "True when THAT SEAT's own units or completed buildings reveal the tile right now. It is the simulation's own vision test, not the fog you are looking at, so it answers the same on every client and in a replay. Allied vision is NOT folded in: ask about each ally, or use \"players are allied\". A seat that is not in the lobby owns nothing and answers false; the creep seat answers like any other. It does not know about night, possession or a submerged submarine's halved sight — it is the daylight baseline radius plus the sightRadius buff. It SCANS every revealer in the world, so it costs about what \"units of player\" costs; do not put it inside a big loop. Needs map format 3. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "player",
        "at"
      ],
      "properties": {
        "k": {
          "const": "isPointVisibleTo"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Tile to test."
        }
      },
      "additionalProperties": false
    },
    "Expr.le": {
      "title": "A ≤ B",
      "description": "Less than or equal. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "le"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.lerp": {
      "title": "Interpolate",
      "description": "A blended toward B by T: A + (B - A) x T. T is NOT clamped, so 2 overshoots and -1 extrapolates backwards. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b",
        "t"
      ],
      "properties": {
        "k": {
          "const": "lerp"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        },
        "t": {
          "$ref": "#/definitions/Expr",
          "description": "Blend factor; 0 gives A, 1 gives B."
        }
      },
      "additionalProperties": false
    },
    "Expr.log": {
      "title": "Natural logarithm",
      "description": "Natural log of A. A at or below zero yields 0, never -Infinity and never NaN. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "log"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.lt": {
      "title": "A < B",
      "description": "Less than. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "lt"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.max": {
      "title": "Maximum",
      "description": "The larger of A and B. Returns number.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "max"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.min": {
      "title": "Minimum",
      "description": "The smaller of A and B. Returns number.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "min"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.mod": {
      "title": "A mod B",
      "description": "Remainder (sign of A). Modulo by zero yields 0. Returns number.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "mod"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.mul": {
      "title": "A × B",
      "description": "Product. Returns number.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "mul"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.ne": {
      "title": "A ≠ B",
      "description": "Inequality. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "ne"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.neg": {
      "title": "Negate",
      "description": "Arithmetic negation. Returns number.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "neg"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.not": {
      "title": "Not A",
      "description": "Logical negation. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "not"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.nullUnit": {
      "title": "No unit",
      "description": "Entity id 0. Every property of it reads as a zero value. Returns unit.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "nullUnit"
        }
      },
      "additionalProperties": false
    },
    "Expr.offsetPoint": {
      "title": "Offset point",
      "description": "A point moved by (dx, dy) tiles. Returns point.",
      "type": "object",
      "required": [
        "k",
        "p",
        "dx",
        "dy"
      ],
      "properties": {
        "k": {
          "const": "offsetPoint"
        },
        "p": {
          "$ref": "#/definitions/Expr",
          "description": "Point or unit."
        },
        "dx": {
          "$ref": "#/definitions/Expr",
          "description": "Tiles X."
        },
        "dy": {
          "$ref": "#/definitions/Expr",
          "description": "Tiles Y."
        }
      },
      "additionalProperties": false
    },
    "Expr.or": {
      "title": "A or B",
      "description": "Logical OR. Short-circuits: B is not evaluated when A is true. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "or"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.playerAlive": {
      "title": "Player is alive",
      "description": "True while the seat has not been eliminated or defeated. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "player"
      ],
      "properties": {
        "k": {
          "const": "playerAlive"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        }
      },
      "additionalProperties": false
    },
    "Expr.playerCount": {
      "title": "Number of players",
      "description": "How many seats match. The creep and neutral seats are never counted, so \"alive\" on a two-player map with creeps answers 2. Needs map format 3. Returns int.",
      "type": "object",
      "required": [
        "k",
        "of"
      ],
      "properties": {
        "k": {
          "const": "playerCount"
        },
        "of": {
          "type": "string",
          "enum": [
            "seated",
            "alive",
            "human",
            "ai"
          ],
          "description": "Which seats to count."
        }
      },
      "additionalProperties": false
    },
    "Expr.playerHasUpgrade": {
      "title": "Player has upgrade",
      "description": "True once the seat has completed the research. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "player",
        "upgradeId"
      ],
      "properties": {
        "k": {
          "const": "playerHasUpgrade"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "upgradeId": {
          "type": "string",
          "description": "Upgrade id."
        }
      },
      "additionalProperties": false
    },
    "Expr.playerIsHuman": {
      "title": "A human is at this seat",
      "description": "True when a human is present: a human slot whose player has not left. An AI seat is false, and so is a seat whose human has gone. Needs map format 3. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "player"
      ],
      "properties": {
        "k": {
          "const": "playerIsHuman"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        }
      },
      "additionalProperties": false
    },
    "Expr.playerMaxPop": {
      "title": "Player's population cap",
      "description": "Population cap. Returns int.",
      "type": "object",
      "required": [
        "k",
        "player"
      ],
      "properties": {
        "k": {
          "const": "playerMaxPop"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        }
      },
      "additionalProperties": false
    },
    "Expr.playerName": {
      "title": "Player's name",
      "description": "Display name of a seat. Today this is always \"Player 1\", \"Player 2\"… — the lobby name is a per-client string and a trigger variable is hashed, so it is deliberately not read here. Needs map format 3. Returns string.",
      "type": "object",
      "required": [
        "k",
        "player"
      ],
      "properties": {
        "k": {
          "const": "playerName"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        }
      },
      "additionalProperties": false
    },
    "Expr.playerPop": {
      "title": "Player's population",
      "description": "Population in use. Returns int.",
      "type": "object",
      "required": [
        "k",
        "player"
      ],
      "properties": {
        "k": {
          "const": "playerPop"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        }
      },
      "additionalProperties": false
    },
    "Expr.playerResource": {
      "title": "Player's resource",
      "description": "Current stock of one resource. Returns int.",
      "type": "object",
      "required": [
        "k",
        "player",
        "resource"
      ],
      "properties": {
        "k": {
          "const": "playerResource"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "resource": {
          "type": "string",
          "enum": [
            "gold",
            "lumber",
            "stone",
            "oil"
          ],
          "description": "Resource kind."
        }
      },
      "additionalProperties": false
    },
    "Expr.playerTeam": {
      "title": "Player's team",
      "description": "Team id of the seat, or -1. Returns int.",
      "type": "object",
      "required": [
        "k",
        "player"
      ],
      "properties": {
        "k": {
          "const": "playerTeam"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        }
      },
      "additionalProperties": false
    },
    "Expr.point": {
      "title": "Point",
      "description": "A tile coordinate built from two numbers. Returns point.",
      "type": "object",
      "required": [
        "k",
        "x",
        "y"
      ],
      "properties": {
        "k": {
          "const": "point"
        },
        "x": {
          "$ref": "#/definitions/Expr",
          "description": "Tile X."
        },
        "y": {
          "$ref": "#/definitions/Expr",
          "description": "Tile Y."
        }
      },
      "additionalProperties": false
    },
    "Expr.pointInRegion": {
      "title": "Point in region",
      "description": "True when the point (or unit) lies inside the region. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "p",
        "region"
      ],
      "properties": {
        "k": {
          "const": "pointInRegion"
        },
        "p": {
          "$ref": "#/definitions/Expr",
          "description": "Point or unit."
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "description": "Region id."
        }
      },
      "additionalProperties": false
    },
    "Expr.pointX": {
      "title": "Point X",
      "description": "X of a point. Returns number.",
      "type": "object",
      "required": [
        "k",
        "p"
      ],
      "properties": {
        "k": {
          "const": "pointX"
        },
        "p": {
          "$ref": "#/definitions/Expr",
          "description": "The point."
        }
      },
      "additionalProperties": false
    },
    "Expr.pointY": {
      "title": "Point Y",
      "description": "Y of a point. Returns number.",
      "type": "object",
      "required": [
        "k",
        "p"
      ],
      "properties": {
        "k": {
          "const": "pointY"
        },
        "p": {
          "$ref": "#/definitions/Expr",
          "description": "The point."
        }
      },
      "additionalProperties": false
    },
    "Expr.polarOffset": {
      "title": "Point at an angle",
      "description": "A point (or unit) moved `distance` tiles along `angle`. With `angleBetween` this is the whole of \"spawn behind the hero\", \"ring of totems\", \"fire at this bearing\". Needs map format 3. Returns point.",
      "type": "object",
      "required": [
        "k",
        "p",
        "angle",
        "distance"
      ],
      "properties": {
        "k": {
          "const": "polarOffset"
        },
        "p": {
          "$ref": "#/definitions/Expr",
          "description": "Point or unit to start from."
        },
        "angle": {
          "$ref": "#/definitions/Expr",
          "description": "Direction in RADIANS. Multiply by 57.29577951308232 for the degrees `createUnits.facing` wants."
        },
        "distance": {
          "$ref": "#/definitions/Expr",
          "description": "Distance in tiles; negative goes the other way."
        }
      },
      "additionalProperties": false
    },
    "Expr.pow": {
      "title": "A to the power B",
      "description": "A raised to B. A non-finite result yields 0. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "pow"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.rand": {
      "title": "Random integer",
      "description": "Inclusive random integer from the synchronised game PRNG. Always consumes exactly one draw. Returns int.",
      "type": "object",
      "required": [
        "k",
        "min",
        "max"
      ],
      "properties": {
        "k": {
          "const": "rand"
        },
        "min": {
          "$ref": "#/definitions/Expr",
          "description": "Lower bound (inclusive)."
        },
        "max": {
          "$ref": "#/definitions/Expr",
          "description": "Upper bound (inclusive)."
        }
      },
      "additionalProperties": false
    },
    "Expr.randReal": {
      "title": "Random real",
      "description": "Random real in [min, max) from the synchronised game PRNG. Always consumes exactly one draw, even when min equals max, because a conditional draw would advance the stream on one client and not another. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "min",
        "max"
      ],
      "properties": {
        "k": {
          "const": "randReal"
        },
        "min": {
          "$ref": "#/definitions/Expr",
          "description": "Lower bound (inclusive)."
        },
        "max": {
          "$ref": "#/definitions/Expr",
          "description": "Upper bound (exclusive)."
        }
      },
      "additionalProperties": false
    },
    "Expr.randomPointInRegion": {
      "title": "Random point in region",
      "description": "Random tile inside the region (always two PRNG draws). Returns point.",
      "type": "object",
      "required": [
        "k",
        "region"
      ],
      "properties": {
        "k": {
          "const": "randomPointInRegion"
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "description": "Region id."
        }
      },
      "additionalProperties": false
    },
    "Expr.real": {
      "title": "Real number",
      "description": "A real-number literal. Returns real.",
      "type": "object",
      "required": [
        "k",
        "v"
      ],
      "properties": {
        "k": {
          "const": "real"
        },
        "v": {
          "type": "number",
          "description": "The value."
        }
      },
      "additionalProperties": false
    },
    "Expr.regionCenter": {
      "title": "Region centre",
      "description": "Integer centre tile of a region. Returns point.",
      "type": "object",
      "required": [
        "k",
        "region"
      ],
      "properties": {
        "k": {
          "const": "regionCenter"
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "description": "Region id."
        }
      },
      "additionalProperties": false
    },
    "Expr.round": {
      "title": "Round",
      "description": "Nearest integer, halves going toward +Infinity — so round(2.5) is 3 and round(-2.5) is -2. Needs map format 3. Returns int.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "round"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.sign": {
      "title": "Sign",
      "description": "-1 for a negative A, 1 for a positive one, 0 for zero. Needs map format 3. Returns int.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "sign"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.sin": {
      "title": "Sine",
      "description": "Sine of an angle in radians. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "sin"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Angle in RADIANS. Multiply by 57.29577951308232 for the degrees `createUnits.facing` wants."
        }
      },
      "additionalProperties": false
    },
    "Expr.sqrt": {
      "title": "Square root",
      "description": "Square root. A negative A yields 0, never NaN. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "sqrt"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.str": {
      "title": "Text",
      "description": "A string literal. Returns string.",
      "type": "object",
      "required": [
        "k",
        "v"
      ],
      "properties": {
        "k": {
          "const": "str"
        },
        "v": {
          "type": "string",
          "description": "The value."
        }
      },
      "additionalProperties": false
    },
    "Expr.strFind": {
      "title": "Find text",
      "description": "0-based index of the first occurrence, or -1. An empty search text yields -1. Needs map format 3. Returns int.",
      "type": "object",
      "required": [
        "k",
        "text",
        "find"
      ],
      "properties": {
        "k": {
          "const": "strFind"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "Text to search."
        },
        "find": {
          "$ref": "#/definitions/Expr",
          "description": "Text to look for."
        },
        "start": {
          "$ref": "#/definitions/Expr",
          "description": "Index to start from; negative counts as 0."
        }
      },
      "additionalProperties": false
    },
    "Expr.strLen": {
      "title": "Text length",
      "description": "Length in UTF-16 code units. Returns int.",
      "type": "object",
      "required": [
        "k",
        "text"
      ],
      "properties": {
        "k": {
          "const": "strLen"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "The text."
        }
      },
      "additionalProperties": false
    },
    "Expr.strLower": {
      "title": "Lower case",
      "description": "ASCII A-Z lowered to a-z. Every other code unit is left alone — see `strUpper`. Needs map format 3. Returns string.",
      "type": "object",
      "required": [
        "k",
        "text"
      ],
      "properties": {
        "k": {
          "const": "strLower"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "The text."
        }
      },
      "additionalProperties": false
    },
    "Expr.strReplace": {
      "title": "Replace text",
      "description": "Every occurrence replaced. An empty search text returns the text unchanged rather than inserting between every character. Needs map format 3. Returns string.",
      "type": "object",
      "required": [
        "k",
        "text",
        "find",
        "to"
      ],
      "properties": {
        "k": {
          "const": "strReplace"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "Source text."
        },
        "find": {
          "$ref": "#/definitions/Expr",
          "description": "Text to replace."
        },
        "to": {
          "$ref": "#/definitions/Expr",
          "description": "Replacement."
        }
      },
      "additionalProperties": false
    },
    "Expr.strSplitCount": {
      "title": "Split count",
      "description": "How many fields `strSplitPart` can reach: separator count plus one, and 0 for empty text. Needs map format 3. Returns int.",
      "type": "object",
      "required": [
        "k",
        "text",
        "sep"
      ],
      "properties": {
        "k": {
          "const": "strSplitCount"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "Source text."
        },
        "sep": {
          "$ref": "#/definitions/Expr",
          "description": "Separator."
        }
      },
      "additionalProperties": false
    },
    "Expr.strSplitPart": {
      "title": "Split and take",
      "description": "Field `index` of the text split on `sep`, or empty text when the index is out of range. An empty separator treats the whole text as field 0. Needs map format 3. Returns string.",
      "type": "object",
      "required": [
        "k",
        "text",
        "sep",
        "index"
      ],
      "properties": {
        "k": {
          "const": "strSplitPart"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "Source text."
        },
        "sep": {
          "$ref": "#/definitions/Expr",
          "description": "Separator."
        },
        "index": {
          "$ref": "#/definitions/Expr",
          "description": "0-based field index."
        }
      },
      "additionalProperties": false
    },
    "Expr.strToInt": {
      "title": "Text to integer",
      "description": "Parse text as a number and truncate toward zero. Anything unparseable yields 0. Surrounding ASCII whitespace is ignored. Needs map format 3. Returns int.",
      "type": "object",
      "required": [
        "k",
        "text"
      ],
      "properties": {
        "k": {
          "const": "strToInt"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "The text."
        }
      },
      "additionalProperties": false
    },
    "Expr.strToReal": {
      "title": "Text to real",
      "description": "Parse text as a real number. Anything unparseable, infinite or NaN yields 0. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "text"
      ],
      "properties": {
        "k": {
          "const": "strToReal"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "The text."
        }
      },
      "additionalProperties": false
    },
    "Expr.strTrimAscii": {
      "title": "Trim spaces",
      "description": "Strip leading and trailing ASCII whitespace (space, tab, newline, carriage return, vertical tab, form feed). Non-breaking spaces and the byte-order mark are NOT stripped, because the Unicode whitespace set has grown between browser releases. Needs map format 3. Returns string.",
      "type": "object",
      "required": [
        "k",
        "text"
      ],
      "properties": {
        "k": {
          "const": "strTrimAscii"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "The text."
        }
      },
      "additionalProperties": false
    },
    "Expr.strUpper": {
      "title": "Upper case",
      "description": "ASCII a-z raised to A-Z. Every other code unit is left alone, ON PURPOSE: Unicode case mapping depends on which Unicode revision the browser shipped, and these strings are hashed. Needs map format 3. Returns string.",
      "type": "object",
      "required": [
        "k",
        "text"
      ],
      "properties": {
        "k": {
          "const": "strUpper"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "The text."
        }
      },
      "additionalProperties": false
    },
    "Expr.sub": {
      "title": "A − B",
      "description": "Difference. Returns number.",
      "type": "object",
      "required": [
        "k",
        "a",
        "b"
      ],
      "properties": {
        "k": {
          "const": "sub"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "b": {
          "$ref": "#/definitions/Expr",
          "description": "Right operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.subStr": {
      "title": "Substring",
      "description": "0-based slice; out-of-range start gives empty text. Returns string.",
      "type": "object",
      "required": [
        "k",
        "text",
        "start"
      ],
      "properties": {
        "k": {
          "const": "subStr"
        },
        "text": {
          "$ref": "#/definitions/Expr",
          "description": "Source text."
        },
        "start": {
          "$ref": "#/definitions/Expr",
          "description": "Start index."
        },
        "length": {
          "$ref": "#/definitions/Expr",
          "description": "Maximum length; absent = to the end."
        }
      },
      "additionalProperties": false
    },
    "Expr.tan": {
      "title": "Tangent",
      "description": "Tangent of an angle in radians. Needs map format 3. Returns real.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "tan"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Angle in RADIANS. Multiply by 57.29577951308232 for the degrees `createUnits.facing` wants."
        }
      },
      "additionalProperties": false
    },
    "Expr.tick": {
      "title": "Game tick",
      "description": "The current simulation tick (20 per second) — the only clock in the language. Returns int.",
      "type": "object",
      "required": [
        "k"
      ],
      "properties": {
        "k": {
          "const": "tick"
        }
      },
      "additionalProperties": false
    },
    "Expr.timerRemaining": {
      "title": "Timer ticks left",
      "description": "Ticks until the timer expires (0 if not running). Returns int.",
      "type": "object",
      "required": [
        "k",
        "timer"
      ],
      "properties": {
        "k": {
          "const": "timerRemaining"
        },
        "timer": {
          "type": "string",
          "minLength": 1,
          "description": "Timer name."
        }
      },
      "additionalProperties": false
    },
    "Expr.timerRunning": {
      "title": "Timer is running",
      "description": "True while the timer runs and is not paused. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "timer"
      ],
      "properties": {
        "k": {
          "const": "timerRunning"
        },
        "timer": {
          "type": "string",
          "minLength": 1,
          "description": "Timer name."
        }
      },
      "additionalProperties": false
    },
    "Expr.toStr": {
      "title": "To text",
      "description": "Value as text. Non-integers print with `decimals` places (default 2). Returns string.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "toStr"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        },
        "decimals": {
          "type": "integer",
          "minimum": 0,
          "maximum": 6,
          "description": "Fixed decimal places, 0..6."
        }
      },
      "additionalProperties": false
    },
    "Expr.triggerFireCount": {
      "title": "Trigger fire count",
      "description": "How many times a trigger has fired. Returns int.",
      "type": "object",
      "required": [
        "k",
        "triggerId"
      ],
      "properties": {
        "k": {
          "const": "triggerFireCount"
        },
        "triggerId": {
          "type": "string",
          "minLength": 1,
          "description": "Trigger id."
        }
      },
      "additionalProperties": false
    },
    "Expr.trunc": {
      "title": "Truncate",
      "description": "Real to integer toward zero (`Math.trunc`) — the one real→int rule in the language. Returns int.",
      "type": "object",
      "required": [
        "k",
        "a"
      ],
      "properties": {
        "k": {
          "const": "trunc"
        },
        "a": {
          "$ref": "#/definitions/Expr",
          "description": "Left operand."
        }
      },
      "additionalProperties": false
    },
    "Expr.unitAboard": {
      "title": "Unit aboard transport",
      "description": "Whether the original unit is held in the original transport cargo. False for missing units or hulls. Needs map format 3. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "transport"
      ],
      "properties": {
        "k": {
          "const": "unitAboard"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "transport": {
          "$ref": "#/definitions/Expr",
          "description": "Transport to check."
        }
      },
      "additionalProperties": false
    },
    "Expr.unitHasBuff": {
      "title": "Unit has buff",
      "description": "True while this exact buff id is on the unit and has not run out. A buff whose remaining time has reached zero already answers false, one tick before the engine sweeps it up — so \"re-apply when it runs out\" does not double-cast. Matches the whole id, never a prefix. Needs map format 3. Returns bool.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "buffId"
      ],
      "properties": {
        "k": {
          "const": "unitHasBuff"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "buffId": {
          "type": "string",
          "description": "Buff id to look for — the same id `add buff` used."
        }
      },
      "additionalProperties": false
    },
    "Expr.unitPoint": {
      "title": "Unit position",
      "description": "Tile position of a unit. Returns point.",
      "type": "object",
      "required": [
        "k",
        "unit"
      ],
      "properties": {
        "k": {
          "const": "unitPoint"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        }
      },
      "additionalProperties": false
    },
    "Expr.unitProp": {
      "title": "Unit property",
      "description": "Read a property of a unit. A unit that died THIS tick answers from its death snapshot; otherwise a missing unit gives the zero value. Returns any.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "prop"
      ],
      "properties": {
        "k": {
          "const": "unitProp"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "prop": {
          "type": "string",
          "enum": [
            "hp",
            "maxHp",
            "hpPercent",
            "mana",
            "maxMana",
            "x",
            "y",
            "level",
            "xp",
            "kills",
            "owner",
            "alive",
            "isHero",
            "isBuilding",
            "isFlying",
            "typeId"
          ],
          "description": "Property to read."
        }
      },
      "additionalProperties": false
    },
    "Expr.unitVelocity": {
      "title": "Unit velocity",
      "description": "Kinematic velocity component or speed (tiles/tick); 0 without kinematics. Returns real.",
      "type": "object",
      "required": [
        "k",
        "unit",
        "axis"
      ],
      "properties": {
        "k": {
          "const": "unitVelocity"
        },
        "unit": {
          "$ref": "#/definitions/Expr",
          "description": "The unit (entity id). A dead or missing unit is harmless: reads give zero values, writes do nothing."
        },
        "axis": {
          "type": "string",
          "enum": [
            "x",
            "y",
            "speed"
          ],
          "description": "Component to read."
        }
      },
      "additionalProperties": false
    },
    "Expr.unitsInRadius": {
      "title": "Units within a radius",
      "description": "Sorted group of units within `radius` tiles of a point or unit. Measured on squared distance, which is exact on an integer grid; a radius below 0 matches nothing. Needs map format 3. Returns unitGroup.",
      "type": "object",
      "required": [
        "k",
        "at",
        "radius"
      ],
      "properties": {
        "k": {
          "const": "unitsInRadius"
        },
        "at": {
          "$ref": "#/definitions/Expr",
          "description": "Centre — a point, or a unit whose tile is used."
        },
        "radius": {
          "$ref": "#/definitions/Expr",
          "description": "Radius in tiles, inclusive."
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Expr.unitsInRegion": {
      "title": "Units in region",
      "description": "Sorted group of units whose tile is inside the region. Returns unitGroup.",
      "type": "object",
      "required": [
        "k",
        "region"
      ],
      "properties": {
        "k": {
          "const": "unitsInRegion"
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "description": "Region id."
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Expr.unitsOfPlayer": {
      "title": "Units of player",
      "description": "Sorted group of units owned by the seat. Returns unitGroup.",
      "type": "object",
      "required": [
        "k",
        "player"
      ],
      "properties": {
        "k": {
          "const": "unitsOfPlayer"
        },
        "player": {
          "$ref": "#/definitions/Expr",
          "description": "Seat id (0-based) of the player."
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Expr.unitsOfType": {
      "title": "Units of type",
      "description": "Sorted group of units or buildings of one type id. Returns unitGroup.",
      "type": "object",
      "required": [
        "k",
        "unitTypeId"
      ],
      "properties": {
        "k": {
          "const": "unitsOfType"
        },
        "unitTypeId": {
          "type": "string",
          "description": "Unit or building type id."
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Expr.unitsWithTag": {
      "title": "Units with tag",
      "description": "Sorted group of placed entities sharing an authored tag. Returns unitGroup.",
      "type": "object",
      "required": [
        "k",
        "tag"
      ],
      "properties": {
        "k": {
          "const": "unitsWithTag"
        },
        "tag": {
          "type": "string",
          "description": "Authored tag."
        },
        "filter": {
          "$ref": "#/definitions/UnitFilter",
          "description": "Optional unit filter; every set field is ANDed. `aliveOnly` defaults to true."
        }
      },
      "additionalProperties": false
    },
    "Expr.var": {
      "title": "Variable",
      "description": "Read a variable: a trigger/function local, a function parameter, a loop variable or a global (resolved in that order). Returns any.",
      "type": "object",
      "required": [
        "k",
        "name"
      ],
      "properties": {
        "k": {
          "const": "var"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Variable name."
        },
        "index": {
          "$ref": "#/definitions/Expr",
          "description": "Element index for an array variable. Out-of-range reads yield the zero value."
        }
      },
      "additionalProperties": false
    },
    "Expr.verifySaveCode": {
      "title": "Read save code",
      "description": "Validate a save code for this map. With `field`, returns that field (or 0); without, returns 1 for a valid code and 0 otherwise. Returns any.",
      "type": "object",
      "required": [
        "k",
        "code"
      ],
      "properties": {
        "k": {
          "const": "verifySaveCode"
        },
        "code": {
          "$ref": "#/definitions/Expr",
          "description": "The code text."
        },
        "field": {
          "type": "string",
          "description": "Field to extract; `playerId` returns the issuing seat."
        }
      },
      "additionalProperties": false
    },
    "FunctionDef": {
      "type": "object",
      "required": [
        "name",
        "actions"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "Function identifier.",
          "pattern": "^(?!__)[A-Za-z_][A-Za-z0-9_]*$"
        },
        "description": {
          "type": "string",
          "description": "Documentation."
        },
        "params": {
          "type": "array",
          "maxItems": 16,
          "items": {
            "$ref": "#/definitions/FunctionParam"
          },
          "description": "Typed parameters (≤ 16, scalars only)."
        },
        "returns": {
          "type": "string",
          "enum": [
            "int",
            "real",
            "bool",
            "string",
            "unit",
            "unitGroup",
            "point",
            "player",
            "region",
            "timer"
          ],
          "description": "Return type; absent = returns nothing."
        },
        "locals": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/VarDecl"
          },
          "description": "Per-call locals."
        },
        "actions": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Action"
          },
          "description": "Body. May not contain wait or stopTrigger."
        }
      },
      "additionalProperties": false
    },
    "FunctionParam": {
      "type": "object",
      "required": [
        "name",
        "type"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "Parameter identifier.",
          "pattern": "^(?!__)[A-Za-z_][A-Za-z0-9_]*$"
        },
        "type": {
          "type": "string",
          "enum": [
            "int",
            "real",
            "bool",
            "string",
            "unit",
            "unitGroup",
            "point",
            "player",
            "region",
            "timer"
          ],
          "description": "Parameter type."
        },
        "description": {
          "type": "string",
          "description": "Documentation."
        }
      },
      "additionalProperties": false
    },
    "HashtableDecl": {
      "type": "object",
      "required": [
        "name",
        "valueType"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "Hashtable identifier.",
          "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
        },
        "valueType": {
          "type": "string",
          "enum": [
            "int",
            "real",
            "bool",
            "string",
            "unit",
            "unitGroup",
            "point",
            "player",
            "region",
            "timer"
          ],
          "description": "Type every stored value is coerced to."
        },
        "maxEntries": {
          "type": "integer",
          "minimum": 1,
          "maximum": 16384,
          "description": "Entry cap (≤ 16384)."
        },
        "description": {
          "type": "string",
          "description": "Documentation."
        }
      },
      "additionalProperties": false
    },
    "RegionDef": {
      "type": "object",
      "required": [
        "id",
        "x",
        "y",
        "w",
        "h"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Region id.",
          "minLength": 1
        },
        "x": {
          "type": "integer",
          "description": "Top-left tile X."
        },
        "y": {
          "type": "integer",
          "description": "Top-left tile Y."
        },
        "w": {
          "type": "integer",
          "minimum": 1,
          "description": "Width in tiles (≥ 1)."
        },
        "h": {
          "type": "integer",
          "minimum": 1,
          "description": "Height in tiles (≥ 1)."
        },
        "name": {
          "type": "string",
          "description": "Editor label."
        }
      },
      "additionalProperties": false
    },
    "Text": {
      "description": "A text template, or a bare string (shorthand for one literal part).",
      "oneOf": [
        {
          "type": "string"
        },
        {
          "$ref": "#/definitions/TextTemplate"
        }
      ]
    },
    "TextTemplate": {
      "type": "object",
      "required": [
        "parts"
      ],
      "properties": {
        "parts": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "t",
                  "s"
                ],
                "additionalProperties": false,
                "properties": {
                  "t": {
                    "const": "lit"
                  },
                  "s": {
                    "type": "string",
                    "description": "Literal text."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "t",
                  "e"
                ],
                "additionalProperties": false,
                "properties": {
                  "t": {
                    "const": "expr"
                  },
                  "e": {
                    "$ref": "#/definitions/Expr",
                    "description": "Expression whose value is printed."
                  },
                  "decimals": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 6,
                    "description": "Fixed decimal places for non-integers."
                  }
                }
              }
            ]
          }
        }
      },
      "additionalProperties": false
    },
    "TriggerDef": {
      "type": "object",
      "required": [
        "id",
        "events",
        "actions"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Stable trigger id.",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "description": "Editor label."
        },
        "enabled": {
          "type": "boolean",
          "description": "Initially enabled (default true)."
        },
        "runOnce": {
          "type": "boolean",
          "description": "Fire at most once."
        },
        "events": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Event"
          },
          "description": "Events (any one fires the trigger)."
        },
        "conditions": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Expr"
          },
          "description": "Conditions, all of which must hold. They see globals only."
        },
        "locals": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/VarDecl"
          },
          "description": "Per-execution local variables; survive wait and save/load."
        },
        "actions": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Action"
          },
          "description": "Actions, run top to bottom."
        }
      },
      "additionalProperties": false
    },
    "UIFrameStyle": {
      "type": "object",
      "properties": {
        "backgroundColor": {
          "type": "string",
          "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$",
          "description": "Hex colour; anything else renders the default."
        },
        "borderColor": {
          "type": "string",
          "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$",
          "description": "Hex colour; anything else renders the default."
        },
        "textColor": {
          "type": "string",
          "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$",
          "description": "Hex colour; anything else renders the default."
        },
        "fontSize": {
          "type": "number",
          "description": "Font size (px)."
        },
        "borderRadius": {
          "type": "number",
          "description": "Corner radius (px)."
        },
        "padding": {
          "type": "number",
          "description": "Padding (px)."
        }
      },
      "additionalProperties": false
    },
    "UnitFilter": {
      "type": "object",
      "properties": {
        "players": {
          "type": "array",
          "items": {
            "type": "integer"
          },
          "description": "Owner must be one of these seats."
        },
        "ofPlayer": {
          "$ref": "#/definitions/Expr",
          "description": "Owner must equal this seat."
        },
        "alliedTo": {
          "$ref": "#/definitions/Expr",
          "description": "Owner must be allied to this seat."
        },
        "enemyOf": {
          "$ref": "#/definitions/Expr",
          "description": "Owner must not be allied to this seat."
        },
        "unitTypeIds": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Unit/building type must be one of these."
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Authored tag must be one of these."
        },
        "aliveOnly": {
          "type": "boolean",
          "description": "Only living units (default true)."
        },
        "heroesOnly": {
          "type": "boolean",
          "description": "Only heroes."
        },
        "buildingsOnly": {
          "type": "boolean",
          "description": "Only buildings."
        },
        "excludeBuildings": {
          "type": "boolean",
          "description": "No buildings."
        },
        "flyingOnly": {
          "type": "boolean",
          "description": "Only flyers."
        },
        "excludeFlying": {
          "type": "boolean",
          "description": "No flyers."
        },
        "excluding": {
          "$ref": "#/definitions/Expr",
          "description": "Drop these units."
        }
      },
      "additionalProperties": false
    },
    "VarDecl": {
      "type": "object",
      "required": [
        "name",
        "type"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "Identifier: letters, digits and _, not starting with a digit or `__`.",
          "pattern": "^(?!__)[A-Za-z_][A-Za-z0-9_]*$"
        },
        "type": {
          "type": "string",
          "enum": [
            "int",
            "real",
            "bool",
            "string",
            "unit",
            "unitGroup",
            "point",
            "player",
            "region",
            "timer"
          ],
          "description": "Value type."
        },
        "array": {
          "type": "boolean",
          "description": "Fixed-length array."
        },
        "arraySize": {
          "type": "integer",
          "minimum": 1,
          "description": "Array length (globals ≤ 8192, locals ≤ 1024).",
          "maximum": 8192
        },
        "init": {
          "$ref": "#/definitions/Expr",
          "description": "Initial value (globals: at map init; locals: at each execution start)."
        }
      },
      "additionalProperties": false,
      "if": {
        "required": [
          "array"
        ],
        "properties": {
          "array": {
            "const": true
          }
        }
      },
      "then": {
        "required": [
          "arraySize"
        ]
      }
    },
    "ZoneChainSpec": {
      "description": "`TriggerScript.chain` — the whole chain, declared once per map.",
      "type": "object",
      "required": [
        "chainId",
        "zones"
      ],
      "properties": {
        "chainId": {
          "description": "Identifies the CHAIN, not any map. `ZoneChain`'s bag binds to this, so every zone in one chain must declare the same value or a hop between them is refused as `'chain-mismatch'`.",
          "type": "string"
        },
        "thisZone": {
          "description": "Which zone this file IS, when it is one of the chain's zones. Lets a single shared chain table be pasted into every zone unchanged.",
          "type": "string"
        },
        "zones": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ZoneDef"
          }
        },
        "carryOver": {
          "description": "What survives a hop. See `ZoneChain.CarryOverSpec`. Absent carries nothing, which is the safe default: too much carried fails silently, too little fails in the first playtest.",
          "$ref": "#/definitions/CarryOverSpec"
        }
      },
      "additionalProperties": false
    },
    "ZoneDef": {
      "description": "One zone in a chain.",
      "type": "object",
      "required": [
        "id",
        "map",
        "respawn"
      ],
      "properties": {
        "id": {
          "description": "Author-chosen id, unique within the chain. Referenced by `travelToZone`.",
          "type": "string"
        },
        "map": {
          "description": "What the shell loads for this zone. A bundled map path (`public/maps/foo.json`), a community map id, or a chain-relative name — resolution is the shell's, because only the shell knows which sources are reachable in this environment. This module never opens a file.",
          "type": "string"
        },
        "entryRegion": {
          "description": "Default arrival region in this zone, when a gateway names none.",
          "type": "string"
        },
        "respawn": {
          "description": "TRUE — the zone is REGENERATED from its map file on every entry. Enemies come back, a building you destroyed is whole again, dropped loot is gone. Nothing is stored, so this costs nothing and is what ships today.",
          "type": "boolean"
        },
        "name": {
          "description": "Editor-only label. Never read by the sim.",
          "type": "string"
        }
      },
      "additionalProperties": false
    }
  }
}
