Skip to content

Commit

Permalink
fix #134: allow abbot placement on tile already surrounded by 8 tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
farin committed Apr 26, 2015
1 parent 4252486 commit 2fcab25
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 85 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -13,6 +13,7 @@
* fix: chat panel now auto hides again
* fix #123: after selecting "play again", game dialog don't hide ai unsupported expansion
* fix #124: non-bidding bidding bazaars and tile stealing
* fix #134: allow abbot placement on tile already surrounded by 8 tiles
* online play: fixed "continue" and wrong player order and names when game created with RANDOM_SEATING_ORDER
* online play: chat is available after game ends

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/jcloisterzone/board/Tile.java
Expand Up @@ -248,6 +248,12 @@ public Set<Location> getUnoccupiedScoreables(boolean excludeCompleted) {
Set<Location> locations = new HashSet<>();
for (Feature f : features) {
if (f instanceof Scoreable) {
if (f instanceof Cloister) {
Cloister c = (Cloister) f;
if (c.isMonastery() && c.getMeeples().isEmpty()) {
locations.add(Location.ABBOT);
}
}
IsOccupied visitor;
if (excludeCompleted && f instanceof Completable) {
visitor = new IsOccupiedOrCompleted();
Expand Down
Expand Up @@ -17,6 +17,7 @@
import com.jcloisterzone.board.Position;
import com.jcloisterzone.board.Tile;
import com.jcloisterzone.board.pointer.FeaturePointer;
import com.jcloisterzone.feature.Cloister;
import com.jcloisterzone.feature.Completable;
import com.jcloisterzone.feature.Feature;
import com.jcloisterzone.feature.visitor.IsCompleted;
Expand Down Expand Up @@ -83,6 +84,13 @@ private List<Feature> getReachableFeatures() {
Tile target = getBoard().get(pos);
if (target != null) {
for (Feature f : target.getFeatures()) {
if (f instanceof Cloister) {
Cloister cloister = (Cloister) f;
if (cloister.isMonastery()) {
result.add(f); //monastery is always valid target
continue;
}
}
if (f instanceof Completable) {
if (f.walk(new IsCompleted())) continue;
result.add(f);
Expand Down
@@ -1,16 +1,9 @@
package com.jcloisterzone.game.capability;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Element;

import com.jcloisterzone.action.MeepleAction;
import com.jcloisterzone.action.PlayerAction;
import com.jcloisterzone.board.Location;
import com.jcloisterzone.board.RemoveTileException;
import com.jcloisterzone.board.Tile;
import com.jcloisterzone.board.pointer.FeaturePointer;
import com.jcloisterzone.feature.Cloister;
import com.jcloisterzone.feature.Feature;
import com.jcloisterzone.game.Capability;
Expand Down Expand Up @@ -40,17 +33,4 @@ public void initTile(Tile tile, Element xml) {
}
}
}

@Override
public void postPrepareActions(List<PlayerAction<?>> actions) {
for (MeepleAction ma : findFollowerActions(actions)) {
List<FeaturePointer> abbots = new ArrayList<>();
for (FeaturePointer fp : ma.getOptions()) {
if (fp.getLocation() == Location.CLOISTER && ((Cloister) getBoard().get(fp)).isMonastery()) {
abbots.add(new FeaturePointer(fp.getPosition(), Location.ABBOT));
}
}
ma.addAll(abbots);
}
}
}
Expand Up @@ -6,6 +6,7 @@
import com.jcloisterzone.board.Tile;
import com.jcloisterzone.board.pointer.FeaturePointer;
import com.jcloisterzone.event.SelectActionEvent;
import com.jcloisterzone.feature.Cloister;
import com.jcloisterzone.feature.Completable;
import com.jcloisterzone.feature.Feature;
import com.jcloisterzone.feature.visitor.IsCompleted;
Expand Down Expand Up @@ -46,6 +47,13 @@ public void enter() {
MeepleAction action = new MeepleAction(meepleType);
for (Feature f : target.getFeatures()) {
if (!(f instanceof Completable)) continue;
if (f instanceof Cloister) {
Cloister cloister = (Cloister) f;
if (cloister.isMonastery()) {
action.add(new FeaturePointer(pos, Location.ABBOT));
}
}

if (f.walk(new IsCompleted())) continue;
if (follower.isDeploymentAllowed(f).result) {
action.add(new FeaturePointer(pos, f.getLocation()));
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/jcloisterzone/game/phase/WagonPhase.java
Expand Up @@ -12,6 +12,7 @@
import com.jcloisterzone.board.Tile;
import com.jcloisterzone.board.pointer.FeaturePointer;
import com.jcloisterzone.event.SelectActionEvent;
import com.jcloisterzone.feature.Cloister;
import com.jcloisterzone.feature.Feature;
import com.jcloisterzone.feature.MultiTileFeature;
import com.jcloisterzone.feature.visitor.FeatureVisitor;
Expand Down Expand Up @@ -136,6 +137,12 @@ public boolean visit(Feature feature) {

if (feature.getNeighbouring() != null) {
for (Feature nei : feature.getNeighbouring()) {
if (nei instanceof Cloister) {
Cloister cloister = (Cloister) nei;
if (cloister.isMonastery() && cloister.getMeeples().isEmpty()) {
wagonMoves.add(new FeaturePointer(nei.getTile().getPosition(), Location.ABBOT));
}
}
if (nei.walk(new IsOccupiedOrCompleted())) continue;
wagonMoves.add(new FeaturePointer(nei.getTile().getPosition(), nei.getLocation()));
}
Expand Down
79 changes: 14 additions & 65 deletions src/main/java/com/jcloisterzone/ui/grid/layer/FeatureAreaLayer.java
Expand Up @@ -6,21 +6,14 @@

import javax.swing.JOptionPane;

import com.jcloisterzone.Player;
import com.jcloisterzone.action.BridgeAction;
import com.jcloisterzone.action.MeepleAction;
import com.jcloisterzone.action.PlayerAction;
import com.jcloisterzone.action.SelectFeatureAction;
import com.jcloisterzone.action.TowerPieceAction;
import com.jcloisterzone.board.Location;
import com.jcloisterzone.board.Position;
import com.jcloisterzone.board.Tile;
import com.jcloisterzone.board.pointer.FeaturePointer;
import com.jcloisterzone.feature.Farm;
import com.jcloisterzone.feature.Feature;
import com.jcloisterzone.feature.Tower;
import com.jcloisterzone.figure.Follower;
import com.jcloisterzone.game.capability.TowerCapability;
import com.jcloisterzone.ui.GameController;
import com.jcloisterzone.ui.grid.ActionLayer;
import com.jcloisterzone.ui.grid.GridPanel;
Expand All @@ -33,6 +26,7 @@ public class FeatureAreaLayer extends AbstractAreaLayer implements ActionLayer<S

private SelectFeatureAction action;
private boolean abbotOption = false;
private boolean abbotOnlyOption = false;

public FeatureAreaLayer(GridPanel gridPanel, GameController gc) {
super(gridPanel, gc);
Expand All @@ -50,10 +44,15 @@ public SelectFeatureAction getAction() {

protected Map<Location, Area> prepareAreas(Tile tile, Position p) {
abbotOption = false;
abbotOnlyOption = false;
Set<Location> locations = action.getLocations(p);
if (locations == null) return null;
if (locations.contains(Location.ABBOT)) {
abbotOption = true;
if (!locations.contains(Location.CLOISTER)) {
locations.add(Location.CLOISTER);
abbotOnlyOption = true;
}
locations.remove(Location.ABBOT);
}
if (action instanceof BridgeAction) {
Expand All @@ -64,81 +63,31 @@ protected Map<Location, Area> prepareAreas(Tile tile, Position p) {
}


// private boolean confirmFarmPlacement() {
// String options[] = {_("Place a follower"), _("Cancel") };
// int result = JOptionPane.showOptionDialog(getClient(),
// _("Do you really want to place a follower on farm?"),
// _("Confirm follower placement"),
// JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
// return JOptionPane.YES_OPTION == result;
// }
//
// private boolean confirmTowerPlacement(Position pos) {
// int result;
// Player activePlayer = getGame().getActivePlayer();
// if (getGame().getCapability(TowerCapability.class).getTowerPieces(activePlayer) > 0) {
// String options[] = {
// _("Confirm follower placement"),
// _("Cancel"),
// _("Place a tower piece")
// };
// result = JOptionPane.showOptionDialog(getClient(),
// _("Do you really want to place a follower on the tower?\n(To prevent tower from adding more pieces on the top)"),
// _("Confirm follower placement"),
// JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
// } else {
// String options[] = {
// _("Confirm follower placement"),
// _("Cancel")
// };
// result = JOptionPane.showOptionDialog(getClient(),
// _("Do you really want to place a follower on the tower?\n(To prevent tower from adding more pieces on the top)"),
// _("Confirm follower placement"),
// JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
// }
// if (result == JOptionPane.CANCEL_OPTION) {
// //place tower piece instead
// for (PlayerAction<?> action : getClient().getControlPanel().getActionPanel().getActions()) {
// if (action instanceof TowerPieceAction) {
// ((TowerPieceAction) action).perform(getRmiProxy(), pos);
// gridPanel.hideLayer(this);
// return false;
// }
// }
// return false;
// }
// return result == JOptionPane.YES_OPTION;
// }


@Override
protected void performAction(final Position pos, Location loc) {
if (action instanceof MeepleAction) {
MeepleAction ma = (MeepleAction) action;
Feature piece = gridPanel.getTile(pos).getFeature(loc);
// if (piece instanceof Farm) {
// if (Follower.class.isAssignableFrom(ma.getMeepleType()) && getClient().getConfig().getConfirm().getFarm_place()) {
// if (!confirmFarmPlacement()) return;
// }
// } else if (piece instanceof Tower) {
// if (getClient().getConfig().getConfirm().getTower_place()) {
// if (!confirmTowerPlacement(pos)) return;
// }
// }

if (loc == Location.FLIER) {
getClient().getConnection().send(new DeployFlierMessage(getGame().getGameId(), ma.getMeepleType()));
return;
}
if (loc == Location.CLOISTER && abbotOption) {
String options[] = {_("Place as monk"), _("Place as abbot") };
String[] options;
if (abbotOnlyOption) {
options = new String[] {_("Place as abbot")};
} else {
options = new String[] {_("Place as monk"), _("Place as abbot") };
}
int result = JOptionPane.showOptionDialog(getClient(),
_("How do you want to place follower on monastery?"),
_("Monastery"),
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if (result == -1) { //closed dialog
return;
}
if (result == JOptionPane.NO_OPTION) {
if (abbotOnlyOption || result == JOptionPane.NO_OPTION) {
loc = Location.ABBOT;
}
}
Expand Down
Expand Up @@ -124,6 +124,7 @@ public PointStatsPanel() {
rowSpec.append("20"); //gap
if (game.hasCapability(KingAndRobberBaronCapability.class)) rowSpec.append("[][]20");
if (game.hasCapability(ClothWineGrainCapability.class)) rowSpec.append("[]");
if (game.hasCapability(GoldminesCapability.class)) rowSpec.append("[]");
if (game.hasCapability(FairyCapability.class)) rowSpec.append("[]");
if (game.hasCapability(TowerCapability.class)) rowSpec.append("[]");
if (hasBazaars) rowSpec.append("[]");
Expand Down

0 comments on commit 2fcab25

Please sign in to comment.