[7602] Fixed possible crash at instant stealth aura apply interrupt at internal visib...
[AHbot.git] / src / game / DBCStores.cpp
blob983b686903d23fdd10bb22df066c7c40b04414e0
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 <CreatureDisplayInfoEntry> sCreatureDisplayInfoStore(CreatureDisplayInfofmt);
50 DBCStorage <CreatureFamilyEntry> sCreatureFamilyStore(CreatureFamilyfmt);
51 DBCStorage <CreatureSpellDataEntry> sCreatureSpellDataStore(CreatureSpellDatafmt);
52 DBCStorage <CreatureTypeEntry> sCreatureTypeStore(CreatureTypefmt);
53 DBCStorage <CurrencyTypesEntry> sCurrencyTypesStore(CurrencyTypesfmt);
55 DBCStorage <DurabilityQualityEntry> sDurabilityQualityStore(DurabilityQualityfmt);
56 DBCStorage <DurabilityCostsEntry> sDurabilityCostsStore(DurabilityCostsfmt);
58 DBCStorage <EmotesTextEntry> sEmotesTextStore(EmoteEntryfmt);
60 typedef std::map<uint32,SimpleFactionsList> FactionTeamMap;
61 static FactionTeamMap sFactionTeamMap;
62 DBCStorage <FactionEntry> sFactionStore(FactionEntryfmt);
63 DBCStorage <FactionTemplateEntry> sFactionTemplateStore(FactionTemplateEntryfmt);
65 DBCStorage <GemPropertiesEntry> sGemPropertiesStore(GemPropertiesEntryfmt);
66 DBCStorage <GlyphPropertiesEntry> sGlyphPropertiesStore(GlyphPropertiesfmt);
67 DBCStorage <GlyphSlotEntry> sGlyphSlotStore(GlyphSlotfmt);
69 DBCStorage <GtBarberShopCostBaseEntry> sGtBarberShopCostBaseStore(GtBarberShopCostBasefmt);
70 DBCStorage <GtCombatRatingsEntry> sGtCombatRatingsStore(GtCombatRatingsfmt);
71 DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore(GtChanceToMeleeCritBasefmt);
72 DBCStorage <GtChanceToMeleeCritEntry> sGtChanceToMeleeCritStore(GtChanceToMeleeCritfmt);
73 DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore(GtChanceToSpellCritBasefmt);
74 DBCStorage <GtChanceToSpellCritEntry> sGtChanceToSpellCritStore(GtChanceToSpellCritfmt);
75 DBCStorage <GtOCTRegenHPEntry> sGtOCTRegenHPStore(GtOCTRegenHPfmt);
76 //DBCStorage <GtOCTRegenMPEntry> sGtOCTRegenMPStore(GtOCTRegenMPfmt); -- not used currently
77 DBCStorage <GtRegenHPPerSptEntry> sGtRegenHPPerSptStore(GtRegenHPPerSptfmt);
78 DBCStorage <GtRegenMPPerSptEntry> sGtRegenMPPerSptStore(GtRegenMPPerSptfmt);
79 DBCStorage <HolidaysEntry> sHolidaysStore(Holidaysfmt);
80 DBCStorage <ItemEntry> sItemStore(Itemfmt);
81 DBCStorage <ItemBagFamilyEntry> sItemBagFamilyStore(ItemBagFamilyfmt);
82 //DBCStorage <ItemCondExtCostsEntry> sItemCondExtCostsStore(ItemCondExtCostsEntryfmt);
83 //DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently
84 DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt);
85 DBCStorage <ItemLimitCategoryEntry> sItemLimitCategoryStore(ItemLimitCategoryEntryfmt);
86 DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore(ItemRandomPropertiesfmt);
87 DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore(ItemRandomSuffixfmt);
88 DBCStorage <ItemSetEntry> sItemSetStore(ItemSetEntryfmt);
90 DBCStorage <LockEntry> sLockStore(LockEntryfmt);
92 DBCStorage <MailTemplateEntry> sMailTemplateStore(MailTemplateEntryfmt);
93 DBCStorage <MapEntry> sMapStore(MapEntryfmt);
95 DBCStorage <QuestSortEntry> sQuestSortStore(QuestSortEntryfmt);
97 DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt);
98 DBCStorage <ScalingStatDistributionEntry> sScalingStatDistributionStore(ScalingStatDistributionfmt);
99 DBCStorage <ScalingStatValuesEntry> sScalingStatValuesStore(ScalingStatValuesfmt);
101 DBCStorage <SkillLineEntry> sSkillLineStore(SkillLinefmt);
102 DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore(SkillLineAbilityfmt);
104 DBCStorage <SoundEntriesEntry> sSoundEntriesStore(SoundEntriesfmt);
106 DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore(SpellItemEnchantmentfmt);
107 DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt);
108 DBCStorage <SpellEntry> sSpellStore(SpellEntryfmt);
109 SpellCategoryStore sSpellCategoryStore;
110 PetFamilySpellsStore sPetFamilySpellsStore;
112 DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore(SpellCastTimefmt);
113 DBCStorage <SpellDurationEntry> sSpellDurationStore(SpellDurationfmt);
114 DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore(SpellFocusObjectfmt);
115 DBCStorage <SpellRadiusEntry> sSpellRadiusStore(SpellRadiusfmt);
116 DBCStorage <SpellRangeEntry> sSpellRangeStore(SpellRangefmt);
117 DBCStorage <SpellRuneCostEntry> sSpellRuneCostStore(SpellRuneCostfmt);
118 DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftfmt);
119 DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore(StableSlotPricesfmt);
120 //DBCStorage <SummonPropertiesEntry> sSummonPropertiesStore(SummonPropertiesfmt);
121 DBCStorage <TalentEntry> sTalentStore(TalentEntryfmt);
122 TalentSpellPosMap sTalentSpellPosMap;
123 DBCStorage <TalentTabEntry> sTalentTabStore(TalentTabEntryfmt);
125 // store absolute bit position for first rank for talent inspect
126 typedef std::map<uint32,uint32> TalentInspectMap;
127 static TalentInspectMap sTalentPosInInspect;
128 static TalentInspectMap sTalentTabSizeInInspect;
129 static uint32 sTalentTabPages[12/*MAX_CLASSES*/][3];
131 DBCStorage <TaxiNodesEntry> sTaxiNodesStore(TaxiNodesEntryfmt);
132 TaxiMask sTaxiNodesMask;
133 TaxiMask sOldContinentsNodesMask;
135 // DBC used only for initialization sTaxiPathSetBySource at startup.
136 TaxiPathSetBySource sTaxiPathSetBySource;
137 DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt);
139 // DBC used only for initialization sTaxiPathSetBySource at startup.
140 TaxiPathNodesByPath sTaxiPathNodesByPath;
142 static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
143 DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt);
144 DBCStorage <VehicleEntry> sVehicleStore(VehicleEntryfmt);
145 DBCStorage <VehicleSeatEntry> sVehicleSeatStore(VehicleSeatEntryfmt);
146 DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore(WorldMapAreaEntryfmt);
147 DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt);
148 DBCStorage <WorldMapOverlayEntry> sWorldMapOverlayStore(WorldMapOverlayEntryfmt);
150 typedef std::list<std::string> StoreProblemList;
152 static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, const std::string& filename)
154 sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize);
156 // assert must fail after function call
157 return false;
160 template<class T>
161 inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, const std::string& dbc_path, const std::string& filename)
163 // compatibility format and C++ structure sizes
164 assert(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename));
166 std::string dbc_filename = dbc_path + filename;
167 if(storage.Load(dbc_filename.c_str()))
169 bar.step();
170 for(uint8 i = 0; i < MAX_LOCALE; ++i)
172 if(!(availableDbcLocales & (1 << i)))
173 continue;
175 std::string dbc_filename_loc = dbc_path + localeNames[i] + "/" + filename;
176 if(!storage.LoadStringsFrom(dbc_filename_loc.c_str()))
177 availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks
180 else
182 // sort problematic dbc to (1) non compatible and (2) non-existed
183 FILE * f=fopen(dbc_filename.c_str(),"rb");
184 if(f)
186 char buf[100];
187 snprintf(buf,100," (exist, but have %d fields instead %d) Wrong client version DBC file?",storage.GetFieldCount(),strlen(storage.GetFormat()));
188 errlist.push_back(dbc_filename + buf);
189 fclose(f);
191 else
192 errlist.push_back(dbc_filename);
196 void LoadDBCStores(const std::string& dataPath)
198 std::string dbcPath = dataPath+"dbc/";
200 const uint32 DBCFilesCount = 75;
202 barGoLink bar( DBCFilesCount );
204 StoreProblemList bad_dbc_files;
205 uint32 availableDbcLocales = 0xFFFFFFFF;
207 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaStore, dbcPath,"AreaTable.dbc");
209 // must be after sAreaStore loading
210 for(uint32 i = 0; i < sAreaStore.GetNumRows(); ++i) // areaflag numbered from 0
212 if(AreaTableEntry const* area = sAreaStore.LookupEntry(i))
214 // fill AreaId->DBC records
215 sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID),area->exploreFlag));
217 // fill MapId->DBC records ( skip sub zones and continents )
218 if(area->zone==0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530 && area->mapid != 571 )
219 sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid,area->exploreFlag));
223 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementStore, dbcPath,"Achievement.dbc");
224 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementCriteriaStore, dbcPath,"Achievement_Criteria.dbc");
225 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc");
226 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaGroupStore, dbcPath,"AreaGroup.dbc");
227 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAuctionHouseStore, dbcPath,"AuctionHouse.dbc");
228 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc");
229 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc");
230 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBarberShopStyleStore, dbcPath,"BarberShopStyle.dbc");
231 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharStartOutfitStore, dbcPath,"CharStartOutfit.dbc");
233 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore, dbcPath,"CharTitles.dbc");
234 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore, dbcPath,"ChatChannels.dbc");
235 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore, dbcPath,"ChrClasses.dbc");
236 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrRacesStore, dbcPath,"ChrRaces.dbc");
237 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureDisplayInfoStore, dbcPath,"CreatureDisplayInfo.dbc");
238 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureFamilyStore, dbcPath,"CreatureFamily.dbc");
239 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureSpellDataStore, dbcPath,"CreatureSpellData.dbc");
240 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureTypeStore, dbcPath,"CreatureType.dbc");
241 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCurrencyTypesStore, dbcPath,"CurrencyTypes.dbc");
242 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityCostsStore, dbcPath,"DurabilityCosts.dbc");
243 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityQualityStore, dbcPath,"DurabilityQuality.dbc");
244 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesTextStore, dbcPath,"EmotesText.dbc");
245 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionStore, dbcPath,"Faction.dbc");
246 for (uint32 i=0;i<sFactionStore.GetNumRows(); ++i)
248 FactionEntry const * faction = sFactionStore.LookupEntry(i);
249 if (faction && faction->team)
251 SimpleFactionsList &flist = sFactionTeamMap[faction->team];
252 flist.push_back(i);
256 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore, dbcPath,"FactionTemplate.dbc");
257 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc");
258 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphPropertiesStore, dbcPath,"GlyphProperties.dbc");
259 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphSlotStore, dbcPath,"GlyphSlot.dbc");
261 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtBarberShopCostBaseStore,dbcPath,"gtBarberShopCostBase.dbc");
262 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtCombatRatingsStore, dbcPath,"gtCombatRatings.dbc");
264 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritBaseStore, dbcPath,"gtChanceToMeleeCritBase.dbc");
265 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritStore, dbcPath,"gtChanceToMeleeCrit.dbc");
267 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritBaseStore, dbcPath,"gtChanceToSpellCritBase.dbc");
268 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritStore, dbcPath,"gtChanceToSpellCrit.dbc");
270 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenHPStore, dbcPath,"gtOCTRegenHP.dbc");
271 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore, dbcPath,"gtOCTRegenMP.dbc"); -- not used currently
272 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenHPPerSptStore, dbcPath,"gtRegenHPPerSpt.dbc");
273 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenMPPerSptStore, dbcPath,"gtRegenMPPerSpt.dbc");
274 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sHolidaysStore, dbcPath,"Holidays.dbc");
275 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemStore, dbcPath,"Item.dbc");
276 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemBagFamilyStore, dbcPath,"ItemBagFamily.dbc");
277 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore, dbcPath,"ItemDisplayInfo.dbc"); -- not used currently
278 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore, dbcPath,"ItemCondExtCosts.dbc");
279 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemExtendedCostStore, dbcPath,"ItemExtendedCost.dbc");
280 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemLimitCategoryStore, dbcPath,"ItemLimitCategory.dbc");
281 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomPropertiesStore,dbcPath,"ItemRandomProperties.dbc");
282 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomSuffixStore, dbcPath,"ItemRandomSuffix.dbc");
283 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemSetStore, dbcPath,"ItemSet.dbc");
284 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sLockStore, dbcPath,"Lock.dbc");
285 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMailTemplateStore, dbcPath,"MailTemplate.dbc");
286 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapStore, dbcPath,"Map.dbc");
287 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sQuestSortStore, dbcPath,"QuestSort.dbc");
288 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sRandomPropertiesPointsStore, dbcPath,"RandPropPoints.dbc");
289 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatDistributionStore, dbcPath,"ScalingStatDistribution.dbc");
290 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatValuesStore, dbcPath,"ScalingStatValues.dbc");
291 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineStore, dbcPath,"SkillLine.dbc");
292 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineAbilityStore, dbcPath,"SkillLineAbility.dbc");
293 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSoundEntriesStore, dbcPath,"SoundEntries.dbc");
294 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellStore, dbcPath,"Spell.dbc");
295 for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
297 SpellEntry const * spell = sSpellStore.LookupEntry(i);
298 if(spell && spell->Category)
299 sSpellCategoryStore[spell->Category].insert(i);
301 // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields
302 // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view
303 #if MANGOS_ENDIAN == MANGOS_BIGENDIAN
304 std::swap(*((uint32*)(&spell->SpellFamilyFlags)),*(((uint32*)(&spell->SpellFamilyFlags))+1));
305 #endif
308 for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
310 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
312 if(!skillLine)
313 continue;
315 SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
317 if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0)
319 for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i)
321 CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i);
322 if(!cFamily)
323 continue;
325 if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1])
326 continue;
328 sPetFamilySpellsStore[i].insert(spellInfo->Id);
333 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellCastTimesStore, dbcPath,"SpellCastTimes.dbc");
334 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc");
335 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore, dbcPath,"SpellFocusObject.dbc");
336 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc");
337 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc");
338 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore, dbcPath,"SpellRadius.dbc");
339 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc");
340 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRuneCostStore, dbcPath,"SpellRuneCost.dbc");
341 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore, dbcPath,"SpellShapeshiftForm.dbc");
342 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sStableSlotPricesStore, dbcPath,"StableSlotPrices.dbc");
343 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSummonPropertiesStore, dbcPath,"SummonProperties.dbc");
344 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentStore, dbcPath,"Talent.dbc");
346 // create talent spells set
347 for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i)
349 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
350 if (!talentInfo) continue;
351 for (int j = 0; j < MAX_TALENT_RANK; j++)
352 if(talentInfo->RankID[j])
353 sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i,j);
356 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentTabStore, dbcPath,"TalentTab.dbc");
358 // prepare fast data access to bit pos of talent ranks for use at inspecting
360 // fill table by amount of talent ranks and fill sTalentTabBitSizeInInspect
361 // store in with (row,col,talent)->size key for correct sorting by (row,col)
362 typedef std::map<uint32,uint32> TalentBitSize;
363 TalentBitSize sTalentBitSize;
364 for(uint32 i = 1; i < sTalentStore.GetNumRows(); ++i)
366 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
367 if (!talentInfo) continue;
369 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
370 if(!talentTabInfo)
371 continue;
373 // find talent rank
374 uint32 curtalent_maxrank = 0;
375 for(uint32 k = MAX_TALENT_RANK; k > 0; --k)
377 if(talentInfo->RankID[k-1])
379 curtalent_maxrank = k;
380 break;
384 sTalentBitSize[(talentInfo->Row<<24) + (talentInfo->Col<<16)+talentInfo->TalentID] = curtalent_maxrank;
385 sTalentTabSizeInInspect[talentInfo->TalentTab] += curtalent_maxrank;
388 // now have all max ranks (and then bit amount used for store talent ranks in inspect)
389 for(uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId)
391 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentTabId );
392 if(!talentTabInfo)
393 continue;
395 // prevent memory corruption; otherwise cls will become 12 below
396 if ((talentTabInfo->ClassMask & CLASSMASK_ALL_PLAYABLE)==0)
397 continue;
399 // store class talent tab pages
400 uint32 cls = 1;
401 for(uint32 m=1;!(m & talentTabInfo->ClassMask) && cls < MAX_CLASSES;m <<=1, ++cls) {}
403 sTalentTabPages[cls][talentTabInfo->tabpage]=talentTabId;
405 // add total amount bits for first rank starting from talent tab first talent rank pos.
406 uint32 pos = 0;
407 for(TalentBitSize::iterator itr = sTalentBitSize.begin(); itr != sTalentBitSize.end(); ++itr)
409 uint32 talentId = itr->first & 0xFFFF;
410 TalentEntry const *talentInfo = sTalentStore.LookupEntry( talentId );
411 if(!talentInfo)
412 continue;
414 if(talentInfo->TalentTab != talentTabId)
415 continue;
417 sTalentPosInInspect[talentId] = pos;
418 pos+= itr->second;
423 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiNodesStore, dbcPath,"TaxiNodes.dbc");
425 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathStore, dbcPath,"TaxiPath.dbc");
426 for(uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i)
427 if(TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i))
428 sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID,entry->price);
429 uint32 pathCount = sTaxiPathStore.GetNumRows();
431 //## TaxiPathNode.dbc ## Loaded only for initialization different structures
432 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathNodeStore, dbcPath,"TaxiPathNode.dbc");
433 // Calculate path nodes count
434 std::vector<uint32> pathLength;
435 pathLength.resize(pathCount); // 0 and some other indexes not used
436 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
437 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
439 if (pathLength[entry->path] < entry->index + 1)
440 pathLength[entry->path] = entry->index + 1;
442 // Set path length
443 sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used
444 for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i)
445 sTaxiPathNodesByPath[i].resize(pathLength[i]);
446 // fill data
447 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
448 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
449 sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay);
450 sTaxiPathNodeStore.Clear();
452 // Initialize global taxinodes mask
453 // include existed nodes that have at least single not spell base (scripted) path
455 std::set<uint32> spellPaths;
456 for(uint32 i = 1; i < sSpellStore.GetNumRows (); ++i)
457 if(SpellEntry const* sInfo = sSpellStore.LookupEntry (i))
458 for(int j=0; j < 3; ++j)
459 if(sInfo->Effect[j]==123 /*SPELL_EFFECT_SEND_TAXI*/)
460 spellPaths.insert(sInfo->EffectMiscValue[j]);
462 memset(sTaxiNodesMask,0,sizeof(sTaxiNodesMask));
463 memset(sOldContinentsNodesMask,0,sizeof(sTaxiNodesMask));
464 for(uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i)
466 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i);
467 if(!node)
468 continue;
470 TaxiPathSetBySource::const_iterator src_i = sTaxiPathSetBySource.find(i);
471 if(src_i!=sTaxiPathSetBySource.end() && !src_i->second.empty())
473 bool ok = false;
474 for(TaxiPathSetForSource::const_iterator dest_i = src_i->second.begin();dest_i != src_i->second.end(); ++dest_i)
476 // not spell path
477 if(spellPaths.find(dest_i->second.ID)==spellPaths.end())
479 ok = true;
480 break;
484 if(!ok)
485 continue;
488 // valid taxi network node
489 uint8 field = (uint8)((i - 1) / 32);
490 uint32 submask = 1<<((i-1)%32);
491 sTaxiNodesMask[field] |= submask;
493 // old continent node (+ nodes virtually at old continents, check explicitly to avoid loading map files for zone info)
494 if (node->map_id < 2 || i == 82 || i == 83 || i == 93 || i == 94)
495 sOldContinentsNodesMask[field] |= submask;
499 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTotemCategoryStore, dbcPath,"TotemCategory.dbc");
500 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleStore, dbcPath,"Vehicle.dbc");
501 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleSeatStore, dbcPath,"VehicleSeat.dbc");
502 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapAreaStore, dbcPath,"WorldMapArea.dbc");
503 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldSafeLocsStore, dbcPath,"WorldSafeLocs.dbc");
504 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapOverlayStore, dbcPath,"WorldMapOverlay.dbc");
506 // error checks
507 if(bad_dbc_files.size() >= DBCFilesCount )
509 sLog.outError("\nIncorrect DataDir value in mangosd.conf or ALL required *.dbc files (%d) not found by path: %sdbc",DBCFilesCount,dataPath.c_str());
510 exit(1);
512 else if(!bad_dbc_files.empty() )
514 std::string str;
515 for(std::list<std::string>::iterator i = bad_dbc_files.begin(); i != bad_dbc_files.end(); ++i)
516 str += *i + "\n";
518 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());
519 exit(1);
522 // Check loaded DBC files proper version
523 if( !sSpellStore.LookupEntry(62735) || // last added spell in 3.0.9
524 !sMapStore.LookupEntry(624) || // last map added in 3.0.8a/3.0.9
525 !sGemPropertiesStore.LookupEntry(1557) || // last gem property added in 3.0.8a/3.0.9
526 !sItemExtendedCostStore.LookupEntry(2589) || // last item extended cost added in 3.0.8a/3.0.9
527 !sCharTitlesStore.LookupEntry(144) || // last char title added in 3.0.8a/3.0.9
528 !sAreaStore.LookupEntry(2769) || // last area (areaflag) added in 3.0.8a/3.0.9
529 !sItemStore.LookupEntry(45037) ) // last client known item added in 3.0.9
531 sLog.outError("\nYou have _outdated_ DBC files. Please extract correct versions from current using client.");
532 exit(1);
535 sLog.outString();
536 sLog.outString( ">> Initialized %d data stores", DBCFilesCount );
539 SimpleFactionsList const* GetFactionTeamList(uint32 faction)
541 FactionTeamMap::const_iterator itr = sFactionTeamMap.find(faction);
542 if(itr==sFactionTeamMap.end())
543 return NULL;
544 return &itr->second;
547 char* GetPetName(uint32 petfamily, uint32 dbclang)
549 if(!petfamily)
550 return NULL;
551 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(petfamily);
552 if(!pet_family)
553 return NULL;
554 return pet_family->Name[dbclang]?pet_family->Name[dbclang]:NULL;
557 TalentSpellPos const* GetTalentSpellPos(uint32 spellId)
559 TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId);
560 if(itr==sTalentSpellPosMap.end())
561 return NULL;
563 return &itr->second;
566 uint32 GetTalentSpellCost(uint32 spellId)
568 if(TalentSpellPos const* pos = GetTalentSpellPos(spellId))
569 return pos->rank+1;
571 return 0;
574 int32 GetAreaFlagByAreaID(uint32 area_id)
576 AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id);
577 if(i == sAreaFlagByAreaID.end())
578 return -1;
580 return i->second;
583 AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
585 int32 areaflag = GetAreaFlagByAreaID(area_id);
586 if(areaflag < 0)
587 return NULL;
589 return sAreaStore.LookupEntry(areaflag );
592 AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id)
594 if(area_flag)
595 return sAreaStore.LookupEntry(area_flag);
597 if(MapEntry const* mapEntry = sMapStore.LookupEntry(map_id))
598 return GetAreaEntryByAreaID(mapEntry->linked_zone);
600 return NULL;
603 uint32 GetAreaFlagByMapId(uint32 mapid)
605 AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid);
606 if(i == sAreaFlagByMapID.end())
607 return 0;
608 else
609 return i->second;
612 uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId)
614 if(mapid != 530 && mapid != 571) // speed for most cases
615 return mapid;
617 if(WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId))
618 return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id;
620 return mapid;
623 ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId)
625 mapid = GetVirtualMapForMapAndZone(mapid,zoneId);
626 if(mapid < 2)
627 return CONTENT_1_60;
629 MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
630 if(!mapEntry)
631 return CONTENT_1_60;
633 switch(mapEntry->Expansion())
635 default: return CONTENT_1_60;
636 case 1: return CONTENT_61_70;
637 case 2: return CONTENT_71_80;
641 ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id)
643 // not sorted, numbering index from 0
644 for(uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
646 ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i);
647 if(ch && ch->ChannelID == channel_id)
648 return ch;
650 return NULL;
653 bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId)
655 if(requiredTotemCategoryId==0)
656 return true;
657 if(itemTotemCategoryId==0)
658 return false;
660 TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId);
661 if(!itemEntry)
662 return false;
663 TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId);
664 if(!reqEntry)
665 return false;
667 if(itemEntry->categoryType!=reqEntry->categoryType)
668 return false;
670 return (itemEntry->categoryMask & reqEntry->categoryMask)==reqEntry->categoryMask;
673 void Zone2MapCoordinates(float& x,float& y,uint32 zone)
675 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
677 // if not listed then map coordinates (instance)
678 if(!maEntry)
679 return;
681 std::swap(x,y); // at client map coords swapped
682 x = x*((maEntry->x2-maEntry->x1)/100)+maEntry->x1;
683 y = y*((maEntry->y2-maEntry->y1)/100)+maEntry->y1; // client y coord from top to down
686 void Map2ZoneCoordinates(float& x,float& y,uint32 zone)
688 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
690 // if not listed then map coordinates (instance)
691 if(!maEntry)
692 return;
694 x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100);
695 y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100); // client y coord from top to down
696 std::swap(x,y); // client have map coords swapped
699 uint32 GetTalentInspectBitPosInTab(uint32 talentId)
701 TalentInspectMap::const_iterator itr = sTalentPosInInspect.find(talentId);
702 if(itr == sTalentPosInInspect.end())
703 return 0;
705 return itr->second;
708 uint32 GetTalentTabInspectBitSize(uint32 talentTabId)
710 TalentInspectMap::const_iterator itr = sTalentTabSizeInInspect.find(talentTabId);
711 if(itr == sTalentTabSizeInInspect.end())
712 return 0;
714 return itr->second;
717 uint32 const* GetTalentTabPages(uint32 cls)
719 return sTalentTabPages[cls];
722 // script support functions
723 MANGOS_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore() { return &sSoundEntriesStore; }
724 MANGOS_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore() { return &sSpellStore; }
725 MANGOS_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore() { return &sSpellRangeStore; }
726 MANGOS_DLL_SPEC DBCStorage <FactionEntry> const* GetFactionStore() { return &sFactionStore; }
727 MANGOS_DLL_SPEC DBCStorage <ItemEntry> const* GetItemDisplayStore() { return &sItemStore; }
728 MANGOS_DLL_SPEC DBCStorage <CreatureDisplayInfoEntry> const* GetCreatureDisplayStore() { return &sCreatureDisplayInfoStore; }