MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / initialUnitSpawn

Method initialUnitSpawn

game/state/battle/battle.cpp:568–1122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

566};
567
568void 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;

Callers 1

enterBattleMethod · 0.80

Calls 15

pickRandomFunction · 0.85
getPlayerMethod · 0.80
getCivilianMethod · 0.80
getTileMethod · 0.80
getPassableMethod · 0.80
getCanStandMethod · 0.80
emptyMethod · 0.80
removeMethod · 0.80
getRestingPositionMethod · 0.80
isLargeMethod · 0.80
canFlyMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected