TrinityCore
GridNotifiersImpl.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore 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 TRINITY_GRIDNOTIFIERSIMPL_H
19#define TRINITY_GRIDNOTIFIERSIMPL_H
20
21#include "GridNotifiers.h"
22#include "Corpse.h"
23#include "Player.h"
24#include "UpdateData.h"
25#include "WorldSession.h"
26
27template<class T>
29{
30 for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
31 {
32 vis_guids.erase(iter->GetSource()->GetGUID());
34 }
35}
36
37template<typename PacketSender>
39{
40 for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
41 {
42 Player* target = iter->GetSource();
43 if (!target->InSamePhase(*i_phaseShift))
44 continue;
45
46 if ((!required3dDist ? target->GetExactDist2dSq(i_source) : target->GetExactDistSq(i_source)) > i_distSq)
47 continue;
48
49 // Send packet to all who are sharing the player's vision
50 if (target->HasSharedVision())
51 {
52 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
53 for (; i != target->GetSharedVisionList().end(); ++i)
54 if ((*i)->m_seer == target)
55 SendPacket(*i);
56 }
57
58 if (target->m_seer == target || target->GetVehicle())
59 SendPacket(target);
60 }
61}
62
63template<typename PacketSender>
65{
66 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
67 {
68 Creature* target = iter->GetSource();
69 if (!target->InSamePhase(*i_phaseShift))
70 continue;
71
72 if ((!required3dDist ? target->GetExactDist2dSq(i_source) : target->GetExactDistSq(i_source)) > i_distSq)
73 continue;
74
75 // Send packet to all who are sharing the creature's vision
76 if (target->HasSharedVision())
77 {
78 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
79 for (; i != target->GetSharedVisionList().end(); ++i)
80 if ((*i)->m_seer == target)
81 SendPacket(*i);
82 }
83 }
84}
85
86template<typename PacketSender>
88{
89 for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
90 {
91 DynamicObject* target = iter->GetSource();
92 if (!target->InSamePhase(*i_phaseShift))
93 continue;
94
95 if ((!required3dDist ? target->GetExactDist2dSq(i_source) : target->GetExactDistSq(i_source)) > i_distSq)
96 continue;
97
98 if (Unit* caster = target->GetCaster())
99 {
100 // Send packet back to the caster if the caster has vision of dynamic object
101 Player* player = caster->ToPlayer();
102 if (player && player->m_seer == target)
103 SendPacket(player);
104 }
105 }
106}
107
108template<typename PacketSender>
110{
111 for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
112 {
113 Player* target = iter->GetSource();
114 if (!target->InSamePhase(*i_phaseShift))
115 continue;
116
117 if (target->GetExactDist2dSq(i_source) > i_distSq)
118 continue;
119
120 // Send packet to all who are sharing the player's vision
121 if (target->HasSharedVision())
122 {
123 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
124 for (; i != target->GetSharedVisionList().end(); ++i)
125 if ((*i)->m_seer == target)
126 SendPacket(*i);
127 }
128
129 if (target->m_seer == target || target->GetVehicle())
130 SendPacket(target);
131 }
132}
133
134template<typename PacketSender>
136{
137 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
138 {
139 Creature* target = iter->GetSource();
140 if (!target->InSamePhase(*i_phaseShift))
141 continue;
142
143 if (target->GetExactDist2dSq(i_source) > i_distSq)
144 continue;
145
146 // Send packet to all who are sharing the creature's vision
147 if (target->HasSharedVision())
148 {
149 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
150 for (; i != target->GetSharedVisionList().end(); ++i)
151 if ((*i)->m_seer == target)
152 SendPacket(*i);
153 }
154 }
155}
156
157template<typename PacketSender>
159{
160 for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
161 {
162 DynamicObject* target = iter->GetSource();
163 if (!target->InSamePhase(*i_phaseShift))
164 continue;
165
166 if (target->GetExactDist2dSq(i_source) > i_distSq)
167 continue;
168
169 if (Unit* caster = target->GetCaster())
170 {
171 // Send packet back to the caster if the caster has vision of dynamic object
172 Player* player = caster->ToPlayer();
173 if (player && player->m_seer == target)
174 SendPacket(player);
175 }
176 }
177}
178
179// SEARCHERS & LIST SEARCHERS & WORKERS
180
181// WorldObject searchers & workers
182
183template <class Check, class Result>
184template <class T>
186{
187 if (!(i_mapTypeMask & GridMapTypeMaskForType<T>::value))
188 return;
189
190 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
191 return;
192
193 for (GridReference<T> const& ref : m)
194 {
195 if (i_check(ref.GetSource()))
196 {
197 this->Insert(ref.GetSource());
198
199 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
200 return;
201 }
202 }
203}
204
205// Gameobject searchers
206
207template <class Check, class Result>
209{
210 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
211 return;
212
213 for (GridReference<GameObject> const& ref : m)
214 {
215 if (!ref.GetSource()->InSamePhase(*i_phaseShift))
216 continue;
217
218 if (i_check(ref.GetSource()))
219 {
220 this->Insert(ref.GetSource());
221
222 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
223 return;
224 }
225 }
226}
227
228// Unit searchers
229
230template <class Check, class Result>
231template <class T>
233{
234 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
235 return;
236
237 for (GridReference<T> const& ref : m)
238 {
239 if (!ref.GetSource()->InSamePhase(*i_phaseShift))
240 continue;
241
242 if (i_check(ref.GetSource()))
243 {
244 this->Insert(ref.GetSource());
245
246 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
247 return;
248 }
249 }
250}
251
252// Creature searchers
253
254template <class Check, class Result>
256{
257 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
258 return;
259
260 for (GridReference<Creature> const& ref : m)
261 {
262 if (!ref.GetSource()->InSamePhase(*i_phaseShift))
263 continue;
264
265 if (i_check(ref.GetSource()))
266 {
267 this->Insert(ref.GetSource());
268
269 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
270 return;
271 }
272 }
273}
274
275// Player searchers
276
277template <class Check, class Result>
279{
280 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
281 return;
282
283 for (GridReference<Player> const& ref : m)
284 {
285 if (!ref.GetSource()->InSamePhase(*i_phaseShift))
286 continue;
287
288 if (i_check(ref.GetSource()))
289 {
290 this->Insert(ref.GetSource());
291
292 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
293 return;
294 }
295 }
296}
297
298template<typename Localizer>
300{
302 uint32 cache_idx = loc_idx + 1;
303 LocalizedAction* action;
304
305 // create if not cached yet
306 if (_localizedCache.size() < cache_idx + 1 || !_localizedCache[cache_idx])
307 {
308 if (_localizedCache.size() < cache_idx + 1)
309 _localizedCache.resize(cache_idx + 1);
310
311 action = _localizer(loc_idx);
312 _localizedCache[cache_idx].reset(action);
313 }
314 else
315 action = _localizedCache[cache_idx].get();
316
317 (*action)(p);
318}
319
320#endif // TRINITY_GRIDNOTIFIERSIMPL_H
LocaleConstant
Definition: Common.h:48
uint32_t uint32
Definition: Define.h:142
Unit * GetCaster() const
Definition: DynamicObject.h:75
iterator end()
iterator begin()
static Player * ToPlayer(Object *o)
Definition: Object.h:213
void UpdateVisibilityOf(WorldObject *target)
Definition: Player.cpp:23902
WorldObject * m_seer
Definition: Player.h:2476
WorldSession * GetSession() const
Definition: Player.h:2101
void operator()(Player const *p)
std::remove_pointer_t< decltype(std::declval< Localizer >()(LocaleConstant{}))> LocalizedAction
Definition: Unit.h:627
Vehicle * GetVehicle() const
Definition: Unit.h:1713
SharedVisionList const & GetSharedVisionList()
Definition: Unit.h:1234
bool HasSharedVision() const
Definition: Unit.h:1237
bool InSamePhase(PhaseShift const &phaseShift) const
Definition: Object.h:527
LocaleConstant GetSessionDbLocaleIndex() const
bool Insert(ContainerUnorderedMap< TypeList< H, T >, KEY_TYPE > &elements, KEY_TYPE const &handle, SPECIFIC_TYPE *obj)
constexpr float GetExactDist2dSq(const float x, const float y) const
Definition: Position.h:97
constexpr float GetExactDistSq(float x, float y, float z) const
Definition: Position.h:110
void Visit(CreatureMapType &m)
void Visit(GameObjectMapType &m)
void Visit(PlayerMapType &m) const
void Visit(PlayerMapType &m) const
void Visit(PlayerMapType &m)
void VisitImpl(GridRefManager< T > &m)
GuidUnorderedSet vis_guids
Definition: GridNotifiers.h:53
void Visit(GridRefManager< T > &m)
std::set< WorldObject * > i_visibleNow
Definition: GridNotifiers.h:52
void Visit(GridRefManager< T > &)