9 package micropolisj.engine;
11 import static micropolisj.engine.TileConstants.*;
12 import micropolisj.util.Utilities;
14 class TerrainBehavior
extends TileBehavior {
17 TerrainBehavior(Micropolis city, B behavior) {
19 this.behavior = behavior;
23 FIRE, FLOOD, RADIOACTIVE, ROAD, RAIL, EXPLOSION;
56 if(
PRNG.nextInt(4) != 0) {
67 for(
int dir = 0; dir < 4; dir++) {
68 if(
PRNG.nextInt(8) == 0) {
69 int xtem = xpos + DX[dir];
70 int ytem = ypos + DY[dir];
75 if(isCombustible(c)) {
77 city.killZone(xtem, ytem, c);
79 city.makeExplosion(xtem, ytem);
88 int rate = cov > 100 ? 1 : cov > 20 ? 2 : cov != 0 ? 3 : 10;
90 if(
PRNG.nextInt(rate + 1) == 0) {
106 if(
city.floodCnt != 0) {
107 for(
int z = 0; z < 4; z++) {
108 if(
PRNG.nextInt(8) == 0) {
109 int xx = xpos + DX[z];
110 int yy = ypos + DY[z];
113 if(isCombustible(t) || t == DIRT || (t >= WOODS5 && t < FLOOD)) {
114 if(isZoneCenter(t)) {
115 city.killZone(xx, yy, t);
124 if(
PRNG.nextInt(16) == 0) {
133 void doRadioactiveTile() {
134 if(
PRNG.nextInt(4096) == 0) {
140 static int[] TRAFFIC_DENSITY_TAB = {
141 ROADBASE, LTRFBASE, HTRFBASE
148 int tilePlayerID = Utilities.getPlayerID(rawTile);
153 if(
PRNG.nextInt(512) == 0) {
154 if(!isConductive(tile)) {
156 if(isOverWater(tile))
166 if(!isCombustible(tile))
176 else if(tile < HTRFBASE)
184 int newLevel = trafficDensity < 64 ? 0 : trafficDensity < 192 ? 1 : 2;
186 assert newLevel >= 0 && newLevel < TRAFFIC_DENSITY_TAB.length;
188 if(tden != newLevel) {
189 int z = (((rawTile & LOMASK) - ROADBASE) & 15) + TRAFFIC_DENSITY_TAB[newLevel];
190 z += rawTile & ALLBITS;
200 int tilePlayerID = Utilities.getPlayerID(rawTile);
202 city.generateTrain(xpos, ypos);
205 if(
PRNG.nextInt(512) == 0) {
206 if(!isConductive(tile)) {
208 if(isOverWater(tile)) {
232 -2, 2, -2, -1, 0, 1, 2
235 -1, -1, 0, 0, 0, 0, 0
237 final char HBRTAB[] = {
238 HBRDG1, HBRDG3, HBRDG0, RIVER, BRWH, RIVER, HBRDG2
240 final char HBRTAB2[] = {
241 RIVER, RIVER, HBRIDGE, HBRIDGE, HBRIDGE, HBRIDGE, HBRIDGE
248 -2, -2, -1, 0, 1, 2, 2
250 final char VBRTAB[] = {
251 VBRDG0, VBRDG1, RIVER, BRWV, RIVER, VBRDG2, VBRDG3
253 final char VBRTAB2[] = {
254 VBRIDGE, RIVER, VBRIDGE, VBRIDGE, VBRIDGE, VBRIDGE, RIVER
259 if(
PRNG.nextInt(4) == 0 && getBoatDis() > 340 / 16) {
261 applyBridgeChange(VDx, VDy, VBRTAB, VBRTAB2);
265 else if(tile == BRWH) {
267 if(
PRNG.nextInt(4) == 0 && getBoatDis() > 340 / 16) {
269 applyBridgeChange(HDx, HDy, HBRTAB, HBRTAB2);
274 if(getBoatDis() < 300 / 16 &&
PRNG.nextInt(8) == 0) {
275 if((rawTile & 1) != 0) {
284 applyBridgeChange(VDx, VDy, VBRTAB2, VBRTAB);
299 applyBridgeChange(HDx, HDy, HBRTAB2, HBRTAB);
313 private void applyBridgeChange(
int[] Dx,
int[] Dy,
char[] fromTab,
char[] toTab) {
319 for(
int z = 0; z < 7; z++) {
320 int x = xpos + Dx[z];
321 int y = ypos + Dy[z];
336 if(s.isVisible() && s.kind == SpriteKind.SHI) {
339 int d = Math.abs(xpos - x) + Math.abs(ypos - y);
340 dist = Math.min(d, dist);