Skip to content

Commit

Permalink
[10385] Remove Unit::GetUnit and update it callers.
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirMangos committed Aug 20, 2010
1 parent 5648fa6 commit 41808eb
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 50 deletions.
30 changes: 16 additions & 14 deletions src/game/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ VendorItem const* VendorItemData::FindItemCostPair(uint32 item_id, uint32 extend

bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
{
if(Unit* victim = Unit::GetUnit(m_owner, m_victim))
if (Unit* victim = m_owner.GetMap()->GetUnit(m_victimGuid))
{
while (!m_assistants.empty())
while (!m_assistantGuids.empty())
{
Creature* assistant = (Creature*)Unit::GetUnit(m_owner, *m_assistants.begin());
m_assistants.pop_front();
Creature* assistant = m_owner.GetMap()->GetAnyTypeCreature(*m_assistantGuids.rbegin());
m_assistantGuids.pop_back();

if (assistant && assistant->CanAssistTo(&m_owner, victim))
{
Expand All @@ -102,6 +102,14 @@ bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
return true;
}

AssistDelayEvent::AssistDelayEvent( ObjectGuid victim, Unit& owner, std::list<Creature*> const& assistants ) : BasicEvent(), m_victimGuid(victim), m_owner(owner)
{
// Pushing guids because in delay can happen some creature gets despawned => invalid pointer
m_assistantGuids.reserve(assistants.size());
for (std::list<Creature*>::const_iterator itr = assistants.begin(); itr != assistants.end(); ++itr)
m_assistantGuids.push_back((*itr)->GetObjectGuid());
}

bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
{
m_owner.ForcedDespawn();
Expand Down Expand Up @@ -1663,13 +1671,7 @@ void Creature::CallAssistance()

if (!assistList.empty())
{
AssistDelayEvent *e = new AssistDelayEvent(getVictim()->GetGUID(), *this);
while (!assistList.empty())
{
// Pushing guids because in delay can happen some creature gets despawned => invalid pointer
e->AddAssistant((*assistList.begin())->GetGUID());
assistList.pop_front();
}
AssistDelayEvent *e = new AssistDelayEvent(getVictim()->GetObjectGuid(), *this, assistList);
m_Events.AddEvent(e, m_Events.CalculateTime(sWorld.getConfig(CONFIG_UINT32_CREATURE_FAMILY_ASSISTANCE_DELAY)));
}
}
Expand Down Expand Up @@ -1945,17 +1947,17 @@ Unit* Creature::SelectAttackingTarget(AttackingTarget target, uint32 position) c
case ATTACKING_TARGET_RANDOM:
{
advance(i, position + (rand() % (threatlist.size() - position)));
return Unit::GetUnit(*this, (*i)->getUnitGuid());
return GetMap()->GetUnit((*i)->getUnitGuid());
}
case ATTACKING_TARGET_TOPAGGRO:
{
advance(i, position);
return Unit::GetUnit(*this, (*i)->getUnitGuid());
return GetMap()->GetUnit((*i)->getUnitGuid());
}
case ATTACKING_TARGET_BOTTOMAGGRO:
{
advance(r, position);
return Unit::GetUnit(*this, (*r)->getUnitGuid());
return GetMap()->GetUnit((*r)->getUnitGuid());
}
// TODO: implement these
//case ATTACKING_TARGET_RANDOM_PLAYER:
Expand Down
9 changes: 4 additions & 5 deletions src/game/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,16 +703,15 @@ class MANGOS_DLL_SPEC Creature : public Unit
class AssistDelayEvent : public BasicEvent
{
public:
AssistDelayEvent(const uint64& victim, Unit& owner) : BasicEvent(), m_victim(victim), m_owner(owner) { }
AssistDelayEvent(ObjectGuid victim, Unit& owner, std::list<Creature*> const& assistants);

bool Execute(uint64 e_time, uint32 p_time);
void AddAssistant(const uint64& guid) { m_assistants.push_back(guid); }
private:
AssistDelayEvent();

uint64 m_victim;
std::list<uint64> m_assistants;
Unit& m_owner;
ObjectGuid m_victimGuid;
std::vector<ObjectGuid> m_assistantGuids;
Unit& m_owner;
};

class ForcedDespawnDelayEvent : public BasicEvent
Expand Down
13 changes: 4 additions & 9 deletions src/game/CreatureEventAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
{
ThreatList const& threatList = m_creature->getThreatManager().getThreatList();
for (ThreatList::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
if(Unit* Temp = Unit::GetUnit(*m_creature,(*i)->getUnitGuid()))
if(Unit* Temp = m_creature->GetMap()->GetUnit((*i)->getUnitGuid()))
m_creature->getThreatManager().modifyThreatPercent(Temp, action.threat_all_pct.percent);
break;
}
Expand Down Expand Up @@ -652,19 +652,14 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
break;
case ACTION_T_QUEST_EVENT_ALL:
if (pActionInvoker && pActionInvoker->GetTypeId() == TYPEID_PLAYER)
{
if (Unit* Temp = Unit::GetUnit(*m_creature,pActionInvoker->GetGUID()))
if (Temp->GetTypeId() == TYPEID_PLAYER)
((Player*)Temp)->GroupEventHappens(action.quest_event_all.questId,m_creature);
}
((Player*)pActionInvoker)->GroupEventHappens(action.quest_event_all.questId,m_creature);
break;
case ACTION_T_CAST_EVENT_ALL:
{
ThreatList const& threatList = m_creature->getThreatManager().getThreatList();
for (ThreatList::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
if (Unit* Temp = Unit::GetUnit(*m_creature,(*i)->getUnitGuid()))
if (Temp->GetTypeId() == TYPEID_PLAYER)
((Player*)Temp)->CastedCreatureOrGO(action.cast_event_all.creatureId, m_creature->GetObjectGuid(), action.cast_event_all.spellId);
if (Player* temp = m_creature->GetMap()->GetPlayer((*i)->getUnitGuid()))
temp->CastedCreatureOrGO(action.cast_event_all.creatureId, m_creature->GetObjectGuid(), action.cast_event_all.spellId);
break;
}
case ACTION_T_REMOVEAURASFROMSPELL:
Expand Down
5 changes: 2 additions & 3 deletions src/game/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4336,16 +4336,15 @@ SpellCastResult Spell::CheckCast(bool strict)
}
else if (m_caster == target)
{

if (m_caster->GetTypeId() == TYPEID_PLAYER) // Target - is player caster
if (m_caster->GetTypeId() == TYPEID_PLAYER && m_caster->IsInWorld())
{
// Additional check for some spells
// If 0 spell effect empty - client not send target data (need use selection)
// TODO: check it on next client version
if (m_targets.m_targetMask == TARGET_FLAG_SELF &&
m_spellInfo->EffectImplicitTargetA[EFFECT_INDEX_1] == TARGET_CHAIN_DAMAGE)
{
if (target = m_caster->GetUnit(*m_caster, ((Player *)m_caster)->GetSelection()))
if (target = m_caster->GetMap()->GetUnit(((Player *)m_caster)->GetSelection()))
m_targets.setUnitTarget(target);
else
return SPELL_FAILED_BAD_TARGETS;
Expand Down
20 changes: 8 additions & 12 deletions src/game/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8643,11 +8643,6 @@ void Unit::ApplyDiminishingAura( DiminishingGroup group, bool apply )
}
}

Unit* Unit::GetUnit(WorldObject const& object, uint64 guid)
{
return ObjectAccessor::GetUnit(object,guid);
}

bool Unit::isVisibleForInState( Player const* u, WorldObject const* viewPoint, bool inVisibleList ) const
{
return isVisibleForOrDetect(u, viewPoint, false, inVisibleList, false);
Expand Down Expand Up @@ -9664,15 +9659,15 @@ void Unit::SetFeared(bool apply, uint64 const& casterGUID, uint32 spellID, uint3
{
if( apply )
{
if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING))
if (HasAuraType(SPELL_AURA_PREVENTS_FLEEING))
return;

SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);

GetMotionMaster()->MovementExpired(false);
CastStop(GetGUID() == casterGUID ? spellID : 0);

Unit* caster = ObjectAccessor::GetUnit(*this,casterGUID);
Unit* caster = IsInWorld() ? GetMap()->GetUnit(casterGUID) : NULL;

GetMotionMaster()->MoveFleeing(caster, time); // caster==NULL processed in MoveFleeing
}
Expand All @@ -9682,18 +9677,19 @@ void Unit::SetFeared(bool apply, uint64 const& casterGUID, uint32 spellID, uint3

GetMotionMaster()->MovementExpired(false);

if( GetTypeId() != TYPEID_PLAYER && isAlive() )
if (GetTypeId() != TYPEID_PLAYER && isAlive())
{
Creature* c = ((Creature*)this);
// restore appropriate movement generator
if(getVictim())
if (getVictim())
GetMotionMaster()->MoveChase(getVictim());
else
GetMotionMaster()->Initialize();

// attack caster if can
Unit* caster = Unit::GetUnit(*this, casterGUID);
if(caster && ((Creature*)this)->AI())
((Creature*)this)->AI()->AttackedBy(caster);
if (Unit* caster = IsInWorld() ? GetMap()->GetUnit(casterGUID) : NULL)
if (c->AI())
c->AI()->AttackedBy(caster);
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/game/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,6 @@ class MANGOS_DLL_SPEC Unit : public WorldObject

void addFollower(FollowerReference* pRef) { m_FollowingRefManager.insertFirst(pRef); }
void removeFollower(FollowerReference* /*pRef*/ ) { /* nothing to do yet */ }
static Unit* GetUnit(WorldObject const& object, uint64 guid);

MotionMaster* GetMotionMaster() { return &i_motionMaster; }

Expand Down Expand Up @@ -1973,13 +1972,13 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
template<typename Func>
void Unit::CallForAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms)
{
if(Pet* pet = GetPet())
if (Pet* pet = GetPet())
func(pet);

if (withGuardians)
{
for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
if(Unit* guardian = Unit::GetUnit(*this,*itr))
if (Pet* guardian = GetMap()->GetPet(*itr))
func(guardian);
}

Expand All @@ -1991,7 +1990,7 @@ void Unit::CallForAllControlledUnits(Func const& func, bool withTotems, bool wit
}

if (withCharms)
if(Unit* charm = GetCharm())
if (Unit* charm = GetCharm())
func(charm);
}

Expand All @@ -2006,7 +2005,7 @@ bool Unit::CheckAllControlledUnits(Func const& func, bool withTotems, bool withG
if (withGuardians)
{
for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
if (Unit const* guardian = Unit::GetUnit(*this,*itr))
if (Pet const* guardian = GetMap()->GetPet(*itr))
if (func(guardian))
return true;

Expand All @@ -2021,7 +2020,7 @@ bool Unit::CheckAllControlledUnits(Func const& func, bool withTotems, bool withG
}

if (withCharms)
if(Unit const* charm = GetCharm())
if (Unit const* charm = GetCharm())
if (func(charm))
return true;

Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10384"
#define REVISION_NR "10385"
#endif // __REVISION_NR_H__

1 comment on commit 41808eb

@rsa
Copy link
Contributor

@rsa rsa commented on 41808eb Aug 20, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't compiled on GNU C. Required
"#include "MapManager.h""
in Unit.h

Please sign in to comment.