diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 4579193a7..e8b5bb04e 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -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 diff --git a/src/game/Pet.h b/src/game/Pet.h index 791851cd8..07e1036ce 100644 --- a/src/game/Pet.h +++ b/src/game/Pet.h @@ -71,8 +71,8 @@ struct PetSpell { uint16 active; - PetSpellState state : 16; - PetSpellType type : 16; + PetSpellState state : 8; + PetSpellType type : 8; }; enum ActionFeedback @@ -106,7 +106,7 @@ enum PetNameInvalidReason PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16 }; -typedef UNORDERED_MAP PetSpellMap; +typedef UNORDERED_MAP PetSpellMap; typedef std::map TeachSpellMap; typedef std::vector AutoSpellList; @@ -202,7 +202,6 @@ class Pet : public Creature void learnLevelupSpells(); bool unlearnSpell(uint32 spell_id); bool removeSpell(uint32 spell_id); - bool _removeSpell(uint32 spell_id); PetSpellMap m_spells; TeachSpellMap m_teachspells; diff --git a/src/game/Player.cpp b/src/game/Player.cpp index fd9b6d491..aba7012ab 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -16397,11 +16397,11 @@ void Player::PetSpellInitialize() // spells loop for (PetSpellMap::const_iterator itr = pet->m_spells.begin(); itr != pet->m_spells.end(); ++itr) { - if(itr->second->state == PETSPELL_REMOVED) + if(itr->second.state == PETSPELL_REMOVED) continue; data << uint16(itr->first); - data << uint16(itr->second->active); // pet spell active state isn't boolean + data << uint16(itr->second.active); // pet spell active state isn't boolean ++addlist; } } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index b7c7183d5..13bd699da 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7834" + #define REVISION_NR "7835" #endif // __REVISION_NR_H__