tile animation: use tiles.rc to control termination of coal plant smoke

when the coal plant is killed

Also, this sets up a framework to handle industrial zones in the same way.

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@759 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-07-20 21:35:05 +00:00
parent a190bbf88b
commit 0c497aa434
5 changed files with 84 additions and 50 deletions

View file

@ -944,22 +944,22 @@
914 misc_animation@0,1392 (conducts) (becomes=915)
915 misc_animation@0,1408 (conducts) (becomes=912)
# BEGIN COAL PLANT SMOKE #
916 misc_animation@0,1424 (conducts) (becomes=917)
917 misc_animation@0,1440 (conducts) (becomes=918)
918 misc_animation@0,1456 (conducts) (becomes=919)
919 misc_animation@0,1472 (conducts) (becomes=916)
920 misc_animation@0,1488 (conducts) (becomes=921)
921 misc_animation@0,1504 (conducts) (becomes=922)
922 misc_animation@0,1520 (conducts) (becomes=923)
923 misc_animation@0,1536 (conducts) (becomes=920)
924 misc_animation@0,1552 (conducts) (becomes=925)
925 misc_animation@0,1568 (conducts) (becomes=926)
926 misc_animation@0,1584 (conducts) (becomes=927)
927 misc_animation@0,1600 (conducts) (becomes=924)
928 misc_animation@0,1616 (conducts) (becomes=929)
929 misc_animation@0,1632 (conducts) (becomes=930)
930 misc_animation@0,1648 (conducts) (becomes=931)
931 misc_animation@0,1664 (conducts) (becomes=928)
916 misc_animation@0,1424 (conducts) (becomes=917)(onshutdown=747)
917 misc_animation@0,1440 (conducts) (becomes=918)(onshutdown=747)
918 misc_animation@0,1456 (conducts) (becomes=919)(onshutdown=747)
919 misc_animation@0,1472 (conducts) (becomes=916)(onshutdown=747)
920 misc_animation@0,1488 (conducts) (becomes=921)(onshutdown=748)
921 misc_animation@0,1504 (conducts) (becomes=922)(onshutdown=748)
922 misc_animation@0,1520 (conducts) (becomes=923)(onshutdown=748)
923 misc_animation@0,1536 (conducts) (becomes=920)(onshutdown=748)
924 misc_animation@0,1552 (conducts) (becomes=925)(onshutdown=751)
925 misc_animation@0,1568 (conducts) (becomes=926)(onshutdown=751)
926 misc_animation@0,1584 (conducts) (becomes=927)(onshutdown=751)
927 misc_animation@0,1600 (conducts) (becomes=924)(onshutdown=751)
928 misc_animation@0,1616 (conducts) (becomes=929)(onshutdown=752)
929 misc_animation@0,1632 (conducts) (becomes=930)(onshutdown=752)
930 misc_animation@0,1648 (conducts) (becomes=931)(onshutdown=752)
931 misc_animation@0,1664 (conducts) (becomes=928)(onshutdown=752)
# BEGIN STADIUM PLAYFIELD #
# Note: the original source code made these unburnable, which doesn't make sense
932 misc_animation@0,1680 (conducts) (becomes=933)

View file

@ -456,18 +456,25 @@ class MapScanner
cchr = city.map[ypos][xpos];
cchr9 = (char) (cchr & LOMASK);
if (cchr9 == NUCLEAR ||
boolean oldPower = (cchr & PWRBIT) == PWRBIT;
boolean newPower = (
cchr9 == NUCLEAR ||
cchr9 == POWERPLANT ||
city.hasPower(xpos,ypos))
city.hasPower(xpos,ypos)
);
if (newPower && !oldPower)
{
city.setTile(xpos, ypos, (char) (cchr | PWRBIT));
return true;
city.powerZone(xpos, ypos, getZoneSizeFor(cchr));
}
else
else if (!newPower && oldPower)
{
city.setTile(xpos, ypos, (char) (cchr & (~PWRBIT)));
return false;
city.shutdownZone(xpos, ypos, getZoneSizeFor(cchr));
}
return newPower;
}
/**
@ -528,7 +535,6 @@ class MapScanner
}
city.powerPlants.add(new CityLocation(xpos,ypos));
coalSmoke();
return;
case NUCLEAR:
@ -1322,26 +1328,6 @@ class MapScanner
return 3;
}
/**
* Process the coal powerplant animation.
* Note: pollution is not accumulated here; see ptlScan()
* instead.
*/
void coalSmoke()
{
for (int dx = -1; dx <= 2; dx++) {
for (int dy = -1; dy <= 2; dy++) {
int tile = city.getTile(xpos+dx, ypos+dy);
TileSpec ts = Tiles.get(tile & LOMASK);
if (ts != null && ts.onPower != null) {
city.setTile(xpos + dx, ypos + dy,
(char) (ts.onPower.tileNumber | (tile & ALLBITS))
);
}
}
}
}
/**
* Record a zone's population change to the rate-of-growth
* map.

View file

@ -2322,6 +2322,7 @@ public class Micropolis
* Should be called whenever the key zone tile of a zone is destroyed,
* since otherwise the user would no longer have a way of destroying
* the zone.
* @see #shutdownZone
*/
void killZone(int xpos, int ypos, int zoneTile)
{
@ -2330,6 +2331,9 @@ public class Micropolis
int sz = TileConstants.getZoneSizeFor(zoneTile);
int zoneBase = (zoneTile&LOMASK)-1-sz;
// this will take care of stopping smoke animations
shutdownZone(xpos, ypos, sz);
for (int y = 0; y < sz; y++) {
for (int x = 0; x < sz; x++, zoneBase++) {
int xtem = xpos - 1 + x;
@ -2338,14 +2342,6 @@ public class Micropolis
continue;
int t = getTile(xtem, ytem);
if ((zoneTile & LOMASK) == POWERPLANT &&
(t & LOMASK) >= COALSMOKE1 &&
(t & LOMASK) < COALSMOKE4+4) {
// animated coal smoke
setTile(xtem, ytem, (char)(zoneBase | BULLBIT));
continue;
}
if ((t & LOMASK) >= ROADBASE) {
setTile(xtem, ytem, (char)(t | BULLBIT));
}
@ -2353,6 +2349,53 @@ public class Micropolis
}
}
/**
* If a zone has a different image (animation) for when it is
* powered, switch to that different image here.
* Note: pollution is not accumulated here; see ptlScan()
* instead.
* @see #shutdownZone
*/
void powerZone(int xpos, int ypos, int zoneSize)
{
for (int dx = 0; dx < zoneSize; dx++) {
for (int dy = 0; dy < zoneSize; dy++) {
int x = xpos - 1 + dx;
int y = ypos - 1 + dy;
int tile = getTile(x, y);
TileSpec ts = Tiles.get(tile & LOMASK);
if (ts != null && ts.onPower != null) {
setTile(x, y,
(char) (ts.onPower.tileNumber | (tile & ALLBITS))
);
}
}
}
}
/**
* If a zone has a different image (animation) for when it is
* powered, switch back to the original image.
* @see #powerZone
* @see #killZone
*/
void shutdownZone(int xpos, int ypos, int zoneSize)
{
for (int dx = 0; dx < zoneSize; dx++) {
for (int dy = 0; dy < zoneSize; dy++) {
int x = xpos - 1 + dx;
int y = ypos - 1 + dy;
int tile = getTile(x, y);
TileSpec ts = Tiles.get(tile & LOMASK);
if (ts != null && ts.onShutdown != null) {
setTile(x, y,
(char) (ts.onShutdown.tileNumber | (tile & ALLBITS))
);
}
}
}
}
void makeExplosion(int xpos, int ypos)
{
makeExplosionAt(xpos*16+8, ypos*16+8);

View file

@ -7,6 +7,7 @@ public class TileSpec
int tileNumber;
TileSpec animNext;
TileSpec onPower;
TileSpec onShutdown;
boolean canBurn;
boolean canConduct;
boolean zone;

View file

@ -49,6 +49,10 @@ public class Tiles
if (tmp != null) {
tiles[i].onPower = get(Integer.parseInt(tmp));
}
tmp = tiles[i].getAttribute("onshutdown");
if (tmp != null) {
tiles[i].onShutdown = get(Integer.parseInt(tmp));
}
}
}