Alchemy
Loading...
Searching...
No Matches

object_nearest.h

Go to the documentation of this file.
1#include "types.h"
2#include "field_obj.h"
3#include "field_scene.h"
4
5// Mercury and Venus Lighthouses' aeries.
6
7/// Returns the placed actor drawn with sprite 0xf2 nearest the leader, within
8/// 640 pixels, or 0.
10 struct EventWork *work = gEventWork;
11 struct FieldActor **slot;
12 struct FieldActor *origin;
13 s32 nearestActor = 0;
14 s32 minDist;
15 u32 actorId;
16
17 minDist = 640;
19 actorId = ACTOR_FIRST_PLACED;
20 slot = work->placedActors;
21 do {
22 struct FieldActor *actor = *slot++;
23 if (actor != 0) {
24 if (actor->sprite->entries[0]->animId == 0xf2) {
25 s32 dist = FixedPoint_Distance(
26 (const u8 *)origin + offsetof(struct FieldActor, x),
27 (const u8 *)actor + offsetof(struct FieldActor, x));
28 if (dist < minDist) {
29 minDist = dist;
30 nearestActor = actorId;
31 }
32 }
33 }
34 actorId++;
35 } while (actorId < ACTOR_FIRST_PLACED + sizeof(work->placedActors) /
36 sizeof(work->placedActors[0]));
37 return nearestActor;
38}
struct FieldActor * Object_GetById(s32 actor)
Returns an actor, or NULL if it does not exist.
Field objects and actors, and the scene transition styles.
The scene table formats: entrances, exits, placements and events, and the macros that write them.
@ ACTOR_FIRST_PLACED
@ ACTOR_PARTY_LEADER
struct EventWork * gEventWork
s32 SceneActor_FindNearestSlotOfKindF2(void)
Returns the placed actor drawn with sprite 0xf2 nearest the leader, within 640 pixels,...
#define offsetof(type, member)
Definition stddef.h:19
The running scene's event work: its placement and event tables, its actors, the triggers and exit it ...
Definition event_work.h:20
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
union FieldCoordinate x
16.16 fixed-point pixels
Definition field_obj.h:35
u16 work
The side of the player's next footprint (2 after a stop), or scene scratch.
Definition field_obj.h:112
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
unsigned char u8
Definition types.h:11