refactor: move makeTraffic() from city to zone-behavior class
git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@875 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
ff84c48091
commit
280126ac05
3 changed files with 31 additions and 32 deletions
|
@ -11,7 +11,7 @@ package micropolisj.engine;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static micropolisj.engine.TileConstants.*;
|
import static micropolisj.engine.TileConstants.*;
|
||||||
import static micropolisj.engine.Micropolis.ZoneType;
|
import static micropolisj.engine.TrafficGen.ZoneType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process individual tiles of the map for each cycle.
|
* Process individual tiles of the map for each cycle.
|
||||||
|
@ -21,11 +21,13 @@ import static micropolisj.engine.Micropolis.ZoneType;
|
||||||
class MapScanner extends TileBehavior
|
class MapScanner extends TileBehavior
|
||||||
{
|
{
|
||||||
final B behavior;
|
final B behavior;
|
||||||
|
TrafficGen traffic;
|
||||||
|
|
||||||
MapScanner(Micropolis city, B behavior)
|
MapScanner(Micropolis city, B behavior)
|
||||||
{
|
{
|
||||||
super(city);
|
super(city);
|
||||||
this.behavior = behavior;
|
this.behavior = behavior;
|
||||||
|
this.traffic = new TrafficGen(city);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum B
|
public static enum B
|
||||||
|
@ -220,9 +222,9 @@ class MapScanner extends TileBehavior
|
||||||
z = city.fireEffect/2; // from the funding ratio
|
z = city.fireEffect/2; // from the funding ratio
|
||||||
}
|
}
|
||||||
|
|
||||||
city.traffic.mapX = xpos;
|
traffic.mapX = xpos;
|
||||||
city.traffic.mapY = ypos;
|
traffic.mapY = ypos;
|
||||||
if (!city.traffic.findPerimeterRoad()) {
|
if (!traffic.findPerimeterRoad()) {
|
||||||
z /= 2;
|
z /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,9 +246,9 @@ class MapScanner extends TileBehavior
|
||||||
z = city.policeEffect / 2;
|
z = city.policeEffect / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
city.traffic.mapX = xpos;
|
traffic.mapX = xpos;
|
||||||
city.traffic.mapY = ypos;
|
traffic.mapY = ypos;
|
||||||
if (!city.traffic.findPerimeterRoad()) {
|
if (!traffic.findPerimeterRoad()) {
|
||||||
z /= 2;
|
z /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,7 +432,7 @@ class MapScanner extends TileBehavior
|
||||||
int trafficGood;
|
int trafficGood;
|
||||||
if (tpop > PRNG.nextInt(6))
|
if (tpop > PRNG.nextInt(6))
|
||||||
{
|
{
|
||||||
trafficGood = city.makeTraffic(xpos, ypos, ZoneType.COMMERCIAL);
|
trafficGood = makeTraffic(ZoneType.COMMERCIAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -484,7 +486,7 @@ class MapScanner extends TileBehavior
|
||||||
int trafficGood;
|
int trafficGood;
|
||||||
if (tpop > PRNG.nextInt(6))
|
if (tpop > PRNG.nextInt(6))
|
||||||
{
|
{
|
||||||
trafficGood = city.makeTraffic(xpos, ypos, ZoneType.INDUSTRIAL);
|
trafficGood = makeTraffic(ZoneType.INDUSTRIAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -545,7 +547,7 @@ class MapScanner extends TileBehavior
|
||||||
int trafficGood;
|
int trafficGood;
|
||||||
if (tpop > PRNG.nextInt(36))
|
if (tpop > PRNG.nextInt(36))
|
||||||
{
|
{
|
||||||
trafficGood = city.makeTraffic(xpos, ypos, ZoneType.RESIDENTIAL);
|
trafficGood = makeTraffic(ZoneType.RESIDENTIAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -949,4 +951,14 @@ class MapScanner extends TileBehavior
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 1 if traffic "passed", 0 if traffic "failed", -1 if no roads found
|
||||||
|
*/
|
||||||
|
int makeTraffic(ZoneType zoneType)
|
||||||
|
{
|
||||||
|
traffic.mapX = xpos;
|
||||||
|
traffic.mapY = ypos;
|
||||||
|
traffic.sourceZone = zoneType;
|
||||||
|
return traffic.makeTraffic();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1813,27 +1813,6 @@ public class Micropolis
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The three main types of zones found in Micropolis.
|
|
||||||
*/
|
|
||||||
static enum ZoneType
|
|
||||||
{
|
|
||||||
RESIDENTIAL, COMMERCIAL, INDUSTRIAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
TrafficGen traffic = new TrafficGen(this);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return 1 if traffic "passed", 0 if traffic "failed", -1 if no roads found
|
|
||||||
*/
|
|
||||||
int makeTraffic(int xpos, int ypos, ZoneType zoneType)
|
|
||||||
{
|
|
||||||
traffic.mapX = xpos;
|
|
||||||
traffic.mapY = ypos;
|
|
||||||
traffic.sourceZone = zoneType;
|
|
||||||
return traffic.makeTraffic();
|
|
||||||
}
|
|
||||||
|
|
||||||
int getPopulationDensity(int xpos, int ypos)
|
int getPopulationDensity(int xpos, int ypos)
|
||||||
{
|
{
|
||||||
return popDensity[ypos/2][xpos/2];
|
return popDensity[ypos/2][xpos/2];
|
||||||
|
|
|
@ -19,7 +19,7 @@ class TrafficGen
|
||||||
final Micropolis city;
|
final Micropolis city;
|
||||||
int mapX;
|
int mapX;
|
||||||
int mapY;
|
int mapY;
|
||||||
Micropolis.ZoneType sourceZone;
|
ZoneType sourceZone;
|
||||||
|
|
||||||
int lastdir;
|
int lastdir;
|
||||||
Stack<CityLocation> positions = new Stack<CityLocation>();
|
Stack<CityLocation> positions = new Stack<CityLocation>();
|
||||||
|
@ -221,4 +221,12 @@ class TrafficGen
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The three main types of zones found in Micropolis.
|
||||||
|
*/
|
||||||
|
static enum ZoneType
|
||||||
|
{
|
||||||
|
RESIDENTIAL, COMMERCIAL, INDUSTRIAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue