PageRenderTime 34ms CodeModel.GetById 19ms app.highlight 12ms RepoModel.GetById 0ms app.codeStats 1ms

/src/tools/map_extractor/adt.h

https://gitlab.com/tkrokli/TrinityCore_434
C Header | 314 lines | 237 code | 32 blank | 45 comment | 14 complexity | ed8fdbb59ade1d0600d9625083bb142e MD5 | raw file
  1/*
  2 * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
  3 * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
  4 *
  5 * This program is free software; you can redistribute it and/or modify it
  6 * under the terms of the GNU General Public License as published by the
  7 * Free Software Foundation; either version 2 of the License, or (at your
  8 * option) any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful, but WITHOUT
 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 13 * more details.
 14 *
 15 * You should have received a copy of the GNU General Public License along
 16 * with this program. If not, see <http://www.gnu.org/licenses/>.
 17 */
 18
 19#ifndef ADT_H
 20#define ADT_H
 21
 22#include "loadlib.h"
 23
 24#define TILESIZE (533.33333f)
 25#define CHUNKSIZE ((TILESIZE) / 16.0f)
 26#define UNITSIZE (CHUNKSIZE / 8.0f)
 27
 28enum LiquidType
 29{
 30    LIQUID_TYPE_WATER = 0,
 31    LIQUID_TYPE_OCEAN = 1,
 32    LIQUID_TYPE_MAGMA = 2,
 33    LIQUID_TYPE_SLIME = 3
 34};
 35
 36//**************************************************************************************
 37// ADT file class
 38//**************************************************************************************
 39#define ADT_CELLS_PER_GRID    16
 40#define ADT_CELL_SIZE         8
 41#define ADT_GRID_SIZE         (ADT_CELLS_PER_GRID*ADT_CELL_SIZE)
 42
 43#pragma pack(push, 1)
 44
 45//
 46// Adt file height map chunk
 47//
 48class adt_MCVT
 49{
 50    union{
 51        uint32 fcc;
 52        char   fcc_txt[4];
 53    };
 54    uint32 size;
 55public:
 56    float height_map[(ADT_CELL_SIZE+1)*(ADT_CELL_SIZE+1)+ADT_CELL_SIZE*ADT_CELL_SIZE];
 57
 58    bool  prepareLoadedData();
 59};
 60
 61//
 62// Adt file liquid map chunk (old)
 63//
 64class adt_MCLQ
 65{
 66    union{
 67        uint32 fcc;
 68        char   fcc_txt[4];
 69    };
 70public:
 71    uint32 size;
 72    float height1;
 73    float height2;
 74    struct liquid_data{
 75        uint32 light;
 76        float  height;
 77    } liquid[ADT_CELL_SIZE+1][ADT_CELL_SIZE+1];
 78
 79    // 1<<0 - ochen
 80    // 1<<1 - lava/slime
 81    // 1<<2 - water
 82    // 1<<6 - all water
 83    // 1<<7 - dark water
 84    // == 0x0F - not show liquid
 85    uint8 flags[ADT_CELL_SIZE][ADT_CELL_SIZE];
 86    uint8 data[84];
 87    bool  prepareLoadedData();
 88};
 89
 90//
 91// Adt file cell chunk
 92//
 93class adt_MCNK
 94{
 95    union{
 96        uint32 fcc;
 97        char   fcc_txt[4];
 98    };
 99public:
100    uint32 size;
101    uint32 flags;
102    uint32 ix;
103    uint32 iy;
104    uint32 nLayers;
105    uint32 nDoodadRefs;
106    uint32 offsMCVT;        // height map
107    uint32 offsMCNR;        // Normal vectors for each vertex
108    uint32 offsMCLY;        // Texture layer definitions
109    uint32 offsMCRF;        // A list of indices into the parent file's MDDF chunk
110    uint32 offsMCAL;        // Alpha maps for additional texture layers
111    uint32 sizeMCAL;
112    uint32 offsMCSH;        // Shadow map for static shadows on the terrain
113    uint32 sizeMCSH;
114    uint32 areaid;
115    uint32 nMapObjRefs;
116    uint32 holes;
117    uint16 s[2];
118    uint32 data1;
119    uint32 data2;
120    uint32 data3;
121    uint32 predTex;
122    uint32 nEffectDoodad;
123    uint32 offsMCSE;
124    uint32 nSndEmitters;
125    uint32 offsMCLQ;         // Liqid level (old)
126    uint32 sizeMCLQ;         //
127    float  zpos;
128    float  xpos;
129    float  ypos;
130    uint32 offsMCCV;         // offsColorValues in WotLK
131    uint32 props;
132    uint32 effectId;
133
134    bool   prepareLoadedData();
135    adt_MCVT *getMCVT()
136    {
137        if (offsMCVT)
138            return (adt_MCVT *)((uint8 *)this + offsMCVT);
139        return 0;
140    }
141    adt_MCLQ *getMCLQ()
142    {
143        if (offsMCLQ)
144            return (adt_MCLQ *)((uint8 *)this + offsMCLQ);
145        return 0;
146    }
147};
148
149//
150// Adt file grid chunk
151//
152class adt_MCIN
153{
154    union{
155        uint32 fcc;
156        char   fcc_txt[4];
157    };
158public:
159    uint32 size;
160    struct adt_CELLS{
161        uint32 offsMCNK;
162        uint32 size;
163        uint32 flags;
164        uint32 asyncId;
165    } cells[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
166
167    bool   prepareLoadedData();
168    // offset from begin file (used this-84)
169    adt_MCNK *getMCNK(int x, int y)
170    {
171        if (cells[x][y].offsMCNK)
172            return (adt_MCNK *)((uint8 *)this + cells[x][y].offsMCNK - 84);
173        return 0;
174    }
175};
176
177#define ADT_LIQUID_HEADER_FULL_LIGHT   0x01
178#define ADT_LIQUID_HEADER_NO_HIGHT     0x02
179
180struct adt_liquid_header{
181    uint16 liquidType;             // Index from LiquidType.dbc
182    uint16 formatFlags;
183    float  heightLevel1;
184    float  heightLevel2;
185    uint8  xOffset;
186    uint8  yOffset;
187    uint8  width;
188    uint8  height;
189    uint32 offsData2a;
190    uint32 offsData2b;
191};
192
193//
194// Adt file liquid data chunk (new)
195//
196class adt_MH2O
197{
198public:
199    union{
200        uint32 fcc;
201        char   fcc_txt[4];
202    };
203    uint32 size;
204
205    struct adt_LIQUID{
206        uint32 offsData1;
207        uint32 used;
208        uint32 offsData2;
209    } liquid[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
210
211    bool   prepareLoadedData();
212
213    adt_liquid_header *getLiquidData(int x, int y)
214    {
215        if (liquid[x][y].used && liquid[x][y].offsData1)
216            return (adt_liquid_header *)((uint8*)this + 8 + liquid[x][y].offsData1);
217        return 0;
218    }
219
220    float *getLiquidHeightMap(adt_liquid_header *h)
221    {
222        if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
223            return 0;
224        if (h->offsData2b)
225            return (float *)((uint8*)this + 8 + h->offsData2b);
226        return 0;
227    }
228
229    uint8 *getLiquidLightMap(adt_liquid_header *h)
230    {
231        if (h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT)
232            return 0;
233        if (h->offsData2b)
234        {
235            if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
236                return (uint8 *)((uint8*)this + 8 + h->offsData2b);
237            return (uint8 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4);
238        }
239        return 0;
240    }
241
242    uint32 *getLiquidFullLightMap(adt_liquid_header *h)
243    {
244        if (!(h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT))
245            return 0;
246        if (h->offsData2b)
247        {
248            if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
249                return (uint32 *)((uint8*)this + 8 + h->offsData2b);
250            return (uint32 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4);
251        }
252        return 0;
253    }
254
255    uint64 getLiquidShowMap(adt_liquid_header *h)
256    {
257        if (h->offsData2a)
258            return *((uint64 *)((uint8*)this + 8 + h->offsData2a));
259        else
260            return 0xFFFFFFFFFFFFFFFFuLL;
261    }
262
263};
264
265//
266// Adt file header chunk
267//
268class ADT_file;
269class adt_MHDR
270{
271    friend class ADT_file;
272
273    union{
274        uint32 fcc;
275        char   fcc_txt[4];
276    };
277public:
278    uint32 size;
279
280    uint32 flags;
281    uint32 offsMCIN;           // MCIN
282    uint32 offsTex;               // MTEX
283    uint32 offsModels;           // MMDX
284    uint32 offsModelsIds;       // MMID
285    uint32 offsMapObejcts;       // MWMO
286    uint32 offsMapObejctsIds;  // MWID
287    uint32 offsDoodsDef;       // MDDF
288    uint32 offsObjectsDef;     // MODF
289    uint32 offsMFBO;           // MFBO
290    uint32 offsMH2O;           // MH2O
291    uint32 data1;
292    uint32 data2;
293    uint32 data3;
294    uint32 data4;
295    uint32 data5;
296    bool prepareLoadedData();
297    adt_MCIN* getMCIN() { return offsMCIN ? (adt_MCIN *)((uint8 *)&flags+offsMCIN) : NULL; }
298    adt_MH2O* getMH2O() { return offsMH2O ? (adt_MH2O *)((uint8 *)&flags+offsMH2O) : NULL; }
299};
300
301class ADT_file : public FileLoader{
302public:
303    bool prepareLoadedData();
304    ADT_file();
305    ~ADT_file();
306    void free();
307
308    adt_MHDR* a_grid;
309    adt_MCNK* cells[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
310};
311
312#pragma pack(pop)
313
314#endif