1
0
Fork 0

(svn r4047) Remove two calls to FindLandscapeHeight() and some confusing use of the comma operator

release/0.5
tron 2006-03-23 06:30:39 +00:00
parent 68ee299e77
commit 9d216c1c56
1 changed files with 33 additions and 30 deletions

View File

@ -182,7 +182,12 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
TransportType transport; TransportType transport;
RailType railtype; RailType railtype;
int sx,sy; int sx,sy;
TileInfo ti_start, ti_end; TileIndex tile_start;
TileIndex tile_end;
uint tileh_start;
uint tileh_end;
uint z_start;
uint z_end;
TileIndex tile; TileIndex tile;
TileIndexDiff delta; TileIndexDiff delta;
uint bridge_len; uint bridge_len;
@ -235,29 +240,27 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE); if (!CheckBridge_Stuff(bridge_type, bridge_len)) return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE);
/* retrieve landscape height and ensure it's on land */ /* retrieve landscape height and ensure it's on land */
if (( tile_start = TileVirtXY(x, y);
FindLandscapeHeight(&ti_end, sx, sy), tile_end = TileVirtXY(sx, sy);
ti_end.type == MP_WATER && ti_end.map5 == 0 if ((IsTileType(tile_start, MP_WATER) && _m[tile_start].m5 == 0) ||
) || ( (IsTileType(tile_end, MP_WATER) && _m[tile_end].m5 == 0)) {
FindLandscapeHeight(&ti_start, x, y),
ti_start.type == MP_WATER && ti_start.map5 == 0
)) {
return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH); return_cmd_error(STR_02A0_ENDS_OF_BRIDGE_MUST_BOTH);
} }
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_start.tileh)) { tileh_start = GetTileSlope(tile_start, &z_start);
ti_start.z += 8; tileh_end = GetTileSlope(tile_end, &z_end);
ti_start.tileh = 0;
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh_start)) {
z_start += 8;
tileh_start = 0;
} }
if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << ti_end.tileh)) { if (BRIDGE_FULL_LEVELED_FOUNDATION & (1 << tileh_end)) {
ti_end.z += 8; z_end += 8;
ti_end.tileh = 0; tileh_end = 0;
} }
if (ti_start.z != ti_end.z) if (z_start != z_end) return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED);
return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED);
// Towns are not allowed to use bridges on slopes. // Towns are not allowed to use bridges on slopes.
allow_on_slopes = (!_is_old_ai_player allow_on_slopes = (!_is_old_ai_player
@ -265,24 +268,24 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* Try and clear the start landscape */ /* Try and clear the start landscape */
ret = DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); ret = DoCommandByTile(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(ret)) return ret; if (CmdFailed(ret)) return ret;
cost = ret; cost = ret;
// true - bridge-start-tile, false - bridge-end-tile // true - bridge-start-tile, false - bridge-end-tile
terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true); terraformcost = CheckBridgeSlope(direction, tileh_start, true);
if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes)) if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes))
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
cost += terraformcost; cost += terraformcost;
/* Try and clear the end landscape */ /* Try and clear the end landscape */
ret = DoCommandByTile(ti_end.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); ret = DoCommandByTile(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(ret)) return ret; if (CmdFailed(ret)) return ret;
cost += ret; cost += ret;
// false - end tile slope check // false - end tile slope check
terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false); terraformcost = CheckBridgeSlope(direction, tileh_end, false);
if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes)) if (CmdFailed(terraformcost) || (terraformcost && !allow_on_slopes))
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
cost += terraformcost; cost += terraformcost;
@ -293,20 +296,20 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
DiagDirection dir = AxisToDiagDir(direction); DiagDirection dir = AxisToDiagDir(direction);
if (transport == TRANSPORT_RAIL) { if (transport == TRANSPORT_RAIL) {
MakeRailBridgeRamp(ti_start.tile, _current_player, bridge_type, dir, railtype); MakeRailBridgeRamp(tile_start, _current_player, bridge_type, dir, railtype);
MakeRailBridgeRamp(ti_end.tile, _current_player, bridge_type, ReverseDiagDir(dir), railtype); MakeRailBridgeRamp(tile_end, _current_player, bridge_type, ReverseDiagDir(dir), railtype);
} else { } else {
MakeRoadBridgeRamp(ti_start.tile, _current_player, bridge_type, dir); MakeRoadBridgeRamp(tile_start, _current_player, bridge_type, dir);
MakeRoadBridgeRamp(ti_end.tile, _current_player, bridge_type, ReverseDiagDir(dir)); MakeRoadBridgeRamp(tile_end, _current_player, bridge_type, ReverseDiagDir(dir));
} }
MarkTileDirtyByTile(ti_start.tile); MarkTileDirtyByTile(tile_start);
MarkTileDirtyByTile(ti_end.tile); MarkTileDirtyByTile(tile_end);
} }
// position of middle part of the odd bridge (larger than MAX(i) otherwise) // position of middle part of the odd bridge (larger than MAX(i) otherwise)
odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len; odd_middle_part = (bridge_len % 2) ? (bridge_len / 2) : bridge_len;
tile = ti_start.tile; tile = tile_start;
delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
for (i = 0; i != bridge_len; i++) { for (i = 0; i != bridge_len; i++) {
TransportType transport_under; TransportType transport_under;
@ -316,7 +319,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
tile += delta; tile += delta;
if (GetTileSlope(tile, &z) != 0 && z >= ti_start.z) { if (GetTileSlope(tile, &z) != 0 && z >= z_start) {
return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED);
} }
@ -400,7 +403,7 @@ not_valid_below:;
} }
} }
SetSignalsOnBothDir(ti_start.tile, direction == AXIS_X ? TRACK_X : TRACK_Y); SetSignalsOnBothDir(tile_start, direction == AXIS_X ? TRACK_X : TRACK_Y);
/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST) /* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
It's unnecessary to execute this command every time for every bridge. So it is done only It's unnecessary to execute this command every time for every bridge. So it is done only