<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="gsystem">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="unbounded" ref="datablock"/>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="referenceblock"/>
      </xs:sequence>
      <xs:attributeGroup ref="attlist.gsystem"/>
    </xs:complexType>
  </xs:element>
  <xs:attributeGroup name="attlist.gsystem">
    <xs:attribute name="name" use="required"/>
  </xs:attributeGroup>

  <xs:element name="datablock">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="data"/>
      </xs:sequence>
      <xs:attributeGroup ref="attlist.datablock"/>
    </xs:complexType>
  </xs:element>
  <xs:attributeGroup name="attlist.datablock">
    <xs:attribute name="name" use="required"/>
  </xs:attributeGroup>
  
  <xs:element name="data">
    <xs:complexType mixed="true">
      <xs:attributeGroup ref="attlist.data"/>
    </xs:complexType>
  </xs:element>
  <xs:attributeGroup name="attlist.data">
    <xs:attribute name="name" use="required"/>
    <xs:attribute name="type" use="required">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="text"/>
          <xs:enumeration value="numeric"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="renamable" default="y"/>
    <xs:attribute name="repeatable" default="y"/>
    <!-- Symbols are used in place of numbers in some games, such as in WoD -->
    <xs:attribute name="symbol"/>
    <!-- Quickedit attributes are special fields that are frequently edited or referenced
         from the character sheet view such as health, recording adventure awards, and 
         spendable traits. 
         
         Never set quickedit on a data element with renamable set to "y". This can cause
         the QuickEdit function in the character sheet window to work incorrectly.-->
    <xs:attribute name="quickedit" default="y"/>
    <!-- Fields that should be included in combat summary output should be flagged. -->
    <xs:attribute name="c_summary" default="y"/>
  </xs:attributeGroup>
  
  <!-- The reference section is used to show tooltips as well as more detailed notes.
       Tooltips should be quite brief, shown when the mouse hovers over the item. 
       A reference element should contain either no other elements, a number of list
       elements or a number of sr elements.
  -->
  <xs:element name="referenceblock">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="reference"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="reference">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="list"/>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="sr"/>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="link"/>
        <xs:element minOccurs="0" maxOccurs="1" ref="math"/>
      </xs:sequence>
      <xs:attributeGroup ref="attlist.reference"/>
    </xs:complexType>
  </xs:element>
  <xs:attributeGroup name="attlist.reference">
    <xs:attribute name="name" use="required"/>
    <xs:attribute name="tooltip"/>
  </xs:attributeGroup>
  
  <!-- A name of a list may be included in order to help organize references 
         since some games contain a great number of specific options.
    -->
  <xs:element name="list">
    <xs:complexType mixed="true"/>
  </xs:element>
  <xs:element name="sr">
    <xs:complexType mixed="true">
      <xs:attributeGroup ref="attlist.sr"/>
    </xs:complexType>
  </xs:element>
  <xs:attributeGroup name="attlist.sr">
    <!-- Attributes for sr (style runs) are defined as follows:
         b = bold, i = italic, u = underline. They can be t "true" or f "false".
         f is the name of the font
         c is the color of the font (format is #RRGGBB where RR = hex code for 
         red intensity, GG for green, BB for blue.)
         s is the size of the font in pixels. -->
    <xs:attribute name="b">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="t"/>
          <xs:enumeration value="f"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="i">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="t"/>
          <xs:enumeration value="f"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="u">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="t"/>
          <xs:enumeration value="f"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="f"/>
    <xs:attribute name="c"/>
    <xs:attribute name="s"/>
  </xs:attributeGroup>
  <!-- Use the link element to include an html link. Should appear at the bottom
       of the information text area. -->
  <xs:element name="link">
    <xs:complexType mixed="true">
      <xs:attribute name="url"/>
    </xs:complexType>
  </xs:element>
  
  <!-- Use the Math section to describe functions for UCV to perform in the Enter 
       Data window. This should be described in a form like Reverse Polish Notation
       where references to numbers are entered followed by a function to perform on them.
  
       The kind of result should also be specified. This may be an integer or a decimal value.
       If the result should be represented in a number of symbols, such as dots or boxes,
       UCS will detect this and format it appropriately.-->
  <xs:element name="math">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="unbounded" ref="enter"/>
        <xs:element minOccurs="1" maxOccurs="1" ref="result"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="enter">
    <xs:complexType mixed="true">
      <xs:attributeGroup ref="attlist.function"/>
    </xs:complexType>
  </xs:element>
  <xs:attributeGroup name="attlist.function">
    <xs:attribute name="function">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="number"/>  <!-- enter a number -->
          <xs:enumeration value="variable"/> <!-- enter a number corresponding to //data[@name='variable']/text() -->
          <xs:enumeration value="add"/> <!-- add all entries -->
          <xs:enumeration value="multiply"/> <!-- multiply all entries -->
          <xs:enumeration value="subtract"/> <!-- subtract last two entries -->
          <xs:enumeration value="divide"/> <!-- divide last two entries -->
          <xs:enumeration value="min"/> <!-- get the smallest number -->
          <xs:enumeration value="max"/> <!-- get the largest number -->
          <xs:enumeration value="mod"/> <!-- get the remainder -->
          <xs:enumeration value="round"/> <!-- round to nearest whole number -->
          <xs:enumeration value="integer"/> <!-- convert to integer (rounds down) -->
          <xs:enumeration value="ceil"/> <!-- round up -->
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:attributeGroup>
  <xs:element name="result">
    <xs:complexType mixed="true">
      <xs:attributeGroup ref="attlist.format"/>
    </xs:complexType>
  </xs:element>
  <xs:attributeGroup name="attlist.format">
    <xs:attribute name="output">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="integer"/> 
          <xs:enumeration value="decimal"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:attributeGroup>
</xs:schema>
