2013-05-16 23:41:40 +00:00
|
|
|
package micropolisj.engine;
|
|
|
|
|
|
|
|
import java.awt.Rectangle;
|
|
|
|
import static micropolisj.engine.TileConstants.*;
|
|
|
|
|
|
|
|
class Bulldozer extends ToolStroke
|
|
|
|
{
|
|
|
|
Bulldozer(Micropolis city, int xpos, int ypos)
|
|
|
|
{
|
|
|
|
super(city, MicropolisTool.BULLDOZER, xpos, ypos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-16 23:45:35 +00:00
|
|
|
protected void applyArea(ToolEffectIfc eff)
|
2013-05-16 23:41:40 +00:00
|
|
|
{
|
|
|
|
Rectangle b = getBounds();
|
|
|
|
|
2013-05-16 23:44:54 +00:00
|
|
|
// scan selection area for rubble, forest, etc...
|
|
|
|
for (int y = 0; y < b.height; y++) {
|
|
|
|
for (int x = 0; x < b.width; x++) {
|
2013-05-16 23:41:40 +00:00
|
|
|
|
2013-05-16 23:45:59 +00:00
|
|
|
int tile = eff.getTile(b.x+x, b.y+y);
|
2013-05-16 23:44:54 +00:00
|
|
|
if (isDozeable(tile) && !isZoneCenter(tile)) {
|
2013-05-16 23:41:40 +00:00
|
|
|
|
2013-05-16 23:45:35 +00:00
|
|
|
dozeField(new TranslatedToolEffect(eff, b.x+x, b.y+y));
|
2013-05-16 23:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-16 23:44:54 +00:00
|
|
|
// scan selection area for zones...
|
|
|
|
for (int y = 0; y < b.height; y++) {
|
|
|
|
for (int x = 0; x < b.width; x++) {
|
2013-05-16 23:41:40 +00:00
|
|
|
|
2013-05-16 23:45:59 +00:00
|
|
|
if (isZoneCenter(eff.getTile(b.x+x,b.y+y))) {
|
2013-05-16 23:45:35 +00:00
|
|
|
dozeZone(new TranslatedToolEffect(eff, b.x+x, b.y+y));
|
2013-05-16 23:41:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-16 23:44:54 +00:00
|
|
|
void dozeZone(ToolEffectIfc eff)
|
2013-05-16 23:41:40 +00:00
|
|
|
{
|
2013-05-16 23:44:54 +00:00
|
|
|
int currTile = eff.getTile(0, 0);
|
2013-05-16 23:41:40 +00:00
|
|
|
|
|
|
|
// zone center bit is set
|
|
|
|
assert isZoneCenter(currTile);
|
|
|
|
|
2013-09-05 11:22:56 +00:00
|
|
|
CityDimension dim = getZoneSizeFor(currTile);
|
|
|
|
assert dim != null;
|
|
|
|
assert dim.width >= 3;
|
|
|
|
assert dim.height >= 3;
|
|
|
|
|
2013-05-16 23:44:54 +00:00
|
|
|
eff.spend(1);
|
2013-09-05 11:22:56 +00:00
|
|
|
|
|
|
|
// make explosion sound;
|
|
|
|
// bigger zones => bigger explosions
|
|
|
|
|
|
|
|
if (dim.width * dim.height < 16) {
|
2013-05-16 23:44:54 +00:00
|
|
|
eff.makeSound(0, 0, Sound.EXPLOSION_HIGH);
|
2013-09-05 11:22:56 +00:00
|
|
|
}
|
|
|
|
else if (dim.width * dim.height < 36) {
|
2013-05-16 23:44:54 +00:00
|
|
|
eff.makeSound(0, 0, Sound.EXPLOSION_LOW);
|
2013-09-05 11:22:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-05-16 23:44:54 +00:00
|
|
|
eff.makeSound(0, 0, Sound.EXPLOSION_BOTH);
|
2013-05-16 23:41:40 +00:00
|
|
|
}
|
2013-09-05 11:22:56 +00:00
|
|
|
|
|
|
|
putRubble(new TranslatedToolEffect(eff, -1, -1), dim.width, dim.height);
|
2013-05-16 23:44:54 +00:00
|
|
|
return;
|
2013-05-16 23:41:40 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 23:44:54 +00:00
|
|
|
void dozeField(ToolEffectIfc eff)
|
2013-05-16 23:41:40 +00:00
|
|
|
{
|
2013-05-16 23:44:54 +00:00
|
|
|
int tile = eff.getTile(0, 0);
|
2013-05-16 23:41:40 +00:00
|
|
|
|
|
|
|
// check dozeable bit
|
|
|
|
assert isDozeable(tile);
|
|
|
|
|
2013-05-28 01:55:25 +00:00
|
|
|
if (isOverWater(tile))
|
2013-05-16 23:41:40 +00:00
|
|
|
{
|
|
|
|
// dozing over water, replace with water.
|
2013-05-16 23:44:54 +00:00
|
|
|
eff.setTile(0, 0, RIVER);
|
2013-05-16 23:41:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// dozing on land, replace with land. Simple, eh?
|
2013-05-16 23:44:54 +00:00
|
|
|
eff.setTile(0, 0, DIRT);
|
2013-05-16 23:41:40 +00:00
|
|
|
}
|
|
|
|
|
2013-07-22 16:03:33 +00:00
|
|
|
fixZone(eff);
|
2013-05-16 23:44:54 +00:00
|
|
|
eff.spend(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void putRubble(ToolEffectIfc eff, int w, int h)
|
|
|
|
{
|
|
|
|
for (int yy = 0; yy < h; yy++) {
|
|
|
|
for (int xx = 0; xx < w; xx++) {
|
|
|
|
int tile = eff.getTile(xx,yy);
|
|
|
|
if (tile == CLEAR)
|
|
|
|
continue;
|
|
|
|
tile = tile & LOMASK;
|
|
|
|
if (tile != RADTILE && tile != DIRT) {
|
2013-05-16 23:46:09 +00:00
|
|
|
int z = inPreview ? 0 : city.PRNG.nextInt(3);
|
2013-07-17 20:59:06 +00:00
|
|
|
int nTile = (TINYEXP + z) | BULLBIT;
|
2013-05-16 23:44:54 +00:00
|
|
|
eff.setTile(xx, yy, nTile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-22 16:03:33 +00:00
|
|
|
fixBorder(eff, w, h);
|
2013-05-16 23:41:40 +00:00
|
|
|
}
|
|
|
|
}
|