<?xml version="1.0" encoding="utf-8"?>
<!--
  xgedef.xsd

  What a game file is made of. The rule of thumb:

    * An attribute NAMES or PICKS something: name, class, object, variable,
      state, action, button, edge, direction, unless, burn, sprite, sound, wave,
      pitch, to, keys. These are labels, and they cannot be computed.
    * Everything else is the content of an element. Wherever the content is a
      number (valueType below) it is either a math expression written out as
      text - window.width.center - title.width / 2 - or a single value tag that
      makes the number, such as <random><min>-7</min><max>7</max></random>. To add a new kind
      of value, add it to the valueTag group and teach load/xml and load/expr
      about it; every place that takes a value takes it.
    * What an object DOES is a list of command tags (the command group below):
      <bounce />, <inc variable="paddle1.score" />, <push state="playing" />.
      They run in the order written.

  Shapes, commands and random numbers are tags, never function calls; only
  plain arithmetic is left to be written out as text.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">

  <!-- The words an attribute may hold. -->
  <xs:simpleType name="edgeType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="left" />
      <xs:enumeration value="right" />
      <xs:enumeration value="top" />
      <xs:enumeration value="bottom" />
      <xs:enumeration value="horizontal" />
      <xs:enumeration value="vertical" />
      <xs:enumeration value="all" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="directionType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="up" />
      <xs:enumeration value="down" />
      <xs:enumeration value="left" />
      <xs:enumeration value="right" />
    </xs:restriction>
  </xs:simpleType>

  <!-- The two ways an object with a heading can turn: clockwise adds to the heading, counterclockwise takes from it. -->
  <xs:simpleType name="turnDirectionType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="clockwise" />
      <xs:enumeration value="counterclockwise" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="flipType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="horizontal" />
      <xs:enumeration value="vertical" />
    </xs:restriction>
  </xs:simpleType>

  <!-- Value tags: the ways, besides writing an expression, to give a number. -->
  <xs:group name="valueTag">
    <xs:choice>
      <xs:element name="random" type="randomType" />
      <xs:element name="formula" type="formulaType" />
    </xs:choice>
  </xs:group>

  <!-- random: a number from <min> up to <max>, each an expression or a <formula>, drawn each time it is worked out. -->
  <xs:complexType name="randomType">
    <xs:sequence>
      <xs:element name="min" type="randomEndType" />
      <xs:element name="max" type="randomEndType" />
    </xs:sequence>
  </xs:complexType>

  <!-- An end of a <random>: text (an expression) or a <formula>, not both. -->
  <xs:complexType name="randomEndType" mixed="true">
    <xs:choice minOccurs="0">
      <xs:element name="formula" type="formulaType" />
    </xs:choice>
  </xs:complexType>

  <!-- Arithmetic without a string to parse: <formula> is one operation whose
       operands are elements: a name, a number, <random> or another operation.
       The first operand is combined with each of the others in turn, so
       a - b - c is a subtract with two subtrahends:
         <formula>
           <subtract>
             <minuend>window.width.center</minuend>
             <subtrahend><divide><dividend>title.width</dividend><divisor>2</divisor></divide></subtrahend>
           </subtract>
         </formula>
       A value tag, so it goes anywhere an expression or <random> does.
       Operations, one per arithmetic word: add, subtract, multiply, divide;
       remainder (a <dividend> and a <divisor>: what is left, from 0 up to
       the divisor); smallest and largest of two or more <value>; absolute,
       negate, sign (-1, 0 or 1), floor, ceiling, round, sine and cosine (of
       degrees) of one <value>; clamp, a <value> kept from <atleast> up to
       <atmost>; and compare, a <value> and its test (<above>, <below>,
       <atleast>, <atmost> or <equal>, the condition words): 1 when it
       holds and 0 when not. -->

  <!-- (The operations are listed twice, here and in operandType: the weak
       validator, load/xsd, does not follow a group that contains itself.) -->
  <xs:complexType name="formulaType">
    <xs:choice>
      <xs:element name="add" type="addType" />
      <xs:element name="subtract" type="subtractType" />
      <xs:element name="multiply" type="multiplyType" />
      <xs:element name="divide" type="divideType" />
      <xs:element name="remainder" type="remainderType" />
      <xs:element name="smallest" type="extremeType" />
      <xs:element name="largest" type="extremeType" />
      <xs:element name="absolute" type="oneOperandType" />
      <xs:element name="negate" type="oneOperandType" />
      <xs:element name="sign" type="oneOperandType" />
      <xs:element name="floor" type="oneOperandType" />
      <xs:element name="ceiling" type="oneOperandType" />
      <xs:element name="round" type="oneOperandType" />
      <xs:element name="sine" type="oneOperandType" />
      <xs:element name="cosine" type="oneOperandType" />
      <xs:element name="clamp" type="clampType" />
      <xs:element name="compare" type="compareOperationType" />
    </xs:choice>
  </xs:complexType>

  <!-- An operand of a formula: text (a name or a number), <random> or an operation, which contains operands in turn. -->
  <xs:complexType name="operandType" mixed="true">
    <xs:choice minOccurs="0">
      <xs:element name="random" type="randomType" />
      <xs:element name="add" type="addType" />
      <xs:element name="subtract" type="subtractType" />
      <xs:element name="multiply" type="multiplyType" />
      <xs:element name="divide" type="divideType" />
      <xs:element name="remainder" type="remainderType" />
      <xs:element name="smallest" type="extremeType" />
      <xs:element name="largest" type="extremeType" />
      <xs:element name="absolute" type="oneOperandType" />
      <xs:element name="negate" type="oneOperandType" />
      <xs:element name="sign" type="oneOperandType" />
      <xs:element name="floor" type="oneOperandType" />
      <xs:element name="ceiling" type="oneOperandType" />
      <xs:element name="round" type="oneOperandType" />
      <xs:element name="sine" type="oneOperandType" />
      <xs:element name="cosine" type="oneOperandType" />
      <xs:element name="clamp" type="clampType" />
      <xs:element name="compare" type="compareOperationType" />
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="extremeType">
    <xs:sequence>
      <xs:element name="value" type="operandType" minOccurs="2" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="oneOperandType">
    <xs:sequence>
      <xs:element name="value" type="operandType" />
    </xs:sequence>
  </xs:complexType>

  <!-- <compare><value>mode.waves</value><atleast>4</atleast></compare>: the <value>
       and its test, the same words as a condition's. -->
  <xs:complexType name="compareOperationType">
    <xs:sequence>
      <xs:element name="value" type="operandType" />
      <xs:choice>
        <xs:element name="above" type="operandType" />
        <xs:element name="below" type="operandType" />
        <xs:element name="atleast" type="operandType" />
        <xs:element name="atmost" type="operandType" />
        <xs:element name="equal" type="operandType" />
      </xs:choice>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="remainderType">
    <xs:sequence>
      <xs:element name="dividend" type="operandType" />
      <xs:element name="divisor" type="operandType" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="clampType">
    <xs:sequence>
      <xs:element name="value" type="operandType" />
      <xs:element name="atleast" type="operandType" />
      <xs:element name="atmost" type="operandType" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="addType">
    <xs:sequence>
      <xs:element name="augend" type="operandType" />
      <xs:element name="addend" type="operandType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="subtractType">
    <xs:sequence>
      <xs:element name="minuend" type="operandType" />
      <xs:element name="subtrahend" type="operandType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="multiplyType">
    <xs:sequence>
      <xs:element name="multiplicand" type="operandType" />
      <xs:element name="multiplier" type="operandType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="divideType">
    <xs:sequence>
      <xs:element name="dividend" type="operandType" />
      <xs:element name="divisor" type="operandType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <!-- A number: text (an expression) or one value tag, not both. -->
  <xs:complexType name="valueType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <!--
    What a condition's variable is compared with: a number, as content
    (<atleast>15</atleast>), which may name another variable, read as the game
    runs: <above>gun2.score</above>.
  -->
  <xs:complexType name="compareType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <!-- A number with a name, for <variable name="score">0</variable>. -->
  <xs:complexType name="variableType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
  </xs:complexType>

  <!-- Two numbers: <position>, <velocity> and a grid's <padding>. -->
  <xs:complexType name="vector2Type">
    <xs:sequence>
      <xs:element name="x" type="valueType" />
      <xs:element name="y" type="valueType" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="emptyType" />

  <!-- Sounds: the voices of an old 8-bit sound chip, and a soft sine. -->
  <xs:simpleType name="waveType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="square" />
      <xs:enumeration value="triangle" />
      <xs:enumeration value="sawtooth" />
      <xs:enumeration value="sine" />
      <xs:enumeration value="noise" />
    </xs:restriction>
  </xs:simpleType>

  <!--
    A note: its pitch (a note name with an octave such as C4, F#3 or Bb5 -
    C4 is middle C - or a number of hertz), optionally a pitch to slide to
    while it plays, and optionally a wave of its own instead of the sound's.
    Its content is how long it lasts, in seconds.
  -->
  <xs:complexType name="noteType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="pitch" type="xs:string" use="required" />
    <xs:attribute name="to" type="xs:string" use="optional" />
    <xs:attribute name="wave" type="waveType" use="optional" />
  </xs:complexType>

  <!--
    A sound that <play sound="..." /> starts: whether it loops (<loop />: over
    and over until a <silence>, or, played from a key, until the key is let
    go), how loud (0 to 1, 0.3 when left
    out), then notes and rests (a rest's content is how many seconds of
    silence), played one after the other, or parts (voices) that play at
    the same time, each its own notes and rests: a tune and its bass. wave is
    every note's that does not give its own (square when left out); a part's
    wave is its notes'.
  -->
  <xs:complexType name="partType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="note" type="noteType" />
      <xs:element name="rest" type="valueType" />
    </xs:choice>
    <xs:attribute name="wave" type="waveType" use="optional" />
  </xs:complexType>

  <xs:complexType name="soundType">
    <xs:sequence>
      <xs:element name="loop" type="emptyType" minOccurs="0" />
      <xs:element name="volume" type="valueType" minOccurs="0" />
      <xs:choice>
        <xs:choice maxOccurs="unbounded">
          <xs:element name="note" type="noteType" />
          <xs:element name="rest" type="valueType" />
        </xs:choice>
        <xs:element name="part" type="partType" maxOccurs="unbounded" />
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="wave" type="waveType" use="optional" />
  </xs:complexType>

  <xs:complexType name="tetherType">
    <xs:sequence>
      <xs:element name="thickness" type="valueType" minOccurs="0" />
      <xs:element name="color" type="xs:string" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="from" type="xs:string" use="required" />
    <xs:attribute name="to" type="xs:string" use="required" />
  </xs:complexType>

  <xs:complexType name="chooseWordType">
    <xs:sequence>
      <xs:element name="by" type="valueType" />
      <xs:element name="word" type="xs:string" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <!-- Sprites: one shape. -->
  <xs:group name="shape">
    <xs:choice>
      <xs:element name="circle">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="radius" type="valueType" />
            <xs:element name="color" type="xs:string" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="rectangle">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="width" type="valueType" />
            <xs:element name="height" type="valueType" />
            <xs:element name="color" type="xs:string" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="text">
        <xs:complexType>
          <xs:sequence>
            <!-- its pieces, in order, a space between them (letters side by side make one word) -->
            <xs:choice maxOccurs="unbounded">
              <!-- a fixed label -->
              <xs:element name="content" type="xs:string" />
              <!-- a live number: an owner.variable stays up to date as it changes -->
              <xs:element name="number" type="valueType" />
              <!-- a number shown as a letter, 0 is A and 25 is Z, live the same way -->
              <xs:element name="letter" type="valueType" />
              <!-- one of its words, picked by a number (0 the first), live the same way -->
              <xs:element name="choose" type="chooseWordType" />
            </xs:choice>
            <!-- left out, the style's -->
            <xs:element name="size" type="valueType" minOccurs="0" />
            <xs:element name="color" type="xs:string" minOccurs="0" />
            <!-- a font file (assets/pressstart2p.ttf); left out, the style's, or assets/tuffy.ttf -->
            <xs:element name="font" type="xs:string" minOccurs="0" />
          </xs:sequence>
          <!-- a <style> of the game's <styles>, for the <size> and <color> left out -->
          <xs:attribute name="style" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!-- a line from the middle of one object to the middle of another, drawn again every frame wherever they are -->
      <xs:element name="tether" type="tetherType" />
      <xs:element name="image">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="path" type="xs:string" />
            <xs:element name="flip" type="flipType" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <!--
        A picture in rows of text, one character to a pixel: a period is a clear
        pixel and an asterisk a solid one, drawn in the color. Every character
        becomes scale by scale real pixels (1 if left out), so a few characters
        make a chunky sprite. The rows must all be the same width. Like a
        drawing of lines it is made into a picture when the game loads.
      -->
      <xs:element name="bitmap">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="row" type="xs:string" maxOccurs="unbounded" />
            <xs:element name="scale" type="valueType" minOccurs="0" />
            <xs:element name="color" type="bitmapColorType" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="flip" type="flipType" minOccurs="0" />
          </xs:sequence>
          <!-- a <style> of the game's <styles>, for the <scale> and <color>s left out -->
          <xs:attribute name="style" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!--
        A drawing from an SVG file, made into a picture when the game loads, so
        every graphics library shows it the same way and a pixel collision tests
        what is shown. The path is read like an image's. x, y, width and height
        (all four, or none for the whole drawing) pick the part of the drawing to
        take, in the drawing's own units, which is how one sheet of sprites
        serves many objects. scale is how many real pixels a unit is (1 if left
        out; it need not be a whole number). Each hide is the id of an element to
        leave out, such as a backdrop. The colors are the drawing's own.
      -->
      <xs:element name="svg">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="path" type="xs:string" />
            <xs:element name="x" type="valueType" minOccurs="0" />
            <xs:element name="y" type="valueType" minOccurs="0" />
            <xs:element name="width" type="valueType" minOccurs="0" />
            <xs:element name="height" type="valueType" minOccurs="0" />
            <xs:element name="scale" type="valueType" minOccurs="0" />
            <xs:element name="hide" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="flip" type="flipType" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:group>

  <!--
    One straight line of a drawing: where from and to, in pixels from the
    sprite's top left, and optionally its color and how many pixels thick it is
    (1 if left out). A sprite of one or more of these is drawn once, when the
    game loads, into the picture that is shown and that a collision of type
    pixel looks at.
  -->
  <xs:complexType name="lineType">
    <xs:sequence>
      <xs:element name="from" type="vector2Type" />
      <xs:element name="to" type="vector2Type" />
      <xs:element name="color" type="xs:string" minOccurs="0" />
      <xs:element name="thickness" type="valueType" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <!--
    One filled shape of a drawing: its corners in order, in pixels from the
    sprite's top left, the last joined back to the first, and its color. A
    sprite of one or more of these is drawn once, when the game loads, and a
    collision of type pixel looks at what is drawn; a <hole> can cut it (hills
    blown into craters).
  -->
  <xs:complexType name="polygonType">
    <xs:sequence>
      <xs:element name="point" type="vector2Type" minOccurs="3" maxOccurs="unbounded" />
      <xs:element name="color" type="xs:string" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <!-- A sprite is named when an object has several, so an animation can pick them out. -->
  <xs:complexType name="spriteType">
    <xs:choice>
      <xs:group ref="shape" />
      <xs:element name="line" type="lineType" maxOccurs="unbounded" />
      <xs:element name="polygon" type="polygonType" maxOccurs="unbounded" />
    </xs:choice>
    <xs:attribute name="name" type="xs:string" use="optional" />
  </xs:complexType>

  <!--
    A sprite that changes one its group has, for a member, row, column or cell:
    the group's sprite of the same name (or the one with no name). Of the same
    shape it gives only what changes, a color say, and keeps the rest; of
    another shape, or as lines, it is a sprite of its own, and must be complete
    (the engine says what is missing). A name the group has not got adds one.
  -->
  <xs:complexType name="spriteChangeType">
    <xs:choice>
      <xs:element name="circle">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="radius" type="valueType" minOccurs="0" />
            <xs:element name="color" type="xs:string" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="rectangle">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="width" type="valueType" minOccurs="0" />
            <xs:element name="height" type="valueType" minOccurs="0" />
            <xs:element name="color" type="xs:string" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="text">
        <xs:complexType>
          <xs:sequence>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
              <xs:element name="content" type="xs:string" />
              <xs:element name="number" type="valueType" />
              <xs:element name="letter" type="valueType" />
              <xs:element name="choose" type="chooseWordType" />
            </xs:choice>
            <xs:element name="size" type="valueType" minOccurs="0" />
            <xs:element name="color" type="xs:string" minOccurs="0" />
            <xs:element name="font" type="xs:string" minOccurs="0" />
          </xs:sequence>
          <!-- a <style> of the game's <styles>, for the <size> and <color> left out -->
          <xs:attribute name="style" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!-- of a tether, from= and to= again, and the <thickness> or <color> that changes -->
      <xs:element name="tether" type="tetherType" />
      <xs:element name="image">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="path" type="xs:string" minOccurs="0" />
            <xs:element name="flip" type="flipType" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="bitmap">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="row" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="scale" type="valueType" minOccurs="0" />
            <xs:element name="color" type="bitmapColorType" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="flip" type="flipType" minOccurs="0" />
          </xs:sequence>
          <!-- a <style> of the game's <styles>, for the <scale> and <color>s left out -->
          <xs:attribute name="style" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <xs:element name="svg">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="path" type="xs:string" minOccurs="0" />
            <xs:element name="x" type="valueType" minOccurs="0" />
            <xs:element name="y" type="valueType" minOccurs="0" />
            <xs:element name="width" type="valueType" minOccurs="0" />
            <xs:element name="height" type="valueType" minOccurs="0" />
            <xs:element name="scale" type="valueType" minOccurs="0" />
            <xs:element name="hide" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
            <xs:element name="flip" type="flipType" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="line" type="lineType" maxOccurs="unbounded" />
      <xs:element name="polygon" type="polygonType" maxOccurs="unbounded" />
    </xs:choice>
    <xs:attribute name="name" type="xs:string" use="optional" />
  </xs:complexType>

  <!--
    An animation: how many seconds each picture is shown, and the sprites it
    shows in turn, round and round, each picked out by the name of one of the
    object's own sprites. At least two frames; the same sprite may come up more
    than once. The frames must all be pictures (bitmaps, svgs or drawings of
    lines) of the same size.
  -->
  <xs:complexType name="animationType">
    <xs:sequence>
      <xs:element name="interval" type="valueType" />
      <xs:element name="frame" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attribute name="sprite" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <!-- named: a look that moves, which <become> and <poses> pick like a sprite -->
    <xs:attribute name="name" type="xs:string" use="optional" />
  </xs:complexType>

  <!-- poses: the look for each way an object moves, picked each frame while it shows one of them. -->
  <xs:complexType name="poseType">
    <xs:attribute name="sprite" type="xs:string" use="required" />
  </xs:complexType>
  <xs:complexType name="posesType">
    <xs:sequence>
      <xs:element name="standing" type="poseType" />
      <xs:element name="walking" type="poseType" minOccurs="0" />
      <xs:element name="skidding" type="poseType" minOccurs="0" />
      <xs:element name="rising" type="poseType" minOccurs="0" />
      <xs:element name="falling" type="poseType" minOccurs="0" />
      <xs:element name="thrusting" type="poseType" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>
  <xs:simpleType name="mirrorType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="left" />
      <xs:enumeration value="right" />
    </xs:restriction>
  </xs:simpleType>
  <!-- How its looks and steps follow its moves: poses, a mirror going one way across, and how quickly it gets to the speed its moves ask for (0 up to 1, 1 at once). -->
  <!-- surface: the drag and grip a thing that grips has while its middle is over it; one left out is its own -->
  <xs:complexType name="surfaceType">
    <xs:sequence>
      <xs:element name="drag" type="valueType" minOccurs="0" />
      <xs:element name="grip" type="valueType" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <xs:group name="moveParts">
    <xs:sequence>
      <xs:element name="poses" type="posesType" minOccurs="0" />
      <xs:element name="mirror" type="mirrorType" minOccurs="0" />
      <xs:element name="grip" type="valueType" minOccurs="0" />
      <xs:element name="joins" type="joinsType" minOccurs="0" />
      <xs:element name="moves" type="pieceMovesType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="marks" type="marksType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="pile" type="pileType" minOccurs="0" />
      <!-- hand: points at piles and carries cards between them (<take />, <lay />, <drop />, <deal />, <call />);
           pile=: its own pile, a player's cards: it takes from that pile alone (any card, face up or down), deals into it
           from a stock with no into=, and stays pointing into it -->
      <xs:element name="hand" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <!-- seat: which player, for a trick's live number winner -->
            <xs:element name="seat" type="xs:positiveInteger" minOccurs="0" />
            <!-- team: its side; partners are hands on the same team (a computer's think lets a partner's card win) -->
            <xs:element name="team" type="xs:positiveInteger" minOccurs="0" />
            <!-- holds: from how many piles it may hold a card at once (a pair taken together); none: one -->
            <xs:element name="holds" type="xs:positiveInteger" minOccurs="0" />
          </xs:sequence>
          <xs:attribute name="pile" type="xs:NMTOKEN" use="optional" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:group>
  <!-- pile: a place that holds cards. faces=: every card put on it turned up or down (left out: each keeps its own).
       fan: each face-up card on from the one below (<hidden>: each face-down one; <width>: the fan is never wider, the
       steps across shrink); dealt: cards dealt it at the start (in a group, <more>: each pile after the first that many
       more); deals: taking from it deals that many into= that pile (none: into the own pile of the hand that takes);
       refill: and taken from empty, that pile is turned back over onto it (<shuffle />: shuffled; <leave>: but for that
       many top cards); takes: what may be laid on it (<matches />: the same suit as the top, or the suit called, or the same
       rank; <wild> ranks go on anything, and the pile then waits for <call />; on an empty one, <empty>'s ranks and suits);
       run: a face-up card may be taken with those above it; showtop: a face-down card left on top turns up; sorted: kept
       in suit then rank order; lift: the face-up card a hand points at is lifted out of the fan by that much;
       points: the live number points adds up the face-up cards' worths, each as high as it may count while the total
       stays <atmost> -->
  <xs:complexType name="pileType">
    <xs:sequence>
      <xs:element name="fan" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="x" type="valueType" minOccurs="0" />
            <xs:element name="y" type="valueType" minOccurs="0" />
            <xs:element name="hidden" type="partialVector2Type" minOccurs="0" />
            <xs:element name="width" type="valueType" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="dealt" minOccurs="0">
        <xs:complexType mixed="true">
          <xs:sequence>
            <xs:group ref="valueTag" minOccurs="0" />
            <xs:element name="more" type="valueType" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="deals" minOccurs="0">
        <xs:complexType mixed="true">
          <xs:group ref="valueTag" minOccurs="0" />
          <xs:attribute name="into" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <xs:element name="refill" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="shuffle" type="emptyType" minOccurs="0" />
            <xs:element name="leave" type="valueType" minOccurs="0" />
          </xs:sequence>
          <xs:attribute name="from" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="takes" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="one" type="emptyType" minOccurs="0" />
            <xs:element name="samesuit" type="emptyType" minOccurs="0" />
            <xs:element name="othercolor" type="emptyType" minOccurs="0" />
            <xs:choice minOccurs="0">
              <xs:element name="up" type="emptyType" />
              <xs:element name="down" type="emptyType" />
            </xs:choice>
            <xs:element name="matches" type="emptyType" minOccurs="0" />
            <xs:element name="wild" minOccurs="0">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="rank" type="xs:string" maxOccurs="unbounded" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
            <xs:element name="empty" minOccurs="0">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="rank" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
                  <xs:element name="suit" type="xs:NMTOKEN" minOccurs="0" maxOccurs="unbounded" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
            <!-- sum: the cards laid, all held together, when their worths add up to this, whatever is on the pile -->
            <xs:element name="sum" type="xs:positiveInteger" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <!-- trick: a pile each player lays a card on; any card leads, then the suit led, unless the hand laying holds
           none. breaks: these suits lead only once one was laid here since the deal, or when the hand holds nothing
           else; trumps: a card of these suits takes the trick over every card of the others. Live numbers lead (the
           suit led) and winner (the seat of the hand whose card takes it) -->
      <xs:element name="trick" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="breaks" minOccurs="0">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="suit" type="xs:NMTOKEN" maxOccurs="unbounded" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
            <xs:element name="trumps" minOccurs="0">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="suit" type="xs:NMTOKEN" maxOccurs="unbounded" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="run" type="emptyType" minOccurs="0" />
      <xs:element name="showtop" type="emptyType" minOccurs="0" />
      <xs:element name="sorted" type="emptyType" minOccurs="0" />
      <xs:element name="lift" type="valueType" minOccurs="0" />
      <!-- score patterns=: its cards (<with pile=>: and that pile's, which holds <full> when all are dealt) scored as the
           best <best> of them (none: all) by the game's <patterns> of that name: live numbers pattern (the highest made,
           from 1 as written; 0 none), strength (higher wins) and odds (percent, against as many unseen cards) -->
      <xs:element name="score" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <!-- melds: scored instead by laying the cards out in groups, each making one of the patterns with all its
                 cards (<same>: one rank, <run>: worths in a row, <suited>: one suit, at least as many as the number),
                 the groups leaving the fewest points over; live number deadwood, the points left over by the best
                 <best> of them -->
            <xs:element name="melds" type="emptyType" minOccurs="0" />
            <xs:element name="with" minOccurs="0">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="full" type="xs:positiveInteger" minOccurs="0" />
                </xs:sequence>
                <xs:attribute name="pile" type="xs:NMTOKEN" use="required" />
              </xs:complexType>
            </xs:element>
            <xs:element name="best" type="xs:positiveInteger" minOccurs="0" />
          </xs:sequence>
          <xs:attribute name="patterns" type="xs:NMTOKEN" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="points" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="atmost" type="valueType" minOccurs="0" />
            <!-- each: a card matching suit=, rank=, both or neither (every card) counts this many (the first that
                 matches), and a card matching none of them its worth -->
            <xs:element name="each" minOccurs="0" maxOccurs="unbounded">
              <xs:complexType mixed="true">
                <xs:sequence>
                  <xs:group ref="valueTag" minOccurs="0" />
                </xs:sequence>
                <xs:attribute name="suit" type="xs:NMTOKEN" use="optional" />
                <xs:attribute name="rank" type="xs:string" use="optional" />
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="faces" use="optional">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="up" />
          <xs:enumeration value="down" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>
  <!-- deck: the cards, one of each suit with each rank (<copies>: that many packs), shuffled into the pile pile= names.
       face: its size in pixels of the picture, the scale, and the color of the face and its edge; back: its color, the
       color of its edge, and a <pattern> tiled inside its frame ('*' the edge's color; none: a lattice); <color char>s:
       more characters the ranks' pictures use; suit: its pip as bitmap rows ('*' its <color>, more characters by
       <color char>), the small pip of the corners (<index>) and the ace's big one (<large>); rank, lowest first: its
       name alone (drawn in a small built-in font, 0-9 and A-Z), or name= with the corner's <index> (rows), and either
       <pips> on a grid (rows: '*' a pip, 'v' one turned round, '@' the large pip) or a <picture> (rows; <half /> first:
       the top half, the bottom the same turned round) -->
  <xs:complexType name="deckRowsType">
    <xs:sequence>
      <xs:element name="row" type="xs:string" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="deckType">
    <xs:sequence>
      <xs:element name="face" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="width" type="xs:positiveInteger" minOccurs="0" />
            <xs:element name="height" type="xs:positiveInteger" minOccurs="0" />
            <xs:element name="scale" type="xs:positiveInteger" minOccurs="0" />
            <xs:element name="color" type="xs:string" minOccurs="0" />
            <xs:element name="edge" type="xs:string" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="back" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="color" type="xs:string" minOccurs="0" />
            <xs:element name="edge" type="xs:string" minOccurs="0" />
            <xs:element name="pattern" type="deckRowsType" minOccurs="0" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="color" type="bitmapColorType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="suit" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="color" type="bitmapColorType" maxOccurs="unbounded" />
            <xs:element name="row" type="xs:string" maxOccurs="unbounded" />
            <xs:element name="index" type="deckRowsType" minOccurs="0" />
            <xs:element name="large" type="deckRowsType" minOccurs="0" />
          </xs:sequence>
          <xs:attribute name="name" type="xs:NMTOKEN" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="rank" maxOccurs="unbounded">
        <xs:complexType mixed="true">
          <xs:sequence>
            <xs:element name="index" type="deckRowsType" minOccurs="0" />
            <xs:choice minOccurs="0">
              <xs:element name="pips" type="deckRowsType" />
              <xs:element name="picture">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="half" type="emptyType" minOccurs="0" />
                    <xs:element name="row" type="xs:string" maxOccurs="unbounded" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:choice>
            <!-- worth: what the card counts for in a pile's points, one or more (an ace's 1 and 11); none: its number in order -->
            <xs:element name="worth" type="xs:nonNegativeInteger" minOccurs="0" maxOccurs="unbounded" />
          </xs:sequence>
          <xs:attribute name="name" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <xs:element name="copies" type="xs:positiveInteger" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:NMTOKEN" use="required" />
    <xs:attribute name="class" type="xs:NMTOKEN" use="optional" />
    <xs:attribute name="pile" type="xs:string" use="required" />
  </xs:complexType>
  <!-- marks: on a picker, pieces it shows in cells of their own map of cells, a copy of object= in each:
       held, the piece it holds; moves, each cell that piece can move to; movable, each piece of class= that can be picked;
       put, each cell a piece of class= can be <put> in;
       last, the cells the last move it placed went from and to (a piece put: its cell). sprite=: only while it shows that look.
       variable=: only while that variable is not 0 (an option) -->
  <xs:complexType name="marksType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="held" type="markType" />
      <xs:element name="moves" type="markType" />
      <xs:element name="movable" type="markType" />
      <xs:element name="put" type="markType" />
      <xs:element name="last" type="markType" />
    </xs:choice>
    <xs:attribute name="sprite" type="xs:NMTOKEN" use="optional" />
  </xs:complexType>
  <xs:complexType name="markType">
    <xs:attribute name="object" type="xs:string" use="required" />
    <xs:attribute name="class" type="xs:NMTOKEN" use="optional" />
    <xs:attribute name="variable" type="xs:string" use="optional" />
  </xs:complexType>
  <!-- moves: on a map with <cells />, a board game piece's moves, made when a picker <place>s it;
       sprite=: the set for that look (a king's), the one without for the other looks.
       forced: while any piece of its class can jump, it may only jump.
       step: to the empty cell that many cells across (x) and down (y).
       jump: over a piece of that class that far away into the empty cell beyond, taking it;
       a piece that can jump again after a jump must, before its turn is over.
       flank: a new piece of its kind is <put> only where it traps a line of pieces of that class
       (any of the eight ways; with <straight />, across and down only) against one of its own,
       and the pieces trapped turn into its kind (reversi).
       on: a piece put goes only on a piece of that class, in its place (dots and boxes' lines on their slots).
       fall: a piece put drops to the lowest free cell of the picker's column (four in a row).
       A set with no step or jump is of pieces put; one with nothing in it puts in any free cell (tic-tac-toe).
       promote: reaching that row, it shows that look (crowned), and its move ends. -->
  <xs:complexType name="pieceMovesType">
    <xs:sequence>
      <xs:element name="forced" type="emptyType" minOccurs="0" />
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="step" type="cellOffsetType" />
        <xs:element name="jump">
          <xs:complexType>
            <xs:complexContent>
              <xs:extension base="cellOffsetType">
                <xs:attribute name="class" type="xs:NMTOKEN" use="required" />
              </xs:extension>
            </xs:complexContent>
          </xs:complexType>
        </xs:element>
      </xs:choice>
      <xs:element name="flank" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="straight" type="emptyType" minOccurs="0" />
          </xs:sequence>
          <xs:attribute name="class" type="xs:NMTOKEN" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="on" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attribute name="class" type="xs:NMTOKEN" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="fall" type="emptyType" minOccurs="0" />
      <xs:element name="promote" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="row" type="xs:positiveInteger" />
          </xs:sequence>
          <xs:attribute name="sprite" type="xs:NMTOKEN" use="required" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="sprite" type="xs:NMTOKEN" use="optional" />
  </xs:complexType>
  <xs:complexType name="cellOffsetType">
    <xs:sequence>
      <xs:element name="x" type="xs:integer" />
      <xs:element name="y" type="xs:integer" />
    </xs:sequence>
  </xs:complexType>
  <!-- joins: on a map with <cells />, the look for where the piece it is joined to lies (the other cells of its shape, falling or settled), and alone; put on while it shows one of them -->
  <xs:complexType name="joinsType">
    <xs:sequence>
      <xs:element name="alone" type="poseType" />
      <xs:element name="left" type="poseType" />
      <xs:element name="right" type="poseType" />
      <xs:element name="up" type="poseType" />
      <xs:element name="down" type="poseType" />
    </xs:sequence>
  </xs:complexType>

  <!-- Commands: what a collision rule, an object action, a key or a condition does. -->
  <!-- inc and dec: which variable, and by how much (1 when there is nothing between the tags). -->
  <xs:complexType name="variableReferenceType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="variable" type="xs:string" use="required" />
  </xs:complexType>

  <!-- pull and seek: which object or group, and how much. -->
  <xs:complexType name="targetValueType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="object" type="xs:string" use="required" />
  </xs:complexType>

  <!-- An object's light, darkness, height off the ground and shadow. -->
  <xs:group name="sightParts">
    <xs:sequence>
      <!-- how far round its middle it lights what is dark -->
      <xs:element name="light" type="valueType" minOccurs="0" />
      <!-- unlit: drawn only while lit; unseen: drawn once it has been lit -->
      <xs:element name="dark" type="darkType" minOccurs="0" />
      <!-- how high off the ground it starts, how fast it rises, how much less each frame, how much it bounces back up -->
      <xs:element name="altitude" type="altitudeType" minOccurs="0" />
      <!-- kept under that object, on the ground -->
      <xs:element name="shadow" type="objectRefType" minOccurs="0" />
    </xs:sequence>
  </xs:group>

  <xs:simpleType name="darkType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="unlit" />
      <xs:enumeration value="unseen" />
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="altitudeType">
    <xs:sequence>
      <xs:element name="start" type="valueType" minOccurs="0" />
      <xs:element name="rise" type="valueType" minOccurs="0" />
      <xs:element name="fall" type="valueType" minOccurs="0" />
      <xs:element name="bounce" type="valueType" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="objectRefType">
    <xs:attribute name="object" type="xs:string" use="required" />
  </xs:complexType>

  <!-- hop: one of the four ways, or a diagonal, and how far: a distance, or for a diagonal an <x> across and a <y> up or down. -->
  <xs:simpleType name="hopDirectionType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="up" />
      <xs:enumeration value="down" />
      <xs:enumeration value="left" />
      <xs:enumeration value="right" />
      <xs:enumeration value="up-left" />
      <xs:enumeration value="up-right" />
      <xs:enumeration value="down-left" />
      <xs:enumeration value="down-right" />
    </xs:restriction>
  </xs:simpleType>
  <!-- hop: how far, as its value, or an <x> and a <y>, then how long it takes, and how high it goes on the way (an <arc>, which needs <seconds>). -->
  <!-- hop: its step and how long; or, on cells, <onto>s: to the nearest cell that way holding one of those classes (left and right along the row; up and down to the nearest row that has one, keeping the column as a text cursor does) -->
  <xs:complexType name="hopType" mixed="true">
    <xs:choice minOccurs="0">
      <xs:group ref="hopParts" />
      <xs:element name="onto" type="ontoType" maxOccurs="unbounded" />
    </xs:choice>
    <xs:attribute name="direction" type="hopDirectionType" use="required" />
  </xs:complexType>
  <!-- onto: a class of piece a hop or a track on cells may go to the cell of -->
  <xs:complexType name="ontoType">
    <xs:attribute name="class" type="xs:NMTOKEN" use="required" />
  </xs:complexType>
  <xs:group name="hopParts">
    <xs:sequence>
      <xs:choice minOccurs="0">
        <xs:group ref="valueTag" />
        <xs:sequence>
          <xs:element name="x" type="valueType" />
          <xs:element name="y" type="valueType" />
        </xs:sequence>
      </xs:choice>
      <xs:element name="seconds" type="valueType" minOccurs="0" />
      <xs:element name="arc" type="valueType" minOccurs="0" />
    </xs:sequence>
  </xs:group>
  <!-- the hop of a hunt by hops: the hunt chooses the way. -->
  <xs:complexType name="huntHopType" mixed="true">
    <xs:group ref="hopParts" minOccurs="0" />
  </xs:complexType>

  <!-- set: the value, worked out as it runs. -->
  <xs:complexType name="setType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="variable" type="xs:string" use="required" />
  </xs:complexType>

  <!-- spawn: which object or group (<random />: one of its members at random, not in turn), into= the map of cells it goes on (left out: its own), where (a half may be <centered>; on a map with <cells />, the <column> and <row> of its top left cell), and how fast. -->
  <xs:complexType name="spawnType">
    <xs:sequence>
      <xs:element name="random" type="emptyType" minOccurs="0" />
      <xs:choice minOccurs="0">
        <xs:element name="position" type="partialPositionType" />
        <xs:sequence>
          <xs:element name="column" type="valueType" />
          <xs:element name="row" type="valueType" />
        </xs:sequence>
        <!-- free: a free cell of the map, at random; with <below>, one under that row -->
        <xs:element name="free">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="below" type="valueType" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
      <xs:element name="velocity" type="partialVector2Type" minOccurs="0" />
      <!-- acceleration: its pull for as long as it lasts (wind on a shell), read as the spawn runs -->
      <xs:element name="acceleration" type="partialVector2Type" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="object" type="xs:string" use="required" />
    <xs:attribute name="into" type="xs:NMTOKEN" use="optional" />
  </xs:complexType>

  <!-- send: on maps with <cells />, the object's piece on map from= goes to map into=, in the <column> and <row> given (left out: the same cell). -->
  <xs:complexType name="sendType">
    <xs:sequence minOccurs="0">
      <xs:element name="column" type="valueType" />
      <xs:element name="row" type="valueType" />
    </xs:sequence>
    <xs:attribute name="object" type="xs:string" use="required" />
    <xs:attribute name="from" type="xs:NMTOKEN" use="required" />
    <xs:attribute name="into" type="xs:NMTOKEN" use="required" />
  </xs:complexType>

  <!-- move: a direction, and how far a frame; on a map with <cells />, how many cells a second while held, after one at once and a <wait> of so many seconds. -->
  <xs:complexType name="stepType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
      <xs:element name="wait" type="valueType" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="direction" type="directionType" use="required" />
  </xs:complexType>

  <!-- slide: on a map with <cells />, a cell at a time that way until the next is refused. -->
  <xs:complexType name="slideType">
    <xs:attribute name="direction" type="directionType" use="required" />
  </xs:complexType>

  <!-- accelerate: a direction, how much to add to the velocity each frame, and optionally the variable it burns. -->
  <xs:complexType name="thrustType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="direction" type="directionType" use="required" />
    <xs:attribute name="burn" type="xs:string" use="optional" />
  </xs:complexType>

  <!-- turn: left or right, and how many degrees a frame while the key is held; a shape on a map with <cells />, a quarter turn with nothing written. -->
  <xs:complexType name="turnType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="direction" type="turnDirectionType" use="required" />
  </xs:complexType>

  <!-- swing: which way it turns (direction=, as <turn>), how far, and how long the stroke takes. -->
  <xs:complexType name="swingType">
    <xs:sequence>
      <!-- how many degrees it turns from where it started -->
      <xs:element name="degrees" type="valueType" />
      <!-- how long the stroke takes: from still, fastest half way, to still -->
      <xs:element name="seconds" type="valueType" />
    </xs:sequence>
    <xs:attribute name="direction" type="turnDirectionType" use="required" />
  </xs:complexType>

  <!-- thrust: how much to add to the velocity each frame along the heading, and optionally the variable it burns. -->
  <xs:complexType name="aheadType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="burn" type="xs:string" use="optional" />
  </xs:complexType>

  <!-- release: the objects (a pool, a group) to put back in play, and how many (one if left out). -->
  <xs:complexType name="releaseType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="object" type="xs:string" use="required" />
  </xs:complexType>

  <!-- deflect: the widest angle, in degrees, a bounce off another object leaves at (at the ends of the side it hit). -->
  <xs:complexType name="deflectType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <!-- knock: how bouncy the meeting is, 0 up to 1; left out, 1. -->
  <xs:complexType name="knockType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <!-- hole: cut in the object's own picture where what it touched struck it,
       its radius as its value; rough, 0 up to 1, gives it a ragged edge. -->
  <xs:complexType name="holeType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
      <xs:element name="rough" type="valueType" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <!-- jump: a direction, how far as its value, how many seconds it takes (0.3 if left out), and how high it goes on the way (none if left out). -->
  <xs:complexType name="jumpType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
      <xs:element name="seconds" type="valueType" minOccurs="0" />
      <xs:element name="arc" type="valueType" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="direction" type="directionType" use="required" />
  </xs:complexType>

  <!-- climb: up or down, the class of what is climbed (a ladder), and the step a frame. -->
  <xs:complexType name="climbType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="direction" use="required">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="up" />
          <xs:enumeration value="down" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="class" type="xs:string" use="required" />
  </xs:complexType>

  <!-- One character of a <map>'s rows. -->
  <xs:simpleType name="mapCharType">
    <xs:restriction base="xs:string">
      <xs:length value="1" />
    </xs:restriction>
  </xs:simpleType>

  <!-- A key of a recorded <demo>: which, and the frame it happened at. -->
  <xs:complexType name="demoKeyType">
    <xs:simpleContent>
      <xs:extension base="xs:unsignedInt">
        <xs:attribute name="button" type="xs:string" use="required" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <!-- A bitmap's <color>: with no char=, the color of its '*'s; with char="w", of its 'w's. -->
  <xs:complexType name="bitmapColorType">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="char" type="mapCharType" use="optional" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <!-- maze: the <map> an object walks, and each class that is a wall to it (only while it shows sprite=, if given). -->
  <xs:complexType name="mazeType">
    <xs:sequence>
      <xs:element name="wall" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attribute name="class" type="xs:string" use="required" />
          <xs:attribute name="sprite" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!-- slow: on a tile holding something of this class, the walker goes at this share of its speed -->
      <xs:element name="slow" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:simpleContent>
            <xs:extension base="xs:decimal">
              <xs:attribute name="class" type="xs:string" use="required" />
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="map" type="xs:string" use="required" />
  </xs:complexType>

  <!-- go: the way to turn at the first gap, and the speed (pixels a frame). -->
  <xs:complexType name="goType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="direction" type="directionType" use="required" />
  </xs:complexType>

  <!--
    hunt: what to hunt, how fast as its value, and how the target is found from it: tiles
    in front of it (ahead), as far again past that as a partner is short of
    it (with), and, within that many tiles of it, another object instead
    (retreat). Or, for an object that walks no maze, a hunt by hops: one
    <hop>, toward it.
  -->
  <xs:complexType name="huntType" mixed="true">
    <xs:choice>
      <xs:element name="hop" type="huntHopType" />
      <xs:sequence>
        <xs:group ref="valueTag" minOccurs="0" />
        <xs:element name="ahead" type="valueType" minOccurs="0" />
        <xs:element name="with" minOccurs="0">
          <xs:complexType>
            <xs:attribute name="object" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element name="retreat" minOccurs="0">
          <xs:complexType mixed="true">
            <xs:sequence>
              <xs:group ref="valueTag" minOccurs="0" />
            </xs:sequence>
            <xs:attribute name="object" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:choice>
    <xs:attribute name="object" type="xs:string" use="required" />
  </xs:complexType>

  <!-- wander: how fast, as its value. -->
  <xs:complexType name="wanderType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <!-- chase: the object to head for, how fast as its value, and (if given) how near is near enough to stop. -->
  <xs:complexType name="chaseType" mixed="true">
    <xs:sequence>
      <xs:group ref="valueTag" minOccurs="0" />
      <xs:element name="near" type="valueType" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="object" type="xs:string" use="required" />
  </xs:complexType>

  <!--
    Commands, in groups by what they need to mean something; each place
    that runs commands names the groups it takes (below).
  -->
  <!-- changes: what can be done from anywhere: a variable, a look, a sound, a scene, an object put back, made or taken away, or another object's action run -->
  <xs:group name="changesCommands">
    <xs:choice>
      <xs:element name="inc" type="variableReferenceType" />
      <xs:element name="dec" type="variableReferenceType" />
      <!-- set: the variable (owner.variable), or owner.x, owner.y,
           owner.velocity.x, owner.velocity.y or owner.heading, takes the
           value, worked out as it runs -->
      <xs:element name="set" type="setType" />
      <!-- copy: the variable into= takes the number variable= holds now (both owner.variable) -->
      <xs:element name="copy">
        <xs:complexType>
          <xs:attribute name="variable" type="xs:string" use="required" />
          <xs:attribute name="into" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- count: the variable into= (owner.variable) takes how many objects of that class are in play now -->
      <xs:element name="count">
        <xs:complexType>
          <xs:attribute name="class" type="xs:NMTOKEN" use="required" />
          <xs:attribute name="into" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- rank: the entry variable= is of goes into the group into= (the best first), in place by that variable -->
      <xs:element name="rank">
        <xs:complexType>
          <xs:attribute name="variable" type="xs:string" use="required" />
          <xs:attribute name="into" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="play">
        <xs:complexType>
          <xs:attribute name="sound" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="silence">
        <xs:complexType>
          <xs:attribute name="sound" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="become">
        <xs:complexType>
          <!-- a look, a palette (a style its bitmaps take instead), or both -->
          <xs:attribute name="sprite" type="xs:string" use="optional" />
          <xs:attribute name="style" type="xs:string" use="optional" />
          <xs:attribute name="object" type="xs:string" use="optional" />
          <!-- only those showing this look change -->
          <xs:attribute name="from" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!-- reveal: as release, or with pile= (no object=), every card of that pile turned face up -->
      <xs:element name="reveal">
        <xs:complexType mixed="true">
          <xs:sequence>
            <xs:group ref="valueTag" minOccurs="0" />
          </xs:sequence>
          <xs:attribute name="object" type="xs:string" use="optional" />
          <xs:attribute name="pile" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!-- shuffle: every card of the game back in pile=, shuffled, face down (a new round) -->
      <xs:element name="shuffle">
        <xs:complexType>
          <xs:attribute name="pile" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- redeal: every card gathered, each deck shuffled into its pile and dealt to the piles' <dealt> again, as a new
           game deals -->
      <xs:element name="redeal" type="emptyType" />
      <!-- collect: every card of pile= onto into= (a trick to whoever took it) -->
      <xs:element name="collect">
        <xs:complexType>
          <xs:attribute name="pile" type="xs:NMTOKEN" use="required" />
          <xs:attribute name="into" type="xs:NMTOKEN" use="required" />
        </xs:complexType>
      </xs:element>
      <xs:element name="follow" type="followType" />
      <!-- <shift object="aliens"><x>2</x></shift>: those objects, and the
           places they go home to, moved by x across and y down -->
      <xs:element name="shift">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="x" type="valueType" minOccurs="0" />
            <xs:element name="y" type="valueType" minOccurs="0" />
          </xs:sequence>
          <xs:attribute name="object" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- <enter scene="room2" />: that scene becomes its state's current one;
           <enter way="east" />: the scene the current scene's way leads to. -->
      <xs:element name="enter">
        <xs:complexType>
          <xs:attribute name="scene" type="xs:string" use="optional" />
          <xs:attribute name="way" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!-- <reset /> puts back the object running it; object= that object
           or group; scene= every object of that scene, as it started; way=
           the scene that way of the current scene leads to. -->
      <xs:element name="reset">
        <xs:complexType>
          <xs:attribute name="object" type="xs:string" use="optional" />
          <xs:attribute name="scene" type="xs:string" use="optional" />
          <xs:attribute name="way" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!-- spawn: a new copy of the object (of a group, its members in
           turn) comes into the game, where the <position> says and going as
           the <velocity> says (a half left out is as the object starts),
           worked out as it runs -->
      <xs:element name="spawn" type="spawnType" />
      <!-- send: a piece from one map of cells to another (a next-piece box
           to the playfield), refused if it has no room there -->
      <xs:element name="send" type="sendType" />
      <!-- despawn: the object running it, or object= every one of that
           name or group, is taken out of the game -->
      <xs:element name="despawn">
        <xs:complexType>
          <xs:attribute name="object" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <xs:element name="trigger">
        <xs:complexType>
          <!-- left out in an object's own collision, action or timer: that object -->
          <xs:attribute name="object" type="xs:string" use="optional" />
          <xs:attribute name="action" type="xs:string" use="required" />
          <!-- only those of them showing this look -->
          <xs:attribute name="from" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:group>

  <!-- flow: the running order of the game: its states, its players' turns, its demo -->
  <xs:group name="flowCommands">
    <xs:choice>
      <xs:element name="push">
        <xs:complexType>
          <xs:attribute name="state" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- <pop /> goes back to the state underneath; <pop state="..." /> puts
           that state in place of this one. -->
      <xs:element name="pop">
        <xs:complexType>
          <xs:attribute name="state" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!-- turns: a <player> for each player taking turns, each with the state that says whose turn it is -->
      <xs:element name="turns">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="player" maxOccurs="unbounded">
              <xs:complexType>
                <xs:attribute name="state" type="xs:string" use="optional" />
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <!-- pass: the next player's turn; out: this player is out, and the next player's turn -->
      <xs:element name="pass" type="emptyType" />
      <xs:element name="out" type="emptyType" />
      <!-- demo: the game's recorded <demo> plays, until a key is pressed -->
      <xs:element name="demo" type="emptyType" />
    </xs:choice>
  </xs:group>

  <!-- self: what an object does to itself -->
  <xs:group name="selfCommands">
    <xs:choice>
      <xs:element name="die" type="emptyType" />
      <xs:element name="drop" type="emptyType" />
      <!-- hop: a step at once; on a map with <cells />, whole cells (one with nothing written), refused and touching what is in the way -->
      <xs:element name="hop" type="hopType" />
      <xs:element name="move" type="stepType" />
      <xs:element name="release" type="releaseType" />
      <xs:element name="reverse" type="emptyType" />
      <xs:element name="stop" type="emptyType" />
      <xs:element name="fire">
        <xs:complexType>
          <xs:attribute name="object" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- settle: on a map with <cells />, a shape's cells stay as loose pieces and the shape is gone; then the map's checks -->
      <xs:element name="settle" type="emptyType" />
      <xs:element name="slide" type="slideType" />
      <!-- cycle: on a map with <cells />, a shape's cells each move on to the next cell of its outline, in reading order, the last to the first (Columns' jewels) -->
      <xs:element name="cycle" type="emptyType" />
      <!-- grow: an object with a <chain> gets one link longer, at its tail, on its next step -->
      <xs:element name="grow" type="emptyType" />
      <!-- split: a piece of a chain cuts it there: it leaves the chain, and the links behind it are a chain of their own, led by the first of them -->
      <xs:element name="split" type="emptyType" />
      <!-- pick: a picker on a map of cells over a board takes up the piece of that class in its cell, one with a move to make; refused when there is none, or while the piece held must jump on -->
      <!-- pick with <only />: the one piece of that class that has a move, wherever the picker is, when only one has -->
      <xs:element name="pick">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="only" type="emptyType" minOccurs="0" />
          </xs:sequence>
          <xs:attribute name="class" type="xs:NMTOKEN" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- place: the piece held makes its move that ends in the picker's cell; refused when none does, and while it can jump on -->
      <xs:element name="place" type="emptyType" />
      <!-- take, on a hand: the card pointed at, with those above it from a pile with a <run />; refused when nothing can be taken -->
      <xs:element name="take" type="emptyType" />
      <!-- lay, on a hand: what it holds on the pile pointed at (pile=: the first of those piles that takes it); refused when none does;
           laid back on the pile it came from it is put back -->
      <xs:element name="lay">
        <xs:complexType>
          <xs:attribute name="pile" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!-- deal, on a hand: from the pile pointed at (pile=: from that one), by its <deals> (or, empty, its <refill>);
           faces=: each card dealt turned up or down -->
      <xs:element name="deal">
        <!-- one card: a new hand of many is <redeal /> -->
        <xs:complexType>
          <xs:attribute name="pile" type="xs:string" use="optional" />
          <xs:attribute name="faces" use="optional">
            <xs:simpleType>
              <xs:restriction base="xs:string">
                <xs:enumeration value="up" />
                <xs:enumeration value="down" />
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
        </xs:complexType>
      </xs:element>
      <!-- call, on a hand with a pile of its own: the suit of the card it points at there is called for pile=, waiting
           with a <wild> card on top; refused when it is not waiting -->
      <xs:element name="call">
        <xs:complexType>
          <xs:attribute name="pile" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- put: a new piece of that class in the picker's cell of the pieces' map; refused when the cell is taken,
           or, when the pieces have <flank>s, where it traps nothing; the pieces it traps turn into its kind -->
      <!-- put with <close class object>: each piece of that class beside the piece put, walled in on its four sides
           by pieces of the class put, is replaced by a copy of the object; then the put counts as refused (the turn goes on) -->
      <xs:element name="put">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="close" minOccurs="0">
              <xs:complexType>
                <xs:attribute name="class" type="xs:NMTOKEN" use="required" />
                <xs:attribute name="object" type="xs:string" use="required" />
              </xs:complexType>
            </xs:element>
          </xs:sequence>
          <xs:attribute name="class" type="xs:NMTOKEN" use="required" />
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:group>

  <!-- steering: an object steering itself toward or around another -->
  <xs:group name="steeringCommands">
    <xs:choice>
      <xs:element name="aim">
        <xs:complexType>
          <xs:sequence>
            <!-- only when lined up with it, across, up or down or on a true
                 diagonal, within this many pixels; otherwise refused -->
            <xs:element name="lined" type="valueType" minOccurs="0" />
          </xs:sequence>
          <xs:attribute name="object" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- chase: head for an object; aim: face it, so the next <fire> goes straight at it -->
      <xs:element name="chase" type="chaseType" />
      <xs:element name="hunt" type="huntType" />
      <xs:element name="wander" type="wanderType" />
    </xs:choice>
  </xs:group>

  <!-- touch: what needs another object, touched -->
  <xs:group name="touchCommands">
    <xs:choice>
      <xs:element name="carry" type="emptyType" />
      <xs:element name="deflect" type="deflectType" />
      <xs:element name="hole" type="holeType" />
      <xs:element name="knock" type="knockType" />
      <!-- land: stand on top of the object touched; leap: a jump of that height under the object's own pull -->
      <xs:element name="land" type="emptyType" />
      <xs:element name="ride" type="emptyType" />
      <!-- through: on a map with <cells />, the refused step is made after all, into the cell with what is there -->
      <xs:element name="through" type="emptyType" />
    </xs:choice>
  </xs:group>

  <!-- edge: what needs a screen edge (stick also takes a touch: only the velocity into what it met stops) -->
  <xs:group name="edgeCommands">
    <xs:choice>
      <xs:element name="stick" type="emptyType" />
      <xs:element name="wrap" type="emptyType" />
    </xs:choice>
  </xs:group>

  <!-- bounce: off a screen edge or another object -->
  <xs:group name="bounceCommands">
    <xs:choice>
      <!-- bounce: off what it touched, mirrored about the way its surface faces;
           its value is the share of the speed kept (left out, 1; above 1, a bumper) -->
      <xs:element name="bounce" type="knockType" />
    </xs:choice>
  </xs:group>

  <!-- controls: how an object moves when its action is asked for -->
  <xs:group name="controlsCommands">
    <xs:choice>
      <xs:element name="accelerate" type="thrustType" />
      <xs:element name="climb" type="climbType" />
      <xs:element name="go" type="goType" />
      <xs:element name="jump" type="jumpType" />
      <xs:element name="leap" type="valueType" />
      <!-- swing: held, the heading turns <degrees> that way in one eased stroke <seconds> long; let go, back to the heading it started with -->
      <xs:element name="swing" type="swingType" />
      <xs:element name="thrust" type="aheadType" />
      <xs:element name="turn" type="turnType" />
      <!-- track: where a control points; path= along that path instead of across the window; on cells, <onto>s: the cell nearest the pointer holding one of those classes -->
      <xs:element name="track">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="onto" type="ontoType" minOccurs="0" maxOccurs="unbounded" />
          </xs:sequence>
          <xs:attribute name="path" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:group>

  <!-- press: a button held down, as a computer player does -->
  <xs:group name="pressCommands">
    <xs:choice>
      <!-- hold: only in a <computer>'s condition: the button held down while it holds -->
      <xs:element name="hold">
        <xs:complexType>
          <xs:attribute name="button" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- think: only in a <computer>'s condition: while it holds, the computer plays the board game pieces of class=,
           looking <depth> moves ahead (4 when left out), each piece worth 1 or its look's <worth>; it walks the picker
           object= to the piece and each cell of its move, pressing button= on each -->
      <xs:element name="think">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="depth" type="xs:positiveInteger" minOccurs="0" />
            <!-- avoid: a card player that keeps out of tricks (Hearts); none: one that takes them -->
            <xs:element name="avoid" type="emptyType" minOccurs="0" />
            <xs:element name="worth" minOccurs="0" maxOccurs="unbounded">
              <xs:complexType>
                <xs:simpleContent>
                  <xs:extension base="xs:decimal">
                    <xs:attribute name="sprite" type="xs:NMTOKEN" use="required" />
                  </xs:extension>
                </xs:simpleContent>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
          <xs:attribute name="class" type="xs:NMTOKEN" use="optional" />
          <xs:attribute name="object" type="xs:string" use="required" />
          <xs:attribute name="button" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:group>

  <!-- cells: what a check of a map with <cells /> does with what it found -->
  <xs:group name="cellsCommands">
    <xs:choice>
      <!-- clear: what it found leaves the game; collapse: what is above a full row comes down a row -->
      <xs:element name="clear" type="emptyType" />
      <xs:element name="collapse" type="emptyType" />
      <!-- fall: every loose piece of the map (with class=, only those of that class) drops down its column onto what is under it -->
      <xs:element name="fall">
        <xs:complexType>
          <xs:attribute name="class" type="xs:NMTOKEN" />
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:group>

  <!-- a check of a map with <cells /> -->
  <xs:group name="checkCommands">
    <xs:choice>
      <xs:group ref="changesCommands" />
      <xs:group ref="cellsCommands" />
    </xs:choice>
  </xs:group>

  <!-- a collision rule: about another object (touch, steering) or about a screen edge (edge); the loader holds each kind to its own -->
  <xs:group name="ruleCommands">
    <xs:choice>
      <xs:group ref="changesCommands" />
      <xs:group ref="selfCommands" />
      <xs:group ref="steeringCommands" />
      <xs:group ref="touchCommands" />
      <xs:group ref="edgeCommands" />
      <xs:group ref="bounceCommands" />
    </xs:choice>
  </xs:group>

  <!-- an object's action -->
  <xs:group name="actionCommands">
    <xs:choice>
      <xs:group ref="changesCommands" />
      <xs:group ref="selfCommands" />
      <xs:group ref="steeringCommands" />
      <xs:group ref="controlsCommands" />
    </xs:choice>
  </xs:group>

  <!-- an object's timer, and a step of a path an object follows -->
  <xs:group name="objectTimeCommands">
    <xs:choice>
      <xs:group ref="changesCommands" />
      <xs:group ref="selfCommands" />
      <xs:group ref="steeringCommands" />
    </xs:choice>
  </xs:group>

  <!-- a state's keys, conditions and timers, and a scene's -->
  <xs:group name="stateCommands">
    <xs:choice>
      <xs:group ref="changesCommands" />
      <xs:group ref="flowCommands" />
    </xs:choice>
  </xs:group>

  <!--
    follow: the object sets off along one of the game's <paths>. With object=
    every object of that name or group does, each <stagger> seconds after the
    one before (0 if left out); with <nearest>N</nearest>, only the N of them
    nearest the object running it.
  -->
  <xs:complexType name="followType">
    <xs:sequence>
      <xs:element name="stagger" type="valueType" minOccurs="0" />
      <xs:element name="nearest" type="valueType" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="path" type="xs:string" use="required" />
    <xs:attribute name="object" type="xs:string" use="optional" />
  </xs:complexType>

  <!--
    A path: how fast it is flown (pixels a frame), where it begins (left out:
    wherever the object is), then its legs in order. A step moves the object
    by x and y from where the step began, and runs its commands as it sets
    off; home takes it back to where it started the game.
  -->
  <xs:complexType name="pathStepType">
    <xs:sequence>
      <xs:element name="x" type="valueType" />
      <xs:element name="y" type="valueType" />
      <xs:group ref="objectTimeCommands" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="pathType">
    <xs:sequence>
      <xs:element name="speed" type="valueType" />
      <xs:element name="start" type="vector2Type" minOccurs="0" />
      <xs:choice maxOccurs="unbounded">
        <xs:element name="step" type="pathStepType" />
        <xs:element name="home" type="emptyType" />
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
  </xs:complexType>

  <!--
    A collision rule. With edge it is about a screen edge, and takes no class
    or object; without, it is about another object, narrowed by class and/or
    object (neither: anything). Either is passed over while the object is
    touching something of the unless class. A
    rule about another object may also begin with slower and/or faster, which
    hold it to when the object's own speed is under (slower) or at least
    (faster) that number. With sprite, it runs only while the object shows its
    sprite of that name (see become).
  -->
  <xs:complexType name="collisionType">
    <xs:sequence>
      <xs:element name="slower" type="valueType" minOccurs="0" />
      <xs:element name="faster" type="valueType" minOccurs="0" />
      <!-- conditions (tests alone, no commands) that must all hold for the
           rule to run; one with no class= or object= is about the object itself -->
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="condition" type="testType" />
        <xs:element name="all" type="joinType" />
        <xs:element name="any" type="joinType" />
      </xs:choice>
      <xs:group ref="ruleCommands" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="edge" type="edgeType" use="optional" />
    <!-- the side of this object the other touched: top, bottom, left, right, horizontal or vertical -->
    <xs:attribute name="side" type="edgeType" use="optional" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="object" type="xs:string" use="optional" />
    <xs:attribute name="unless" type="xs:string" use="optional" />
    <!-- only a touch felt through something of this class (a knock through
         a floor); a rule without it, only a touch itself -->
    <xs:attribute name="through" type="xs:string" use="optional" />
    <xs:attribute name="sprite" type="xs:string" use="optional" />
  </xs:complexType>

  <!-- A named thing an object can do, run by a <trigger>. -->
  <xs:complexType name="actionType">
    <xs:sequence>
      <xs:group ref="actionCommands" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
  </xs:complexType>

  <!-- What pressing a key does in a state: button= is one key, and several
       are a <button> each, before the commands (<button>a</button>
       <button>left</button>); or, with axis= (mouse.x, mouse.y, pad1.x, ...)
       instead, the <trigger> run as that control moves. One of the two,
       which the engine checks. -->
  <xs:complexType name="inputType">
    <xs:sequence>
      <xs:element name="button" type="xs:NMTOKEN" minOccurs="0" maxOccurs="unbounded" />
      <xs:group ref="stateCommands" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="button" type="xs:NMTOKEN" use="optional" />
    <xs:attribute name="axis" type="xs:string" use="optional" />
    <!-- on: the moment of the key it answers. press (left out: the same) runs
         its commands as the key goes down, a held verb staying on while it is
         down; hold runs them every frame while it is down; release once when
         it is let go. hold and release answer only a press made in this state. -->
    <xs:attribute name="on" type="keyMomentType" use="optional" />
  </xs:complexType>

  <xs:simpleType name="keyMomentType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="press" />
      <xs:enumeration value="hold" />
      <xs:enumeration value="release" />
    </xs:restriction>
  </xs:simpleType>

  <!--
    One test of a condition: atleast / atmost / above / below /
    equal compare what is tested (the variable named by variable= of every
    object that matches class and/or object; a total= over them; or each
    one's distance= to the nearest of another) with a number or another
    variable; remaining counts the matching objects still in play.
  -->
  <xs:group name="conditionTest">
    <xs:choice>
      <xs:element name="atleast" type="compareType" />
      <xs:element name="atmost" type="compareType" />
      <xs:element name="above" type="compareType" />
      <xs:element name="below" type="compareType" />
      <xs:element name="equal" type="compareType" />
      <xs:element name="remaining" type="valueType" />
    </xs:choice>
  </xs:group>

  <xs:simpleType name="totalType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="count" />
      <xs:enumeration value="sum" />
      <xs:enumeration value="highest" />
      <xs:enumeration value="lowest" />
    </xs:restriction>
  </xs:simpleType>

  <!-- A <condition> inside an <all>, an <any> or a <collision>: one test with what it tests, and no commands. -->
  <xs:complexType name="testType">
    <xs:group ref="conditionTest" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="object" type="xs:string" use="optional" />
    <xs:attribute name="variable" type="xs:string" use="optional" />
    <!-- count: how many are in play; sum, highest, lowest: of variable= over them -->
    <xs:attribute name="total" type="totalType" use="optional" />
    <!-- how far each is from the nearest in play of this object or group -->
    <xs:attribute name="distance" type="xs:string" use="optional" />
  </xs:complexType>

  <!-- all: every condition holds; any: one of them does. Each a test of its own. -->
  <xs:complexType name="joinType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="condition" type="testType" />
      <xs:element name="all" type="joinType" />
      <xs:element name="any" type="joinType" />
    </xs:choice>
  </xs:complexType>

  <!--
    Checked every frame. One test (or an <all> or <any> of conditions), then the
    commands to run when it holds. Or, with set="name" and nothing else, a
    named <conditions> set's conditions in its place.
  -->
  <xs:group name="conditionHead">
    <xs:choice>
      <xs:group ref="conditionTest" />
      <xs:element name="all" type="joinType" />
      <xs:element name="any" type="joinType" />
    </xs:choice>
  </xs:group>
  <xs:attributeGroup name="conditionAttributes">
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="object" type="xs:string" use="optional" />
    <xs:attribute name="variable" type="xs:string" use="optional" />
    <!-- count: how many are in play; sum, highest, lowest: of variable= over them -->
    <xs:attribute name="total" type="totalType" use="optional" />
    <!-- how far each is from the nearest in play of this object or group -->
    <xs:attribute name="distance" type="xs:string" use="optional" />
    <xs:attribute name="set" type="xs:string" use="optional" />
    <!-- a scene from= this one's can put a condition of the same name in its place -->
    <xs:attribute name="name" type="xs:string" use="optional" />
  </xs:attributeGroup>
  <xs:complexType name="conditionType">
    <xs:sequence minOccurs="0">
      <xs:group ref="conditionHead" />
      <xs:group ref="stateCommands" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attributeGroup ref="conditionAttributes" />
  </xs:complexType>
  <!-- A computer player's condition: a state's test, then the buttons it holds down while it holds. -->
  <xs:complexType name="computerConditionType">
    <xs:sequence minOccurs="0">
      <xs:group ref="conditionHead" />
      <xs:group ref="pressCommands" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attributeGroup ref="conditionAttributes" />
  </xs:complexType>
  <xs:complexType name="computerType">
    <xs:sequence>
      <xs:element name="condition" type="computerConditionType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <!--
    Timers: each goes off after a number of seconds - <every> again and again
    (worked out again each time, so a <random> waits a new time), <after>
    once - and runs its commands. An object's count while it is shown and in
    play; a state's while it is the current state. A reset starts them over.
  -->
  <xs:group name="timerHead">
    <xs:choice>
      <xs:element name="every" type="valueType" />
      <xs:element name="after" type="valueType" />
    </xs:choice>
  </xs:group>
  <xs:attributeGroup name="timerAttributes">
    <!-- a scene from= this one's can put a timer of the same name in its place -->
    <xs:attribute name="name" type="xs:string" use="optional" />
    <!-- an object's timer that counts only while it shows this look -->
    <xs:attribute name="sprite" type="xs:string" use="optional" />
  </xs:attributeGroup>
  <xs:complexType name="objectTimerType">
    <xs:sequence>
      <xs:group ref="timerHead" />
      <xs:group ref="objectTimeCommands" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attributeGroup ref="timerAttributes" />
  </xs:complexType>
  <xs:complexType name="stateTimerType">
    <xs:sequence>
      <xs:group ref="timerHead" />
      <xs:group ref="stateCommands" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attributeGroup ref="timerAttributes" />
  </xs:complexType>

  <!-- An object's timers, and a state's or a scene's: the same timer, each running the commands of its place. -->
  <xs:complexType name="objectTimersType">
    <xs:sequence>
      <xs:element name="timer" type="objectTimerType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="stateTimersType">
    <xs:sequence>
      <xs:element name="timer" type="stateTimerType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <!--
    Where an object starts: a value, or <centered>, its middle at the
    expression it holds, less half its own width (or height); left empty, at
    the window's middle: <x><centered /></x>, <y><centered>cell / 2</centered></y>.
  -->
  <xs:complexType name="positionValueType" mixed="true">
    <xs:choice minOccurs="0">
      <xs:group ref="valueTag" />
      <xs:element name="centered" type="xs:string" />
    </xs:choice>
  </xs:complexType>

  <!-- Some of a <position>: a group's, a member's, a cell's or a scene's change (a half left out is the group's, or 0). -->
  <xs:complexType name="partialPositionType">
    <xs:sequence>
      <xs:element name="x" type="positionValueType" minOccurs="0" />
      <xs:element name="y" type="positionValueType" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <!-- Some of two numbers: a group's or a member's <velocity> and <padding>, and an object's <velocity> (a half left out is 0). -->
  <xs:complexType name="partialVector2Type">
    <xs:sequence>
      <xs:element name="x" type="valueType" minOccurs="0" />
      <xs:element name="y" type="valueType" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <!-- How an object's shape is tested: as a box (the default), or by the pixels drawn. -->
  <xs:simpleType name="collisionShapeType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="box" />
      <xs:enumeration value="pixel" />
    </xs:restriction>
  </xs:simpleType>

  <!-- Whether collisions are on, whether the object moves in lockstep with the others of its group, how its shape is tested, then the rules. -->
  <xs:complexType name="collisionsType">
    <xs:sequence>
      <!-- enabled: left out, true; a <collisions> is written to be touched -->
      <xs:element name="enabled" type="xs:boolean" minOccurs="0" />
      <xs:element name="lockstep" type="xs:boolean" minOccurs="0" />
      <xs:element name="type" type="collisionShapeType" minOccurs="0" />
      <xs:element name="solid" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attribute name="char" use="required">
            <xs:simpleType>
              <xs:restriction base="xs:string">
                <xs:length value="1" />
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
        </xs:complexType>
      </xs:element>
      <xs:element name="hitbox" type="hitboxType" minOccurs="0" />
      <xs:element name="collision" type="collisionType" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <!-- What an object touches others with instead of its picture: a rectangle or a circle, its top left from the picture's. -->
  <xs:complexType name="hitboxType">
    <xs:sequence>
      <xs:choice>
        <xs:element name="rectangle">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="width" type="valueType" />
              <xs:element name="height" type="valueType" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="circle">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="radius" type="valueType" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
      <xs:element name="position" type="partialVector2Type" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="actionsType">
    <xs:sequence>
      <xs:element name="action" type="actionType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <!-- The variables an object owns. -->
  <xs:complexType name="variablesType">
    <xs:sequence>
      <xs:element name="variable" type="variableType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <!--
    Anything that can be drawn, moved or collided with. One with no sprite only
    holds numbers (a score, the lives): it is never drawn, and its position,
    0, 0 if left out, is only where it is.

    from= starts it as a copy of a piece of the game's <kit> (or of a named
    member of a group piece), changed by what it gives; one named after a
    piece takes it the same way without from=. In a state or scene from=
    another, one named after an object the other has changes that object.
    What is given goes over what it starts from: sprites and animations by
    name, either half of a position or velocity, variables, actions and
    timers by name, collision rules after the piece's, anything else in its
    place. So everything here may be left out, and the engine checks that
    the object made is complete.
  -->
  <!--
    What every object-like thing may have after its sprites, animations and
    position: an object, a group (for all its members), a piece of the <kit>,
    an object or group on a <map>. Written once so they cannot drift apart.
  -->
  <xs:group name="objectParts">
    <xs:sequence>
      <!-- on a map with <cells />: the cells it fills, a <row> of characters each; each character picks an object of the map by its char= -->
      <xs:element name="shape" type="shapeType" minOccurs="0" />
      <xs:element name="velocity" type="partialVector2Type" minOccurs="0" />
      <xs:element name="acceleration" type="vector2Type" minOccurs="0" />
      <xs:element name="heading" type="valueType" minOccurs="0" />
      <!-- the point of its picture, as drawn, that the heading turns it about (left out, its middle); its <position> is then where that point is on the screen -->
      <xs:element name="pivot" type="vector2Type" minOccurs="0" />
      <xs:element name="drag" type="valueType" minOccurs="0" />
      <!-- how much a surface it touches holds it back along that surface, as a share of how hard it meets it (0 none); and enough of it holds it still where its pull cannot slide it -->
      <xs:element name="friction" type="valueType" minOccurs="0" />
      <!-- how hard it is to knock; left out, a knock does not move it -->
      <xs:element name="mass" type="valueType" minOccurs="0" />
      <!-- ground: what holds a thing with a <grip> whose middle is over it, in place of its own drag and grip (grass, sand, oil) -->
      <xs:element name="surface" type="surfaceType" minOccurs="0" />
      <!-- pulled toward the nearest of each, that much speed a frame -->
      <xs:element name="pull" type="targetValueType" minOccurs="0" maxOccurs="unbounded" />
      <!-- turns the way it goes toward the nearest of it, at most that many degrees a frame -->
      <xs:element name="seek" type="targetValueType" minOccurs="0" />
      <xs:group ref="sightParts" />
      <xs:element name="facing" type="directionType" minOccurs="0" />
      <xs:group ref="moveParts" />
      <xs:element name="maze" type="mazeType" minOccurs="0" />
      <!-- on a map with <cells />: the pieces of that name or group behind it follow its trail, a cell each step; <grow /> adds one at the tail -->
      <xs:element name="chain" minOccurs="0">
        <xs:complexType>
          <xs:attribute name="object" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
      <!-- false: out of play (not drawn, touching nothing, not counted) until a <reveal>, <release> or <fire> brings it in -->
      <xs:element name="active" type="xs:boolean" minOccurs="0" />
      <xs:element name="drawn" type="xs:boolean" minOccurs="0" />
      <!-- most: how many copies a <spawn> may have made of it at once -->
      <xs:element name="most" type="xs:positiveInteger" minOccurs="0" />
      <xs:element name="collisions" type="collisionsType" minOccurs="0" />
      <xs:element name="actions" type="actionsType" minOccurs="0" />
      <xs:element name="variables" type="variablesType" minOccurs="0" />
      <xs:element name="timers" type="objectTimersType" minOccurs="0" />
    </xs:sequence>
  </xs:group>

  <xs:complexType name="shapeType">
    <xs:sequence>
      <xs:element name="row" type="xs:string" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="objectType">
    <xs:sequence>
      <xs:element name="sprite" type="spriteType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="animation" type="animationType" minOccurs="0" maxOccurs="unbounded" />
      <!-- both halves, unless it starts from something that has them -->
      <xs:element name="position" type="partialPositionType" minOccurs="0" />
      <xs:group ref="objectParts" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="from" type="xs:string" use="optional" />
  </xs:complexType>

  <!--
    Objects that share a description: a lane of logs or cars, the pads at the
    top of Frogger, a wall of bricks. The group says what its members have in
    common (all of it optional) and each member says only what is its own; what
    a member leaves out it takes from its group, and after that it must be as
    complete as an object. The group's class is every member's, and the group's
    name means all of them.

    The members are either listed, each a <member> (called name="..." if it
    says so, otherwise the group's name, a dot, and its number counting from 1,
    lane3.2), or laid out in <columns> and <rows>: a cell to each place, the
    group's <position> the top left of the first, with <padding> the gaps
    between them. A cell is called the group's name, its column and its row
    (bricks.5.3), counting from 1. A <row number="...">, <column number="...">
    or <cell row="..." column="..."> then changes what the cells it picks have;
    a row or column and a cell may both, and the cell wins, but a row and a
    column (or two rows) that pick one cell may not change the same thing in it.
  -->
  <xs:complexType name="memberType">
    <xs:sequence>
      <xs:element name="sprite" type="spriteChangeType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="animation" type="animationType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="position" type="partialPositionType" minOccurs="0" />
      <xs:element name="velocity" type="partialVector2Type" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="optional" />
  </xs:complexType>

  <!-- One thing a state shows: an object (or a group) by name, a named
       <shows> set, or (in a state's own <shows>) another state, whose objects
       are drawn still underneath. One of the three. -->
  <xs:complexType name="showType">
    <xs:attribute name="object" type="xs:string" use="optional" />
    <xs:attribute name="set" type="xs:string" use="optional" />
    <xs:attribute name="state" type="xs:string" use="optional" />
  </xs:complexType>

  <!--
    What the rows (or columns) it picks change. Its padding is the gap before
    it: a row's <y> the gap above it and its <x> the gaps between its cells, a
    column's <x> the gap to its left. The first row and column have no gap
    before them.
  -->
  <xs:complexType name="lineOfCellsType">
    <xs:sequence>
      <!-- which it picks: number="2", or a <number> each, or <odd /> or <even /> -->
      <xs:choice minOccurs="0">
        <xs:element name="number" type="xs:positiveInteger" maxOccurs="unbounded" />
        <xs:element name="odd" type="emptyType" />
        <xs:element name="even" type="emptyType" />
      </xs:choice>
      <xs:element name="sprite" type="spriteChangeType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="animation" type="animationType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="velocity" type="partialVector2Type" minOccurs="0" />
      <xs:element name="padding" type="partialVector2Type" minOccurs="0" />
      <xs:element name="variables" type="variablesType" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="number" type="xs:positiveInteger" use="optional" />
  </xs:complexType>

  <!-- What one cell changes, and a name of its own. -->
  <xs:complexType name="cellType">
    <xs:sequence>
      <xs:element name="sprite" type="spriteChangeType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="animation" type="animationType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="velocity" type="partialVector2Type" minOccurs="0" />
      <xs:element name="variables" type="variablesType" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="row" type="xs:positiveInteger" use="required" />
    <xs:attribute name="column" type="xs:positiveInteger" use="required" />
    <xs:attribute name="name" type="xs:string" use="optional" />
  </xs:complexType>

  <!-- How a group lays out cells: before its sprites. -->
  <xs:group name="groupLayout">
    <xs:sequence>
      <xs:element name="columns" type="xs:positiveInteger" minOccurs="0" />
      <xs:element name="rows" type="xs:positiveInteger" minOccurs="0" />
      <xs:element name="padding" type="partialVector2Type" minOccurs="0" />
      <!-- each column this much lower than the one before it (higher when
           below 0): a sloped girder of pieces -->
      <xs:element name="slope" type="valueType" minOccurs="0" />
    </xs:sequence>
  </xs:group>

  <!-- What a group gives after its sprites. -->
  <xs:group name="groupParts">
    <xs:sequence>
      <xs:element name="animation" type="animationType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="position" type="partialPositionType" minOccurs="0" />
      <xs:group ref="objectParts" />
    </xs:sequence>
  </xs:group>

  <!-- A group's members, or what changes its cells. -->
  <xs:group name="groupMembers">
    <xs:choice>
      <xs:element name="member" type="memberType" maxOccurs="unbounded" />
      <xs:sequence>
        <xs:element name="row" type="lineOfCellsType" minOccurs="0" maxOccurs="unbounded" />
        <xs:element name="column" type="lineOfCellsType" minOccurs="0" maxOccurs="unbounded" />
        <xs:element name="cell" type="cellType" minOccurs="0" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:choice>
  </xs:group>

  <!-- A group, as an object can be, can start from a piece of the <kit>
       (from=, or named after it); then its members may be left out, and
       given, they replace the piece's. -->
  <xs:complexType name="groupType">
    <xs:sequence>
      <xs:group ref="groupLayout" />
      <xs:element name="sprite" type="spriteType" minOccurs="0" maxOccurs="unbounded" />
      <xs:group ref="groupParts" />
      <xs:choice minOccurs="0">
        <xs:group ref="groupMembers" />
        <xs:element name="group" type="innerGroupType" maxOccurs="unbounded" />
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="from" type="xs:string" use="optional" />
  </xs:complexType>

  <!-- A group inside another: the same, except that a sprite of the outer group's (by name) need only give what changes. -->
  <xs:complexType name="innerGroupType">
    <xs:sequence>
      <xs:group ref="groupLayout" />
      <xs:element name="sprite" type="spriteChangeType" minOccurs="0" maxOccurs="unbounded" />
      <xs:group ref="groupParts" />
      <xs:choice>
        <xs:group ref="groupMembers" />
        <xs:element name="group" type="innerGroupType" maxOccurs="unbounded" />
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="class" type="xs:string" use="optional" />
  </xs:complexType>

  <!--
    An object on a <map>: as any other, but with no <position>; char= picks
    the one tile of the map's rows it starts on.
  -->
  <xs:complexType name="mapObjectType">
    <xs:sequence>
      <!-- none for a <shape>, which its cells draw -->
      <xs:element name="sprite" type="spriteType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="animation" type="animationType" minOccurs="0" maxOccurs="unbounded" />
      <xs:group ref="objectParts" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <!-- on a map with <cells />, left out (or on no tile): it waits to be spawned -->
    <xs:attribute name="char" type="mapCharType" use="optional" />
  </xs:complexType>

  <!--
    A group on a <map>: a member on each tile of the character char= picks,
    or groups inside it that each pick one (and change its sprites by name,
    as an inner group does). The map says where, so it has no layout, no
    <position> and no <member>s.
  -->
  <xs:complexType name="mapGroupType">
    <xs:sequence>
      <xs:element name="sprite" type="spriteChangeType" minOccurs="0" maxOccurs="unbounded" />
      <xs:element name="animation" type="animationType" minOccurs="0" maxOccurs="unbounded" />
      <xs:group ref="objectParts" />
      <xs:element name="group" type="mapGroupType" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="char" type="mapCharType" use="optional" />
  </xs:complexType>

  <!--
    Level data: the size of a tile, where the top left of the map is, its
    <row>s of characters (a character a tile, every row as wide), and the
    groups and objects that say what each character is. A character nothing
    picks is an empty tile. The map's name means everything on it. A map that
    takes a map of the kit (from=, or by its name) gives only what it changes,
    most often its <row>s; each part is then left out here, and the loader
    asks for any the map still lacks.
  -->
  <xs:complexType name="mapType">
    <xs:sequence>
      <xs:element name="tile" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="width" type="valueType" />
            <xs:element name="height" type="valueType" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="position" type="partialVector2Type" minOccurs="0" />
      <!-- how many tiles across and down, for a map with no <row>s -->
      <xs:element name="columns" type="xs:positiveInteger" minOccurs="0" />
      <xs:element name="rows" type="xs:positiveInteger" minOccurs="0" />
      <!-- its pieces move a cell at a time, and a move that is refused touches what refused it -->
      <xs:element name="cells" type="emptyType" minOccurs="0" />
      <xs:element name="row" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="group" type="mapGroupType" />
        <xs:element name="object" type="mapObjectType" />
      </xs:choice>
      <!-- on a map with <cells />: what it asks after something settles -->
      <xs:element name="checks" type="checksType" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="from" type="xs:string" use="optional" />
  </xs:complexType>

  <!-- A cell map's checks: <full> is a row every cell of which holds a loose piece (of class=, if given); its commands run once for each. <line> is every line of so many alike. -->
  <xs:complexType name="checksType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="full">
        <xs:complexType>
          <xs:sequence>
            <xs:group ref="checkCommands" maxOccurs="unbounded" />
          </xs:sequence>
          <xs:attribute name="class" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
      <!-- line: <atleast> so many pieces alike (of one group) in a row, across, down or diagonal; every such line at once, asked again after its commands until none.
           <straight />: across and down only. <alike variable="hue" />: alike by that variable's value instead of by group. -->
      <xs:element name="line">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="atleast" type="xs:positiveInteger" />
            <xs:element name="straight" type="emptyType" minOccurs="0" />
            <xs:element name="alike" minOccurs="0">
              <xs:complexType>
                <xs:attribute name="variable" type="xs:NMTOKEN" use="required" />
              </xs:complexType>
            </xs:element>
            <xs:group ref="checkCommands" maxOccurs="unbounded" />
          </xs:sequence>
          <xs:attribute name="class" type="xs:string" use="optional" />
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:complexType>

  <!-- Objects and groups: the game's, a state's or a scene's. -->
  <xs:complexType name="objectsType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="object" type="objectType" />
      <xs:element name="group" type="groupType" />
      <xs:element name="map" type="mapType" />
      <xs:element name="deck" type="deckType" />
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="conditionsType">
    <xs:sequence>
      <xs:element name="condition" type="conditionType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <!--
    One place of a state: its own numbers (read inside it by their plain
    names), its objects, and the conditions and timers that run while it is
    its state's current scene. from= starts it as a copy of an earlier
    scene: its objects, variables, ways, conditions and timers, changed by
    its own of the same names, and with its own added.
  -->
  <!-- Where a scene's ways lead: <way name="east" scene="screen2" />, a
       scene of the same state, gone to by <enter way="east" />. -->
  <xs:complexType name="waysType">
    <xs:sequence>
      <xs:element name="way" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attribute name="name" type="xs:string" use="required" />
          <xs:attribute name="scene" type="xs:string" use="required" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="sceneType">
    <xs:sequence>
      <xs:element name="ways" type="waysType" minOccurs="0" />
      <xs:element name="variables" type="variablesType" minOccurs="0" />
      <xs:element name="objects" type="objectsType" minOccurs="0" />
      <xs:element name="conditions" type="conditionsType" minOccurs="0" />
      <xs:element name="timers" type="stateTimersType" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="from" type="xs:string" use="optional" />
  </xs:complexType>

  <!-- The scenes; the first is current when the game starts. -->
  <xs:complexType name="scenesType">
    <xs:sequence>
      <xs:element name="scene" type="sceneType" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <!--
    The kit: objects, groups and maps written once, in play only where something
    takes them: an object or group of the game's, a state's or a scene's
    that is from= one (or named after one), or a <spawn>, <fire> or
    <release> that names one, whose copies come into the game beside what
    spawns them. A piece can be from= an earlier piece.
  -->
  <xs:complexType name="kitType">
    <xs:choice maxOccurs="unbounded">
      <xs:element name="object" type="objectType" />
      <xs:element name="group" type="groupType" />
      <xs:element name="map" type="mapType" />
    </xs:choice>
  </xs:complexType>

  <xs:element name="game">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="window">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="width" type="xs:unsignedShort" />
              <xs:element name="height" type="xs:unsignedShort" />
              <!-- scale: each of the game's pixels drawn as a square this many window pixels across -->
              <xs:element name="scale" type="xs:positiveInteger" minOccurs="0" />
              <!-- left out: color.black, false and 60 -->
              <xs:element name="background" type="xs:string" minOccurs="0" />
              <xs:element name="fullscreen" type="xs:boolean" minOccurs="0" />
              <xs:element name="framerate" type="xs:unsignedByte" minOccurs="0" />
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element name="variables">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="variable" type="variableType" maxOccurs="unbounded" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="sounds" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="sound" type="soundType" maxOccurs="unbounded" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="paths" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="path" type="pathType" maxOccurs="unbounded" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <!--
          Named looks for text: a <text style="title"> takes the <size> and
          <color> it leaves out from the <style name="title">.
        -->
        <xs:element name="styles" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="style" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <!-- a <text>'s -->
                    <xs:element name="size" type="valueType" minOccurs="0" />
                    <!-- a <bitmap>'s -->
                    <xs:element name="scale" type="valueType" minOccurs="0" />
                    <!-- either's: the one with no char=; a bitmap's, each char= -->
                    <xs:element name="color" type="bitmapColorType" minOccurs="0" maxOccurs="unbounded" />
                    <!-- a <text>'s font file -->
                    <xs:element name="font" type="xs:string" minOccurs="0" />
                  </xs:sequence>
                  <xs:attribute name="name" type="xs:string" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <!--
          What a pile's cards may make, the lowest first, for a pile's
          <score patterns="name">: each <pattern> one or more parts that all
          hold: <same>N (N cards of one rank; each <same> a rank of its own),
          <run>N (N worths in a row, a card counting any of its <worth>s) and
          <suited>N (N cards of one suit).
        -->
        <xs:element name="patterns" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="pattern" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:choice maxOccurs="unbounded">
                    <xs:element name="same" type="xs:positiveInteger" />
                    <xs:element name="run" type="xs:positiveInteger" />
                    <xs:element name="suited" type="xs:positiveInteger" />
                  </xs:choice>
                  <xs:attribute name="name" type="xs:NMTOKEN" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="name" type="xs:NMTOKEN" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element name="kit" type="kitType" minOccurs="0" />
        <xs:element name="objects" type="objectsType" minOccurs="0" />
        <!--
          What a full <reset /> passes over: each <keep> names an object or a
          group, which keeps what it holds (a best score) into the next game.
        -->
        <xs:element name="keeps" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="keep" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:attribute name="object" type="xs:string" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="states">
          <xs:complexType>
            <xs:sequence>
              <!--
                A named set of key bindings that states can share: a state's
                <inputs keys="name"> takes them, and its own <input>s go over
                them, key by key.
              -->
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="keys">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element name="input" type="inputType" maxOccurs="unbounded" />
                    </xs:sequence>
                    <xs:attribute name="name" type="xs:string" use="required" />
                  </xs:complexType>
                </xs:element>
                <!--
                  A named set of objects that states can share: a state's
                  <show set="name" /> shows them, in order, where it stands.
                  A set can take a set written before it.
                -->
                <xs:element name="shows">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element name="show" type="showType" maxOccurs="unbounded" />
                    </xs:sequence>
                    <xs:attribute name="name" type="xs:string" use="required" />
                  </xs:complexType>
                </xs:element>
                <!--
                  A named set of conditions that states can share: a state's
                  <condition set="name" /> checks them, in order, where it
                  stands. A set can take a set written before it.
                -->
                <xs:element name="conditions">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element name="condition" type="conditionType" maxOccurs="unbounded" />
                    </xs:sequence>
                    <xs:attribute name="name" type="xs:string" use="required" />
                  </xs:complexType>
                </xs:element>
              </xs:choice>
              <xs:element name="state" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <!-- the state's own objects, in play in every scene of it -->
                    <xs:element name="objects" type="objectsType" minOccurs="0" />
                    <xs:element name="scenes" type="scenesType" minOccurs="0" />
                    <xs:element name="shows" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="show" type="showType" maxOccurs="unbounded" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                    <!--
                      music: a sound of the game's that is the state's own.
                      One that loops plays while the state is the current one;
                      one that does not plays once as the state begins.
                    -->
                    <xs:element name="music" minOccurs="0">
                      <xs:complexType>
                        <xs:attribute name="sound" type="xs:string" use="required" />
                      </xs:complexType>
                    </xs:element>
                    <!-- needed, unless the state is from= another, whose it takes -->
                    <xs:element name="inputs" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <!-- the <keys> sets it takes: keys="name", or a <keys> each -->
                          <xs:element name="keys" type="xs:NMTOKEN" minOccurs="0" maxOccurs="unbounded" />
                          <xs:element name="input" type="inputType" minOccurs="0" maxOccurs="unbounded" />
                        </xs:sequence>
                        <xs:attribute name="keys" type="xs:NMTOKEN" use="optional" />
                      </xs:complexType>
                    </xs:element>
                    <xs:element name="conditions" type="conditionsType" minOccurs="0" />
                    <!--
                      computer: a player the game plays itself. Every one of
                      its conditions is tested every frame, and while one
                      holds, the buttons its <hold>s name are held down.
                    -->
                    <xs:element name="computer" type="computerType" minOccurs="0" />
                    <xs:element name="timers" type="stateTimersType" minOccurs="0" />
                  </xs:sequence>
                  <xs:attribute name="name" type="xs:string" use="required" />
                  <!--
                    A copy of an earlier state: its objects (an <object> or
                    <group> of one of their names changes it, as a scene changes
                    a piece it takes), shows, keys, conditions, timers and music,
                    with this one's own over them.
                  -->
                  <xs:attribute name="from" type="xs:string" use="optional" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <!--
          A recorded game for the attract mode (written by recording a game with xgecli):
          the random seed it was played with, how many frames long it is,
          then each key pressed and let go, at the frame it happened. A
          <demo /> command plays it.
        -->
        <xs:element name="demo" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="seed" type="xs:unsignedInt" />
              <xs:element name="frames" type="xs:unsignedInt" />
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="press" type="demoKeyType" />
                <xs:element name="release" type="demoKeyType" />
              </xs:choice>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
