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

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

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-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
79            DBCFile dbc;
80            // Check if load was sucessful, only then continue
81            if(!dbc.Load(fn, fmt))
82                return false;
83
84            fieldCount = dbc.GetCols();
85            m_dataTable = (T*)dbc.AutoProduceData(fmt,nCount,(char**&)indexTable);
86            m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable));
87
88            // error in dbc file at loading if NULL
89            return indexTable!=NULL;
90        }
91
92        bool LoadStringsFrom(char const* fn)
93        {
94            // DBC must be already loaded using Load
95            if(!indexTable)
96                return false;
97
98            DBCFile dbc;
99            // Check if load was successful, only then continue
100            if(!dbc.Load(fn, fmt))
101                return false;
102
103            m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable));
104
105            return true;
106        }
107
108        void Clear()
109        {
110            if (!indexTable)
111                return;
112
113            delete[] ((char*)indexTable);
114            indexTable = NULL;
115            delete[] ((char*)m_dataTable);
116            m_dataTable = NULL;
117
118            while(!m_stringPoolList.empty())
119            {
120                delete[] m_stringPoolList.front();
121                m_stringPoolList.pop_front();
122            }
123            nCount = 0;
124        }
125
126    private:
127        uint32 nCount;
128        uint32 fieldCount;
129        char const* fmt;
130        T** indexTable;
131        T* m_dataTable;
132        StringPoolList m_stringPoolList;
133};
134
135extern DBCStorage <AreaTableEntry>               sAreaStore;// recommend access using functions
136extern DBCStorage <AreaTriggerEntry>             sAreaTriggerStore;
137extern DBCStorage <BankBagSlotPricesEntry>       sBankBagSlotPricesStore;
138extern DBCStorage <BattlemasterListEntry>        sBattlemasterListStore;
139//extern DBCStorage <ChatChannelsEntry>           sChatChannelsStore; -- accessed using function, no usable index
140extern DBCStorage <CharTitlesEntry>              sCharTitlesStore;
141extern DBCStorage <ChrClassesEntry>              sChrClassesStore;
142extern DBCStorage <ChrRacesEntry>                sChrRacesStore;
143extern DBCStorage <CreatureDisplayInfoEntry>     sCreatureDisplayInfoStore;
144extern DBCStorage <CreatureFamilyEntry>          sCreatureFamilyStore;
145extern DBCStorage <CreatureSpellDataEntry>       sCreatureSpellDataStore;
146extern DBCStorage <DurabilityCostsEntry>         sDurabilityCostsStore;
147extern DBCStorage <DurabilityQualityEntry>       sDurabilityQualityStore;
148extern DBCStorage <EmotesTextEntry>              sEmotesTextStore;
149extern DBCStorage <FactionEntry>                 sFactionStore;
150extern DBCStorage <FactionTemplateEntry>         sFactionTemplateStore;
151extern DBCStorage <GemPropertiesEntry>           sGemPropertiesStore;
152
153extern DBCStorage <GtCombatRatingsEntry>         sGtCombatRatingsStore;
154extern DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore;
155extern DBCStorage <GtChanceToMeleeCritEntry>     sGtChanceToMeleeCritStore;
156extern DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore;
157extern DBCStorage <GtChanceToSpellCritEntry>     sGtChanceToSpellCritStore;
158extern DBCStorage <GtOCTRegenHPEntry>            sGtOCTRegenHPStore;
159//extern DBCStorage <GtOCTRegenMPEntry>            sGtOCTRegenMPStore; -- not used currently
160extern DBCStorage <GtRegenHPPerSptEntry>         sGtRegenHPPerSptStore;
161extern DBCStorage <GtRegenMPPerSptEntry>         sGtRegenMPPerSptStore;
162extern DBCStorage <ItemEntry>                    sItemStore;
163//extern DBCStorage <ItemDisplayInfoEntry>      sItemDisplayInfoStore; -- not used currently
164extern DBCStorage <ItemExtendedCostEntry>        sItemExtendedCostStore;
165extern DBCStorage <ItemRandomPropertiesEntry>    sItemRandomPropertiesStore;
166extern DBCStorage <ItemRandomSuffixEntry>        sItemRandomSuffixStore;
167extern DBCStorage <ItemSetEntry>                 sItemSetStore;
168extern DBCStorage <LockEntry>                    sLockStore;
169extern DBCStorage <MailTemplateEntry>            sMailTemplateStore;
170extern DBCStorage <MapEntry>                     sMapStore;
171extern DBCStorage <QuestSortEntry>               sQuestSortStore;
172extern DBCStorage <RandomPropertiesPointsEntry>  sRandomPropertiesPointsStore;
173extern DBCStorage <SkillLineEntry>               sSkillLineStore;
174extern DBCStorage <SkillLineAbilityEntry>        sSkillLineAbilityStore;
175extern DBCStorage <SoundEntriesEntry>            sSoundEntriesStore;
176extern DBCStorage <SpellCastTimesEntry>          sSpellCastTimesStore;
177extern DBCStorage <SpellDurationEntry>           sSpellDurationStore;
178extern DBCStorage <SpellFocusObjectEntry>        sSpellFocusObjectStore;
179extern DBCStorage <SpellItemEnchantmentEntry>    sSpellItemEnchantmentStore;
180extern DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore;
181extern SpellCategoryStore                        sSpellCategoryStore;
182extern PetFamilySpellsStore                      sPetFamilySpellsStore;
183extern DBCStorage <SpellRadiusEntry>             sSpellRadiusStore;
184extern DBCStorage <SpellRangeEntry>              sSpellRangeStore;
185extern DBCStorage <SpellShapeshiftEntry>         sSpellShapeshiftStore;
186extern DBCStorage <SpellEntry>                   sSpellStore;
187extern DBCStorage <StableSlotPricesEntry>        sStableSlotPricesStore;
188extern DBCStorage <TalentEntry>                  sTalentStore;
189extern DBCStorage <TalentTabEntry>               sTalentTabStore;
190extern DBCStorage <TaxiNodesEntry>               sTaxiNodesStore;
191extern DBCStorage <TaxiPathEntry>                sTaxiPathStore;
192extern TaxiMask                                  sTaxiNodesMask;
193extern TaxiPathSetBySource                       sTaxiPathSetBySource;
194extern TaxiPathNodesByPath                       sTaxiPathNodesByPath;
195extern DBCStorage <TotemCategoryEntry>           sTotemCategoryStore;
196//extern DBCStorage <WorldMapAreaEntry>           sWorldMapAreaStore; -- use Zone2MapCoordinates and Map2ZoneCoordinates
197extern DBCStorage <WorldSafeLocsEntry>           sWorldSafeLocsStore;
198
199void LoadDBCStores(std::string dataPath);
200
201// script support functions
202TRINITY_DLL_SPEC DBCStorage <SoundEntriesEntry>  const* GetSoundEntriesStore();
203TRINITY_DLL_SPEC DBCStorage <SpellEntry>         const* GetSpellStore();
204TRINITY_DLL_SPEC DBCStorage <SpellRangeEntry>    const* GetSpellRangeStore();
205#endif
Note: See TracBrowser for help on using the browser.