Alchemy
Loading...
Searching...
No Matches

script_motion.h

Go to the documentation of this file.
1#ifndef ALCHEMY_SCRIPT_MOTION_H
2#define ALCHEMY_SCRIPT_MOTION_H
3
4/// @file
5/// ScriptMotionObject, an object moved by a field script.
6
7#include "types.h"
8#include "static_assert.h"
9
10union FieldObject;
11
12// UB: scripts have variable lengths, so a one-word member cannot describe
13// them. Keep the native view outside UBFIX: a flat word pointer changes one
14// Thumb load's base/index order; a pointer to an unbounded array does too.
15#ifdef UBFIX
17#else
18/// The words of an object's script, as its script pointer reads them.
21};
23#endif
24
25/// A field object as the motion code sees it: its script, position, motion
26/// toward a target, bounce and gravity, motion flags and wait, and its hook.
28 const ScriptMotionWords *script; ///< null when the object is free
29 u16 scriptCursor; ///< in words; read signed
30 u16 facing; ///< 1/65536 turns
31 s32 x; ///< 16.16 fixed-point pixels
32 s32 y; ///< 16.16 fixed-point pixels
33 s32 z; ///< 16.16 fixed-point pixels
34 s32 terrainHeight; ///< 16.16 fixed-point pixels
35 u8 unk18[0x0a]; ///< the x and y scales and the radius; not named here
36 u8 terrainId; ///< the map layer whose ground height it follows
37 u8 unk23; ///< FieldActor.priorityFlags; not named here
38 s32 velocityX; ///< 16.16 fixed-point pixels per frame
39 s32 velocityY; ///< 16.16 fixed-point pixels per frame
40 s32 velocityZ; ///< 16.16 fixed-point pixels per frame
41 s32 speedLimit; ///< 16.16 fixed-point pixels per frame
42 /// Added toward the target each frame, or taken off the speed when there is
43 /// none, in 16.16 fixed-point pixels per frame.
45 s32 targetX; ///< 16.16 fixed-point pixels; 0x80000000 when unset
46 s32 targetY; ///< 16.16 fixed-point pixels; 0x80000000 when unset
47 s32 targetZ; ///< 16.16 fixed-point pixels; 0x80000000 when unset
48 union {
49 /// The share of the falling speed kept on landing, 16.16 fixed point.
50 s32 bounce;
51 /// A floating object's step along gScriptObject_CycleTable, low six bits.
52 s32 phase;
54 /// Taken off velocityY each frame above the ground, 16.16 fixed-point
55 /// pixels per frame; also scales a floating object's bob.
57 /// A spare word, the sprite pointer and the sprite kind; not named here.
59 /// bits: 4 no slowdown on slopes | 3 bigger float | 2 floats | 1 falls |
60 /// 0 follows the terrain; zero is free flight in 3D
62 u8 arrivalAxis; ///< the ARRIVAL_AXIS_* that decides arrival
63 u8 unk57; ///< the object script's last flag test; not named here
64 u8 snapToTarget; ///< nonzero lands it exactly on its target
65 u8 collisionFlags; ///< bit 7: a solid object refuses its move
66 u8 steeringFlags; ///< bit 0: turns toward its velocity, 1/16 turn a frame
67 u8 paused; ///< nonzero skips its script and motion, not its hook
68 /// The flag that keeps its sprite's VRAM, and the object script's SC_LOOP
69 /// count; not named here.
71 s16 wait; ///< frames left before its script runs again
72 u8 refused; ///< frames in a row a solid object refused its move
73 u8 frozen; ///< nonzero skips steering, terrain, gravity and floating
74 /// Two bytes scene code uses, the action parameter, the footprint side
75 /// and the linked object; not named here.
76 u8 unk62[10];
77 /// Called each frame before its script.
78 void (*hook)(union FieldObject *object);
79};
80
81STATIC_ASSERT(sizeof(struct ScriptMotionObject) == 0x70);
82STATIC_ASSERT(offsetof(struct ScriptMotionObject, script) == 0x00);
83STATIC_ASSERT(offsetof(struct ScriptMotionObject, scriptCursor) == 0x04);
84STATIC_ASSERT(offsetof(struct ScriptMotionObject, facing) == 0x06);
85STATIC_ASSERT(offsetof(struct ScriptMotionObject, vertical) == 0x44);
86STATIC_ASSERT(offsetof(struct ScriptMotionObject, arrivalAxis) == 0x56);
88STATIC_ASSERT(offsetof(struct ScriptMotionObject, frozen) == 0x61);
90
91#endif
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 object as the motion code sees it: its script, position, motion toward a target,...
s32 acceleration
Added toward the target each frame, or taken off the speed when there is none, in 16....
s32 terrainHeight
16.16 fixed-point pixels
s32 targetX
16.16 fixed-point pixels; 0x80000000 when unset
u8 unk57
the object script's last flag test; not named here
s32 x
16.16 fixed-point pixels
u8 arrivalAxis
the ARRIVAL_AXIS_* that decides arrival
u16 scriptCursor
in words; read signed
s32 velocityY
16.16 fixed-point pixels per frame
s32 speedLimit
16.16 fixed-point pixels per frame
u8 paused
nonzero skips its script and motion, not its hook
void(*) hook(union FieldObject *object)
Called each frame before its script.
u8 collisionFlags
bit 7: a solid object refuses its move
u8 unk23
FieldActor.priorityFlags; not named here.
u8 unk5c[2]
The flag that keeps its sprite's VRAM, and the object script's SC_LOOP count; not named here.
u8 refused
frames in a row a solid object refused its move
s32 velocityX
16.16 fixed-point pixels per frame
s32 targetY
16.16 fixed-point pixels; 0x80000000 when unset
u8 motionFlags
bits: 4 no slowdown on slopes | 3 bigger float | 2 floats | 1 falls | 0 follows the terrain; zero is ...
u16 facing
1/65536 turns
const ScriptMotionWords * script
null when the object is free
u8 unk62[10]
Two bytes scene code uses, the action parameter, the footprint side and the linked object; not named ...
s32 gravity
Taken off velocityY each frame above the ground, 16.16 fixed-point pixels per frame; also scales a fl...
u8 unk18[0x0a]
the x and y scales and the radius; not named here
union ScriptMotionObject::@251026000204114031114155171320036163006104311101 vertical
u8 terrainId
the map layer whose ground height it follows
u8 steeringFlags
bit 0: turns toward its velocity, 1/16 turn a frame
s16 wait
frames left before its script runs again
u8 frozen
nonzero skips steering, terrain, gravity and floating
u8 snapToTarget
nonzero lands it exactly on its target
s32 y
16.16 fixed-point pixels
s32 z
16.16 fixed-point pixels
s32 targetZ
16.16 fixed-point pixels; 0x80000000 when unset
u8 unk4c[9]
A spare word, the sprite pointer and the sprite kind; not named here.
s32 velocityZ
16.16 fixed-point pixels per frame
The words of an object's script, as its script pointer reads them.
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
An object on the field, read as an actor or as an effect.
s32 phase
A floating object's step along gScriptObject_CycleTable, low six bits.
s32 bounce
The share of the falling speed kept on landing, 16.16 fixed point.