Alchemy
Loading...
Searching...
No Matches

game_state.h

Go to the documentation of this file.
1#ifndef ALCHEMY_GAME_STATE_H
2#define ALCHEMY_GAME_STATE_H
3
4/// @file
5/// GameState, the game's state: play time, coins, the scene and the leader's
6/// position, the active party and the options.
7
8#include "types.h"
9#include "static_assert.h"
10#include "battle_unit.h"
11
12/// The game's state: play time, coins, the scene and the leader's position,
13/// the active party and the options.
14struct GameState {
15 /// Runtime_GetBuildStampTime's value when the game was last saved; its low
16 /// half goes into the file's summary.
18 u32 playTime; ///< frames, copied from gPlayTimeFrames when saving
19 /// Not named by TBS code. The party's struct DjinnRecoveryTable
20 /// (Djinn_GetRecoveryTable) starts at byte 4, its first 8 bytes running
21 /// over coins.
24 /// The party's Djinn recovery list (struct DjinnRecoveryList), read through
25 /// Djinn_GetRecoveryTable; not named by TBS code.
26 u8 unk014[0x104];
27 s32 shopCredit; ///< spent on a Game Ticket; not written by name in TBS
28 s8 shopGifts; ///< indexes the Game Ticket's credit cost
29 /// The slot machine's prize weights, three prizes to each of 4, 8, 16, 32
30 /// and 64 on a new game; not read by name in TBS.
32 /// Lucky Wheels: 0 to 7 the prize categories won, ended by -1 (-2 once
33 /// awarded); 8 on the last variant given of each category.
35 u8 unk13c[0x84]; ///< not named by TBS code
38 s16 savedScene; ///< where a defeat returns to without a defeat point
39 s16 savedEntrance; ///< where a defeat returns to without a defeat point
40 s16 defaultScene; ///< the scene being run, kept as it starts
41 s16 defaultEntrance; ///< the entrance it was entered by
42 s16 sceneGroup; ///< the current scene's group; a new group resets its flags
43 s16 nextScene; ///< where the event sends the party next; -1 for none
44 s16 nextEntrance; ///< where the event sends the party next; -1 for none
45 s16 defeatScene; ///< where a defeat returns to; -1 for none
46 s16 defeatEntrance; ///< where a defeat returns to; -1 for none
47 s16 special; ///< the battle backdrop chosen for the scene or terrain
48 u8 unk1d8[2]; ///< not named by TBS code
49 s16 map; ///< the scene's map; SceneId_Clear for the world map
50 s32 x; ///< 16.16 fixed-point pixels
51 s32 y; ///< 16.16 fixed-point pixels
52 s32 z; ///< 16.16 fixed-point pixels
53 u32 heading; ///< 1/65536 turns
54 u16 turn; ///< the leader's terrainId, kept with its position
55 s16 sceneCue; ///< the battle music chosen for the encounter
56 s16 cue; ///< the current scene's field music
57 u8 movementMode; ///< 1 while the leader is climbing, 0 otherwise
58 u8 unk1f3; ///< not named by TBS code
59 s32 selectedActor; ///< the leader: its unit and its actor
60 u8 activeOwners[8]; ///< the party in order
61 u8 unk200[5]; ///< not named by TBS code
62 u8 paletteGlow[2]; ///< window hue (0 to 24), brightness
63 u8 unk207[3]; ///< not named by TBS code
64 u8 speech; ///< 1 shows speakers' portraits beside their messages
65 u8 unk20b; ///< 1 on a new game; not read by name in TBS
66 u8 messageSpeed; ///< 0 to 2; 1 on a new game
67 u8 unk20d[2]; ///< not named by TBS code
68 /// Set on saving at the end of the game; copied to the file's summary as
69 /// sendFlag.
71 /// The buttons for each field command, as KEY_ masks; read with gKeysPressed
72 /// except dashKeys, held.
73 ///@{
74 u16 aKeys; ///< examine; KEY_A
75 u16 bKeys; ///< KEY_B; not read by name in TBS
76 u16 selectKeys; ///< the menu; KEY_SELECT
77 u16 startKeys; ///< KEY_START
78 u16 firstShortcutKeys; ///< firstShortcut; KEY_L
79 u16 secondShortcutKeys; ///< secondShortcut; KEY_R
80 u16 dashKeys; ///< KEY_B
81 ///@}
82 s16 returnCue; ///< music playing when the field left; -1 for none
83 /// The shortcuts' assignments. bits: 15..14 kind (0 Psynergy, 1 an item) |
84 /// 13..0 which one.
85 ///@{
88 ///@}
89 u8 perspectiveScene; ///< set to 1 on the world map; not read by name in TBS
90 u8 unk225[5]; ///< not named by TBS code
91 u8 idleSleepEnabled; ///< the option, saved from gIdleSleepEnabled
92 u8 battleStart; ///< how the next battle starts (Battle_SetStart)
93 /// Hazardous ground (the Lamakan Desert's heat): every hazardLimit steps the
94 /// party takes hazardDamage (bit 8 a flag, bits 7 to 0 the amount).
95 ///@{
97 s16 hazardMode; ///< 0 counts on hazard cells only; 1 counts every step
99 s16 hazardSteps; ///< reset on entering a new scene group
100 ///@}
101 /// The Djinni battle pending (DJINNI_0 plus its number, flags in bits 15 to
102 /// 11), resolved on returning to the field.
104 s16 sceneChangeReason; ///< the last battle's result; -1 for a defeat
105 s32 encounterSteps; ///< the encounter count, reset with a new group
106 u16 pendingItem; ///< given on returning to the field if the party has room
107 s16 sceneVariant; ///< the current scene's variant from its record
108 s16 retreatScene; ///< where Retreat goes; the group's first entrance
109 s16 retreatEntrance; ///< where Retreat goes; the group's first entrance
110 s32 avoidDistance; ///< distance left of Avoid, 16.16 pixels; 0 when off
111 s8 avoidByItem; ///< Avoid came from an item (the Sacred Feather)
112 s8 pausedPose; ///< Halt: the stopped object's first animation param
113 s16 pausedObject; ///< Halt: the stopped object; -1 for none
114 s16 cloaked; ///< 1 under Cloak, which prevents battles
115 u8 unk24e[2]; ///< not named by TBS code
116 u32 pausedUpdate; ///< Halt: the stopped object's update; not read by name
117 u8 unk254[0x50]; ///< not named by TBS code
118 /// The link lobby's tallies: 4 the total wins and 7 the consecutive wins it
119 /// reports, 3 cleared on choosing a monster battle; the others not named by
120 /// TBS code.
122 u8 unk2b4[4]; ///< not named by TBS code
123 u32 startStamp; ///< Runtime_GetBuildStampTime's value at a new game
124 u8 unk2bc[4]; ///< not named by TBS code
125 struct BattleUnit owners[8]; ///< the characters
126};
127
128STATIC_ASSERT(offsetof(struct GameState, buildStamp) == 0);
129STATIC_ASSERT(offsetof(struct GameState, playTime) == 4);
130STATIC_ASSERT(offsetof(struct GameState, idleSleepEnabled) == 0x22a);
131STATIC_ASSERT(offsetof(struct GameState, coins) == 0x10);
132STATIC_ASSERT(offsetof(struct GameState, shopCredit) == 0x118);
133STATIC_ASSERT(offsetof(struct GameState, shopGifts) == 0x11c);
134STATIC_ASSERT(offsetof(struct GameState, owners) == 0x2c0);
135STATIC_ASSERT(sizeof(struct GameState) == 0xd20);
136STATIC_ASSERT(offsetof(struct GameState, wonPrizes) == 0x12c);
137STATIC_ASSERT(offsetof(struct GameState, sceneGroup) == 0x1cc);
138STATIC_ASSERT(offsetof(struct GameState, dashKeys) == 0x21c);
139STATIC_ASSERT(offsetof(struct GameState, avoidDistance) == 0x244);
140STATIC_ASSERT(offsetof(struct GameState, entrance) == 0x1c2);
141STATIC_ASSERT(offsetof(struct GameState, special) == 0x1d6);
142STATIC_ASSERT(offsetof(struct GameState, x) == 0x1dc);
143STATIC_ASSERT(offsetof(struct GameState, movementMode) == 0x1f2);
144STATIC_ASSERT(offsetof(struct GameState, selectedActor) == 0x1f4);
145STATIC_ASSERT(offsetof(struct GameState, activeOwners) == 0x1f8);
146STATIC_ASSERT(offsetof(struct GameState, speech) == 0x20a);
147STATIC_ASSERT(offsetof(struct GameState, messageSpeed) == 0x20c);
148STATIC_ASSERT(offsetof(struct GameState, aKeys) == 0x210);
149STATIC_ASSERT(offsetof(struct GameState, firstShortcutKeys) == 0x218);
150STATIC_ASSERT(offsetof(struct GameState, secondShortcutKeys) == 0x21a);
151STATIC_ASSERT(offsetof(struct GameState, firstShortcut) == 0x220);
152STATIC_ASSERT(offsetof(struct GameState, retreatEntrance) == 0x242);
153STATIC_ASSERT(offsetof(struct GameState, cloaked) == 0x24c);
154STATIC_ASSERT(offsetof(struct GameState, linkTallies) == 0x2a4);
155STATIC_ASSERT(offsetof(struct GameState, startStamp) == 0x2b8);
156
157#ifndef OWN_gGameState
158extern struct GameState gGameState;
159#endif
160
161/// Sets the battle start type.
162// A statement macro (S2: a layer, 34 sites): written as one, its store stays in
163// place at every use; as a plain assignment, tbs-en differs.
164#define Battle_SetStart(mode) \
165 do { \
166 gGameState.battleStart = (mode); \
167 } while (0)
168
169#endif
BattleUnit, a party member's or enemy's battle state, with the elements, abilities and actions it use...
struct GameState gGameState
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 unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
The game's state: play time, coins, the scene and the leader's position, the active party and the opt...
Definition game_state.h:14
u16 startKeys
KEY_START.
Definition game_state.h:77
u8 unk2b4[4]
not named by TBS code
Definition game_state.h:122
u16 firstShortcut
The shortcuts' assignments.
Definition game_state.h:86
s16 nextScene
where the event sends the party next; -1 for none
Definition game_state.h:43
u8 unk2bc[4]
not named by TBS code
Definition game_state.h:124
s16 cloaked
1 under Cloak, which prevents battles
Definition game_state.h:114
u8 unk20b
1 on a new game; not read by name in TBS
Definition game_state.h:65
s16 hazardLimit
Hazardous ground (the Lamakan Desert's heat): every hazardLimit steps the party takes hazardDamage (b...
Definition game_state.h:96
s16 special
the battle backdrop chosen for the scene or terrain
Definition game_state.h:47
s32 z
16.16 fixed-point pixels
Definition game_state.h:52
u16 bKeys
KEY_B; not read by name in TBS.
Definition game_state.h:75
u8 paletteGlow[2]
window hue (0 to 24), brightness
Definition game_state.h:62
u32 playTime
frames, copied from gPlayTimeFrames when saving
Definition game_state.h:18
s16 nextEntrance
where the event sends the party next; -1 for none
Definition game_state.h:44
s8 pausedPose
Halt: the stopped object's first animation param.
Definition game_state.h:112
u8 unk20d[2]
not named by TBS code
Definition game_state.h:67
s16 map
the scene's map; SceneId_Clear for the world map
Definition game_state.h:49
u32 buildStamp
Runtime_GetBuildStampTime's value when the game was last saved; its low half goes into the file's sum...
Definition game_state.h:17
s16 sceneGroup
the current scene's group; a new group resets its flags
Definition game_state.h:42
u16 selectKeys
the menu; KEY_SELECT
Definition game_state.h:76
u8 perspectiveScene
set to 1 on the world map; not read by name in TBS
Definition game_state.h:89
s8 shopGifts
indexes the Game Ticket's credit cost
Definition game_state.h:28
s16 sceneCue
the battle music chosen for the encounter
Definition game_state.h:55
u16 dashKeys
KEY_B.
Definition game_state.h:80
s32 y
16.16 fixed-point pixels
Definition game_state.h:51
u8 unk225[5]
not named by TBS code
Definition game_state.h:90
u16 turn
the leader's terrainId, kept with its position
Definition game_state.h:54
s16 defaultEntrance
the entrance it was entered by
Definition game_state.h:41
u8 unk20f
Set on saving at the end of the game; copied to the file's summary as sendFlag.
Definition game_state.h:70
s16 pendingDjinnEvent
The Djinni battle pending (DJINNI_0 plus its number, flags in bits 15 to 11), resolved on returning t...
Definition game_state.h:103
s32 avoidDistance
distance left of Avoid, 16.16 pixels; 0 when off
Definition game_state.h:110
u8 unk254[0x50]
not named by TBS code
Definition game_state.h:117
u8 unk13c[0x84]
not named by TBS code
Definition game_state.h:35
s32 shopCredit
spent on a Game Ticket; not written by name in TBS
Definition game_state.h:27
s8 avoidByItem
Avoid came from an item (the Sacred Feather).
Definition game_state.h:111
s16 hazardSteps
reset on entering a new scene group
Definition game_state.h:99
s16 pausedObject
Halt: the stopped object; -1 for none.
Definition game_state.h:113
u8 idleSleepEnabled
the option, saved from gIdleSleepEnabled
Definition game_state.h:91
s8 prizeWeights[0x0f]
The slot machine's prize weights, three prizes to each of 4, 8, 16, 32 and 64 on a new game; not read...
Definition game_state.h:31
s32 encounterSteps
the encounter count, reset with a new group
Definition game_state.h:105
u32 pausedUpdate
Halt: the stopped object's update; not read by name.
Definition game_state.h:116
struct BattleUnit owners[8]
the characters
Definition game_state.h:125
u16 secondShortcut
Definition game_state.h:87
u8 unk200[5]
not named by TBS code
Definition game_state.h:61
s16 defeatEntrance
where a defeat returns to; -1 for none
Definition game_state.h:46
u32 heading
1/65536 turns
Definition game_state.h:53
u8 unk24e[2]
not named by TBS code
Definition game_state.h:115
s16 hazardDamage
Definition game_state.h:98
s16 sceneChangeReason
the last battle's result; -1 for a defeat
Definition game_state.h:104
u8 unk008[8]
Not named by TBS code.
Definition game_state.h:22
s16 retreatEntrance
where Retreat goes; the group's first entrance
Definition game_state.h:109
s16 defeatScene
where a defeat returns to; -1 for none
Definition game_state.h:45
s16 retreatScene
where Retreat goes; the group's first entrance
Definition game_state.h:108
s16 defaultScene
the scene being run, kept as it starts
Definition game_state.h:40
s16 sceneVariant
the current scene's variant from its record
Definition game_state.h:107
u8 activeOwners[8]
the party in order
Definition game_state.h:60
s16 entrance
Definition game_state.h:37
u8 messageSpeed
0 to 2; 1 on a new game
Definition game_state.h:66
s8 wonPrizes[0x10]
Lucky Wheels: 0 to 7 the prize categories won, ended by -1 (-2 once awarded); 8 on the last variant g...
Definition game_state.h:34
u16 secondShortcutKeys
secondShortcut; KEY_R
Definition game_state.h:79
s32 x
16.16 fixed-point pixels
Definition game_state.h:50
u8 unk014[0x104]
The party's Djinn recovery list (struct DjinnRecoveryList), read through Djinn_GetRecoveryTable; not ...
Definition game_state.h:26
u8 movementMode
1 while the leader is climbing, 0 otherwise
Definition game_state.h:57
u32 startStamp
Runtime_GetBuildStampTime's value at a new game.
Definition game_state.h:123
u8 battleStart
how the next battle starts (Battle_SetStart)
Definition game_state.h:92
u16 pendingItem
given on returning to the field if the party has room
Definition game_state.h:106
s32 selectedActor
the leader: its unit and its actor
Definition game_state.h:59
u16 aKeys
The buttons for each field command, as KEY_ masks; read with gKeysPressed except dashKeys,...
Definition game_state.h:74
u8 unk1f3
not named by TBS code
Definition game_state.h:58
s16 savedScene
where a defeat returns to without a defeat point
Definition game_state.h:38
s16 cue
the current scene's field music
Definition game_state.h:56
s16 returnCue
music playing when the field left; -1 for none
Definition game_state.h:82
u8 speech
1 shows speakers' portraits beside their messages
Definition game_state.h:64
s16 hazardMode
0 counts on hazard cells only; 1 counts every step
Definition game_state.h:97
u8 unk1d8[2]
not named by TBS code
Definition game_state.h:48
u16 linkTallies[8]
The link lobby's tallies: 4 the total wins and 7 the consecutive wins it reports, 3 cleared on choosi...
Definition game_state.h:121
u8 unk207[3]
not named by TBS code
Definition game_state.h:63
u16 firstShortcutKeys
firstShortcut; KEY_L
Definition game_state.h:78
s16 savedEntrance
where a defeat returns to without a defeat point
Definition game_state.h:39
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