Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
MovingClouds.inc.c
Go to the documentation of this file.
1#include "common.h"
2
3// Used for clouds moving back and forth in stage backgrounds
4// They turn around upon reaching the edge of the stage
5// The position at any give time is represented by an angle, with one full
6// cycle corresponding to a cycle of the cloud's motion around the stage.
7
8// determines angle of 'patrolling' cloud based on position
9API_CALLABLE(N(InterpCloudTransform)) {
10 Bytecode* args = script->ptrReadPos;
11 f32 interpAngleDeg = evt_get_variable(script, *args++) / 10.0;
12 s32 outVarX = *args++;
13 s32 outVarY = *args++;
14 s32 outVarZ = *args++;
15 s32 outVarAngle = *args++;
16 f32 interpAngleRad = DEG_TO_RAD(interpAngleDeg);
17 f32 posX = sin_rad(interpAngleRad) * 150.0f + 0.0f;
18 f32 posY = sin_rad(interpAngleRad * 8.0f) * 10.0f + 0.0f;
19 f32 posZ = cos_rad(interpAngleRad) * 150.0f / 20.0f + -50.0f;
20 s32 outAngle;
21
22 evt_set_float_variable(script, outVarX, posX);
23 evt_set_float_variable(script, outVarY, posY);
24 evt_set_float_variable(script, outVarZ, posZ);
25
26 outAngle = 0;
27 if (interpAngleDeg > 90.0f && interpAngleDeg < 270.0f) {
28 outAngle = 180;
29 }
30 if ((s32)fabsf(90.0f - interpAngleDeg) < 45) {
31 outAngle = 2.0f * (interpAngleDeg - 45.0f);
32 }
33 if ((s32)fabsf(270.0f - interpAngleDeg) < 45) {
34 outAngle = 2.0f * (interpAngleDeg - 225.0f) + 180.0f;
35 }
36 evt_set_variable(script, outVarAngle, outAngle);
37
38 return ApiStatus_DONE2;
39}
40
41// (in) LVar0 : modelID
42// (in) LVar2 : motion phase offset
43EvtScript N(EVS_AnimateCloud) = {
46 Mul(LVar7, 10)
47 Label(0)
48 Add(LVar7, 4)
49 IfGt(LVar7, 3599)
50 Sub(LVar7, 3600)
51 EndIf
52 Call(N(InterpCloudTransform), LVar7, LVar0, LVar1, LVar2, LVar3)
54 Call(RotateModel, LVarA, LVar3, 0, 1, 0)
55 Wait(1)
56 Goto(0)
57 Return
58 End
59};
60
61// (in) LVar0 : modelID
62// (in) LVar2 : motion phase offset
63// (in) LVar3 : offsetY
64// (in) LVar4 : offsetZ
65EvtScript N(EVS_AnimateCloud_WithOffset2D) = {
70 Mul(LVar7, 10)
71 Label(0)
72 Add(LVar7, 4)
73 IfGt(LVar7, 3599)
74 Sub(LVar7, 3600)
75 EndIf
76 Call(N(InterpCloudTransform), LVar7, LVar0, LVar1, LVar2, LVar3)
80 Call(RotateModel, LVarA, LVar3, 0, 1, 0)
81 Wait(1)
82 Goto(0)
83 Return
84 End
85};
86
87// (in) LVar0 : modelID
88// (in) LVar2 : motion phase offset
89// (in) LVar3 : offsetX
90// (in) LVar4 : offsetY
91// (in) LVar4 : offsetZ
92EvtScript N(EVS_AnimateCloud_WithOffset3D) = {
98 Mul(LVar7, 10)
99 Label(0)
100 Add(LVar7, 4)
101 IfGt(LVar7, 3599)
102 Sub(LVar7, 3600)
103 EndIf
104 Call(N(InterpCloudTransform), LVar7, LVar0, LVar1, LVar2, LVar3)
109 Call(RotateModel, LVarA, LVar3, 0, 1, 0)
110 Wait(1)
111 Goto(0)
112 Return
113 End
114};
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 fabsf(f32 f)
f32 evt_set_float_variable(Evt *script, Bytecode var, f32 value)
Definition evt.c:1977
s32 evt_set_variable(Evt *script, Bytecode var, s32 value)
Definition evt.c:1847
f32 cos_rad(f32 x)
Definition 43F0.c:717
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.
#define Mul(VAR, INT_VALUE)
Definition macros.h:378
#define Set(VAR, INT_VALUE)
Sets the given variable to a given value casted to an integer.
Definition macros.h:365
#define AddF(VAR, FLOAT_VALUE)
Definition macros.h:383
#define Sub(VAR, INT_VALUE)
Definition macros.h:377
#define End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#define Add(VAR, INT_VALUE)
Definition macros.h:376
#define Goto(LABEL_ID)
Moves execution to the given label.
Definition macros.h:232
#define LVarC
Definition macros.h:160
#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 LVar7
Definition macros.h:155
#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 LVarD
Definition macros.h:161
#define Wait(NUM_FRAMES)
Blocks for the given number of frames.
Definition macros.h:254
#define Call(FUNC, ARGS...)
Calls a given C EVT API function with any number of arguments.
Definition macros.h:576
#define LVar4
Definition macros.h:152
#define LVar3
Definition macros.h:151
#define LVar0
Definition macros.h:148
#define Return
Kills the current EVT thread.
Definition macros.h:217