fix that li'l spacing issue
[QuestHelper.git] / graph_flightpath.lua
blob54a8f9b66bfab23f77f6a9c5b54475dad2d5866f
1 QuestHelper_File["graph_flightpath.lua"] = "Development Version"
2 QuestHelper_Loadtime["graph_flightpath.lua"] = GetTime()
4 -- Name to Name, gives {time, accurate}
5 QH_Flight_Distances = {}
7 function QH_redo_flightpath()
8 QuestHelper: Assert(DB_Ready())
10 -- First, let's figure out if the player can fly.
11 -- The logic we're using: if he has 225 or 300, then he can fly in Outland. If he's got Cold Weather Flying and those levels, he can fly in Northrend.
13 local ridingLevel = (select(4,GetAchievementInfo(892)) and 300) or (select(4,GetAchievementInfo(890)) and 225) or (select(4,GetAchievementInfo(889)) and 150) or (select(4,GetAchievementInfo(891)) and 75) or 0 -- this is thanks to Maldivia, who is a fucking genius
14 local has_cwf = not not GetSpellInfo(GetSpellInfo(54197))
16 local speed
17 if ridingLevel == 225 then
18 speed = 11
19 elseif ridingLevel == 300 then
20 speed = 27
21 end
23 if ridingLevel >= 225 then
24 QH_Graph_Flyplaneset(3, speed) -- Outland
25 end
27 if ridingLevel >= 225 and has_cwf then
28 QH_Graph_Flyplaneset(4, speed) -- Northrend
29 end
30 end
32 local flightids = DB_ListItems("flightmasters")
33 local flightdb = {}
35 local has = {}
37 for k, v in pairs(flightids) do
38 flightdb[v] = DB_GetItem("flightmasters", v, true, true)
39 if QuestHelper_KnownFlightRoutes[flightdb[v].name] then
40 has[k] = true
41 end
42 end
44 local adjacency = {}
46 local important = {}
48 QH_Timeslice_Yield()
50 for k, v in pairs(has) do
51 local tdb = DB_GetItem("flightpaths", k, true, true)
52 if tdb then
53 for dest, dat in pairs(tdb) do
54 if has[dest] then
55 for _, route in ipairs(dat) do
56 local passes = true
57 if route.path then for _, intermed in ipairs(route.path) do
58 if not has[intermed] then passes = false break end
59 end end
61 if passes then
62 --QuestHelper:TextOut(string.format("Found link between %s and %s, cost %f", flightdb[k].name, flightdb[dest].name, route.distance))
63 if not adjacency[k] then adjacency[k] = {} end
64 if not adjacency[dest] then adjacency[dest] = {} end
65 QuestHelper: Assert(not (adjacency[k][dest] and adjacency[k][dest].time))
66 adjacency[k][dest] = {time = route.distance, dist = route.distance, original = true}
68 -- no such thing as strongly asymmetric routes
69 -- note that we're only hitting up adjacency here, because we don't have "time info"
70 if not adjacency[dest][k] then
71 adjacency[dest][k] = {dist = route.distance * 1.1, original = true} -- It's original because, in theory, we may end up basing other links on this one. It's still not time-authoritative, though.
72 end
74 important[k] = true
75 important[dest] = true
76 break
77 end
78 end
79 end
80 end
81 DB_ReleaseItem(tdb)
82 end
83 end
85 QH_Timeslice_Yield()
87 local imp_flat = {}
88 local flightmasters = {}
89 for k, v in pairs(important) do
90 table.insert(imp_flat, k)
91 if flightdb[k].mid then
92 local fmx = DB_GetItem("monster", flightdb[k].mid, true, true)
93 if fmx.loc then
94 flightmasters[k] = QuestHelper:CreateTable("flightmaster cachey")
95 for tk, v in pairs(fmx.loc[1]) do
96 if not tk:match("__.*") then
97 flightmasters[k][tk] = v
98 QuestHelper:Assert(type(tk) ~= "table")
99 QuestHelper:Assert(type(v) ~= "table")
102 else
103 --QuestHelper:TextOut(string.format("Missing flightmaster location for node %d/%s", k, tostring(flightdb[k].name)))
105 DB_ReleaseItem(fmx)
106 else
107 --QuestHelper:TextOut(string.format("Missing flightmaster for node %d/%s", k, tostring(flightdb[k].name)))
110 table.sort(imp_flat)
112 for _, v in ipairs(imp_flat) do
113 adjacency[v] = adjacency[v] or {}
116 for _, pivot in ipairs(imp_flat) do
117 QH_Timeslice_Yield()
118 for _, i in ipairs(imp_flat) do
119 for _, j in ipairs(imp_flat) do
120 if adjacency[i][pivot] and adjacency[pivot][j] then
121 local cst = adjacency[i][pivot].dist + adjacency[pivot][j].dist
122 if not adjacency[i][j] or adjacency[i][j].dist > cst then
123 if not adjacency[i][j] then adjacency[i][j] = {} end
124 adjacency[i][j].dist = cst
125 adjacency[i][j].original = nil
132 QH_Timeslice_Yield()
135 local clustaken = {}
137 for src, t in pairs(adjacency) do
138 if not clustaken[src] then
139 local tcst = {}
140 local tcct = 0
141 local ctd = {}
142 table.insert(ctd, src)
144 while #ctd > 0 do
145 local ite = table.remove(ctd)
146 QuestHelper: Assert(not clustaken[ite] or tcst[ite])
148 if not tcst[ite] then
149 clustaken[ite] = true
150 tcst[ite] = true
151 for _, dst in pairs(imp_flat) do
152 if adjacency[ite][dst] and not tcst[dst] then
153 table.insert(ctd, dst)
157 tcct = tcct + 1
161 --QuestHelper: TextOut(string.format("Starting with %d, cluster of %d", src, tcct))
166 QH_Graph_Plane_Destroylinks("flightpath")
168 -- reset!
169 QH_Flight_Distances = {}
171 for src, t in pairs(adjacency) do
172 QH_Timeslice_Yield()
173 for dest, dat in pairs(t) do
175 local fms = flightmasters[src]
176 local fmd = flightmasters[dest]
177 if fms and fmd then
178 QuestHelper: Assert(fms.c and (fms.c == fmd.c))
179 QuestHelper: Assert(fms.rc and (fms.rc == fmd.rc))
184 local sname = flightdb[src].name
185 local dname = flightdb[dest].name
187 if not QH_Flight_Distances[sname] then QH_Flight_Distances[sname] = {} end
188 QuestHelper: Assert(not QH_Flight_Distances[sname][dname])
189 QH_Flight_Distances[sname][dname] = {adjacency[src][dest].dist, not adjacency[src][dest].original}
192 if dat.original and not (src > dest and adjacency[dest][src] and adjacency[dest][src].original) then
193 local fms = flightmasters[src]
194 local fmd = flightmasters[dest]
195 if fms and fmd then
196 QuestHelper: Assert(fms.c and (fms.c == fmd.c))
197 QuestHelper: Assert(fms.rc and (fms.rc == fmd.rc))
199 local snode = {x = fms.x, y = fms.y, c = fms.c, p = QuestHelper_IndexLookup[fms.rc][fms.rz], map_desc = {QHFormat("WAYPOINT_REASON", QHFormat("FLIGHT_POINT", flightdb[dest].name))}, condense_class = "flightpath"}
200 local dnode = {x = fmd.x, y = fmd.y, c = fmd.c, p = QuestHelper_IndexLookup[fmd.rc][fmd.rz], map_desc = {QHFormat("WAYPOINT_REASON", QHFormat("FLIGHT_POINT", flightdb[src].name))}, condense_class = "flightpath"}
202 local ret = adjacency[dest][src] and adjacency[dest][src].original and adjacency[dest][src].dist
203 QH_Graph_Plane_Makelink("flightpath", snode, dnode, dat.dist, ret)
209 for _, v in pairs(flightdb) do
210 DB_ReleaseItem(v)
212 for _, v in pairs(flightmasters) do
213 QuestHelper:ReleaseTable(v)