TileConstants: remove hardcoded tile values from OverlayMapView

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@787 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-08-11 22:43:13 +00:00
parent 9c6e987f65
commit 9e9d1b2e9b
2 changed files with 65 additions and 21 deletions

View file

@ -171,10 +171,7 @@ public class TileConstants
public static final char TINYEXP = 860; public static final char TINYEXP = 860;
public static final char SOMETINYEXP = 864; public static final char SOMETINYEXP = 864;
public static final char LASTTINYEXP = 867; public static final char LASTTINYEXP = 867;
public static final char COALSMOKE1 = 916; public static final char SMOKEBASE2 = 884;
public static final char COALSMOKE2 = 920;
public static final char COALSMOKE3 = 924;
public static final char COALSMOKE4 = 928;
public static final char FOOTBALLGAME1 = 932; public static final char FOOTBALLGAME1 = 932;
public static final char FOOTBALLGAME2 = 940; public static final char FOOTBALLGAME2 = 940;
public static final char VBRDG0 = 948; //draw bridge tiles (vert) public static final char VBRDG0 = 948; //draw bridge tiles (vert)
@ -466,12 +463,24 @@ public class TileConstants
return (tile == DIRT || ((tile & BULLBIT) != 0 && isCombustible(tile))); return (tile == DIRT || ((tile & BULLBIT) != 0 && isCombustible(tile)));
} }
/**
* Note: does not include rail/road tiles.
* @see #isRoadAny
*/
public static boolean isRoad(int tile) public static boolean isRoad(int tile)
{ {
int tmp = tile & LOMASK; int tmp = tile & LOMASK;
return (tmp >= ROADBASE && tmp < POWERBASE); return (tmp >= ROADBASE && tmp < POWERBASE);
} }
public static boolean isRoadAny(int tile)
{
int tmp = tile & LOMASK;
return (tmp >= ROADBASE && tmp < POWERBASE)
|| (tmp == HRAILROAD)
|| (tmp == VRAILROAD);
}
/** /**
* Checks whether the tile is a road that will automatically change to connect to * Checks whether the tile is a road that will automatically change to connect to
* neighboring roads. * neighboring roads.
@ -532,6 +541,14 @@ public class TileConstants
return (tmp >= RAILBASE && tmp < RESBASE); return (tmp >= RAILBASE && tmp < RESBASE);
} }
public static boolean isRailAny(int tile)
{
int tmp = tile & LOMASK;
return (tmp >= RAILBASE && tmp < RESBASE)
|| (tmp == RAILHPOWERV)
|| (tmp == RAILVPOWERH);
}
public static boolean isRailDynamic(int tile) public static boolean isRailDynamic(int tile)
{ {
int tmp = tile & LOMASK; int tmp = tile & LOMASK;
@ -618,29 +635,38 @@ public class TileConstants
public static boolean isCommercialZone(int tile) public static boolean isCommercialZone(int tile)
{ {
assert isZoneCenter(tile);
return (tile & LOMASK) >= COMBASE && return (tile & LOMASK) >= COMBASE &&
(tile & LOMASK) < INDBASE; (tile & LOMASK) < INDBASE;
} }
public static boolean isHospitalOrChurch(int tile) public static boolean isHospitalOrChurch(int tile)
{ {
assert isZoneCenter(tile);
return (tile & LOMASK) >= HOSPITAL && return (tile & LOMASK) >= HOSPITAL &&
(tile & LOMASK) < COMBASE; (tile & LOMASK) < COMBASE;
} }
public static boolean isIndustrialZone(int tile) public static boolean isIndustrialZone(int tile)
{ {
assert isZoneCenter(tile); int tmp = tile & LOMASK;
return (tile & LOMASK) >= INDBASE && return (tmp >= INDBASE && tmp < PORTBASE)
(tile & LOMASK) < PORTBASE; || (tmp >= SMOKEBASE && tmp < TINYEXP)
|| (tmp >= SMOKEBASE2 && tmp < FOOTBALLGAME1);
} }
/** Note: does not include hospital/church.
* @see #isHospitalOrChurch
*/
public static boolean isResidentialZone(int tile) public static boolean isResidentialZone(int tile)
{ {
assert isZoneCenter(tile); return (tile & LOMASK) >= RESBASE &&
return (tile & LOMASK) < HOSPITAL; (tile & LOMASK) < HOSPITAL;
}
// includes hospital/church.
public static boolean isResidentialZoneAny(int tile)
{
int tmp = tile & LOMASK;
return (tile >= RESBASE && tile < COMBASE);
} }
public static boolean isSpecialZone(int tile) public static boolean isSpecialZone(int tile)
@ -649,6 +675,12 @@ public class TileConstants
return (tile & LOMASK) >= PORTBASE; return (tile & LOMASK) >= PORTBASE;
} }
/** Tile represents a part of any sort of building. */
public static boolean isZoneAny(int tile)
{
return (tile & LOMASK) >= RESBASE;
}
public static boolean isZoneCenter(int tile) public static boolean isZoneCenter(int tile)
{ {
TileSpec spec = Tiles.get(tile & LOMASK); TileSpec spec = Tiles.get(tile & LOMASK);

View file

@ -301,26 +301,38 @@ public class OverlayMapView extends JComponent
int tile = engine.getTile(x,y) & LOMASK; int tile = engine.getTile(x,y) & LOMASK;
switch (mapState) { switch (mapState) {
case RESIDENTIAL: case RESIDENTIAL:
if (tile >= COMBASE) { tile = DIRT; } if (isZoneAny(tile) &&
!isResidentialZone(tile) &&
!isHospitalOrChurch(tile))
{
tile = DIRT;
}
break; break;
case COMMERCIAL: case COMMERCIAL:
if (tile > COMLAST || (tile >= RESBASE && tile < COMBASE)) { tile = DIRT; } if (isZoneAny(tile) &&
!isCommercialZone(tile))
{
tile = DIRT;
}
break; break;
case INDUSTRIAL: case INDUSTRIAL:
if ((tile >= RESBASE && tile < INDBASE) || if (isZoneAny(tile) &&
(tile >= PORTBASE && tile < SMOKEBASE) || !isIndustrialZone(tile))
(tile >= TINYEXP && tile < 884) || {
tile >= FOOTBALLGAME1) tile = DIRT;
{ tile = DIRT; } }
break; break;
case POWER_OVERLAY: case POWER_OVERLAY:
tile = checkPower(img, x, y, engine.getTile(x,y)); tile = checkPower(img, x, y, engine.getTile(x,y));
break; break;
case TRANSPORT: case TRANSPORT:
case TRAFFIC_OVERLAY: case TRAFFIC_OVERLAY:
if (tile >= RESBASE || if (isConstructed(tile)
(tile >= 207 && tile <= LVPOWER10) || && !isRoadAny(tile)
tile == 223) { tile = DIRT; } && !isRailAny(tile))
{
tile = DIRT;
}
break; break;
default: default:
} }