Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
enter_exit.c
Go to the documentation of this file.
1#include "common.h"
2#include "../partners.h"
3
4extern s32 DoorModelsSwingCCW[3];
5extern s32 DoorModelsSwingCW[3];
6
7API_CALLABLE(CheckUsingRideablePartner) {
8 PlayerStatus* playerStatus = &gPlayerStatus;
9
10 script->varTable[10] = 0;
11 if (partner_get_enter_map_script() != NULL) {
13 script->varTable[10] = 0;
14 } else {
15 script->varTable[10] = 1;
16 script->varTablePtr[11] = partner_get_enter_map_script();
17 script->varTable[13] = playerStatus->targetYaw;
18 }
19 }
20 return ApiStatus_DONE2;
21}
22
23API_CALLABLE(TeleportPartnerToPlayer) {
24 PlayerStatus* playerStatus = &gPlayerStatus;
25 Npc* partner;
26
28 return ApiStatus_DONE2;
29 }
30
31 partner = get_npc_unsafe(NPC_PARTNER);
32 partner->pos.x = playerStatus->pos.x;
33 partner->pos.z = playerStatus->pos.z;
34
35 if (partner_is_flying()) {
36 partner->pos.y = playerStatus->pos.y;
37 }
38
39 set_npc_yaw(partner, playerStatus->targetYaw);
41 return ApiStatus_DONE2;
42}
43
44API_CALLABLE(SetPlayerPositionFromSaveData) {
45 PlayerStatus* playerStatus = &gPlayerStatus;
47 s32 currentPartner = gPlayerData.curPartner;
48
49 playerStatus->pos.x = gGameStatusPtr->savedPos.x;
50 playerStatus->pos.y = gGameStatusPtr->savedPos.y;
51 playerStatus->pos.z = gGameStatusPtr->savedPos.z;
52
53 if (currentPartner != PARTNER_NONE) {
54 Npc* partner = get_npc_unsafe(NPC_PARTNER);
55 f32 angle = clamp_angle((playerStatus->spriteFacingAngle < 180.0f) ? (90.0f) : (-90.0f));
56
57 partner->pos.x = playerStatus->pos.x;
58 partner->pos.y = playerStatus->pos.y;
59 partner->pos.z = playerStatus->pos.z;
60 add_vec2D_polar(&partner->pos.x, &partner->pos.z, playerStatus->colliderDiameter + 5, angle);
62 }
63
64 camera->needsReinit = TRUE;
65 return ApiStatus_DONE2;
66}
67
68API_CALLABLE(EnterPlayerPostPipe) {
69 PlayerStatus* playerStatus = &gPlayerStatus;
72
73 if (isInitialCall) {
74 playerStatus->pos.x = (*mapSettings->entryList)[gGameStatusPtr->entryID].x;
75 playerStatus->pos.z = (*mapSettings->entryList)[gGameStatusPtr->entryID].z;
76 script->varTable[2] = (*mapSettings->entryList)[gGameStatusPtr->entryID].y;
77 playerStatus->pos.y = script->varTable[2] - 40;
78 playerStatus->flags |= PS_FLAG_CAMERA_DOESNT_FOLLOW;
79 } else {
80 playerStatus->pos.y += 1.0f;
81 if (!(playerStatus->pos.y < script->varTable[2])) {
82 playerStatus->pos.y = script->varTable[2];
83 playerStatus->flags &= ~PS_FLAG_CAMERA_DOESNT_FOLLOW;
84 ret = ApiStatus_DONE2;
85 }
86 }
87 gCameras[CAM_DEFAULT].targetPos.x = playerStatus->pos.x;
88 gCameras[CAM_DEFAULT].targetPos.y = playerStatus->pos.y;
89 gCameras[CAM_DEFAULT].targetPos.z = playerStatus->pos.z;
90 return ret;
91}
92
93API_CALLABLE(ShortenPartnerTetherDistance) {
95 return ApiStatus_DONE2;
96}
97
98API_CALLABLE(ResetPartnerTetherDistance) {
100 return ApiStatus_DONE2;
101}
102
103API_CALLABLE(PlayerMoveToDoor) {
104 Bytecode* args = script->ptrReadPos;
105 PlayerStatus* playerStatus = &gPlayerStatus;
106
107 if (isInitialCall) {
108 script->functionTemp[0] = evt_get_variable(script, *args++);
109 move_player(script->functionTemp[0], playerStatus->targetYaw, playerStatus->runSpeed);
110 }
111
112 script->functionTemp[0]--;
113 if (script->functionTemp[0] < 0) {
114 return ApiStatus_DONE1;
115 } else {
116 return ApiStatus_BLOCK;
117 }
118}
119
120API_CALLABLE(GetEntryCoords) {
121 Bytecode* args = script->ptrReadPos;
122 MapSettings* mapSettings = get_current_map_settings();
123 Vec4f* entryList = (Vec4f*)mapSettings->entryList;
124 s32 index = evt_get_variable(script, *args++);
125
126 evt_set_variable(script, *args++, entryList[index].x);
127 evt_set_variable(script, *args++, entryList[index].y);
128 evt_set_variable(script, *args++, entryList[index].z);
129 evt_set_variable(script, *args++, entryList[index].yaw);
130
131 return ApiStatus_DONE2;
132}
133
134API_CALLABLE(SetupSingleDoor) {
135 if (script->varTable[3] >= 0) {
136 DoorModelsSwingCCW[0] = script->varTable[2];
137 DoorModelsSwingCCW[1] = -1;
138 DoorModelsSwingCW[0] = -1;
139 } else {
140 DoorModelsSwingCW[0] = script->varTable[2];
141 DoorModelsSwingCW[1] = -1;
142 DoorModelsSwingCCW[0] = -1;
143 }
144
145 script->varTablePtr[2] = &DoorModelsSwingCCW;
146 script->varTablePtr[3] = &DoorModelsSwingCW;
147
148 return ApiStatus_DONE2;
149}
150
151API_CALLABLE(SetupSplitSingleDoor) {
152 if (script->varTable[3] >= 0) {
153 DoorModelsSwingCCW[0] = script->varTable[2];
154 DoorModelsSwingCCW[1] = script->varTable[4];
155 DoorModelsSwingCCW[2] = -1;
156 DoorModelsSwingCW[0] = -1;
157 } else {
158 DoorModelsSwingCW[0] = script->varTable[2];
159 DoorModelsSwingCW[1] = script->varTable[4];
160 DoorModelsSwingCW[2] = -1;
161 DoorModelsSwingCCW[0] = -1;
162 }
163
164 script->varTablePtr[2] = &DoorModelsSwingCCW;
165 script->varTablePtr[3] = &DoorModelsSwingCW;
166
167 return ApiStatus_DONE2;
168}
169
170API_CALLABLE(SetupDoubleDoors) {
171 DoorModelsSwingCCW[0] = script->varTable[2];
172 DoorModelsSwingCCW[1] = -1;
173
174 DoorModelsSwingCW[0] = script->varTable[3];
175 DoorModelsSwingCW[1] = -1;
176
177 script->varTablePtr[3] = &DoorModelsSwingCW;
178 script->varTablePtr[2] = &DoorModelsSwingCCW;
179
180 return ApiStatus_DONE2;
181}
182
183API_CALLABLE(SetupSplitDoubleDoors) {
184 DoorModelsSwingCCW[0] = script->varTable[2];
185 DoorModelsSwingCCW[1] = script->varTable[4];
186 DoorModelsSwingCCW[2] = -1;
187
188 DoorModelsSwingCW[0] = script->varTable[3];
189 DoorModelsSwingCW[1] = script->varTable[5];
190 DoorModelsSwingCW[2] = -1;
191
192 script->varTablePtr[3] = &DoorModelsSwingCW;
193 script->varTablePtr[2] = &DoorModelsSwingCCW;
194
195 return ApiStatus_DONE2;
196}
197
199 Call(ShortenPartnerTetherDistance)
200 Call(CheckUsingRideablePartner)
201 Call(UseEntryHeading, 60, 15)
202 IfEq(LVarA, 0)
203 Call(TeleportPartnerToPlayer)
205 Else
206 Set(LVarF, LVar0)
207 Set(LVar0, 0)
208 Set(LVarC, 1)
209 Set(LVar4, 15)
211 Set(LVar0, LVarF)
212 EndIf
213 Exec(LVar0)
215 Call(ResetPartnerTetherDistance)
216 Return
217 End
218};
219
221 Call(ShortenPartnerTetherDistance)
222 Call(CheckUsingRideablePartner)
223 Call(UseEntryHeading, 40, 15)
224 IfEq(LVarA, 0)
225 Call(TeleportPartnerToPlayer)
227 Else
228 Set(LVarF, LVar0)
229 Set(LVar0, 0)
230 Set(LVarC, 1)
231 Set(LVar4, 15)
233 Set(LVar0, LVarF)
234 EndIf
235 Exec(LVar0)
237 Call(ResetPartnerTetherDistance)
238 Return
239 End
240};
241
243 Call(ShortenPartnerTetherDistance)
244 Call(CheckUsingRideablePartner)
246 IfEq(LVarA, 0)
247 Call(TeleportPartnerToPlayer)
249 Else
250 Set(LVarF, LVar0)
251 Set(LVar0, 0)
252 Set(LVarC, 1)
254 Set(LVar0, LVarF)
255 EndIf
256 Exec(LVar0)
258 Call(ResetPartnerTetherDistance)
259 Return
260 End
261};
262
265 Call(ShortenPartnerTetherDistance)
266 Call(CheckUsingRideablePartner)
267 Call(EnterPlayerPostPipe)
268 Call(ResetPartnerTetherDistance)
270 Return
271 End
272};
273
275 Call(ShortenPartnerTetherDistance)
276 Call(SetPlayerPositionFromSaveData)
278 Call(ResetPartnerTetherDistance)
279 Return
280 End
281};
282
285 Call(ShortenPartnerTetherDistance)
286 Call(CheckUsingRideablePartner)
287 IfEq(LVarA, 0)
289 Else
290 Set(LVar0, 0)
291 Set(LVarC, 0)
292 Set(LVar4, 15)
294 EndIf
295 Call(ResetPartnerTetherDistance)
296 Return
297 End
298};
299
301 Call(SetupSingleDoor)
303 Return
304 End
305};
306
308 Call(SetupSingleDoor)
310 Return
311 End
312};
313
315 Call(SetupSplitSingleDoor)
317 Return
318 End
319};
320
322 Call(SetupSplitSingleDoor)
324 Return
325 End
326};
327
329 Call(SetupDoubleDoors)
331 Return
332 End
333};
334
336 Call(SetupDoubleDoors)
338 Return
339 End
340};
341
343 Call(SetupSplitDoubleDoors)
345 Return
346 End
347};
348
350 Call(SetupSplitDoubleDoors)
352 Return
353 End
354};
355
359 Call(ShortenPartnerTetherDistance)
360 Set(LVar9, LVar0)
361 Call(GetEntryCoords, LVar0, LVarC, LVarD, LVarE, LVarB)
362 Add(LVarB, 180)
366 Call(MakeLerp, 0, 80, 10, EASING_LINEAR)
367 Label(0)
370 Loop(0)
372 IfEq(LVarA, -1)
374 EndIf
375 Call(RotateModel, LVarA, LVar0, 0, 1, 0)
376 EndLoop
378 Loop(0)
380 IfEq(LVarA, -1)
382 EndIf
383 Call(RotateModel, LVarA, LVar0, 0, -1, 0)
384 EndLoop
385 Wait(1)
386 IfNe(LVar1, 0)
387 Goto(0)
388 EndIf
390 Call(CheckUsingRideablePartner)
391 IfEq(LVarA, 0)
393 Else
394 Set(LVar0, 0)
395 Set(LVarC, 0)
396 Set(LVar4, 15)
398 EndIf
399 Call(ResetPartnerTetherDistance)
402 Return
403 End
404};
405
408 Call(ShortenPartnerTetherDistance)
410 Loop(0)
412 IfEq(LVarA, -1)
414 EndIf
415 Call(RotateModel, LVarA, -80, 0, 1, 0)
416 EndLoop
418 Loop(0)
420 IfEq(LVarA, -1)
422 EndIf
423 Call(RotateModel, LVarA, -80, 0, -1, 0)
424 EndLoop
425 Call(GetEntryCoords, LVar0, LVar7, LVar8, LVar9, LVarB)
427 Call(CheckUsingRideablePartner)
428 IfEq(LVarA, 0)
429 Call(TeleportPartnerToPlayer)
430 Call(PlayerMoveToDoor, 10)
431 Else
432 Set(LVar0, 1)
433 Set(LVarC, 1)
434 Set(LVar4, 15)
436 EndIf
437 Thread
438 Wait(8)
441 Call(MakeLerp, -80, 0, 10, EASING_LINEAR)
442 Label(0)
445 Loop(0)
447 IfEq(LVarA, -1)
449 EndIf
450 Call(RotateModel, LVarA, LVar0, 0, 1, 0)
451 EndLoop
453 Loop(0)
455 IfEq(LVarA, -1)
457 EndIf
458 Call(RotateModel, LVarA, LVar0, 0, -1, 0)
459 EndLoop
460 Wait(1)
461 IfNe(LVar1, 0)
462 Goto(0)
463 EndIf
464 Call(ResetPartnerTetherDistance)
466 Return
467 End
468};
Bytecode EvtScript[]
#define clamp_angle
EvtScript ExitSplitSingleDoor
Definition enter_exit.c:314
EvtScript EnterSingleDoor
Definition enter_exit.c:307
EvtScript EnterSplitDoubleDoor
Definition enter_exit.c:349
EvtScript ExitWalk
Definition enter_exit.c:283
EvtScript EnterSplitSingleDoor
Definition enter_exit.c:321
EvtScript ExitSplitDoubleDoor
Definition enter_exit.c:342
EvtScript EnterDoubleDoor
Definition enter_exit.c:335
s32 DoorModelsSwingCW[3]
Definition script_list.c:66
EvtScript EnterSavePoint
Definition enter_exit.c:274
s32 DoorModelsSwingCCW[3]
Definition script_list.c:67
EvtScript ExitDoubleDoor
Definition enter_exit.c:328
EvtScript EnterWalk
Definition enter_exit.c:198
EvtScript ExitSingleDoor
Definition enter_exit.c:300
EvtScript BaseEnterDoor
Definition enter_exit.c:406
EvtScript BaseExitDoor
Definition enter_exit.c:356
EvtScript EnterWalkCustom
Definition enter_exit.c:242
EvtScript EnterWalkShort
Definition enter_exit.c:220
EvtScript EnterPostPipe
Definition enter_exit.c:263
@ PS_FLAG_CAMERA_DOESNT_FOLLOW
Definition enums.h:3075
@ COLLIDER_FLAGS_UPPER_MASK
Definition enums.h:4692
@ NPC_PARTNER
Definition enums.h:2528
@ EASING_LINEAR
Definition enums.h:510
@ SOUND_DOOR_CLOSE
Definition enums.h:1694
@ SOUND_DOOR_OPEN
Definition enums.h:1693
@ PARTNER_NONE
Definition enums.h:2885
@ ACTION_STATE_IDLE
Definition enums.h:2426
@ SOUND_SPACE_DEFAULT
Definition enums.h:1737
@ CAM_DEFAULT
Definition enums.h:1800
s32 ApiStatus
Definition evt.h:115
#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
void partner_clear_player_tracking(Npc *partner)
Definition partners.c:2436
s32 evt_set_variable(Evt *script, Bytecode var, s32 value)
Definition evt.c:1847
void move_player(s32 duration, f32 heading, f32 speed)
Definition 7BB60.c:57
s32 partner_is_flying(void)
Definition partners.c:572
void enable_partner_ai(void)
Definition partners.c:2390
EvtScript * partner_get_enter_map_script(void)
Definition partners.c:1058
void partner_set_tether_distance(f32)
Definition partners.c:2401
void partner_reset_tether_distance(void)
Definition partners.c:2405
void add_vec2D_polar(f32 *x, f32 *y, f32 r, f32 theta)
Definition 43F0.c:685
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
void set_npc_yaw(Npc *npc, f32 yaw)
Definition npc.c:1246
ApiStatus ClearPartnerMoveHistory(Evt *script, b32 isInitialCall)
ApiStatus func_802D2148(Evt *script, b32 isInitialCall)
ApiStatus UseEntryHeading(Evt *script, b32 isInitialCall)
ApiStatus RotateModel(Evt *script, b32 isInitialCall)
Rotates the model the given amount on the selected axis.
ApiStatus DisablePlayerInput(Evt *script, b32 isInitialCall)
Disables player and partner input, and disables the status menu.
ApiStatus UpdateLerp(Evt *script, b32 isInitialCall)
ApiStatus UseExitHeading(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 MakeLerp(Evt *script, b32 isInitialCall)
ApiStatus InterpPlayerYaw(Evt *script, b32 isInitialCall)
ApiStatus ModifyColliderFlags(Evt *script, b32 isInitialCall)
Set flags for collider + siblings + children.
ApiStatus PlaySoundAt(Evt *script, b32 isInitialCall)
#define Else
Marks the end of an if statement and the start of the else block.
Definition macros.h:295
#define Set(VAR, INT_VALUE)
Sets the given variable to a given value casted to an integer.
Definition macros.h:365
#define LVarF
Definition macros.h:163
#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 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 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 BreakLoop
Breaks out of the innermost loop.
Definition macros.h:251
#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 LVarD
Definition macros.h:161
#define Wait(NUM_FRAMES)
Blocks for the given number of frames.
Definition macros.h:254
#define LVar9
Definition macros.h:157
#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 LVarE
Definition macros.h:162
#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
b16 needsReinit
Vec3f targetPos
Vec3f pos
PartnerStatus gPartnerStatus
Definition partners.c:42
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Camera gCameras[4]
Definition cam_main.c:17
PlayerData gPlayerData
Definition 77480.c:40
PlayerStatus gPlayerStatus
Definition 77480.c:39
s32 gCurrentCameraID
Definition cam_math.c:4