Alchemy
Loading...
Searching...
No Matches

field_runtime.h

Go to the documentation of this file.
1#ifndef ALCHEMY_FIELD_RUNTIME_H
2#define ALCHEMY_FIELD_RUNTIME_H
3
4/// @file
5/// The field's runtime work: map cells, scene records and regions, map markers
6/// and FieldWork.
7
8#include "types.h"
9#include "static_assert.h"
10#include "object_runtime.h"
11#include "field_scene.h"
12
13struct MapCell;
14struct FieldActor;
15
16/// A scene's row in gField_SceneTable: its overlay's resource, its group
17/// (the place it belongs to), a variant and its map.
18struct SceneRecord {
21 s8 variant; ///< copied to gGameState.sceneVariant; 2 sets flag 0x123
23 u16 reserved; ///< 0 in every row; not read
24};
25
26STATIC_ASSERT(sizeof(struct SceneRecord) == 8);
27
28/// A scene's exit region: the box that, while its condition holds, takes the
29/// party leader out through its exit.
31 s16 minX, minY, minZ; ///< pixels, inclusive; minX -1 ends the table
32 s16 maxX, maxY, maxZ; ///< pixels, exclusive
33 s16 condition; ///< -1 always, a flag | 0x1000 set, else the flag clear
34 s16 value; ///< the exit kind, stored in FieldWork's exit
35};
36
37STATIC_ASSERT(sizeof(struct SceneRegion) == 16);
38
39/// The entry table at the start of each scene overlay: its initialize
40/// function and the functions returning its entrances, exits, placements,
41/// events and regions, each behind a veneer word.
44 s32 (*initialize)(void);
46 const struct SceneEntrance *(*entrances)(void);
48 const u32 *(*exits)(void);
50 const struct ScenePlacement *(*placements)(void);
52 const struct SceneEvent *(*events)(void);
54 const struct SceneRegion *(*regions)(void);
55};
56
57STATIC_ASSERT(sizeof(struct SceneEntries) == 48);
58STATIC_ASSERT(offsetof(struct SceneEntries, exits) == 0x14);
59STATIC_ASSERT(offsetof(struct SceneEntries, regions) == 0x2c);
60
61/// A map marker placed as an actor: a chest or a Psynergy stone.
62struct MarkerSlot {
64 u8 id; ///< the trigger of its scene event
65 u8 unk05; ///< cleared with the slot; not named by TBS code
66 u8 column; ///< its 16-pixel cell
68};
69
70STATIC_ASSERT(sizeof(struct MarkerSlot) == 8);
72STATIC_ASSERT(offsetof(struct MarkerSlot, column) == 6);
74
75/// Full event work allocated by Field_RunScene (heap slot 27). The twelve
76/// requests from action to event are handled by the field loop.
77struct FieldWork {
78 /// The placement tables placed so far, recorded by Event_SpawnObjectTable.
80 const struct SceneEvent *events; ///< the scene's event table
81 /// The actors by id: 0 to 7 the party's characters, 8 on the placed actors.
82 struct FieldActor *actors[66];
83 struct MarkerSlot markers[10]; ///< the map's markers (MARKER_MAX)
84 /// The twelve requests: each nonzero value asks the field loop for one
85 /// thing; Field_ClearRequests clears them and Field_CountRequests sums them.
86 ///@{
87 s16 action; ///< a step event (1 to 239) for Scene_RunTouchOrExit
88 s16 input; ///< a tile code (252 to 254) for Field_RunPushTileEvent
89 s16 exit; ///< the exit taken, which ends the scene
90 s16 menu; ///< open the main menu
91 s16 examine; ///< the A button: examine what is ahead
92 s16 start; ///< the Start button: open the pause menu
93 u16 descriptor; ///< an actor's event, as actor | 0x1000
94 s16 tile; ///< a tile's collision code, for Field_SearchTile
95 s16 battle; ///< the enemy group of a random encounter
96 s16 command; ///< a field Psynergy to use, as owner << 10 | Psynergy
97 s16 item; ///< an item to use, packed as Field_UseItem reads it
98 /// A raised event for Scene_RunRaisedEvent, or -1 when characters fell to
99 /// poison or hazard damage, -888 the world map, -889 a visibility change.
101 ///@}
102 s16 fallenCount; ///< the characters who fell this step
103 s16 survivorCount; ///< 0 when the whole party fell
104 s16 fallenOwners[9]; ///< the characters who fell, from the active party
105 s16 itemArgument; ///< the inventory slot Field_UseItem receives
106 /// Frames the leader has pushed against something, counted by the player
107 /// controls; touch events and push tiles need more than 12.
109 s16 mode; ///< MODE_WORLD_MAP (3) on the world map
110 u8 encounterGroups[8]; ///< encounter zone for each kind of ground
111 s32 encounterBias; ///< randomized distance adjustment between battles
112 s32 encounterThreshold; ///< encounter steps before a battle; 0x100000
113 s32 walkingDistanceScale; ///< scales movement for PP and status updates
114 s32 walkingDistance; ///< accumulated 16.16 distance awaiting an update
115 struct MapCell *currentTile; ///< the cell the leader last stepped onto
116 struct MapCell *previousTile; ///< the cell before it
117 s32 transition; ///< SCENE_TRANSITION(style, variant); 0x100 on entry
118 u16 unk1c4; ///< not named by TBS code
119 u16 transitionActive; ///< set once the opening transition has started
120 s32 transitionFrames; ///< frames; 16 on entry and at each event
121 s32 fastForward; ///< debug: skip timed event waits and actor messages
122 u8 unk1d0[8]; ///< not named by TBS code
123 s16 message; ///< the next message, advanced as each window opens
124 u16 unk1da; ///< set to 0xffff by FieldEvent_Begin; not read by name
125 s16 unk1dc; ///< set to -1 by FieldEvent_Begin; not read by name
126 s16 unk1de; ///< set to -1 by FieldEvent_Begin; not read by name
127 struct ObjectRuntime *camera; ///< the object the map view follows
128 u8 unk1e4[0x10]; ///< not named by TBS code
129 s32 speaker; ///< the actor speaking; the leader at each event
130 s32 messageWindow; ///< the open message window, 0 for none
131 s32 sideWindow; ///< the speaker's portrait window
132 /// ObjectTable_ResetForObject builds the leader's two-row placement table
133 /// at its start; nothing else names it.
134 u8 unk200[0xab6];
135 /// Set while a raised or touch event runs; FieldEvent_Begin then resets the
136 /// effect counter.
138 s16 revealActive; ///< nonzero while Reveal is active
139 s16 revealFrames; ///< the frames Reveal has left
140 s16 revealCenterX; ///< where Reveal was cast, in pixels
142 /// Nonzero lets the Reveal countdown advance; menus and other effects pause
143 /// it.
145 s16 nameMessage; ///< first message of the menu's name window (0: none)
146 s16 nameWidth; ///< width of the name window (0: the default)
147 s8 resolvingAction; ///< set while Psynergy takes effect
148 s8 castStarted; ///< set once a cast has been announced
149 s16 queuedSound; ///< a sound BattleFx_PlayQueuedSound plays; -1 for none
150};
151
152STATIC_ASSERT(sizeof(struct FieldWork) == 0xccc);
153STATIC_ASSERT(offsetof(struct FieldWork, tables) == 0);
154STATIC_ASSERT(offsetof(struct FieldWork, events) == 0x10);
155STATIC_ASSERT(offsetof(struct FieldWork, actors) == 0x14);
156STATIC_ASSERT(offsetof(struct FieldWork, markers) == 0x11c);
158STATIC_ASSERT(offsetof(struct FieldWork, descriptor) == 0x178);
159STATIC_ASSERT(offsetof(struct FieldWork, battle) == 0x17c);
160STATIC_ASSERT(offsetof(struct FieldWork, event) == 0x182);
161STATIC_ASSERT(offsetof(struct FieldWork, blockedSteps) == 0x19c);
162STATIC_ASSERT(offsetof(struct FieldWork, mode) == 0x19e);
163STATIC_ASSERT(offsetof(struct FieldWork, encounterGroups) == 0x1a0);
164STATIC_ASSERT(offsetof(struct FieldWork, encounterBias) == 0x1a8);
165STATIC_ASSERT(offsetof(struct FieldWork, encounterThreshold) == 0x1ac);
166STATIC_ASSERT(offsetof(struct FieldWork, walkingDistanceScale) == 0x1b0);
167STATIC_ASSERT(offsetof(struct FieldWork, walkingDistance) == 0x1b4);
168STATIC_ASSERT(offsetof(struct FieldWork, currentTile) == 0x1b8);
169STATIC_ASSERT(offsetof(struct FieldWork, previousTile) == 0x1bc);
170STATIC_ASSERT(offsetof(struct FieldWork, transition) == 0x1c0);
171STATIC_ASSERT(offsetof(struct FieldWork, transitionActive) == 0x1c6);
172STATIC_ASSERT(offsetof(struct FieldWork, transitionFrames) == 0x1c8);
173STATIC_ASSERT(offsetof(struct FieldWork, fastForward) == 0x1cc);
174STATIC_ASSERT(offsetof(struct FieldWork, message) == 0x1d8);
175STATIC_ASSERT(offsetof(struct FieldWork, camera) == 0x1e0);
176STATIC_ASSERT(offsetof(struct FieldWork, unk1da) == 0x1da);
177STATIC_ASSERT(offsetof(struct FieldWork, unk1dc) == 0x1dc);
178STATIC_ASSERT(offsetof(struct FieldWork, unk1de) == 0x1de);
179STATIC_ASSERT(offsetof(struct FieldWork, speaker) == 0x1f4);
180STATIC_ASSERT(offsetof(struct FieldWork, messageWindow) == 0x1f8);
181STATIC_ASSERT(offsetof(struct FieldWork, sideWindow) == 0x1fc);
182STATIC_ASSERT(offsetof(struct FieldWork, busy) == 0xcb6);
183STATIC_ASSERT(offsetof(struct FieldWork, revealActive) == 0xcb8);
184STATIC_ASSERT(offsetof(struct FieldWork, revealFrames) == 0xcba);
185STATIC_ASSERT(offsetof(struct FieldWork, revealCenterX) == 0xcbc);
186STATIC_ASSERT(offsetof(struct FieldWork, revealCenterY) == 0xcbe);
187STATIC_ASSERT(offsetof(struct FieldWork, effectTimerRunning) == 0xcc0);
188STATIC_ASSERT(offsetof(struct FieldWork, nameMessage) == 0xcc2);
189STATIC_ASSERT(offsetof(struct FieldWork, nameWidth) == 0xcc4);
190STATIC_ASSERT(offsetof(struct FieldWork, resolvingAction) == 0xcc6);
191STATIC_ASSERT(offsetof(struct FieldWork, castStarted) == 0xcc7);
192STATIC_ASSERT(offsetof(struct FieldWork, queuedSound) == 0xcc8);
193
194/// A position on the field.
196 s32 x, y, z; ///< 16.16 fixed-point pixels
197};
198
199STATIC_ASSERT(sizeof(struct FieldPosition) == 12);
200
201extern const struct SceneRecord gField_SceneTable[];
202extern struct SceneEntries gOverlayArea;
203
204#endif
const struct SceneRecord gField_SceneTable[]
struct SceneEntries gOverlayArea
The scene table formats: entrances, exits, placements and events, and the macros that write them.
ObjectRuntime, a field object's runtime state, and the object snapshots.
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
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
A position on the field.
s32 z
16.16 fixed-point pixels
Full event work allocated by Field_RunScene (heap slot 27).
s16 exit
the exit taken, which ends the scene
u16 transitionActive
set once the opening transition has started
s16 unk1de
set to -1 by FieldEvent_Begin; not read by name
s8 resolvingAction
set while Psynergy takes effect
u16 descriptor
an actor's event, as actor | 0x1000
s16 input
a tile code (252 to 254) for Field_RunPushTileEvent
s16 event
A raised event for Scene_RunRaisedEvent, or -1 when characters fell to poison or hazard damage,...
s16 command
a field Psynergy to use, as owner << 10 | Psynergy
const struct SceneEvent * events
the scene's event table
s16 revealActive
nonzero while Reveal is active
s16 effectTimerRunning
Nonzero lets the Reveal countdown advance; menus and other effects pause it.
s16 unk1dc
set to -1 by FieldEvent_Begin; not read by name
s16 queuedSound
a sound BattleFx_PlayQueuedSound plays; -1 for none
s32 transition
SCENE_TRANSITION(style, variant); 0x100 on entry.
s16 itemArgument
the inventory slot Field_UseItem receives
u16 busy
Set while a raised or touch event runs; FieldEvent_Begin then resets the effect counter.
struct MarkerSlot markers[10]
the map's markers (MARKER_MAX)
s16 tile
a tile's collision code, for Field_SearchTile
struct MapCell * previousTile
the cell before it
s8 castStarted
set once a cast has been announced
u8 unk200[0xab6]
ObjectTable_ResetForObject builds the leader's two-row placement table at its start; nothing else nam...
u8 encounterGroups[8]
encounter zone for each kind of ground
s16 start
the Start button: open the pause menu
s16 fallenOwners[9]
the characters who fell, from the active party
s32 encounterBias
randomized distance adjustment between battles
u8 unk1d0[8]
not named by TBS code
s32 fastForward
debug: skip timed event waits and actor messages
u16 unk1da
set to 0xffff by FieldEvent_Begin; not read by name
s16 nameMessage
first message of the menu's name window (0: none)
s16 battle
the enemy group of a random encounter
s32 speaker
the actor speaking; the leader at each event
s16 survivorCount
0 when the whole party fell
s32 walkingDistanceScale
scales movement for PP and status updates
struct ScenePlacement * tables[4]
The placement tables placed so far, recorded by Event_SpawnObjectTable.
s16 message
the next message, advanced as each window opens
struct ObjectRuntime * camera
the object the map view follows
s16 nameWidth
width of the name window (0: the default)
s32 sideWindow
the speaker's portrait window
s16 menu
open the main menu
s16 mode
MODE_WORLD_MAP (3) on the world map.
s16 revealCenterX
where Reveal was cast, in pixels
u16 unk1c4
not named by TBS code
s16 examine
the A button: examine what is ahead
struct MapCell * currentTile
the cell the leader last stepped onto
s32 messageWindow
the open message window, 0 for none
s16 item
an item to use, packed as Field_UseItem reads it
s16 action
The twelve requests: each nonzero value asks the field loop for one thing; Field_ClearRequests clears...
struct FieldActor * actors[66]
The actors by id: 0 to 7 the party's characters, 8 on the placed actors.
s16 fallenCount
the characters who fell this step
s32 encounterThreshold
encounter steps before a battle; 0x100000
s16 revealFrames
the frames Reveal has left
u8 unk1e4[0x10]
not named by TBS code
s16 blockedSteps
Frames the leader has pushed against something, counted by the player controls; touch events and push...
s32 transitionFrames
frames; 16 on entry and at each event
s32 walkingDistance
accumulated 16.16 distance awaiting an update
One cell of a map layer: its metatile and flags, its collision code and an attribute indexing the col...
Definition map.h:13
A map marker placed as an actor: a chest or a Psynergy stone.
u8 unk05
cleared with the slot; not named by TBS code
u8 id
the trigger of its scene event
struct ObjectRuntime * object
u8 column
its 16-pixel cell
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
s16 action
The parameter its action script reads (a follow distance or an angle), or the player's frames to its ...
A scene entrance: where and facing which way the party arrives, and the camera's bounds there (-1 for...
Definition field_scene.h:54
The entry table at the start of each scene overlay: its initialize function and the functions returni...
s32(*) initialize(void)
A scene event: its kind and detail, the trigger it answers, its condition and its value (a message or...
An actor a scene places: its sprite, the condition for placing it, how it behaves,...
Definition field_scene.h:81
An actor's animation object, seen for the flags and rotation that lay a wounded soldier in his bed.
s8 variant
copied to gGameState.sceneVariant; 2 sets flag 0x123
u16 reserved
0 in every row; not read
A scene's exit region: the box that, while its condition holds, takes the party leader out through it...
s16 value
the exit kind, stored in FieldWork's exit
s16 minZ
pixels, inclusive; minX -1 ends the table
s16 condition
-1 always, a flag | 0x1000 set, else the flag clear
s16 maxZ
pixels, exclusive
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed char s8
Definition types.h:10
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11