Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
Bulldozer.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 import static micropolisj.engine.TileConstants.*;
12 import micropolisj.util.Utilities;
13 
14 class Bulldozer extends ToolStroke {
15 
16  Bulldozer(Micropolis city, int xpos, int ypos) {
17  super(city, MicropolisTool.BULLDOZER, xpos, ypos);
18  }
19 
20  @Override
21  protected void applyArea(ToolEffectIfc eff) {
22  CityRect b = getBounds();
23 
24  // scan selection area for rubble, forest, etc...
25  for (int y = 0; y < b.height; y++) {
26  for (int x = 0; x < b.width; x++) {
27 
28  ToolEffectIfc subEff = new TranslatedToolEffect(eff, b.x + x, b.y + y);
29  if (city.isTileDozeable(subEff)) {
30 
31  dozeField(subEff);
32  }
33 
34  }
35  }
36 
37  // scan selection area for zones...
38  for (int y = 0; y < b.height; y++) {
39  for (int x = 0; x < b.width; x++) {
40 // if (city.isTileDozeable(eff)) {
41  if (isZoneCenter(eff.getTile(b.x + x, b.y + y))) {
42  dozeZone(new TranslatedToolEffect(eff, b.x + x, b.y + y));
43 // }
44  }
45  }
46  }
47  }
48 
49  void dozeZone(ToolEffectIfc eff) {
50 // int currTile = eff.getTile(0, 0);
51  int x = ((TranslatedToolEffect) eff).dx;
52  int y = ((TranslatedToolEffect) eff).dy;
53 // System.out.println(x + " - " + y);
54  int currTile = this.city.getTileRaw(x, y);
55 
56 
57 // System.out.println("dozing Zone");
58 // System.out.println(eff.getPlayerID());
59 // System.out.println(Utilities.getPlayerID(currTile));
60 // System.out.println(currTile);
61 
62 
63 
64  if(eff.getPlayerID() != Utilities.getPlayerID((char)currTile)) {
65  return;
66  }
67 
68  // zone center bit is set
69  assert isZoneCenter(currTile);
70  currTile &= TileConstants.LOMASK;
71 
72  CityDimension dim = getZoneSizeFor(currTile);
73  assert dim != null;
74  assert dim.width >= 3;
75  assert dim.height >= 3;
76 
77  eff.spend(1);
78 
79  // make explosion sound;
80  // bigger zones => bigger explosions
81 
82  if (dim.width * dim.height < 16) {
83  eff.makeSound(0, 0, Sound.EXPLOSION_HIGH);
84  } else if (dim.width * dim.height < 36) {
85  eff.makeSound(0, 0, Sound.EXPLOSION_LOW);
86  } else {
87  eff.makeSound(0, 0, Sound.EXPLOSION_BOTH);
88  }
89 
90  putRubble(new TranslatedToolEffect(eff, -1, -1), dim.width, dim.height);
91  return;
92  }
93 
94  void dozeField(ToolEffectIfc eff) {
95  int tile = eff.getTile(0, 0);
96 
97 // System.out.println("Bulldozing field");
98 // System.out.println(Utilities.getPlayerID((char) tile));
99 
100  if (isOverWater(tile)) {
101  // dozing over water, replace with water.
102  eff.setTile(0, 0, RIVER);
103  } else {
104  // dozing on land, replace with land. Simple, eh?
105  eff.setTile(0, 0, DIRT);
106  }
107 
108  fixZone(eff);
109  eff.spend(1);
110  return;
111  }
112 
113  void putRubble(ToolEffectIfc eff, int w, int h) {
114  for (int yy = 0; yy < h; yy++) {
115  for (int xx = 0; xx < w; xx++) {
116  int tile = eff.getTile(xx, yy);
117  if (tile == CLEAR)
118  continue;
119 
120  if (tile != RADTILE && tile != DIRT) {
121  int z = inPreview ? 0 : city.PRNG.nextInt(3);
122  int nTile = TINYEXP + z;
123  eff.setTile(xx, yy, nTile);
124  }
125  }
126  }
127  fixBorder(eff, w, h);
128  }
129 }