Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / src / shared / Database / DBCStores.cpp
blob0c0af078b6a3cea40573cdb16142fe414fe8709f
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
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.
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.
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
19 #include "DBCStores.h"
20 //#include "DataStore.h"
21 #include "Policies/SingletonImp.h"
22 #include "Log.h"
23 #include "ProgressBar.h"
25 #include "DBCfmt.cpp"
27 #include <map>
29 typedef std::map<uint16,uint32> AreaFlagByAreaID;
30 typedef std::map<uint32,uint32> AreaFlagByMapID;
32 DBCStorage <AreaTableEntry> sAreaStore(AreaTableEntryfmt);
33 static AreaFlagByAreaID sAreaFlagByAreaID;
34 static AreaFlagByMapID sAreaFlagByMapID; // for instances without generated *.map files
36 DBCStorage <AreaTriggerEntry> sAreaTriggerStore(AreaTriggerEntryfmt);
37 DBCStorage <BankBagSlotPricesEntry> sBankBagSlotPricesStore(BankBagSlotPricesEntryfmt);
38 DBCStorage <BattlemasterListEntry> sBattlemasterListStore(BattlemasterListEntryfmt);
39 DBCStorage <CharTitlesEntry> sCharTitlesStore(CharTitlesEntryfmt);
40 DBCStorage <ChatChannelsEntry> sChatChannelsStore(ChatChannelsEntryfmt);
41 DBCStorage <ChrClassesEntry> sChrClassesStore(ChrClassesEntryfmt);
42 DBCStorage <ChrRacesEntry> sChrRacesStore(ChrRacesEntryfmt);
43 DBCStorage <CreatureDisplayInfoEntry> sCreatureDisplayInfoStore(CreatureDisplayInfofmt);
44 DBCStorage <CreatureFamilyEntry> sCreatureFamilyStore(CreatureFamilyfmt);
45 DBCStorage <CreatureSpellDataEntry> sCreatureSpellDataStore(CreatureSpellDatafmt);
47 DBCStorage <DurabilityQualityEntry> sDurabilityQualityStore(DurabilityQualityfmt);
48 DBCStorage <DurabilityCostsEntry> sDurabilityCostsStore(DurabilityCostsfmt);
50 DBCStorage <EmotesTextEntry> sEmotesTextStore(EmoteEntryfmt);
52 typedef std::map<uint32,SimpleFactionsList> FactionTeamMap;
53 static FactionTeamMap sFactionTeamMap;
54 DBCStorage <FactionEntry> sFactionStore(FactionEntryfmt);
55 DBCStorage <FactionTemplateEntry> sFactionTemplateStore(FactionTemplateEntryfmt);
57 DBCStorage <GemPropertiesEntry> sGemPropertiesStore(GemPropertiesEntryfmt);
59 DBCStorage <GtCombatRatingsEntry> sGtCombatRatingsStore(GtCombatRatingsfmt);
60 DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore(GtChanceToMeleeCritBasefmt);
61 DBCStorage <GtChanceToMeleeCritEntry> sGtChanceToMeleeCritStore(GtChanceToMeleeCritfmt);
62 DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore(GtChanceToSpellCritBasefmt);
63 DBCStorage <GtChanceToSpellCritEntry> sGtChanceToSpellCritStore(GtChanceToSpellCritfmt);
64 DBCStorage <GtOCTRegenHPEntry> sGtOCTRegenHPStore(GtOCTRegenHPfmt);
65 //DBCStorage <GtOCTRegenMPEntry> sGtOCTRegenMPStore(GtOCTRegenMPfmt); -- not used currently
66 DBCStorage <GtRegenHPPerSptEntry> sGtRegenHPPerSptStore(GtRegenHPPerSptfmt);
67 DBCStorage <GtRegenMPPerSptEntry> sGtRegenMPPerSptStore(GtRegenMPPerSptfmt);
68 DBCStorage <ItemEntry> sItemStore(Itemfmt);
69 //DBCStorage <ItemCondExtCostsEntry> sItemCondExtCostsStore(ItemCondExtCostsEntryfmt);
70 //DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently
71 DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt);
72 DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore(ItemRandomPropertiesfmt);
73 DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore(ItemRandomSuffixfmt);
74 DBCStorage <ItemSetEntry> sItemSetStore(ItemSetEntryfmt);
76 DBCStorage <LockEntry> sLockStore(LockEntryfmt);
78 DBCStorage <MailTemplateEntry> sMailTemplateStore(MailTemplateEntryfmt);
79 DBCStorage <MapEntry> sMapStore(MapEntryfmt);
81 DBCStorage <QuestSortEntry> sQuestSortStore(QuestSortEntryfmt);
83 DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt);
85 DBCStorage <SkillLineEntry> sSkillLineStore(SkillLinefmt);
86 DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore(SkillLineAbilityfmt);
88 DBCStorage <SoundEntriesEntry> sSoundEntriesStore(SoundEntriesfmt);
90 DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore(SpellItemEnchantmentfmt);
91 DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt);
92 DBCStorage <SpellEntry> sSpellStore(SpellEntryfmt);
93 SpellCategoryStore sSpellCategoryStore;
94 PetFamilySpellsStore sPetFamilySpellsStore;
96 DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore(SpellCastTimefmt);
97 DBCStorage <SpellDurationEntry> sSpellDurationStore(SpellDurationfmt);
98 DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore(SpellFocusObjectfmt);
99 DBCStorage <SpellRadiusEntry> sSpellRadiusStore(SpellRadiusfmt);
100 DBCStorage <SpellRangeEntry> sSpellRangeStore(SpellRangefmt);
101 DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftfmt);
102 DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore(StableSlotPricesfmt);
103 DBCStorage <TalentEntry> sTalentStore(TalentEntryfmt);
104 TalentSpellPosMap sTalentSpellPosMap;
105 DBCStorage <TalentTabEntry> sTalentTabStore(TalentTabEntryfmt);
107 // store absolute bit position for first rank for talent inspect
108 typedef std::map<uint32,uint32> TalentInspectMap;
109 static TalentInspectMap sTalentPosInInspect;
110 static TalentInspectMap sTalentTabSizeInInspect;
111 static uint32 sTalentTabPages[12/*MAX_CLASSES*/][3];
113 DBCStorage <TaxiNodesEntry> sTaxiNodesStore(TaxiNodesEntryfmt);
114 TaxiMask sTaxiNodesMask;
116 // DBC used only for initialization sTaxiPathSetBySource at startup.
117 TaxiPathSetBySource sTaxiPathSetBySource;
118 DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt);
120 // DBC used only for initialization sTaxiPathSetBySource at startup.
121 TaxiPathNodesByPath sTaxiPathNodesByPath;
123 static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
124 DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt);
125 DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore(WorldMapAreaEntryfmt);
126 DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt);
128 typedef std::list<std::string> StoreProblemList;
130 static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, std::string filename)
132 sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize);
134 // assert must fail after function call
135 return false;
138 template<class T>
139 inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, std::string dbc_path, std::string filename)
141 // compatibility format and C++ structure sizes
142 assert(DBCFile::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFile::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename));
144 std::string dbc_filename = dbc_path + filename;
145 if(storage.Load(dbc_filename.c_str()))
147 bar.step();
148 for(uint8 i = 0; i < MAX_LOCALE; ++i)
150 if(!(availableDbcLocales & (1 << i)))
151 continue;
153 std::string dbc_filename_loc = dbc_path + localeNames[i] + "/" + filename;
154 if(!storage.LoadStringsFrom(dbc_filename_loc.c_str()))
155 availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks
158 else
160 // sort problematic dbc to (1) non compatible and (2) non-existed
161 FILE * f=fopen(dbc_filename.c_str(),"rb");
162 if(f)
164 char buf[100];
165 snprintf(buf,100," (exist, but have %d fields instead %d) Wrong client version DBC file?",storage.GetFieldCount(),strlen(storage.GetFormat()));
166 errlist.push_back(dbc_filename + buf);
167 fclose(f);
169 else
170 errlist.push_back(dbc_filename);
174 void LoadDBCStores(std::string dataPath)
176 std::string dbcPath = dataPath+"dbc/";
178 const uint32 DBCFilesCount = 56;
180 barGoLink bar( DBCFilesCount );
182 StoreProblemList bad_dbc_files;
183 uint32 availableDbcLocales = 0xFFFFFFFF;
185 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaStore, dbcPath,"AreaTable.dbc");
187 // must be after sAreaStore loading
188 for(uint32 i = 0; i < sAreaStore.GetNumRows(); ++i) // areaflag numbered from 0
190 if(AreaTableEntry const* area = sAreaStore.LookupEntry(i))
192 // fill AreaId->DBC records
193 sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID),area->exploreFlag));
195 // fill MapId->DBC records ( skip sub zones and continents )
196 if(area->zone==0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530 )
197 sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid,area->exploreFlag));
201 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc");
202 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc");
203 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc");
204 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore, dbcPath,"CharTitles.dbc");
205 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore, dbcPath,"ChatChannels.dbc");
206 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore, dbcPath,"ChrClasses.dbc");
207 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrRacesStore, dbcPath,"ChrRaces.dbc");
208 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureDisplayInfoStore, dbcPath,"CreatureDisplayInfo.dbc");
209 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureFamilyStore, dbcPath,"CreatureFamily.dbc");
210 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureSpellDataStore, dbcPath,"CreatureSpellData.dbc");
211 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityCostsStore, dbcPath,"DurabilityCosts.dbc");
212 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityQualityStore, dbcPath,"DurabilityQuality.dbc");
213 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesTextStore, dbcPath,"EmotesText.dbc");
214 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionStore, dbcPath,"Faction.dbc");
215 for (uint32 i=0;i<sFactionStore.GetNumRows(); ++i)
217 FactionEntry const * faction = sFactionStore.LookupEntry(i);
218 if (faction && faction->team)
220 SimpleFactionsList &flist = sFactionTeamMap[faction->team];
221 flist.push_back(i);
225 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore, dbcPath,"FactionTemplate.dbc");
226 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc");
228 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtCombatRatingsStore, dbcPath,"gtCombatRatings.dbc");
230 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritBaseStore, dbcPath,"gtChanceToMeleeCritBase.dbc");
231 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritStore, dbcPath,"gtChanceToMeleeCrit.dbc");
233 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritBaseStore, dbcPath,"gtChanceToSpellCritBase.dbc");
234 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritStore, dbcPath,"gtChanceToSpellCrit.dbc");
236 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenHPStore, dbcPath,"gtOCTRegenHP.dbc");
237 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore, dbcPath,"gtOCTRegenMP.dbc"); -- not used currently
238 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenHPPerSptStore, dbcPath,"gtRegenHPPerSpt.dbc");
239 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenMPPerSptStore, dbcPath,"gtRegenMPPerSpt.dbc");
240 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemStore, dbcPath,"Item.dbc");
241 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore, dbcPath,"ItemDisplayInfo.dbc"); -- not used currently
242 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore, dbcPath,"ItemCondExtCosts.dbc");
243 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemExtendedCostStore, dbcPath,"ItemExtendedCost.dbc");
244 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomPropertiesStore,dbcPath,"ItemRandomProperties.dbc");
245 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomSuffixStore, dbcPath,"ItemRandomSuffix.dbc");
246 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemSetStore, dbcPath,"ItemSet.dbc");
247 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sLockStore, dbcPath,"Lock.dbc");
248 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMailTemplateStore, dbcPath,"MailTemplate.dbc");
249 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapStore, dbcPath,"Map.dbc");
250 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sQuestSortStore, dbcPath,"QuestSort.dbc");
251 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sRandomPropertiesPointsStore, dbcPath,"RandPropPoints.dbc");
252 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineStore, dbcPath,"SkillLine.dbc");
253 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineAbilityStore, dbcPath,"SkillLineAbility.dbc");
254 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSoundEntriesStore, dbcPath,"SoundEntries.dbc");
255 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellStore, dbcPath,"Spell.dbc");
256 for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
258 SpellEntry const * spell = sSpellStore.LookupEntry(i);
259 if(spell && spell->Category)
260 sSpellCategoryStore[spell->Category].insert(i);
262 // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields
263 // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view
264 #if MANGOS_ENDIAN == MANGOS_BIGENDIAN
265 std::swap(*((uint32*)(&spell->SpellFamilyFlags)),*(((uint32*)(&spell->SpellFamilyFlags))+1));
266 #endif
269 for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
271 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
273 if(!skillLine)
274 continue;
276 SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
278 if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0)
280 for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i)
282 CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i);
283 if(!cFamily)
284 continue;
286 if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1])
287 continue;
289 sPetFamilySpellsStore[i].insert(spellInfo->Id);
294 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellCastTimesStore, dbcPath,"SpellCastTimes.dbc");
295 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc");
296 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore, dbcPath,"SpellFocusObject.dbc");
297 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc");
298 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc");
299 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore, dbcPath,"SpellRadius.dbc");
300 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc");
301 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore, dbcPath,"SpellShapeshiftForm.dbc");
302 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sStableSlotPricesStore, dbcPath,"StableSlotPrices.dbc");
303 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentStore, dbcPath,"Talent.dbc");
305 // create talent spells set
306 for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i)
308 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
309 if (!talentInfo) continue;
310 for (int j = 0; j < 5; j++)
311 if(talentInfo->RankID[j])
312 sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i,j);
315 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentTabStore, dbcPath,"TalentTab.dbc");
317 // prepare fast data access to bit pos of talent ranks for use at inspecting
319 // fill table by amount of talent ranks and fill sTalentTabBitSizeInInspect
320 // store in with (row,col,talent)->size key for correct sorting by (row,col)
321 typedef std::map<uint32,uint32> TalentBitSize;
322 TalentBitSize sTalentBitSize;
323 for(uint32 i = 1; i < sTalentStore.GetNumRows(); ++i)
325 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
326 if (!talentInfo) continue;
328 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
329 if(!talentTabInfo)
330 continue;
332 // find talent rank
333 uint32 curtalent_maxrank = 0;
334 for(uint32 k = 5; k > 0; --k)
336 if(talentInfo->RankID[k-1])
338 curtalent_maxrank = k;
339 break;
343 sTalentBitSize[(talentInfo->Row<<24) + (talentInfo->Col<<16)+talentInfo->TalentID] = curtalent_maxrank;
344 sTalentTabSizeInInspect[talentInfo->TalentTab] += curtalent_maxrank;
347 // now have all max ranks (and then bit amount used for store talent ranks in inspect)
348 for(uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId)
350 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentTabId );
351 if(!talentTabInfo)
352 continue;
354 // store class talent tab pages
355 uint32 cls = 1;
356 for(uint32 m=1;!(m & talentTabInfo->ClassMask) && cls < 12 /*MAX_CLASSES*/;m <<=1, ++cls) {}
358 sTalentTabPages[cls][talentTabInfo->tabpage]=talentTabId;
360 // add total amount bits for first rank starting from talent tab first talent rank pos.
361 uint32 pos = 0;
362 for(TalentBitSize::iterator itr = sTalentBitSize.begin(); itr != sTalentBitSize.end(); ++itr)
364 uint32 talentId = itr->first & 0xFFFF;
365 TalentEntry const *talentInfo = sTalentStore.LookupEntry( talentId );
366 if(!talentInfo)
367 continue;
369 if(talentInfo->TalentTab != talentTabId)
370 continue;
372 sTalentPosInInspect[talentId] = pos;
373 pos+= itr->second;
378 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiNodesStore, dbcPath,"TaxiNodes.dbc");
380 // Initialize global taxinodes mask
381 memset(sTaxiNodesMask,0,sizeof(sTaxiNodesMask));
382 for(uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i)
384 if(sTaxiNodesStore.LookupEntry(i))
386 uint8 field = (uint8)((i - 1) / 32);
387 uint32 submask = 1<<((i-1)%32);
388 sTaxiNodesMask[field] |= submask;
392 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathStore, dbcPath,"TaxiPath.dbc");
393 for(uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i)
394 if(TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i))
395 sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID,entry->price);
396 uint32 pathCount = sTaxiPathStore.GetNumRows();
398 //## TaxiPathNode.dbc ## Loaded only for initialization different structures
399 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathNodeStore, dbcPath,"TaxiPathNode.dbc");
400 // Calculate path nodes count
401 std::vector<uint32> pathLength;
402 pathLength.resize(pathCount); // 0 and some other indexes not used
403 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
404 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
405 ++pathLength[entry->path];
406 // Set path length
407 sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used
408 for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i)
409 sTaxiPathNodesByPath[i].resize(pathLength[i]);
410 // fill data
411 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
412 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
413 sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay);
414 sTaxiPathNodeStore.Clear();
416 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTotemCategoryStore, dbcPath,"TotemCategory.dbc");
417 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapAreaStore, dbcPath,"WorldMapArea.dbc");
418 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldSafeLocsStore, dbcPath,"WorldSafeLocs.dbc");
420 // error checks
421 if(bad_dbc_files.size() >= DBCFilesCount )
423 sLog.outError("\nIncorrect DataDir value in mangosd.conf or ALL required *.dbc files (%d) not found by path: %sdbc",DBCFilesCount,dataPath.c_str());
424 exit(1);
426 else if(!bad_dbc_files.empty() )
428 std::string str;
429 for(std::list<std::string>::iterator i = bad_dbc_files.begin(); i != bad_dbc_files.end(); ++i)
430 str += *i + "\n";
432 sLog.outError("\nSome required *.dbc files (%u from %d) not found or not compatible:\n%s",bad_dbc_files.size(),DBCFilesCount,str.c_str());
433 exit(1);
436 // check at up-to-date DBC files (53085 is last added spell in 2.4.3)
437 // check at up-to-date DBC files (17514 is last ID in SkillLineAbilities in 2.4.3)
438 // check at up-to-date DBC files (598 is last map added in 2.4.3)
439 // check at up-to-date DBC files (1127 is last gem property added in 2.4.3)
440 // check at up-to-date DBC files (2425 is last item extended cost added in 2.4.3)
441 // check at up-to-date DBC files (71 is last char title added in 2.4.3)
442 // check at up-to-date DBC files (1768 is last area added in 2.4.3)
443 if( !sSpellStore.LookupEntry(53085) ||
444 !sSkillLineAbilityStore.LookupEntry(17514) ||
445 !sMapStore.LookupEntry(598) ||
446 !sGemPropertiesStore.LookupEntry(1127) ||
447 !sItemExtendedCostStore.LookupEntry(2425) ||
448 !sCharTitlesStore.LookupEntry(71) ||
449 !sAreaStore.LookupEntry(1768) )
451 sLog.outError("\nYou have _outdated_ DBC files. Please extract correct versions from current using client.");
452 exit(1);
455 sLog.outString();
456 sLog.outString( ">> Loaded %d data stores", DBCFilesCount );
457 sLog.outString();
460 SimpleFactionsList const* GetFactionTeamList(uint32 faction)
462 FactionTeamMap::const_iterator itr = sFactionTeamMap.find(faction);
463 if(itr==sFactionTeamMap.end())
464 return NULL;
465 return &itr->second;
468 char* GetPetName(uint32 petfamily, uint32 dbclang)
470 if(!petfamily)
471 return NULL;
472 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(petfamily);
473 if(!pet_family)
474 return NULL;
475 return pet_family->Name[dbclang]?pet_family->Name[dbclang]:NULL;
478 TalentSpellPos const* GetTalentSpellPos(uint32 spellId)
480 TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId);
481 if(itr==sTalentSpellPosMap.end())
482 return NULL;
484 return &itr->second;
487 uint32 GetTalentSpellCost(uint32 spellId)
489 if(TalentSpellPos const* pos = GetTalentSpellPos(spellId))
490 return pos->rank+1;
492 return 0;
495 AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
497 AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id);
498 if(i == sAreaFlagByAreaID.end())
499 return NULL;
501 return sAreaStore.LookupEntry(i->second);
504 AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id)
506 if(area_flag)
507 return sAreaStore.LookupEntry(area_flag);
509 if(MapEntry const* mapEntry = sMapStore.LookupEntry(map_id))
510 return GetAreaEntryByAreaID(mapEntry->linked_zone);
512 return NULL;
515 uint32 GetAreaFlagByMapId(uint32 mapid)
517 AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid);
518 if(i == sAreaFlagByMapID.end())
519 return 0;
520 else
521 return i->second;
524 uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId)
526 if(mapid != 530) // speed for most cases
527 return mapid;
529 if(WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId))
530 return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id;
532 return mapid;
535 ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId)
537 mapid = GetVirtualMapForMapAndZone(mapid,zoneId);
538 if(mapid < 2)
539 return CONTENT_1_60;
541 MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
542 if(!mapEntry)
543 return CONTENT_1_60;
545 switch(mapEntry->Expansion())
547 default: return CONTENT_1_60;
548 case 1: return CONTENT_61_70;
549 case 2: return CONTENT_71_80;
553 ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id)
555 // not sorted, numbering index from 0
556 for(uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
558 ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i);
559 if(ch && ch->ChannelID == channel_id)
560 return ch;
562 return NULL;
565 bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId)
567 if(requiredTotemCategoryId==0)
568 return true;
569 if(itemTotemCategoryId==0)
570 return false;
572 TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId);
573 if(!itemEntry)
574 return false;
575 TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId);
576 if(!reqEntry)
577 return false;
579 if(itemEntry->categoryType!=reqEntry->categoryType)
580 return false;
582 return (itemEntry->categoryMask & reqEntry->categoryMask)==reqEntry->categoryMask;
585 void Zone2MapCoordinates(float& x,float& y,uint32 zone)
587 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
589 // if not listed then map coordinates (instance)
590 if(!maEntry)
591 return;
593 std::swap(x,y); // at client map coords swapped
594 x = x*((maEntry->x2-maEntry->x1)/100)+maEntry->x1;
595 y = y*((maEntry->y2-maEntry->y1)/100)+maEntry->y1; // client y coord from top to down
598 void Map2ZoneCoordinates(float& x,float& y,uint32 zone)
600 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
602 // if not listed then map coordinates (instance)
603 if(!maEntry)
604 return;
606 x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100);
607 y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100); // client y coord from top to down
608 std::swap(x,y); // client have map coords swapped
611 uint32 GetTalentInspectBitPosInTab(uint32 talentId)
613 TalentInspectMap::const_iterator itr = sTalentPosInInspect.find(talentId);
614 if(itr == sTalentPosInInspect.end())
615 return 0;
617 return itr->second;
620 uint32 GetTalentTabInspectBitSize(uint32 talentTabId)
622 TalentInspectMap::const_iterator itr = sTalentTabSizeInInspect.find(talentTabId);
623 if(itr == sTalentTabSizeInInspect.end())
624 return 0;
626 return itr->second;
629 uint32 const* GetTalentTabPages(uint32 cls)
631 return sTalentTabPages[cls];
634 // script support functions
635 MANGOS_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore() { return &sSoundEntriesStore; }
636 MANGOS_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore() { return &sSpellStore; }
637 MANGOS_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore() { return &sSpellRangeStore; }