getMissionClusters
Definition
-- @/lua/ge/extensions/gameplay/missions/startTrigger.lua:138
local function getMissionClusters(mergeRadius)
if not missionClusterCacheByRadius[mergeRadius or -1] then
-- first get all mission locations, sorted in buckets by level
local missions = gameplay_missions_missions.get()
local locationsByLevel = {}
for _, m in ipairs(missions) do
local isVisible = true -- gameplay_missions_missionManager.isVisible(m)
if isVisible then
local locs = gameplay_missions_missions.getLocations(m)
for i, l in ipairs(locs) do
if l.type == 'coordinates' then
l.id = m.id.."-"..i
l.missionId = m.id
locationsByLevel[l.level] = locationsByLevel[l.level] or {}
table.insert(locationsByLevel[l.level], l)
end
end
end
end
-- get the clusters for each level
local allClusters = {}
local cluster = {}
for level, locations in pairs(locationsByLevel) do
local qt = quadtree.newQuadtree()
table.sort(locations, idSort)
local count = 0
for i, loc in ipairs(locations) do
qt:preLoad(i, quadtree.pointBBox(loc.pos.x, loc.pos.y, (mergeRadius or loc.radius)))
count = i
end
qt:build()
-- go from the start to the end of the list
for index = 1, count do
local cur = locations[index]
if cur then
table.clear(cluster)
-- find all the locations that potentially overlap with cur, and get all the ones that actually overlap into cluster list
for id in qt:query(quadtree.pointBBox(cur.pos.x, cur.pos.y, mergeRadius or cur.radius)) do
local candidate = locations[id]
candidate._qtId = id
if cur.pos:squaredDistance(candidate.pos) < square(cur.radius+(mergeRadius or candidate.radius)) then
table.insert(cluster, candidate)
end
end
-- remove all the elements in the cluster from the qt and the locations list
for _, c in ipairs(cluster) do
qt:remove(c._qtId, locations[c._qtId].pos.x, locations[c._qtId].pos.y)
locations[c._qtId] = false
end
table.sort(cluster, idSort)
merge(allClusters, cluster, mergeRadius)
end
end
end
missionClusterCacheByRadius[mergeRadius or -1] = allClusters
end
return missionClusterCacheByRadius[mergeRadius or -1]
end
Callers