Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
msg_api.c
Go to the documentation of this file.
1#include "common.h"
2
5extern s32 D_802DAE58[2]; // unused?
6extern char D_802DAE60[0x400]; // unused?
8extern s32 D_802DB264;
10
11ApiStatus _show_message(Evt* script, s32 isInitialCall, s32 mode);
12
13enum {
18};
19
20API_CALLABLE(SpeakToPlayer) {
21 return _show_message(script, isInitialCall, SHOW_MESSAGE_SPEAK_TO_PLAYER);
22}
23
24API_CALLABLE(EndSpeech) {
25 return _show_message(script, isInitialCall, SHOW_MESSAGE_END_SPEECH);
26}
27
28API_CALLABLE(ContinueSpeech) {
29 return _show_message(script, isInitialCall, SHOW_MESSAGE_CONTINUE_SPEECH);
30}
31
32API_CALLABLE(SpeakToNpc) {
33 return _show_message(script, isInitialCall, SHOW_MESSAGE_SPEAK_TO_NPC);
34}
35
36s32 _show_message(Evt* script, s32 isInitialCall, s32 mode) {
37 PlayerStatus* playerStatus = &gPlayerStatus;
38 Bytecode* args = script->ptrReadPos;
39 s32 screenX, screenY, screenZ;
40 Npc* speakerNpc;
41 Npc* targetNpc;
42 f32 reverseAngle;
43 f32 angle;
44 f32* listenerYaw;
45 s32 speakerNpcID;
46 s32 targetNpcID;
47 s32 msgID;
48 s32 animID;
49 s32 ret;
50
51 targetNpc = NULL;
52
53 if (isInitialCall) {
54 D_802DB264 = 0;
55 speakerNpcID = evt_get_variable(script, *args++);
56 script->varTable[13] = evt_get_variable(script, *args++);
57 script->varTable[14] = evt_get_variable(script, *args++);
58 script->functionTemp[1] = evt_get_variable(script, *args++);
61
62 if (script->functionTemp[1] & SPEECH_FLAG_HAS_OFFSET) {
65 }
66
67 switch (mode) {
69 msgID = evt_get_variable(script, *args++);
71 break;
74 break;
76 msgID = evt_get_variable(script, *args++);
78 break;
80 targetNpcID = evt_get_variable(script, *args++);
81 msgID = evt_get_variable(script, *args++);
82 targetNpc = resolve_npc(script, targetNpcID);
84 break;
85 }
86
87 if (speakerNpcID == NPC_PLAYER) {
89 playerStatus->pos.y + playerStatus->colliderHeight, playerStatus->pos.z,
90 &screenX, &screenY, &screenZ);
91 script->functionTemp[3] = playerStatus->anim;
92 speakerNpc = (Npc*) NPC_PLAYER;
93 script->varTable[15] = playerStatus->targetYaw;
94 } else {
95 speakerNpc = resolve_npc(script, speakerNpcID);
96 get_screen_coords(gCurrentCameraID, speakerNpc->pos.x, speakerNpc->pos.y + speakerNpc->collisionHeight, speakerNpc->pos.z,
97 &screenX, &screenY, &screenZ);
98 script->functionTemp[3] = speakerNpc->curAnim;
99 script->varTable[15] = speakerNpc->yaw;
100 }
101
103 screenX + ShowMessageScreenOffsetX,
104 screenY + ShowMessageScreenOffsetY);
105 script->varTablePtr[12] = speakerNpc;
106
107 if (speakerNpc != (Npc*) NPC_PLAYER) {
108 if (mode == SHOW_MESSAGE_SPEAK_TO_NPC) {
109 listenerYaw = &targetNpc->yaw;
110 angle = atan2(speakerNpc->pos.x, speakerNpc->pos.z, targetNpc->pos.x, targetNpc->pos.z);
111 } else {
112 listenerYaw = &playerStatus->targetYaw;
113 angle = atan2(speakerNpc->pos.x, speakerNpc->pos.z, playerStatus->pos.x, playerStatus->pos.z);
114 }
115
116 reverseAngle = clamp_angle(angle + 180.0f);
117 switch (script->functionTemp[1] & SPEECH_ORIENTATION_MASK) {
119 speakerNpc->yaw = angle;
120 *listenerYaw = reverseAngle;
121 break;
123 speakerNpc->yaw = reverseAngle;
124 *listenerYaw = reverseAngle;
125 break;
127 speakerNpc->yaw = angle;
128 *listenerYaw = angle;
129 break;
131 speakerNpc->yaw = reverseAngle;
132 *listenerYaw = angle;
133 break;
135 speakerNpc->yaw = angle;
136 break;
137 case 5:
138 break;
139 }
140 }
141 }
142
143 speakerNpc = script->varTablePtr[12];
144 if (speakerNpc != (Npc*) NPC_PLAYER) {
145 get_screen_coords(gCurrentCameraID, speakerNpc->pos.x, speakerNpc->pos.y + speakerNpc->collisionHeight, speakerNpc->pos.z, &screenX, &screenY, &screenZ);
146 animID = script->varTable[13];
147 if (animID != -1) {
149 animID = script->varTable[14];
150 }
151 set_npc_animation(speakerNpc, animID);
152 }
153 } else {
154 get_screen_coords(gCurrentCameraID, playerStatus->pos.x, playerStatus->pos.y + playerStatus->colliderHeight, playerStatus->pos.z, &screenX, &screenY, &screenZ);
155 if (script->varTable[13] != -1) {
157 playerStatus->anim = script->varTable[13];
158 } else {
159 playerStatus->anim = script->varTable[14];
160 }
161 }
162 }
163
164 if (!(script->functionTemp[1] & SPEECH_FLAG_200)) {
166 }
167
169 return TRUE;
170 }
171
172 if (D_802DB264 != 1) {
173 return FALSE;
174 }
175
176 if (script->varTable[13] != -1) {
177 if (speakerNpc != (Npc*) NPC_PLAYER) {
178 set_npc_animation(speakerNpc, script->functionTemp[3]);
179 } else {
180 playerStatus->anim = script->functionTemp[3];
181 }
182 }
183 if (script->functionTemp[1] & SPEECH_FLAG_10) {
184 speakerNpc->yaw = script->varTable[0xF];
185 }
186 return TRUE;
187}
188
189API_CALLABLE(ShowMessageAtScreenPos) {
190 Bytecode* args = script->ptrReadPos;
191
192 if (isInitialCall) {
193 s32 msgID = evt_get_variable(script, *args++);
194 s32 x = evt_get_variable(script, *args++);
195 s32 y = evt_get_variable(script, *args++);
196 s32* temp802DB264 = &D_802DB264;
197
198 *temp802DB264 = 0;
199 gCurrentPrintContext = msg_get_printer_for_msg(msgID, temp802DB264);
201 }
202
204 return ApiStatus_DONE1;
205 }
206
207 if (D_802DB264 != 1) {
208 return ApiStatus_BLOCK;
209 }
210
211 script->varTable[0] = gCurrentPrintContext->curOption;
212 return ApiStatus_DONE1;
213}
214
215API_CALLABLE(ShowMessageAtWorldPos) {
216 Bytecode* args = script->ptrReadPos;
217 MessagePrintState** currentPrintContext;
218 s32* currentCameraID = &gCurrentCameraID;
219
220 if (isInitialCall) {
221 s32 msgID = evt_get_variable(script, *args++);
222 s32 x = evt_get_variable(script, *args++);
223 s32 y = evt_get_variable(script, *args++);
224 s32 z = evt_get_variable(script, *args++);
225 s32 x2;
226 s32 y2;
227 s32 z2;
228 s32* temp802DB264 = &D_802DB264;
229
230 *temp802DB264 = 0;
231 currentPrintContext = &gCurrentPrintContext;
232 *currentPrintContext = msg_get_printer_for_msg(msgID, temp802DB264);
233 get_screen_coords(*currentCameraID, x, y, z, &x2, &y2, &z2);
234 msg_printer_set_origin_pos(*currentPrintContext, x2, y2);
235 }
236
238 return ApiStatus_DONE1;
239 }
240
241 if (D_802DB264 != 1) {
242 return ApiStatus_BLOCK;
243 }
244
245 script->varTable[0] = gCurrentPrintContext->curOption;
246 return ApiStatus_DONE1;
247}
248
249API_CALLABLE(CloseMessage) {
250 if (isInitialCall) {
252 }
253
255 return ApiStatus_DONE1;
256 } else if (D_802DB264 != 1) {
257 return ApiStatus_BLOCK;
258 } else {
259 script->varTable[0] = gCurrentPrintContext->curOption;
260 return ApiStatus_DONE1;
261 }
262}
263
264API_CALLABLE(SwitchMessage) {
265 Bytecode* args = script->ptrReadPos;
266
267 if (isInitialCall) {
269 }
270
272 return ApiStatus_DONE1;
273 } else if (D_802DB264 != 1) {
274 return ApiStatus_BLOCK;
275 } else {
276 script->varTable[0] = gCurrentPrintContext->curOption;
277 return ApiStatus_DONE1;
278 }
279}
280
281API_CALLABLE(ShowChoice) {
282 Bytecode* args = script->ptrReadPos;
283 MessagePrintState** temp802DB268;
284
285 if (isInitialCall) {
286 s32 msgID = evt_get_variable(script, *args++);
287
288 script->functionTemp[1] = 0;
289 D_802DB268 = msg_get_printer_for_msg(msgID, &script->functionTemp[1]);
290 }
291
292 temp802DB268 = &D_802DB268;
293 script->varTable[0] = gCurrentPrintContext->curOption = (*temp802DB268)->curOption;
294
295 if ((*temp802DB268)->stateFlags & MSG_STATE_FLAG_40) {
296 return ApiStatus_DONE1;
297 }
298
299 return script->functionTemp[1] == 1;
300}
301
302API_CALLABLE(CloseChoice) {
304 return ApiStatus_DONE1;
305}
306
307API_CALLABLE(CancelMessage) {
309 return ApiStatus_DONE2;
310}
311
314 return 0;
315}
316
317API_CALLABLE(SetMessageImages) {
318 Bytecode* args = script->ptrReadPos;
319
321 return ApiStatus_DONE2;
322}
323
324API_CALLABLE(func_802D0C94) {
325 Bytecode* args = script->ptrReadPos;
326
327 if (evt_get_variable(script, *args++) == 0) {
329 } else {
330 gOverrideFlags &= ~GLOBAL_OVERRIDES_MESSAGES_OVER_FRONTUI;
331 }
332 return ApiStatus_DONE2;
333}
334
335API_CALLABLE(SetMessageText) {
336 Bytecode* args = script->ptrReadPos;
337 s32 msg = evt_get_variable(script, *args++);
338 s32 index = evt_get_variable(script, *args++);
339
340 set_message_text_var(msg, index);
341 return ApiStatus_DONE2;
342}
343
344API_CALLABLE(SetMessageValue) {
345 Bytecode* ptrReadPos = script->ptrReadPos;
346 s32 value = evt_get_variable(script, *ptrReadPos++);
347 s32 index = evt_get_variable(script, *ptrReadPos);
348
349 set_message_int_var(value, index);
350 return ApiStatus_DONE2;
351}
Bytecode * ptrReadPos
#define clamp_angle
#define atan2
@ MSG_STATE_FLAG_40
Definition enums.h:6244
@ MSG_STATE_FLAG_SPEAKING
Definition enums.h:6245
@ SPEECH_FLAG_10
Definition enums.h:1936
@ SPEECH_FACE_LIKE_LISTENER
Definition enums.h:1944
@ SPEECH_FACE_SPEAKER_ONLY
Definition enums.h:1941
@ SPEECH_FLAG_HAS_OFFSET
Definition enums.h:1937
@ SPEECH_ORIENTATION_MASK
Definition enums.h:1940
@ SPEECH_FACE_AWAY_FROM
Definition enums.h:1942
@ SPEECH_FACE_EACH_OTHER
Definition enums.h:1945
@ SPEECH_FLAG_200
Definition enums.h:1938
@ SPEECH_FACE_LIKE_SPEAKER
Definition enums.h:1943
@ NPC_PLAYER
Definition enums.h:2527
@ GLOBAL_OVERRIDES_MESSAGES_OVER_FRONTUI
Definition enums.h:4323
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 set_npc_animation(Npc *npc, u32 animID)
Definition npc_api.c:18
void msg_printer_set_origin_pos(MessagePrintState *msgPrintState, s32 x, s32 y)
Definition msg.c:1489
void get_screen_coords(s32 camID, f32 x, f32 y, f32 z, s32 *screenX, s32 *screenY, s32 *screenZ)
Definition cam_main.c:410
s32 cancel_message(MessagePrintState *msgPrintState)
Definition msg.c:1507
void close_message(MessagePrintState *msgPrintState)
Definition msg.c:1568
MessagePrintState * msg_get_printer_for_msg(s32 msgID, s32 *a1)
Definition msg.c:1424
void set_message_int_var(s32 value, s32 index)
Definition msg.c:1550
void set_message_text_var(s32 msgID, s32 index)
Definition msg.c:1520
Npc * resolve_npc(Evt *script, s32 npcIdOrPtr)
Definition npc_api.c:8
void set_message_images(MessageImageData *images)
Definition msg.c:1516
s32 msg_printer_load_msg(s32 msgID, MessagePrintState *printer)
Definition msg.c:1474
s32 ShowMessageScreenOffsetY
Definition script_list.c:37
@ SHOW_MESSAGE_END_SPEECH
Definition msg_api.c:15
@ SHOW_MESSAGE_SPEAK_TO_NPC
Definition msg_api.c:17
@ SHOW_MESSAGE_CONTINUE_SPEECH
Definition msg_api.c:16
@ SHOW_MESSAGE_SPEAK_TO_PLAYER
Definition msg_api.c:14
MessagePrintState * gCurrentPrintContext
Definition script_list.c:38
char D_802DAE60[0x400]
s32 D_802DAE58[2]
ApiStatus _show_message(Evt *script, s32 isInitialCall, s32 mode)
Definition msg_api.c:36
MessagePrintState * D_802DB268
Definition script_list.c:39
s32 ShowMessageScreenOffsetX
Definition script_list.c:36
s32 D_802DB264
Definition script_list.c:40
s32 cancel_current_message(void)
Definition msg_api.c:312
#define EndSpeech(ARGS...)
Definition msg_api.h:10
#define SpeakToNpc(ARGS...)
Definition msg_api.h:18
#define ContinueSpeech(ARGS...)
Definition msg_api.h:14
#define SpeakToPlayer(ARGS...)
Definition msg_api.h:6
ApiStatus SetMessageText(Evt *script, b32 isInitialCall)
ApiStatus ShowMessageAtWorldPos(Evt *script, b32 isInitialCall)
ApiStatus SwitchMessage(Evt *script, b32 isInitialCall)
ApiStatus ShowChoice(Evt *script, b32 isInitialCall)
ApiStatus SetMessageImages(Evt *script, b32 isInitialCall)
ApiStatus CloseMessage(Evt *script, b32 isInitialCall)
ApiStatus func_802D0C94(Evt *script, b32 isInitialCall)
ApiStatus CancelMessage(Evt *script, b32 isInitialCall)
ApiStatus ShowMessageAtScreenPos(Evt *script, b32 isInitialCall)
ApiStatus SetMessageValue(Evt *script, b32 isInitialCall)
ApiStatus CloseChoice(Evt *script, b32 isInitialCall)
AnimID curAnim
s16 collisionHeight
Vec3f pos
s32 gOverrideFlags
Definition main_loop.c:11
PlayerStatus gPlayerStatus
Definition 77480.c:39
s32 gCurrentCameraID
Definition cam_math.c:4