api: setTile() no longer accepts upper bits

also- eliminate "rawTile" from TileBehavior class and subclasses
This commit is contained in:
Jason Long 2014-06-20 11:39:05 -04:00
parent 69e50258e7
commit 300acc7381
4 changed files with 23 additions and 14 deletions

View file

@ -109,7 +109,7 @@ class MapScanner extends TileBehavior
boolean setZonePower()
{
boolean oldPower = (rawTile & PWRBIT) == PWRBIT;
boolean oldPower = city.isTilePowered(xpos, ypos);
boolean newPower = (
tile == NUCLEAR ||
tile == POWERPLANT ||
@ -118,12 +118,12 @@ class MapScanner extends TileBehavior
if (newPower && !oldPower)
{
city.setTile(xpos, ypos, (char) (rawTile | PWRBIT));
city.setTilePower(xpos, ypos, true);
city.powerZone(xpos, ypos, getZoneSizeFor(tile));
}
else if (!newPower && oldPower)
{
city.setTile(xpos, ypos, (char) (rawTile & (~PWRBIT)));
city.setTilePower(xpos, ypos, false);
city.shutdownZone(xpos, ypos, getZoneSizeFor(tile));
}
@ -172,9 +172,8 @@ class MapScanner extends TileBehavior
}
}
// refresh rawTile, tile
this.rawTile = city.map[ypos][xpos];
this.tile = (char) (rawTile & LOMASK);
// refresh own tile property
this.tile = city.getTile(xpos, ypos);
setZonePower();
return true;
@ -798,8 +797,10 @@ class MapScanner extends TileBehavior
{
// downgrade from full-size zone to 8 little houses
int pwrBit = (rawTile & PWRBIT);
city.setTile(xpos, ypos, (char)(RESCLR | pwrBit));
boolean pwr = city.isTilePowered(xpos, ypos);
city.setTile(xpos, ypos, RESCLR);
city.setTilePower(xpos, ypos, pwr);
for (int x = xpos-1; x <= xpos+1; x++)
{
for (int y = ypos-1; y <= ypos+1; y++)

View file

@ -464,8 +464,15 @@ public class Micropolis
return (getTileRaw(xpos, ypos) & PWRBIT) == PWRBIT;
}
/**
* Note: this method clears the PWRBIT of the given location.
*/
public void setTile(int xpos, int ypos, char newTile)
{
// check to make sure we aren't setting an upper bit using
// this method
assert (newTile & LOMASK) == newTile;
if (map[ypos][xpos] != newTile)
{
map[ypos][xpos] = newTile;
@ -473,6 +480,11 @@ public class Micropolis
}
}
public void setTilePower(int xpos, int ypos, boolean power)
{
map[ypos][xpos] = (char)(map[ypos][xpos] & (~PWRBIT) | (power ? PWRBIT : 0));
}
final public boolean testBounds(int xpos, int ypos)
{
return xpos >= 0 && xpos < getWidth() &&

View file

@ -203,9 +203,7 @@ class TerrainBehavior extends TileBehavior
if (tden != newLevel)
{
int z = (((rawTile & LOMASK) - ROADBASE) & 15) + TRAFFIC_DENSITY_TAB[newLevel];
z += rawTile & ALLBITS;
int z = ((tile - ROADBASE) & 15) + TRAFFIC_DENSITY_TAB[newLevel];
city.setTile(xpos, ypos, (char) z);
}
}

View file

@ -18,7 +18,6 @@ public abstract class TileBehavior
int xpos;
int ypos;
int tile;
int rawTile;
protected TileBehavior(Micropolis city)
{
@ -30,8 +29,7 @@ public abstract class TileBehavior
{
this.xpos = xpos;
this.ypos = ypos;
this.rawTile = city.getTileRaw(xpos, ypos);
this.tile = rawTile & LOMASK;
this.tile = city.getTile(xpos, ypos);
apply();
}