Should stop updating the player's position when they're dead, under the assumption...
[QuestHelper.git] / upgrade.lua
bloba6fa894d0009e8d294e07d289522bbf57c99d195
1 QuestHelper_File = {}
2 QuestHelper_File["upgrade.lua"] = "Development Version"
4 QuestHelper_Zones =
5 {{[0]="Kalimdor",
6 [1]="Ashenvale",
7 [2]="Azshara",
8 [3]="Azuremyst Isle",
9 [4]="Bloodmyst Isle",
10 [5]="Darkshore",
11 [6]="Darnassus",
12 [7]="Desolace",
13 [8]="Durotar",
14 [9]="Dustwallow Marsh",
15 [10]="Felwood",
16 [11]="Feralas",
17 [12]="Moonglade",
18 [13]="Mulgore",
19 [14]="Orgrimmar",
20 [15]="Silithus",
21 [16]="Stonetalon Mountains",
22 [17]="Tanaris",
23 [18]="Teldrassil",
24 [19]="The Barrens",
25 [20]="The Exodar",
26 [21]="Thousand Needles",
27 [22]="Thunder Bluff",
28 [23]="Un'Goro Crater",
29 [24]="Winterspring"},
30 {[0]="Eastern Kingdoms",
31 [1]="Alterac Mountains",
32 [2]="Arathi Highlands",
33 [3]="Badlands",
34 [4]="Blasted Lands",
35 [5]="Burning Steppes",
36 [6]="Deadwind Pass",
37 [7]="Dun Morogh",
38 [8]="Duskwood",
39 [9]="Eastern Plaguelands",
40 [10]="Elwynn Forest",
41 [11]="Eversong Woods",
42 [12]="Ghostlands",
43 [13]="Hillsbrad Foothills",
44 [14]="Ironforge",
45 [15]="Isle of Quel'Danas",
46 [16]="Loch Modan",
47 [17]="Redridge Mountains",
48 [18]="Searing Gorge",
49 [19]="Silvermoon City",
50 [20]="Silverpine Forest",
51 [21]="Stormwind City",
52 [22]="Stranglethorn Vale",
53 [23]="Swamp of Sorrows",
54 [24]="The Hinterlands",
55 [25]="Tirisfal Glades",
56 [26]="Undercity",
57 [27]="Western Plaguelands",
58 [28]="Westfall",
59 [29]="Wetlands"},
60 {[0]="Outland",
61 [1]="Blade's Edge Mountains",
62 [2]="Hellfire Peninsula",
63 [3]="Nagrand",
64 [4]="Netherstorm",
65 [5]="Shadowmoon Valley",
66 [6]="Shattrath City",
67 [7]="Terokkar Forest",
68 [8]="Zangarmarsh"}}
70 -- This will be translated to [LOCALE_NAME] = INDEX by QuestHelper_BuildZoneLookup.
71 -- Additionally, [CONT_INDEX][ZONE_INDEX] = INDEX will also be added.
72 QuestHelper_IndexLookup =
73 {["Hinterlands"] = {42, 2, 24},
74 ["Moonglade"] = {20, 1, 12},
75 ["ThousandNeedles"] = {14, 1, 21},
76 ["Winterspring"] = {19, 1, 24},
77 ["BloodmystIsle"] = {9, 1, 4},
78 ["TerokkarForest"] = {55, 3, 7},
79 ["Arathi"] = {39, 2, 2},
80 ["EversongWoods"] = {41, 2, 11},
81 ["Dustwallow"] = {10, 1, 9},
82 ["Badlands"] = {27, 2, 3},
83 ["Darkshore"] = {16, 1, 5},
84 ["Ogrimmar"] = {1, 1, 14},
85 ["BladesEdgeMountains"] = {54, 3, 1},
86 ["Undercity"] = {45, 2, 26},
87 ["Desolace"] = {4, 1, 7},
88 ["Netherstorm"] = {59, 3, 4},
89 ["Barrens"] = {11, 1, 19},
90 ["Tanaris"] = {8, 1, 17},
91 ["Stormwind"] = {36, 2, 21},
92 ["Zangarmarsh"] = {57, 3, 8},
93 ["Durotar"] = {7, 1, 8},
94 ["Hellfire"] = {56, 3, 2},
95 ["Silithus"] = {5, 1, 15},
96 ["ShattrathCity"] = {60, 3, 6},
97 ["ShadowmoonValley"] = {53, 3, 5},
98 ["SwampOfSorrows"] = {46, 2, 23},
99 ["SilvermoonCity"] = {52, 2, 19},
100 ["Darnassis"] = {21, 1, 6},
101 ["AzuremystIsle"] = {3, 1, 3},
102 ["Elwynn"] = {37, 2, 10},
103 ["Stranglethorn"] = {38, 2, 22},
104 ["EasternPlaguelands"] = {34, 2, 9},
105 ["Duskwood"] = {31, 2, 8},
106 ["WesternPlaguelands"] = {50, 2, 27},
107 ["Westfall"] = {49, 2, 28},
108 ["Ashenvale"] = {2, 1, 1},
109 ["Teldrassil"] = {24, 1, 18},
110 ["Redridge"] = {30, 2, 17},
111 ["UngoroCrater"] = {18, 1, 23},
112 ["Mulgore"] = {22, 1, 13},
113 ["Ironforge"] = {25, 2, 14},
114 ["Felwood"] = {13, 1, 10},
115 ["Hilsbrad"] = {48, 2, 13},
116 ["DeadwindPass"] = {47, 2, 6},
117 ["BurningSteppes"] = {40, 2, 5},
118 ["Ghostlands"] = {44, 2, 12},
119 ["Tirisfal"] = {43, 2, 25},
120 ["TheExodar"] = {12, 1, 20},
121 ["Wetlands"] = {51, 2, 29},
122 ["SearingGorge"] = {32, 2, 18},
123 ["BlastedLands"] = {33, 2, 4},
124 ["Silverpine"] = {35, 2, 20},
125 ["LochModan"] = {29, 2, 16},
126 ["Feralas"] = {17, 1, 11},
127 ["DunMorogh"] = {28, 2, 7},
128 ["Alterac"] = {26, 2, 1},
129 ["ThunderBluff"] = {23, 1, 22},
130 ["Aszhara"] = {15, 1, 2},
131 ["StonetalonMountains"] = {6, 1, 16},
132 ["Nagrand"] = {58, 3, 3},
133 ["Kalimdor"] = {61, 1, 0},
134 ["Azeroth"] = {62, 2, 0},
135 ["Expansion01"] = {63, 3, 0},
136 ["Sunwell"] = {64, 2, 15}}
138 local next_index = 1
139 for i, j in pairs(QuestHelper_IndexLookup) do next_index = math.max(next_index, j[1]+1) end
141 -- Maps zone names and indexes to a two element array, containing zone index a continent/zone
142 QuestHelper_ZoneLookup = {}
144 -- Maps indexes to zone names.
145 QuestHelper_NameLookup = {}
147 local built = false
149 function QuestHelper_BuildZoneLookup()
150 if built then return end
151 built = true
153 if GetMapContinents and GetMapZones then
154 -- Called from inside the WoW client.
156 local original_lookup, original_zones = QuestHelper_IndexLookup, QuestHelper_Zones
157 QuestHelper_IndexLookup = {}
158 QuestHelper_Zones = {}
160 for c, cname in pairs({GetMapContinents()}) do
161 QuestHelper_Zones[c] = {}
162 for z, zname in pairs({[0] = cname, GetMapZones(c)}) do
163 SetMapZoom(c, z)
164 local base_name = GetMapInfo()
166 local index = original_lookup[base_name] and original_lookup[base_name][1]
168 local altered_index = "!!! QuestHelper_IndexLookup entry needs update: [%q] = {%s, %s, %s}"
169 local altered_zone = "!!! QuestHelper_Zones entry needs update: [%s][%s] = %q -- was %s"
171 if not index then
172 QuestHelper:TextOut(altered_index:format(base_name, next_index, c, z))
173 next_index = next_index + 1
174 else
175 if QuestHelper_Locale == "enUS" then
176 if original_lookup[base_name][2] ~= c or original_lookup[base_name][3] ~= z then
177 QuestHelper:TextOut(altered_index:format(base_name, index, c, z))
180 if original_zones[c][z] ~= zname then
181 QuestHelper:TextOut(altered_zone:format(c, z, zname, original_zones[c][z] or "missing"))
185 local pair = {c, z}
186 if not QuestHelper_IndexLookup[c] then QuestHelper_IndexLookup[c] = {} end
187 QuestHelper_IndexLookup[c][z] = index
188 QuestHelper_IndexLookup[zname] = index
190 QuestHelper_NameLookup[index] = zname
192 QuestHelper_ZoneLookup[zname] = pair
193 QuestHelper_ZoneLookup[index] = pair
195 QuestHelper_Zones[c][z] = zname
199 else
200 -- Called from some lua script.
201 local original_lookup = QuestHelper_IndexLookup
202 QuestHelper_IndexLookup = {}
204 for base_name, i in pairs(original_lookup) do
205 local index = i[1]
206 local pair = {i[2], i[3]}
207 local name = QuestHelper_Zones[pair[1]][pair[2]]
209 assert(index and name)
211 if not QuestHelper_IndexLookup[pair[1]] then QuestHelper_IndexLookup[pair[1]] = {} end
212 QuestHelper_IndexLookup[pair[1]][pair[2]] = index
213 QuestHelper_IndexLookup[name] = index
215 QuestHelper_NameLookup[index] = name
217 QuestHelper_ZoneLookup[name] = pair
218 QuestHelper_ZoneLookup[index] = pair
223 local convert_lookup =
224 {{2, 15, 3, 9, 16, 21, 4, 7, 10, 13, 17, 20, 22, 1, 5, 6, 8, 24, 11, 12, 14, 23, 18, 19},
225 {26, 39, 27, 33, 40, 47, 28, 31, 34, 37, 41, 44, 48, 25, 29, 30, 32, 52, 35, 36, 38, 46, 42, 43, 45, 50, 49, 51},
226 {54, 56, 58, 59, 53, 60, 55, 57}}
228 function QuestHelper_ValidPosition(c, z, x, y)
229 return type(x) == "number" and type(y) == "number" and x > -0.1 and y > -0.1 and x < 1.1 and y < 1.1 and c and convert_lookup[c] and z and convert_lookup[c][z] and true
232 function QuestHelper_PrunePositionList(list)
233 if type(list) ~= "table" then
234 return nil
237 local i = 1
238 while i <= #list do
239 local pos = list[i]
240 if QuestHelper_ValidPosition(unpack(list[i])) and type(pos[5]) == "number" and pos[5] >= 1 then
241 i = i + 1
242 else
243 local rem = table.remove(list, i)
247 return #list > 0 and list or nil
250 local function QuestHelper_ConvertPosition(pos)
251 pos[2] = convert_lookup[pos[1]][pos[2]]
252 table.remove(pos, 1)
255 local function QuestHelper_ConvertPositionList(list)
256 if list then
257 for i, pos in pairs(list) do
258 QuestHelper_ConvertPosition(pos)
263 local function QuestHelper_ConvertFaction(locale, faction)
264 if faction == 1 or faction == "Alliance" or faction == FACTION_ALLIANCE then return 1
265 elseif faction == 2 or faction == "Horde" or faction == FACTION_HORDE then return 2
266 else
267 if locale == "enUS" then
268 if faction == "Alliance" then return 1
269 elseif faction == "Horde" then return 2 end
270 elseif locale == "frFR" then
271 if faction == "Alliance" then return 1
272 elseif faction == "Horde" then return 2 end
273 elseif locale == "deDE" then
274 if faction == "Alliance" then return 1
275 elseif faction == "Horde" then return 2 end
278 assert(false, "Unknown faction: "..locale.."/'"..faction.."'")
282 function QuestHelper_UpgradeDatabase(data)
283 if data.QuestHelper_SaveVersion == 1 then
285 -- Reputation objectives weren't parsed correctly before.
286 if data.QuestHelper_Objectives["reputation"] then
287 for faction, objective in pairs(data.QuestHelper_Objectives["reputation"]) do
288 local real_faction = string.find(faction, "%s*(.+)%s*:%s*") or faction
289 if faction ~= real_faction then
290 data.QuestHelper_Objectives["reputation"][real_faction] = data.QuestHelper_Objectives["reputation"][faction]
291 data.QuestHelper_Objectives["reputation"][faction] = nil
296 -- Items that wern't in the local cache when I read the quest log ended up with empty names.
297 if data.QuestHelper_Objectives["item"] then
298 data.QuestHelper_Objectives["item"][" "] = nil
301 data.QuestHelper_SaveVersion = 2
304 if data.QuestHelper_SaveVersion == 2 then
306 -- The hashes for the quests were wrong. Damnit!
307 for faction, level_list in pairs(data.QuestHelper_Quests) do
308 for level, quest_list in pairs(level_list) do
309 for quest_name, quest_data in pairs(quest_list) do
310 quest_data.hash = nil
311 quest_data.alt = nil
316 -- None of the information I collected about quest items previously can be trusted.
317 -- I also didn't properly mark quest items as such, so I'll have to remove the information for non
318 -- quest items also.
320 if data.QuestHelper_Objectives["item"] then
321 for item, item_data in pairs(data.QuestHelper_Objectives["item"]) do
322 -- I'll remerge the bad data later if I find out its not used solely for quests.
323 item_data.bad_pos = item_data.bad_pos or item_data.pos
324 item_data.bad_drop = item_data.bad_drop or item_data.drop
325 item_data.pos = nil
326 item_data.drop = nil
328 -- In the future i'll delete the bad_x data.
329 -- When I do, either just delete it, or of all the monsters or positions match the monsters and positions of the
330 -- quest, merge them into that.
334 data.QuestHelper_SaveVersion = 3
337 if data.QuestHelper_SaveVersion == 3 then
338 -- We'll go through this and make sure all the position lists are correct.
339 for faction, level_list in pairs(data.QuestHelper_Quests) do
340 for level, quest_list in pairs(level_list) do
341 for quest_name, quest_data in pairs(quest_list) do
342 quest_data.pos = QuestHelper_PrunePositionList(quest_data.pos)
343 if quest_data.item then for name, data in pairs(quest_data.item) do
344 data.pos = QuestHelper_PrunePositionList(data.pos)
345 end end
346 if quest_data.alt then for hash, data in pairs(quest_data.alt) do
347 data.pos = QuestHelper_PrunePositionList(data.pos)
348 if data.item then for name, data in pairs(data.item) do
349 data.pos = QuestHelper_PrunePositionList(data.pos)
350 end end
351 end end
356 for cat, list in pairs(data.QuestHelper_Objectives) do
357 for name, data in pairs(list) do
358 data.pos = QuestHelper_PrunePositionList(data.pos)
362 if data.QuestHelper_ZoneTransition then
363 for c, z1list in pairs(data.QuestHelper_ZoneTransition) do
364 for z1, z2list in pairs(z1list) do
365 for z2, poslist in pairs(z2list) do
366 z2list[z2] = QuestHelper_PrunePositionList(poslist)
372 data.QuestHelper_SaveVersion = 4
375 if data.QuestHelper_SaveVersion == 4 then
376 -- Zone transitions have been obsoleted by a bug.
377 data.QuestHelper_ZoneTransition = nil
378 data.QuestHelper_SaveVersion = 5
381 if data.QuestHelper_SaveVersion == 5 then
382 -- For version 6, I'm converting area positions from a continent/zone index pair to a single index.
384 if data.QuestHelper_FlightRoutes then
385 local old_routes = data.QuestHelper_FlightRoutes
386 data.QuestHelper_FlightRoutes = {}
387 for c, value in pairs(old_routes) do
388 data.QuestHelper_FlightRoutes[QuestHelper_IndexLookup[c][0]] = value
392 for faction, level_list in pairs(data.QuestHelper_Quests) do
393 for level, quest_list in pairs(level_list) do
394 for quest_name, quest_data in pairs(quest_list) do
395 QuestHelper_ConvertPositionList(quest_data.pos)
396 if quest_data.item then for name, data in pairs(quest_data.item) do
397 QuestHelper_ConvertPositionList(data.pos)
398 end end
399 if quest_data.alt then for hash, data in pairs(quest_data.alt) do
400 QuestHelper_ConvertPositionList(data.pos)
401 if data.item then for name, data in pairs(data.item) do
402 QuestHelper_ConvertPositionList(data.pos)
403 end end
404 end end
409 for cat, list in pairs(data.QuestHelper_Objectives) do
410 for name, data in pairs(list) do
411 QuestHelper_ConvertPositionList(data.pos)
415 data.QuestHelper_SaveVersion = 6
418 if data.QuestHelper_SaveVersion == 6 then
419 -- Redoing how flightpaths work, previously collected flightpath data is now obsolete.
420 data.QuestHelper_FlightRoutes = {}
422 -- FlightInstructors table should be fine, will leave it.
423 -- Upgrading per-character data is handled in main.lua.
425 -- Also converting factions to numbers, 1 for Alliance, 2 for Horde.
426 local replacement = {}
427 for faction, dat in pairs(data.QuestHelper_Quests) do
428 replacement[QuestHelper_ConvertFaction(data.QuestHelper_Locale, faction)] = dat
430 data.QuestHelper_Quests = replacement
432 replacement = {}
433 if data.QuestHelper_FlightInstructors then for faction, dat in pairs(data.QuestHelper_FlightInstructors) do
434 replacement[QuestHelper_ConvertFaction(data.QuestHelper_Locale, faction)] = dat
435 end end
436 data.QuestHelper_FlightInstructors = replacement
438 for cat, list in pairs(data.QuestHelper_Objectives) do
439 for name, obj in pairs(list) do
440 if obj.faction then
441 obj.faction = QuestHelper_ConvertFaction(data.QuestHelper_Locale, obj.faction)
446 data.QuestHelper_SaveVersion = 7
449 if data.QuestHelper_SaveVersion == 7 then
450 -- It sure took me long enough to discover that I broke vendor objectives.
451 -- their factions were strings and didn't match the number value of QuestHelper.faction
453 for cat, list in pairs(data.QuestHelper_Objectives) do
454 for name, obj in pairs(list) do
455 if type(obj.faction) == "string" then
456 obj.faction = (obj.faction == "Alliance" and 1) or (obj.faction == "Horde" and 2) or nil
461 data.QuestHelper_SaveVersion = 8
465 function QuestHelper_UpgradeComplete()
466 -- This function deletes everything related to upgrading, as it isn't going to be needed again.
467 built = nil
468 next_index = nil
469 convert_lookup = nil
470 QuestHelper_BuildZoneLookup = nil
471 QuestHelper_ValidPosition = nil
472 QuestHelper_PrunePositionList = nil
473 QuestHelper_ConvertPosition = nil
474 QuestHelper_ConvertPositionList = nil
475 QuestHelper_ConvertFaction = nil
476 QuestHelper_UpgradeDatabase = nil
477 QuestHelper_UpgradeComplete = nil