Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
NormalItemChoice.inc.c
Go to the documentation of this file.
1#ifndef _COMMON_CONSUMABLE_CHOICE_
2#define _COMMON_CONSUMABLE_CHOICE_
3
4#include "common.h"
5#include "sprite/player.h"
6
7static s32 N(ItemChoice_List)[ITEM_NUM_CONSUMABLES + 1];
8
9#ifndef _CHOICE_SUPPORT_
10#define _CHOICE_SUPPORT_
11
12s32 N(ItemChoice_HasSelectedItem) = 0;
13s32 N(ItemChoice_SelectedItemID) = 0;
14
17
18API_CALLABLE(N(ItemChoice_WaitForSelection)) {
19 Bytecode* args = script->ptrReadPos;
20
21 if (isInitialCall) {
22 N(ItemChoice_HasSelectedItem) = FALSE;
23 }
24
25 if (N(ItemChoice_HasSelectedItem)) {
26 N(ItemChoice_HasSelectedItem) = FALSE;
27 evt_set_variable(script, *args++, N(ItemChoice_SelectedItemID));
28 return ApiStatus_DONE2;
29 }
30
31 return ApiStatus_BLOCK;
32}
33
34API_CALLABLE(N(ItemChoice_SaveSelected)) {
35 Bytecode* args = script->ptrReadPos;
36
37 N(ItemChoice_SelectedItemID) = evt_get_variable(script, *args);
38 N(ItemChoice_HasSelectedItem) = TRUE;
39 return ApiStatus_DONE2;
40}
41
42#endif
43
44API_CALLABLE(N(BuildItemChoiceList)) {
45 Bytecode* args = script->ptrReadPos;
46 s32* allowedItemList = (s32*)evt_get_variable(script, *args++);
47 s32 i;
48
49 if (allowedItemList != NULL) {
50 for (i = 0; allowedItemList[i] != ITEM_NONE; i++) {
51 N(ItemChoice_List)[i] = allowedItemList[i];
52 }
53 N(ItemChoice_List)[i] = ITEM_NONE;
54 } else {
55 for (i = 0; i < ITEM_NUM_CONSUMABLES; i++) {
56 N(ItemChoice_List)[i] = ITEM_FIRST_CONSUMABLE + i;
57 N(ItemChoice_List)[ITEM_NUM_CONSUMABLES] = ITEM_NONE; // oddity -- should be after the loop!
58 }
59 }
60 return ApiStatus_DONE2;
61}
62
63EvtScript N(EVS_ItemChoicePopup) = {
68 CaseEq(0)
69 CaseEq(-1)
73 Call(N(AddPlayerHandsOffset), LVar3, LVar4, LVar5)
75 Call(SetPlayerAnimation, ANIM_MarioW1_TakeItem)
76 Wait(30)
77 Call(SetPlayerAnimation, ANIM_Mario1_Idle)
80 Call(N(ItemChoice_SaveSelected), LVarA)
82 Unbind
83 Return
84 End
85};
86
87EvtScript N(EVS_ChooseItem) = {
88 Call(N(BuildItemChoiceList), LVar0)
89 BindPadlock(Ref(N(EVS_ItemChoicePopup)), TRIGGER_FORCE_ACTIVATE, 0, Ref(N(ItemChoice_List)), 0, 1)
90 Call(N(ItemChoice_WaitForSelection), LVar0)
91 Return
92 End
93};
94
95#define EVT_CHOOSE_ANY_CONSUMABLE(unkMode) \
96 Set(LVar0, NULL) \
97 Set(LVar1, unkMode) \
98 ExecWait(N(EVS_ChooseItem))
99
100#define EVT_CHOOSE_CONSUMABLE_FROM(itemList, unkMode) \
101 Set(LVar0, Ref(itemList)) \
102 Set(LVar1, unkMode) \
103 ExecWait(N(EVS_ChooseItem))
104
105#endif
Bytecode EvtScript[]
@ ITEM_SPAWN_MODE_DECORATION
Definition enums.h:2292
@ TRIGGER_FORCE_ACTIVATE
Definition enums.h:2675
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
#define ApiStatus_BLOCK
Definition evt.h:116
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
ApiStatus CloseChoicePopup(Evt *script, b32 isInitialCall)
ApiStatus RemoveItemEntity(Evt *script, b32 isInitialCall)
ApiStatus ShowConsumableChoicePopup(Evt *script, b32 isInitialCall)
ApiStatus SetPlayerAnimation(Evt *script, b32 isInitialCall)
ApiStatus MakeItemEntity(Evt *script, b32 isInitialCall)
ApiStatus RemoveItemAt(Evt *script, b32 isInitialCall)
ApiStatus GetPlayerPos(Evt *script, b32 isInitialCall)
#define Switch(LVAR)
Marks the start of a switch statement.
Definition macros.h:311
#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 End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#define Unbind
Unbinds the current thread from the trigger it was bound to, if any.
Definition macros.h:507
#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 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 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 LVar9
Definition macros.h:157
#define EndSwitch
Marks the end of a switch statement and any case.
Definition macros.h:362
#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