Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
LetterDelivery.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "sprite/npc/WorldParakarry.h"
3
6
12
13BSS s32 N(LetterDelivery_SavedNpcAnim);
14
15API_CALLABLE(N(LetterDelivery_Init)) {
16 Bytecode* args = script->ptrReadPos;
17
18 script->varTable[2] = evt_get_variable(script, *args++);
19 script->varTable[3] = evt_get_variable(script, *args++);
20 script->varTable[4] = evt_get_variable(script, *args++);
21 script->varTable[5] = evt_get_variable(script, *args++);
22 script->varTable[6] = evt_get_variable(script, *args++);
23 script->varTable[7] = evt_get_variable(script, *args++);
24 script->varTable[8] = evt_get_variable(script, *args++);
25 script->varTable[9] = evt_get_variable(script, *args++);
26 script->varTable[10] = evt_get_variable(script, *args++);
27 script->varTable[11] = evt_get_variable(script, *args++);
28 return ApiStatus_DONE2;
29}
30
31API_CALLABLE(N(LetterDelivery_CalcLetterPos)) {
32 Bytecode* args = script->ptrReadPos;
33 s32 varX = *args++;
34 f32 x = evt_get_variable(script, varX);
35 s32 varY = *args++;
36 f32 y = evt_get_variable(script, varY);
37 s32 varZ = *args++;
38 f32 z = evt_get_variable(script, varZ);
39 Npc* partner = get_npc_unsafe(NPC_PARTNER);
40 f32 currentCamYaw = clamp_angle(gCameras[gCurrentCameraID].curYaw + 180.0f);
41
42 add_vec2D_polar(&x, &z, 15.0f, partner->yaw);
43 add_vec2D_polar(&x, &z, 10.0f, currentCamYaw);
44
45 evt_set_variable(script, varX, x);
46 evt_set_variable(script, varY, y);
47 evt_set_variable(script, varZ, z);
48
49 return ApiStatus_DONE2;
50}
51
52API_CALLABLE(N(LetterDelivery_SaveNpcAnim)) {
53 Npc* npc = get_npc_unsafe(script->varTable[2]);
54
55 N(LetterDelivery_SavedNpcAnim) = npc->curAnim;
56 npc->curAnim = script->varTable[4];
57 return ApiStatus_DONE2;
58}
59
60API_CALLABLE(N(LetterDelivery_RestoreNpcAnim)) {
61 Npc* npc = get_npc_unsafe(script->varTable[2]);
62
63 npc->curAnim = N(LetterDelivery_SavedNpcAnim);
64 return ApiStatus_DONE2;
65}
66
67EvtScript N(EVS_LetterDelivery_CarryLetter) = {
68 Loop(0)
70 Call(N(LetterDelivery_CalcLetterPos), LVar3, LVar4, LVar5)
72 Wait(1)
74 Return
75 End
76};
77
78EvtScript N(EVS_LetterDelivery_ItemPrompt) = {
83 CaseEq(0)
84 CaseEq(-1)
89 Call(N(LetterDelivery_CalcLetterPos), LVar3, LVar4, LVar5)
92 ExecGetTID(N(EVS_LetterDelivery_CarryLetter), LVarA)
93 Call(SetNpcAnimation, NPC_PARTNER, ANIM_WorldParakarry_Walk)
98 IfLe(LVarB, 180)
99 Add(LVar6, 20)
100 Else
101 Add(LVar6, -20)
102 EndIf
103 Add(LVar7, 10)
108 Wait(20)
110 Add(LVarA, 180)
112 Wait(5)
114 Call(SetNpcAnimation, NPC_PARTNER, ANIM_WorldParakarry_Idle)
116 Wait(5)
119 Wait(5)
121 Call(N(ItemChoice_SaveSelected), LVarA)
123 Unbind
124 Return
125 End
126};
127
128EvtScript N(EVS_ShowLetterChoice) = {
129 Set(LVar0, LVarB)
130 Set(LVar1, LVar2)
131 Call(N(BuildKeyItemChoiceList), LVar0)
132 BindPadlock(N(EVS_LetterDelivery_ItemPrompt), TRIGGER_FORCE_ACTIVATE, 0, Ref(N(KeyItemChoiceList)), 0, 1)
133 Call(N(ItemChoice_WaitForSelection), LVar0)
134 Return
135 End
136};
137
138// returns DeliveryResult on LVarC
139EvtScript N(EVS_DoLetterDelivery) = {
142 Return
143 EndIf
144 Call(N(LetterDelivery_SaveNpcAnim))
148 IfNe(LVar1, -1)
150 Call(PlayerFaceNpc, LVar2, FALSE)
151 Wait(1)
155 Add(LVar0, 10)
157 Call(SpeakToNpc, NPC_PARTNER, ANIM_WorldParakarry_Talk, ANIM_WorldParakarry_Idle, 0, LVar2, LVar7)
159 ExecWait(N(EVS_ShowLetterChoice))
161 CaseEq(-1)
163 Wait(1)
164 Call(SpeakToPlayer, NPC_PARTNER, ANIM_WorldParakarry_Talk, ANIM_WorldParakarry_Idle, 5, LVar8)
169 Wait(1)
170 Call(SpeakToPlayer, NPC_PARTNER, ANIM_WorldParakarry_Talk, ANIM_WorldParakarry_Idle, 5, LVar9)
171 IfNe(LVarA, 0)
173 EndIf
175 IfNe(LVar6, ITEM_NONE)
177 EndIf
180 EndIf
181 EndIf
182 Call(N(LetterDelivery_RestoreNpcAnim))
183 Return
184 End
185};
186
187#define EVT_LETTER_PROMPT(npcName, npcID, animTalk, animIdle, msg1, msg2, ms3, msg4, itemID, itemList) \
188 EvtScript N(EVS_LetterPrompt_##npcName) = { \
189 Call(N(LetterDelivery_Init), \
190 npcID, animTalk, animIdle, \
191 itemID, ITEM_NONE, \
192 msg1, msg2, ms3, msg4, \
193 Ref(itemList)) \
194 ExecWait(N(EVS_DoLetterDelivery)) \
195 Return \
196 End \
197 }
198
199#define EVT_LETTER_REWARD(npcName) \
200 EvtScript N(EVS_LetterReward_##npcName) = { \
201 IfEq(LVarC, DELIVERY_ACCEPTED) \
202 EVT_GIVE_STAR_PIECE() \
203 EndIf \
204 Return \
205 End \
206 }
207
208#define EVT_LETTER_CHECK(npcName) \
209 ExecWait(N(EVS_LetterPrompt_##npcName)) \
210 ExecWait(N(EVS_LetterReward_##npcName))
#define EVT_GIVE_REWARD(itemID)
DeliveryResult
@ DELIVERY_ACCEPTED
@ DELIVERY_NOT_POSSIBLE
@ DELIVERY_REJECTED
Bytecode EvtScript[]
#define clamp_angle
@ STORY_CH2_PARAKARRY_JOINED_PARTY
Definition enums.h:68
@ ITEM_SPAWN_MODE_DECORATION
Definition enums.h:2292
@ VIS_GROUP_5
Definition enums.h:2285
@ NPC_PARTNER
Definition enums.h:2528
@ PARTNER_PARAKARRY
Definition enums.h:2889
@ TRIGGER_FORCE_ACTIVATE
Definition enums.h:2675
@ NPC_FLAG_IGNORE_PLAYER_COLLISION
Definition enums.h:3006
#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
s32 evt_set_variable(Evt *script, Bytecode var, s32 value)
Definition evt.c:1847
void add_vec2D_polar(f32 *x, f32 *y, f32 r, f32 theta)
Definition 43F0.c:685
#define SpeakToNpc(ARGS...)
Definition msg_api.h:18
#define SpeakToPlayer(ARGS...)
Definition msg_api.h:6
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
@ GB_StoryProgress
ApiStatus CloseChoicePopup(Evt *script, b32 isInitialCall)
ApiStatus RemoveItemEntity(Evt *script, b32 isInitialCall)
ApiStatus DisablePartnerAI(Evt *script, b32 isInitialCall)
ApiStatus SetItemPos(Evt *script, b32 isInitialCall)
ApiStatus GetNpcPos(Evt *script, b32 isInitialCall)
ApiStatus GetCurrentPartnerID(Evt *script, b32 isInitialCall)
ApiStatus SetNpcAnimation(Evt *script, b32 isInitialCall)
ApiStatus EnablePartnerAI(Evt *script, b32 isInitialCall)
ApiStatus NpcFaceNpc(Evt *script, b32 isInitialCall)
ApiStatus GetNpcYaw(Evt *script, b32 isInitialCall)
ApiStatus InterpNpcYaw(Evt *script, b32 isInitialCall)
ApiStatus PlayerFaceNpc(Evt *script, b32 isInitialCall)
ApiStatus NpcJump1(Evt *script, b32 isInitialCall)
ApiStatus MakeItemEntity(Evt *script, b32 isInitialCall)
ApiStatus SetNpcJumpscale(Evt *script, b32 isInitialCall)
ApiStatus GetAngleBetweenNPCs(Evt *script, b32 isInitialCall)
ApiStatus SetNpcFlagBits(Evt *script, b32 isInitialCall)
ApiStatus RemoveKeyItemAt(Evt *script, b32 isInitialCall)
ApiStatus FindItem(Evt *script, b32 isInitialCall)
ApiStatus ShowKeyChoicePopup(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 Switch(LVAR)
Marks the start of a switch statement.
Definition macros.h:311
#define LVar6
Definition macros.h:154
#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 CaseEq(RVAR)
Marks the start of a switch case that executes only if LVAR == RVAR. It also marks the end of any pre...
Definition macros.h:319
#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 Add(VAR, INT_VALUE)
Definition macros.h:376
#define EndLoop
Marks the end of a loop.
Definition macros.h:248
#define Unbind
Unbinds the current thread from the trigger it was bound to, if any.
Definition macros.h:507
#define BSS
Definition macros.h:7
#define LVarC
Definition macros.h:160
#define BindPadlock(EVT_SOURCE, TRIGGER, COLLIDER_ID, ITEM_LIST, UNK_A3, TRIGGER_PTR_OUTVAR)
Similar to BindTrigger, but also takes arguments for the item list to show.
Definition macros.h:503
#define IfLt(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR < RVAR.
Definition macros.h:275
#define Float(DOUBLE)
Definition macros.h:51
#define EndIf
Marks the end of an if statement or an else block.
Definition macros.h:298
#define LVar5
Definition macros.h:153
#define CaseDefault
Marks the start of a switch case that executes unconditionally. It also marks the end of any previous...
Definition macros.h:337
#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 IfLe(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR > RVAR.
Definition macros.h:281
#define KillThread(TID)
Kills a thread by its thread ID.
Definition macros.h:510
#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 ExecGetTID(EVT_SOURCE, OUTVAR)
Identical to Exec, but the newly-launched thread ID is stored in OUTVAR.
Definition macros.h:460
#define Wait(NUM_FRAMES)
Blocks for the given number of frames.
Definition macros.h:254
#define LVar9
Definition macros.h:157
#define EndSwitch
Marks the end of a switch statement and any case.
Definition macros.h:362
#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 BitwiseOrConst(VAR, CONST)
VAR |= CONST, but CONST is treated as-is rather than dereferenced with evt_get_variable.
Definition macros.h:445
#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 Return
Kills the current EVT thread.
Definition macros.h:217
AnimID curAnim
Camera gCameras[4]
Definition cam_main.c:17
s32 gCurrentCameraID
Definition cam_math.c:4