Skip to content

Commit

Permalink
Merge branch 'bigtop'
Browse files Browse the repository at this point in the history
  • Loading branch information
farin committed Dec 27, 2021
2 parents a79e330 + a20e50f commit 47bf043
Show file tree
Hide file tree
Showing 27 changed files with 543 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/jcloisterzone/action/MeepleAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@ public MeepleAction merge(MeepleAction ma) {
}
return new MeepleAction(meepleType, options, origin);
}

}
11 changes: 11 additions & 0 deletions src/main/java/com/jcloisterzone/action/ScoreAcrobatsAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jcloisterzone.action;

import com.jcloisterzone.board.pointer.FeaturePointer;
import io.vavr.collection.Set;

public class ScoreAcrobatsAction extends AbstractPlayerAction<FeaturePointer> implements SelectFeatureAction {

public ScoreAcrobatsAction(Set<FeaturePointer> options) {
super(options);
}
}
28 changes: 19 additions & 9 deletions src/main/java/com/jcloisterzone/board/TileBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,22 @@ public Tile createTile(String tileId, Element tileElement, boolean isTunnelActiv
processRiverElement(el);
break;
case "tower":
initFeature(el, new Tower(), new FeaturePointer(Position.ZERO, Tower.class, Location.I));
initFeature(el, new Tower());
break;
case "yaga-hut":
initFeature(el, new YagaHut(), new FeaturePointer(Position.ZERO, YagaHut.class, Location.I));
initFeature(el, new YagaHut());
break;
case "watchtower":
tileModifiers = tileModifiers.add(new WatchtowerCapability.WatchtowerModifier(el.getAttribute("bonus")));
break;
case "circus":
// init feature even if capability is not enabled, because of ringmaster scoring
initFeature(el, new Circus());
break;
case "acrobats":
// init feature even if capability is not enabled, because of ringmaster scoring
initFeature(el, new Acrobats());
break;
}
}

Expand Down Expand Up @@ -150,14 +158,16 @@ public Tile createTile(String tileId, Element tileElement, boolean isTunnelActiv
return tileDef;
}

