9 package micropolisj.engine;
11 import java.io.Serializable;
13 import javax.swing.JOptionPane;
15 import static micropolisj.engine.TileConstants.*;
16 import micropolisj.research.ResearchState;
17 import micropolisj.util.Utilities;
46 ToolEffect eff =
new ToolEffect(city, playerID);
57 ToolEffect eff =
new ToolEffect(city, playerID);
59 return eff.apply(playerID);
67 apply1(
new TranslatedToolEffect(eff, r.
x + j, r.
y + i));
76 return applyParkTool(eff);
79 return applyZone(eff, RESCLR);
82 return applyZone(eff, COMCLR);
85 return applyZone(eff, INDCLR);
88 return applyZone(eff, FIRESTATION);
91 return applyZone(eff, POLICESTATION);
94 return applyZone(eff, POWERPLANT);
97 return applyZone(eff, STADIUM);
100 return applyZone(eff, PORT);
103 return applyZone(eff, NUCLEAR);
106 return applyZone(eff, AIRPORT);
110 return applyZone(eff, UNIVERSITY);
113 return applyZone(eff, TEMPEL);
123 city.generateRocket(0, 0, xpos, ypos, playerID);
130 city.sendMessage(MicropolisMessage.INSUFFICIENT_RESEARCH);
136 throw new Error(
"unexpected tool: " + tool);
140 public void dragTo(
int xdest,
int ydest) {
179 assert isZoneCenter(base);
183 throw new Error(
"Cannot applyZone to #" + base);
187 boolean canBuild =
true;
188 for (
int rowNum = 0; rowNum < bi.height; rowNum++) {
189 for (
int columnNum = 0; columnNum < bi.width; columnNum++) {
190 int tileValue = eff.
getTile(columnNum, rowNum);
191 tileValue = tileValue & LOMASK;
193 if (tileValue != DIRT) {
194 if (city.
autoBulldoze && canAutoBulldozeZ((
char) tileValue)) {
210 for (
int rowNum = 0; rowNum < bi.height; rowNum++) {
211 for (
int columnNum = 0; columnNum < bi.width; columnNum++) {
212 eff.
setTile(columnNum, rowNum, bi.members[i]);
217 fixBorder(eff, bi.width, bi.height);
222 void fixBorder(
int left,
int top,
int right,
int bottom) {
223 ToolEffect eff =
new ToolEffect(city, left, top, playerID);
224 fixBorder(eff, right + 1 - left, bottom + 1 - top);
228 void fixBorder(ToolEffectIfc eff,
int width,
int height) {
229 for (
int x = 0; x < width; x++) {
230 fixZone(
new TranslatedToolEffect(eff, x, 0));
231 fixZone(
new TranslatedToolEffect(eff, x, height - 1));
233 for (
int y = 1; y < height - 1; y++) {
234 fixZone(
new TranslatedToolEffect(eff, 0, y));
235 fixZone(
new TranslatedToolEffect(eff, width - 1, y));
239 boolean applyParkTool(ToolEffectIfc eff) {
242 if (eff.getTile(0, 0) != DIRT) {
245 eff.toolResult(ToolResult.UH_OH);
250 if (isRubble(eff.getTile(0, 0))) {
255 eff.toolResult(ToolResult.UH_OH);
260 int z = inPreview ? 0 : city.PRNG.nextInt(5);
269 eff.setTile(0, 0, tile);
275 ToolEffect eff =
new ToolEffect(city, xpos, ypos, playerID);
284 fixSingle(
new TranslatedToolEffect(eff, 0, -1));
285 fixSingle(
new TranslatedToolEffect(eff, -1, 0));
286 fixSingle(
new TranslatedToolEffect(eff, 1, 0));
287 fixSingle(
new TranslatedToolEffect(eff, 0, 1));
293 if (isRoadDynamic(tile)) {
298 if (roadConnectsSouth(eff.
getTile(0, -1))) {
303 if (roadConnectsWest(eff.
getTile(1, 0))) {
308 if (roadConnectsNorth(eff.
getTile(0, 1))) {
313 if (roadConnectsEast(eff.
getTile(-1, 0))) {
317 eff.
setTile(0, 0, RoadTable[adjTile]);
320 else if (isRailDynamic(tile)) {
325 if (railConnectsSouth(eff.
getTile(0, -1))) {
330 if (railConnectsWest(eff.
getTile(1, 0))) {
335 if (railConnectsNorth(eff.
getTile(0, 1))) {
340 if (railConnectsEast(eff.
getTile(-1, 0))) {
344 eff.
setTile(0, 0, RailTable[adjTile]);
347 else if (isWireDynamic(tile)) {
352 if (wireConnectsSouth(eff.
getTile(0, -1))) {
357 if (wireConnectsWest(eff.
getTile(1, 0))) {
362 if (wireConnectsNorth(eff.
getTile(0, 1))) {
367 if (wireConnectsEast(eff.
getTile(-1, 0))) {
371 eff.
setTile(0, 0, WireTable[adjTile]);