refactor: make getZoneSizeFor return CityDimension (width AND height)
git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@843 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
2af5cf14a7
commit
94e9892731
3 changed files with 45 additions and 49 deletions
|
@ -46,25 +46,27 @@ class Bulldozer extends ToolStroke
|
|||
// zone center bit is set
|
||||
assert isZoneCenter(currTile);
|
||||
|
||||
CityDimension dim = getZoneSizeFor(currTile);
|
||||
assert dim != null;
|
||||
assert dim.width >= 3;
|
||||
assert dim.height >= 3;
|
||||
|
||||
eff.spend(1);
|
||||
switch (getZoneSizeFor(currTile))
|
||||
{
|
||||
case 3:
|
||||
|
||||
// make explosion sound;
|
||||
// bigger zones => bigger explosions
|
||||
|
||||
if (dim.width * dim.height < 16) {
|
||||
eff.makeSound(0, 0, Sound.EXPLOSION_HIGH);
|
||||
putRubble(new TranslatedToolEffect(eff, -1, -1), 3, 3);
|
||||
break;
|
||||
case 4:
|
||||
eff.makeSound(0, 0, Sound.EXPLOSION_LOW);
|
||||
putRubble(new TranslatedToolEffect(eff, -1, -1), 4, 4);
|
||||
break;
|
||||
case 6:
|
||||
eff.makeSound(0, 0, Sound.EXPLOSION_BOTH);
|
||||
putRubble(new TranslatedToolEffect(eff, -1, -1), 6, 6);
|
||||
break;
|
||||
default:
|
||||
assert false;
|
||||
break;
|
||||
}
|
||||
else if (dim.width * dim.height < 36) {
|
||||
eff.makeSound(0, 0, Sound.EXPLOSION_LOW);
|
||||
}
|
||||
else {
|
||||
eff.makeSound(0, 0, Sound.EXPLOSION_BOTH);
|
||||
}
|
||||
|
||||
putRubble(new TranslatedToolEffect(eff, -1, -1), dim.width, dim.height);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -2293,14 +2293,19 @@ public class Micropolis
|
|||
{
|
||||
rateOGMem[ypos/8][xpos/8] -= 20;
|
||||
|
||||
int sz = TileConstants.getZoneSizeFor(zoneTile);
|
||||
int zoneBase = (zoneTile&LOMASK)-1-sz;
|
||||
assert isZoneCenter(zoneTile);
|
||||
CityDimension dim = getZoneSizeFor(zoneTile);
|
||||
assert dim != null;
|
||||
assert dim.width >= 3;
|
||||
assert dim.height >= 3;
|
||||
|
||||
int zoneBase = (zoneTile&LOMASK) - 1 - dim.width;
|
||||
|
||||
// this will take care of stopping smoke animations
|
||||
shutdownZone(xpos, ypos, sz);
|
||||
shutdownZone(xpos, ypos, dim);
|
||||
|
||||
for (int y = 0; y < sz; y++) {
|
||||
for (int x = 0; x < sz; x++, zoneBase++) {
|
||||
for (int y = 0; y < dim.height; y++) {
|
||||
for (int x = 0; x < dim.width; x++, zoneBase++) {
|
||||
int xtem = xpos - 1 + x;
|
||||
int ytem = ypos - 1 + y;
|
||||
if (!testBounds(xtem, ytem))
|
||||
|
@ -2321,10 +2326,13 @@ public class Micropolis
|
|||
* instead.
|
||||
* @see #shutdownZone
|
||||
*/
|
||||
void powerZone(int xpos, int ypos, int zoneSize)
|
||||
void powerZone(int xpos, int ypos, CityDimension zoneSize)
|
||||
{
|
||||
for (int dx = 0; dx < zoneSize; dx++) {
|
||||
for (int dy = 0; dy < zoneSize; dy++) {
|
||||
assert zoneSize.width >= 3;
|
||||
assert zoneSize.height >= 3;
|
||||
|
||||
for (int dx = 0; dx < zoneSize.width; dx++) {
|
||||
for (int dy = 0; dy < zoneSize.height; dy++) {
|
||||
int x = xpos - 1 + dx;
|
||||
int y = ypos - 1 + dy;
|
||||
int tile = getTile(x, y);
|
||||
|
@ -2344,10 +2352,13 @@ public class Micropolis
|
|||
* @see #powerZone
|
||||
* @see #killZone
|
||||
*/
|
||||
void shutdownZone(int xpos, int ypos, int zoneSize)
|
||||
void shutdownZone(int xpos, int ypos, CityDimension zoneSize)
|
||||
{
|
||||
for (int dx = 0; dx < zoneSize; dx++) {
|
||||
for (int dy = 0; dy < zoneSize; dy++) {
|
||||
assert zoneSize.width >= 3;
|
||||
assert zoneSize.height >= 3;
|
||||
|
||||
for (int dx = 0; dx < zoneSize.width; dx++) {
|
||||
for (int dy = 0; dy < zoneSize.height; dy++) {
|
||||
int x = xpos - 1 + dx;
|
||||
int y = ypos - 1 + dy;
|
||||
int tile = getTile(x, y);
|
||||
|
|
|
@ -396,30 +396,13 @@ public class TileConstants
|
|||
x == BRWV);
|
||||
}
|
||||
|
||||
public static int getZoneSizeFor(int tile)
|
||||
public static CityDimension getZoneSizeFor(int tile)
|
||||
{
|
||||
int ch = tile & LOMASK;
|
||||
if (ch >= RESBASE && ch < PORTBASE) {
|
||||
return 3;
|
||||
}
|
||||
else if (ch >= PORTBASE && ch <= LASTPORT) {
|
||||
return 4;
|
||||
}
|
||||
else if (ch >= AIRPORTBASE && ch < COALBASE) {
|
||||
return 6;
|
||||
}
|
||||
else if (ch >= COALBASE && ch <= LASTPOWERPLANT) {
|
||||
return 4;
|
||||
}
|
||||
else if (ch >= FIRESTBASE && ch < STADIUMBASE) {
|
||||
return 3;
|
||||
}
|
||||
else if (ch >= STADIUMBASE && ch <= LASTZONE) {
|
||||
return 4;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
TileSpec spec = Tiles.get(tile & LOMASK);
|
||||
if (spec.owner != null) {
|
||||
spec = spec.owner;
|
||||
}
|
||||
return spec.getBuildingSize();
|
||||
}
|
||||
|
||||
public static boolean isConstructed(int tile)
|
||||
|
|
Reference in a new issue