Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
mega_shock.c File Reference

Go to the source code of this file.

Functions

void N update (void)
 
void N draw (void)
 
void N free (void)
 

Variables

s32 D_802A9930_42E340 [] = { 0, 25, 50, 75, 75, 0, 0, 0 }
 
s32 actionCmdTableMegaShock []
 

Function Documentation

◆ update()

void N update ( void )

Definition at line 98 of file mega_shock.c.

98 {
99 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
100 BattleStatus* battleStatus = &gBattleStatus;
101
102 s32 buttonsPushed;
103 s32 frameCount;
104 s32 buttonsAB;
105 s32 bufferPos;
106 s32 hudElement;
107 s32 mashMeterIndex;
108 s32 mashMeterCutoff;
109 s8 adjustedFillLevel;
110
111 switch (actionCommandStatus->state) {
112 case 0:
114
115 hudElement = actionCommandStatus->hudElements[0];
116 if (actionCommandStatus->showHud) {
118 }
119 hud_element_set_alpha(hudElement, 255);
120
121 hudElement = actionCommandStatus->hudElements[2];
122 if (actionCommandStatus->showHud) {
124 }
125 hud_element_set_alpha(hudElement, 255);
126
127 hudElement = actionCommandStatus->hudElements[1];
128 hud_element_set_alpha(hudElement, 255);
129 if (actionCommandStatus->showHud) {
131 }
132
133 actionCommandStatus->state = 1;
134 break;
135 case 1:
137 if (actionCommandStatus->hudPrepareTime != 0) {
138 actionCommandStatus->hudPrepareTime--;
139 break;
140 }
141
142 actionCommandStatus->hudPosX += 20;
143 if (actionCommandStatus->hudPosX > 50) {
144 actionCommandStatus->hudPosX = 50;
145 }
146
147 hud_element_set_render_pos(actionCommandStatus->hudElements[0], actionCommandStatus->hudPosX - 17,
148 actionCommandStatus->hudPosY);
149 hud_element_set_render_pos(actionCommandStatus->hudElements[2], actionCommandStatus->hudPosX + 23,
150 actionCommandStatus->hudPosY);
151 hud_element_set_render_pos(actionCommandStatus->hudElements[1], actionCommandStatus->hudPosX,
152 actionCommandStatus->hudPosY + 28);
153 break;
154 case 10:
156 if (actionCommandStatus->prepareTime != 0) {
157 actionCommandStatus->prepareTime--;
158 break;
159 }
160 hud_element_set_script(actionCommandStatus->hudElements[0], &HES_MashAButton);
161 hud_element_set_script(actionCommandStatus->hudElements[2], &HES_MashBButton1);
162 actionCommandStatus->barFillLevel = 0;
163 actionCommandStatus->unk_5C = 0;
164 actionCommandStatus->frameCounter = actionCommandStatus->duration;
166 actionCommandStatus->state = 11;
167 case 11:
169 if (!actionCommandStatus->isBarFilled) {
170 s16 newFillLevel;
171
172 if (actionCommandStatus->targetWeakness != 0) {
173 s8 mashMeterIntervals = actionCommandStatus->mashMeterIntervals;
174 s16* mashMeterCutoffs = actionCommandStatus->mashMeterCutoffs;
175 s32 index;
176
177 mashMeterCutoff = mashMeterCutoffs[mashMeterIntervals];
178 index = actionCommandStatus->barFillLevel / mashMeterCutoff / 20;
179 newFillLevel = actionCommandStatus->barFillLevel - D_802A9930_42E340[index];
180 } else {
181 newFillLevel = actionCommandStatus->barFillLevel - 10;
182 }
183
184 actionCommandStatus->barFillLevel = newFillLevel;
185 if (actionCommandStatus->barFillLevel < 0) {
186 actionCommandStatus->barFillLevel = 0;
187 }
188 }
189
190 bufferPos = battleStatus->inputBufferPos;
191 bufferPos -= 2;
192 if (bufferPos < 0) {
193 bufferPos += ARRAY_COUNT(battleStatus->pushInputBuffer);
194 }
195
196 buttonsPushed = 0;
197 frameCount = 1;
198
199 while (frameCount >= 0) {
200 if (bufferPos >= ARRAY_COUNT(battleStatus->pushInputBuffer)) {
201 bufferPos -= ARRAY_COUNT(battleStatus->pushInputBuffer);
202 }
203
204 buttonsPushed |= battleStatus->pushInputBuffer[bufferPos++];
205 frameCount--;
206 }
207
208 buttonsAB = BUTTON_A | BUTTON_B;
209 if ((buttonsPushed & buttonsAB) == buttonsAB) {
210 if (actionCommandStatus->targetWeakness != 0) {
211 s32 fillLevel;
212
213 fillLevel = actionCommandStatus->targetWeakness * 780;
214 fillLevel = fillLevel / 100 * battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty];
215
216 // Perplexing reuse of buttonsPushed here, but it fixes register allocation. Likely another
217 // subexpression from above can be put into a variable and reused instead.
218 //
219 // TODO: Find a way to avoid reusing buttonsPushed.
220 buttonsPushed = fillLevel / 100;
221
222 actionCommandStatus->barFillLevel += buttonsPushed;
223 } else {
224 actionCommandStatus->barFillLevel += 100;
225
226 if (actionCommandStatus->barFillLevel >= 500) {
227 actionCommandStatus->barFillLevel = 500;
228 }
229 }
230
231 bufferPos = battleStatus->inputBufferPos;
232 bufferPos -= 2;
233 if (bufferPos < 0) {
234 bufferPos += ARRAY_COUNT(battleStatus->pushInputBuffer);
235 }
236
237 frameCount = 1;
238 while (frameCount >= 0) {
239 if (bufferPos >= ARRAY_COUNT(battleStatus->pushInputBuffer)) {
240 bufferPos -= ARRAY_COUNT(battleStatus->pushInputBuffer);
241 }
242
243 battleStatus->pushInputBuffer[bufferPos++] = 0;
244 frameCount--;
245 }
246 }
247
248 if (actionCommandStatus->barFillLevel > 10000) {
249 hudElement = actionCommandStatus->hudElements[4];
250 actionCommandStatus->barFillLevel = 10000;
251 actionCommandStatus->isBarFilled = TRUE;
252 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX + 50,
253 actionCommandStatus->hudPosY + 28);
255 }
256
257 adjustedFillLevel = actionCommandStatus->barFillLevel / 100;
258
259 battleStatus->actionQuality = adjustedFillLevel;
260 sfx_adjust_env_sound_params(SOUND_LOOP_CHARGE_BAR, 0, 0, adjustedFillLevel * 12);
261
262 if (actionCommandStatus->frameCounter == 0) {
263 s16 threshold;
264
265 // Again, reusing buttonsPushed specifically for reg-alloc. See above.
266 //
267 // TODO: Find a way to avoid reusing buttonsPushed.
268 buttonsPushed = actionCommandStatus->barFillLevel;
269 if (actionCommandStatus->targetWeakness == 0) {
270 buttonsPushed = 0;
271 }
272
273 if (buttonsPushed == 0) {
274 battleStatus->actionSuccess = -1;
275 } else {
276 battleStatus->actionSuccess = buttonsPushed / 100;
277 }
278
279 mashMeterIndex = actionCommandStatus->mashMeterIntervals - 1;
280 mashMeterCutoff = actionCommandStatus->mashMeterCutoffs[mashMeterIndex];
281 threshold = mashMeterCutoff / 2;
282
283 if (battleStatus->actionQuality <= threshold) {
284 battleStatus->actionResult = ACTION_RESULT_MINUS_4;
285 } else {
286 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
287 }
288
289 if (battleStatus->actionSuccess == 100) {
291 }
292
295 actionCommandStatus->frameCounter = 5;
296 actionCommandStatus->state = 12;
297 } else {
298 actionCommandStatus->frameCounter -= 1;
299 }
300 break;
301 case 12:
302 if (actionCommandStatus->targetWeakness == 0) {
303 actionCommandStatus->barFillLevel -= 100;
304 if (actionCommandStatus->barFillLevel < 0) {
305 actionCommandStatus->barFillLevel = 0;
306 }
307 }
308
309 if (actionCommandStatus->frameCounter != 0) {
310 actionCommandStatus->frameCounter -= 1;
311 } else {
313 }
314 break;
315 }
316}
BSS ActionCommandStatus gActionCommandStatus
Definition action_cmd.c:91
void func_80269160(void)
Definition action_cmd.c:655
void action_command_free(void)
Definition action_cmd.c:446
HudScript HES_MashBButton1
HudScript HES_MashAButton
@ BUTTON_A
Definition enums.h:2790
@ BUTTON_B
Definition enums.h:2789
@ SOUND_LOOP_CHARGE_BAR
Definition enums.h:1646
@ ACTION_RESULT_SUCCESS
Definition enums.h:1968
@ ACTION_RESULT_MINUS_4
Definition enums.h:1964
void btl_set_popup_duration(s32 duration)
void hud_element_set_alpha(s32 id, s32 opacity)
void hud_element_set_script(s32 id, HudScript *anim)
void hud_element_set_render_pos(s32 id, s32 x, s32 y)
void hud_element_clear_flags(s32 id, s32 flags)
Turns off the given flags.
@ HUD_ELEMENT_FLAG_DISABLED
Definition hud_element.h:74
s32 D_802A9930_42E340[]
Definition mega_shock.c:7
void sfx_stop_sound(s32 soundID)
Definition sfx.c:507
void sfx_adjust_env_sound_params(s32 soundID, u8 volume, u8 pan, s16 pitchShift)
Definition sfx.c:492
void sfx_play_sound_with_params(s32 soundID, u8 volume, u8 pan, s16 pitchShift)
Definition sfx.c:458
#define ARRAY_COUNT(arr)
Definition macros.h:40
s32 * actionCmdDifficultyTable
s32 pushInputBuffer[64]
BattleStatus gBattleStatus
Definition battle.c:11

