Merge commit 'mangos/master'
[auctionmangos.git] / src / game / GridNotifiers.cpp
blob2d2d637505f07326d312660ed2df2efafca56970
1 /*
2 * Copyright (C) 2005-2008 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 #include "GridNotifiers.h"
20 #include "WorldPacket.h"
21 #include "WorldSession.h"
22 #include "UpdateData.h"
23 #include "Item.h"
24 #include "Map.h"
25 #include "MapManager.h"
26 #include "Transports.h"
27 #include "ObjectAccessor.h"
29 using namespace MaNGOS;
31 void
32 MaNGOS::PlayerNotifier::Visit(PlayerMapType &m)
34 for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
36 if( iter->getSource() == &i_player )
37 continue;
39 iter->getSource()->UpdateVisibilityOf(&i_player);
40 i_player.UpdateVisibilityOf(iter->getSource());
44 void
45 VisibleChangesNotifier::Visit(PlayerMapType &m)
47 for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
49 if(iter->getSource() == &i_object)
50 continue;
52 iter->getSource()->UpdateVisibilityOf(&i_object);
56 void
57 VisibleNotifier::Visit(PlayerMapType &m)
59 for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
61 if( iter->getSource() == &i_player )
62 continue;
64 iter->getSource()->UpdateVisibilityOf(&i_player);
65 i_player.UpdateVisibilityOf(iter->getSource(),i_data,i_data_updates,i_visibleNow);
66 i_clientGUIDs.erase(iter->getSource()->GetGUID());
70 void
71 VisibleNotifier::Notify()
73 // at this moment i_clientGUIDs have guids that not iterate at grid level checks
74 // but exist one case when this possible and object not out of range: transports
75 if(Transport* transport = i_player.GetTransport())
77 for(Transport::PlayerSet::const_iterator itr = transport->GetPassengers().begin();itr!=transport->GetPassengers().end();++itr)
79 if(i_clientGUIDs.find((*itr)->GetGUID())!=i_clientGUIDs.end())
81 (*itr)->UpdateVisibilityOf(&i_player);
82 i_player.UpdateVisibilityOf((*itr),i_data,i_data_updates,i_visibleNow);
83 i_clientGUIDs.erase((*itr)->GetGUID());
88 // generate outOfRange for not iterate objects
89 i_data.AddOutOfRangeGUID(i_clientGUIDs);
90 for(Player::ClientGUIDs::iterator itr = i_clientGUIDs.begin();itr!=i_clientGUIDs.end();++itr)
92 i_player.m_clientGUIDs.erase(*itr);
94 #ifdef MANGOS_DEBUG
95 if((sLog.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES)==0)
96 sLog.outDebug("Object %u (Type: %u) is out of range (no in active cells set) now for player %u",GUID_LOPART(*itr),GuidHigh2TypeId(GUID_HIPART(*itr)),i_player.GetGUIDLow());
97 #endif
100 // send update to other players (except player updates that already sent using SendUpdateToPlayer)
101 for(UpdateDataMapType::iterator iter = i_data_updates.begin(); iter != i_data_updates.end(); ++iter)
103 if(iter->first==&i_player)
104 continue;
106 WorldPacket packet;
107 iter->second.BuildPacket(&packet);
108 iter->first->GetSession()->SendPacket(&packet);
111 if( i_data.HasData() )
113 // send create/outofrange packet to player (except player create updates that already sent using SendUpdateToPlayer)
114 WorldPacket packet;
115 i_data.BuildPacket(&packet);
116 i_player.GetSession()->SendPacket(&packet);
118 // send out of range to other players if need
119 std::set<uint64> const& oor = i_data.GetOutOfRangeGUIDs();
120 for(std::set<uint64>::const_iterator iter = oor.begin(); iter != oor.end(); ++iter)
122 if(!IS_PLAYER_GUID(*iter))
123 continue;
125 Player* plr = ObjectAccessor::GetPlayer(i_player,*iter);
126 if(plr)
127 plr->UpdateVisibilityOf(&i_player);
131 // Now do operations that required done at object visibility change to visible
133 // target aura duration for caster show only if target exist at caster client
134 // send data at target visibility change (adding to client)
135 for(std::set<WorldObject*>::const_iterator vItr = i_visibleNow.begin(); vItr != i_visibleNow.end(); ++vItr)
136 if((*vItr)!=&i_player && (*vItr)->isType(TYPEMASK_UNIT))
137 i_player.SendAuraDurationsForTarget((Unit*)(*vItr));
140 void
141 MessageDeliverer::Visit(PlayerMapType &m)
143 for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
145 if( i_toSelf || iter->getSource() != &i_player)
147 if(WorldSession* session = iter->getSource()->GetSession())
148 session->SendPacket(i_message);
153 void
154 ObjectMessageDeliverer::Visit(PlayerMapType &m)
156 for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
158 if(WorldSession* session = iter->getSource()->GetSession())
159 session->SendPacket(i_message);
163 void
164 MessageDistDeliverer::Visit(PlayerMapType &m)
166 for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
168 if( (i_toSelf || iter->getSource() != &i_player ) &&
169 (!i_ownTeamOnly || iter->getSource()->GetTeam() == i_player.GetTeam() ) &&
170 (!i_dist || iter->getSource()->GetDistance(&i_player) <= i_dist) )
172 if(WorldSession* session = iter->getSource()->GetSession())
173 session->SendPacket(i_message);
178 void
179 ObjectMessageDistDeliverer::Visit(PlayerMapType &m)
181 for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
183 if( !i_dist || iter->getSource()->GetDistance(&i_object) <= i_dist )
185 if(WorldSession* session = iter->getSource()->GetSession())
186 session->SendPacket(i_message);
191 template<class T> void
192 ObjectUpdater::Visit(GridRefManager<T> &m)
194 for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
196 iter->getSource()->Update(i_timeDiff);
200 template void ObjectUpdater::Visit<GameObject>(GameObjectMapType &);
201 template void ObjectUpdater::Visit<DynamicObject>(DynamicObjectMapType &);
203 bool CannibalizeObjectCheck::operator()(Corpse* u)
205 // ignore bones
206 if(u->GetType()==CORPSE_BONES)
207 return false;
209 Player* owner = ObjectAccessor::FindPlayer(u->GetOwnerGUID());
211 if( !owner || i_funit->IsFriendlyTo(owner))
212 return false;
214 if(i_funit->IsWithinDistInMap(u, i_range) )
215 return true;
217 return false;