Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
MonitorPlayerOrbiting.inc.c
Go to the documentation of this file.
2
3API_CALLABLE(N(MonitorPlayerOrbiting)) {
4 PlayerStatus* playerStatus = &gPlayerStatus;
5 PlayerOrbitTarget* target = (PlayerOrbitTarget*) evt_get_variable(script, *script->ptrReadPos);
6 PlayerOrbitState* orbit;
7 s32 prevAngle, curAngle;
8 s32 deltaAngle;
9 s32 dist;
10
11 if (isInitialCall) {
12 orbit = script->functionTempPtr[1] = heap_malloc(sizeof(*orbit));
13 orbit->pos.x = target->pos.x;
14 orbit->pos.y = target->pos.y;
15 orbit->pos.z = target->pos.z;
16 orbit->startRadius = target->startRadius;
17 orbit->orbitRadius = target->orbitRadius;
18 orbit->eventListener = target->eventListener;
19 orbit->totalOrbitAngle = 0;
20 orbit->numRotations = 0;
21 orbit->state = 0;
22 orbit->firstPlayerX = 0;
23 orbit->firstPlayerZ = 0;
24 orbit->lastPlayerX = 0;
25 orbit->lastPlayerZ = 0;
26 orbit->direction = 0;
27 orbit->lastNumRotations = 0;
28 }
29
30 orbit = script->functionTempPtr[1];
31 switch (orbit->state) {
33 // wait for player to come within range
34 dist = get_xz_dist_to_player(orbit->pos.x, orbit->pos.z);
35 if (dist < orbit->startRadius) {
36 orbit->firstPlayerX = playerStatus->pos.x;
37 orbit->firstPlayerZ = playerStatus->pos.z;
38 orbit->state++;
39 }
40 break;
41
43 // determine direction the player is orbiting
44 dist = get_xz_dist_to_player(orbit->pos.x, orbit->pos.z);
45 if (dist < orbit->startRadius) {
46 prevAngle = atan2(orbit->pos.x, orbit->pos.z, orbit->firstPlayerX, orbit->firstPlayerZ);
47 curAngle = atan2(orbit->pos.x, orbit->pos.z, playerStatus->pos.x, playerStatus->pos.z);
48 deltaAngle = get_clamped_angle_diff(prevAngle, curAngle);
49 orbit->direction = signF(deltaAngle);
50 orbit->state++;
51 break;
52 }
54 break;
55
57 dist = get_xz_dist_to_player(orbit->pos.x, orbit->pos.z);
58 if (dist < orbit->startRadius) {
59 prevAngle = atan2(orbit->pos.x, orbit->pos.z, orbit->lastPlayerX, orbit->lastPlayerZ);
60 curAngle = atan2(orbit->pos.x, orbit->pos.z, playerStatus->pos.x, playerStatus->pos.z);
61 deltaAngle = get_clamped_angle_diff(prevAngle, curAngle);
62 if (orbit->direction == signF(deltaAngle)) {
63 prevAngle = atan2(orbit->pos.x, orbit->pos.z, orbit->firstPlayerX, orbit->firstPlayerZ);
64 curAngle = atan2(orbit->pos.x, orbit->pos.z, playerStatus->pos.x, playerStatus->pos.z);
65 deltaAngle = get_clamped_angle_diff(prevAngle, curAngle);
66 if (fabsf(deltaAngle) > 90.0f) {
67 if (orbit->eventListener != NULL) {
68 orbit->eventListener(orbit, PLAYER_ORBIT_BEGIN);
69 }
70 orbit->totalOrbitAngle += fabsf(deltaAngle);
71 orbit->state++;
72 }
73 break;
74 }
75 }
77 break;
78
80 dist = get_xz_dist_to_player(orbit->pos.x, orbit->pos.z);
81 if (dist < orbit->orbitRadius) {
82 prevAngle = atan2(orbit->pos.x, orbit->pos.z, orbit->lastPlayerX, orbit->lastPlayerZ);
83 curAngle = atan2(orbit->pos.x, orbit->pos.z, playerStatus->pos.x, playerStatus->pos.z);
84 deltaAngle = get_clamped_angle_diff(prevAngle, curAngle);
85 if (orbit->direction != signF(deltaAngle)) {
86 if (orbit->eventListener != NULL) {
88 }
89 orbit->state++;
90 } else {
91 orbit->totalOrbitAngle = orbit->totalOrbitAngle + fabsf(deltaAngle);
92 orbit->numRotations = orbit->totalOrbitAngle / 360;
93 if (orbit->numRotations != orbit->lastNumRotations) {
94 if (orbit->eventListener != NULL) {
96 }
97 orbit->lastNumRotations = orbit->numRotations;
98 }
99 }
100 if (orbit->eventListener != NULL) {
102 }
103 } else {
104 if (orbit->eventListener != NULL) {
106 }
107 orbit->state++;
108 }
109 break;
110
112 orbit->totalOrbitAngle = 0.0f;
113 orbit->numRotations = 0;
114 orbit->lastNumRotations = 0;
116 break;
117 }
118
119 orbit->lastPlayerX = playerStatus->pos.x;
120 orbit->lastPlayerZ = playerStatus->pos.z;
121
122 return ApiStatus_BLOCK;
123}
@ PLAYER_ORBIT_COMPLETE_ROTATION
@ PLAYER_ORBIT_CHANGE_DIRECTION
@ PLAYER_ORBIT_BEGIN
@ PLAYER_ORBIT_LEFT_REGION
@ PLAYER_ORBIT_CONTINUE_ORBIT
@ ORBIT_STATE_STARTING_ORBIT
@ ORBIT_STATE_FIRST_FRAME
@ ORBIT_STATE_SECOND_FRAME
@ ORBIT_STATE_MAINTAIN_ORBIT
@ ORBIT_STATE_BREAK_ORBIT
#define atan2
#define ApiStatus_BLOCK
Definition evt.h:116
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
f32 fabsf(f32 f)
f32 signF(f32 val)
Definition 43F0.c:557
f32 get_xz_dist_to_player(f32, f32)
Definition 77480.c:960
f32 get_clamped_angle_diff(f32, f32)
Definition 43F0.c:606
void * heap_malloc(s32 size)
Definition heap.c:34
void(* eventListener)(struct PlayerOrbitState *, s32)
void(* eventListener)(PlayerOrbitState *, s32)
PlayerStatus gPlayerStatus
Definition 77480.c:39