tiles: transfer ZONEBIT knowledge to tiles.rc

and synthesize ZONEBIT when saving (for compatibility)

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@740 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-07-20 21:10:29 +00:00
parent 9bf2e91783
commit 91b3736886
8 changed files with 83 additions and 70 deletions

View file

@ -509,7 +509,7 @@ class MapScanner
{
for (int x = xpos-1; x <= xpos+1; x++)
{
city.setTile(x, y, (char)(base | BNCNBIT | (x == xpos && y == ypos ? ZONEBIT + BULLBIT : 0)));
city.setTile(x, y, (char)(base | BNCNBIT | (x == xpos && y == ypos ? BULLBIT : 0)));
base++;
}
}
@ -1207,7 +1207,7 @@ class MapScanner
{
// downgrade from full-size zone to 8 little houses
city.setTile(xpos, ypos, (char)(FREEZ | BLBNCNBIT | ZONEBIT));
city.setTile(xpos, ypos, (char)(FREEZ | BLBNCNBIT));
for (int x = xpos-1; x <= xpos+1; x++)
{
for (int y = ypos-1; y <= ypos+1; y++)
@ -1374,7 +1374,7 @@ class MapScanner
for (int x = 0; x < 4; x++, zoneBase++)
{
city.setTile(xpos - 1 + x, ypos - 1 + y,
(char) (zoneBase | BNCNBIT | (x == 1 && y == 1 ? (ZONEBIT|PWRBIT) : 0)));
(char) (zoneBase | BNCNBIT | (x == 1 && y == 1 ? (PWRBIT) : 0)));
}
}
}

View file

@ -1965,7 +1965,7 @@ public class Micropolis
for (int y = 0; y < DEFAULT_HEIGHT; y++)
{
int z = dis.readShort();
z &= ~(2048); // clear ANIMBIT on import
z &= ~(1024 | 2048); // clear ZONEBIT,ANIMBIT on import
map[y][x] = (char) z;
}
}
@ -1982,6 +1982,9 @@ public class Micropolis
if (isAnimated(z)) {
z |= 2048; //synthesize ANIMBIT on export
}
if (isZoneCenter(z)) {
z |= 1024; //synthesize ZONEBIT
}
out.writeShort(z);
}
}

View file

@ -213,7 +213,7 @@ public class TileConstants
public static final char BURNBIT = 8192; // bit 13 ... is combustible
public static final char BULLBIT = 4096; // bit 12 ... is bulldozable
// bit 11 ... unused
public static final char ZONEBIT = 1024; // bit 10 ... is the special tile for a zone
// bit 10 ... unused
public static final char ALLBITS = 64512; // mask for upper 6 bits
public static final char LOMASK = 1023; //mask for low 10 bits
@ -290,7 +290,7 @@ public class TileConstants
public static boolean isArsonable(int tile)
{
return (
(tile & ZONEBIT) == 0 &&
!isZoneCenter(tile) &&
(tile & LOMASK) >= LHTHR &&
(tile & LOMASK) <= LASTZONE
);
@ -372,7 +372,7 @@ public class TileConstants
int tem2 = tile & LOMASK;
if (tem2 < RESBASE ||
tem2 > LASTZONE ||
(tile & ZONEBIT) != 0
isZoneCenter(tile)
) {
return false;
} else {
@ -473,7 +473,8 @@ public class TileConstants
public static boolean isZoneCenter(int tile)
{
return tile >= 0 && (tile & ZONEBIT) != 0;
TileSpec spec = Tiles.get(tile & LOMASK);
return spec != null && spec.zone;
}
/**

View file

@ -6,6 +6,8 @@ public class TileSpec
{
int tileNumber;
TileSpec animNext;
boolean zone;
Map<String,String> attributes;
List<String> images;
@ -28,6 +30,12 @@ public class TileSpec
return attributes.get(key);
}
public boolean getBooleanAttribute(String key)
{
String v = getAttribute(key);
return (v != null && v.equals("true"));
}
public String [] getImages()
{
return images.toArray(new String[0]);
@ -42,7 +50,7 @@ public class TileSpec
if (in.peekChar() == '(') {
in.eatChar('(');
String k = in.readAttributeKey();
String v = "1";
String v = "true";
if (in.peekChar() == '=') {
in.eatChar('=');
v = in.readAttributeValue();
@ -60,6 +68,8 @@ public class TileSpec
images.add(v);
}
}
this.zone = getBooleanAttribute("zone");
}
static class Scanner

View file

@ -182,8 +182,7 @@ public class ToolStroke
for (int columnNum = 0; columnNum < width; columnNum++)
{
eff.setTile(columnNum, rowNum, (char) (
tileBase + BNCNBIT +
(columnNum == centerColNum && rowNum == centerRowNum ? ZONEBIT : 0)
tileBase + BNCNBIT
));
tileBase++;
}