| 2365 | } |
| 2366 | |
| 2367 | static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new) |
| 2368 | { |
| 2369 | if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) { |
| 2370 | switch (GetRoadTileType(tile)) { |
| 2371 | case RoadTileType::Crossing: |
| 2372 | if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); |
| 2373 | break; |
| 2374 | |
| 2375 | case RoadTileType::Depot: |
| 2376 | if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); |
| 2377 | break; |
| 2378 | |
| 2379 | case RoadTileType::Normal: { |
| 2380 | RoadBits bits = GetAllRoadBits(tile); |
| 2381 | RoadBits bits_copy = bits; |
| 2382 | /* Check if the slope-road_bits combination is valid at all, i.e. it is safe to call GetRoadFoundation(). */ |
| 2383 | if (CheckRoadSlope(tileh_new, &bits_copy, ROAD_NONE, ROAD_NONE).Succeeded()) { |
| 2384 | /* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */ |
| 2385 | if (bits == bits_copy) { |
| 2386 | auto [tileh_old, z_old] = GetTileSlopeZ(tile); |
| 2387 | |
| 2388 | /* Get the slope on top of the foundation */ |
| 2389 | z_old += ApplyFoundationToSlope(GetRoadFoundation(tileh_old, bits), tileh_old); |
| 2390 | z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), tileh_new); |
| 2391 | |
| 2392 | /* The surface slope must not be changed */ |
| 2393 | if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); |
| 2394 | } |
| 2395 | } |
| 2396 | break; |
| 2397 | } |
| 2398 | |
| 2399 | default: NOT_REACHED(); |
| 2400 | } |
| 2401 | } |
| 2402 | |
| 2403 | return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile); |
| 2404 | } |
| 2405 | |
| 2406 | /** |
| 2407 | * Checks the tile and returns whether the current player is allowed to convert the roadtype to another roadtype without taking ownership |
nothing calls this directly
no test coverage detected