Alchemy
Loading...
Searching...
No Matches

script.h

Go to the documentation of this file.
1#ifndef ALCHEMY_FIELD_SCRIPT_H
2#define ALCHEMY_FIELD_SCRIPT_H
3
4/// @file
5/// The field object script interpreter and the operands its commands read.
6
7#include "edition.h"
8#include "types.h"
9#include "static_assert.h"
10
12
13typedef s32 (*ScriptCommand)(struct ScriptInterpreter *);
14
15/// The prefix that command handlers read from a field object's 0x70-byte slot.
17 const s32 *script; ///< the running script; SC_END sets gScript_MainScript
18 s16 cursor; ///< the word index of the next command in script
19 u8 padding06[0x4e]; ///< the object's own fields; not read by the commands
20 /// FieldActor's spriteStorageKind: SC_B54_ON sets 1, one sprite drawn, and
21 /// SC_B54_OFF sets 0, which hides the object's sprites.
23 u8 padding55[2]; ///< the object's own fields; not read by the commands
24 u8 conditionResult; ///< the last flag test, read by SC_IF and SC_IFNOT
25 u8 padding58[5]; ///< the object's own fields; not read by the commands
26 u8 repeatCount; ///< SC_LOOP's count of jumps so far
27 /// Frames left of SC_WAIT (n - 1 when it starts); the update loops count
28 /// it down, and Script_FindLabel clears it.
30 /// Frames in a row a solid object has refused the object's move
31 /// (ScriptMotionObject.refused); SC_SYNC stops waiting after 60 and clears
32 /// it.
34};
35
36STATIC_ASSERT(sizeof(struct ScriptInterpreter) == 0x64);
37STATIC_ASSERT(offsetof(struct ScriptInterpreter, script) == 0x00);
38STATIC_ASSERT(offsetof(struct ScriptInterpreter, cursor) == 0x04);
39STATIC_ASSERT(offsetof(struct ScriptInterpreter, spriteStorageKind) == 0x54);
40STATIC_ASSERT(offsetof(struct ScriptInterpreter, conditionResult) == 0x57);
41STATIC_ASSERT(offsetof(struct ScriptInterpreter, repeatCount) == 0x5d);
43STATIC_ASSERT(offsetof(struct ScriptInterpreter, refused) == 0x60);
44
45/// The whole 0x70-byte slot as SC_SET, SC_ADD and SC_CMP see it: each field
46/// is one work value (enum ScriptWork in objcmd.h), reached through
47/// gScript_OperandHandlerTable, and named for what the engine keeps there.
48/// The types are the widths the handlers read, not the engine's own.
50 u32 scriptAddress; ///< SW_SCRIPT; an add steps it by whole words
51 u16 cursor; ///< SW_CURSOR, compared as signed
52 u16 facing; ///< SW_FACING, and work values 2 and 4
53 u32 x; ///< SW_X, 16.16 fixed-point pixels
54 u32 y; ///< SW_Y
55 u32 z; ///< SW_Z
56 u32 terrainHeight; ///< SW_GROUND
57 u32 scaleX; ///< SW_SCALE_X, 16.16 fixed point
58 u32 scaleY; ///< SW_SCALE_Y, and work value 0x0b
59 u16 radius; ///< SW_RADIUS, in pixels; compared as signed
60 u8 padding22[2]; ///< the layer and priority flags; no work value
61 u32 velocityX; ///< SW_VELOCITY_X, 16.16 fixed-point pixels per frame
62 u32 velocityY; ///< SW_VELOCITY_Y
63 u32 velocityZ; ///< SW_VELOCITY_Z
64 u32 speedLimit; ///< SW_SPEED
65 u32 acceleration; ///< SW_ACCEL
66 u32 targetX; ///< SW_TARGET_X; 0x80000000 when unset
67 u32 targetY; ///< SW_TARGET_Y
68 u32 targetZ; ///< SW_TARGET_Z
69 u32 bounce; ///< SW_BOUNCE, or a floating object's phase
70 u32 gravity; ///< SW_GRAVITY
71 /// Work value 0x17: the word FieldObject_Create zeroes and only scene code
72 /// reads.
74 u32 sprite; ///< work value 0x18: the sprite, or its list of four
75 u8 spriteStorageKind; ///< work value 0x19: 0 hidden, 1 one, 2 a group
76 u8 motionFlags; ///< SW_MOTION, ActorMotionFlag bits
77 u8 arrivalAxis; ///< SW_ARRIVAL
78 u8 conditionResult; ///< SW_RESULT, the last test; every compare sets it
79 u8 snapToTarget; ///< SW_SNAP
80 u8 collisionFlags; ///< SW_COLLISION
81 u8 steeringFlags; ///< SW_STEERING
82 u8 paused; ///< SW_PAUSED
83 u8 byte5c; ///< keeps the sprite's VRAM; no work value
84 u8 repeatCount; ///< SW_REPEAT, SC_LOOP's count
85 u16 wait; ///< SW_WAIT, compared as signed
86 u8 refused; ///< ScriptInterpreter.refused; no work value
87 u8 frozen; ///< ScriptMotionObject.frozen; no work value
88 u8 sceneByte62; ///< work value 0x27, kept by scene code
89 u8 sceneByte63; ///< work value 0x28, kept by scene code
90 s16 actionParameter; ///< work value 0x23, what its action script reads
91 s16 footprintSide; ///< work value 0x24, or scene scratch
92 u32 linkedObject; ///< work value 0x25, the object it follows or faces
93 u32 hook; ///< SW_HOOK, the routine run each frame
94};
95
96STATIC_ASSERT(offsetof(struct ScriptOperands, scriptAddress) == 0x00);
97STATIC_ASSERT(offsetof(struct ScriptOperands, cursor) == 0x04);
98STATIC_ASSERT(offsetof(struct ScriptOperands, facing) == 0x06);
99STATIC_ASSERT(offsetof(struct ScriptOperands, radius) == 0x20);
100STATIC_ASSERT(offsetof(struct ScriptOperands, sceneWord) == 0x4c);
101STATIC_ASSERT(offsetof(struct ScriptOperands, spriteStorageKind) == 0x54);
102STATIC_ASSERT(offsetof(struct ScriptOperands, repeatCount) == 0x5d);
103STATIC_ASSERT(offsetof(struct ScriptOperands, refused) == 0x60);
104STATIC_ASSERT(offsetof(struct ScriptOperands, conditionResult) == 0x57);
105STATIC_ASSERT(offsetof(struct ScriptOperands, wait) == 0x5e);
106STATIC_ASSERT(offsetof(struct ScriptOperands, actionParameter) == 0x64);
107STATIC_ASSERT(offsetof(struct ScriptOperands, linkedObject) == 0x68);
108STATIC_ASSERT(offsetof(struct ScriptOperands, hook) == 0x6c);
109STATIC_ASSERT(sizeof(struct ScriptOperands) == 0x70);
110
111#endif
The edition's language, for C to compare (LANGUAGE == LANGUAGE_GERMAN).
s32(*) ScriptCommand(struct ScriptInterpreter *)
Definition script.h:13
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
The prefix that command handlers read from a field object's 0x70-byte slot.
Definition script.h:16
u8 padding58[5]
the object's own fields; not read by the commands
Definition script.h:25
u8 padding55[2]
the object's own fields; not read by the commands
Definition script.h:23
u8 repeatCount
SC_LOOP's count of jumps so far.
Definition script.h:26
u8 spriteStorageKind
FieldActor's spriteStorageKind: SC_B54_ON sets 1, one sprite drawn, and SC_B54_OFF sets 0,...
Definition script.h:22
s16 cursor
the word index of the next command in script
Definition script.h:18
u8 padding06[0x4e]
the object's own fields; not read by the commands
Definition script.h:19
u8 conditionResult
the last flag test, read by SC_IF and SC_IFNOT
Definition script.h:24
const s32 * script
the running script; SC_END sets gScript_MainScript
Definition script.h:17
s16 wait
Frames left of SC_WAIT (n - 1 when it starts); the update loops count it down, and Script_FindLabel c...
Definition script.h:29
u8 refused
Frames in a row a solid object has refused the object's move (ScriptMotionObject.refused); SC_SYNC st...
Definition script.h:33
The whole 0x70-byte slot as SC_SET, SC_ADD and SC_CMP see it: each field is one work value (enum Scri...
Definition script.h:49
u32 velocityZ
SW_VELOCITY_Z.
Definition script.h:63
s16 actionParameter
work value 0x23, what its action script reads
Definition script.h:90
u32 sceneWord
Work value 0x17: the word FieldObject_Create zeroes and only scene code reads.
Definition script.h:73
u32 sprite
work value 0x18: the sprite, or its list of four
Definition script.h:74
u32 velocityY
SW_VELOCITY_Y.
Definition script.h:62
u32 acceleration
SW_ACCEL.
Definition script.h:65
u8 snapToTarget
SW_SNAP.
Definition script.h:79
u32 gravity
SW_GRAVITY.
Definition script.h:70
u32 scaleX
SW_SCALE_X, 16.16 fixed point.
Definition script.h:57
u8 steeringFlags
SW_STEERING.
Definition script.h:81
u32 terrainHeight
SW_GROUND.
Definition script.h:56
u32 velocityX
SW_VELOCITY_X, 16.16 fixed-point pixels per frame.
Definition script.h:61
u32 linkedObject
work value 0x25, the object it follows or faces
Definition script.h:92
u16 cursor
SW_CURSOR, compared as signed.
Definition script.h:51
u32 scaleY
SW_SCALE_Y, and work value 0x0b.
Definition script.h:58
u8 refused
ScriptInterpreter.refused; no work value.
Definition script.h:86
u8 spriteStorageKind
work value 0x19: 0 hidden, 1 one, 2 a group
Definition script.h:75
u8 byte5c
keeps the sprite's VRAM; no work value
Definition script.h:83
u8 sceneByte63
work value 0x28, kept by scene code
Definition script.h:89
u32 bounce
SW_BOUNCE, or a floating object's phase.
Definition script.h:69
u32 targetY
SW_TARGET_Y.
Definition script.h:67
u32 hook
SW_HOOK, the routine run each frame.
Definition script.h:93
u8 collisionFlags
SW_COLLISION.
Definition script.h:80
u8 paused
SW_PAUSED.
Definition script.h:82
u8 motionFlags
SW_MOTION, ActorMotionFlag bits.
Definition script.h:76
u8 repeatCount
SW_REPEAT, SC_LOOP's count.
Definition script.h:84
u32 z
SW_Z.
Definition script.h:55
u8 arrivalAxis
SW_ARRIVAL.
Definition script.h:77
s16 footprintSide
work value 0x24, or scene scratch
Definition script.h:91
u8 padding22[2]
the layer and priority flags; no work value
Definition script.h:60
u16 wait
SW_WAIT, compared as signed.
Definition script.h:85
u32 speedLimit
SW_SPEED.
Definition script.h:64
u32 y
SW_Y.
Definition script.h:54
u16 facing
SW_FACING, and work values 2 and 4.
Definition script.h:52
u8 frozen
ScriptMotionObject.frozen; no work value.
Definition script.h:87
u32 targetX
SW_TARGET_X; 0x80000000 when unset.
Definition script.h:66
u8 conditionResult
SW_RESULT, the last test; every compare sets it.
Definition script.h:78
u32 targetZ
SW_TARGET_Z.
Definition script.h:68
u32 scriptAddress
SW_SCRIPT; an add steps it by whole words.
Definition script.h:50
u8 sceneByte62
work value 0x27, kept by scene code
Definition script.h:88
u32 x
SW_X, 16.16 fixed-point pixels.
Definition script.h:53
u16 radius
SW_RADIUS, in pixels; compared as signed.
Definition script.h:59
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 short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11