Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
item_api.c
Go to the documentation of this file.
1#include "common.h"
2#include "inventory.h"
4#include "hud_element.h"
5#include "world/partners.h"
6
8
9API_CALLABLE(ShowKeyChoicePopup) {
10 PlayerData* playerData = &gPlayerData;
12 Trigger* trigger = script->owner2.trigger;
13 s32 numEntries;
14 s32 i;
15
16 if (isInitialCall) {
17 script->functionTemp[0] = 0;
18 }
19
20 switch (script->functionTemp[0]) {
21 case 0:
26 numEntries = 0;
27
29
30 for (i = 0; i < ARRAY_COUNT(playerData->keyItems); i++) {
31 s16 invItem = playerData->keyItems[i];
32
33 if (invItem != ITEM_NONE) {
34 s32 found = FALSE;
35 s32* itemIt = trigger->itemList;
36
37 while (*itemIt > 0) {
38 if (invItem == *itemIt) {
39 found = TRUE;
40 break;
41 }
42 itemIt++;
43 }
44
45 if (found) {
46 ItemData* item = &gItemTable[playerData->keyItems[i]];
47
48 menu->ptrIcon[numEntries] = gItemHudScripts[item->hudElemID].enabled;
49 menu->userIndex[numEntries] = i;
50 menu->enabled[numEntries] = TRUE;
51 menu->nameMsg[numEntries] = item->nameMsg;
52 menu->descMsg[numEntries] = item->shortDescMsg;
53 numEntries++;
54 }
55 }
56 }
57
58 if (numEntries == 0) {
59 script->varTable[0] = 0;
60 return ApiStatus_DONE1;
61 }
63 menu->numEntries = numEntries;
64 menu->initialPos = 0;
66 script->functionTemp[1] = 0;
67 script->functionTemp[0] = 1;
68 break;
69 case 1:
70 if (script->functionTemp[1] == 0) {
71 script->functionTemp[2] = menu->result;
72 if (script->functionTemp[2] == 0) {
73 break;
74 }
76 }
77
78 script->functionTemp[1]++;
79 if (script->functionTemp[1] >= 15) {
81
82 if (script->functionTemp[2] == 0xFF) {
83 script->varTable[0] = -1;
84 } else {
85 s32 invIndex = menu->userIndex[script->functionTemp[2] - 1];
86 script->varTable[1] = invIndex;
87 script->varTable[0] = playerData->keyItems[invIndex];
88 }
89 return ApiStatus_DONE1;
90 }
91 break;
92 }
93 return ApiStatus_BLOCK;
94}
95
96API_CALLABLE(ShowConsumableChoicePopup) {
97 PlayerData* playerData = &gPlayerData;
99 Trigger* trigger = script->owner2.trigger;
100 s32 numEntries;
101 s32 i;
102
103 if (isInitialCall) {
104 script->functionTemp[0] = 0;
105 }
106
107 switch (script->functionTemp[0]) {
108 case 0:
113 numEntries = 0;
114
116
117 for (i = 0; i < ARRAY_COUNT(playerData->invItems); i++) {
118 s16 invItem = playerData->invItems[i];
119
120 if (invItem != ITEM_NONE) {
121 s32 found = FALSE;
122 s32* itemIt = trigger->itemList;
123
124 while (*itemIt > 0) {
125 if (invItem == *itemIt) {
126 found = TRUE;
127 break;
128 }
129 itemIt++;
130 }
131
132 if (found) {
133 ItemData* item = &gItemTable[playerData->invItems[i]];
134
135 menu->ptrIcon[numEntries] = gItemHudScripts[item->hudElemID].enabled;
136 menu->userIndex[numEntries] = i;
137 menu->enabled[numEntries] = TRUE;
138 menu->nameMsg[numEntries] = item->nameMsg;
139 menu->descMsg[numEntries] = item->shortDescMsg;
140 numEntries++;
141 }
142 }
143 }
144
145 if (numEntries == 0) {
146 script->varTable[0] = 0;
147 return ApiStatus_DONE1;
148 }
150 menu->numEntries = numEntries;
151 menu->initialPos = 0;
153 script->functionTemp[1] = 0;
154 script->functionTemp[0] = 1;
155 break;
156 case 1:
157 if (script->functionTemp[1] == 0) {
158 script->functionTemp[2] = menu->result;
159 if (script->functionTemp[2] == 0) {
160 break;
161 }
163 }
164
165 script->functionTemp[1]++;
166 if (script->functionTemp[1] >= 15) {
168
169 if (script->functionTemp[2] == 0xFF) {
170 script->varTable[0] = -1;
171 } else {
172 s32 invIdx = menu->userIndex[script->functionTemp[2] - 1];
173 script->varTable[1] = invIdx;
174 script->varTable[0] = playerData->invItems[invIdx];
175 }
176 return ApiStatus_DONE1;
177 }
178 break;
179 }
180 return ApiStatus_BLOCK;
181}
182
183API_CALLABLE(RemoveItemAt) {
184 Bytecode* args = script->ptrReadPos;
185 s32 index = evt_get_variable(script, *args++);
186
187 gPlayerData.invItems[index] = ITEM_NONE;
189 return ApiStatus_DONE2;
190}
191
192API_CALLABLE(RemoveKeyItemAt) {
193 Bytecode* args = script->ptrReadPos;
194 s32 index = evt_get_variable(script, *args++);
195
196 gPlayerData.keyItems[index] = ITEM_NONE;
197 return ApiStatus_DONE2;
198}
199
200API_CALLABLE(CloseChoicePopup) {
204 gOverrideFlags &= ~GLOBAL_OVERRIDES_40;
205 return ApiStatus_DONE2;
206}
207
208API_CALLABLE(AddItem) {
209 Bytecode* args = script->ptrReadPos;
210 s32 itemID = evt_get_variable(script, *args++);
211 Bytecode outVar = *args++;
212
213 s32 addedIdx = add_item(itemID);
214
215 evt_set_variable(script, outVar, addedIdx);
216 return ApiStatus_DONE2;
217}
218
219API_CALLABLE(RemoveItem) {
220 Bytecode* args = script->ptrReadPos;
221 s32 itemID = evt_get_variable(script, *args++);
222 Bytecode outVar = *args++;
223
224 s32 removedIdx = remove_item(itemID);
225
226 evt_set_variable(script, outVar, removedIdx);
227 return ApiStatus_DONE2;
228}
229
230API_CALLABLE(FindItem) {
231 Bytecode* args = script->ptrReadPos;
232 s32 itemID = evt_get_variable(script, *args++);
233 Bytecode outVar = *args++;
234
235 s32 foundIdx = find_item(itemID);
236
237 evt_set_variable(script, outVar, foundIdx);
238 return ApiStatus_DONE2;
239}
240
241API_CALLABLE(CountItem) {
242 Bytecode* args = script->ptrReadPos;
243 s32 itemID = evt_get_variable(script, *args++);
244 Bytecode outVar = *args++;
245
246 b32 count = count_item(itemID);
247
248 evt_set_variable(script, outVar, count);
249 return ApiStatus_DONE2;
250}
251
252API_CALLABLE(HasItem) {
253 Bytecode* args = script->ptrReadPos;
254 s32 itemID = evt_get_variable(script, *args++);
255 Bytecode outVar = *args++;
256
257 b32 hasItem = has_item(itemID);
258
259 evt_set_variable(script, outVar, hasItem);
260 return ApiStatus_DONE2;
261}
262
263API_CALLABLE(MakeItemEntity) {
264 Bytecode* args = script->ptrReadPos;
265 s32 itemID = evt_get_variable(script, *args++);
266 s32 x = evt_get_variable(script, *args++);
267 s32 y = evt_get_variable(script, *args++);
268 s32 z = evt_get_variable(script, *args++);
269 s32 itemSpawnMode = evt_get_variable(script, *args++);
270 s32 pickupVar = evt_get_variable_index(script, *args++);
271
272 script->varTable[0] = make_item_entity_nodelay(itemID, x, y, z, itemSpawnMode, pickupVar);
273 return ApiStatus_DONE2;
274}
275
276API_CALLABLE(DropItemEntity) {
277 Bytecode* args = script->ptrReadPos;
278 s32 itemID = evt_get_variable(script, *args++);
279 s32 x = evt_get_variable(script, *args++);
280 s32 y = evt_get_variable(script, *args++);
281 s32 z = evt_get_variable(script, *args++);
282 s32 itemSpawnMode = evt_get_variable(script, *args++);
283 s32 pickupVar = evt_get_variable(script, *args++);
284
285 script->varTable[0] = make_item_entity_nodelay(itemID, x, y, z, itemSpawnMode, pickupVar);
286 return ApiStatus_DONE2;
287}
288
289API_CALLABLE(DropResizableItemEntity) {
290 Bytecode* args = script->ptrReadPos;
291 s32 itemID = evt_get_variable(script, *args++);
292 s32 x = evt_get_variable(script, *args++);
293 s32 y = evt_get_variable(script, *args++);
294 s32 z = evt_get_variable(script, *args++);
295 s32 itemSpawnMode = evt_get_variable(script, *args++);
296 s32 pickupVar = evt_get_variable_index(script, *args++);
297
298 script->varTable[0] = make_item_entity_nodelay(itemID, x, y, z, itemSpawnMode, pickupVar);
299 set_item_entity_flags(script->varTable[0], ITEM_ENTITY_RESIZABLE);
300 return ApiStatus_DONE2;
301}
302
303API_CALLABLE(RemoveItemEntity) {
304 Bytecode* args = script->ptrReadPos;
305 s32 itemEntityIndex = evt_get_variable(script, *args++);
306
307 remove_item_entity_by_index(itemEntityIndex);
308 return ApiStatus_DONE2;
309}
310
311API_CALLABLE(SetItemPos) {
312 Bytecode* args = script->ptrReadPos;
313 ItemEntity* ptrItemEntity;
314 s32 itemEntityIndex;
315 s32 x, y, z;
316
317 itemEntityIndex = evt_get_variable(script, *args++);
318 x = evt_get_variable(script, *args++);
319 y = evt_get_variable(script, *args++);
320 z = evt_get_variable(script, *args++);
321
322 ptrItemEntity = (ItemEntity*) get_item_entity(itemEntityIndex);
323 ptrItemEntity->pos.x = x;
324 ptrItemEntity->pos.y = y;
325 ptrItemEntity->pos.z = z;
326 return ApiStatus_DONE2;
327}
328
329API_CALLABLE(SetItemFlags) {
330 Bytecode* args = script->ptrReadPos;
331 s32 itemEntityIndex = evt_get_variable(script, *args++);
332 s32 flagBits = *args++;
333 s32 mode = evt_get_variable(script, *args++);
334 ItemEntity* itemEntity = get_item_entity(itemEntityIndex);
335
336 if (mode != 0) {
337 itemEntity->flags |= flagBits;
338 } else {
339 itemEntity->flags &= ~flagBits;
340 }
341 return ApiStatus_DONE2;
342}
343
344API_CALLABLE(SetItemAlpha) {
345 Bytecode* args = script->ptrReadPos;
346 s32 itemEntityIndex = evt_get_variable(script, *args++);
347 s32 alpha = evt_get_variable(script, *args++);
348 ItemEntity* itemEntity = get_item_entity(itemEntityIndex);
349
350 itemEntity->alpha = alpha;
351 return ApiStatus_DONE2;
352}
353
354API_CALLABLE(AddCoin) {
355 script->varTable[0] = add_coins(evt_get_variable(script, *script->ptrReadPos));
356 return ApiStatus_DONE2;
357}
358
359API_CALLABLE(AddStarPoints) {
360 script->varTable[0] = add_star_points(evt_get_variable(script, *script->ptrReadPos));
361 return ApiStatus_DONE2;
362}
363
364API_CALLABLE(AddStarPieces) {
365 script->varTable[0] = add_star_pieces(evt_get_variable(script, *script->ptrReadPos));
366 return ApiStatus_DONE2;
367}
368
369API_CALLABLE(GetItemPower) {
370 Bytecode* args = script->ptrReadPos;
371 s32 itemIdx = evt_get_variable(script, *args++);
372 Bytecode out1 = *args++;
373 Bytecode out2 = *args++;
374
375 evt_set_variable(script, out1, (&gItemTable[itemIdx])->potencyA);
376 evt_set_variable(script, out2, (&gItemTable[itemIdx])->potencyB);
377 return ApiStatus_DONE2;
378}
379
380API_CALLABLE(ShowGotItem) {
381 Bytecode* args = script->ptrReadPos;
382 s32 itemID, unkCond, pickupMsgFlags;
383
384 if (isInitialCall) {
385 script->functionTemp[0] = FALSE;
386 }
387
388 if (script->functionTemp[0]) {
389 if (get_item_entity(script->functionTemp[1]) == NULL) {
390 return ApiStatus_DONE2;
391 }
392 } else {
393 itemID = evt_get_variable(script, *args++);
394 unkCond = evt_get_variable(script, *args++);
395 pickupMsgFlags = *args++;
396 script->functionTemp[1] = make_item_entity_at_player(itemID, unkCond, pickupMsgFlags);
397 script->functionTemp[0] = TRUE;
398 }
399 return ApiStatus_BLOCK;
400}
void create_standard_popup_menu(PopupMenu *popup)
IconHudScriptPair gItemHudScripts[]
s32 b32
s16 keyItems[32]
s16 invItems[10]
@ ITEM_ENTITY_RESIZABLE
Definition enums.h:2708
@ POPUP_MENU_USEKEY
Definition enums.h:3143
@ GLOBAL_OVERRIDES_40
Definition enums.h:4325
#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_index(Evt *script, s32 var)
Definition evt.c:1761
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
s32 add_star_pieces(s32 amt)
Definition inventory.c:2104
void hide_popup_menu(void)
void partner_disable_input(void)
Definition partners.c:2489
void sort_consumables(void)
Bubbles up player inventory items such that all ITEM_NONE values are at the bottom.
Definition inventory.c:404
s32 disable_player_input(void)
Definition 77480.c:990
ItemEntity * get_item_entity(s32 itemEntityIndex)
s32 make_item_entity_at_player(s32 itemID, s32 arg1, s32 pickupMsgFlags)
s32 disable_player_static_collisions(void)
Definition 77480.c:972
s32 evt_set_variable(Evt *script, Bytecode var, s32 value)
Definition evt.c:1847
void close_status_bar(void)
Definition inventory.c:1440
s32 make_item_entity_nodelay(s32 itemID, f32 x, f32 y, f32 z, s32 itemSpawnMode, s32 pickupVar)
s32 enable_player_input(void)
Definition 77480.c:998
void destroy_popup_menu(void)
s32 add_star_points(s32 amt)
Definition inventory.c:2086
s32 find_item(s32)
Search player inventory for itemID and return first matching array index.
Definition inventory.c:258
void remove_item_entity_by_index(s32 index)
s32 enable_player_static_collisions(void)
Definition 77480.c:980
void set_item_entity_flags(s32 itemEntityIndex, s32 flag)
s32 add_coins(s32 amt)
Definition inventory.c:2065
s32 userIndex[32]
s32 nameMsg[32]
HudScript * ptrIcon[32]
s32 enabled[32]
HudScript * enabled
s32 descMsg[32]
s32 count_item(s32 itemID)
Search player inventory for itemID and count the number matches.
Definition inventory.c:304
s32 remove_item(s32 itemID)
Remove first instance of itemID found in player inventory.
Definition inventory.c:198
b32 has_item(s32 itemID)
Check whether player has itemID in their inventory.
Definition inventory.c:337
s32 add_item(s32 itemID)
Add itemID to player inventory and return inventory slot in which it was placed.
Definition inventory.c:146
PopupMenu gItemChoicePopupMenu
Definition script_list.c:55
void partner_enable_input(void)
Definition partners.c:2480
ApiStatus CloseChoicePopup(Evt *script, b32 isInitialCall)
ApiStatus AddItem(Evt *script, b32 isInitialCall)
ApiStatus RemoveItemEntity(Evt *script, b32 isInitialCall)
ApiStatus ShowConsumableChoicePopup(Evt *script, b32 isInitialCall)
ApiStatus AddStarPieces(Evt *script, b32 isInitialCall)
ApiStatus RemoveItem(Evt *script, b32 isInitialCall)
ApiStatus SetItemAlpha(Evt *script, b32 isInitialCall)
ApiStatus SetItemPos(Evt *script, b32 isInitialCall)
ApiStatus SetItemFlags(Evt *script, b32 isInitialCall)
ApiStatus DropItemEntity(Evt *script, b32 isInitialCall)
ApiStatus HasItem(Evt *script, b32 isInitialCall)
ApiStatus MakeItemEntity(Evt *script, b32 isInitialCall)
ApiStatus AddStarPoints(Evt *script, b32 isInitialCall)
ApiStatus ShowGotItem(Evt *script, b32 isInitialCall)
ApiStatus AddCoin(Evt *script, b32 isInitialCall)
ApiStatus DropResizableItemEntity(Evt *script, b32 isInitialCall)
ApiStatus GetItemPower(Evt *script, b32 isInitialCall)
ApiStatus RemoveItemAt(Evt *script, b32 isInitialCall)
ApiStatus RemoveKeyItemAt(Evt *script, b32 isInitialCall)
ApiStatus FindItem(Evt *script, b32 isInitialCall)
ApiStatus ShowKeyChoicePopup(Evt *script, b32 isInitialCall)
#define ARRAY_COUNT(arr)
Definition macros.h:40
s32 * itemList
s32 gOverrideFlags
Definition main_loop.c:11
ItemData gItemTable[]
PlayerData gPlayerData
Definition 77480.c:40