unbanished_formats/game/construction/build.rs
1//! Build, destroy and clear-area descriptions: the work of putting up and taking down.
2
3use super::*;
4
5/// `BuildDescription`: what constructing a building costs.
6///
7/// Original: `FUN_14010e610`.
8#[derive(Debug, Clone)]
9pub struct BuildDescription {
10 // +0x20
11 /// `(count, raw material)` requirements.
12 pub materials: Vec<(i32, Option<String>)>,
13 // +0x30
14 /// Construction work.
15 pub work: i32,
16 // +0x34
17 /// Shows `labelBuildMulti` in the CreateBar (costs per area).
18 pub multi: bool,
19}
20
21/// Read a [`BuildDescription`] from the bytes of its resource.
22pub fn build_description(data: &[u8]) -> Result<BuildDescription> {
23 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
24 if h.type_id != type_id("BuildDescription") {
25 return format_err(format!(
26 "expected BuildDescription, found {:#010x}",
27 h.type_id
28 ));
29 }
30 r.block(|r, _| {
31 let materials = (0..r.count()?)
32 .map(|_| Ok((r.i32()?, r.external_ref()?)))
33 .collect::<Result<_>>()?;
34 Ok(BuildDescription {
35 materials,
36 work: r.i32()?,
37 multi: r.bool()?,
38 })
39 })
40 })?;
41 Ok(value)
42}
43
44// +0x20; +0x28; +0x2c; +0x30
45/// `DestroyDescription`: the template left in the building's place once it is torn down (the
46/// quarry's and mine's hole; none for most), the ModelComponent's material set while damaged, the
47/// decal while damaged, the lowest construction mesh a collapse steps down to.
48///
49/// Original: `FUN_140123340`, `FUN_14012a4f0`, `FUN_140122aa0`.
50#[derive(Debug, Clone, Default, PartialEq, Eq)]
51pub struct DestroyDescription {
52 /// The template left in the building's place once it is torn down (the quarry's and mine's hole; none for most).
53 pub replace: Option<String>,
54 /// The ModelComponent's material set while damaged.
55 pub material: i32,
56 /// The decal while damaged.
57 pub decal: i32,
58 /// The lowest construction mesh a collapse steps down to.
59 pub min_mesh: i32,
60}
61
62/// Read a [`DestroyDescription`] from the bytes of its resource.
63pub fn destroy_description(data: &[u8]) -> Result<DestroyDescription> {
64 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
65 if h.type_id != type_id("DestroyDescription") {
66 return format_err(format!(
67 "expected DestroyDescription, found {:#010x}",
68 h.type_id
69 ));
70 }
71 r.block(|r, _| {
72 Ok(DestroyDescription {
73 replace: r.external_ref()?,
74 material: r.i32()?,
75 decal: r.i32()?,
76 min_mesh: r.i32()?,
77 })
78 })
79 })?;
80 Ok(value)
81}
82
83/// `ClearAreaDescription` (`Template\X.rsc:cleararea`).
84///
85/// Original: `FUN_14011d5c0`.
86#[derive(Debug, Clone, Default)]
87pub struct ClearAreaDescription {
88 // +0x20
89 /// An external reference handed to the ClearArea work.
90 ///
91 /// Original: `FUN_1400ebe30`.
92 pub reference: Option<String>,
93 // +0x28..+0x2a
94 /// The ClearArea work clears natural resources.
95 pub clear_resources: bool,
96 /// The ClearArea work clears empty cells.
97 pub clear_cells: bool,
98 /// The ClearArea work clears piles.
99 pub clear_piles: bool,
100 // +0x2b
101 /// Register the work keeping its priority.
102 pub keep_priority: bool,
103 // +0x2c
104 /// Stamp the footprint once cleared.
105 ///
106 /// Original: `FUN_14011d740`.
107 pub stamp: bool,
108 // +0x2d
109 /// Remove everything in the footprint at once.
110 ///
111 /// Original: `FUN_14011d230`.
112 pub instant: bool,
113 /// Not identified yet.
114 pub value_30: i32,
115}
116
117/// Read a [`ClearAreaDescription`] from the bytes of its resource.
118pub fn clear_area_description(data: &[u8]) -> Result<ClearAreaDescription> {
119 let (_, value) = crs::parse(data, |r: &mut Reader, h| {
120 if h.type_id != type_id("ClearAreaDescription") {
121 return format_err(format!(
122 "expected ClearAreaDescription, found {:#010x}",
123 h.type_id
124 ));
125 }
126 r.block(|r, _| {
127 Ok(ClearAreaDescription {
128 reference: r.external_ref()?,
129 clear_resources: r.bool()?,
130 clear_cells: r.bool()?,
131 clear_piles: r.bool()?,
132 keep_priority: r.bool()?,
133 stamp: r.bool()?,
134 instant: r.bool()?,
135 value_30: r.i32()?,
136 })
137 })
138 })?;
139 Ok(value)
140}