TileConstants: continue moving tile number logic to central location (rails and wires)
git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@782 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
b4f7e09d74
commit
d60bbad2e1
2 changed files with 103 additions and 76 deletions
|
@ -495,6 +495,90 @@ public class TileConstants
|
||||||
return (tmp >= RAILBASE && tmp < RESBASE);
|
return (tmp >= RAILBASE && tmp < RESBASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isRailDynamic(int tile)
|
||||||
|
{
|
||||||
|
int tmp = tile & LOMASK;
|
||||||
|
return (tmp >= LHRAIL && tmp <= LVRAIL10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean railConnectsEast(int tile)
|
||||||
|
{
|
||||||
|
tile = neutralizeRoad(tile);
|
||||||
|
return (tile >= RAILHPOWERV && tile <= VRAILROAD &&
|
||||||
|
tile != RAILVPOWERH &&
|
||||||
|
tile != VRAILROAD &&
|
||||||
|
tile != VRAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean railConnectsNorth(int tile)
|
||||||
|
{
|
||||||
|
tile = neutralizeRoad(tile);
|
||||||
|
return (tile >= RAILHPOWERV && tile <= VRAILROAD &&
|
||||||
|
tile != RAILHPOWERV &&
|
||||||
|
tile != HRAILROAD &&
|
||||||
|
tile != HRAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean railConnectsSouth(int tile)
|
||||||
|
{
|
||||||
|
tile = neutralizeRoad(tile);
|
||||||
|
return (tile >= RAILHPOWERV && tile <= VRAILROAD &&
|
||||||
|
tile != RAILHPOWERV &&
|
||||||
|
tile != HRAILROAD &&
|
||||||
|
tile != HRAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean railConnectsWest(int tile)
|
||||||
|
{
|
||||||
|
tile = neutralizeRoad(tile);
|
||||||
|
return (tile >= RAILHPOWERV && tile <= VRAILROAD &&
|
||||||
|
tile != RAILVPOWERH &&
|
||||||
|
tile != VRAILROAD &&
|
||||||
|
tile != VRAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWireDynamic(int tile)
|
||||||
|
{
|
||||||
|
int tmp = tile & LOMASK;
|
||||||
|
return (tmp >= LHPOWER && tile <= LVPOWER10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean wireConnectsEast(int tile)
|
||||||
|
{
|
||||||
|
int ntile = neutralizeRoad(tile);
|
||||||
|
return (isConductive(tile) &&
|
||||||
|
ntile != HPOWER &&
|
||||||
|
ntile != HROADPOWER &&
|
||||||
|
ntile != RAILHPOWERV);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean wireConnectsNorth(int tile)
|
||||||
|
{
|
||||||
|
int ntile = neutralizeRoad(tile);
|
||||||
|
return (isConductive(tile) &&
|
||||||
|
ntile != VPOWER &&
|
||||||
|
ntile != VROADPOWER &&
|
||||||
|
ntile != RAILVPOWERH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean wireConnectsSouth(int tile)
|
||||||
|
{
|
||||||
|
int ntile = neutralizeRoad(tile);
|
||||||
|
return (isConductive(tile) &&
|
||||||
|
ntile != VPOWER &&
|
||||||
|
ntile != VROADPOWER &&
|
||||||
|
ntile != RAILVPOWERH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean wireConnectsWest(int tile)
|
||||||
|
{
|
||||||
|
int ntile = neutralizeRoad(tile);
|
||||||
|
return (isConductive(tile) &&
|
||||||
|
ntile != HPOWER &&
|
||||||
|
ntile != HROADPOWER &&
|
||||||
|
ntile != RAILHPOWERV);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isCommercialZone(int tile)
|
public static boolean isCommercialZone(int tile)
|
||||||
{
|
{
|
||||||
assert isZoneCenter(tile);
|
assert isZoneCenter(tile);
|
||||||
|
|
|
@ -271,8 +271,7 @@ public class ToolStroke
|
||||||
|
|
||||||
private void fixSingle(ToolEffectIfc eff)
|
private void fixSingle(ToolEffectIfc eff)
|
||||||
{
|
{
|
||||||
int tile = (eff.getTile(0, 0) & LOMASK);
|
int tile = eff.getTile(0, 0);
|
||||||
tile = neutralizeRoad(tile);
|
|
||||||
|
|
||||||
if (isRoadDynamic(tile))
|
if (isRoadDynamic(tile))
|
||||||
{
|
{
|
||||||
|
@ -306,121 +305,65 @@ public class ToolStroke
|
||||||
eff.setTile(0, 0, (RoadTable[adjTile] | BULLBIT));
|
eff.setTile(0, 0, (RoadTable[adjTile] | BULLBIT));
|
||||||
} //endif on a road tile
|
} //endif on a road tile
|
||||||
|
|
||||||
else if (tile >= LHRAIL && tile <= LVRAIL10)
|
else if (isRailDynamic(tile))
|
||||||
{
|
{
|
||||||
// cleanup Rail
|
// cleanup Rail
|
||||||
int adjTile = 0;
|
int adjTile = 0;
|
||||||
|
|
||||||
// check rail to north
|
// check rail to north
|
||||||
|
if (railConnectsSouth(eff.getTile(0, -1)))
|
||||||
{
|
{
|
||||||
tile = eff.getTile(0, -1);
|
adjTile |= 1;
|
||||||
tile = neutralizeRoad(tile);
|
|
||||||
if (tile >= RAILHPOWERV && tile <= VRAILROAD &&
|
|
||||||
tile != RAILHPOWERV &&
|
|
||||||
tile != HRAILROAD &&
|
|
||||||
tile != HRAIL)
|
|
||||||
{
|
|
||||||
adjTile |= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rail to east
|
// check rail to east
|
||||||
|
if (railConnectsWest(eff.getTile(1, 0)))
|
||||||
{
|
{
|
||||||
tile = eff.getTile(1, 0);
|
adjTile |= 2;
|
||||||
tile = neutralizeRoad(tile);
|
|
||||||
if (tile >= RAILHPOWERV && tile <= VRAILROAD &&
|
|
||||||
tile != RAILVPOWERH &&
|
|
||||||
tile != VRAILROAD &&
|
|
||||||
tile != VRAIL)
|
|
||||||
{
|
|
||||||
adjTile |= 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rail to south
|
// check rail to south
|
||||||
|
if (railConnectsNorth(eff.getTile(0, 1)))
|
||||||
{
|
{
|
||||||
tile = eff.getTile(0, 1);
|
adjTile |= 4;
|
||||||
tile = neutralizeRoad(tile);
|
|
||||||
if (tile >= RAILHPOWERV && tile <= VRAILROAD &&
|
|
||||||
tile != RAILHPOWERV &&
|
|
||||||
tile != HRAILROAD &&
|
|
||||||
tile != HRAIL)
|
|
||||||
{
|
|
||||||
adjTile |= 4;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rail to west
|
// check rail to west
|
||||||
|
if (railConnectsEast(eff.getTile(-1, 0)))
|
||||||
{
|
{
|
||||||
tile = eff.getTile(-1, 0);
|
adjTile |= 8;
|
||||||
tile = neutralizeRoad(tile);
|
|
||||||
if (tile >= RAILHPOWERV && tile <= VRAILROAD &&
|
|
||||||
tile != RAILVPOWERH &&
|
|
||||||
tile != VRAILROAD &&
|
|
||||||
tile != VRAIL)
|
|
||||||
{
|
|
||||||
adjTile |= 8;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eff.setTile(0, 0, (RailTable[adjTile] | BULLBIT));
|
eff.setTile(0, 0, (RailTable[adjTile] | BULLBIT));
|
||||||
} //end if on a rail tile
|
} //end if on a rail tile
|
||||||
|
|
||||||
else if (tile >= LHPOWER && tile <= LVPOWER10)
|
else if (isWireDynamic(tile))
|
||||||
{
|
{
|
||||||
// Cleanup Wire
|
// Cleanup Wire
|
||||||
int adjTile = 0;
|
int adjTile = 0;
|
||||||
|
|
||||||
// check wire to north
|
// check wire to north
|
||||||
|
if (wireConnectsSouth(eff.getTile(0, -1)))
|
||||||
{
|
{
|
||||||
tile = eff.getTile(0, -1);
|
adjTile |= 1;
|
||||||
char ntile = neutralizeRoad(tile);
|
|
||||||
if (isConductive(tile) &&
|
|
||||||
ntile != VPOWER &&
|
|
||||||
ntile != VROADPOWER &&
|
|
||||||
ntile != RAILVPOWERH)
|
|
||||||
{
|
|
||||||
adjTile |= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check wire to east
|
// check wire to east
|
||||||
|
if (wireConnectsWest(eff.getTile(1, 0)))
|
||||||
{
|
{
|
||||||
tile = eff.getTile(1, 0);
|
adjTile |= 2;
|
||||||
char ntile = neutralizeRoad(tile);
|
|
||||||
if (isConductive(tile) &&
|
|
||||||
ntile != HPOWER &&
|
|
||||||
ntile != HROADPOWER &&
|
|
||||||
ntile != RAILHPOWERV)
|
|
||||||
{
|
|
||||||
adjTile |= 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check wire to south
|
// check wire to south
|
||||||
|
if (wireConnectsNorth(eff.getTile(0, 1)))
|
||||||
{
|
{
|
||||||
tile = eff.getTile(0, 1);
|
adjTile |= 4;
|
||||||
char ntile = neutralizeRoad(tile);
|
|
||||||
if (isConductive(tile) &&
|
|
||||||
ntile != VPOWER &&
|
|
||||||
ntile != VROADPOWER &&
|
|
||||||
ntile != RAILVPOWERH)
|
|
||||||
{
|
|
||||||
adjTile |= 4;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check wire to west
|
// check wire to west
|
||||||
|
if (wireConnectsEast(eff.getTile(-1, 0)))
|
||||||
{
|
{
|
||||||
tile = eff.getTile(-1, 0);
|
adjTile |= 8;
|
||||||
char ntile = neutralizeRoad(tile);
|
|
||||||
if (isConductive(tile) &&
|
|
||||||
ntile != HPOWER &&
|
|
||||||
ntile != HROADPOWER &&
|
|
||||||
ntile != RAILHPOWERV)
|
|
||||||
{
|
|
||||||
adjTile |= 8;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eff.setTile(0, 0, (WireTable[adjTile] | BULLBIT));
|
eff.setTile(0, 0, (WireTable[adjTile] | BULLBIT));
|
||||||
|
|
Reference in a new issue