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
|
end
|
||||||
ns.Project = Project
|
ns.Project = Project
|
||||||
|
|
||||||
-- the map the client places a node on, plus every map above it
|
local function Parent(uiMapID)
|
||||||
local chains = {}
|
local info = C_Map.GetMapInfo(uiMapID)
|
||||||
local function Chain(id)
|
return info and info.parentMapID ~= 0 and info.parentMapID or nil
|
||||||
local c = chains[id]
|
end
|
||||||
if c then
|
|
||||||
return c
|
-- a is b or one of the maps above it
|
||||||
end
|
local function Above(a, b)
|
||||||
local n = ns.nodes[id]
|
|
||||||
c = { maps = {} }
|
|
||||||
local ok, mapID = pcall(C_Map.GetMapPosFromWorldPos, n[1], CreateVector2D(n[2], n[3]))
|
|
||||||
for _ = 1, 10 do
|
for _ = 1, 10 do
|
||||||
if not ok or not mapID or mapID == 0 or c.maps[mapID] then
|
if not b then
|
||||||
break
|
return false
|
||||||
|
elseif a == b then
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
local info = C_Map.GetMapInfo(mapID)
|
b = Parent(b)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
chains[id] = c
|
return false
|
||||||
if log then
|
end
|
||||||
log.chain[id] = c.zone or (c.found and "no zone") or "not found"
|
|
||||||
|
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
|
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
|
end
|
||||||
|
|
||||||
-- whether node id belongs on uiMapID, and where
|
-- whether node id belongs on uiMapID, and where
|
||||||
local function Place(uiMapID, mapType, id)
|
local function Place(uiMapID, mapType, id)
|
||||||
local c = Chain(id)
|
local u, v = Project(uiMapID, id)
|
||||||
if c.found then
|
if not u or mapType == Enum.UIMapType.Continent then
|
||||||
if not c.maps[uiMapID] then
|
return u, v
|
||||||
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
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
@ -237,7 +266,8 @@ function provider:RefreshAllData()
|
||||||
if Visible(id) and Leader(id) then
|
if Visible(id) and Leader(id) then
|
||||||
local u, v = Place(mapID, info.mapType, id)
|
local u, v = Place(mapID, info.mapType, id)
|
||||||
if u then
|
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
|
if zone and not learned[zone] then
|
||||||
learned[zone] = true
|
learned[zone] = true
|
||||||
LearnZone(zone)
|
LearnZone(zone)
|
||||||
|
|
@ -287,7 +317,8 @@ local function WaypointPoint(id, mapID)
|
||||||
if not (C_Map.CanSetUserWaypointOnMap and C_Map.SetUserWaypoint and UiMapPoint) then
|
if not (C_Map.CanSetUserWaypointOnMap and C_Map.SetUserWaypoint and UiMapPoint) then
|
||||||
return nil
|
return nil
|
||||||
end
|
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)
|
local u, v = Project(m, id)
|
||||||
if u and C_Map.CanSetUserWaypointOnMap(m) then
|
if u and C_Map.CanSetUserWaypointOnMap(m) then
|
||||||
return UiMapPoint.CreateFromCoordinates(m, u, v)
|
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
|
FlightFinderCharDB = { version = 3 } -- older versions learned every node as known
|
||||||
end
|
end
|
||||||
FlightFinderCharDB.known = FlightFinderCharDB.known or {}
|
FlightFinderCharDB.known = FlightFinderCharDB.known or {}
|
||||||
FlightFinderCharDB.log = { map = {}, chain = {} }
|
FlightFinderCharDB.log = { map = {}, zone = {} }
|
||||||
db, known, log = FlightFinderDB, FlightFinderCharDB.known, FlightFinderCharDB.log
|
db, known, log = FlightFinderDB, FlightFinderCharDB.known, FlightFinderCharDB.log
|
||||||
Attach()
|
Attach()
|
||||||
elseif name == "Blizzard_WorldMap" then
|
elseif name == "Blizzard_WorldMap" then
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,14 @@ end
|
||||||
local RECTS = {
|
local RECTS = {
|
||||||
[1415] = { inst = 0, top = 7467, bottom = -16000, left = 16000, right = -19200, type = 2, parent = 947 },
|
[1415] = { inst = 0, top = 7467, bottom = -16000, left = 16000, right = -19200, type = 2, parent = 947 },
|
||||||
[1414] = { inst = 1, top = 12800, bottom = -11733, left = 17067, right = -19733, type = 2, parent = 947 },
|
[1414] = { inst = 1, top = 12800, bottom = -11733, left = 17067, right = -19733, type = 2, parent = 947 },
|
||||||
[1437] = { inst = 0, top = -1500, bottom = -4800, left = 200, right = -4800, type = 3, parent = 1415 }, -- Wetlands
|
[1437] = { inst = 0, top = -1500, bottom = -5600, left = 200, right = -4800, type = 3, parent = 1415 }, -- Wetlands (rect reaches over Thelsamar)
|
||||||
[1432] = { inst = 0, top = -4500, bottom = -6300, left = -1700, right = -4500, type = 3, parent = 1415 }, -- Loch Modan
|
[1432] = { inst = 0, top = -4500, bottom = -6300, left = -1700, right = -4500, type = 3, parent = 1415 }, -- Loch Modan
|
||||||
[1426] = { inst = 0, top = -3400, bottom = -6600, left = 1500, right = -2500, type = 3, parent = 1415 }, -- Dun Morogh
|
[1426] = { inst = 0, top = -4200, bottom = -6600, left = 1500, right = -2500, type = 3, parent = 1415 }, -- Dun Morogh
|
||||||
[1455] = { inst = 0, top = -4500, bottom = -5200, left = -700, right = -1500, type = 3, parent = 1426 }, -- Ironforge
|
[1455] = { inst = 0, top = -4500, bottom = -5200, left = -700, right = -1500, type = 3, parent = 1426 }, -- Ironforge
|
||||||
[1434] = { inst = 0, top = -11000, bottom = -15000, left = 2000, right = -2000, type = 3, parent = 1415 }, -- Stranglethorn
|
[1434] = { inst = 0, top = -11000, bottom = -15000, left = 2000, right = -2000, type = 3, parent = 1415 }, -- Stranglethorn
|
||||||
}
|
}
|
||||||
-- which zone the client puts a world point in: first matching rect among these, smallest first
|
-- zones the continent map highlights, in hit-test order
|
||||||
local ZONES = { 1455, 1437, 1432, 1426, 1434 }
|
local ZONES = { 1432, 1426, 1437, 1434 }
|
||||||
|
|
||||||
Enum = { UIMapType = { Cosmic = 0, World = 1, Continent = 2, Zone = 3, Dungeon = 4, Micro = 5 } }
|
Enum = { UIMapType = { Cosmic = 0, World = 1, Continent = 2, Zone = 3, Dungeon = 4, Micro = 5 } }
|
||||||
function CreateVector2D(x, y)
|
function CreateVector2D(x, y)
|
||||||
|
|
@ -40,14 +40,21 @@ C_Map = {
|
||||||
if not r then return nil end
|
if not r then return nil end
|
||||||
return r.inst, CreateVector2D(r.top + (r.bottom - r.top) * v.y, r.left + (r.right - r.left) * v.x)
|
return r.inst, CreateVector2D(r.top + (r.bottom - r.top) * v.y, r.left + (r.right - r.left) * v.x)
|
||||||
end,
|
end,
|
||||||
|
-- like Forever: only ever answers with the continent
|
||||||
GetMapPosFromWorldPos = function(inst, pos)
|
GetMapPosFromWorldPos = function(inst, pos)
|
||||||
|
return inst == 0 and 1415 or 1414, CreateVector2D(0, 0)
|
||||||
|
end,
|
||||||
|
-- the zone under a continent map point, or the continent itself
|
||||||
|
GetMapInfoAtPosition = function(cont, u, v)
|
||||||
|
local c = RECTS[cont]
|
||||||
|
local x, y = c.top + (c.bottom - c.top) * v, c.left + (c.right - c.left) * u
|
||||||
for _, id in ipairs(ZONES) do
|
for _, id in ipairs(ZONES) do
|
||||||
local r = RECTS[id]
|
local r = RECTS[id]
|
||||||
if r.inst == inst and pos.x <= r.top and pos.x >= r.bottom and pos.y <= r.left and pos.y >= r.right then
|
if r.parent == cont and r.inst == c.inst and x <= r.top and x >= r.bottom and y <= r.left and y >= r.right then
|
||||||
return id, CreateVector2D(0, 0)
|
return { mapID = id, mapType = r.type, parentMapID = cont }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return inst == 0 and 1415 or 1414, CreateVector2D(0, 0)
|
return { mapID = cont, mapType = c.type, parentMapID = 947 }
|
||||||
end,
|
end,
|
||||||
CanSetUserWaypointOnMap = function(id) return RECTS[id].type == 3 end,
|
CanSetUserWaypointOnMap = function(id) return RECTS[id].type == 3 end,
|
||||||
SetUserWaypoint = function(p) waypoint = p end,
|
SetUserWaypoint = function(p) waypoint = p end,
|
||||||
|
|
@ -157,8 +164,9 @@ check(not show(1437)[7], "known Menethil not marked")
|
||||||
apiKnown[1437] = nil
|
apiKnown[1437] = nil
|
||||||
check(not show(1415)[7], "Menethil stays known on the continent map")
|
check(not show(1415)[7], "Menethil stays known on the continent map")
|
||||||
check(show(1415)[8], "Thelsamar still marked on the continent map")
|
check(show(1415)[8], "Thelsamar still marked on the continent map")
|
||||||
-- city node shows on its zone (Ironforge sits in Dun Morogh)
|
-- city node shows on its zone and on the city map inside it
|
||||||
check(show(1426)[6], "Ironforge marked on Dun Morogh")
|
check(show(1426)[6], "Ironforge marked on Dun Morogh")
|
||||||
|
check(show(1455)[6], "Ironforge marked on the Ironforge city map")
|
||||||
|
|
||||||
-- taxi map: Thelsamar reachable, Ironforge not yet discovered
|
-- taxi map: Thelsamar reachable, Ironforge not yet discovered
|
||||||
taxi = { { "Thelsamar, Loch Modan", "REACHABLE" }, { "Ironforge, Dun Morogh", "DISTANT" } }
|
taxi = { { "Thelsamar, Loch Modan", "REACHABLE" }, { "Ironforge, Dun Morogh", "DISTANT" } }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue