Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
Pipe.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "npc.h"
3#include "sprite/player.h"
4
5// ----------------------------------------------------------------
6// User macros
7
8#define EVT_EXIT_PIPE_HORIZONTAL(entry, collider, script) \
9{ \
10 SetGroup(EVT_GROUP_EXIT_MAP) \
11 Set(LVarA, entry) \
12 Set(LVarB, collider) \
13 Set(LVarC, Ref(script)) \
14 ExecWait(N(EVS_Pipe_ExitHorizontal)) \
15 Return \
16 End \
17}
18
19#define EVT_EXIT_PIPE_VERTICAL(entry, collider, script) \
20{ \
21 SetGroup(EVT_GROUP_EXIT_MAP) \
22 Set(LVarA, entry) \
23 Set(LVarB, collider) \
24 Set(LVarC, Ref(script)) \
25 ExecWait(N(EVS_Pipe_ExitVertical)) \
26 Return \
27 End \
28}
29
30#define EVT_ENTER_PIPE_HORIZONTAL(collider, bindExitsScript) \
31 Set(LVarA, Ref(bindExitsScript)) \
32 Set(LVarB, collider) \
33 Exec(N(EVS_Pipe_EnterHorizontal))
34
35#define EVT_ENTER_PIPE_VERTICAL(bindExitsScript) \
36 Set(LVarA, Ref(bindExitsScript)) \
37 Exec(N(EVS_Pipe_EnterVertical))
38
39// ----------------------------------------------------------------
40// Implementation
41
42API_CALLABLE(N(Pipe_SetAnimFlag)) {
44 return ApiStatus_DONE2;
45}
46
47API_CALLABLE(N(Pipe_GetCurrentFloor)) {
48 script->varTable[0] = gCollisionStatus.curFloor;
49 return ApiStatus_DONE2;
50}
51
52API_CALLABLE(N(Pipe_AwaitDownInput)) {
53 CollisionStatus* collisionStatus = &gCollisionStatus;
54 s32 stickX, stickY;
55
56 if (collisionStatus->curFloor != script->varTable[11]) {
57 script->varTable[0] = FALSE;
58 return ApiStatus_DONE2;
59 }
60
61 stickX = abs(gGameStatusPtr->stickX[0]);
62 stickY = gGameStatusPtr->stickY[0];
63
64 if (stickX != 0 || stickY != 0) {
65 if (atan2(0.0f, 0.0f, stickX, stickY) < 60.0f) {
66 script->varTable[0] = TRUE;
67 return ApiStatus_DONE2;
68 }
69 }
70
71 return ApiStatus_BLOCK;
72}
73
74API_CALLABLE(N(Pipe_GetEntryPos)) {
76 s32 index = evt_get_variable(script, LVar0);
77
78 evt_set_variable(script, LVar1, ((Vec4f*)*mapSettings->entryList)[index].x);
79 evt_set_variable(script, LVar2, ((Vec4f*)*mapSettings->entryList)[index].y);
80 evt_set_variable(script, LVar3, ((Vec4f*)*mapSettings->entryList)[index].z);
81 evt_set_variable(script, LVar4, ((Vec4f*)*mapSettings->entryList)[index].yaw);
82
83 return ApiStatus_DONE2;
84}
85
86API_CALLABLE(N(Pipe_GetCameraYaw)) {
87 script->varTable[0] = clamp_angle(gCameras[gCurrentCameraID].curYaw + 180.0f);
88 return ApiStatus_DONE2;
89}
90
91API_CALLABLE(N(Pipe_GetPointAheadOfPlayer)) {
92 PlayerStatus* playerStatus = &gPlayerStatus;
93 f32 r = evt_get_float_variable(script, *script->ptrReadPos);
94 f32 x = playerStatus->pos.x;
95 f32 y = playerStatus->pos.y;
96 f32 z = playerStatus->pos.z;
97
98 add_vec2D_polar(&x, &z, r, playerStatus->targetYaw);
99 evt_set_float_variable(script, LVar0, x);
100 evt_set_float_variable(script, LVar1, y);
101 evt_set_float_variable(script, LVar2, z);
102
103 return ApiStatus_DONE2;
104}
105
106// ----------------------------------------------------------------
107// Scripts
108
109extern EvtScript N(EVS_Pipe_ExitVertical_Impl);
110
111EvtScript N(EVS_Pipe_EnterVertical) = {
116 Call(SetPlayerAnimation, ANIM_Mario1_Still)
121 EndIf
123 Call(N(Pipe_GetEntryPos))
124 Sub(LVar2, 40)
131 Loop(40)
132 Add(LVar1, 1)
134 Wait(1)
135 EndLoop
136 Wait(3)
139 Thread
142 Sub(LVar2, 3)
148 EndIf
149 Wait(2)
150 Call(UpdatePlayerImgFX, ANIM_Mario1_Still, IMGFX_CLEAR, 0, 0, 0, 0)
151 Wait(1)
152 Call(SetPlayerAnimation, ANIM_Mario1_Idle)
155 Call(HidePlayerShadow, FALSE)
156 Label(0)
157 Call(N(Pipe_GetCurrentFloor))
158 Wait(1)
159 IfNe(LVar0, -1)
160 Goto(0)
161 EndIf
162 Exec(LVarA)
163 Return
164 End
165};
166
167EvtScript N(EVS_Pipe_EnterHorizontal) = {
173 Call(N(Pipe_GetEntryPos))
174 Set(LVar5, LVar1)
175 Set(LVar6, LVar2)
176 Set(LVar7, LVar3)
177 Add(LVar2, 2)
180 IfEq(LVar4, 90)
181 Add(LVar5, 40)
182 Else
183 Sub(LVar5, 40)
184 EndIf
188 Call(PanToTarget, CAM_DEFAULT, 0, TRUE)
195 EndIf
196 Wait(1)
198 Thread
199 Wait(25)
200 Call(HidePlayerShadow, FALSE)
204 Loop(40)
205 Call(N(Pipe_GetPointAheadOfPlayer), Float(1.0))
207 Wait(1)
208 EndLoop
211 Thread
213 Sub(LVar2, 3)
218 EndIf
219 Wait(5)
220 Call(UpdatePlayerImgFX, ANIM_Mario1_Idle, IMGFX_CLEAR, 0, 0, 0, 0)
224 Call(PanToTarget, CAM_DEFAULT, 0, FALSE)
225 Exec(LVarA)
226 Return
227 End
228};
229
230EvtScript N(EVS_Pipe_ExitVertical) = {
231 Call(N(Pipe_AwaitDownInput))
232 IfEq(LVar0, 0)
233 Return
234 EndIf
239 Return
240 Else
243 EndIf
244 Else
246 EndIf
247 ExecWait(N(EVS_Pipe_ExitVertical_Impl))
248 Return
249 End
250};
251
252EvtScript N(EVS_Pipe_ExitVertical_Impl) = {
253 Call(N(Pipe_SetAnimFlag))
257 Set(LVar0, LVarA)
258 Call(N(Pipe_GetEntryPos))
260 Set(LVar0, LVarA)
261 Call(N(Pipe_GetEntryPos))
264 Call(N(Pipe_GetCameraYaw))
266 Wait(2)
270 Thread
271 Wait(4)
272 Loop(40)
273 Sub(LVar1, 1)
275 Wait(1)
276 EndLoop
280 Wait(25)
282 Return
283 End
284};
285
286EvtScript N(EVS_Pipe_ExitHorizontal) = {
288 IfEq(LVar0, FALSE)
289 Return
290 EndIf
293 Return
294 EndIf
299 Return
300 Else
303 EndIf
304 Else
306 EndIf
308 Call(N(Pipe_SetAnimFlag))
311 Set(LVar0, LVarA)
312 Call(N(Pipe_GetEntryPos))
313 Set(LVar5, LVar1)
314 Set(LVar6, LVar2)
315 Add(LVar6, 2)
316 Set(LVar7, LVar3)
317 Set(LVar8, LVar4)
318 Add(LVar8, 180)
319 IfGe(LVar4, 360)
320 Sub(LVar4, 360)
321 EndIf
323 Wait(1)
327 Call(SetPlayerAnimation, ANIM_Mario1_Still)
330 Thread
331 Wait(8)
334 Thread
335 Wait(3)
336 Loop(40)
337 Call(N(Pipe_GetPointAheadOfPlayer), Float(1.0))
339 Wait(1)
340 EndLoop
342 Wait(25)
344 Return
345 End
346};
Bytecode EvtScript[]
#define clamp_angle
#define atan2
@ IMGFX_CLEAR
Definition enums.h:5117
@ IMGFX_SET_ANIM
Definition enums.h:5122
@ PS_FLAG_NO_FLIPPING
Definition enums.h:3067
@ IMGFX_ANIM_VERTICAL_PIPE_CURL
Definition enums.h:5140
@ IMGFX_ANIM_HORIZONTAL_PIPE_CURL
Definition enums.h:5141
@ COLLIDER_FLAGS_UPPER_MASK
Definition enums.h:4692
@ NPC_PARTNER
Definition enums.h:2528
@ PA_FLAG_CHANGING_MAP
Definition enums.h:3112
@ MODIFY_COLLIDER_FLAGS_SET_BITS
Definition enums.h:4705
@ SOUND_ENTER_PIPE
Definition enums.h:785
@ PARTNER_NONE
Definition enums.h:2885
@ PARTNER_WATT
Definition enums.h:2891
@ ACTION_STATE_SPIN
Definition enums.h:2454
@ CAM_DEFAULT
Definition enums.h:1800
@ IMGFX_FLAG_REVERSE_ANIM
Definition enums.h:5101
@ IMGFX_FLAG_800
Definition enums.h:5104
@ NPC_FLAG_INVISIBLE
Definition enums.h:2999
#define ApiStatus_DONE2
Definition evt.h:118
@ EVT_GROUP_EXIT_MAP
Definition evt.h:145
#define ApiStatus_BLOCK
Definition evt.h:116
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
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 evt_get_float_variable(Evt *script, Bytecode var)
Definition evt.c:1930
void add_vec2D_polar(f32 *x, f32 *y, f32 r, f32 theta)
Definition 43F0.c:685
ApiStatus GetPartnerInUse(Evt *script, b32 isInitialCall)
ApiStatus SetPlayerImgFXFlags(Evt *script, b32 isInitialCall)
ApiStatus PlaySound(Evt *script, b32 isInitialCall)
ApiStatus SetPlayerPos(Evt *script, b32 isInitialCall)
Sets the player position.
ApiStatus GetEntryID(Evt *script, b32 isInitialCall)
Returns the entryID of the Entry that the player entered the map from.
ApiStatus DisablePartnerAI(Evt *script, b32 isInitialCall)
ApiStatus IsPlayerOnValidFloor(Evt *script, b32 isInitialCall)
ApiStatus SetPlayerAnimation(Evt *script, b32 isInitialCall)
ApiStatus UpdatePlayerImgFX(Evt *script, b32 isInitialCall)
ApiStatus PanToTarget(Evt *script, b32 isInitialCall)
ApiStatus DisablePlayerInput(Evt *script, b32 isInitialCall)
Disables player and partner input, and disables the status menu.
ApiStatus HidePlayerShadow(Evt *script, b32 isInitialCall)
Hides the player's shadow if hide is TRUE, shows it if FALSE.
ApiStatus EnableNpcShadow(Evt *script, b32 isInitialCall)
ApiStatus GetCurrentPartnerID(Evt *script, b32 isInitialCall)
ApiStatus GetPlayerActionState(Evt *script, b32 isInitialCall)
ApiStatus EnablePartnerAI(Evt *script, b32 isInitialCall)
ApiStatus InterpNpcYaw(Evt *script, b32 isInitialCall)
ApiStatus SetNpcPos(Evt *script, b32 isInitialCall)
ApiStatus PlayerMoveTo(Evt *script, b32 isInitialCall)
ApiStatus DisablePlayerPhysics(Evt *script, b32 isInitialCall)
Disables player physics if disable is TRUE, enables it if FALSE.
ApiStatus SetNpcFlagBits(Evt *script, b32 isInitialCall)
ApiStatus InterpPlayerYaw(Evt *script, b32 isInitialCall)
ApiStatus SetPlayerFlagBits(Evt *script, b32 isInitialCall)
ApiStatus InterruptUsePartner(Evt *script, b32 isInitialCall)
ApiStatus GetPlayerPos(Evt *script, b32 isInitialCall)
ApiStatus UseSettingsFrom(Evt *script, b32 isInitialCall)
ApiStatus SetPanTarget(Evt *script, b32 isInitialCall)
ApiStatus SetCamSpeed(Evt *script, b32 isInitialCall)
ApiStatus ModifyColliderFlags(Evt *script, b32 isInitialCall)
Set flags for collider + siblings + children.
#define Else
Marks the end of an if statement and the start of the else block.
Definition macros.h:295
#define LVar6
Definition macros.h:154
#define IfGe(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR >= RVAR.
Definition macros.h:284
#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 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 Float(DOUBLE)
Definition macros.h:51
#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 ExecWait(EVT_SOURCE)
Launches a new child thread.
Definition macros.h:475
#define LVar7
Definition macros.h:155
#define Thread
Marks the start of a thread block.
Definition macros.h:544
#define EndThread
Marks the end of a thread block.
Definition macros.h:547
#define LVar8
Definition macros.h:156
#define LVar2
Definition macros.h:150
#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 SetGroup(GROUP)
Sets the current thread's group. Group value meanings are currently not known.
Definition macros.h:519
#define NPC_DISPOSE_LOCATION
Definition macros.h:158
#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 LVar4
Definition macros.h:152
#define LVar3
Definition macros.h:151
#define LVar0
Definition macros.h:148
#define Exec(EVT_SOURCE)
Launches a new thread.
Definition macros.h:455
#define Return
Kills the current EVT thread.
Definition macros.h:217
MapSettings * get_current_map_settings(void)
Definition world.c:224
EntryList * entryList
Definition map.h:32
Fields other than main, entryList, entryCount, background, and tattle are initialised when the map lo...
Definition map.h:26
PlayerStatus * gPlayerStatusPtr
CollisionStatus gCollisionStatus
Definition 7BB60.c:6
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Camera gCameras[4]
Definition cam_main.c:17
PlayerStatus gPlayerStatus
Definition 77480.c:39
s32 gCurrentCameraID
Definition cam_math.c:4