[7616] Implement .debug play cinematic and .debig play movie. Rename .debug playsound...
[AHbot.git] / src / game / DBCStores.cpp
blob1d5fbb78f71826d62d30ce083e0c7b3d575fcd9c
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 <EmotesTextEntry> sEmotesTextStore(EmoteEntryfmt);
61 typedef std::map<uint32,SimpleFactionsList> FactionTeamMap;
62 static FactionTeamMap sFactionTeamMap;
63 DBCStorage <FactionEntry> sFactionStore(FactionEntryfmt);
64 DBCStorage <FactionTemplateEntry> sFactionTemplateStore(FactionTemplateEntryfmt);
66 DBCStorage <GemPropertiesEntry> sGemPropertiesStore(GemPropertiesEntryfmt);
67 DBCStorage <GlyphPropertiesEntry> sGlyphPropertiesStore(GlyphPropertiesfmt);
68 DBCStorage <GlyphSlotEntry> sGlyphSlotStore(GlyphSlotfmt);
70 DBCStorage <GtBarberShopCostBaseEntry> sGtBarberShopCostBaseStore(GtBarberShopCostBasefmt);
71 DBCStorage <GtCombatRatingsEntry> sGtCombatRatingsStore(GtCombatRatingsfmt);
72 DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore(GtChanceToMeleeCritBasefmt);
73 DBCStorage <GtChanceToMeleeCritEntry> sGtChanceToMeleeCritStore(GtChanceToMeleeCritfmt);
74 DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore(GtChanceToSpellCritBasefmt);
75 DBCStorage <GtChanceToSpellCritEntry> sGtChanceToSpellCritStore(GtChanceToSpellCritfmt);
76 DBCStorage <GtOCTRegenHPEntry> sGtOCTRegenHPStore(GtOCTRegenHPfmt);
77 //DBCStorage <GtOCTRegenMPEntry> sGtOCTRegenMPStore(GtOCTRegenMPfmt); -- not used currently
78 DBCStorage <GtRegenHPPerSptEntry> sGtRegenHPPerSptStore(GtRegenHPPerSptfmt);
79 DBCStorage <GtRegenMPPerSptEntry> sGtRegenMPPerSptStore(GtRegenMPPerSptfmt);
81 DBCStorage <HolidaysEntry> sHolidaysStore(Holidaysfmt);
83 DBCStorage <ItemEntry> sItemStore(Itemfmt);
84 DBCStorage <ItemBagFamilyEntry> sItemBagFamilyStore(ItemBagFamilyfmt);
85 //DBCStorage <ItemCondExtCostsEntry> sItemCondExtCostsStore(ItemCondExtCostsEntryfmt);
86 //DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently
87 DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt);
88 DBCStorage <ItemLimitCategoryEntry> sItemLimitCategoryStore(ItemLimitCategoryEntryfmt);
89 DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore(ItemRandomPropertiesfmt);
90 DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore(ItemRandomSuffixfmt);
91 DBCStorage <ItemSetEntry> sItemSetStore(ItemSetEntryfmt);
93 DBCStorage <LockEntry> sLockStore(LockEntryfmt);
95 DBCStorage <MailTemplateEntry> sMailTemplateStore(MailTemplateEntryfmt);
96 DBCStorage <MapEntry> sMapStore(MapEntryfmt);
97 DBCStorage <MovieEntry> sMovieStore(MovieEntryfmt);
99 DBCStorage <QuestSortEntry> sQuestSortStore(QuestSortEntryfmt);
101 DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt);
102 DBCStorage <ScalingStatDistributionEntry> sScalingStatDistributionStore(ScalingStatDistributionfmt);
103 DBCStorage <ScalingStatValuesEntry> sScalingStatValuesStore(ScalingStatValuesfmt);
105 DBCStorage <SkillLineEntry> sSkillLineStore(SkillLinefmt);
106 DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore(SkillLineAbilityfmt);
108 DBCStorage <SoundEntriesEntry> sSoundEntriesStore(SoundEntriesfmt);
110 DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore(SpellItemEnchantmentfmt);
111 DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt);
112 DBCStorage <SpellEntry> sSpellStore(SpellEntryfmt);
113 SpellCategoryStore sSpellCategoryStore;
114 PetFamilySpellsStore sPetFamilySpellsStore;
116 DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore(SpellCastTimefmt);
117 DBCStorage <SpellDurationEntry> sSpellDurationStore(SpellDurationfmt);
118 DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore(SpellFocusObjectfmt);
119 DBCStorage <SpellRadiusEntry> sSpellRadiusStore(SpellRadiusfmt);
120 DBCStorage <SpellRangeEntry> sSpellRangeStore(SpellRangefmt);
121 DBCStorage <SpellRuneCostEntry> sSpellRuneCostStore(SpellRuneCostfmt);
122 DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftfmt);
123 DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore(StableSlotPricesfmt);
124 //DBCStorage <SummonPropertiesEntry> sSummonPropertiesStore(SummonPropertiesfmt);
125 DBCStorage <TalentEntry> sTalentStore(TalentEntryfmt);
126 TalentSpellPosMap sTalentSpellPosMap;
127 DBCStorage <TalentTabEntry> sTalentTabStore(TalentTabEntryfmt);
129 // store absolute bit position for first rank for talent inspect
130 typedef std::map<uint32,uint32> TalentInspectMap;
131 static TalentInspectMap sTalentPosInInspect;
132 static TalentInspectMap sTalentTabSizeInInspect;
133 static uint32 sTalentTabPages[12/*MAX_CLASSES*/][3];
135 DBCStorage <TaxiNodesEntry> sTaxiNodesStore(TaxiNodesEntryfmt);
136 TaxiMask sTaxiNodesMask;
137 TaxiMask sOldContinentsNodesMask;
139 // DBC used only for initialization sTaxiPathSetBySource at startup.
140 TaxiPathSetBySource sTaxiPathSetBySource;
141 DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt);
143 // DBC used only for initialization sTaxiPathSetBySource at startup.
144 TaxiPathNodesByPath sTaxiPathNodesByPath;
146 static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
147 DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt);
148 DBCStorage <VehicleEntry> sVehicleStore(VehicleEntryfmt);
149 DBCStorage <VehicleSeatEntry> sVehicleSeatStore(VehicleSeatEntryfmt);
150 DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore(WorldMapAreaEntryfmt);
151 DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt);
152 DBCStorage <WorldMapOverlayEntry> sWorldMapOverlayStore(WorldMapOverlayEntryfmt);
154 typedef std::list<std::string> StoreProblemList;
156 static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, const std::string& filename)
158 sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize);
160 // assert must fail after function call
161 return false;
164 template<class T>
165 inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, const std::string& dbc_path, const std::string& filename)
167 // compatibility format and C++ structure sizes
168 assert(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename));
170 std::string dbc_filename = dbc_path + filename;
171 if(storage.Load(dbc_filename.c_str()))
173 bar.step();
174 for(uint8 i = 0; i < MAX_LOCALE; ++i)
176 if(!(availableDbcLocales & (1 << i)))
177 continue;
179 std::string dbc_filename_loc = dbc_path + localeNames[i] + "/" + filename;
180 if(!storage.LoadStringsFrom(dbc_filename_loc.c_str()))
181 availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks
184 else
186 // sort problematic dbc to (1) non compatible and (2) non-existed
187 FILE * f=fopen(dbc_filename.c_str(),"rb");
188 if(f)
190 char buf[100];
191 snprintf(buf,100," (exist, but have %d fields instead %d) Wrong client version DBC file?",storage.GetFieldCount(),strlen(storage.GetFormat()));
192 errlist.push_back(dbc_filename + buf);
193 fclose(f);
195 else
196 errlist.push_back(dbc_filename);
200 void LoadDBCStores(const std::string& dataPath)
202 std::string dbcPath = dataPath+"dbc/";
204 const uint32 DBCFilesCount = 77;
206 barGoLink bar( DBCFilesCount );
208 StoreProblemList bad_dbc_files;
209 uint32 availableDbcLocales = 0xFFFFFFFF;
211 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaStore, dbcPath,"AreaTable.dbc");
213 // must be after sAreaStore loading
214 for(uint32 i = 0; i < sAreaStore.GetNumRows(); ++i) // areaflag numbered from 0
216 if(AreaTableEntry const* area = sAreaStore.LookupEntry(i))
218 // fill AreaId->DBC records
219 sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID),area->exploreFlag));
221 // fill MapId->DBC records ( skip sub zones and continents )
222 if(area->zone==0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530 && area->mapid != 571 )
223 sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid,area->exploreFlag));
227 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementStore, dbcPath,"Achievement.dbc");
228 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementCriteriaStore, dbcPath,"Achievement_Criteria.dbc");
229 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc");
230 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaGroupStore, dbcPath,"AreaGroup.dbc");
231 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAuctionHouseStore, dbcPath,"AuctionHouse.dbc");
232 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc");
233 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc");
234 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBarberShopStyleStore, dbcPath,"BarberShopStyle.dbc");
235 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharStartOutfitStore, dbcPath,"CharStartOutfit.dbc");
237 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore, dbcPath,"CharTitles.dbc");
238 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore, dbcPath,"ChatChannels.dbc");
239 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore, dbcPath,"ChrClasses.dbc");
240 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrRacesStore, dbcPath,"ChrRaces.dbc");
241 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCinematicSequencesStore, dbcPath,"CinematicSequences.dbc");
242 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureDisplayInfoStore, dbcPath,"CreatureDisplayInfo.dbc");
243 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureFamilyStore, dbcPath,"CreatureFamily.dbc");
244 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureSpellDataStore, dbcPath,"CreatureSpellData.dbc");
245 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureTypeStore, dbcPath,"CreatureType.dbc");
246 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCurrencyTypesStore, dbcPath,"CurrencyTypes.dbc");
247 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityCostsStore, dbcPath,"DurabilityCosts.dbc");
248 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityQualityStore, dbcPath,"DurabilityQuality.dbc");
249 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesTextStore, dbcPath,"EmotesText.dbc");
250 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionStore, dbcPath,"Faction.dbc");
251 for (uint32 i=0;i<sFactionStore.GetNumRows(); ++i)
253 FactionEntry const * faction = sFactionStore.LookupEntry(i);
254 if (faction && faction->team)
256 SimpleFactionsList &flist = sFactionTeamMap[faction->team];
257 flist.push_back(i);
261 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore, dbcPath,"FactionTemplate.dbc");
262 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc");
263 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphPropertiesStore, dbcPath,"GlyphProperties.dbc");
264 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphSlotStore, dbcPath,"GlyphSlot.dbc");
266 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtBarberShopCostBaseStore,dbcPath,"gtBarberShopCostBase.dbc");
267 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtCombatRatingsStore, dbcPath,"gtCombatRatings.dbc");
269 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritBaseStore, dbcPath,"gtChanceToMeleeCritBase.dbc");
270 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritStore, dbcPath,"gtChanceToMeleeCrit.dbc");
272 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritBaseStore, dbcPath,"gtChanceToSpellCritBase.dbc");
273 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritStore, dbcPath,"gtChanceToSpellCrit.dbc");
275 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenHPStore, dbcPath,"gtOCTRegenHP.dbc");
276 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore, dbcPath,"gtOCTRegenMP.dbc"); -- not used currently
277 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenHPPerSptStore, dbcPath,"gtRegenHPPerSpt.dbc");
278 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenMPPerSptStore, dbcPath,"gtRegenMPPerSpt.dbc");
279 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sHolidaysStore, dbcPath,"Holidays.dbc");
280 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemStore, dbcPath,"Item.dbc");
281 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemBagFamilyStore, dbcPath,"ItemBagFamily.dbc");
282 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore, dbcPath,"ItemDisplayInfo.dbc"); -- not used currently
283 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore, dbcPath,"ItemCondExtCosts.dbc");
284 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemExtendedCostStore, dbcPath,"ItemExtendedCost.dbc");
285 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemLimitCategoryStore, dbcPath,"ItemLimitCategory.dbc");
286 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomPropertiesStore,dbcPath,"ItemRandomProperties.dbc");
287 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomSuffixStore, dbcPath,"ItemRandomSuffix.dbc");
288 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemSetStore, dbcPath,"ItemSet.dbc");
289 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sLockStore, dbcPath,"Lock.dbc");
290 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMailTemplateStore, dbcPath,"MailTemplate.dbc");
291 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapStore, dbcPath,"Map.dbc");
292 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMovieStore, dbcPath,"Movie.dbc");
293 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sQuestSortStore, dbcPath,"QuestSort.dbc");
294 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sRandomPropertiesPointsStore, dbcPath,"RandPropPoints.dbc");
295 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatDistributionStore, dbcPath,"ScalingStatDistribution.dbc");
296 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatValuesStore, dbcPath,"ScalingStatValues.dbc");
297 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineStore, dbcPath,"SkillLine.dbc");
298 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineAbilityStore, dbcPath,"SkillLineAbility.dbc");
299 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSoundEntriesStore, dbcPath,"SoundEntries.dbc");
300 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellStore, dbcPath,"Spell.dbc");
301 for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
303 SpellEntry const * spell = sSpellStore.LookupEntry(i);
304 if(spell && spell->Category)
305 sSpellCategoryStore[spell->Category].insert(i);
307 // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields
308 // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view
309 #if MANGOS_ENDIAN == MANGOS_BIGENDIAN
310 std::swap(*((uint32*)(&spell->SpellFamilyFlags)),*(((uint32*)(&spell->SpellFamilyFlags))+1));
311 #endif
314 for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
316 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
318 if(!skillLine)
319 continue;
321 SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
323 if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0)
325 for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i)
327 CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i);
328 if(!cFamily)
329 continue;
331 if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1])
332 continue;
334 sPetFamilySpellsStore[i].insert(spellInfo->Id);
339 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellCastTimesStore, dbcPath,"SpellCastTimes.dbc");
340 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc");
341 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore, dbcPath,"SpellFocusObject.dbc");
342 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc");
343 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc");
344 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore, dbcPath,"SpellRadius.dbc");
345 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc");
346 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRuneCostStore, dbcPath,"SpellRuneCost.dbc");
347 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore, dbcPath,"SpellShapeshiftForm.dbc");
348 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sStableSlotPricesStore, dbcPath,"StableSlotPrices.dbc");
349 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSummonPropertiesStore, dbcPath,"SummonProperties.dbc");
350 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentStore, dbcPath,"Talent.dbc");
352 // create talent spells set
353 for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i)
355 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
356 if (!talentInfo) continue;
357 for (int j = 0; j < MAX_TALENT_RANK; j++)
358 if(talentInfo->RankID[j])
359 sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i,j);
362 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentTabStore, dbcPath,"TalentTab.dbc");
364 // prepare fast data access to bit pos of talent ranks for use at inspecting
366 // fill table by amount of talent ranks and fill sTalentTabBitSizeInInspect
367 // store in with (row,col,talent)->size key for correct sorting by (row,col)
368 typedef std::map<uint32,uint32> TalentBitSize;
369 TalentBitSize sTalentBitSize;
370 for(uint32 i = 1; i < sTalentStore.GetNumRows(); ++i)
372 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
373 if (!talentInfo) continue;
375 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
376 if(!talentTabInfo)
377 continue;
379 // find talent rank
380 uint32 curtalent_maxrank = 0;
381 for(uint32 k = MAX_TALENT_RANK; k > 0; --k)
383 if(talentInfo->RankID[k-1])
385 curtalent_maxrank = k;
386 break;
390 sTalentBitSize[(talentInfo->Row<<24) + (talentInfo->Col<<16)+talentInfo->TalentID] = curtalent_maxrank;
391 sTalentTabSizeInInspect[talentInfo->TalentTab] += curtalent_maxrank;
394 // now have all max ranks (and then bit amount used for store talent ranks in inspect)
395 for(uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId)
397 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentTabId );
398 if(!talentTabInfo)
399 continue;
401 // prevent memory corruption; otherwise cls will become 12 below
402 if ((talentTabInfo->ClassMask & CLASSMASK_ALL_PLAYABLE)==0)
403 continue;
405 // store class talent tab pages
406 uint32 cls = 1;
407 for(uint32 m=1;!(m & talentTabInfo->ClassMask) && cls < MAX_CLASSES;m <<=1, ++cls) {}
409 sTalentTabPages[cls][talentTabInfo->tabpage]=talentTabId;
411 // add total amount bits for first rank starting from talent tab first talent rank pos.
412 uint32 pos = 0;
413 for(TalentBitSize::iterator itr = sTalentBitSize.begin(); itr != sTalentBitSize.end(); ++itr)
415 uint32 talentId = itr->first & 0xFFFF;
416 TalentEntry const *talentInfo = sTalentStore.LookupEntry( talentId );
417 if(!talentInfo)
418 continue;
420 if(talentInfo->TalentTab != talentTabId)
421 continue;
423 sTalentPosInInspect[talentId] = pos;
424 pos+= itr->second;
429 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiNodesStore, dbcPath,"TaxiNodes.dbc");
431 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathStore, dbcPath,"TaxiPath.dbc");
432 for(uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i)
433 if(TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i))
434 sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID,entry->price);
435 uint32 pathCount = sTaxiPathStore.GetNumRows();
437 //## TaxiPathNode.dbc ## Loaded only for initialization different structures
438 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathNodeStore, dbcPath,"TaxiPathNode.dbc");
439 // Calculate path nodes count
440 std::vector<uint32> pathLength;
441 pathLength.resize(pathCount); // 0 and some other indexes not used
442 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
443 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
445 if (pathLength[entry->path] < entry->index + 1)
446 pathLength[entry->path] = entry->index + 1;
448 // Set path length
449 sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used
450 for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i)
451 sTaxiPathNodesByPath[i].resize(pathLength[i]);
452 // fill data
453 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
454 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
455 sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay);
456 sTaxiPathNodeStore.Clear();
458 // Initialize global taxinodes mask
459 // include existed nodes that have at least single not spell base (scripted) path
461 std::set<uint32> spellPaths;
462 for(uint32 i = 1; i < sSpellStore.GetNumRows (); ++i)
463 if(SpellEntry const* sInfo = sSpellStore.LookupEntry (i))
464 for(int j=0; j < 3; ++j)
465 if(sInfo->Effect[j]==123 /*SPELL_EFFECT_SEND_TAXI*/)
466 spellPaths.insert(sInfo->EffectMiscValue[j]);
468 memset(sTaxiNodesMask,0,sizeof(sTaxiNodesMask));
469 memset(sOldContinentsNodesMask,0,sizeof(sTaxiNodesMask));
470 for(uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i)
472 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i);
473 if(!node)
474 continue;
476 TaxiPathSetBySource::const_iterator src_i = sTaxiPathSetBySource.find(i);
477 if(src_i!=sTaxiPathSetBySource.end() && !src_i->second.empty())
479 bool ok = false;
480 for(TaxiPathSetForSource::const_iterator dest_i = src_i->second.begin();dest_i != src_i->second.end(); ++dest_i)
482 // not spell path
483 if(spellPaths.find(dest_i->second.ID)==spellPaths.end())
485 ok = true;
486 break;
490 if(!ok)
491 continue;
494 // valid taxi network node
495 uint8 field = (uint8)((i - 1) / 32);
496 uint32 submask = 1<<((i-1)%32);
497 sTaxiNodesMask[field] |= submask;
499 // old continent node (+ nodes virtually at old continents, check explicitly to avoid loading map files for zone info)
500 if (node->map_id < 2 || i == 82 || i == 83 || i == 93 || i == 94)
501 sOldContinentsNodesMask[field] |= submask;
505 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTotemCategoryStore, dbcPath,"TotemCategory.dbc");
506 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleStore, dbcPath,"Vehicle.dbc");
507 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleSeatStore, dbcPath,"VehicleSeat.dbc");
508 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapAreaStore, dbcPath,"WorldMapArea.dbc");
509 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldSafeLocsStore, dbcPath,"WorldSafeLocs.dbc");
510 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapOverlayStore, dbcPath,"WorldMapOverlay.dbc");
512 // error checks
513 if(bad_dbc_files.size() >= DBCFilesCount )
515 sLog.outError("\nIncorrect DataDir value in mangosd.conf or ALL required *.dbc files (%d) not found by path: %sdbc",DBCFilesCount,dataPath.c_str());
516 exit(1);
518 else if(!bad_dbc_files.empty() )
520 std::string str;
521 for(std::list<std::string>::iterator i = bad_dbc_files.begin(); i != bad_dbc_files.end(); ++i)
522 str += *i + "\n";
524 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());
525 exit(1);
528 // Check loaded DBC files proper version
529 if( !sSpellStore.LookupEntry(62735) || // last added spell in 3.0.9
530 !sMapStore.LookupEntry(624) || // last map added in 3.0.8a/3.0.9
531 !sGemPropertiesStore.LookupEntry(1557) || // last gem property added in 3.0.8a/3.0.9
532 !sItemExtendedCostStore.LookupEntry(2589) || // last item extended cost added in 3.0.8a/3.0.9
533 !sCharTitlesStore.LookupEntry(144) || // last char title added in 3.0.8a/3.0.9
534 !sAreaStore.LookupEntry(2769) || // last area (areaflag) added in 3.0.8a/3.0.9
535 !sItemStore.LookupEntry(45037) ) // last client known item added in 3.0.9
537 sLog.outError("\nYou have _outdated_ DBC files. Please extract correct versions from current using client.");
538 exit(1);
541 sLog.outString();
542 sLog.outString( ">> Initialized %d data stores", DBCFilesCount );
545 SimpleFactionsList const* GetFactionTeamList(uint32 faction)
547 FactionTeamMap::const_iterator itr = sFactionTeamMap.find(faction);
548 if(itr==sFactionTeamMap.end())
549 return NULL;
550 return &itr->second;
553 char* GetPetName(uint32 petfamily, uint32 dbclang)
555 if(!petfamily)
556 return NULL;
557 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(petfamily);
558 if(!pet_family)
559 return NULL;
560 return pet_family->Name[dbclang]?pet_family->Name[dbclang]:NULL;
563 TalentSpellPos const* GetTalentSpellPos(uint32 spellId)
565 TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId);
566 if(itr==sTalentSpellPosMap.end())
567 return NULL;
569 return &itr->second;
572 uint32 GetTalentSpellCost(uint32 spellId)
574 if(TalentSpellPos const* pos = GetTalentSpellPos(spellId))
575 return pos->rank+1;
577 return 0;
580 int32 GetAreaFlagByAreaID(uint32 area_id)
582 AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id);
583 if(i == sAreaFlagByAreaID.end())
584 return -1;
586 return i->second;
589 AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
591 int32 areaflag = GetAreaFlagByAreaID(area_id);
592 if(areaflag < 0)
593 return NULL;
595 return sAreaStore.LookupEntry(areaflag );
598 AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id)
600 if(area_flag)
601 return sAreaStore.LookupEntry(area_flag);
603 if(MapEntry const* mapEntry = sMapStore.LookupEntry(map_id))
604 return GetAreaEntryByAreaID(mapEntry->linked_zone);
606 return NULL;
609 uint32 GetAreaFlagByMapId(uint32 mapid)
611 AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid);
612 if(i == sAreaFlagByMapID.end())
613 return 0;
614 else
615 return i->second;
618 uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId)
620 if(mapid != 530 && mapid != 571) // speed for most cases
621 return mapid;
623 if(WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId))
624 return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id;
626 return mapid;
629 ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId)
631 mapid = GetVirtualMapForMapAndZone(mapid,zoneId);
632 if(mapid < 2)
633 return CONTENT_1_60;
635 MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
636 if(!mapEntry)
637 return CONTENT_1_60;
639 switch(mapEntry->Expansion())
641 default: return CONTENT_1_60;
642 case 1: return CONTENT_61_70;
643 case 2: return CONTENT_71_80;
647 ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id)
649 // not sorted, numbering index from 0
650 for(uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
652 ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i);
653 if(ch && ch->ChannelID == channel_id)
654 return ch;
656 return NULL;
659 bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId)
661 if(requiredTotemCategoryId==0)
662 return true;
663 if(itemTotemCategoryId==0)
664 return false;
666 TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId);
667 if(!itemEntry)
668 return false;
669 TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId);
670 if(!reqEntry)
671 return false;
673 if(itemEntry->categoryType!=reqEntry->categoryType)
674 return false;
676 return (itemEntry->categoryMask & reqEntry->categoryMask)==reqEntry->categoryMask;
679 void Zone2MapCoordinates(float& x,float& y,uint32 zone)
681 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
683 // if not listed then map coordinates (instance)
684 if(!maEntry)
685 return;
687 std::swap(x,y); // at client map coords swapped
688 x = x*((maEntry->x2-maEntry->x1)/100)+maEntry->x1;
689 y = y*((maEntry->y2-maEntry->y1)/100)+maEntry->y1; // client y coord from top to down
692 void Map2ZoneCoordinates(float& x,float& y,uint32 zone)
694 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
696 // if not listed then map coordinates (instance)
697 if(!maEntry)
698 return;
700 x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100);
701 y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100); // client y coord from top to down
702 std::swap(x,y); // client have map coords swapped
705 uint32 GetTalentInspectBitPosInTab(uint32 talentId)
707 TalentInspectMap::const_iterator itr = sTalentPosInInspect.find(talentId);
708 if(itr == sTalentPosInInspect.end())
709 return 0;
711 return itr->second;
714 uint32 GetTalentTabInspectBitSize(uint32 talentTabId)
716 TalentInspectMap::const_iterator itr = sTalentTabSizeInInspect.find(talentTabId);
717 if(itr == sTalentTabSizeInInspect.end())
718 return 0;
720 return itr->second;
723 uint32 const* GetTalentTabPages(uint32 cls)
725 return sTalentTabPages[cls];
728 // script support functions
729 MANGOS_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore() { return &sSoundEntriesStore; }
730 MANGOS_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore() { return &sSpellStore; }
731 MANGOS_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore() { return &sSpellRangeStore; }
732 MANGOS_DLL_SPEC DBCStorage <FactionEntry> const* GetFactionStore() { return &sFactionStore; }
733 MANGOS_DLL_SPEC DBCStorage <ItemEntry> const* GetItemDisplayStore() { return &sItemStore; }
734 MANGOS_DLL_SPEC DBCStorage <CreatureDisplayInfoEntry> const* GetCreatureDisplayStore() { return &sCreatureDisplayInfoStore; }