refactor: move traffic-density mutation code to new function

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@861 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-09-28 16:33:56 +00:00
parent 99954a3619
commit 72fac6d84e
2 changed files with 32 additions and 22 deletions

View file

@ -1028,6 +1028,36 @@ public class Micropolis
}
}
/**
* Increase the traffic-density measurement at a particular
* spot.
* @param traffic the amount to add to the density
*/
void addTraffic(int mapX, int mapY, int traffic)
{
int z = trfDensity[mapY/2][mapX/2];
z += traffic;
//FIXME- why is this only capped to 240
// by random chance. why is there no cap
// the rest of the time?
if (z > 240 && PRNG.nextInt(6) == 0)
{
z = 240;
trafficMaxLocationX = mapX;
trafficMaxLocationY = mapY;
HelicopterSprite copter = (HelicopterSprite) getSprite(SpriteKind.COP);
if (copter != null) {
copter.destX = mapX;
copter.destY = mapY;
}
}
trfDensity[mapY/2][mapX/2] = z;
}
public int getTrafficDensity(int xpos, int ypos)
{
if (testBounds(xpos, ypos)) {

View file

@ -60,31 +60,11 @@ class TrafficGen
mapY = pos.y;
assert city.testBounds(mapX, mapY);
// check for road/rail
int tile = city.getTile(mapX, mapY) & LOMASK;
if (tile >= ROADBASE && tile < POWERBASE)
{
// check for rail
int z = city.trfDensity[mapY/2][mapX/2];
z += 50;
//FIXME- why is this only capped to 240
// by random chance. why is there no cap
// the rest of the time?
if (z > 240 && city.PRNG.nextInt(6) == 0)
{
z = 240;
city.trafficMaxLocationX = mapX;
city.trafficMaxLocationY = mapY;
HelicopterSprite copter = (HelicopterSprite) city.getSprite(SpriteKind.COP);
if (copter != null) {
copter.destX = mapX;
copter.destY = mapY;
}
}
city.trfDensity[mapY/2][mapX/2] = z;
city.addTraffic(mapX, mapY, 50);
}
}
}