[9290] Some cleanups in realmd, no functional changes
[getmangos.git] / src / game / DBCStores.cpp
blobca497b3bbdae1930d569e16c805ef7aaf8f6ddf0
1 /*
2 * Copyright (C) 2005-2010 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"
24 #include "ObjectDefines.h"
26 #include "DBCfmt.h"
28 #include <map>
30 typedef std::map<uint16,uint32> AreaFlagByAreaID;
31 typedef std::map<uint32,uint32> AreaFlagByMapID;
33 DBCStorage <AreaTableEntry> sAreaStore(AreaTableEntryfmt);
34 DBCStorage <AreaGroupEntry> sAreaGroupStore(AreaGroupEntryfmt);
35 static AreaFlagByAreaID sAreaFlagByAreaID;
36 static AreaFlagByMapID sAreaFlagByMapID; // for instances without generated *.map files
38 DBCStorage <AchievementEntry> sAchievementStore(Achievementfmt);
39 DBCStorage <AchievementCriteriaEntry> sAchievementCriteriaStore(AchievementCriteriafmt);
40 DBCStorage <AreaTriggerEntry> sAreaTriggerStore(AreaTriggerEntryfmt);
41 DBCStorage <AuctionHouseEntry> sAuctionHouseStore(AuctionHouseEntryfmt);
42 DBCStorage <BankBagSlotPricesEntry> sBankBagSlotPricesStore(BankBagSlotPricesEntryfmt);
43 DBCStorage <BattlemasterListEntry> sBattlemasterListStore(BattlemasterListEntryfmt);
44 DBCStorage <BarberShopStyleEntry> sBarberShopStyleStore(BarberShopStyleEntryfmt);
45 DBCStorage <CharStartOutfitEntry> sCharStartOutfitStore(CharStartOutfitEntryfmt);
46 DBCStorage <CharTitlesEntry> sCharTitlesStore(CharTitlesEntryfmt);
47 DBCStorage <ChatChannelsEntry> sChatChannelsStore(ChatChannelsEntryfmt);
48 DBCStorage <ChrClassesEntry> sChrClassesStore(ChrClassesEntryfmt);
49 DBCStorage <ChrRacesEntry> sChrRacesStore(ChrRacesEntryfmt);
50 DBCStorage <CinematicSequencesEntry> sCinematicSequencesStore(CinematicSequencesEntryfmt);
51 DBCStorage <CreatureDisplayInfoEntry> sCreatureDisplayInfoStore(CreatureDisplayInfofmt);
52 DBCStorage <CreatureFamilyEntry> sCreatureFamilyStore(CreatureFamilyfmt);
53 DBCStorage <CreatureSpellDataEntry> sCreatureSpellDataStore(CreatureSpellDatafmt);
54 DBCStorage <CreatureTypeEntry> sCreatureTypeStore(CreatureTypefmt);
55 DBCStorage <CurrencyTypesEntry> sCurrencyTypesStore(CurrencyTypesfmt);
57 DBCStorage <DurabilityQualityEntry> sDurabilityQualityStore(DurabilityQualityfmt);
58 DBCStorage <DurabilityCostsEntry> sDurabilityCostsStore(DurabilityCostsfmt);
60 DBCStorage <EmotesEntry> sEmotesStore(EmotesEntryfmt);
61 DBCStorage <EmotesTextEntry> sEmotesTextStore(EmotesTextEntryfmt);
63 typedef std::map<uint32,SimpleFactionsList> FactionTeamMap;
64 static FactionTeamMap sFactionTeamMap;
65 DBCStorage <FactionEntry> sFactionStore(FactionEntryfmt);
66 DBCStorage <FactionTemplateEntry> sFactionTemplateStore(FactionTemplateEntryfmt);
68 DBCStorage <GameObjectDisplayInfoEntry> sGameObjectDisplayInfoStore(GameObjectDisplayInfofmt);
69 DBCStorage <GemPropertiesEntry> sGemPropertiesStore(GemPropertiesEntryfmt);
70 DBCStorage <GlyphPropertiesEntry> sGlyphPropertiesStore(GlyphPropertiesfmt);
71 DBCStorage <GlyphSlotEntry> sGlyphSlotStore(GlyphSlotfmt);
73 DBCStorage <GtBarberShopCostBaseEntry> sGtBarberShopCostBaseStore(GtBarberShopCostBasefmt);
74 DBCStorage <GtCombatRatingsEntry> sGtCombatRatingsStore(GtCombatRatingsfmt);
75 DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore(GtChanceToMeleeCritBasefmt);
76 DBCStorage <GtChanceToMeleeCritEntry> sGtChanceToMeleeCritStore(GtChanceToMeleeCritfmt);
77 DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore(GtChanceToSpellCritBasefmt);
78 DBCStorage <GtChanceToSpellCritEntry> sGtChanceToSpellCritStore(GtChanceToSpellCritfmt);
79 DBCStorage <GtOCTRegenHPEntry> sGtOCTRegenHPStore(GtOCTRegenHPfmt);
80 //DBCStorage <GtOCTRegenMPEntry> sGtOCTRegenMPStore(GtOCTRegenMPfmt); -- not used currently
81 DBCStorage <GtRegenHPPerSptEntry> sGtRegenHPPerSptStore(GtRegenHPPerSptfmt);
82 DBCStorage <GtRegenMPPerSptEntry> sGtRegenMPPerSptStore(GtRegenMPPerSptfmt);
84 DBCStorage <HolidaysEntry> sHolidaysStore(Holidaysfmt);
86 DBCStorage <ItemEntry> sItemStore(Itemfmt);
87 DBCStorage <ItemBagFamilyEntry> sItemBagFamilyStore(ItemBagFamilyfmt);
88 //DBCStorage <ItemCondExtCostsEntry> sItemCondExtCostsStore(ItemCondExtCostsEntryfmt);
89 //DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently
90 DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt);
91 DBCStorage <ItemLimitCategoryEntry> sItemLimitCategoryStore(ItemLimitCategoryEntryfmt);
92 DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore(ItemRandomPropertiesfmt);
93 DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore(ItemRandomSuffixfmt);
94 DBCStorage <ItemSetEntry> sItemSetStore(ItemSetEntryfmt);
96 DBCStorage <LockEntry> sLockStore(LockEntryfmt);
98 DBCStorage <MailTemplateEntry> sMailTemplateStore(MailTemplateEntryfmt);
99 DBCStorage <MapEntry> sMapStore(MapEntryfmt);
101 // DBC used only for initialization sMapDifficultyMap at startup.
102 DBCStorage <MapDifficultyEntry> sMapDifficultyStore(MapDifficultyEntryfmt); // only for loading
103 MapDifficultyMap sMapDifficultyMap;
105 DBCStorage <MovieEntry> sMovieStore(MovieEntryfmt);
107 DBCStorage <QuestSortEntry> sQuestSortStore(QuestSortEntryfmt);
108 DBCStorage <PvPDifficultyEntry> sPvPDifficultyStore(PvPDifficultyfmt);
110 DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt);
111 DBCStorage <ScalingStatDistributionEntry> sScalingStatDistributionStore(ScalingStatDistributionfmt);
112 DBCStorage <ScalingStatValuesEntry> sScalingStatValuesStore(ScalingStatValuesfmt);
114 DBCStorage <SkillLineEntry> sSkillLineStore(SkillLinefmt);
115 DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore(SkillLineAbilityfmt);
117 DBCStorage <SoundEntriesEntry> sSoundEntriesStore(SoundEntriesfmt);
119 DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore(SpellItemEnchantmentfmt);
120 DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt);
121 DBCStorage <SpellEntry> sSpellStore(SpellEntryfmt);
122 SpellCategoryStore sSpellCategoryStore;
123 PetFamilySpellsStore sPetFamilySpellsStore;
125 DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore(SpellCastTimefmt);
126 DBCStorage <SpellDurationEntry> sSpellDurationStore(SpellDurationfmt);
127 DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore(SpellFocusObjectfmt);
128 DBCStorage <SpellRadiusEntry> sSpellRadiusStore(SpellRadiusfmt);
129 DBCStorage <SpellRangeEntry> sSpellRangeStore(SpellRangefmt);
130 DBCStorage <SpellRuneCostEntry> sSpellRuneCostStore(SpellRuneCostfmt);
131 DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftfmt);
132 DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore(StableSlotPricesfmt);
133 DBCStorage <SummonPropertiesEntry> sSummonPropertiesStore(SummonPropertiesfmt);
134 DBCStorage <TalentEntry> sTalentStore(TalentEntryfmt);
135 TalentSpellPosMap sTalentSpellPosMap;
136 DBCStorage <TalentTabEntry> sTalentTabStore(TalentTabEntryfmt);
138 // store absolute bit position for first rank for talent inspect
139 static uint32 sTalentTabPages[MAX_CLASSES][3];
141 DBCStorage <TaxiNodesEntry> sTaxiNodesStore(TaxiNodesEntryfmt);
142 TaxiMask sTaxiNodesMask;
143 TaxiMask sOldContinentsNodesMask;
145 // DBC used only for initialization sTaxiPathSetBySource at startup.
146 TaxiPathSetBySource sTaxiPathSetBySource;
147 DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt);
149 // DBC used only for initialization sTaxiPathNodeStore at startup.
150 TaxiPathNodesByPath sTaxiPathNodesByPath;
151 static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
153 DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt);
154 DBCStorage <VehicleEntry> sVehicleStore(VehicleEntryfmt);
155 DBCStorage <VehicleSeatEntry> sVehicleSeatStore(VehicleSeatEntryfmt);
156 DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore(WorldMapAreaEntryfmt);
157 DBCStorage <WorldMapOverlayEntry> sWorldMapOverlayStore(WorldMapOverlayEntryfmt);
158 DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt);
160 typedef std::list<std::string> StoreProblemList;
162 bool IsAcceptableClientBuild(uint32 build)
164 int accepted_versions[] = EXPECTED_MANGOSD_CLIENT_BUILD;
165 for(int i = 0; accepted_versions[i]; ++i)
166 if(build == accepted_versions[i])
167 return true;
169 return false;
172 std::string AcceptableClientBuildsListStr()
174 std::ostringstream data;
175 int accepted_versions[] = EXPECTED_MANGOSD_CLIENT_BUILD;
176 for(int i = 0; accepted_versions[i]; ++i)
177 data << accepted_versions[i] << " ";
178 return data.str();
181 static bool ReadDBCBuildFileText(const std::string& dbc_path, char const* localeName, std::string& text)
183 std::string filename = dbc_path + "component.wow-" + localeName + ".txt";
185 if(FILE* file = fopen(filename.c_str(),"rb"))
187 char buf[100];
188 fread(buf,1,100-1,file);
189 fclose(file);
191 text = &buf[0];
192 return true;
194 else
195 return false;
198 static uint32 ReadDBCBuild(const std::string& dbc_path, char const* localeName = NULL)
200 std::string text;
202 if (!localeName)
204 for(LocaleNameStr* itr = &fullLocaleNameList[0]; itr->name; ++itr)
205 if (ReadDBCBuildFileText(dbc_path,itr->name,text))
206 break;
208 else
209 ReadDBCBuildFileText(dbc_path,localeName,text);
211 if (text.empty())
212 return 0;
214 size_t pos = text.find("version=\"");
215 size_t pos1 = pos + strlen("version=\"");
216 size_t pos2 = text.find("\"",pos1);
217 if (pos == text.npos || pos2 == text.npos || pos1 >= pos2)
218 return 0;
220 std::string build_str = text.substr(pos1,pos2-pos1);
222 int build = atoi(build_str.c_str());
223 if (build <= 0)
224 return 0;
226 return build;
229 static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, const std::string& filename)
231 sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize);
233 // assert must fail after function call
234 return false;
237 struct LocalData
239 explicit LocalData(uint32 build) : main_build(build), availableDbcLocales(0xFFFFFFFF),checkedDbcLocaleBuilds(0) {}
240 uint32 main_build;
242 // bitmasks for index of fullLocaleNameList
243 uint32 availableDbcLocales;
244 uint32 checkedDbcLocaleBuilds;
247 template<class T>
248 inline void LoadDBC(LocalData& localeData,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, const std::string& dbc_path, const std::string& filename)
250 // compatibility format and C++ structure sizes
251 assert(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename));
253 std::string dbc_filename = dbc_path + filename;
254 if(storage.Load(dbc_filename.c_str()))
256 bar.step();
257 for(uint8 i = 0; fullLocaleNameList[i].name; ++i)
259 if (!(localeData.availableDbcLocales & (1 << i)))
260 continue;
262 std::string dbc_dir_loc = dbc_path + fullLocaleNameList[i].name + "/";
264 if (!(localeData.checkedDbcLocaleBuilds & (1 << i)))
266 localeData.checkedDbcLocaleBuilds |= (1<<i);// mark as checked for speedup next checks
268 uint32 build_loc = ReadDBCBuild(dbc_dir_loc,fullLocaleNameList[i].name);
269 if(localeData.main_build != build_loc)
271 localeData.availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks
273 // exist but wrong build
274 if (build_loc)
276 std::string dbc_filename_loc = dbc_path + fullLocaleNameList[i].name + "/" + filename;
277 char buf[200];
278 snprintf(buf,200," (exist, but DBC locale subdir %s have DBCs for build %u instead expected build %u, it and other DBC from subdir skipped)",fullLocaleNameList[i].name,build_loc,localeData.main_build);
279 errlist.push_back(dbc_filename_loc + buf);
282 continue;
286 std::string dbc_filename_loc = dbc_path + fullLocaleNameList[i].name + "/" + filename;
287 if(!storage.LoadStringsFrom(dbc_filename_loc.c_str()))
288 localeData.availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks
291 else
293 // sort problematic dbc to (1) non compatible and (2) non-existed
294 FILE * f=fopen(dbc_filename.c_str(),"rb");
295 if(f)
297 char buf[100];
298 snprintf(buf,100," (exist, but have %d fields instead " SIZEFMTD ") Wrong client version DBC file?",storage.GetFieldCount(),strlen(storage.GetFormat()));
299 errlist.push_back(dbc_filename + buf);
300 fclose(f);
302 else
303 errlist.push_back(dbc_filename);
307 void LoadDBCStores(const std::string& dataPath)
309 std::string dbcPath = dataPath+"dbc/";
311 uint32 build = ReadDBCBuild(dbcPath);
313 // Check the expected DBC version
314 if (!IsAcceptableClientBuild(build))
316 if (build)
317 sLog.outError("Found DBC files for build %u but mangosd expected DBC for one from builds: %s Please extract correct DBC files.", build, AcceptableClientBuildsListStr().c_str());
318 else
319 sLog.outError("Incorrect DataDir value in mangosd.conf or not found build info (outdated DBC files). Required one from builds: %s Please extract correct DBC files.",AcceptableClientBuildsListStr().c_str());
320 exit(1);
323 const uint32 DBCFilesCount = 82;
325 barGoLink bar( DBCFilesCount );
327 StoreProblemList bad_dbc_files;
329 LocalData availableDbcLocales(build);
331 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaStore, dbcPath,"AreaTable.dbc");
333 // must be after sAreaStore loading
334 for(uint32 i = 0; i < sAreaStore.GetNumRows(); ++i) // areaflag numbered from 0
336 if(AreaTableEntry const* area = sAreaStore.LookupEntry(i))
338 // fill AreaId->DBC records
339 sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID),area->exploreFlag));
341 // fill MapId->DBC records ( skip sub zones and continents )
342 if(area->zone==0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530 && area->mapid != 571 )
343 sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid,area->exploreFlag));
347 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementStore, dbcPath,"Achievement.dbc");
348 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementCriteriaStore, dbcPath,"Achievement_Criteria.dbc");
349 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc");
350 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaGroupStore, dbcPath,"AreaGroup.dbc");
351 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAuctionHouseStore, dbcPath,"AuctionHouse.dbc");
352 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc");
353 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc");
354 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBarberShopStyleStore, dbcPath,"BarberShopStyle.dbc");
355 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharStartOutfitStore, dbcPath,"CharStartOutfit.dbc");
356 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore, dbcPath,"CharTitles.dbc");
357 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore, dbcPath,"ChatChannels.dbc");
358 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore, dbcPath,"ChrClasses.dbc");
359 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrRacesStore, dbcPath,"ChrRaces.dbc");
360 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCinematicSequencesStore, dbcPath,"CinematicSequences.dbc");
361 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureDisplayInfoStore, dbcPath,"CreatureDisplayInfo.dbc");
362 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureFamilyStore, dbcPath,"CreatureFamily.dbc");
363 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureSpellDataStore, dbcPath,"CreatureSpellData.dbc");
364 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureTypeStore, dbcPath,"CreatureType.dbc");
365 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCurrencyTypesStore, dbcPath,"CurrencyTypes.dbc");
366 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityCostsStore, dbcPath,"DurabilityCosts.dbc");
367 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityQualityStore, dbcPath,"DurabilityQuality.dbc");
368 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesStore, dbcPath,"Emotes.dbc");
369 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesTextStore, dbcPath,"EmotesText.dbc");
370 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionStore, dbcPath,"Faction.dbc");
371 for (uint32 i=0;i<sFactionStore.GetNumRows(); ++i)
373 FactionEntry const * faction = sFactionStore.LookupEntry(i);
374 if (faction && faction->team)
376 SimpleFactionsList &flist = sFactionTeamMap[faction->team];
377 flist.push_back(i);
381 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore, dbcPath,"FactionTemplate.dbc");
382 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGameObjectDisplayInfoStore,dbcPath,"GameObjectDisplayInfo.dbc");
383 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc");
384 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphPropertiesStore, dbcPath,"GlyphProperties.dbc");
385 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphSlotStore, dbcPath,"GlyphSlot.dbc");
387 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtBarberShopCostBaseStore,dbcPath,"gtBarberShopCostBase.dbc");
388 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtCombatRatingsStore, dbcPath,"gtCombatRatings.dbc");
390 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritBaseStore, dbcPath,"gtChanceToMeleeCritBase.dbc");
391 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritStore, dbcPath,"gtChanceToMeleeCrit.dbc");
393 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritBaseStore, dbcPath,"gtChanceToSpellCritBase.dbc");
394 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritStore, dbcPath,"gtChanceToSpellCrit.dbc");
396 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenHPStore, dbcPath,"gtOCTRegenHP.dbc");
397 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore, dbcPath,"gtOCTRegenMP.dbc"); -- not used currently
398 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenHPPerSptStore, dbcPath,"gtRegenHPPerSpt.dbc");
399 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenMPPerSptStore, dbcPath,"gtRegenMPPerSpt.dbc");
400 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sHolidaysStore, dbcPath,"Holidays.dbc");
401 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemStore, dbcPath,"Item.dbc");
402 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemBagFamilyStore, dbcPath,"ItemBagFamily.dbc");
403 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore, dbcPath,"ItemDisplayInfo.dbc"); -- not used currently
404 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore, dbcPath,"ItemCondExtCosts.dbc");
405 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemExtendedCostStore, dbcPath,"ItemExtendedCost.dbc");
406 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemLimitCategoryStore, dbcPath,"ItemLimitCategory.dbc");
407 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomPropertiesStore,dbcPath,"ItemRandomProperties.dbc");
408 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomSuffixStore, dbcPath,"ItemRandomSuffix.dbc");
409 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemSetStore, dbcPath,"ItemSet.dbc");
410 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sLockStore, dbcPath,"Lock.dbc");
411 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMailTemplateStore, dbcPath,"MailTemplate.dbc");
412 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapStore, dbcPath,"Map.dbc");
414 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapDifficultyStore, dbcPath,"MapDifficulty.dbc");
415 // fill data
416 for(uint32 i = 1; i < sMapDifficultyStore.GetNumRows(); ++i)
417 if(MapDifficultyEntry const* entry = sMapDifficultyStore.LookupEntry(i))
418 sMapDifficultyMap[MAKE_PAIR32(entry->MapId,entry->Difficulty)] = MapDifficulty(entry->resetTime,entry->maxPlayers);
419 sMapDifficultyStore.Clear();
421 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMovieStore, dbcPath,"Movie.dbc");
422 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sQuestSortStore, dbcPath,"QuestSort.dbc");
423 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sPvPDifficultyStore, dbcPath,"PvpDifficulty.dbc");
424 for(uint32 i = 0; i < sPvPDifficultyStore.GetNumRows(); ++i)
425 if (PvPDifficultyEntry const* entry = sPvPDifficultyStore.LookupEntry(i))
426 if (entry->bracketId > MAX_BATTLEGROUND_BRACKETS)
427 assert(false && "Need update MAX_BATTLEGROUND_BRACKETS by DBC data");
429 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sRandomPropertiesPointsStore, dbcPath,"RandPropPoints.dbc");
430 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatDistributionStore, dbcPath,"ScalingStatDistribution.dbc");
431 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatValuesStore, dbcPath,"ScalingStatValues.dbc");
432 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineStore, dbcPath,"SkillLine.dbc");
433 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineAbilityStore, dbcPath,"SkillLineAbility.dbc");
434 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSoundEntriesStore, dbcPath,"SoundEntries.dbc");
435 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellStore, dbcPath,"Spell.dbc");
436 for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
438 SpellEntry const * spell = sSpellStore.LookupEntry(i);
439 if(spell && spell->Category)
440 sSpellCategoryStore[spell->Category].insert(i);
442 // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields
443 // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view
444 #if MANGOS_ENDIAN == MANGOS_BIGENDIAN
445 std::swap(*((uint32*)(&spell->SpellFamilyFlags)),*(((uint32*)(&spell->SpellFamilyFlags))+1));
446 #endif
449 for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
451 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
453 if(!skillLine)
454 continue;
456 SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
458 if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0)
460 for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i)
462 CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i);
463 if(!cFamily)
464 continue;
466 if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1])
467 continue;
469 sPetFamilySpellsStore[i].insert(spellInfo->Id);
474 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellCastTimesStore, dbcPath,"SpellCastTimes.dbc");
475 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc");
476 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore, dbcPath,"SpellFocusObject.dbc");
477 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc");
478 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc");
479 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore, dbcPath,"SpellRadius.dbc");
480 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc");
481 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRuneCostStore, dbcPath,"SpellRuneCost.dbc");
482 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore, dbcPath,"SpellShapeshiftForm.dbc");
483 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sStableSlotPricesStore, dbcPath,"StableSlotPrices.dbc");
484 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSummonPropertiesStore, dbcPath,"SummonProperties.dbc");
485 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentStore, dbcPath,"Talent.dbc");
487 // create talent spells set
488 for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i)
490 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
491 if (!talentInfo) continue;
492 for (int j = 0; j < MAX_TALENT_RANK; j++)
493 if(talentInfo->RankID[j])
494 sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i,j);
497 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentTabStore, dbcPath,"TalentTab.dbc");
499 // prepare fast data access to bit pos of talent ranks for use at inspecting
501 // now have all max ranks (and then bit amount used for store talent ranks in inspect)
502 for(uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId)
504 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentTabId );
505 if(!talentTabInfo)
506 continue;
508 // prevent memory corruption; otherwise cls will become 12 below
509 if ((talentTabInfo->ClassMask & CLASSMASK_ALL_PLAYABLE)==0)
510 continue;
512 // store class talent tab pages
513 uint32 cls = 1;
514 for(uint32 m=1;!(m & talentTabInfo->ClassMask) && cls < MAX_CLASSES;m <<=1, ++cls) {}
516 sTalentTabPages[cls][talentTabInfo->tabpage]=talentTabId;
520 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiNodesStore, dbcPath,"TaxiNodes.dbc");
522 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathStore, dbcPath,"TaxiPath.dbc");
523 for(uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i)
524 if(TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i))
525 sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID,entry->price);
526 uint32 pathCount = sTaxiPathStore.GetNumRows();
528 //## TaxiPathNode.dbc ## Loaded only for initialization different structures
529 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathNodeStore, dbcPath,"TaxiPathNode.dbc");
530 // Calculate path nodes count
531 std::vector<uint32> pathLength;
532 pathLength.resize(pathCount); // 0 and some other indexes not used
533 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
534 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
536 if (pathLength[entry->path] < entry->index + 1)
537 pathLength[entry->path] = entry->index + 1;
539 // Set path length
540 sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used
541 for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i)
542 sTaxiPathNodesByPath[i].resize(pathLength[i]);
543 // fill data
544 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
545 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
546 sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay);
547 sTaxiPathNodeStore.Clear();
549 // Initialize global taxinodes mask
550 // include existed nodes that have at least single not spell base (scripted) path
552 std::set<uint32> spellPaths;
553 for(uint32 i = 1; i < sSpellStore.GetNumRows (); ++i)
554 if(SpellEntry const* sInfo = sSpellStore.LookupEntry (i))
555 for(int j=0; j < 3; ++j)
556 if(sInfo->Effect[j]==123 /*SPELL_EFFECT_SEND_TAXI*/)
557 spellPaths.insert(sInfo->EffectMiscValue[j]);
559 memset(sTaxiNodesMask,0,sizeof(sTaxiNodesMask));
560 memset(sOldContinentsNodesMask,0,sizeof(sTaxiNodesMask));
561 for(uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i)
563 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i);
564 if(!node)
565 continue;
567 TaxiPathSetBySource::const_iterator src_i = sTaxiPathSetBySource.find(i);
568 if(src_i!=sTaxiPathSetBySource.end() && !src_i->second.empty())
570 bool ok = false;
571 for(TaxiPathSetForSource::const_iterator dest_i = src_i->second.begin();dest_i != src_i->second.end(); ++dest_i)
573 // not spell path
574 if(spellPaths.find(dest_i->second.ID)==spellPaths.end())
576 ok = true;
577 break;
581 if(!ok)
582 continue;
585 // valid taxi network node
586 uint8 field = (uint8)((i - 1) / 32);
587 uint32 submask = 1<<((i-1)%32);
588 sTaxiNodesMask[field] |= submask;
590 // old continent node (+ nodes virtually at old continents, check explicitly to avoid loading map files for zone info)
591 if (node->map_id < 2 || i == 82 || i == 83 || i == 93 || i == 94)
592 sOldContinentsNodesMask[field] |= submask;
596 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTotemCategoryStore, dbcPath,"TotemCategory.dbc");
597 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleStore, dbcPath,"Vehicle.dbc");
598 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleSeatStore, dbcPath,"VehicleSeat.dbc");
599 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapAreaStore, dbcPath,"WorldMapArea.dbc");
600 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapOverlayStore, dbcPath,"WorldMapOverlay.dbc");
601 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldSafeLocsStore, dbcPath,"WorldSafeLocs.dbc");
603 // error checks
604 if(bad_dbc_files.size() >= DBCFilesCount )
606 sLog.outError("\nIncorrect DataDir value in mangosd.conf or ALL required *.dbc files (%d) not found by path: %sdbc",DBCFilesCount,dataPath.c_str());
607 exit(1);
609 else if(!bad_dbc_files.empty() )
611 std::string str;
612 for(std::list<std::string>::iterator i = bad_dbc_files.begin(); i != bad_dbc_files.end(); ++i)
613 str += *i + "\n";
615 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());
616 exit(1);
619 // Check loaded DBC files proper version
620 if( !sSpellStore.LookupEntry(73190) || // last added spell in 3.3.0a
621 !sMapStore.LookupEntry(718) || // last map added in 3.3.0a
622 !sGemPropertiesStore.LookupEntry(1629) || // last gem property added in 3.3.0a
623 !sItemExtendedCostStore.LookupEntry(2935) || // last item extended cost added in 3.3.0a
624 !sCharTitlesStore.LookupEntry(177) || // last char title added in 3.3.0a
625 !sAreaStore.LookupEntry(3460) || // last area (areaflag) added in 3.3.0a
626 !sItemStore.LookupEntry(52062) ) // last client known item added in 3.3.0a
628 sLog.outError("\nYou have mixed version DBC files. Please re-extract DBC files for one from client build: %s",AcceptableClientBuildsListStr().c_str());
629 exit(1);
632 sLog.outString();
633 sLog.outString( ">> Initialized %d data stores", DBCFilesCount );
636 SimpleFactionsList const* GetFactionTeamList(uint32 faction)
638 FactionTeamMap::const_iterator itr = sFactionTeamMap.find(faction);
639 if(itr==sFactionTeamMap.end())
640 return NULL;
641 return &itr->second;
644 char* GetPetName(uint32 petfamily, uint32 dbclang)
646 if(!petfamily)
647 return NULL;
648 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(petfamily);
649 if(!pet_family)
650 return NULL;
651 return pet_family->Name[dbclang]?pet_family->Name[dbclang]:NULL;
654 TalentSpellPos const* GetTalentSpellPos(uint32 spellId)
656 TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId);
657 if(itr==sTalentSpellPosMap.end())
658 return NULL;
660 return &itr->second;
663 uint32 GetTalentSpellCost(uint32 spellId)
665 if(TalentSpellPos const* pos = GetTalentSpellPos(spellId))
666 return pos->rank+1;
668 return 0;
671 int32 GetAreaFlagByAreaID(uint32 area_id)
673 AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id);
674 if(i == sAreaFlagByAreaID.end())
675 return -1;
677 return i->second;
680 AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
682 int32 areaflag = GetAreaFlagByAreaID(area_id);
683 if(areaflag < 0)
684 return NULL;
686 return sAreaStore.LookupEntry(areaflag );
689 AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id)
691 if(area_flag)
692 return sAreaStore.LookupEntry(area_flag);
694 if(MapEntry const* mapEntry = sMapStore.LookupEntry(map_id))
695 return GetAreaEntryByAreaID(mapEntry->linked_zone);
697 return NULL;
700 uint32 GetAreaFlagByMapId(uint32 mapid)
702 AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid);
703 if(i == sAreaFlagByMapID.end())
704 return 0;
705 else
706 return i->second;
709 uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId)
711 if(mapid != 530 && mapid != 571) // speed for most cases
712 return mapid;
714 if(WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId))
715 return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id;
717 return mapid;
720 ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId)
722 mapid = GetVirtualMapForMapAndZone(mapid,zoneId);
723 if(mapid < 2)
724 return CONTENT_1_60;
726 MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
727 if(!mapEntry)
728 return CONTENT_1_60;
730 switch(mapEntry->Expansion())
732 default: return CONTENT_1_60;
733 case 1: return CONTENT_61_70;
734 case 2: return CONTENT_71_80;
738 ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id)
740 // not sorted, numbering index from 0
741 for(uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
743 ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i);
744 if(ch && ch->ChannelID == channel_id)
745 return ch;
747 return NULL;
750 bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId)
752 if(requiredTotemCategoryId==0)
753 return true;
754 if(itemTotemCategoryId==0)
755 return false;
757 TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId);
758 if(!itemEntry)
759 return false;
760 TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId);
761 if(!reqEntry)
762 return false;
764 if(itemEntry->categoryType!=reqEntry->categoryType)
765 return false;
767 return (itemEntry->categoryMask & reqEntry->categoryMask)==reqEntry->categoryMask;
770 void Zone2MapCoordinates(float& x,float& y,uint32 zone)
772 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
774 // if not listed then map coordinates (instance)
775 if(!maEntry)
776 return;
778 std::swap(x,y); // at client map coords swapped
779 x = x*((maEntry->x2-maEntry->x1)/100)+maEntry->x1;
780 y = y*((maEntry->y2-maEntry->y1)/100)+maEntry->y1; // client y coord from top to down
783 void Map2ZoneCoordinates(float& x,float& y,uint32 zone)
785 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
787 // if not listed then map coordinates (instance)
788 if(!maEntry)
789 return;
791 x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100);
792 y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100); // client y coord from top to down
793 std::swap(x,y); // client have map coords swapped
796 MapDifficulty const* GetMapDifficultyData(uint32 mapId, Difficulty difficulty)
798 MapDifficultyMap::const_iterator itr = sMapDifficultyMap.find(MAKE_PAIR32(mapId,difficulty));
799 return itr != sMapDifficultyMap.end() ? &itr->second : NULL;
802 PvPDifficultyEntry const* GetBattlegroundBracketByLevel( uint32 mapid, uint32 level )
804 // prevent out-of-range levels for dbc data
805 if (level > DEFAULT_MAX_LEVEL)
806 level = DEFAULT_MAX_LEVEL;
808 for(uint32 i = 0; i < sPvPDifficultyStore.GetNumRows(); ++i)
809 if (PvPDifficultyEntry const* entry = sPvPDifficultyStore.LookupEntry(i))
810 if (entry->mapId == mapid && entry->minLevel <= level && entry->maxLevel >= level)
811 return entry;
813 return NULL;
816 PvPDifficultyEntry const* GetBattlegroundBracketById(uint32 mapid, BattleGroundBracketId id)
818 for(uint32 i = 0; i < sPvPDifficultyStore.GetNumRows(); ++i)
819 if (PvPDifficultyEntry const* entry = sPvPDifficultyStore.LookupEntry(i))
820 if (entry->mapId == mapid && entry->GetBracketId() == id)
821 return entry;
823 return NULL;
826 uint32 const* GetTalentTabPages(uint32 cls)
828 return sTalentTabPages[cls];
831 // script support functions
832 MANGOS_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore() { return &sSoundEntriesStore; }
833 MANGOS_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore() { return &sSpellStore; }
834 MANGOS_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore() { return &sSpellRangeStore; }
835 MANGOS_DLL_SPEC DBCStorage <FactionEntry> const* GetFactionStore() { return &sFactionStore; }
836 MANGOS_DLL_SPEC DBCStorage <ItemEntry> const* GetItemDisplayStore() { return &sItemStore; }
837 MANGOS_DLL_SPEC DBCStorage <CreatureDisplayInfoEntry> const* GetCreatureDisplayStore() { return &sCreatureDisplayInfoStore; }
838 MANGOS_DLL_SPEC DBCStorage <EmotesEntry> const* GetEmotesStore() { return &sEmotesStore; }
839 MANGOS_DLL_SPEC DBCStorage <EmotesTextEntry> const* GetEmotesTextStore() { return &sEmotesTextStore; }