Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
tidal_wave.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

HudScriptD_802A97C0_42CEB0 [3] = { &HES_PressAButton, &HES_PressBButton, &HES_PressCDownButton }
 
HudScriptD_802A97CC_42CEBC [3] = { &HES_AButtonDown, &HES_BButtonHeld, &HES_CDownButtonHeld }
 
s32 actionCmdTableTidalWave []
 

Function Documentation

◆ update()

void N update ( void )

Definition at line 79 of file tidal_wave.c.

79 {
80 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
81 BattleStatus* battleStatus = &gBattleStatus;
82 s32 id;
83 s8 oldButton;
84 s8 newButton;
85 s32 numLookbackFrames;
86 s32 bufferPos;
87 s32 buttonsPressed;
88 s32 success;
89 s32 i;
90
91 switch (actionCommandStatus->state) {
92 case 0:
94 id = actionCommandStatus->hudElements[0];
95 if (actionCommandStatus->showHud) {
97 }
98 hud_element_set_alpha(id, 255);
99 actionCommandStatus->state = 1;
100 break;
101 case 1:
103 actionCommandStatus->hudPosX += 20;
104 if (actionCommandStatus->hudPosX > 50) {
105 actionCommandStatus->hudPosX = 50;
106 }
108 actionCommandStatus->hudElements[0],
109 actionCommandStatus->hudPosX + 21,
110 actionCommandStatus->hudPosY + 28);
111 break;
112 case 10:
114 if (actionCommandStatus->prepareTime != 0) {
115 actionCommandStatus->prepareTime--;
116 break;
117 }
118 actionCommandStatus->unk_5D = 1;
119 actionCommandStatus->frameCounter = actionCommandStatus->duration;
120 actionCommandStatus->unk_5C = rand_int(2);
121 actionCommandStatus->state = 11;
122 actionCommandStatus->wrongInputFrameCounter = 0;
123 // fallthrough
124 case 11:
126
127 // Pick a new button that doesn't match the old one.
128 oldButton = actionCommandStatus->unk_5C;
129 do {
130 newButton = rand_int(2);
131 actionCommandStatus->unk_5C = newButton;
132 } while (oldButton == newButton);
133
134 id = actionCommandStatus->hudElements[actionCommandStatus->unk_5D];
136 id, D_802A97C0_42CEB0[newButton]);
138 id,
139 actionCommandStatus->hudPosX + ((actionCommandStatus->unk_5D - 1) * 20) + 16,
140 actionCommandStatus->hudPosY);
143 actionCommandStatus->lookBackCounter = 1;
144 actionCommandStatus->state = 12;
145 // fallthrough
146 case 12:
148 if (--actionCommandStatus->frameCounter == 0) {
149 actionCommandStatus->state = 13;
150 break;
151 }
152
153 // Stops checking for input if on the 15th button.
154 if (actionCommandStatus->unk_5D == 15) {
155 break;
156 }
157
158 // Number of frames until input possible (if negative, used to look backward;
159 // allows correct presses to be buffered after an incorrect press).
160 actionCommandStatus->lookBackCounter--;
161 // Wrong-input lockout frame counter
162 actionCommandStatus->wrongInputFrameCounter--;
163
164 if (actionCommandStatus->lookBackCounter <= 0) {
165 // Determine number of frames to look back in input buffer (up to 20).
166 numLookbackFrames = abs(actionCommandStatus->lookBackCounter);
167 if (numLookbackFrames > 20) {
168 numLookbackFrames = 20;
169 }
170
171 // Determine starting point in input buffer.
172 bufferPos = battleStatus->inputBufferPos - numLookbackFrames;
173 if (bufferPos < 0) {
174 bufferPos += ARRAY_COUNT(battleStatus->pushInputBuffer);
175 }
176
177 // If determined that 0 frames should be searched, search a minimum of 1.
178 if (numLookbackFrames == 0) {
179 numLookbackFrames = 1;
180 }
181
182 // Check buffer for past N frames' worth of button presses.
183 for (i = 0; i < numLookbackFrames; i++) {
184 if (bufferPos >= ARRAY_COUNT(battleStatus->pushInputBuffer)) {
185 bufferPos -= ARRAY_COUNT(battleStatus->pushInputBuffer);
186 }
187
188 // If not locked out from previous wrong press...
189 if (actionCommandStatus->wrongInputFrameCounter > 0) {
190 break;
191 };
192
193 success = FALSE;
194 actionCommandStatus->wrongButtonPressed = FALSE;
195
196 // Check for presses of the current button.
197 switch (actionCommandStatus->unk_5C) {
198 case 0:
199 if (actionCommandStatus->autoSucceed) {
200 success = TRUE;
201 } else {
202 buttonsPressed = battleStatus->pushInputBuffer[bufferPos];
203 if (buttonsPressed != 0) {
204 if (buttonsPressed & ~BUTTON_A) {
205 actionCommandStatus->wrongButtonPressed = TRUE;
206 } else {
207 success = TRUE;
208 }
209 }
210 }
211 break;
212 case 1:
213 if (actionCommandStatus->autoSucceed) {
214 success = TRUE;
215 } else {
216 buttonsPressed = battleStatus->pushInputBuffer[bufferPos];
217 if (buttonsPressed != 0) {
218 if (buttonsPressed & ~BUTTON_B) {
219 actionCommandStatus->wrongButtonPressed = TRUE;
220 } else {
221 success = TRUE;
222 }
223 }
224 }
225 break;
226 case 2:
227 if (actionCommandStatus->autoSucceed) {
228 success = TRUE;
229 } else {
230 buttonsPressed = battleStatus->pushInputBuffer[bufferPos];
231 if (buttonsPressed != 0) {
232 if (buttonsPressed & ~BUTTON_C_DOWN) {
233 actionCommandStatus->wrongButtonPressed = TRUE;
234 } else {
235 success = TRUE;
236 }
237 }
238 }
239 break;
240 }
241
242 if (actionCommandStatus->wrongButtonPressed) {
243 // Wrong; prevent successful inputs for 10 frames.
244 actionCommandStatus->wrongInputFrameCounter = 10;
246 actionCommandStatus->lookBackCounter = 0;
247 }
248
249 if (success) {
250 // Correct; shrink button, set up next button press, etc.
251 id = actionCommandStatus->hudElements[actionCommandStatus->unk_5D];
252 hud_element_set_script(id, D_802A97CC_42CEBC[actionCommandStatus->unk_5C]);
253 hud_element_set_scale(id, 0.5f);
255 id,
256 actionCommandStatus->hudPosX + ((actionCommandStatus->unk_5D - 1) * 20),
257 actionCommandStatus->hudPosY + 7);
258 actionCommandStatus->unk_5D++;
259 actionCommandStatus->barFillLevel +=
260 battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty] * 0x12;
261 if (actionCommandStatus->barFillLevel > 10000) {
262 actionCommandStatus->barFillLevel = 10000;
263 }
264 actionCommandStatus->state = 11;
265 battleStatus->actionQuality++;
267 return;
268 }
269
270 bufferPos++;
271 }
272 }
273 break;
274 case 13:
275 if (battleStatus->actionQuality == 0) {
276 battleStatus->actionSuccess = -1;
277 } else {
278 battleStatus->actionSuccess = battleStatus->actionQuality;
279 }
280 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
281 if (battleStatus->actionSuccess >= 10) {
283 }
285 actionCommandStatus->frameCounter = 5;
286 actionCommandStatus->state = 14;
287 break;
288 case 14:
289 if (actionCommandStatus->frameCounter != 0) {
290 actionCommandStatus->frameCounter--;
291 } else {
293 }
294 break;
295 }
296}
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
#define rand_int
@ BUTTON_A
Definition enums.h:2790
@ BUTTON_C_DOWN
Definition enums.h:2779
@ BUTTON_B
Definition enums.h:2789
@ SOUND_TIMING_BAR_TICK
Definition enums.h:952
@ SOUND_APPROVE
Definition enums.h:932
@ SOUND_MENU_ERROR
Definition enums.h:933
@ ACTION_RESULT_SUCCESS
Definition enums.h:1968
void btl_set_popup_duration(s32 duration)
void hud_element_set_scale(s32 index, f32 scale)
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
void sfx_play_sound(s32 soundID)
Definition sfx.c:517
#define ARRAY_COUNT(arr)
Definition macros.h:40
s32 * actionCmdDifficultyTable
s32 pushInputBuffer[64]
HudScript * D_802A97C0_42CEB0[3]
Definition tidal_wave.c:6
HudScript * D_802A97CC_42CEBC[3]
Definition tidal_wave.c:7
BattleStatus gBattleStatus
Definition battle.c:11

◆ draw()

void N draw ( void )

Definition at line 298 of file tidal_wave.c.

298 {
299 s32 i;
300
301 for (i = 1; i < ARRAY_COUNT(gActionCommandStatus.hudElements) - 1; i++) {
303 }
304}
void hud_element_draw_clipped(s32 id)

◆ free()

void N free ( void )

Definition at line 306 of file tidal_wave.c.

306 {
307 s32 i;
308
310
311 for (i = 1; i < ARRAY_COUNT(gActionCommandStatus.hudElements) - 1; i++) {
313 }
314}
void hud_element_free(s32 id)

Variable Documentation

◆ D_802A97C0_42CEB0

Definition at line 6 of file tidal_wave.c.

HudScript HES_PressAButton
HudScript HES_PressBButton
HudScript HES_PressCDownButton

Referenced by update().

◆ D_802A97CC_42CEBC

Definition at line 7 of file tidal_wave.c.

HudScript HES_CDownButtonHeld
HudScript HES_BButtonHeld
HudScript HES_AButtonDown

Referenced by update().

◆ actionCmdTableTidalWave

s32 actionCmdTableTidalWave[]
extern

Definition at line 50 of file action_cmd.c.

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