api: TileConstants- never accept "raw" tile numbers
git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@899 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
78d094c8ac
commit
c2286465a7
1 changed files with 122 additions and 66 deletions
|
@ -227,7 +227,8 @@ public class TileConstants
|
||||||
//used by scanTile
|
//used by scanTile
|
||||||
public static String getTileBehavior(int tile)
|
public static String getTileBehavior(int tile)
|
||||||
{
|
{
|
||||||
tile &= LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
TileSpec ts = Tiles.get(tile);
|
TileSpec ts = Tiles.get(tile);
|
||||||
return ts != null ? ts.getAttribute("behavior") : null;
|
return ts != null ? ts.getAttribute("behavior") : null;
|
||||||
}
|
}
|
||||||
|
@ -235,7 +236,8 @@ public class TileConstants
|
||||||
//used by queryZoneStatus
|
//used by queryZoneStatus
|
||||||
public static int getDescriptionNumber(int tile)
|
public static int getDescriptionNumber(int tile)
|
||||||
{
|
{
|
||||||
tile &= LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
TileSpec ts = Tiles.get(tile);
|
TileSpec ts = Tiles.get(tile);
|
||||||
if (ts != null) {
|
if (ts != null) {
|
||||||
return ts.getDescriptionNumber();
|
return ts.getDescriptionNumber();
|
||||||
|
@ -247,23 +249,29 @@ public class TileConstants
|
||||||
|
|
||||||
public static int getPollutionValue(int tile)
|
public static int getPollutionValue(int tile)
|
||||||
{
|
{
|
||||||
TileSpec spec = Tiles.get(tile & LOMASK);
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
TileSpec spec = Tiles.get(tile);
|
||||||
return spec != null ? spec.getPollutionValue() : 0;
|
return spec != null ? spec.getPollutionValue() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAnimated(int tile)
|
public static boolean isAnimated(int tile)
|
||||||
{
|
{
|
||||||
TileSpec spec = Tiles.get(tile & LOMASK);
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
TileSpec spec = Tiles.get(tile);
|
||||||
return spec != null && spec.animNext != null;
|
return spec != null && spec.animNext != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//used by setFire()
|
//used by setFire()
|
||||||
public static boolean isArsonable(int tile)
|
public static boolean isArsonable(int tile)
|
||||||
{
|
{
|
||||||
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
!isZoneCenter(tile) &&
|
!isZoneCenter(tile) &&
|
||||||
(tile & LOMASK) >= LHTHR &&
|
tile >= LHTHR &&
|
||||||
(tile & LOMASK) <= LASTZONE
|
tile <= LASTZONE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,54 +283,67 @@ public class TileConstants
|
||||||
|
|
||||||
public static boolean isCombustible(int tile)
|
public static boolean isCombustible(int tile)
|
||||||
{
|
{
|
||||||
TileSpec spec = Tiles.get(tile & LOMASK);
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
TileSpec spec = Tiles.get(tile);
|
||||||
return spec != null && spec.canBurn;
|
return spec != null && spec.canBurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConductive(int tile)
|
public static boolean isConductive(int tile)
|
||||||
{
|
{
|
||||||
TileSpec spec = Tiles.get(tile & LOMASK);
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
TileSpec spec = Tiles.get(tile);
|
||||||
return spec != null && spec.canConduct;
|
return spec != null && spec.canConduct;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used in repairZone(). */
|
/** Used in repairZone(). */
|
||||||
public static boolean isIndestructible(int tile)
|
public static boolean isIndestructible(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
return tmp >= RUBBLE && tmp < ROADBASE;
|
|
||||||
|
return tile >= RUBBLE && tile < ROADBASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used in zonePlop(). */
|
/** Used in zonePlop(). */
|
||||||
public static boolean isIndestructible2(int tile)
|
public static boolean isIndestructible2(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
return tmp >= FLOOD && tmp < ROADBASE;
|
|
||||||
|
return tile >= FLOOD && tile < ROADBASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOverWater(int tile)
|
public static boolean isOverWater(int tile)
|
||||||
{
|
{
|
||||||
TileSpec spec = Tiles.get(tile & LOMASK);
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
TileSpec spec = Tiles.get(tile);
|
||||||
return spec != null && spec.overWater;
|
return spec != null && spec.overWater;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRubble(int cell)
|
public static boolean isRubble(int tile)
|
||||||
{
|
{
|
||||||
return (((cell & LOMASK) >= RUBBLE) &&
|
assert (tile & LOMASK) == tile;
|
||||||
((cell & LOMASK) <= LASTRUBBLE));
|
|
||||||
|
return ((tile >= RUBBLE) &&
|
||||||
|
(tile <= LASTRUBBLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTree(char cell)
|
public static boolean isTree(char tile)
|
||||||
{
|
{
|
||||||
return (((cell & LOMASK) >= WOODS_LOW) &&
|
assert (tile & LOMASK) == tile;
|
||||||
((cell & LOMASK) <= WOODS_HIGH));
|
|
||||||
|
return ((tile >= WOODS_LOW) &&
|
||||||
|
(tile <= WOODS_HIGH));
|
||||||
}
|
}
|
||||||
|
|
||||||
//used by makeEarthquake
|
//used by makeEarthquake
|
||||||
public static boolean isVulnerable(int tile)
|
public static boolean isVulnerable(int tile)
|
||||||
{
|
{
|
||||||
int tem2 = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
if (tem2 < RESBASE ||
|
|
||||||
tem2 > LASTZONE ||
|
if (tile < RESBASE ||
|
||||||
|
tile > LASTZONE ||
|
||||||
isZoneCenter(tile)
|
isZoneCenter(tile)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -333,42 +354,51 @@ public class TileConstants
|
||||||
|
|
||||||
public static boolean checkWet(int tile)
|
public static boolean checkWet(int tile)
|
||||||
{
|
{
|
||||||
int x = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
return (x == POWERBASE ||
|
|
||||||
x == POWERBASE+1 ||
|
return (tile == POWERBASE ||
|
||||||
x == RAILBASE ||
|
tile == POWERBASE+1 ||
|
||||||
x == RAILBASE + 1 ||
|
tile == RAILBASE ||
|
||||||
x == BRWH ||
|
tile == RAILBASE + 1 ||
|
||||||
x == BRWV);
|
tile == BRWH ||
|
||||||
|
tile == BRWV);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CityDimension getZoneSizeFor(int tile)
|
public static CityDimension getZoneSizeFor(int tile)
|
||||||
{
|
{
|
||||||
assert isZoneCenter(tile);
|
assert isZoneCenter(tile);
|
||||||
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
TileSpec spec = Tiles.get(tile & LOMASK);
|
TileSpec spec = Tiles.get(tile);
|
||||||
return spec != null ? spec.getBuildingSize() : null;
|
return spec != null ? spec.getBuildingSize() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConstructed(int tile)
|
public static boolean isConstructed(int tile)
|
||||||
{
|
{
|
||||||
return tile >= 0 && (tile & LOMASK) >= ROADBASE;
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
return tile >= 0 && tile >= ROADBASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isRiverEdge(int tile)
|
static boolean isRiverEdge(int tile)
|
||||||
{
|
{
|
||||||
tile &= LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
return tile >= FIRSTRIVEDGE && tile <= LASTRIVEDGE;
|
return tile >= FIRSTRIVEDGE && tile <= LASTRIVEDGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDozeable(int tile)
|
public static boolean isDozeable(int tile)
|
||||||
{
|
{
|
||||||
TileSpec spec = Tiles.get(tile & LOMASK);
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
TileSpec spec = Tiles.get(tile);
|
||||||
return spec != null && spec.canBulldoze;
|
return spec != null && spec.canBulldoze;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isFloodable(int tile)
|
static boolean isFloodable(int tile)
|
||||||
{
|
{
|
||||||
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
return (tile == DIRT || (isDozeable(tile) && isCombustible(tile)));
|
return (tile == DIRT || (isDozeable(tile) && isCombustible(tile)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,16 +408,18 @@ public class TileConstants
|
||||||
*/
|
*/
|
||||||
public static boolean isRoad(int tile)
|
public static boolean isRoad(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
return (tmp >= ROADBASE && tmp < POWERBASE);
|
|
||||||
|
return (tile >= ROADBASE && tile < POWERBASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRoadAny(int tile)
|
public static boolean isRoadAny(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
return (tmp >= ROADBASE && tmp < POWERBASE)
|
|
||||||
|| (tmp == HRAILROAD)
|
return (tile >= ROADBASE && tile < POWERBASE)
|
||||||
|| (tmp == VRAILROAD);
|
|| (tile == HRAILROAD)
|
||||||
|
|| (tile == VRAILROAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -446,22 +478,25 @@ public class TileConstants
|
||||||
|
|
||||||
public static boolean isRail(int tile)
|
public static boolean isRail(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
return (tmp >= RAILBASE && tmp < RESBASE);
|
|
||||||
|
return (tile >= RAILBASE && tile < RESBASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRailAny(int tile)
|
public static boolean isRailAny(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
return (tmp >= RAILBASE && tmp < RESBASE)
|
|
||||||
|| (tmp == RAILHPOWERV)
|
return (tile >= RAILBASE && tile < RESBASE)
|
||||||
|| (tmp == RAILVPOWERH);
|
|| (tile == RAILHPOWERV)
|
||||||
|
|| (tile == RAILVPOWERH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRailDynamic(int tile)
|
public static boolean isRailDynamic(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
return (tmp >= LHRAIL && tmp <= LVRAIL10);
|
|
||||||
|
return (tile >= LHRAIL && tile <= LVRAIL10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean railConnectsEast(int tile)
|
public static boolean railConnectsEast(int tile)
|
||||||
|
@ -502,8 +537,9 @@ public class TileConstants
|
||||||
|
|
||||||
public static boolean isWireDynamic(int tile)
|
public static boolean isWireDynamic(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
return (tmp >= LHPOWER && tmp <= LVPOWER10);
|
|
||||||
|
return (tile >= LHPOWER && tile <= LVPOWER10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean wireConnectsEast(int tile)
|
public static boolean wireConnectsEast(int tile)
|
||||||
|
@ -544,8 +580,9 @@ public class TileConstants
|
||||||
|
|
||||||
public static boolean isCommercialZone(int tile)
|
public static boolean isCommercialZone(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
TileSpec ts = Tiles.get(tmp);
|
|
||||||
|
TileSpec ts = Tiles.get(tile);
|
||||||
if (ts != null) {
|
if (ts != null) {
|
||||||
if (ts.owner != null) {
|
if (ts.owner != null) {
|
||||||
ts = ts.owner;
|
ts = ts.owner;
|
||||||
|
@ -557,8 +594,10 @@ public class TileConstants
|
||||||
|
|
||||||
public static boolean isHospitalOrChurch(int tile)
|
public static boolean isHospitalOrChurch(int tile)
|
||||||
{
|
{
|
||||||
return (tile & LOMASK) >= HOSPITAL &&
|
assert (tile & LOMASK) == tile;
|
||||||
(tile & LOMASK) < COMBASE;
|
|
||||||
|
return tile >= HOSPITAL &&
|
||||||
|
tile < COMBASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -568,8 +607,9 @@ public class TileConstants
|
||||||
*/
|
*/
|
||||||
public static boolean isIndustrialZone(int tile)
|
public static boolean isIndustrialZone(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
TileSpec ts = Tiles.get(tmp);
|
|
||||||
|
TileSpec ts = Tiles.get(tile);
|
||||||
if (ts != null) {
|
if (ts != null) {
|
||||||
if (ts.owner != null) {
|
if (ts.owner != null) {
|
||||||
ts = ts.owner;
|
ts = ts.owner;
|
||||||
|
@ -581,7 +621,9 @@ public class TileConstants
|
||||||
|
|
||||||
public static boolean isResidentialClear(int tile)
|
public static boolean isResidentialClear(int tile)
|
||||||
{
|
{
|
||||||
return (tile & LOMASK) >= RESBASE && (tile & LOMASK) <= RESBASE+8;
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
return tile >= RESBASE && tile <= RESBASE+8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Note: does not include hospital/church.
|
/** Note: does not include hospital/church.
|
||||||
|
@ -589,15 +631,18 @@ public class TileConstants
|
||||||
*/
|
*/
|
||||||
public static boolean isResidentialZone(int tile)
|
public static boolean isResidentialZone(int tile)
|
||||||
{
|
{
|
||||||
return (tile & LOMASK) >= RESBASE &&
|
assert (tile & LOMASK) == tile;
|
||||||
(tile & LOMASK) < HOSPITAL;
|
|
||||||
|
return tile >= RESBASE &&
|
||||||
|
tile < HOSPITAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// includes hospital/church.
|
// includes hospital/church.
|
||||||
public static boolean isResidentialZoneAny(int tile)
|
public static boolean isResidentialZoneAny(int tile)
|
||||||
{
|
{
|
||||||
int tmp = tile & LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
TileSpec ts = Tiles.get(tmp);
|
|
||||||
|
TileSpec ts = Tiles.get(tile);
|
||||||
if (ts != null) {
|
if (ts != null) {
|
||||||
if (ts.owner != null) {
|
if (ts.owner != null) {
|
||||||
ts = ts.owner;
|
ts = ts.owner;
|
||||||
|
@ -610,12 +655,16 @@ public class TileConstants
|
||||||
/** Tile represents a part of any sort of building. */
|
/** Tile represents a part of any sort of building. */
|
||||||
public static boolean isZoneAny(int tile)
|
public static boolean isZoneAny(int tile)
|
||||||
{
|
{
|
||||||
return (tile & LOMASK) >= RESBASE;
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
return tile >= RESBASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isZoneCenter(int tile)
|
public static boolean isZoneCenter(int tile)
|
||||||
{
|
{
|
||||||
TileSpec spec = Tiles.get(tile & LOMASK);
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
TileSpec spec = Tiles.get(tile);
|
||||||
return spec != null && spec.zone;
|
return spec != null && spec.zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -625,7 +674,8 @@ public class TileConstants
|
||||||
*/
|
*/
|
||||||
public static char neutralizeRoad(int tile)
|
public static char neutralizeRoad(int tile)
|
||||||
{
|
{
|
||||||
tile &= LOMASK;
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
if (tile >= ROADBASE && tile <= LASTROAD) {
|
if (tile >= ROADBASE && tile <= LASTROAD) {
|
||||||
tile = ((tile - ROADBASE) & 0xf) + ROADBASE;
|
tile = ((tile - ROADBASE) & 0xf) + ROADBASE;
|
||||||
}
|
}
|
||||||
|
@ -640,7 +690,9 @@ public class TileConstants
|
||||||
*/
|
*/
|
||||||
public static int residentialZonePop(int tile)
|
public static int residentialZonePop(int tile)
|
||||||
{
|
{
|
||||||
TileSpec ts = Tiles.get(tile & LOMASK);
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
TileSpec ts = Tiles.get(tile);
|
||||||
return ts.getPopulation();
|
return ts.getPopulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,7 +704,9 @@ public class TileConstants
|
||||||
*/
|
*/
|
||||||
public static int commercialZonePop(int tile)
|
public static int commercialZonePop(int tile)
|
||||||
{
|
{
|
||||||
TileSpec ts = Tiles.get(tile & LOMASK);
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
TileSpec ts = Tiles.get(tile);
|
||||||
return ts.getPopulation() / 8;
|
return ts.getPopulation() / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,7 +717,9 @@ public class TileConstants
|
||||||
*/
|
*/
|
||||||
public static int industrialZonePop(int tile)
|
public static int industrialZonePop(int tile)
|
||||||
{
|
{
|
||||||
TileSpec ts = Tiles.get(tile & LOMASK);
|
assert (tile & LOMASK) == tile;
|
||||||
|
|
||||||
|
TileSpec ts = Tiles.get(tile);
|
||||||
return ts.getPopulation() / 8;
|
return ts.getPopulation() / 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue