Alchemy
Loading...
Searching...
No Matches

object_facing.h

Go to the documentation of this file.
1#include "script.h"
2#include "types.h"
3#include "facing_object.h"
4
5// Altin Peak, Bilibin, Imil, Kolima, McCoy's palace and garden, Sol Sanctum's
6// Elemental Star room, and Vale's Kraden, Babi, home and interiors scenes.
7
8/// An object script call: an actor with a facing target turns towards it, at
9/// most a sixteenth of a turn a frame.
10static s32 Scene_TurnTowardTarget(struct ScriptInterpreter *interpreter) {
11 struct FacingObject *obj = (struct FacingObject *)interpreter;
12 s32 delta;
13 u16 old;
14 s32 angle;
15 struct FacingObject *target;
16
17 target = obj->facingTarget;
18 if (target != 0) {
19 obj->facingFlags = (0xFE & obj->facingFlags);
20 angle = (u16)ArcTan2(target->positionZ - obj->positionZ,
21 target->positionX - obj->positionX);
22 old = obj->facing;
23 delta = (s16)(angle - old);
24 if (delta != 0) {
25 if (delta > 0x1000) {
26 delta = 0x1000;
27 }
28
29 if (delta < -0x1000) {
30 delta = -0x1000;
31 }
32 obj->facing = (old + delta);
33 }
34 }
35 return 1;
36}
FacingObject, the view of an object that turns to face a target.
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,...
Definition math.c:36
static s32 Scene_TurnTowardTarget(struct ScriptInterpreter *interpreter)
An object script call: an actor with a facing target turns towards it, at most a sixteenth of a turn ...
The field object script interpreter and the operands its commands read.
A field object seen as one that turns toward its facing target: its facing, its ground position and t...
u16 facing
1/65536 turns
s32 positionZ
16.16 fixed-point pixels
s32 positionX
16.16 fixed-point pixels
u8 facingFlags
The steering flags (SW_STEERING); bit 0, turning toward its velocity, is cleared while it turns towar...
struct FacingObject * facingTarget
The linked object (work value 0x25), or null.
The prefix that command handlers read from a field object's 0x70-byte slot.
Definition script.h:16
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13