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

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

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

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