tile animation: synthesize ANIMBIT when saving (for compatibility)
Also, add some safety checks in case Tiles.get() is called with an out-of-range tile number. git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@739 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
568377ccc8
commit
9bf2e91783
3 changed files with 15 additions and 4 deletions
|
@ -1964,7 +1964,9 @@ public class Micropolis
|
||||||
{
|
{
|
||||||
for (int y = 0; y < DEFAULT_HEIGHT; y++)
|
for (int y = 0; y < DEFAULT_HEIGHT; y++)
|
||||||
{
|
{
|
||||||
map[y][x] = (char) dis.readShort();
|
int z = dis.readShort();
|
||||||
|
z &= ~(2048); // clear ANIMBIT on import
|
||||||
|
map[y][x] = (char) z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1976,7 +1978,11 @@ public class Micropolis
|
||||||
{
|
{
|
||||||
for (int y = 0; y < DEFAULT_HEIGHT; y++)
|
for (int y = 0; y < DEFAULT_HEIGHT; y++)
|
||||||
{
|
{
|
||||||
out.writeShort(map[y][x]);
|
int z = map[y][x];
|
||||||
|
if (isAnimated(z)) {
|
||||||
|
z |= 2048; //synthesize ANIMBIT on export
|
||||||
|
}
|
||||||
|
out.writeShort(z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,7 +283,7 @@ public class TileConstants
|
||||||
public static boolean isAnimated(int tile)
|
public static boolean isAnimated(int tile)
|
||||||
{
|
{
|
||||||
TileSpec spec = Tiles.get(tile & LOMASK);
|
TileSpec spec = Tiles.get(tile & LOMASK);
|
||||||
return spec.animNext != null;
|
return spec != null && spec.animNext != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//used by setFire()
|
//used by setFire()
|
||||||
|
|
|
@ -50,6 +50,11 @@ public class Tiles
|
||||||
|
|
||||||
public static TileSpec get(int tileNumber)
|
public static TileSpec get(int tileNumber)
|
||||||
{
|
{
|
||||||
|
if (tileNumber >= 0 && tileNumber < tiles.length) {
|
||||||
return tiles[tileNumber];
|
return tiles[tileNumber];
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue