TrinityCore
Loading...
Searching...
No Matches
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, class MapTypeMaskCheck>
184template <class T>
186{
187 if (this->ShouldContinue() == WorldObjectSearcherContinuation::Return)
188 return;
189
190 for (GridReference<T> const& ref : m)
191 {
192 if (!ref.GetSource()->InSamePhase(*i_phaseShift))
193 continue;
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
205template<typename Localizer>
207{
209 uint32 cache_idx = loc_idx + 1;
210 LocalizedAction* action;
211
212 // create if not cached yet
213 if (_localizedCache.size() < cache_idx + 1 || !_localizedCache[cache_idx])
214 {
215 if (_localizedCache.size() < cache_idx + 1)
216 _localizedCache.resize(cache_idx + 1);
217
218 action = _localizer(loc_idx);
219 _localizedCache[cache_idx].reset(action);
220 }
221 else
222 action = _localizedCache[cache_idx].get();
223
224 (*action)(p);
225}
226
227#endif // TRINITY_GRIDNOTIFIERSIMPL_H
LocaleConstant
Definition Common.h:51
uint32_t uint32
Definition Define.h:154
Unit * GetCaster() const
Player * ToPlayer()
Definition Object.h:126
void UpdateVisibilityOf(WorldObject *target)
Definition Player.cpp:24652
WorldObject * m_seer
Definition Player.h:2666
WorldSession * GetSession() const
Definition Player.h:2272
iterator end()
Definition RefManager.h:36
iterator begin()
Definition RefManager.h:35
void operator()(Player const *p)
std::remove_pointer_t< decltype(std::declval< Localizer >()(LocaleConstant{}))> LocalizedAction
Definition Unit.h:635
Vehicle * GetVehicle() const
Definition Unit.h:1784
SharedVisionList const & GetSharedVisionList()
Definition Unit.h:1255
bool HasSharedVision() const
Definition Unit.h:1258
bool InSamePhase(PhaseShift const &phaseShift) const
Definition Object.h:314
LocaleConstant GetSessionDbLocaleIndex() const
constexpr float GetExactDist2dSq(const float x, const float y) const
Definition Position.h:108
constexpr float GetExactDistSq(float x, float y, float z) const
Definition Position.h:121
void Visit(PlayerMapType &m) const
GuidUnorderedSet vis_guids
void Visit(GridRefManager< T > &m)
std::set< WorldObject * > i_visibleNow
void VisitImpl(GridRefManager< T > &)