Alchemy
Loading...
Searching...
No Matches

field_obj.h

Go to the documentation of this file.
1#ifndef ALCHEMY_FIELD_OBJ_H
2#define ALCHEMY_FIELD_OBJ_H
3
4/// @file
5/// Field objects and actors, and the scene transition styles.
6
7#include "types.h"
8#include "static_assert.h"
9
10#include "event_work.h"
11
12extern struct EventWork *gEventWork;
13
18};
19
20#define SCENE_TRANSITION(style, variant) ((style) << 8 | (variant))
21
22#include "field_coordinate.h"
23
24#include "animspr.h"
25
26union FieldObject;
27
28/// A field actor: a person or thing on the field with a position, motion
29/// toward a target, sprites and an update callback.
30struct FieldActor {
31 /// The object's script pointer (nonzero while the object is live) and its
32 /// cursor, which ObjectRuntime names script and step.
34 u16 facing; ///< 1/65536 turns
35 union FieldCoordinate x; ///< 16.16 fixed-point pixels
36 union FieldCoordinate y; ///< 16.16 fixed-point pixels
37 union FieldCoordinate z; ///< 16.16 fixed-point pixels
38 s32 terrainHeight; ///< 16.16 fixed-point pixels
39 s32 scaleX; ///< 16.16 fixed point, 0x10000 full size
40 s32 scaleY; ///< 16.16 fixed point, 0x10000 full size
41 /// Collision radius in pixels: 16, or half the sprite metadata's boxY, when
42 /// created; the overlap checks use it less 2.
44 /// The map layer (0 to 3) its ground height is read from, which the
45 /// scrolling camera updates from the cell under it; the fixed camera passes
46 /// it as the sprite's draw slot.
48 /// ActorPriorityFlag bits, read by the scrolling camera.
49 /// bits: 2 sorted as if 320 pixels lower | 1 sorted as if 320 pixels
50 /// higher | 0 sprite priority from the cell under it
52 s32 velocityX; ///< 16.16 fixed-point pixels per frame
53 s32 velocityY; ///< 16.16 fixed-point pixels per frame
54 s32 velocityZ; ///< 16.16 fixed-point pixels per frame
55 s32 speed; ///< speed limit, 16.16 fixed-point pixels per frame
56 /// Added toward the target each frame, or taken off the speed when there is
57 /// none, in 16.16 fixed-point pixels per frame; 0x10000 when created.
59 s32 targetX; ///< 16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
60 s32 targetY; ///< 16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
61 s32 targetZ; ///< 16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
62 /// The share of its falling speed kept as it bounces on landing, 16.16
63 /// fixed point (0x4000 when created); a floating object's phase instead.
65 /// Taken off the vertical velocity each frame while it is above the
66 /// ground, in 16.16 fixed-point pixels per frame (0x10000 when created);
67 /// also scales a floating object's bob.
69 /// Zeroed by FieldObject_Create and not read by the engine; scene code
70 /// keeps a resting height, a sway or a countdown here.
72 union {
73 struct AnimationObject *sprite; ///< spriteStorageKind 1
74 void **sprites; ///< spriteStorageKind 2: four sprites, empty ones null
75 };
76 /// Zero hides sprites; one draws a single sprite, two draws a group.
77 /// The engine reads the low four bits; SC_B54_ON and SC_B54_OFF set 1 and 0.
79 /// ActorMotionFlag bits; zero is free flight in 3D, and 3 is set on
80 /// creation.
81 /// bits: 4 no slowdown on slopes | 3 bigger float | 2 floats | 1 falls |
82 /// 0 follows the terrain
84 /// The ARRIVAL_AXIS_* watched for arrival, the object script's last flag
85 /// test (ScriptInterpreter.conditionResult), and whether it snaps onto its
86 /// target on arrival: ScriptMotionObject names 0x56 and 0x58.
88 /// bits: 7 refuses to move into a solid object | 4 nearer for Psynergy
89 /// targets | 3 never a talk or Psynergy target | 2 nearer to talk to |
90 /// 1 the player pushes it | 0 solid
92 u8 steeringFlags; ///< ActorSteeringFlag bits
93 u8 paused; ///< nonzero skips its script and motion, not its update
94 /// Nonzero keeps its sprite's VRAM cache entry while sprites are suspended
95 /// or it is off screen (ObjectSystem_UpdateCamera).
97 u8 repeatCount; ///< the object script's SC_LOOP count (ScriptInterpreter)
98 u16 wait; ///< the object script's wait, in frames (ScriptMotionObject)
99 /// Frames a solid object has refused its move (ScriptMotionObject's
100 /// refused); SC_SYNC stops waiting after 60.
102 /// Nonzero skips steering, terrain, gravity and floating; its velocity
103 /// still moves it (ScriptMotionObject.frozen).
105 u8 riseCounter; ///< not read by the engine; scene code's own counter
106 u8 riseEnabled; ///< not read by the engine; scene code's own state
107 /// The parameter its action script reads (a follow distance or an angle to
108 /// face), the player's frames to its next footprint, or scene scratch.
110 /// The side of the player's next footprint (2 after a stop), or scene
111 /// scratch.
113 /// The object its action script follows or faces.
115 /// Called each frame before the object's script, while the object is live.
116 void (*update)(union FieldObject *object);
117};
118
119STATIC_ASSERT(offsetof(struct FieldActor, facing) == 0x06);
122STATIC_ASSERT(offsetof(struct FieldActor, terrainHeight) == 0x14);
123STATIC_ASSERT(offsetof(struct FieldActor, scaleY) == 0x1c);
124STATIC_ASSERT(offsetof(struct FieldActor, priorityFlags) == 0x23);
125STATIC_ASSERT(offsetof(struct FieldActor, motionFlags) == 0x55);
126STATIC_ASSERT(offsetof(struct FieldActor, collisionFlags) == 0x59);
127STATIC_ASSERT(offsetof(struct FieldActor, steeringFlags) == 0x5a);
128STATIC_ASSERT(offsetof(struct FieldActor, paused) == 0x5b);
129STATIC_ASSERT(offsetof(struct FieldActor, retainSpriteCache) == 0x5c);
130STATIC_ASSERT(offsetof(struct FieldActor, repeatCount) == 0x5d);
131STATIC_ASSERT(offsetof(struct FieldActor, wait) == 0x5e);
132STATIC_ASSERT(offsetof(struct FieldActor, refused) == 0x60);
133STATIC_ASSERT(offsetof(struct FieldActor, frozen) == 0x61);
134STATIC_ASSERT(offsetof(struct FieldActor, riseEnabled) == 0x63);
135STATIC_ASSERT(offsetof(struct FieldActor, bounce) == 0x44);
136STATIC_ASSERT(offsetof(struct FieldActor, gravity) == 0x48);
137STATIC_ASSERT(offsetof(struct FieldActor, riseBaseY) == 0x4c);
138STATIC_ASSERT(offsetof(struct FieldActor, velocityY) == 0x28);
139STATIC_ASSERT(offsetof(struct FieldActor, speed) == 0x30);
140STATIC_ASSERT(offsetof(struct FieldActor, targetX) == 0x38);
141STATIC_ASSERT(offsetof(struct FieldActor, sprite) == 0x50);
142STATIC_ASSERT(offsetof(struct FieldActor, update) == 0x6c);
143
144/// A target coordinate that is not set: the object has no target.
145#define ACTOR_NO_TARGET ((s32)0x80000000)
146
147/// Preserves the current action and motion when assigning a linked target.
149
150/// FieldActor.priorityFlags bits.
152 /// The sprite takes its priority from the map cell under it.
154 /// The depth sort treats it as 320 pixels higher on the screen.
156};
157
158/// FieldActor.motionFlags bits.
160 ACTOR_FOLLOWS_TERRAIN = 0x01, ///< moves with the ground height under it
161 ACTOR_FALLS = 0x02 ///< falls by its gravity and bounces
162};
163
164/// FieldActor.steeringFlags bits.
166 ACTOR_FACES_MOTION = 0x01 ///< turns toward its velocity, 1/16 turn a frame
167};
168
169#endif
Animated sprites: their layers, frames and colour modes, and the resource slots they draw from.
EventWork, the running scene's event work.
FieldCoordinate, a position on the field.
ActorLinkFlag
Preserves the current action and motion when assigning a linked target.
Definition field_obj.h:148
@ ACTOR_LINK_KEEP_MOTION
Definition field_obj.h:148
SceneTransitionStyle
Definition field_obj.h:14
@ TRANSITION_WINDOW
Definition field_obj.h:17
@ TRANSITION_BACKDROP_FADE
Definition field_obj.h:16
@ TRANSITION_FADE
Definition field_obj.h:15
ActorPriorityFlag
FieldActor.priorityFlags bits.
Definition field_obj.h:151
@ ACTOR_PRIORITY_UNDERFOOT
The depth sort treats it as 320 pixels higher on the screen.
Definition field_obj.h:155
@ ACTOR_PRIORITY_AUTOMATIC
The sprite takes its priority from the map cell under it.
Definition field_obj.h:153
ActorMotionFlag
FieldActor.motionFlags bits.
Definition field_obj.h:159
@ ACTOR_FOLLOWS_TERRAIN
moves with the ground height under it
Definition field_obj.h:160
@ ACTOR_FALLS
falls by its gravity and bounces
Definition field_obj.h:161
ActorSteeringFlag
FieldActor.steeringFlags bits.
Definition field_obj.h:165
@ ACTOR_FACES_MOTION
turns toward its velocity, 1/16 turn a frame
Definition field_obj.h:166
struct EventWork * gEventWork
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
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
The running scene's event work: its placement and event tables, its actors, the triggers and exit it ...
Definition event_work.h:20
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
s16 timer
The parameter its action script reads (a follow distance or an angle to face), the player's frames to...
Definition field_obj.h:109
s32 speed
speed limit, 16.16 fixed-point pixels per frame
Definition field_obj.h:55
s32 targetX
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:59
struct FieldActor * linkedObject
The object its action script follows or faces.
Definition field_obj.h:114
u16 radius
Collision radius in pixels: 16, or half the sprite metadata's boxY, when created; the overlap checks ...
Definition field_obj.h:43
u8 steeringFlags
ActorSteeringFlag bits.
Definition field_obj.h:92
u8 motionFlags
ActorMotionFlag bits; zero is free flight in 3D, and 3 is set on creation.
Definition field_obj.h:83
u8 refused
Frames a solid object has refused its move (ScriptMotionObject's refused); SC_SYNC stops waiting afte...
Definition field_obj.h:101
u8 riseCounter
not read by the engine; scene code's own counter
Definition field_obj.h:105
union FieldCoordinate x
16.16 fixed-point pixels
Definition field_obj.h:35
s32 targetZ
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:61
u8 retainSpriteCache
Nonzero keeps its sprite's VRAM cache entry while sprites are suspended or it is off screen (ObjectSy...
Definition field_obj.h:96
s32 velocityX
16.16 fixed-point pixels per frame
Definition field_obj.h:52
u8 paused
nonzero skips its script and motion, not its update
Definition field_obj.h:93
s32 bounce
The share of its falling speed kept as it bounces on landing, 16.16 fixed point (0x4000 when created)...
Definition field_obj.h:64
union FieldCoordinate y
16.16 fixed-point pixels
Definition field_obj.h:36
u8 priorityFlags
ActorPriorityFlag bits, read by the scrolling camera.
Definition field_obj.h:51
u8 repeatCount
the object script's SC_LOOP count (ScriptInterpreter)
Definition field_obj.h:97
s32 terrainHeight
16.16 fixed-point pixels
Definition field_obj.h:38
s32 velocityY
16.16 fixed-point pixels per frame
Definition field_obj.h:53
u8 spriteStorageKind
Zero hides sprites; one draws a single sprite, two draws a group.
Definition field_obj.h:78
s32 gravity
Taken off the vertical velocity each frame while it is above the ground, in 16.16 fixed-point pixels ...
Definition field_obj.h:68
u8 unk56[3]
The ARRIVAL_AXIS_* watched for arrival, the object script's last flag test (ScriptInterpreter....
Definition field_obj.h:87
union FieldCoordinate z
16.16 fixed-point pixels
Definition field_obj.h:37
u16 facing
1/65536 turns
Definition field_obj.h:34
s32 acceleration
Added toward the target each frame, or taken off the speed when there is none, in 16....
Definition field_obj.h:58
s32 targetY
16.16 fixed-point pixels; ACTOR_NO_TARGET when unset
Definition field_obj.h:60
s32 scaleX
16.16 fixed point, 0x10000 full size
Definition field_obj.h:39
s32 scaleY
16.16 fixed point, 0x10000 full size
Definition field_obj.h:40
u8 unk00[6]
The object's script pointer (nonzero while the object is live) and its cursor, which ObjectRuntime na...
Definition field_obj.h:33
void(*) update(union FieldObject *object)
Called each frame before the object's script, while the object is live.
Definition field_obj.h:116
s32 riseBaseY
Zeroed by FieldObject_Create and not read by the engine; scene code keeps a resting height,...
Definition field_obj.h:71
u16 wait
the object script's wait, in frames (ScriptMotionObject)
Definition field_obj.h:98
u16 work
The side of the player's next footprint (2 after a stop), or scene scratch.
Definition field_obj.h:112
u8 collisionFlags
bits: 7 refuses to move into a solid object | 4 nearer for Psynergy targets | 3 never a talk or Psyne...
Definition field_obj.h:91
s32 velocityZ
16.16 fixed-point pixels per frame
Definition field_obj.h:54
u8 riseEnabled
not read by the engine; scene code's own state
Definition field_obj.h:106
u8 terrainId
The map layer (0 to 3) its ground height is read from, which the scrolling camera updates from the ce...
Definition field_obj.h:47
u8 frozen
Nonzero skips steering, terrain, gravity and floating; its velocity still moves it (ScriptMotionObjec...
Definition field_obj.h:104
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
struct AnimationObject * sprite
spriteStorageKind 1
void ** sprites
spriteStorageKind 2: four sprites, empty ones null
A field coordinate, read whole or as its fraction and its whole pixels.
An object on the field, read as an actor or as an effect.