Created
January 15, 2022 03:12
-
-
Save Rseding91/04a119255c1a66f448287d925221ff47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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