* Prepare the site where a building is about to be put down. * * This function performs some basic sanity checks, and implements the * auto-bulldoze functionality to prepare the site. * All effects are stored in the \a effects object. * * @param leftX Position of left column of tiles of the building. * @param topY Position of top row of tiles of the building. * @param sizeX Horiz
| 647 | * @return: Result of preparation. |
| 648 | */ |
| 649 | ToolResult Micropolis::prepareBuildingSite(int leftX, int topY, |
| 650 | int sizeX, int sizeY, |
| 651 | ToolEffects *effects) |
| 652 | { |
| 653 | // Check that the entire site is on the map |
| 654 | if (leftX < 0 || leftX + sizeX > WORLD_W) { |
| 655 | return TOOLRESULT_FAILED; |
| 656 | } |
| 657 | if (topY < 0 || topY + sizeY > WORLD_H) { |
| 658 | return TOOLRESULT_FAILED; |
| 659 | } |
| 660 | |
| 661 | // Check whether the tiles are clear |
| 662 | for (int dy = 0; dy < sizeY; dy++) { |
| 663 | int posY = topY + dy; |
| 664 | |
| 665 | for (int dx = 0; dx < sizeX; dx++) { |
| 666 | int posX = leftX + dx; |
| 667 | |
| 668 | unsigned short tileValue = effects->getMapTile(posX, posY); |
| 669 | |
| 670 | if (tileValue == DIRT) { // DIRT tile is buidable |
| 671 | continue; |
| 672 | } |
| 673 | |
| 674 | if (!autoBulldoze) { |
| 675 | // No DIRT and no bull-dozer => not buildable |
| 676 | return TOOLRESULT_NEED_BULLDOZE; |
| 677 | } |
| 678 | if (!tally(tileValue)) { |
| 679 | // tilevalue cannot be auto-bulldozed |
| 680 | return TOOLRESULT_NEED_BULLDOZE; |
| 681 | } |
| 682 | |
| 683 | effects->setMapValue(posX, posY, DIRT); |
| 684 | effects->addCost(gCostOf[TOOL_BULLDOZER]); |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | return TOOLRESULT_OK; |
| 689 | } |
| 690 | |
| 691 | |
| 692 | /** |
nothing calls this directly
no test coverage detected