From 4c66df859fc328db2a5c22ccee65dfb151cba3ae Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Sun, 1 Sep 2013 00:26:16 +0000 Subject: [PATCH] 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 --- graphics/tiles.rc | 16 +++++++------- src/micropolisj/engine/TileSpec.java | 5 +++++ src/micropolisj/engine/Tiles.java | 33 ++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/graphics/tiles.rc b/graphics/tiles.rc index c2d4a33..b59b665 100644 --- a/graphics/tiles.rc +++ b/graphics/tiles.rc @@ -854,14 +854,14 @@ 830 misc_animation@0,48 (noburn) 831 misc_animation@0,64 (noburn) # BEGIN RADAR DISH # -832 misc_animation@0,80 (conducts) (becomes=833)(onshutdown=711) -833 misc_animation@0,96 (conducts) (becomes=834)(onshutdown=711) -834 misc_animation@0,112 (conducts) (becomes=835)(onshutdown=711) -835 misc_animation@0,128 (conducts) (becomes=836)(onshutdown=711) -836 misc_animation@0,144 (conducts) (becomes=837)(onshutdown=711) -837 misc_animation@0,160 (conducts) (becomes=838)(onshutdown=711) -838 misc_animation@0,176 (conducts) (becomes=839)(onshutdown=711) -839 misc_animation@0,192 (conducts) (becomes=832)(onshutdown=711) +832 misc_animation@0,80 (conducts)(building-part=716,1,-1) (becomes=833)(onshutdown=711) +833 misc_animation@0,96 (conducts)(building-part=716,1,-1) (becomes=834)(onshutdown=711) +834 misc_animation@0,112 (conducts)(building-part=716,1,-1) (becomes=835)(onshutdown=711) +835 misc_animation@0,128 (conducts)(building-part=716,1,-1) (becomes=836)(onshutdown=711) +836 misc_animation@0,144 (conducts)(building-part=716,1,-1) (becomes=837)(onshutdown=711) +837 misc_animation@0,160 (conducts)(building-part=716,1,-1) (becomes=838)(onshutdown=711) +838 misc_animation@0,176 (conducts)(building-part=716,1,-1) (becomes=839)(onshutdown=711) +839 misc_animation@0,192 (conducts)(building-part=716,1,-1) (becomes=832)(onshutdown=711) # BEGIN FOUNTAIN / FLAG # 840 misc_animation@0,208 (becomes=841) 841 misc_animation@0,224 (becomes=842) diff --git a/src/micropolisj/engine/TileSpec.java b/src/micropolisj/engine/TileSpec.java index 04c0786..01355da 100644 --- a/src/micropolisj/engine/TileSpec.java +++ b/src/micropolisj/engine/TileSpec.java @@ -231,4 +231,9 @@ public class TileSpec return peekChar() != -1; } } + + public String toString() + { + return "{tile#"+tileNumber+"}"; + } } diff --git a/src/micropolisj/engine/Tiles.java b/src/micropolisj/engine/Tiles.java index ebbd742..e6b4a1a 100644 --- a/src/micropolisj/engine/Tiles.java +++ b/src/micropolisj/engine/Tiles.java @@ -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) {