/** * Constructor which sets up a new City for a particular Player, with optional City name, Town * Center name, Brute name, Assigned Work. If any of these optional values are null, they will be * set to default values (e.g. "New City", etc.). * * @param playerId * @param cityName * @param townCenterName * @param bruteName * @param assignedWork * @throws DataSourceParseException * @throws UnitNotFoundException * @throws BuildingAtMaxGarrisonException * @throws InvalidBuildingProductionTypeException */ public City( Integer playerId, String cityName, String townCenterName, String bruteName, ArrayList<Integer> assignedWork) throws DataSourceParseException, UnitNotFoundException, BuildingAtMaxGarrisonException, InvalidBuildingProductionTypeException { this.setId(0); if (cityName == null || cityName.equals(null) || cityName.isEmpty() || cityName.equals("")) { this.setName("New City"); } else { this.setName(cityName); } // this.setOwner(Player.getInstance(playerId)); this.setOwner(playerId); // new Town Center ArrayList<Building> newBuildings = new ArrayList<Building>(); Building b = new Building(1); if (townCenterName == null || townCenterName.equals(null) || townCenterName.isEmpty() || townCenterName.equals("")) { // keep default Town Center name } else { b.setName(townCenterName); } b.setCity(this.getId()); // new Brute Unit u = new Unit(1); if (bruteName == null || bruteName.equals(null) || bruteName.isEmpty() || bruteName.equals("")) { // keep default Brute name } else { u.setName(bruteName); } b.addOccupant(u.getId()); b.addGarrisonedUnit(u.getId()); newBuildings.add(b); this.setBuildings(newBuildings); // calculate new City offense & defense Integer off = 0; Integer def = 0; Iterator<Building> it = newBuildings.iterator(); while (it.hasNext()) { Building temp = it.next(); off += temp.getOffense(); def += temp.getDefense(); } this.setOffense(off); this.setDefense(def); this.setPopulation(100); // default Resources this.addResource(1, 0); this.addResource(2, 0); this.addResource(3, 0); this.addResource(4, 0); this.addResource(5, 0); this.addResource(6, 0); this.addResource(7, 0); this.addResource(8, 100); this.addResource(9, 100); this.setValue(this.getResourceValue()); this.setHappiness(this.getHappinessValue()); this.setScore(this.getValue() + this.getHappiness() + this.getPopulation()); this.setImage(null); ArrayList<Integer> work = new ArrayList<Integer>(); if (assignedWork == null || assignedWork.equals(null) || assignedWork.isEmpty() || assignedWork.size() == 0) { work.add(0); // farmers work.add(0); // miners work.add(0); // lumberjacks work.add(0); // merchants work.add(0); // civil defense work.add(100); // unemployed this.setAssignedWork(work); } else { this.setAssignedWork(assignedWork); } }