vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Magellan
3  
4 By Torgo <jimmcq@concentric.net>
5  
6 This mod will populate the the main map with MetaMap for local landmarks.
7 It requires the either MetaMap or CT_MapMod AddOn to be installed.
8  
9 Feel free to use any of this code in other mods, or to modify this AddOn itself. My only request is that you send me your modifications.
10  
11 URL: http://curse-gaming.com/mod.php?addid=994
12  
13 Modified for MetaMap by Devla
14 ]]
15  
16  
17 Magellan_Version = "002";
18 Magellan_ZoneNames = {};
19  
20 function Magellan_Init(...)
21 if (CT_MapMod_AddNote or MiniNotePOI) then
22 this:RegisterEvent("WORLD_MAP_UPDATE");
23 else
24 DEFAULT_CHAT_FRAME:AddMessage("Magellan could not find either MetaMap nor CT_MapMod to update");
25 end
26 for i=1, arg.n, 1 do
27 Magellan_LoadZones(i, GetMapZones(i));
28 end
29 SlashCmdList["MAGELLANSYSTEMSLASHMAIN"] = Magellan_Main_ChatCommandHandler;
30 SLASH_MAGELLANSYSTEMSLASHMAIN1 = "/magellan";
31 end
32  
33 function Magellan_LoadZones(...)
34 j = arg[1];
35 Magellan_ZoneNames[j] = {};
36 for i=1, arg.n-1, 1 do
37 Magellan_ZoneNames[j][i] = arg[i+1];
38 end
39 end
40  
41 function Magellan_OnEvent()
42 NumMapLandmarks = GetNumMapLandmarks();
43 mapZoneName = nil;
44 if( GetCurrentMapContinent() == -1 ) then
45 return
46 end
47 for landmarkIndex = 1, NumMapLandmarks, 1 do
48 name, unknown, textureIndex, x, y = GetMapLandmarkInfo(landmarkIndex);
49 name = Magellan_AddNote(name, textureIndex, x, y);
50 if (name) then
51 mapZoneName = name;
52 end
53 end
54 if (mapZoneName and DEFAULT_CHAT_FRAME) then
55 DEFAULT_CHAT_FRAME:AddMessage("Magellan updated Map Notes for "..mapZoneName, 1.0, 0.5, 0.25);
56 PlaySound("MapPing");
57 end
58 end
59  
60 function Magellan_AddNote(name, textureIndex, x, y)
61 local continent = GetCurrentMapContinent();
62 if( continent == 0 ) then
63 return;
64 end
65 local currentZone;
66 local zone;
67 if( continent == -1 ) then
68 if( not MetaMapNotes_Data[GetZoneText()] ) then
69 MetaMapNotes_Data[GetZoneText()] = { };
70 end
71 currentZone = MetaMapNotes_Data[GetZoneText()];
72 zone = -1;
73 else
74 zone = MetaMapNotes_ZoneShift[continent][GetCurrentMapZone()];
75 if( not MetaMapNotes_Data[continent][zone] ) then
76 MetaMapNotes_Data[continent][zone] = { };
77 end
78  
79 currentZone = MetaMapNotes_Data[continent][zone];
80 end
81  
82 if (zone == 0) then
83 return;
84 end
85  
86 if (MiniNotePOI ~= nil) then
87 -- MetaMap AddOn found
88 local id = 0;
89 local icon = 9;
90  
91 if (textureIndex == 15) then
92 icon = 5;
93 elseif (textureIndex == 6) then
94 icon = 6;
95 end
96  
97 if (x == 0 and y == 0) then
98 return;
99 end
100  
101 local checknote = false;
102 if( continent > 0 ) then
103 checknote = MetaMapNotes_CheckNearNotes(continent, zone, x, y);
104 end
105  
106 if (checknote == false) then
107 local i = 0;
108 for j, value in currentZone do
109 i = i + 1;
110 end
111 if (i < MetaMapNotes_NotesPerZone) then
112 MetaMapNotes_TempData_Id = i + 1;
113 currentZone[MetaMapNotes_TempData_Id] = {};
114 currentZone[MetaMapNotes_TempData_Id].name = name;
115 currentZone[MetaMapNotes_TempData_Id].ncol = 6;
116 currentZone[MetaMapNotes_TempData_Id].inf1 = "";
117 currentZone[MetaMapNotes_TempData_Id].in1c = 0;
118 currentZone[MetaMapNotes_TempData_Id].inf2 = "";
119 currentZone[MetaMapNotes_TempData_Id].in2c = 0;
120 currentZone[MetaMapNotes_TempData_Id].creator = "Magellan AddOn";
121 currentZone[MetaMapNotes_TempData_Id].icon = icon;
122 currentZone[MetaMapNotes_TempData_Id].xPos = x;
123 currentZone[MetaMapNotes_TempData_Id].yPos = y;
124  
125 if( continent > 0 ) then
126 return Magellan_ZoneNames[continent][zone];
127 else
128 return GetZoneText();
129 end
130 end
131 end
132  
133 elseif (CT_MapMod_AddNote) then
134 -- CT_MapMod AddOn found
135 zonename = Magellan_ZoneNames[continent][zone];
136 update = true;
137 local icon = 4;
138  
139 if (textureIndex == 15) then
140 icon = 1;
141 elseif (textureIndex == 6) then
142 icon = 3;
143 end
144  
145 if (CT_UserMap_Notes[zonename] ) then
146 for j, value in CT_UserMap_Notes[zonename] do
147 noteName = CT_UserMap_Notes[zonename][j]["name"];
148 if (noteName == name) then
149 update = false;
150 end
151 end
152 end
153  
154 if (update == true) then
155 CT_MapMod_AddNote(x, y, zonename, name, "Created by Magellan AddOn", icon, 4);
156 return zonename;
157 end
158 end
159 end
160  
161 function Magellan_Extract_NextParameter(msg)
162 local params = msg;
163 local command = params;
164 local index = strfind(command, " ");
165 if ( index ) then
166 command = strsub(command, 1, index-1);
167 params = strsub(params, index+1);
168 else
169 params = "";
170 end
171 return command, params;
172 end
173  
174 function Magellan_Main_ChatCommandHandler(msg)
175 local commandName, params = Magellan_Extract_NextParameter(msg);
176 if ( strfind( commandName, "reset" ) ) then
177 Magellan_DeleteNotes();
178 end
179 end
180  
181 function Magellan_DeleteNotes()
182 local i;
183 local j;
184 local k;
185 for i, value in MetaMapNotes_Data do
186 for j, value in MetaMapNotes_Data[i] do
187 for k, value in MetaMapNotes_Data[i][j] do
188 if (MetaMapNotes_Data[i][j][k].creator == "Magellan AddOn") then
189 Magellan_DeleteNote(i, j, k);
190 end
191 end
192 end
193 end
194 DEFAULT_CHAT_FRAME:AddMessage("All Magellan Map Notes have been deleted.");
195 end
196  
197 function Magellan_DeleteNote(continent, zone, id)
198 if (id == 0) then
199 MetaMapNotes_tloc_xPos = nil;
200 MetaMapNotes_tloc_yPos = nil;
201 return;
202 elseif (id == -1) then
203 MetaMapNotes_PartyNoteData.xPos = nil;
204 MetaMapNotes_PartyNoteData.yPos = nil;
205 MetaMapNotes_PartyNoteData.continent = nil;
206 MetaMapNotes_PartyNoteData.zone = nil;
207 return;
208 end
209 local lastEntry = Magellan_LastNote(continent, zone) - 1;
210 MetaMapNotes_DeleteLines(continent, zone, MetaMapNotes_Data[continent][zone][id].xPos, MetaMapNotes_Data[continent][zone][id].yPos);
211 if ((lastEntry ~= 0) and (id <= lastEntry)) then
212 MetaMapNotes_Data[continent][zone][id].name = MetaMapNotes_Data[continent][zone][lastEntry].name;
213 MetaMapNotes_Data[continent][zone][lastEntry].name = nil;
214 MetaMapNotes_Data[continent][zone][id].ncol = MetaMapNotes_Data[continent][zone][lastEntry].ncol;
215 MetaMapNotes_Data[continent][zone][lastEntry].ncol = nil;
216 MetaMapNotes_Data[continent][zone][id].inf1 = MetaMapNotes_Data[continent][zone][lastEntry].inf1;
217 MetaMapNotes_Data[continent][zone][lastEntry].inf1 = nil;
218 MetaMapNotes_Data[continent][zone][id].in1c = MetaMapNotes_Data[continent][zone][lastEntry].in1c;
219 MetaMapNotes_Data[continent][zone][lastEntry].in1c = nil;
220 MetaMapNotes_Data[continent][zone][id].inf2 = MetaMapNotes_Data[continent][zone][lastEntry].inf2;
221 MetaMapNotes_Data[continent][zone][lastEntry].inf2 = nil;
222 MetaMapNotes_Data[continent][zone][id].in2c = MetaMapNotes_Data[continent][zone][lastEntry].in2c;
223 MetaMapNotes_Data[continent][zone][lastEntry].in2c = nil;
224 MetaMapNotes_Data[continent][zone][id].creator = MetaMapNotes_Data[continent][zone][lastEntry].creator;
225 MetaMapNotes_Data[continent][zone][lastEntry].creator = nil;
226 MetaMapNotes_Data[continent][zone][id].icon = MetaMapNotes_Data[continent][zone][lastEntry].icon;
227 MetaMapNotes_Data[continent][zone][lastEntry].icon = nil;
228 MetaMapNotes_Data[continent][zone][id].xPos = MetaMapNotes_Data[continent][zone][lastEntry].xPos;
229 MetaMapNotes_Data[continent][zone][lastEntry].xPos = nil;
230 MetaMapNotes_Data[continent][zone][id].yPos = MetaMapNotes_Data[continent][zone][lastEntry].yPos;
231 MetaMapNotes_Data[continent][zone][lastEntry].yPos = nil;
232 MetaMapNotes_Data[continent][zone][lastEntry] = nil;
233 end
234 if (continent == MetaMapNotes_MiniNote_Data.continent and zone == MetaMapNotes_MiniNote_Data.zone) then
235 if (MetaMapNotes_MiniNote_Data.id > id) then
236 MetaMapNotes_MiniNote_Data.id = id - 1;
237 elseif (MetaMapNotes_MiniNote_Data.id == id) then
238 MetaMapNotes_MiniNote_Data.id = 0;
239 end
240 end
241 end
242  
243 function Magellan_LastNote(continent, zone)
244 local i = 0;
245 for j, value in MetaMapNotes_Data[continent][zone] do
246 i = i + 1;
247 end
248 return (i + 1);
249 end