src/field/field_script_commands.c
Actor script commands: waits, jumps, flags, moves and state values. More…
Included by field.c.
Macros
| Name | Description | |
|---|---|---|
#define | SCRIPT_LABEL_KEY_MASK 0xbfffffff | SC_LABEL and SC_TO differ only in bit 30; a jump searches for the label. |
#define | SCRIPT_DEFINE_FLAG_COMMAND (name, change) | Defines a flag command: stores the flag's current value in conditionResult, then changes the flag with change. |
#define | SCRIPT_DEFINE_OPERAND_WORD (name, field) | Defines the handler for a 32-bit state value: set it, add to it, or compare it (into conditionResult). |
#define | SCRIPT_DEFINE_OPERAND_ADDRESS (name, field) | The same for an address: an add steps by value words (value * 4 bytes). |
#define | SCRIPT_DEFINE_OPERAND_NARROW (name, field, type) | The same for an 8- or 16-bit value: a compare narrows value to its type. |
Enumerations
| Name | Description | |
|---|---|---|
enum | anonymous enum { SCRIPT_LABEL_SEARCH_WORDS, SCRIPT_BLOCKED_MOVE_TICKS, SCRIPT … } | The script commands' limits, distances and turns. |
enum | SCRIPT_OPERAND_OPERATION { SCRIPT_OPERAND_SET, SCRIPT_OPERAND_ADD, SCRIPT_OPERAND_COMPA … } | What a state value handler does with its value, for SC_SET, SC_ADD and SC_CMP in turn. |
Functions
| Name | Description | |
|---|---|---|
Sint32 | fdActorScriptWait (ACTOR *actor) | SC_WAIT(n): waits n ticks; this tick counts as the first. |
Bool | fdActorScriptWaitForArrival (ACTOR *actor) | SC_SYNC: waits until the actor arrives at its target, or until a solid actor has blocked it for 60 ticks (refused is the blocked count, which fdActorUpdateAllOnField raises). |
Bool | fdActorScriptInvokeCallback (ACTOR *actor) | SC_CALL(fn): calls fn with the actor. |
Sint32 | fdActorScriptFindLabel (ACTOR *actor, Uint32 labelKey) | Returns the cursor just past the script's label key (SC_LABEL or SC_TO, matched without the bit that tells them apart), searching its first 1024 words, or 0 (the start) when key is 0 or not found, so a missing label restarts the script. |
Sint32 | fdActorScriptRepeatOrJump (ACTOR *actor) | SC_LOOP(n, to): jumps to label to until it has done so n - 1 times, then moves on; with n = SC_FOREVER it always jumps. |
Sint32 | fdActorScriptJumpToLabel (ACTOR *actor) | SC_JUMP(to): jumps to label to. |
Sint32 | fdActorScriptJumpIfTrue (ACTOR *actor) | SC_IF(to): jumps to label to when the last test was true. |
Sint32 | fdActorScriptJumpIfFalse (ACTOR *actor) | SC_IFNOT(to): jumps to label to when the last test was false. |
Sint32 | fdActorScriptEnd (ACTOR *actor) | SC_END: hands the actor back to the idle script, ActorScriptEndScript, whose lone SC_END runs again each tick. |
Sint32 | fdActorScriptTestFlag (ACTOR *actor) | SC_FLAG_CHECK(f): tests game flag f. |
Sint32 | fdActorScriptToggleFlagAndTest (ACTOR *actor) | SC_FLAG_REV(f): tests game flag f, then flips it. |
Sint32 | fdActorScriptSetAnimation (ACTOR *actor) | SC_ANIMATION(v): switches the actor's sprites to animation v. |
Sint32 | fdActorScriptRelease (ACTOR *actor) | SC_RELEASE: releases the actor through fdActorRelease, which releases its sprites and zeroes its slot. |
Sint32 | fdActorScriptNoOperation (ACTOR *actor) | SC_NOP(v): does nothing with its operand. |
Sint32 | fdActorScriptPlaySound (ACTOR *actor) | SC_SE(n): sends sound command n. |
Sint32 | fdActorScriptCheckOverlap (ACTOR *actor, Sint32 *pos) | Returns -1 when the actor, moved to pos (x, y, z), would overlap a solid actor (ACTOR_SOLID), each radius less 2 pixels; otherwise 0. |
ACTOR * | fdActorScriptFindOverlappingActor (ACTOR *actor, Sint32 *pos) | Returns the first solid actor that the actor, moved to pos, would overlap, as fdActorScriptCheckOverlap tests, or NULL. |
static __inline__ Sint32 | fdActorScriptApplyPosCommand ( ACTOR *actor, void (*applyPos)(ACTOR *actor, Sint32 x, Sint32 y, Sint32 z)) | SC_POSITION's and SC_MOVE's shared body: calls applyPos with the command's (x, y, z) and steps past them. |
Sint32 | fdActorScriptSetPosAndResetMotion (ACTOR *actor) | SC_POSITION(x, y, z): places the actor at (x, y, z) and stops it. |
Sint32 | fdActorScriptMove (ACTOR *actor) | SC_MOVE(x, y, z): sends the actor towards (x, y, z). |
Sint32 | fdActorScriptMoveBy (ACTOR *actor) | SC_MOVE_BY(x, y, z): sends the actor towards its position plus (x, y, z). |
Sint32 | fdActorScriptFaceWatched (ACTOR *actor) | SC_FACE_WATCHED: turns the actor to face its watched actor across the ground. |
Sint32 | fdActorScriptMoveToWatched (ACTOR *actor) | SC_MOVE_TO_WATCHED: sends the actor towards its watched actor. |
Sint32 | fdActorScriptMoveLocal (ACTOR *actor) | SC_MOVE_LOCAL(a, b): sends the actor towards its position plus an offset that is never filled in; the operands are skipped unread. |
Sint32 | fdCameraFollowLeaderInBounds (ACTOR *cameraActor) | SC_CAMERA: keeps the camera actor on its leader (watchedActor), clamped so the view stays on the map. |
Bool | fdActorApproachWatchedActor (ACTOR *actor) | SC_APPROACH_WATCHED: follows the watched actor at its speed. |
Bool | fdActorWander (ACTOR *actor) | SC_WANDER(base, range, limit): walks to a random point base to base + range away, within 90 degrees either side of the way it faces, that no solid actor or wall blocks, with clear ground 8 pixels further at 45 degrees either side, and within limit pixels of home. |
Sint32 | fdActorScriptWanderNearHome (ACTOR *actor) | SC_WANDER_HOME(base, range, limit): wanders as SC_WANDER does, testing more ground around the point, while it is within limit pixels of home; outside that, or when no point works, it heads back towards home. |
void | fdActorScriptSetOrCompareCursor (SCRIPT_OPERANDS *operands, Sint32 operation, Sint32 value) | SW_CURSOR: its add and compare take the cursor as a signed halfword. |
void | fdActorScriptSetOrCompareRadius (SCRIPT_OPERANDS *operands, Sint32 operation, Sint32 value) | SW_RADIUS: its compare takes value as a signed halfword. |
static __inline__ Sint32 | fdActorScriptApplyOperandCommand (SCRIPT_OPERANDS *operands, Sint32 operation) | Reads the two words after the command (a state value number and a value) and passes operation to that value's handler. |
Sint32 | fdActorScriptApplyOperandSet (ACTOR *actor) | SC_SET(w, v): sets state value w to v. |
Sint32 | fdActorScriptApplyOperandAdd (ACTOR *actor) | SC_ADD(w, v): adds v to state value w. |
Sint32 | fdActorScriptApplyOperandCompare (ACTOR *actor) | SC_CMP(w, v): tests whether state value w equals v. |
Description
Actor script commands: waits, jumps, flags, moves and state values.
Each SC_ handler here is reached through ActorScriptCommandTable
(actor_script.c), which fdActorUpdateAll and fdActorUpdateAllOnField call for
each live actor; each returns 1 to run on and 0 to end the actor's tick (the
protocol is in this folder's README).
Macros in detail
SCRIPT_LABEL_KEY_MASK
#define SCRIPT_LABEL_KEY_MASK 0xbfffffff
SC_LABEL and SC_TO differ only in bit 30; a jump searches for the label.
Referenced by fdActorScriptFindLabel().
Definition at line 43 of file field_script_commands.c.
SCRIPT_DEFINE_FLAG_COMMAND
#define SCRIPT_DEFINE_FLAG_COMMAND(name, change)
Defines a flag command: stores the flag's current value in conditionResult, then changes the flag with change.
Definition at line 211 of file field_script_commands.c.
SCRIPT_DEFINE_OPERAND_WORD
#define SCRIPT_DEFINE_OPERAND_WORD(name, field)
Defines the handler for a 32-bit state value: set it, add to it, or compare it (into conditionResult).
Definition at line 825 of file field_script_commands.c.
SCRIPT_DEFINE_OPERAND_ADDRESS
#define SCRIPT_DEFINE_OPERAND_ADDRESS(name, field)
The same for an address: an add steps by value words (value * 4 bytes).
Definition at line 842 of file field_script_commands.c.
SCRIPT_DEFINE_OPERAND_NARROW
#define SCRIPT_DEFINE_OPERAND_NARROW(name, field, type)
The same for an 8- or 16-bit value: a compare narrows value to its type.
Definition at line 859 of file field_script_commands.c.
Enumerations in detail
anonymous enum
enum { SCRIPT_LABEL_SEARCH_WORDS, SCRIPT_BLOCKED_MOVE_TICKS, SCRIPT_WANDER_TRIES, SCRIPT_WANDER_PROBE_DISTANCE, … }
The script commands' limits, distances and turns.
| Enumerator | Value | Description |
|---|---|---|
SCRIPT_LABEL_SEARCH_WORDS | 1024 | Script words a jump searches. |
SCRIPT_BLOCKED_MOVE_TICKS | 60 | Refused ticks SC_SYNC waits through. |
SCRIPT_WANDER_TRIES | 7 | Random points a wander tries a tick. |
SCRIPT_WANDER_PROBE_DISTANCE | toFIXED(8) | The wander probes' distance, 8 pixels in 16.16: past the point for ground, and along the heading for solid actors (SC_WANDER_HOME). |
SCRIPT_WANDER_DIAGONAL_ANGLE | DEGtoANG(45) | One eighth of a turn. |
SCRIPT_WANDER_SIDE_ANGLE | DEGtoANG(90) | One quarter of a turn. |
SCRIPT_HALF_TURN | DEGtoANG(180) | |
SCRIPT_APPROACH_DISTANCE | 16 | Whole pixels SC_APPROACH_WATCHED stays short of its watched actor. |
CAMERA_FOLLOW_FINE_DISTANCE | toFIXED(64) | Under 64 pixels (16.16) SC_CAMERA measures its distance in 16.16. |
CAMERA_FOLLOW_SNAP_DISTANCE | toFIXED(1) / 4 | Within a quarter pixel (16.16) SC_CAMERA lands on its point. |
CAMERA_FOLLOW_HEIGHT_SNAP | toFIXED(1) / 2 | Within half a pixel (16.16) SC_CAMERA takes the leader's height at once. |
Definition at line 11 of file field_script_commands.c.
SCRIPT_OPERAND_OPERATION
enum SCRIPT_OPERAND_OPERATION
What a state value handler does with its value, for SC_SET, SC_ADD and SC_CMP
in turn.
| Enumerator | Value | Description |
|---|---|---|
SCRIPT_OPERAND_SET | ||
SCRIPT_OPERAND_ADD | ||
SCRIPT_OPERAND_COMPARE | sets conditionResult to 1 when equal, else 0 |
Definition at line 816 of file field_script_commands.c.
Functions in detail
fdActorScriptWait
Sint32 fdActorScriptWait(ACTOR *actor)
SC_WAIT(n): waits n ticks; this tick counts as the first.
References Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 46 of file field_script_commands.c.
fdActorScriptWaitForArrival
Bool fdActorScriptWaitForArrival(ACTOR *actor)
SC_SYNC: waits until the actor arrives at its target, or until a solid actor
has blocked it for 60 ticks (refused is the blocked count, which
fdActorUpdateAllOnField raises).
References fdActorIsTargetUnset().
Referenced by ActorScriptCommandTable.
Definition at line 58 of file field_script_commands.c.
fdActorScriptInvokeCallback
Bool fdActorScriptInvokeCallback(ACTOR *actor)
SC_CALL(fn): calls fn with the actor.
Referenced by ActorScriptCommandTable.
Definition at line 75 of file field_script_commands.c.
fdActorScriptFindLabel
Sint32 fdActorScriptFindLabel(ACTOR *actor, Uint32 labelKey)
Returns the cursor just past the script's label key (SC_LABEL or SC_TO,
matched without the bit that tells them apart), searching its first 1024
words, or 0 (the start) when key is 0 or not found, so a missing label
restarts the script. Clears the wait.
References Sint32.
Referenced by fdActorScriptJumpIfFalse(), fdActorScriptJumpIfTrue(), fdActorScriptJumpToLabel() and fdActorScriptRepeatOrJump().
Definition at line 91 of file field_script_commands.c.
fdActorScriptRepeatOrJump
Sint32 fdActorScriptRepeatOrJump(ACTOR *actor)
SC_LOOP(n, to): jumps to label to until it has done so n - 1 times, then
moves on; with n = SC_FOREVER it always jumps.
References fdActorScriptFindLabel() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 116 of file field_script_commands.c.
fdActorScriptJumpToLabel
Sint32 fdActorScriptJumpToLabel(ACTOR *actor)
SC_JUMP(to): jumps to label to.
References fdActorScriptFindLabel() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 148 of file field_script_commands.c.
fdActorScriptJumpIfTrue
Sint32 fdActorScriptJumpIfTrue(ACTOR *actor)
SC_IF(to): jumps to label to when the last test was true.
References fdActorScriptFindLabel() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 156 of file field_script_commands.c.
fdActorScriptJumpIfFalse
Sint32 fdActorScriptJumpIfFalse(ACTOR *actor)
SC_IFNOT(to): jumps to label to when the last test was false.
References fdActorScriptFindLabel() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 174 of file field_script_commands.c.
fdActorScriptEnd
Sint32 fdActorScriptEnd(ACTOR *actor)
SC_END: hands the actor back to the idle script, ActorScriptEndScript, whose
lone SC_END runs again each tick. Returns 0.
References ActorScriptEndScript and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 193 of file field_script_commands.c.
fdActorScriptTestFlag
Sint32 fdActorScriptTestFlag(ACTOR *actor)
SC_FLAG_CHECK(f): tests game flag f.
References gmFlagGetStub() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 201 of file field_script_commands.c.
fdActorScriptToggleFlagAndTest
Sint32 fdActorScriptToggleFlagAndTest(ACTOR *actor)
SC_FLAG_REV(f): tests game flag f, then flips it.
References gmFlagClearStub(), gmFlagGetStub(), gmFlagSetStub() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 228 of file field_script_commands.c.
fdActorScriptSetAnimation
Sint32 fdActorScriptSetAnimation(ACTOR *actor)
SC_ANIMATION(v): switches the actor's sprites to animation v.
References fdActorSelectAnimation() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 249 of file field_script_commands.c.
fdActorScriptRelease
Sint32 fdActorScriptRelease(ACTOR *actor)
SC_RELEASE: releases the actor through fdActorRelease, which releases its
sprites and zeroes its slot.
References fdActorRelease() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 258 of file field_script_commands.c.
fdActorScriptNoOperation
Sint32 fdActorScriptNoOperation(ACTOR *actor)
SC_NOP(v): does nothing with its operand.
References Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 265 of file field_script_commands.c.
fdActorScriptPlaySound
Sint32 fdActorScriptPlaySound(ACTOR *actor)
SC_SE(n): sends sound command n.
References Sint32 and sySoundPlayStub().
Referenced by ActorScriptCommandTable.
Definition at line 272 of file field_script_commands.c.
fdActorScriptCheckOverlap
Sint32 fdActorScriptCheckOverlap(ACTOR *actor, Sint32 *pos)
Returns -1 when the actor, moved to pos (x, y, z), would overlap a solid
actor (ACTOR_SOLID), each radius less 2 pixels; otherwise 0.
References fdCheckSpheresOverlap() and Sint32.
Referenced by fdActorScriptWanderNearHome(), fdActorUpdateAllOnField(), fdActorUpdatePlayerControl() and fdActorWander().
Definition at line 281 of file field_script_commands.c.
fdActorScriptFindOverlappingActor
ACTOR *fdActorScriptFindOverlappingActor(ACTOR *actor, Sint32 *pos)
Returns the first solid actor that the actor, moved to pos, would overlap, as
fdActorScriptCheckOverlap tests, or NULL.
References fdCheckSpheresOverlap() and Sint32.
Definition at line 304 of file field_script_commands.c.
fdActorScriptApplyPosCommand
static __inline__ Sint32 fdActorScriptApplyPosCommand( ACTOR *actor, void (*applyPos)(ACTOR *actor, Sint32 x, Sint32 y, Sint32 z))
SC_POSITION's and SC_MOVE's shared body: calls applyPos with the command's
(x, y, z) and steps past them.
References Sint32.
Referenced by fdActorScriptMove() and fdActorScriptSetPosAndResetMotion().
Definition at line 327 of file field_script_commands.c.
fdActorScriptSetPosAndResetMotion
Sint32 fdActorScriptSetPosAndResetMotion(ACTOR *actor)
SC_POSITION(x, y, z): places the actor at (x, y, z) and stops it.
References fdActorScriptApplyPosCommand(), fdActorSetPosAndResetMotion() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 348 of file field_script_commands.c.
fdActorScriptMove
Sint32 fdActorScriptMove(ACTOR *actor)
SC_MOVE(x, y, z): sends the actor towards (x, y, z).
References fdActorScriptApplyPosCommand(), fdActorSetMoveTarget() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 354 of file field_script_commands.c.
fdActorScriptMoveBy
Sint32 fdActorScriptMoveBy(ACTOR *actor)
SC_MOVE_BY(x, y, z): sends the actor towards its position plus (x, y, z).
References fdActorSetMoveTarget() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 360 of file field_script_commands.c.
fdActorScriptFaceWatched
Sint32 fdActorScriptFaceWatched(ACTOR *actor)
SC_FACE_WATCHED: turns the actor to face its watched actor across the ground.
References Sint32 and syAtan().
Referenced by ActorScriptCommandTable.
Definition at line 377 of file field_script_commands.c.
fdActorScriptMoveToWatched
Sint32 fdActorScriptMoveToWatched(ACTOR *actor)
SC_MOVE_TO_WATCHED: sends the actor towards its watched actor.
References fdActorSetMoveTarget() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 389 of file field_script_commands.c.
fdActorScriptMoveLocal
Sint32 fdActorScriptMoveLocal(ACTOR *actor)
SC_MOVE_LOCAL(a, b): sends the actor towards its position plus an offset that
is never filled in; the operands are skipped unread.
References fdActorSetMoveTarget() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 402 of file field_script_commands.c.
fdCameraFollowLeaderInBounds
Sint32 fdCameraFollowLeaderInBounds(ACTOR *cameraActor)
SC_CAMERA: keeps the camera actor on its leader (watchedActor), clamped so
the view stays on the map.
References Sint32, syDivFX(), syMulFX(), sySquartFX() and sySquartIWRAM().
Referenced by ActorScriptCommandTable.
Definition at line 421 of file field_script_commands.c.
fdActorApproachWatchedActor
Bool fdActorApproachWatchedActor(ACTOR *actor)
SC_APPROACH_WATCHED: follows the watched actor at its speed.
References fdActorSelectAnimation(), fdActorSetMoveTarget(), Sint32 and sySquartIWRAM().
Referenced by ActorScriptCommandTable.
Definition at line 529 of file field_script_commands.c.
fdActorWander
Bool fdActorWander(ACTOR *actor)
SC_WANDER(base, range, limit): walks to a random point base to base + range
away, within 90 degrees either side of the way it faces, that no solid actor
or wall blocks, with clear ground 8 pixels further at 45 degrees either side,
and within limit pixels of home.
References fdActorScriptCheckOverlap(), fdActorSetMoveTarget(), fdMapGridCheckCollision(), Sint32, syMulFX(), syRandom() and syVectorAddPolarOffset().
Referenced by ActorScriptCommandTable.
Definition at line 575 of file field_script_commands.c.
fdActorScriptWanderNearHome
Sint32 fdActorScriptWanderNearHome(ACTOR *actor)
SC_WANDER_HOME(base, range, limit): wanders as SC_WANDER does, testing more
ground around the point, while it is within limit pixels of home; outside
that, or when no point works, it heads back towards home.
References fdActorScriptCheckOverlap(), fdActorSetMoveTarget(), fdMapGridCheckCollision(), Sint32, syAtan(), syMulFX(), syRandom() and syVectorAddPolarOffset().
Referenced by ActorScriptCommandTable.
Definition at line 671 of file field_script_commands.c.
fdActorScriptSetOrCompareCursor
void fdActorScriptSetOrCompareCursor(SCRIPT_OPERANDS *operands, Sint32 operation, Sint32 value)
SW_CURSOR: its add and compare take the cursor as a signed halfword.
References Sint32.
Referenced by ActorScriptOperandHandlerTable.
Definition at line 884 of file field_script_commands.c.
fdActorScriptSetOrCompareRadius
void fdActorScriptSetOrCompareRadius(SCRIPT_OPERANDS *operands, Sint32 operation, Sint32 value)
SW_RADIUS: its compare takes value as a signed halfword.
References Sint32.
Referenced by ActorScriptOperandHandlerTable.
Definition at line 910 of file field_script_commands.c.
fdActorScriptApplyOperandCommand
static __inline__ Sint32 fdActorScriptApplyOperandCommand(SCRIPT_OPERANDS *operands, Sint32 operation)
Reads the two words after the command (a state value number and a value) and passes operation to that value's handler.
References ActorScriptOperandHandlerTable and Sint32.
Referenced by fdActorScriptApplyOperandAdd(), fdActorScriptApplyOperandCompare() and fdActorScriptApplyOperandSet().
Definition at line 984 of file field_script_commands.c.
fdActorScriptApplyOperandSet
Sint32 fdActorScriptApplyOperandSet(ACTOR *actor)
SC_SET(w, v): sets state value w to v.
References fdActorScriptApplyOperandCommand() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 999 of file field_script_commands.c.
fdActorScriptApplyOperandAdd
Sint32 fdActorScriptApplyOperandAdd(ACTOR *actor)
SC_ADD(w, v): adds v to state value w.
References fdActorScriptApplyOperandCommand() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 1007 of file field_script_commands.c.
fdActorScriptApplyOperandCompare
Sint32 fdActorScriptApplyOperandCompare(ACTOR *actor)
SC_CMP(w, v): tests whether state value w equals v.
References fdActorScriptApplyOperandCommand() and Sint32.
Referenced by ActorScriptCommandTable.
Definition at line 1015 of file field_script_commands.c.