Skip to content

Commit 1b06743

Browse files
authored
Merge pull request #343 from erik-vos/master
1837: Improvements and bug fixes, part III
2 parents 3c68668 + fdb8d0d commit 1b06743

File tree

11 files changed

+476
-354
lines changed

11 files changed

+476
-354
lines changed

src/main/java/net/sf/rails/common/parser/Tag.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,24 @@ private void parseSubTags(Element element) throws ConfigurationException {
276276
value = attribute.getNodeValue();
277277
attributes.put(name, value);
278278
}
279-
} else if ( "IfOption".equalsIgnoreCase(childTagName)) {
280-
Node nameAttr = nnp.getNamedItem("name");
281-
if (nameAttr == null)
282-
throw new ConfigurationException(
283-
"IfOption has no optionName attribute");
284-
name = nameAttr.getNodeValue();
285-
286-
Node parmAttr = nnp.getNamedItem("parm");
287-
if (parmAttr != null) {
288-
value = parmAttr.getNodeValue();
289-
Iterable<String> parameters = Splitter.on(XMLTags.VALUES_DELIM).split(value);
290-
name = GameOption.constructParameterisedName(name, ImmutableList.copyOf(parameters));
279+
} else if ("IfOption".equalsIgnoreCase(childTagName)
280+
|| "IfVariant".equalsIgnoreCase(childTagName)) {
281+
282+
if ("IfOption".equalsIgnoreCase(childTagName)) {
283+
Node nameAttr = nnp.getNamedItem("name");
284+
if (nameAttr == null)
285+
throw new ConfigurationException(
286+
"IfOption has no optionName attribute");
287+
name = nameAttr.getNodeValue();
288+
289+
Node parmAttr = nnp.getNamedItem("parm");
290+
if (parmAttr != null) {
291+
value = parmAttr.getNodeValue();
292+
Iterable<String> parameters = Splitter.on(XMLTags.VALUES_DELIM).split(value);
293+
name = GameOption.constructParameterisedName(name, ImmutableList.copyOf(parameters));
294+
}
295+
} else { // IfVariant
296+
name = "Variant";
291297
}
292298

293299
Node valueAttr = nnp.getNamedItem("value");

src/main/java/net/sf/rails/game/StartItem.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public class StartItem extends RailsAbstractItem {
3737
protected int column = 0;
3838
protected int index;
3939

40+
// To allow the displayed name to include both primary and secondary.
41+
// Default is the primary name (id) only.
42+
protected String displayName = null;
43+
4044
// Bids
4145
protected final GenericState<Player> lastBidder = new GenericState<>(this, "lastBidder");
4246
protected final Map<Player, CountingMoneyModel> bids = Maps.newHashMap();
@@ -271,6 +275,14 @@ public Certificate getSecondary() {
271275
return secondary;
272276
}
273277

278+
public String getDisplayName() {
279+
return (displayName != null ? displayName : getId());
280+
}
281+
282+
public void setDisplayName(String displayName) {
283+
this.displayName = displayName;
284+
}
285+
274286
/**
275287
* Get the start item base price.
276288
*

src/main/java/net/sf/rails/game/StartPacket.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public class StartPacket extends RailsAbstractItem {
3030
protected int minimumIncrement = 5;
3131
/** The modulus of all bids (i.e. of which value the bid must be a multiple) */
3232
protected int modulus = 5;
33+
/** Is multiple-column display enabled?
34+
* If so, row and col attributes become mandatory for all start items
35+
* (if the <MultipleColumn> tag precedes all start items).*/
36+
protected boolean multipleColumns = false;
37+
/** The number of columns. Will be derived from the column attributes. */
38+
protected int numberOfColumns = 1;
39+
/** The number of rows. Will be derived from the row attributes, if multipleColumns is true. */
40+
protected int numberOfRows;
3341

3442
/** Default name */
3543
public static final String DEFAULT_ID = "Initial";
@@ -56,6 +64,12 @@ public static StartPacket create(RailsItem parent, String id, String roundClassN
5664
* @throws ConfigurationException if anything goes wrong.
5765
*/
5866
public void configureFromXML(Tag tag) throws ConfigurationException {
67+
68+
// Multiple column display?
69+
Tag columnsTag = tag.getChild("MultipleColumns");
70+
multipleColumns = columnsTag != null;
71+
72+
// Bidding parameters, if applicable
5973
Tag biddingTag = tag.getChild("Bidding");
6074
if (biddingTag != null) {
6175
minimumInitialIncrement =
@@ -83,14 +97,27 @@ public void configureFromXML(Tag tag) throws ConfigurationException {
8397

8498
int basePrice = itemTag.getAttributeAsInteger("basePrice", 0);
8599
boolean reduceable = itemTag.getAttributeAsBoolean("reduceable", false);
86-
StartItem item = StartItem.create(this, itemName, itemType, basePrice, reduceable, index++, president);
100+
StartItem item = StartItem.create(this, itemName, itemType,
101+
basePrice, reduceable, index++, president);
87102
items.add(item);
88103

89104
// Optional attributes
90105
int row = itemTag.getAttributeAsInteger("row", 0);
91-
if (row > 0) item.setRow(row);
106+
item.setRow(row);
92107
int column = itemTag.getAttributeAsInteger("column", 0);
93-
if (column > 0) item.setColumn(column);
108+
if (multipleColumns) {
109+
if (!(row > 0 && column > 0)) {
110+
throw new ConfigurationException(
111+
"With multiple columns, both row and column attributes are required");
112+
}
113+
item.setColumn(column);
114+
numberOfRows = Math.max (numberOfRows, row);
115+
numberOfColumns = Math.max (numberOfColumns, column);
116+
}
117+
118+
// Displayed name
119+
String displayName = itemTag.getAttributeAsString("displayName", null);
120+
if (displayName != null) item.setDisplayName(displayName);
94121

95122
// Check if there is another certificate
96123
List<Tag> subItemTags = itemTag.getChildren("SubItem");
@@ -241,4 +268,15 @@ public int getModulus() {
241268
return modulus;
242269
}
243270

271+
public boolean isMultipleColumns() {
272+
return multipleColumns;
273+
}
274+
275+
public int getNumberOfColumns() {
276+
return numberOfColumns;
277+
}
278+
279+
public int getNumberOfRows() {
280+
return numberOfRows;
281+
}
244282
}

src/main/java/net/sf/rails/game/TileUpgrade.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,13 @@ private Rotation processRotations(HexSide side) {
383383
log.debug("base={} target={}", base, target);
384384
}
385385
// check if there are stations to map
386-
Map<Station, Station> stationMapping = assignStations(base, target);
386+
Map<Station, Station> stationMapping = assignStations(base, target);
387387

388388
// Try something else: match sides with old and new Stations in a simple way
389389
// Each pair of stations that matches with the same side is connected.
390390
// This finally appears to work for the 1837 green Vienna upgrade.
391391
// Though it may only work where both base and target tiles have a fixed orientation.
392+
// (may be obsolete, now that automatic relay works better (see issue #341).
392393
if (stationMapping == null) {
393394
stationMapping = new HashMap<>(6);
394395
Station b, t;
@@ -506,8 +507,11 @@ private Map<Station, Station> assignStations(TrackConfig base, TrackConfig targe
506507
}
507508
}
508509
// check if all base and target stations are assigned
509-
if (stationMap.keySet().size() != baseNb ||
510-
Sets.newHashSet(stationMap.values()).size() != targetNb) {
510+
if (stationMap.keySet().size() != baseNb
511+
/* Unclear why the all-stations-mapped check was applied to the new tile.
512+
It inhibited upgrading 1837 Vienna to green (4 -> 6 stations).
513+
|| Sets.newHashSet(stationMap.values()).size() != targetNb*/
514+
) {
511515
stationMap = null;
512516
log.debug("Mapping: Not all stations assigned, set stationMap to null");
513517
}

src/main/java/net/sf/rails/ui/swing/ORUIManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,9 @@ private void relayBaseTokens (LayTile action) {
788788
Tile newTile = action.getLaidTile();
789789
Tile oldTile = hex.getCurrentTile();
790790

791-
// Why does that need to be configured?
792-
// Shouldn't tokens always be relaid??
791+
// Check if manual token relay is required.
792+
// This was an emergency measure in cases where automatic relay
793+
// did not work (e.g. 1837 tile 427). Now probably obsolete.
793794
if (!action.isRelayBaseTokens()
794795
&& !oldTile.relayBaseTokensOnUpgrade()) return; // is deprecated
795796

@@ -798,7 +799,6 @@ private void relayBaseTokens (LayTile action) {
798799
/* Check which tokens must be relaid, and in which sequence.
799800
* Ideally, the game engine should instruct the UI what to do
800801
* if there is more than one stop and more than one token.
801-
* TODO LayTile does not yet allow that.
802802
*
803803
* For now, the only case that needs special handling is the 1835 BA home hex L6,
804804
* where it it possible to have two tokens laid before even one tile.

0 commit comments

Comments
 (0)