Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
void Surface::listFriendlyEntities(const MapPosition& position,
ForceID forceID,
double maxDistance,
std::vector<EntityWithOwner*>& result,
bool onlyUnits)
{
BoundingBox searchingBox(-maxDistance, -maxDistance, maxDistance, maxDistance);
searchingBox += position;
ChunkPosition leftTop(TilePosition(searchingBox.leftTop));
ChunkPosition rightBottom(TilePosition(searchingBox.rightBottom));
const auto collaborators = this->map.forceManager.getCollaborators(forceID);
for (ChunkPosition chunkPosition(leftTop.x, 0); chunkPosition.x <= rightBottom.x; chunkPosition.x++)
for (chunkPosition.y = leftTop.y; chunkPosition.y <= rightBottom.y; chunkPosition.y++)
{
Chunk& chunk = this->getChunk(chunkPosition);
for (ForceID otherForceID : collaborators)
if (auto militaryTargets = chunk.getMilitaryTargetsOptional(otherForceID))
for (EntityWithOwner& entity : *militaryTargets)
if (position.distanceSquared(entity.position) < maxDistance * maxDistance &&
(!onlyUnits || entity.isUnit()))
result.push_back(&entity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment