Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
mystery.c
Go to the documentation of this file.
1#include "common.h"
2#include "script_api/battle.h"
3#include "effects.h"
4#include "entity.h"
5#include "ld_addrs.h"
6#include "include_asset.h"
7
8#define NAMESPACE battle_item_mystery
9
11
13
14static s32 _pad = 0;
15
16#include "battle/move/item/mystery.png.h"
17INCLUDE_IMG("battle/move/item/mystery.png", battle_item_mystery_png);
18INCLUDE_PAL("battle/move/item/mystery.pal", battle_item_mystery_pal);
19
20Vtx N(model)[] = {
21 { .v = {{ -16, -16, 0 }, FALSE, { 0, 0 }, { 0, 0, 0, 255 }}},
22 { .v = {{ 15, -16, 0 }, FALSE, { 1024, 0 }, { 0, 0, 0, 255 }}},
23 { .v = {{ 15, 15, 0 }, FALSE, { 1024, 1024 }, { 0, 0, 0, 255 }}},
24 { .v = {{ -16, 15, 0 }, FALSE, { 0, 1024 }, { 0, 0, 0, 255 }}},
25};
26
27Gfx N(displayList)[] = {
28 gsDPPipeSync(),
29 gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON),
30 gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA),
31 gsDPSetTexturePersp(G_TP_PERSP),
32 gsDPSetTextureDetail(G_TD_CLAMP),
33 gsDPSetTextureLOD(G_TL_TILE),
34 gsDPSetTextureLUT(G_TT_NONE),
35 gsDPSetTextureFilter(G_TF_AVERAGE),
36 gsDPSetTextureConvert(G_TC_FILT),
37 gsDPSetTextureLUT(G_TT_RGBA16),
38 gsDPLoadTLUT_pal16(0, battle_item_mystery_pal),
39 gsDPLoadTextureTile_4b(battle_item_mystery_png, G_IM_FMT_CI, battle_item_mystery_png_width, battle_item_mystery_png_height, 0, 0, battle_item_mystery_png_width - 1, battle_item_mystery_png_height - 1, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD),
40 gsSPClearGeometryMode(G_LIGHTING),
41 gsSPClearGeometryMode(G_SHADING_SMOOTH),
42 gsSPVertex(N(model), ARRAY_COUNT(N(model)), 0),
43 gsSP1Triangle(0, 1, 2, 0),
44 gsSP1Triangle(0, 2, 3, 0),
45 gsDPPipeSync(),
46 gsSPEndDisplayList(),
47};
48
49EntityModelScript N(modelCommandList) = STANDARD_ENTITY_MODEL_SCRIPT(N(displayList), RENDER_MODE_ALPHATEST);
50
51s32 N(D_802A227C_72D82C)[8] = {
52 ITEM_MUSHROOM,
53 ITEM_SUPER_SHROOM,
54 ITEM_FIRE_FLOWER,
55 ITEM_STONE_CAP,
56 ITEM_DIZZY_DIAL,
57 ITEM_THUNDER_RAGE,
58 ITEM_PEBBLE,
59 ITEM_MUSHROOM
60};
61
62s32 N(D_802A229C_72D84C)[8] = {
63 ITEM_MUSHROOM,
64 ITEM_SUPER_SHROOM,
65 ITEM_PEBBLE,
66 ITEM_STONE_CAP,
67 ITEM_MUSHROOM,
68 ITEM_SUPER_SHROOM,
69 ITEM_PEBBLE,
70 ITEM_MUSHROOM
71};
72
74
75BSS s32 D_802A25C4; // unused?
84
85void N(func_802A123C_72C7EC(void)) {
86 s32 var_s3;
87 s32 id;
88 s32 i;
89
90 if (D_802A25E4 < 6) {
91 if (D_802A25E4 > 0) {
92 draw_box(0, WINDOW_STYLE_7, 106, 86, 0, 36, 36, 255, 0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, NULL, NULL, NULL, SCREEN_WIDTH, SCREEN_HEIGHT, NULL);
93 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, 108, 90, 139, 118);
94
95 for (i = 0; i < ARRAY_COUNT(D_802A25C8); i++) {
96 id = D_802A25C8[i];
97 hud_element_set_render_pos(id, 124, (i * 26) + 104 - (D_802A25EC / 100));
99 }
100 id = D_802A25C8[0];
101 hud_element_set_render_pos(id, 124, (i * 26) + 104 - (D_802A25EC / 100));
103 }
104 }
105}
106
107API_CALLABLE(N(func_802A13E4_72C994)) {
108 BattleStatus* battleStatus = &gBattleStatus;
109 s32 temp_a0_4;
110 s32 temp_v1_3;
111 s32 var_v0_2;
112 s32 var_v0_3;
113 s32 id;
114 s32 i;
115
116 if (isInitialCall) {
117 D_802A25E4 = 0;
118 }
119
120 switch (D_802A25E4) {
121 case 0:
122 D_802A25F8 = create_worker_frontUI(NULL, N(func_802A123C_72C7EC));
123 D_802A25EC = rand_int(18200);
124 D_802A25F0 = 1000;
125 D_802A25FC = N(D_802A227C_72D82C);
126
127 if (battleStatus->darknessMode > BTL_DARKNESS_STATE_NONE) {
128 u8 type;
129 f32 zoom;
130
132 if (zoom >= 215.0f) {
133 D_802A25FC = N(D_802A229C_72D84C);
134 }
135 }
136
137 for (i = 0; i < ARRAY_COUNT(D_802A25C8); i++) {
138 id = hud_element_create(gItemHudScripts[gItemTable[D_802A25FC[i]].hudElemID].enabled);
139 D_802A25C8[i] = id;
141 }
142 D_802A25E4 = 1;
143 return ApiStatus_BLOCK;
144 case 1:
146 if (D_802A25EC / 100 >= 182) {
147 D_802A25EC -= 18200;
148 }
149
150 if (D_802A25F0 > 400) {
151 D_802A25F0 -= 10;
152 } else if (D_802A25F0 > 100) {
153 D_802A25F0 -= 5;
154 } else {
155 D_802A25F0 -= 1;
156 }
157
158 if (D_802A25F0 < 10) {
159 D_802A25E8 = D_802A25EC / 100;
160
161 if (((D_802A25EC / 100) % 26) < 13) {
162 if (rand_int(100) < 80) {
163 D_802A25E4 = 2;
164 } else {
165 D_802A25E4 = 3;
166 }
167 break;
168 }
169
170 if (rand_int(100) < 60) {
171 D_802A25E4 = 3;
172 } else {
173 D_802A25E4 = 2;
174 }
175 }
176 break;
177 case 2:
178 temp_a0_4 = D_802A25E8 % 26;
179 var_v0_2 = temp_a0_4 + 3;
180 if (var_v0_2 < 0) {
181 var_v0_2 += 3;
182 }
183 temp_a0_4 = var_v0_2 >> 2;
184 D_802A25E8 -= temp_a0_4;
185 D_802A25EC = D_802A25E8 * 100;
186 if (temp_a0_4 == 0) {
187 D_802A25E4 = 4;
188 }
189 break;
190 case 3:
191 temp_v1_3 = D_802A25E8 % 26;
192 if (temp_v1_3 == 0) {
193 D_802A25E4 = 4;
194 break;
195 }
196 temp_a0_4 = 26 - temp_v1_3;
197 var_v0_3 = temp_a0_4 + 3;
198 if (var_v0_3 < 0) {
199 var_v0_3 += 3;
200 }
201 temp_a0_4 = var_v0_3 >> 2;
202 D_802A25E8 += temp_a0_4;
203 D_802A25EC = D_802A25E8 * 100;
204 break;
205 case 4:
206 D_802A25F4 = 20;
207 D_802A25E4 = 5;
208 break;
209 case 5:
210 if (D_802A25F4 != 0) {
211 D_802A25F4--;
212 break;
213 }
214
215 var_v0_3 = i = D_802A25E8 / 26; // use of i required to match
216 battleStatus->moveArgument = D_802A25FC[D_802A25E8 / 26];
217 script->varTable[0] = battleStatus->moveArgument;
219 for (i = 0; i < ARRAY_COUNT(D_802A25C8); i++) {
221 }
222 return ApiStatus_DONE2;
223 }
224 return ApiStatus_BLOCK;
225}
226
227API_CALLABLE(N(func_802A188C_72CE3C)) {
228 Bytecode* args = script->ptrReadPos;
229 s32 a = evt_get_variable(script, *args++);
230 s32 b = evt_get_variable(script, *args++);
231 s32 c = evt_get_variable(script, *args++);
232
233 fx_damage_stars(FX_DAMAGE_STARS_2, a, b, c, 0, -1.0f, 0, 5);
234
235 return ApiStatus_DONE2;
236}
237
238EvtScript N(EVS_UseItem) = {
239 SetConst(LVarA, ITEM_MYSTERY)
240 ExecWait(N(UseItemWithEffect))
241 Thread
242 Wait(220)
243 Call(PlaySoundAtActor, ACTOR_PLAYER, SOUND_DING)
245 Call(PlaySoundAtActor, ACTOR_PLAYER, SOUND_MYSTERY_REEL)
246 Call(N(func_802A13E4_72C994))
247 Wait(2)
248 IfNe(LVar0, 133)
250 Return
251 EndIf
252 Call(CreateVirtualEntity, LVarA, Ref(N(modelCommandList)))
253 Call(GetActorPos, ACTOR_PLAYER, LVar0, LVar1, LVar2)
254 Add(LVar1, 150)
256 Call(SetOwnerTarget, ACTOR_PLAYER, 0)
257 Call(SetGoalToTarget, ACTOR_SELF)
258 Call(GetGoalPos, ACTOR_SELF, LVar0, LVar1, LVar2)
259 Thread
260 Set(LVar0, 0)
261 Loop(18)
262 Add(LVar0, -60)
264 Wait(1)
265 EndLoop
268 Add(LVar2, 5)
270 Thread
271 Add(LVar0, 60)
272 Add(LVar1, 0)
276 Call(SetTargetActor, ACTOR_SELF, ACTOR_PLAYER)
277 Call(SetGoalToTarget, ACTOR_SELF)
278 Call(GetGoalPos, ACTOR_SELF, LVar0, LVar1, LVar2)
279 Call(N(func_802A188C_72CE3C), LVar0, LVar1, LVar2)
280 Call(SetBattleFlagBits, BS_FLAGS1_TRIGGER_EVENTS, TRUE)
281 Call(DispatchDamagePlayerEvent, 1, EVENT_HIT)
282 Return
283 End
284};
Bytecode EvtScript[]
#define rand_int
#define draw_box
@ FX_DAMAGE_STARS_2
Definition effects.h:358
s32 EntityModelScript[]
Definition entity.h:7
#define STANDARD_ENTITY_MODEL_SCRIPT(gfx, renderMode)
Definition entity.h:56
@ WINDOW_STYLE_7
Definition enums.h:6377
@ BS_FLAGS1_TRIGGER_EVENTS
Definition enums.h:3575
@ SCREEN_LAYER_BACK
Definition enums.h:2383
@ SOUND_DING
Definition enums.h:1306
@ SOUND_MYSTERY_REEL
Definition enums.h:1176
@ RENDER_MODE_ALPHATEST
Definition enums.h:3276
@ ACTOR_PLAYER
Definition enums.h:2085
@ ACTOR_SELF
Definition enums.h:2084
@ EVENT_HIT
Definition enums.h:2132
@ BTL_DARKNESS_STATE_NONE
Definition enums.h:6365
#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
void free_worker(s32)
Definition worker.c:176
void get_screen_overlay_params(s32, u8 *type, f32 *zoom)
s32 create_worker_frontUI(void(*updateFunc)(void), void(*drawFunc)(void))
Definition worker.c:63
void hud_element_draw_without_clipping(s32 id)
void hud_element_set_render_pos(s32 id, s32 x, s32 y)
s32 hud_element_create(HudScript *anim)
Creates a new HUD element and returns its ID.
void hud_element_set_flags(s32 id, s32 flags)
Turns on the given flags.
void hud_element_free(s32 id)
@ HUD_ELEMENT_FLAG_80
Definition hud_element.h:80
EvtScript EVS_UseMystery
Definition use_items.c:203
#define INCLUDE_PAL(FILENAME, SYMBOLNAME)
#define INCLUDE_IMG(FILENAME, SYMBOLNAME)
IconHudScriptPair gItemHudScripts[]
BSS s32 D_802A25EC
Definition mystery.c:79
BSS s32 * D_802A25FC
Definition mystery.c:83
BSS s32 D_802A25E4
Definition mystery.c:77
BSS s32 D_802A25E8
Definition mystery.c:78
BSS s32 D_802A25C4
Definition mystery.c:75
BSS s32 D_802A25F4
Definition mystery.c:81
BSS s32 D_802A25F0
Definition mystery.c:80
BSS s32 D_802A25F8
Definition mystery.c:82
BSS s32 D_802A25C8[7]
Definition mystery.c:76
ApiStatus CreateVirtualEntity(Evt *script, b32 isInitialCall)
ApiStatus SetVirtualEntityPosition(Evt *script, b32 isInitialCall)
ApiStatus SetVirtualEntityJumpGravity(Evt *script, b32 isInitialCall)
ApiStatus DeleteVirtualEntity(Evt *script, b32 isInitialCall)
ApiStatus VirtualEntityJumpTo(Evt *script, b32 isInitialCall)
ApiStatus SetVirtualEntityRotation(Evt *script, b32 isInitialCall)
#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 SCREEN_WIDTH
Definition macros.h:105
#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 BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
#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 SCREEN_HEIGHT
Definition macros.h:106
#define ExecWait(EVT_SOURCE)
Launches a new child thread.
Definition macros.h:475
#define Thread
Marks the start of a thread block.
Definition macros.h:544
#define EndThread
Marks the end of a thread block.
Definition macros.h:547
#define LVar2
Definition macros.h:150
#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 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 LVar0
Definition macros.h:148
#define SetConst(VAR, CONST)
Sets the given variable to a given value, skipping the evt_get_variable call.
Definition macros.h:370
#define Return
Kills the current EVT thread.
Definition macros.h:217
#define Jump(EVT_SOURCE)
Jumps to a given instruction pointer and begins execution from there.
Definition macros.h:222
ItemData gItemTable[]
Gfx * gMainGfxPos
Definition cam_main.c:15
BattleStatus gBattleStatus
Definition battle.c:11
void fx_damage_stars(s32, f32, f32, f32, f32, f32, f32, s32)