Package org.freerealm.settlement

Examples of org.freerealm.settlement.SettlementBuildable


        xml.append("<population>" + settlement.getPopulation() + "</population>\n");
        xml.append("<productionPoints>" + settlement.getProductionPoints() + "</productionPoints>\n");
        xml.append("<productionQueue>\n");
        Iterator<SettlementBuildable> iterator = settlement.getProductionQueueIterator();
        while (iterator.hasNext()) {
            SettlementBuildable settlementBuildable = iterator.next();
            if (settlementBuildable instanceof SettlementImprovementType) {
                SettlementImprovementType cityImprovementType = (SettlementImprovementType) settlementBuildable;
                xml.append("<queueItem>\n");
                xml.append("<type>SETTLEMENT_IMPROVEMENT</type>\n");
                xml.append("<id>" + cityImprovementType.getId() + "</id>\n");
View Full Code Here


        }
    }

    private void manageCityProduction(Settlement settlement) {
        int productionPoints = settlement.getProductionPoints();
        SettlementBuildable currentProduction = settlement.getCurrentProduction();
        if ((currentProduction != null) && (productionPoints >= currentProduction.getProductionCost())) {
            if (settlement.canBuild(currentProduction)) {
                if (currentProduction instanceof SettlementImprovementType) {
                    Executor.getInstance().execute(new AddSettlementImprovementCommand(settlement, (SettlementImprovementType) currentProduction));
                    settlement.removeFromProductionQueue(0);
                    StringBuffer messageText = new StringBuffer("City of " + settlement.getName() + " has completed " + currentProduction);
                    SettlementImprovementCompletedMessage message = new SettlementImprovementCompletedMessage();
                    message.setSubject("Building complete");
                    message.setText(messageText);
                    message.setTurnSent(realm.getNumberOfTurns());
                    message.setSettlement(settlement);
                    message.setSettlementImprovementType((SettlementImprovementType) currentProduction);
                    message.setNextProduction(settlement.getCurrentProduction());
                    settlement.getPlayer().addMessage(message);
                } else if (currentProduction instanceof UnitType) {
                    if (((UnitType) currentProduction).getAbility("BuildCity") != null) {
                        int cityFoundingPopulation = Integer.parseInt(realm.getProperty("city_founding_population"));
                        if (settlement.getPopulation() < cityFoundingPopulation) {
                            StringBuffer messageText = new StringBuffer("Not enough population for unit");
                            DefaultMessage message = new DefaultMessage();
                            message.setText(messageText);
                            message.setTurnSent(realm.getNumberOfTurns());
                            settlement.getPlayer().addMessage(message);
                            return;
                        }
                        settlement.setPopulation(settlement.getPopulation() - cityFoundingPopulation);
                    }
                    Unit newUnit = new Unit(realm);
                    newUnit.setType((UnitType) currentProduction);
                    newUnit.setCoordinate(settlement.getCoordinate());
                    newUnit.setPlayer(settlement.getPlayer());
                    Executor.getInstance().execute(new AddUnitCommand(settlement.getPlayer(), newUnit));
                    if ((settlement.getPlayer().getActiveUnit() == null)) {
                        Executor.getInstance().execute(new SetActiveUnitCommand(settlement.getPlayer(), newUnit));
                    }
                    if (!settlement.isContiuousProduction()) {
                        settlement.removeFromProductionQueue(0);
                    }
                }
                settlement.setProductionPoints(productionPoints - currentProduction.getProductionCost());
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.freerealm.settlement.SettlementBuildable

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.