diff options
-rw-r--r-- | src/game/Pet.cpp | 119 | ||||
-rw-r--r-- | src/game/Pet.h | 8 | ||||
-rw-r--r-- | src/game/Player.cpp | 4 |
3 files changed, 57 insertions, 74 deletions
diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 72a4ef5be07..32acbf29381 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -58,15 +58,6 @@ m_declinedname(NULL), m_owner(owner) Pet::~Pet() { - if(m_uint32Values) // only for fully created Object - { - //if(GetOwnerGUID()) - // sLog.outCrash("Pet %u is deconstructed but it still has owner guid", GetEntry()); - - for (PetSpellMap::const_iterator i = m_spells.begin(); i != m_spells.end(); ++i) - delete i->second; - } - delete m_declinedname; } @@ -1114,19 +1105,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; } } @@ -1223,7 +1227,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) @@ -1247,16 +1251,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); @@ -1271,19 +1274,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)) @@ -1308,13 +1311,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; @@ -1331,7 +1334,7 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell else if(state == PETSPELL_NEW) m_charmInfo->AddSpellToAB(oldspell_id, spell_id, (ActiveStates)active); - if(newspell->active == ACT_ENABLED) + if(newspell.active == ACT_ENABLED) ToggleAutocast(spell_id, true); uint32 talentCost = GetTalentSpellCost(spell_id); @@ -1396,16 +1399,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); @@ -1424,24 +1424,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; @@ -1561,7 +1546,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; @@ -1641,7 +1626,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); if(itr == m_spells.end()) return; @@ -1656,11 +1641,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; } } } @@ -1673,11 +1658,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; } } } @@ -1726,7 +1711,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 e0cf9e49a63..63ad3979fe5 100644 --- a/src/game/Pet.h +++ b/src/game/Pet.h @@ -72,8 +72,8 @@ struct PetSpell { uint16 active; - PetSpellState state : 16; - PetSpellType type : 16; + PetSpellState state : 8; + PetSpellType type : 8; }; enum ActionFeedback @@ -113,7 +113,7 @@ enum PetNameInvalidReason PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16 }; -typedef UNORDERED_MAP<uint32, PetSpell*> PetSpellMap; +typedef UNORDERED_MAP<uint32, PetSpell> PetSpellMap; typedef std::map<uint32,uint32> TeachSpellMap; typedef std::vector<uint32> AutoSpellList; @@ -205,8 +205,6 @@ class Pet : public Guardian void learnLevelupSpells(); bool unlearnSpell(uint32 spell_id); bool removeSpell(uint32 spell_id); - bool _removeSpell(uint32 spell_id); - void _resetSpells(); PetSpellMap m_spells; TeachSpellMap m_teachspells; diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 548ef84ae7b..349a1947c79 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -16814,11 +16814,11 @@ void Player::PetSpellInitialize() // spells loop for (PetSpellMap::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; } } |