root/trunk/src/shared/Database/DBCStores.h @ 279

Revision 279, 8.8 kB (checked in by yumileroy, 17 years ago)

Merged commit 269 (5f0e38da128a).

Original author: gvcoman
Date: 2008-11-21 14:34:05-05:00

Line 
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
31typedef std::list<uint32> SimpleFactionsList;
32
33SimpleFactionsList const* GetFactionTeamList(uint32 faction);
34char* GetPetName(uint32 petfamily, uint32 dbclang);
35uint32 GetTalentSpellCost(uint32 spellId);
36TalentSpellPos const* GetTalentSpellPos(uint32 spellId);
37
38AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id);
39AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id);
40uint32 GetAreaFlagByMapId(uint32 mapid);
41
42uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId);
43
44enum ContentLevels
45{
46    CONTENT_1_60 = 0,
47    CONTENT_61_70,
48    CONTENT_71_80
49};
50ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId);
51
52ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id);
53
54bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId);
55
56void Zone2MapCoordinates(float& x,float& y,uint32 zone);
57void Map2ZoneCoordinates(float& x,float& y,uint32 zone);
58
59uint32 GetTalentInspectBitPosInTab(uint32 talentId);
60uint32 GetTalentTabInspectBitSize(uint32 talentTabId);
61uint32 const* /*[3]*/ GetTalentTabPages(uint32 cls);
62
63template<class T>
64class 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
134extern DBCStorage <AreaTableEntry>               sAreaStore;// recommend access using functions
135extern DBCStorage <AreaTriggerEntry>             sAreaTriggerStore;
136extern DBCStorage <BankBagSlotPricesEntry>       sBankBagSlotPricesStore;
137extern DBCStorage <BattlemasterListEntry>        sBattlemasterListStore;
138//extern DBCStorage <ChatChannelsEntry>           sChatChannelsStore; -- accessed using function, no usable index
139extern DBCStorage <CharTitlesEntry>              sCharTitlesStore;
140extern DBCStorage <ChrClassesEntry>              sChrClassesStore;
141extern DBCStorage <ChrRacesEntry>                sChrRacesStore;
142extern DBCStorage <CreatureDisplayInfoEntry>     sCreatureDisplayInfoStore;
143extern DBCStorage <CreatureFamilyEntry>          sCreatureFamilyStore;
144extern DBCStorage <CreatureSpellDataEntry>       sCreatureSpellDataStore;
145extern DBCStorage <DurabilityCostsEntry>         sDurabilityCostsStore;
146extern DBCStorage <DurabilityQualityEntry>       sDurabilityQualityStore;
147extern DBCStorage <EmotesTextEntry>              sEmotesTextStore;
148extern DBCStorage <FactionEntry>                 sFactionStore;
149extern DBCStorage <FactionTemplateEntry>         sFactionTemplateStore;
150extern DBCStorage <GemPropertiesEntry>           sGemPropertiesStore;
151
152extern DBCStorage <GtCombatRatingsEntry>         sGtCombatRatingsStore;
153extern DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore;
154extern DBCStorage <GtChanceToMeleeCritEntry>     sGtChanceToMeleeCritStore;
155extern DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore;
156extern DBCStorage <GtChanceToSpellCritEntry>     sGtChanceToSpellCritStore;
157extern DBCStorage <GtOCTRegenHPEntry>            sGtOCTRegenHPStore;
158//extern DBCStorage <GtOCTRegenMPEntry>            sGtOCTRegenMPStore; -- not used currently
159extern DBCStorage <GtRegenHPPerSptEntry>         sGtRegenHPPerSptStore;
160extern DBCStorage <GtRegenMPPerSptEntry>         sGtRegenMPPerSptStore;
161extern DBCStorage <ItemEntry>                    sItemStore;
162//extern DBCStorage <ItemDisplayInfoEntry>      sItemDisplayInfoStore; -- not used currently
163extern DBCStorage <ItemExtendedCostEntry>        sItemExtendedCostStore;
164extern DBCStorage <ItemRandomPropertiesEntry>    sItemRandomPropertiesStore;
165extern DBCStorage <ItemRandomSuffixEntry>        sItemRandomSuffixStore;
166extern DBCStorage <ItemSetEntry>                 sItemSetStore;
167extern DBCStorage <LockEntry>                    sLockStore;
168extern DBCStorage <MailTemplateEntry>            sMailTemplateStore;
169extern DBCStorage <MapEntry>                     sMapStore;
170extern DBCStorage <QuestSortEntry>               sQuestSortStore;
171extern DBCStorage <RandomPropertiesPointsEntry>  sRandomPropertiesPointsStore;
172extern DBCStorage <SkillLineEntry>               sSkillLineStore;
173extern DBCStorage <SkillLineAbilityEntry>        sSkillLineAbilityStore;
174extern DBCStorage <SoundEntriesEntry>            sSoundEntriesStore;
175extern DBCStorage <SpellCastTimesEntry>          sSpellCastTimesStore;
176extern DBCStorage <SpellDurationEntry>           sSpellDurationStore;
177extern DBCStorage <SpellFocusObjectEntry>        sSpellFocusObjectStore;
178extern DBCStorage <SpellItemEnchantmentEntry>    sSpellItemEnchantmentStore;
179extern DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore;
180extern SpellCategoryStore                        sSpellCategoryStore;
181extern PetFamilySpellsStore                      sPetFamilySpellsStore;
182extern DBCStorage <SpellRadiusEntry>             sSpellRadiusStore;
183extern DBCStorage <SpellRangeEntry>              sSpellRangeStore;
184extern DBCStorage <SpellShapeshiftEntry>         sSpellShapeshiftStore;
185extern DBCStorage <SpellEntry>                   sSpellStore;
186extern DBCStorage <StableSlotPricesEntry>        sStableSlotPricesStore;
187extern DBCStorage <TalentEntry>                  sTalentStore;
188extern DBCStorage <TalentTabEntry>               sTalentTabStore;
189extern DBCStorage <TaxiNodesEntry>               sTaxiNodesStore;
190extern DBCStorage <TaxiPathEntry>                sTaxiPathStore;
191extern TaxiMask                                  sTaxiNodesMask;
192extern TaxiPathSetBySource                       sTaxiPathSetBySource;
193extern TaxiPathNodesByPath                       sTaxiPathNodesByPath;
194extern DBCStorage <TotemCategoryEntry>           sTotemCategoryStore;
195//extern DBCStorage <WorldMapAreaEntry>           sWorldMapAreaStore; -- use Zone2MapCoordinates and Map2ZoneCoordinates
196extern DBCStorage <WorldSafeLocsEntry>           sWorldSafeLocsStore;
197
198void LoadDBCStores(std::string dataPath);
199
200// script support functions
201TRINITY_DLL_SPEC DBCStorage <SoundEntriesEntry>  const* GetSoundEntriesStore();
202TRINITY_DLL_SPEC DBCStorage <SpellEntry>         const* GetSpellStore();
203TRINITY_DLL_SPEC DBCStorage <SpellRangeEntry>    const* GetSpellRangeStore();
204#endif
Note: See TracBrowser for help on using the browser.