[7295] Make more static world data accessable for scripts use.
[AHbot.git] / src / shared / Database / DBCStores.cpp
blobd1f16d71081c62db646c1134153569bd76c18e0f
1 /*
2 * Copyright (C) 2005-2009 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 DBCStorage <AreaGroupEntry> sAreaGroupStore(AreaGroupEntryfmt);
34 static AreaFlagByAreaID sAreaFlagByAreaID;
35 static AreaFlagByMapID sAreaFlagByMapID; // for instances without generated *.map files
37 DBCStorage <AchievementEntry> sAchievementStore(Achievementfmt);
38 DBCStorage <AchievementCriteriaEntry> sAchievementCriteriaStore(AchievementCriteriafmt);
39 DBCStorage <AreaTriggerEntry> sAreaTriggerStore(AreaTriggerEntryfmt);
40 DBCStorage <AuctionHouseEntry> sAuctionHouseStore(AuctionHouseEntryfmt);
41 DBCStorage <BankBagSlotPricesEntry> sBankBagSlotPricesStore(BankBagSlotPricesEntryfmt);
42 DBCStorage <BattlemasterListEntry> sBattlemasterListStore(BattlemasterListEntryfmt);
43 DBCStorage <BarberShopStyleEntry> sBarberShopStyleStore(BarberShopStyleEntryfmt);
44 DBCStorage <CharStartOutfitEntry> sCharStartOutfitStore(CharStartOutfitEntryfmt);
45 DBCStorage <CharTitlesEntry> sCharTitlesStore(CharTitlesEntryfmt);
46 DBCStorage <ChatChannelsEntry> sChatChannelsStore(ChatChannelsEntryfmt);
47 DBCStorage <ChrClassesEntry> sChrClassesStore(ChrClassesEntryfmt);
48 DBCStorage <ChrRacesEntry> sChrRacesStore(ChrRacesEntryfmt);
49 DBCStorage <CreatureDisplayInfoEntry> sCreatureDisplayInfoStore(CreatureDisplayInfofmt);
50 DBCStorage <CreatureFamilyEntry> sCreatureFamilyStore(CreatureFamilyfmt);
51 DBCStorage <CreatureSpellDataEntry> sCreatureSpellDataStore(CreatureSpellDatafmt);
52 DBCStorage <CreatureTypeEntry> sCreatureTypeStore(CreatureTypefmt);
54 DBCStorage <DurabilityQualityEntry> sDurabilityQualityStore(DurabilityQualityfmt);
55 DBCStorage <DurabilityCostsEntry> sDurabilityCostsStore(DurabilityCostsfmt);
57 DBCStorage <EmotesTextEntry> sEmotesTextStore(EmoteEntryfmt);
59 typedef std::map<uint32,SimpleFactionsList> FactionTeamMap;
60 static FactionTeamMap sFactionTeamMap;
61 DBCStorage <FactionEntry> sFactionStore(FactionEntryfmt);
62 DBCStorage <FactionTemplateEntry> sFactionTemplateStore(FactionTemplateEntryfmt);
64 DBCStorage <GemPropertiesEntry> sGemPropertiesStore(GemPropertiesEntryfmt);
65 DBCStorage <GlyphPropertiesEntry> sGlyphPropertiesStore(GlyphPropertiesfmt);
66 DBCStorage <GlyphSlotEntry> sGlyphSlotStore(GlyphSlotfmt);
68 DBCStorage <GtBarberShopCostBaseEntry> sGtBarberShopCostBaseStore(GtBarberShopCostBasefmt);
69 DBCStorage <GtCombatRatingsEntry> sGtCombatRatingsStore(GtCombatRatingsfmt);
70 DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore(GtChanceToMeleeCritBasefmt);
71 DBCStorage <GtChanceToMeleeCritEntry> sGtChanceToMeleeCritStore(GtChanceToMeleeCritfmt);
72 DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore(GtChanceToSpellCritBasefmt);
73 DBCStorage <GtChanceToSpellCritEntry> sGtChanceToSpellCritStore(GtChanceToSpellCritfmt);
74 DBCStorage <GtOCTRegenHPEntry> sGtOCTRegenHPStore(GtOCTRegenHPfmt);
75 //DBCStorage <GtOCTRegenMPEntry> sGtOCTRegenMPStore(GtOCTRegenMPfmt); -- not used currently
76 DBCStorage <GtRegenHPPerSptEntry> sGtRegenHPPerSptStore(GtRegenHPPerSptfmt);
77 DBCStorage <GtRegenMPPerSptEntry> sGtRegenMPPerSptStore(GtRegenMPPerSptfmt);
78 DBCStorage <ItemEntry> sItemStore(Itemfmt);
79 //DBCStorage <ItemCondExtCostsEntry> sItemCondExtCostsStore(ItemCondExtCostsEntryfmt);
80 //DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently
81 DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt);
82 DBCStorage <ItemLimitCategoryEntry> sItemLimitCategoryStore(ItemLimitCategoryEntryfmt);
83 DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore(ItemRandomPropertiesfmt);
84 DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore(ItemRandomSuffixfmt);
85 DBCStorage <ItemSetEntry> sItemSetStore(ItemSetEntryfmt);
87 DBCStorage <LockEntry> sLockStore(LockEntryfmt);
89 DBCStorage <MailTemplateEntry> sMailTemplateStore(MailTemplateEntryfmt);
90 DBCStorage <MapEntry> sMapStore(MapEntryfmt);
92 DBCStorage <QuestSortEntry> sQuestSortStore(QuestSortEntryfmt);
94 DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt);
95 DBCStorage <ScalingStatDistributionEntry> sScalingStatDistributionStore(ScalingStatDistributionfmt);
96 DBCStorage <ScalingStatValuesEntry> sScalingStatValuesStore(ScalingStatValuesfmt);
98 DBCStorage <SkillLineEntry> sSkillLineStore(SkillLinefmt);
99 DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore(SkillLineAbilityfmt);
101 DBCStorage <SoundEntriesEntry> sSoundEntriesStore(SoundEntriesfmt);
103 DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore(SpellItemEnchantmentfmt);
104 DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt);
105 DBCStorage <SpellEntry> sSpellStore(SpellEntryfmt);
106 SpellCategoryStore sSpellCategoryStore;
107 PetFamilySpellsStore sPetFamilySpellsStore;
109 DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore(SpellCastTimefmt);
110 DBCStorage <SpellDurationEntry> sSpellDurationStore(SpellDurationfmt);
111 DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore(SpellFocusObjectfmt);
112 DBCStorage <SpellRadiusEntry> sSpellRadiusStore(SpellRadiusfmt);
113 DBCStorage <SpellRangeEntry> sSpellRangeStore(SpellRangefmt);
114 DBCStorage <SpellRuneCostEntry> sSpellRuneCostStore(SpellRuneCostfmt);
115 DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftfmt);
116 DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore(StableSlotPricesfmt);
117 //DBCStorage <SummonPropertiesEntry> sSummonPropertiesStore(SummonPropertiesfmt);
118 DBCStorage <TalentEntry> sTalentStore(TalentEntryfmt);
119 TalentSpellPosMap sTalentSpellPosMap;
120 DBCStorage <TalentTabEntry> sTalentTabStore(TalentTabEntryfmt);
122 // store absolute bit position for first rank for talent inspect
123 typedef std::map<uint32,uint32> TalentInspectMap;
124 static TalentInspectMap sTalentPosInInspect;
125 static TalentInspectMap sTalentTabSizeInInspect;
126 static uint32 sTalentTabPages[12/*MAX_CLASSES*/][3];
128 DBCStorage <TaxiNodesEntry> sTaxiNodesStore(TaxiNodesEntryfmt);
129 TaxiMask sTaxiNodesMask;
131 // DBC used only for initialization sTaxiPathSetBySource at startup.
132 TaxiPathSetBySource sTaxiPathSetBySource;
133 DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt);
135 // DBC used only for initialization sTaxiPathSetBySource at startup.
136 TaxiPathNodesByPath sTaxiPathNodesByPath;
138 static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
139 DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt);
140 DBCStorage <VehicleEntry> sVehicleStore(VehicleEntryfmt);
141 DBCStorage <VehicleSeatEntry> sVehicleSeatStore(VehicleSeatEntryfmt);
142 DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore(WorldMapAreaEntryfmt);
143 DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt);
144 DBCStorage <WorldMapOverlayEntry> sWorldMapOverlayStore(WorldMapOverlayEntryfmt);
146 typedef std::list<std::string> StoreProblemList;
148 static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, const std::string& filename)
150 sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize);
152 // assert must fail after function call
153 return false;
156 template<class T>
157 inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, const std::string& dbc_path, const std::string& filename)
159 // compatibility format and C++ structure sizes
160 assert(DBCFile::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFile::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename));
162 std::string dbc_filename = dbc_path + filename;
163 if(storage.Load(dbc_filename.c_str()))
165 bar.step();
166 for(uint8 i = 0; i < MAX_LOCALE; ++i)
168 if(!(availableDbcLocales & (1 << i)))
169 continue;
171 std::string dbc_filename_loc = dbc_path + localeNames[i] + "/" + filename;
172 if(!storage.LoadStringsFrom(dbc_filename_loc.c_str()))
173 availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks
176 else
178 // sort problematic dbc to (1) non compatible and (2) non-existed
179 FILE * f=fopen(dbc_filename.c_str(),"rb");
180 if(f)
182 char buf[100];
183 snprintf(buf,100," (exist, but have %d fields instead %d) Wrong client version DBC file?",storage.GetFieldCount(),strlen(storage.GetFormat()));
184 errlist.push_back(dbc_filename + buf);
185 fclose(f);
187 else
188 errlist.push_back(dbc_filename);
192 void LoadDBCStores(const std::string& dataPath)
194 std::string dbcPath = dataPath+"dbc/";
196 const uint32 DBCFilesCount = 72;
198 barGoLink bar( DBCFilesCount );
200 StoreProblemList bad_dbc_files;
201 uint32 availableDbcLocales = 0xFFFFFFFF;
203 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaStore, dbcPath,"AreaTable.dbc");
205 // must be after sAreaStore loading
206 for(uint32 i = 0; i < sAreaStore.GetNumRows(); ++i) // areaflag numbered from 0
208 if(AreaTableEntry const* area = sAreaStore.LookupEntry(i))
210 // fill AreaId->DBC records
211 sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID),area->exploreFlag));
213 // fill MapId->DBC records ( skip sub zones and continents )
214 if(area->zone==0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530 && area->mapid != 571 )
215 sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid,area->exploreFlag));
219 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementStore, dbcPath,"Achievement.dbc");
220 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementCriteriaStore, dbcPath,"Achievement_Criteria.dbc");
221 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc");
222 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaGroupStore, dbcPath,"AreaGroup.dbc");
223 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAuctionHouseStore, dbcPath,"AuctionHouse.dbc");
224 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc");
225 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc");
226 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBarberShopStyleStore, dbcPath,"BarberShopStyle.dbc");
227 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharStartOutfitStore, dbcPath,"CharStartOutfit.dbc");
229 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore, dbcPath,"CharTitles.dbc");
230 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore, dbcPath,"ChatChannels.dbc");
231 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore, dbcPath,"ChrClasses.dbc");
232 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrRacesStore, dbcPath,"ChrRaces.dbc");
233 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureDisplayInfoStore, dbcPath,"CreatureDisplayInfo.dbc");
234 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureFamilyStore, dbcPath,"CreatureFamily.dbc");
235 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureSpellDataStore, dbcPath,"CreatureSpellData.dbc");
236 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureTypeStore, dbcPath,"CreatureType.dbc");
237 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityCostsStore, dbcPath,"DurabilityCosts.dbc");
238 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityQualityStore, dbcPath,"DurabilityQuality.dbc");
239 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesTextStore, dbcPath,"EmotesText.dbc");
240 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionStore, dbcPath,"Faction.dbc");
241 for (uint32 i=0;i<sFactionStore.GetNumRows(); ++i)
243 FactionEntry const * faction = sFactionStore.LookupEntry(i);
244 if (faction && faction->team)
246 SimpleFactionsList &flist = sFactionTeamMap[faction->team];
247 flist.push_back(i);
251 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore, dbcPath,"FactionTemplate.dbc");
252 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc");
253 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphPropertiesStore, dbcPath,"GlyphProperties.dbc");
254 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphSlotStore, dbcPath,"GlyphSlot.dbc");
256 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtBarberShopCostBaseStore,dbcPath,"gtBarberShopCostBase.dbc");
257 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtCombatRatingsStore, dbcPath,"gtCombatRatings.dbc");
259 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritBaseStore, dbcPath,"gtChanceToMeleeCritBase.dbc");
260 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritStore, dbcPath,"gtChanceToMeleeCrit.dbc");
262 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritBaseStore, dbcPath,"gtChanceToSpellCritBase.dbc");
263 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritStore, dbcPath,"gtChanceToSpellCrit.dbc");
265 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenHPStore, dbcPath,"gtOCTRegenHP.dbc");
266 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore, dbcPath,"gtOCTRegenMP.dbc"); -- not used currently
267 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenHPPerSptStore, dbcPath,"gtRegenHPPerSpt.dbc");
268 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenMPPerSptStore, dbcPath,"gtRegenMPPerSpt.dbc");
269 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemStore, dbcPath,"Item.dbc");
270 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore, dbcPath,"ItemDisplayInfo.dbc"); -- not used currently
271 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore, dbcPath,"ItemCondExtCosts.dbc");
272 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemExtendedCostStore, dbcPath,"ItemExtendedCost.dbc");
273 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemLimitCategoryStore, dbcPath,"ItemLimitCategory.dbc");
274 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomPropertiesStore,dbcPath,"ItemRandomProperties.dbc");
275 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomSuffixStore, dbcPath,"ItemRandomSuffix.dbc");
276 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemSetStore, dbcPath,"ItemSet.dbc");
277 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sLockStore, dbcPath,"Lock.dbc");
278 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMailTemplateStore, dbcPath,"MailTemplate.dbc");
279 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapStore, dbcPath,"Map.dbc");
280 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sQuestSortStore, dbcPath,"QuestSort.dbc");
281 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sRandomPropertiesPointsStore, dbcPath,"RandPropPoints.dbc");
282 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatDistributionStore, dbcPath,"ScalingStatDistribution.dbc");
283 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatValuesStore, dbcPath,"ScalingStatValues.dbc");
284 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineStore, dbcPath,"SkillLine.dbc");
285 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineAbilityStore, dbcPath,"SkillLineAbility.dbc");
286 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSoundEntriesStore, dbcPath,"SoundEntries.dbc");
287 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellStore, dbcPath,"Spell.dbc");
288 for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
290 SpellEntry const * spell = sSpellStore.LookupEntry(i);
291 if(spell && spell->Category)
292 sSpellCategoryStore[spell->Category].insert(i);
294 // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields
295 // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view
296 #if MANGOS_ENDIAN == MANGOS_BIGENDIAN
297 std::swap(*((uint32*)(&spell->SpellFamilyFlags)),*(((uint32*)(&spell->SpellFamilyFlags))+1));
298 #endif
301 for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
303 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
305 if(!skillLine)
306 continue;
308 SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
310 if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0)
312 for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i)
314 CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i);
315 if(!cFamily)
316 continue;
318 if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1])
319 continue;
321 sPetFamilySpellsStore[i].insert(spellInfo->Id);
326 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellCastTimesStore, dbcPath,"SpellCastTimes.dbc");
327 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc");
328 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore, dbcPath,"SpellFocusObject.dbc");
329 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc");
330 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc");
331 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore, dbcPath,"SpellRadius.dbc");
332 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc");
333 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRuneCostStore, dbcPath,"SpellRuneCost.dbc");
334 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore, dbcPath,"SpellShapeshiftForm.dbc");
335 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sStableSlotPricesStore, dbcPath,"StableSlotPrices.dbc");
336 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSummonPropertiesStore, dbcPath,"SummonProperties.dbc");
337 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentStore, dbcPath,"Talent.dbc");
339 // create talent spells set
340 for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i)
342 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
343 if (!talentInfo) continue;
344 for (int j = 0; j < 5; j++)
345 if(talentInfo->RankID[j])
346 sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i,j);
349 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentTabStore, dbcPath,"TalentTab.dbc");
351 // prepare fast data access to bit pos of talent ranks for use at inspecting
353 // fill table by amount of talent ranks and fill sTalentTabBitSizeInInspect
354 // store in with (row,col,talent)->size key for correct sorting by (row,col)
355 typedef std::map<uint32,uint32> TalentBitSize;
356 TalentBitSize sTalentBitSize;
357 for(uint32 i = 1; i < sTalentStore.GetNumRows(); ++i)
359 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
360 if (!talentInfo) continue;
362 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
363 if(!talentTabInfo)
364 continue;
366 // find talent rank
367 uint32 curtalent_maxrank = 0;
368 for(uint32 k = 5; k > 0; --k)
370 if(talentInfo->RankID[k-1])
372 curtalent_maxrank = k;
373 break;
377 sTalentBitSize[(talentInfo->Row<<24) + (talentInfo->Col<<16)+talentInfo->TalentID] = curtalent_maxrank;
378 sTalentTabSizeInInspect[talentInfo->TalentTab] += curtalent_maxrank;
381 // now have all max ranks (and then bit amount used for store talent ranks in inspect)
382 for(uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId)
384 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentTabId );
385 if(!talentTabInfo)
386 continue;
388 // store class talent tab pages
389 uint32 cls = 1;
390 for(uint32 m=1;!(m & talentTabInfo->ClassMask) && cls < 12 /*MAX_CLASSES*/;m <<=1, ++cls) {}
392 sTalentTabPages[cls][talentTabInfo->tabpage]=talentTabId;
394 // add total amount bits for first rank starting from talent tab first talent rank pos.
395 uint32 pos = 0;
396 for(TalentBitSize::iterator itr = sTalentBitSize.begin(); itr != sTalentBitSize.end(); ++itr)
398 uint32 talentId = itr->first & 0xFFFF;
399 TalentEntry const *talentInfo = sTalentStore.LookupEntry( talentId );
400 if(!talentInfo)
401 continue;
403 if(talentInfo->TalentTab != talentTabId)
404 continue;
406 sTalentPosInInspect[talentId] = pos;
407 pos+= itr->second;
412 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiNodesStore, dbcPath,"TaxiNodes.dbc");
414 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathStore, dbcPath,"TaxiPath.dbc");
415 for(uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i)
416 if(TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i))
417 sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID,entry->price);
418 uint32 pathCount = sTaxiPathStore.GetNumRows();
420 //## TaxiPathNode.dbc ## Loaded only for initialization different structures
421 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathNodeStore, dbcPath,"TaxiPathNode.dbc");
422 // Calculate path nodes count
423 std::vector<uint32> pathLength;
424 pathLength.resize(pathCount); // 0 and some other indexes not used
425 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
426 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
428 if (pathLength[entry->path] < entry->index + 1)
429 pathLength[entry->path] = entry->index + 1;
431 // Set path length
432 sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used
433 for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i)
434 sTaxiPathNodesByPath[i].resize(pathLength[i]);
435 // fill data
436 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
437 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
438 sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay);
439 sTaxiPathNodeStore.Clear();
441 // Initialize global taxinodes mask
442 // include existed nodes that have at least single not spell base (scripted) path
444 std::set<uint32> spellPaths;
445 for(uint32 i = 1; i < sSpellStore.GetNumRows (); ++i)
446 if(SpellEntry const* sInfo = sSpellStore.LookupEntry (i))
447 for(int j=0; j < 3; ++j)
448 if(sInfo->Effect[j]==123 /*SPELL_EFFECT_SEND_TAXI*/)
449 spellPaths.insert(sInfo->EffectMiscValue[j]);
451 memset(sTaxiNodesMask,0,sizeof(sTaxiNodesMask));
452 for(uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i)
454 if(!sTaxiNodesStore.LookupEntry(i))
455 continue;
457 TaxiPathSetBySource::const_iterator src_i = sTaxiPathSetBySource.find(i);
458 if(src_i!=sTaxiPathSetBySource.end() && !src_i->second.empty())
460 bool ok = false;
461 for(TaxiPathSetForSource::const_iterator dest_i = src_i->second.begin();dest_i != src_i->second.end(); ++dest_i)
463 // not spell path
464 if(spellPaths.find(dest_i->second.ID)==spellPaths.end())
466 ok = true;
467 break;
471 if(!ok)
472 continue;
475 // valid taxi netowrk node
476 uint8 field = (uint8)((i - 1) / 32);
477 uint32 submask = 1<<((i-1)%32);
478 sTaxiNodesMask[field] |= submask;
482 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTotemCategoryStore, dbcPath,"TotemCategory.dbc");
483 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleStore, dbcPath,"Vehicle.dbc");
484 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleSeatStore, dbcPath,"VehicleSeat.dbc");
485 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapAreaStore, dbcPath,"WorldMapArea.dbc");
486 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldSafeLocsStore, dbcPath,"WorldSafeLocs.dbc");
487 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapOverlayStore, dbcPath,"WorldMapOverlay.dbc");
489 // error checks
490 if(bad_dbc_files.size() >= DBCFilesCount )
492 sLog.outError("\nIncorrect DataDir value in mangosd.conf or ALL required *.dbc files (%d) not found by path: %sdbc",DBCFilesCount,dataPath.c_str());
493 exit(1);
495 else if(!bad_dbc_files.empty() )
497 std::string str;
498 for(std::list<std::string>::iterator i = bad_dbc_files.begin(); i != bad_dbc_files.end(); ++i)
499 str += *i + "\n";
501 sLog.outError("\nSome required *.dbc files (%u from %d) not found or not compatible:\n%s",bad_dbc_files.size(),DBCFilesCount,str.c_str());
502 exit(1);
505 // Check loaded DBC files proper version
506 if( !sSpellStore.LookupEntry(54909) || // last added spell in 3.0.8a
507 !sSpellStore.LookupEntry(49184) || // last added spell in 3.0.8a
508 sSpellStore.LookupEntry(49184)->RecoveryTime!=5000||// last changed spell in 3.0.8a
509 !sMapStore.LookupEntry(624) || // last map added in 3.0.8a
510 !sGemPropertiesStore.LookupEntry(1557) || // last gem property added in 3.0.8a
511 !sItemExtendedCostStore.LookupEntry(2589) || // last item extended cost added in 3.0.8a
512 !sCharTitlesStore.LookupEntry(144) || // last char title added in 3.0.8a
513 !sAreaStore.LookupEntry(2769) ) // last area (areaflag) added in 3.0.8a
515 sLog.outError("\nYou have _outdated_ DBC files. Please extract correct versions from current using client.");
516 exit(1);
519 sLog.outString();
520 sLog.outString( ">> Initialized %d data stores", DBCFilesCount );
523 SimpleFactionsList const* GetFactionTeamList(uint32 faction)
525 FactionTeamMap::const_iterator itr = sFactionTeamMap.find(faction);
526 if(itr==sFactionTeamMap.end())
527 return NULL;
528 return &itr->second;
531 char* GetPetName(uint32 petfamily, uint32 dbclang)
533 if(!petfamily)
534 return NULL;
535 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(petfamily);
536 if(!pet_family)
537 return NULL;
538 return pet_family->Name[dbclang]?pet_family->Name[dbclang]:NULL;
541 TalentSpellPos const* GetTalentSpellPos(uint32 spellId)
543 TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId);
544 if(itr==sTalentSpellPosMap.end())
545 return NULL;
547 return &itr->second;
550 uint32 GetTalentSpellCost(uint32 spellId)
552 if(TalentSpellPos const* pos = GetTalentSpellPos(spellId))
553 return pos->rank+1;
555 return 0;
558 int32 GetAreaFlagByAreaID(uint32 area_id)
560 AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id);
561 if(i == sAreaFlagByAreaID.end())
562 return -1;
564 return i->second;
567 AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
569 int32 areaflag = GetAreaFlagByAreaID(area_id);
570 if(areaflag < 0)
571 return NULL;
573 return sAreaStore.LookupEntry(areaflag );
576 AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id)
578 if(area_flag)
579 return sAreaStore.LookupEntry(area_flag);
581 if(MapEntry const* mapEntry = sMapStore.LookupEntry(map_id))
582 return GetAreaEntryByAreaID(mapEntry->linked_zone);
584 return NULL;
587 uint32 GetAreaFlagByMapId(uint32 mapid)
589 AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid);
590 if(i == sAreaFlagByMapID.end())
591 return 0;
592 else
593 return i->second;
596 uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId)
598 if(mapid != 530 && mapid != 571) // speed for most cases
599 return mapid;
601 if(WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId))
602 return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id;
604 return mapid;
607 ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId)
609 mapid = GetVirtualMapForMapAndZone(mapid,zoneId);
610 if(mapid < 2)
611 return CONTENT_1_60;
613 MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
614 if(!mapEntry)
615 return CONTENT_1_60;
617 switch(mapEntry->Expansion())
619 default: return CONTENT_1_60;
620 case 1: return CONTENT_61_70;
621 case 2: return CONTENT_71_80;
625 ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id)
627 // not sorted, numbering index from 0
628 for(uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
630 ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i);
631 if(ch && ch->ChannelID == channel_id)
632 return ch;
634 return NULL;
637 bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId)
639 if(requiredTotemCategoryId==0)
640 return true;
641 if(itemTotemCategoryId==0)
642 return false;
644 TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId);
645 if(!itemEntry)
646 return false;
647 TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId);
648 if(!reqEntry)
649 return false;
651 if(itemEntry->categoryType!=reqEntry->categoryType)
652 return false;
654 return (itemEntry->categoryMask & reqEntry->categoryMask)==reqEntry->categoryMask;
657 void Zone2MapCoordinates(float& x,float& y,uint32 zone)
659 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
661 // if not listed then map coordinates (instance)
662 if(!maEntry)
663 return;
665 std::swap(x,y); // at client map coords swapped
666 x = x*((maEntry->x2-maEntry->x1)/100)+maEntry->x1;
667 y = y*((maEntry->y2-maEntry->y1)/100)+maEntry->y1; // client y coord from top to down
670 void Map2ZoneCoordinates(float& x,float& y,uint32 zone)
672 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
674 // if not listed then map coordinates (instance)
675 if(!maEntry)
676 return;
678 x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100);
679 y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100); // client y coord from top to down
680 std::swap(x,y); // client have map coords swapped
683 uint32 GetTalentInspectBitPosInTab(uint32 talentId)
685 TalentInspectMap::const_iterator itr = sTalentPosInInspect.find(talentId);
686 if(itr == sTalentPosInInspect.end())
687 return 0;
689 return itr->second;
692 uint32 GetTalentTabInspectBitSize(uint32 talentTabId)
694 TalentInspectMap::const_iterator itr = sTalentTabSizeInInspect.find(talentTabId);
695 if(itr == sTalentTabSizeInInspect.end())
696 return 0;
698 return itr->second;
701 uint32 const* GetTalentTabPages(uint32 cls)
703 return sTalentTabPages[cls];
706 // script support functions
707 MANGOS_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore() { return &sSoundEntriesStore; }
708 MANGOS_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore() { return &sSpellStore; }
709 MANGOS_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore() { return &sSpellRangeStore; }
710 MANGOS_DLL_SPEC DBCStorage <FactionEntry> const* GetFactionStore() { return &sFactionStore; }
711 MANGOS_DLL_SPEC DBCStorage <ItemEntry> const* GetItemDisplayStore() { return &sItemStore; }
712 MANGOS_DLL_SPEC DBCStorage <CreatureDisplayInfoEntry> const* GetCreatureDisplayStore() { return &sCreatureDisplayInfoStore; }