Skip to content

Commit

Permalink
[11293] Cleanups in spell target lists
Browse files Browse the repository at this point in the history
  • Loading branch information
zergtmn committed Mar 27, 2011
1 parent 84358c5 commit 0b25669
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 71 deletions.
124 changes: 62 additions & 62 deletions src/game/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ void Spell::CleanupTargetList()

void Spell::AddUnitTarget(Unit* pVictim, SpellEffectIndex effIndex)
{
if( m_spellInfo->Effect[effIndex] == 0 )
if (m_spellInfo->Effect[effIndex] == 0)
return;

// Check for effect immune skip if immuned
Expand All @@ -811,7 +811,7 @@ void Spell::AddUnitTarget(Unit* pVictim, SpellEffectIndex effIndex)
ObjectGuid targetGUID = pVictim->GetObjectGuid();

// Lookup target in already in list
for(std::list<TargetInfo>::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if (targetGUID == ihit->targetGUID) // Found in list
{
Expand Down Expand Up @@ -879,13 +879,13 @@ void Spell::AddUnitTarget(uint64 unitGUID, SpellEffectIndex effIndex)

void Spell::AddGOTarget(GameObject* pVictim, SpellEffectIndex effIndex)
{
if( m_spellInfo->Effect[effIndex] == 0 )
if (m_spellInfo->Effect[effIndex] == 0)
return;

ObjectGuid targetGUID = pVictim->GetObjectGuid();

// Lookup target in already in list
for(std::list<GOTargetInfo>::iterator ihit = m_UniqueGOTargetInfo.begin(); ihit != m_UniqueGOTargetInfo.end(); ++ihit)
for(GOTargetList::iterator ihit = m_UniqueGOTargetInfo.begin(); ihit != m_UniqueGOTargetInfo.end(); ++ihit)
{
if (targetGUID == ihit->targetGUID) // Found in list
{
Expand Down Expand Up @@ -931,11 +931,11 @@ void Spell::AddGOTarget(uint64 goGUID, SpellEffectIndex effIndex)

void Spell::AddItemTarget(Item* pitem, SpellEffectIndex effIndex)
{
if( m_spellInfo->Effect[effIndex] == 0 )
if (m_spellInfo->Effect[effIndex] == 0)
return;

// Lookup target in already in list
for(std::list<ItemTargetInfo>::iterator ihit = m_UniqueItemInfo.begin(); ihit != m_UniqueItemInfo.end(); ++ihit)
for(ItemTargetList::iterator ihit = m_UniqueItemInfo.begin(); ihit != m_UniqueItemInfo.end(); ++ihit)
{
if (pitem == ihit->item) // Found in list
{
Expand Down Expand Up @@ -1416,9 +1416,9 @@ bool Spell::IsAliveUnitPresentInTargetList()

uint8 needAliveTargetMask = m_needAliveTargetMask;

for(std::list<TargetInfo>::const_iterator ihit= m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if( ihit->missCondition == SPELL_MISS_NONE && (needAliveTargetMask & ihit->effectMask) )
if (ihit->missCondition == SPELL_MISS_NONE && (needAliveTargetMask & ihit->effectMask))
{
Unit *unit = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID);

Expand Down Expand Up @@ -2839,12 +2839,12 @@ void Spell::cancel()

case SPELL_STATE_CASTING:
{
for(std::list<TargetInfo>::const_iterator ihit= m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if( ihit->missCondition == SPELL_MISS_NONE )
if (ihit->missCondition == SPELL_MISS_NONE)
{
Unit* unit = m_caster->GetObjectGuid() == (*ihit).targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID);
if( unit && unit->isAlive() )
if (unit && unit->isAlive())
unit->RemoveAurasByCasterSpell(m_spellInfo->Id, m_caster->GetGUID());
}
}
Expand Down Expand Up @@ -3103,7 +3103,7 @@ void Spell::cast(bool skipCheck)
TakeCastItem();

// fill initial spell damage from caster for delayed casted spells
for(std::list<TargetInfo>::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
HandleDelayedSpellLaunch(&(*ihit));

// Okay, maps created, now prepare flags
Expand Down Expand Up @@ -3140,10 +3140,10 @@ void Spell::handle_immediate()
// process immediate effects (items, ground, etc.) also initialize some variables
_handle_immediate_phase();

for(std::list<TargetInfo>::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
DoAllEffectOnTarget(&(*ihit));

for(std::list<GOTargetInfo>::iterator ihit = m_UniqueGOTargetInfo.begin(); ihit != m_UniqueGOTargetInfo.end(); ++ihit)
for(GOTargetList::iterator ihit = m_UniqueGOTargetInfo.begin(); ihit != m_UniqueGOTargetInfo.end(); ++ihit)
DoAllEffectOnTarget(&(*ihit));

// spell is finished, perform some last features of the spell here
Expand All @@ -3167,25 +3167,25 @@ uint64 Spell::handle_delayed(uint64 t_offset)
}

// now recheck units targeting correctness (need before any effects apply to prevent adding immunity at first effect not allow apply second spell effect and similar cases)
for(std::list<TargetInfo>::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if (ihit->processed == false)
if (!ihit->processed)
{
if ( ihit->timeDelay <= t_offset )
if (ihit->timeDelay <= t_offset)
DoAllEffectOnTarget(&(*ihit));
else if( next_time == 0 || ihit->timeDelay < next_time )
else if (next_time == 0 || ihit->timeDelay < next_time)
next_time = ihit->timeDelay;
}
}

// now recheck gameobject targeting correctness
for(std::list<GOTargetInfo>::iterator ighit = m_UniqueGOTargetInfo.begin(); ighit != m_UniqueGOTargetInfo.end(); ++ighit)
for(GOTargetList::iterator ighit = m_UniqueGOTargetInfo.begin(); ighit != m_UniqueGOTargetInfo.end(); ++ighit)
{
if (ighit->processed == false)
if (!ighit->processed)
{
if ( ighit->timeDelay <= t_offset )
if (ighit->timeDelay <= t_offset)
DoAllEffectOnTarget(&(*ighit));
else if( next_time == 0 || ighit->timeDelay < next_time )
else if (next_time == 0 || ighit->timeDelay < next_time)
next_time = ighit->timeDelay;
}
}
Expand Down Expand Up @@ -3235,7 +3235,7 @@ void Spell::_handle_immediate_phase()
m_diminishGroup = DIMINISHING_NONE;

// process items
for(std::list<ItemTargetInfo>::iterator ihit = m_UniqueItemInfo.begin(); ihit != m_UniqueItemInfo.end(); ++ihit)
for(ItemTargetList::iterator ihit = m_UniqueItemInfo.begin(); ihit != m_UniqueItemInfo.end(); ++ihit)
DoAllEffectOnTarget(&(*ihit));

// process ground
Expand Down Expand Up @@ -3358,24 +3358,24 @@ void Spell::update(uint32 difftime)
{
if ( Player* p = m_caster->GetCharmerOrOwnerPlayerOrPlayerItself() )
{
for(std::list<TargetInfo>::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
TargetInfo* target = &*ihit;
if(!target->targetGUID.IsCreature())
TargetInfo const& target = *ihit;
if (!target.targetGUID.IsCreature())
continue;

Unit* unit = m_caster->GetObjectGuid() == target->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, target->targetGUID);
Unit* unit = m_caster->GetObjectGuid() == target.targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, target.targetGUID);
if (unit == NULL)
continue;

p->RewardPlayerAndGroupAtCast(unit, m_spellInfo->Id);
}

for(std::list<GOTargetInfo>::iterator ihit = m_UniqueGOTargetInfo.begin(); ihit != m_UniqueGOTargetInfo.end(); ++ihit)
for(GOTargetList::const_iterator ihit = m_UniqueGOTargetInfo.begin(); ihit != m_UniqueGOTargetInfo.end(); ++ihit)
{
GOTargetInfo* target = &*ihit;
GOTargetInfo const& target = *ihit;

GameObject* go = m_caster->GetMap()->GetGameObject(target->targetGUID);
GameObject* go = m_caster->GetMap()->GetGameObject(target.targetGUID);
if(!go)
continue;

Expand Down Expand Up @@ -3417,9 +3417,9 @@ void Spell::finish(bool ok)
{
if (!(*i)->isAffectedOnSpell(m_spellInfo))
continue;
for(std::list<TargetInfo>::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if( ihit->missCondition == SPELL_MISS_NONE )
if (ihit->missCondition == SPELL_MISS_NONE)
{
// check m_caster->GetGUID() let load auras at login and speedup most often case
Unit *unit = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID);
Expand Down Expand Up @@ -3462,7 +3462,7 @@ void Spell::finish(bool ok)
bool needDrop = true;
if (!IsPositiveSpell(m_spellInfo->Id))
{
for(std::list<TargetInfo>::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if (ihit->missCondition != SPELL_MISS_NONE && ihit->targetGUID != m_caster->GetObjectGuid())
{
Expand Down Expand Up @@ -3691,7 +3691,7 @@ void Spell::SendSpellGo()
m_caster->SendMessageToSet(&data, true);
}

void Spell::WriteAmmoToPacket( WorldPacket * data )
void Spell::WriteAmmoToPacket(WorldPacket* data)
{
uint32 ammoInventoryType = 0;
uint32 ammoDisplayID = 0;
Expand Down Expand Up @@ -3763,47 +3763,47 @@ void Spell::WriteAmmoToPacket( WorldPacket * data )
*data << uint32(ammoInventoryType);
}

void Spell::WriteSpellGoTargets( WorldPacket * data )
void Spell::WriteSpellGoTargets(WorldPacket* data)
{
size_t count_pos = data->wpos();
*data << uint8(0); // placeholder

// This function also fill data for channeled spells:
// m_needAliveTargetMask req for stop channeling if one target die
uint32 hit = m_UniqueGOTargetInfo.size(); // Always hits on GO
uint32 hit = m_UniqueGOTargetInfo.size(); // Always hits on GO
uint32 miss = 0;
for(std::list<TargetInfo>::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)

for(TargetList::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if ((*ihit).effectMask == 0) // No effect apply - all immuned add state
if (ihit->effectMask == 0) // No effect apply - all immuned add state
{
// possibly SPELL_MISS_IMMUNE2 for this??
ihit->missCondition = SPELL_MISS_IMMUNE2;
++miss;
}
else if ((*ihit).missCondition == SPELL_MISS_NONE)
++hit;
else
++miss;
}

*data << (uint8)hit;
for(std::list<TargetInfo>::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if ((*ihit).missCondition == SPELL_MISS_NONE) // Add only hits
else if (ihit->missCondition == SPELL_MISS_NONE) // Add only hits
{
++hit;
*data << ihit->targetGUID;
m_needAliveTargetMask |=ihit->effectMask;
m_needAliveTargetMask |= ihit->effectMask;
}
else
++miss;
}

for(std::list<GOTargetInfo>::const_iterator ighit = m_UniqueGOTargetInfo.begin(); ighit != m_UniqueGOTargetInfo.end(); ++ighit)
for(GOTargetList::const_iterator ighit = m_UniqueGOTargetInfo.begin(); ighit != m_UniqueGOTargetInfo.end(); ++ighit)
*data << ighit->targetGUID; // Always hits

data->put<uint8>(count_pos, hit);

*data << (uint8)miss;
for(std::list<TargetInfo>::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if( ihit->missCondition != SPELL_MISS_NONE ) // Add only miss
if (ihit->missCondition != SPELL_MISS_NONE) // Add only miss
{
*data << ihit->targetGUID;
*data << uint8(ihit->missCondition);
if( ihit->missCondition == SPELL_MISS_REFLECT )
if (ihit->missCondition == SPELL_MISS_REFLECT)
*data << uint8(ihit->reflectResult);
}
}
Expand Down Expand Up @@ -3965,7 +3965,7 @@ void Spell::SendChannelStart(uint32 duration)
// select first not resisted target from target list for _0_ effect
if (!m_UniqueTargetInfo.empty())
{
for(std::list<TargetInfo>::const_iterator itr = m_UniqueTargetInfo.begin(); itr != m_UniqueTargetInfo.end(); ++itr)
for(TargetList::const_iterator itr = m_UniqueTargetInfo.begin(); itr != m_UniqueTargetInfo.end(); ++itr)
{
if ((itr->effectMask & (1 << EFFECT_INDEX_0)) && itr->reflectResult == SPELL_MISS_NONE &&
itr->targetGUID != m_caster->GetObjectGuid())
Expand All @@ -3977,7 +3977,7 @@ void Spell::SendChannelStart(uint32 duration)
}
else if(!m_UniqueGOTargetInfo.empty())
{
for(std::list<GOTargetInfo>::const_iterator itr = m_UniqueGOTargetInfo.begin(); itr != m_UniqueGOTargetInfo.end(); ++itr)
for(GOTargetList::const_iterator itr = m_UniqueGOTargetInfo.begin(); itr != m_UniqueGOTargetInfo.end(); ++itr)
{
if (itr->effectMask & (1 << EFFECT_INDEX_0))
{
Expand Down Expand Up @@ -4302,7 +4302,7 @@ void Spell::HandleThreatSpells()
// since 2.0.1 threat from positive effects also is distributed among all targets, so the overall caused threat is at most the defined bonus
threat /= m_UniqueTargetInfo.size();

for (std::list<TargetInfo>::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for (TargetList::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if (ihit->missCondition != SPELL_MISS_NONE)
continue;
Expand Down Expand Up @@ -5773,8 +5773,8 @@ bool Spell::CanAutoCast(Unit* target)
{
FillTargetMap();
//check if among target units, our WANTED target is as well (->only self cast spells return false)
for(std::list<TargetInfo>::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
if( ihit->targetGUID == targetguid )
for(TargetList::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
if (ihit->targetGUID == targetguid)
return true;
}
return false; //target invalid
Expand Down Expand Up @@ -6497,7 +6497,7 @@ void Spell::DelayedChannel()

DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo->Id, delaytime, m_timer);

for(std::list<TargetInfo>::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
for(TargetList::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if ((*ihit).missCondition == SPELL_MISS_NONE)
{
Expand Down Expand Up @@ -6680,15 +6680,15 @@ bool Spell::IsTriggeredSpellWithRedundentData() const

bool Spell::HaveTargetsForEffect(SpellEffectIndex effect) const
{
for(std::list<TargetInfo>::const_iterator itr = m_UniqueTargetInfo.begin(); itr != m_UniqueTargetInfo.end(); ++itr)
for(TargetList::const_iterator itr = m_UniqueTargetInfo.begin(); itr != m_UniqueTargetInfo.end(); ++itr)
if(itr->effectMask & (1 << effect))
return true;

for(std::list<GOTargetInfo>::const_iterator itr = m_UniqueGOTargetInfo.begin(); itr != m_UniqueGOTargetInfo.end(); ++itr)
for(GOTargetList::const_iterator itr = m_UniqueGOTargetInfo.begin(); itr != m_UniqueGOTargetInfo.end(); ++itr)
if(itr->effectMask & (1 << effect))
return true;

for(std::list<ItemTargetInfo>::const_iterator itr = m_UniqueItemInfo.begin(); itr != m_UniqueItemInfo.end(); ++itr)
for(ItemTargetList::const_iterator itr = m_UniqueItemInfo.begin(); itr != m_UniqueItemInfo.end(); ++itr)
if(itr->effectMask & (1 << effect))
return true;

Expand Down
15 changes: 10 additions & 5 deletions src/game/Spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ class Spell
void DoSummonTotem(SpellEffectIndex eff_idx, uint8 slot_dbc = 0);
void DoSummonCritter(SpellEffectIndex eff_idx, uint32 forceFaction = 0);

void WriteSpellGoTargets( WorldPacket * data );
void WriteAmmoToPacket( WorldPacket * data );
void WriteSpellGoTargets(WorldPacket* data);
void WriteAmmoToPacket(WorldPacket* data);

typedef std::list<Unit*> UnitList;
void FillTargetMap();
Expand Down Expand Up @@ -581,7 +581,6 @@ class Spell
uint8 effectMask:8;
bool processed:1;
};
std::list<TargetInfo> m_UniqueTargetInfo;
uint8 m_needAliveTargetMask; // Mask req. alive targets

struct GOTargetInfo
Expand All @@ -591,14 +590,20 @@ class Spell
uint8 effectMask:8;
bool processed:1;
};
std::list<GOTargetInfo> m_UniqueGOTargetInfo;

struct ItemTargetInfo
{
Item *item;
uint8 effectMask;
};
std::list<ItemTargetInfo> m_UniqueItemInfo;

typedef std::list<TargetInfo> TargetList;
typedef std::list<GOTargetInfo> GOTargetList;
typedef std::list<ItemTargetInfo> ItemTargetList;

TargetList m_UniqueTargetInfo;
GOTargetList m_UniqueGOTargetInfo;
ItemTargetList m_UniqueItemInfo;

void AddUnitTarget(Unit* target, SpellEffectIndex effIndex);
void AddUnitTarget(uint64 unitGUID, SpellEffectIndex effIndex);
Expand Down

0 comments on commit 0b25669

Please sign in to comment.