src/road_cmd.cpp
changeset 8230 64f28fe2d5c8
parent 8224 c5a64d87cc54
child 8232 a4883a0598db
equal deleted inserted replaced
8229:00e7467ceeee 8230:64f28fe2d5c8
   112 
   112 
   113 	/* true if the roadpiece was always removeable,
   113 	/* true if the roadpiece was always removeable,
   114 	 * false if it was a center piece. Affects town ratings drop */
   114 	 * false if it was a center piece. Affects town ratings drop */
   115 	bool edge_road;
   115 	bool edge_road;
   116 
   116 
   117 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
       
   118 
       
   119 	RoadType rt = (RoadType)GB(p1, 4, 2);
   117 	RoadType rt = (RoadType)GB(p1, 4, 2);
   120 	if (!IsValidRoadType(rt)) return CMD_ERROR;
   118 	if (!IsValidRoadType(rt)) return CMD_ERROR;
   121 
   119 
   122 	Town *t = NULL;
   120 	Town *t = NULL;
   123 	switch (GetTileType(tile)) {
   121 	switch (GetTileType(tile)) {
   154 
   152 
   155 	if (!IsTileType(tile, MP_ROAD)) {
   153 	if (!IsTileType(tile, MP_ROAD)) {
   156 		/* If it's the last roadtype, just clear the whole tile */
   154 		/* If it's the last roadtype, just clear the whole tile */
   157 		if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   155 		if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   158 
   156 
   159 		CommandCost cost;
   157 		CommandCost cost(EXPENSES_CONSTRUCTION);
   160 		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
   158 		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
   161 			TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
   159 			TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
   162 			/* Pay for *every* tile of the bridge or tunnel */
   160 			/* Pay for *every* tile of the bridge or tunnel */
   163 			cost.AddCost((DistanceManhattan(other_end, tile) + 1) * _price.remove_road);
   161 			cost.AddCost((DistanceManhattan(other_end, tile) + 1) * _price.remove_road);
   164 			if (flags & DC_EXEC) {
   162 			if (flags & DC_EXEC) {
   179 			if (flags & DC_EXEC) {
   177 			if (flags & DC_EXEC) {
   180 				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
   178 				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
   181 				MarkTileDirtyByTile(tile);
   179 				MarkTileDirtyByTile(tile);
   182 			}
   180 			}
   183 		}
   181 		}
   184 		return CommandCost(cost);
   182 		return cost;
   185 	}
   183 	}
   186 
   184 
   187 	switch (GetRoadTileType(tile)) {
   185 	switch (GetRoadTileType(tile)) {
   188 		case ROAD_TILE_NORMAL: {
   186 		case ROAD_TILE_NORMAL: {
   189 			RoadBits present = GetRoadBits(tile, rt);
   187 			RoadBits present = GetRoadBits(tile, rt);
   222 					if (rt != ROADTYPE_TRAM) SetDisallowedRoadDirections(tile, DRD_NONE);
   220 					if (rt != ROADTYPE_TRAM) SetDisallowedRoadDirections(tile, DRD_NONE);
   223 					SetRoadBits(tile, present, rt);
   221 					SetRoadBits(tile, present, rt);
   224 					MarkTileDirtyByTile(tile);
   222 					MarkTileDirtyByTile(tile);
   225 				}
   223 				}
   226 			}
   224 			}
   227 			return CommandCost(CountBits(c) * _price.remove_road);
   225 			return CommandCost(EXPENSES_CONSTRUCTION, CountBits(c) * _price.remove_road);
   228 		}
   226 		}
   229 
   227 
   230 		case ROAD_TILE_CROSSING: {
   228 		case ROAD_TILE_CROSSING: {
   231 			if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
   229 			if (pieces & ComplementRoadBits(GetCrossingRoadBits(tile))) {
   232 				return CMD_ERROR;
   230 				return CMD_ERROR;
   248 					SetRoadTypes(tile, rts);
   246 					SetRoadTypes(tile, rts);
   249 				}
   247 				}
   250 				MarkTileDirtyByTile(tile);
   248 				MarkTileDirtyByTile(tile);
   251 				YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
   249 				YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
   252 			}
   250 			}
   253 			return CommandCost(_price.remove_road * 2);
   251 			return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road * 2);
   254 		}
   252 		}
   255 
   253 
   256 		default:
   254 		default:
   257 		case ROAD_TILE_DEPOT:
   255 		case ROAD_TILE_DEPOT:
   258 			return CMD_ERROR;
   256 			return CMD_ERROR;
   344 	if (IsSteepSlope(tileh)) {
   342 	if (IsSteepSlope(tileh)) {
   345 		/* Force straight roads. */
   343 		/* Force straight roads. */
   346 		*pieces |= MirrorRoadBits(*pieces);
   344 		*pieces |= MirrorRoadBits(*pieces);
   347 
   345 
   348 		if (existing == ROAD_NONE || existing == *pieces) {
   346 		if (existing == ROAD_NONE || existing == *pieces) {
   349 			if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
   347 			if (*pieces == ROAD_X || *pieces == ROAD_Y) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
   350 		}
   348 		}
   351 		return CMD_ERROR;
   349 		return CMD_ERROR;
   352 	}
   350 	}
   353 
   351 
   354 	RoadBits road_bits = *pieces | existing;
   352 	RoadBits road_bits = *pieces | existing;
   356 	/* Single bits on slopes.
   354 	/* Single bits on slopes.
   357 	 * We check for the roads that need at least 2 bits */
   355 	 * We check for the roads that need at least 2 bits */
   358 	if (_patches.build_on_slopes && !_is_old_ai_player &&
   356 	if (_patches.build_on_slopes && !_is_old_ai_player &&
   359 			existing == ROAD_NONE && CountBits(*pieces) == 1 &&
   357 			existing == ROAD_NONE && CountBits(*pieces) == 1 &&
   360 			(_valid_tileh_slopes_road[2][tileh] & *pieces) == ROAD_NONE) {
   358 			(_valid_tileh_slopes_road[2][tileh] & *pieces) == ROAD_NONE) {
   361 		return CommandCost(_price.terraform);
   359 		return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
   362 	}
   360 	}
   363 
   361 
   364 	/* no special foundation */
   362 	/* no special foundation */
   365 	if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == ROAD_NONE) {
   363 	if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == ROAD_NONE) {
   366 		/* force that all bits are set when we have slopes */
   364 		/* force that all bits are set when we have slopes */
   368 		return CommandCost(); // no extra cost
   366 		return CommandCost(); // no extra cost
   369 	}
   367 	}
   370 
   368 
   371 	/* foundation is used. Whole tile is leveled up */
   369 	/* foundation is used. Whole tile is leveled up */
   372 	if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == ROAD_NONE) {
   370 	if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == ROAD_NONE) {
   373 		return CommandCost(existing != ROAD_NONE ? (Money)0 : _price.terraform);
   371 		return CommandCost(EXPENSES_CONSTRUCTION, existing != ROAD_NONE ? (Money)0 : _price.terraform);
   374 	}
   372 	}
   375 
   373 
   376 	/* Force straight roads. */
   374 	/* Force straight roads. */
   377 	*pieces |= MirrorRoadBits(*pieces);
   375 	*pieces |= MirrorRoadBits(*pieces);
   378 
   376 
   379 	/* partly leveled up tile, only if there's no road on that tile */
   377 	/* partly leveled up tile, only if there's no road on that tile */
   380 	if ((existing == ROAD_NONE || existing == *pieces) && (tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)) {
   378 	if ((existing == ROAD_NONE || existing == *pieces) && (tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)) {
   381 		if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
   379 		if (*pieces == ROAD_X || *pieces == ROAD_Y) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
   382 	}
   380 	}
   383 	return CMD_ERROR;
   381 	return CMD_ERROR;
   384 }
   382 }
   385 
   383 
   386 /** Build a piece of road.
   384 /** Build a piece of road.
   391  *           bit 6..7 disallowed directions to toggle
   389  *           bit 6..7 disallowed directions to toggle
   392  * @param p2 the town that is building the road (0 if not applicable)
   390  * @param p2 the town that is building the road (0 if not applicable)
   393  */
   391  */
   394 CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   392 CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   395 {
   393 {
   396 	CommandCost cost;
   394 	CommandCost cost(EXPENSES_CONSTRUCTION);
   397 	CommandCost ret;
   395 	CommandCost ret;
   398 	RoadBits existing = ROAD_NONE;
   396 	RoadBits existing = ROAD_NONE;
   399 	RoadBits all_bits = ROAD_NONE;
   397 	RoadBits all_bits = ROAD_NONE;
   400 	Slope tileh;
   398 	Slope tileh;
   401 
       
   402 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
       
   403 
   399 
   404 	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
   400 	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
   405 	 * if a non-player is building the road */
   401 	 * if a non-player is building the road */
   406 	if ((IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
   402 	if ((IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
   407 
   403 
   492 				YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
   488 				YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
   493 				/* Always add road to the roadtypes (can't draw without it) */
   489 				/* Always add road to the roadtypes (can't draw without it) */
   494 				MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
   490 				MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
   495 				MarkTileDirtyByTile(tile);
   491 				MarkTileDirtyByTile(tile);
   496 			}
   492 			}
   497 			return CommandCost(_price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
   493 			return CommandCost(EXPENSES_CONSTRUCTION, _price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
   498 		}
   494 		}
   499 
   495 
   500 		case MP_STATION:
   496 		case MP_STATION:
   501 			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
   497 			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
   502 			if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
   498 			if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
   602  * - p2 = (bit 5) - set road direction
   598  * - p2 = (bit 5) - set road direction
   603  */
   599  */
   604 CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   600 CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   605 {
   601 {
   606 	TileIndex start_tile, tile;
   602 	TileIndex start_tile, tile;
   607 	CommandCost cost, ret;
   603 	CommandCost ret, cost(EXPENSES_CONSTRUCTION);
   608 	bool had_bridge = false;
   604 	bool had_bridge = false;
   609 	bool had_tunnel = false;
   605 	bool had_tunnel = false;
   610 	bool had_success = false;
   606 	bool had_success = false;
   611 	DisallowedRoadDirections drd = DRD_NORTHBOUND;
   607 	DisallowedRoadDirections drd = DRD_NORTHBOUND;
   612 
       
   613 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
       
   614 
   608 
   615 	if (p1 >= MapSize()) return CMD_ERROR;
   609 	if (p1 >= MapSize()) return CMD_ERROR;
   616 
   610 
   617 	start_tile = p1;
   611 	start_tile = p1;
   618 	RoadType rt = (RoadType)GB(p2, 3, 2);
   612 	RoadType rt = (RoadType)GB(p2, 3, 2);
   689  * - p2 = (bit 3 + 4) - road type
   683  * - p2 = (bit 3 + 4) - road type
   690  */
   684  */
   691 CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   685 CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   692 {
   686 {
   693 	TileIndex start_tile, tile;
   687 	TileIndex start_tile, tile;
   694 	CommandCost cost, ret, money;
   688 	CommandCost ret, cost(EXPENSES_CONSTRUCTION);
   695 
   689 	Money money;
   696 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
       
   697 
   690 
   698 	if (p1 >= MapSize()) return CMD_ERROR;
   691 	if (p1 >= MapSize()) return CMD_ERROR;
   699 
   692 
   700 	start_tile = p1;
   693 	start_tile = p1;
   701 	RoadType rt = (RoadType)GB(p2, 3, 2);
   694 	RoadType rt = (RoadType)GB(p2, 3, 2);
   711 		start_tile = end_tile;
   704 		start_tile = end_tile;
   712 		end_tile = t;
   705 		end_tile = t;
   713 		p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
   706 		p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
   714 	}
   707 	}
   715 
   708 
   716 	money.AddCost(GetAvailableMoneyForCommand());
   709 	money = GetAvailableMoneyForCommand();
   717 	tile = start_tile;
   710 	tile = start_tile;
   718 	/* Start tile is the small number. */
   711 	/* Start tile is the small number. */
   719 	for (;;) {
   712 	for (;;) {
   720 		RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
   713 		RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
   721 
   714 
   725 		/* try to remove the halves. */
   718 		/* try to remove the halves. */
   726 		if (bits != 0) {
   719 		if (bits != 0) {
   727 			ret = DoCommand(tile, rt << 4 | bits, 0, flags & ~DC_EXEC, CMD_REMOVE_ROAD);
   720 			ret = DoCommand(tile, rt << 4 | bits, 0, flags & ~DC_EXEC, CMD_REMOVE_ROAD);
   728 			if (CmdSucceeded(ret)) {
   721 			if (CmdSucceeded(ret)) {
   729 				if (flags & DC_EXEC) {
   722 				if (flags & DC_EXEC) {
   730 					money.AddCost(-ret.GetCost());
   723 					money -= ret.GetCost();
   731 					if (money.GetCost() < 0) {
   724 					if (money < 0) {
   732 						_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
   725 						_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
   733 						return cost;
   726 						return cost;
   734 					}
   727 					}
   735 					DoCommand(tile, rt << 4 | bits, 0, flags, CMD_REMOVE_ROAD);
   728 					DoCommand(tile, rt << 4 | bits, 0, flags, CMD_REMOVE_ROAD);
   736 				}
   729 				}
   759 CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   752 CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   760 {
   753 {
   761 	CommandCost cost;
   754 	CommandCost cost;
   762 	Slope tileh;
   755 	Slope tileh;
   763 
   756 
   764 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
       
   765 
       
   766 	DiagDirection dir = Extract<DiagDirection, 0>(p1);
   757 	DiagDirection dir = Extract<DiagDirection, 0>(p1);
   767 	RoadType rt = (RoadType)GB(p1, 2, 2);
   758 	RoadType rt = (RoadType)GB(p1, 2, 2);
   768 
   759 
   769 	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
   760 	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
   770 
   761 
   806 	if (flags & DC_EXEC) {
   797 	if (flags & DC_EXEC) {
   807 		DoClearSquare(tile);
   798 		DoClearSquare(tile);
   808 		delete GetDepotByTile(tile);
   799 		delete GetDepotByTile(tile);
   809 	}
   800 	}
   810 
   801 
   811 	return CommandCost(_price.remove_road_depot);
   802 	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_road_depot);
   812 }
   803 }
   813 
   804 
   814 static CommandCost ClearTile_Road(TileIndex tile, byte flags)
   805 static CommandCost ClearTile_Road(TileIndex tile, byte flags)
   815 {
   806 {
   816 	switch (GetRoadTileType(tile)) {
   807 	switch (GetRoadTileType(tile)) {
   822 			if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) ||
   813 			if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) ||
   823 			    ((flags & DC_AI_BUILDING) && IsTileOwner(tile, OWNER_TOWN)) ||
   814 			    ((flags & DC_AI_BUILDING) && IsTileOwner(tile, OWNER_TOWN)) ||
   824 			    !(flags & DC_AUTO)
   815 			    !(flags & DC_AUTO)
   825 				) {
   816 				) {
   826 				RoadTypes rts = GetRoadTypes(tile);
   817 				RoadTypes rts = GetRoadTypes(tile);
   827 				CommandCost ret;
   818 				CommandCost ret(EXPENSES_CONSTRUCTION);
   828 				for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
   819 				for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
   829 					if (HasBit(rts, rt)) {
   820 					if (HasBit(rts, rt)) {
   830 						CommandCost tmp_ret = DoCommand(tile, rt << 4 | GetRoadBits(tile, rt), 0, flags, CMD_REMOVE_ROAD);
   821 						CommandCost tmp_ret = DoCommand(tile, rt << 4 | GetRoadBits(tile, rt), 0, flags, CMD_REMOVE_ROAD);
   831 						if (CmdFailed(tmp_ret)) return tmp_ret;
   822 						if (CmdFailed(tmp_ret)) return tmp_ret;
   832 						ret.AddCost(tmp_ret);
   823 						ret.AddCost(tmp_ret);
   837 			return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
   828 			return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
   838 		}
   829 		}
   839 
   830 
   840 		case ROAD_TILE_CROSSING: {
   831 		case ROAD_TILE_CROSSING: {
   841 			RoadTypes rts = GetRoadTypes(tile);
   832 			RoadTypes rts = GetRoadTypes(tile);
   842 			CommandCost ret;
   833 			CommandCost ret(EXPENSES_CONSTRUCTION);
   843 
   834 
   844 			if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
   835 			if (flags & DC_AUTO) return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
   845 
   836 
   846 			/* Must iterate over the roadtypes in a reverse manner because
   837 			/* Must iterate over the roadtypes in a reverse manner because
   847 			 * tram tracks must be removed before the road bits. */
   838 			 * tram tracks must be removed before the road bits. */
  1418 static CommandCost TerraformTile_Road(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
  1409 static CommandCost TerraformTile_Road(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
  1419 {
  1410 {
  1420 	if (_patches.build_on_slopes && AutoslopeEnabled()) {
  1411 	if (_patches.build_on_slopes && AutoslopeEnabled()) {
  1421 		switch (GetRoadTileType(tile)) {
  1412 		switch (GetRoadTileType(tile)) {
  1422 			case ROAD_TILE_CROSSING:
  1413 			case ROAD_TILE_CROSSING:
  1423 				if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return _price.terraform;
  1414 				if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
  1424 				break;
  1415 				break;
  1425 
  1416 
  1426 			case ROAD_TILE_DEPOT:
  1417 			case ROAD_TILE_DEPOT:
  1427 				if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return _price.terraform;
  1418 				if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
  1428 				break;
  1419 				break;
  1429 
  1420 
  1430 			case ROAD_TILE_NORMAL: {
  1421 			case ROAD_TILE_NORMAL: {
  1431 				RoadBits bits = GetAllRoadBits(tile);
  1422 				RoadBits bits = GetAllRoadBits(tile);
  1432 				RoadBits bits_copy = bits;
  1423 				RoadBits bits_copy = bits;
  1440 						/* Get the slope on top of the foundation */
  1431 						/* Get the slope on top of the foundation */
  1441 						z_old += ApplyFoundationToSlope(GetRoadFoundation(tileh_old, bits), &tileh_old);
  1432 						z_old += ApplyFoundationToSlope(GetRoadFoundation(tileh_old, bits), &tileh_old);
  1442 						z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), &tileh_new);
  1433 						z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), &tileh_new);
  1443 
  1434 
  1444 						/* The surface slope must not be changed */
  1435 						/* The surface slope must not be changed */
  1445 						if ((z_old == z_new) && (tileh_old == tileh_new)) return _price.terraform;
  1436 						if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
  1446 					}
  1437 					}
  1447 				}
  1438 				}
  1448 				break;
  1439 				break;
  1449 			}
  1440 			}
  1450 
  1441