api: setTile() no longer accepts upper bits
also- eliminate "rawTile" from TileBehavior class and subclasses
This commit is contained in:
parent
69e50258e7
commit
300acc7381
4 changed files with 23 additions and 14 deletions
|
@ -109,7 +109,7 @@ class MapScanner extends TileBehavior
|
||||||
|
|
||||||
boolean setZonePower()
|
boolean setZonePower()
|
||||||
{
|
{
|
||||||
boolean oldPower = (rawTile & PWRBIT) == PWRBIT;
|
boolean oldPower = city.isTilePowered(xpos, ypos);
|
||||||
boolean newPower = (
|
boolean newPower = (
|
||||||
tile == NUCLEAR ||
|
tile == NUCLEAR ||
|
||||||
tile == POWERPLANT ||
|
tile == POWERPLANT ||
|
||||||
|
@ -118,12 +118,12 @@ class MapScanner extends TileBehavior
|
||||||
|
|
||||||
if (newPower && !oldPower)
|
if (newPower && !oldPower)
|
||||||
{
|
{
|
||||||
city.setTile(xpos, ypos, (char) (rawTile | PWRBIT));
|
city.setTilePower(xpos, ypos, true);
|
||||||
city.powerZone(xpos, ypos, getZoneSizeFor(tile));
|
city.powerZone(xpos, ypos, getZoneSizeFor(tile));
|
||||||
}
|
}
|
||||||
else if (!newPower && oldPower)
|
else if (!newPower && oldPower)
|
||||||
{
|
{
|
||||||
city.setTile(xpos, ypos, (char) (rawTile & (~PWRBIT)));
|
city.setTilePower(xpos, ypos, false);
|
||||||
city.shutdownZone(xpos, ypos, getZoneSizeFor(tile));
|
city.shutdownZone(xpos, ypos, getZoneSizeFor(tile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,9 +172,8 @@ class MapScanner extends TileBehavior
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// refresh rawTile, tile
|
// refresh own tile property
|
||||||
this.rawTile = city.map[ypos][xpos];
|
this.tile = city.getTile(xpos, ypos);
|
||||||
this.tile = (char) (rawTile & LOMASK);
|
|
||||||
|
|
||||||
setZonePower();
|
setZonePower();
|
||||||
return true;
|
return true;
|
||||||
|
@ -798,8 +797,10 @@ class MapScanner extends TileBehavior
|
||||||
{
|
{
|
||||||
// downgrade from full-size zone to 8 little houses
|
// downgrade from full-size zone to 8 little houses
|
||||||
|
|
||||||
int pwrBit = (rawTile & PWRBIT);
|
boolean pwr = city.isTilePowered(xpos, ypos);
|
||||||
city.setTile(xpos, ypos, (char)(RESCLR | pwrBit));
|
city.setTile(xpos, ypos, RESCLR);
|
||||||
|
city.setTilePower(xpos, ypos, pwr);
|
||||||
|
|
||||||
for (int x = xpos-1; x <= xpos+1; x++)
|
for (int x = xpos-1; x <= xpos+1; x++)
|
||||||
{
|
{
|
||||||
for (int y = ypos-1; y <= ypos+1; y++)
|
for (int y = ypos-1; y <= ypos+1; y++)
|
||||||
|
|
|
@ -464,8 +464,15 @@ public class Micropolis
|
||||||
return (getTileRaw(xpos, ypos) & PWRBIT) == PWRBIT;
|
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)
|
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)
|
if (map[ypos][xpos] != newTile)
|
||||||
{
|
{
|
||||||
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)
|
final public boolean testBounds(int xpos, int ypos)
|
||||||
{
|
{
|
||||||
return xpos >= 0 && xpos < getWidth() &&
|
return xpos >= 0 && xpos < getWidth() &&
|
||||||
|
|
|
@ -203,9 +203,7 @@ class TerrainBehavior extends TileBehavior
|
||||||
|
|
||||||
if (tden != newLevel)
|
if (tden != newLevel)
|
||||||
{
|
{
|
||||||
int z = (((rawTile & LOMASK) - ROADBASE) & 15) + TRAFFIC_DENSITY_TAB[newLevel];
|
int z = ((tile - ROADBASE) & 15) + TRAFFIC_DENSITY_TAB[newLevel];
|
||||||
z += rawTile & ALLBITS;
|
|
||||||
|
|
||||||
city.setTile(xpos, ypos, (char) z);
|
city.setTile(xpos, ypos, (char) z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ public abstract class TileBehavior
|
||||||
int xpos;
|
int xpos;
|
||||||
int ypos;
|
int ypos;
|
||||||
int tile;
|
int tile;
|
||||||
int rawTile;
|
|
||||||
|
|
||||||
protected TileBehavior(Micropolis city)
|
protected TileBehavior(Micropolis city)
|
||||||
{
|
{
|
||||||
|
@ -30,8 +29,7 @@ public abstract class TileBehavior
|
||||||
{
|
{
|
||||||
this.xpos = xpos;
|
this.xpos = xpos;
|
||||||
this.ypos = ypos;
|
this.ypos = ypos;
|
||||||
this.rawTile = city.getTileRaw(xpos, ypos);
|
this.tile = city.getTile(xpos, ypos);
|
||||||
this.tile = rawTile & LOMASK;
|
|
||||||
apply();
|
apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue