Package org.freerealm.unit

Examples of org.freerealm.unit.UnitType


    public String toXML() {
        StringBuffer xml = new StringBuffer();
        xml.append("<UnitTypes>\n");
        for (Iterator<UnitType> iterator = unitTypeManager.getUnitTypesIterator(); iterator.hasNext();) {
            UnitType unitType = iterator.next();
            xml.append((new UnitTypeXMLConverter()).toXML(unitType) + "\n");
        }
        xml.append("</UnitTypes>");
        return xml.toString();
    }
View Full Code Here


    }

    public void initializeFromNode(Realm realm, Node node) {
        for (Node unitTypeNode = node.getFirstChild(); unitTypeNode != null; unitTypeNode = unitTypeNode.getNextSibling()) {
            if (unitTypeNode.getNodeType() == Node.ELEMENT_NODE) {
                UnitType unitType = new UnitTypeXMLConverter().initializeFromNode(realm, unitTypeNode);
                unitTypeManager.getUnitTypes().put(unitType.getId(), unitType);
            }
        }
    }
View Full Code Here

        xml.append("</UnitType>");
        return xml.toString();
    }

    public UnitType initializeFromNode(Realm realm, Node node) {
        UnitType unitType = new UnitType();
        int idValue = Integer.parseInt(node.getAttributes().getNamedItem("id").getNodeValue());
        String nameValue = node.getAttributes().getNamedItem("name").getNodeValue();
        int explorationRadius = Integer.parseInt(node.getAttributes().getNamedItem("explorationRadius").getNodeValue());
        int weightForContainerValue = Integer.parseInt(node.getAttributes().getNamedItem("weightForContainer").getNodeValue());
        unitType.setId(idValue);
        unitType.setName(nameValue);
        unitType.setExplorationRadius(explorationRadius);
        unitType.setWeightForContainer(weightForContainerValue);
        for (Node subNode = node.getFirstChild(); subNode != null; subNode = subNode.getNextSibling()) {
            if (subNode.getNodeType() == Node.ELEMENT_NODE) {
                if (subNode.getNodeName().equals("Properties")) {
                    for (Node abilityNode = subNode.getFirstChild(); abilityNode != null; abilityNode = abilityNode.getNextSibling()) {
                        if (abilityNode.getNodeType() == Node.ELEMENT_NODE) {
                            Property ability = PropertyFactory.createProperty(realm, abilityNode);
                            unitType.addAbility(ability);
                        }
                    }
                }
            }
        }
View Full Code Here

                } else if (subNode.getNodeName().equals("skippedForCurrentTurn")) {
                    boolean skippedForCurrentTurnValue = Boolean.parseBoolean(subNode.getFirstChild().getNodeValue());
                    unit.setSkippedForCurrentTurn(skippedForCurrentTurnValue);
                } else if (subNode.getNodeName().equals("type")) {
                    String unitTypeName = subNode.getFirstChild().getNodeValue();
                    UnitType unitType = realm.getUnitTypeManager().getUnitType(unitTypeName);
                    unit.setType(unitType);
                } else if (subNode.getNodeName().equals("Coordinate")) {
                    Coordinate coordinate = new Coordinate();
                    (new CoordinateXMLWrapper(coordinate)).initializeFromNode(realm, subNode);
                    unit.setCoordinate(coordinate);
View Full Code Here

                xml.append("<queueItem>\n");
                xml.append("<type>SETTLEMENT_IMPROVEMENT</type>\n");
                xml.append("<id>" + cityImprovementType.getId() + "</id>\n");
                xml.append("</queueItem>\n");
            } else if (settlementBuildable instanceof UnitType) {
                UnitType unitType = (UnitType) settlementBuildable;
                xml.append("<queueItem>\n");
                xml.append("<type>UNIT</type>\n");
                xml.append("<id>" + unitType.getId() + "</id>\n");
                xml.append("</queueItem>\n");
            }
        }
        xml.append("</productionQueue>\n");
        xml.append("<contiuousProduction>" + settlement.isContiuousProduction() + "</contiuousProduction>\n");
View Full Code Here

                            int id = Integer.parseInt(queueItemIdNode.getFirstChild().getNodeValue());
                            if (queueItemType.equals("SETTLEMENT_IMPROVEMENT")) {
                                SettlementImprovementType cityImprovementType = realm.getSettlementImprovementManager().getImprovement(id);
                                settlement.addToProductionQueue(cityImprovementType);
                            } else if (queueItemType.equals("UNIT")) {
                                UnitType unitType = realm.getUnitTypeManager().getUnitType(id);
                                settlement.addToProductionQueue(unitType);
                            }
                        }
                    }
                } else if (subNode.getNodeName().equals("contiuousProduction")) {
View Full Code Here

    public int getUnitUpkeep() {
        int upkeep = 0;
        Iterator<Unit> unitsIterator = getUnits().values().iterator();
        while (unitsIterator.hasNext()) {
            UnitType unitType = unitsIterator.next().getType();
            upkeep = upkeep + unitType.getUpkeepCost();
        }
        return upkeep;
    }
View Full Code Here

TOP

Related Classes of org.freerealm.unit.UnitType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.