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

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

Merged commit 269 (5f0e38da128a).

Original author: gvcoman
Date: 2008-11-21 14:34:05-05:00

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