[10338] Create Map version for GetPlayer/GetUnit fucntions

* This let make map local way access for cases when player/all units
  expected to be at same map (for scripts cases for example).
  Ofc, still exist many places where code expect world wide player search.
  Spell casting for support far target cases, groups/guilds/chat/etc packets

* Function Unit::GetUnit depricated and will removed soon.
* Function GetCreatureOrPetOrVehicle renamed to less horriable GetAnyTypeCreature name.
This commit is contained in:
VladimirMangos 2010-08-10 17:26:11 +04:00
parent 0aa9e5a133
commit 45cdc67f58
16 changed files with 22391 additions and 22313 deletions

View file

@ -78,7 +78,7 @@ void AggressorAI::EnterEvadeMode()
return;
}
Unit* victim = ObjectAccessor::GetUnit(*m_creature, i_victimGuid );
Unit* victim = m_creature->GetMap()->GetUnit(i_victimGuid);
if (!victim)
{

View file

@ -1993,7 +1993,8 @@ Unit* ChatHandler::getSelectedUnit()
if (guid == 0)
return m_session->GetPlayer();
return ObjectAccessor::GetUnit(*m_session->GetPlayer(),guid);
// can be selected player at another map
return ObjectAccessor::GetUnit(*m_session->GetPlayer(), guid);
}
Creature* ChatHandler::getSelectedCreature()
@ -2001,7 +2002,7 @@ Creature* ChatHandler::getSelectedCreature()
if(!m_session)
return NULL;
return m_session->GetPlayer()->GetMap()->GetCreatureOrPetOrVehicle(m_session->GetPlayer()->GetSelection());
return m_session->GetPlayer()->GetMap()->GetAnyTypeCreature(m_session->GetPlayer()->GetSelection());
}
/**

View file

@ -31,14 +31,17 @@ void WorldSession::HandleAttackSwingOpcode( WorldPacket & recv_data )
DEBUG_FILTER_LOG(LOG_FILTER_COMBAT, "WORLD: Recvd CMSG_ATTACKSWING Message %s", guid.GetString().c_str());
Unit *pEnemy = ObjectAccessor::GetUnit(*_player, guid);
if(!guid.IsUnit())
{
sLog.outError("WORLD: %s isn't unit", guid.GetString().c_str());
return;
}
Unit *pEnemy = _player->GetMap()->GetUnit(guid);
if(!pEnemy)
{
if(!guid.IsUnit())
sLog.outError("WORLD: %s isn't player, pet or creature", guid.GetString().c_str());
else
sLog.outError( "WORLD: Enemy %s not found", guid.GetString().c_str());
sLog.outError( "WORLD: Enemy %s not found", guid.GetString().c_str());
// stop attack state at client
SendAttackStop(NULL);

View file

@ -71,7 +71,7 @@ void GuardAI::EnterEvadeMode()
return;
}
Unit* victim = ObjectAccessor::GetUnit(*m_creature, i_victimGuid );
Unit* victim = m_creature->GetMap()->GetUnit(i_victimGuid);
if (!victim)
{

View file

@ -2882,32 +2882,69 @@ void Map::ScriptsProcess()
}
}
/**
* Function return player that in world at CURRENT map
*
* Note: This is function preferred if you sure that need player only placed at specific map
* This is not true for some spell cast targeting and most packet handlers
*
* @param guid must be player guid (HIGHGUID_PLAYER)
*/
Player* Map::GetPlayer(ObjectGuid guid)
{
Player* plr = ObjectAccessor::FindPlayer(guid); // return only in world players
return plr && plr->GetMap() == this ? plr : NULL;
}
/**
* Function return creature (non-pet and then most summoned by spell creatures, and not vehicle) that in world at CURRENT map
*
* @param guid must be creature guid (HIGHGUID_UNIT)
*/
Creature* Map::GetCreature(ObjectGuid guid)
{
return m_objectsStore.find<Creature>(guid.GetRawValue(), (Creature*)NULL);
}
/**
* Function return vehicle that in world at CURRENT map
*
* @param guid must be vehicle guid (HIGHGUID_VEHICLE)
*/
Vehicle* Map::GetVehicle(ObjectGuid guid)
{
return m_objectsStore.find<Vehicle>(guid.GetRawValue(), (Vehicle*)NULL);
}
/**
* Function return pet that in world at CURRENT map
*
* @param guid must be pet guid (HIGHGUID_PET)
*/
Pet* Map::GetPet(ObjectGuid guid)
{
return m_objectsStore.find<Pet>(guid.GetRawValue(), (Pet*)NULL);
}
/**
* Function return corpse that at CURRENT map
*
* Note: corpse can be NOT IN WORLD, so can't be used corspe->GetMap() without pre-check corpse->isInWorld()
*
* @param guid must be corpse guid (HIGHGUID_CORPSE)
*/
Corpse* Map::GetCorpse(ObjectGuid guid)
{
Corpse * ret = ObjectAccessor::GetCorpseInMap(guid,GetId());
if (!ret)
return NULL;
if (ret->GetInstanceId() != GetInstanceId())
return NULL;
return ret;
return ret && ret->GetInstanceId() == GetInstanceId() ? ret : NULL;
}
Creature* Map::GetCreatureOrPetOrVehicle(ObjectGuid guid)
/**
* Function return non-player unit object that in world at CURRENT map, so creature, or pet, or vehicle
*
* @param guid must be non-player unit guid (HIGHGUID_PET HIGHGUID_UNIT HIGHGUID_VEHICLE)
*/
Creature* Map::GetAnyTypeCreature(ObjectGuid guid)
{
switch(guid.GetHigh())
{
@ -2920,27 +2957,61 @@ Creature* Map::GetCreatureOrPetOrVehicle(ObjectGuid guid)
return NULL;
}
/**
* Function return gameobject that in world at CURRENT map
*
* @param guid must be gameobject guid (HIGHGUID_GAMEOBJECT)
*/
GameObject* Map::GetGameObject(ObjectGuid guid)
{
return m_objectsStore.find<GameObject>(guid.GetRawValue(), (GameObject*)NULL);
}
/**
* Function return dynamic object that in world at CURRENT map
*
* @param guid must be dynamic object guid (HIGHGUID_DYNAMICOBJECT)
*/
DynamicObject* Map::GetDynamicObject(ObjectGuid guid)
{
return m_objectsStore.find<DynamicObject>(guid.GetRawValue(), (DynamicObject*)NULL);
}
/**
* Function return unit in world at CURRENT map
*
* Note: in case player guid not always expected need player at current map only.
* For example in spell casting can be expected any in world player targeting in some cases
*
* @param guid must be unit guid (HIGHGUID_PLAYER HIGHGUID_PET HIGHGUID_UNIT HIGHGUID_VEHICLE)
*/
Unit* Map::GetUnit(ObjectGuid guid)
{
if (guid.IsPlayer())
return GetPlayer(guid);
return GetAnyTypeCreature(guid);
}
/**
* Function return world object in world at CURRENT map, so any except transports
*/
WorldObject* Map::GetWorldObject(ObjectGuid guid)
{
switch(guid.GetHigh())
{
case HIGHGUID_PLAYER: return ObjectAccessor::FindPlayer(guid);
case HIGHGUID_PLAYER: return GetPlayer(guid);
case HIGHGUID_GAMEOBJECT: return GetGameObject(guid);
case HIGHGUID_UNIT: return GetCreature(guid);
case HIGHGUID_PET: return GetPet(guid);
case HIGHGUID_VEHICLE: return GetVehicle(guid);
case HIGHGUID_DYNAMICOBJECT:return GetDynamicObject(guid);
case HIGHGUID_CORPSE: return GetCorpse(guid);
case HIGHGUID_CORPSE:
{
// corpse special case, it can be not in world
Corpse* corpse = GetCorpse(guid);
return corpse && corpse->IsInWorld() ? corpse : NULL;
}
case HIGHGUID_MO_TRANSPORT:
case HIGHGUID_TRANSPORT:
default: break;

View file

@ -240,14 +240,16 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
// must called with RemoveFromWorld
void RemoveFromActive(WorldObject* obj);
Player* GetPlayer(ObjectGuid guid);
Creature* GetCreature(ObjectGuid guid);
Vehicle* GetVehicle(ObjectGuid guid);
Pet* GetPet(ObjectGuid guid);
Creature* GetCreatureOrPetOrVehicle(ObjectGuid guid);
Creature* GetAnyTypeCreature(ObjectGuid guid); // normal creature or pet or vehicle
GameObject* GetGameObject(ObjectGuid guid);
DynamicObject* GetDynamicObject(ObjectGuid guid);
Corpse* GetCorpse(ObjectGuid guid);
WorldObject* GetWorldObject(ObjectGuid guid);
Corpse* GetCorpse(ObjectGuid guid); // !!! find corpse can be not in world
Unit* GetUnit(ObjectGuid guid); // only use if sure that need objects at current map, specially for player case
WorldObject* GetWorldObject(ObjectGuid guid); // only use if sure that need objects at current map, specially for player case
TypeUnorderedMapContainer<AllMapStoredObjectTypes>& GetObjectsStore() { return m_objectsStore; }

View file

@ -65,7 +65,7 @@ ObjectAccessor::GetUnit(WorldObject const &u, ObjectGuid guid)
if (!u.IsInWorld())
return NULL;
return u.GetMap()->GetCreatureOrPetOrVehicle(guid);
return u.GetMap()->GetAnyTypeCreature(guid);
}
Corpse* ObjectAccessor::GetCorpseInMap(ObjectGuid guid, uint32 mapid)

View file

@ -103,11 +103,12 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor,
static Creature* GetCreatureInWorld(ObjectGuid guid) { return FindHelper<Creature>(guid); }
static GameObject* GetGameObjectInWorld(ObjectGuid guid) { return FindHelper<GameObject>(guid); }
// possible local search for specific object map
static Unit* GetUnit(WorldObject const &, ObjectGuid guid);
// Search player at any map in world and other objects at same map with `obj`
// Note: recommended use Map::GetUnit version if player also expected at same map only
static Unit* GetUnit(WorldObject const& obj, ObjectGuid guid);
// Player access
static Player* FindPlayer(ObjectGuid guid);
static Player* FindPlayer(ObjectGuid guid); // if need player at specific map better use Map::GetPlayer
static Player* FindPlayerByName(const char *name);
static void KickPlayer(uint64 guid);

View file

@ -41,8 +41,8 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
uint32 spellid = UNIT_ACTION_BUTTON_ACTION(data);
uint8 flag = UNIT_ACTION_BUTTON_TYPE(data); //delete = 0x07 CastSpell = C1
// used also for charmed creature
Unit* pet= ObjectAccessor::GetUnit(*_player, guid1);
// used also for charmed creature/player
Unit* pet = _player->GetMap()->GetUnit(guid1);
DETAIL_LOG("HandlePetAction.Pet %u flag is %u, spellid is %u, target %u.", uint32(GUID_LOPART(guid1)), uint32(flag), spellid, uint32(GUID_LOPART(guid2)) );
if (!pet)
{
@ -98,7 +98,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
case COMMAND_ATTACK: //spellid=1792 //ATTACK
{
const uint64& selguid = _player->GetSelection();
Unit *TargetUnit = ObjectAccessor::GetUnit(*_player, selguid);
Unit *TargetUnit = _player->GetMap()->GetUnit(selguid);
if(!TargetUnit)
return;
@ -174,7 +174,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
return;
if(guid2)
unit_target = ObjectAccessor::GetUnit(*_player,guid2);
unit_target = _player->GetMap()->GetUnit(guid2);
// do not cast unknown spells
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid );
@ -286,7 +286,7 @@ void WorldSession::HandlePetNameQuery( WorldPacket & recv_data )
void WorldSession::SendPetNameQuery( uint64 petguid, uint32 petnumber)
{
Creature* pet = _player->GetMap()->GetCreatureOrPetOrVehicle(petguid);
Creature* pet = _player->GetMap()->GetAnyTypeCreature(petguid);
if(!pet || !pet->GetCharmInfo() || pet->GetCharmInfo()->GetPetNumber() != petnumber)
return;
@ -318,7 +318,7 @@ void WorldSession::HandlePetSetAction( WorldPacket & recv_data )
recv_data >> petguid;
Creature* pet = _player->GetMap()->GetCreatureOrPetOrVehicle(petguid);
Creature* pet = _player->GetMap()->GetAnyTypeCreature(petguid);
if(!pet || (pet != _player->GetPet() && pet != _player->GetCharm()))
{
@ -506,7 +506,7 @@ void WorldSession::HandlePetAbandon( WorldPacket & recv_data )
return;
// pet/charmed
if (Creature* pet = _player->GetMap()->GetCreatureOrPetOrVehicle(guid))
if (Creature* pet = _player->GetMap()->GetAnyTypeCreature(guid))
{
if(pet->isPet())
{
@ -563,7 +563,7 @@ void WorldSession::HandlePetSpellAutocastOpcode( WorldPacket& recvPacket )
if(!_player->GetPet() && !_player->GetCharm())
return;
Creature* pet = _player->GetMap()->GetCreatureOrPetOrVehicle(guid);
Creature* pet = _player->GetMap()->GetAnyTypeCreature(guid);
if(!pet || (pet != _player->GetPet() && pet != _player->GetCharm()))
{
@ -607,7 +607,7 @@ void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket )
if (!_player->GetPet() && !_player->GetCharm())
return;
Creature* pet = _player->GetMap()->GetCreatureOrPetOrVehicle(guid);
Creature* pet = _player->GetMap()->GetAnyTypeCreature(guid);
if (!pet || (pet != _player->GetPet() && pet!= _player->GetCharm()))
{

View file

@ -2240,7 +2240,7 @@ Creature* Player::GetNPCIfCanInteractWith(ObjectGuid guid, uint32 npcflagmask)
return NULL;
// exist (we need look pets also for some interaction (quest/etc)
Creature *unit = GetMap()->GetCreatureOrPetOrVehicle(guid);
Creature *unit = GetMap()->GetAnyTypeCreature(guid);
if (!unit)
return NULL;
@ -13066,7 +13066,7 @@ void Player::PrepareQuestMenu( uint64 guid )
QuestRelations* pObjectQIR;
// pets also can have quests
if (Creature *pCreature = GetMap()->GetCreatureOrPetOrVehicle(guid))
if (Creature *pCreature = GetMap()->GetAnyTypeCreature(guid))
{
pObject = (Object*)pCreature;
pObjectQR = &sObjectMgr.mCreatureQuestRelations;
@ -13160,7 +13160,7 @@ void Player::SendPreparedQuest(uint64 guid)
std::string title = "";
// need pet case for some quests
if (Creature *pCreature = GetMap()->GetCreatureOrPetOrVehicle(guid))
if (Creature *pCreature = GetMap()->GetAnyTypeCreature(guid))
{
uint32 textid = GetGossipTextId(pCreature);
@ -13233,7 +13233,7 @@ Quest const * Player::GetNextQuest( uint64 guid, Quest const *pQuest )
QuestRelations* pObjectQR;
QuestRelations* pObjectQIR;
if (Creature *pCreature = GetMap()->GetCreatureOrPetOrVehicle(guid))
if (Creature *pCreature = GetMap()->GetAnyTypeCreature(guid))
{
pObject = (Object*)pCreature;
pObjectQR = &sObjectMgr.mCreatureQuestRelations;
@ -20035,7 +20035,7 @@ void Player::UpdateForQuestWorldObjects()
}
else if (itr->IsCreatureOrVehicle())
{
Creature *obj = GetMap()->GetCreatureOrPetOrVehicle(*itr);
Creature *obj = GetMap()->GetAnyTypeCreature(*itr);
if(!obj)
continue;

View file

@ -659,7 +659,7 @@ void WorldSession::HandleQuestgiverStatusMultipleQuery(WorldPacket& /*recvPacket
if (itr->IsCreatureOrPet())
{
// need also pet quests case support
Creature *questgiver = GetPlayer()->GetMap()->GetCreatureOrPetOrVehicle(*itr);
Creature *questgiver = GetPlayer()->GetMap()->GetAnyTypeCreature(*itr);
if (!questgiver || questgiver->IsHostileTo(_player))
continue;

View file

@ -97,7 +97,7 @@ ReactorAI::EnterEvadeMode()
return;
}
Unit* victim = ObjectAccessor::GetUnit(*m_creature, i_victimGuid );
Unit* victim = m_creature->GetMap()->GetUnit(i_victimGuid);
if (!victim)
{

View file

@ -2794,7 +2794,7 @@ void Spell::EffectJump(SpellEffectIndex eff_idx)
else if(unitTarget->getVictim())
pTarget = m_caster->getVictim();
else if(m_caster->GetTypeId() == TYPEID_PLAYER)
pTarget = ObjectAccessor::GetUnit(*m_caster, ((Player*)m_caster)->GetSelection());
pTarget = m_caster->GetMap()->GetUnit(((Player*)m_caster)->GetSelection());
o = pTarget ? pTarget->GetOrientation() : m_caster->GetOrientation();
}
@ -2863,7 +2863,7 @@ void Spell::EffectTeleportUnits(SpellEffectIndex eff_idx)
else if(unitTarget->getVictim())
pTarget = unitTarget->getVictim();
else if(unitTarget->GetTypeId() == TYPEID_PLAYER)
pTarget = ObjectAccessor::GetUnit(*unitTarget, ((Player*)unitTarget)->GetSelection());
pTarget = unitTarget->GetMap()->GetUnit(((Player*)unitTarget)->GetSelection());
// Init dest coordinates
float x = m_targets.m_destX;

View file

@ -486,7 +486,7 @@ void WorldSession::HandlePetCancelAuraOpcode( WorldPacket& recvPacket)
return;
}
Creature* pet = GetPlayer()->GetMap()->GetCreatureOrPetOrVehicle(guid);
Creature* pet = GetPlayer()->GetMap()->GetAnyTypeCreature(guid);
if(!pet)
{
@ -574,7 +574,7 @@ void WorldSession::HandleSpellClick( WorldPacket & recv_data )
if (_player->isInCombat()) // client prevent click and set different icon at combat state
return;
Creature *unit = _player->GetMap()->GetCreatureOrPetOrVehicle(guid);
Creature *unit = _player->GetMap()->GetAnyTypeCreature(guid);
if (!unit || unit->isInCombat()) // client prevent click and set different icon at combat state
return;

View file

@ -71,7 +71,7 @@ TotemAI::UpdateAI(const uint32 /*diff*/)
// SPELLMOD_RANGE not applied in this place just because nonexistent range mods for attacking totems
// pointer to appropriate target if found any
Unit* victim = i_victimGuid ? ObjectAccessor::GetUnit(*m_creature, i_victimGuid) : NULL;
Unit* victim = i_victimGuid ? m_creature->GetMap()->GetUnit(i_victimGuid) : NULL;
// Search victim if no, not attackable, or out of range, or friendly (possible in case duel end)
if( !victim ||

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10337"
#define REVISION_NR "10338"
#endif // __REVISION_NR_H__