/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. #ifndef ADT_H
  19. #define ADT_H
  20. #include "loadlib.h"
  21. #define TILESIZE (533.33333f)
  22. #define CHUNKSIZE ((TILESIZE) / 16.0f)
  23. #define UNITSIZE (CHUNKSIZE / 8.0f)
  24. enum LiquidType
  25. {
  26. LIQUID_TYPE_WATER = 0,
  27. LIQUID_TYPE_OCEAN = 1,
  28. LIQUID_TYPE_MAGMA = 2,
  29. LIQUID_TYPE_SLIME = 3
  30. };
  31. //**************************************************************************************
  32. // ADT file class
  33. //**************************************************************************************
  34. #define ADT_CELLS_PER_GRID 16
  35. #define ADT_CELL_SIZE 8
  36. #define ADT_GRID_SIZE (ADT_CELLS_PER_GRID*ADT_CELL_SIZE)
  37. #pragma pack(push, 1)
  38. //
  39. // Adt file height map chunk
  40. //
  41. class adt_MCVT
  42. {
  43. union{
  44. uint32 fcc;
  45. char fcc_txt[4];
  46. };
  47. uint32 size;
  48. public:
  49. float height_map[(ADT_CELL_SIZE+1)*(ADT_CELL_SIZE+1)+ADT_CELL_SIZE*ADT_CELL_SIZE];
  50. bool prepareLoadedData();
  51. };
  52. //
  53. // Adt file liquid map chunk (old)
  54. //
  55. class adt_MCLQ
  56. {
  57. union{
  58. uint32 fcc;
  59. char fcc_txt[4];
  60. };
  61. public:
  62. uint32 size;
  63. float height1;
  64. float height2;
  65. struct liquid_data{
  66. uint32 light;
  67. float height;
  68. } liquid[ADT_CELL_SIZE+1][ADT_CELL_SIZE+1];
  69. // 1<<0 - ochen
  70. // 1<<1 - lava/slime
  71. // 1<<2 - water
  72. // 1<<6 - all water
  73. // 1<<7 - dark water
  74. // == 0x0F - not show liquid
  75. uint8 flags[ADT_CELL_SIZE][ADT_CELL_SIZE];
  76. uint8 data[84];
  77. bool prepareLoadedData();
  78. };
  79. //
  80. // Adt file cell chunk
  81. //
  82. class adt_MCNK
  83. {
  84. union{
  85. uint32 fcc;
  86. char fcc_txt[4];
  87. };
  88. public:
  89. uint32 size;
  90. uint32 flags;
  91. uint32 ix;
  92. uint32 iy;
  93. uint32 nLayers;
  94. uint32 nDoodadRefs;
  95. uint32 offsMCVT; // height map
  96. uint32 offsMCNR; // Normal vectors for each vertex
  97. uint32 offsMCLY; // Texture layer definitions
  98. uint32 offsMCRF; // A list of indices into the parent file's MDDF chunk
  99. uint32 offsMCAL; // Alpha maps for additional texture layers
  100. uint32 sizeMCAL;
  101. uint32 offsMCSH; // Shadow map for static shadows on the terrain
  102. uint32 sizeMCSH;
  103. uint32 areaid;
  104. uint32 nMapObjRefs;
  105. uint32 holes;
  106. uint16 s[2];
  107. uint32 data1;
  108. uint32 data2;
  109. uint32 data3;
  110. uint32 predTex;
  111. uint32 nEffectDoodad;
  112. uint32 offsMCSE;
  113. uint32 nSndEmitters;
  114. uint32 offsMCLQ; // Liqid level (old)
  115. uint32 sizeMCLQ; //
  116. float zpos;
  117. float xpos;
  118. float ypos;
  119. uint32 offsMCCV; // offsColorValues in WotLK
  120. uint32 props;
  121. uint32 effectId;
  122. bool prepareLoadedData();
  123. adt_MCVT *getMCVT()
  124. {
  125. if (offsMCVT)
  126. return (adt_MCVT *)((uint8 *)this + offsMCVT);
  127. return 0;
  128. }
  129. adt_MCLQ *getMCLQ()
  130. {
  131. if (offsMCLQ)
  132. return (adt_MCLQ *)((uint8 *)this + offsMCLQ);
  133. return 0;
  134. }
  135. };
  136. //
  137. // Adt file grid chunk
  138. //
  139. class adt_MCIN
  140. {
  141. union{
  142. uint32 fcc;
  143. char fcc_txt[4];
  144. };
  145. public:
  146. uint32 size;
  147. struct adt_CELLS{
  148. uint32 offsMCNK;
  149. uint32 size;
  150. uint32 flags;
  151. uint32 asyncId;
  152. } cells[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
  153. bool prepareLoadedData();
  154. // offset from begin file (used this-84)
  155. adt_MCNK *getMCNK(int x, int y)
  156. {
  157. if (cells[x][y].offsMCNK)
  158. return (adt_MCNK *)((uint8 *)this + cells[x][y].offsMCNK - 84);
  159. return 0;
  160. }
  161. };
  162. #define ADT_LIQUID_HEADER_FULL_LIGHT 0x01
  163. #define ADT_LIQUID_HEADER_NO_HIGHT 0x02
  164. struct adt_liquid_header{
  165. uint16 liquidType; // Index from LiquidType.dbc
  166. uint16 formatFlags;
  167. float heightLevel1;
  168. float heightLevel2;
  169. uint8 xOffset;
  170. uint8 yOffset;
  171. uint8 width;
  172. uint8 height;
  173. uint32 offsData2a;
  174. uint32 offsData2b;
  175. };
  176. //
  177. // Adt file liquid data chunk (new)
  178. //
  179. class adt_MH2O
  180. {
  181. public:
  182. union{
  183. uint32 fcc;
  184. char fcc_txt[4];
  185. };
  186. uint32 size;
  187. struct adt_LIQUID{
  188. uint32 offsData1;
  189. uint32 used;
  190. uint32 offsData2;
  191. } liquid[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
  192. bool prepareLoadedData();
  193. adt_liquid_header *getLiquidData(int x, int y)
  194. {
  195. if (liquid[x][y].used && liquid[x][y].offsData1)
  196. return (adt_liquid_header *)((uint8*)this + 8 + liquid[x][y].offsData1);
  197. return 0;
  198. }
  199. float *getLiquidHeightMap(adt_liquid_header *h)
  200. {
  201. if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
  202. return 0;
  203. if (h->offsData2b)
  204. return (float *)((uint8*)this + 8 + h->offsData2b);
  205. return 0;
  206. }
  207. uint8 *getLiquidLightMap(adt_liquid_header *h)
  208. {
  209. if (h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT)
  210. return 0;
  211. if (h->offsData2b)
  212. {
  213. if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
  214. return (uint8 *)((uint8*)this + 8 + h->offsData2b);
  215. return (uint8 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4);
  216. }
  217. return 0;
  218. }
  219. uint32 *getLiquidFullLightMap(adt_liquid_header *h)
  220. {
  221. if (!(h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT))
  222. return 0;
  223. if (h->offsData2b)
  224. {
  225. if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
  226. return (uint32 *)((uint8*)this + 8 + h->offsData2b);
  227. return (uint32 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4);
  228. }
  229. return 0;
  230. }
  231. uint64 getLiquidShowMap(adt_liquid_header *h)
  232. {
  233. if (h->offsData2a)
  234. return *((uint64 *)((uint8*)this + 8 + h->offsData2a));
  235. else
  236. return 0xFFFFFFFFFFFFFFFFuLL;
  237. }
  238. };
  239. //
  240. // Adt file header chunk
  241. //
  242. class ADT_file;
  243. class adt_MHDR
  244. {
  245. friend class ADT_file;
  246. union{
  247. uint32 fcc;
  248. char fcc_txt[4];
  249. };
  250. public:
  251. uint32 size;
  252. uint32 flags;
  253. uint32 offsMCIN; // MCIN
  254. uint32 offsTex; // MTEX
  255. uint32 offsModels; // MMDX
  256. uint32 offsModelsIds; // MMID
  257. uint32 offsMapObejcts; // MWMO
  258. uint32 offsMapObejctsIds; // MWID
  259. uint32 offsDoodsDef; // MDDF
  260. uint32 offsObjectsDef; // MODF
  261. uint32 offsMFBO; // MFBO
  262. uint32 offsMH2O; // MH2O
  263. uint32 data1;
  264. uint32 data2;
  265. uint32 data3;
  266. uint32 data4;
  267. uint32 data5;
  268. bool prepareLoadedData();
  269. adt_MCIN* getMCIN() { return offsMCIN ? (adt_MCIN *)((uint8 *)&flags+offsMCIN) : NULL; }
  270. adt_MH2O* getMH2O() { return offsMH2O ? (adt_MH2O *)((uint8 *)&flags+offsMH2O) : NULL; }
  271. };
  272. class ADT_file : public FileLoader{
  273. public:
  274. bool prepareLoadedData();
  275. ADT_file();
  276. ~ADT_file();
  277. void free();
  278. adt_MHDR* a_grid;
  279. adt_MCNK* cells[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
  280. };
  281. #pragma pack(pop)
  282. #endif