Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
KeyItemChoice.inc.c
Go to the documentation of this file.
1#ifndef _COMMON_KEY_CHOICE_
2#define _COMMON_KEY_CHOICE_
3
4#include "common.h"
5#include "sprite/player.h"
6#include "inventory.h"
7
8static s32 N(KeyItemChoiceList)[ITEM_NUM_KEYS + 1];
9
10#ifndef _CHOICE_SUPPORT_
11#define _CHOICE_SUPPORT_
12
13s32 N(ItemChoice_HasSelectedItem) = 0;
14s32 N(ItemChoice_SelectedItemID) = 0;
15
18
19API_CALLABLE(N(ItemChoice_WaitForSelection)) {
20 Bytecode* args = script->ptrReadPos;
21
22 if (isInitialCall) {
23 N(ItemChoice_HasSelectedItem) = FALSE;
24 }
25
26 if (N(ItemChoice_HasSelectedItem)) {
27 N(ItemChoice_HasSelectedItem) = FALSE;
28 evt_set_variable(script, *args++, N(ItemChoice_SelectedItemID));
29 return ApiStatus_DONE2;
30 }
31
32 return ApiStatus_BLOCK;
33}
34
35API_CALLABLE(N(ItemChoice_SaveSelected)) {
36 Bytecode* args = script->ptrReadPos;
37
38 N(ItemChoice_SelectedItemID) = evt_get_variable(script, *args);
39 N(ItemChoice_HasSelectedItem) = TRUE;
40 return ApiStatus_DONE2;
41}
42
43#endif
44
45API_CALLABLE(N(BuildKeyItemChoiceList)) {
46 Bytecode* args = script->ptrReadPos;
47 s32* allowedItemList = (s32*)evt_get_variable(script, *args++);
48 s32 i;
49
50 if (allowedItemList != NULL) {
51 for (i = 0; allowedItemList[i] != ITEM_NONE; i++) {
52 N(KeyItemChoiceList)[i] = allowedItemList[i];
53 }
54 N(KeyItemChoiceList)[i] = ITEM_NONE;
55 } else {
56 s32 pos = 0;
57 for (i = 0; i < NUM_ITEMS; i++) {
58 if (item_is_key(i)) {
59 N(KeyItemChoiceList)[pos++] = i;
60 }
61 }
62 N(KeyItemChoiceList)[pos] = ITEM_NONE;
63 }
64 return ApiStatus_DONE2;
65}
66
67EvtScript N(EVS_KeyItemChoicePopup) = {
72 CaseEq(0)
73 CaseEq(-1)
77 Call(N(AddPlayerHandsOffset), LVar3, LVar4, LVar5)
78 BitwiseOrConst(LVar0, ITEM_VIS_GROUP(ITEM_NONE, 5))
80 Call(SetPlayerAnimation, ANIM_MarioW1_TakeItem)
81 Wait(30)
82 Call(SetPlayerAnimation, ANIM_Mario1_Idle)
85 Call(N(ItemChoice_SaveSelected), LVarA)
87 Unbind
88 Return
89 End
90};
91
92EvtScript N(EVS_ChooseKeyItem) = {
93 Call(N(BuildKeyItemChoiceList), LVar0)
94 BindPadlock(Ref(N(EVS_KeyItemChoicePopup)), TRIGGER_FORCE_ACTIVATE, 0, Ref(N(KeyItemChoiceList)), 0, 1)
95 Call(N(ItemChoice_WaitForSelection), LVar0)
96 Return
97 End
98};
99
100#define EVT_CHOOSE_ANY_KEY_ITEM() \
101 Set(LVar0, NULL) \
102 Set(LVar1, 0) \
103 ExecWait(N(EVS_ChooseKeyItem))
104
105#define EVT_CHOOSE_KEY_ITEM_FROM(itemList) \
106 Set(LVar0, Ref(itemList)) \
107 Set(LVar1, 0) \
108 ExecWait(N(EVS_ChooseKeyItem))
109
110#endif
Bytecode EvtScript[]
Vec3s pos
Definition demo_api.c:17
@ 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 SetPlayerAnimation(Evt *script, b32 isInitialCall)
ApiStatus MakeItemEntity(Evt *script, b32 isInitialCall)
ApiStatus GetPlayerPos(Evt *script, b32 isInitialCall)
ApiStatus RemoveKeyItemAt(Evt *script, b32 isInitialCall)
ApiStatus ShowKeyChoicePopup(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 ITEM_VIS_GROUP(itemID, visGroupID)
Definition macros.h:181
#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 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 LVar0
Definition macros.h:148
#define Return
Kills the current EVT thread.
Definition macros.h:217