| 99 | } |
| 100 | |
| 101 | static bool updateIndustrialSurface(SurfaceElement& elSurface, const World::Pos2 loc) |
| 102 | { |
| 103 | auto* industry = IndustryManager::get(elSurface.industryId()); |
| 104 | auto* industryObj = industry->getObject(); |
| 105 | if (industryObj->hasFlags(IndustryObjectFlags::builtOnSnow) && elSurface.snowCoverage() < 4) |
| 106 | { |
| 107 | TileManager::removeSurfaceIndustry(loc); |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | if (elSurface.getGrowthStage() != industryObj->farmTileGrowthStageNoProduction || elSurface.getGrowthStage() == 0) |
| 112 | { |
| 113 | elSurface.setUpdateTimer(elSurface.getUpdateTimer() + 1); |
| 114 | if (elSurface.getUpdateTimer() == 0) |
| 115 | { |
| 116 | uint8_t newGrowthStage = elSurface.getGrowthStage() + 1; |
| 117 | if (newGrowthStage >= industryObj->farmTileNumGrowthStages) |
| 118 | { |
| 119 | newGrowthStage = 0; |
| 120 | } |
| 121 | elSurface.setGrowthStage(newGrowthStage); |
| 122 | Ui::ViewportManager::invalidate(loc, elSurface.baseHeight(), elSurface.baseHeight()); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | SurfaceElement* surf = &elSurface; |
| 127 | bool tileAddedRemoved = false; |
| 128 | for (auto i = 0; i < 4; ++i) |
| 129 | { |
| 130 | // This loop looks for walls on either sides of the surface tile being updated |
| 131 | // |
| 132 | // | N | |
| 133 | // | 2 | |
| 134 | // --- | ----- | --- |
| 135 | // | 1 | |
| 136 | // N 2 | 1 X 1 | 2 N |
| 137 | // | 1 | |
| 138 | // --- | ----- | --- |
| 139 | // | 2 | |
| 140 | // | N | |
| 141 | // |
| 142 | // N == Neighbour tile (this loop) |
| 143 | // X == Surface being updated |
| 144 | // 1 == Potential wall on surface being updated |
| 145 | // 2 == Potential wall on Neighbour tile (this loop) |
| 146 | |
| 147 | auto* elWall = getWallElement(loc, surf->baseZ(), surf->baseZ() + 16, i); |
| 148 | if (elWall) |
| 149 | { |
| 150 | // Wall has been found on this surface tile. |
| 151 | // Validate if it should be here and if not |
| 152 | // remove it |
| 153 | if (surf->getGrowthStage() != industryObj->farmTileGrowthStageNoProduction) |
| 154 | { |
| 155 | continue; |
| 156 | } |
| 157 | const auto nextLoc = loc + kRotationOffset[i]; |
| 158 | if (!validCoords(nextLoc)) |
no test coverage detected