/** {@inheritDoc} */ @Override protected void readChild(FreeColXMLReader xr) throws XMLStreamException { final Game game = getGame(); final String tag = xr.getLocalName(); if (ALARM_TAG.equals(tag)) { Player player = xr.findFreeColGameObject(game, PLAYER_TAG, Player.class, (Player) null, true); // @compat 0.10.5 if (getName() != null) { // Alarm used to imply contact, but only set contacted if // we also have a valid name for the settlement. setContacted(player); } // end @compat alarm.put(player, new Tension(xr.getAttribute(VALUE_TAG, 0))); xr.closeTag(ALARM_TAG); } else if (CONTACT_LEVEL_TAG.equals(tag)) { ContactLevel cl = xr.getAttribute(LEVEL_TAG, ContactLevel.class, ContactLevel.UNCONTACTED); Player player = xr.findFreeColGameObject(game, PLAYER_TAG, Player.class, (Player) null, true); contactLevels.put(player, cl); xr.closeTag(CONTACT_LEVEL_TAG); // @compat 0.10.5 } else if (IS_VISITED_TAG.equals(tag)) { Player player = xr.findFreeColGameObject(game, PLAYER_TAG, Player.class, (Player) null, true); setScouted(player); xr.closeTag(IS_VISITED_TAG); // end @compat } else if (MISSIONARY_TAG.equals(tag)) { xr.nextTag(); missionary = xr.readFreeColGameObject(game, Unit.class); missionary.setLocationNoUpdate(this); xr.closeTag(MISSIONARY_TAG); // @compat 0.10.1 } else if (OLD_UNITS_TAG.equals(tag)) { while (xr.nextTag() != XMLStreamConstants.END_ELEMENT) { super.readChild(xr); } // end @compat } else if (OWNED_UNITS_TAG.equals(tag)) { Unit unit = xr.makeFreeColGameObject(game, ID_ATTRIBUTE_TAG, Unit.class, true); addOwnedUnit(unit); xr.closeTag(OWNED_UNITS_TAG); } else { super.readChild(xr); } }
/** {@inheritDoc} */ @Override protected void writeAttributes(FreeColXMLWriter xw) throws XMLStreamException { super.writeAttributes(xw); final Player hated = getMostHated(); if (getName() != null) { // Delegated from Settlement xw.writeAttribute(NAME_TAG, getName()); } if (xw.validFor(getOwner())) { xw.writeAttribute(LAST_TRIBUTE_TAG, lastTribute); xw.writeAttribute(CONVERT_PROGRESS_TAG, convertProgress); } if (learnableSkill != null) { xw.writeAttribute(LEARNABLE_SKILL_TAG, learnableSkill); } for (int i = 0; i < wantedGoods.length; i++) { if (wantedGoods[i] != null) { xw.writeAttribute(WANTED_GOODS_TAG + i, wantedGoods[i]); } } if (hated != null) xw.writeAttribute(MOST_HATED_TAG, hated); }
/** {@inheritDoc} */ @Override public void disposeResources() { // Orphan the units whose home settlement this is. while (!ownedUnits.isEmpty()) { ownedUnits.remove(0).setHomeIndianSettlement(null); } super.disposeResources(); }
/** {@inheritDoc} */ @Override protected void readChildren(FreeColXMLReader xr) throws XMLStreamException { // Clear containers. contactLevels.clear(); alarm.clear(); missionary = null; ownedUnits.clear(); super.readChildren(xr); // @compat 0.10.1 for (Unit u : getUnitList()) { if (u.getLocation() != this) { u.setLocationNoUpdate(this); logger.warning("Fixing unit location" + " from " + u.getLocation() + " to " + this.getId()); } } // end @compat }
/** {@inheritDoc} */ @Override protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException { super.readAttributes(xr); final Specification spec = getSpecification(); lastTribute = xr.getAttribute(LAST_TRIBUTE_TAG, 0); convertProgress = xr.getAttribute(CONVERT_PROGRESS_TAG, 0); learnableSkill = xr.getType(spec, LEARNABLE_SKILL_TAG, UnitType.class, (UnitType) null); mostHated = xr.findFreeColGameObject(getGame(), MOST_HATED_TAG, Player.class, (Player) null, false); for (int i = 0; i < wantedGoods.length; i++) { wantedGoods[i] = xr.getType(spec, WANTED_GOODS_TAG + i, GoodsType.class, (GoodsType) null); } }
/** {@inheritDoc} */ @Override protected void writeChildren(FreeColXMLWriter xw) throws XMLStreamException { super.writeChildren(xw); if (missionary != null) { xw.writeStartElement(MISSIONARY_TAG); missionary.toXML(xw); xw.writeEndElement(); } if (xw.validFor(getOwner())) { for (Player p : getSortedCopy(contactLevels.keySet())) { xw.writeStartElement(CONTACT_LEVEL_TAG); xw.writeAttribute(LEVEL_TAG, contactLevels.get(p)); xw.writeAttribute(PLAYER_TAG, p); xw.writeEndElement(); } for (Player p : getSortedCopy(alarm.keySet())) { xw.writeStartElement(ALARM_TAG); xw.writeAttribute(PLAYER_TAG, p); xw.writeAttribute(VALUE_TAG, alarm.get(p).getValue()); xw.writeEndElement(); } for (Unit unit : getSortedCopy(ownedUnits)) { xw.writeStartElement(OWNED_UNITS_TAG); xw.writeAttribute(ID_ATTRIBUTE_TAG, unit); xw.writeEndElement(); } } else { Player client = xw.getClientPlayer(); ContactLevel cl = contactLevels.get(client); if (cl != null) { xw.writeStartElement(CONTACT_LEVEL_TAG); xw.writeAttribute(LEVEL_TAG, cl); xw.writeAttribute(PLAYER_TAG, client); xw.writeEndElement(); } Tension alarm = getAlarm(client); if (alarm != null) { xw.writeStartElement(ALARM_TAG); xw.writeAttribute(PLAYER_TAG, client); xw.writeAttribute(VALUE_TAG, alarm.getValue()); xw.writeEndElement(); } } }