Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
tidal_wave.c
Go to the documentation of this file.
1#include "common.h"
2#include "battle/action_cmd.h"
3
4#define NAMESPACE action_command_tidal_wave
5
8
9extern s32 actionCmdTableTidalWave[];
10
11API_CALLABLE(N(init)) {
12 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
13 BattleStatus* battleStatus = &gBattleStatus;
14 s32 id;
15 s32 i;
16
17 battleStatus->unk_82 = 5;
19
21 battleStatus->actionSuccess = 0;
22 return ApiStatus_DONE2;
23 } else {
25 actionCommandStatus->actionCommandID = ACTION_COMMAND_TIDAL_WAVE;
26 actionCommandStatus->state = 0;
27 actionCommandStatus->wrongButtonPressed = FALSE;
28 actionCommandStatus->barFillLevel = 0;
29 actionCommandStatus->barFillWidth = 0;
30 battleStatus->actionQuality = 0;
31 actionCommandStatus->hudPosX = -48;
32 actionCommandStatus->hudPosY = 80;
33
35 actionCommandStatus->hudElements[0] = id;
36 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
39
40 for (i = 1; i < ARRAY_COUNT(actionCommandStatus->hudElements) - 1; i++) {
42 actionCommandStatus->hudElements[i] = id;
43 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
46 }
47
48 return ApiStatus_DONE2;
49 }
50}
51
52API_CALLABLE(N(start)) {
53 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
54 BattleStatus* battleStatus = &gBattleStatus;
55 Bytecode* args = script->ptrReadPos;
56
58 battleStatus->actionSuccess = 0;
59 return ApiStatus_DONE2;
60 }
61
63 actionCommandStatus->prepareTime = evt_get_variable(script, *args++);
64 actionCommandStatus->duration = evt_get_variable(script, *args++);
65 actionCommandStatus->difficulty = evt_get_variable(script, *args++);
66 actionCommandStatus->difficulty = adjust_action_command_difficulty(actionCommandStatus->difficulty);
67 actionCommandStatus->wrongButtonPressed = FALSE;
68 actionCommandStatus->barFillLevel = 0;
69 actionCommandStatus->barFillWidth = 0;
70 battleStatus->actionSuccess = 0;
71 battleStatus->actionQuality = 0;
72 battleStatus->actionResult = ACTION_RESULT_FAIL;
73 actionCommandStatus->state = 10;
74 battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
76 return ApiStatus_DONE2;
77}
78
79void N(update)(void) {
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}
297
298void N(draw)(void) {
299 s32 i;
300
301 for (i = 1; i < ARRAY_COUNT(gActionCommandStatus.hudElements) - 1; i++) {
303 }
304}
305
306void N(free)(void) {
307 s32 i;
308
310
311 for (i = 1; i < ARRAY_COUNT(gActionCommandStatus.hudElements) - 1; i++) {
313 }
314}
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
s32 adjust_action_command_difficulty(s32 arg0)
Definition action_cmd.c:101
void action_command_init_status(void)
Definition action_cmd.c:256
void func_80269118(void)
Definition action_cmd.c:641
HudScript HES_AButton
HudScript HES_CDownButtonHeld
HudScript HES_BlueMeter
HudScript HES_BButtonHeld
HudScript HES_PressAButton
HudScript HES_AButtonDown
HudScript HES_PressBButton
@ ACTION_COMMAND_MODE_NOT_LEARNED
Definition action_cmd.h:38
HudScript HES_PressCDownButton
#define rand_int
@ ACTION_COMMAND_TIDAL_WAVE
Definition enums.h:3495
@ 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
@ ACTION_RESULT_FAIL
Definition enums.h:1967
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
void btl_set_popup_duration(s32 duration)
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
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_depth(s32 id, s32 z)
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_clear_flags(s32 id, s32 flags)
Turns off the given flags.
void hud_element_draw_clipped(s32 id)
void hud_element_free(s32 id)
@ HUD_ELEMENT_FLAG_DISABLED
Definition hud_element.h:74
@ HUD_ELEMENT_FLAG_80
Definition hud_element.h:80
s32 HudScript[]
Definition hud_element.h:9
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
s32 actionCmdTableTidalWave[]
Definition action_cmd.c:50
void N free(void)
Definition tidal_wave.c:306
HudScript * D_802A97CC_42CEBC[3]
Definition tidal_wave.c:7
void N update(void)
Definition tidal_wave.c:79
void N draw(void)
Definition tidal_wave.c:298
BattleStatus gBattleStatus
Definition battle.c:11
void N init(Npc *bombette)
Definition bombette.c:66