OregonCore  revision fb2a440-git
Your Favourite TBC server
GridNotifiersImpl.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OREGON_GRIDNOTIFIERSIMPL_H
19 #define OREGON_GRIDNOTIFIERSIMPL_H
20 
21 #include "GridNotifiers.h"
22 #include "WorldPacket.h"
23 #include "Corpse.h"
24 #include "Player.h"
25 #include "UpdateData.h"
26 #include "CreatureAI.h"
27 #include "SpellAuras.h"
28 
29 template<class T>
30 inline void
32 {
33  for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
34  {
35  vis_guids.erase(iter->GetSource()->GetGUID());
36  i_player.UpdateVisibilityOf(iter->GetSource(), i_data, i_visibleNow);
37  }
38 }
39 
40 inline void
42 {
43  for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
44  if (iter->GetSource()->IsInWorld())
45  iter->GetSource()->Update(i_timeDiff);
46 }
47 
48 // SEARCHERS & LIST SEARCHERS & WORKERS
49 
50 // WorldObject searchers & workers
51 
52 template<class Check>
54 {
55  // already found
56  if (i_object)
57  return;
58 
59  for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
60  {
61  if (!itr->GetSource()->InSamePhase(i_phaseMask))
62  continue;
63 
64  if (i_check(itr->GetSource()))
65  {
66  i_object = itr->GetSource();
67  return;
68  }
69  }
70 }
71 
72 template<class Check>
74 {
75  // already found
76  if (i_object)
77  return;
78 
79  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
80  {
81  if (!itr->GetSource()->InSamePhase(i_phaseMask))
82  continue;
83 
84  if (i_check(itr->GetSource()))
85  {
86  i_object = itr->GetSource();
87  return;
88  }
89  }
90 }
91 
92 template<class Check>
94 {
95  // already found
96  if (i_object)
97  return;
98 
99  for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
100  {
101  if (!itr->GetSource()->InSamePhase(i_phaseMask))
102  continue;
103 
104  if (i_check(itr->GetSource()))
105  {
106  i_object = itr->GetSource();
107  return;
108  }
109  }
110 }
111 
112 template<class Check>
114 {
115  // already found
116  if (i_object)
117  return;
118 
119  for (CorpseMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
120  {
121  if (!itr->GetSource()->InSamePhase(i_phaseMask))
122  continue;
123 
124  if (i_check(itr->GetSource()))
125  {
126  i_object = itr->GetSource();
127  return;
128  }
129  }
130 }
131 
132 template<class Check>
134 {
135  // already found
136  if (i_object)
137  return;
138 
139  for (DynamicObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
140  {
141  if (!itr->GetSource()->InSamePhase(i_phaseMask))
142  continue;
143 
144  if (i_check(itr->GetSource()))
145  {
146  i_object = itr->GetSource();
147  return;
148  }
149  }
150 }
151 
152 template<class Check>
154 {
155  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
156  if (itr->GetSource()->InSamePhase(i_phaseMask))
157  if (i_check(itr->GetSource()))
158  i_objects.push_back(itr->GetSource());
159 }
160 
161 template<class Check>
163 {
164  for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
165  if (itr->GetSource()->InSamePhase(i_phaseMask))
166  if (i_check(itr->GetSource()))
167  i_objects.push_back(itr->GetSource());
168 }
169 
170 template<class Check>
172 {
173  for (CorpseMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
174  if (itr->GetSource()->InSamePhase(i_phaseMask))
175  if (i_check(itr->GetSource()))
176  i_objects.push_back(itr->GetSource());
177 }
178 
179 template<class Check>
181 {
182  for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
183  if (itr->GetSource()->InSamePhase(i_phaseMask))
184  if (i_check(itr->GetSource()))
185  i_objects.push_back(itr->GetSource());
186 }
187 
188 template<class Check>
190 {
191  for (DynamicObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
192  if (itr->GetSource()->InSamePhase(i_phaseMask))
193  if (i_check(itr->GetSource()))
194  i_objects.push_back(itr->GetSource());
195 }
196 
197 // Gameobject searchers
198 
199 template<class Check>
201 {
202  // already found
203  if (i_object)
204  return;
205 
206  for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
207  {
208  if (!itr->GetSource()->InSamePhase(i_phaseMask))
209  continue;
210 
211  if (i_check(itr->GetSource()))
212  {
213  i_object = itr->GetSource();
214  return;
215  }
216  }
217 }
218 
219 template<class Check>
221 {
222  for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
223  {
224  if (!itr->GetSource()->InSamePhase(i_phaseMask))
225  continue;
226 
227  if (i_check(itr->GetSource()))
228  i_object = itr->GetSource();
229  }
230 }
231 
232 template<class Check>
234 {
235  for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
236  if (itr->GetSource()->InSamePhase(i_phaseMask))
237  if (i_check(itr->GetSource()))
238  i_objects.push_back(itr->GetSource());
239 }
240 
241 // Unit searchers
242 
243 template<class Check>
245 {
246  // already found
247  if (i_object)
248  return;
249 
250  for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
251  {
252  if (!itr->GetSource()->InSamePhase(i_phaseMask))
253  continue;
254 
255  if (i_check(itr->GetSource()))
256  {
257  i_object = itr->GetSource();
258  return;
259  }
260  }
261 }
262 
263 template<class Check>
265 {
266  // already found
267  if (i_object)
268  return;
269 
270  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
271  {
272  if (!itr->GetSource()->InSamePhase(i_phaseMask))
273  continue;
274 
275  if (i_check(itr->GetSource()))
276  {
277  i_object = itr->GetSource();
278  return;
279  }
280  }
281 }
282 
283 template<class Check>
285 {
286  for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
287  {
288  if (!itr->GetSource()->InSamePhase(i_phaseMask))
289  continue;
290 
291  if (i_check(itr->GetSource()))
292  i_object = itr->GetSource();
293  }
294 }
295 
296 template<class Check>
298 {
299  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
300  {
301  if (!itr->GetSource()->InSamePhase(i_phaseMask))
302  continue;
303 
304  if (i_check(itr->GetSource()))
305  i_object = itr->GetSource();
306  }
307 }
308 
309 template<class Check>
311 {
312  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
313  if (itr->GetSource()->InSamePhase(i_phaseMask))
314  if (i_check(itr->GetSource()))
315  i_objects.push_back(itr->GetSource());
316 }
317 
318 template<class Check>
320 {
321  for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
322  if (itr->GetSource()->InSamePhase(i_phaseMask))
323  if (i_check(itr->GetSource()))
324  i_objects.push_back(itr->GetSource());
325 }
326 
327 // Creature searchers
328 
329 template<class Check>
331 {
332  // already found
333  if (i_object)
334  return;
335 
336  for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
337  {
338  if (!itr->GetSource()->InSamePhase(i_phaseMask))
339  continue;
340 
341  if (i_check(itr->GetSource()))
342  {
343  i_object = itr->GetSource();
344  return;
345  }
346  }
347 }
348 
349 template<class Check>
351 {
352  for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
353  {
354  if (!itr->GetSource()->InSamePhase(i_phaseMask))
355  continue;
356 
357  if (i_check(itr->GetSource()))
358  i_object = itr->GetSource();
359  }
360 }
361 
362 template<class Check>
364 {
365  for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
366  if (itr->GetSource()->InSamePhase(i_phaseMask))
367  if (i_check(itr->GetSource()))
368  i_objects.push_back(itr->GetSource());
369 }
370 
371 template<class Check>
373 {
374  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
375  if (itr->GetSource()->InSamePhase(i_phaseMask))
376  if (i_check(itr->GetSource()))
377  i_objects.push_back(itr->GetSource());
378 }
379 
380 template<class Check>
382 {
383  // already found
384  if (i_object)
385  return;
386 
387  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
388  {
389  if (!itr->GetSource()->InSamePhase(i_phaseMask))
390  continue;
391 
392  if (i_check(itr->GetSource()))
393  {
394  i_object = itr->GetSource();
395  return;
396  }
397  }
398 }
399 
400 template<class Builder>
402 {
403  uint32 loc_idx = p->GetSession()->GetSessionDbLocaleIndex();
404  uint32 cache_idx = loc_idx + 1;
405  WorldPacket* data;
406 
407  // create if not cached yet
408  if (i_data_cache.size() < cache_idx + 1 || !i_data_cache[cache_idx])
409  {
410  if (i_data_cache.size() < cache_idx + 1)
411  i_data_cache.resize(cache_idx + 1);
412 
413  data = new WorldPacket(SMSG_MESSAGECHAT, 200);
414 
415  i_builder(*data, loc_idx);
416 
417  i_data_cache[cache_idx] = data;
418  }
419  else
420  data = i_data_cache[cache_idx];
421 
422  p->SendDirectMessage(data);
423 }
424 
425 template<class Builder>
427 {
428  uint32 loc_idx = p->GetSession()->GetSessionDbLocaleIndex();
429  uint32 cache_idx = loc_idx + 1;
430  WorldPacketList* data_list;
431 
432  // create if not cached yet
433  if (i_data_cache.size() < cache_idx + 1 || i_data_cache[cache_idx].empty())
434  {
435  if (i_data_cache.size() < cache_idx + 1)
436  i_data_cache.resize(cache_idx + 1);
437 
438  data_list = &i_data_cache[cache_idx];
439 
440  i_builder(*data_list, loc_idx);
441  }
442  else
443  data_list = &i_data_cache[cache_idx];
444 
445  for (size_t i = 0; i < data_list->size(); ++i)
446  p->SendDirectMessage((*data_list)[i]);
447 }
448 
449 #endif // OREGON_GRIDNOTIFIERSIMPL_H
450 
void Visit(CreatureMapType &m)
void Visit(CreatureMapType &m)
void Visit(GameObjectMapType &m)
void UpdateVisibilityOf(WorldObject *target)
Definition: Player.cpp:18789
void resize(size_t newsize)
Definition: ByteBuffer.h:345
void Visit(GridRefManager< T > &m)
void Visit(PlayerMapType &m)
std::set< Unit * > i_visibleNow
Definition: GridNotifiers.h:43
void Visit(GameObjectMapType &m)
void Visit(CreatureMapType &m)
void SendDirectMessage(WorldPacket *data)
Definition: Player.cpp:5724
Player::ClientGUIDs vis_guids
Definition: GridNotifiers.h:44
iterator end()
void Visit(GameObjectMapType &m)
void Visit(PlayerMapType &m)
int GetSessionDbLocaleIndex() const
Definition: WorldSession.h:237
void Visit(GameObjectMapType &m)
void Visit(CreatureMapType &m)
iterator begin()
WorldSession * GetSession() const
Definition: Player.h:1944
std::vector< WorldPacket * > WorldPacketList
ACE_UINT32 uint32
Definition: Define.h:71
void Visit(CreatureMapType &m)
Definition: Player.h:922
void Visit(GridRefManager< T > &m)
void Visit(PlayerMapType &m)