1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
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. |
---|
8 | * |
---|
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. |
---|
13 | * |
---|
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 |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef MANGOS_GRIDNOTIFIERS_H |
---|
20 | #define MANGOS_GRIDNOTIFIERS_H |
---|
21 | |
---|
22 | #include "ObjectGridLoader.h" |
---|
23 | #include "ByteBuffer.h" |
---|
24 | #include "UpdateData.h" |
---|
25 | #include <iostream> |
---|
26 | |
---|
27 | #include "Corpse.h" |
---|
28 | #include "Object.h" |
---|
29 | #include "DynamicObject.h" |
---|
30 | #include "GameObject.h" |
---|
31 | #include "Player.h" |
---|
32 | #include "Unit.h" |
---|
33 | |
---|
34 | class Player; |
---|
35 | //class Map; |
---|
36 | |
---|
37 | namespace MaNGOS |
---|
38 | { |
---|
39 | |
---|
40 | struct MANGOS_DLL_DECL PlayerNotifier |
---|
41 | { |
---|
42 | explicit PlayerNotifier(Player &pl) : i_player(pl) {} |
---|
43 | void Visit(PlayerMapType &); |
---|
44 | template<class SKIP> void Visit(GridRefManager<SKIP> &) {} |
---|
45 | Player &i_player; |
---|
46 | }; |
---|
47 | |
---|
48 | struct MANGOS_DLL_DECL VisibleNotifier |
---|
49 | { |
---|
50 | Player &i_player; |
---|
51 | UpdateData i_data; |
---|
52 | UpdateDataMapType i_data_updates; |
---|
53 | Player::ClientGUIDs i_clientGUIDs; |
---|
54 | std::set<WorldObject*> i_visibleNow; |
---|
55 | |
---|
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); |
---|
60 | }; |
---|
61 | |
---|
62 | struct MANGOS_DLL_DECL VisibleChangesNotifier |
---|
63 | { |
---|
64 | WorldObject &i_object; |
---|
65 | |
---|
66 | explicit VisibleChangesNotifier(WorldObject &object) : i_object(object) {} |
---|
67 | template<class T> void Visit(GridRefManager<T> &) {} |
---|
68 | void Visit(PlayerMapType &); |
---|
69 | }; |
---|
70 | |
---|
71 | struct MANGOS_DLL_DECL GridUpdater |
---|
72 | { |
---|
73 | GridType &i_grid; |
---|
74 | uint32 i_timeDiff; |
---|
75 | GridUpdater(GridType &grid, uint32 diff) : i_grid(grid), i_timeDiff(diff) {} |
---|
76 | |
---|
77 | template<class T> void updateObjects(GridRefManager<T> &m) |
---|
78 | { |
---|
79 | for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter) |
---|
80 | iter->getSource()->Update(i_timeDiff); |
---|
81 | } |
---|
82 | |
---|
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); } |
---|
88 | }; |
---|
89 | |
---|
90 | struct MANGOS_DLL_DECL MessageDeliverer |
---|
91 | { |
---|
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> &) {} |
---|
98 | }; |
---|
99 | |
---|
100 | struct MANGOS_DLL_DECL ObjectMessageDeliverer |
---|
101 | { |
---|
102 | WorldPacket *i_message; |
---|
103 | explicit ObjectMessageDeliverer(WorldPacket *msg) : i_message(msg) {} |
---|
104 | void Visit(PlayerMapType &m); |
---|
105 | template<class SKIP> void Visit(GridRefManager<SKIP> &) {} |
---|
106 | }; |
---|
107 | |
---|
108 | struct MANGOS_DLL_DECL MessageDistDeliverer |
---|
109 | { |
---|
110 | Player &i_player; |
---|
111 | WorldPacket *i_message; |
---|
112 | bool i_toSelf; |
---|
113 | bool i_ownTeamOnly; |
---|
114 | float i_dist; |
---|
115 | 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) {} |
---|
116 | void Visit(PlayerMapType &m); |
---|
117 | template<class SKIP> void Visit(GridRefManager<SKIP> &) {} |
---|
118 | }; |
---|
119 | |
---|
120 | struct MANGOS_DLL_DECL ObjectMessageDistDeliverer |
---|
121 | { |
---|
122 | WorldObject &i_object; |
---|
123 | WorldPacket *i_message; |
---|
124 | float i_dist; |
---|
125 | ObjectMessageDistDeliverer(WorldObject &obj, WorldPacket *msg, float dist) : i_object(obj), i_message(msg), i_dist(dist) {} |
---|
126 | void Visit(PlayerMapType &m); |
---|
127 | template<class SKIP> void Visit(GridRefManager<SKIP> &) {} |
---|
128 | }; |
---|
129 | |
---|
130 | struct MANGOS_DLL_DECL ObjectUpdater |
---|
131 | { |
---|
132 | uint32 i_timeDiff; |
---|
133 | explicit ObjectUpdater(const uint32 &diff) : i_timeDiff(diff) {} |
---|
134 | template<class T> void Visit(GridRefManager<T> &m); |
---|
135 | void Visit(PlayerMapType &) {} |
---|
136 | void Visit(CorpseMapType &) {} |
---|
137 | void Visit(CreatureMapType &); |
---|
138 | }; |
---|
139 | |
---|
140 | template<class T> |
---|
141 | struct MANGOS_DLL_DECL ObjectAccessorNotifier |
---|
142 | { |
---|
143 | T *& i_object; |
---|
144 | |
---|
145 | uint64 i_id; |
---|
146 | ObjectAccessorNotifier(T * &obj, uint64 id) : i_object(obj), i_id(id) |
---|
147 | { |
---|
148 | i_object = NULL; |
---|
149 | } |
---|
150 | |
---|
151 | void Visit(GridRefManager<T> &m ) |
---|
152 | { |
---|
153 | if( i_object == NULL ) |
---|
154 | { |
---|
155 | GridRefManager<T> *iter = m.find(i_id); |
---|
156 | if( iter != m.end() ) |
---|
157 | { |
---|
158 | assert( iter->second != NULL ); |
---|
159 | i_object = iter->second; |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
165 | }; |
---|
166 | |
---|
167 | struct MANGOS_DLL_DECL PlayerRelocationNotifier |
---|
168 | { |
---|
169 | Player &i_player; |
---|
170 | PlayerRelocationNotifier(Player &pl) : i_player(pl) {} |
---|
171 | template<class T> void Visit(GridRefManager<T> &) {} |
---|
172 | void Visit(PlayerMapType &); |
---|
173 | void Visit(CreatureMapType &); |
---|
174 | }; |
---|
175 | |
---|
176 | struct MANGOS_DLL_DECL CreatureRelocationNotifier |
---|
177 | { |
---|
178 | Creature &i_creature; |
---|
179 | CreatureRelocationNotifier(Creature &c) : i_creature(c) {} |
---|
180 | template<class T> void Visit(GridRefManager<T> &) {} |
---|
181 | #ifdef WIN32 |
---|
182 | template<> void Visit(PlayerMapType &); |
---|
183 | #endif |
---|
184 | }; |
---|
185 | |
---|
186 | struct MANGOS_DLL_DECL DynamicObjectUpdater |
---|
187 | { |
---|
188 | DynamicObject &i_dynobject; |
---|
189 | Unit* i_check; |
---|
190 | DynamicObjectUpdater(DynamicObject &dynobject, Unit* caster) : i_dynobject(dynobject) |
---|
191 | { |
---|
192 | i_check = caster; |
---|
193 | Unit* owner = i_check->GetOwner(); |
---|
194 | if(owner) |
---|
195 | i_check = owner; |
---|
196 | } |
---|
197 | |
---|
198 | template<class T> inline void Visit(GridRefManager<T> &) {} |
---|
199 | #ifdef WIN32 |
---|
200 | template<> inline void Visit<Player>(PlayerMapType &); |
---|
201 | template<> inline void Visit<Creature>(CreatureMapType &); |
---|
202 | #endif |
---|
203 | |
---|
204 | void VisitHelper(Unit* target); |
---|
205 | }; |
---|
206 | |
---|
207 | // SEARCHERS & LIST SEARCHERS & WORKERS |
---|
208 | |
---|
209 | // WorldObject searchers & workers |
---|
210 | |
---|
211 | template<class Check> |
---|
212 | struct MANGOS_DLL_DECL WorldObjectSearcher |
---|
213 | { |
---|
214 | WorldObject* &i_object; |
---|
215 | Check &i_check; |
---|
216 | |
---|
217 | WorldObjectSearcher(WorldObject* & result, Check& check) : i_object(result),i_check(check) {} |
---|
218 | |
---|
219 | void Visit(GameObjectMapType &m); |
---|
220 | void Visit(PlayerMapType &m); |
---|
221 | void Visit(CreatureMapType &m); |
---|
222 | void Visit(CorpseMapType &m); |
---|
223 | void Visit(DynamicObjectMapType &m); |
---|
224 | |
---|
225 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
226 | }; |
---|
227 | |
---|
228 | template<class Check> |
---|
229 | struct MANGOS_DLL_DECL WorldObjectListSearcher |
---|
230 | { |
---|
231 | std::list<WorldObject*> &i_objects; |
---|
232 | Check& i_check; |
---|
233 | |
---|
234 | WorldObjectListSearcher(std::list<WorldObject*> &objects, Check & check) : i_objects(objects),i_check(check) {} |
---|
235 | |
---|
236 | void Visit(PlayerMapType &m); |
---|
237 | void Visit(CreatureMapType &m); |
---|
238 | void Visit(CorpseMapType &m); |
---|
239 | void Visit(GameObjectMapType &m); |
---|
240 | void Visit(DynamicObjectMapType &m); |
---|
241 | |
---|
242 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
243 | }; |
---|
244 | |
---|
245 | template<class Do> |
---|
246 | struct MANGOS_DLL_DECL WorldObjectWorker |
---|
247 | { |
---|
248 | Do const& i_do; |
---|
249 | |
---|
250 | explicit WorldObjectWorker(Do const& _do) : i_do(_do) {} |
---|
251 | |
---|
252 | void Visit(GameObjectMapType &m) |
---|
253 | { |
---|
254 | for(GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
255 | i_do(itr->getSource()); |
---|
256 | } |
---|
257 | |
---|
258 | void Visit(PlayerMapType &m) |
---|
259 | { |
---|
260 | for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
261 | i_do(itr->getSource()); |
---|
262 | } |
---|
263 | void Visit(CreatureMapType &m) |
---|
264 | { |
---|
265 | for(CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
266 | i_do(itr->getSource()); |
---|
267 | } |
---|
268 | |
---|
269 | void Visit(CorpseMapType &m) |
---|
270 | { |
---|
271 | for(CorpseMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
272 | i_do(itr->getSource()); |
---|
273 | } |
---|
274 | |
---|
275 | void Visit(DynamicObjectMapType &m) |
---|
276 | { |
---|
277 | for(DynamicObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
278 | i_do(itr->getSource()); |
---|
279 | } |
---|
280 | |
---|
281 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
282 | }; |
---|
283 | |
---|
284 | // Gameobject searchers |
---|
285 | |
---|
286 | template<class Check> |
---|
287 | struct MANGOS_DLL_DECL GameObjectSearcher |
---|
288 | { |
---|
289 | GameObject* &i_object; |
---|
290 | Check &i_check; |
---|
291 | |
---|
292 | GameObjectSearcher(GameObject* & result, Check& check) : i_object(result),i_check(check) {} |
---|
293 | |
---|
294 | void Visit(GameObjectMapType &m); |
---|
295 | |
---|
296 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
297 | }; |
---|
298 | |
---|
299 | // Last accepted by Check GO if any (Check can change requirements at each call) |
---|
300 | template<class Check> |
---|
301 | struct MANGOS_DLL_DECL GameObjectLastSearcher |
---|
302 | { |
---|
303 | GameObject* &i_object; |
---|
304 | Check& i_check; |
---|
305 | |
---|
306 | GameObjectLastSearcher(GameObject* & result, Check& check) : i_object(result),i_check(check) {} |
---|
307 | |
---|
308 | void Visit(GameObjectMapType &m); |
---|
309 | |
---|
310 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
311 | }; |
---|
312 | |
---|
313 | template<class Check> |
---|
314 | struct MANGOS_DLL_DECL GameObjectListSearcher |
---|
315 | { |
---|
316 | std::list<GameObject*> &i_objects; |
---|
317 | Check& i_check; |
---|
318 | |
---|
319 | GameObjectListSearcher(std::list<GameObject*> &objects, Check & check) : i_objects(objects),i_check(check) {} |
---|
320 | |
---|
321 | void Visit(GameObjectMapType &m); |
---|
322 | |
---|
323 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
324 | }; |
---|
325 | |
---|
326 | // Unit searchers |
---|
327 | |
---|
328 | // First accepted by Check Unit if any |
---|
329 | template<class Check> |
---|
330 | struct MANGOS_DLL_DECL UnitSearcher |
---|
331 | { |
---|
332 | Unit* &i_object; |
---|
333 | Check & i_check; |
---|
334 | |
---|
335 | UnitSearcher(Unit* & result, Check & check) : i_object(result),i_check(check) {} |
---|
336 | |
---|
337 | void Visit(CreatureMapType &m); |
---|
338 | void Visit(PlayerMapType &m); |
---|
339 | |
---|
340 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
341 | }; |
---|
342 | |
---|
343 | // Last accepted by Check Unit if any (Check can change requirements at each call) |
---|
344 | template<class Check> |
---|
345 | struct MANGOS_DLL_DECL UnitLastSearcher |
---|
346 | { |
---|
347 | Unit* &i_object; |
---|
348 | Check & i_check; |
---|
349 | |
---|
350 | UnitLastSearcher(Unit* & result, Check & check) : i_object(result),i_check(check) {} |
---|
351 | |
---|
352 | void Visit(CreatureMapType &m); |
---|
353 | void Visit(PlayerMapType &m); |
---|
354 | |
---|
355 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
356 | }; |
---|
357 | |
---|
358 | // All accepted by Check units if any |
---|
359 | template<class Check> |
---|
360 | struct MANGOS_DLL_DECL UnitListSearcher |
---|
361 | { |
---|
362 | std::list<Unit*> &i_objects; |
---|
363 | Check& i_check; |
---|
364 | |
---|
365 | UnitListSearcher(std::list<Unit*> &objects, Check & check) : i_objects(objects),i_check(check) {} |
---|
366 | |
---|
367 | void Visit(PlayerMapType &m); |
---|
368 | void Visit(CreatureMapType &m); |
---|
369 | |
---|
370 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
371 | }; |
---|
372 | |
---|
373 | // Creature searchers |
---|
374 | |
---|
375 | template<class Check> |
---|
376 | struct MANGOS_DLL_DECL CreatureSearcher |
---|
377 | { |
---|
378 | Creature* &i_object; |
---|
379 | Check & i_check; |
---|
380 | |
---|
381 | CreatureSearcher(Creature* & result, Check & check) : i_object(result),i_check(check) {} |
---|
382 | |
---|
383 | void Visit(CreatureMapType &m); |
---|
384 | |
---|
385 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
386 | }; |
---|
387 | |
---|
388 | // Last accepted by Check Creature if any (Check can change requirements at each call) |
---|
389 | template<class Check> |
---|
390 | struct MANGOS_DLL_DECL CreatureLastSearcher |
---|
391 | { |
---|
392 | Creature* &i_object; |
---|
393 | Check & i_check; |
---|
394 | |
---|
395 | CreatureLastSearcher(Creature* & result, Check & check) : i_object(result),i_check(check) {} |
---|
396 | |
---|
397 | void Visit(CreatureMapType &m); |
---|
398 | |
---|
399 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
400 | }; |
---|
401 | |
---|
402 | template<class Check> |
---|
403 | struct MANGOS_DLL_DECL CreatureListSearcher |
---|
404 | { |
---|
405 | std::list<Creature*> &i_objects; |
---|
406 | Check& i_check; |
---|
407 | |
---|
408 | CreatureListSearcher(std::list<Creature*> &objects, Check & check) : i_objects(objects),i_check(check) {} |
---|
409 | |
---|
410 | void Visit(CreatureMapType &m); |
---|
411 | |
---|
412 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
413 | }; |
---|
414 | |
---|
415 | // Player searchers |
---|
416 | |
---|
417 | template<class Check> |
---|
418 | struct MANGOS_DLL_DECL PlayerSearcher |
---|
419 | { |
---|
420 | Player* &i_object; |
---|
421 | Check & i_check; |
---|
422 | |
---|
423 | PlayerSearcher(Player* & result, Check & check) : i_object(result),i_check(check) {} |
---|
424 | |
---|
425 | void Visit(PlayerMapType &m); |
---|
426 | |
---|
427 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
428 | }; |
---|
429 | |
---|
430 | template<class Do> |
---|
431 | struct MANGOS_DLL_DECL PlayerWorker |
---|
432 | { |
---|
433 | Do& i_do; |
---|
434 | |
---|
435 | explicit PlayerWorker(Do& _do) : i_do(_do) {} |
---|
436 | |
---|
437 | void Visit(PlayerMapType &m) |
---|
438 | { |
---|
439 | for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr) |
---|
440 | i_do(itr->getSource()); |
---|
441 | } |
---|
442 | |
---|
443 | template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {} |
---|
444 | }; |
---|
445 | |
---|
446 | // CHECKS && DO classes |
---|
447 | |
---|
448 | // WorldObject check classes |
---|
449 | class CannibalizeObjectCheck |
---|
450 | { |
---|
451 | public: |
---|
452 | CannibalizeObjectCheck(Unit* funit, float range) : i_funit(funit), i_range(range) {} |
---|
453 | bool operator()(Player* u) |
---|
454 | { |
---|
455 | if( i_funit->IsFriendlyTo(u) || u->isAlive() || u->isInFlight() ) |
---|
456 | return false; |
---|
457 | |
---|
458 | if(i_funit->IsWithinDistInMap(u, i_range) ) |
---|
459 | return true; |
---|
460 | |
---|
461 | return false; |
---|
462 | } |
---|
463 | bool operator()(Corpse* u); |
---|
464 | bool operator()(Creature* u) |
---|
465 | { |
---|
466 | if( i_funit->IsFriendlyTo(u) || u->isAlive() || u->isInFlight() || |
---|
467 | (u->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD)==0) |
---|
468 | return false; |
---|
469 | |
---|
470 | if(i_funit->IsWithinDistInMap(u, i_range) ) |
---|
471 | return true; |
---|
472 | |
---|
473 | return false; |
---|
474 | } |
---|
475 | template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED* u) { return false; } |
---|
476 | private: |
---|
477 | Unit* const i_funit; |
---|
478 | float i_range; |
---|
479 | }; |
---|
480 | |
---|
481 | // WorldObject do classes |
---|
482 | |
---|
483 | class RespawnDo |
---|
484 | { |
---|
485 | public: |
---|
486 | RespawnDo() {} |
---|
487 | void operator()(Creature* u) const { u->Respawn(); } |
---|
488 | void operator()(GameObject* u) const { u->Respawn(); } |
---|
489 | void operator()(WorldObject*) const {} |
---|
490 | void operator()(Corpse*) const {} |
---|
491 | }; |
---|
492 | |
---|
493 | // GameObject checks |
---|
494 | |
---|
495 | class GameObjectFocusCheck |
---|
496 | { |
---|
497 | public: |
---|
498 | GameObjectFocusCheck(Unit const* unit,uint32 focusId) : i_unit(unit), i_focusId(focusId) {} |
---|
499 | bool operator()(GameObject* go) const |
---|
500 | { |
---|
501 | if(go->GetGOInfo()->type != GAMEOBJECT_TYPE_SPELL_FOCUS) |
---|
502 | return false; |
---|
503 | |
---|
504 | if(go->GetGOInfo()->spellFocus.focusId != i_focusId) |
---|
505 | return false; |
---|
506 | |
---|
507 | float dist = go->GetGOInfo()->spellFocus.dist; |
---|
508 | |
---|
509 | return go->IsWithinDistInMap(i_unit, dist); |
---|
510 | } |
---|
511 | private: |
---|
512 | Unit const* i_unit; |
---|
513 | uint32 i_focusId; |
---|
514 | }; |
---|
515 | |
---|
516 | // Find the nearest Fishing hole and return true only if source object is in range of hole |
---|
517 | class NearestGameObjectFishingHole |
---|
518 | { |
---|
519 | public: |
---|
520 | NearestGameObjectFishingHole(WorldObject const& obj, float range) : i_obj(obj), i_range(range) {} |
---|
521 | bool operator()(GameObject* go) |
---|
522 | { |
---|
523 | if(go->GetGOInfo()->type == GAMEOBJECT_TYPE_FISHINGHOLE && go->isSpawned() && i_obj.IsWithinDistInMap(go, i_range) && i_obj.IsWithinDistInMap(go, go->GetGOInfo()->fishinghole.radius)) |
---|
524 | { |
---|
525 | i_range = i_obj.GetDistance(go); |
---|
526 | return true; |
---|
527 | } |
---|
528 | return false; |
---|
529 | } |
---|
530 | float GetLastRange() const { return i_range; } |
---|
531 | private: |
---|
532 | WorldObject const& i_obj; |
---|
533 | float i_range; |
---|
534 | |
---|
535 | // prevent clone |
---|
536 | NearestGameObjectFishingHole(NearestGameObjectFishingHole const&); |
---|
537 | }; |
---|
538 | |
---|
539 | // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO) |
---|
540 | class NearestGameObjectEntryInObjectRangeCheck |
---|
541 | { |
---|
542 | public: |
---|
543 | NearestGameObjectEntryInObjectRangeCheck(WorldObject const& obj,uint32 entry, float range) : i_obj(obj), i_entry(entry), i_range(range) {} |
---|
544 | bool operator()(GameObject* go) |
---|
545 | { |
---|
546 | if(go->GetEntry() == i_entry && i_obj.IsWithinDistInMap(go, i_range)) |
---|
547 | { |
---|
548 | i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check |
---|
549 | return true; |
---|
550 | } |
---|
551 | return false; |
---|
552 | } |
---|
553 | float GetLastRange() const { return i_range; } |
---|
554 | private: |
---|
555 | WorldObject const& i_obj; |
---|
556 | uint32 i_entry; |
---|
557 | float i_range; |
---|
558 | |
---|
559 | // prevent clone this object |
---|
560 | NearestGameObjectEntryInObjectRangeCheck(NearestGameObjectEntryInObjectRangeCheck const&); |
---|
561 | }; |
---|
562 | |
---|
563 | class GameObjectWithDbGUIDCheck |
---|
564 | { |
---|
565 | public: |
---|
566 | GameObjectWithDbGUIDCheck(WorldObject const& obj,uint32 db_guid) : i_obj(obj), i_db_guid(db_guid) {} |
---|
567 | bool operator()(GameObject const* go) const |
---|
568 | { |
---|
569 | return go->GetDBTableGUIDLow() == i_db_guid; |
---|
570 | } |
---|
571 | private: |
---|
572 | WorldObject const& i_obj; |
---|
573 | uint32 i_db_guid; |
---|
574 | }; |
---|
575 | |
---|
576 | // Unit checks |
---|
577 | |
---|
578 | class AnyUnfriendlyUnitInObjectRangeCheck |
---|
579 | { |
---|
580 | public: |
---|
581 | AnyUnfriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {} |
---|
582 | bool operator()(Unit* u) |
---|
583 | { |
---|
584 | if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range) && !i_funit->IsFriendlyTo(u)) |
---|
585 | return true; |
---|
586 | else |
---|
587 | return false; |
---|
588 | } |
---|
589 | private: |
---|
590 | WorldObject const* i_obj; |
---|
591 | Unit const* i_funit; |
---|
592 | float i_range; |
---|
593 | }; |
---|
594 | |
---|
595 | class AnyFriendlyUnitInObjectRangeCheck |
---|
596 | { |
---|
597 | public: |
---|
598 | AnyFriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {} |
---|
599 | bool operator()(Unit* u) |
---|
600 | { |
---|
601 | if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range) && i_funit->IsFriendlyTo(u)) |
---|
602 | return true; |
---|
603 | else |
---|
604 | return false; |
---|
605 | } |
---|
606 | private: |
---|
607 | WorldObject const* i_obj; |
---|
608 | Unit const* i_funit; |
---|
609 | float i_range; |
---|
610 | }; |
---|
611 | |
---|
612 | class AnyUnitInObjectRangeCheck |
---|
613 | { |
---|
614 | public: |
---|
615 | AnyUnitInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {} |
---|
616 | bool operator()(Unit* u) |
---|
617 | { |
---|
618 | if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range)) |
---|
619 | return true; |
---|
620 | |
---|
621 | return false; |
---|
622 | } |
---|
623 | private: |
---|
624 | WorldObject const* i_obj; |
---|
625 | float i_range; |
---|
626 | }; |
---|
627 | |
---|
628 | // Success at unit in range, range update for next check (this can be use with UnitLastSearcher to find nearest unit) |
---|
629 | class NearestAttackableUnitInObjectRangeCheck |
---|
630 | { |
---|
631 | public: |
---|
632 | NearestAttackableUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {} |
---|
633 | bool operator()(Unit* u) |
---|
634 | { |
---|
635 | if( u->isTargetableForAttack() && i_obj->IsWithinDistInMap(u, i_range) && |
---|
636 | !i_funit->IsFriendlyTo(u) && u->isVisibleForOrDetect(i_funit,false) ) |
---|
637 | { |
---|
638 | i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check |
---|
639 | return true; |
---|
640 | } |
---|
641 | |
---|
642 | return false; |
---|
643 | } |
---|
644 | private: |
---|
645 | WorldObject const* i_obj; |
---|
646 | Unit const* i_funit; |
---|
647 | float i_range; |
---|
648 | |
---|
649 | // prevent clone this object |
---|
650 | NearestAttackableUnitInObjectRangeCheck(NearestAttackableUnitInObjectRangeCheck const&); |
---|
651 | }; |
---|
652 | |
---|
653 | class AnyAoETargetUnitInObjectRangeCheck |
---|
654 | { |
---|
655 | public: |
---|
656 | AnyAoETargetUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) |
---|
657 | : i_obj(obj), i_funit(funit), i_range(range) |
---|
658 | { |
---|
659 | Unit const* check = i_funit; |
---|
660 | Unit const* owner = i_funit->GetOwner(); |
---|
661 | if(owner) |
---|
662 | check = owner; |
---|
663 | i_targetForPlayer = ( check->GetTypeId()==TYPEID_PLAYER ); |
---|
664 | } |
---|
665 | bool operator()(Unit* u) |
---|
666 | { |
---|
667 | // Check contains checks for: live, non-selectable, non-attackable flags, flight check and GM check, ignore totems |
---|
668 | if (!u->isTargetableForAttack()) |
---|
669 | return false; |
---|
670 | if(u->GetTypeId()==TYPEID_UNIT && ((Creature*)u)->isTotem()) |
---|
671 | return false; |
---|
672 | |
---|
673 | if(( i_targetForPlayer ? !i_funit->IsFriendlyTo(u) : i_funit->IsHostileTo(u) )&& i_obj->IsWithinDistInMap(u, i_range)) |
---|
674 | return true; |
---|
675 | |
---|
676 | return false; |
---|
677 | } |
---|
678 | private: |
---|
679 | bool i_targetForPlayer; |
---|
680 | WorldObject const* i_obj; |
---|
681 | Unit const* i_funit; |
---|
682 | float i_range; |
---|
683 | }; |
---|
684 | |
---|
685 | struct AnyDeadUnitCheck |
---|
686 | { |
---|
687 | bool operator()(Unit* u) { return !u->isAlive(); } |
---|
688 | }; |
---|
689 | |
---|
690 | struct AnyStealthedCheck |
---|
691 | { |
---|
692 | bool operator()(Unit* u) { return u->GetVisibility()==VISIBILITY_GROUP_STEALTH; } |
---|
693 | }; |
---|
694 | |
---|
695 | // Creature checks |
---|
696 | |
---|
697 | class InAttackDistanceFromAnyHostileCreatureCheck |
---|
698 | { |
---|
699 | public: |
---|
700 | explicit InAttackDistanceFromAnyHostileCreatureCheck(Unit* funit) : i_funit(funit) {} |
---|
701 | bool operator()(Creature* u) |
---|
702 | { |
---|
703 | if(u->isAlive() && u->IsHostileTo(i_funit) && i_funit->IsWithinDistInMap(u, u->GetAttackDistance(i_funit))) |
---|
704 | return true; |
---|
705 | |
---|
706 | return false; |
---|
707 | } |
---|
708 | private: |
---|
709 | Unit* const i_funit; |
---|
710 | }; |
---|
711 | |
---|
712 | class NearestAssistCreatureInCreatureRangeCheck |
---|
713 | { |
---|
714 | public: |
---|
715 | NearestAssistCreatureInCreatureRangeCheck(Creature* obj,Unit* enemy, float range) |
---|
716 | : i_obj(obj), i_enemy(enemy), i_range(range) {} |
---|
717 | |
---|
718 | bool operator()(Creature* u) |
---|
719 | { |
---|
720 | if(u->getFaction() == i_obj->getFaction() && !u->isInCombat() && !u->GetCharmerOrOwnerGUID() && u->IsHostileTo(i_enemy) && u->isAlive()&& i_obj->IsWithinDistInMap(u, i_range) && i_obj->IsWithinLOSInMap(u)) |
---|
721 | { |
---|
722 | i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check |
---|
723 | return true; |
---|
724 | } |
---|
725 | return false; |
---|
726 | } |
---|
727 | float GetLastRange() const { return i_range; } |
---|
728 | private: |
---|
729 | Creature* const i_obj; |
---|
730 | Unit* const i_enemy; |
---|
731 | float i_range; |
---|
732 | |
---|
733 | // prevent clone this object |
---|
734 | NearestAssistCreatureInCreatureRangeCheck(NearestAssistCreatureInCreatureRangeCheck const&); |
---|
735 | }; |
---|
736 | |
---|
737 | class AnyAssistCreatureInRangeCheck |
---|
738 | { |
---|
739 | public: |
---|
740 | AnyAssistCreatureInRangeCheck(Unit* funit, Unit* enemy, float range) |
---|
741 | : i_funit(funit), i_enemy(enemy), i_range(range) |
---|
742 | { |
---|
743 | } |
---|
744 | bool operator()(Creature* u) |
---|
745 | { |
---|
746 | if(u == i_funit) |
---|
747 | return false; |
---|
748 | |
---|
749 | // we don't need help from zombies :) |
---|
750 | if( !u->isAlive() ) |
---|
751 | return false; |
---|
752 | |
---|
753 | // skip fighting creature |
---|
754 | if( u->isInCombat() ) |
---|
755 | return false; |
---|
756 | |
---|
757 | // only from same creature faction |
---|
758 | if(u->getFaction() != i_funit->getFaction() ) |
---|
759 | return false; |
---|
760 | |
---|
761 | // only free creature |
---|
762 | if( u->GetCharmerOrOwnerGUID() ) |
---|
763 | return false; |
---|
764 | |
---|
765 | // too far |
---|
766 | if( !i_funit->IsWithinDistInMap(u, i_range) ) |
---|
767 | return false; |
---|
768 | |
---|
769 | // skip non hostile to caster enemy creatures |
---|
770 | if( !u->IsHostileTo(i_enemy) ) |
---|
771 | return false; |
---|
772 | |
---|
773 | // only if see assisted creature |
---|
774 | if(!u->IsWithinLOSInMap(i_funit) ) |
---|
775 | return false; |
---|
776 | |
---|
777 | return true; |
---|
778 | } |
---|
779 | private: |
---|
780 | Unit* const i_funit; |
---|
781 | Unit* const i_enemy; |
---|
782 | float i_range; |
---|
783 | }; |
---|
784 | |
---|
785 | // Success at unit in range, range update for next check (this can be use with CreatureLastSearcher to find nearest creature) |
---|
786 | class NearestCreatureEntryWithLiveStateInObjectRangeCheck |
---|
787 | { |
---|
788 | public: |
---|
789 | NearestCreatureEntryWithLiveStateInObjectRangeCheck(WorldObject const& obj,uint32 entry, bool alive, float range) |
---|
790 | : i_obj(obj), i_entry(entry), i_alive(alive), i_range(range) {} |
---|
791 | |
---|
792 | bool operator()(Creature* u) |
---|
793 | { |
---|
794 | if(u->GetEntry() == i_entry && u->isAlive()==i_alive && i_obj.IsWithinDistInMap(u, i_range)) |
---|
795 | { |
---|
796 | i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check |
---|
797 | return true; |
---|
798 | } |
---|
799 | return false; |
---|
800 | } |
---|
801 | float GetLastRange() const { return i_range; } |
---|
802 | private: |
---|
803 | WorldObject const& i_obj; |
---|
804 | uint32 i_entry; |
---|
805 | bool i_alive; |
---|
806 | float i_range; |
---|
807 | |
---|
808 | // prevent clone this object |
---|
809 | NearestCreatureEntryWithLiveStateInObjectRangeCheck(NearestCreatureEntryWithLiveStateInObjectRangeCheck const&); |
---|
810 | }; |
---|
811 | |
---|
812 | class AnyPlayerInObjectRangeCheck |
---|
813 | { |
---|
814 | public: |
---|
815 | AnyPlayerInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {} |
---|
816 | bool operator()(Player* u) |
---|
817 | { |
---|
818 | if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range)) |
---|
819 | return true; |
---|
820 | |
---|
821 | return false; |
---|
822 | } |
---|
823 | private: |
---|
824 | WorldObject const* i_obj; |
---|
825 | float i_range; |
---|
826 | }; |
---|
827 | |
---|
828 | // Searchers used by ScriptedAI |
---|
829 | class MostHPMissingInRange |
---|
830 | { |
---|
831 | public: |
---|
832 | MostHPMissingInRange(Unit const* obj, float range, uint32 hp) : i_obj(obj), i_range(range), i_hp(hp) {} |
---|
833 | bool operator()(Unit* u) |
---|
834 | { |
---|
835 | if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && u->GetMaxHealth() - u->GetHealth() > i_hp) |
---|
836 | { |
---|
837 | i_hp = u->GetMaxHealth() - u->GetHealth(); |
---|
838 | return true; |
---|
839 | } |
---|
840 | return false; |
---|
841 | } |
---|
842 | private: |
---|
843 | Unit const* i_obj; |
---|
844 | float i_range; |
---|
845 | uint32 i_hp; |
---|
846 | }; |
---|
847 | |
---|
848 | class FriendlyCCedInRange |
---|
849 | { |
---|
850 | public: |
---|
851 | FriendlyCCedInRange(Unit const* obj, float range) : i_obj(obj), i_range(range) {} |
---|
852 | bool operator()(Unit* u) |
---|
853 | { |
---|
854 | if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && |
---|
855 | (u->isFeared() || u->isCharmed() || u->isFrozen() || u->hasUnitState(UNIT_STAT_STUNNED) || u->hasUnitState(UNIT_STAT_CONFUSED))) |
---|
856 | { |
---|
857 | return true; |
---|
858 | } |
---|
859 | return false; |
---|
860 | } |
---|
861 | private: |
---|
862 | Unit const* i_obj; |
---|
863 | float i_range; |
---|
864 | }; |
---|
865 | |
---|
866 | class FriendlyMissingBuffInRange |
---|
867 | { |
---|
868 | public: |
---|
869 | FriendlyMissingBuffInRange(Unit const* obj, float range, uint32 spellid) : i_obj(obj), i_range(range), i_spell(spellid) {} |
---|
870 | bool operator()(Unit* u) |
---|
871 | { |
---|
872 | if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && |
---|
873 | !(u->HasAura(i_spell, 0) || u->HasAura(i_spell, 1) || u->HasAura(i_spell, 2))) |
---|
874 | { |
---|
875 | return true; |
---|
876 | } |
---|
877 | return false; |
---|
878 | } |
---|
879 | private: |
---|
880 | Unit const* i_obj; |
---|
881 | float i_range; |
---|
882 | uint32 i_spell; |
---|
883 | }; |
---|
884 | |
---|
885 | class AllFriendlyCreaturesInGrid |
---|
886 | { |
---|
887 | public: |
---|
888 | AllFriendlyCreaturesInGrid(Unit const* obj) : pUnit(obj) {} |
---|
889 | bool operator() (Unit* u) |
---|
890 | { |
---|
891 | if(u->isAlive() && u->GetVisibility() == VISIBILITY_ON && u->IsFriendlyTo(pUnit)) |
---|
892 | return true; |
---|
893 | |
---|
894 | return false; |
---|
895 | } |
---|
896 | private: |
---|
897 | Unit const* pUnit; |
---|
898 | }; |
---|
899 | |
---|
900 | class AllGameObjectsWithEntryInGrid |
---|
901 | { |
---|
902 | public: |
---|
903 | AllGameObjectsWithEntryInGrid(uint32 ent) : entry(ent) {} |
---|
904 | bool operator() (GameObject* g) |
---|
905 | { |
---|
906 | if(g->GetEntry() == entry) |
---|
907 | return true; |
---|
908 | |
---|
909 | return false; |
---|
910 | } |
---|
911 | private: |
---|
912 | uint32 entry; |
---|
913 | }; |
---|
914 | |
---|
915 | class AllCreaturesOfEntryInRange |
---|
916 | { |
---|
917 | public: |
---|
918 | AllCreaturesOfEntryInRange(Unit const* obj, uint32 ent, float ran) : pUnit(obj), entry(ent), range(ran) {} |
---|
919 | bool operator() (Unit* u) |
---|
920 | { |
---|
921 | if(u->GetEntry() == entry && pUnit->IsWithinDistInMap(u, range)) |
---|
922 | return true; |
---|
923 | |
---|
924 | return false; |
---|
925 | } |
---|
926 | private: |
---|
927 | Unit const* pUnit; |
---|
928 | uint32 entry; |
---|
929 | float range; |
---|
930 | }; |
---|
931 | |
---|
932 | #ifndef WIN32 |
---|
933 | template<> void PlayerRelocationNotifier::Visit<Creature>(CreatureMapType &); |
---|
934 | template<> void PlayerRelocationNotifier::Visit<Player>(PlayerMapType &); |
---|
935 | template<> void CreatureRelocationNotifier::Visit<Player>(PlayerMapType &); |
---|
936 | template<> void CreatureRelocationNotifier::Visit<Creature>(CreatureMapType &); |
---|
937 | template<> inline void DynamicObjectUpdater::Visit<Creature>(CreatureMapType &); |
---|
938 | template<> inline void DynamicObjectUpdater::Visit<Player>(PlayerMapType &); |
---|
939 | #endif |
---|
940 | } |
---|
941 | #endif |
---|