[8587] MaNGOS 0.14 release.
[getmangos.git] / contrib / extractor / loadlib / adt.cpp
blobfde70681113cc67bbdef60589aca0d4e1f6aa51e
1 #define _CRT_SECURE_NO_DEPRECATE
3 #include "adt.h"
5 // Helper
6 int holetab_h[4] = {0x1111, 0x2222, 0x4444, 0x8888};
7 int holetab_v[4] = {0x000F, 0x00F0, 0x0F00, 0xF000};
9 bool isHole(int holes, int i, int j)
11 int testi = i / 2;
12 int testj = j / 4;
13 if(testi > 3) testi = 3;
14 if(testj > 3) testj = 3;
15 return (holes & holetab_h[testi] & holetab_v[testj]) != 0;
19 // Adt file loader class
21 ADT_file::ADT_file()
23 a_grid = 0;
26 ADT_file::~ADT_file()
28 free();
31 void ADT_file::free()
33 a_grid = 0;
34 FileLoader::free();
38 // Adt file check function
40 bool ADT_file::prepareLoadedData()
42 // Check parent
43 if (!FileLoader::prepareLoadedData())
44 return false;
46 // Check and prepare MHDR
47 a_grid = (adt_MHDR *)(GetData()+8+version->size);
48 if (!a_grid->prepareLoadedData())
49 return false;
51 return true;
54 bool adt_MHDR::prepareLoadedData()
56 if (fcc != 'MHDR')
57 return false;
59 if (size!=sizeof(adt_MHDR)-8)
60 return false;
62 // Check and prepare MCIN
63 if (offsMCIN && !getMCIN()->prepareLoadedData())
64 return false;
66 // Check and prepare MH2O
67 if (offsMH2O && !getMH2O()->prepareLoadedData())
68 return false;
70 return true;
73 bool adt_MCIN::prepareLoadedData()
75 if (fcc != 'MCIN')
76 return false;
78 // Check cells data
79 for (int i=0; i<ADT_CELLS_PER_GRID;i++)
80 for (int j=0; j<ADT_CELLS_PER_GRID;j++)
81 if (cells[i][j].offsMCNK && !getMCNK(i,j)->prepareLoadedData())
82 return false;
84 return true;
87 bool adt_MH2O::prepareLoadedData()
89 if (fcc != 'MH2O')
90 return false;
92 // Check liquid data
93 // for (int i=0; i<ADT_CELLS_PER_GRID;i++)
94 // for (int j=0; j<ADT_CELLS_PER_GRID;j++)
96 return true;
99 bool adt_MCNK::prepareLoadedData()
101 if (fcc != 'MCNK')
102 return false;
104 // Check height map
105 if (offsMCVT && !getMCVT()->prepareLoadedData())
106 return false;
107 // Check liquid data
108 if (offsMCLQ && !getMCLQ()->prepareLoadedData())
109 return false;
111 return true;
114 bool adt_MCVT::prepareLoadedData()
116 if (fcc != 'MCVT')
117 return false;
119 if (size != sizeof(adt_MCVT)-8)
120 return false;
122 return true;
125 bool adt_MCLQ::prepareLoadedData()
127 if (fcc != 'MCLQ')
128 return false;
130 return true;