diff --git a/src/micropolisj/engine/MapScanner.java b/src/micropolisj/engine/MapScanner.java index 7aa2db0..a7ccd94 100644 --- a/src/micropolisj/engine/MapScanner.java +++ b/src/micropolisj/engine/MapScanner.java @@ -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++) diff --git a/src/micropolisj/engine/Micropolis.java b/src/micropolisj/engine/Micropolis.java index 93535c7..faf978c 100644 --- a/src/micropolisj/engine/Micropolis.java +++ b/src/micropolisj/engine/Micropolis.java @@ -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() && diff --git a/src/micropolisj/engine/TerrainBehavior.java b/src/micropolisj/engine/TerrainBehavior.java index 6452c57..1907349 100644 --- a/src/micropolisj/engine/TerrainBehavior.java +++ b/src/micropolisj/engine/TerrainBehavior.java @@ -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); } } diff --git a/src/micropolisj/engine/TileBehavior.java b/src/micropolisj/engine/TileBehavior.java index 24d3956..021e757 100644 --- a/src/micropolisj/engine/TileBehavior.java +++ b/src/micropolisj/engine/TileBehavior.java @@ -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(); }