Files
TCPlayerbotCore/src/game/GridNotifiersImpl.h
T

588 lines
16 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
* Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-14 11:57:03 -05:00
#ifndef TRINITY_GRIDNOTIFIERSIMPL_H
#define TRINITY_GRIDNOTIFIERSIMPL_H
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "GridNotifiers.h"
#include "WorldPacket.h"
#include "Corpse.h"
#include "Player.h"
#include "UpdateData.h"
#include "CreatureAI.h"
#include "SpellAuras.h"
2009-10-17 15:51:44 -07:00
template<class T>
inline void
Trinity::VisibleNotifier::Visit(GridRefManager<T> &m)
{
for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
{
vis_guids.erase(iter->getSource()->GetGUID());
if(force/* || iter->getSource()->isNeedNotify(NOTIFY_VISIBILITY_CHANGED)*/)
i_player.UpdateVisibilityOf(iter->getSource(),i_data,i_visibleNow);
}
}
inline void
Trinity::VisibleNotifier::Visit(CreatureMapType &m)
{
for(CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
{
vis_guids.erase(iter->getSource()->GetGUID());
if(force || iter->getSource()->isNeedNotify(NOTIFY_VISIBILITY_CHANGED))
i_player.UpdateVisibilityOf(iter->getSource(),i_data,i_visibleNow);
}
}
2008-10-02 16:23:55 -05:00
inline void
2008-10-14 11:57:03 -05:00
Trinity::ObjectUpdater::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
2009-05-03 10:34:02 -05:00
if(iter->getSource()->IsInWorld() && !iter->getSource()->isSpiritService())
2008-10-02 16:23:55 -05:00
iter->getSource()->Update(i_timeDiff);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
inline void PlayerCreatureRelocationWorker(Player* pl, Creature* c)
{
2009-03-08 11:11:21 -06:00
if(!pl->isAlive() || !c->isAlive() || pl->isInFlight())
return;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Creature AI reaction
2008-12-08 16:34:03 -06:00
if(c->HasReactState(REACT_AGGRESSIVE) && !c->hasUnitState(UNIT_STAT_SIGHTLESS))
if(c->_IsWithinDist(pl, c->m_SightDistance, true) && c->IsAIEnabled)
2008-10-02 16:23:55 -05:00
c->AI()->MoveInLineOfSight(pl);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
inline void CreatureCreatureRelocationWorker(Creature* c1, Creature* c2)
{
2008-12-08 16:34:03 -06:00
if(c1->HasReactState(REACT_AGGRESSIVE) && !c1->hasUnitState(UNIT_STAT_SIGHTLESS))
if(c1->_IsWithinDist(c2, c1->m_SightDistance, true) && c1->IsAIEnabled)
2008-10-02 16:23:55 -05:00
c1->AI()->MoveInLineOfSight(c2);
2009-10-17 15:51:44 -07:00
2008-12-08 16:34:03 -06:00
if(c2->HasReactState(REACT_AGGRESSIVE) && !c2->hasUnitState(UNIT_STAT_SIGHTLESS))
if(c1->_IsWithinDist(c2, c2->m_SightDistance, true) && c2->IsAIEnabled)
2008-10-02 16:23:55 -05:00
c2->AI()->MoveInLineOfSight(c1);
}
2009-10-17 15:51:44 -07:00
template<class T, class VISITOR>
2009-03-08 11:11:21 -06:00
inline void
2009-12-20 15:20:04 +01:00
Trinity::DelayedUnitRelocation::Notify(GridRefManager<T> &m)
2009-03-08 11:11:21 -06:00
{
for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
2009-03-08 11:11:21 -06:00
{
T * unit = iter->getSource();
if(!unit->isAlive() || !unit->isNeedNotify(NOTIFY_AI_RELOCATION))
2009-03-08 11:11:21 -06:00
continue;
2009-10-17 15:51:44 -07:00
VISITOR relocate(*unit);
TypeContainerVisitor<VISITOR, WorldTypeMapContainer > c2world_relocation(relocate);
TypeContainerVisitor<VISITOR, GridTypeMapContainer > c2grid_relocation(relocate);
2009-10-17 15:51:44 -07:00
i_lock->Visit(i_lock, c2world_relocation, i_map, *unit, i_radius);
i_lock->Visit(i_lock, c2grid_relocation, i_map, *unit, i_radius);
2009-10-17 15:51:44 -07:00
unit->SetNotified(NOTIFY_AI_RELOCATION);
2009-03-08 11:11:21 -06:00
}
}
2009-10-17 15:51:44 -07:00
template<class T>
inline void
2009-12-20 15:20:04 +01:00
Trinity::ResetNotifier::resetNotify(GridRefManager<T> &m)
{
for(typename GridRefManager<T>::iterator iter=m.begin(); iter != m.end(); ++iter)
iter->getSource()->ResetAllNotifiesbyMask(reset_mask);
}
2009-03-08 11:11:21 -06:00
template<>
2008-10-02 16:23:55 -05:00
inline void
2008-10-14 11:57:03 -05:00
Trinity::PlayerRelocationNotifier::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
if(!i_player.isAlive() || i_player.isInFlight())
return;
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
2009-03-08 11:11:21 -06:00
{
Creature * c = iter->getSource();
if(c->isAlive() && !c->NotifyExecuted(NOTIFY_AI_RELOCATION))
PlayerCreatureRelocationWorker(&i_player, c);
2009-03-08 11:11:21 -06:00
}
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<>
inline void
2008-10-14 11:57:03 -05:00
Trinity::CreatureRelocationNotifier::Visit(PlayerMapType &m)
2008-10-02 16:23:55 -05:00
{
if(!i_creature.isAlive())
return;
2009-10-17 15:51:44 -07:00
for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
{
Player * pl = iter->getSource();
if( pl->isAlive() && !pl->isInFlight() && !pl->NotifyExecuted(NOTIFY_AI_RELOCATION))
PlayerCreatureRelocationWorker(pl, &i_creature);
2009-03-08 11:11:21 -06:00
}
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<>
inline void
2008-10-14 11:57:03 -05:00
Trinity::CreatureRelocationNotifier::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
if(!i_creature.isAlive())
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
2008-10-02 16:23:55 -05:00
{
Creature* c = iter->getSource();
if( c != &i_creature && c->isAlive() && !c->NotifyExecuted(NOTIFY_AI_RELOCATION))
CreatureCreatureRelocationWorker(c, &i_creature);
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// SEARCHERS & LIST SEARCHERS & WORKERS
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// WorldObject searchers & workers
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::WorldObjectSearcher<Check>::Visit(GameObjectMapType &m)
2008-10-02 16:23:55 -05:00
{
// already found
if(i_object)
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
if (i_check(itr->getSource()))
2008-10-02 16:23:55 -05:00
{
i_object = itr->getSource();
return;
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::WorldObjectSearcher<Check>::Visit(PlayerMapType &m)
2008-10-02 16:23:55 -05:00
{
// already found
if(i_object)
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
{
i_object = itr->getSource();
return;
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::WorldObjectSearcher<Check>::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
// already found
if(i_object)
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
{
i_object = itr->getSource();
return;
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::WorldObjectSearcher<Check>::Visit(CorpseMapType &m)
2008-10-02 16:23:55 -05:00
{
// already found
if(i_object)
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (CorpseMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
{
i_object = itr->getSource();
return;
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::WorldObjectSearcher<Check>::Visit(DynamicObjectMapType &m)
2008-10-02 16:23:55 -05:00
{
// already found
if(i_object)
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (DynamicObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
{
i_object = itr->getSource();
return;
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::WorldObjectListSearcher<Check>::Visit(PlayerMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
if(itr->getSource()->InSamePhase(i_phaseMask))
if(i_check(itr->getSource()))
i_objects.push_back(itr->getSource());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::WorldObjectListSearcher<Check>::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
if(itr->getSource()->InSamePhase(i_phaseMask))
if(i_check(itr->getSource()))
i_objects.push_back(itr->getSource());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::WorldObjectListSearcher<Check>::Visit(CorpseMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (CorpseMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
if(itr->getSource()->InSamePhase(i_phaseMask))
if(i_check(itr->getSource()))
i_objects.push_back(itr->getSource());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::WorldObjectListSearcher<Check>::Visit(GameObjectMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
if(itr->getSource()->InSamePhase(i_phaseMask))
if(i_check(itr->getSource()))
i_objects.push_back(itr->getSource());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::WorldObjectListSearcher<Check>::Visit(DynamicObjectMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (DynamicObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
if(itr->getSource()->InSamePhase(i_phaseMask))
if(i_check(itr->getSource()))
i_objects.push_back(itr->getSource());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Gameobject searchers
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::GameObjectSearcher<Check>::Visit(GameObjectMapType &m)
2008-10-02 16:23:55 -05:00
{
// already found
if(i_object)
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
{
i_object = itr->getSource();
return;
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::GameObjectLastSearcher<Check>::Visit(GameObjectMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
i_object = itr->getSource();
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::GameObjectListSearcher<Check>::Visit(GameObjectMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
if(itr->getSource()->InSamePhase(i_phaseMask))
if(i_check(itr->getSource()))
i_objects.push_back(itr->getSource());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Unit searchers
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::UnitSearcher<Check>::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
// already found
if(i_object)
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
{
i_object = itr->getSource();
return;
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::UnitSearcher<Check>::Visit(PlayerMapType &m)
2008-10-02 16:23:55 -05:00
{
// already found
if(i_object)
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
{
i_object = itr->getSource();
return;
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::UnitLastSearcher<Check>::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
i_object = itr->getSource();
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::UnitLastSearcher<Check>::Visit(PlayerMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
i_object = itr->getSource();
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::UnitListSearcher<Check>::Visit(PlayerMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
if(itr->getSource()->InSamePhase(i_phaseMask))
if(i_check(itr->getSource()))
i_objects.push_back(itr->getSource());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::UnitListSearcher<Check>::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
if(itr->getSource()->InSamePhase(i_phaseMask))
if(i_check(itr->getSource()))
i_objects.push_back(itr->getSource());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Creature searchers
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::CreatureSearcher<Check>::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
// already found
if(i_object)
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
{
i_object = itr->getSource();
return;
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::CreatureLastSearcher<Check>::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
i_object = itr->getSource();
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::CreatureListSearcher<Check>::Visit(CreatureMapType &m)
2008-10-02 16:23:55 -05:00
{
2009-10-17 16:20:24 -07:00
for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
if(itr->getSource()->InSamePhase(i_phaseMask))
if( i_check(itr->getSource()))
i_objects.push_back(itr->getSource());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
template<class Check>
void Trinity::PlayerListSearcher<Check>::Visit(PlayerMapType &m)
{
2009-10-17 16:20:24 -07:00
for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
if(itr->getSource()->InSamePhase(i_phaseMask))
if( i_check(itr->getSource()))
i_objects.push_back(itr->getSource());
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
template<class Check>
2008-10-14 11:57:03 -05:00
void Trinity::PlayerSearcher<Check>::Visit(PlayerMapType &m)
2008-10-02 16:23:55 -05:00
{
// already found
if(i_object)
return;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
if(!itr->getSource()->InSamePhase(i_phaseMask))
continue;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if(i_check(itr->getSource()))
{
i_object = itr->getSource();
return;
}
}
}
2009-10-17 15:51:44 -07:00
template<class Builder>
2009-12-20 15:20:04 +01:00
void Trinity::LocalizedPacketDo<Builder>::operator()( Player* p )
{
int32 loc_idx = p->GetSession()->GetSessionDbLocaleIndex();
uint32 cache_idx = loc_idx+1;
WorldPacket* data;
2009-10-17 15:51:44 -07:00
// create if not cached yet
if(i_data_cache.size() < cache_idx+1 || !i_data_cache[cache_idx])
{
if(i_data_cache.size() < cache_idx+1)
i_data_cache.resize(cache_idx+1);
2009-10-17 15:51:44 -07:00
data = new WorldPacket(SMSG_MESSAGECHAT, 200);
2009-10-17 15:51:44 -07:00
i_builder(*data,loc_idx);
2009-10-17 15:51:44 -07:00
i_data_cache[cache_idx] = data;
}
else
data = i_data_cache[cache_idx];
2009-10-17 15:51:44 -07:00
p->SendDirectMessage(data);
}
2009-10-17 15:51:44 -07:00
template<class Builder>
2009-12-20 15:20:04 +01:00
void Trinity::LocalizedPacketListDo<Builder>::operator()( Player* p )
{
int32 loc_idx = p->GetSession()->GetSessionDbLocaleIndex();
uint32 cache_idx = loc_idx+1;
WorldPacketList* data_list;
2009-10-17 15:51:44 -07:00
// create if not cached yet
if(i_data_cache.size() < cache_idx+1 || i_data_cache[cache_idx].empty())
{
if(i_data_cache.size() < cache_idx+1)
i_data_cache.resize(cache_idx+1);
2009-10-17 15:51:44 -07:00
data_list = &i_data_cache[cache_idx];
2009-10-17 15:51:44 -07:00
i_builder(*data_list,loc_idx);
}
else
data_list = &i_data_cache[cache_idx];
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (size_t i = 0; i < data_list->size(); ++i)
p->SendDirectMessage((*data_list)[i]);
}
2009-10-17 15:51:44 -07:00
2009-08-06 17:36:32 +02:00
struct ObjectDistanceOrder : public std::binary_function<const WorldObject, const WorldObject, bool>
{
const Unit* m_pSource;
2009-10-17 15:51:44 -07:00
2009-08-06 17:36:32 +02:00
ObjectDistanceOrder(const Unit* pSource) : m_pSource(pSource) {};
2009-10-17 15:51:44 -07:00
2009-08-06 17:36:32 +02:00
bool operator()(const WorldObject* pLeft, const WorldObject* pRight) const
{
return m_pSource->GetDistanceOrder(pLeft, pRight);
}
};
2009-10-17 15:51:44 -07:00
2009-08-06 17:36:32 +02:00
struct ObjectDistanceOrderReversed : public std::binary_function<const WorldObject, const WorldObject, bool>
{
const Unit* m_pSource;
2009-10-17 15:51:44 -07:00
2009-08-06 17:36:32 +02:00
ObjectDistanceOrderReversed(const Unit* pSource) : m_pSource(pSource) {};
2009-10-17 15:51:44 -07:00
2009-08-06 17:36:32 +02:00
bool operator()(const WorldObject* pLeft, const WorldObject* pRight) const
{
return !m_pSource->GetDistanceOrder(pLeft, pRight);
}
};
2009-10-17 15:51:44 -07:00
#endif // MANGOS_GRIDNOTIFIERSIMPL_H