diff --git a/src/micropolisj/engine/CityDimension.java b/src/micropolisj/engine/CityDimension.java new file mode 100644 index 0000000..3c7f926 --- /dev/null +++ b/src/micropolisj/engine/CityDimension.java @@ -0,0 +1,48 @@ +// This file is part of MicropolisJ. +// Copyright (C) 2013 Jason Long +// Portions Copyright (C) 1989-2007 Electronic Arts Inc. +// +// MicropolisJ is free software; you can redistribute it and/or modify +// it under the terms of the GNU GPLv3, with additional terms. +// See the README file, included in this distribution, for details. + +package micropolisj.engine; + +/** + * Encapsulates the width and height of a rectangular section of a Micropolis city. + */ +public class CityDimension +{ + public int width; + public int height; + + public CityDimension(int width, int height) + { + this.width = width; + this.height = height; + } + + @Override + public int hashCode() + { + return width*33+height; + } + + @Override + public boolean equals(Object obj) + { + if (obj instanceof CityDimension) { + CityDimension rhs = (CityDimension) obj; + return this.width == rhs.width && this.height == rhs.height; + } + else { + return false; + } + } + + @Override + public String toString() + { + return width+"x"+height; + } +} diff --git a/src/micropolisj/engine/TileSpec.java b/src/micropolisj/engine/TileSpec.java index 89733ef..d39567f 100644 --- a/src/micropolisj/engine/TileSpec.java +++ b/src/micropolisj/engine/TileSpec.java @@ -52,16 +52,13 @@ public class TileSpec public BuildingInfo getBuildingInfo() { - String tmp = getAttribute("building"); - if (tmp == null) { return null; } + CityDimension buildingSize = getBuildingSize(); + if (buildingSize == 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]); + bi.width = buildingSize.width; + bi.height = buildingSize.height; bi.members = new short[bi.width*bi.height]; int startTile = tileNumber; @@ -78,6 +75,18 @@ public class TileSpec return bi; } + public CityDimension getBuildingSize() + { + String tmp = getAttribute("building"); + if (tmp == null) { return null; } + + String [] p2 = tmp.split("x"); + return new CityDimension( + Integer.parseInt(p2[0]), + Integer.parseInt(p2[1]) + ); + } + public int getDescriptionNumber() { String v = getAttribute("description");