MCPcopy Create free account
hub / github.com/SimHacker/micropolis / prepareBuildingSite

Method prepareBuildingSite

MicropolisCore/src/MicropolisEngine/src/tool.cpp:649–689  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

647 * @return: Result of preparation.
648 */
649ToolResult 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/**

Callers

nothing calls this directly

Calls 4

tallyFunction · 0.85
getMapTileMethod · 0.80
addCostMethod · 0.80
setMapValueMethod · 0.60

Tested by

no test coverage detected