1use std::collections::HashMap;
20
21use serde::{Deserialize, Serialize};
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct OpenStrandedMap {
30 pub meta: MapMeta,
32 pub terrain: TerrainData,
34 #[serde(default)]
36 pub entities: Vec<MapEntity>,
37 #[serde(default)]
39 pub player_spawn: Option<PlayerSpawn>,
40 #[serde(default)]
42 pub environment: HashMap<String, String>,
43 #[serde(default)]
45 pub colormap: Option<ColormapData>,
46 #[serde(default)]
48 pub grass: Option<GrassData>,
49 #[serde(default)]
51 pub password: String,
52 #[serde(default)]
54 pub scripts: Vec<ScriptData>,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct MapMeta {
60 pub name: String,
62 pub engine_version: String,
64 pub map_version: String,
66 #[serde(default)]
68 pub source_file: String,
69 #[serde(default)]
71 pub s2_header: Option<S2Header>,
72 #[serde(default)]
74 pub created_at: String,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct S2Header {
80 pub version: String,
81 pub date: String,
82 pub time: String,
83 pub author: String,
84 pub map_type: String,
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct TerrainData {
90 pub size: u32,
92 pub heights: Vec<f32>,
95 #[serde(default = "default_seaground")]
97 pub seaground_level: f32,
98}
99
100fn default_seaground() -> f32 {
101 -2.0
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
106pub struct ColormapData {
107 pub dim: u32,
109 pub pixels: Vec<u8>,
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct GrassData {
116 pub dim: u32,
118 pub values: Vec<u8>,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
125pub struct MapEntity {
126 pub class: String,
128 pub type_id: u32,
130 pub id: u32,
132 pub position: (f32, f32, f32),
134 #[serde(default)]
136 pub rotation_yaw: f32,
137 #[serde(default)]
139 pub health: f32,
140 #[serde(default)]
142 pub health_max: f32,
143 #[serde(default)]
145 pub states: Vec<String>,
146 #[serde(default)]
148 pub script: Option<String>,
149 #[serde(default)]
151 pub amount: u32,
152 #[serde(default)]
154 pub parent_id: u32,
155 #[serde(default)]
157 pub parent_class: u8,
158 #[serde(default)]
160 pub links: Vec<u32>,
161 #[serde(default)]
163 pub build_progress: u32,
164 #[serde(default)]
166 pub unit_data: Option<UnitData>,
167 #[serde(default)]
169 pub extensions: HashMap<String, String>,
170}
171
172#[derive(Debug, Clone, Serialize, Deserialize)]
174pub struct UnitData {
175 #[serde(default)]
176 pub hunger: f32,
177 #[serde(default)]
178 pub thirst: f32,
179 #[serde(default)]
180 pub exhaustion: f32,
181 #[serde(default)]
182 pub ai_center_x: f32,
183 #[serde(default)]
184 pub ai_center_z: f32,
185 #[serde(default)]
186 pub day_timer: f32,
187}
188
189#[derive(Debug, Clone, Serialize, Deserialize)]
191pub struct PlayerSpawn {
192 pub position: (f32, f32, f32),
193 pub rotation_yaw: f32,
194}
195
196#[derive(Debug, Clone, Serialize, Deserialize)]
198pub struct ScriptData {
199 pub text: String,
200 pub entity_id: u32,
201}
202
203#[derive(Debug, Clone)]
209pub struct S2Map {
210 pub header: S2Header,
211 pub minimap: Vec<u8>,
212 pub password: S2Password,
213 pub env_vars: S2EnvVars,
214 pub quickslots: Vec<String>,
215 pub colormap_dim: u32,
216 pub colormap: Vec<u8>,
217 pub terrain_size: u32,
218 pub heights: Vec<f32>,
219 pub grass: Vec<u8>,
220 pub objects: Vec<S2Object>,
221 pub units: Vec<S2Unit>,
222 pub items: Vec<S2Item>,
223 pub infos: Vec<S2Info>,
224 pub states: Vec<S2State>,
225 pub extensions: Vec<S2Extension>,
226 pub trailer: S2Trailer,
227}
228
229#[derive(Debug, Clone)]
232pub struct S2Password {
233 pub key: u8,
235 pub encoded: String,
237 pub decoded: String,
239}
240
241#[derive(Debug, Clone)]
242pub struct S2EnvVars {
243 pub day: u32,
244 pub hour: u8,
245 pub minute: u8,
246 pub freezetime: u8,
247 pub skybox: String,
248 pub multiplayer: u8,
249 pub climate: u8,
250 pub music: String,
251 pub briefing: String,
252 pub fog: [u8; 4],
253 pub extra: u8,
254}
255
256#[derive(Debug, Clone)]
258pub struct S2Object {
259 pub id: u32,
260 pub typ: u32,
261 pub x: f32,
262 pub z: f32,
263 pub yaw: f32,
264 pub health: f32,
265 pub health_max: f32,
266 pub day_timer: u32,
267}
268
269#[derive(Debug, Clone)]
273pub struct S2Unit {
274 pub id: u32,
275 pub typ: u32,
276 pub x: f32,
277 pub y: f32,
278 pub z: f32,
279 pub yaw: f32,
280 pub health: f32,
281 pub health_max: f32,
282 pub hunger: f32,
283 pub thirst: f32,
284 pub exhaustion: f32,
285 pub ai_center_x: f32,
286 pub ai_center_z: f32,
287}
288
289#[derive(Debug, Clone)]
291pub struct S2Item {
292 pub id: u32,
293 pub typ: u32,
294 pub x: f32,
295 pub y: f32,
296 pub z: f32,
297 pub yaw: f32,
298 pub health: f32,
299 pub count: u32,
300 pub parent_class: u8,
301 pub parent_mode: u8,
302 pub parent_id: u32,
303}
304
305#[derive(Debug, Clone)]
307pub struct S2Info {
308 pub id: u32,
309 pub typ: u8,
310 pub x: f32,
311 pub y: f32,
312 pub z: f32,
313 pub pitch: f32,
314 pub yaw: f32,
315 pub vars: String,
316}
317
318#[derive(Debug, Clone)]
320pub struct S2State {
321 pub typ: u32,
322 pub parent_class: u32,
323 pub parent_id: u32,
324 pub x: f32,
325 pub y: f32,
326 pub z: f32,
327 pub fx: f32,
328 pub fy: f32,
329 pub fz: f32,
330 pub value: u32,
331 pub value_f: f32,
332 pub value_s: String,
333}
334
335#[derive(Debug, Clone)]
337pub struct S2Extension {
338 pub typ: u8,
339 pub parent_class: u8,
340 pub parent_id: u32,
341 pub mode: u32,
342 pub key: String,
343 pub value: String,
344 pub stuff: String,
345}
346
347#[derive(Debug, Clone)]
349pub struct S2Trailer {
350 pub blank: String,
351 pub eof_marker: String,
352 pub url: String,
353}