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

Method useSpawner

game/state/battle/battleunit.cpp:4597–4654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4595}
4596
4597bool BattleUnit::useSpawner(GameState &state, const AEquipmentType &item)
4598{
4599 std::list<Vec3<int>> posToCheck;
4600 Vec3<int> curPos = position;
4601 posToCheck.push_back(curPos + Vec3<int>{1, 0, 0});
4602 posToCheck.push_back(curPos + Vec3<int>{0, 1, 0});
4603 posToCheck.push_back(curPos + Vec3<int>{-1, 0, 0});
4604 posToCheck.push_back(curPos + Vec3<int>{0, -1, 0});
4605 posToCheck.push_back(curPos + Vec3<int>{1, 1, 0});
4606 posToCheck.push_back(curPos + Vec3<int>{1, -1, 0});
4607 posToCheck.push_back(curPos + Vec3<int>{-1, 1, 0});
4608 posToCheck.push_back(curPos + Vec3<int>{-1, -1, 0});
4609 posToCheck.push_back(curPos + Vec3<int>{2, 0, 0});
4610 posToCheck.push_back(curPos + Vec3<int>{0, 2, 0});
4611 posToCheck.push_back(curPos + Vec3<int>{-2, 0, 0});
4612 posToCheck.push_back(curPos + Vec3<int>{0, -2, 0});
4613 std::list<Vec3<int>> posToSpawn;
4614 posToSpawn.push_back(curPos);
4615 int numToSpawn = -1;
4616 for (const auto &entry : item.spawnList)
4617 {
4618 numToSpawn += entry.second;
4619 }
4620 auto &map = tileObject->map;
4621 auto helper = BattleUnitTileHelper(map, *this);
4622 while (numToSpawn > 0 && !posToCheck.empty())
4623 {
4624 auto pos = posToCheck.front();
4625 posToCheck.pop_front();
4626 if (!map.tileIsValid(pos))
4627 {
4628 continue;
4629 }
4630 if (state.current_battle->findShortestPath(curPos, pos, helper, false, false, true, 0, true)
4631 .back() == pos)
4632 {
4633 numToSpawn--;
4634 posToSpawn.push_back(pos);
4635 }
4636 }
4637 auto aliens = state.getAliens();
4638 for (const auto &entry : item.spawnList)
4639 {
4640 for (int i = 0; i < entry.second; i++)
4641 {
4642 if (posToSpawn.empty())
4643 {
4644 break;
4645 }
4646 auto pos = posToSpawn.front();
4647 posToSpawn.pop_front();
4648 state.current_battle->spawnUnit(state, aliens, entry.first,
4649 {pos.x + 0.5f, pos.y + 0.5f, pos.z + 0.1f}, facing,
4650 BodyState::Standing);
4651 }
4652 }
4653 return true;
4654}

Callers

nothing calls this directly

Calls 6

emptyMethod · 0.80
tileIsValidMethod · 0.80
getAliensMethod · 0.80
spawnUnitMethod · 0.80
findShortestPathMethod · 0.45

Tested by

no test coverage detected