refactor: doSpecialZone- split up into separate functions for each zone type

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@835 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-09-03 01:07:25 +00:00
parent 1932084d22
commit 18f00153a3

View file

@ -414,20 +414,6 @@ class MapScanner
return dist; return dist;
} }
/**
* Called when the current tile is the key tile of an airport.
*/
void doAirport()
{
if (PRNG.nextInt(6) == 0) {
city.generatePlane(xpos, ypos);
}
if (PRNG.nextInt(13) == 0) {
city.generateCopter(xpos, ypos);
}
}
boolean checkZonePower() boolean checkZonePower()
{ {
boolean zonePwrFlag = setZonePower(); boolean zonePwrFlag = setZonePower();
@ -518,24 +504,20 @@ class MapScanner
return true; return true;
} }
/** void doCoalPower()
* Called when the current tile is the key tile of a "special" zone.
*/
void doSpecialZone()
{ {
boolean powerOn = checkZonePower(); boolean powerOn = checkZonePower();
switch (cchr9)
{
case POWERPLANT:
city.coalCount++; city.coalCount++;
if ((city.cityTime % 8) == 0) { if ((city.cityTime % 8) == 0) {
repairZone(POWERPLANT, 4); repairZone(POWERPLANT, 4);
} }
city.powerPlants.add(new CityLocation(xpos,ypos)); city.powerPlants.add(new CityLocation(xpos,ypos));
return; }
case NUCLEAR: void doNuclearPower()
{
boolean powerOn = checkZonePower();
if (!city.noDisasters && PRNG.nextInt(city.MltdwnTab[city.gameLevel]+1) == 0) { if (!city.noDisasters && PRNG.nextInt(city.MltdwnTab[city.gameLevel]+1) == 0) {
city.doMeltdown(xpos, ypos); city.doMeltdown(xpos, ypos);
return; return;
@ -547,10 +529,11 @@ class MapScanner
} }
city.powerPlants.add(new CityLocation(xpos, ypos)); city.powerPlants.add(new CityLocation(xpos, ypos));
return; }
case FIRESTATION: void doFireStation()
{ {
boolean powerOn = checkZonePower();
city.fireStationCount++; city.fireStationCount++;
if ((city.cityTime % 8) == 0) { if ((city.cityTime % 8) == 0) {
repairZone(FIRESTATION, 3); repairZone(FIRESTATION, 3);
@ -570,11 +553,11 @@ class MapScanner
} }
city.fireStMap[ypos/8][xpos/8] += z; city.fireStMap[ypos/8][xpos/8] += z;
return;
} }
case POLICESTATION: void doPoliceStation()
{ {
boolean powerOn = checkZonePower();
city.policeCount++; city.policeCount++;
if ((city.cityTime % 8) == 0) { if ((city.cityTime % 8) == 0) {
repairZone(POLICESTATION, 3); repairZone(POLICESTATION, 3);
@ -594,10 +577,11 @@ class MapScanner
} }
city.policeMap[ypos/8][xpos/8] += z; city.policeMap[ypos/8][xpos/8] += z;
return;
} }
case STADIUM: void doStadiumEmpty()
{
boolean powerOn = checkZonePower();
city.stadiumCount++; city.stadiumCount++;
if ((city.cityTime % 16) == 0) { if ((city.cityTime % 16) == 0) {
repairZone(STADIUM, 4); repairZone(STADIUM, 4);
@ -611,27 +595,40 @@ class MapScanner
city.setTile(xpos+1,ypos+1,(char)(FOOTBALLGAME2)); city.setTile(xpos+1,ypos+1,(char)(FOOTBALLGAME2));
} }
} }
return; }
case FULLSTADIUM: void doStadiumFull()
{
boolean powerOn = checkZonePower();
city.stadiumCount++; city.stadiumCount++;
if (((city.cityTime + xpos + ypos) % 8) == 0) { if (((city.cityTime + xpos + ypos) % 8) == 0) {
drawStadium(STADIUM); drawStadium(STADIUM);
} }
return; }
case AIRPORT: void doAirport()
{
boolean powerOn = checkZonePower();
city.airportCount++; city.airportCount++;
if ((city.cityTime % 8) == 0) { if ((city.cityTime % 8) == 0) {
repairZone(AIRPORT, 6); repairZone(AIRPORT, 6);
} }
if (powerOn) { if (powerOn) {
doAirport();
}
return;
case PORT: if (PRNG.nextInt(6) == 0) {
city.generatePlane(xpos, ypos);
}
if (PRNG.nextInt(13) == 0) {
city.generateCopter(xpos, ypos);
}
}
}
void doSeaport()
{
boolean powerOn = checkZonePower();
city.seaportCount++; city.seaportCount++;
if ((city.cityTime % 16) == 0) { if ((city.cityTime % 16) == 0) {
repairZone(PORT, 4); repairZone(PORT, 4);
@ -640,6 +637,45 @@ class MapScanner
if (powerOn && !city.hasSprite(SpriteKind.SHI)) { if (powerOn && !city.hasSprite(SpriteKind.SHI)) {
city.generateShip(); city.generateShip();
} }
}
/**
* Called when the current tile is the key tile of a "special" zone.
*/
void doSpecialZone()
{
switch (cchr9)
{
case POWERPLANT:
doCoalPower();
return;
case NUCLEAR:
doNuclearPower();
return;
case FIRESTATION:
doFireStation();
return;
case POLICESTATION:
doPoliceStation();
return;
case STADIUM:
doStadiumEmpty();
return;
case FULLSTADIUM:
doStadiumFull();
return;
case AIRPORT:
doAirport();
return;
case PORT:
doSeaport();
return; return;
default: default: