Migrate <change> to <tile-type-change>.

This commit is contained in:
Mike Pope 2016-07-17 09:53:26 +09:30
parent ab3857daaa
commit eca52c6409
8 changed files with 196 additions and 89 deletions

View File

@ -29,14 +29,22 @@
<scope type="model.tile.arctic" match-negated="true" />
<scope type="model.tile.hills" match-negated="true" />
<scope type="model.tile.mountains" match-negated="true" />
<change from="model.tile.plains" to="model.tile.mixedForest"/>
<change from="model.tile.grassland" to="model.tile.coniferForest"/>
<change from="model.tile.prairie" to="model.tile.broadleafForest"/>
<change from="model.tile.savannah" to="model.tile.tropicalForest"/>
<change from="model.tile.marsh" to="model.tile.wetlandForest"/>
<change from="model.tile.swamp" to="model.tile.rainForest"/>
<change from="model.tile.desert" to="model.tile.scrubForest"/>
<change from="model.tile.tundra" to="model.tile.borealForest"/>
<tile-type-change from="model.tile.plains"
to="model.tile.mixedForest"/>
<tile-type-change from="model.tile.grassland"
to="model.tile.coniferForest"/>
<tile-type-change from="model.tile.prairie"
to="model.tile.broadleafForest"/>
<tile-type-change from="model.tile.savannah"
to="model.tile.tropicalForest"/>
<tile-type-change from="model.tile.marsh"
to="model.tile.wetlandForest"/>
<tile-type-change from="model.tile.swamp"
to="model.tile.rainForest"/>
<tile-type-change from="model.tile.desert"
to="model.tile.scrubForest"/>
<tile-type-change from="model.tile.tundra"
to="model.tile.borealForest"/>
</tile-improvement-type>
</tile-improvement-types>
</freecol-specification>

View File

@ -20,7 +20,7 @@
In case of incompatible changes, please update version number and
XSD schema for validation.
-->
<freecol-specification id="classic" version="0.107">
<freecol-specification id="classic" version="0.108">
<!-- Modifiers that are not attached to other game object
types. They may be modified, but MUST NOT be removed. -->
@ -1363,30 +1363,37 @@
expended-amount="1"
expose-resource-percent="5">
<scope method-name="isForested" method-value="true" />
<change from="model.tile.mixedForest" to="model.tile.plains">
<tile-type-change from="model.tile.mixedForest" to="model.tile.plains">
<production goods-type="model.goods.lumber" value="20" />
</change>
<change from="model.tile.coniferForest" to="model.tile.grassland">
</tile-type-change>
<tile-type-change from="model.tile.coniferForest"
to="model.tile.grassland">
<production goods-type="model.goods.lumber" value="20" />
</change>
<change from="model.tile.broadleafForest" to="model.tile.prairie">
</tile-type-change>
<tile-type-change from="model.tile.broadleafForest"
to="model.tile.prairie">
<production goods-type="model.goods.lumber" value="20" />
</change>
<change from="model.tile.tropicalForest" to="model.tile.savannah">
</tile-type-change>
<tile-type-change from="model.tile.tropicalForest"
to="model.tile.savannah">
<production goods-type="model.goods.lumber" value="20" />
</change>
<change from="model.tile.wetlandForest" to="model.tile.marsh">
</tile-type-change>
<tile-type-change from="model.tile.wetlandForest"
to="model.tile.marsh">
<production goods-type="model.goods.lumber" value="20" />
</change>
<change from="model.tile.rainForest" to="model.tile.swamp">
</tile-type-change>
<tile-type-change from="model.tile.rainForest"
to="model.tile.swamp">
<production goods-type="model.goods.lumber" value="20" />
</change>
<change from="model.tile.scrubForest" to="model.tile.desert">
</tile-type-change>
<tile-type-change from="model.tile.scrubForest"
to="model.tile.desert">
<production goods-type="model.goods.lumber" value="10" />
</change>
<change from="model.tile.borealForest" to="model.tile.tundra">
</tile-type-change>
<tile-type-change from="model.tile.borealForest"
to="model.tile.tundra">
<production goods-type="model.goods.lumber" value="20" />
</change>
</tile-type-change>
</tile-improvement-type>
<tile-improvement-type id="model.improvement.fishBonusLand" natural="true"
zIndex="250">

View File

@ -20,7 +20,7 @@
In case of incompatible changes, please update version number and
XSD schema for validation.
-->
<freecol-specification id="freecol" version="0.107" extends="classic">
<freecol-specification id="freecol" version="0.108" extends="classic">
<goods-types>
<goods-type id="model.goods.horses" is-farmed="false"

