unbanished_formats/save/map.rs
1//! The map blocks of a save: the heights and the cells.
2
3/// The map component's terrain grid.
4///
5/// Original: `FUN_1400b59a0`.
6#[derive(Debug, Clone)]
7pub struct MapHeights {
8 /// Samples per side (`2n + 1`).
9 pub width: usize,
10 /// The heights, row by row: height × 256.
11 pub heights: Vec<i16>,
12}
13
14/// One cell of the gameplay map, as a save stores it (the cell is 48 bytes in memory).
15///
16/// Original: `FUN_14001b570`.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub struct MapCell {
19 // +0x00; +0x08
20 /// Whether the two object pointers are set.
21 pub objects: [bool; 2],
22 // +0x10
23 /// External reference id at (`u32::MAX` when unset).
24 pub external: u32,
25 // +0x1c..+0x25
26 /// Bytes.
27 pub flags: [u8; 9],
28 // +0x26
29 /// Not identified yet.
30 pub value: u16,
31 // +0x29; +0x28..+0x2d
32 /// Bytes; `[1]` is the cell type.
33 pub bytes: [u8; 6],
34}
35
36/// The gameplay map (serializer version 4): `size × size` cells covering the centre of the terrain
37/// (the terrain grid is twice as wide).
38///
39/// Original: `FUN_1400a45d0`.
40#[derive(Debug, Clone)]
41pub struct MapCells {
42 /// The number of cells on each side.
43 pub size: usize,
44 /// The cells, row by row.
45 pub cells: Vec<MapCell>,
46 // +0x90
47 /// The nine values that end the map block.
48 pub trailer: [i16; 9],
49}
50
51impl MapCell {
52 /// The cell's type (see `unbanished_terrain::CellType`).
53 pub fn cell_type(&self) -> u8 {
54 self.bytes[1]
55 }
56}