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 SOMETINYEXP = 864;
public static final char LASTTINYEXP = 867;
public static final char COALSMOKE1 = 916;
public static final char COALSMOKE2 = 920;
public static final char COALSMOKE3 = 924;
public static final char COALSMOKE4 = 928;
public static final char SMOKEBASE2 = 884;
public static final char FOOTBALLGAME1 = 932;
public static final char FOOTBALLGAME2 = 940;
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)));
}
/**
* Note: does not include rail/road tiles.
* @see #isRoadAny
*/
public static boolean isRoad(int tile)
{
int tmp = tile & LOMASK;
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
* neighboring roads.
@ -532,6 +541,14 @@ public class TileConstants
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)
{
int tmp = tile & LOMASK;
@ -618,29 +635,38 @@ public class TileConstants
public static boolean isCommercialZone(int tile)
{
assert isZoneCenter(tile);
return (tile & LOMASK) >= COMBASE &&
(tile & LOMASK) < INDBASE;
}
public static boolean isHospitalOrChurch(int tile)
{
assert isZoneCenter(tile);
return (tile & LOMASK) >= HOSPITAL &&
(tile & LOMASK) < COMBASE;
}
public static boolean isIndustrialZone(int tile)
{
assert isZoneCenter(tile);
return (tile & LOMASK) >= INDBASE &&
(tile & LOMASK) < PORTBASE;
int tmp = tile & LOMASK;
return (tmp >= INDBASE && tmp < PORTBASE)
|| (tmp >= SMOKEBASE && tmp < TINYEXP)
|| (tmp >= SMOKEBASE2 && tmp < FOOTBALLGAME1);
}
/** Note: does not include hospital/church.
* @see #isHospitalOrChurch
*/
public static boolean isResidentialZone(int tile)
{
assert isZoneCenter(tile);
return (tile & LOMASK) < HOSPITAL;
return (tile & LOMASK) >= RESBASE &&
(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)
@ -649,6 +675,12 @@ public class TileConstants
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)
{
TileSpec spec = Tiles.get(tile & LOMASK);

View file

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