| 239 | } |
| 240 | |
| 241 | Base::BuildError Base::canBuildFacility(StateRef<FacilityType> type, Vec2<int> pos, bool free) const |
| 242 | { |
| 243 | if (pos.x < 0 || pos.y < 0 || pos.x + type->size > SIZE || pos.y + type->size > SIZE) |
| 244 | { |
| 245 | return BuildError::OutOfBounds; |
| 246 | } |
| 247 | for (int x = pos.x; x < pos.x + type->size; ++x) |
| 248 | { |
| 249 | for (int y = pos.y; y < pos.y + type->size; ++y) |
| 250 | { |
| 251 | if (!corridors[x][y]) |
| 252 | { |
| 253 | return BuildError::OutOfBounds; |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | for (int x = pos.x; x < pos.x + type->size; ++x) |
| 258 | { |
| 259 | for (int y = pos.y; y < pos.y + type->size; ++y) |
| 260 | { |
| 261 | if (getFacility({x, y}) != nullptr) |
| 262 | { |
| 263 | return BuildError::Occupied; |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | if (!free) |
| 268 | { |
| 269 | if (!building) |
| 270 | { |
| 271 | LogError("Building disappeared"); |
| 272 | return BuildError::OutOfBounds; |
| 273 | } |
| 274 | else if (building->owner->balance - type->buildCost < 0) |
| 275 | { |
| 276 | return BuildError::NoMoney; |
| 277 | } |
| 278 | } |
| 279 | return BuildError::NoError; |
| 280 | } |
| 281 | |
| 282 | void Base::buildFacility(GameState &state, StateRef<FacilityType> type, Vec2<int> pos, bool free) |
| 283 | { |
no outgoing calls
no test coverage detected