*
* @return
*/
@Override
public Node toXML() {
Node parent = new Node(XML_NAME);
// update sizes and write properties
properties.putInt("rows", rows);
properties.putInt("columns", columns);
parent.appendChild(properties.toXML());
Node child = new Node("Maps");
parent.appendChild(child);
// terrain map
BitBuffer terrainMapBuffer = new BitBuffer(BITSIZE_TERRAINID * rows * columns);
for (int row = 0; row < rows; row++) {
for (int column = 0; column < columns; column++) {
terrainMapBuffer.add(map[row][column].terrainID, BITSIZE_TERRAINID);
}
}
Node schild = new Node("Terrains");
schild.appendChild(terrainMapBuffer.toXMLString());
child.appendChild(schild);
// resources map
BitBuffer resourcesMapBuffer = new BitBuffer((BITSIZE_RESOURCEID + 1) * rows * columns);
for (int row = 0; row < rows; row++) {
for (int column = 0; column < columns; column++) {
resourcesMapBuffer.add(map[row][column].resourceID, BITSIZE_RESOURCEID);
resourcesMapBuffer.add(map[row][column].resourceVisible);
}
}
schild = new Node("Resources");
schild.appendChild(resourcesMapBuffer.toXMLString());
child.appendChild(schild);
// provinces
BitBuffer provinceMapBuffer = new BitBuffer(BITSIZE_PROVINCEID * rows * columns);
for (int row = 0; row < rows; row++) {
for (int column = 0; column < columns; column++) {
provinceMapBuffer.add(map[row][column].provinceID, BITSIZE_PROVINCEID);
}
}
schild = new Node("Provinces");
schild.appendChild(provinceMapBuffer.toXMLString());
child.appendChild(schild);
// railroads
BitBuffer railMapBuffer = new BitBuffer(BITSIZE_RAILROAD_CONFIG * rows * columns);
for (int row = 0; row < rows; row++) {
for (int column = 0; column < columns; column++) {
railMapBuffer.add(map[row][column].railroadConfig, BITSIZE_RAILROAD_CONFIG);
}
}
schild = new Node("Railroads");
schild.appendChild(railMapBuffer.toXMLString());
child.appendChild(schild);
// river overlay
BitBuffer riverBuffer = new BitBuffer(BITSIZE_RIVERID * rows * columns);
for (int row = 0; row < rows; row++) {
for (int column = 0; column < columns; column++) {
riverBuffer.add(map[row][column].riverID, BITSIZE_RIVERID);
}
}
schild = new Node("Rivers");
schild.appendChild(riverBuffer.toXMLString());
child.appendChild(schild);
// nation list
parent.appendChild(nations.toXML());