Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
UnkFunc62.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "npc.h"
3
4API_CALLABLE(N(UnkFunc62)) {
5 Bytecode* args = script->ptrReadPos;
6 Actor* actor = get_actor(script->owner1.enemyID);
7 ActorState* state = &actor->state;
15 f64 velocity;
21 f32 temp;
23 f32 phi_f0;
24 f64 phi_f2;
28
29 if (isInitialCall) {
30 actor->state.moveTime = evt_get_variable(script, *args++);
32 script->functionTemp[1] = 0;
33 script->functionTemp[0] = 0;
34 if (actor->state.moveArcAmplitude == 1) {
35 script->functionTemp[0] = 2;
36 }
37 }
38
39 if (script->functionTemp[0] == 0) {
40 state->curPos.x = actor->curPos.x;
41 state->curPos.y = actor->curPos.y;
42 stateGoalX = state->goalPos.x;
43 stateGoalZ = state->goalPos.z;
44 stateCurrentX = state->curPos.x;
45 stateCurrentZ = actor->curPos.z;
46 state->curPos.z = stateCurrentZ;
49 if (state->moveTime == 0) {
50 state->moveTime = state->dist / state->speed;
51 temp = state->dist - (state->moveTime * state->speed);
52 } else {
53 state->speed = state->dist / state->moveTime;
54 temp = state->dist - (state->moveTime * state->speed);
55 }
56
57 if (state->moveTime == 0) {
58 return ApiStatus_DONE2;
59 }
60
61 state->velStep.x = (state->goalPos.x - state->curPos.x) / state->moveTime;
62 state->velStep.y = (state->goalPos.y - state->curPos.y) / state->moveTime;
63 state->velStep.z = (state->goalPos.z - state->curPos.z) / state->moveTime;
64 state->acceleration = PI_S / state->moveTime;
65 state->vel = 0.0f;
66 state->speed += temp / state->moveTime;
67
68 if (state->moveArcAmplitude < 3) {
69 state->unk_24 = 90.0f;
70 state->unk_28 = 360 / state->moveTime;
71 temp = state->dist;
72 temp -= 20.0;
73 temp /= 6.0;
74 temp += 47.0;
75 state->bounceDivisor = temp;
76 if (state->moveArcAmplitude == 2) {
77 state->bounceDivisor *= 1.12;
78 }
79 state->unk_18.x = 0.0f;
80 state->unk_18.y = 0.0f;
81 phi_f20 = state->vel;
82 temp_f22_2 = state->acceleration;
84 phi_f2 = 0.53;
85 state->vel = phi_f20 + ((phi_f0 * phi_f2 * temp_f22_2) + temp_f22_2);
86 } else {
87 state->unk_24 = 90.0f;
88 state->unk_28 = 360 / state->moveTime;
89 temp = state->dist;
90 temp -= 20.0;
91 temp /= 6.0;
92 temp += 47.0;
93 state->bounceDivisor = temp;
94 if (state->moveArcAmplitude == 4) {
95 state->bounceDivisor *= 1.25;
96 }
97 state->unk_18.x = 0.0f;
98 state->unk_18.y = 0.0f;
99 velocity = state->vel;
100 temp_f22_3 = state->acceleration;
101 phi_f0 = sin_rad(DEG_TO_RAD(state->unk_24));
102 phi_f2 = 0.8;
103 state->vel = velocity + ((phi_f0 * phi_f2 * temp_f22_3) + temp_f22_3);
104 }
107 script->functionTemp[0] = 1;
108 }
109
110 switch (script->functionTemp[0]) {
111 case 1:
112 if (state->vel > PI_S / 2) {
114 }
115 oldActorX = actor->curPos.x;
116 oldActorY = actor->curPos.y;
117 state->curPos.x += state->velStep.x;
118 state->curPos.y = state->curPos.y + state->velStep.y;
119 state->curPos.z = state->curPos.z + state->velStep.z;
120 state->unk_18.x = actor->curPos.y;
121 actor->curPos.x = state->curPos.x;
122 actor->curPos.y = state->curPos.y + (state->bounceDivisor * sin_rad(state->vel));
123 actor->curPos.z = state->curPos.z;
124 if (state->goalPos.y > actor->curPos.y && state->moveTime < 3) {
125 actor->curPos.y = state->goalPos.y;
126 }
127
128 actor->rot.z = -atan2(oldActorX, -oldActorY, actor->curPos.x, -actor->curPos.y);
129 state->unk_18.y = actor->curPos.y;
130 if (state->moveArcAmplitude < 3) {
131 phi_f20_2 = state->vel;
132 temp_f22_5 = state->acceleration;
134 phi_f2_2 = 0.53;
135 state->vel = phi_f20_2 + ((phi_f0_2 * phi_f2_2 * temp_f22_5) + temp_f22_5);
136 } else {
137 temp_f20_6 = state->vel;
138 temp_f22_6 = state->acceleration;
140 phi_f2_2 = 0.8;
142 }
143
144 state->unk_24 += state->unk_28;
145 state->unk_24 = clamp_angle(state->unk_24);
146 state->moveTime--;
147 if (state->moveTime == 0) {
148 actor->curPos.y = state->goalPos.y;
149 state->acceleration = 1.8f;
150 state->vel = -(state->unk_18.x - state->unk_18.y);
152 return ApiStatus_DONE1;
153 }
154 break;
155 case 2:
156 state->moveTime = 1;
157 state->acceleration = 1.8f;
158 state->unk_24 = 90.0f;
159 state->vel = -(state->unk_18.x - state->unk_18.y);
160 state->bounceDivisor = fabsf(state->unk_18.x - state->unk_18.y) / 16.5;
161 state->unk_28 = 360 / state->moveTime;
162 state->curPos.x = actor->curPos.x;
163 state->curPos.y = actor->curPos.y;
164 state->curPos.z = actor->curPos.z;
165 script->functionTemp[0] = 3;
166 // fallthrough
167 case 3:
168 currentPosX64 = state->curPos.x; // required to match
169 state->curPos.x = currentPosX64 + state->bounceDivisor * sin_rad(DEG_TO_RAD(state->unk_24)) / 33.0;
170 state->curPos.y -= state->bounceDivisor * sin_rad(DEG_TO_RAD(state->unk_24));
171 state->unk_24 += state->unk_28;
172 state->unk_24 = clamp_angle(state->unk_24);
173 actor->curPos.x = state->curPos.x;
174 actor->curPos.y = state->curPos.y;
175 actor->curPos.z = state->curPos.z;
176
177 state->moveTime--;
178 if (state->moveTime == 0) {
179 return ApiStatus_DONE1;
180 }
181 break;
182 }
183
184 return ApiStatus_BLOCK;
185}
BSS s32 PopupMenu_SelectedIndex
ActorState state
Vec3f curPos
#define clamp_angle
#define atan2
@ SOUND_QUICK_PLAYER_JUMP
Definition enums.h:1427
@ ACTOR_SELF
Definition enums.h:2117
#define ApiStatus_DONE2
Definition evt.h:119
s32 Bytecode
Definition evt.h:7
#define ApiStatus_DONE1
Definition evt.h:118
#define ApiStatus_BLOCK
Definition evt.h:117
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1730
f32 fabsf(f32 f)
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
void set_actor_anim(s32 actorID, s32 partID, AnimID animID)
Definition 190B20.c:737
Actor * get_actor(s32 actorID)
Definition actor_api.c:155
f32 sin_rad(f32 x)
Definition 43F0.c:713
void sfx_play_sound(s32 soundID)
#define DEG_TO_RAD(deg)
Definition macros.h:145
#define PI_S
Definition macros.h:140