}
}
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());
}
}
}