private Castle replaceCityWithCastle(Tile tile, Location loc) { ListIterator<Feature> iter = tile.getFeatures().listIterator(); City city = null; while (iter.hasNext()) { Feature feature = iter.next(); if (feature.getLocation() == loc) { city = (City) feature; break; } } List<Meeple> meeples = new ArrayList<>(city.getMeeples()); // collection copy required!!! undeploy modify it for (Meeple m : meeples) { m.undeploy(); } Castle castle = new Castle(); castle.setTile(tile); castle.setId(game.idSequnceNextVal()); castle.setLocation(loc.rotateCCW(tile.getRotation())); iter.set(castle); for (Feature f : tile.getFeatures()) { // replace also city references if (f instanceof Farm) { Farm farm = (Farm) f; Feature[] adjoining = farm.getAdjoiningCities(); if (adjoining != null) { for (int i = 0; i < adjoining.length; i++) { if (adjoining[i] == city) { adjoining[i] = castle; break; } } } } } FeaturePointer fp = new FeaturePointer(tile.getPosition(), loc); for (Meeple m : meeples) { if (m.getPlayer() == game.getActivePlayer() && m.isDeploymentAllowed(castle).result) { m.deploy(fp); } } return castle; }
private void scoreFollowersOnBarnFarm(Farm farm, Map<City, CityScoreContext> cityCache) { FarmScoreContext ctx = farm.getScoreContext(); ctx.setCityCache(cityCache); farm.walk(ctx); boolean hasBarn = false; for (Meeple m : ctx.getSpecialMeeples()) { if (m instanceof Barn) { hasBarn = true; break; } } if (hasBarn) { for (Player p : ctx.getMajorOwners()) { int points = ctx.getPointsWhenBarnIsConnected(p); game.scoreFeature(points, ctx, p); } for (Meeple m : ctx.getMeeples()) { if (!(m instanceof Barn)) { m.undeploy(false); } } } }
@Override public boolean visit(Feature feature) { Farm farm = (Farm) feature; if (farm.isAdjoiningCityOfCarcassonne()) { adjoiningCityOfCarcassonne = true; } if (farm.getAdjoiningCities() != null) { addAdjoiningCompletedCities(farm.getAdjoiningCities()); } for (Meeple m : farm.getMeeples()) { if (m instanceof Pig) { pigs.add(m.getPlayer()); } } if (farm.isPigHerd()) { pigHerd = true; } return super.visit(feature); }
@Override public FarmScoreContext getFarmScoreContext(Farm farm) { return farm.getScoreContext(); }