package org.freerealm;
import java.util.Iterator;
import org.freerealm.settlement.improvement.SettlementImprovementManager;
import java.util.Properties;
import java.util.Vector;
import org.freerealm.settlement.Settlement;
import org.freerealm.diplomacy.Diplomacy;
import org.freerealm.history.History;
import org.freerealm.map.Coordinate;
import org.freerealm.map.WorldMap;
import org.freerealm.resource.ResourceManager;
import org.freerealm.player.*;
import org.freerealm.tile.Tile;
import org.freerealm.tile.TileTypeManager;
import org.freerealm.tile.improvement.TileImprovementTypeManager;
import org.freerealm.map.PathFinder;
import org.freerealm.nation.NationManager;
import org.freerealm.resource.bonus.BonusResourceManager;
import org.freerealm.unit.UnitTypeManager;
import org.freerealm.vegetation.VegetationManager;
/**
*
* @author Deniz ARIKAN
*/
public class Realm {
private Properties properties;
private ResourceManager resourceManager;
private BonusResourceManager bonusResourceManager;
private TileTypeManager tileTypeManager;
private TileImprovementTypeManager tileImprovementTypeManager;
private VegetationManager vegetationManager;
private UnitTypeManager unitTypeManager;
private SettlementImprovementManager cityImprovementManager;
private NationManager nationManager;
private PlayerManager playerManager;
private int numberOfTurns;
private int managedObjectCount = 0;
private WorldMap worldMap;
private Diplomacy diplomacy;
private PathFinder pathFinder;
private History history;
public Realm() {
numberOfTurns = 0;
properties = new Properties();
}
public static final String getVersion() {
return "0.4.0.8";
}
public int getManagedObjectCount() {
return managedObjectCount++;
}
public void setManagedObjectCount(int managedObjectCount) {
this.managedObjectCount = managedObjectCount;
}
public Settlement getCity(int cityId) {
Iterator<Player> playerIterator = getPlayerManager().getPlayersIterator();
while (playerIterator.hasNext()) {
Player player = playerIterator.next();
Iterator<Settlement> settlementsIterator = player.getSettlementsIterator();
while (settlementsIterator.hasNext()) {
Settlement settlement = settlementsIterator.next();
if (settlement.getId() == cityId) {
return settlement;
}
}
}
return null;
}
public boolean isValidCoordinate(Coordinate coordinate) {
if ((coordinate.getOrdinate() < 0) || (coordinate.getOrdinate() >= getMapHeight())) {
return false;
}
return true;
}
private Coordinate normalizeCoordinate(Coordinate coordinate) {
if (isValidCoordinate(coordinate)) {
int abscissa = (coordinate.getAbscissa() + getMapWidth()) % getMapWidth();
return new Coordinate(abscissa, coordinate.getOrdinate());
} else {
return null;
}
}
public Vector<Coordinate> normalizeCoordinates(Vector<Coordinate> coordinates) {
Vector<Coordinate> normalizedCoordinates = new Vector<Coordinate>();
for (Coordinate coordinate : coordinates) {
Coordinate normalizedCoordinate = normalizeCoordinate(coordinate);
if (normalizedCoordinate != null) {
normalizedCoordinates.add(normalizedCoordinate);
}
}
return normalizedCoordinates;
}
// <editor-fold defaultstate="collapsed" desc="Get, set, add methods ">
public void setPathFinder(PathFinder pathFinder) {
this.pathFinder = pathFinder;
}
public PathFinder getPathFinder() {
return pathFinder;
}
public int getNumberOfTurns() {
return numberOfTurns;
}
public void setNumberOfTurns(int numberOfTurns) {
this.numberOfTurns = numberOfTurns;
}
public int getMapWidth() {
return getWorldMap().getWidth();
}
public int getMapHeight() {
return getWorldMap().getHeight();
}
public TileTypeManager getTileTypeManager() {
return tileTypeManager;
}
public void setTileTypeManager(TileTypeManager tileTypeManager) {
this.tileTypeManager = tileTypeManager;
}
public UnitTypeManager getUnitTypeManager() {
return unitTypeManager;
}
public void setUnitTypeManager(UnitTypeManager unitTypeManager) {
this.unitTypeManager = unitTypeManager;
}
public SettlementImprovementManager getCityImprovementManager() {
return cityImprovementManager;
}
public void setCityImprovementManager(SettlementImprovementManager cityImprovementManager) {
this.cityImprovementManager = cityImprovementManager;
}
public ResourceManager getResourceManager() {
return resourceManager;
}
public void setResourceManager(ResourceManager resourceManager) {
this.resourceManager = resourceManager;
}
public BonusResourceManager getBonusResourceManager() {
return bonusResourceManager;
}
public void setBonusResourceManager(BonusResourceManager bonusResourceManager) {
this.bonusResourceManager = bonusResourceManager;
}
public PlayerManager getPlayerManager() {
return playerManager;
}
public void setPlayerManager(PlayerManager playerManager) {
this.playerManager = playerManager;
}
public WorldMap getWorldMap() {
return worldMap;
}
public void setWorldMap(WorldMap worldMap) {
this.worldMap = worldMap;
}
public Tile getTile(Coordinate coordinate) {
return getWorldMap().getTile(coordinate);
}
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
public String getProperty(String key) {
return properties.getProperty(key);
}
public NationManager getNationManager() {
return nationManager;
}
public void setNationManager(NationManager nationManager) {
this.nationManager = nationManager;
}
public TileImprovementTypeManager getTileImprovementTypeManager() {
return tileImprovementTypeManager;
}
public void setTileImprovementTypeManager(TileImprovementTypeManager tileImprovementTypeManager) {
this.tileImprovementTypeManager = tileImprovementTypeManager;
}
public VegetationManager getVegetationManager() {
return vegetationManager;
}
public void setVegetationManager(VegetationManager vegetationManager) {
this.vegetationManager = vegetationManager;
}
public Diplomacy getDiplomacy() {
return diplomacy;
}
public void setDiplomacy(Diplomacy diplomacy) {
this.diplomacy = diplomacy;
}
public History getHistory() {
return history;
}
public void setHistory(History history) {
this.history = history;
}
// </editor-fold>
}