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;
8 f32 stateCurrentX;
9 f32 stateCurrentZ;
10 f32 stateGoalX;
11 f32 stateGoalZ;
12 f32 oldActorY;
13 f32 oldActorX;
14 f64 currentPosX64;
15 f32 temp_f8_2;
16 f64 velocity;
17 f64 temp_f20_6;
18 f64 temp_f22_2;
19 f64 temp_f22_3;
20 f64 temp_f22_5;
21 f64 temp_f22_6;
22 f32 temp;
23 f64 phi_f20;
24 f32 phi_f0;
25 f64 phi_f2;
26 f64 phi_f20_2;
27 f32 phi_f0_2;
28 f64 phi_f2_2;
29
30 if (isInitialCall) {
31 actor->state.moveTime = evt_get_variable(script, *args++);
32 actor->state.moveArcAmplitude = evt_get_variable(script, *args++);
33 script->functionTemp[1] = 0;
34 script->functionTemp[0] = 0;
35 if (actor->state.moveArcAmplitude == 1) {
36 script->functionTemp[0] = 2;
37 }
38 }
39
40 if (script->functionTemp[0] == 0) {
41 state->curPos.x = actor->curPos.x;
42 state->curPos.y = actor->curPos.y;
43 stateGoalX = state->goalPos.x;
44 stateGoalZ = state->goalPos.z;
45 stateCurrentX = state->curPos.x;
46 stateCurrentZ = actor->curPos.z;
47 state->curPos.z = stateCurrentZ;
48 state->angle = atan2(stateCurrentX, stateCurrentZ, stateGoalX, stateGoalZ);
49 state->dist = dist2D(stateCurrentX, stateCurrentZ, stateGoalX, stateGoalZ);
50 if (state->moveTime == 0) {
51 state->moveTime = state->dist / state->speed;
52 temp = state->dist - (state->moveTime * state->speed);
53 } else {
54 state->speed = state->dist / state->moveTime;
55 temp = state->dist - (state->moveTime * state->speed);
56 }
57
58 if (state->moveTime == 0) {
59 return ApiStatus_DONE2;
60 }
61
62 state->velStep.x = (state->goalPos.x - state->curPos.x) / state->moveTime;
63 state->velStep.y = (state->goalPos.y - state->curPos.y) / state->moveTime;
64 state->velStep.z = (state->goalPos.z - state->curPos.z) / state->moveTime;
65 state->acceleration = PI_S / state->moveTime;
66 state->vel = 0.0f;
67 state->speed += temp / state->moveTime;
68
69 if (state->moveArcAmplitude < 3) {
70 state->unk_24 = 90.0f;
71 state->unk_28 = 360 / state->moveTime;
72 temp = state->dist;
73 temp -= 20.0;
74 temp /= 6.0;
75 temp += 47.0;
76 state->bounceDivisor = temp;
77 if (state->moveArcAmplitude == 2) {
78 state->bounceDivisor *= 1.12;
79 }
80 state->unk_18.x = 0.0f;
81 state->unk_18.y = 0.0f;
82 phi_f20 = state->vel;
83 temp_f22_2 = state->acceleration;
84 phi_f0 = sin_rad(DEG_TO_RAD(state->unk_24));
85 phi_f2 = 0.53;
86 state->vel = phi_f20 + ((phi_f0 * phi_f2 * temp_f22_2) + temp_f22_2);
87 } else {
88 state->unk_24 = 90.0f;
89 state->unk_28 = 360 / state->moveTime;
90 temp = state->dist;
91 temp -= 20.0;
92 temp /= 6.0;
93 temp += 47.0;
94 state->bounceDivisor = temp;
95 if (state->moveArcAmplitude == 4) {
96 state->bounceDivisor *= 1.25;
97 }
98 state->unk_18.x = 0.0f;
99 state->unk_18.y = 0.0f;
100 velocity = state->vel;
101 temp_f22_3 = state->acceleration;
102 phi_f0 = sin_rad(DEG_TO_RAD(state->unk_24));
103 phi_f2 = 0.8;
104 state->vel = velocity + ((phi_f0 * phi_f2 * temp_f22_3) + temp_f22_3);
105 }
108 script->functionTemp[0] = 1;
109 }
110
111 switch (script->functionTemp[0]) {
112 case 1:
113 if (state->vel > PI_S / 2) {
115 }
116 oldActorX = actor->curPos.x;
117 oldActorY = actor->curPos.y;
118 state->curPos.x += state->velStep.x;
119 state->curPos.y = state->curPos.y + state->velStep.y;
120 state->curPos.z = state->curPos.z + state->velStep.z;
121 state->unk_18.x = actor->curPos.y;
122 actor->curPos.x = state->curPos.x;
123 actor->curPos.y = state->curPos.y + (state->bounceDivisor * sin_rad(state->vel));
124 actor->curPos.z = state->curPos.z;
125 if (state->goalPos.y > actor->curPos.y && state->moveTime < 3) {
126 actor->curPos.y = state->goalPos.y;
127 }
128
129 actor->rot.z = -atan2(oldActorX, -oldActorY, actor->curPos.x, -actor->curPos.y);
130 state->unk_18.y = actor->curPos.y;
131 if (state->moveArcAmplitude < 3) {
132 phi_f20_2 = state->vel;
133 temp_f22_5 = state->acceleration;
134 phi_f0_2 = sin_rad(DEG_TO_RAD(state->unk_24));
135 phi_f2_2 = 0.53;
136 state->vel = phi_f20_2 + ((phi_f0_2 * phi_f2_2 * temp_f22_5) + temp_f22_5);
137 } else {
138 temp_f20_6 = state->vel;
139 temp_f22_6 = state->acceleration;
140 phi_f0_2 = sin_rad(DEG_TO_RAD(state->unk_24));
141 phi_f2_2 = 0.8;
142 state->vel = temp_f20_6 + ((phi_f0_2 * phi_f2_2 * temp_f22_6) + temp_f22_6);
143 }
144
145 state->unk_24 += state->unk_28;
146 state->unk_24 = clamp_angle(state->unk_24);
147 state->moveTime--;
148 if (state->moveTime == 0) {
149 actor->curPos.y = state->goalPos.y;
150 state->acceleration = 1.8f;
151 state->vel = -(state->unk_18.x - state->unk_18.y);
153 return ApiStatus_DONE1;
154 }
155 break;
156 case 2:
157 state->moveTime = 1;
158 state->acceleration = 1.8f;
159 state->unk_24 = 90.0f;
160 state->vel = -(state->unk_18.x - state->unk_18.y);
161 state->bounceDivisor = fabsf(state->unk_18.x - state->unk_18.y) / 16.5;
162 state->unk_28 = 360 / state->moveTime;
163 state->curPos.x = actor->curPos.x;
164 state->curPos.y = actor->curPos.y;
165 state->curPos.z = actor->curPos.z;
166 script->functionTemp[0] = 3;
167 // fallthrough
168 case 3:
169 currentPosX64 = state->curPos.x; // required to match
170 state->curPos.x = currentPosX64 + state->bounceDivisor * sin_rad(DEG_TO_RAD(state->unk_24)) / 33.0;
171 state->curPos.y -= state->bounceDivisor * sin_rad(DEG_TO_RAD(state->unk_24));
172 state->unk_24 += state->unk_28;
173 state->unk_24 = clamp_angle(state->unk_24);
174 actor->curPos.x = state->curPos.x;
175 actor->curPos.y = state->curPos.y;
176 actor->curPos.z = state->curPos.z;
177
178 state->moveTime--;
179 if (state->moveTime == 0) {
180 return ApiStatus_DONE1;
181 }
182 break;
183 }
184
185 return ApiStatus_BLOCK;
186}
ActorState state
Vec3f curPos
#define clamp_angle
#define atan2
@ SOUND_QUICK_PLAYER_JUMP
Definition enums.h:1424
@ ACTOR_SELF
Definition enums.h:2084
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
#define ApiStatus_DONE1
Definition evt.h:117
#define ApiStatus_BLOCK
Definition evt.h:116
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
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:1005
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)
Definition sfx.c:517
#define DEG_TO_RAD(deg)
Definition macros.h:134
#define PI_S
Definition macros.h:129