aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormegamage <none@none>2009-02-16 20:10:04 -0600
committermegamage <none@none>2009-02-16 20:10:04 -0600
commit319f70fb7612f2b25943b7f823da16eb80cde1a3 (patch)
tree2786d783dd4a746ac06c2dac6daecf1558253e9d /src
parent0a5b8f78f5aeabb0dac9b5d35e8685f62ac1d3e0 (diff)
[7283] Use map for trainer spells for fast find data by spell id. Author: zhenya
--HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/Creature.cpp13
-rw-r--r--src/game/Creature.h13
-rw-r--r--src/game/NPCHandler.cpp4
-rw-r--r--src/game/ObjectMgr.cpp34
-rw-r--r--src/shared/revision_nr.h2
5 files changed, 31 insertions, 35 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index d9cd7b6a0c8..eeee530bae1 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -51,18 +51,11 @@
// apply implementation of the singletons
#include "Policies/SingletonImp.h"
-void TrainerSpellData::Clear()
-{
- for (TrainerSpellList::iterator itr = spellList.begin(); itr != spellList.end(); ++itr)
- delete (*itr);
- spellList.clear();
-}
-
TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const
{
- for(TrainerSpellList::const_iterator itr = spellList.begin(); itr != spellList.end(); ++itr)
- if((*itr)->spell == spell_id)
- return *itr;
+ TrainerSpellMap::const_iterator itr = spellList.find(spell_id);
+ if (itr != spellList.end())
+ return &itr->second;
return NULL;
}
diff --git a/src/game/Creature.h b/src/game/Creature.h
index e79164bfed6..d218e2dcd93 100644
--- a/src/game/Creature.h
+++ b/src/game/Creature.h
@@ -368,6 +368,12 @@ typedef std::list<VendorItemCount> VendorItemCounts;
struct TrainerSpell
{
+ TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0), learnedSpell(0) {}
+
+ TrainerSpell(uint32 _spell, uint32 _spellCost, uint32 _reqSkill, uint32 _reqSkillValue, uint32 _reqLevel, uint32 _learnedspell)
+ : spell(_spell), spellCost(_spellCost), reqSkill(_reqSkill), reqSkillValue(_reqSkillValue), reqLevel(_reqLevel), learnedSpell(_learnedspell)
+ {}
+
uint32 spell;
uint32 spellCost;
uint32 reqSkill;
@@ -379,18 +385,17 @@ struct TrainerSpell
bool IsCastable() const { return learnedSpell != spell; }
};
-typedef std::vector<TrainerSpell*> TrainerSpellList;
+typedef UNORDERED_MAP<uint32 /*spellid*/, TrainerSpell> TrainerSpellMap;
struct TrainerSpellData
{
TrainerSpellData() : trainerType(0) {}
- TrainerSpellList spellList;
+ TrainerSpellMap spellList;
uint32 trainerType; // trainer type based at trainer spells, can be different from creature_template value.
// req. for correct show non-prof. trainers like weaponmaster, allowed values 0 and 2.
-
- void Clear();
TrainerSpell const* Find(uint32 spell_id) const;
+ void Clear() { spellList.clear(); }
};
typedef std::list<GossipOption> GossipOptionList;
diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp
index 1865f90ea27..019de97db11 100644
--- a/src/game/NPCHandler.cpp
+++ b/src/game/NPCHandler.cpp
@@ -162,9 +162,9 @@ void WorldSession::SendTrainerList( uint64 guid, const std::string& strTitle )
float fDiscountMod = _player->GetReputationPriceDiscount(unit);
uint32 count = 0;
- for(TrainerSpellList::const_iterator itr = trainer_spells->spellList.begin(); itr != trainer_spells->spellList.end(); ++itr)
+ for(TrainerSpellMap::const_iterator itr = trainer_spells->spellList.begin(); itr != trainer_spells->spellList.end(); ++itr)
{
- TrainerSpell const* tSpell = *itr;
+ TrainerSpell const* tSpell = &itr->second;
if(!_player->IsSpellFitByClassAndRace(tSpell->learnedSpell))
continue;
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index b7dafe9a55a..dae60a230f1 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -7100,36 +7100,34 @@ void ObjectMgr::LoadTrainerSpell()
continue;
}
- TrainerSpell* pTrainerSpell = new TrainerSpell();
- pTrainerSpell->spell = spell;
- pTrainerSpell->spellCost = fields[2].GetUInt32();
- pTrainerSpell->reqSkill = fields[3].GetUInt32();
- pTrainerSpell->reqSkillValue = fields[4].GetUInt32();
- pTrainerSpell->reqLevel = fields[5].GetUInt32();
+ TrainerSpellData& data = m_mCacheTrainerSpellMap[entry];
+
+ if(SpellMgr::IsProfessionSpell(spell))
+ data.trainerType = 2;
+
+ TrainerSpell& trainerSpell = data.spellList[spell];
+ trainerSpell.spell = spell;
+ trainerSpell.spellCost = fields[2].GetUInt32();
+ trainerSpell.reqSkill = fields[3].GetUInt32();
+ trainerSpell.reqSkillValue = fields[4].GetUInt32();
+ trainerSpell.reqLevel = fields[5].GetUInt32();
- if(!pTrainerSpell->reqLevel)
- pTrainerSpell->reqLevel = spellinfo->spellLevel;
+ if(!trainerSpell.reqLevel)
+ trainerSpell.reqLevel = spellinfo->spellLevel;
// calculate learned spell for profession case when stored cast-spell
- pTrainerSpell->learnedSpell = spell;
+ trainerSpell.learnedSpell = spell;
for(int i = 0; i <3; ++i)
{
- if(spellinfo->Effect[i]!=SPELL_EFFECT_LEARN_SPELL)
+ if(spellinfo->Effect[i] != SPELL_EFFECT_LEARN_SPELL)
continue;
-
if(SpellMgr::IsProfessionOrRidingSpell(spellinfo->EffectTriggerSpell[i]))
{
- pTrainerSpell->learnedSpell = spellinfo->EffectTriggerSpell[i];
+ trainerSpell.learnedSpell = spellinfo->EffectTriggerSpell[i];
break;
}
}
- TrainerSpellData& data = m_mCacheTrainerSpellMap[entry];
-
- if(SpellMgr::IsProfessionSpell(spell))
- data.trainerType = 2;
-
- data.spellList.push_back(pTrainerSpell);
++count;
} while (result->NextRow());
diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h
index ffc05b9d676..e87df561a83 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 "7282"
+ #define REVISION_NR "7283"
#endif // __REVISION_NR_H__