Corrected VS2012 Solution File
[getmangos.git] / contrib / extractor / loadlib / adt.cpp
blobe8c24c1a706785c315aab2e31bf9a1b0c96e26de
1 /*
2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
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.
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.
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
19 #define _CRT_SECURE_NO_DEPRECATE
21 #include "adt.h"
23 // Helper
24 int holetab_h[4] = {0x1111, 0x2222, 0x4444, 0x8888};
25 int holetab_v[4] = {0x000F, 0x00F0, 0x0F00, 0xF000};
27 bool isHole(int holes, int i, int j)
29 int testi = i / 2;
30 int testj = j / 4;
31 if (testi > 3) testi = 3;
32 if (testj > 3) testj = 3;
33 return (holes & holetab_h[testi] & holetab_v[testj]) != 0;
37 // Adt file loader class
39 ADT_file::ADT_file()
41 a_grid = 0;
44 ADT_file::~ADT_file()
46 free();
49 void ADT_file::free()
51 a_grid = 0;
52 FileLoader::free();
56 // Adt file check function
58 bool ADT_file::prepareLoadedData()
60 // Check parent
61 if (!FileLoader::prepareLoadedData())
62 return false;
64 // Check and prepare MHDR
65 a_grid = (adt_MHDR *)(GetData() + 8 + version->size);
66 if (!a_grid->prepareLoadedData())
67 return false;
69 // funny offsets calculations because there is no mapping for them and they have variable lengths
70 uint8* ptr = (uint8*)a_grid + a_grid->size + 8;
71 uint32 mcnk_count = 0;
72 memset(cells, 0, ADT_CELLS_PER_GRID * ADT_CELLS_PER_GRID * sizeof(adt_MCNK*));
73 while (ptr < GetData() + GetDataSize())
75 uint32 header = *(uint32*)ptr;
76 uint32 size = *(uint32*)(ptr + 4);
77 if (header == 'MCNK')
79 cells[mcnk_count / ADT_CELLS_PER_GRID][mcnk_count % ADT_CELLS_PER_GRID] = (adt_MCNK*)ptr;
80 ++mcnk_count;
83 // move to next chunk
84 ptr += size + 8;
87 if (mcnk_count != ADT_CELLS_PER_GRID * ADT_CELLS_PER_GRID)
88 return false;
90 return true;
93 bool adt_MHDR::prepareLoadedData()
95 if (fcc != 'MHDR')
96 return false;
98 if (size != sizeof(adt_MHDR) - 8)
99 return false;
101 // Check and prepare MCIN
102 if (offsMCIN && !getMCIN()->prepareLoadedData())
103 return false;
105 // Check and prepare MH2O
106 if (offsMH2O && !getMH2O()->prepareLoadedData())
107 return false;
109 return true;
112 bool adt_MCIN::prepareLoadedData()
114 if (fcc != 'MCIN')
115 return false;
117 // Check cells data
118 for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
119 for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
120 if (cells[i][j].offsMCNK && !getMCNK(i, j)->prepareLoadedData())
121 return false;
123 return true;
126 bool adt_MH2O::prepareLoadedData()
128 if (fcc != 'MH2O')
129 return false;
131 // Check liquid data
132 // for (int i=0; i<ADT_CELLS_PER_GRID;i++)
133 // for (int j=0; j<ADT_CELLS_PER_GRID;j++)
135 return true;
138 bool adt_MCNK::prepareLoadedData()
140 if (fcc != 'MCNK')
141 return false;
143 // Check height map
144 if (offsMCVT && !getMCVT()->prepareLoadedData())
145 return false;
146 // Check liquid data
147 if (offsMCLQ && !getMCLQ()->prepareLoadedData())
148 return false;
150 return true;
153 bool adt_MCVT::prepareLoadedData()
155 if (fcc != 'MCVT')
156 return false;
158 if (size != sizeof(adt_MCVT) - 8)
159 return false;
161 return true;
164 bool adt_MCLQ::prepareLoadedData()
166 if (fcc != 'MCLQ')
167 return false;
169 return true;