[7835] Store structures (with size = uint32) insteed pointer to structure in PetSpellMap.

This commit is contained in:
VladimirMangos 2009-05-15 17:19:46 +04:00
parent 6aacc45ace
commit 7a7ee86f97
4 changed files with 57 additions and 68 deletions

View file

@ -58,11 +58,7 @@ m_declinedname(NULL)
Pet::~Pet()
{
if(m_uint32Values) // only for fully created Object
{
for (PetSpellMap::const_iterator i = m_spells.begin(); i != m_spells.end(); ++i)
delete i->second;
ObjectAccessor::Instance().RemoveObject(this);
}
delete m_declinedname;
}
@ -1132,19 +1128,32 @@ void Pet::_LoadSpells()
void Pet::_SaveSpells()
{
for (PetSpellMap::const_iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next)
for (PetSpellMap::iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next)
{
++next;
if (itr->second->type == PETSPELL_FAMILY) continue; // prevent saving family passives to DB
if (itr->second->state == PETSPELL_REMOVED || itr->second->state == PETSPELL_CHANGED)
CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first);
if (itr->second->state == PETSPELL_NEW || itr->second->state == PETSPELL_CHANGED)
CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,active) VALUES ('%u', '%u', '%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second->active);
if (itr->second->state == PETSPELL_REMOVED)
_removeSpell(itr->first);
else
itr->second->state = PETSPELL_UNCHANGED;
// prevent saving family passives to DB
if (itr->second.type == PETSPELL_FAMILY)
continue;
switch(itr->second.state)
{
case PETSPELL_REMOVED:
CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first);
m_spells.erase(itr);
continue;
case PETSPELL_CHANGED:
CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first);
CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,active) VALUES ('%u', '%u', '%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second.active);
break;
case PETSPELL_NEW:
CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,active) VALUES ('%u', '%u', '%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second.active);
break;
case PETSPELL_UNCHANGED:
continue;
}
itr->second.state = PETSPELL_UNCHANGED;
}
}
@ -1275,7 +1284,7 @@ void Pet::_SaveAuras()
}
}
bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpellType type)
bool Pet::addSpell(uint32 spell_id,uint16 active /*= ACT_DECIDE*/, PetSpellState state /*= PETSPELL_NEW*/, PetSpellType type /*= PETSPELL_NORMAL*/)
{
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id);
if (!spellInfo)
@ -1295,16 +1304,15 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
PetSpellMap::iterator itr = m_spells.find(spell_id);
if (itr != m_spells.end())
{
if (itr->second->state == PETSPELL_REMOVED)
if (itr->second.state == PETSPELL_REMOVED)
{
delete itr->second;
m_spells.erase(itr);
state = PETSPELL_CHANGED;
}
else if (state == PETSPELL_UNCHANGED && itr->second->state != PETSPELL_UNCHANGED)
else if (state == PETSPELL_UNCHANGED && itr->second.state != PETSPELL_UNCHANGED)
{
// can be in case spell loading but learned at some previous spell loading
itr->second->state = PETSPELL_UNCHANGED;
itr->second.state = PETSPELL_UNCHANGED;
if(active == ACT_ENABLED)
ToggleAutocast(spell_id, true);
@ -1319,19 +1327,19 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
uint32 oldspell_id = 0;
PetSpell *newspell = new PetSpell;
newspell->state = state;
newspell->type = type;
PetSpell newspell;
newspell.state = state;
newspell.type = type;
if(active == ACT_DECIDE) //active was not used before, so we save it's autocast/passive state here
{
if(IsPassiveSpell(spell_id))
newspell->active = ACT_PASSIVE;
newspell.active = ACT_PASSIVE;
else
newspell->active = ACT_DISABLED;
newspell.active = ACT_DISABLED;
}
else
newspell->active = active;
newspell.active = active;
// talent: unlearn all other talent ranks (high and low)
if(TalentSpellPos const* talentPos = GetTalentSpellPos(spell_id))
@ -1356,13 +1364,13 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
{
for (PetSpellMap::const_iterator itr2 = m_spells.begin(); itr2 != m_spells.end(); ++itr2)
{
if(itr2->second->state == PETSPELL_REMOVED) continue;
if(itr2->second.state == PETSPELL_REMOVED) continue;
if(spellmgr.GetFirstSpellInChain(itr2->first) == chainstart)
{
newspell->active = itr2->second->active;
newspell.active = itr2->second.active;
if(newspell->active == ACT_ENABLED)
if(newspell.active == ACT_ENABLED)
ToggleAutocast(itr2->first, false);
oldspell_id = itr2->first;
@ -1379,7 +1387,7 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
else if(state == PETSPELL_NEW)
m_charmInfo->AddSpellToAB(oldspell_id, spell_id);
if(newspell->active == ACT_ENABLED)
if(newspell.active == ACT_ENABLED)
ToggleAutocast(spell_id, true);
uint32 talentCost = GetTalentSpellCost(spell_id);
@ -1455,16 +1463,13 @@ bool Pet::removeSpell(uint32 spell_id)
if (itr == m_spells.end())
return false;
if(itr->second->state == PETSPELL_REMOVED)
if(itr->second.state == PETSPELL_REMOVED)
return false;
if(itr->second->state == PETSPELL_NEW)
{
delete itr->second;
if(itr->second.state == PETSPELL_NEW)
m_spells.erase(itr);
}
else
itr->second->state = PETSPELL_REMOVED;
itr->second.state = PETSPELL_REMOVED;
RemoveAurasDueToSpell(spell_id);
@ -1483,24 +1488,9 @@ bool Pet::removeSpell(uint32 spell_id)
return true;
}
bool Pet::_removeSpell(uint32 spell_id)
{
PetSpellMap::iterator itr = m_spells.find(spell_id);
if (itr != m_spells.end())
{
delete itr->second;
m_spells.erase(itr);
return true;
}
return false;
}
void Pet::InitPetCreateSpells()
{
m_charmInfo->InitPetActionBar();
for (PetSpellMap::const_iterator i = m_spells.begin(); i != m_spells.end(); ++i)
delete i->second;
m_spells.clear();
uint32 petspellid;
@ -1619,7 +1609,7 @@ bool Pet::resetTalents(bool no_cost)
{
for(PetSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end();)
{
if(itr->second->state == PETSPELL_REMOVED)
if(itr->second.state == PETSPELL_REMOVED)
{
++itr;
continue;
@ -1698,7 +1688,7 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply)
if(IsPassiveSpell(spellid))
return;
PetSpellMap::const_iterator itr = m_spells.find(spellid);
PetSpellMap::iterator itr = m_spells.find(spellid);
int i;
@ -1711,11 +1701,11 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply)
{
m_autospells.push_back(spellid);
if(itr->second->active != ACT_ENABLED)
if(itr->second.active != ACT_ENABLED)
{
itr->second->active = ACT_ENABLED;
if(itr->second->state != PETSPELL_NEW)
itr->second->state = PETSPELL_CHANGED;
itr->second.active = ACT_ENABLED;
if(itr->second.state != PETSPELL_NEW)
itr->second.state = PETSPELL_CHANGED;
}
}
}
@ -1728,11 +1718,11 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply)
if (i < m_autospells.size())
{
m_autospells.erase(itr2);
if(itr->second->active != ACT_DISABLED)
if(itr->second.active != ACT_DISABLED)
{
itr->second->active = ACT_DISABLED;
if(itr->second->state != PETSPELL_NEW)
itr->second->state = PETSPELL_CHANGED;
itr->second.active = ACT_DISABLED;
if(itr->second.state != PETSPELL_NEW)
itr->second.state = PETSPELL_CHANGED;
}
}
}
@ -1784,7 +1774,7 @@ bool Pet::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint3
bool Pet::HasSpell(uint32 spell) const
{
PetSpellMap::const_iterator itr = m_spells.find(spell);
return (itr != m_spells.end() && itr->second->state != PETSPELL_REMOVED );
return (itr != m_spells.end() && itr->second.state != PETSPELL_REMOVED );
}
// Get all passive spells in our skill line