mirror of https://github.com/OpenTTD/OpenTTD
(svn r20728) -Codechange: shuffle some code in CMD_BUILD_ROAD so it doesn't call CMD_LANDSCAPE_CLEAR in test-mode from exec-mode
parent
9b5808a89d
commit
bd379e283f
|
@ -476,7 +476,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
|
|
||||||
Slope tileh = GetTileSlope(tile, NULL);
|
Slope tileh = GetTileSlope(tile, NULL);
|
||||||
|
|
||||||
bool tile_cleared = false; // Used to remember that the tile was cleared during test run
|
bool need_to_clear = false;
|
||||||
switch (GetTileType(tile)) {
|
switch (GetTileType(tile)) {
|
||||||
case MP_ROAD:
|
case MP_ROAD:
|
||||||
switch (GetRoadTileType(tile)) {
|
switch (GetRoadTileType(tile)) {
|
||||||
|
@ -614,14 +614,17 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
do_clear:;
|
do_clear:;
|
||||||
CommandCost ret = DoCommand(tile, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
need_to_clear = true;
|
||||||
if (ret.Failed()) return ret;
|
|
||||||
cost.AddCost(ret);
|
|
||||||
tile_cleared = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (need_to_clear) {
|
||||||
|
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
cost.AddCost(ret);
|
||||||
|
}
|
||||||
|
|
||||||
if (other_bits != pieces) {
|
if (other_bits != pieces) {
|
||||||
/* Check the foundation/slopes when adding road/tram bits */
|
/* Check the foundation/slopes when adding road/tram bits */
|
||||||
CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
|
CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
|
||||||
|
@ -633,7 +636,8 @@ do_clear:;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tile_cleared && IsTileType(tile, MP_ROAD)) {
|
if (!need_to_clear) {
|
||||||
|
if (IsTileType(tile, MP_ROAD)) {
|
||||||
/* Don't put the pieces that already exist */
|
/* Don't put the pieces that already exist */
|
||||||
pieces &= ComplementRoadBits(existing);
|
pieces &= ComplementRoadBits(existing);
|
||||||
|
|
||||||
|
@ -655,22 +659,18 @@ do_clear:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tile_cleared) {
|
|
||||||
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
||||||
if (ret.Failed()) return ret;
|
if (ret.Failed()) return ret;
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
cost.AddCost(CountBits(pieces) * _price[PR_BUILD_ROAD]);
|
cost.AddCost(CountBits(pieces) * _price[PR_BUILD_ROAD]);
|
||||||
if (!tile_cleared && IsTileType(tile, MP_TUNNELBRIDGE)) {
|
|
||||||
|
if (!need_to_clear && IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||||
/* Pay for *every* tile of the bridge or tunnel */
|
/* Pay for *every* tile of the bridge or tunnel */
|
||||||
cost.MultiplyCost(GetTunnelBridgeLength(GetOtherTunnelBridgeEnd(tile), tile) + 2);
|
cost.MultiplyCost(GetTunnelBridgeLength(GetOtherTunnelBridgeEnd(tile), tile) + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
/* CmdBuildLongRoad calls us directly with DC_EXEC, so we may only clear the tile after all
|
|
||||||
* fail/success tests have been done. */
|
|
||||||
if (tile_cleared) DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
||||||
|
|
||||||
switch (GetTileType(tile)) {
|
switch (GetTileType(tile)) {
|
||||||
case MP_ROAD: {
|
case MP_ROAD: {
|
||||||
RoadTileType rtt = GetRoadTileType(tile);
|
RoadTileType rtt = GetRoadTileType(tile);
|
||||||
|
|
Loading…
Reference in New Issue