Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
WaterEffects.inc.c
Go to the documentation of this file.
1#include "common.h"
2
3enum {
8};
9
10API_CALLABLE(N(UpdateAnimatedFish)) {
11 Bytecode* args = script->ptrReadPos;
12 f32 vt0 = 0.0f;
13 f32 vt1 = 0.0f;
14 f32 vt2 = 0.0f;
15 f32 vt3;
16 f32 vt4;
17 f32 vt5;
18 f32 vt6;
19 f32 vt7;
20
21 f64 temp_f20;
22 f64 temp_f20_2;
23 f64 temp_f20_3;
24 f64 temp_f20_4;
25 s32 state;
26
27 script->functionTemp[0] = state = evt_get_variable(script, *args++);
28
29 switch (state) {
30 case FISH_STATE_INIT:
31 vt0 = 142.0f;
32 vt1 = 0.0f;
33 vt2 = -118.0f;
34 script->varTable[3] = 142;
35 script->varTable[4] = 0;
36 script->varTable[5] = -118;
37 script->varTable[6] = 44;
38 script->varTable[7] = -118;
39 script->varTable[8] = 3;
40 script->varTable[9] = 0;
41 script->varTable[11] = 0;
42 script->functionTemp[0] = FISH_STATE_1;
43 break;
44 case FISH_STATE_3:
45 vt0 = 91.0f;
46 vt1 = 0.0f;
47 vt2 = -118.0f;
48 script->varTable[3] = 91;
49 script->varTable[4] = 0;
50 script->varTable[5] = -118;
51 script->varTable[6] = 91;
52 script->varTable[7] = -118;
53 script->varTable[8] = 3;
54 script->varTable[9] = 0;
55 script->varTable[11] = 0;
56 script->functionTemp[0] = FISH_STATE_1;
57 break;
58 case FISH_STATE_1:
59 script->varTable[9] += script->varTable[8];
60 if (script->varTable[9] > 45) {
61 script->varTable[9] = 45;
62 }
63 vt0 = script->varTable[3];
64 vt1 = script->varTable[4];
65 vt2 = script->varTable[5];
66 vt3 = script->varTable[6];
67 vt4 = script->varTable[7];
68 temp_f20 = vt0 * (1.0 - sin_rad(DEG_TO_RAD(script->varTable[9])));
69 vt0 = (temp_f20 + (vt3 * sin_rad(DEG_TO_RAD(script->varTable[9]))));
70 vt1 = vt1 + sin_rad(DEG_TO_RAD(script->varTable[9] * 2)) * 90.0f;
71 temp_f20_2 = vt2 * (1.0 - sin_rad(DEG_TO_RAD(script->varTable[9])));
72 vt2 = temp_f20_2 + (vt4 * sin_rad(DEG_TO_RAD(script->varTable[9])));
73 if (script->varTable[9] == 45) {
74 script->varTable[11] = 1;
75 }
76 break;
77 case FISH_STATE_2:
78 script->varTable[9] += script->varTable[8];
79 if (script->varTable[9] > 90) {
80 script->varTable[9] = 90;
81 }
82 vt0 = script->varTable[3];
83 vt1 = script->varTable[4];
84 vt2 = script->varTable[5];
85 vt3 = script->varTable[6];
86 vt4 = script->varTable[7];
87 temp_f20_3 = vt0 * (1.0 - sin_rad(DEG_TO_RAD(script->varTable[9])));
88 vt0 = (temp_f20_3 + (vt3 * sin_rad(DEG_TO_RAD(script->varTable[9]))));
89 vt1 = vt1 + sin_rad(DEG_TO_RAD(script->varTable[9] * 2)) * 90.0f;
90 temp_f20_4 = vt2 * (1.0 - sin_rad(DEG_TO_RAD(script->varTable[9])));
91 vt2 = temp_f20_4 + (vt4 * sin_rad(DEG_TO_RAD(script->varTable[9])));
92 if (script->varTable[9] == 90) {
93 script->varTable[11] = 2;
94 }
95 break;
96 }
97 script->varTable[0] = vt0;
98 script->varTable[1] = vt1;
99 script->varTable[2] = vt2;
100 return ApiStatus_DONE2;
101}
102
103EvtScript N(EVS_AnimateFishModel) = {
104 Set(LVarA, LVar0)
105 Label(0)
106 Call(N(UpdateAnimatedFish), FISH_STATE_INIT)
108 Call(RotateModel, LVarA, -20, 0, 0, 1)
109 Wait(1)
110 Loop(0)
111 Call(N(UpdateAnimatedFish), FISH_STATE_1)
113 Call(RotateModel, LVarA, -20, 0, 0, 1)
114 Wait(1)
115 IfEq(LVarB, 1)
117 EndIf
118 EndLoop
120 Call(RotateModel, LVarA, -7, 0, 0, 1)
121 Wait(5)
123 Call(RotateModel, LVarA, -27, 0, 0, 1)
124 Wait(2)
126 Call(RotateModel, LVarA, -5, 0, 0, 1)
127 Wait(3)
129 Call(RotateModel, LVarA, -20, 0, 0, 1)
130 Wait(5)
131 Loop(0)
132 Call(N(UpdateAnimatedFish), FISH_STATE_2)
134 Call(RotateModel, LVarA, -20, 0, 0, 1)
135 Wait(1)
136 IfEq(LVarB, 2)
138 EndIf
139 EndLoop
140 Call(RandInt, 80, LVarB)
141 Add(LVarB, 30)
142 Loop(LVarB)
144 Call(RotateModel, LVarA, -20, 0, 0, 1)
145 Wait(1)
146 EndLoop
147 Call(RandInt, 5, LVar0)
148 IfNe(LVar0, 0)
149 Goto(0)
150 EndIf
151 Call(N(UpdateAnimatedFish), FISH_STATE_3)
153 Call(RotateModel, LVarA, -20, 0, 0, 1)
154 Wait(1)
155 Loop(0)
156 Call(N(UpdateAnimatedFish), FISH_STATE_1)
158 Call(RotateModel, LVarA, -20, 0, 0, 1)
159 Wait(1)
160 IfEq(LVarB, 1)
162 EndIf
163 EndLoop
165 Call(RotateModel, LVarA, -7, 0, 0, 1)
166 Wait(5)
168 Call(RotateModel, LVarA, -27, 0, 0, 1)
169 Wait(2)
171 Call(RotateModel, LVarA, -5, 0, 0, 1)
172 Wait(3)
174 Call(RotateModel, LVarA, -20, 0, 0, 1)
175 Wait(5)
176 Loop(0)
177 Call(N(UpdateAnimatedFish), FISH_STATE_2)
179 Call(RotateModel, LVarA, -20, 0, 0, 1)
180 Wait(1)
181 IfEq(LVarB, 2)
183 EndIf
184 EndLoop
185 Call(RandInt, 80, LVarB)
186 Add(LVarB, 30)
187 Loop(LVarB)
189 Call(RotateModel, LVarA, -20, 0, 0, 1)
190 Wait(1)
191 EndLoop
192 Goto(0)
193 Return
194 End
195};
196
197EvtScript N(EVS_AnimateWaveModel) = {
198 Set(LVarA, LVar0)
199 Loop(0)
200 Call(TranslateModel, LVarA, 1, 0, 0)
201 Wait(2)
202 Call(TranslateModel, LVarA, 1, 0, 0)
203 Wait(2)
204 Call(TranslateModel, LVarA, 1, -1, 0)
205 Wait(2)
206 Call(TranslateModel, LVarA, 2, -1, 0)
207 Wait(2)
208 Call(TranslateModel, LVarA, 2, -1, 0)
209 Wait(2)
210 Call(TranslateModel, LVarA, 2, -1, 0)
211 Wait(2)
212 Call(TranslateModel, LVarA, 3, -2, 0)
213 Wait(2)
214 Call(TranslateModel, LVarA, 3, -2, 0)
215 Wait(2)
216 Call(TranslateModel, LVarA, 3, -3, 0)
217 Wait(2)
218 Call(TranslateModel, LVarA, 3, -3, 0)
219 Wait(2)
220 Call(TranslateModel, LVarA, 3, -3, 0)
221 Wait(2)
222 Call(TranslateModel, LVarA, 3, -2, 0)
223 Wait(2)
224 Call(TranslateModel, LVarA, 2, -2, 0)
225 Wait(2)
226 Call(TranslateModel, LVarA, 2, -1, 0)
227 Wait(2)
228 Call(TranslateModel, LVarA, 1, 0, 0)
229 Wait(2)
230 Call(TranslateModel, LVarA, 1, 1, 0)
231 Wait(2)
232 Call(TranslateModel, LVarA, 0, 1, 0)
233 Wait(2)
234 Call(TranslateModel, LVarA, -1, 1, 0)
235 Wait(2)
236 Call(TranslateModel, LVarA, -1, 1, 0)
237 Wait(2)
238 Call(TranslateModel, LVarA, -1, 0, 0)
239 Wait(2)
240 Call(TranslateModel, LVarA, -1, 0, 0)
241 Wait(2)
242 Call(TranslateModel, LVarA, 0, 0, 0)
243 Wait(2)
244 EndLoop
245 Return
246 End
247};
248
249s32 N(DriftBobbingOffsets)[] = {
250 0, -1, -1, -2, -2, -3, -5, -8,
251 -8, -7, -6, -4, -2, -1, 0, 255,
252};
253
254EvtScript N(EVS_AnimateDrifting) = {
255 Set(LVarA, LVar0) // modelID
256 Set(LVarB, LVar1)
257 Set(LVar5, 5)
258 UseBuf(Ref(N(DriftBobbingOffsets)))
259 Label(0)
260 // drift along from left to right
262 IfEq(LVar1, 255)
263 UseBuf(Ref(N(DriftBobbingOffsets)))
265 EndIf
266 Set(LVar0, LVar5)
268 Wait(1)
269 Add(LVar5, 1)
270 Set(LVarC, LVarB)
271 Sub(LVarC, 20)
273 Goto(1)
274 EndIf
275 Set(LVar0, LVar5)
277 Wait(1)
278 Add(LVar5, 1)
279 Set(LVarC, LVarB)
280 Sub(LVarC, 20)
282 Goto(1)
283 EndIf
284 Goto(0)
285 Label(1)
286 // fall down
287 Set(LVar2, 0)
288 Loop(20)
289 Add(LVar5, 1)
290 Sub(LVar1, 2)
291 Set(LVar0, LVar5)
293 Wait(1)
294 EndLoop
295 // reset to left side of stage
296 Sub(LVar5, 280)
297 Set(LVar1, 0)
298 Goto(0)
299 Return
300 End
301};
302
303EvtScript N(EVS_AnimateFlotsam) = {
304 Set(LVarA, LVar0)
305 Loop(0)
306 Call(TranslateModel, LVarA, 0, 0, 0)
307 Wait(2)
308 Call(TranslateModel, LVarA, 0, 0, 0)
309 Wait(2)
310 Call(TranslateModel, LVarA, 0, -1, 0)
311 Wait(2)
312 Call(TranslateModel, LVarA, 0, -1, 0)
313 Wait(2)
314 Call(TranslateModel, LVarA, 0, -1, 0)
315 Wait(2)
316 Call(TranslateModel, LVarA, 0, -1, 0)
317 Wait(2)
318 Call(TranslateModel, LVarA, 0, -2, 0)
319 Wait(2)
320 Call(TranslateModel, LVarA, 0, -2, 0)
321 Wait(2)
322 Call(TranslateModel, LVarA, 0, -3, 0)
323 Wait(2)
324 Call(TranslateModel, LVarA, 0, -3, 0)
325 Wait(2)
326 Call(TranslateModel, LVarA, 0, -3, 0)
327 Wait(2)
328 Call(TranslateModel, LVarA, 0, -2, 0)
329 Wait(2)
330 Call(TranslateModel, LVarA, 0, -2, 0)
331 Wait(2)
332 Call(TranslateModel, LVarA, 0, -1, 0)
333 Wait(2)
334 Call(TranslateModel, LVarA, 0, 0, 0)
335 Wait(2)
336 Call(TranslateModel, LVarA, 0, 1, 0)
337 Wait(2)
338 Call(TranslateModel, LVarA, 0, 1, 0)
339 Wait(2)
340 Call(TranslateModel, LVarA, 0, 1, 0)
341 Wait(2)
342 Call(TranslateModel, LVarA, 0, 1, 0)
343 Wait(2)
344 Call(TranslateModel, LVarA, 0, 0, 0)
345 Wait(2)
346 Call(TranslateModel, LVarA, 0, 0, 0)
347 Wait(2)
348 Call(TranslateModel, LVarA, 0, 0, 0)
349 Wait(2)
350 EndLoop
351 Return
352 End
353};
@ FISH_STATE_1
@ FISH_STATE_2
@ FISH_STATE_INIT
@ FISH_STATE_3
Bytecode EvtScript[]
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
f32 sin_rad(f32 x)
Definition 43F0.c:713
ApiStatus TranslateModel(Evt *script, b32 isInitialCall)
Translates the given model's position.
ApiStatus RotateModel(Evt *script, b32 isInitialCall)
Rotates the model the given amount on the selected axis.
ApiStatus RandInt(Evt *script, b32 isInitialCall)
#define Ref(sym)
Address/pointer constant.
Definition macros.h:60
#define Set(VAR, INT_VALUE)
Sets the given variable to a given value casted to an integer.
Definition macros.h:365
#define Sub(VAR, INT_VALUE)
Definition macros.h:377
#define IfNe(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR != RVAR.
Definition macros.h:272
#define End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#define UseBuf(INT_PTR)
Loads a s32 pointer for use with subsequent EVT_BUF_READ commands.
Definition macros.h:389
#define Add(VAR, INT_VALUE)
Definition macros.h:376
#define EndLoop
Marks the end of a loop.
Definition macros.h:248
#define Goto(LABEL_ID)
Moves execution to the given label.
Definition macros.h:232
#define LVarC
Definition macros.h:160
#define BufRead1(VAR)
Consumes the next s32 from the buffer and stores it in the given variable.
Definition macros.h:392
#define IfGt(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR <= RVAR.
Definition macros.h:278
#define Label(LABEL_ID)
Marks this point in the script as a Goto target.
Definition macros.h:227
#define EndIf
Marks the end of an if statement or an else block.
Definition macros.h:298
#define LVar5
Definition macros.h:153
#define LVarB
Definition macros.h:159
#define BreakLoop
Breaks out of the innermost loop.
Definition macros.h:251
#define LVar2
Definition macros.h:150
#define DEG_TO_RAD(deg)
Definition macros.h:134
#define LVar1
Definition macros.h:149
#define LVarA
Definition macros.h:158
#define Wait(NUM_FRAMES)
Blocks for the given number of frames.
Definition macros.h:254
#define IfEq(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR == RVAR.
Definition macros.h:269
#define Call(FUNC, ARGS...)
Calls a given C EVT API function with any number of arguments.
Definition macros.h:576
#define Loop(TIMES)
Marks the beginning of a loop.
Definition macros.h:245
#define LVar0
Definition macros.h:148
#define Return
Kills the current EVT thread.
Definition macros.h:217