/* Answer whether the faction both contains the sysPath, and has a homeworld closer than the passed distance. if it is, then the passed distance will also be updated to be the distance from the factions homeworld to the sysPath. */ const bool Faction::IsCloserAndContains(double& closestFactionDist, const Sector sec, Uint32 sysIndex) { /* Treat factions without homeworlds as if they are of effectively infinite radius, so every world is potentially within their borders, but also treat them as if they had a homeworld that was infinitely far away, so every other faction has a better claim. */ float distance = HUGE_VAL; bool inside = true; /* Factions that have a homeworld... */ if (hasHomeworld) { /* ...automatically gain the allegiance of worlds within the same sector... */ if (sec.Contains(homeworld)) { distance = 0; } /* ...otherwise we need to calculate whether the world is inside the the faction border, and how far away it is. */ else { if (!m_homesector) m_homesector = new Sector(homeworld.sectorX, homeworld.sectorY, homeworld.sectorZ); distance = Sector::DistanceBetween(m_homesector, homeworld.systemIndex, &sec, sysIndex); inside = distance < Radius(); } } /* if the faction contains the world, and its homeworld is closer, then this faction wins, and we update the closestFactionDist */ if (inside && (distance <= closestFactionDist)) { closestFactionDist = distance; return true; /* otherwise this isn't the faction we were looking for */ } else { return false; } }