1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef DBCSTORES_H |
---|
22 | #define DBCSTORES_H |
---|
23 | |
---|
24 | #include "Common.h" |
---|
25 | //#include "DataStore.h" |
---|
26 | #include "dbcfile.h" |
---|
27 | #include "DBCStructure.h" |
---|
28 | |
---|
29 | #include <list> |
---|
30 | |
---|
31 | typedef std::list<uint32> SimpleFactionsList; |
---|
32 | |
---|
33 | SimpleFactionsList const* GetFactionTeamList(uint32 faction); |
---|
34 | char* GetPetName(uint32 petfamily, uint32 dbclang); |
---|
35 | uint32 GetTalentSpellCost(uint32 spellId); |
---|
36 | TalentSpellPos const* GetTalentSpellPos(uint32 spellId); |
---|
37 | |
---|
38 | AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id); |
---|
39 | AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id); |
---|
40 | uint32 GetAreaFlagByMapId(uint32 mapid); |
---|
41 | |
---|
42 | uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId); |
---|
43 | |
---|
44 | enum ContentLevels |
---|
45 | { |
---|
46 | CONTENT_1_60 = 0, |
---|
47 | CONTENT_61_70, |
---|
48 | CONTENT_71_80 |
---|
49 | }; |
---|
50 | ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId); |
---|
51 | |
---|
52 | ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id); |
---|
53 | |
---|
54 | bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId); |
---|
55 | |
---|
56 | void Zone2MapCoordinates(float& x,float& y,uint32 zone); |
---|
57 | void Map2ZoneCoordinates(float& x,float& y,uint32 zone); |
---|
58 | |
---|
59 | uint32 GetTalentInspectBitPosInTab(uint32 talentId); |
---|
60 | uint32 GetTalentTabInspectBitSize(uint32 talentTabId); |
---|
61 | uint32 const* /*[3]*/ GetTalentTabPages(uint32 cls); |
---|
62 | |
---|
63 | template<class T> |
---|
64 | class DBCStorage |
---|
65 | { |
---|
66 | typedef std::list<char*> StringPoolList; |
---|
67 | public: |
---|
68 | explicit DBCStorage(const char *f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { } |
---|
69 | ~DBCStorage() { Clear(); } |
---|
70 | |
---|
71 | T const* LookupEntry(uint32 id) const { return (id>=nCount)?NULL:indexTable[id]; } |
---|
72 | uint32 GetNumRows() const { return nCount; } |
---|
73 | char const* GetFormat() const { return fmt; } |
---|
74 | uint32 GetFieldCount() const { return fieldCount; } |
---|
75 | |
---|
76 | bool Load(char const* fn) |
---|
77 | { |
---|
78 | DBCFile dbc; |
---|
79 | // Check if load was sucessful, only then continue |
---|
80 | if(!dbc.Load(fn, fmt)) |
---|
81 | return false; |
---|
82 | |
---|
83 | fieldCount = dbc.GetCols(); |
---|
84 | m_dataTable = (T*)dbc.AutoProduceData(fmt,nCount,(char**&)indexTable); |
---|
85 | m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable)); |
---|
86 | |
---|
87 | // error in dbc file at loading if NULL |
---|
88 | return indexTable!=NULL; |
---|
89 | } |
---|
90 | |
---|
91 | bool LoadStringsFrom(char const* fn) |
---|
92 | { |
---|
93 | // DBC must be already loaded using Load |
---|
94 | if(!indexTable) |
---|
95 | return false; |
---|
96 | |
---|
97 | DBCFile dbc; |
---|
98 | // Check if load was successful, only then continue |
---|
99 | if(!dbc.Load(fn, fmt)) |
---|
100 | return false; |
---|
101 | |
---|
102 | m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable)); |
---|
103 | |
---|
104 | return true; |
---|
105 | } |
---|
106 | |
---|
107 | void Clear() |
---|
108 | { |
---|
109 | if (!indexTable) |
---|
110 | return; |
---|
111 | |
---|
112 | delete[] ((char*)indexTable); |
---|
113 | indexTable = NULL; |
---|
114 | delete[] ((char*)m_dataTable); |
---|
115 | m_dataTable = NULL; |
---|
116 | |
---|
117 | while(!m_stringPoolList.empty()) |
---|
118 | { |
---|
119 | delete[] m_stringPoolList.front(); |
---|
120 | m_stringPoolList.pop_front(); |
---|
121 | } |
---|
122 | nCount = 0; |
---|
123 | } |
---|
124 | |
---|
125 | private: |
---|
126 | uint32 nCount; |
---|
127 | uint32 fieldCount; |
---|
128 | char const* fmt; |
---|
129 | T** indexTable; |
---|
130 | T* m_dataTable; |
---|
131 | StringPoolList m_stringPoolList; |
---|
132 | }; |
---|
133 | |
---|
134 | extern DBCStorage <AreaTableEntry> sAreaStore;// recommend access using functions |
---|
135 | extern DBCStorage <AreaTriggerEntry> sAreaTriggerStore; |
---|
136 | extern DBCStorage <BankBagSlotPricesEntry> sBankBagSlotPricesStore; |
---|
137 | extern DBCStorage <BattlemasterListEntry> sBattlemasterListStore; |
---|
138 | //extern DBCStorage <ChatChannelsEntry> sChatChannelsStore; -- accessed using function, no usable index |
---|
139 | extern DBCStorage <CharTitlesEntry> sCharTitlesStore; |
---|
140 | extern DBCStorage <ChrClassesEntry> sChrClassesStore; |
---|
141 | extern DBCStorage <ChrRacesEntry> sChrRacesStore; |
---|
142 | extern DBCStorage <CreatureDisplayInfoEntry> sCreatureDisplayInfoStore; |
---|
143 | extern DBCStorage <CreatureFamilyEntry> sCreatureFamilyStore; |
---|
144 | extern DBCStorage <CreatureSpellDataEntry> sCreatureSpellDataStore; |
---|
145 | extern DBCStorage <DurabilityCostsEntry> sDurabilityCostsStore; |
---|
146 | extern DBCStorage <DurabilityQualityEntry> sDurabilityQualityStore; |
---|
147 | extern DBCStorage <EmotesTextEntry> sEmotesTextStore; |
---|
148 | extern DBCStorage <FactionEntry> sFactionStore; |
---|
149 | extern DBCStorage <FactionTemplateEntry> sFactionTemplateStore; |
---|
150 | extern DBCStorage <GemPropertiesEntry> sGemPropertiesStore; |
---|
151 | |
---|
152 | extern DBCStorage <GtCombatRatingsEntry> sGtCombatRatingsStore; |
---|
153 | extern DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore; |
---|
154 | extern DBCStorage <GtChanceToMeleeCritEntry> sGtChanceToMeleeCritStore; |
---|
155 | extern DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore; |
---|
156 | extern DBCStorage <GtChanceToSpellCritEntry> sGtChanceToSpellCritStore; |
---|
157 | extern DBCStorage <GtOCTRegenHPEntry> sGtOCTRegenHPStore; |
---|
158 | //extern DBCStorage <GtOCTRegenMPEntry> sGtOCTRegenMPStore; -- not used currently |
---|
159 | extern DBCStorage <GtRegenHPPerSptEntry> sGtRegenHPPerSptStore; |
---|
160 | extern DBCStorage <GtRegenMPPerSptEntry> sGtRegenMPPerSptStore; |
---|
161 | extern DBCStorage <ItemEntry> sItemStore; |
---|
162 | //extern DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore; -- not used currently |
---|
163 | extern DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore; |
---|
164 | extern DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore; |
---|
165 | extern DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore; |
---|
166 | extern DBCStorage <ItemSetEntry> sItemSetStore; |
---|
167 | extern DBCStorage <LockEntry> sLockStore; |
---|
168 | extern DBCStorage <MailTemplateEntry> sMailTemplateStore; |
---|
169 | extern DBCStorage <MapEntry> sMapStore; |
---|
170 | extern DBCStorage <QuestSortEntry> sQuestSortStore; |
---|
171 | extern DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore; |
---|
172 | extern DBCStorage <SkillLineEntry> sSkillLineStore; |
---|
173 | extern DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore; |
---|
174 | extern DBCStorage <SoundEntriesEntry> sSoundEntriesStore; |
---|
175 | extern DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore; |
---|
176 | extern DBCStorage <SpellDurationEntry> sSpellDurationStore; |
---|
177 | extern DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore; |
---|
178 | extern DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore; |
---|
179 | extern DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore; |
---|
180 | extern SpellCategoryStore sSpellCategoryStore; |
---|
181 | extern PetFamilySpellsStore sPetFamilySpellsStore; |
---|
182 | extern DBCStorage <SpellRadiusEntry> sSpellRadiusStore; |
---|
183 | extern DBCStorage <SpellRangeEntry> sSpellRangeStore; |
---|
184 | extern DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore; |
---|
185 | extern DBCStorage <SpellEntry> sSpellStore; |
---|
186 | extern DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore; |
---|
187 | extern DBCStorage <TalentEntry> sTalentStore; |
---|
188 | extern DBCStorage <TalentTabEntry> sTalentTabStore; |
---|
189 | extern DBCStorage <TaxiNodesEntry> sTaxiNodesStore; |
---|
190 | extern DBCStorage <TaxiPathEntry> sTaxiPathStore; |
---|
191 | extern TaxiMask sTaxiNodesMask; |
---|
192 | extern TaxiPathSetBySource sTaxiPathSetBySource; |
---|
193 | extern TaxiPathNodesByPath sTaxiPathNodesByPath; |
---|
194 | extern DBCStorage <TotemCategoryEntry> sTotemCategoryStore; |
---|
195 | //extern DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore; -- use Zone2MapCoordinates and Map2ZoneCoordinates |
---|
196 | extern DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore; |
---|
197 | |
---|
198 | void LoadDBCStores(std::string dataPath); |
---|
199 | |
---|
200 | // script support functions |
---|
201 | TRINITY_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore(); |
---|
202 | TRINITY_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore(); |
---|
203 | TRINITY_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore(); |
---|
204 | #endif |
---|