package org.freerealm.property;
import java.util.Iterator;
import java.util.Vector;
import org.freerealm.tile.Tile;
import org.freerealm.tile.TileBuildablePrerequisite;
import org.freerealm.tile.improvement.TileImprovementType;
/**
*
* @author Deniz ARIKAN
*/
public class BuildTileImprovement implements Property {
private static final String NAME = "BuildTileImprovement";
private int productionPoints;
private Vector<TileImprovementType> tileImprovements = new Vector<TileImprovementType>();
public String getName() {
return NAME;
}
public boolean canBuildTileImprovement(TileImprovementType tileImprovement, Tile tile) {
if (tile.hasImprovement(tileImprovement)) {
return false;
}
if (!getTileImprovements().contains(tileImprovement)) {
return false;
}
if (!tileImprovement.canBeBuiltOnTileType(tile.getType())) {
return false;
}
Iterator<TileBuildablePrerequisite> tileBuildablePrerequisiteIterator = tileImprovement.getPrerequisitesIterator();
while (tileBuildablePrerequisiteIterator.hasNext()) {
TileBuildablePrerequisite tileBuildablePrerequisite = tileBuildablePrerequisiteIterator.next();
tileBuildablePrerequisite.setTile(tile);
if (!tileBuildablePrerequisite.isSatisfied()) {
return false;
}
}
return true;
}
public Vector<TileImprovementType> getTileImprovements() {
return tileImprovements;
}
public int getProductionPoints() {
return productionPoints;
}
public void setProductionPoints(int productionPoints) {
this.productionPoints = productionPoints;
}
}