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:
parent
1932084d22
commit
18f00153a3
1 changed files with 143 additions and 107 deletions
|
@ -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,128 +504,178 @@ class MapScanner
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void doCoalPower()
|
||||||
|
{
|
||||||
|
boolean powerOn = checkZonePower();
|
||||||
|
city.coalCount++;
|
||||||
|
if ((city.cityTime % 8) == 0) {
|
||||||
|
repairZone(POWERPLANT, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
city.powerPlants.add(new CityLocation(xpos,ypos));
|
||||||
|
}
|
||||||
|
|
||||||
|
void doNuclearPower()
|
||||||
|
{
|
||||||
|
boolean powerOn = checkZonePower();
|
||||||
|
if (!city.noDisasters && PRNG.nextInt(city.MltdwnTab[city.gameLevel]+1) == 0) {
|
||||||
|
city.doMeltdown(xpos, ypos);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
city.nuclearCount++;
|
||||||
|
if ((city.cityTime % 8) == 0) {
|
||||||
|
repairZone(NUCLEAR, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
city.powerPlants.add(new CityLocation(xpos, ypos));
|
||||||
|
}
|
||||||
|
|
||||||
|
void doFireStation()
|
||||||
|
{
|
||||||
|
boolean powerOn = checkZonePower();
|
||||||
|
city.fireStationCount++;
|
||||||
|
if ((city.cityTime % 8) == 0) {
|
||||||
|
repairZone(FIRESTATION, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
int z;
|
||||||
|
if (powerOn) {
|
||||||
|
z = city.fireEffect; //if powered, get effect
|
||||||
|
} else {
|
||||||
|
z = city.fireEffect/2; // from the funding ratio
|
||||||
|
}
|
||||||
|
|
||||||
|
city.traffic.mapX = xpos;
|
||||||
|
city.traffic.mapY = ypos;
|
||||||
|
if (!city.traffic.findPerimeterRoad()) {
|
||||||
|
z /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
city.fireStMap[ypos/8][xpos/8] += z;
|
||||||
|
}
|
||||||
|
|
||||||
|
void doPoliceStation()
|
||||||
|
{
|
||||||
|
boolean powerOn = checkZonePower();
|
||||||
|
city.policeCount++;
|
||||||
|
if ((city.cityTime % 8) == 0) {
|
||||||
|
repairZone(POLICESTATION, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
int z;
|
||||||
|
if (powerOn) {
|
||||||
|
z = city.policeEffect;
|
||||||
|
} else {
|
||||||
|
z = city.policeEffect / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
city.traffic.mapX = xpos;
|
||||||
|
city.traffic.mapY = ypos;
|
||||||
|
if (!city.traffic.findPerimeterRoad()) {
|
||||||
|
z /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
city.policeMap[ypos/8][xpos/8] += z;
|
||||||
|
}
|
||||||
|
|
||||||
|
void doStadiumEmpty()
|
||||||
|
{
|
||||||
|
boolean powerOn = checkZonePower();
|
||||||
|
city.stadiumCount++;
|
||||||
|
if ((city.cityTime % 16) == 0) {
|
||||||
|
repairZone(STADIUM, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (powerOn)
|
||||||
|
{
|
||||||
|
if (((city.cityTime + xpos + ypos) % 32) == 0) {
|
||||||
|
drawStadium(FULLSTADIUM);
|
||||||
|
city.setTile(xpos+1,ypos, (char)(FOOTBALLGAME1));
|
||||||
|
city.setTile(xpos+1,ypos+1,(char)(FOOTBALLGAME2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void doStadiumFull()
|
||||||
|
{
|
||||||
|
boolean powerOn = checkZonePower();
|
||||||
|
city.stadiumCount++;
|
||||||
|
if (((city.cityTime + xpos + ypos) % 8) == 0) {
|
||||||
|
drawStadium(STADIUM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void doAirport()
|
||||||
|
{
|
||||||
|
boolean powerOn = checkZonePower();
|
||||||
|
city.airportCount++;
|
||||||
|
if ((city.cityTime % 8) == 0) {
|
||||||
|
repairZone(AIRPORT, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (powerOn) {
|
||||||
|
|
||||||
|
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++;
|
||||||
|
if ((city.cityTime % 16) == 0) {
|
||||||
|
repairZone(PORT, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (powerOn && !city.hasSprite(SpriteKind.SHI)) {
|
||||||
|
city.generateShip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the current tile is the key tile of a "special" zone.
|
* Called when the current tile is the key tile of a "special" zone.
|
||||||
*/
|
*/
|
||||||
void doSpecialZone()
|
void doSpecialZone()
|
||||||
{
|
{
|
||||||
boolean powerOn = checkZonePower();
|
|
||||||
switch (cchr9)
|
switch (cchr9)
|
||||||
{
|
{
|
||||||
case POWERPLANT:
|
case POWERPLANT:
|
||||||
city.coalCount++;
|
doCoalPower();
|
||||||
if ((city.cityTime % 8) == 0) {
|
|
||||||
repairZone(POWERPLANT, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
city.powerPlants.add(new CityLocation(xpos,ypos));
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case NUCLEAR:
|
case NUCLEAR:
|
||||||
if (!city.noDisasters && PRNG.nextInt(city.MltdwnTab[city.gameLevel]+1) == 0) {
|
doNuclearPower();
|
||||||
city.doMeltdown(xpos, ypos);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
city.nuclearCount++;
|
|
||||||
if ((city.cityTime % 8) == 0) {
|
|
||||||
repairZone(NUCLEAR, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
city.powerPlants.add(new CityLocation(xpos, ypos));
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case FIRESTATION:
|
case FIRESTATION:
|
||||||
{
|
doFireStation();
|
||||||
city.fireStationCount++;
|
|
||||||
if ((city.cityTime % 8) == 0) {
|
|
||||||
repairZone(FIRESTATION, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
int z;
|
|
||||||
if (powerOn) {
|
|
||||||
z = city.fireEffect; //if powered, get effect
|
|
||||||
} else {
|
|
||||||
z = city.fireEffect/2; // from the funding ratio
|
|
||||||
}
|
|
||||||
|
|
||||||
city.traffic.mapX = xpos;
|
|
||||||
city.traffic.mapY = ypos;
|
|
||||||
if (!city.traffic.findPerimeterRoad()) {
|
|
||||||
z /= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
city.fireStMap[ypos/8][xpos/8] += z;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
case POLICESTATION:
|
case POLICESTATION:
|
||||||
{
|
doPoliceStation();
|
||||||
city.policeCount++;
|
|
||||||
if ((city.cityTime % 8) == 0) {
|
|
||||||
repairZone(POLICESTATION, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
int z;
|
|
||||||
if (powerOn) {
|
|
||||||
z = city.policeEffect;
|
|
||||||
} else {
|
|
||||||
z = city.policeEffect / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
city.traffic.mapX = xpos;
|
|
||||||
city.traffic.mapY = ypos;
|
|
||||||
if (!city.traffic.findPerimeterRoad()) {
|
|
||||||
z /= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
city.policeMap[ypos/8][xpos/8] += z;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
case STADIUM:
|
case STADIUM:
|
||||||
city.stadiumCount++;
|
doStadiumEmpty();
|
||||||
if ((city.cityTime % 16) == 0) {
|
|
||||||
repairZone(STADIUM, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (powerOn)
|
|
||||||
{
|
|
||||||
if (((city.cityTime + xpos + ypos) % 32) == 0) {
|
|
||||||
drawStadium(FULLSTADIUM);
|
|
||||||
city.setTile(xpos+1,ypos, (char)(FOOTBALLGAME1));
|
|
||||||
city.setTile(xpos+1,ypos+1,(char)(FOOTBALLGAME2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case FULLSTADIUM:
|
case FULLSTADIUM:
|
||||||
city.stadiumCount++;
|
doStadiumFull();
|
||||||
if (((city.cityTime + xpos + ypos) % 8) == 0) {
|
|
||||||
drawStadium(STADIUM);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case AIRPORT:
|
case AIRPORT:
|
||||||
city.airportCount++;
|
doAirport();
|
||||||
if ((city.cityTime % 8) == 0) {
|
|
||||||
repairZone(AIRPORT, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (powerOn) {
|
|
||||||
doAirport();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PORT:
|
case PORT:
|
||||||
city.seaportCount++;
|
doSeaport();
|
||||||
if ((city.cityTime % 16) == 0) {
|
|
||||||
repairZone(PORT, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (powerOn && !city.hasSprite(SpriteKind.SHI)) {
|
|
||||||
city.generateShip();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Reference in a new issue