[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / GridNotifiers.h
bloba000dd9278c2abcbe3dcf218f47a980369be7bb3
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_GRIDNOTIFIERS_H
20 #define MANGOS_GRIDNOTIFIERS_H
22 #include "ObjectGridLoader.h"
23 #include "ByteBuffer.h"
24 #include "UpdateData.h"
25 #include <iostream>
27 #include "Corpse.h"
28 #include "Object.h"
29 #include "DynamicObject.h"
30 #include "GameObject.h"
31 #include "Player.h"
32 #include "Unit.h"
34 class Player;
35 //class Map;
37 namespace MaNGOS
40 struct MANGOS_DLL_DECL PlayerNotifier
42 explicit PlayerNotifier(Player &pl) : i_player(pl) {}
43 void Visit(PlayerMapType &);
44 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
45 Player &i_player;
48 struct MANGOS_DLL_DECL VisibleNotifier
50 Player &i_player;
51 UpdateData i_data;
52 UpdateDataMapType i_data_updates;
53 Player::ClientGUIDs i_clientGUIDs;
54 std::set<WorldObject*> i_visibleNow;
56 explicit VisibleNotifier(Player &player) : i_player(player),i_clientGUIDs(player.m_clientGUIDs) {}
57 template<class T> void Visit(GridRefManager<T> &m);
58 void Visit(PlayerMapType &);
59 void Notify(void);
62 struct MANGOS_DLL_DECL VisibleChangesNotifier
64 WorldObject &i_object;
66 explicit VisibleChangesNotifier(WorldObject &object) : i_object(object) {}
67 template<class T> void Visit(GridRefManager<T> &) {}
68 void Visit(PlayerMapType &);
71 struct MANGOS_DLL_DECL GridUpdater
73 GridType &i_grid;
74 uint32 i_timeDiff;
75 GridUpdater(GridType &grid, uint32 diff) : i_grid(grid), i_timeDiff(diff) {}
77 template<class T> void updateObjects(GridRefManager<T> &m)
79 for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
80 iter->getSource()->Update(i_timeDiff);
83 void Visit(PlayerMapType &m) { updateObjects<Player>(m); }
84 void Visit(CreatureMapType &m){ updateObjects<Creature>(m); }
85 void Visit(GameObjectMapType &m) { updateObjects<GameObject>(m); }
86 void Visit(DynamicObjectMapType &m) { updateObjects<DynamicObject>(m); }
87 void Visit(CorpseMapType &m) { updateObjects<Corpse>(m); }
90 struct MANGOS_DLL_DECL MessageDeliverer
92 Player &i_player;
93 WorldPacket *i_message;
94 bool i_toSelf;
95 MessageDeliverer(Player &pl, WorldPacket *msg, bool to_self) : i_player(pl), i_message(msg), i_toSelf(to_self) {}
96 void Visit(PlayerMapType &m);
97 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
100 struct MANGOS_DLL_DECL ObjectMessageDeliverer
102 uint32 i_phaseMask;
103 WorldPacket *i_message;
104 explicit ObjectMessageDeliverer(WorldObject& obj, WorldPacket *msg)
105 : i_phaseMask(obj.GetPhaseMask()), i_message(msg) {}
106 void Visit(PlayerMapType &m);
107 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
110 struct MANGOS_DLL_DECL MessageDistDeliverer
112 Player &i_player;
113 WorldPacket *i_message;
114 bool i_toSelf;
115 bool i_ownTeamOnly;
116 float i_dist;
117 MessageDistDeliverer(Player &pl, WorldPacket *msg, float dist, bool to_self, bool ownTeamOnly) : i_player(pl), i_message(msg), i_dist(dist), i_toSelf(to_self), i_ownTeamOnly(ownTeamOnly) {}
118 void Visit(PlayerMapType &m);
119 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
122 struct MANGOS_DLL_DECL ObjectMessageDistDeliverer
124 WorldObject &i_object;
125 WorldPacket *i_message;
126 float i_dist;
127 ObjectMessageDistDeliverer(WorldObject &obj, WorldPacket *msg, float dist) : i_object(obj), i_message(msg), i_dist(dist) {}
128 void Visit(PlayerMapType &m);
129 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
132 struct MANGOS_DLL_DECL ObjectUpdater
134 uint32 i_timeDiff;
135 explicit ObjectUpdater(const uint32 &diff) : i_timeDiff(diff) {}
136 template<class T> void Visit(GridRefManager<T> &m);
137 void Visit(PlayerMapType &) {}
138 void Visit(CorpseMapType &) {}
139 void Visit(CreatureMapType &);
142 template<class T>
143 struct MANGOS_DLL_DECL ObjectAccessorNotifier
145 T *& i_object;
147 uint64 i_id;
148 ObjectAccessorNotifier(T * &obj, uint64 id) : i_object(obj), i_id(id)
150 i_object = NULL;
153 void Visit(GridRefManager<T> &m )
155 if( i_object == NULL )
157 GridRefManager<T> *iter = m.find(i_id);
158 if( iter != m.end() )
160 assert( iter->second != NULL );
161 i_object = iter->second;
166 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
169 struct MANGOS_DLL_DECL PlayerRelocationNotifier
171 Player &i_player;
172 PlayerRelocationNotifier(Player &pl) : i_player(pl) {}
173 template<class T> void Visit(GridRefManager<T> &) {}
174 void Visit(PlayerMapType &);
175 void Visit(CreatureMapType &);
178 struct MANGOS_DLL_DECL CreatureRelocationNotifier
180 Creature &i_creature;
181 CreatureRelocationNotifier(Creature &c) : i_creature(c) {}
182 template<class T> void Visit(GridRefManager<T> &) {}
183 #ifdef WIN32
184 template<> void Visit(PlayerMapType &);
185 #endif
188 struct MANGOS_DLL_DECL DynamicObjectUpdater
190 DynamicObject &i_dynobject;
191 Unit* i_check;
192 DynamicObjectUpdater(DynamicObject &dynobject, Unit* caster) : i_dynobject(dynobject)
194 i_check = caster;
195 Unit* owner = i_check->GetOwner();
196 if(owner)
197 i_check = owner;
200 template<class T> inline void Visit(GridRefManager<T> &) {}
201 #ifdef WIN32
202 template<> inline void Visit<Player>(PlayerMapType &);
203 template<> inline void Visit<Creature>(CreatureMapType &);
204 #endif
206 void VisitHelper(Unit* target);
209 // SEARCHERS & LIST SEARCHERS & WORKERS
211 // WorldObject searchers & workers
213 template<class Check>
214 struct MANGOS_DLL_DECL WorldObjectSearcher
216 uint32 i_phaseMask;
217 WorldObject* &i_object;
218 Check &i_check;
220 WorldObjectSearcher(WorldObject const* searcher, WorldObject* & result, Check& check)
221 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
223 void Visit(GameObjectMapType &m);
224 void Visit(PlayerMapType &m);
225 void Visit(CreatureMapType &m);
226 void Visit(CorpseMapType &m);
227 void Visit(DynamicObjectMapType &m);
229 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
232 template<class Check>
233 struct MANGOS_DLL_DECL WorldObjectListSearcher
235 uint32 i_phaseMask;
236 std::list<WorldObject*> &i_objects;
237 Check& i_check;
239 WorldObjectListSearcher(WorldObject const* searcher, std::list<WorldObject*> &objects, Check & check)
240 : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects),i_check(check) {}
242 void Visit(PlayerMapType &m);
243 void Visit(CreatureMapType &m);
244 void Visit(CorpseMapType &m);
245 void Visit(GameObjectMapType &m);
246 void Visit(DynamicObjectMapType &m);
248 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
251 template<class Do>
252 struct MANGOS_DLL_DECL WorldObjectWorker
254 uint32 i_phaseMask;
255 Do const& i_do;
257 WorldObjectWorker(WorldObject const* searcher, Do const& _do)
258 : i_phaseMask(searcher->GetPhaseMask()), i_do(_do) {}
260 void Visit(GameObjectMapType &m)
262 for(GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
263 if(itr->getSource()->InSamePhase(i_phaseMask))
264 i_do(itr->getSource());
267 void Visit(PlayerMapType &m)
269 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
270 if(itr->getSource()->InSamePhase(i_phaseMask))
271 i_do(itr->getSource());
273 void Visit(CreatureMapType &m)
275 for(CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
276 if(itr->getSource()->InSamePhase(i_phaseMask))
277 i_do(itr->getSource());
280 void Visit(CorpseMapType &m)
282 for(CorpseMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
283 if(itr->getSource()->InSamePhase(i_phaseMask))
284 i_do(itr->getSource());
287 void Visit(DynamicObjectMapType &m)
289 for(DynamicObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
290 if(itr->getSource()->InSamePhase(i_phaseMask))
291 i_do(itr->getSource());
294 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
297 // Gameobject searchers
299 template<class Check>
300 struct MANGOS_DLL_DECL GameObjectSearcher
302 uint32 i_phaseMask;
303 GameObject* &i_object;
304 Check &i_check;
306 GameObjectSearcher(WorldObject const* searcher, GameObject* & result, Check& check)
307 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
309 void Visit(GameObjectMapType &m);
311 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
314 // Last accepted by Check GO if any (Check can change requirements at each call)
315 template<class Check>
316 struct MANGOS_DLL_DECL GameObjectLastSearcher
318 uint32 i_phaseMask;
319 GameObject* &i_object;
320 Check& i_check;
322 GameObjectLastSearcher(WorldObject const* searcher, GameObject* & result, Check& check)
323 : i_phaseMask(searcher->GetPhaseMask()), i_object(result), i_check(check) {}
325 void Visit(GameObjectMapType &m);
327 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
330 template<class Check>
331 struct MANGOS_DLL_DECL GameObjectListSearcher
333 uint32 i_phaseMask;
334 std::list<GameObject*> &i_objects;
335 Check& i_check;
337 GameObjectListSearcher(WorldObject const* searcher, std::list<GameObject*> &objects, Check & check)
338 : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) {}
340 void Visit(GameObjectMapType &m);
342 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
345 // Unit searchers
347 // First accepted by Check Unit if any
348 template<class Check>
349 struct MANGOS_DLL_DECL UnitSearcher
351 uint32 i_phaseMask;
352 Unit* &i_object;
353 Check & i_check;
355 UnitSearcher(WorldObject const* searcher, Unit* & result, Check & check)
356 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
358 void Visit(CreatureMapType &m);
359 void Visit(PlayerMapType &m);
361 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
364 // Last accepted by Check Unit if any (Check can change requirements at each call)
365 template<class Check>
366 struct MANGOS_DLL_DECL UnitLastSearcher
368 uint32 i_phaseMask;
369 Unit* &i_object;
370 Check & i_check;
372 UnitLastSearcher(WorldObject const* searcher, Unit* & result, Check & check)
373 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
375 void Visit(CreatureMapType &m);
376 void Visit(PlayerMapType &m);
378 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
381 // All accepted by Check units if any
382 template<class Check>
383 struct MANGOS_DLL_DECL UnitListSearcher
385 uint32 i_phaseMask;
386 std::list<Unit*> &i_objects;
387 Check& i_check;
389 UnitListSearcher(WorldObject const* searcher, std::list<Unit*> &objects, Check & check)
390 : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects),i_check(check) {}
392 void Visit(PlayerMapType &m);
393 void Visit(CreatureMapType &m);
395 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
398 // Creature searchers
400 template<class Check>
401 struct MANGOS_DLL_DECL CreatureSearcher
403 uint32 i_phaseMask;
404 Creature* &i_object;
405 Check & i_check;
407 CreatureSearcher(WorldObject const* searcher, Creature* & result, Check & check)
408 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
410 void Visit(CreatureMapType &m);
412 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
415 // Last accepted by Check Creature if any (Check can change requirements at each call)
416 template<class Check>
417 struct MANGOS_DLL_DECL CreatureLastSearcher
419 uint32 i_phaseMask;
420 Creature* &i_object;
421 Check & i_check;
423 CreatureLastSearcher(WorldObject const* searcher, Creature* & result, Check & check)
424 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
426 void Visit(CreatureMapType &m);
428 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
431 template<class Check>
432 struct MANGOS_DLL_DECL CreatureListSearcher
434 uint32 i_phaseMask;
435 std::list<Creature*> &i_objects;
436 Check& i_check;
438 CreatureListSearcher(WorldObject const* searcher, std::list<Creature*> &objects, Check & check)
439 : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects),i_check(check) {}
441 void Visit(CreatureMapType &m);
443 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
446 // Player searchers
448 template<class Check>
449 struct MANGOS_DLL_DECL PlayerSearcher
451 uint32 i_phaseMask;
452 Player* &i_object;
453 Check & i_check;
455 PlayerSearcher(WorldObject const* searcher, Player* & result, Check & check)
456 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
458 void Visit(PlayerMapType &m);
460 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
463 template<class Do>
464 struct MANGOS_DLL_DECL PlayerWorker
466 uint32 i_phaseMask;
467 Do& i_do;
469 PlayerWorker(WorldObject const* searcher, Do& _do)
470 : i_phaseMask(searcher->GetPhaseMask()), i_do(_do) {}
472 void Visit(PlayerMapType &m)
474 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
475 if(itr->getSource()->InSamePhase(i_phaseMask))
476 i_do(itr->getSource());
479 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
482 // CHECKS && DO classes
484 // WorldObject check classes
485 class CannibalizeObjectCheck
487 public:
488 CannibalizeObjectCheck(Unit* funit, float range) : i_funit(funit), i_range(range) {}
489 bool operator()(Player* u)
491 if( i_funit->IsFriendlyTo(u) || u->isAlive() || u->isInFlight() )
492 return false;
494 if(i_funit->IsWithinDistInMap(u, i_range) )
495 return true;
497 return false;
499 bool operator()(Corpse* u);
500 bool operator()(Creature* u)
502 if( i_funit->IsFriendlyTo(u) || u->isAlive() || u->isInFlight() ||
503 (u->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD)==0)
504 return false;
506 if(i_funit->IsWithinDistInMap(u, i_range) )
507 return true;
509 return false;
511 template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
512 private:
513 Unit* const i_funit;
514 float i_range;
517 // WorldObject do classes
519 class RespawnDo
521 public:
522 RespawnDo() {}
523 void operator()(Creature* u) const { u->Respawn(); }
524 void operator()(GameObject* u) const { u->Respawn(); }
525 void operator()(WorldObject*) const {}
526 void operator()(Corpse*) const {}
529 // GameObject checks
531 class GameObjectFocusCheck
533 public:
534 GameObjectFocusCheck(Unit const* unit,uint32 focusId) : i_unit(unit), i_focusId(focusId) {}
535 bool operator()(GameObject* go) const
537 if(go->GetGOInfo()->type != GAMEOBJECT_TYPE_SPELL_FOCUS)
538 return false;
540 if(go->GetGOInfo()->spellFocus.focusId != i_focusId)
541 return false;
543 float dist = go->GetGOInfo()->spellFocus.dist;
545 return go->IsWithinDistInMap(i_unit, dist);
547 private:
548 Unit const* i_unit;
549 uint32 i_focusId;
552 // Find the nearest Fishing hole and return true only if source object is in range of hole
553 class NearestGameObjectFishingHole
555 public:
556 NearestGameObjectFishingHole(WorldObject const& obj, float range) : i_obj(obj), i_range(range) {}
557 bool operator()(GameObject* go)
559 if(go->GetGOInfo()->type == GAMEOBJECT_TYPE_FISHINGHOLE && go->isSpawned() && i_obj.IsWithinDistInMap(go, i_range) && i_obj.IsWithinDistInMap(go, go->GetGOInfo()->fishinghole.radius))
561 i_range = i_obj.GetDistance(go);
562 return true;
564 return false;
566 float GetLastRange() const { return i_range; }
567 private:
568 WorldObject const& i_obj;
569 float i_range;
571 // prevent clone
572 NearestGameObjectFishingHole(NearestGameObjectFishingHole const&);
575 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO)
576 class NearestGameObjectEntryInObjectRangeCheck
578 public:
579 NearestGameObjectEntryInObjectRangeCheck(WorldObject const& obj,uint32 entry, float range) : i_obj(obj), i_entry(entry), i_range(range) {}
580 bool operator()(GameObject* go)
582 if(go->GetEntry() == i_entry && i_obj.IsWithinDistInMap(go, i_range))
584 i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
585 return true;
587 return false;
589 float GetLastRange() const { return i_range; }
590 private:
591 WorldObject const& i_obj;
592 uint32 i_entry;
593 float i_range;
595 // prevent clone this object
596 NearestGameObjectEntryInObjectRangeCheck(NearestGameObjectEntryInObjectRangeCheck const&);
599 class GameObjectWithDbGUIDCheck
601 public:
602 GameObjectWithDbGUIDCheck(WorldObject const& obj,uint32 db_guid) : i_obj(obj), i_db_guid(db_guid) {}
603 bool operator()(GameObject const* go) const
605 return go->GetDBTableGUIDLow() == i_db_guid;
607 private:
608 WorldObject const& i_obj;
609 uint32 i_db_guid;
612 // Unit checks
614 class AnyUnfriendlyUnitInObjectRangeCheck
616 public:
617 AnyUnfriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
618 bool operator()(Unit* u)
620 if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range) && !i_funit->IsFriendlyTo(u))
621 return true;
622 else
623 return false;
625 private:
626 WorldObject const* i_obj;
627 Unit const* i_funit;
628 float i_range;
631 class AnyFriendlyUnitInObjectRangeCheck
633 public:
634 AnyFriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
635 bool operator()(Unit* u)
637 if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range) && i_funit->IsFriendlyTo(u))
638 return true;
639 else
640 return false;
642 private:
643 WorldObject const* i_obj;
644 Unit const* i_funit;
645 float i_range;
648 class AnyUnitInObjectRangeCheck
650 public:
651 AnyUnitInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {}
652 bool operator()(Unit* u)
654 if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range))
655 return true;
657 return false;
659 private:
660 WorldObject const* i_obj;
661 float i_range;
664 // Success at unit in range, range update for next check (this can be use with UnitLastSearcher to find nearest unit)
665 class NearestAttackableUnitInObjectRangeCheck
667 public:
668 NearestAttackableUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
669 bool operator()(Unit* u)
671 if( u->isTargetableForAttack() && i_obj->IsWithinDistInMap(u, i_range) &&
672 !i_funit->IsFriendlyTo(u) && u->isVisibleForOrDetect(i_funit,false) )
674 i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check
675 return true;
678 return false;
680 private:
681 WorldObject const* i_obj;
682 Unit const* i_funit;
683 float i_range;
685 // prevent clone this object
686 NearestAttackableUnitInObjectRangeCheck(NearestAttackableUnitInObjectRangeCheck const&);
689 class AnyAoETargetUnitInObjectRangeCheck
691 public:
692 AnyAoETargetUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range)
693 : i_obj(obj), i_funit(funit), i_range(range)
695 Unit const* check = i_funit;
696 Unit const* owner = i_funit->GetOwner();
697 if(owner)
698 check = owner;
699 i_targetForPlayer = ( check->GetTypeId()==TYPEID_PLAYER );
701 bool operator()(Unit* u)
703 // Check contains checks for: live, non-selectable, non-attackable flags, flight check and GM check, ignore totems
704 if (!u->isTargetableForAttack())
705 return false;
706 if(u->GetTypeId()==TYPEID_UNIT && ((Creature*)u)->isTotem())
707 return false;
709 if(( i_targetForPlayer ? !i_funit->IsFriendlyTo(u) : i_funit->IsHostileTo(u) )&& i_obj->IsWithinDistInMap(u, i_range))
710 return true;
712 return false;
714 private:
715 bool i_targetForPlayer;
716 WorldObject const* i_obj;
717 Unit const* i_funit;
718 float i_range;
721 struct AnyDeadUnitCheck
723 bool operator()(Unit* u) { return !u->isAlive(); }
726 struct AnyStealthedCheck
728 bool operator()(Unit* u) { return u->GetVisibility()==VISIBILITY_GROUP_STEALTH; }
731 // Creature checks
733 class InAttackDistanceFromAnyHostileCreatureCheck
735 public:
736 explicit InAttackDistanceFromAnyHostileCreatureCheck(Unit* funit) : i_funit(funit) {}
737 bool operator()(Creature* u)
739 if(u->isAlive() && u->IsHostileTo(i_funit) && i_funit->IsWithinDistInMap(u, u->GetAttackDistance(i_funit)))
740 return true;
742 return false;
744 private:
745 Unit* const i_funit;
748 class AnyAssistCreatureInRangeCheck
750 public:
751 AnyAssistCreatureInRangeCheck(Unit* funit, Unit* enemy, float range)
752 : i_funit(funit), i_enemy(enemy), i_range(range)
755 bool operator()(Creature* u)
757 if(u == i_funit)
758 return false;
760 if ( !u->CanAssistTo(i_funit, i_enemy) )
761 return false;
763 // too far
764 if( !i_funit->IsWithinDistInMap(u, i_range) )
765 return false;
767 // only if see assisted creature
768 if( !i_funit->IsWithinLOSInMap(u) )
769 return false;
771 return true;
773 private:
774 Unit* const i_funit;
775 Unit* const i_enemy;
776 float i_range;
779 // Success at unit in range, range update for next check (this can be use with CreatureLastSearcher to find nearest creature)
780 class NearestCreatureEntryWithLiveStateInObjectRangeCheck
782 public:
783 NearestCreatureEntryWithLiveStateInObjectRangeCheck(WorldObject const& obj,uint32 entry, bool alive, float range)
784 : i_obj(obj), i_entry(entry), i_alive(alive), i_range(range) {}
786 bool operator()(Creature* u)
788 if(u->GetEntry() == i_entry && u->isAlive()==i_alive && i_obj.IsWithinDistInMap(u, i_range))
790 i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check
791 return true;
793 return false;
795 float GetLastRange() const { return i_range; }
796 private:
797 WorldObject const& i_obj;
798 uint32 i_entry;
799 bool i_alive;
800 float i_range;
802 // prevent clone this object
803 NearestCreatureEntryWithLiveStateInObjectRangeCheck(NearestCreatureEntryWithLiveStateInObjectRangeCheck const&);
806 class AnyPlayerInObjectRangeCheck
808 public:
809 AnyPlayerInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {}
810 bool operator()(Player* u)
812 if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range))
813 return true;
815 return false;
817 private:
818 WorldObject const* i_obj;
819 float i_range;
822 #ifndef WIN32
823 template<> void PlayerRelocationNotifier::Visit<Creature>(CreatureMapType &);
824 template<> void PlayerRelocationNotifier::Visit<Player>(PlayerMapType &);
825 template<> void CreatureRelocationNotifier::Visit<Player>(PlayerMapType &);
826 template<> void CreatureRelocationNotifier::Visit<Creature>(CreatureMapType &);
827 template<> inline void DynamicObjectUpdater::Visit<Creature>(CreatureMapType &);
828 template<> inline void DynamicObjectUpdater::Visit<Player>(PlayerMapType &);
829 #endif
831 #endif