Flight Finder: find zones via the continent map
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5f6cdfe6b2
commit
62c016d672
2 changed files with 84 additions and 45 deletions
|
|
@ -104,49 +104,78 @@ local function Project(uiMapID, id)
|
|||
end
|
||||
ns.Project = Project
|
||||
|
||||
-- the map the client places a node on, plus every map above it
|
||||
local chains = {}
|
||||
local function Chain(id)
|
||||
local c = chains[id]
|
||||
if c then
|
||||
return c
|
||||
end
|
||||
local n = ns.nodes[id]
|
||||
c = { maps = {} }
|
||||
local ok, mapID = pcall(C_Map.GetMapPosFromWorldPos, n[1], CreateVector2D(n[2], n[3]))
|
||||
local function Parent(uiMapID)
|
||||
local info = C_Map.GetMapInfo(uiMapID)
|
||||
return info and info.parentMapID ~= 0 and info.parentMapID or nil
|
||||
end
|
||||
|
||||
-- a is b or one of the maps above it
|
||||
local function Above(a, b)
|
||||
for _ = 1, 10 do
|
||||
if not ok or not mapID or mapID == 0 or c.maps[mapID] then
|
||||
break
|
||||
if not b then
|
||||
return false
|
||||
elseif a == b then
|
||||
return true
|
||||
end
|
||||
local info = C_Map.GetMapInfo(mapID)
|
||||
if not info then
|
||||
break
|
||||
end
|
||||
c.maps[mapID] = true
|
||||
c.found = true
|
||||
if not c.zone and info.mapType == Enum.UIMapType.Zone then
|
||||
c.zone = mapID
|
||||
end
|
||||
mapID = info.parentMapID
|
||||
b = Parent(b)
|
||||
end
|
||||
chains[id] = c
|
||||
if log then
|
||||
log.chain[id] = c.zone or (c.found and "no zone") or "not found"
|
||||
return false
|
||||
end
|
||||
|
||||
local continents = {}
|
||||
local function Continent(uiMapID)
|
||||
local cached = continents[uiMapID]
|
||||
if cached == nil then
|
||||
cached = false
|
||||
local m = uiMapID
|
||||
for _ = 1, 10 do
|
||||
local info = m and C_Map.GetMapInfo(m)
|
||||
if not info then
|
||||
break
|
||||
elseif info.mapType == Enum.UIMapType.Continent then
|
||||
cached = m
|
||||
break
|
||||
end
|
||||
m = info.parentMapID
|
||||
end
|
||||
continents[uiMapID] = cached
|
||||
end
|
||||
return c
|
||||
return cached or nil
|
||||
end
|
||||
|
||||
-- The zone a node is in: the one the continent map highlights at its spot. (In Forever,
|
||||
-- C_Map.GetMapPosFromWorldPos only ever answers with the continent.)
|
||||
local zones = {}
|
||||
local function Zone(id, continent)
|
||||
local key = continent * 100000 + id
|
||||
local cached = zones[key]
|
||||
if cached == nil then
|
||||
cached = false
|
||||
local u, v = Project(continent, id)
|
||||
local info = u and C_Map.GetMapInfoAtPosition(continent, u, v)
|
||||
if info and info.mapID and info.mapID ~= continent then
|
||||
cached = info.mapID
|
||||
end
|
||||
zones[key] = cached
|
||||
if log then
|
||||
log.zone[id] = cached or "none"
|
||||
end
|
||||
end
|
||||
return cached or nil
|
||||
end
|
||||
|
||||
-- whether node id belongs on uiMapID, and where
|
||||
local function Place(uiMapID, mapType, id)
|
||||
local c = Chain(id)
|
||||
if c.found then
|
||||
if not c.maps[uiMapID] then
|
||||
return nil
|
||||
end
|
||||
elseif mapType ~= Enum.UIMapType.Continent then
|
||||
return nil -- client can't say which zone it's in: only trust the continent map
|
||||
local u, v = Project(uiMapID, id)
|
||||
if not u or mapType == Enum.UIMapType.Continent then
|
||||
return u, v
|
||||
end
|
||||
return Project(uiMapID, id)
|
||||
local continent = Continent(uiMapID)
|
||||
local zone = continent and Zone(id, continent)
|
||||
if zone and not (Above(zone, uiMapID) or Above(uiMapID, zone)) then
|
||||
return nil -- inside this map's rectangle, but in a neighbouring zone
|
||||
end
|
||||
return u, v
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
|
@ -237,7 +266,8 @@ function provider:RefreshAllData()
|
|||
if Visible(id) and Leader(id) then
|
||||
local u, v = Place(mapID, info.mapType, id)
|
||||
if u then
|
||||
local zone = Chain(id).zone
|
||||
local continent = Continent(mapID)
|
||||
local zone = continent and Zone(id, continent)
|
||||
if zone and not learned[zone] then
|
||||
learned[zone] = true
|
||||
LearnZone(zone)
|
||||
|
|
@ -287,7 +317,8 @@ local function WaypointPoint(id, mapID)
|
|||
if not (C_Map.CanSetUserWaypointOnMap and C_Map.SetUserWaypoint and UiMapPoint) then
|
||||
return nil
|
||||
end
|
||||
for _, m in ipairs({ Chain(id).zone or mapID, mapID }) do
|
||||
local continent = Continent(mapID)
|
||||
for _, m in ipairs({ continent and Zone(id, continent) or mapID, mapID }) do
|
||||
local u, v = Project(m, id)
|
||||
if u and C_Map.CanSetUserWaypointOnMap(m) then
|
||||
return UiMapPoint.CreateFromCoordinates(m, u, v)
|
||||
|
|
@ -356,7 +387,7 @@ frame:SetScript("OnEvent", function(_, event, name)
|
|||
FlightFinderCharDB = { version = 3 } -- older versions learned every node as known
|
||||
end
|
||||
FlightFinderCharDB.known = FlightFinderCharDB.known or {}
|
||||
FlightFinderCharDB.log = { map = {}, chain = {} }
|
||||
FlightFinderCharDB.log = { map = {}, zone = {} }
|
||||
db, known, log = FlightFinderDB, FlightFinderCharDB.known, FlightFinderCharDB.log
|
||||
Attach()
|
||||
elseif name == "Blizzard_WorldMap" then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue