|
From: <ev...@us...> - 2011-03-06 13:05:49
|
Revision: 1493
http://rails.svn.sourceforge.net/rails/?rev=1493&view=rev
Author: evos
Date: 2011-03-06 13:05:43 +0000 (Sun, 06 Mar 2011)
Log Message:
-----------
Fixed bad neighbour calculation in NS maps with letters vertical and A odd
Modified Paths:
--------------
trunk/18xx/rails/game/MapHex.java
trunk/18xx/rails/game/MapManager.java
trunk/18xx/rails/ui/swing/hexmap/GUIHex.java
Modified: trunk/18xx/rails/game/MapHex.java
===================================================================
--- trunk/18xx/rails/game/MapHex.java 2011-03-05 20:10:40 UTC (rev 1492)
+++ trunk/18xx/rails/game/MapHex.java 2011-03-06 13:05:43 UTC (rev 1493)
@@ -356,6 +356,7 @@
public void setNeighbor(int orientation, MapHex neighbour) {
orientation %= 6;
neighbours[orientation] = neighbour;
+ //log.debug("+++ Hex="+getName()+":"+orientation+"->"+neighbour.getName());
}
public MapHex getNeighbor(int orientation) {
Modified: trunk/18xx/rails/game/MapManager.java
===================================================================
--- trunk/18xx/rails/game/MapManager.java 2011-03-05 20:10:40 UTC (rev 1492)
+++ trunk/18xx/rails/game/MapManager.java 2011-03-06 13:05:43 UTC (rev 1493)
@@ -124,21 +124,16 @@
}
// Initialise the neighbours
+ int ii, jj;
for (i = minX; i <= maxX; i++) {
for (j = minY; j <= maxY; j++) {
if ((hex = hexes[i][j]) == null) continue;
for (k = 0; k < 6; k++) {
- if (tileOrientation == MapHex.EW) {
- dx = (j % 2 == 0 ? xYEvenDeltaEW[k] : xYOddDeltaEW[k]);
- dy = yDeltaEW[k];
- } else {
- dx = xDeltaNS[k];
- dy = (i % 2 == 0 ? yXEvenDeltaNS[k] : yXOddDeltaNS[k]);
- }
- if (i + dx >= minX && i + dx <= maxX && j + dy >= minY
- && j + dy <= maxY
- && (nb = hexes[i + dx][j + dy]) != null) {
+ ii = getAdjacentX (i, j, k);
+ jj = getAdjacentY (i, j, k);
+ if (ii >= minX && ii <= maxX && jj >= minY && jj <= maxY
+ && (nb = hexes[ii][jj]) != null) {
if (hex.isNeighbour(nb, k)
&& nb.isNeighbour(hex, k + 3)) {
hex.setNeighbor(k, nb);
@@ -146,7 +141,6 @@
}
if (hex.isImpassable(nb) || nb.isImpassable(hex)) {
hex.addImpassableSide(k);
- //nb.addImpassableSide(k+3);
}
}
@@ -177,6 +171,25 @@
public boolean lettersGoHorizontal() {
return lettersGoHorizontal;
}
+
+ public int getAdjacentX (int x, int y, int orientation) {
+
+ if (tileOrientation == MapHex.EW) {
+ return x + (y % 2 == 0 ? xYEvenDeltaEW[orientation] : xYOddDeltaEW[orientation]);
+ } else {
+ return x + xDeltaNS[orientation];
+ }
+ }
+
+ public int getAdjacentY (int x, int y, int orientation) {
+
+ if (tileOrientation == MapHex.EW) {
+ return y + yDeltaEW[orientation];
+ } else {
+ return y + ((x % 2 == 0) == letterAHasEvenNumbers ?
+ yXEvenDeltaNS[orientation] : yXOddDeltaNS[orientation]);
+ }
+ }
/**
* @return Returns the currentTileOrientation.
Modified: trunk/18xx/rails/ui/swing/hexmap/GUIHex.java
===================================================================
--- trunk/18xx/rails/ui/swing/hexmap/GUIHex.java 2011-03-05 20:10:40 UTC (rev 1492)
+++ trunk/18xx/rails/ui/swing/hexmap/GUIHex.java 2011-03-06 13:05:43 UTC (rev 1493)
@@ -319,21 +319,6 @@
return polygon;
}
- public void setNeighbor(int i, GUIHex hex) {
- if (i >= 0 && i < 6) {
- neighbors[i] = hex;
- getHexModel().setNeighbor(i, hex.getHexModel());
- }
- }
-
- public GUIHex getNeighbor(int i) {
- if (i < 0 || i > 6) {
- return null;
- } else {
- return neighbors[i];
- }
- }
-
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
@@ -704,9 +689,13 @@
if (Util.hasValue(name)) {
tt.append(" (").append(name).append(")");
}
+ // For debugging: display x,y-coordinates
+ //tt.append("<small> x=" + x + " y="+y+"</small>");
+
tt.append("<br><b>Tile</b>: ").append(currentTile.getId());
- // TEMPORARY
- tt.append("<small> rot=" + currentTileOrientation + "</small>");
+
+ // For debugging: display rotation
+ //tt.append("<small> rot=" + currentTileOrientation + "</small>");
if (model.hasOffBoardValues()) {
tt.append("<br>Value ");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|