TrafficGen: s/engine/city for consistency with MapScanner class

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@563 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-02-20 01:36:43 +00:00
parent fb2f73c008
commit d21f73e186

View file

@ -11,9 +11,12 @@ package micropolisj.engine;
import java.util.*; import java.util.*;
import static micropolisj.engine.TileConstants.*; import static micropolisj.engine.TileConstants.*;
/**
* Contains the code for generating city traffic.
*/
class TrafficGen class TrafficGen
{ {
Micropolis engine; final Micropolis city;
int mapX; int mapX;
int mapY; int mapY;
Micropolis.ZoneType sourceZone; Micropolis.ZoneType sourceZone;
@ -23,9 +26,9 @@ class TrafficGen
static final int MAX_TRAFFIC_DISTANCE = 30; static final int MAX_TRAFFIC_DISTANCE = 30;
public TrafficGen(Micropolis engine) public TrafficGen(Micropolis city)
{ {
this.engine = engine; this.city = city;
} }
int makeTraffic() int makeTraffic()
@ -55,33 +58,33 @@ class TrafficGen
CityLocation pos = positions.pop(); CityLocation pos = positions.pop();
mapX = pos.x; mapX = pos.x;
mapY = pos.y; mapY = pos.y;
assert engine.testBounds(mapX, mapY); assert city.testBounds(mapX, mapY);
int tile = engine.getTile(mapX, mapY) & LOMASK; int tile = city.getTile(mapX, mapY) & LOMASK;
if (tile >= ROADBASE && tile < POWERBASE) if (tile >= ROADBASE && tile < POWERBASE)
{ {
// check for rail // check for rail
int z = engine.trfDensity[mapY/2][mapX/2]; int z = city.trfDensity[mapY/2][mapX/2];
z += 50; z += 50;
//FIXME- why is this only capped to 240 //FIXME- why is this only capped to 240
// by random chance. why is there no cap // by random chance. why is there no cap
// the rest of the time? // the rest of the time?
if (z > 240 && engine.PRNG.nextInt(6) == 0) if (z > 240 && city.PRNG.nextInt(6) == 0)
{ {
z = 240; z = 240;
engine.trafficMaxLocationX = mapX; city.trafficMaxLocationX = mapX;
engine.trafficMaxLocationY = mapY; city.trafficMaxLocationY = mapY;
HelicopterSprite copter = (HelicopterSprite) engine.getSprite(SpriteKind.COP); HelicopterSprite copter = (HelicopterSprite) city.getSprite(SpriteKind.COP);
if (copter != null) { if (copter != null) {
copter.destX = mapX; copter.destX = mapX;
copter.destY = mapY; copter.destY = mapY;
} }
} }
engine.trfDensity[mapY/2][mapX/2] = z; city.trfDensity[mapY/2][mapX/2] = z;
} }
} }
} }
@ -95,7 +98,7 @@ class TrafficGen
int tx = mapX + PerimX[z]; int tx = mapX + PerimX[z];
int ty = mapY + PerimY[z]; int ty = mapY + PerimY[z];
if (engine.testBounds(tx, ty) if (city.testBounds(tx, ty)
&& roadTest(tx, ty)) && roadTest(tx, ty))
{ {
mapX = tx; mapX = tx;
@ -108,7 +111,7 @@ class TrafficGen
boolean roadTest(int tx, int ty) boolean roadTest(int tx, int ty)
{ {
char c = engine.getTile(tx, ty); char c = city.getTile(tx, ty);
c &= LOMASK; c &= LOMASK;
if (c < ROADBASE) if (c < ROADBASE)
@ -161,7 +164,7 @@ class TrafficGen
boolean tryGo(int z) boolean tryGo(int z)
{ {
// random starting direction // random starting direction
int rdir = engine.PRNG.nextInt(4); int rdir = city.PRNG.nextInt(4);
for (int d = rdir; d < rdir + 4; d++) for (int d = rdir; d < rdir + 4; d++)
{ {
@ -211,25 +214,25 @@ class TrafficGen
if (mapY > 0) if (mapY > 0)
{ {
int tile = engine.getTile(mapX, mapY-1) & LOMASK; int tile = city.getTile(mapX, mapY-1) & LOMASK;
if (tile >= low && tile <= high) if (tile >= low && tile <= high)
return true; return true;
} }
if (mapX + 1 < engine.getWidth()) if (mapX + 1 < city.getWidth())
{ {
int tile = engine.getTile(mapX + 1, mapY) & LOMASK; int tile = city.getTile(mapX + 1, mapY) & LOMASK;
if (tile >= low && tile <= high) if (tile >= low && tile <= high)
return true; return true;
} }
if (mapY + 1 < engine.getHeight()) if (mapY + 1 < city.getHeight())
{ {
int tile = engine.getTile(mapX, mapY + 1) & LOMASK; int tile = city.getTile(mapX, mapY + 1) & LOMASK;
if (tile >= low && tile <= high) if (tile >= low && tile <= high)
return true; return true;
} }
if (mapX > 0) if (mapX > 0)
{ {
int tile = engine.getTile(mapX - 1, mapY) & LOMASK; int tile = city.getTile(mapX - 1, mapY) & LOMASK;
if (tile >= low && tile <= high) if (tile >= low && tile <= high)
return true; return true;
} }