port over some changes from Trinity version including one possible memory leak fix
[AHbot.git] / src / game / DBCStores.cpp
blobcf39de8717d176a50ca7866efc72cabe0c06f39c
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 "Policies/SingletonImp.h"
21 #include "Log.h"
22 #include "ProgressBar.h"
23 #include "SharedDefines.h"
25 #include "DBCfmt.h"
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 <CinematicSequencesEntry> sCinematicSequencesStore(CinematicSequencesEntryfmt);
50 DBCStorage <CreatureDisplayInfoEntry> sCreatureDisplayInfoStore(CreatureDisplayInfofmt);
51 DBCStorage <CreatureFamilyEntry> sCreatureFamilyStore(CreatureFamilyfmt);
52 DBCStorage <CreatureSpellDataEntry> sCreatureSpellDataStore(CreatureSpellDatafmt);
53 DBCStorage <CreatureTypeEntry> sCreatureTypeStore(CreatureTypefmt);
54 DBCStorage <CurrencyTypesEntry> sCurrencyTypesStore(CurrencyTypesfmt);
56 DBCStorage <DurabilityQualityEntry> sDurabilityQualityStore(DurabilityQualityfmt);
57 DBCStorage <DurabilityCostsEntry> sDurabilityCostsStore(DurabilityCostsfmt);
59 DBCStorage <EmotesEntry> sEmotesStore(EmotesEntryfmt);
60 DBCStorage <EmotesTextEntry> sEmotesTextStore(EmotesTextEntryfmt);
62 typedef std::map<uint32,SimpleFactionsList> FactionTeamMap;
63 static FactionTeamMap sFactionTeamMap;
64 DBCStorage <FactionEntry> sFactionStore(FactionEntryfmt);
65 DBCStorage <FactionTemplateEntry> sFactionTemplateStore(FactionTemplateEntryfmt);
67 DBCStorage <GemPropertiesEntry> sGemPropertiesStore(GemPropertiesEntryfmt);
68 DBCStorage <GlyphPropertiesEntry> sGlyphPropertiesStore(GlyphPropertiesfmt);
69 DBCStorage <GlyphSlotEntry> sGlyphSlotStore(GlyphSlotfmt);
71 DBCStorage <GtBarberShopCostBaseEntry> sGtBarberShopCostBaseStore(GtBarberShopCostBasefmt);
72 DBCStorage <GtCombatRatingsEntry> sGtCombatRatingsStore(GtCombatRatingsfmt);
73 DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore(GtChanceToMeleeCritBasefmt);
74 DBCStorage <GtChanceToMeleeCritEntry> sGtChanceToMeleeCritStore(GtChanceToMeleeCritfmt);
75 DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore(GtChanceToSpellCritBasefmt);
76 DBCStorage <GtChanceToSpellCritEntry> sGtChanceToSpellCritStore(GtChanceToSpellCritfmt);
77 DBCStorage <GtOCTRegenHPEntry> sGtOCTRegenHPStore(GtOCTRegenHPfmt);
78 //DBCStorage <GtOCTRegenMPEntry> sGtOCTRegenMPStore(GtOCTRegenMPfmt); -- not used currently
79 DBCStorage <GtRegenHPPerSptEntry> sGtRegenHPPerSptStore(GtRegenHPPerSptfmt);
80 DBCStorage <GtRegenMPPerSptEntry> sGtRegenMPPerSptStore(GtRegenMPPerSptfmt);
82 DBCStorage <HolidaysEntry> sHolidaysStore(Holidaysfmt);
84 DBCStorage <ItemEntry> sItemStore(Itemfmt);
85 DBCStorage <ItemBagFamilyEntry> sItemBagFamilyStore(ItemBagFamilyfmt);
86 //DBCStorage <ItemCondExtCostsEntry> sItemCondExtCostsStore(ItemCondExtCostsEntryfmt);
87 //DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently
88 DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt);
89 DBCStorage <ItemLimitCategoryEntry> sItemLimitCategoryStore(ItemLimitCategoryEntryfmt);
90 DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore(ItemRandomPropertiesfmt);
91 DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore(ItemRandomSuffixfmt);
92 DBCStorage <ItemSetEntry> sItemSetStore(ItemSetEntryfmt);
94 DBCStorage <LockEntry> sLockStore(LockEntryfmt);
96 DBCStorage <MailTemplateEntry> sMailTemplateStore(MailTemplateEntryfmt);
97 DBCStorage <MapEntry> sMapStore(MapEntryfmt);
98 DBCStorage <MovieEntry> sMovieStore(MovieEntryfmt);
100 DBCStorage <QuestSortEntry> sQuestSortStore(QuestSortEntryfmt);
102 DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt);
103 DBCStorage <ScalingStatDistributionEntry> sScalingStatDistributionStore(ScalingStatDistributionfmt);
104 DBCStorage <ScalingStatValuesEntry> sScalingStatValuesStore(ScalingStatValuesfmt);
106 DBCStorage <SkillLineEntry> sSkillLineStore(SkillLinefmt);
107 DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore(SkillLineAbilityfmt);
109 DBCStorage <SoundEntriesEntry> sSoundEntriesStore(SoundEntriesfmt);
111 DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore(SpellItemEnchantmentfmt);
112 DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt);
113 DBCStorage <SpellEntry> sSpellStore(SpellEntryfmt);
114 SpellCategoryStore sSpellCategoryStore;
115 PetFamilySpellsStore sPetFamilySpellsStore;
117 DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore(SpellCastTimefmt);
118 DBCStorage <SpellDurationEntry> sSpellDurationStore(SpellDurationfmt);
119 DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore(SpellFocusObjectfmt);
120 DBCStorage <SpellRadiusEntry> sSpellRadiusStore(SpellRadiusfmt);
121 DBCStorage <SpellRangeEntry> sSpellRangeStore(SpellRangefmt);
122 DBCStorage <SpellRuneCostEntry> sSpellRuneCostStore(SpellRuneCostfmt);
123 DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftfmt);
124 DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore(StableSlotPricesfmt);
125 //DBCStorage <SummonPropertiesEntry> sSummonPropertiesStore(SummonPropertiesfmt);
126 DBCStorage <TalentEntry> sTalentStore(TalentEntryfmt);
127 TalentSpellPosMap sTalentSpellPosMap;
128 DBCStorage <TalentTabEntry> sTalentTabStore(TalentTabEntryfmt);
130 // store absolute bit position for first rank for talent inspect
131 static uint32 sTalentTabPages[12/*MAX_CLASSES*/][3];
133 DBCStorage <TaxiNodesEntry> sTaxiNodesStore(TaxiNodesEntryfmt);
134 TaxiMask sTaxiNodesMask;
135 TaxiMask sOldContinentsNodesMask;
137 // DBC used only for initialization sTaxiPathSetBySource at startup.
138 TaxiPathSetBySource sTaxiPathSetBySource;
139 DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt);
141 // DBC used only for initialization sTaxiPathSetBySource at startup.
142 TaxiPathNodesByPath sTaxiPathNodesByPath;
144 static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
145 DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt);
146 DBCStorage <VehicleEntry> sVehicleStore(VehicleEntryfmt);
147 DBCStorage <VehicleSeatEntry> sVehicleSeatStore(VehicleSeatEntryfmt);
148 DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore(WorldMapAreaEntryfmt);
149 DBCStorage <WorldMapOverlayEntry> sWorldMapOverlayStore(WorldMapOverlayEntryfmt);
150 DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt);
152 typedef std::list<std::string> StoreProblemList;
154 static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, const std::string& filename)
156 sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize);
158 // assert must fail after function call
159 return false;
162 template<class T>
163 inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, const std::string& dbc_path, const std::string& filename)
165 // compatibility format and C++ structure sizes
166 assert(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename));
168 std::string dbc_filename = dbc_path + filename;
169 if(storage.Load(dbc_filename.c_str()))
171 bar.step();
172 for(uint8 i = 0; i < MAX_LOCALE; ++i)
174 if(!(availableDbcLocales & (1 << i)))
175 continue;
177 std::string dbc_filename_loc = dbc_path + localeNames[i] + "/" + filename;
178 if(!storage.LoadStringsFrom(dbc_filename_loc.c_str()))
179 availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks
182 else
184 // sort problematic dbc to (1) non compatible and (2) non-existed
185 FILE * f=fopen(dbc_filename.c_str(),"rb");
186 if(f)
188 char buf[100];
189 snprintf(buf,100," (exist, but have %d fields instead %d) Wrong client version DBC file?",storage.GetFieldCount(),strlen(storage.GetFormat()));
190 errlist.push_back(dbc_filename + buf);
191 fclose(f);
193 else
194 errlist.push_back(dbc_filename);
198 void LoadDBCStores(const std::string& dataPath)
200 std::string dbcPath = dataPath+"dbc/";
202 const uint32 DBCFilesCount = 78;
204 barGoLink bar( DBCFilesCount );
206 StoreProblemList bad_dbc_files;
207 uint32 availableDbcLocales = 0xFFFFFFFF;
209 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaStore, dbcPath,"AreaTable.dbc");
211 // must be after sAreaStore loading
212 for(uint32 i = 0; i < sAreaStore.GetNumRows(); ++i) // areaflag numbered from 0
214 if(AreaTableEntry const* area = sAreaStore.LookupEntry(i))
216 // fill AreaId->DBC records
217 sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID),area->exploreFlag));
219 // fill MapId->DBC records ( skip sub zones and continents )
220 if(area->zone==0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530 && area->mapid != 571 )
221 sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid,area->exploreFlag));
225 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementStore, dbcPath,"Achievement.dbc");
226 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementCriteriaStore, dbcPath,"Achievement_Criteria.dbc");
227 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc");
228 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaGroupStore, dbcPath,"AreaGroup.dbc");
229 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAuctionHouseStore, dbcPath,"AuctionHouse.dbc");
230 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc");
231 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc");
232 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBarberShopStyleStore, dbcPath,"BarberShopStyle.dbc");
233 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharStartOutfitStore, dbcPath,"CharStartOutfit.dbc");
235 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore, dbcPath,"CharTitles.dbc");
236 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore, dbcPath,"ChatChannels.dbc");
237 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore, dbcPath,"ChrClasses.dbc");
238 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrRacesStore, dbcPath,"ChrRaces.dbc");
239 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCinematicSequencesStore, dbcPath,"CinematicSequences.dbc");
240 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureDisplayInfoStore, dbcPath,"CreatureDisplayInfo.dbc");
241 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureFamilyStore, dbcPath,"CreatureFamily.dbc");
242 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureSpellDataStore, dbcPath,"CreatureSpellData.dbc");
243 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureTypeStore, dbcPath,"CreatureType.dbc");
244 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCurrencyTypesStore, dbcPath,"CurrencyTypes.dbc");
245 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityCostsStore, dbcPath,"DurabilityCosts.dbc");
246 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityQualityStore, dbcPath,"DurabilityQuality.dbc");
247 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesStore, dbcPath,"Emotes.dbc");
248 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesTextStore, dbcPath,"EmotesText.dbc");
249 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionStore, dbcPath,"Faction.dbc");
250 for (uint32 i=0;i<sFactionStore.GetNumRows(); ++i)
252 FactionEntry const * faction = sFactionStore.LookupEntry(i);
253 if (faction && faction->team)
255 SimpleFactionsList &flist = sFactionTeamMap[faction->team];
256 flist.push_back(i);
260 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore, dbcPath,"FactionTemplate.dbc");
261 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc");
262 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphPropertiesStore, dbcPath,"GlyphProperties.dbc");
263 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphSlotStore, dbcPath,"GlyphSlot.dbc");
265 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtBarberShopCostBaseStore,dbcPath,"gtBarberShopCostBase.dbc");
266 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtCombatRatingsStore, dbcPath,"gtCombatRatings.dbc");
268 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritBaseStore, dbcPath,"gtChanceToMeleeCritBase.dbc");
269 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritStore, dbcPath,"gtChanceToMeleeCrit.dbc");
271 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritBaseStore, dbcPath,"gtChanceToSpellCritBase.dbc");
272 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritStore, dbcPath,"gtChanceToSpellCrit.dbc");
274 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenHPStore, dbcPath,"gtOCTRegenHP.dbc");
275 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore, dbcPath,"gtOCTRegenMP.dbc"); -- not used currently
276 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenHPPerSptStore, dbcPath,"gtRegenHPPerSpt.dbc");
277 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenMPPerSptStore, dbcPath,"gtRegenMPPerSpt.dbc");
278 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sHolidaysStore, dbcPath,"Holidays.dbc");
279 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemStore, dbcPath,"Item.dbc");
280 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemBagFamilyStore, dbcPath,"ItemBagFamily.dbc");
281 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore, dbcPath,"ItemDisplayInfo.dbc"); -- not used currently
282 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore, dbcPath,"ItemCondExtCosts.dbc");
283 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemExtendedCostStore, dbcPath,"ItemExtendedCost.dbc");
284 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemLimitCategoryStore, dbcPath,"ItemLimitCategory.dbc");
285 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomPropertiesStore,dbcPath,"ItemRandomProperties.dbc");
286 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomSuffixStore, dbcPath,"ItemRandomSuffix.dbc");
287 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemSetStore, dbcPath,"ItemSet.dbc");
288 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sLockStore, dbcPath,"Lock.dbc");
289 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMailTemplateStore, dbcPath,"MailTemplate.dbc");
290 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapStore, dbcPath,"Map.dbc");
291 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMovieStore, dbcPath,"Movie.dbc");
292 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sQuestSortStore, dbcPath,"QuestSort.dbc");
293 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sRandomPropertiesPointsStore, dbcPath,"RandPropPoints.dbc");
294 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatDistributionStore, dbcPath,"ScalingStatDistribution.dbc");
295 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatValuesStore, dbcPath,"ScalingStatValues.dbc");
296 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineStore, dbcPath,"SkillLine.dbc");
297 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineAbilityStore, dbcPath,"SkillLineAbility.dbc");
298 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSoundEntriesStore, dbcPath,"SoundEntries.dbc");
299 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellStore, dbcPath,"Spell.dbc");
300 for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
302 SpellEntry const * spell = sSpellStore.LookupEntry(i);
303 if(spell && spell->Category)
304 sSpellCategoryStore[spell->Category].insert(i);
306 // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields
307 // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view
308 #if MANGOS_ENDIAN == MANGOS_BIGENDIAN
309 std::swap(*((uint32*)(&spell->SpellFamilyFlags)),*(((uint32*)(&spell->SpellFamilyFlags))+1));
310 #endif
313 for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
315 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
317 if(!skillLine)
318 continue;
320 SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
322 if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0)
324 for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i)
326 CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i);
327 if(!cFamily)
328 continue;
330 if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1])
331 continue;
333 sPetFamilySpellsStore[i].insert(spellInfo->Id);
338 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellCastTimesStore, dbcPath,"SpellCastTimes.dbc");
339 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc");
340 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore, dbcPath,"SpellFocusObject.dbc");
341 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc");
342 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc");
343 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore, dbcPath,"SpellRadius.dbc");
344 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc");
345 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRuneCostStore, dbcPath,"SpellRuneCost.dbc");
346 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore, dbcPath,"SpellShapeshiftForm.dbc");
347 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sStableSlotPricesStore, dbcPath,"StableSlotPrices.dbc");
348 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSummonPropertiesStore, dbcPath,"SummonProperties.dbc");
349 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentStore, dbcPath,"Talent.dbc");
351 // create talent spells set
352 for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i)
354 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
355 if (!talentInfo) continue;
356 for (int j = 0; j < MAX_TALENT_RANK; j++)
357 if(talentInfo->RankID[j])
358 sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i,j);
361 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentTabStore, dbcPath,"TalentTab.dbc");
363 // prepare fast data access to bit pos of talent ranks for use at inspecting
365 // now have all max ranks (and then bit amount used for store talent ranks in inspect)
366 for(uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId)
368 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentTabId );
369 if(!talentTabInfo)
370 continue;
372 // prevent memory corruption; otherwise cls will become 12 below
373 if ((talentTabInfo->ClassMask & CLASSMASK_ALL_PLAYABLE)==0)
374 continue;
376 // store class talent tab pages
377 uint32 cls = 1;
378 for(uint32 m=1;!(m & talentTabInfo->ClassMask) && cls < MAX_CLASSES;m <<=1, ++cls) {}
380 sTalentTabPages[cls][talentTabInfo->tabpage]=talentTabId;
384 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiNodesStore, dbcPath,"TaxiNodes.dbc");
386 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathStore, dbcPath,"TaxiPath.dbc");
387 for(uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i)
388 if(TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i))
389 sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID,entry->price);
390 uint32 pathCount = sTaxiPathStore.GetNumRows();
392 //## TaxiPathNode.dbc ## Loaded only for initialization different structures
393 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathNodeStore, dbcPath,"TaxiPathNode.dbc");
394 // Calculate path nodes count
395 std::vector<uint32> pathLength;
396 pathLength.resize(pathCount); // 0 and some other indexes not used
397 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
398 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
400 if (pathLength[entry->path] < entry->index + 1)
401 pathLength[entry->path] = entry->index + 1;
403 // Set path length
404 sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used
405 for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i)
406 sTaxiPathNodesByPath[i].resize(pathLength[i]);
407 // fill data
408 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
409 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
410 sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay);
411 sTaxiPathNodeStore.Clear();
413 // Initialize global taxinodes mask
414 // include existed nodes that have at least single not spell base (scripted) path
416 std::set<uint32> spellPaths;
417 for(uint32 i = 1; i < sSpellStore.GetNumRows (); ++i)
418 if(SpellEntry const* sInfo = sSpellStore.LookupEntry (i))
419 for(int j=0; j < 3; ++j)
420 if(sInfo->Effect[j]==123 /*SPELL_EFFECT_SEND_TAXI*/)
421 spellPaths.insert(sInfo->EffectMiscValue[j]);
423 memset(sTaxiNodesMask,0,sizeof(sTaxiNodesMask));
424 memset(sOldContinentsNodesMask,0,sizeof(sTaxiNodesMask));
425 for(uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i)
427 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i);
428 if(!node)
429 continue;
431 TaxiPathSetBySource::const_iterator src_i = sTaxiPathSetBySource.find(i);
432 if(src_i!=sTaxiPathSetBySource.end() && !src_i->second.empty())
434 bool ok = false;
435 for(TaxiPathSetForSource::const_iterator dest_i = src_i->second.begin();dest_i != src_i->second.end(); ++dest_i)
437 // not spell path
438 if(spellPaths.find(dest_i->second.ID)==spellPaths.end())
440 ok = true;
441 break;
445 if(!ok)
446 continue;
449 // valid taxi network node
450 uint8 field = (uint8)((i - 1) / 32);
451 uint32 submask = 1<<((i-1)%32);
452 sTaxiNodesMask[field] |= submask;
454 // old continent node (+ nodes virtually at old continents, check explicitly to avoid loading map files for zone info)
455 if (node->map_id < 2 || i == 82 || i == 83 || i == 93 || i == 94)
456 sOldContinentsNodesMask[field] |= submask;
460 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTotemCategoryStore, dbcPath,"TotemCategory.dbc");
461 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleStore, dbcPath,"Vehicle.dbc");
462 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleSeatStore, dbcPath,"VehicleSeat.dbc");
463 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapAreaStore, dbcPath,"WorldMapArea.dbc");
464 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapOverlayStore, dbcPath,"WorldMapOverlay.dbc");
465 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldSafeLocsStore, dbcPath,"WorldSafeLocs.dbc");
467 // error checks
468 if(bad_dbc_files.size() >= DBCFilesCount )
470 sLog.outError("\nIncorrect DataDir value in mangosd.conf or ALL required *.dbc files (%d) not found by path: %sdbc",DBCFilesCount,dataPath.c_str());
471 exit(1);
473 else if(!bad_dbc_files.empty() )
475 std::string str;
476 for(std::list<std::string>::iterator i = bad_dbc_files.begin(); i != bad_dbc_files.end(); ++i)
477 str += *i + "\n";
479 sLog.outError("\nSome required *.dbc files (%u from %d) not found or not compatible:\n%s",(uint32)bad_dbc_files.size(),DBCFilesCount,str.c_str());
480 exit(1);
483 // Check loaded DBC files proper version
484 if( !sSpellStore.LookupEntry(65509) || // last added spell in 3.1.1
485 !sMapStore.LookupEntry(624) || // last map added in 3.1.1
486 !sGemPropertiesStore.LookupEntry(1609) || // last gem property added in 3.1.1
487 !sItemExtendedCostStore.LookupEntry(2670) || // last item extended cost added in 3.1.1
488 !sCharTitlesStore.LookupEntry(166) || // last char title added in 3.1.1
489 !sAreaStore.LookupEntry(2905) || // last area (areaflag) added in 3.1.1
490 !sItemStore.LookupEntry(46379) ) // last client known item added in 3.1.1
492 sLog.outError("\nYou have _outdated_ DBC files. Please extract correct versions from current using client.");
493 exit(1);
496 sLog.outString();
497 sLog.outString( ">> Initialized %d data stores", DBCFilesCount );
500 SimpleFactionsList const* GetFactionTeamList(uint32 faction)
502 FactionTeamMap::const_iterator itr = sFactionTeamMap.find(faction);
503 if(itr==sFactionTeamMap.end())
504 return NULL;
505 return &itr->second;
508 char* GetPetName(uint32 petfamily, uint32 dbclang)
510 if(!petfamily)
511 return NULL;
512 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(petfamily);
513 if(!pet_family)
514 return NULL;
515 return pet_family->Name[dbclang]?pet_family->Name[dbclang]:NULL;
518 TalentSpellPos const* GetTalentSpellPos(uint32 spellId)
520 TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId);
521 if(itr==sTalentSpellPosMap.end())
522 return NULL;
524 return &itr->second;
527 uint32 GetTalentSpellCost(uint32 spellId)
529 if(TalentSpellPos const* pos = GetTalentSpellPos(spellId))
530 return pos->rank+1;
532 return 0;
535 int32 GetAreaFlagByAreaID(uint32 area_id)
537 AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id);
538 if(i == sAreaFlagByAreaID.end())
539 return -1;
541 return i->second;
544 AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
546 int32 areaflag = GetAreaFlagByAreaID(area_id);
547 if(areaflag < 0)
548 return NULL;
550 return sAreaStore.LookupEntry(areaflag );
553 AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id)
555 if(area_flag)
556 return sAreaStore.LookupEntry(area_flag);
558 if(MapEntry const* mapEntry = sMapStore.LookupEntry(map_id))
559 return GetAreaEntryByAreaID(mapEntry->linked_zone);
561 return NULL;
564 uint32 GetAreaFlagByMapId(uint32 mapid)
566 AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid);
567 if(i == sAreaFlagByMapID.end())
568 return 0;
569 else
570 return i->second;
573 uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId)
575 if(mapid != 530 && mapid != 571) // speed for most cases
576 return mapid;
578 if(WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId))
579 return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id;
581 return mapid;
584 ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId)
586 mapid = GetVirtualMapForMapAndZone(mapid,zoneId);
587 if(mapid < 2)
588 return CONTENT_1_60;
590 MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
591 if(!mapEntry)
592 return CONTENT_1_60;
594 switch(mapEntry->Expansion())
596 default: return CONTENT_1_60;
597 case 1: return CONTENT_61_70;
598 case 2: return CONTENT_71_80;
602 ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id)
604 // not sorted, numbering index from 0
605 for(uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
607 ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i);
608 if(ch && ch->ChannelID == channel_id)
609 return ch;
611 return NULL;
614 bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId)
616 if(requiredTotemCategoryId==0)
617 return true;
618 if(itemTotemCategoryId==0)
619 return false;
621 TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId);
622 if(!itemEntry)
623 return false;
624 TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId);
625 if(!reqEntry)
626 return false;
628 if(itemEntry->categoryType!=reqEntry->categoryType)
629 return false;
631 return (itemEntry->categoryMask & reqEntry->categoryMask)==reqEntry->categoryMask;
634 void Zone2MapCoordinates(float& x,float& y,uint32 zone)
636 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
638 // if not listed then map coordinates (instance)
639 if(!maEntry)
640 return;
642 std::swap(x,y); // at client map coords swapped
643 x = x*((maEntry->x2-maEntry->x1)/100)+maEntry->x1;
644 y = y*((maEntry->y2-maEntry->y1)/100)+maEntry->y1; // client y coord from top to down
647 void Map2ZoneCoordinates(float& x,float& y,uint32 zone)
649 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
651 // if not listed then map coordinates (instance)
652 if(!maEntry)
653 return;
655 x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100);
656 y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100); // client y coord from top to down
657 std::swap(x,y); // client have map coords swapped
660 uint32 const* GetTalentTabPages(uint32 cls)
662 return sTalentTabPages[cls];
665 // script support functions
666 MANGOS_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore() { return &sSoundEntriesStore; }
667 MANGOS_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore() { return &sSpellStore; }
668 MANGOS_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore() { return &sSpellRangeStore; }
669 MANGOS_DLL_SPEC DBCStorage <FactionEntry> const* GetFactionStore() { return &sFactionStore; }
670 MANGOS_DLL_SPEC DBCStorage <ItemEntry> const* GetItemDisplayStore() { return &sItemStore; }
671 MANGOS_DLL_SPEC DBCStorage <CreatureDisplayInfoEntry> const* GetCreatureDisplayStore() { return &sCreatureDisplayInfoStore; }
672 MANGOS_DLL_SPEC DBCStorage <EmotesEntry> const* GetEmotesStore() { return &sEmotesStore; }
673 MANGOS_DLL_SPEC DBCStorage <EmotesTextEntry> const* GetEmotesTextStore() { return &sEmotesTextStore; }