11#define TARGET_UNSET ((s32)0x80000000)
12#define TURN_MAX 0x1000
16#define IWRAM_ENTRY(type, offset) ((type)(IwramIrqMain + (offset)))
17#define IwramSqrt IWRAM_ENTRY(s32 (*)(s32 value), Iwram_SqrtOffset)
18#define IwramRatioMulQ14 \
19 IWRAM_ENTRY(s32 (*)(s32 divisor, s32 value), Iwram_RatioMulQ14Offset)
56 slot = nextSlot,
object = nextObject) {
58 nextObject =
object + 1;
63 if (object->script ==
NULL)
65 if (object->paused != 0)
70 if (object->wait != 0) {
74 s32 cursor = (
s16)object->scriptCursor;
76 u32 command =
object->script[cursor];
78 u32 command =
object->script->word[cursor];
86 object->scriptCursor++;
89 if (object->script ==
NULL)
100 if (object->frozen == 0) {
106 deltaX = (
object->targetX -
x) / 65536;
107 deltaZ = (
object->targetZ -
z) / 65536;
108 distance =
IwramSqrt(deltaX * deltaX + deltaZ * deltaZ) << 16;
109 if (distance <= 0xffffff) {
110 deltaX =
object->targetX -
x;
111 deltaZ =
object->targetZ -
z;
129 if (distance > object->speedLimit) {
141 deltaX =
object->velocityX;
142 deltaZ =
object->velocityZ;
147 if (distance - object->acceleration < 0) {
148 object->velocityX = 0;
149 object->velocityZ = 0;
152 distance, distance - object->acceleration);
153 object->velocityX =
MulQ16(deltaX, speedRatio);
154 object->velocityZ =
MulQ16(deltaZ, speedRatio);
157 object->velocityX = 0;
158 object->velocityZ = 0;
163 if (object->motionFlags & 2) {
164 groundY =
object->terrainHeight;
166 object->velocityY -=
object->gravity;
170 -
MulQ16(object->velocityY, object->vertical.bounce);
171 if ((object->velocityY < 0 ? -object->velocityY
172 : object->velocityY) <= object->gravity)
173 object->velocityY = 0;
179 x +=
object->velocityX;
180 y +=
object->velocityY;
181 z +=
object->velocityZ;
185 switch (object->arrivalAxis) {
187 if (
x == object->targetX ||
188 ((object->x - object->targetX) ^ (
x - object->targetX)) < 0)
192 if (
y == object->targetY ||
193 ((object->y - object->targetY) ^ (
y - object->targetY)) < 0)
197 if (
z == object->targetZ ||
198 ((object->z - object->targetZ) ^ (
z - object->targetZ)) < 0)
205 if (object->snapToTarget) {
207 object->velocityX = 0;
209 object->velocityZ = 0;
210 if (object->motionFlags == 0) {
212 object->velocityY = 0;
218 object->arrivalAxis = 0;
223 if (object->steeringFlags & 1) {
224 x =
object->velocityX;
225 z =
object->velocityZ;
226 if (
x != 0 ||
z != 0) {
228 turnDelta = (
s16)(travelAngle - object->facing);
233 object->facing += turnDelta;
#define TARGET_UNSET
A movement target coordinate that is not set.
The hardware's interrupt sources and the interrupt handler table.
The IWRAM call layer: the routines the game keeps resident in IWRAM, each at its fixed address,...
Small statement macros both games use for positions, velocities and bounds.
#define SET_POSITION(p, px, py, pz)
Sets the position or the velocity of a particle, a piece of debris or an object in one statement.
MulQ16, the 16.16 fixed-point multiply.
static __inline__ s32 MulQ16(s32 left, s32 right)
Multiplies 16.16 fixed-point values, returning the middle 32 product bits.
const ScriptCommand gScriptObject_CommandTable[47]
The handler for each script command number; 0x24 onwards act as SC_END.
ScriptMotionObject, an object moved by a field script.
The prefix that command handlers read from a field object's 0x70-byte slot.
A field object as the motion code sees it: its script, position, motion toward a target,...
s32 x
16.16 fixed-point pixels
s32 velocityY
16.16 fixed-point pixels per frame
void(*) hook(union FieldObject *object)
Called each frame before its script.
s32 velocityX
16.16 fixed-point pixels per frame
const ScriptMotionWords * script
null when the object is free
s32 y
16.16 fixed-point pixels
s32 z
16.16 fixed-point pixels
s32 velocityZ
16.16 fixed-point pixels per frame
The integer types, TRUE, UNUSED and the fixed-address macros.
An object on the field, read as an actor or as an effect.
s32 ArcTan2FarArm(s32 z, s32 x)
struct ScriptMotionObject * gObjectSlots
s32 IwramSqrtFarArm(s32 value)
void Object_UpdateAll(void)
Advances the eight script-driven objects by one frame.
s32 IwramRatioMulQ14FarArm(s32 divisor, s32 value)
#define TURN_MAX
the most an object turns in one frame
#define OBJECT_SLOTS
script-driven objects updated each frame