[8483] Implement glyph 43361.
[getmangos.git] / src / game / DBCStores.cpp
blob9050a1b524d29ad5b71ba386d29687f139bb855f
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "DBCStores.h"
20 #include "Policies/SingletonImp.h"
21 #include "Log.h"
22 #include "ProgressBar.h"
23 #include "SharedDefines.h"
25 #include "DBCfmt.h"
27 #include <map>
29 typedef std::map<uint16,uint32> AreaFlagByAreaID;
30 typedef std::map<uint32,uint32> AreaFlagByMapID;
32 DBCStorage <AreaTableEntry> sAreaStore(AreaTableEntryfmt);
33 DBCStorage <AreaGroupEntry> sAreaGroupStore(AreaGroupEntryfmt);
34 static AreaFlagByAreaID sAreaFlagByAreaID;
35 static AreaFlagByMapID sAreaFlagByMapID; // for instances without generated *.map files
37 DBCStorage <AchievementEntry> sAchievementStore(Achievementfmt);
38 DBCStorage <AchievementCriteriaEntry> sAchievementCriteriaStore(AchievementCriteriafmt);
39 DBCStorage <AreaTriggerEntry> sAreaTriggerStore(AreaTriggerEntryfmt);
40 DBCStorage <AuctionHouseEntry> sAuctionHouseStore(AuctionHouseEntryfmt);
41 DBCStorage <BankBagSlotPricesEntry> sBankBagSlotPricesStore(BankBagSlotPricesEntryfmt);
42 DBCStorage <BattlemasterListEntry> sBattlemasterListStore(BattlemasterListEntryfmt);
43 DBCStorage <BarberShopStyleEntry> sBarberShopStyleStore(BarberShopStyleEntryfmt);
44 DBCStorage <CharStartOutfitEntry> sCharStartOutfitStore(CharStartOutfitEntryfmt);
45 DBCStorage <CharTitlesEntry> sCharTitlesStore(CharTitlesEntryfmt);
46 DBCStorage <ChatChannelsEntry> sChatChannelsStore(ChatChannelsEntryfmt);
47 DBCStorage <ChrClassesEntry> sChrClassesStore(ChrClassesEntryfmt);
48 DBCStorage <ChrRacesEntry> sChrRacesStore(ChrRacesEntryfmt);
49 DBCStorage <CinematicSequencesEntry> sCinematicSequencesStore(CinematicSequencesEntryfmt);
50 DBCStorage <CreatureDisplayInfoEntry> sCreatureDisplayInfoStore(CreatureDisplayInfofmt);
51 DBCStorage <CreatureFamilyEntry> sCreatureFamilyStore(CreatureFamilyfmt);
52 DBCStorage <CreatureSpellDataEntry> sCreatureSpellDataStore(CreatureSpellDatafmt);
53 DBCStorage <CreatureTypeEntry> sCreatureTypeStore(CreatureTypefmt);
54 DBCStorage <CurrencyTypesEntry> sCurrencyTypesStore(CurrencyTypesfmt);
56 DBCStorage <DurabilityQualityEntry> sDurabilityQualityStore(DurabilityQualityfmt);
57 DBCStorage <DurabilityCostsEntry> sDurabilityCostsStore(DurabilityCostsfmt);
59 DBCStorage <EmotesEntry> sEmotesStore(EmotesEntryfmt);
60 DBCStorage <EmotesTextEntry> sEmotesTextStore(EmotesTextEntryfmt);
62 typedef std::map<uint32,SimpleFactionsList> FactionTeamMap;
63 static FactionTeamMap sFactionTeamMap;
64 DBCStorage <FactionEntry> sFactionStore(FactionEntryfmt);
65 DBCStorage <FactionTemplateEntry> sFactionTemplateStore(FactionTemplateEntryfmt);
67 DBCStorage <GameObjectDisplayInfoEntry> sGameObjectDisplayInfoStore(GameObjectDisplayInfofmt);
68 DBCStorage <GemPropertiesEntry> sGemPropertiesStore(GemPropertiesEntryfmt);
69 DBCStorage <GlyphPropertiesEntry> sGlyphPropertiesStore(GlyphPropertiesfmt);
70 DBCStorage <GlyphSlotEntry> sGlyphSlotStore(GlyphSlotfmt);
72 DBCStorage <GtBarberShopCostBaseEntry> sGtBarberShopCostBaseStore(GtBarberShopCostBasefmt);
73 DBCStorage <GtCombatRatingsEntry> sGtCombatRatingsStore(GtCombatRatingsfmt);
74 DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore(GtChanceToMeleeCritBasefmt);
75 DBCStorage <GtChanceToMeleeCritEntry> sGtChanceToMeleeCritStore(GtChanceToMeleeCritfmt);
76 DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore(GtChanceToSpellCritBasefmt);
77 DBCStorage <GtChanceToSpellCritEntry> sGtChanceToSpellCritStore(GtChanceToSpellCritfmt);
78 DBCStorage <GtOCTRegenHPEntry> sGtOCTRegenHPStore(GtOCTRegenHPfmt);
79 //DBCStorage <GtOCTRegenMPEntry> sGtOCTRegenMPStore(GtOCTRegenMPfmt); -- not used currently
80 DBCStorage <GtRegenHPPerSptEntry> sGtRegenHPPerSptStore(GtRegenHPPerSptfmt);
81 DBCStorage <GtRegenMPPerSptEntry> sGtRegenMPPerSptStore(GtRegenMPPerSptfmt);
83 DBCStorage <HolidaysEntry> sHolidaysStore(Holidaysfmt);
85 DBCStorage <ItemEntry> sItemStore(Itemfmt);
86 DBCStorage <ItemBagFamilyEntry> sItemBagFamilyStore(ItemBagFamilyfmt);
87 //DBCStorage <ItemCondExtCostsEntry> sItemCondExtCostsStore(ItemCondExtCostsEntryfmt);
88 //DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently
89 DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt);
90 DBCStorage <ItemLimitCategoryEntry> sItemLimitCategoryStore(ItemLimitCategoryEntryfmt);
91 DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore(ItemRandomPropertiesfmt);
92 DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore(ItemRandomSuffixfmt);
93 DBCStorage <ItemSetEntry> sItemSetStore(ItemSetEntryfmt);
95 DBCStorage <LockEntry> sLockStore(LockEntryfmt);
97 DBCStorage <MailTemplateEntry> sMailTemplateStore(MailTemplateEntryfmt);
98 DBCStorage <MapEntry> sMapStore(MapEntryfmt);
99 DBCStorage <MovieEntry> sMovieStore(MovieEntryfmt);
101 DBCStorage <QuestSortEntry> sQuestSortStore(QuestSortEntryfmt);
103 DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt);
104 DBCStorage <ScalingStatDistributionEntry> sScalingStatDistributionStore(ScalingStatDistributionfmt);
105 DBCStorage <ScalingStatValuesEntry> sScalingStatValuesStore(ScalingStatValuesfmt);
107 DBCStorage <SkillLineEntry> sSkillLineStore(SkillLinefmt);
108 DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore(SkillLineAbilityfmt);
110 DBCStorage <SoundEntriesEntry> sSoundEntriesStore(SoundEntriesfmt);
112 DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore(SpellItemEnchantmentfmt);
113 DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt);
114 DBCStorage <SpellEntry> sSpellStore(SpellEntryfmt);
115 SpellCategoryStore sSpellCategoryStore;
116 PetFamilySpellsStore sPetFamilySpellsStore;
118 DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore(SpellCastTimefmt);
119 DBCStorage <SpellDurationEntry> sSpellDurationStore(SpellDurationfmt);
120 DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore(SpellFocusObjectfmt);
121 DBCStorage <SpellRadiusEntry> sSpellRadiusStore(SpellRadiusfmt);
122 DBCStorage <SpellRangeEntry> sSpellRangeStore(SpellRangefmt);
123 DBCStorage <SpellRuneCostEntry> sSpellRuneCostStore(SpellRuneCostfmt);
124 DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftfmt);
125 DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore(StableSlotPricesfmt);
126 //DBCStorage <SummonPropertiesEntry> sSummonPropertiesStore(SummonPropertiesfmt);
127 DBCStorage <TalentEntry> sTalentStore(TalentEntryfmt);
128 TalentSpellPosMap sTalentSpellPosMap;
129 DBCStorage <TalentTabEntry> sTalentTabStore(TalentTabEntryfmt);
131 // store absolute bit position for first rank for talent inspect
132 static uint32 sTalentTabPages[12/*MAX_CLASSES*/][3];
134 DBCStorage <TaxiNodesEntry> sTaxiNodesStore(TaxiNodesEntryfmt);
135 TaxiMask sTaxiNodesMask;
136 TaxiMask sOldContinentsNodesMask;
138 // DBC used only for initialization sTaxiPathSetBySource at startup.
139 TaxiPathSetBySource sTaxiPathSetBySource;
140 DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt);
142 // DBC used only for initialization sTaxiPathSetBySource at startup.
143 TaxiPathNodesByPath sTaxiPathNodesByPath;
145 static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
146 DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt);
147 DBCStorage <VehicleEntry> sVehicleStore(VehicleEntryfmt);
148 DBCStorage <VehicleSeatEntry> sVehicleSeatStore(VehicleSeatEntryfmt);
149 DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore(WorldMapAreaEntryfmt);
150 DBCStorage <WorldMapOverlayEntry> sWorldMapOverlayStore(WorldMapOverlayEntryfmt);
151 DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt);
153 typedef std::list<std::string> StoreProblemList;
155 static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, const std::string& filename)
157 sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize);
159 // assert must fail after function call
160 return false;
163 template<class T>
164 inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, const std::string& dbc_path, const std::string& filename)
166 // compatibility format and C++ structure sizes
167 assert(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename));
169 std::string dbc_filename = dbc_path + filename;
170 if(storage.Load(dbc_filename.c_str()))
172 bar.step();
173 for(uint8 i = 0; i < MAX_LOCALE; ++i)
175 if(!(availableDbcLocales & (1 << i)))
176 continue;
178 std::string dbc_filename_loc = dbc_path + localeNames[i] + "/" + filename;
179 if(!storage.LoadStringsFrom(dbc_filename_loc.c_str()))
180 availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks
183 else
185 // sort problematic dbc to (1) non compatible and (2) non-existed
186 FILE * f=fopen(dbc_filename.c_str(),"rb");
187 if(f)
189 char buf[100];
190 snprintf(buf,100," (exist, but have %d fields instead " SIZEFMTD ") Wrong client version DBC file?",storage.GetFieldCount(),strlen(storage.GetFormat()));
191 errlist.push_back(dbc_filename + buf);
192 fclose(f);
194 else
195 errlist.push_back(dbc_filename);
199 void LoadDBCStores(const std::string& dataPath)
201 std::string dbcPath = dataPath+"dbc/";
203 const uint32 DBCFilesCount = 79;
205 barGoLink bar( DBCFilesCount );
207 StoreProblemList bad_dbc_files;
208 uint32 availableDbcLocales = 0xFFFFFFFF;
210 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaStore, dbcPath,"AreaTable.dbc");
212 // must be after sAreaStore loading
213 for(uint32 i = 0; i < sAreaStore.GetNumRows(); ++i) // areaflag numbered from 0
215 if(AreaTableEntry const* area = sAreaStore.LookupEntry(i))
217 // fill AreaId->DBC records
218 sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID),area->exploreFlag));
220 // fill MapId->DBC records ( skip sub zones and continents )
221 if(area->zone==0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530 && area->mapid != 571 )
222 sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid,area->exploreFlag));
226 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementStore, dbcPath,"Achievement.dbc");
227 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementCriteriaStore, dbcPath,"Achievement_Criteria.dbc");
228 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc");
229 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaGroupStore, dbcPath,"AreaGroup.dbc");
230 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAuctionHouseStore, dbcPath,"AuctionHouse.dbc");
231 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc");
232 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc");
233 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBarberShopStyleStore, dbcPath,"BarberShopStyle.dbc");
234 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharStartOutfitStore, dbcPath,"CharStartOutfit.dbc");
236 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore, dbcPath,"CharTitles.dbc");
237 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore, dbcPath,"ChatChannels.dbc");
238 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore, dbcPath,"ChrClasses.dbc");
239 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrRacesStore, dbcPath,"ChrRaces.dbc");
240 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCinematicSequencesStore, dbcPath,"CinematicSequences.dbc");
241 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureDisplayInfoStore, dbcPath,"CreatureDisplayInfo.dbc");
242 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureFamilyStore, dbcPath,"CreatureFamily.dbc");
243 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureSpellDataStore, dbcPath,"CreatureSpellData.dbc");
244 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureTypeStore, dbcPath,"CreatureType.dbc");
245 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCurrencyTypesStore, dbcPath,"CurrencyTypes.dbc");
246 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityCostsStore, dbcPath,"DurabilityCosts.dbc");
247 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityQualityStore, dbcPath,"DurabilityQuality.dbc");
248 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesStore, dbcPath,"Emotes.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,sGameObjectDisplayInfoStore,dbcPath,"GameObjectDisplayInfo.dbc");
263 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc");
264 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphPropertiesStore, dbcPath,"GlyphProperties.dbc");
265 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphSlotStore, dbcPath,"GlyphSlot.dbc");
267 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtBarberShopCostBaseStore,dbcPath,"gtBarberShopCostBase.dbc");
268 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtCombatRatingsStore, dbcPath,"gtCombatRatings.dbc");
270 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritBaseStore, dbcPath,"gtChanceToMeleeCritBase.dbc");
271 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritStore, dbcPath,"gtChanceToMeleeCrit.dbc");
273 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritBaseStore, dbcPath,"gtChanceToSpellCritBase.dbc");
274 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritStore, dbcPath,"gtChanceToSpellCrit.dbc");
276 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenHPStore, dbcPath,"gtOCTRegenHP.dbc");
277 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore, dbcPath,"gtOCTRegenMP.dbc"); -- not used currently
278 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenHPPerSptStore, dbcPath,"gtRegenHPPerSpt.dbc");
279 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenMPPerSptStore, dbcPath,"gtRegenMPPerSpt.dbc");
280 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sHolidaysStore, dbcPath,"Holidays.dbc");
281 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemStore, dbcPath,"Item.dbc");
282 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemBagFamilyStore, dbcPath,"ItemBagFamily.dbc");
283 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore, dbcPath,"ItemDisplayInfo.dbc"); -- not used currently
284 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore, dbcPath,"ItemCondExtCosts.dbc");
285 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemExtendedCostStore, dbcPath,"ItemExtendedCost.dbc");
286 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemLimitCategoryStore, dbcPath,"ItemLimitCategory.dbc");
287 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomPropertiesStore,dbcPath,"ItemRandomProperties.dbc");
288 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomSuffixStore, dbcPath,"ItemRandomSuffix.dbc");
289 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemSetStore, dbcPath,"ItemSet.dbc");
290 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sLockStore, dbcPath,"Lock.dbc");
291 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMailTemplateStore, dbcPath,"MailTemplate.dbc");
292 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapStore, dbcPath,"Map.dbc");
293 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMovieStore, dbcPath,"Movie.dbc");
294 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sQuestSortStore, dbcPath,"QuestSort.dbc");
295 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sRandomPropertiesPointsStore, dbcPath,"RandPropPoints.dbc");
296 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatDistributionStore, dbcPath,"ScalingStatDistribution.dbc");
297 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatValuesStore, dbcPath,"ScalingStatValues.dbc");
298 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineStore, dbcPath,"SkillLine.dbc");
299 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineAbilityStore, dbcPath,"SkillLineAbility.dbc");
300 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSoundEntriesStore, dbcPath,"SoundEntries.dbc");
301 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellStore, dbcPath,"Spell.dbc");
302 for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
304 SpellEntry const * spell = sSpellStore.LookupEntry(i);
305 if(spell && spell->Category)
306 sSpellCategoryStore[spell->Category].insert(i);
308 // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields
309 // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view
310 #if MANGOS_ENDIAN == MANGOS_BIGENDIAN
311 std::swap(*((uint32*)(&spell->SpellFamilyFlags)),*(((uint32*)(&spell->SpellFamilyFlags))+1));
312 #endif
315 for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
317 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
319 if(!skillLine)
320 continue;
322 SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
324 if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0)
326 for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i)
328 CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i);
329 if(!cFamily)
330 continue;
332 if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1])
333 continue;
335 sPetFamilySpellsStore[i].insert(spellInfo->Id);
340 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellCastTimesStore, dbcPath,"SpellCastTimes.dbc");
341 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc");
342 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore, dbcPath,"SpellFocusObject.dbc");
343 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc");
344 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc");
345 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore, dbcPath,"SpellRadius.dbc");
346 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc");
347 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRuneCostStore, dbcPath,"SpellRuneCost.dbc");
348 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore, dbcPath,"SpellShapeshiftForm.dbc");
349 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sStableSlotPricesStore, dbcPath,"StableSlotPrices.dbc");
350 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSummonPropertiesStore, dbcPath,"SummonProperties.dbc");
351 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentStore, dbcPath,"Talent.dbc");
353 // create talent spells set
354 for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i)
356 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
357 if (!talentInfo) continue;
358 for (int j = 0; j < MAX_TALENT_RANK; j++)
359 if(talentInfo->RankID[j])
360 sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i,j);
363 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentTabStore, dbcPath,"TalentTab.dbc");
365 // prepare fast data access to bit pos of talent ranks for use at inspecting
367 // now have all max ranks (and then bit amount used for store talent ranks in inspect)
368 for(uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId)
370 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentTabId );
371 if(!talentTabInfo)
372 continue;
374 // prevent memory corruption; otherwise cls will become 12 below
375 if ((talentTabInfo->ClassMask & CLASSMASK_ALL_PLAYABLE)==0)
376 continue;
378 // store class talent tab pages
379 uint32 cls = 1;
380 for(uint32 m=1;!(m & talentTabInfo->ClassMask) && cls < MAX_CLASSES;m <<=1, ++cls) {}
382 sTalentTabPages[cls][talentTabInfo->tabpage]=talentTabId;
386 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiNodesStore, dbcPath,"TaxiNodes.dbc");
388 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathStore, dbcPath,"TaxiPath.dbc");
389 for(uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i)
390 if(TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i))
391 sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID,entry->price);
392 uint32 pathCount = sTaxiPathStore.GetNumRows();
394 //## TaxiPathNode.dbc ## Loaded only for initialization different structures
395 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathNodeStore, dbcPath,"TaxiPathNode.dbc");
396 // Calculate path nodes count
397 std::vector<uint32> pathLength;
398 pathLength.resize(pathCount); // 0 and some other indexes not used
399 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
400 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
402 if (pathLength[entry->path] < entry->index + 1)
403 pathLength[entry->path] = entry->index + 1;
405 // Set path length
406 sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used
407 for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i)
408 sTaxiPathNodesByPath[i].resize(pathLength[i]);
409 // fill data
410 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
411 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
412 sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay);
413 sTaxiPathNodeStore.Clear();
415 // Initialize global taxinodes mask
416 // include existed nodes that have at least single not spell base (scripted) path
418 std::set<uint32> spellPaths;
419 for(uint32 i = 1; i < sSpellStore.GetNumRows (); ++i)
420 if(SpellEntry const* sInfo = sSpellStore.LookupEntry (i))
421 for(int j=0; j < 3; ++j)
422 if(sInfo->Effect[j]==123 /*SPELL_EFFECT_SEND_TAXI*/)
423 spellPaths.insert(sInfo->EffectMiscValue[j]);
425 memset(sTaxiNodesMask,0,sizeof(sTaxiNodesMask));
426 memset(sOldContinentsNodesMask,0,sizeof(sTaxiNodesMask));
427 for(uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i)
429 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i);
430 if(!node)
431 continue;
433 TaxiPathSetBySource::const_iterator src_i = sTaxiPathSetBySource.find(i);
434 if(src_i!=sTaxiPathSetBySource.end() && !src_i->second.empty())
436 bool ok = false;
437 for(TaxiPathSetForSource::const_iterator dest_i = src_i->second.begin();dest_i != src_i->second.end(); ++dest_i)
439 // not spell path
440 if(spellPaths.find(dest_i->second.ID)==spellPaths.end())
442 ok = true;
443 break;
447 if(!ok)
448 continue;
451 // valid taxi network node
452 uint8 field = (uint8)((i - 1) / 32);
453 uint32 submask = 1<<((i-1)%32);
454 sTaxiNodesMask[field] |= submask;
456 // old continent node (+ nodes virtually at old continents, check explicitly to avoid loading map files for zone info)
457 if (node->map_id < 2 || i == 82 || i == 83 || i == 93 || i == 94)
458 sOldContinentsNodesMask[field] |= submask;
462 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTotemCategoryStore, dbcPath,"TotemCategory.dbc");
463 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleStore, dbcPath,"Vehicle.dbc");
464 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleSeatStore, dbcPath,"VehicleSeat.dbc");
465 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapAreaStore, dbcPath,"WorldMapArea.dbc");
466 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapOverlayStore, dbcPath,"WorldMapOverlay.dbc");
467 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldSafeLocsStore, dbcPath,"WorldSafeLocs.dbc");
469 // error checks
470 if(bad_dbc_files.size() >= DBCFilesCount )
472 sLog.outError("\nIncorrect DataDir value in mangosd.conf or ALL required *.dbc files (%d) not found by path: %sdbc",DBCFilesCount,dataPath.c_str());
473 exit(1);
475 else if(!bad_dbc_files.empty() )
477 std::string str;
478 for(std::list<std::string>::iterator i = bad_dbc_files.begin(); i != bad_dbc_files.end(); ++i)
479 str += *i + "\n";
481 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());
482 exit(1);
485 // Check loaded DBC files proper version
486 if( !sSpellStore.LookupEntry(66530) || // last added spell in 3.1.3
487 !sMapStore.LookupEntry(624) || // last map added in 3.1.3
488 !sGemPropertiesStore.LookupEntry(1609) || // last gem property added in 3.1.3
489 !sItemExtendedCostStore.LookupEntry(2671) || // last item extended cost added in 3.1.3
490 !sCharTitlesStore.LookupEntry(166) || // last char title added in 3.1.3
491 !sAreaStore.LookupEntry(2905) || // last area (areaflag) added in 3.1.3
492 !sItemStore.LookupEntry(46894) ) // last client known item added in 3.1.3
494 sLog.outError("\nYou have _outdated_ DBC files. Please extract correct versions from current using client.");
495 exit(1);
498 sLog.outString();
499 sLog.outString( ">> Initialized %d data stores", DBCFilesCount );
502 SimpleFactionsList const* GetFactionTeamList(uint32 faction)
504 FactionTeamMap::const_iterator itr = sFactionTeamMap.find(faction);
505 if(itr==sFactionTeamMap.end())
506 return NULL;
507 return &itr->second;
510 char* GetPetName(uint32 petfamily, uint32 dbclang)
512 if(!petfamily)
513 return NULL;
514 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(petfamily);
515 if(!pet_family)
516 return NULL;
517 return pet_family->Name[dbclang]?pet_family->Name[dbclang]:NULL;
520 TalentSpellPos const* GetTalentSpellPos(uint32 spellId)
522 TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId);
523 if(itr==sTalentSpellPosMap.end())
524 return NULL;
526 return &itr->second;
529 uint32 GetTalentSpellCost(uint32 spellId)
531 if(TalentSpellPos const* pos = GetTalentSpellPos(spellId))
532 return pos->rank+1;
534 return 0;
537 int32 GetAreaFlagByAreaID(uint32 area_id)
539 AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id);
540 if(i == sAreaFlagByAreaID.end())
541 return -1;
543 return i->second;
546 AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
548 int32 areaflag = GetAreaFlagByAreaID(area_id);
549 if(areaflag < 0)
550 return NULL;
552 return sAreaStore.LookupEntry(areaflag );
555 AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id)
557 if(area_flag)
558 return sAreaStore.LookupEntry(area_flag);
560 if(MapEntry const* mapEntry = sMapStore.LookupEntry(map_id))
561 return GetAreaEntryByAreaID(mapEntry->linked_zone);
563 return NULL;
566 uint32 GetAreaFlagByMapId(uint32 mapid)
568 AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid);
569 if(i == sAreaFlagByMapID.end())
570 return 0;
571 else
572 return i->second;
575 uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId)
577 if(mapid != 530 && mapid != 571) // speed for most cases
578 return mapid;
580 if(WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId))
581 return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id;
583 return mapid;
586 ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId)
588 mapid = GetVirtualMapForMapAndZone(mapid,zoneId);
589 if(mapid < 2)
590 return CONTENT_1_60;
592 MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
593 if(!mapEntry)
594 return CONTENT_1_60;
596 switch(mapEntry->Expansion())
598 default: return CONTENT_1_60;
599 case 1: return CONTENT_61_70;
600 case 2: return CONTENT_71_80;
604 ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id)
606 // not sorted, numbering index from 0
607 for(uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
609 ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i);
610 if(ch && ch->ChannelID == channel_id)
611 return ch;
613 return NULL;
616 bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId)
618 if(requiredTotemCategoryId==0)
619 return true;
620 if(itemTotemCategoryId==0)
621 return false;
623 TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId);
624 if(!itemEntry)
625 return false;
626 TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId);
627 if(!reqEntry)
628 return false;
630 if(itemEntry->categoryType!=reqEntry->categoryType)
631 return false;
633 return (itemEntry->categoryMask & reqEntry->categoryMask)==reqEntry->categoryMask;
636 void Zone2MapCoordinates(float& x,float& y,uint32 zone)
638 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
640 // if not listed then map coordinates (instance)
641 if(!maEntry)
642 return;
644 std::swap(x,y); // at client map coords swapped
645 x = x*((maEntry->x2-maEntry->x1)/100)+maEntry->x1;
646 y = y*((maEntry->y2-maEntry->y1)/100)+maEntry->y1; // client y coord from top to down
649 void Map2ZoneCoordinates(float& x,float& y,uint32 zone)
651 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
653 // if not listed then map coordinates (instance)
654 if(!maEntry)
655 return;
657 x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100);
658 y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100); // client y coord from top to down
659 std::swap(x,y); // client have map coords swapped
662 uint32 const* GetTalentTabPages(uint32 cls)
664 return sTalentTabPages[cls];
667 // script support functions
668 MANGOS_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore() { return &sSoundEntriesStore; }
669 MANGOS_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore() { return &sSpellStore; }
670 MANGOS_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore() { return &sSpellRangeStore; }
671 MANGOS_DLL_SPEC DBCStorage <FactionEntry> const* GetFactionStore() { return &sFactionStore; }
672 MANGOS_DLL_SPEC DBCStorage <ItemEntry> const* GetItemDisplayStore() { return &sItemStore; }
673 MANGOS_DLL_SPEC DBCStorage <CreatureDisplayInfoEntry> const* GetCreatureDisplayStore() { return &sCreatureDisplayInfoStore; }
674 MANGOS_DLL_SPEC DBCStorage <EmotesEntry> const* GetEmotesStore() { return &sEmotesStore; }
675 MANGOS_DLL_SPEC DBCStorage <EmotesTextEntry> const* GetEmotesTextStore() { return &sEmotesTextStore; }