[9440] Store in plauer spell list structure instead pointer.

Just not reason in element persistanse storage as std::map
store pointer to structure with size < 16 bits.
This commit is contained in:
VladimirMangos 2010-02-23 19:07:33 +03:00
parent 528b2cf324
commit 6295275529
6 changed files with 71 additions and 80 deletions

View file

@ -515,9 +515,6 @@ Player::~Player ()
}
CleanupChannels();
for (PlayerSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr)
delete itr->second;
//all mailed items should be deleted, also all mail should be deallocated
for (PlayerMails::const_iterator itr = m_mail.begin(); itr != m_mail.end();++itr)
delete *itr;
@ -2721,10 +2718,10 @@ void Player::SendInitialSpells()
for (PlayerSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr)
{
if(itr->second->state == PLAYERSPELL_REMOVED)
if(itr->second.state == PLAYERSPELL_REMOVED)
continue;
if(!itr->second->active || itr->second->disabled)
if(!itr->second.active || itr->second.disabled)
continue;
data << uint32(itr->first);
@ -2903,33 +2900,33 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
}
// not do anything if already known in expected state
if(itr->second->state != PLAYERSPELL_REMOVED && itr->second->active == active &&
itr->second->dependent == dependent && itr->second->disabled == disabled)
if(itr->second.state != PLAYERSPELL_REMOVED && itr->second.active == active &&
itr->second.dependent == dependent && itr->second.disabled == disabled)
{
if(!IsInWorld() && !learning) // explicitly load from DB and then exist in it already and set correctly
itr->second->state = PLAYERSPELL_UNCHANGED;
itr->second.state = PLAYERSPELL_UNCHANGED;
return false;
}
// dependent spell known as not dependent, overwrite state
if (itr->second->state != PLAYERSPELL_REMOVED && !itr->second->dependent && dependent)
if (itr->second.state != PLAYERSPELL_REMOVED && !itr->second.dependent && dependent)
{
itr->second->dependent = dependent;
if (itr->second->state != PLAYERSPELL_NEW)
itr->second->state = PLAYERSPELL_CHANGED;
itr->second.dependent = dependent;
if (itr->second.state != PLAYERSPELL_NEW)
itr->second.state = PLAYERSPELL_CHANGED;
dependent_set = true;
}
// update active state for known spell
if(itr->second->active != active && itr->second->state != PLAYERSPELL_REMOVED && !itr->second->disabled)
if(itr->second.active != active && itr->second.state != PLAYERSPELL_REMOVED && !itr->second.disabled)
{
itr->second->active = active;
itr->second.active = active;
if(!IsInWorld() && !learning && !dependent_set) // explicitly load from DB and then exist in it already and set correctly
itr->second->state = PLAYERSPELL_UNCHANGED;
else if(itr->second->state != PLAYERSPELL_NEW)
itr->second->state = PLAYERSPELL_CHANGED;
itr->second.state = PLAYERSPELL_UNCHANGED;
else if(itr->second.state != PLAYERSPELL_NEW)
itr->second.state = PLAYERSPELL_CHANGED;
if(active)
{
@ -2957,24 +2954,23 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
return active; // learn (show in spell book if active now)
}
if(itr->second->disabled != disabled && itr->second->state != PLAYERSPELL_REMOVED)
if(itr->second.disabled != disabled && itr->second.state != PLAYERSPELL_REMOVED)
{
if(itr->second->state != PLAYERSPELL_NEW)
itr->second->state = PLAYERSPELL_CHANGED;
itr->second->disabled = disabled;
if(itr->second.state != PLAYERSPELL_NEW)
itr->second.state = PLAYERSPELL_CHANGED;
itr->second.disabled = disabled;
if(disabled)
return false;
disabled_case = true;
}
else switch(itr->second->state)
else switch(itr->second.state)
{
case PLAYERSPELL_UNCHANGED: // known saved spell
return false;
case PLAYERSPELL_REMOVED: // re-learning removed not saved spell
{
delete itr->second;
m_spells.erase(itr);
state = PLAYERSPELL_CHANGED;
break; // need re-add
@ -2983,7 +2979,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
{
// can be in case spell loading but learned at some previous spell loading
if(!IsInWorld() && !learning && !dependent_set)
itr->second->state = PLAYERSPELL_UNCHANGED;
itr->second.state = PLAYERSPELL_UNCHANGED;
return false;
}
@ -3017,24 +3013,24 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
learnSpell(prev_spell,true);
}
PlayerSpell *newspell = new PlayerSpell;
newspell->state = state;
newspell->active = active;
newspell->dependent = dependent;
newspell->disabled = disabled;
PlayerSpell newspell;
newspell.state = state;
newspell.active = active;
newspell.dependent = dependent;
newspell.disabled = disabled;
// replace spells in action bars and spellbook to bigger rank if only one spell rank must be accessible
if(newspell->active && !newspell->disabled && !SpellMgr::canStackSpellRanks(spellInfo) && sSpellMgr.GetSpellRank(spellInfo->Id) != 0)
if(newspell.active && !newspell.disabled && !SpellMgr::canStackSpellRanks(spellInfo) && sSpellMgr.GetSpellRank(spellInfo->Id) != 0)
{
for( PlayerSpellMap::iterator itr2 = m_spells.begin(); itr2 != m_spells.end(); ++itr2 )
{
if(itr2->second->state == PLAYERSPELL_REMOVED) continue;
if(itr2->second.state == PLAYERSPELL_REMOVED) continue;
SpellEntry const *i_spellInfo = sSpellStore.LookupEntry(itr2->first);
if(!i_spellInfo) continue;
if( sSpellMgr.IsRankSpellDueToSpell(spellInfo,itr2->first) )
{
if(itr2->second->active)
if(itr2->second.active)
{
if(sSpellMgr.IsHighRankOfSpell(spell_id,itr2->first))
{
@ -3047,9 +3043,9 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
}
// mark old spell as disable (SMSG_SUPERCEDED_SPELL replace it in client by new)
itr2->second->active = false;
if(itr2->second->state != PLAYERSPELL_NEW)
itr2->second->state = PLAYERSPELL_CHANGED;
itr2->second.active = false;
if(itr2->second.state != PLAYERSPELL_NEW)
itr2->second.state = PLAYERSPELL_CHANGED;
superceded_old = true; // new spell replace old in action bars and spell book.
}
else if(sSpellMgr.IsHighRankOfSpell(itr2->first,spell_id))
@ -3063,9 +3059,9 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
}
// mark new spell as disable (not learned yet for client and will not learned)
newspell->active = false;
if(newspell->state != PLAYERSPELL_NEW)
newspell->state = PLAYERSPELL_CHANGED;
newspell.active = false;
if(newspell.state != PLAYERSPELL_NEW)
newspell.state = PLAYERSPELL_CHANGED;
}
}
}
@ -3075,7 +3071,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
m_spells[spell_id] = newspell;
// return false if spell disabled
if (newspell->disabled)
if (newspell.disabled)
return false;
}
@ -3210,8 +3206,8 @@ void Player::learnSpell(uint32 spell_id, bool dependent)
{
PlayerSpellMap::iterator itr = m_spells.find(spell_id);
bool disabled = (itr != m_spells.end()) ? itr->second->disabled : false;
bool active = disabled ? itr->second->active : true;
bool disabled = (itr != m_spells.end()) ? itr->second.disabled : false;
bool active = disabled ? itr->second.active : true;
bool learning = addSpell(spell_id,active,true,dependent,false);
@ -3222,7 +3218,7 @@ void Player::learnSpell(uint32 spell_id, bool dependent)
for(SpellChainMapNext::const_iterator i = nextMap.lower_bound(spell_id); i != nextMap.upper_bound(spell_id); ++i)
{
PlayerSpellMap::iterator iter = m_spells.find(i->second);
if (iter != m_spells.end() && iter->second->disabled)
if (iter != m_spells.end() && iter->second.disabled)
learnSpell(i->second,false);
}
}
@ -3242,7 +3238,7 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo
if (itr == m_spells.end())
return;
if (itr->second->state == PLAYERSPELL_REMOVED || (disabled && itr->second->disabled))
if (itr->second.state == PLAYERSPELL_REMOVED || (disabled && itr->second.disabled))
return;
// unlearn non talent higher ranks (recursive)
@ -3256,24 +3252,21 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo
if (itr == m_spells.end())
return; // already unleared
bool cur_active = itr->second->active;
bool cur_dependent = itr->second->dependent;
bool cur_active = itr->second.active;
bool cur_dependent = itr->second.dependent;
if (disabled)
{
itr->second->disabled = disabled;
if(itr->second->state != PLAYERSPELL_NEW)
itr->second->state = PLAYERSPELL_CHANGED;
itr->second.disabled = disabled;
if(itr->second.state != PLAYERSPELL_NEW)
itr->second.state = PLAYERSPELL_CHANGED;
}
else
{
if(itr->second->state == PLAYERSPELL_NEW)
{
delete itr->second;
if(itr->second.state == PLAYERSPELL_NEW)
m_spells.erase(itr);
}
else
itr->second->state = PLAYERSPELL_REMOVED;
itr->second.state = PLAYERSPELL_REMOVED;
}
RemoveAurasDueToSpell(spell_id);
@ -3390,17 +3383,17 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo
PlayerSpellMap::iterator prev_itr = m_spells.find(prev_id);
if (prev_itr != m_spells.end())
{
if (prev_itr->second->dependent != cur_dependent)
if (prev_itr->second.dependent != cur_dependent)
{
prev_itr->second->dependent = cur_dependent;
if (prev_itr->second->state != PLAYERSPELL_NEW)
prev_itr->second->state = PLAYERSPELL_CHANGED;
prev_itr->second.dependent = cur_dependent;
if (prev_itr->second.state != PLAYERSPELL_NEW)
prev_itr->second.state = PLAYERSPELL_CHANGED;
}
// now re-learn if need re-activate
if (cur_active && !prev_itr->second->active && learn_low_rank)
if (cur_active && !prev_itr->second.active && learn_low_rank)
{
if (addSpell(prev_id,true,false,prev_itr->second->dependent,prev_itr->second->disabled))
if (addSpell(prev_id,true,false,prev_itr->second.dependent,prev_itr->second.disabled))
{
// downgrade spell ranks in spellbook and action bar
WorldPacket data(SMSG_SUPERCEDED_SPELL, 4 + 4);
@ -3636,7 +3629,7 @@ bool Player::resetTalents(bool no_cost)
{
for(PlayerSpellMap::iterator itr = GetSpellMap().begin(); itr != GetSpellMap().end();)
{
if(itr->second->state == PLAYERSPELL_REMOVED || itr->second->disabled)
if(itr->second.state == PLAYERSPELL_REMOVED || itr->second.disabled)
{
++itr;
continue;
@ -3892,15 +3885,15 @@ void Player::DestroyForPlayer( Player *target, bool anim ) const
bool Player::HasSpell(uint32 spell) const
{
PlayerSpellMap::const_iterator itr = m_spells.find(spell);
return (itr != m_spells.end() && itr->second->state != PLAYERSPELL_REMOVED &&
!itr->second->disabled);
return (itr != m_spells.end() && itr->second.state != PLAYERSPELL_REMOVED &&
!itr->second.disabled);
}
bool Player::HasActiveSpell(uint32 spell) const
{
PlayerSpellMap::const_iterator itr = m_spells.find(spell);
return (itr != m_spells.end() && itr->second->state != PLAYERSPELL_REMOVED &&
itr->second->active && !itr->second->disabled);
return (itr != m_spells.end() && itr->second.state != PLAYERSPELL_REMOVED &&
itr->second.active && !itr->second.disabled);
}
TrainerSpellState Player::GetTrainerSpellState(TrainerSpell const* trainer_spell) const
@ -16654,21 +16647,18 @@ void Player::_SaveSpells()
{
for (PlayerSpellMap::iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end();)
{
if (itr->second->state == PLAYERSPELL_REMOVED || itr->second->state == PLAYERSPELL_CHANGED)
if (itr->second.state == PLAYERSPELL_REMOVED || itr->second.state == PLAYERSPELL_CHANGED)
CharacterDatabase.PExecute("DELETE FROM character_spell WHERE guid = '%u' and spell = '%u'", GetGUIDLow(), itr->first);
// add only changed/new not dependent spells
if (!itr->second->dependent && (itr->second->state == PLAYERSPELL_NEW || itr->second->state == PLAYERSPELL_CHANGED))
CharacterDatabase.PExecute("INSERT INTO character_spell (guid,spell,active,disabled) VALUES ('%u', '%u', '%u', '%u')", GetGUIDLow(), itr->first, itr->second->active ? 1 : 0,itr->second->disabled ? 1 : 0);
if (!itr->second.dependent && (itr->second.state == PLAYERSPELL_NEW || itr->second.state == PLAYERSPELL_CHANGED))
CharacterDatabase.PExecute("INSERT INTO character_spell (guid,spell,active,disabled) VALUES ('%u', '%u', '%u', '%u')", GetGUIDLow(), itr->first, itr->second.active ? 1 : 0,itr->second.disabled ? 1 : 0);
if (itr->second->state == PLAYERSPELL_REMOVED)
{
delete itr->second;
if (itr->second.state == PLAYERSPELL_REMOVED)
m_spells.erase(itr++);
}
else
{
itr->second->state = PLAYERSPELL_UNCHANGED;
itr->second.state = PLAYERSPELL_UNCHANGED;
++itr;
}
@ -17857,7 +17847,7 @@ void Player::ProhibitSpellSchool(SpellSchoolMask idSchoolMask, uint32 unTimeMs )
time_t curTime = time(NULL);
for(PlayerSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr)
{
if (itr->second->state == PLAYERSPELL_REMOVED)
if (itr->second.state == PLAYERSPELL_REMOVED)
continue;
uint32 unSpellId = itr->first;
SpellEntry const *spellInfo = sSpellStore.LookupEntry(unSpellId);
@ -19162,7 +19152,7 @@ void Player::learnQuestRewardedSpells(Quest const* quest)
// search other specialization for same prof
for(PlayerSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr)
{
if(itr->second->state == PLAYERSPELL_REMOVED || itr->first==learned_0)
if(itr->second.state == PLAYERSPELL_REMOVED || itr->first==learned_0)
continue;
SpellEntry const *itrInfo = sSpellStore.LookupEntry(itr->first);