◆ draw()

void N draw ( void )

Definition at line 318 of file mega_shock.c.

318 {
319 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
320
321 s32 hudElement;
322 s32 hudElementX;
323 s32 hudElementY;
324
325 hud_element_draw_clipped(actionCommandStatus->hudElements[0]);
326 hud_element_draw_clipped(actionCommandStatus->hudElements[2]);
327
328 hudElement = actionCommandStatus->hudElements[1];
329 hud_element_draw_clipped(hudElement);
330 hud_element_get_render_pos(hudElement, &hudElementX, &hudElementY);
331
332 if (!actionCommandStatus->isBarFilled) {
333 draw_mash_meter_multicolor(hudElementX, hudElementY, actionCommandStatus->barFillLevel / 100);
334 } else {
335 draw_mash_meter_blink(hudElementX, hudElementY, actionCommandStatus->barFillLevel / 100);
336 }
337
338 hud_element_draw_clipped(actionCommandStatus->hudElements[4]);
339}
void draw_mash_meter_multicolor(s32 posX, s32 posY, s32 fillValue)
Definition action_cmd.c:226
void draw_mash_meter_blink(s32 posX, s32 posY, s32 fillValue)
Definition action_cmd.c:246
void hud_element_get_render_pos(s32 id, s32 *x, s32 *y)
void hud_element_draw_clipped(s32 id)

◆ free()

Variable Documentation

◆ D_802A9930_42E340

s32 D_802A9930_42E340[] = { 0, 25, 50, 75, 75, 0, 0, 0 }

Definition at line 7 of file mega_shock.c.

7{ 0, 25, 50, 75, 75, 0, 0, 0 };

Referenced by update().

◆ actionCmdTableMegaShock

s32 actionCmdTableMegaShock[]
extern

Definition at line 44 of file action_cmd.c.

44{ 130, 120, 110, 100, 90, 80, 70, 60 };