* Returns if a certain facility can be successfully * placed on the currently selected square. * @param rule Facility type. * @return True if placeable, False otherwise. */
| 195 | * @return True if placeable, False otherwise. |
| 196 | */ |
| 197 | bool BaseView::isPlaceable(RuleBaseFacility *rule) const |
| 198 | { |
| 199 | // Check if square isn't occupied |
| 200 | for (int y = _gridY; y < _gridY + rule->getSize(); ++y) |
| 201 | { |
| 202 | for (int x = _gridX; x < _gridX + rule->getSize(); ++x) |
| 203 | { |
| 204 | if (x < 0 || x >= BASE_SIZE || y < 0 || y >= BASE_SIZE) |
| 205 | { |
| 206 | return false; |
| 207 | } |
| 208 | if (_facilities[x][y] != 0) |
| 209 | { |
| 210 | return false; |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | bool bq=Options::allowBuildingQueue; |
| 216 | |
| 217 | // Check for another facility to connect to |
| 218 | for (int i = 0; i < rule->getSize(); ++i) |
| 219 | { |
| 220 | if ((_gridX > 0 && _facilities[_gridX - 1][_gridY + i] != 0 && (bq || _facilities[_gridX - 1][_gridY + i]->getBuildTime() == 0)) || |
| 221 | (_gridY > 0 && _facilities[_gridX + i][_gridY - 1] != 0 && (bq || _facilities[_gridX + i][_gridY - 1]->getBuildTime() == 0)) || |
| 222 | (_gridX + rule->getSize() < BASE_SIZE && _facilities[_gridX + rule->getSize()][_gridY + i] != 0 && (bq || _facilities[_gridX + rule->getSize()][_gridY + i]->getBuildTime() == 0)) || |
| 223 | (_gridY + rule->getSize() < BASE_SIZE && _facilities[_gridX + i][_gridY + rule->getSize()] != 0 && (bq || _facilities[_gridX + i][_gridY + rule->getSize()]->getBuildTime() == 0))) |
| 224 | { |
| 225 | return true; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Returns if the placed facility is placed in queue or not. |
no test coverage detected