| 566 | }; |
| 567 | |
| 568 | void Battle::initialUnitSpawn(GameState &state) |
| 569 | { |
| 570 | class SpawnBlock |
| 571 | { |
| 572 | public: |
| 573 | // true = walker, false = flyer |
| 574 | std::map<bool, std::set<Vec3<int>>> positions; |
| 575 | Vec3<int> start; |
| 576 | Vec3<int> end; |
| 577 | }; |
| 578 | class SpawnKey |
| 579 | { |
| 580 | public: |
| 581 | SpawnType spawnType = SpawnType::Player; |
| 582 | UnitSize unitSize = UnitSize::Small; |
| 583 | UnitMovement unitMovement = UnitMovement::Walking; |
| 584 | bool lowPriority = false; |
| 585 | SpawnKey() = default; |
| 586 | SpawnKey(SpawnType spawnType, UnitSize unitSize, UnitMovement unitMovement, |
| 587 | bool lowPriority) |
| 588 | : spawnType(spawnType), unitSize(unitSize), unitMovement(unitMovement), |
| 589 | lowPriority(lowPriority) |
| 590 | { |
| 591 | } |
| 592 | bool operator<(const SpawnKey &other) const |
| 593 | { |
| 594 | return std::tie(spawnType, unitSize, unitMovement, lowPriority) < |
| 595 | std::tie(other.spawnType, other.unitSize, other.unitMovement, other.lowPriority); |
| 596 | } |
| 597 | }; |
| 598 | |
| 599 | // Spawn maps for specific units of specific orgs |
| 600 | std::map<SpawnKey, std::list<sp<SpawnBlock>>> spawnMaps; |
| 601 | // Spawn maps for units of different type (spawn aliens in civ spots etc.) |
| 602 | std::map<SpawnKey, std::list<sp<SpawnBlock>>> spawnInverse; |
| 603 | // Other blocks that have 0 spawn priority, to be used when all others are exhausted |
| 604 | std::list<sp<SpawnBlock>> spawnOther; |
| 605 | // Spawn types belonging to organisations |
| 606 | // (X-Com -> Player, Security/Alien -> Enemy, Civ -> Civ) |
| 607 | std::map<StateRef<Organisation>, SpawnType> spawnTypeMap; |
| 608 | |
| 609 | // Fill organisation -> spawnType maps |
| 610 | for (auto &o : participants) |
| 611 | { |
| 612 | SpawnType spawnType = SpawnType::Enemy; |
| 613 | if (o == state.getPlayer()) |
| 614 | { |
| 615 | spawnType = SpawnType::Player; |
| 616 | } |
| 617 | else if (o == state.getCivilian()) |
| 618 | { |
| 619 | spawnType = SpawnType::Civilian; |
| 620 | } |
| 621 | spawnTypeMap[o] = spawnType; |
| 622 | } |
| 623 | |
| 624 | // Fill spawn blocks |
| 625 | std::vector<sp<SpawnBlock>> spawnBlocks; |
no test coverage detected