1mod build;
4pub use build::{
5 build_description, clear_area_description, destroy_description, BuildDescription,
6 ClearAreaDescription, DestroyDescription,
7};
8
9use super::*;
10
11#[derive(Debug, Clone)]
16pub struct CreatePlacedDescription {
17 pub flags: u32,
20 pub values: Vec<u32>,
23 pub name: String,
26 pub width: i32,
29 pub height: i32,
31 pub value: i32,
34 pub related: Option<String>,
37}
38
39pub fn create_placed_description(data: &[u8]) -> Result<CreatePlacedDescription> {
41 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
42 if h.type_id != type_id("CreatePlacedDescription") {
43 return format_err(format!(
44 "expected CreatePlacedDescription, found {:#010x}",
45 h.type_id
46 ));
47 }
48 r.block(|r, _| {
49 let flags = r.u32()?;
50 let values = (0..r.count()?).map(|_| r.u32()).collect::<Result<_>>()?;
51 Ok(CreatePlacedDescription {
52 flags,
53 values,
54 name: r.string()?,
55 width: r.i32()?,
56 height: r.i32()?,
57 value: r.i32()?,
58 related: r.external_ref()?,
59 })
60 })
61 })?;
62 Ok(value)
63}
64
65#[derive(Debug, Clone, Default, PartialEq)]
72pub struct CreateFencedDescription {
73 pub mask: u32,
75 pub parts: Vec<Option<String>>,
77 pub max: (i32, i32),
79 pub min: (i32, i32),
81 pub centered: bool,
83 pub clear: Option<String>,
85}
86
87pub fn create_fenced_description(data: &[u8]) -> Result<CreateFencedDescription> {
89 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
90 if h.type_id != type_id("CreateFencedDescription") {
91 return format_err(format!(
92 "expected CreateFencedDescription, found {:#010x}",
93 h.type_id
94 ));
95 }
96 r.block(|r, _| {
97 let mask = r.u32()?;
98 let parts = (0..6).map(|_| r.external_ref()).collect::<Result<_>>()?;
99 Ok(CreateFencedDescription {
100 mask,
101 parts,
102 max: (r.i32()?, r.i32()?),
103 min: (r.i32()?, r.i32()?),
104 centered: r.bool()?,
105 clear: r.external_ref()?,
106 })
107 })
108 })?;
109 Ok(value)
110}
111
112#[derive(Debug, Clone, Default, PartialEq, Eq)]
118pub struct CreateRoadDescription {
119 pub kind: u8,
121 pub material: Option<String>,
123}
124
125pub fn create_road_description(data: &[u8]) -> Result<CreateRoadDescription> {
127 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
128 if h.type_id != type_id("CreateRoadDescription") {
129 return format_err(format!(
130 "expected CreateRoadDescription, found {:#010x}",
131 h.type_id
132 ));
133 }
134 r.block(|r, _| {
135 Ok(CreateRoadDescription {
136 kind: r.u8()?,
137 material: r.external_ref()?,
138 })
139 })
140 })?;
141 Ok(value)
142}
143
144#[derive(Debug, Clone, Default, PartialEq, Eq)]
151pub struct CreateBridgeDescription {
152 pub span: u32,
154 pub banks: u32,
156 pub shown: u32,
158 pub needs: u32,
160 pub sides: u32,
162 pub half_width: i32,
164 pub parts: Vec<Option<String>>,
166}
167
168pub fn create_bridge_description(data: &[u8]) -> Result<CreateBridgeDescription> {
170 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
171 if h.type_id != type_id("CreateBridgeDescription") {
172 return format_err(format!(
173 "expected CreateBridgeDescription, found {:#010x}",
174 h.type_id
175 ));
176 }
177 r.block(|r, _| {
178 let span = r.u32()?;
179 let shown = r.u32()?;
180 let needs = r.u32()?;
181 let banks = r.u32()?;
182 let sides = r.u32()?;
183 let half_width = r.i32()?;
184 let parts = (0..5).map(|_| r.external_ref()).collect::<Result<_>>()?;
185 Ok(CreateBridgeDescription {
186 span,
187 banks,
188 shown,
189 needs,
190 sides,
191 half_width,
192 parts,
193 })
194 })
195 })?;
196 Ok(value)
197}
198
199#[derive(Debug, Clone, Default, PartialEq, Eq)]
204pub struct FloorDescription {
205 pub mesh: Option<String>,
207 pub active: bool,
209}
210
211pub fn floor_description(data: &[u8]) -> Result<FloorDescription> {
213 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
214 if h.type_id != type_id("FloorDescription") {
215 return format_err(format!(
216 "expected FloorDescription, found {:#010x}",
217 h.type_id
218 ));
219 }
220 r.block(|r, _| {
221 Ok(FloorDescription {
222 mesh: r.external_ref()?,
223 active: r.bool()?,
224 })
225 })
226 })?;
227 Ok(value)
228}
229
230#[derive(Debug, Clone, Default, PartialEq, Eq)]
236pub struct TerraformDescription {
237 pub floor: Option<String>,
239 pub floor_mask: u32,
241 pub ceiling: Option<String>,
243 pub ceiling_mask: u32,
245}
246
247pub fn terraform_description(data: &[u8]) -> Result<TerraformDescription> {
249 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
250 if h.type_id != type_id("TerraformDescription") {
251 return format_err(format!(
252 "expected TerraformDescription, found {:#010x}",
253 h.type_id
254 ));
255 }
256 r.block(|r, _| {
257 Ok(TerraformDescription {
258 floor: r.external_ref()?,
259 floor_mask: r.u32()?,
260 ceiling: r.external_ref()?,
261 ceiling_mask: r.u32()?,
262 })
263 })
264 })?;
265 Ok(value)
266}
267
268#[derive(Debug, Clone, Default)]
273pub struct CreateRemovalDescription {
274 pub resources: bool,
277 pub filters: Vec<String>,
280 pub template: Option<String>,
283 pub roads: bool,
286 pub buildings: bool,
288 pub cancel: bool,
290 pub priority: bool,
292}
293
294pub fn create_removal_description(data: &[u8]) -> Result<CreateRemovalDescription> {
296 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
297 if h.type_id != type_id("CreateRemovalDescription") {
298 return format_err(format!(
299 "expected CreateRemovalDescription, found {:#010x}",
300 h.type_id
301 ));
302 }
303 r.block(|r, _| {
304 let resources = r.bool()?;
305 let n = r.count()?;
306 let filters = (0..n)
307 .map(|_| Ok(r.external_ref()?.unwrap_or_default()))
308 .collect::<Result<_>>()?;
309 Ok(CreateRemovalDescription {
310 resources,
311 filters,
312 template: r.external_ref()?,
313 roads: r.bool()?,
314 buildings: r.bool()?,
315 cancel: r.bool()?,
316 priority: r.bool()?,
317 })
318 })
319 })?;
320 Ok(value)
321}
322
323#[derive(Debug, Clone, Default)]
327pub struct CreateDragDescription {
328 pub mask: u32,
333 pub value_28: i32,
335 pub value_2c: i32,
337 pub value_30: i32,
339 pub value_34: i32,
341 pub override_occupant: bool,
344 pub reference: Option<String>,
347}
348
349pub fn create_drag_description(data: &[u8]) -> Result<CreateDragDescription> {
351 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
352 if h.type_id != type_id("CreateDragDescription") {
353 return format_err(format!(
354 "expected CreateDragDescription, found {:#010x}",
355 h.type_id
356 ));
357 }
358 r.block(|r, _| {
359 Ok(CreateDragDescription {
360 mask: r.u32()?,
361 value_28: r.i32()?,
362 value_2c: r.i32()?,
363 value_30: r.i32()?,
364 value_34: r.i32()?,
365 override_occupant: r.bool()?,
366 reference: r.external_ref()?,
367 })
368 })
369 })?;
370 Ok(value)
371}