Code:
-------------------------
-- MAP DIMENSIONS
-------------------------
MapDims= {
Ulduar = {
[1] = {w = 3064.9614761023, h = 2039.5413309668}, -- Expedition Base Camp
[2] = {w = 624.19069622949, h = 415.89374357805}, -- Antechamber of Ulduar
[3] = {w = 1238.37427179, h = 823.90183235628}, -- Conservatory of Life
[4] = {w = 848.38069183829, h = 564.6688835337}, -- Prison of Yogg-Saron
[5] = {w = 1460.4694647684, h = 974.65312886234}, -- Spark of Imagination
[6] = {w = 576.71549337896, h = 384.46653291368}, -- The Mind's Eye (Under Yogg)
},
Naxxramas = {
[1] = {w = 1018.3655494957, h = 679.40523953718}, -- Construct
[2] = {w = 1019.1310739251, h = 679.18864376555}, -- Arachnid
[3] = {w = 1118.1083638787, h = 744.57895516418}, -- Military
[4] = {w = 1117.0809918236, h = 745.97398439776}, -- Plague
[5] = {w = 1927.3190541014, h = 1284.6530841959}, -- Entrance
[6] = {w = 610.62737087301, h = 407.3875157986}, -- KT/Sapphiron
},
TheObsidianSanctum = {
[0] = {w = 1081.6334214432, h = 721.79860069158},
},
TheEyeofEternity = {
[1] = {w = 400.728405332355, h = 267.09113174487},
},
TheArgentColiseum = {
[1] = {w = 344.20785972537, h = 229.57961178118}, -- Main Floor
[2] = {w = 688.60679691348, h = 458.95801567569}, -- Anub
},
VaultofArchavon = {
[1] = {w = 842.2254908359, h = 561.59878021123},
},
IcecrownCitadel = {
[1] = {w = 1262.8025621533, h = 841.91669450207}, -- The Lower Citadel
[2] = {w = 993.25701607873, h = 662.58829476644}, -- The Rampart of Skulls
[3] = {w = 181.83564716405, h = 121.29684810833}, -- Deathbringer's Rise
[4] = {w = 720.60965618252, h = 481.1621506613}, -- The Frost Queen's Lair
[5] = {w = 1069.6156745738, h = 713.83371679543}, -- The Upper Reaches
[6] = {w = 348.05218433541, h = 232.05964286208}, -- Royal Quarters
[7] = {w = 272.80314344785, h = 181.89449398676}, -- The Frozen Throne
},
TheRubySanctum = {
[0] = {w = 752.083, h = 502.09}, -- The Ruby Sanctumn
},
-- Credits for this map data goes to LibMapData, has been verified with
TheBastionofTwilight = {
[1] = { w = 1078.33402252197, h = 718.889984130859}, -- LibMapData, Halfus + Dragons
[2] = { w = 778.343017578125, h = 518.894958496094}, -- LibMapData, Council + Cho'gall
[3] = { w = 1042.34202575684, h = 694.894958496094}, -- LibMapData, Sinestra
},
BlackwingDescent = {
[1] = { w = 849.69401550293, h = 566.462341070175}, -- LibMapData
[2] = { w = 999.69297790527, h = 666.462005615234}, -- LibMapData
},
ThroneoftheFourWinds = {
-- I am aware that there is only 1 entry here. However throne returns a 1 not a zero when getting num levels.
[1] = { w = 1514.534846, h = 1080.831578}, -- IsItemInRange
--[1] = {w = 1500.0, h = 1000.0}, -- LibMapData
},
ThunderKingRaid = {
[1] = { w = 1285.0, h = 856.6669921875},
[2] = { w = 1550.009765625, h = 1033.33984375},
[3] = { w = 1030.0, h = 686.6669921875},
[4] = { w = 591.280029296875, h = 394.18701171875},
[5] = { w = 1030.0, h = 686.6669921875},
[6] = { w = 910.0, h = 606.6669921875},
[7] = { w = 810.0, h = 540.0},
[8] = { w = 617.5, h = 411.6669921875},
},
ValeofEternalBlossoms = {
[0] = { w = 2533.333984, h = 1687.500977},
},
}
function Distance(unit1, unit2)
local x1,y1
local x2,y2
local list = MapDims[GetMapInfo()]
if not list then return end
local level = GetCurrentMapDungeonLevel()
local dims = list[level]
if not dims then
-- Zoning in and out will set the dungeon level to 0 so
-- we need some special handling to get to the dungeon
-- level we want
if level == 0 and list[1] then
SetMapToCurrentZone()
level = GetCurrentMapDungeonLevel()
dims = list[level]
if not dims then return end
else return end
end
x1,y1 = GetPlayerMapPosition(unit1)
x2,y2 = GetPlayerMapPosition(unit2)
-- if either unit is in a different zone return nil to abort the check
if x1 <= 0 and y1 <= 0 then
return nil
end
if x2 <= 0 and y2 <= 0 then
return nil
end
local dx = (x2 - x1) * dims.w
local dy = (y2 - y1) * dims.h
return sqrt(dx*dx + dy*dy) -- distance in yard
end