Get all cells covered by the building, optionally including those covered by OccupyHeight.
| 410 | |
| 411 | // Get all cells covered by the building, optionally including those covered by OccupyHeight. |
| 412 | const std::vector<CellStruct> BuildingExt::GetFoundationCells(BuildingClass* const pThis, CellStruct const baseCoords, bool includeOccupyHeight) |
| 413 | { |
| 414 | const CellStruct foundationEnd = { 0x7FFF, 0x7FFF }; |
| 415 | auto const pFoundation = pThis->GetFoundationData(false); |
| 416 | |
| 417 | int occupyHeight = includeOccupyHeight ? pThis->Type->OccupyHeight : 1; |
| 418 | |
| 419 | if (occupyHeight <= 0) |
| 420 | occupyHeight = 1; |
| 421 | |
| 422 | auto pCellIterator = pFoundation; |
| 423 | |
| 424 | while (*pCellIterator != foundationEnd) |
| 425 | ++pCellIterator; |
| 426 | |
| 427 | std::vector<CellStruct> foundationCells; |
| 428 | foundationCells.reserve(static_cast<int>(std::distance(pFoundation, pCellIterator + 1)) * occupyHeight); |
| 429 | pCellIterator = pFoundation; |
| 430 | |
| 431 | while (*pCellIterator != foundationEnd) |
| 432 | { |
| 433 | auto actualCell = baseCoords + *pCellIterator; |
| 434 | |
| 435 | for (auto i = occupyHeight; i > 0; --i) |
| 436 | { |
| 437 | foundationCells.emplace_back(actualCell); |
| 438 | --actualCell.X; |
| 439 | --actualCell.Y; |
| 440 | } |
| 441 | ++pCellIterator; |
| 442 | } |
| 443 | |
| 444 | std::sort(foundationCells.begin(), foundationCells.end(), |
| 445 | [](const CellStruct& lhs, const CellStruct& rhs) -> bool |
| 446 | { |
| 447 | return lhs.X > rhs.X || lhs.X == rhs.X && lhs.Y > rhs.Y; |
| 448 | }); |
| 449 | |
| 450 | auto const it = std::unique(foundationCells.begin(), foundationCells.end()); |
| 451 | foundationCells.erase(it, foundationCells.end()); |
| 452 | |
| 453 | return foundationCells; |
| 454 | } |
| 455 | |
| 456 | // ============================= |
| 457 | // load / save |