View File

@ -273,6 +273,7 @@
<xs:element ref="scope"/>
<xs:choice>
<xs:element ref="modifier"/>
<xs:element ref="tile-type-change"/>
<xs:element ref="change"/>
<xs:element name="disaster">
<xs:complexType>
@ -316,7 +317,10 @@
<xs:element ref="scope"/>
<xs:choice>
<xs:element ref="modifier"/>
<xs:element ref="tile-type-change"/>
<!-- @compat 0.11.6 -->
<xs:element ref="change"/>
<!-- end @compat 0.11.6 -->
<xs:element name="disaster">
<xs:complexType>
<xs:attribute name="id" type="xs:string"/>
@ -345,7 +349,18 @@
<!-- end @compat 0.10.x -->
</xs:complexType>
</xs:element>
<xs:element name="tile-type-change">
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:element name="production" type="AbstractGoodsType" />
</xs:sequence>
<xs:attribute name="from" use="required" type="TileTypeId"/>
<xs:attribute name="to" use="required" type="TileTypeId"/>
</xs:complexType>
</xs:element>
<!-- @compat 0.11.6 -->
<xs:element name="change">
<xs:complexType>
<xs:sequence minOccurs="0">
@ -355,6 +370,7 @@
<xs:attribute name="to" use="required" type="TileTypeId"/>
</xs:complexType>
</xs:element>
<!-- end @compat 0.11.6 -->
<xs:element name="action">
<xs:complexType>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- XSD for specification version 0.107
<!-- XSD for specification version 0.108
CHANGELOG:
0.26: add capture-equipment
0.27: add limits
@ -84,6 +84,7 @@
0.105: Fix capitalization in Operand.
0.106: Add priority to unit-type.
0.107: Improve unit changes.
0.108: Start migrating <change> to <tile-type-change>.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:annotation>
@ -390,6 +391,7 @@
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="scope"/>
<xs:choice>
<xs:element ref="tile-type-change"/>
<xs:element ref="change"/>
<xs:element name="disaster">
<xs:complexType>
@ -438,7 +440,10 @@
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="scope"/>
<xs:choice>
<xs:element ref="tile-type-change"/>
<!-- @compat 0.11.6 -->
<xs:element ref="change"/>
<!-- end @compat 0.11.6 -->
<xs:element name="disaster">
<xs:complexType>
<xs:attribute name="id" type="xs:string"/>
@ -470,7 +475,9 @@
<!-- end @compat 0.10.x -->
</xs:complexType>
</xs:element>
<!-- @compat 0.11.6
Replace the non-specific "change" with tile-type-change. -->
<xs:element name="change">
<xs:complexType>
<xs:sequence>
@ -480,7 +487,18 @@
<xs:attribute name="to" use="required" type="TileTypeId"/>
</xs:complexType>
</xs:element>
<!-- end @compat 0.11.6 -->
<xs:element name="tile-type-change">
<xs:complexType>
<xs:sequence>
<xs:element name="production" type="AbstractGoodsType"/>
</xs:sequence>
<xs:attribute name="from" use="required" type="TileTypeId"/>
<xs:attribute name="to" use="required" type="TileTypeId"/>
</xs:complexType>
</xs:element>
<xs:element name="action">
<xs:complexType>
<xs:attribute name="name" use="required" type="xs:string"/>

View File

