Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
api: setTile() no longer accepts upper bits
also- eliminate "rawTile" from TileBehavior class and subclasses
  • Loading branch information
jason@long.name committed Jun 21, 2014
1 parent f4e460e commit ad3128b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
17 changes: 9 additions & 8 deletions micropolis-java/src/micropolisj/engine/MapScanner.java
Expand Up @@ -109,7 +109,7 @@ boolean checkZonePower()

boolean setZonePower()
{
boolean oldPower = (rawTile & PWRBIT) == PWRBIT;
boolean oldPower = city.isTilePowered(xpos, ypos);
boolean newPower = (
tile == NUCLEAR ||
tile == POWERPLANT ||
Expand All @@ -118,12 +118,12 @@ boolean setZonePower()

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));
}

Expand Down Expand Up @@ -172,9 +172,8 @@ boolean zonePlop(int base)
}
}

// 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;
Expand Down Expand Up @@ -798,8 +797,10 @@ private void doResidentialOut(int pop, int value)
{
// 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++)
Expand Down
12 changes: 12 additions & 0 deletions micropolis-java/src/micropolisj/engine/Micropolis.java
Expand Up @@ -464,15 +464,27 @@ public boolean isTilePowered(int xpos, int ypos)
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;
fireTileChanged(xpos, ypos);
}
}

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() &&
Expand Down
4 changes: 1 addition & 3 deletions micropolis-java/src/micropolisj/engine/TerrainBehavior.java
Expand Up @@ -203,9 +203,7 @@ else if (tile < HTRFBASE)

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);
}
}
Expand Down
4 changes: 1 addition & 3 deletions micropolis-java/src/micropolisj/engine/TileBehavior.java
Expand Up @@ -18,7 +18,6 @@ public abstract class TileBehavior
int xpos;
int ypos;
int tile;
int rawTile;

protected TileBehavior(Micropolis city)
{
Expand All @@ -30,8 +29,7 @@ public final void processTile(int xpos, int ypos)
{
this.xpos = xpos;
this.ypos = ypos;
this.rawTile = city.getTileRaw(xpos, ypos);
this.tile = rawTile & LOMASK;
this.tile = city.getTile(xpos, ypos);
apply();
}

Expand Down

0 comments on commit ad3128b

Please sign in to comment.