root/trunk/src/shared/Database/DBCStores.cpp @ 2

Revision 2, 28.3 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19#include "DBCStores.h"
20//#include "DataStore.h"
21#include "Policies/SingletonImp.h"
22#include "Log.h"
23#include "ProgressBar.h"
24
25#include "DBCfmt.cpp"
26
27#include <map>
28
29typedef std::map<uint16,uint32> AreaFlagByAreaID;
30typedef std::map<uint32,uint32> AreaFlagByMapID;
31
32DBCStorage <AreaTableEntry> sAreaStore(AreaTableEntryfmt);
33static AreaFlagByAreaID sAreaFlagByAreaID;
34static AreaFlagByMapID  sAreaFlagByMapID;                   // for instances without generated *.map files
35
36DBCStorage <AreaTriggerEntry> sAreaTriggerStore(AreaTriggerEntryfmt);
37DBCStorage <BankBagSlotPricesEntry> sBankBagSlotPricesStore(BankBagSlotPricesEntryfmt);
38DBCStorage <BattlemasterListEntry> sBattlemasterListStore(BattlemasterListEntryfmt);
39DBCStorage <CharTitlesEntry> sCharTitlesStore(CharTitlesEntryfmt);
40DBCStorage <ChatChannelsEntry> sChatChannelsStore(ChatChannelsEntryfmt);
41DBCStorage <ChrClassesEntry> sChrClassesStore(ChrClassesEntryfmt);
42DBCStorage <ChrRacesEntry> sChrRacesStore(ChrRacesEntryfmt);
43DBCStorage <CreatureDisplayInfoEntry> sCreatureDisplayInfoStore(CreatureDisplayInfofmt);
44DBCStorage <CreatureFamilyEntry> sCreatureFamilyStore(CreatureFamilyfmt);
45DBCStorage <CreatureSpellDataEntry> sCreatureSpellDataStore(CreatureSpellDatafmt);
46
47DBCStorage <DurabilityQualityEntry> sDurabilityQualityStore(DurabilityQualityfmt);
48DBCStorage <DurabilityCostsEntry> sDurabilityCostsStore(DurabilityCostsfmt);
49
50DBCStorage <EmotesTextEntry> sEmotesTextStore(EmoteEntryfmt);
51
52typedef std::map<uint32,SimpleFactionsList> FactionTeamMap;
53static FactionTeamMap sFactionTeamMap;
54DBCStorage <FactionEntry> sFactionStore(FactionEntryfmt);
55DBCStorage <FactionTemplateEntry> sFactionTemplateStore(FactionTemplateEntryfmt);
56
57DBCStorage <GemPropertiesEntry> sGemPropertiesStore(GemPropertiesEntryfmt);
58
59DBCStorage <GtCombatRatingsEntry>         sGtCombatRatingsStore(GtCombatRatingsfmt);
60DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore(GtChanceToMeleeCritBasefmt);
61DBCStorage <GtChanceToMeleeCritEntry>     sGtChanceToMeleeCritStore(GtChanceToMeleeCritfmt);
62DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore(GtChanceToSpellCritBasefmt);
63DBCStorage <GtChanceToSpellCritEntry>     sGtChanceToSpellCritStore(GtChanceToSpellCritfmt);
64DBCStorage <GtOCTRegenHPEntry>            sGtOCTRegenHPStore(GtOCTRegenHPfmt);
65//DBCStorage <GtOCTRegenMPEntry>            sGtOCTRegenMPStore(GtOCTRegenMPfmt);  -- not used currently
66DBCStorage <GtRegenHPPerSptEntry>         sGtRegenHPPerSptStore(GtRegenHPPerSptfmt);
67DBCStorage <GtRegenMPPerSptEntry>         sGtRegenMPPerSptStore(GtRegenMPPerSptfmt);
68DBCStorage <ItemEntry>                    sItemStore(Itemfmt);
69//DBCStorage <ItemCondExtCostsEntry> sItemCondExtCostsStore(ItemCondExtCostsEntryfmt);
70//DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently
71DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt);
72DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore(ItemRandomPropertiesfmt);
73DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore(ItemRandomSuffixfmt);
74DBCStorage <ItemSetEntry> sItemSetStore(ItemSetEntryfmt);
75
76DBCStorage <LockEntry> sLockStore(LockEntryfmt);
77
78DBCStorage <MailTemplateEntry> sMailTemplateStore(MailTemplateEntryfmt);
79DBCStorage <MapEntry> sMapStore(MapEntryfmt);
80
81DBCStorage <QuestSortEntry> sQuestSortStore(QuestSortEntryfmt);
82
83DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt);
84
85DBCStorage <SkillLineEntry> sSkillLineStore(SkillLinefmt);
86DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore(SkillLineAbilityfmt);
87
88DBCStorage <SoundEntriesEntry> sSoundEntriesStore(SoundEntriesfmt);
89
90DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore(SpellItemEnchantmentfmt);
91DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt);
92DBCStorage <SpellEntry> sSpellStore(SpellEntryfmt);
93SpellCategoryStore sSpellCategoryStore;
94PetFamilySpellsStore sPetFamilySpellsStore;
95
96DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore(SpellCastTimefmt);
97DBCStorage <SpellDurationEntry> sSpellDurationStore(SpellDurationfmt);
98DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore(SpellFocusObjectfmt);
99DBCStorage <SpellRadiusEntry> sSpellRadiusStore(SpellRadiusfmt);
100DBCStorage <SpellRangeEntry> sSpellRangeStore(SpellRangefmt);
101DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftfmt);
102DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore(StableSlotPricesfmt);
103DBCStorage <TalentEntry> sTalentStore(TalentEntryfmt);
104TalentSpellPosMap sTalentSpellPosMap;
105DBCStorage <TalentTabEntry> sTalentTabStore(TalentTabEntryfmt);
106
107// store absolute bit position for first rank for talent inspect
108typedef std::map<uint32,uint32> TalentInspectMap;
109static TalentInspectMap sTalentPosInInspect;
110static TalentInspectMap sTalentTabSizeInInspect;
111static uint32 sTalentTabPages[12/*MAX_CLASSES*/][3];
112
113DBCStorage <TaxiNodesEntry> sTaxiNodesStore(TaxiNodesEntryfmt);
114TaxiMask sTaxiNodesMask;
115
116// DBC used only for initialization sTaxiPathSetBySource at startup.
117TaxiPathSetBySource sTaxiPathSetBySource;
118DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt);
119
120// DBC used only for initialization sTaxiPathSetBySource at startup.
121TaxiPathNodesByPath sTaxiPathNodesByPath;
122struct TaxiPathNodeEntry
123{
124    uint32    path;
125    uint32    index;
126    uint32    mapid;
127    float     x;
128    float     y;
129    float     z;
130    uint32    actionFlag;
131    uint32    delay;
132};
133static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
134
135DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt);
136
137DBCStorage <WorldMapAreaEntry>  sWorldMapAreaStore(WorldMapAreaEntryfmt);
138DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt);
139
140typedef std::list<std::string> StoreProblemList;
141
142static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, std::string filename)
143{
144    sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize);
145
146    // assert must fail after function call
147    return false;
148}
149
150template<class T>
151inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, std::string dbc_path, std::string filename)
152{
153    // compatibility format and C++ structure sizes
154    assert(DBCFile::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFile::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename));
155
156    std::string dbc_filename = dbc_path + filename;
157    if(storage.Load(dbc_filename.c_str()))
158    {
159        bar.step();
160        for(uint8 i = 0; i < MAX_LOCALE; ++i)
161        {
162            if(!(availableDbcLocales & (1 << i)))
163                continue;
164
165            std::string dbc_filename_loc = dbc_path + localeNames[i] + "/" + filename;
166            if(!storage.LoadStringsFrom(dbc_filename_loc.c_str()))
167                availableDbcLocales &= ~(1<<i);             // mark as not available for speedup next checks
168        }
169    }
170    else
171    {
172        // sort problematic dbc to (1) non compatible and (2) non-existed
173        FILE * f=fopen(dbc_filename.c_str(),"rb");
174        if(f)
175        {
176            char buf[100];
177            snprintf(buf,100," (exist, but have %d fields instead %d) Wrong client version DBC file?",storage.GetFieldCount(),strlen(storage.GetFormat()));
178            errlist.push_back(dbc_filename + buf);
179            fclose(f);
180        }
181        else
182            errlist.push_back(dbc_filename);
183    }
184}
185
186void LoadDBCStores(std::string dataPath)
187{
188    std::string dbcPath = dataPath+"dbc/";
189
190    const uint32 DBCFilesCount = 56;
191
192    barGoLink bar( DBCFilesCount );
193
194    StoreProblemList bad_dbc_files;
195    uint32 availableDbcLocales = 0xFFFFFFFF;
196
197    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaStore,                dbcPath,"AreaTable.dbc");
198
199    // must be after sAreaStore loading
200    for(uint32 i = 0; i < sAreaStore.GetNumRows(); ++i)           // areaflag numbered from 0
201    {
202        if(AreaTableEntry const* area = sAreaStore.LookupEntry(i))
203        {
204            // fill AreaId->DBC records
205            sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID),area->exploreFlag));
206
207            // fill MapId->DBC records ( skip sub zones and continents )
208            if(area->zone==0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530 )
209                sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid,area->exploreFlag));
210        }
211    }
212
213    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore,         dbcPath,"AreaTrigger.dbc");
214    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore,   dbcPath,"BankBagSlotPrices.dbc");
215    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore,    dbcPath,"BattlemasterList.dbc");
216    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore,          dbcPath,"CharTitles.dbc");
217    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore,        dbcPath,"ChatChannels.dbc");
218    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore,          dbcPath,"ChrClasses.dbc");
219    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrRacesStore,            dbcPath,"ChrRaces.dbc");
220    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureDisplayInfoStore, dbcPath,"CreatureDisplayInfo.dbc");
221    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureFamilyStore,      dbcPath,"CreatureFamily.dbc");
222    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureSpellDataStore,   dbcPath,"CreatureSpellData.dbc");
223    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityCostsStore,     dbcPath,"DurabilityCosts.dbc");
224    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityQualityStore,   dbcPath,"DurabilityQuality.dbc");
225    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesTextStore,          dbcPath,"EmotesText.dbc");
226    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionStore,             dbcPath,"Faction.dbc");
227    for (uint32 i=0;i<sFactionStore.GetNumRows(); ++i)
228    {
229        FactionEntry const * faction = sFactionStore.LookupEntry(i);
230        if (faction && faction->team)
231        {
232            SimpleFactionsList &flist = sFactionTeamMap[faction->team];
233            flist.push_back(i);
234        }
235    }
236   
237    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore,     dbcPath,"FactionTemplate.dbc");
238    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore,       dbcPath,"GemProperties.dbc");
239
240    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtCombatRatingsStore,     dbcPath,"gtCombatRatings.dbc");
241
242    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritBaseStore, dbcPath,"gtChanceToMeleeCritBase.dbc");
243    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritStore, dbcPath,"gtChanceToMeleeCrit.dbc");
244
245    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritBaseStore, dbcPath,"gtChanceToSpellCritBase.dbc");
246    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritStore, dbcPath,"gtChanceToSpellCrit.dbc");
247
248    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenHPStore,        dbcPath,"gtOCTRegenHP.dbc");
249    //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore,        dbcPath,"gtOCTRegenMP.dbc");       -- not used currently
250    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenHPPerSptStore,     dbcPath,"gtRegenHPPerSpt.dbc");
251    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenMPPerSptStore,     dbcPath,"gtRegenMPPerSpt.dbc");
252    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemStore,                dbcPath,"Item.dbc");
253    //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore,     dbcPath,"ItemDisplayInfo.dbc");     -- not used currently
254    //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore,    dbcPath,"ItemCondExtCosts.dbc");
255    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemExtendedCostStore,    dbcPath,"ItemExtendedCost.dbc");
256    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomPropertiesStore,dbcPath,"ItemRandomProperties.dbc");
257    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomSuffixStore,    dbcPath,"ItemRandomSuffix.dbc");
258    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemSetStore,             dbcPath,"ItemSet.dbc");
259    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sLockStore,                dbcPath,"Lock.dbc");
260    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMailTemplateStore,        dbcPath,"MailTemplate.dbc");
261    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapStore,                 dbcPath,"Map.dbc");
262    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sQuestSortStore,           dbcPath,"QuestSort.dbc");
263    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sRandomPropertiesPointsStore, dbcPath,"RandPropPoints.dbc");
264    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineStore,           dbcPath,"SkillLine.dbc");
265    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineAbilityStore,    dbcPath,"SkillLineAbility.dbc");
266    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSoundEntriesStore,        dbcPath,"SoundEntries.dbc");
267    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellStore,               dbcPath,"Spell.dbc");
268    for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
269    {
270        SpellEntry const * spell = sSpellStore.LookupEntry(i);
271        if(spell && spell->Category)
272            sSpellCategoryStore[spell->Category].insert(i);
273
274        // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields
275        // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view
276        #if MANGOS_ENDIAN == MANGOS_BIGENDIAN
277        std::swap(*((uint32*)(&spell->SpellFamilyFlags)),*(((uint32*)(&spell->SpellFamilyFlags))+1));
278        #endif
279    }
280
281    for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
282    {
283        SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
284   
285        if(!skillLine)
286            continue;
287
288        SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
289
290        if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0)
291        {     
292            for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i)
293            {
294                CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i);
295                if(!cFamily)
296                    continue;
297
298                if(skillLine->skillId != cFamily->skillLine && skillLine->skillId != cFamily->skillLine2)
299                    continue;
300
301                sPetFamilySpellsStore[i].insert(spellInfo->Id);
302            }
303        }
304    }
305
306    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellCastTimesStore,      dbcPath,"SpellCastTimes.dbc");
307    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore,       dbcPath,"SpellDuration.dbc");
308    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore,    dbcPath,"SpellFocusObject.dbc");
309    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc");
310   
311    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc");
312    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore,         dbcPath,"SpellRadius.dbc");
313    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore,          dbcPath,"SpellRange.dbc");
314    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore,     dbcPath,"SpellShapeshiftForm.dbc");
315    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sStableSlotPricesStore,    dbcPath,"StableSlotPrices.dbc");
316    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentStore,              dbcPath,"Talent.dbc");
317
318    // create talent spells set
319    for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i)
320    {
321        TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
322        if (!talentInfo) continue;
323        for (int j = 0; j < 5; j++)
324            if(talentInfo->RankID[j])
325                sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i,j);
326    }
327
328    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentTabStore,           dbcPath,"TalentTab.dbc");
329
330    // preper fast data access to bit pos of talent ranks for use at inspecting
331    {
332        // fill table by amount of talent ranks and fill sTalentTabBitSizeInInspect
333        // store in with (row,col,talent)->size key for correct sorting by (row,col)
334        typedef std::map<uint32,uint32> TalentBitSize;
335        TalentBitSize sTalentBitSize;
336        for(uint32 i = 1; i < sTalentStore.GetNumRows(); ++i)
337        {
338            TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
339            if (!talentInfo) continue;
340
341            TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
342            if(!talentTabInfo)
343                continue;
344
345            // find talent rank
346            uint32 curtalent_maxrank = 0;
347            for(uint32 k = 5; k > 0; --k)
348            {
349                if(talentInfo->RankID[k-1])
350                {
351                    curtalent_maxrank = k;
352                    break;
353                }
354            }
355
356            sTalentBitSize[(talentInfo->Row<<24) + (talentInfo->Col<<16)+talentInfo->TalentID] = curtalent_maxrank;
357            sTalentTabSizeInInspect[talentInfo->TalentTab] += curtalent_maxrank;
358        }
359
360        // now have all max ranks (and then bit amount used for store talent ranks in inspect)
361        for(uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId)
362        {
363            TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentTabId );
364            if(!talentTabInfo)
365                continue;
366
367            // store class talent tab pages
368            uint32 cls = 1;
369            for(uint32 m=1;!(m & talentTabInfo->ClassMask) && cls < 12 /*MAX_CLASSES*/;m <<=1, ++cls) {}
370
371            sTalentTabPages[cls][talentTabInfo->tabpage]=talentTabId;
372
373            // add total amount bits for first rank starting from talent tab first talent rank pos.
374            uint32 pos = 0;
375            for(TalentBitSize::iterator itr = sTalentBitSize.begin(); itr != sTalentBitSize.end(); ++itr)
376            {
377                uint32 talentId = itr->first & 0xFFFF;
378                TalentEntry const *talentInfo = sTalentStore.LookupEntry( talentId );
379                if(!talentInfo)
380                    continue;
381
382                if(talentInfo->TalentTab != talentTabId)
383                    continue;
384
385                sTalentPosInInspect[talentId] = pos;
386                pos+= itr->second;
387            }
388        }
389    }
390
391    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiNodesStore,           dbcPath,"TaxiNodes.dbc");
392
393    // Initialize global taxinodes mask
394    memset(sTaxiNodesMask,0,sizeof(sTaxiNodesMask));
395    for(uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i)
396    {
397        if(sTaxiNodesStore.LookupEntry(i))
398        {
399            uint8  field   = (uint8)((i - 1) / 32);
400            uint32 submask = 1<<((i-1)%32);
401            sTaxiNodesMask[field] |= submask;
402        }
403    }
404
405    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathStore,            dbcPath,"TaxiPath.dbc");
406    for(uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i)
407        if(TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i))
408            sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID,entry->price);
409    uint32 pathCount = sTaxiPathStore.GetNumRows();
410
411    //## TaxiPathNode.dbc ## Loaded only for initialization different structures
412    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathNodeStore,        dbcPath,"TaxiPathNode.dbc");
413    // Calculate path nodes count
414    std::vector<uint32> pathLength;
415    pathLength.resize(pathCount);                           // 0 and some other indexes not used
416    for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
417        if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
418            ++pathLength[entry->path];
419    // Set path length
420    sTaxiPathNodesByPath.resize(pathCount);                 // 0 and some other indexes not used
421    for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i)
422        sTaxiPathNodesByPath[i].resize(pathLength[i]);
423    // fill data
424    for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
425        if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
426            sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay);
427    sTaxiPathNodeStore.Clear();
428
429    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTotemCategoryStore,       dbcPath,"TotemCategory.dbc");
430    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapAreaStore,        dbcPath,"WorldMapArea.dbc");
431    LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldSafeLocsStore,       dbcPath,"WorldSafeLocs.dbc");
432
433    // error checks
434    if(bad_dbc_files.size() >= DBCFilesCount )
435    {
436        sLog.outError("\nIncorrect DataDir value in mangosd.conf or ALL required *.dbc files (%d) not found by path: %sdbc",DBCFilesCount,dataPath.c_str());
437        exit(1);
438    }
439    else if(!bad_dbc_files.empty() )
440    {
441        std::string str;
442        for(std::list<std::string>::iterator i = bad_dbc_files.begin(); i != bad_dbc_files.end(); ++i)
443            str += *i + "\n";
444
445        sLog.outError("\nSome required *.dbc files (%u from %d) not found or not compatible:\n%s",bad_dbc_files.size(),DBCFilesCount,str.c_str());
446        exit(1);
447    }
448
449    // check at up-to-date DBC files (53085 is last added spell in 2.4.3)
450    // check at up-to-date DBC files (17514 is last ID in SkillLineAbilities in 2.4.3)
451    // check at up-to-date DBC files (598 is last map added in 2.4.3)
452    // check at up-to-date DBC files (1127 is last gem property added in 2.4.3)
453    // check at up-to-date DBC files (2425 is last item extended cost added in 2.4.3)
454    // check at up-to-date DBC files (71 is last char title added in 2.4.3)
455    // check at up-to-date DBC files (1768 is last area added in 2.4.3)
456    if( !sSpellStore.LookupEntry(53085)            || 
457        !sSkillLineAbilityStore.LookupEntry(17514) || 
458        !sMapStore.LookupEntry(598)                ||
459        !sGemPropertiesStore.LookupEntry(1127)     || 
460        !sItemExtendedCostStore.LookupEntry(2425)  || 
461        !sCharTitlesStore.LookupEntry(71)          ||
462        !sAreaStore.LookupEntry(1768)              )
463    {
464        sLog.outError("\nYou have _outdated_ DBC files. Please extract correct versions from current using client.");
465        exit(1);
466    }
467
468    sLog.outString();
469    sLog.outString( ">> Loaded %d data stores", DBCFilesCount );
470    sLog.outString();
471}
472
473SimpleFactionsList const* GetFactionTeamList(uint32 faction)
474{
475    FactionTeamMap::const_iterator itr = sFactionTeamMap.find(faction);
476    if(itr==sFactionTeamMap.end())
477        return NULL;
478    return &itr->second;
479}
480
481char* GetPetName(uint32 petfamily, uint32 dbclang)
482{
483    if(!petfamily)
484        return NULL;
485    CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(petfamily);
486    if(!pet_family)
487        return NULL;
488    return pet_family->Name[dbclang]?pet_family->Name[dbclang]:NULL;
489}
490
491TalentSpellPos const* GetTalentSpellPos(uint32 spellId)
492{
493    TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId);
494    if(itr==sTalentSpellPosMap.end())
495        return NULL;
496
497    return &itr->second;
498}
499
500uint32 GetTalentSpellCost(uint32 spellId)
501{
502    if(TalentSpellPos const* pos = GetTalentSpellPos(spellId))
503        return pos->rank+1;
504
505    return 0;
506}
507
508AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
509{
510    AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id);
511    if(i == sAreaFlagByAreaID.end())
512        return NULL;
513
514    return sAreaStore.LookupEntry(i->second);
515}
516
517AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id)
518{
519    if(area_flag)
520        return sAreaStore.LookupEntry(area_flag);
521
522    if(MapEntry const* mapEntry = sMapStore.LookupEntry(map_id))
523        return GetAreaEntryByAreaID(mapEntry->linked_zone);
524
525    return NULL;
526}
527
528uint32 GetAreaFlagByMapId(uint32 mapid)
529{
530    AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid);
531    if(i == sAreaFlagByMapID.end())
532        return 0;
533    else
534        return i->second;
535}
536
537uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId)
538{
539    if(mapid != 530)                                        // speed for most cases
540        return mapid;
541
542    if(WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId))
543        return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id;
544
545    return mapid;
546}
547
548ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId)
549{
550    mapid = GetVirtualMapForMapAndZone(mapid,zoneId);
551    if(mapid < 2)
552        return CONTENT_1_60;
553
554    MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
555    return (!mapEntry || !mapEntry->IsExpansionMap()) ? CONTENT_1_60 : CONTENT_61_70;
556}
557
558ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id)
559{
560    // not sorted, numbering index from 0
561    for(uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
562    {
563        ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i);
564        if(ch && ch->ChannelID == channel_id)
565            return ch;
566    }
567    return NULL;
568}
569
570bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId)
571{
572    if(requiredTotemCategoryId==0)
573        return true;
574    if(itemTotemCategoryId==0)
575        return false;
576
577    TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId);
578    if(!itemEntry)
579        return false;
580    TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId);
581    if(!reqEntry)
582        return false;
583
584    if(itemEntry->categoryType!=reqEntry->categoryType)
585        return false;
586
587    return (itemEntry->categoryMask & reqEntry->categoryMask)==reqEntry->categoryMask;
588}
589
590void Zone2MapCoordinates(float& x,float& y,uint32 zone)
591{
592    WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
593
594    // if not listed then map coordinates (instance)
595    if(!maEntry)
596        return;
597
598    std::swap(x,y);                                         // at client map coords swapped
599    x = x*((maEntry->x2-maEntry->x1)/100)+maEntry->x1;
600    y = y*((maEntry->y2-maEntry->y1)/100)+maEntry->y1;      // client y coord from top to down
601}
602
603void Map2ZoneCoordinates(float& x,float& y,uint32 zone)
604{
605    WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
606
607    // if not listed then map coordinates (instance)
608    if(!maEntry)
609        return;
610
611    x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100);
612    y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100);    // client y coord from top to down
613    std::swap(x,y);                                         // client have map coords swapped
614}
615
616uint32 GetTalentInspectBitPosInTab(uint32 talentId)
617{
618    TalentInspectMap::const_iterator itr = sTalentPosInInspect.find(talentId);
619    if(itr == sTalentPosInInspect.end())
620        return 0;
621
622    return itr->second;
623}
624
625uint32 GetTalentTabInspectBitSize(uint32 talentTabId)
626{
627    TalentInspectMap::const_iterator itr = sTalentTabSizeInInspect.find(talentTabId);
628    if(itr == sTalentTabSizeInInspect.end())
629        return 0;
630
631    return itr->second;
632}
633
634uint32 const* GetTalentTabPages(uint32 cls)
635{
636    return sTalentTabPages[cls];
637}
638
639// script support functions
640MANGOS_DLL_SPEC DBCStorage <SoundEntriesEntry>  const* GetSoundEntriesStore()   { return &sSoundEntriesStore;   }
641MANGOS_DLL_SPEC DBCStorage <SpellEntry>         const* GetSpellStore()          { return &sSpellStore;          }
642MANGOS_DLL_SPEC DBCStorage <SpellRangeEntry>    const* GetSpellRangeStore()     { return &sSpellRangeStore;     }
Note: See TracBrowser for help on using the browser.