From a8713b682e1835b686eb79c9d891b3253e50c225 Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Fri, 6 Dec 2013 16:02:02 +0000 Subject: [PATCH] api: getTile() now returns masked tile number use getTileRaw() to get the raw tile number git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@897 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/engine/ExplosionSprite.java | 2 +- src/micropolisj/engine/Micropolis.java | 23 +++++++++++++-------- src/micropolisj/engine/RoadLikeTool.java | 6 +++--- src/micropolisj/engine/ShipSprite.java | 2 +- src/micropolisj/engine/Sprite.java | 4 ++-- src/micropolisj/engine/TerrainBehavior.java | 2 +- src/micropolisj/engine/TileBehavior.java | 2 +- src/micropolisj/engine/TrafficGen.java | 11 +++++----- 8 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/micropolisj/engine/ExplosionSprite.java b/src/micropolisj/engine/ExplosionSprite.java index 9a21691..93e659d 100644 --- a/src/micropolisj/engine/ExplosionSprite.java +++ b/src/micropolisj/engine/ExplosionSprite.java @@ -52,7 +52,7 @@ public class ExplosionSprite extends Sprite if (!city.testBounds(xpos, ypos)) return; - int z = city.getTile(xpos, ypos); + int z = city.getTileRaw(xpos, ypos); int t = z & LOMASK; if (!isCombustible(z) && t != DIRT) return; diff --git a/src/micropolisj/engine/Micropolis.java b/src/micropolisj/engine/Micropolis.java index 9c13fd5..8909359 100644 --- a/src/micropolisj/engine/Micropolis.java +++ b/src/micropolisj/engine/Micropolis.java @@ -424,13 +424,18 @@ public class Micropolis } public char getTile(int xpos, int ypos) + { + return (char)(map[ypos][xpos] & LOMASK); + } + + public char getTileRaw(int xpos, int ypos) { return map[ypos][xpos]; } boolean isTileDozeable(ToolEffectIfc eff) { - int myTile = eff.getTile(0, 0) & LOMASK; + int myTile = eff.getTile(0, 0); TileSpec ts = Tiles.get(myTile); if (ts.canBulldoze) { return true; @@ -440,7 +445,7 @@ public class Micropolis // part of a zone; only bulldozeable if the owner tile is // no longer intact. - int baseTile = eff.getTile(-ts.ownerOffsetX, -ts.ownerOffsetY) & LOMASK; + int baseTile = eff.getTile(-ts.ownerOffsetX, -ts.ownerOffsetY); return !(ts.owner.tileNumber == baseTile); } @@ -456,7 +461,7 @@ public class Micropolis public boolean isTilePowered(int xpos, int ypos) { - return (getTile(xpos, ypos) & PWRBIT) == PWRBIT; + return (getTileRaw(xpos, ypos) & PWRBIT) == PWRBIT; } public void setTile(int xpos, int ypos, char newTile) @@ -1467,7 +1472,7 @@ public class Micropolis void mapScanTile(int xpos, int ypos) { - int rawTile = getTile(xpos, ypos); + int rawTile = getTileRaw(xpos, ypos); String behaviorStr = getTileBehavior(rawTile & LOMASK); if (behaviorStr == null) { return; //nothing to do @@ -2083,11 +2088,11 @@ public class Micropolis for (int y = 0; y < map.length; y++) { for (int x = 0; x < map[y].length; x++) { int tile = getTile(x,y); - if ((tile & LOMASK) == NUCLEAR) { + if (tile == NUCLEAR) { nuclearCount++; powerPlants.add(new CityLocation(x,y)); } - else if ((tile & LOMASK) == POWERPLANT) { + else if (tile == POWERPLANT) { coalCount++; powerPlants.add(new CityLocation(x,y)); } @@ -2319,7 +2324,7 @@ public class Micropolis int x = PRNG.nextInt(getWidth() - 19) + 10; int y = PRNG.nextInt(getHeight() - 9) + 5; int t = getTile(x, y); - if ((t & LOMASK) == RIVER) { + if (t == RIVER) { makeMonsterAt(x, y); return; } @@ -2421,7 +2426,7 @@ public class Micropolis for (int dy = 0; dy < zoneSize.height; dy++) { int x = xpos - 1 + dx; int y = ypos - 1 + dy; - int tile = getTile(x, y); + int tile = getTileRaw(x, y); TileSpec ts = Tiles.get(tile & LOMASK); if (ts != null && ts.onPower != null) { setTile(x, y, @@ -2447,7 +2452,7 @@ public class Micropolis for (int dy = 0; dy < zoneSize.height; dy++) { int x = xpos - 1 + dx; int y = ypos - 1 + dy; - int tile = getTile(x, y); + int tile = getTileRaw(x, y); TileSpec ts = Tiles.get(tile & LOMASK); if (ts != null && ts.onShutdown != null) { setTile(x, y, diff --git a/src/micropolisj/engine/RoadLikeTool.java b/src/micropolisj/engine/RoadLikeTool.java index a4acb07..8649d74 100644 --- a/src/micropolisj/engine/RoadLikeTool.java +++ b/src/micropolisj/engine/RoadLikeTool.java @@ -145,7 +145,7 @@ class RoadLikeTool extends ToolStroke int cost = RAIL_COST; - char tile = (char) (eff.getTile(0, 0) & LOMASK); + char tile = (char) eff.getTile(0, 0); tile = neutralizeRoad(tile); switch (tile) @@ -250,7 +250,7 @@ class RoadLikeTool extends ToolStroke int cost = ROAD_COST; - char tile = (char) (eff.getTile(0, 0) & LOMASK); + char tile = (char) eff.getTile(0, 0); switch (tile) { case RIVER: // road on water @@ -354,7 +354,7 @@ class RoadLikeTool extends ToolStroke int cost = WIRE_COST; - char tile = (char) (eff.getTile(0, 0) & LOMASK); + char tile = (char) eff.getTile(0, 0); tile = neutralizeRoad(tile); switch (tile) diff --git a/src/micropolisj/engine/ShipSprite.java b/src/micropolisj/engine/ShipSprite.java index 9224039..f98f833 100644 --- a/src/micropolisj/engine/ShipSprite.java +++ b/src/micropolisj/engine/ShipSprite.java @@ -74,7 +74,7 @@ public class ShipSprite extends Sprite int ypos = this.y / 16 + BDy[z]; if (city.testBounds(xpos, ypos)) { - t = city.getTile(xpos, ypos) & LOMASK; + t = city.getTile(xpos, ypos); if ((t == CHANNEL) || (t == BRWH) || (t == BRWV) || tryOther(t, this.dir, z)) { diff --git a/src/micropolisj/engine/Sprite.java b/src/micropolisj/engine/Sprite.java index dd7e038..4f3d304 100644 --- a/src/micropolisj/engine/Sprite.java +++ b/src/micropolisj/engine/Sprite.java @@ -44,7 +44,7 @@ public abstract class Sprite int xpos = x / 16; int ypos = y / 16; if (city.testBounds(xpos, ypos)) { - return (city.getTile(xpos, ypos) & LOMASK); + return city.getTile(xpos, ypos); } else { return -1; } @@ -171,7 +171,7 @@ public abstract class Sprite if (!city.testBounds(xpos, ypos)) return; - int z = city.getTile(xpos, ypos); + int z = city.getTileRaw(xpos, ypos); int t = z & LOMASK; if (t >= TREEBASE) { diff --git a/src/micropolisj/engine/TerrainBehavior.java b/src/micropolisj/engine/TerrainBehavior.java index 479d301..56e435d 100644 --- a/src/micropolisj/engine/TerrainBehavior.java +++ b/src/micropolisj/engine/TerrainBehavior.java @@ -117,7 +117,7 @@ class TerrainBehavior extends TileBehavior int xx = xpos + DX[z]; int yy = ypos + DY[z]; if (city.testBounds(xx, yy)) { - int c = city.getTile(xx, yy); + int c = city.getTileRaw(xx, yy); int t = c & LOMASK; if (isCombustible(c) || c == DIRT || (t >= WOODS5 && t < FLOOD)) diff --git a/src/micropolisj/engine/TileBehavior.java b/src/micropolisj/engine/TileBehavior.java index ff367db..24d3956 100644 --- a/src/micropolisj/engine/TileBehavior.java +++ b/src/micropolisj/engine/TileBehavior.java @@ -30,7 +30,7 @@ public abstract class TileBehavior { this.xpos = xpos; this.ypos = ypos; - this.rawTile = city.getTile(xpos, ypos); + this.rawTile = city.getTileRaw(xpos, ypos); this.tile = rawTile & LOMASK; apply(); } diff --git a/src/micropolisj/engine/TrafficGen.java b/src/micropolisj/engine/TrafficGen.java index 5fecc86..7ef7533 100644 --- a/src/micropolisj/engine/TrafficGen.java +++ b/src/micropolisj/engine/TrafficGen.java @@ -61,7 +61,7 @@ class TrafficGen assert city.testBounds(mapX, mapY); // check for road/rail - int tile = city.getTile(mapX, mapY) & LOMASK; + int tile = city.getTile(mapX, mapY); if (tile >= ROADBASE && tile < POWERBASE) { city.addTraffic(mapX, mapY, 50); @@ -95,7 +95,6 @@ class TrafficGen } char c = city.getTile(tx, ty); - c &= LOMASK; if (c < ROADBASE) return false; @@ -197,25 +196,25 @@ class TrafficGen if (mapY > 0) { - int tile = city.getTile(mapX, mapY-1) & LOMASK; + int tile = city.getTile(mapX, mapY-1); if (tile >= low && tile <= high) return true; } if (mapX + 1 < city.getWidth()) { - int tile = city.getTile(mapX + 1, mapY) & LOMASK; + int tile = city.getTile(mapX + 1, mapY); if (tile >= low && tile <= high) return true; } if (mapY + 1 < city.getHeight()) { - int tile = city.getTile(mapX, mapY + 1) & LOMASK; + int tile = city.getTile(mapX, mapY + 1); if (tile >= low && tile <= high) return true; } if (mapX > 0) { - int tile = city.getTile(mapX - 1, mapY) & LOMASK; + int tile = city.getTile(mapX - 1, mapY); if (tile >= low && tile <= high) return true; }