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

Go to the source code of this file.

Enumerations

enum  { HIDX_METER = 0 , HIDX_FIRST_BUTTON = 1 }
 
enum  {
  TIDAL_WAVE_STATE_INIT = 0 , TIDAL_WAVE_STATE_APPEAR = 1 , TIDAL_WAVE_STATE_START = 10 , TIDAL_WAVE_STATE_NEXT_BUTTON = 11 ,
  TIDAL_WAVE_STATE_AWAIT_INPUT = 12 , TIDAL_WAVE_STATE_WRAPUP = 13 , TIDAL_WAVE_STATE_DISPOSE = 14
}
 
enum  { TIDAL_WAVE_INPUT_A = 0 , TIDAL_WAVE_INPUT_B = 1 , TIDAL_WAVE_INPUT_C_DOWN = 2 , TIDAL_WAVE_INPUT_COUNT }
 

Functions

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

Variables

s32 actionCmdTableTidalWave []
 
HudScriptHudButtonsUp [TIDAL_WAVE_INPUT_COUNT] = { &HES_PressAButton, &HES_PressBButton, &HES_PressCDownButton }
 
HudScriptHudButtonsDown [TIDAL_WAVE_INPUT_COUNT] = { &HES_AButtonDown, &HES_BButtonHeld, &HES_CDownButtonHeld }
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
HIDX_METER 
HIDX_FIRST_BUTTON 

Definition at line 9 of file tidal_wave.c.

9 {
10 HIDX_METER = 0,
12 // remaining HIDX are for the sequence of buttons
13};
@ HIDX_METER
Definition tidal_wave.c:10
@ HIDX_FIRST_BUTTON
Definition tidal_wave.c:11

◆ anonymous enum

anonymous enum
Enumerator
TIDAL_WAVE_STATE_INIT 
TIDAL_WAVE_STATE_APPEAR 
TIDAL_WAVE_STATE_START 
TIDAL_WAVE_STATE_NEXT_BUTTON 
TIDAL_WAVE_STATE_AWAIT_INPUT 
TIDAL_WAVE_STATE_WRAPUP 
TIDAL_WAVE_STATE_DISPOSE 

Definition at line 16 of file tidal_wave.c.

16 {
17 TIDAL_WAVE_STATE_INIT = 0, // create hud elements
18 TIDAL_WAVE_STATE_APPEAR = 1, // hud elements move into position
20 TIDAL_WAVE_STATE_NEXT_BUTTON = 11, // choose the next required input
21 TIDAL_WAVE_STATE_AWAIT_INPUT = 12, // wait for the player's response
22 TIDAL_WAVE_STATE_WRAPUP = 13, // tally overall success
23 TIDAL_WAVE_STATE_DISPOSE = 14, // delay and disappear
24};
@ TIDAL_WAVE_STATE_AWAIT_INPUT
Definition tidal_wave.c:21
@ TIDAL_WAVE_STATE_WRAPUP
Definition tidal_wave.c:22
@ TIDAL_WAVE_STATE_NEXT_BUTTON
Definition tidal_wave.c:20
@ TIDAL_WAVE_STATE_START
Definition tidal_wave.c:19
@ TIDAL_WAVE_STATE_INIT
Definition tidal_wave.c:17
@ TIDAL_WAVE_STATE_DISPOSE
Definition tidal_wave.c:23
@ TIDAL_WAVE_STATE_APPEAR
Definition tidal_wave.c:18

◆ anonymous enum

anonymous enum
Enumerator
TIDAL_WAVE_INPUT_A 
TIDAL_WAVE_INPUT_B 
TIDAL_WAVE_INPUT_C_DOWN 
TIDAL_WAVE_INPUT_COUNT 

Definition at line 26 of file tidal_wave.c.

26 {
31};
@ TIDAL_WAVE_INPUT_COUNT
Definition tidal_wave.c:30
@ TIDAL_WAVE_INPUT_A
Definition tidal_wave.c:27
@ TIDAL_WAVE_INPUT_C_DOWN
Definition tidal_wave.c:29
@ TIDAL_WAVE_INPUT_B
Definition tidal_wave.c:28

Function Documentation

◆ update()

void N update ( void )