@ -42,12 +42,15 @@ import static net.sf.freecol.common.util.CollectionUtils.*;
* A FreeColSpecObjectType does not always need a reference to the
* specification. However, if it has attributes or children that are
* themselves FreeColSpecObjectTypes, then the specification must be
* set before the type is de-serialized, otherwise the identifiers can
* not be resolved.
* set before the type is de-serialized, otherwise the identifiers
* therein can not be resolved.
*
* FreeColSpecObjectTypes can be abstract. Abstract types can be used
* to derive other types, but can not be instantiated. They will be
* removed from the Specification after it has loaded completely.
*
* Many FreeColSpecObjectTypes have ids, but some leaf types do not
* need them and there they may be omitted.
*/
public abstract class FreeColSpecObjectType extends FreeColSpecObject
implements Named {
@ -272,7 +275,6 @@ public abstract class FreeColSpecObjectType extends FreeColSpecObject
@Override
protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException {
super.readAttributes(xr);
if (getId() == null) throw new XMLStreamException("Null id");
this.abstractType = xr.getAttribute(ABSTRACT_TAG, false);
}

View File

@ -385,7 +385,6 @@ public final class TileImprovementType extends FreeColSpecObjectType {
// Serialization
private static final String ADD_WORK_TURNS_TAG = "add-work-turns";
private static final String CHANGE_TAG = "change";
private static final String DELIVER_AMOUNT_TAG = "deliver-amount";
private static final String DELIVER_GOODS_TYPE_TAG = "deliver-goods-type";
private static final String DISASTER_TAG = "disaster";
@ -398,6 +397,7 @@ public final class TileImprovementType extends FreeColSpecObjectType {
private static final String PROBABILITY_TAG = "probability";
private static final String REQUIRED_IMPROVEMENT_TAG = "required-improvement";
private static final String REQUIRED_ROLE_TAG = "required-role";
private static final String TILE_TYPE_CHANGE_TAG = "tile-type-change";
private static final String TO_TAG = "to";
private static final String WORKER_TAG = "worker";
private static final String ZINDEX_TAG = "zIndex";
@ -406,8 +406,10 @@ public final class TileImprovementType extends FreeColSpecObjectType {
// end @compat 0.10.x
// @compat 0.11.3
private static final String OLD_EXPOSE_RESOURCE_PERCENT_TAG = "exposeResourcePercent";
// end @compat 0.11.3
// @compat 0.11.6
private static final String OLD_CHANGE_TAG = "change";
// end @compat 0.11.6
/**
@ -548,24 +550,31 @@ public final class TileImprovementType extends FreeColSpecObjectType {
final Specification spec = getSpecification();
final String tag = xr.getLocalName();
if (CHANGE_TAG.equals(tag)) {
TileTypeChange change = new TileTypeChange();
if (deliverGoodsType == null) {
change.readFromXML(xr, spec);
} else {
// @compat 0.10.4
if (TILE_TYPE_CHANGE_TAG.equals(tag)) {
TileTypeChange change = new TileTypeChange(xr, spec);
if (change != null) addChange(change);
// @compat 0.11.6
} else if (OLD_CHANGE_TAG.equals(tag)) {
// @compat 0.10.4
if (deliverGoodsType != null) {
TileTypeChange change = new TileTypeChange(spec);
TileType from = xr.getType(spec, FROM_TAG,
TileType.class, (TileType)null);
TileType to = xr.getType(spec, TO_TAG,
TileType.class, (TileType)null);
xr.closeTag(OLD_CHANGE_TAG);
change.setFrom(from);
change.setTo(to);
change.setProduction(new AbstractGoods(deliverGoodsType,
deliverAmount));
xr.closeTag(CHANGE_TAG);
// end @compat
addChange(change);
} else {
// end @compat 0.10.4
TileTypeChange change = new TileTypeChange(xr, spec);
if (change != null) addChange(change);
}
addChange(change);
// end @compat 0.11.6
} else if (DISASTER_TAG.equals(tag)) {
Disaster disaster = xr.getType(spec, ID_ATTRIBUTE_TAG,

View File

@ -30,7 +30,7 @@ import net.sf.freecol.common.util.Utils;
/**
* A change in a tile type, including some bonus production when this occurs.
*/
public class TileTypeChange implements Comparable<TileTypeChange> {
public class TileTypeChange extends FreeColSpecObjectType {
/** The original tile type. */
private TileType from;
@ -45,6 +45,29 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
private AbstractGoods production;
/**
* Create a new tile type change.
*
* @param specification The <code>Specification</code> to refer to.
*/
public TileTypeChange(Specification specification) {
super(specification);
}
/**
* Creates a new <code>TileTypeChange</code> instance.
*
* @param xr The <code>FreeColXMLReader</code> to read from.
* @param specification The <code>Specification</code> to refer to.
* @exception XMLStreamException if an error occurs
*/
public TileTypeChange(FreeColXMLReader xr, Specification specification) throws XMLStreamException {
this(specification);
readFromXML(xr);
}
/**
* Gets the original tile type.
*
@ -54,6 +77,7 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
return from;
}
// @compat 0.10.4
/**
* Set the original tile type.
*
@ -62,6 +86,7 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
public final void setFrom(final TileType from) {
this.from = from;
}
// end @compat 0.10.4
/**
* Gets the destination tile type.
@ -72,6 +97,7 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
return to;
}
// @compat 0.10.4
/**
* Set the destination tile type.
*
@ -80,6 +106,7 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
public final void setTo(final TileType to) {
this.to = to;
}
// end @compat 0.10.4
/**
* Gets the production consequent to the type change.
@ -90,6 +117,7 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
return production;
}
// @compat 0.10.4
/**
* Set the production consequent to the type change.
*
@ -98,23 +126,28 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
public final void setProduction(final AbstractGoods production) {
this.production = production;
}
// end @compat 0.10.4
// Interface Comparable<TileTypeChange>
// Override FreeColObject
/**
* {@inheritDoc}
*/
@Override
public int compareTo(TileTypeChange other) {
int cmp;
cmp = (from == null) ? ((other.from == null) ? 0 : -1)
: (other.from == null) ? 1
: FreeColObject.compareIds(from, other.from);
if (cmp != 0) return cmp;
return (to == null) ? ((other.to == null) ? 0 : -1)
: (other.to == null) ? 1
: FreeColObject.compareIds(to, other.to);
public int compareTo(FreeColObject fco) {
int cmp = 0;
if (fco instanceof TileTypeChange) {
TileTypeChange other = (TileTypeChange)fco;
cmp = (from == null) ? ((other.from == null) ? 0 : -1)
: (other.from == null) ? 1
: FreeColObject.compareIds(from, other.from);
if (cmp == 0) cmp = (to == null) ? ((other.to == null) ? 0 : -1)
: (other.to == null) ? 1
: FreeColObject.compareIds(to, other.to);
}
if (cmp == 0) cmp = super.compareTo(fco);
return cmp;
}
// Override Object
@ -136,9 +169,9 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
@Override
public int hashCode() {
int hash = super.hashCode();
hash = 37 * hash + Utils.hashCode(from);
hash = 37 * hash + Utils.hashCode(to);
return 37 * hash + Utils.hashCode(production);
hash = 37 * hash + Utils.hashCode(this.from);
hash = 37 * hash + Utils.hashCode(this.to);
return 37 * hash + Utils.hashCode(this.production);
}
@ -152,46 +185,60 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
/**
* Makes an XML-representation of this object.
*
* @param xw The <code>FreeColXMLWriter</code> to write to.
* @throws XMLStreamException if there are any problems writing to the
* stream.
* {@inheritDoc}
*/
public void toXML(FreeColXMLWriter xw) throws XMLStreamException {
xw.writeStartElement(getTagName());
@Override
protected void writeAttributes(FreeColXMLWriter xw) throws XMLStreamException {
// No id, so no super.writeAttributes().
xw.writeAttribute(FROM_TAG, from);
xw.writeAttribute(FROM_TAG, this.from);
xw.writeAttribute(TO_TAG, to);
if (production != null) {
xw.writeStartElement(PRODUCTION_TAG);
xw.writeAttribute(GOODS_TYPE_TAG, production.getType());
xw.writeAttribute(VALUE_TAG, production.getAmount());
xw.writeEndElement();
}
xw.writeEndElement();
xw.writeAttribute(TO_TAG, this.to);
}
/**
* Reads this object from an XML stream.
*
* @param xr The XML input stream.
* @param spec The <code>Specification</code> to use.
* @throws XMLStreamException if a problem was encountered
* during parsing.
* {@inheritDoc}
*/
public void readFromXML(FreeColXMLReader xr,
Specification spec) throws XMLStreamException {
@Override
protected void writeChildren(FreeColXMLWriter xw) throws XMLStreamException {
super.writeChildren(xw);
if (this.production != null) {
xw.writeStartElement(PRODUCTION_TAG);
xw.writeAttribute(GOODS_TYPE_TAG, this.production.getType());
xw.writeAttribute(VALUE_TAG, this.production.getAmount());
xw.writeEndElement();
}
}
/**
* {@inheritDoc}
*/
@Override
protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException {
// No id, so no super.readAttributes().
final Specification spec = getSpecification();
from = xr.getType(spec, FROM_TAG, TileType.class, (TileType)null);
to = xr.getType(spec, TO_TAG, TileType.class, (TileType)null);
}
/**
* {@inheritDoc}
*/
@Override
protected void readChildren(FreeColXMLReader xr) throws XMLStreamException {
final Specification spec = getSpecification();
// Clear containers.
if (xr.shouldClearContainers()) {
this.production = null;
}
while (xr.nextTag() != XMLStreamConstants.END_ELEMENT) {
final String tag = xr.getLocalName();
@ -201,7 +248,7 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
int amount = xr.getAttribute(VALUE_TAG, 0);
production = new AbstractGoods(type, amount);
this.production = new AbstractGoods(type, amount);
xr.closeTag(PRODUCTION_TAG);
@ -222,9 +269,9 @@ public class TileTypeChange implements Comparable<TileTypeChange> {
/**
* Gets the tag name of the root element representing this object.
*
* @return "change".
* @return "tile-type-change".
*/
public static String getTagName() {
return "change";
return "tile-type-change";
}
}