Added a comment about '/qh submit' when nagging if there are 20 or more changes found.
[QuestHelper.git] / upgrade.lua
blob72935d36af30dd7fff509073c8c784fc3163609d
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 if not index then
169 QuestHelper:TextOut(QHFormat("ALTERED_INDEX", base_name, next_index, c, z))
170 next_index = next_index + 1
171 else
172 if QuestHelper_Locale == "enUS" then
173 if original_lookup[base_name][2] ~= c or original_lookup[base_name][3] ~= z then
174 QuestHelper:TextOut(QHFormat("ALTERED_INDEX", base_name, index, c, z))
177 if original_zones[c][z] ~= zname then
178 QuestHelper:TextOut(QHFormat("ALTERED_ZONE", c, z, zname, original_zones[c][z] or "missing"))
182 local pair = {c, z}
183 if not QuestHelper_IndexLookup[c] then QuestHelper_IndexLookup[c] = {} end
184 QuestHelper_IndexLookup[c][z] = index
185 QuestHelper_IndexLookup[zname] = index
187 QuestHelper_NameLookup[index] = zname
189 QuestHelper_ZoneLookup[zname] = pair
190 QuestHelper_ZoneLookup[index] = pair
192 QuestHelper_Zones[c][z] = zname
196 else
197 -- Called from some lua script.
198 local original_lookup = QuestHelper_IndexLookup
199 QuestHelper_IndexLookup = {}
201 for base_name, i in pairs(original_lookup) do
202 local index = i[1]
203 local pair = {i[2], i[3]}
204 local name = QuestHelper_Zones[pair[1]][pair[2]]
206 assert(index and name)
208 if not QuestHelper_IndexLookup[pair[1]] then QuestHelper_IndexLookup[pair[1]] = {} end
209 QuestHelper_IndexLookup[pair[1]][pair[2]] = index
210 QuestHelper_IndexLookup[name] = index
212 QuestHelper_NameLookup[index] = name
214 QuestHelper_ZoneLookup[name] = pair
215 QuestHelper_ZoneLookup[index] = pair
220 local convert_lookup =
221 {{2, 15, 3, 9, 16, 21, 4, 7, 10, 13, 17, 20, 22, 1, 5, 6, 8, 24, 11, 12, 14, 23, 18, 19},
222 {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},
223 {54, 56, 58, 59, 53, 60, 55, 57}}
225 function QuestHelper_ValidPosition(c, z, x, y)
226 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
229 function QuestHelper_PrunePositionList(list)
230 if type(list) ~= "table" then
231 return nil
234 local i = 1
235 while i <= #list do
236 local pos = list[i]
237 if QuestHelper_ValidPosition(unpack(list[i])) and type(pos[5]) == "number" and pos[5] >= 1 then
238 i = i + 1
239 else
240 local rem = table.remove(list, i)
244 return #list > 0 and list or nil
247 local function QuestHelper_ConvertPosition(pos)
248 pos[2] = convert_lookup[pos[1]][pos[2]]
249 table.remove(pos, 1)
252 local function QuestHelper_ConvertPositionList(list)
253 if list then
254 for i, pos in pairs(list) do
255 QuestHelper_ConvertPosition(pos)
260 local function QuestHelper_ConvertFaction(locale, faction)
261 if faction == 1 or faction == "Alliance" or faction == FACTION_ALLIANCE then return 1
262 elseif faction == 2 or faction == "Horde" or faction == FACTION_HORDE then return 2
263 else
264 if locale == "enUS" then
265 if faction == "Alliance" then return 1
266 elseif faction == "Horde" then return 2 end
267 elseif locale == "frFR" then
268 if faction == "Alliance" then return 1
269 elseif faction == "Horde" then return 2 end
270 elseif locale == "deDE" then
271 if faction == "Alliance" then return 1
272 elseif faction == "Horde" then return 2 end
275 assert(false, "Unknown faction: "..locale.."/'"..faction.."'")
279 function QuestHelper_UpgradeDatabase(data)
280 if data.QuestHelper_SaveVersion == 1 then
282 -- Reputation objectives weren't parsed correctly before.
283 if data.QuestHelper_Objectives["reputation"] then
284 for faction, objective in pairs(data.QuestHelper_Objectives["reputation"]) do
285 local real_faction = string.find(faction, "%s*(.+)%s*:%s*") or faction
286 if faction ~= real_faction then
287 data.QuestHelper_Objectives["reputation"][real_faction] = data.QuestHelper_Objectives["reputation"][faction]
288 data.QuestHelper_Objectives["reputation"][faction] = nil
293 -- Items that wern't in the local cache when I read the quest log ended up with empty names.
294 if data.QuestHelper_Objectives["item"] then
295 data.QuestHelper_Objectives["item"][" "] = nil
298 data.QuestHelper_SaveVersion = 2
301 if data.QuestHelper_SaveVersion == 2 then
303 -- The hashes for the quests were wrong. Damnit!
304 for faction, level_list in pairs(data.QuestHelper_Quests) do
305 for level, quest_list in pairs(level_list) do
306 for quest_name, quest_data in pairs(quest_list) do
307 quest_data.hash = nil
308 quest_data.alt = nil
313 -- None of the information I collected about quest items previously can be trusted.
314 -- I also didn't properly mark quest items as such, so I'll have to remove the information for non
315 -- quest items also.
317 if data.QuestHelper_Objectives["item"] then
318 for item, item_data in pairs(data.QuestHelper_Objectives["item"]) do
319 -- I'll remerge the bad data later if I find out its not used solely for quests.
320 item_data.bad_pos = item_data.bad_pos or item_data.pos
321 item_data.bad_drop = item_data.bad_drop or item_data.drop
322 item_data.pos = nil
323 item_data.drop = nil
325 -- In the future i'll delete the bad_x data.
326 -- When I do, either just delete it, or of all the monsters or positions match the monsters and positions of the
327 -- quest, merge them into that.
331 data.QuestHelper_SaveVersion = 3
334 if data.QuestHelper_SaveVersion == 3 then
335 -- We'll go through this and make sure all the position lists are correct.
336 for faction, level_list in pairs(data.QuestHelper_Quests) do
337 for level, quest_list in pairs(level_list) do
338 for quest_name, quest_data in pairs(quest_list) do
339 quest_data.pos = QuestHelper_PrunePositionList(quest_data.pos)
340 if quest_data.item then for name, data in pairs(quest_data.item) do
341 data.pos = QuestHelper_PrunePositionList(data.pos)
342 end end
343 if quest_data.alt then for hash, data in pairs(quest_data.alt) do
344 data.pos = QuestHelper_PrunePositionList(data.pos)
345 if data.item then for name, data in pairs(data.item) do
346 data.pos = QuestHelper_PrunePositionList(data.pos)
347 end end
348 end end
353 for cat, list in pairs(data.QuestHelper_Objectives) do
354 for name, data in pairs(list) do
355 data.pos = QuestHelper_PrunePositionList(data.pos)
359 if data.QuestHelper_ZoneTransition then
360 for c, z1list in pairs(data.QuestHelper_ZoneTransition) do
361 for z1, z2list in pairs(z1list) do
362 for z2, poslist in pairs(z2list) do
363 z2list[z2] = QuestHelper_PrunePositionList(poslist)
369 data.QuestHelper_SaveVersion = 4
372 if data.QuestHelper_SaveVersion == 4 then
373 -- Zone transitions have been obsoleted by a bug.
374 data.QuestHelper_ZoneTransition = nil
375 data.QuestHelper_SaveVersion = 5
378 if data.QuestHelper_SaveVersion == 5 then
379 -- For version 6, I'm converting area positions from a continent/zone index pair to a single index.
381 if data.QuestHelper_FlightRoutes then
382 local old_routes = data.QuestHelper_FlightRoutes
383 data.QuestHelper_FlightRoutes = {}
384 for c, value in pairs(old_routes) do
385 data.QuestHelper_FlightRoutes[QuestHelper_IndexLookup[c][0]] = value
389 for faction, level_list in pairs(data.QuestHelper_Quests) do
390 for level, quest_list in pairs(level_list) do
391 for quest_name, quest_data in pairs(quest_list) do
392 QuestHelper_ConvertPositionList(quest_data.pos)
393 if quest_data.item then for name, data in pairs(quest_data.item) do
394 QuestHelper_ConvertPositionList(data.pos)
395 end end
396 if quest_data.alt then for hash, data in pairs(quest_data.alt) do
397 QuestHelper_ConvertPositionList(data.pos)
398 if data.item then for name, data in pairs(data.item) do
399 QuestHelper_ConvertPositionList(data.pos)
400 end end
401 end end
406 for cat, list in pairs(data.QuestHelper_Objectives) do
407 for name, data in pairs(list) do
408 QuestHelper_ConvertPositionList(data.pos)
412 data.QuestHelper_SaveVersion = 6
415 if data.QuestHelper_SaveVersion == 6 then
416 -- Redoing how flightpaths work, previously collected flightpath data is now obsolete.
417 data.QuestHelper_FlightRoutes = {}
419 -- FlightInstructors table should be fine, will leave it.
420 -- Upgrading per-character data is handled in main.lua.
422 -- Also converting factions to numbers, 1 for Alliance, 2 for Horde.
423 local replacement = {}
424 for faction, dat in pairs(data.QuestHelper_Quests) do
425 replacement[QuestHelper_ConvertFaction(data.QuestHelper_Locale, faction)] = dat
427 data.QuestHelper_Quests = replacement
429 replacement = {}
430 if data.QuestHelper_FlightInstructors then for faction, dat in pairs(data.QuestHelper_FlightInstructors) do
431 replacement[QuestHelper_ConvertFaction(data.QuestHelper_Locale, faction)] = dat
432 end end
433 data.QuestHelper_FlightInstructors = replacement
435 for cat, list in pairs(data.QuestHelper_Objectives) do
436 for name, obj in pairs(list) do
437 if obj.faction then
438 obj.faction = QuestHelper_ConvertFaction(data.QuestHelper_Locale, obj.faction)
443 data.QuestHelper_SaveVersion = 7
446 if data.QuestHelper_SaveVersion == 7 then
447 -- It sure took me long enough to discover that I broke vendor objectives.
448 -- their factions were strings and didn't match the number value of QuestHelper.faction
450 for cat, list in pairs(data.QuestHelper_Objectives) do
451 for name, obj in pairs(list) do
452 if type(obj.faction) == "string" then
453 obj.faction = (obj.faction == "Alliance" and 1) or (obj.faction == "Horde" and 2) or nil
458 data.QuestHelper_SaveVersion = 8
462 function QuestHelper_UpgradeComplete()
463 -- This function deletes everything related to upgrading, as it isn't going to be needed again.
464 built = nil
465 next_index = nil
466 convert_lookup = nil
467 QuestHelper_BuildZoneLookup = nil
468 QuestHelper_ValidPosition = nil
469 QuestHelper_PrunePositionList = nil
470 QuestHelper_ConvertPosition = nil
471 QuestHelper_ConvertPositionList = nil
472 QuestHelper_ConvertFaction = nil
473 QuestHelper_UpgradeDatabase = nil
474 QuestHelper_UpgradeComplete = nil