TileConstants: move tile number comparisons to central location (road numbers)

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@781 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-08-11 04:07:11 +00:00
parent 1c4eb5a346
commit b4f7e09d74
2 changed files with 63 additions and 46 deletions

View file

@ -435,6 +435,60 @@ public class TileConstants
return (tmp >= ROADBASE && tmp < POWERBASE);
}
/**
* Checks whether the tile is a road that will automatically change to connect to
* neighboring roads.
*/
public static boolean isRoadDynamic(int tile)
{
int tmp = neutralizeRoad(tile);
return (tmp >= ROADS && tile <= INTERSECTION);
}
public static boolean roadConnectsEast(int tile)
{
tile = neutralizeRoad(tile);
return (((tile == VRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER)
) &&
(tile != VROADPOWER) &&
(tile != HRAILROAD) &&
(tile != VBRIDGE));
}
public static boolean roadConnectsNorth(int tile)
{
tile = neutralizeRoad(tile);
return (((tile == HRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER)
) &&
(tile != HROADPOWER) &&
(tile != VRAILROAD) &&
(tile != ROADBASE));
}
public static boolean roadConnectsSouth(int tile)
{
tile = neutralizeRoad(tile);
return (((tile == HRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER)
) &&
(tile != HROADPOWER) &&
(tile != VRAILROAD) &&
(tile != ROADBASE));
}
public static boolean roadConnectsWest(int tile)
{
tile = neutralizeRoad(tile);
return (((tile == VRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER)
) &&
(tile != VROADPOWER) &&
(tile != HRAILROAD) &&
(tile != VBRIDGE));
}
public static boolean isRail(int tile)
{
int tmp = tile & LOMASK;

View file

@ -274,70 +274,33 @@ public class ToolStroke
int tile = (eff.getTile(0, 0) & LOMASK);
tile = neutralizeRoad(tile);
if (tile >= TileConstants.ROADS && tile <= INTERSECTION)
if (isRoadDynamic(tile))
{
// cleanup road
int adjTile = 0;
// check road to north
if (roadConnectsSouth(eff.getTile(0, -1)))
{
tile = eff.getTile(0, -1);
tile = neutralizeRoad(tile);
if (((tile == HRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER)
) &&
(tile != HROADPOWER) &&
(tile != VRAILROAD) &&
(tile != ROADBASE))
{
adjTile |= 1;
}
adjTile |= 1;
}
// check road to east
if (roadConnectsWest(eff.getTile(1, 0)))
{
tile = eff.getTile(1, 0);
tile = neutralizeRoad(tile);
if (((tile == VRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER)
) &&
(tile != VROADPOWER) &&
(tile != HRAILROAD) &&
(tile != VBRIDGE))
{
adjTile |= 2;
}
adjTile |= 2;
}
// check road to south
if (roadConnectsNorth(eff.getTile(0, 1)))
{
tile = eff.getTile(0, 1);
tile = neutralizeRoad(tile);
if (((tile == HRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER)
) &&
(tile != HROADPOWER) &&
(tile != VRAILROAD) &&
(tile != ROADBASE))
{
adjTile |= 4;
}
adjTile |= 4;
}
// check road to west
if (roadConnectsEast(eff.getTile(-1, 0)))
{
tile = eff.getTile(-1, 0);
tile = neutralizeRoad(tile);
if (((tile == VRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER)
) &&
(tile != VROADPOWER) &&
(tile != HRAILROAD) &&
(tile != VBRIDGE))
{
adjTile |= 8;
}
adjTile |= 8;
}
eff.setTile(0, 0, (RoadTable[adjTile] | BULLBIT));