1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//! MH2O - Multi-layer water system (WotLK+).
//!
//! MH2O replaced the legacy MCLQ chunk starting in Wrath of the Lich King (3.x).
//! It provides a more flexible system supporting:
//!
//! - Multiple liquid layers per chunk
//! - Partial tile coverage (8×8 grid)
//! - Four vertex data formats (LVF) for different use cases
//! - Fishable and deep water attributes
//!
//! ## Structure Hierarchy
//!
//! ```text
//! MH2O Chunk
//! ├─ 256 Headers (16×16 grid)
//! │ ├─ offset_instances → Instance array
//! │ ├─ layer_count (usually 0-1, occasionally 2+)
//! │ └─ offset_attributes → Mh2oAttributes (optional)
//! │
//! ├─ Instances (per layer)
//! │ ├─ liquid_type (LiquidTypeRec FK)
//! │ ├─ Position/dimensions in 8×8 tile grid
//! │ ├─ offset_exists_bitmap → Tile presence bitmap
//! │ └─ offset_vertex_data → Vertex data (format depends on LVF)
//! │
//! └─ Attributes (optional, 8×8 bitmaps)
//! ├─ fishable - Fishing allowed
//! └─ deep - Fatigue/deep water
//! ```
//!
//! ## Offset System
//!
//! **CRITICAL**: All offsets are relative to the start of MH2O chunk **data**
//! (after the 8-byte chunk header), NOT to the chunk header itself.
//! This differs from MCNK which uses offsets relative to chunk start.
//!
//! ## Liquid Vertex Formats (LVF)
//!
//! The instance's `liquid_object_or_lvf` field determines the vertex data format:
//!
//! - **LVF 0**: Height + Depth (5 bytes/vertex) - Basic water with transparency
//! - **LVF 1**: Height + UV (8 bytes/vertex) - Textured water
//! - **LVF 2**: Depth Only (1 byte/vertex) - Rare, transparency only
//! - **LVF 3**: Height + UV + Depth (9 bytes/vertex) - Full-featured water
//!
//! For WotLK (values < 42), LVF is the lower 2 bits of `liquid_object_or_lvf`.
//! For Cataclysm+ (values ≥ 42), format must be calculated from vertex data size.
//!
//! ## Usage Example
//!
//! ```rust,no_run
//! use wow_adt::chunks::mh2o::{Mh2oChunk, Mh2oHeader, Mh2oInstance};
//! use binrw::BinRead;
//! use std::io::Cursor;
//!
//! # fn example() -> binrw::BinResult<()> {
//! // Access water data from parsed ADT
//! # let chunk_data: Mh2oChunk = todo!();
//! let chunk = &chunk_data;
//!
//! // Iterate through all 256 map chunks
//! for (idx, entry) in chunk.entries.iter().enumerate() {
//! if entry.header.has_liquid() {
//! println!("Chunk {} has {} liquid layer(s)", idx, entry.header.layer_count);
//!
//! for instance in &entry.instances {
//! println!(" Liquid dimensions: {}×{}", instance.width, instance.height);
//! println!(" Vertex count: {}", instance.vertex_count());
//! }
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! Reference: <https://wowdev.wiki/ADT/v18#MH2O_chunk>
// Re-export main types
pub use ;
pub use ;
pub use ;
/// Complete MH2O chunk with 256 entries (16×16 grid, WotLK+).
///
/// Each entry corresponds to one MCNK terrain chunk and contains:
/// - Header with offsets to instances and attributes
/// - Instance array (liquid layers)
/// - Optional attributes (fishable/deep water zones)
///
/// # Example
///
/// ```no_run
/// # use wow_adt::chunks::mh2o::Mh2oChunk;
/// # let water_data: Mh2oChunk = todo!();
/// // Iterate through all map chunks
/// for (idx, entry) in water_data.entries.iter().enumerate() {
/// if entry.header.has_liquid() {
/// let row = idx / 16;
/// let col = idx % 16;
/// println!("Chunk ({}, {}) has {} liquid layer(s)",
/// row, col, entry.header.layer_count);
/// }
/// }
/// ```
///
/// ## Version Support
///
/// - **Vanilla (1.12.1)**: ❌ Not present
/// - **TBC (2.4.3)**: ❌ Not present
/// - **WotLK (3.3.5a)**: ✅ Introduced (replaced MCLQ)
/// - **Cataclysm (4.3.4)**: ✅ Present
/// - **MoP (5.4.8)**: ✅ Present
/// Water data for a single map chunk (1/256 of ADT).
///
/// Contains header with offsets, parsed instances, optional vertex data, and attributes.
///
/// # Example
///
/// ```no_run
/// # use wow_adt::chunks::mh2o::Mh2oEntry;
/// # let entry: Mh2oEntry = todo!();
/// if entry.header.has_liquid() {
/// println!("Has {} liquid layer(s)", entry.instances.len());
///
/// // Check for vertex data
/// for (idx, vertex_data) in entry.vertex_data.iter().enumerate() {
/// if let Some(data) = vertex_data {
/// println!("Layer {} has {} vertices", idx, data.len());
/// }
/// }
///
/// if let Some(attrs) = &entry.attributes {
/// println!("Has {} fishable tiles", attrs.fishable_count());
/// println!("Has {} deep water tiles", attrs.deep_count());
/// }
/// }
/// ```