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
|
// zone center bit is set
|
||||||
assert isZoneCenter(currTile);
|
assert isZoneCenter(currTile);
|
||||||
|
|
||||||
|
CityDimension dim = getZoneSizeFor(currTile);
|
||||||
|
assert dim != null;
|
||||||
|
assert dim.width >= 3;
|
||||||
|
assert dim.height >= 3;
|
||||||
|
|
||||||
eff.spend(1);
|
eff.spend(1);
|
||||||
switch (getZoneSizeFor(currTile))
|
|
||||||
{
|
// make explosion sound;
|
||||||
case 3:
|
// bigger zones => bigger explosions
|
||||||
|
|
||||||
|
if (dim.width * dim.height < 16) {
|
||||||
eff.makeSound(0, 0, Sound.EXPLOSION_HIGH);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2293,14 +2293,19 @@ public class Micropolis
|
||||||
{
|
{
|
||||||
rateOGMem[ypos/8][xpos/8] -= 20;
|
rateOGMem[ypos/8][xpos/8] -= 20;
|
||||||
|
|
||||||
int sz = TileConstants.getZoneSizeFor(zoneTile);
|
assert isZoneCenter(zoneTile);
|
||||||
int zoneBase = (zoneTile&LOMASK)-1-sz;
|
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
|
// 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 y = 0; y < dim.height; y++) {
|
||||||
for (int x = 0; x < sz; x++, zoneBase++) {
|
for (int x = 0; x < dim.width; x++, zoneBase++) {
|
||||||
int xtem = xpos - 1 + x;
|
int xtem = xpos - 1 + x;
|
||||||
int ytem = ypos - 1 + y;
|
int ytem = ypos - 1 + y;
|
||||||
if (!testBounds(xtem, ytem))
|
if (!testBounds(xtem, ytem))
|
||||||
|
@ -2321,10 +2326,13 @@ public class Micropolis
|
||||||
* instead.
|
* instead.
|
||||||
* @see #shutdownZone
|
* @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++) {
|
assert zoneSize.width >= 3;
|
||||||
for (int dy = 0; dy < zoneSize; dy++) {
|
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 x = xpos - 1 + dx;
|
||||||
int y = ypos - 1 + dy;
|
int y = ypos - 1 + dy;
|
||||||
int tile = getTile(x, y);
|
int tile = getTile(x, y);
|
||||||
|
@ -2344,10 +2352,13 @@ public class Micropolis
|
||||||
* @see #powerZone
|
* @see #powerZone
|
||||||
* @see #killZone
|
* @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++) {
|
assert zoneSize.width >= 3;
|
||||||
for (int dy = 0; dy < zoneSize; dy++) {
|
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 x = xpos - 1 + dx;
|
||||||
int y = ypos - 1 + dy;
|
int y = ypos - 1 + dy;
|
||||||
int tile = getTile(x, y);
|
int tile = getTile(x, y);
|
||||||
|
|
|
@ -396,30 +396,13 @@ public class TileConstants
|
||||||
x == BRWV);
|
x == BRWV);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getZoneSizeFor(int tile)
|
public static CityDimension getZoneSizeFor(int tile)
|
||||||
{
|
{
|
||||||
int ch = tile & LOMASK;
|
TileSpec spec = Tiles.get(tile & LOMASK);
|
||||||
if (ch >= RESBASE && ch < PORTBASE) {
|
if (spec.owner != null) {
|
||||||
return 3;
|
spec = spec.owner;
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
return spec.getBuildingSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConstructed(int tile)
|
public static boolean isConstructed(int tile)
|
||||||
|
|
Reference in a new issue