Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
TileConstants.java
Go to the documentation of this file.
1 // This file is part of MicropolisJ.
2 // Copyright (C) 2013 Jason Long
3 // Portions Copyright (C) 1989-2007 Electronic Arts Inc.
4 //
5 // MicropolisJ is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU GPLv3, with additional terms.
7 // See the README file, included in this distribution, for details.
8 
9 package micropolisj.engine;
10 
11 
35 public class TileConstants {
36  //
37  // terrain mapping
38  //
39  public static final short CLEAR = -1;
40  public static final char DIRT = 0;
41  static final char RIVER = 2;
42  static final char REDGE = 3;
43  static final char CHANNEL = 4;
44  static final char RIVEDGE = 5;
45  static final char FIRSTRIVEDGE = 5;
46  static final char LASTRIVEDGE = 20;
47  static final char TREEBASE = 21;
48  static final char WOODS_LOW = TREEBASE;
49  static final char WOODS = 37;
50  static final char WOODS_HIGH = 39;
51  static final char WOODS2 = 40;
52  static final char WOODS5 = 43;
53  static final char RUBBLE = 44;
54  static final char LASTRUBBLE = 47;
55  static final char FLOOD = 48;
56  static final char LASTFLOOD = 51;
57  static final char RADTILE = 52;
58  static final char FIRE = 56;
59  static final char ROADBASE = 64;
60  static final char HBRIDGE = 64;
61  static final char VBRIDGE = 65;
62  static final char ROADS = 66;
63  static final char ROADS2 = 67;
64  // used in array below
65  private static final char ROADS3 = 68;
66  private static final char ROADS4 = 69;
67  private static final char ROADS5 = 70;
68  private static final char ROADS6 = 71;
69  private static final char ROADS7 = 72;
70  private static final char ROADS8 = 73;
71  private static final char ROADS9 = 74;
72  private static final char ROADS10 = 75;
73  static final char INTERSECTION = 76;
74  static final char HROADPOWER = 77;
75  static final char VROADPOWER = 78;
76  static final char BRWH = 79; // horz bridge, open
77  static final char LTRFBASE = 80;
78  static final char BRWV = 95; // vert bridge, open
79  static final char HTRFBASE = 144;
80  private static final char LASTROAD = 206;
81  static final char POWERBASE = 208;
82  static final char HPOWER = 208; // underwater power-line
83  static final char VPOWER = 209;
84  static final char LHPOWER = 210;
85  static final char LVPOWER = 211;
86  static final char LVPOWER2 = 212;
87  // used in array below
88  private static final char LVPOWER3 = 213;
89  private static final char LVPOWER4 = 214;
90  private static final char LVPOWER5 = 215;
91  private static final char LVPOWER6 = 216;
92  private static final char LVPOWER7 = 217;
93  private static final char LVPOWER8 = 218;
94  private static final char LVPOWER9 = 219;
95  private static final char LVPOWER10 = 220;
96  static final char RAILHPOWERV = 221;
97  static final char RAILVPOWERH = 222;
98  static final char LASTPOWER = 222;
99  static final char RAILBASE = 224;
100  static final char HRAIL = 224; // underwater rail (horz)
101  static final char VRAIL = 225; // underwater rail (vert)
102  static final char LHRAIL = 226;
103  static final char LVRAIL = 227;
104  static final char LVRAIL2 = 228;
105  // used in array below
106  private static final char LVRAIL3 = 229;
107  private static final char LVRAIL4 = 230;
108  private static final char LVRAIL5 = 231;
109  private static final char LVRAIL6 = 232;
110  private static final char LVRAIL7 = 233;
111  private static final char LVRAIL8 = 234;
112  private static final char LVRAIL9 = 235;
113  private static final char LVRAIL10 = 236;
114  static final char HRAILROAD = 237;
115  static final char VRAILROAD = 238;
116  static final char LASTRAIL = 238;
117  static final char RESBASE = 240;
118  static final char RESCLR = 244;
119  static final char HOUSE = 249;
120  static final char LHTHR = 249; // 12 house tiles
121  static final char HHTHR = 260;
122  static final char RZB = 265; // residential zone base
123  static final char HOSPITAL = 409;
124  static final char CHURCH = 418;
125  static final char COMBASE = 423;
126  static final char COMCLR = 427;
127  static final char CZB = 436; // commercial zone base
128  static final char INDBASE = 612;
129  static final char INDCLR = 616;
130  static final char IZB = 625;
131  static final char PORTBASE = 693;
132  static final char PORT = 698;
133  static final char AIRPORT = 716;
134  static final char POWERPLANT = 750;
135  static final char FIRESTATION = 765;
136  static final char POLICESTATION = 774;
137  static final char STADIUM = 784;
138  static final char FULLSTADIUM = 800;
139  static final char NUCLEAR = 816;
140  static final char LASTZONE = 826;
141  public static final char LIGHTNINGBOLT = 827;
142  static final char HBRDG0 = 828; // draw bridge tiles (horz)
143  static final char HBRDG1 = 829;
144  static final char HBRDG2 = 830;
145  static final char HBRDG3 = 831;
146  static final char FOUNTAIN = 840;
147  static final char TINYEXP = 860;
148  private static final char LASTTINYEXP = 867;
149  static final char FOOTBALLGAME1 = 932;
150  static final char FOOTBALLGAME2 = 940;
151  static final char VBRDG0 = 948; // draw bridge tiles (vert)
152  static final char VBRDG1 = 949;
153  static final char VBRDG2 = 950;
154  static final char VBRDG3 = 951;
155 
156  //CUSTOM TILES FOR CUSTOM TOOLS
157  static final char UNIVERSITY = 964;
158  static final char TEMPEL = 976;
159  public static final char LAST_TILE = 1005;
160 
161  // TODO COMMENT where the order in these arrays comes from
162  static final char[] RoadTable = new char[] {
163  ROADS, ROADS2, ROADS, ROADS3, ROADS2, ROADS2, ROADS4, ROADS8, ROADS, ROADS6, ROADS, ROADS7, ROADS5, ROADS10, ROADS9,
164  INTERSECTION
165  };
166 
167  static final char[] RailTable = new char[] {
168  LHRAIL, LVRAIL, LHRAIL, LVRAIL2, LVRAIL, LVRAIL, LVRAIL3, LVRAIL7, LHRAIL, LVRAIL5, LHRAIL, LVRAIL6, LVRAIL4,
170  };
171 
172  static final char[] WireTable = new char[] {
173  LHPOWER, LVPOWER, LHPOWER, LVPOWER2, LVPOWER, LVPOWER, LVPOWER3, LVPOWER7, LHPOWER, LVPOWER5, LHPOWER, LVPOWER6,
175  };
176 
177  //
178  // status bits
179  //
180  public static final char PWRBIT = 32768; // bit 15 ... currently powered
181 // bit 14 ... - playerID
182 // bit 13 ... - playerID
183 // bit 12 ... - playerID
184 // bit 11 ... unused
185 // bit 10 ... unused
186 
187  public static final char ALLBITS = 64512; // mask for upper 6 bits
188  public static final char LOMASK = 1023; // mask for low 10 bits
189 
190  private TileConstants() {
191  }
192 
197  public static boolean canAutoBulldozeRRW(int tileValue) {
198  // can we autobulldoze this tile?
199  return ((tileValue >= FIRSTRIVEDGE && tileValue <= LASTRUBBLE) || (tileValue >= TINYEXP && tileValue <= LASTTINYEXP));
200  }
201 
205  public static boolean canAutoBulldozeZ(char tileValue) {
206  // FIXME- what is significance of POWERBASE+2 and POWERBASE+12 ?
207 
208  // can we autobulldoze this tile?
209  // TODO: check if the following could replace this function
210  //return ((tileValue >= FIRSTRIVEDGE && tileValue <= LASTRUBBLE) || (tileValue >= POWERBASE && tileValue <= LASTPOWER)
211  // || (tileValue >= TINYEXP && tileValue <= LASTTINYEXP));
212  if((tileValue >= FIRSTRIVEDGE && tileValue <= LASTRUBBLE) || (tileValue >= POWERBASE + 2 && tileValue <= POWERBASE + 12)
213  || (tileValue >= TINYEXP && tileValue <= LASTTINYEXP)) {
214  return true;
215  }
216  else {
217  return false;
218  }
219  }
220 
221  // used by scanTile
222  public static String getTileBehavior(int tile) {
223  assert (tile & LOMASK) == tile;
224 
225  TileSpec ts = Tiles.get(tile);
226  return ts != null ? ts.getAttribute("behavior") : null;
227  }
228 
229  // used by queryZoneStatus
230  public static int getDescriptionNumber(int tile) {
231  assert (tile & LOMASK) == tile;
232 
233  TileSpec ts = Tiles.get(tile);
234  if(ts != null) {
235  return ts.getDescriptionNumber();
236  }
237  else {
238  return -1;
239  }
240  }
241 
242  public static int getPollutionValue(int tile, Micropolis city) {
243  assert (tile & LOMASK) == tile;
244 
245  TileSpec spec = Tiles.get(tile);
246  return spec != null ? spec.getPollutionValue(city) : 0;
247  }
248 
249  public static boolean isAnimated(int tile) {
250  assert (tile & LOMASK) == tile;
251 
252  TileSpec spec = Tiles.get(tile);
253  return spec != null && spec.animNext != null;
254  }
255 
256  // used by setFire()
257  public static boolean isArsonable(int tile) {
258  assert (tile & LOMASK) == tile;
259 
260  return (!isZoneCenter(tile) && tile >= LHTHR && tile <= LASTZONE);
261  }
262 
263  // used by Sprite::destroyTile
264  public static boolean isBridge(int tile) {
265  return isRoad(tile) && !isCombustible(tile);
266  }
267 
268  public static boolean isCombustible(int tile) {
269  assert (tile & LOMASK) == tile;
270 
271  TileSpec spec = Tiles.get(tile);
272  return spec != null && spec.canBurn;
273  }
274 
275  public static boolean isConductive(int tile) {
276  assert (tile & LOMASK) == tile;
277 
278  TileSpec spec = Tiles.get(tile);
279  return spec != null && spec.canConduct;
280  }
281 
283  public static boolean isIndestructible(int tile) {
284  assert (tile & LOMASK) == tile;
285 
286  return tile >= RUBBLE && tile < ROADBASE;
287  }
288 
290  public static boolean isIndestructible2(int tile) {
291  assert (tile & LOMASK) == tile;
292 
293  return tile >= FLOOD && tile < ROADBASE;
294  }
295 
296  public static boolean isOverWater(int tile) {
297  assert (tile & LOMASK) == tile;
298 
299  TileSpec spec = Tiles.get(tile);
300  return spec != null && spec.overWater;
301  }
302 
303  public static boolean isRubble(int tile) {
304  assert (tile & LOMASK) == tile;
305 
306  return ((tile >= RUBBLE) && (tile <= LASTRUBBLE));
307  }
308 
309  public static boolean isTree(char tile) {
310  assert (tile & LOMASK) == tile;
311 
312  return ((tile >= WOODS_LOW) && (tile <= WOODS_HIGH));
313  }
314 
315  // used by makeEarthquake
316  public static boolean isVulnerable(int tile) {
317  assert (tile & LOMASK) == tile;
318 
319  if(tile < RESBASE || tile > LASTZONE || isZoneCenter(tile)) {
320  return false;
321  }
322  else {
323  return true;
324  }
325  }
326 
327  public static boolean checkWet(int tile) {
328  assert (tile & LOMASK) == tile;
329 
330  return (tile == POWERBASE || tile == POWERBASE + 1 || tile == RAILBASE || tile == RAILBASE + 1 || tile == BRWH || tile == BRWV);
331  }
332 
333  public static CityDimension getZoneSizeFor(int tile) {
334  assert isZoneCenter(tile);
335  assert (tile & LOMASK) == tile;
336 
337  TileSpec spec = Tiles.get(tile);
338  return spec != null ? spec.getBuildingSize() : null;
339  }
340 
341  public static boolean isConstructed(int tile) {
342  assert (tile & LOMASK) == tile;
343 
344  return tile >= 0 && tile >= ROADBASE;
345  }
346 
347  static boolean isRiverEdge(int tile) {
348  assert (tile & LOMASK) == tile;
349 
350  return tile >= FIRSTRIVEDGE && tile <= LASTRIVEDGE;
351  }
352 
353  public static boolean isDozeable(int tile) {
354  assert (tile & LOMASK) == tile;
355 
356  TileSpec spec = Tiles.get(tile);
357  return spec != null && spec.canBulldoze;
358  }
359 
360  static boolean isFloodable(int tile) {
361  assert (tile & LOMASK) == tile;
362 
363  return (tile == DIRT || (isDozeable(tile) && isCombustible(tile)));
364  }
365 
371  public static boolean isRoad(int tile) {
372  assert (tile & LOMASK) == tile;
373 
374  return (tile >= ROADBASE && tile < POWERBASE);
375  }
376 
377  public static boolean isRoadAny(int tile) {
378  assert (tile & LOMASK) == tile;
379 
380  return (tile >= ROADBASE && tile < POWERBASE) || (tile == HRAILROAD) || (tile == VRAILROAD);
381  }
382 
387  public static boolean isRoadDynamic(int tile) {
388  int tmp = neutralizeRoad(tile);
389  return (tmp >= ROADS && tmp <= INTERSECTION);
390  }
391 
392  public static boolean roadConnectsEast(int tile) {
393  tile = neutralizeRoad(tile);
394  return (((tile == VRAILROAD) || (tile >= ROADBASE && tile <= VROADPOWER)) && (tile != VROADPOWER) && (tile != HRAILROAD) && (tile != VBRIDGE));
395  }
396 
397  public static boolean roadConnectsNorth(int tile) {
398  tile = neutralizeRoad(tile);
399  return (((tile == HRAILROAD) || (tile >= ROADBASE && tile <= VROADPOWER)) && (tile != HROADPOWER) && (tile != VRAILROAD) && (tile != ROADBASE));
400  }
401 
402  public static boolean roadConnectsSouth(int tile) {
403  tile = neutralizeRoad(tile);
404  return (((tile == HRAILROAD) || (tile >= ROADBASE && tile <= VROADPOWER)) && (tile != HROADPOWER) && (tile != VRAILROAD) && (tile != ROADBASE));
405  }
406 
407  public static boolean roadConnectsWest(int tile) {
408  tile = neutralizeRoad(tile);
409  return (((tile == VRAILROAD) || (tile >= ROADBASE && tile <= VROADPOWER)) && (tile != VROADPOWER) && (tile != HRAILROAD) && (tile != VBRIDGE));
410  }
411 
412  public static boolean isRail(int tile) {
413  assert (tile & LOMASK) == tile;
414 
415  return (tile >= RAILBASE && tile < RESBASE);
416  }
417 
418  public static boolean isRailAny(int tile) {
419  assert (tile & LOMASK) == tile;
420 
421  return (tile >= RAILBASE && tile < RESBASE) || (tile == RAILHPOWERV) || (tile == RAILVPOWERH);
422  }
423 
424  public static boolean isRailDynamic(int tile) {
425  assert (tile & LOMASK) == tile;
426 
427  return (tile >= LHRAIL && tile <= LVRAIL10);
428  }
429 
430  public static boolean railConnectsEast(int tile) {
431  tile = neutralizeRoad(tile);
432  return (tile >= RAILHPOWERV && tile <= VRAILROAD && tile != RAILVPOWERH && tile != VRAILROAD && tile != VRAIL);
433  }
434 
435  public static boolean railConnectsNorth(int tile) {
436  tile = neutralizeRoad(tile);
437  return (tile >= RAILHPOWERV && tile <= VRAILROAD && tile != RAILHPOWERV && tile != HRAILROAD && tile != HRAIL);
438  }
439 
440  public static boolean railConnectsSouth(int tile) {
441  tile = neutralizeRoad(tile);
442  return (tile >= RAILHPOWERV && tile <= VRAILROAD && tile != RAILHPOWERV && tile != HRAILROAD && tile != HRAIL);
443  }
444 
445  public static boolean railConnectsWest(int tile) {
446  tile = neutralizeRoad(tile);
447  return (tile >= RAILHPOWERV && tile <= VRAILROAD && tile != RAILVPOWERH && tile != VRAILROAD && tile != VRAIL);
448  }
449 
450  public static boolean isWireDynamic(int tile) {
451  assert (tile & LOMASK) == tile;
452 
453  return (tile >= LHPOWER && tile <= LVPOWER10);
454  }
455 
456  public static boolean wireConnectsEast(int tile) {
457  int ntile = neutralizeRoad(tile);
458  return (isConductive(tile) && ntile != HPOWER && ntile != HROADPOWER && ntile != RAILHPOWERV);
459  }
460 
461  public static boolean wireConnectsNorth(int tile) {
462  int ntile = neutralizeRoad(tile);
463  return (isConductive(tile) && ntile != VPOWER && ntile != VROADPOWER && ntile != RAILVPOWERH);
464  }
465 
466  public static boolean wireConnectsSouth(int tile) {
467  int ntile = neutralizeRoad(tile);
468  return (isConductive(tile) && ntile != VPOWER && ntile != VROADPOWER && ntile != RAILVPOWERH);
469  }
470 
471  public static boolean wireConnectsWest(int tile) {
472  int ntile = neutralizeRoad(tile);
473  return (isConductive(tile) && ntile != HPOWER && ntile != HROADPOWER && ntile != RAILHPOWERV);
474  }
475 
476  public static boolean isCommercialZone(int tile) {
477  assert (tile & LOMASK) == tile;
478 
479  TileSpec ts = Tiles.get(tile);
480  if(ts != null) {
481  if(ts.owner != null) {
482  ts = ts.owner;
483  }
484  return ts.getBooleanAttribute("commercial-zone");
485  }
486  return false;
487  }
488 
489  public static boolean isHospitalOrChurch(int tile) {
490  assert (tile & LOMASK) == tile;
491 
492  return tile >= HOSPITAL && tile < COMBASE;
493  }
494 
500  public static boolean isIndustrialZone(int tile) {
501  assert (tile & LOMASK) == tile;
502 
503  TileSpec ts = Tiles.get(tile);
504  if(ts != null) {
505  if(ts.owner != null) {
506  ts = ts.owner;
507  }
508  return ts.getBooleanAttribute("industrial-zone");
509  }
510  return false;
511  }
512 
513  public static boolean isResidentialClear(int tile) {
514  assert (tile & LOMASK) == tile;
515 
516  return tile >= RESBASE && tile <= RESBASE + 8;
517  }
518 
524  public static boolean isResidentialZone(int tile) {
525  assert (tile & LOMASK) == tile;
526 
527  return tile >= RESBASE && tile < HOSPITAL;
528  }
529 
530  // includes hospital/church.
531  public static boolean isResidentialZoneAny(int tile) {
532  assert (tile & LOMASK) == tile;
533 
534  TileSpec ts = Tiles.get(tile);
535  if(ts != null) {
536  if(ts.owner != null) {
537  ts = ts.owner;
538  }
539  return ts.getBooleanAttribute("residential-zone");
540  }
541  return false;
542  }
543 
545  public static boolean isZoneAny(int tile) {
546  assert (tile & LOMASK) == tile;
547 
548  return tile >= RESBASE;
549  }
550 
551  public static boolean isZoneCenter(int tile) {
552  assert (tile & LOMASK) == tile;
553 
554  TileSpec spec = Tiles.get(tile);
555  return spec != null && spec.zone;
556  }
557 
562  public static char neutralizeRoad(int tile) {
563  assert (tile & LOMASK) == tile;
564 
565  if(tile >= ROADBASE && tile <= LASTROAD) {
566  tile = ((tile - ROADBASE) & 0xf) + ROADBASE;
567  }
568  return (char) tile;
569  }
570 
577  public static int residentialZonePop(int tile) {
578  assert (tile & LOMASK) == tile;
579 
580  TileSpec ts = Tiles.get(tile);
581  return ts.getPopulation();
582  }
583 
590  public static int commercialZonePop(int tile) {
591  assert (tile & LOMASK) == tile;
592 
593  TileSpec ts = Tiles.get(tile);
594  return ts.getPopulation() / 8;
595  }
596 
603  public static int industrialZonePop(int tile) {
604  assert (tile & LOMASK) == tile;
605 
606  TileSpec ts = Tiles.get(tile);
607  return ts.getPopulation() / 8;
608  }
609 }