buildings: allow defining anim tiles as belonging to a building

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@814 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-09-01 00:26:16 +00:00
parent 306058afeb
commit 4c66df859f
3 changed files with 42 additions and 12 deletions

View file

@ -231,4 +231,9 @@ public class TileSpec
return peekChar() != -1;
}
}
public String toString()
{
return "{tile#"+tileNumber+"}";
}
}

View file

@ -53,19 +53,44 @@ public class Tiles
if (tmp != null) {
tiles[i].onShutdown = get(Integer.parseInt(tmp));
}
tmp = tiles[i].getAttribute("building-part");
if (tmp != null) {
handleBuildingPart(tiles[i], tmp);
}
TileSpec.BuildingInfo bi = tiles[i].getBuildingInfo();
if (bi != null) {
for (int j = 0; j < bi.members.length; j++) {
int tid = bi.members[j];
tiles[tid].owner = tiles[i];
tiles[tid].ownerOffsetX = (bi.width >= 3 ? -1 : 0) + j % bi.width;
tiles[tid].ownerOffsetY = (bi.height >= 3 ? -1 : 0) + j / bi.width;
int offx = (bi.width >= 3 ? -1 : 0) + j % bi.width;
int offy = (bi.height >= 3 ? -1 : 0) + j / bi.width;
if (tiles[tid].owner == null &&
(offx != 0 || offy != 0)
)
{
tiles[tid].owner = tiles[i];
tiles[tid].ownerOffsetX = offx;
tiles[tid].ownerOffsetY = offy;
}
}
}
}
}
private static void handleBuildingPart(TileSpec partTile, String tmp)
{
String [] parts = tmp.split(",");
if (parts.length != 3) {
throw new Error("Invalid building-part specification");
}
partTile.owner = get(Integer.parseInt(parts[0]));
partTile.ownerOffsetX = Integer.parseInt(parts[1]);
partTile.ownerOffsetY = Integer.parseInt(parts[2]);
assert partTile.ownerOffsetX != 0 || partTile.ownerOffsetY != 0;
}
public static TileSpec get(int tileNumber)
{
if (tileNumber >= 0 && tileNumber < tiles.length) {