Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
use_items.c
Go to the documentation of this file.
1#include "common.h"
2#include "ld_addrs.h"
3#include "battle.h"
4
33
34#define GENERIC_FOOD_ITEM -1
35
36// items in this list must correspond with BattleMoveEntry in gBattleItemTable
37s32 ItemKeys[] = {
39 ITEM_MUSHROOM,
40 ITEM_FIRE_FLOWER,
41 ITEM_DUSTY_HAMMER,
42 ITEM_POW_BLOCK,
43 ITEM_PEBBLE,
44 ITEM_VOLT_SHROOM,
45 ITEM_THUNDER_RAGE,
46 ITEM_SNOWMAN_DOLL,
47 ITEM_DRIED_SHROOM,
48 ITEM_SHOOTING_STAR,
49 ITEM_SLEEPY_SHEEP,
50 ITEM_STONE_CAP,
51 ITEM_TASTY_TONIC,
52 ITEM_THUNDER_BOLT,
53 ITEM_SUPER_SHROOM,
54 ITEM_ULTRA_SHROOM,
55 ITEM_SUPER_SODA,
56 ITEM_HUSTLE_DRINK,
57 ITEM_STOP_WATCH,
58 ITEM_DIZZY_DIAL,
59 ITEM_PLEASE_COME_BACK,
60 ITEM_EGG_MISSILE,
61 ITEM_INSECTICIDE_HERB,
62 ITEM_FRIGHT_JAR,
63 ITEM_MYSTERY,
64 ITEM_REPEL_GEL,
65 ITEM_LIFE_SHROOM,
66 ITEM_COCONUT,
67 ITEM_ELECTRO_POP,
68 ITEM_STRANGE_CAKE,
69 ITEM_KOOKY_COOKIE,
70 ITEM_NONE
71};
72
74 BTL_ITEM(food),
75 BTL_ITEM(mushroom),
76 BTL_ITEM(fire_flower),
77 BTL_ITEM(dusty_hammer),
78 BTL_ITEM(pow_block),
79 BTL_ITEM(pebble),
80 BTL_ITEM(volt_shroom),
81 BTL_ITEM(thunder_rage),
82 BTL_ITEM(snowman_doll),
83 BTL_ITEM(mushroom),
84 BTL_ITEM(shooting_star),
85 BTL_ITEM(sleepy_sheep),
86 BTL_ITEM(stone_cap),
87 BTL_ITEM(tasty_tonic),
88 BTL_ITEM(thunder_bolt),
89 BTL_ITEM(mushroom),
90 BTL_ITEM(mushroom),
91 BTL_ITEM(super_soda),
92 BTL_ITEM(hustle_drink),
93 BTL_ITEM(stop_watch),
94 BTL_ITEM(dizzy_dial),
95 BTL_ITEM(please_come_back),
96 BTL_ITEM(egg_missile),
97 BTL_ITEM(insecticide_herb),
98 BTL_ITEM(fright_jar),
99 BTL_ITEM(mystery),
100 BTL_ITEM(repel_gel),
101 BTL_ITEM(life_shroom),
102 BTL_ITEM(coconut),
103 BTL_ITEM(electro_pop),
104 BTL_ITEM(strange_cake),
105 BTL_ITEM(strange_cake),
106};
107
108// Offsets into gBattleItemTable?
109u16 D_80293E04[] = {
110 1, 31, 1, 5, 1, 2, 9, 3, 9, 3, 9, 1, 10, 6, 10, 6, 10, 4, 11, 8, 11, 8, 11, 4, 12, 3, 12, 3, 12, 1,
111};
112
113API_CALLABLE(LoadItemScript) {
114 PlayerData* playerData = &gPlayerData;
115 BattleStatus* battleStatus = &gBattleStatus;
116 s16 itemID = battleStatus->moveArgument;
117 ItemData* item = &gItemTable[itemID];
118 s32 i = 0;
119 s32* itemPtr;
120
121 while (TRUE) {
122 if (playerData->invItems[i] == itemID) {
123 playerData->invItems[i] = ITEM_NONE;
124 break;
125 }
126 i++;
127 }
129
130 if (battleStatus->selectedMoveID == MOVE_DOUBLE_DIP) {
131 if (battleStatus->itemUsesLeft == 2) {
133 }
134 }
135
136 if (battleStatus->selectedMoveID == MOVE_TRIPLE_DIP) {
137 if (battleStatus->itemUsesLeft == 3) {
139 }
140 }
141
142 itemPtr = &ItemKeys[0];
143 for (i = 0; *itemPtr != ITEM_NONE; i++, itemPtr++) {
144 if (*itemPtr == battleStatus->moveArgument) {
145 break;
146 }
147 }
148
149 if (*itemPtr == ITEM_NONE) {
151 i = 0;
152 } else {
153 i = 1;
154 }
155 }
156
157 dma_copy(gBattleItemTable[i].romStart, gBattleItemTable[i].romEnd, gBattleItemTable[i].vramStart);
158
159 script->varTablePtr[0] = gBattleItemTable[i].mainScript;
160 script->varTable[1] = FALSE;
161
162 return ApiStatus_DONE2;
163}
164
165API_CALLABLE(LoadMysteryItemScript) {
166 BattleStatus* battleStatus = &gBattleStatus;
167 Actor* actor = battleStatus->playerActor;
168 ItemData* item = &gItemTable[battleStatus->moveArgument];
169 SelectableTarget* target;
170 s32* itemPtr;
171 s32 i;
172
174 battleStatus->curAttackElement = 0;
175
177 target = &actor->targetData[actor->targetIndexList[0]];
178
179 battleStatus->curTargetID = target->actorID;
180 battleStatus->curTargetPart = target->partID;
181
182 itemPtr = &ItemKeys[0];
183 for (i = 0; *itemPtr != ITEM_NONE; i++, itemPtr++) {
184 if (*itemPtr == battleStatus->moveArgument){
185 break;
186 }
187 }
188
189 if (*itemPtr == ITEM_NONE) {
191 i = 0;
192 } else {
193 i = 1;
194 }
195 }
196
197 dma_copy(gBattleItemTable[i].romStart, gBattleItemTable[i].romEnd, gBattleItemTable[i].vramStart);
198 script->varTablePtr[0] = gBattleItemTable[i].mainScript;
199 script->varTable[1] = TRUE;
200 return ApiStatus_DONE2;
201}
202
204 Wait(2)
205 Call(LoadMysteryItemScript)
207 Return
208 End
209};
struct SelectableTarget targetData[24]
s8 targetIndexList[24]
Bytecode EvtScript[]
s16 invItems[10]
@ ITEM_TYPE_FLAG_FOOD_OR_DRINK
Definition enums.h:1840
@ TARGET_FLAG_PRIMARY_ONLY
Definition enums.h:1863
#define ApiStatus_DONE2
Definition evt.h:118
void sort_consumables(void)
Bubbles up player inventory items such that all ITEM_NONE values are at the bottom.
Definition inventory.c:404
u32 dma_copy(Addr romStart, Addr romEnd, void *vramDest)
Definition 43F0.c:444
void deduct_current_move_fp(void)
Definition 190B20.c:961
void create_current_pos_target_list(Actor *actor)
Definition 190B20.c:472
#define End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#define ExecWait(EVT_SOURCE)
Launches a new child thread.
Definition macros.h:475
#define Wait(NUM_FRAMES)
Blocks for the given number of frames.
Definition macros.h:254
#define Call(FUNC, ARGS...)
Calls a given C EVT API function with any number of arguments.
Definition macros.h:576
#define LVar0
Definition macros.h:148
#define Return
Kills the current EVT thread.
Definition macros.h:217
EvtScript * mainScript
Definition battle.h:111
#define BTL_ITEM(name)
Definition battle.h:122
struct Actor * playerActor
EvtScript battle_item_stone_cap_EVS_UseItem
EvtScript battle_item_hustle_drink_EVS_UseItem
EvtScript battle_item_fire_flower_EVS_UseItem
EvtScript battle_item_repel_gel_EVS_UseItem
EvtScript battle_item_volt_shroom_EVS_UseItem
EvtScript battle_item_snowman_doll_EVS_UseItem
EvtScript EVS_UseMystery
Definition use_items.c:203
EvtScript battle_item_egg_missile_EVS_UseItem
EvtScript battle_item_pow_block_EVS_UseItem
EvtScript battle_item_super_soda_EVS_UseItem
EvtScript battle_item_strange_cake_EVS_UseItem
EvtScript battle_item_pebble_EVS_UseItem
EvtScript battle_item_shooting_star_EVS_UseItem
EvtScript battle_item_mystery_EVS_UseItem
EvtScript battle_item_life_shroom_EVS_UseItem
EvtScript battle_item_fright_jar_EVS_UseItem
s32 ItemKeys[]
Definition use_items.c:37
EvtScript battle_item_tasty_tonic_EVS_UseItem
EvtScript battle_item_stop_watch_EVS_UseItem
BattleMoveEntry gBattleItemTable[]
Definition use_items.c:73
EvtScript battle_item_thunder_rage_EVS_UseItem
EvtScript battle_item_insecticide_herb_EVS_UseItem
u16 D_80293E04[]
Definition use_items.c:109
EvtScript battle_item_dusty_hammer_EVS_UseItem
EvtScript battle_item_please_come_back_EVS_UseItem
EvtScript battle_item_dizzy_dial_EVS_UseItem
#define GENERIC_FOOD_ITEM
Definition use_items.c:34
EvtScript battle_item_sleepy_sheep_EVS_UseItem
EvtScript battle_item_mushroom_EVS_UseItem
EvtScript battle_item_thunder_bolt_EVS_UseItem
EvtScript battle_item_coconut_EVS_UseItem
EvtScript battle_item_food_EVS_UseItem
EvtScript battle_item_electro_pop_EVS_UseItem
ItemData gItemTable[]
PlayerData gPlayerData
Definition 77480.c:40
BattleStatus gBattleStatus
Definition battle.c:11