Alchemy
Loading...
Searching...
No Matches

field_scene.h

Go to the documentation of this file.
1#ifndef ALCHEMY_FIELD_SCENE_H
2#define ALCHEMY_FIELD_SCENE_H
3
4/// @file
5/// The scene table formats: entrances, exits, placements and events, and the
6/// macros that write them.
7
8#include "static_assert.h"
9#include "scene_ids.h"
10#include "character_ids.h"
11
12enum SceneId {
23};
24
25enum Facing {
26 FACING_EAST = 0x0000,
28 FACING_SOUTH = 0x4000,
30 FACING_WEST = 0x8000,
32 FACING_NORTH = 0xc000,
34};
35
36enum { FACING_STEP = 0x1000 };
37
38#define FACING_IS_NORTH(facing) \
39 ((u32)((facing) - (FACING_NORTHWEST + 1)) <= \
40 FACING_NORTHEAST - FACING_NORTHWEST - 2)
41
42enum {
46};
47
48#define IF_FLAG_SET(flag) ((flag) | CONDITION_FLAG_SET)
49
50enum { FLAG_PARTY_LEFT_VALE = 0x815 };
51
52/// A scene entrance: where and facing which way the party arrives, and the
53/// camera's bounds there (-1 for none).
55 s16 entrance; ///< the entrance number the game state names; -1 ends
56 s16 requiredFlag; ///< a flag that must be set, or -1 for none
57 s16 x; ///< pixels
58 s16 y; ///< pixels
59 s16 z; ///< pixels
60 u16 facing; ///< 1/65536 turns (enum Facing)
61 s16 unused1; ///< 0 in every table; not read
62 s16 cameraLeft; ///< pixels
63 s16 cameraTop; ///< pixels
64 s16 cameraRight; ///< pixels
65 s16 cameraBottom; ///< pixels
66 s16 unused2; ///< 0 in every table; not read
67};
68
69STATIC_ASSERT(sizeof(struct SceneEntrance) == 24);
70STATIC_ASSERT(offsetof(struct SceneEntrance, cameraLeft) == 14);
71
72#define SCENE_EXITS(scene) ((u32)(scene))
73#define SCENE_EXIT(exit, scene, entrance) \
74 ((u32)(exit) << 20 | (u32)(entrance) << 12 | (u32)(scene))
75#define SCENE_EXIT_IF(exit, scene, entrance, flag) \
76 (SCENE_EXIT(exit, scene, entrance) | 0x10000000), (u32)(flag)
77#define SCENE_EXITS_END 0x1ff
78
79/// An actor a scene places: its sprite, the condition for placing it, how it
80/// behaves, where it stands and which way it faces, and how it turns to talk.
82 /// The actor's sprite; 0 to 7 are the party's characters, each in its own
83 /// actor slot, and -1 ends the table.
85 /// -1 always, a flag | 0x1000 set, else the flag clear; off the world map,
86 /// 48 to 127 also need condition + 80 to hold.
88 /// A built-in action (enum ActorBehavior, 1 to 7) or an action script, for
89 /// ObjectMotion_SetActionCallback.
91 s32 x; ///< 16.16 fixed-point pixels
92 s32 y; ///< 16.16 fixed-point pixels
93 s32 z; ///< 16.16 fixed-point pixels
94 u16 facing; ///< 1/65536 turns (enum Facing)
95 u8 talkFacing; ///< enum ActorTalkFacing; 3 follows the leader afterwards
96 u8 flags; ///< PLACEMENT_SHARE_PREVIOUS_SPRITE
97};
98
99STATIC_ASSERT(sizeof(struct ScenePlacement) == 24);
100STATIC_ASSERT(offsetof(struct ScenePlacement, talkFacing) == 22);
101
103
108};
109
110#define PLACEMENT_SHARE_PREVIOUS_SPRITE 0x01
111
113
114#define PIXELS(value) ((value) << 16)
115
116/// A scene event: its kind and detail, the trigger it answers, its condition
117/// and its value (a message or an event script).
119 /// The kind and its detail, read by Scene_FindEvent and the item, Psynergy
120 /// and search lookups; -1 ends the table. The detail bits depend on the kind.
121 /// bits: 30..28 Psynergy phase | 15..12 touch facing | 15..8 item or ability
122 /// | 11 short push | 10 facing | 9 walking | 8..4 search target
123 /// | 7 Psynergy in area | 5..4 exit sound | 4 on an actor | 3..0 kind
125 /// What the event answers: an actor id, a tile's collision code, a marker
126 /// id or a raised value. Item and Psynergy events read it as bits below;
127 /// bit 10 also skips a search's checking message and a Psynergy's effect.
128 /// bits: 15..12 facing | 11 needs facing | 10 own message | 7..0 target
130 s16 condition; ///< -1 always, a flag | 0x1000 set, else the flag clear
131 /// A message below 0x10000, else an event function; for an exit, the exit
132 /// kind its scene's exit table matches, and for a search, a FIND_ value.
134};
135
136STATIC_ASSERT(sizeof(struct SceneEvent) == 12);
137
146};
147
148#define EVENT_TOUCH_WALKING 0x200
149#define EVENT_TOUCH_FACING 0x400
150#define TOUCH_WALKING (EVENT_TOUCH | EVENT_TOUCH_WALKING)
151#define TOUCH_FACING(facing) (EVENT_TOUCH | EVENT_TOUCH_FACING | (facing))
152#define TOUCH_WALKING_INTO(facing) \
153 (EVENT_TOUCH | EVENT_TOUCH_WALKING | EVENT_TOUCH_FACING | (facing))
154
155#define EVENT_PSYNERGY_ON_ACTOR 0x10
156#define PSYNERGY_ON_ACTOR(ability) \
157 (EVENT_PSYNERGY | EVENT_PSYNERGY_ON_ACTOR | (ability) << 8)
158/// A Psynergy event on an actor at one phase of the cast, as PSYNERGY_IN_AREA
159/// is for an area.
160#define PSYNERGY_PHASE_ON_ACTOR(ability, phase) \
161 ((u32)(phase) << 28 | PSYNERGY_ON_ACTOR(ability))
162
163#define EVENT_PSYNERGY_IN_AREA 0x80
164#define PSYNERGY_IN_AREA(ability, phase) \
165 ((u32)(phase) << 28 | (ability) << 8 | EVENT_PSYNERGY_IN_AREA | \
166 EVENT_PSYNERGY)
167
168// Using an item (one byte) on a tile code, or on an actor, as
169// Field_FindItemEvent reads them.
170#define EVENT_ITEM_ON_ACTOR 0x10
171#define USE_ITEM(item) (EVENT_ITEM | (item) << 8)
172#define USE_ITEM_ON_ACTOR(item) (EVENT_ITEM | EVENT_ITEM_ON_ACTOR | (item) << 8)
173
174#define SEARCH(target) (EVENT_SEARCH | (target) << 4)
175
209};
210
211#define FIND_ITEM(item) (0x00100000 | (item))
212#define FIND_COINS(coins) (0x00200000 | (coins))
213#define FIND_PSYNERGY_STONE 0x00300000
214#define FIND_MESSAGE(message) (0x00400000 | (message))
215
216#define EVENT_SCRIPT(script) ((u32)(script))
217#define SCENE_EVENTS_END 0xffffffff
218
219struct SceneRegion;
220
221#endif
Character numbers, with each character's Japanese name.
SceneEventKind
@ EVENT_SEARCH
@ EVENT_TOUCH
@ EVENT_EXIT
@ EVENT_PSYNERGY
@ EVENT_TALK
@ EVENT_RAISED
@ EVENT_ITEM
@ FACING_STEP
Definition field_scene.h:36
SceneId
Definition field_scene.h:12
@ SCENE_LUNPA_FORTRESS
Definition field_scene.h:21
@ SCENE_VAULT
Definition field_scene.h:14
@ SCENE_SUHALLA_GATE
Definition field_scene.h:22
@ SCENE_WEST_LUNPA_CAVE
Definition field_scene.h:19
@ SCENE_VAULT_JAIL
Definition field_scene.h:15
@ SCENE_LUNPA
Definition field_scene.h:17
@ SCENE_VAULT_REVISIT
Definition field_scene.h:16
@ SCENE_LUNPA_SUHALLA
Definition field_scene.h:18
@ SCENE_WORLD_MAP
Definition field_scene.h:13
@ SCENE_LUNPA_FORTRESS_GATE
Definition field_scene.h:20
@ ACTOR_FIRST_PLACED
@ ACTOR_PARTY_LEADER
@ CONDITION_FLAG_SET
Definition field_scene.h:45
@ SCENE_TABLE_END
Definition field_scene.h:43
@ CONDITION_ALWAYS
Definition field_scene.h:44
@ FLAG_PARTY_LEFT_VALE
Definition field_scene.h:50
ActorTalkFacing
@ TALK_KEEP_FACING
@ TALK_FACE_PARTY
@ TALK_FACE_PARTY_AND_BACK
ActorBehavior
@ ACTOR_WANDER
@ ACTOR_STAND
Facing
Definition field_scene.h:25
@ FACING_NORTHEAST
Definition field_scene.h:33
@ FACING_EAST
Definition field_scene.h:26
@ FACING_SOUTHEAST
Definition field_scene.h:27
@ FACING_NORTH
Definition field_scene.h:32
@ FACING_SOUTHWEST
Definition field_scene.h:29
@ FACING_NORTHWEST
Definition field_scene.h:31
@ FACING_SOUTH
Definition field_scene.h:28
@ FACING_WEST
Definition field_scene.h:30
SearchTarget
@ SEARCH_FIREWOOD
@ SEARCH_OVEN
@ SEARCH_WELL
@ SEARCH_BOOKCASE
@ SEARCH_DOOR
@ SEARCH_HOLE
@ SEARCH_BED
@ SEARCH_STALACTITE
@ SEARCH_WOODEN_BOX
@ SEARCH_CHIMNEY
@ SEARCH_TABLE
@ SEARCH_SHELF
@ SEARCH_JAR
@ SEARCH_GROUND
@ SEARCH_UNDERBRUSH
@ SEARCH_STONE_PILLAR
@ SEARCH_WARDROBE
@ SEARCH_STONE_COFFIN
@ SEARCH_WATER
@ SEARCH_UNNAMED
@ SEARCH_STONE_STATUE
@ SEARCH_TREE
@ SEARCH_FIREPLACE
@ SEARCH_STONE_TABLET
@ SEARCH_FOUNTAIN
@ SEARCH_CHEST
@ SEARCH_ROCK
@ SEARCH_BOARDS
@ SEARCH_BOOKS
@ SEARCH_WALL
@ SEARCH_BARREL
@ SEARCH_GRAVE
Scene numbers, named after their places.
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 scene entrance: where and facing which way the party arrives, and the camera's bounds there (-1 for...
Definition field_scene.h:54
s16 requiredFlag
a flag that must be set, or -1 for none
Definition field_scene.h:56
s16 unused2
0 in every table; not read
Definition field_scene.h:66
s16 unused1
0 in every table; not read
Definition field_scene.h:61
s16 y
pixels
Definition field_scene.h:58
s16 cameraTop
pixels
Definition field_scene.h:63
s16 cameraRight
pixels
Definition field_scene.h:64
s16 cameraLeft
pixels
Definition field_scene.h:62
s16 entrance
the entrance number the game state names; -1 ends
Definition field_scene.h:55
s16 z
pixels
Definition field_scene.h:59
s16 x
pixels
Definition field_scene.h:57
u16 facing
1/65536 turns (enum Facing)
Definition field_scene.h:60
s16 cameraBottom
pixels
Definition field_scene.h:65
A scene event: its kind and detail, the trigger it answers, its condition and its value (a message or...
s16 condition
-1 always, a flag | 0x1000 set, else the flag clear
s16 trigger
What the event answers: an actor id, a tile's collision code, a marker id or a raised value.
u32 value
A message below 0x10000, else an event function; for an exit, the exit kind its scene's exit table ma...
u32 control
The kind and its detail, read by Scene_FindEvent and the item, Psynergy and search lookups; -1 ends t...
An actor a scene places: its sprite, the condition for placing it, how it behaves,...
Definition field_scene.h:81
s32 x
16.16 fixed-point pixels
Definition field_scene.h:91
u8 flags
PLACEMENT_SHARE_PREVIOUS_SPRITE.
Definition field_scene.h:96
s16 condition
-1 always, a flag | 0x1000 set, else the flag clear; off the world map, 48 to 127 also need condition...
Definition field_scene.h:87
u16 facing
1/65536 turns (enum Facing)
Definition field_scene.h:94
u8 talkFacing
enum ActorTalkFacing; 3 follows the leader afterwards
Definition field_scene.h:95
s32 z
16.16 fixed-point pixels
Definition field_scene.h:93
s32 y
16.16 fixed-point pixels
Definition field_scene.h:92
s16 sprite
The actor's sprite; 0 to 7 are the party's characters, each in its own actor slot,...
Definition field_scene.h:84
s32 behavior
A built-in action (enum ActorBehavior, 1 to 7) or an action script, for ObjectMotion_SetActionCallbac...
Definition field_scene.h:90
A scene's exit region: the box that, while its condition holds, takes the party leader out through it...
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11