Alchemy
Loading...
Searching...
No Matches

object_script.c

Go to the documentation of this file.
1/// @file
2/// Field object scripts: the ones the engine starts itself, and the command
3/// table.
4
6#include "unit/field/field.h"
7#include "object_dispatch.h"
8#include "field.h"
9#include "objcmd.h"
10#include "types.h"
11
12/// The script FieldObject_Create gives every new object: it does nothing and
13/// returns to the idle script.
15 SC_END,
16};
17
18/// Runs SC_KEY_COUNT every frame; started by ObjectDispatch_StartKeyCheck.
19/// This and the scripts below each repeat one command every frame.
22 SC_WAIT(1),
24};
25
26/// Started by ObjectDispatch_StartMoveByKeys.
28 SC_KEYS,
29 SC_WAIT(1),
31};
32
33/// Started by ObjectDispatch_StartPlayerControl.
36 SC_WAIT(1),
38};
39
40/// Started by ObjectDispatch_StartWorldMapControl.
43 SC_WAIT(1),
45};
46
47/// Started by ObjectDispatch_StartCamera.
50 SC_WAIT(1),
52};
53
54/// Started by ObjectDispatch_StartApproachLink.
57 SC_WAIT(1),
59};
60
61/// The idle script ObjectDispatch_StartIdle gives an object.
63 SC_END,
64};
65
66/// The handler for each script command number; 0x24 onwards act as SC_END.
67/// Object_UpdateAll (update.c) and Object_UpdateAllThumb (object_motion.c)
68/// call through it.
70 Script_Wait, // 0x00 SC_WAIT
71 Script_WaitForArrival, // 0x01 SC_SYNC
73 Script_ApplyAbsolutePosition, // 0x03 SC_MOVE
74 Script_ApplyRelativePosition, // 0x04 SC_MOVE_BY
75 Script_StoreAngleToLinkedObject, // 0x05 SC_FACE_LINK
76 Script_ApplyLinkedObjectPosition, // 0x06 SC_MOVE_LINK
77 Script_ApplyLocalOffsetPosition, // 0x07 SC_MOVE_LOCAL
78 Object_Wander, // 0x08 SC_WANDER
79 ScriptObject_WanderNearHome, // 0x09 SC_WANDER_HOME
80 Object_ApproachLinkedObject, // 0x0a SC_APPROACH_LINK
81 Camera_FollowLeaderInBounds, // 0x0b SC_CAMERA
82 Script_RepeatOrJump, // 0x0c SC_LOOP
83 Script_JumpToLabel, // 0x0d SC_JUMP
84 Script_JumpIfTrue, // 0x0e SC_IF
85 Script_JumpIfFalse, // 0x0f SC_IFNOT
86 Script_End, // 0x10 SC_END
87 Script_TestFlag, // 0x11 SC_FLAG_CHECK
88 Script_SetFlagAndTest, // 0x12 SC_FLAG_ON
89 Script_ClearFlagAndTest, // 0x13 SC_FLAG_OFF
90 Script_ToggleFlagAndTest, // 0x14 SC_FLAG_REV
91 Script_ApplyOperandSet, // 0x15 SC_SET
92 Script_ApplyOperandAdd, // 0x16 SC_ADD
93 Script_ApplyOperandCompare, // 0x17 SC_CMP
94 FieldObject_UpdatePlayerControl, // 0x18 SC_PLAYER
95 Object_MoveByKeys, // 0x19 SC_KEYS
96 Object_MoveOnWorldMap, // 0x1a SC_WORLD
97 Script_FreeObject, // 0x1b SC_FREE
98 Script_SetAnimation, // 0x1c SC_ARG
99 Script_Nop, // 0x1d SC_NOP
100 Script_PlaySound, // 0x1e SC_SE
101 Script_SetBase, // 0x1f SC_BASE
102 Script_ClearByte54, // 0x20 SC_B54_OFF
103 Script_SetByte54, // 0x21 SC_B54_ON
104 Script_InvokeCallback, // 0x22 SC_CALL
105 Field_CheckConfiguredKeysAndCount, // 0x23 SC_KEY_COUNT
106 Script_End, // 0x24
107 Script_End, // 0x25
108 Script_End, // 0x26
109 Script_End, // 0x27
110 Script_End, // 0x28
111 Script_End, // 0x29
112 Script_End, // 0x2a
113 Script_End, // 0x2b
114 Script_End, // 0x2c
115 Script_End, // 0x2d
116 Script_End, // 0x2e
117};
Field object scripts: one s32 command word, then its operands, as gScriptObject_CommandTable runs the...
#define SC_PLAYER
Player input control.
Definition objcmd.h:40
#define SC_WORLD
World map control.
Definition objcmd.h:42
#define SC_LOOP(n, to)
Repeat up to n times.
Definition objcmd.h:28
#define SC_FOREVER
Definition objcmd.h:14
#define SC_KEY_COUNT
Definition objcmd.h:51
#define SC_APPROACH_LINK
Definition objcmd.h:26
#define SC_WAIT(n)
Wait n frames.
Definition objcmd.h:16
#define SC_CAMERA
Follow the leader.
Definition objcmd.h:27
#define SC_TOP
Script start.
Definition objcmd.h:13
#define SC_END
Return to the main script.
Definition objcmd.h:32
#define SC_KEYS
Definition objcmd.h:41
The object dispatcher's scripts: key checks, the player, the world map and the camera.
s32 Script_SetBase(struct ScriptInterpreter *interpreter)
SC_BASE: restarts the script at the next word, and returns 1 to run on.
s32 Script_ClearByte54(struct ScriptInterpreter *interpreter)
SC_B54_OFF: clears spriteStorageKind, hiding the sprites, and moves on to the next command.
s32 Script_SetByte54(struct ScriptInterpreter *interpreter)
SC_B54_ON: sets spriteStorageKind to 1, one sprite drawn, and moves on to the next command.
const s32 gObjectDispatch_EndScript[]
The idle script ObjectDispatch_StartIdle gives an object.
const s32 gObjectDispatch_KeysScript[]
Started by ObjectDispatch_StartMoveByKeys.
const s32 gObjectDispatch_ApproachLinkScript[]
Started by ObjectDispatch_StartApproachLink.
const s32 gObjectDispatch_CameraScript[]
Started by ObjectDispatch_StartCamera.
const s32 gObjectDispatch_PlayerScript[]
Started by ObjectDispatch_StartPlayerControl.
const s32 gObjectDispatch_KeyCheckScript[]
Runs SC_KEY_COUNT every frame; started by ObjectDispatch_StartKeyCheck.
const s32 gObjectDispatch_DefaultScript[]
The script FieldObject_Create gives every new object: it does nothing and returns to the idle script.
const ScriptCommand gScriptObject_CommandTable[47]
The handler for each script command number; 0x24 onwards act as SC_END.
const s32 gObjectDispatch_WorldMapScript[]
Started by ObjectDispatch_StartWorldMapControl.
s32 Object_MoveByKeys(struct ScriptInterpreter *interpreter)
SC_KEYS: moves an object 8 pixels at a time by the direction pad, with up and down changing its heigh...
s32 Field_CheckConfiguredKeysAndCount(struct ScriptInterpreter *interpreter)
SC_KEY_COUNT: checks the configured keys (Field_CheckConfiguredKeys).
s32 Object_MoveOnWorldMap(struct ScriptInterpreter *interpreter)
SC_WORLD: moves the player on the world map by the direction pad, as SC_PLAYER does on the field,...
s32 FieldObject_UpdatePlayerControl(struct ScriptInterpreter *interpreter)
SC_PLAYER: moves the player on the field by the direction pad: walking or running,...
s32(*) ScriptCommand(struct ScriptInterpreter *)
Definition script.h:13
s32 Object_ApproachLinkedObject(struct ScriptInterpreter *interpreter)
SC_APPROACH_LINK: follows the linked object at its speed.
s32 Script_RepeatOrJump(struct ScriptInterpreter *interpreter)
SC_LOOP(n, to): jumps to label to until it has done so n - 1 times, then moves on; with n = SC_FOREVE...
s32 Script_ApplyRelativePosition(struct ScriptInterpreter *interpreter)
SC_MOVE_BY(x, y, z): sends the object towards its position plus (x, y, z).
s32 Script_StoreAngleToLinkedObject(struct ScriptInterpreter *interpreter)
SC_FACE_LINK: stores the angle from the object to its linked object in scriptValue,...
s32 Script_SetFlagAndTest(struct ScriptInterpreter *interpreter)
SC_FLAG_ON(f) and SC_FLAG_OFF(f): test game flag f, then set or clear it.
s32 Script_JumpToLabel(struct ScriptInterpreter *interpreter)
SC_JUMP(to): jumps to label to.
s32 Script_Wait(struct ScriptInterpreter *interpreter)
SC_WAIT(n): waits n frames; this frame counts as the first.
s32 Script_ClearFlagAndTest(struct ScriptInterpreter *interpreter)
s32 Script_PlaySound(struct ScriptInterpreter *interpreter)
SC_SE(n): sends sound command n (a sound effect).
s32 Camera_FollowLeaderInBounds(struct ScriptInterpreter *interpreter)
SC_CAMERA: keeps the camera object on its leader (linkedObject), clamped so the view stays on the map...
s32 Script_ApplyOperandSet(struct ScriptInterpreter *interpreter)
SC_SET(w, v): sets work value w to v.
s32 Script_JumpIfTrue(struct ScriptInterpreter *interpreter)
SC_IF(to): jumps to label to when the last test was true.
s32 Script_ApplyOperandAdd(struct ScriptInterpreter *interpreter)
SC_ADD(w, v): adds v to work value w.
s32 Script_ToggleFlagAndTest(struct ScriptInterpreter *interpreter)
SC_FLAG_REV(f): tests game flag f, then flips it.
s32 Script_InvokeCallback(struct ScriptInterpreter *interpreter)
SC_CALL(fn): calls fn with the object.
s32 Script_ApplyLocalOffsetPosition(struct ScriptInterpreter *interpreter)
SC_MOVE_LOCAL(a, b): sends the object towards its position plus an offset that is never filled in; th...
s32 Script_Nop(struct ScriptInterpreter *interpreter)
SC_NOP(v): does nothing with its operand.
s32 Script_FreeObject(struct ScriptInterpreter *interpreter)
SC_FREE: releases the object through ObjectDispatch_Release, which releases its sprites and zeroes it...
s32 Script_End(struct ScriptInterpreter *interpreter)
SC_END: hands the object back to the idle script, gScript_MainScript, whose lone SC_END runs again ea...
s32 Script_ApplyAbsolutePosition(struct ScriptInterpreter *interpreter)
SC_MOVE(x, y, z): sends the object towards (x, y, z).
s32 ScriptObject_WanderNearHome(struct ScriptInterpreter *interpreter)
SC_WANDER_HOME(base, range, limit): wanders as SC_WANDER does, testing more ground around the point,...
s32 Script_WaitForArrival(struct ScriptInterpreter *interpreter)
SC_SYNC: waits until the object arrives at its target, or until a solid object has blocked it for 60 ...
s32 Object_Wander(struct ScriptInterpreter *interpreter)
SC_WANDER(base, range, limit): walks to a random point base to base + range away, within 90 degrees e...
s32 Script_TestFlag(struct ScriptInterpreter *interpreter)
SC_FLAG_CHECK(f): tests game flag f.
s32 Script_ApplyOperandCompare(struct ScriptInterpreter *interpreter)
SC_CMP(w, v): tests whether work value w equals v.
s32 Script_SetPositionAndResetMotion(struct ScriptInterpreter *interpreter)
SC_POS(x, y, z): places the object at (x, y, z) and stops it.
s32 Script_SetAnimation(struct ScriptInterpreter *interpreter)
SC_ARG(v): switches the object's sprites to animation v.
s32 Script_ApplyLinkedObjectPosition(struct ScriptInterpreter *interpreter)
SC_MOVE_LINK: sends the object towards its linked object.
s32 Script_JumpIfFalse(struct ScriptInterpreter *interpreter)
SC_IFNOT(to): jumps to label to when the last test was false.
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14