* Calculate the costs for roads on slopes * Aside modify the RoadBits to fit on the slopes * * @note The RoadBits are modified too! * @param tileh The current slope * @param pieces The RoadBits we want to add * @param existing The existent RoadBits of the current type * @param other The other existent RoadBits * @return The costs for these RoadBits on this slope */
| 532 | * @return The costs for these RoadBits on this slope |
| 533 | */ |
| 534 | static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existing, RoadBits other) |
| 535 | { |
| 536 | /* Remove already build pieces */ |
| 537 | *pieces &= ~existing; |
| 538 | |
| 539 | /* If we can't build anything stop here */ |
| 540 | if (*pieces == ROAD_NONE) return CMD_ERROR; |
| 541 | |
| 542 | /* All RoadBit combos are valid on flat land */ |
| 543 | if (tileh == SLOPE_FLAT) return CommandCost(); |
| 544 | |
| 545 | /* Steep slopes behave the same as slopes with one corner raised. */ |
| 546 | if (IsSteepSlope(tileh)) { |
| 547 | tileh = SlopeWithOneCornerRaised(GetHighestSlopeCorner(tileh)); |
| 548 | } |
| 549 | |
| 550 | /* Save the merge of all bits of the current type */ |
| 551 | RoadBits type_bits = existing | *pieces; |
| 552 | |
| 553 | /* Roads on slopes */ |
| 554 | if (_settings_game.construction.build_on_slopes && (_invalid_tileh_slopes_road[0][tileh] & (other | type_bits)) == ROAD_NONE) { |
| 555 | |
| 556 | /* If we add leveling we've got to pay for it */ |
| 557 | if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); |
| 558 | |
| 559 | return CommandCost(); |
| 560 | } |
| 561 | |
| 562 | /* Autocomplete uphill roads */ |
| 563 | *pieces |= MirrorRoadBits(*pieces); |
| 564 | type_bits = existing | *pieces; |
| 565 | |
| 566 | /* Uphill roads */ |
| 567 | if (IsStraightRoad(type_bits) && (other == type_bits || other == ROAD_NONE) && |
| 568 | (_invalid_tileh_slopes_road[1][tileh] & (other | type_bits)) == ROAD_NONE) { |
| 569 | |
| 570 | /* Slopes with foundation ? */ |
| 571 | if (IsSlopeWithOneCornerRaised(tileh)) { |
| 572 | |
| 573 | /* Prevent build on slopes if it isn't allowed */ |
| 574 | if (_settings_game.construction.build_on_slopes) { |
| 575 | |
| 576 | /* If we add foundation we've got to pay for it */ |
| 577 | if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); |
| 578 | |
| 579 | return CommandCost(); |
| 580 | } |
| 581 | } else { |
| 582 | if (HasExactlyOneBit(existing) && GetRoadFoundation(tileh, existing) == FOUNDATION_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); |
| 583 | return CommandCost(); |
| 584 | } |
| 585 | } |
| 586 | return CMD_ERROR; |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * Build a piece of road. |
no test coverage detected