toolstroke: cleanup: rename 'engine' variable to 'city' variable

for consistency

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@621 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-05-16 23:36:11 +00:00
parent 8901474800
commit 6438791974

View file

@ -80,14 +80,14 @@ public class ToolStroke
} }
} }
ToolResult apply3x3buildingTool(Micropolis engine, int xpos, int ypos, char tileBase) ToolResult apply3x3buildingTool(Micropolis city, int xpos, int ypos, char tileBase)
{ {
int mapH = xpos - 1; int mapH = xpos - 1;
int mapV = ypos - 1; int mapV = ypos - 1;
if (!(mapH >= 0 && mapH + 2 < engine.getWidth())) if (!(mapH >= 0 && mapH + 2 < city.getWidth()))
return ToolResult.UH_OH; return ToolResult.UH_OH;
if (!(mapV >= 0 && mapV + 2 < engine.getHeight())) if (!(mapV >= 0 && mapV + 2 < city.getHeight()))
return ToolResult.UH_OH; return ToolResult.UH_OH;
int cost = 0; int cost = 0;
@ -98,11 +98,11 @@ public class ToolStroke
{ {
int x = mapH + columnNum; int x = mapH + columnNum;
int y = mapV + rowNum; int y = mapV + rowNum;
char tileValue = (char) (engine.getTile(x,y) & LOMASK); char tileValue = (char) (city.getTile(x,y) & LOMASK);
if (tileValue != DIRT) if (tileValue != DIRT)
{ {
if (engine.autoBulldoze) if (city.autoBulldoze)
{ {
if (canAutoBulldozeZ(tileValue)) if (canAutoBulldozeZ(tileValue))
cost++; cost++;
@ -120,17 +120,17 @@ public class ToolStroke
cost += tool.getToolCost(); cost += tool.getToolCost();
if (engine.budget.totalFunds < cost) if (city.budget.totalFunds < cost)
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
// take care of the money situation here // take care of the money situation here
engine.spend(cost); city.spend(cost);
for (int rowNum = 0; rowNum <= 2; rowNum++) for (int rowNum = 0; rowNum <= 2; rowNum++)
{ {
for (int columnNum = 0; columnNum <= 2; columnNum++) for (int columnNum = 0; columnNum <= 2; columnNum++)
{ {
engine.setTile(mapH + columnNum, mapV + rowNum, (char) ( city.setTile(mapH + columnNum, mapV + rowNum, (char) (
tileBase + BNCNBIT + tileBase + BNCNBIT +
(columnNum == 1 && rowNum == 1 ? ZONEBIT : 0) (columnNum == 1 && rowNum == 1 ? ZONEBIT : 0)
)); ));
@ -138,18 +138,18 @@ public class ToolStroke
} }
} }
fixBorder(engine, mapH, mapV, mapH + 2, mapV + 2); fixBorder(city, mapH, mapV, mapH + 2, mapV + 2);
return ToolResult.SUCCESS; return ToolResult.SUCCESS;
} }
ToolResult apply4x4buildingTool(Micropolis engine, int xpos, int ypos, char tileBase) ToolResult apply4x4buildingTool(Micropolis city, int xpos, int ypos, char tileBase)
{ {
int mapH = xpos - 1; int mapH = xpos - 1;
int mapV = ypos - 1; int mapV = ypos - 1;
if (!(mapH >= 0 && mapH + 3 < engine.getWidth())) if (!(mapH >= 0 && mapH + 3 < city.getWidth()))
return ToolResult.UH_OH; return ToolResult.UH_OH;
if (!(mapV >= 0 && mapV + 3 < engine.getHeight())) if (!(mapV >= 0 && mapV + 3 < city.getHeight()))
return ToolResult.UH_OH; return ToolResult.UH_OH;
int cost = 0; int cost = 0;
@ -160,11 +160,11 @@ public class ToolStroke
{ {
int x = mapH + columnNum; int x = mapH + columnNum;
int y = mapV + rowNum; int y = mapV + rowNum;
char tileValue = (char) (engine.getTile(x,y) & LOMASK); char tileValue = (char) (city.getTile(x,y) & LOMASK);
if (tileValue != DIRT) if (tileValue != DIRT)
{ {
if (engine.autoBulldoze) if (city.autoBulldoze)
{ {
if (canAutoBulldozeZ(tileValue)) if (canAutoBulldozeZ(tileValue))
cost++; cost++;
@ -182,17 +182,17 @@ public class ToolStroke
cost += tool.getToolCost(); cost += tool.getToolCost();
if (engine.budget.totalFunds < cost) if (city.budget.totalFunds < cost)
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
// take care of the money situation here // take care of the money situation here
engine.spend(cost); city.spend(cost);
for (int rowNum = 0; rowNum <= 3; rowNum++) for (int rowNum = 0; rowNum <= 3; rowNum++)
{ {
for (int columnNum = 0; columnNum <= 3; columnNum++) for (int columnNum = 0; columnNum <= 3; columnNum++)
{ {
engine.setTile(mapH + columnNum, mapV + rowNum, (char) ( city.setTile(mapH + columnNum, mapV + rowNum, (char) (
tileBase + BNCNBIT + tileBase + BNCNBIT +
(columnNum == 1 && rowNum == 1 ? ZONEBIT : 0) + (columnNum == 1 && rowNum == 1 ? ZONEBIT : 0) +
(columnNum == 1 && rowNum == 2 ? ANIMBIT : 0) (columnNum == 1 && rowNum == 2 ? ANIMBIT : 0)
@ -201,18 +201,18 @@ public class ToolStroke
} }
} }
fixBorder(engine, mapH, mapV, mapH + 3, mapV + 3); fixBorder(city, mapH, mapV, mapH + 3, mapV + 3);
return ToolResult.SUCCESS; return ToolResult.SUCCESS;
} }
ToolResult apply6x6buildingTool(Micropolis engine, int xpos, int ypos, char tileBase) ToolResult apply6x6buildingTool(Micropolis city, int xpos, int ypos, char tileBase)
{ {
int mapH = xpos - 1; int mapH = xpos - 1;
int mapV = ypos - 1; int mapV = ypos - 1;
if (!(mapH >= 0 && mapH + 5 < engine.getWidth())) if (!(mapH >= 0 && mapH + 5 < city.getWidth()))
return ToolResult.UH_OH; return ToolResult.UH_OH;
if (!(mapV >= 0 && mapV + 5 < engine.getHeight())) if (!(mapV >= 0 && mapV + 5 < city.getHeight()))
return ToolResult.UH_OH; return ToolResult.UH_OH;
int cost = 0; int cost = 0;
@ -223,11 +223,11 @@ public class ToolStroke
{ {
int x = mapH + columnNum; int x = mapH + columnNum;
int y = mapV + rowNum; int y = mapV + rowNum;
char tileValue = (char) (engine.getTile(x,y) & LOMASK); char tileValue = (char) (city.getTile(x,y) & LOMASK);
if (tileValue != DIRT) if (tileValue != DIRT)
{ {
if (engine.autoBulldoze) if (city.autoBulldoze)
{ {
if (canAutoBulldozeZ(tileValue)) if (canAutoBulldozeZ(tileValue))
cost++; cost++;
@ -245,17 +245,17 @@ public class ToolStroke
cost += tool.getToolCost(); cost += tool.getToolCost();
if (engine.budget.totalFunds < cost) if (city.budget.totalFunds < cost)
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
// take care of the money situation here // take care of the money situation here
engine.spend(cost); city.spend(cost);
for (int rowNum = 0; rowNum <= 5; rowNum++) for (int rowNum = 0; rowNum <= 5; rowNum++)
{ {
for (int columnNum = 0; columnNum <= 5; columnNum++) for (int columnNum = 0; columnNum <= 5; columnNum++)
{ {
engine.setTile(mapH + columnNum, mapV + rowNum, (char) ( city.setTile(mapH + columnNum, mapV + rowNum, (char) (
tileBase + BNCNBIT + tileBase + BNCNBIT +
(columnNum == 1 && rowNum == 1 ? ZONEBIT : 0) (columnNum == 1 && rowNum == 1 ? ZONEBIT : 0)
)); ));
@ -263,51 +263,51 @@ public class ToolStroke
} }
} }
fixBorder(engine, mapH, mapV, mapH + 5, mapV + 5); fixBorder(city, mapH, mapV, mapH + 5, mapV + 5);
return ToolResult.SUCCESS; return ToolResult.SUCCESS;
} }
void fixBorder(Micropolis engine, int left, int top, int right, int bottom) void fixBorder(Micropolis city, int left, int top, int right, int bottom)
{ {
for (int x = left; x <= right; x++) for (int x = left; x <= right; x++)
{ {
fixZone(engine, x, top); fixZone(city, x, top);
fixZone(engine, x, bottom); fixZone(city, x, bottom);
} }
for (int y = top + 1; y <= bottom - 1; y++) for (int y = top + 1; y <= bottom - 1; y++)
{ {
fixZone(engine, left, y); fixZone(city, left, y);
fixZone(engine, right, y); fixZone(city, right, y);
} }
} }
ToolResult applyBulldozer(Micropolis engine, int xpos, int ypos) ToolResult applyBulldozer(Micropolis city, int xpos, int ypos)
{ {
if (!engine.testBounds(xpos, ypos)) if (!city.testBounds(xpos, ypos))
return ToolResult.UH_OH; return ToolResult.UH_OH;
char currTile = engine.getTile(xpos, ypos); char currTile = city.getTile(xpos, ypos);
char tmp = (char)(currTile & LOMASK); char tmp = (char)(currTile & LOMASK);
if ((currTile & ZONEBIT) != 0) if ((currTile & ZONEBIT) != 0)
{ {
// zone center bit is set // zone center bit is set
if (engine.budget.totalFunds >= 1) if (city.budget.totalFunds >= 1)
{ {
engine.spend(1); city.spend(1);
switch (checkSize(tmp)) switch (checkSize(tmp))
{ {
case 3: case 3:
engine.makeSound(xpos, ypos, Sound.EXPLOSION_HIGH); city.makeSound(xpos, ypos, Sound.EXPLOSION_HIGH);
putRubble(engine, xpos, ypos, 3, 3); putRubble(city, xpos, ypos, 3, 3);
break; break;
case 4: case 4:
engine.makeSound(xpos, ypos, Sound.EXPLOSION_LOW); city.makeSound(xpos, ypos, Sound.EXPLOSION_LOW);
putRubble(engine, xpos, ypos, 4, 4); putRubble(city, xpos, ypos, 4, 4);
break; break;
case 6: case 6:
engine.makeSound(xpos, ypos, Sound.EXPLOSION_BOTH); city.makeSound(xpos, ypos, Sound.EXPLOSION_BOTH);
putRubble(engine, xpos, ypos, 6, 6); putRubble(city, xpos, ypos, 6, 6);
break; break;
default: default:
assert false; assert false;
@ -333,14 +333,14 @@ public class ToolStroke
tmp == REDGE || tmp == REDGE ||
tmp == CHANNEL) tmp == CHANNEL)
{ {
if (engine.budget.totalFunds >= 6) if (city.budget.totalFunds >= 6)
{ {
ToolResult result = layDoze(engine, xpos, ypos); ToolResult result = layDoze(city, xpos, ypos);
if (tmp != (engine.getTile(xpos, ypos) & LOMASK)) if (tmp != (city.getTile(xpos, ypos) & LOMASK))
{ {
// tile changed // tile changed
engine.spend(5); city.spend(5);
fixZone(engine, xpos, ypos); fixZone(city, xpos, ypos);
} }
return result; return result;
} }
@ -350,46 +350,46 @@ public class ToolStroke
} }
else else
{ {
ToolResult result = layDoze(engine, xpos, ypos); ToolResult result = layDoze(city, xpos, ypos);
fixZone(engine, xpos, ypos); fixZone(city, xpos, ypos);
return result; return result;
} }
} }
ToolResult applyRailTool(Micropolis engine, int xpos, int ypos) ToolResult applyRailTool(Micropolis city, int xpos, int ypos)
{ {
if (!engine.testBounds(xpos, ypos)) if (!city.testBounds(xpos, ypos))
return ToolResult.UH_OH; return ToolResult.UH_OH;
ToolResult result = layRail(engine, xpos, ypos); ToolResult result = layRail(city, xpos, ypos);
fixZone(engine, xpos, ypos); fixZone(city, xpos, ypos);
return result; return result;
} }
ToolResult applyRoadTool(Micropolis engine, int xpos, int ypos) ToolResult applyRoadTool(Micropolis city, int xpos, int ypos)
{ {
if (!engine.testBounds(xpos, ypos)) if (!city.testBounds(xpos, ypos))
return ToolResult.UH_OH; return ToolResult.UH_OH;
ToolResult result = layRoad(engine, xpos, ypos); ToolResult result = layRoad(city, xpos, ypos);
fixZone(engine, xpos, ypos); fixZone(city, xpos, ypos);
return result; return result;
} }
ToolResult applyParkTool(Micropolis engine, int xpos, int ypos) ToolResult applyParkTool(Micropolis city, int xpos, int ypos)
{ {
if (!engine.testBounds(xpos, ypos)) if (!city.testBounds(xpos, ypos))
return ToolResult.UH_OH; return ToolResult.UH_OH;
int cost = tool.getToolCost(); int cost = tool.getToolCost();
if (engine.getTile(xpos, ypos) != DIRT) { if (city.getTile(xpos, ypos) != DIRT) {
// some sort of bulldozing is necessary // some sort of bulldozing is necessary
if (!engine.autoBulldoze) { if (!city.autoBulldoze) {
return ToolResult.UH_OH; return ToolResult.UH_OH;
} }
if (isRubble(engine.getTile(xpos, ypos))) { if (isRubble(city.getTile(xpos, ypos))) {
// this tile can be auto-bulldozed // this tile can be auto-bulldozed
cost++; cost++;
} }
@ -399,11 +399,11 @@ public class ToolStroke
} }
} }
if (engine.budget.totalFunds < cost) { if (city.budget.totalFunds < cost) {
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
} }
int z = engine.PRNG.nextInt(5); int z = city.PRNG.nextInt(5);
int tile; int tile;
if (z < 4) { if (z < 4) {
tile = (WOODS2 + z) | BURNBIT | BULLBIT; tile = (WOODS2 + z) | BURNBIT | BULLBIT;
@ -411,18 +411,18 @@ public class ToolStroke
tile = FOUNTAIN | BURNBIT | BULLBIT | ANIMBIT; tile = FOUNTAIN | BURNBIT | BULLBIT | ANIMBIT;
} }
engine.spend(cost); city.spend(cost);
engine.setTile(xpos, ypos, (char) tile); city.setTile(xpos, ypos, (char) tile);
return ToolResult.SUCCESS; return ToolResult.SUCCESS;
} }
ToolResult applyWireTool(Micropolis engine, int xpos, int ypos) ToolResult applyWireTool(Micropolis city, int xpos, int ypos)
{ {
if (!engine.testBounds(xpos, ypos)) if (!city.testBounds(xpos, ypos))
return ToolResult.UH_OH; return ToolResult.UH_OH;
ToolResult result = layWire(engine, xpos, ypos); ToolResult result = layWire(city, xpos, ypos);
fixZone(engine, xpos, ypos); fixZone(city, xpos, ypos);
return result; return result;
} }
@ -434,12 +434,12 @@ public class ToolStroke
return tile; return tile;
} }
private ToolResult layDoze(Micropolis engine, int xpos, int ypos) private ToolResult layDoze(Micropolis city, int xpos, int ypos)
{ {
if (engine.budget.totalFunds <= 0) if (city.budget.totalFunds <= 0)
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
char tile = engine.getTile(xpos, ypos); char tile = city.getTile(xpos, ypos);
// check dozeable bit // check dozeable bit
if ((tile & BULLBIT) == 0) if ((tile & BULLBIT) == 0)
@ -449,28 +449,28 @@ public class ToolStroke
if (isOverWater(tile)) if (isOverWater(tile))
{ {
// dozing over water, replace with water. // dozing over water, replace with water.
engine.setTile(xpos, ypos, RIVER); city.setTile(xpos, ypos, RIVER);
} }
else else
{ {
// dozing on land, replace with land. Simple, eh? // dozing on land, replace with land. Simple, eh?
engine.setTile(xpos, ypos, DIRT); city.setTile(xpos, ypos, DIRT);
} }
engine.spend(1); city.spend(1);
return ToolResult.SUCCESS; return ToolResult.SUCCESS;
} }
private ToolResult layRail(Micropolis engine, int xpos, int ypos) private ToolResult layRail(Micropolis city, int xpos, int ypos)
{ {
final int RAIL_COST = 20; final int RAIL_COST = 20;
final int TUNNEL_COST = 100; final int TUNNEL_COST = 100;
int cost = RAIL_COST; int cost = RAIL_COST;
if (engine.budget.totalFunds < cost) if (city.budget.totalFunds < cost)
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
char tile = (char) (engine.getTile(xpos, ypos) & LOMASK); char tile = (char) (city.getTile(xpos, ypos) & LOMASK);
switch (tile) switch (tile)
{ {
case RIVER: // rail on water case RIVER: // rail on water
@ -478,53 +478,53 @@ public class ToolStroke
case CHANNEL: case CHANNEL:
cost = TUNNEL_COST; cost = TUNNEL_COST;
if (engine.budget.totalFunds < cost) if (city.budget.totalFunds < cost)
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
if (xpos + 1 < engine.getWidth()) if (xpos + 1 < city.getWidth())
{ {
char eTile = neutralizeRoad(engine.getTile(xpos + 1, ypos)); char eTile = neutralizeRoad(city.getTile(xpos + 1, ypos));
if (eTile == RAILHPOWERV || if (eTile == RAILHPOWERV ||
eTile == HRAIL || eTile == HRAIL ||
(eTile >= LHRAIL && eTile <= HRAILROAD)) (eTile >= LHRAIL && eTile <= HRAILROAD))
{ {
engine.setTile(xpos, ypos, (char) (HRAIL | BULLBIT)); city.setTile(xpos, ypos, (char) (HRAIL | BULLBIT));
break; break;
} }
} }
if (xpos > 0) if (xpos > 0)
{ {
char wTile = neutralizeRoad(engine.getTile(xpos - 1, ypos)); char wTile = neutralizeRoad(city.getTile(xpos - 1, ypos));
if (wTile == RAILHPOWERV || if (wTile == RAILHPOWERV ||
wTile == HRAIL || wTile == HRAIL ||
(wTile > VRAIL && wTile < VRAILROAD)) (wTile > VRAIL && wTile < VRAILROAD))
{ {
engine.setTile(xpos, ypos, (char) (HRAIL | BULLBIT)); city.setTile(xpos, ypos, (char) (HRAIL | BULLBIT));
break; break;
} }
} }
if (ypos + 1 < engine.getHeight()) if (ypos + 1 < city.getHeight())
{ {
char sTile = neutralizeRoad(engine.getTile(xpos, ypos + 1)); char sTile = neutralizeRoad(city.getTile(xpos, ypos + 1));
if (sTile == RAILVPOWERH || if (sTile == RAILVPOWERH ||
sTile == VRAILROAD || sTile == VRAILROAD ||
(sTile > HRAIL && sTile < HRAILROAD)) (sTile > HRAIL && sTile < HRAILROAD))
{ {
engine.setTile(xpos, ypos, (char) (VRAIL | BULLBIT)); city.setTile(xpos, ypos, (char) (VRAIL | BULLBIT));
break; break;
} }
} }
if (ypos > 0) if (ypos > 0)
{ {
char nTile = neutralizeRoad(engine.getTile(xpos, ypos - 1)); char nTile = neutralizeRoad(city.getTile(xpos, ypos - 1));
if (nTile == RAILVPOWERH || if (nTile == RAILVPOWERH ||
nTile == VRAILROAD || nTile == VRAILROAD ||
(nTile > HRAIL && nTile < HRAILROAD)) (nTile > HRAIL && nTile < HRAILROAD))
{ {
engine.setTile(xpos, ypos, (char) (VRAIL | BULLBIT)); city.setTile(xpos, ypos, (char) (VRAIL | BULLBIT));
break; break;
} }
} }
@ -533,24 +533,24 @@ public class ToolStroke
return ToolResult.NONE; return ToolResult.NONE;
case LHPOWER: // rail on power case LHPOWER: // rail on power
engine.setTile(xpos, ypos, (char) (RAILVPOWERH | CONDBIT | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (RAILVPOWERH | CONDBIT | BURNBIT | BULLBIT));
break; break;
case LVPOWER: // rail on power case LVPOWER: // rail on power
engine.setTile(xpos, ypos, (char) (RAILHPOWERV | CONDBIT | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (RAILHPOWERV | CONDBIT | BURNBIT | BULLBIT));
break; break;
case TileConstants.ROADS: // rail on road (case 1) case TileConstants.ROADS: // rail on road (case 1)
engine.setTile(xpos, ypos, (char) (VRAILROAD | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (VRAILROAD | BURNBIT | BULLBIT));
break; break;
case ROADS2: // rail on road (case 2) case ROADS2: // rail on road (case 2)
engine.setTile(xpos, ypos, (char) (HRAILROAD | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (HRAILROAD | BURNBIT | BULLBIT));
break; break;
default: default:
if (tile != DIRT) { if (tile != DIRT) {
if (engine.autoBulldoze && canAutoBulldozeRRW(tile)) { if (city.autoBulldoze && canAutoBulldozeRRW(tile)) {
cost += 1; //autodoze cost cost += 1; //autodoze cost
} }
else { else {
@ -560,24 +560,24 @@ public class ToolStroke
} }
//rail on dirt //rail on dirt
engine.setTile(xpos, ypos, (char) (LHRAIL | BULLBIT | BURNBIT)); city.setTile(xpos, ypos, (char) (LHRAIL | BULLBIT | BURNBIT));
break; break;
} }
engine.spend(cost); city.spend(cost);
return ToolResult.SUCCESS; return ToolResult.SUCCESS;
} }
private ToolResult layRoad(Micropolis engine, int xpos, int ypos) private ToolResult layRoad(Micropolis city, int xpos, int ypos)
{ {
final int ROAD_COST = 10; final int ROAD_COST = 10;
final int BRIDGE_COST = 50; final int BRIDGE_COST = 50;
int cost = ROAD_COST; int cost = ROAD_COST;
if (engine.budget.totalFunds < cost) if (city.budget.totalFunds < cost)
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
char tile = (char) (engine.getTile(xpos, ypos) & LOMASK); char tile = (char) (city.getTile(xpos, ypos) & LOMASK);
switch (tile) switch (tile)
{ {
case RIVER: // road on water case RIVER: // road on water
@ -585,53 +585,53 @@ public class ToolStroke
case CHANNEL: // check how to build bridges, if possible. case CHANNEL: // check how to build bridges, if possible.
cost = BRIDGE_COST; cost = BRIDGE_COST;
if (engine.budget.totalFunds < cost) if (city.budget.totalFunds < cost)
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
if (xpos + 1 < engine.getWidth()) if (xpos + 1 < city.getWidth())
{ {
char eTile = neutralizeRoad(engine.getTile(xpos + 1, ypos)); char eTile = neutralizeRoad(city.getTile(xpos + 1, ypos));
if (eTile == VRAILROAD || if (eTile == VRAILROAD ||
eTile == HBRIDGE || eTile == HBRIDGE ||
(eTile >= TileConstants.ROADS && eTile <= HROADPOWER)) (eTile >= TileConstants.ROADS && eTile <= HROADPOWER))
{ {
engine.setTile(xpos, ypos, (char) (HBRIDGE | BULLBIT)); city.setTile(xpos, ypos, (char) (HBRIDGE | BULLBIT));
break; break;
} }
} }
if (xpos > 0) if (xpos > 0)
{ {
char wTile = neutralizeRoad(engine.getTile(xpos - 1, ypos)); char wTile = neutralizeRoad(city.getTile(xpos - 1, ypos));
if (wTile == VRAILROAD || if (wTile == VRAILROAD ||
wTile == HBRIDGE || wTile == HBRIDGE ||
(wTile >= TileConstants.ROADS && wTile <= INTERSECTION)) (wTile >= TileConstants.ROADS && wTile <= INTERSECTION))
{ {
engine.setTile(xpos, ypos, (char) (HBRIDGE | BULLBIT)); city.setTile(xpos, ypos, (char) (HBRIDGE | BULLBIT));
break; break;
} }
} }
if (ypos + 1 < engine.getHeight()) if (ypos + 1 < city.getHeight())
{ {
char sTile = neutralizeRoad(engine.getTile(xpos, ypos + 1)); char sTile = neutralizeRoad(city.getTile(xpos, ypos + 1));
if (sTile == HRAILROAD || if (sTile == HRAILROAD ||
sTile == VROADPOWER || sTile == VROADPOWER ||
(sTile >= VBRIDGE && sTile <= INTERSECTION)) (sTile >= VBRIDGE && sTile <= INTERSECTION))
{ {
engine.setTile(xpos, ypos, (char) (VBRIDGE | BULLBIT)); city.setTile(xpos, ypos, (char) (VBRIDGE | BULLBIT));
break; break;
} }
} }
if (ypos > 0) if (ypos > 0)
{ {
char nTile = neutralizeRoad(engine.getTile(xpos, ypos - 1)); char nTile = neutralizeRoad(city.getTile(xpos, ypos - 1));
if (nTile == HRAILROAD || if (nTile == HRAILROAD ||
nTile == VROADPOWER || nTile == VROADPOWER ||
(nTile >= VBRIDGE && nTile <= INTERSECTION)) (nTile >= VBRIDGE && nTile <= INTERSECTION))
{ {
engine.setTile(xpos, ypos, (char) (VBRIDGE | BULLBIT)); city.setTile(xpos, ypos, (char) (VBRIDGE | BULLBIT));
break; break;
} }
} }
@ -640,24 +640,24 @@ public class ToolStroke
return ToolResult.NONE; return ToolResult.NONE;
case LHPOWER: //road on power case LHPOWER: //road on power
engine.setTile(xpos, ypos, (char) (VROADPOWER | CONDBIT | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (VROADPOWER | CONDBIT | BURNBIT | BULLBIT));
break; break;
case LVPOWER: //road on power #2 case LVPOWER: //road on power #2
engine.setTile(xpos, ypos, (char) (HROADPOWER | CONDBIT | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (HROADPOWER | CONDBIT | BURNBIT | BULLBIT));
break; break;
case LHRAIL: //road on rail case LHRAIL: //road on rail
engine.setTile(xpos, ypos, (char) (HRAILROAD | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (HRAILROAD | BURNBIT | BULLBIT));
break; break;
case LVRAIL: //road on rail #2 case LVRAIL: //road on rail #2
engine.setTile(xpos, ypos, (char) (VRAILROAD | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (VRAILROAD | BURNBIT | BULLBIT));
break; break;
default: default:
if (tile != DIRT) { if (tile != DIRT) {
if (engine.autoBulldoze && canAutoBulldozeRRW(tile)) { if (city.autoBulldoze && canAutoBulldozeRRW(tile)) {
cost += 1; //autodoze cost cost += 1; //autodoze cost
} }
else { else {
@ -667,24 +667,24 @@ public class ToolStroke
} }
// road on dirt // road on dirt
engine.setTile(xpos, ypos, (char) (TileConstants.ROADS | BULLBIT | BURNBIT)); city.setTile(xpos, ypos, (char) (TileConstants.ROADS | BULLBIT | BURNBIT));
break; break;
} }
engine.spend(cost); city.spend(cost);
return ToolResult.SUCCESS; return ToolResult.SUCCESS;
} }
private ToolResult layWire(Micropolis engine, int xpos, int ypos) private ToolResult layWire(Micropolis city, int xpos, int ypos)
{ {
final int WIRE_COST = 5; final int WIRE_COST = 5;
final int UNDERWATER_WIRE_COST = 25; final int UNDERWATER_WIRE_COST = 25;
int cost = WIRE_COST; int cost = WIRE_COST;
if (engine.budget.totalFunds < cost) if (city.budget.totalFunds < cost)
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
char tile = (char) (engine.getTile(xpos, ypos) & LOMASK); char tile = (char) (city.getTile(xpos, ypos) & LOMASK);
tile = neutralizeRoad(tile); tile = neutralizeRoad(tile);
switch (tile) switch (tile)
@ -694,12 +694,12 @@ public class ToolStroke
case CHANNEL: case CHANNEL:
cost = UNDERWATER_WIRE_COST; cost = UNDERWATER_WIRE_COST;
if (engine.budget.totalFunds < cost) if (city.budget.totalFunds < cost)
return ToolResult.INSUFFICIENT_FUNDS; return ToolResult.INSUFFICIENT_FUNDS;
if (xpos + 1 < engine.getWidth()) if (xpos + 1 < city.getWidth())
{ {
char tmp = engine.getTile(xpos + 1, ypos); char tmp = city.getTile(xpos + 1, ypos);
char tmpn = neutralizeRoad(tmp); char tmpn = neutralizeRoad(tmp);
if ((tmp & CONDBIT) != 0 && if ((tmp & CONDBIT) != 0 &&
@ -707,14 +707,14 @@ public class ToolStroke
tmpn != RAILHPOWERV && tmpn != RAILHPOWERV &&
tmpn != HPOWER) tmpn != HPOWER)
{ {
engine.setTile(xpos, ypos, (char) (VPOWER | CONDBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (VPOWER | CONDBIT | BULLBIT));
break; break;
} }
} }
if (xpos > 0) if (xpos > 0)
{ {
char tmp = engine.getTile(xpos - 1, ypos); char tmp = city.getTile(xpos - 1, ypos);
char tmpn = neutralizeRoad(tmp); char tmpn = neutralizeRoad(tmp);
if ((tmp & CONDBIT) != 0 && if ((tmp & CONDBIT) != 0 &&
@ -722,14 +722,14 @@ public class ToolStroke
tmpn != RAILHPOWERV && tmpn != RAILHPOWERV &&
tmpn != HPOWER) tmpn != HPOWER)
{ {
engine.setTile(xpos, ypos, (char) (VPOWER | CONDBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (VPOWER | CONDBIT | BULLBIT));
break; break;
} }
} }
if (ypos + 1 < engine.getHeight()) if (ypos + 1 < city.getHeight())
{ {
char tmp = engine.getTile(xpos, ypos + 1); char tmp = city.getTile(xpos, ypos + 1);
char tmpn = neutralizeRoad(tmp); char tmpn = neutralizeRoad(tmp);
if ((tmp & CONDBIT) != 0 && if ((tmp & CONDBIT) != 0 &&
@ -737,14 +737,14 @@ public class ToolStroke
tmpn != RAILVPOWERH && tmpn != RAILVPOWERH &&
tmpn != VPOWER) tmpn != VPOWER)
{ {
engine.setTile(xpos, ypos, (char) (HPOWER | CONDBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (HPOWER | CONDBIT | BULLBIT));
break; break;
} }
} }
if (ypos > 0) if (ypos > 0)
{ {
char tmp = engine.getTile(xpos, ypos - 1); char tmp = city.getTile(xpos, ypos - 1);
char tmpn = neutralizeRoad(tmp); char tmpn = neutralizeRoad(tmp);
if ((tmp & CONDBIT) != 0 && if ((tmp & CONDBIT) != 0 &&
@ -752,7 +752,7 @@ public class ToolStroke
tmpn != RAILVPOWERH && tmpn != RAILVPOWERH &&
tmpn != VPOWER) tmpn != VPOWER)
{ {
engine.setTile(xpos, ypos, (char) (HPOWER | CONDBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (HPOWER | CONDBIT | BULLBIT));
break; break;
} }
} }
@ -761,24 +761,24 @@ public class ToolStroke
return ToolResult.NONE; return ToolResult.NONE;
case TileConstants.ROADS: // wire on E/W road case TileConstants.ROADS: // wire on E/W road
engine.setTile(xpos, ypos, (char) (HROADPOWER | CONDBIT | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (HROADPOWER | CONDBIT | BURNBIT | BULLBIT));
break; break;
case ROADS2: // wire on N/S road case ROADS2: // wire on N/S road
engine.setTile(xpos, ypos, (char) (VROADPOWER | CONDBIT | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (VROADPOWER | CONDBIT | BURNBIT | BULLBIT));
break; break;
case LHRAIL: // wire on E/W railroad tracks case LHRAIL: // wire on E/W railroad tracks
engine.setTile(xpos, ypos, (char) (RAILHPOWERV | CONDBIT | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (RAILHPOWERV | CONDBIT | BURNBIT | BULLBIT));
break; break;
case LVRAIL: // wire on N/S railroad tracks case LVRAIL: // wire on N/S railroad tracks
engine.setTile(xpos, ypos, (char) (RAILVPOWERH | CONDBIT | BURNBIT | BULLBIT)); city.setTile(xpos, ypos, (char) (RAILVPOWERH | CONDBIT | BURNBIT | BULLBIT));
break; break;
default: default:
if (tile != DIRT) { if (tile != DIRT) {
if (engine.autoBulldoze && canAutoBulldozeRRW(tile)) { if (city.autoBulldoze && canAutoBulldozeRRW(tile)) {
cost += 1; //autodoze cost cost += 1; //autodoze cost
} }
else { else {
@ -788,30 +788,30 @@ public class ToolStroke
} }
//wire on dirt //wire on dirt
engine.setTile(xpos, ypos, (char) (LHPOWER | CONDBIT | BULLBIT | BURNBIT)); city.setTile(xpos, ypos, (char) (LHPOWER | CONDBIT | BULLBIT | BURNBIT));
break; break;
} }
engine.spend(cost); city.spend(cost);
return ToolResult.SUCCESS; return ToolResult.SUCCESS;
} }
private void fixZone(Micropolis engine, int xpos, int ypos) private void fixZone(Micropolis city, int xpos, int ypos)
{ {
fixSingle(engine, xpos, ypos); fixSingle(city, xpos, ypos);
if (ypos > 0) if (ypos > 0)
fixSingle(engine, xpos, ypos - 1); fixSingle(city, xpos, ypos - 1);
if (xpos > 0) if (xpos > 0)
fixSingle(engine, xpos - 1, ypos); fixSingle(city, xpos - 1, ypos);
if (xpos + 1 < engine.getWidth()) if (xpos + 1 < city.getWidth())
fixSingle(engine, xpos + 1, ypos); fixSingle(city, xpos + 1, ypos);
if (ypos + 1 < engine.getHeight()) if (ypos + 1 < city.getHeight())
fixSingle(engine, xpos, ypos + 1); fixSingle(city, xpos, ypos + 1);
} }
private void fixSingle(Micropolis engine, int xpos, int ypos) private void fixSingle(Micropolis city, int xpos, int ypos)
{ {
char tile = (char) (engine.getTile(xpos, ypos) & LOMASK); char tile = (char) (city.getTile(xpos, ypos) & LOMASK);
tile = neutralizeRoad(tile); tile = neutralizeRoad(tile);
if (tile >= TileConstants.ROADS && tile <= INTERSECTION) if (tile >= TileConstants.ROADS && tile <= INTERSECTION)
@ -821,7 +821,7 @@ public class ToolStroke
if (ypos > 0) if (ypos > 0)
{ {
tile = engine.getTile(xpos, ypos - 1); tile = city.getTile(xpos, ypos - 1);
tile = neutralizeRoad(tile); tile = neutralizeRoad(tile);
if (((tile == HRAILROAD) || if (((tile == HRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER) (tile >= ROADBASE && tile <= VROADPOWER)
@ -834,9 +834,9 @@ public class ToolStroke
} }
} }
if (xpos + 1 < engine.getWidth()) if (xpos + 1 < city.getWidth())
{ {
tile = engine.getTile(xpos + 1, ypos); tile = city.getTile(xpos + 1, ypos);
tile = neutralizeRoad(tile); tile = neutralizeRoad(tile);
if (((tile == VRAILROAD) || if (((tile == VRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER) (tile >= ROADBASE && tile <= VROADPOWER)
@ -849,9 +849,9 @@ public class ToolStroke
} }
} }
if (ypos + 1 < engine.getHeight()) if (ypos + 1 < city.getHeight())
{ {
tile = engine.getTile(xpos, ypos + 1); tile = city.getTile(xpos, ypos + 1);
tile = neutralizeRoad(tile); tile = neutralizeRoad(tile);
if (((tile == HRAILROAD) || if (((tile == HRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER) (tile >= ROADBASE && tile <= VROADPOWER)
@ -867,7 +867,7 @@ public class ToolStroke
if (xpos > 0) if (xpos > 0)
{ {
tile = engine.getTile(xpos - 1, ypos); tile = city.getTile(xpos - 1, ypos);
tile = neutralizeRoad(tile); tile = neutralizeRoad(tile);
if (((tile == VRAILROAD) || if (((tile == VRAILROAD) ||
(tile >= ROADBASE && tile <= VROADPOWER) (tile >= ROADBASE && tile <= VROADPOWER)
@ -880,7 +880,7 @@ public class ToolStroke
} }
} }
engine.setTile(xpos, ypos, (char)(RoadTable[adjTile] | BULLBIT | BURNBIT)); city.setTile(xpos, ypos, (char)(RoadTable[adjTile] | BULLBIT | BURNBIT));
return; return;
} //endif on a road tile } //endif on a road tile
@ -891,7 +891,7 @@ public class ToolStroke
if (ypos > 0) if (ypos > 0)
{ {
tile = engine.getTile(xpos, ypos - 1); tile = city.getTile(xpos, ypos - 1);
tile = neutralizeRoad(tile); tile = neutralizeRoad(tile);
if (tile >= RAILHPOWERV && tile <= VRAILROAD && if (tile >= RAILHPOWERV && tile <= VRAILROAD &&
tile != RAILHPOWERV && tile != RAILHPOWERV &&
@ -902,9 +902,9 @@ public class ToolStroke
} }
} }
if (xpos + 1 < engine.getWidth()) if (xpos + 1 < city.getWidth())
{ {
tile = engine.getTile(xpos + 1, ypos); tile = city.getTile(xpos + 1, ypos);
tile = neutralizeRoad(tile); tile = neutralizeRoad(tile);
if (tile >= RAILHPOWERV && tile <= VRAILROAD && if (tile >= RAILHPOWERV && tile <= VRAILROAD &&
tile != RAILVPOWERH && tile != RAILVPOWERH &&
@ -915,9 +915,9 @@ public class ToolStroke
} }
} }
if (ypos + 1 < engine.getHeight()) if (ypos + 1 < city.getHeight())
{ {
tile = engine.getTile(xpos, ypos + 1); tile = city.getTile(xpos, ypos + 1);
tile = neutralizeRoad(tile); tile = neutralizeRoad(tile);
if (tile >= RAILHPOWERV && tile <= VRAILROAD && if (tile >= RAILHPOWERV && tile <= VRAILROAD &&
tile != RAILHPOWERV && tile != RAILHPOWERV &&
@ -930,7 +930,7 @@ public class ToolStroke
if (xpos > 0) if (xpos > 0)
{ {
tile = engine.getTile(xpos - 1, ypos); tile = city.getTile(xpos - 1, ypos);
tile = neutralizeRoad(tile); tile = neutralizeRoad(tile);
if (tile >= RAILHPOWERV && tile <= VRAILROAD && if (tile >= RAILHPOWERV && tile <= VRAILROAD &&
tile != RAILVPOWERH && tile != RAILVPOWERH &&
@ -941,7 +941,7 @@ public class ToolStroke
} }
} }
engine.setTile(xpos, ypos, (char)(RailTable[adjTile] | BULLBIT | BURNBIT)); city.setTile(xpos, ypos, (char)(RailTable[adjTile] | BULLBIT | BURNBIT));
return; return;
} //end if on a rail tile } //end if on a rail tile
@ -952,7 +952,7 @@ public class ToolStroke
if (ypos > 0) if (ypos > 0)
{ {
tile = engine.getTile(xpos, ypos - 1); tile = city.getTile(xpos, ypos - 1);
char ntile = neutralizeRoad(tile); char ntile = neutralizeRoad(tile);
if ((tile & CONDBIT) != 0 && if ((tile & CONDBIT) != 0 &&
ntile != VPOWER && ntile != VPOWER &&
@ -963,9 +963,9 @@ public class ToolStroke
} }
} }
if (xpos + 1 < engine.getWidth()) if (xpos + 1 < city.getWidth())
{ {
tile = engine.getTile(xpos + 1, ypos); tile = city.getTile(xpos + 1, ypos);
char ntile = neutralizeRoad(tile); char ntile = neutralizeRoad(tile);
if ((tile & CONDBIT) != 0 && if ((tile & CONDBIT) != 0 &&
ntile != HPOWER && ntile != HPOWER &&
@ -976,9 +976,9 @@ public class ToolStroke
} }
} }
if (ypos + 1 < engine.getHeight()) if (ypos + 1 < city.getHeight())
{ {
tile = engine.getTile(xpos, ypos + 1); tile = city.getTile(xpos, ypos + 1);
char ntile = neutralizeRoad(tile); char ntile = neutralizeRoad(tile);
if ((tile & CONDBIT) != 0 && if ((tile & CONDBIT) != 0 &&
ntile != VPOWER && ntile != VPOWER &&
@ -991,7 +991,7 @@ public class ToolStroke
if (xpos > 0) if (xpos > 0)
{ {
tile = engine.getTile(xpos - 1, ypos); tile = city.getTile(xpos - 1, ypos);
char ntile = neutralizeRoad(tile); char ntile = neutralizeRoad(tile);
if ((tile & CONDBIT) != 0 && if ((tile & CONDBIT) != 0 &&
ntile != HPOWER && ntile != HPOWER &&
@ -1002,21 +1002,21 @@ public class ToolStroke
} }
} }
engine.setTile(xpos, ypos, (char)(WireTable[adjTile] | BULLBIT | BURNBIT | CONDBIT)); city.setTile(xpos, ypos, (char)(WireTable[adjTile] | BULLBIT | BURNBIT | CONDBIT));
return; return;
} //end if on a rail tile } //end if on a rail tile
} }
void putRubble(Micropolis engine, int xpos, int ypos, int w, int h) void putRubble(Micropolis city, int xpos, int ypos, int w, int h)
{ {
for (int xx = xpos - 1; xx <= xpos + w-2; xx++) { for (int xx = xpos - 1; xx <= xpos + w-2; xx++) {
for (int yy = ypos - 1; yy <= ypos + h-2; yy++) { for (int yy = ypos - 1; yy <= ypos + h-2; yy++) {
if (engine.testBounds(xx, yy)) { if (city.testBounds(xx, yy)) {
int tile = engine.getTile(xx,yy) & LOMASK; int tile = city.getTile(xx,yy) & LOMASK;
if (tile != RADTILE && tile != DIRT) { if (tile != RADTILE && tile != DIRT) {
int nTile = (TINYEXP + engine.PRNG.nextInt(3)) int nTile = (TINYEXP + city.PRNG.nextInt(3))
| ANIMBIT | BULLBIT; | ANIMBIT | BULLBIT;
engine.setTile(xx, yy, (char)nTile); city.setTile(xx, yy, (char)nTile);
} }
} }
} }