diff --git a/src/micropolisj/engine/MapScanner.java b/src/micropolisj/engine/MapScanner.java index 5ff4da0..6e4a6f5 100644 --- a/src/micropolisj/engine/MapScanner.java +++ b/src/micropolisj/engine/MapScanner.java @@ -481,6 +481,52 @@ class MapScanner return newPower; } + /** + * Place a 3x3 zone on to the map, centered on the current location. + * Note: nothing is done if part of this zone is off the edge + * of the map or is being flooded or radioactive. + * + * @param base The "zone" tile value for this zone. + * @return true iff the zone was actually placed. + */ + boolean zonePlopNew(int base) + { + assert isZoneCenter(base); + + TileSpec.BuildingInfo bi = Tiles.get(base).getBuildingInfo(); + assert bi != null; + if (bi == null) + return false; + + for (int y = ypos-1; y < ypos-1+bi.height; y++) + { + for (int x = xpos-1; x < xpos-1+bi.width; x++) + { + if (!city.testBounds(x, y)) { + return false; + } + if (isIndestructible2(city.getTile(x,y))) { + // radioactive, on fire, or flooded + return false; + } + } + } + + assert bi.members.length == bi.width * bi.height; + int i = 0; + for (int y = ypos-1; y < ypos-1+bi.height; y++) + { + for (int x = xpos-1; x < xpos-1+bi.width; x++) + { + city.setTile(x, y, (char)(bi.members[i] | (x == xpos && y == ypos ? BULLBIT : 0))); + i++; + } + } + + setZonePower(); + return true; + } + /** * Place a 3x3 zone on to the map, centered on the current location. * Note: nothing is done if part of this zone is off the edge diff --git a/src/micropolisj/engine/TileSpec.java b/src/micropolisj/engine/TileSpec.java index d41cf4c..09647e8 100644 --- a/src/micropolisj/engine/TileSpec.java +++ b/src/micropolisj/engine/TileSpec.java @@ -40,6 +40,38 @@ public class TileSpec return (v != null && v.equals("true")); } + public static class BuildingInfo + { + int width; + int height; + short [] members; + } + + public BuildingInfo getBuildingInfo() + { + String tmp = getAttribute("compound"); + if (tmp == null) { return null; } + + BuildingInfo bi = new BuildingInfo(); + + String [] parts = tmp.split(","); + String [] p2 = parts[0].split("x"); + + bi.width = Integer.parseInt(p2[0]); + bi.height = Integer.parseInt(p2[1]); + short startTile = Short.parseShort(parts[1]); + + bi.members = new short[bi.width*bi.height]; + for (int row = 0; row < bi.height; row++) { + for (int col = 0; col < bi.width; col++) { + bi.members[row*bi.width+col] = startTile; + startTile++; + } + } + + return bi; + } + public String [] getImages() { return images.toArray(new String[0]);