30 deltaX = target->
x -
object->x;
33 pixelsX = deltaX >> 16;
34 deltaZ = target->
z -
object->z;
37 pixelsZ = deltaZ >> 16;
38 distance =
Iwram_Sqrt(pixelsX * pixelsX + pixelsZ * pixelsZ);
39 step =
object->action;
40 if (distance >=
step) {
43 newX =
object->x + (
s32)((
u32)pixelsX << 20) /
step;
44 newZ =
object->z + (
s32)((
u32)pixelsZ << 20) /
step;
64 object->actionFlags &= 0xfe;
65 targetAngle = (
u16)
ArcTan2(target->
z - object->
z, target->
x - object->
x);
66 currentAngle =
object->angle;
67 turnStep = targetAngle - currentAngle;
69 if (turnStep > 0x1000)
71 if (turnStep < -0x1000)
73 object->angle = (currentAngle + turnStep);
100 object->linkedObject =
123 s32 heightDifference;
131 nearestDistance = 40;
133 for (slotIndex = 0; slotIndex < 64; slotIndex++, entry++) {
140 heightDifference = entry->
y - self->
y;
141 if (heightDifference >= 0) {
142 if (heightDifference > 0x2fffff)
145 if (self->
y - entry->
y > 0x2fffff)
148 pixelX = (entry->
x - self->
x) / 0x10000;
149 pixelZ = (entry->
z - self->
z) / 0x10000;
150 distance =
Iwram_Sqrt(pixelX * pixelX + pixelZ * pixelZ);
151 if (distance >= nearestDistance)
156 if (angleDifference < -0x2fff)
158 if (angleDifference > 0x2fff)
162 nearestDistance = distance;
struct FieldActor * Object_GetById(s32 actor)
Returns an actor, or NULL if it does not exist.
struct ObjectRuntime * Object_FindNearestFacingTarget(struct ObjectRuntime *self, s32 sprite)
Finds the nearest animated object to self within 40 pixels and 48 pixels of height,...
s32 Object_ClearChildAndCollisionFlags(void *obj)
Script step: clears an object's sprite flags and its collision flags.
void ObjectMotion_SetActionCallback(struct ObjectRuntime *object, s32 action)
Starts an actor's action script: 1 to 4 the fixed action scripts, 5 follow the linked object,...
s32 ObjectMotion_TurnTowardLinkedTarget(struct ObjectRuntime *object)
Script step of action 6: turns the object toward its linked object, at most 1/16 turn a frame.
s32 ObjectMotion_MoveTowardTarget(struct ObjectRuntime *object)
Script step of action 5: follows the linked object.
void ObjectDispatch_SetSingleChildFlagsFar(struct DispatchObject *obj, u32 flags)
void ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void ObjectDispatch_InitializeFar(struct DispatchObject *obj, const s32 *script)
void Object_SetMoveTargetFar(struct ObjectRuntime *object, s32 x, s32 y, s32 z)
const u8 gObjectMotion_ActionKind4Script[]
const u8 gObjectMotion_ActionKind1Script[]
const u8 gObjectMotion_MoveTowardTargetScript[]
const u8 gObjectMotion_TurnTowardLinkedScript[]
const u8 gObjectMotion_ResetActionScript[]
const u8 gObjectMotion_ActionKind2Script[]
const u8 gObjectMotion_ActionKind3Script[]
struct GameState gGameState
static s32 Iwram_Sqrt(s32 value)
s32 ArcTan2(s32 x, s32 y)
Returns the angle of the vector (x, y), in 1/65536 turns, measured from the y axis: 0 along +y,...
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
A field object as the object dispatcher's far calls take it.
s32 selectedActor
the leader: its unit and its actor
One of the 64 field objects in the object pool (heap slot 5): its script, position,...
s32 z
16.16 fixed-point pixels
s32 * script
the object script it runs; null when the object is free
void * animation
its sprite, or its list of four, by animationKind
s32 x
16.16 fixed-point pixels
s16 step
the script cursor, in words
s32 y
16.16 fixed-point pixels
u8 animationKind
Low four bits: 0 no sprite, 1 one sprite, 2 a group of up to four.
struct ObjectRuntime * linkedObject
The object its action script follows or faces.
s16 action
The parameter its action script reads (a follow distance or an angle), or the player's frames to its ...
A field object as its object script commands see it: the script and its place, position,...
u8 flags59
FieldActor.collisionFlags.
struct ScriptMotionObject * gObjectSlots