Skip to content

Instantly share code, notes, and snippets.

@Rseding91
Created January 15, 2022 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rseding91/04a119255c1a66f448287d925221ff47 to your computer and use it in GitHub Desktop.
Save Rseding91/04a119255c1a66f448287d925221ff47 to your computer and use it in GitHub Desktop.
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