[9033] Fixed percent mana regneration from spell 53228 and ranks buff.
[getmangos.git] / src / game / DBCStores.cpp
blobd5bf0cbc34ef0d4db1f4f18f03248b686e710a8b
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"
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);
109 DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt);
110 DBCStorage <ScalingStatDistributionEntry> sScalingStatDistributionStore(ScalingStatDistributionfmt);
111 DBCStorage <ScalingStatValuesEntry> sScalingStatValuesStore(ScalingStatValuesfmt);
113 DBCStorage <SkillLineEntry> sSkillLineStore(SkillLinefmt);
114 DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore(SkillLineAbilityfmt);
116 DBCStorage <SoundEntriesEntry> sSoundEntriesStore(SoundEntriesfmt);
118 DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore(SpellItemEnchantmentfmt);
119 DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt);
120 DBCStorage <SpellEntry> sSpellStore(SpellEntryfmt);
121 SpellCategoryStore sSpellCategoryStore;
122 PetFamilySpellsStore sPetFamilySpellsStore;
124 DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore(SpellCastTimefmt);
125 DBCStorage <SpellDurationEntry> sSpellDurationStore(SpellDurationfmt);
126 DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore(SpellFocusObjectfmt);
127 DBCStorage <SpellRadiusEntry> sSpellRadiusStore(SpellRadiusfmt);
128 DBCStorage <SpellRangeEntry> sSpellRangeStore(SpellRangefmt);
129 DBCStorage <SpellRuneCostEntry> sSpellRuneCostStore(SpellRuneCostfmt);
130 DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftfmt);
131 DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore(StableSlotPricesfmt);
132 DBCStorage <SummonPropertiesEntry> sSummonPropertiesStore(SummonPropertiesfmt);
133 DBCStorage <TalentEntry> sTalentStore(TalentEntryfmt);
134 TalentSpellPosMap sTalentSpellPosMap;
135 DBCStorage <TalentTabEntry> sTalentTabStore(TalentTabEntryfmt);
137 // store absolute bit position for first rank for talent inspect
138 static uint32 sTalentTabPages[MAX_CLASSES][3];
140 DBCStorage <TaxiNodesEntry> sTaxiNodesStore(TaxiNodesEntryfmt);
141 TaxiMask sTaxiNodesMask;
142 TaxiMask sOldContinentsNodesMask;
144 // DBC used only for initialization sTaxiPathSetBySource at startup.
145 TaxiPathSetBySource sTaxiPathSetBySource;
146 DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt);
148 // DBC used only for initialization sTaxiPathNodeStore at startup.
149 TaxiPathNodesByPath sTaxiPathNodesByPath;
150 static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
152 DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt);
153 DBCStorage <VehicleEntry> sVehicleStore(VehicleEntryfmt);
154 DBCStorage <VehicleSeatEntry> sVehicleSeatStore(VehicleSeatEntryfmt);
155 DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore(WorldMapAreaEntryfmt);
156 DBCStorage <WorldMapOverlayEntry> sWorldMapOverlayStore(WorldMapOverlayEntryfmt);
157 DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt);
159 typedef std::list<std::string> StoreProblemList;
161 static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, const std::string& filename)
163 sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize);
165 // assert must fail after function call
166 return false;
169 template<class T>
170 inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, const std::string& dbc_path, const std::string& filename)
172 // compatibility format and C++ structure sizes
173 assert(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename));
175 std::string dbc_filename = dbc_path + filename;
176 if(storage.Load(dbc_filename.c_str()))
178 bar.step();
179 for(uint8 i = 0; i < MAX_LOCALE; ++i)
181 if(!(availableDbcLocales & (1 << i)))
182 continue;
184 std::string dbc_filename_loc = dbc_path + localeNames[i] + "/" + filename;
185 if(!storage.LoadStringsFrom(dbc_filename_loc.c_str()))
186 availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks
189 else
191 // sort problematic dbc to (1) non compatible and (2) non-existed
192 FILE * f=fopen(dbc_filename.c_str(),"rb");
193 if(f)
195 char buf[100];
196 snprintf(buf,100," (exist, but have %d fields instead " SIZEFMTD ") Wrong client version DBC file?",storage.GetFieldCount(),strlen(storage.GetFormat()));
197 errlist.push_back(dbc_filename + buf);
198 fclose(f);
200 else
201 errlist.push_back(dbc_filename);
205 void LoadDBCStores(const std::string& dataPath)
207 std::string dbcPath = dataPath+"dbc/";
209 const uint32 DBCFilesCount = 81;
211 barGoLink bar( DBCFilesCount );
213 StoreProblemList bad_dbc_files;
214 uint32 availableDbcLocales = 0xFFFFFFFF;
216 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaStore, dbcPath,"AreaTable.dbc");
218 // must be after sAreaStore loading
219 for(uint32 i = 0; i < sAreaStore.GetNumRows(); ++i) // areaflag numbered from 0
221 if(AreaTableEntry const* area = sAreaStore.LookupEntry(i))
223 // fill AreaId->DBC records
224 sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID),area->exploreFlag));
226 // fill MapId->DBC records ( skip sub zones and continents )
227 if(area->zone==0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530 && area->mapid != 571 )
228 sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid,area->exploreFlag));
232 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementStore, dbcPath,"Achievement.dbc");
233 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAchievementCriteriaStore, dbcPath,"Achievement_Criteria.dbc");
234 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc");
235 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaGroupStore, dbcPath,"AreaGroup.dbc");
236 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAuctionHouseStore, dbcPath,"AuctionHouse.dbc");
237 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc");
238 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc");
239 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBarberShopStyleStore, dbcPath,"BarberShopStyle.dbc");
240 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharStartOutfitStore, dbcPath,"CharStartOutfit.dbc");
241 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore, dbcPath,"CharTitles.dbc");
242 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore, dbcPath,"ChatChannels.dbc");
243 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore, dbcPath,"ChrClasses.dbc");
244 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrRacesStore, dbcPath,"ChrRaces.dbc");
245 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCinematicSequencesStore, dbcPath,"CinematicSequences.dbc");
246 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureDisplayInfoStore, dbcPath,"CreatureDisplayInfo.dbc");
247 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureFamilyStore, dbcPath,"CreatureFamily.dbc");
248 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureSpellDataStore, dbcPath,"CreatureSpellData.dbc");
249 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureTypeStore, dbcPath,"CreatureType.dbc");
250 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCurrencyTypesStore, dbcPath,"CurrencyTypes.dbc");
251 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityCostsStore, dbcPath,"DurabilityCosts.dbc");
252 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityQualityStore, dbcPath,"DurabilityQuality.dbc");
253 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesStore, dbcPath,"Emotes.dbc");
254 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesTextStore, dbcPath,"EmotesText.dbc");
255 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionStore, dbcPath,"Faction.dbc");
256 for (uint32 i=0;i<sFactionStore.GetNumRows(); ++i)
258 FactionEntry const * faction = sFactionStore.LookupEntry(i);
259 if (faction && faction->team)
261 SimpleFactionsList &flist = sFactionTeamMap[faction->team];
262 flist.push_back(i);
266 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore, dbcPath,"FactionTemplate.dbc");
267 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGameObjectDisplayInfoStore,dbcPath,"GameObjectDisplayInfo.dbc");
268 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc");
269 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphPropertiesStore, dbcPath,"GlyphProperties.dbc");
270 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGlyphSlotStore, dbcPath,"GlyphSlot.dbc");
272 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtBarberShopCostBaseStore,dbcPath,"gtBarberShopCostBase.dbc");
273 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtCombatRatingsStore, dbcPath,"gtCombatRatings.dbc");
275 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritBaseStore, dbcPath,"gtChanceToMeleeCritBase.dbc");
276 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritStore, dbcPath,"gtChanceToMeleeCrit.dbc");
278 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritBaseStore, dbcPath,"gtChanceToSpellCritBase.dbc");
279 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritStore, dbcPath,"gtChanceToSpellCrit.dbc");
281 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenHPStore, dbcPath,"gtOCTRegenHP.dbc");
282 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore, dbcPath,"gtOCTRegenMP.dbc"); -- not used currently
283 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenHPPerSptStore, dbcPath,"gtRegenHPPerSpt.dbc");
284 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenMPPerSptStore, dbcPath,"gtRegenMPPerSpt.dbc");
285 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sHolidaysStore, dbcPath,"Holidays.dbc");
286 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemStore, dbcPath,"Item.dbc");
287 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemBagFamilyStore, dbcPath,"ItemBagFamily.dbc");
288 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore, dbcPath,"ItemDisplayInfo.dbc"); -- not used currently
289 //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore, dbcPath,"ItemCondExtCosts.dbc");
290 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemExtendedCostStore, dbcPath,"ItemExtendedCost.dbc");
291 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemLimitCategoryStore, dbcPath,"ItemLimitCategory.dbc");
292 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomPropertiesStore,dbcPath,"ItemRandomProperties.dbc");
293 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomSuffixStore, dbcPath,"ItemRandomSuffix.dbc");
294 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemSetStore, dbcPath,"ItemSet.dbc");
295 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sLockStore, dbcPath,"Lock.dbc");
296 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMailTemplateStore, dbcPath,"MailTemplate.dbc");
297 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapStore, dbcPath,"Map.dbc");
299 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapDifficultyStore, dbcPath,"MapDifficulty.dbc");
300 // fill data
301 for(uint32 i = 1; i < sMapDifficultyStore.GetNumRows(); ++i)
302 if(MapDifficultyEntry const* entry = sMapDifficultyStore.LookupEntry(i))
303 sMapDifficultyMap[MAKE_PAIR32(entry->MapId,entry->Difficulty)] = MapDifficulty(entry->resetTime,entry->maxPlayers);
304 sMapDifficultyStore.Clear();
306 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMovieStore, dbcPath,"Movie.dbc");
307 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sQuestSortStore, dbcPath,"QuestSort.dbc");
308 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sRandomPropertiesPointsStore, dbcPath,"RandPropPoints.dbc");
309 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatDistributionStore, dbcPath,"ScalingStatDistribution.dbc");
310 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sScalingStatValuesStore, dbcPath,"ScalingStatValues.dbc");
311 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineStore, dbcPath,"SkillLine.dbc");
312 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineAbilityStore, dbcPath,"SkillLineAbility.dbc");
313 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSoundEntriesStore, dbcPath,"SoundEntries.dbc");
314 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellStore, dbcPath,"Spell.dbc");
315 for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
317 SpellEntry const * spell = sSpellStore.LookupEntry(i);
318 if(spell && spell->Category)
319 sSpellCategoryStore[spell->Category].insert(i);
321 // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields
322 // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view
323 #if MANGOS_ENDIAN == MANGOS_BIGENDIAN
324 std::swap(*((uint32*)(&spell->SpellFamilyFlags)),*(((uint32*)(&spell->SpellFamilyFlags))+1));
325 #endif
328 for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
330 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
332 if(!skillLine)
333 continue;
335 SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
337 if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0)
339 for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i)
341 CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i);
342 if(!cFamily)
343 continue;
345 if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1])
346 continue;
348 sPetFamilySpellsStore[i].insert(spellInfo->Id);
353 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellCastTimesStore, dbcPath,"SpellCastTimes.dbc");
354 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc");
355 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore, dbcPath,"SpellFocusObject.dbc");
356 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc");
357 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc");
358 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore, dbcPath,"SpellRadius.dbc");
359 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc");
360 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRuneCostStore, dbcPath,"SpellRuneCost.dbc");
361 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore, dbcPath,"SpellShapeshiftForm.dbc");
362 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sStableSlotPricesStore, dbcPath,"StableSlotPrices.dbc");
363 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSummonPropertiesStore, dbcPath,"SummonProperties.dbc");
364 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentStore, dbcPath,"Talent.dbc");
366 // create talent spells set
367 for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i)
369 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
370 if (!talentInfo) continue;
371 for (int j = 0; j < MAX_TALENT_RANK; j++)
372 if(talentInfo->RankID[j])
373 sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i,j);
376 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentTabStore, dbcPath,"TalentTab.dbc");
378 // prepare fast data access to bit pos of talent ranks for use at inspecting
380 // now have all max ranks (and then bit amount used for store talent ranks in inspect)
381 for(uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId)
383 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentTabId );
384 if(!talentTabInfo)
385 continue;
387 // prevent memory corruption; otherwise cls will become 12 below
388 if ((talentTabInfo->ClassMask & CLASSMASK_ALL_PLAYABLE)==0)
389 continue;
391 // store class talent tab pages
392 uint32 cls = 1;
393 for(uint32 m=1;!(m & talentTabInfo->ClassMask) && cls < MAX_CLASSES;m <<=1, ++cls) {}
395 sTalentTabPages[cls][talentTabInfo->tabpage]=talentTabId;
399 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiNodesStore, dbcPath,"TaxiNodes.dbc");
401 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathStore, dbcPath,"TaxiPath.dbc");
402 for(uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i)
403 if(TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i))
404 sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID,entry->price);
405 uint32 pathCount = sTaxiPathStore.GetNumRows();
407 //## TaxiPathNode.dbc ## Loaded only for initialization different structures
408 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathNodeStore, dbcPath,"TaxiPathNode.dbc");
409 // Calculate path nodes count
410 std::vector<uint32> pathLength;
411 pathLength.resize(pathCount); // 0 and some other indexes not used
412 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
413 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
415 if (pathLength[entry->path] < entry->index + 1)
416 pathLength[entry->path] = entry->index + 1;
418 // Set path length
419 sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used
420 for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i)
421 sTaxiPathNodesByPath[i].resize(pathLength[i]);
422 // fill data
423 for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i)
424 if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i))
425 sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay);
426 sTaxiPathNodeStore.Clear();
428 // Initialize global taxinodes mask
429 // include existed nodes that have at least single not spell base (scripted) path
431 std::set<uint32> spellPaths;
432 for(uint32 i = 1; i < sSpellStore.GetNumRows (); ++i)
433 if(SpellEntry const* sInfo = sSpellStore.LookupEntry (i))
434 for(int j=0; j < 3; ++j)
435 if(sInfo->Effect[j]==123 /*SPELL_EFFECT_SEND_TAXI*/)
436 spellPaths.insert(sInfo->EffectMiscValue[j]);
438 memset(sTaxiNodesMask,0,sizeof(sTaxiNodesMask));
439 memset(sOldContinentsNodesMask,0,sizeof(sTaxiNodesMask));
440 for(uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i)
442 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i);
443 if(!node)
444 continue;
446 TaxiPathSetBySource::const_iterator src_i = sTaxiPathSetBySource.find(i);
447 if(src_i!=sTaxiPathSetBySource.end() && !src_i->second.empty())
449 bool ok = false;
450 for(TaxiPathSetForSource::const_iterator dest_i = src_i->second.begin();dest_i != src_i->second.end(); ++dest_i)
452 // not spell path
453 if(spellPaths.find(dest_i->second.ID)==spellPaths.end())
455 ok = true;
456 break;
460 if(!ok)
461 continue;
464 // valid taxi network node
465 uint8 field = (uint8)((i - 1) / 32);
466 uint32 submask = 1<<((i-1)%32);
467 sTaxiNodesMask[field] |= submask;
469 // old continent node (+ nodes virtually at old continents, check explicitly to avoid loading map files for zone info)
470 if (node->map_id < 2 || i == 82 || i == 83 || i == 93 || i == 94)
471 sOldContinentsNodesMask[field] |= submask;
475 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTotemCategoryStore, dbcPath,"TotemCategory.dbc");
476 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleStore, dbcPath,"Vehicle.dbc");
477 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sVehicleSeatStore, dbcPath,"VehicleSeat.dbc");
478 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapAreaStore, dbcPath,"WorldMapArea.dbc");
479 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapOverlayStore, dbcPath,"WorldMapOverlay.dbc");
480 LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldSafeLocsStore, dbcPath,"WorldSafeLocs.dbc");
482 // error checks
483 if(bad_dbc_files.size() >= DBCFilesCount )
485 sLog.outError("\nIncorrect DataDir value in mangosd.conf or ALL required *.dbc files (%d) not found by path: %sdbc",DBCFilesCount,dataPath.c_str());
486 exit(1);
488 else if(!bad_dbc_files.empty() )
490 std::string str;
491 for(std::list<std::string>::iterator i = bad_dbc_files.begin(); i != bad_dbc_files.end(); ++i)
492 str += *i + "\n";
494 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());
495 exit(1);
498 // Check loaded DBC files proper version
499 if( !sSpellStore.LookupEntry(66530) || // last added spell in 3.1.3
500 !sMapStore.LookupEntry(624) || // last map added in 3.1.3
501 !sGemPropertiesStore.LookupEntry(1609) || // last gem property added in 3.1.3
502 !sItemExtendedCostStore.LookupEntry(2671) || // last item extended cost added in 3.1.3
503 !sCharTitlesStore.LookupEntry(166) || // last char title added in 3.1.3
504 !sAreaStore.LookupEntry(2905) || // last area (areaflag) added in 3.1.3
505 !sItemStore.LookupEntry(46894) ) // last client known item added in 3.1.3
507 sLog.outError("\nYou have _outdated_ DBC files. Please extract correct versions from current using client.");
508 exit(1);
511 sLog.outString();
512 sLog.outString( ">> Initialized %d data stores", DBCFilesCount );
515 SimpleFactionsList const* GetFactionTeamList(uint32 faction)
517 FactionTeamMap::const_iterator itr = sFactionTeamMap.find(faction);
518 if(itr==sFactionTeamMap.end())
519 return NULL;
520 return &itr->second;
523 char* GetPetName(uint32 petfamily, uint32 dbclang)
525 if(!petfamily)
526 return NULL;
527 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(petfamily);
528 if(!pet_family)
529 return NULL;
530 return pet_family->Name[dbclang]?pet_family->Name[dbclang]:NULL;
533 TalentSpellPos const* GetTalentSpellPos(uint32 spellId)
535 TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId);
536 if(itr==sTalentSpellPosMap.end())
537 return NULL;
539 return &itr->second;
542 uint32 GetTalentSpellCost(uint32 spellId)
544 if(TalentSpellPos const* pos = GetTalentSpellPos(spellId))
545 return pos->rank+1;
547 return 0;
550 int32 GetAreaFlagByAreaID(uint32 area_id)
552 AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id);
553 if(i == sAreaFlagByAreaID.end())
554 return -1;
556 return i->second;
559 AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
561 int32 areaflag = GetAreaFlagByAreaID(area_id);
562 if(areaflag < 0)
563 return NULL;
565 return sAreaStore.LookupEntry(areaflag );
568 AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id)
570 if(area_flag)
571 return sAreaStore.LookupEntry(area_flag);
573 if(MapEntry const* mapEntry = sMapStore.LookupEntry(map_id))
574 return GetAreaEntryByAreaID(mapEntry->linked_zone);
576 return NULL;
579 uint32 GetAreaFlagByMapId(uint32 mapid)
581 AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid);
582 if(i == sAreaFlagByMapID.end())
583 return 0;
584 else
585 return i->second;
588 uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId)
590 if(mapid != 530 && mapid != 571) // speed for most cases
591 return mapid;
593 if(WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId))
594 return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id;
596 return mapid;
599 ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId)
601 mapid = GetVirtualMapForMapAndZone(mapid,zoneId);
602 if(mapid < 2)
603 return CONTENT_1_60;
605 MapEntry const* mapEntry = sMapStore.LookupEntry(mapid);
606 if(!mapEntry)
607 return CONTENT_1_60;
609 switch(mapEntry->Expansion())
611 default: return CONTENT_1_60;
612 case 1: return CONTENT_61_70;
613 case 2: return CONTENT_71_80;
617 ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id)
619 // not sorted, numbering index from 0
620 for(uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
622 ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i);
623 if(ch && ch->ChannelID == channel_id)
624 return ch;
626 return NULL;
629 bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId)
631 if(requiredTotemCategoryId==0)
632 return true;
633 if(itemTotemCategoryId==0)
634 return false;
636 TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId);
637 if(!itemEntry)
638 return false;
639 TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId);
640 if(!reqEntry)
641 return false;
643 if(itemEntry->categoryType!=reqEntry->categoryType)
644 return false;
646 return (itemEntry->categoryMask & reqEntry->categoryMask)==reqEntry->categoryMask;
649 void Zone2MapCoordinates(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 std::swap(x,y); // at client map coords swapped
658 x = x*((maEntry->x2-maEntry->x1)/100)+maEntry->x1;
659 y = y*((maEntry->y2-maEntry->y1)/100)+maEntry->y1; // client y coord from top to down
662 void Map2ZoneCoordinates(float& x,float& y,uint32 zone)
664 WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone);
666 // if not listed then map coordinates (instance)
667 if(!maEntry)
668 return;
670 x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100);
671 y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100); // client y coord from top to down
672 std::swap(x,y); // client have map coords swapped
675 MapDifficulty const* GetMapDifficultyData(uint32 mapId, Difficulty difficulty)
677 MapDifficultyMap::const_iterator itr = sMapDifficultyMap.find(MAKE_PAIR32(mapId,difficulty));
678 return itr != sMapDifficultyMap.end() ? &itr->second : NULL;
681 uint32 const* GetTalentTabPages(uint32 cls)
683 return sTalentTabPages[cls];
686 // script support functions
687 MANGOS_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore() { return &sSoundEntriesStore; }
688 MANGOS_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore() { return &sSpellStore; }
689 MANGOS_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore() { return &sSpellRangeStore; }
690 MANGOS_DLL_SPEC DBCStorage <FactionEntry> const* GetFactionStore() { return &sFactionStore; }
691 MANGOS_DLL_SPEC DBCStorage <ItemEntry> const* GetItemDisplayStore() { return &sItemStore; }
692 MANGOS_DLL_SPEC DBCStorage <CreatureDisplayInfoEntry> const* GetCreatureDisplayStore() { return &sCreatureDisplayInfoStore; }
693 MANGOS_DLL_SPEC DBCStorage <EmotesEntry> const* GetEmotesStore() { return &sEmotesStore; }
694 MANGOS_DLL_SPEC DBCStorage <EmotesTextEntry> const* GetEmotesTextStore() { return &sEmotesTextStore; }