Alchemy
Loading...
Searching...
No Matches

map.h

Go to the documentation of this file.
1#ifndef ALCHEMY_MAP_H
2#define ALCHEMY_MAP_H
3
4/// @file
5/// Maps: their cells, layers, animations and blend scripts, and the map state.
6
7#include "unit/field/field.h"
8#include "types.h"
9#include "static_assert.h"
10
11/// One cell of a map layer: its metatile and flags, its collision code and an
12/// attribute indexing the collision table.
13struct MapCell {
14 /// bits: 15..12 flags (15..14 read by Map_GetCellHighFlags) | 11..0 metatile
16 /// The step code: 1 to 239 scene events, 240 and 241 encounter ground, 250
17 /// hazard, 252 to 254 for Field_RunPushTileEvent, 0xff a wall.
19 /// Indexes the 4-byte collision entries (gMapCollision): terrain kind in the
20 /// first byte's low four bits, then its height samples.
22};
23
24/// A map layer's scroll record, seen from its cells.
25struct MapLayer {
26 struct MapCell *cells; ///< the layer's first cell (MapLayerScroll's cells)
27 u8 unk04[0x2c]; ///< the next layer's scroll values; not named by TBS code
28};
29
30/// The map's running blend script, which sets the blend registers over time.
34 u16 delay; ///< frames
36};
37
38/// One of the 16 tile animation channels, which copy tiles into VRAM by
39/// script.
41 const u16 *start;
42 const u16 *cursor;
43 u16 timer; ///< frames
45};
46
47/// The map work in heap slot 8 (struct MapScrollWork), seen as its tile
48/// animation channels, blend script and layers' cells.
49struct MapState {
50 u8 unk000[0x14]; ///< MapScrollWork's origin, shake and script
51 u16 flags; ///< REG_DISPCNT bits; Map_SetShownLayers sets BG1 to BG3
52 u8 wideTiles; ///< nonzero: tile animations copy 64-byte tiles
53 u8 unk17; ///< MapScrollWork's footprints; Bilibin Cave sets it
54 struct MapAnimation anim[16];
56 u8 unke4[0x1f]; ///< MapScrollWork's view, bounds and shown layers
57 /// The last BLDCNT the blend script wrote; with mode 1 in bits 7..6 its
58 /// values go to BLDALPHA, else to BLDY.
60 u8 unk104[0x2c]; ///< the first layer's scroll values; not named by TBS code
61 /// Each layer's cells, at MapScrollWork's layers[i].cells; readers mask the
62 /// layer with 3, and the fourth entry lies past MapScrollWork's end.
63 struct MapLayer layers[4];
64};
65
66STATIC_ASSERT(sizeof(struct MapAnimation) == 12);
67STATIC_ASSERT(offsetof(struct MapState, flags) == 0x14);
68STATIC_ASSERT(offsetof(struct MapState, wideTiles) == 0x16);
69STATIC_ASSERT(offsetof(struct MapState, anim) == 0x18);
70STATIC_ASSERT(offsetof(struct MapState, blend) == 0xd8);
71STATIC_ASSERT(offsetof(struct MapState, layers) == 0x130);
72
73/// A position on the world map, as its walkability check reads it.
75 s32 x; ///< 16.16 fixed-point pixels
76 s32 height; ///< 16.16 fixed-point pixels
77 s32 y; ///< 16.16 fixed-point pixels
78};
79
80extern u32 gMapBlocks[];
81
82extern u8 gMapLayerData[];
83
84extern u8 gMapCollision[];
85
86extern u8 gBgTileBuffer[];
87
89
90#endif
u32 gMapBlocks[]
u8 * gMapAnimationPages
u8 gMapLayerData[]
u8 gMapCollision[]
u8 gBgTileBuffer[]
STATIC_ASSERT, a compile-time check that emits nothing.
#define STATIC_ASSERT(condition)
C89 permits repeated extern declarations of the same array.
#define offsetof(type, member)
Definition stddef.h:19
The map's running blend script, which sets the blend registers over time.
Definition map.h:31
u16 * cursor
Definition map.h:33
u16 * script
Definition map.h:32
u16 delay
frames
Definition map.h:34
One of the 16 tile animation channels, which copy tiles into VRAM by script.
Definition map.h:40
const u16 * cursor
Definition map.h:42
u16 timer
frames
Definition map.h:43
const u16 * start
Definition map.h:41
u16 paused
Definition map.h:44
One cell of a map layer: its metatile and flags, its collision code and an attribute indexing the col...
Definition map.h:13
u8 attributeB
Indexes the 4-byte collision entries (gMapCollision): terrain kind in the first byte's low four bits,...
Definition map.h:21
u16 metatileAndFlags
bits: 15..12 flags (15..14 read by Map_GetCellHighFlags) | 11..0 metatile
Definition map.h:15
u8 collisionCode
The step code: 1 to 239 scene events, 240 and 241 encounter ground, 250 hazard, 252 to 254 for Field_...
Definition map.h:18
A map layer's scroll record, seen from its cells.
Definition map.h:25
u8 unk04[0x2c]
the next layer's scroll values; not named by TBS code
Definition map.h:27
struct MapCell * cells
the layer's first cell (MapLayerScroll's cells)
Definition map.h:26
The map work in heap slot 8 (struct MapScrollWork), seen as its tile animation channels,...
Definition map.h:49
u8 unk104[0x2c]
the first layer's scroll values; not named by TBS code
Definition map.h:60
u8 blendControl
The last BLDCNT the blend script wrote; with mode 1 in bits 7..6 its values go to BLDALPHA,...
Definition map.h:59
u8 unk17
MapScrollWork's footprints; Bilibin Cave sets it.
Definition map.h:53
u16 flags
REG_DISPCNT bits; Map_SetShownLayers sets BG1 to BG3.
Definition map.h:51
struct MapAnimation anim[16]
Definition map.h:54
struct MapLayer layers[4]
Each layer's cells, at MapScrollWork's layers[i].cells; readers mask the layer with 3,...
Definition map.h:63
u8 unke4[0x1f]
MapScrollWork's view, bounds and shown layers.
Definition map.h:56
struct BlendScriptState blend
Definition map.h:55
u8 unk000[0x14]
MapScrollWork's origin, shake and script.
Definition map.h:50
u8 wideTiles
nonzero: tile animations copy 64-byte tiles
Definition map.h:52
A position on the world map, as its walkability check reads it.
Definition map.h:74
s32 x
16.16 fixed-point pixels
Definition map.h:75
s32 y
16.16 fixed-point pixels
Definition map.h:77
s32 height
16.16 fixed-point pixels
Definition map.h:76
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11