2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
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"
29 #include "DynamicObject.h"
30 #include "GameObject.h"
40 struct MANGOS_DLL_DECL PlayerNotifier
42 PlayerNotifier(Player
&pl
) : i_player(pl
) {}
43 void Visit(PlayerMapType
&);
44 void BuildForMySelf(void);
48 struct MANGOS_DLL_DECL VisibleNotifier
52 VisibleNotifier(Player
&player
) : i_player(player
) {}
53 template<class T
> void Visit(std::map
<OBJECT_HANDLE
, T
*> &m
);
54 void Visit(std::map
<OBJECT_HANDLE
, GameObject
*> &);
59 template<> void VisibleNotifier::Visit(std::map
<OBJECT_HANDLE
, Creature
*> &);
60 template<> void VisibleNotifier::Visit(std::map
<OBJECT_HANDLE
, Player
*> &);
64 struct MANGOS_DLL_DECL VisibleChangesNotifier
67 VisibleChangesNotifier(Player
&player
) : i_player(player
) {}
68 template<class T
> void Visit(std::map
<OBJECT_HANDLE
, T
*> &m
);
71 template<> void VisibleChangesNotifier::Visit(std::map
<OBJECT_HANDLE
, Player
*> &);
75 struct MANGOS_DLL_DECL NotVisibleNotifier
79 NotVisibleNotifier(Player
&player
) : i_player(player
) {}
81 template<class T
> void Visit(std::map
<OBJECT_HANDLE
, T
*> &m
);
82 void Visit(std::map
<OBJECT_HANDLE
, GameObject
*> &);
85 template<> void NotVisibleNotifier::Visit(std::map
<OBJECT_HANDLE
, Creature
*> &);
86 template<> void NotVisibleNotifier::Visit(std::map
<OBJECT_HANDLE
, Player
*> &);
90 struct MANGOS_DLL_DECL ObjectVisibleNotifier
93 ObjectVisibleNotifier(Object
&obj
) : i_object(obj
) {}
94 void Visit(PlayerMapType
&);
97 struct MANGOS_DLL_DECL ObjectNotVisibleNotifier
100 ObjectNotVisibleNotifier(Object
&obj
) : i_object(obj
) {}
101 void Visit(PlayerMapType
&);
104 struct MANGOS_DLL_DECL GridUpdater
108 GridUpdater(GridType
&grid
, uint32 diff
) : i_grid(grid
), i_timeDiff(diff
) {}
110 template<class T
> void updateObjects(std::map
<OBJECT_HANDLE
, T
*> &m
)
112 for(typename
std::map
<OBJECT_HANDLE
, T
*>::iterator iter
=m
.begin(); iter
!= m
.end(); ++iter
)
113 iter
->second
->Update(i_timeDiff
);
116 void Visit(PlayerMapType
&m
) { updateObjects
<Player
>(m
); }
117 void Visit(CreatureMapType
&m
){ updateObjects
<Creature
>(m
); }
118 void Visit(GameObjectMapType
&m
) { updateObjects
<GameObject
>(m
); }
119 void Visit(DynamicObjectMapType
&m
) { updateObjects
<DynamicObject
>(m
); }
120 void Visit(CorpseMapType
&m
) { updateObjects
<Corpse
>(m
); }
123 struct MANGOS_DLL_DECL MessageDeliverer
126 WorldPacket
*i_message
;
129 MessageDeliverer(Player
&pl
, WorldPacket
*msg
, bool to_self
, bool ownTeamOnly
) : i_player(pl
), i_message(msg
), i_toSelf(to_self
), i_ownTeamOnly(ownTeamOnly
) {}
130 void Visit(PlayerMapType
&m
);
133 struct MANGOS_DLL_DECL ObjectMessageDeliverer
136 WorldPacket
*i_message
;
137 ObjectMessageDeliverer(Object
&obj
, WorldPacket
*msg
) : i_object(obj
), i_message(msg
) {}
138 void Visit(PlayerMapType
&m
);
141 struct MANGOS_DLL_DECL CreatureVisibleMovementNotifier
143 Creature
&i_creature
;
144 CreatureVisibleMovementNotifier(Creature
&creature
) : i_creature(creature
) {}
145 void Visit(PlayerMapType
&m
);
148 struct MANGOS_DLL_DECL CreatureNotVisibleMovementNotifier
150 Creature
&i_creature
;
151 CreatureNotVisibleMovementNotifier(Creature
&creature
) : i_creature(creature
) {}
152 void Visit(PlayerMapType
&m
);
155 struct MANGOS_DLL_DECL ObjectUpdater
158 ObjectUpdater(const uint32
&diff
) : i_timeDiff(diff
) {}
159 template<class T
> void Visit(std::map
<OBJECT_HANDLE
, T
*> &m
);
161 template<> void Visit(std::map
<OBJECT_HANDLE
, Creature
*> &);
166 struct MANGOS_DLL_DECL ObjectAccessorNotifier
170 ObjectAccessorNotifier(T
* &obj
, uint64 id
) : i_object(obj
), i_id(id
)
175 void Visit(std::map
<OBJECT_HANDLE
, T
*> &m
)
177 if( i_object
== NULL
)
179 typename
std::map
<OBJECT_HANDLE
, T
*>::iterator iter
= m
.find(i_id
);
180 if( iter
!= m
.end() )
182 assert( iter
->second
!= NULL
);
183 i_object
= iter
->second
;
188 template<class NOT_INTERESTED
> void Visit(std::map
<OBJECT_HANDLE
, NOT_INTERESTED
*> &m
) {}
191 template<class Check
>
192 struct MANGOS_DLL_DECL GameObjectSearcher
194 GameObject
* &i_object
;
195 Check
const& i_check
;
197 GameObjectSearcher(GameObject
* & result
, Check
const& check
) : i_object(result
),i_check(check
) {}
199 void Visit(std::map
<OBJECT_HANDLE
, GameObject
*> &m
);
201 template<class NOT_INTERESTED
> void Visit(std::map
<OBJECT_HANDLE
, NOT_INTERESTED
*> &m
) {}
204 template<class Check
>
205 void GameObjectSearcher
<Check
>::Visit(std::map
<OBJECT_HANDLE
, GameObject
*> &m
)
210 for(std::map
<OBJECT_HANDLE
, GameObject
*>::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
212 if(i_check(itr
->second
))
214 i_object
= itr
->second
;
220 class GameObjectFocusCheck
223 GameObjectFocusCheck(Unit
* unit
,uint32 focusId
) : i_unit(unit
), i_focusId(focusId
) {}
224 bool operator()(GameObject
* go
) const
226 if(go
->GetGOInfo()->type
!= GAMEOBJECT_TYPE_SPELL_FOCUS
|| go
->GetGOInfo()->sound0
!= i_focusId
)
229 float dist
= go
->GetGOInfo()->sound1
;
231 return go
->IsWithinDist(i_unit
, dist
);
239 template<class Check
>
240 struct MANGOS_DLL_DECL UnitSearcher
245 UnitSearcher(Unit
* & result
, Check
& check
) : i_object(result
),i_check(check
) {}
247 void Visit(std::map
<OBJECT_HANDLE
, Creature
*> &m
);
248 void Visit(std::map
<OBJECT_HANDLE
, Player
*> &m
);
250 template<class NOT_INTERESTED
> void Visit(std::map
<OBJECT_HANDLE
, NOT_INTERESTED
*> &m
) {}
253 template<class Check
>
254 struct MANGOS_DLL_DECL UnitListSearcher
256 std::list
<Unit
*> &i_objects
;
259 UnitListSearcher(std::list
<Unit
*> &objects
, Check
& check
) : i_objects(objects
),i_check(check
) {}
261 void Visit(std::map
<OBJECT_HANDLE
, Player
*> &m
)
263 for(std::map
<OBJECT_HANDLE
, Player
*>::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
265 if(i_check(itr
->second
))
266 i_objects
.push_back(itr
->second
);
270 void Visit(std::map
<OBJECT_HANDLE
, Creature
*> &m
)
272 for(std::map
<OBJECT_HANDLE
, Creature
*>::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
274 if(i_check(itr
->second
))
275 i_objects
.push_back(itr
->second
);
279 template<class NOT_INTERESTED
> void Visit(std::map
<OBJECT_HANDLE
, NOT_INTERESTED
*> &m
) {}
282 class AnyUnfriendlyUnitInObjectRangeCheck
285 AnyUnfriendlyUnitInObjectRangeCheck(Object
* obj
, Unit
* funit
, float range
) : i_obj(obj
), i_funit(funit
), i_range(range
), i_result(NULL
) {}
286 bool operator()(Unit
* u
)
288 if(!i_funit
->IsFriendlyTo(u
) && i_obj
->IsWithinDist(u
, i_range
))
295 Unit
*GetResult() const { return i_result
; }
303 struct MANGOS_DLL_DECL GridUnitListNotifier
305 std::list
<Unit
*> &i_data
;
306 GridUnitListNotifier(std::list
<Unit
*> &data
) : i_data(data
) {}
308 template<class T
> inline void Visit(std::map
<OBJECT_HANDLE
, T
*> &m
)
310 for(typename
std::map
<OBJECT_HANDLE
, T
*>::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
312 i_data
.push_back(itr
->second
);
317 template<> inline void Visit(std::map
<OBJECT_HANDLE
, Corpse
*> &m
) {}
318 template<> inline void Visit(std::map
<OBJECT_HANDLE
, GameObject
*> &m
) {}
319 template<> inline void Visit(std::map
<OBJECT_HANDLE
, DynamicObject
*> &m
) {}
323 struct MANGOS_DLL_DECL PlayerRelocationNotifier
326 PlayerRelocationNotifier(Player
&pl
) : i_player(pl
) {}
327 template<class T
> void Visit(std::map
<OBJECT_HANDLE
, T
*> &m
) {}
329 template<> void Visit(std::map
<OBJECT_HANDLE
, Corpse
*> &);
330 template<> void Visit(std::map
<OBJECT_HANDLE
, Player
*> &);
331 template<> void Visit(std::map
<OBJECT_HANDLE
, Creature
*> &);
335 struct MANGOS_DLL_DECL CreatureRelocationNotifier
337 Creature
&i_creature
;
338 CreatureRelocationNotifier(Creature
&c
) : i_creature(c
) {}
339 template<class T
> void Visit(std::map
<OBJECT_HANDLE
, T
*> &m
) {}
341 template<> void Visit(std::map
<OBJECT_HANDLE
, Player
*> &);
345 struct MANGOS_DLL_DECL DynamicObjectUpdater
347 DynamicObject
&owner
;
348 DynamicObjectUpdater(DynamicObject
&owner
) : owner(owner
) {}
350 template<class T
> inline void Visit(std::map
<OBJECT_HANDLE
, T
*> &m
) {}
352 template<> inline void Visit
<Player
>(std::map
<OBJECT_HANDLE
, Player
*> &);
353 template<> inline void Visit
<Creature
>(std::map
<OBJECT_HANDLE
, Creature
*> &);
359 template<> void VisibleNotifier::Visit
<Creature
>(std::map
<OBJECT_HANDLE
, Creature
*> &);
360 template<> void VisibleNotifier::Visit
<Player
>(std::map
<OBJECT_HANDLE
, Player
*> &);
361 template<> void VisibleChangesNotifier::Visit
<Player
>(std::map
<OBJECT_HANDLE
, Player
*> &);
362 template<> void NotVisibleNotifier::Visit
<Creature
>(std::map
<OBJECT_HANDLE
, Creature
*> &);
363 template<> void NotVisibleNotifier::Visit
<Player
>(std::map
<OBJECT_HANDLE
, Player
*> &);
364 template<> void ObjectUpdater::Visit
<Creature
>(std::map
<OBJECT_HANDLE
, Creature
*> &);
365 template<> void PlayerRelocationNotifier::Visit
<Corpse
>(std::map
<OBJECT_HANDLE
, Corpse
*> &);
366 template<> void PlayerRelocationNotifier::Visit
<Creature
>(std::map
<OBJECT_HANDLE
, Creature
*> &);
367 template<> void PlayerRelocationNotifier::Visit
<Player
>(std::map
<OBJECT_HANDLE
, Player
*> &);
368 template<> void CreatureRelocationNotifier::Visit
<Player
>(std::map
<OBJECT_HANDLE
, Player
*> &);
369 template<> inline void DynamicObjectUpdater::Visit
<Creature
>(std::map
<OBJECT_HANDLE
, Creature
*> &);
370 template<> inline void DynamicObjectUpdater::Visit
<Player
>(std::map
<OBJECT_HANDLE
, Player
*> &);
371 template<> inline void GridUnitListNotifier::Visit(std::map
<OBJECT_HANDLE
, Corpse
*> &m
) {}
372 template<> inline void GridUnitListNotifier::Visit(std::map
<OBJECT_HANDLE
, GameObject
*> &m
) {}
373 template<> inline void GridUnitListNotifier::Visit(std::map
<OBJECT_HANDLE
, DynamicObject
*> &m
) {}