<?xml version="1.0" encoding="UTF-8"?>
<!--
    *  Copyright (C) 2002-2021  The FreeCol Team
    *
    *  This file is part of FreeCol.
    *
    *  FreeCol is free software: you can redistribute it and/or modify
    *  it under the terms of the GNU General Public License as published by
    *  the Free Software Foundation, either version 2 of the License, or
    *  (at your option) any later version.
    *
    *  FreeCol is distributed in the hope that it will be useful,
    *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    *  GNU General Public License for more details.
    *
    *  You should have received a copy of the GNU General Public License
    *  along with FreeCol.  If not, see <http://www.gnu.org/licenses/>.

    In case of incompatible changes, please update version number and
    XSD schema for validation.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

  <!-- Nations -->
  <xs:element name="nations">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="nation" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="nation">
    <xs:complexType>
      <xs:attribute name="id" use="required" type="xs:ID"/>
      <xs:attribute name="preserve" use="optional" type="xs:boolean"/>

      <!-- color is not really a string, but XML lacks hex constants -->
      <xs:attribute name="color" use="optional" type="xs:string"/>
      <xs:attribute name="nation-type" use="required" type="NationTypeId"/>
      <xs:attribute name="preferred-latitude" type="xs:int"/>
      <xs:attribute name="ref" type="xs:string"/>
      <xs:attribute name="selectable" type="xs:boolean"/>
      <xs:attribute name="starts-on-east-coast" type="xs:boolean"/>
      <!-- @compat 0.11.3 -->
      <xs:attribute name="preferredLatitude" type="xs:int"/>
      <xs:attribute name="startsOnEastCoast" type="xs:boolean"/>
      <!-- end @compat 0.11.3 -->
    </xs:complexType>
  </xs:element>

  <xs:element name="european-nation-types">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="delete" minOccurs="0" maxOccurs="unbounded" 
                    type="NationTypeId" />

        <xs:element name="european-nation-type" maxOccurs="unbounded" 
                    type="european-nation-type"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="indian-nation-types">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="delete" minOccurs="0" maxOccurs="unbounded" 
                    type="NationTypeId" />

        <xs:element name="indian-nation-type" maxOccurs="unbounded" 
                    type="indian-nation-type"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="nation-type">
    <xs:attribute name="id" use="required" type="xs:string"/>
    <xs:attribute name="extends" type="xs:string" />
    <xs:attribute name="preserve" use="optional" type="xs:boolean"/>

    <xs:attribute name="abstract" type="xs:boolean" />
    <xs:attribute name="aggression">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="high"/>
          <xs:enumeration value="low"/>
          <xs:enumeration value="average"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="number-of-settlements">
      <xs:simpleType>
        <xs:restriction base="xs:token">
          <xs:enumeration value="high"/>
          <xs:enumeration value="low"/>
          <xs:enumeration value="average"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="european-nation-type">
    <xs:complexContent>
      <xs:extension base="nation-type">
        <xs:sequence>
          <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="ability"/>
            <xs:element ref="modifier"/>
            <xs:element ref="settlement"/>
            <xs:element name="unit">
              <xs:complexType>
                <xs:attribute name="id" use="required" type="xs:string"/>

                <xs:attribute name="expert-starting-units" type="xs:string"/>
                <xs:attribute name="missionary" type="xs:boolean"/>
                <xs:attribute name="mounted" type="xs:boolean"/>
                <xs:attribute name="role" type="RoleId"/>
                <xs:attribute name="tools" type="xs:nonNegativeInteger"/>
                <xs:attribute name="type" use="required" type="UnitTypeId"/>
              </xs:complexType>
            </xs:element>
        </xs:choice>
        </xs:sequence>
        <xs:attribute name="ref" type="xs:boolean"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="indian-nation-type">
    <xs:complexContent>
      <xs:extension base="nation-type">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element ref="ability"/>
          <xs:element ref="modifier"/>
          <xs:element name="region">
            <xs:complexType>
              <xs:attribute name="id">
                <xs:simpleType>
                  <xs:restriction base="xs:token">
                    <xs:enumeration value="model.region.center"/>
                    <xs:enumeration value="model.region.north"/>
                    <xs:enumeration value="model.region.northEast"/>
                    <xs:enumeration value="model.region.east"/>
                    <xs:enumeration value="model.region.southEast"/>
                    <xs:enumeration value="model.region.south"/>
                    <xs:enumeration value="model.region.southWest"/>
                    <xs:enumeration value="model.region.west"/>
                    <xs:enumeration value="model.region.northWest"/>
                  </xs:restriction>
                </xs:simpleType>
              </xs:attribute>
            </xs:complexType>
          </xs:element>
          <xs:element ref="settlement"/>
          <xs:element name="skill">
            <xs:complexType>
              <xs:attribute name="id" use="required" type="UnitTypeId"/>
              <xs:attribute name="probability" use="required"
                            type="PercentageType"/>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:element name="settlement">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="ability"/>
        <xs:element name="gifts" type="RandomRange"/>
        <xs:element ref="modifier"/>
        <xs:element ref="plunder"/>
      </xs:choice>
      <xs:attribute name="id" use="required" type="SettlementTypeId"/>
      <xs:attribute name="preserve" use="optional" type="xs:boolean"/>

      <xs:attribute name="capital" type="xs:boolean"/>
      <xs:attribute name="claimable-radius" type="xs:integer"/>
      <xs:attribute name="convert-threshold" type="xs:integer"/>
      <xs:attribute name="extra-claimable-radius" type="xs:integer"/>
      <xs:attribute name="maximum-growth" type="xs:integer"/>
      <xs:attribute name="maximum-size" type="xs:integer"/>
      <xs:attribute name="minimum-growth" type="xs:integer"/>
      <xs:attribute name="minimum-size" type="xs:integer"/>
      <xs:attribute name="trade-bonus" type="xs:integer"/>
      <xs:attribute name="visible-radius" type="xs:integer"/>
      <xs:attribute name="wandering-radius" type="xs:integer"/>
      <!-- @compat 0.11.3 -->
      <xs:attribute name="claimableRadius" type="xs:integer"/>
      <xs:attribute name="convertThreshold" type="xs:integer"/>
      <xs:attribute name="extraClaimableRadius" type="xs:integer"/>
      <xs:attribute name="maximumGrowth" type="xs:integer"/>
      <xs:attribute name="maximumSize" type="xs:integer"/>
      <xs:attribute name="minimumGrowth" type="xs:integer"/>
      <xs:attribute name="minimumSize" type="xs:integer"/>
      <xs:attribute name="tradeBonus" type="xs:integer"/>
      <xs:attribute name="visibleRadius" type="xs:integer"/>
      <xs:attribute name="wanderingRadius" type="xs:integer"/>
      <!-- end @compat 0.11.3 -->
    </xs:complexType>
  </xs:element>

  <xs:element name="plunder">
    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="RandomRange" >
          <!-- Should be required -->
          <xs:attribute name="id" type="xs:string" use="optional"/>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>


</xs:schema>
