TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GridNotifiersImpl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITY_GRIDNOTIFIERSIMPL_H
20 #define TRINITY_GRIDNOTIFIERSIMPL_H
21 
22 #include "GridNotifiers.h"
23 #include "WorldPacket.h"
24 #include "Corpse.h"
25 #include "Player.h"
26 #include "UpdateData.h"
27 #include "CreatureAI.h"
28 #include "SpellAuras.h"
29 #include "Opcodes.h"
30 
31 template<class T>
33 {
34  for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
35  {
36  vis_guids.erase(iter->GetSource()->GetGUID());
37  i_player.UpdateVisibilityOf(iter->GetSource(), i_data, i_visibleNow);
38  }
39 }
40 
41 // SEARCHERS & LIST SEARCHERS & WORKERS
42 
43 // WorldObject searchers & workers
44 
45 template<class Check>
47 {
48  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_GAMEOBJECT))
49  return;
50 
51  // already found
52  if (i_object)
53  return;
54 
55  for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
56  {
57  if (!itr->GetSource()->IsInPhase(_searcher))
58  continue;
59 
60  if (i_check(itr->GetSource()))
61  {
62  i_object = itr->GetSource();
63  return;
64  }
65  }
66 }
67 
68 template<class Check>
70 {
71  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_PLAYER))
72  return;
73 
74  // already found
75  if (i_object)
76  return;
77 
78  for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
79  {
80  if (!itr->GetSource()->IsInPhase(_searcher))
81  continue;
82 
83  if (i_check(itr->GetSource()))
84  {
85  i_object = itr->GetSource();
86  return;
87  }
88  }
89 }
90 
91 template<class Check>
93 {
94  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CREATURE))
95  return;
96 
97  // already found
98  if (i_object)
99  return;
100 
101  for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
102  {
103  if (!itr->GetSource()->IsInPhase(_searcher))
104  continue;
105 
106  if (i_check(itr->GetSource()))
107  {
108  i_object = itr->GetSource();
109  return;
110  }
111  }
112 }
113 
114 template<class Check>
116 {
117  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CORPSE))
118  return;
119 
120  // already found
121  if (i_object)
122  return;
123 
124  for (CorpseMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
125  {
126  if (!itr->GetSource()->IsInPhase(_searcher))
127  continue;
128 
129  if (i_check(itr->GetSource()))
130  {
131  i_object = itr->GetSource();
132  return;
133  }
134  }
135 }
136 
137 template<class Check>
139 {
140  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_DYNAMICOBJECT))
141  return;
142 
143  // already found
144  if (i_object)
145  return;
146 
147  for (DynamicObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
148  {
149  if (!itr->GetSource()->IsInPhase(_searcher))
150  continue;
151 
152  if (i_check(itr->GetSource()))
153  {
154  i_object = itr->GetSource();
155  return;
156  }
157  }
158 }
159 
160 template<class Check>
162 {
163  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_AREATRIGGER))
164  return;
165 
166  // already found
167  if (i_object)
168  return;
169 
170  for (AreaTriggerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
171  {
172  if (!itr->GetSource()->IsInPhase(_searcher))
173  continue;
174 
175  if (i_check(itr->GetSource()))
176  {
177  i_object = itr->GetSource();
178  return;
179  }
180  }
181 }
182 
183 template<class Check>
185 {
186  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_GAMEOBJECT))
187  return;
188 
189  for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
190  {
191  if (!itr->GetSource()->IsInPhase(_searcher))
192  continue;
193 
194  if (i_check(itr->GetSource()))
195  i_object = itr->GetSource();
196  }
197 }
198 
199 template<class Check>
201 {
202  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_PLAYER))
203  return;
204 
205  for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
206  {
207  if (!itr->GetSource()->IsInPhase(_searcher))
208  continue;
209 
210  if (i_check(itr->GetSource()))
211  i_object = itr->GetSource();
212  }
213 }
214 
215 template<class Check>
217 {
218  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CREATURE))
219  return;
220 
221  for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
222  {
223  if (!itr->GetSource()->IsInPhase(_searcher))
224  continue;
225 
226  if (i_check(itr->GetSource()))
227  i_object = itr->GetSource();
228  }
229 }
230 
231 template<class Check>
233 {
234  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CORPSE))
235  return;
236 
237  for (CorpseMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
238  {
239  if (!itr->GetSource()->IsInPhase(_searcher))
240  continue;
241 
242  if (i_check(itr->GetSource()))
243  i_object = itr->GetSource();
244  }
245 }
246 
247 template<class Check>
249 {
250  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_DYNAMICOBJECT))
251  return;
252 
253  for (DynamicObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
254  {
255  if (!itr->GetSource()->IsInPhase(_searcher))
256  continue;
257 
258  if (i_check(itr->GetSource()))
259  i_object = itr->GetSource();
260  }
261 }
262 
263 template<class Check>
265 {
266  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_AREATRIGGER))
267  return;
268 
269  for (AreaTriggerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
270  {
271  if (!itr->GetSource()->IsInPhase(_searcher))
272  continue;
273 
274  if (i_check(itr->GetSource()))
275  i_object = itr->GetSource();
276  }
277 }
278 
279 template<class Check>
281 {
282  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_PLAYER))
283  return;
284 
285  for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
286  if (i_check(itr->GetSource()))
287  i_objects.push_back(itr->GetSource());
288 }
289 
290 template<class Check>
292 {
293  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CREATURE))
294  return;
295 
296  for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
297  if (i_check(itr->GetSource()))
298  i_objects.push_back(itr->GetSource());
299 }
300 
301 template<class Check>
303 {
304  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_CORPSE))
305  return;
306 
307  for (CorpseMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
308  if (i_check(itr->GetSource()))
309  i_objects.push_back(itr->GetSource());
310 }
311 
312 template<class Check>
314 {
315  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_GAMEOBJECT))
316  return;
317 
318  for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
319  if (i_check(itr->GetSource()))
320  i_objects.push_back(itr->GetSource());
321 }
322 
323 template<class Check>
325 {
326  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_DYNAMICOBJECT))
327  return;
328 
329  for (DynamicObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
330  if (i_check(itr->GetSource()))
331  i_objects.push_back(itr->GetSource());
332 }
333 
334 template<class Check>
336 {
337  if (!(i_mapTypeMask & GRID_MAP_TYPE_MASK_AREATRIGGER))
338  return;
339 
340  for (AreaTriggerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
341  if (i_check(itr->GetSource()))
342  i_objects.push_back(itr->GetSource());
343 }
344 
345 // Gameobject searchers
346 
347 template<class Check>
349 {
350  // already found
351  if (i_object)
352  return;
353 
354  for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
355  {
356  if (!itr->GetSource()->IsInPhase(_searcher))
357  continue;
358 
359  if (i_check(itr->GetSource()))
360  {
361  i_object = itr->GetSource();
362  return;
363  }
364  }
365 }
366 
367 template<class Check>
369 {
370  for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
371  {
372  if (!itr->GetSource()->IsInPhase(_searcher))
373  continue;
374 
375  if (i_check(itr->GetSource()))
376  i_object = itr->GetSource();
377  }
378 }
379 
380 template<class Check>
382 {
383  for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
384  if (itr->GetSource()->IsInPhase(_searcher))
385  if (i_check(itr->GetSource()))
386  i_objects.push_back(itr->GetSource());
387 }
388 
389 // Unit searchers
390 
391 template<class Check>
393 {
394  // already found
395  if (i_object)
396  return;
397 
398  for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
399  {
400  if (!itr->GetSource()->IsInPhase(_searcher))
401  continue;
402 
403  if (i_check(itr->GetSource()))
404  {
405  i_object = itr->GetSource();
406  return;
407  }
408  }
409 }
410 
411 template<class Check>
413 {
414  // already found
415  if (i_object)
416  return;
417 
418  for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
419  {
420  if (!itr->GetSource()->IsInPhase(_searcher))
421  continue;
422 
423  if (i_check(itr->GetSource()))
424  {
425  i_object = itr->GetSource();
426  return;
427  }
428  }
429 }
430 
431 template<class Check>
433 {
434  for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
435  {
436  if (!itr->GetSource()->IsInPhase(_searcher))
437  continue;
438 
439  if (i_check(itr->GetSource()))
440  i_object = itr->GetSource();
441  }
442 }
443 
444 template<class Check>
446 {
447  for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
448  {
449  if (!itr->GetSource()->IsInPhase(_searcher))
450  continue;
451 
452  if (i_check(itr->GetSource()))
453  i_object = itr->GetSource();
454  }
455 }
456 
457 template<class Check>
459 {
460  for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
461  if (itr->GetSource()->IsInPhase(_searcher))
462  if (i_check(itr->GetSource()))
463  i_objects.push_back(itr->GetSource());
464 }
465 
466 template<class Check>
468 {
469  for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
470  if (itr->GetSource()->IsInPhase(_searcher))
471  if (i_check(itr->GetSource()))
472  i_objects.push_back(itr->GetSource());
473 }
474 
475 // Creature searchers
476 
477 template<class Check>
479 {
480  // already found
481  if (i_object)
482  return;
483 
484  for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
485  {
486  if (!itr->GetSource()->IsInPhase(_searcher))
487  continue;
488 
489  if (i_check(itr->GetSource()))
490  {
491  i_object = itr->GetSource();
492  return;
493  }
494  }
495 }
496 
497 template<class Check>
499 {
500  for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
501  {
502  if (!itr->GetSource()->IsInPhase(_searcher))
503  continue;
504 
505  if (i_check(itr->GetSource()))
506  i_object = itr->GetSource();
507  }
508 }
509 
510 template<class Check>
512 {
513  for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
514  if (itr->GetSource()->IsInPhase(_searcher))
515  if (i_check(itr->GetSource()))
516  i_objects.push_back(itr->GetSource());
517 }
518 
519 template<class Check>
521 {
522  for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
523  if (itr->GetSource()->IsInPhase(_searcher))
524  if (i_check(itr->GetSource()))
525  i_objects.push_back(itr->GetSource());
526 }
527 
528 template<class Check>
530 {
531  // already found
532  if (i_object)
533  return;
534 
535  for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
536  {
537  if (!itr->GetSource()->IsInPhase(_searcher))
538  continue;
539 
540  if (i_check(itr->GetSource()))
541  {
542  i_object = itr->GetSource();
543  return;
544  }
545  }
546 }
547 
548 template<class Check>
550 {
551  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
552  {
553  if (!itr->GetSource()->IsInPhase(_searcher))
554  continue;
555 
556  if (i_check(itr->GetSource()))
557  i_object = itr->GetSource();
558  }
559 }
560 
561 template<class Builder>
563 {
564  LocaleConstant loc_idx = p->GetSession()->GetSessionDbLocaleIndex();
565  uint32 cache_idx = loc_idx+1;
566  WorldPackets::Packet* data;
567 
568  // create if not cached yet
569  if (i_data_cache.size() < cache_idx + 1 || !i_data_cache[cache_idx])
570  {
571  if (i_data_cache.size() < cache_idx + 1)
572  i_data_cache.resize(cache_idx + 1);
573 
574  data = i_builder(loc_idx);
575 
576  ASSERT(data->GetSize() == 0);
577 
578  data->Write();
579 
580  i_data_cache[cache_idx] = data;
581  }
582  else
583  data = i_data_cache[cache_idx];
584 
585  p->SendDirectMessage(data->GetRawPacket());
586 }
587 
588 template<class Builder>
590 {
591  LocaleConstant loc_idx = p->GetSession()->GetSessionDbLocaleIndex();
592  uint32 cache_idx = loc_idx+1;
593  WorldPacketList* data_list;
594 
595  // create if not cached yet
596  if (i_data_cache.size() < cache_idx+1 || i_data_cache[cache_idx].empty())
597  {
598  if (i_data_cache.size() < cache_idx+1)
599  i_data_cache.resize(cache_idx+1);
600 
601  data_list = &i_data_cache[cache_idx];
602 
603  i_builder(*data_list, loc_idx);
604  }
605  else
606  data_list = &i_data_cache[cache_idx];
607 
608  for (size_t i = 0; i < data_list->size(); ++i)
609  p->SendDirectMessage((*data_list)[i]->GetRawPacket());
610 }
611 
612 #endif // TRINITY_GRIDNOTIFIERSIMPL_H
Definition: GridDefines.h:78
UpdateData i_data
Definition: GridNotifiers.h:46
void Visit(PlayerMapType &m)
Definition: GridNotifiersImpl.h:549
void Visit(CreatureMapType &m)
Definition: GridNotifiersImpl.h:498
Definition: GridDefines.h:77
void Visit(CreatureMapType &m)
Definition: GridNotifiersImpl.h:511
void Visit(PlayerMapType &m)
Definition: GridNotifiersImpl.h:458
std::vector< WorldPackets::Packet * > WorldPacketList
Definition: GridNotifiers.h:1422
void Visit(GameObjectMapType &m)
Definition: GridNotifiersImpl.h:348
void Visit(CreatureMapType &m)
Definition: GridNotifiersImpl.h:432
void Visit(GameObjectMapType &m)
Definition: GridNotifiersImpl.h:46
Definition: GridDefines.h:76
void Visit(GameObjectMapType &m)
Definition: GridNotifiersImpl.h:184
void Visit(GridRefManager< T > &m)
Definition: GridNotifiersImpl.h:32
LocaleConstant
Definition: Common.h:115
void operator()(Player *p)
Definition: GridNotifiersImpl.h:562
Definition: Packet.h:25
void Visit(PlayerMapType &m)
Definition: GridNotifiersImpl.h:529
WorldPacket const * GetRawPacket() const
Definition: Packet.h:38
Definition: GridDefines.h:75
uint32_t uint32
Definition: Define.h:150
Definition: LinkedList.h:141
Player & i_player
Definition: GridNotifiers.h:45
void operator()(Player *p)
Definition: GridNotifiersImpl.h:589
iterator begin()
Definition: GridRefManager.h:36
size_t GetSize() const
Definition: Packet.h:39
void Visit(PlayerMapType &m)
Definition: GridNotifiersImpl.h:520
void Visit(GameObjectMapType &m)
Definition: GridNotifiersImpl.h:381
virtual WorldPacket const * Write()=0
void Visit(CreatureMapType &m)
Definition: GridNotifiersImpl.h:392
#define ASSERT
Definition: Errors.h:55
std::set< Unit * > i_visibleNow
Definition: GridNotifiers.h:47
GuidUnorderedSet vis_guids
Definition: GridNotifiers.h:48
Definition: GridDefines.h:74
iterator end()
Definition: GridRefManager.h:37
void Visit(PlayerMapType &m)
Definition: GridNotifiersImpl.h:280
void Visit(CreatureMapType &m)
Definition: GridNotifiersImpl.h:478
Definition: GridDefines.h:73
void Visit(GameObjectMapType &m)
Definition: GridNotifiersImpl.h:368