public void initFeature(Element xml, Feature feature, FeaturePointer fp) {
public void initFeature(Element xml, Feature feature) {
if (feature instanceof Field && tileId.startsWith("CO/")) {
//this is not part of Count capability because it is integral behaviour valid also when capability is off
feature = ((Field) feature).setAdjoiningCityOfCarcassonne(true);
}
for (Capability<?> cap: state.getCapabilities().toSeq()) {
feature = cap.initFeature(state, tileId, feature, xml);
}

FeaturePointer fp = feature.getPlaces().get();
features.put(fp, feature);

if (feature instanceof NeighbouringFeature) {
Expand Down Expand Up @@ -191,7 +201,7 @@ private Map<FeatureModifier<?>, Object> getFeatureModifiers(String featureType,
private void processMonasteryElement(Element e) {
Map<FeatureModifier<?>, Object> modifiers = getFeatureModifiers("monastery", e);
Monastery monastery = new Monastery(modifiers);
initFeature(e, monastery, new FeaturePointer(Position.ZERO, Monastery.class, Location.I));
initFeature(e, monastery);
}

private void processRoadElement(Element e, boolean isTunnelActive) {
Expand All @@ -213,7 +223,7 @@ private void processRoadElement(Stream<Location> sides, Element e, boolean isTun
if (isTunnelActive && attributeBoolValue(e, "tunnel")) {
road = road.setOpenTunnelEnds(HashSet.of(fp));
}
initFeature(e, road, fp);
initFeature(e, road);
}

private void processCityElement(Element e) {
Expand All @@ -233,21 +243,21 @@ private void processCityElement(Element e) {

Map<FeatureModifier<?>, Object> modifiers = getFeatureModifiers("city", e);
City city = new City(List.of(fp), openEdges, modifiers);
initFeature(e, city, fp);
initFeature(e, city);

if (e.hasAttribute("city-gate")) {
attrAsLocations(e, "city-gate").forEach(loc -> {
assert loc.isEdge();
FeaturePointer gateFp = new FeaturePointer(Position.ZERO, CityGate.class, loc);
initFeature(null, new CityGate(List.of(gateFp), fp), gateFp);
initFeature(null, new CityGate(List.of(gateFp), fp));
});
}
}

private void processRiverElement(Element e) {
Stream<Location> sides = contentAsLocations(e);
FeaturePointer fp = initFeaturePointer(sides, River.class);
initFeature(e, new River(List.of(fp)), fp);
initFeature(e, new River(List.of(fp)));
}

private void processFieldElement(Element e) {
Expand Down Expand Up @@ -278,7 +288,7 @@ private void processFieldElement(Element e) {

Map<FeatureModifier<?>, Object> modifiers = getFeatureModifiers("field", e);
Field field = new Field(List.of(fp), adjoiningCities, false, modifiers);
initFeature(e, field, fp);
initFeature(e, field);
}

private FeaturePointer initFeaturePointer(Stream<Location> sides, Class<? extends Feature> clazz) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/jcloisterzone/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ private Map<Class<? extends Meeple>, Integer> addMeeples(
}

private Set<Class<? extends Capability<?>>> addCapabilities(
Set<Class<? extends Capability<?>>> capabilties, GameSetupMessage setupMsg, String key, Class<? extends Capability<?>> cls) {
Set<Class<? extends Capability<?>>> capabilities, GameSetupMessage setupMsg, String key, Class<? extends Capability<?>> cls) {
Object value = setupMsg.getElements().get(key);
if (value == null) {
return capabilties;
return capabilities;
}
return capabilties.add(cls);
return capabilities.add(cls);
}

private GameSetup createSetupFromMessage(GameSetupMessage setupMsg) {
Expand All @@ -96,6 +96,7 @@ private GameSetup createSetupFromMessage(GameSetupMessage setupMsg) {
meeples = addMeeples(meeples, setupMsg, "wagon", Wagon.class);
meeples = addMeeples(meeples, setupMsg, "mayor", Mayor.class);
meeples = addMeeples(meeples, setupMsg, "shepherd", Shepherd.class);
meeples = addMeeples(meeples, setupMsg, "ringmaster", Ringmaster.class);

Set<Class<? extends Capability<?>>> capabilities = HashSet.empty();
capabilities = addCapabilities(capabilities, setupMsg,"abbot", AbbotCapability.class);
Expand All @@ -104,6 +105,7 @@ private GameSetup createSetupFromMessage(GameSetupMessage setupMsg) {
capabilities = addCapabilities(capabilities, setupMsg,"phantom", PhantomCapability.class);
capabilities = addCapabilities(capabilities, setupMsg,"shepherd", SheepCapability.class);
capabilities = addCapabilities(capabilities, setupMsg,"wagon", WagonCapability.class);
capabilities = addCapabilities(capabilities, setupMsg,"ringmaster", RingmasterCapability.class);

capabilities = addCapabilities(capabilities, setupMsg,"dragon", DragonCapability.class);
capabilities = addCapabilities(capabilities, setupMsg,"fairy", FairyCapability.class);
Expand Down Expand Up @@ -132,6 +134,8 @@ private GameSetup createSetupFromMessage(GameSetupMessage setupMsg) {
capabilities = addCapabilities(capabilities, setupMsg,"vineyard", VineyardCapability.class);
capabilities = addCapabilities(capabilities, setupMsg,"shrine", ShrineCapability.class);
capabilities = addCapabilities(capabilities, setupMsg,"festival", FestivalCapability.class);
capabilities = addCapabilities(capabilities, setupMsg,"big-top", BigTopCapability.class);
capabilities = addCapabilities(capabilities, setupMsg,"acrobats", AcrobatsCapability.class);

capabilities = addCapabilities(capabilities, setupMsg,"river", RiverCapability.class);
capabilities = addCapabilities(capabilities, setupMsg,"corn-circle", CornCircleCapability.class);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/jcloisterzone/engine/StateGsonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Gson create() {
builder.registerTypeAdapter(GoldPieceAction.class, new GoldPieceActionSerializer());
builder.registerTypeAdapter(RemoveMageOrWitchAction.class, new ActionSerializer("RemoveMageOrWitch"));
builder.registerTypeAdapter(LittleBuildingAction.class, new LittleBuildingActionSerializer());
builder.registerTypeAdapter(ScoreAcrobatsAction.class, new SelectFeatureActionSerializer());
return builder.create();
}

Expand Down Expand Up @@ -281,6 +282,12 @@ public JsonElement serializeNeutralFigures(GameState root, JsonSerializationCont
data.add("placement", context.serialize(fp));
neutral.add("count", data);
}
pos = state.getBigTopDeployment();
if (pos != null) {
JsonObject data = new JsonObject();
data.add("placement", context.serialize(pos));
neutral.add("bigtop", data);
}
return neutral;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public PointsExpression(String name, ExprItem...items) {
this(name, List.of(items));
}


public int getPoints() {
return items.map(exp -> exp.getPoints()).sum().intValue();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jcloisterzone/event/ScoreEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ScoreEvent extends PlayEvent {
private static final long serialVersionUID = 1L;

private final List<ReceivedPoints> points;
private final boolean landscapeSource;
private final boolean landscapeSource; // only landscape sources trigger Count (when adds points to opponent)
private final boolean isFinal;

public ScoreEvent(List<ReceivedPoints> points, boolean landscapeSource, boolean isFinal) {
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/jcloisterzone/feature/Acrobats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.jcloisterzone.feature;

import com.jcloisterzone.board.Location;
import com.jcloisterzone.board.Position;
import com.jcloisterzone.board.Rotation;
import com.jcloisterzone.board.pointer.FeaturePointer;

import io.vavr.collection.List;

public class Acrobats extends TileFeature implements Structure {

public static final List<FeaturePointer> INITIAL_PLACE = List.of(new FeaturePointer(Position.ZERO, Acrobats.class, Location.I));

public Acrobats() {
super(INITIAL_PLACE);
}

public Acrobats(List<FeaturePointer> places) {
super(places);
}

@Override
public Feature placeOnBoard(Position pos, Rotation rot) {
return new Acrobats(placeOnBoardPlaces(pos, rot));
}

public static String name() {
return "Acrobats";
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/jcloisterzone/feature/Circus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.jcloisterzone.feature;

import com.jcloisterzone.board.Location;
import com.jcloisterzone.board.Position;
import com.jcloisterzone.board.Rotation;
import com.jcloisterzone.board.pointer.FeaturePointer;
import io.vavr.collection.List;


public class Circus extends TileFeature implements Structure {

private static final List<FeaturePointer> INITIAL_PLACE = List.of(new FeaturePointer(Position.ZERO, Circus.class, Location.I));

public Circus() {
this(INITIAL_PLACE);
}

public Circus(List<FeaturePointer> places) {
super(places);
}

@Override
public Feature placeOnBoard(Position pos, Rotation rot) {
return new Circus(placeOnBoardPlaces(pos, rot));
}

public static String name() {
return "Circus";
}
}
1 change: 0 additions & 1 deletion src/main/java/com/jcloisterzone/figure/Follower.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.jcloisterzone.feature.Scoreable;
import com.jcloisterzone.game.capability.TowerCapability;
import com.jcloisterzone.game.state.GameState;

import io.vavr.collection.Array;
import io.vavr.collection.List;
import io.vavr.collection.Stream;
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/jcloisterzone/figure/Ringmaster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.jcloisterzone.figure;

import com.jcloisterzone.Immutable;
import com.jcloisterzone.Player;
import com.jcloisterzone.board.pointer.FeaturePointer;
import com.jcloisterzone.feature.Acrobats;
import com.jcloisterzone.feature.Structure;
import com.jcloisterzone.game.state.GameState;

@Immutable
public class Ringmaster extends SmallFollower {

private static final long serialVersionUID = 1L;

public Ringmaster(String id, Player player) {
super(id, player);
}

@Override
public DeploymentCheckResult isDeploymentAllowed(GameState state, FeaturePointer fp, Structure feature) {
if (feature instanceof Acrobats) {
return new DeploymentCheckResult("Cannot place ringmaster on the acrobats space.");
}
return super.isDeploymentAllowed(state, fp, feature);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/jcloisterzone/figure/neutral/BigTop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.jcloisterzone.figure.neutral;

import com.jcloisterzone.Immutable;
import com.jcloisterzone.board.Position;

@Immutable
public class BigTop extends NeutralFigure<Position> {

private static final long serialVersionUID = 1L;

public BigTop(String id) {
super(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public GameStatePhaseReducer(GameSetup setup, double initialRandom) {
next = new DragonPhase(randomGenerator, next);
}
if (setup.contains(CountCapability.class)) next = new CocFollowerPhase(randomGenerator, next);
if (setup.contains(BigTopCapability.class)) next = new BigTopPhase(randomGenerator, next);
if (setup.contains(WagonCapability.class)) next = new WagonPhase(randomGenerator, next);
next = new ScoringPhase(randomGenerator, next);
if (setup.contains(CountCapability.class)) next = new CocScoringPhase(randomGenerator, next);
Expand Down
Loading

0 comments on commit 47bf043

Please sign in to comment.