Definition at line 109 of file tidal_wave.c.

109 {
111 BattleStatus* battleStatus = &gBattleStatus;
112 HudElemID hid;
113 s8 oldButton;
114 s8 newButton;
115 s32 numLookbackFrames;
116 s32 bufferPos;
117 s32 buttonsPressed;
118 s32 success;
119 s32 i;
120
121 switch (acs->state) {
124 hid = acs->hudElemIDs[HIDX_METER];
125 if (acs->showHud) {
127 }
128 hud_element_set_alpha(hid, 255);
130 break;
133 acs->hudPosX += 20;
134 if (acs->hudPosX > 50) {
135 acs->hudPosX = 50;
136 }
138 break;
141 if (acs->prepareTime != 0) {
142 acs->prepareTime--;
143 break;
144 }
145 acs->tidalWave.inputCount = 1;
146 acs->stateTimer = acs->duration;
147 acs->tidalWave.prevButton = rand_int(TIDAL_WAVE_INPUT_COUNT - 1);
149 acs->wrongInputFrameCounter = 0;
150
151 // fallthrough
154
155 // Pick a new button that doesn't match the old one.
156 oldButton = acs->tidalWave.prevButton;
157 do {
158 newButton = rand_int(TIDAL_WAVE_INPUT_COUNT - 1);
159 acs->tidalWave.prevButton = newButton;
160 } while (oldButton == newButton);
161
162 hid = acs->hudElemIDs[acs->tidalWave.inputCount];
163 hud_element_set_script(hid, HudButtonsUp[newButton]);
164 hud_element_set_render_pos(hid, acs->hudPosX + ((acs->tidalWave.inputCount - 1) * 20) + 16, acs->hudPosY);
167 acs->lookBackCounter = 1;
169
170 // fallthrough
173
174 acs->stateTimer--;
175 if (acs->stateTimer == 0) {
177 break;
178 }
179
180 // Stops checking for input if on the 15th button.
181 if (acs->tidalWave.inputCount == 15) {
182 break;
183 }
184
185 // Number of frames until input possible (if negative, used to look backward;
186 // allows correct presses to be buffered after an incorrect press).
187 acs->lookBackCounter--;
188 // Wrong-input lockout frame counter
190
191 if (acs->lookBackCounter <= 0) {
192 // Determine number of frames to look back in input buffer (up to 20).
193 numLookbackFrames = abs(acs->lookBackCounter);
194 if (numLookbackFrames > 20) {
195 numLookbackFrames = 20;
196 }
197
198 // Determine starting point in input buffer.
199 bufferPos = battleStatus->inputBufferPos - numLookbackFrames;
200 if (bufferPos < 0) {
201 bufferPos += ARRAY_COUNT(battleStatus->pushInputBuffer);
202 }
203
204 // If determined that 0 frames should be searched, search a minimum of 1.
205 if (numLookbackFrames == 0) {
206 numLookbackFrames = 1;
207 }
208
209 // Check buffer for past N frames' worth of button presses.
210 for (i = 0; i < numLookbackFrames; i++) {
211 if (bufferPos >= ARRAY_COUNT(battleStatus->pushInputBuffer)) {
212 bufferPos -= ARRAY_COUNT(battleStatus->pushInputBuffer);
213 }
214
215 // If not locked out from previous wrong press...
216 if (acs->wrongInputFrameCounter > 0) {
217 break;
218 };
219
220 success = FALSE;
221 acs->wrongButtonPressed = FALSE;
222
223 // Check for presses of the current button.
224 switch (acs->tidalWave.prevButton) {
226 if (acs->autoSucceed) {
227 success = TRUE;
228 } else {
229 buttonsPressed = battleStatus->pushInputBuffer[bufferPos];
230 if (buttonsPressed != 0) {
231 if (buttonsPressed & ~BUTTON_A) {
232 acs->wrongButtonPressed = TRUE;
233 } else {
234 success = TRUE;
235 }
236 }
237 }
238 break;
240 if (acs->autoSucceed) {
241 success = TRUE;
242 } else {
243 buttonsPressed = battleStatus->pushInputBuffer[bufferPos];
244 if (buttonsPressed != 0) {
245 if (buttonsPressed & ~BUTTON_B) {
246 acs->wrongButtonPressed = TRUE;
247 } else {
248 success = TRUE;
249 }
250 }
251 }
252 break;
254 if (acs->autoSucceed) {
255 success = TRUE;
256 } else {
257 buttonsPressed = battleStatus->pushInputBuffer[bufferPos];
258 if (buttonsPressed != 0) {
259 if (buttonsPressed & ~BUTTON_C_DOWN) {
260 acs->wrongButtonPressed = TRUE;
261 } else {
262 success = TRUE;
263 }
264 }
265 }
266 break;
267 }
268
269 if (acs->wrongButtonPressed) {
270 // Wrong; prevent successful inputs for 10 frames.
271 acs->wrongInputFrameCounter = 10;
273 acs->lookBackCounter = 0;
274 }
275
276 if (success) {
277 // Correct; shrink button, set up next button press, etc.
278 hid = acs->hudElemIDs[acs->tidalWave.inputCount];
279 hud_element_set_script(hid, HudButtonsDown[acs->tidalWave.prevButton]);
280 hud_element_set_scale(hid, 0.5f);
281 hud_element_set_render_pos(hid, acs->hudPosX + ((acs->tidalWave.inputCount - 1) * 20), acs->hudPosY + 7);
282 acs->tidalWave.inputCount++;
283 acs->meterFillLevel += battleStatus->actionCmdDifficultyTable[acs->difficulty] * 18;
284 if (acs->meterFillLevel > MAX_MASH_UNITS) {
286 }
288 battleStatus->actionProgress++;
290 return;
291 }
292
293 bufferPos++;
294 }
295 }
296 break;
298 if (battleStatus->actionProgress == 0) {
299 battleStatus->actionQuality = AC_QUALITY_FAILED;
300 } else {
301 battleStatus->actionQuality = battleStatus->actionProgress;
302 }
303 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
304 if (battleStatus->actionQuality >= 10) {
306 }
308 acs->stateTimer = 5;
310 break;
312 if (acs->stateTimer != 0) {
313 acs->stateTimer--;
314 } else {
316 }
317 break;
318 }
319}
BSS ActionCommandStatus gActionCommandStatus
Definition action_cmd.c:91
void action_command_free(void)
Definition action_cmd.c:446
void increment_action_command_success_count(void)
Definition action_cmd.c:655
#define AC_QUALITY_FAILED
Definition action_cmd.h:66
HudElemID hudElemIDs[16]
Definition action_cmd.h:83
#define MAX_MASH_UNITS
Definition action_cmd.h:75
s32 HudElemID
#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:72
void sfx_play_sound(s32 soundID)
Definition sfx.c:517
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define POPUP_MSG_OFF
Definition battle.h:270
#define POPUP_MSG_ON
Definition battle.h:269
s32 * actionCmdDifficultyTable
s32 pushInputBuffer[64]
HudScript * HudButtonsUp[TIDAL_WAVE_INPUT_COUNT]
Definition tidal_wave.c:33
HudScript * HudButtonsDown[TIDAL_WAVE_INPUT_COUNT]
Definition tidal_wave.c:34
BattleStatus gBattleStatus
Definition battle.c:11

◆ draw()

void N draw ( void )

Definition at line 321 of file tidal_wave.c.

321 {
322 s32 i;
323
326 }
327}
void hud_element_draw_clipped(s32 id)

◆ free()

void N free ( void )

Definition at line 329 of file tidal_wave.c.

329 {
330 s32 i;
331
333
336 }
337}
void hud_element_free(s32 id)

Variable Documentation

◆ actionCmdTableTidalWave

s32 actionCmdTableTidalWave[]
extern

Definition at line 50 of file action_cmd.c.

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

◆ HudButtonsUp

Definition at line 33 of file tidal_wave.c.

HudScript HES_PressAButton
HudScript HES_PressBButton
HudScript HES_PressCDownButton

Referenced by update().

◆ HudButtonsDown

Definition at line 34 of file tidal_wave.c.

HudScript HES_CDownButtonHeld
HudScript HES_BButtonHeld
HudScript HES_AButtonDown

Referenced by update().