Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
hammer.c
Go to the documentation of this file.
1#include "common.h"
2#include "battle/action_cmd.h"
3
4#define NAMESPACE action_command_hammer
5
7
8// indices into ActionCommandStatus::hudElements for this action command
9enum {
17};
18
19API_CALLABLE(N(init)) {
23
25 battleStatus->actionCmdDifficultyTable = actionCmdTableHammer;
26 battleStatus->actionResult = ACTION_RESULT_FAIL;
27
28 if (battleStatus->actionCommandMode == AC_MODE_NOT_LEARNED) {
29 battleStatus->actionQuality = 0;
30 battleStatus->actionProgress = 0;
31 return ApiStatus_DONE2;
32 }
33
35 acs->actionCommandID = ACTION_COMMAND_SMASH;
36 acs->state = AC_STATE_INIT;
37 acs->wrongButtonPressed = false;
38 acs->hudPosX = -48;
39 acs->hudPosY = 96;
40
42 acs->hudElemIDs[HIDX_FRAME] = hid;
44 hud_element_set_render_pos(hid, acs->hudPosX, acs->hudPosY);
46
48 acs->hudElemIDs[HIDX_WAIT] = hid;
50 hud_element_set_render_pos(hid, acs->hudPosX, acs->hudPosY);
52
54 acs->hudElemIDs[HIDX_CHARGE_A] = hid;
56 hud_element_set_render_pos(hid, acs->hudPosX, acs->hudPosY);
58
60 acs->hudElemIDs[HIDX_CHARGE_B] = hid;
62 hud_element_set_render_pos(hid, acs->hudPosX, acs->hudPosY);
64
66 acs->hudElemIDs[HIDX_CHARGE_C] = hid;
68 hud_element_set_render_pos(hid, acs->hudPosX, acs->hudPosY);
70
72 acs->hudElemIDs[HIDX_STICK] = hid;
74 hud_element_set_render_pos(hid, acs->hudPosX, acs->hudPosY);
76
78 acs->hudElemIDs[HIDX_RIGHT_ON] = hid;
80 hud_element_set_render_pos(hid, acs->hudPosX, acs->hudPosY);
83
84 return ApiStatus_DONE2;
85}
86
87API_CALLABLE(N(start)) {
90 Bytecode* args = script->ptrReadPos;
91
92 if (battleStatus->actionCommandMode == AC_MODE_NOT_LEARNED) {
94 battleStatus->actionProgress = 0;
95 return ApiStatus_DONE2;
96 }
97
99 acs->prepareTime = evt_get_variable(script, *args++);
100 acs->duration = evt_get_variable(script, *args++);
101 acs->difficulty = evt_get_variable(script, *args++);
102 acs->difficulty = adjust_action_command_difficulty(acs->difficulty);
103 acs->wrongButtonPressed = false;
104 acs->playHammerSounds = true;
105 if (acs->prepareTime < 0) {
106 acs->prepareTime = 0;
107 acs->playHammerSounds = false;
108 }
109
110 acs->hammerMissedStart = false;
111 battleStatus->actionQuality = 0;
112 battleStatus->actionProgress = 0;
113 battleStatus->actionResult = ACTION_RESULT_FAIL;
114 acs->state = AC_STATE_START;
116
118
119 return ApiStatus_DONE2;
120}
121
122void N(update)(void) {
129 s32 i;
130 s32 new_var;
131
132 switch (acs->state) {
133 case AC_STATE_INIT:
135
136 hid = acs->hudElemIDs[HIDX_FRAME];
137 if (acs->showHud) {
139 }
141
142 hid = acs->hudElemIDs[HIDX_WAIT];
143 if (acs->showHud) {
145 }
147
148 hid = acs->hudElemIDs[HIDX_CHARGE_A];
149 if (acs->showHud) {
151 }
153
154 hid = acs->hudElemIDs[HIDX_CHARGE_B];
155 if (acs->showHud) {
157 }
159
160 hid = acs->hudElemIDs[HIDX_CHARGE_C];
161 if (acs->showHud) {
163 }
165
166 hid = acs->hudElemIDs[HIDX_STICK];
167 if (acs->showHud) {
169 }
171
172 acs->state = AC_STATE_APPEAR;
173 break;
174 case AC_STATE_APPEAR:
176 acs->hudPosX += 20;
177 if (acs->hudPosX > 50) {
178 acs->hudPosX = 50;
179 }
180 hud_element_set_render_pos(acs->hudElemIDs[HIDX_FRAME], acs->hudPosX, acs->hudPosY);
181 hud_element_set_render_pos(acs->hudElemIDs[HIDX_WAIT], acs->hudPosX + 21, acs->hudPosY - 3);
182 hud_element_set_render_pos(acs->hudElemIDs[HIDX_CHARGE_A], acs->hudPosX + 5, acs->hudPosY + 1);
183 hud_element_set_render_pos(acs->hudElemIDs[HIDX_CHARGE_B], acs->hudPosX - 7, acs->hudPosY + 1);
184 hud_element_set_render_pos(acs->hudElemIDs[HIDX_CHARGE_C], acs->hudPosX - 19, acs->hudPosY + 1);
185 hud_element_set_render_pos(acs->hudElemIDs[HIDX_STICK], acs->hudPosX, acs->hudPosY - 23);
186 if (acs->autoSucceed != 0) {
187 hid = acs->hudElemIDs[HIDX_RIGHT_ON];
188 hud_element_set_render_pos(hid, acs->hudPosX + 50, acs->hudPosY);
189 if (acs->showHud) {
191 break;
192 }
193 }
194 break;
195 case AC_STATE_START:
197 if (acs->prepareTime < 15) {
198 hud_element_set_alpha(acs->hudElemIDs[HIDX_FRAME], 255);
199 hud_element_set_alpha(acs->hudElemIDs[HIDX_WAIT], 255);
200 hud_element_set_alpha(acs->hudElemIDs[HIDX_CHARGE_A], 255);
201 hud_element_set_alpha(acs->hudElemIDs[HIDX_CHARGE_B], 255);
202 hud_element_set_alpha(acs->hudElemIDs[HIDX_CHARGE_C], 255);
203 hud_element_set_alpha(acs->hudElemIDs[HIDX_STICK], 255);
204 }
205
206 if (acs->prepareTime != 0) {
207 acs->prepareTime--;
208 return;
209 }
210
211 acs->stateTimer = 0;
212 if (!(battleStatus->curButtonsDown & BUTTON_STICK_LEFT) && battleStatus->actionCommandMode < AC_MODE_TUTORIAL) {
213 acs->hammerMissedStart = true;
214 }
215 acs->state = AC_STATE_ACTIVE;
216
217 // fallthrough
218 case AC_STATE_ACTIVE:
220
221 if (battleStatus->actionCommandMode <= AC_MODE_TUTORIAL_BLOCK) {
222 return;
223 }
224
225 inputWindow = battleStatus->actionCmdDifficultyTable[acs->difficulty];
226 new_var = inputWindow + 2;
227 oneThird = (acs->duration - new_var) / 3;
228
229 if (acs->stateTimer < oneThird) {
231 battleStatus->actionProgress = 0;
232 if (acs->stateTimer == 0) {
233 if (acs->playHammerSounds) {
235 }
236 }
237 } else if (acs->stateTimer < oneThird * 2) {
239 battleStatus->actionProgress = 1;
240 if (acs->stateTimer == oneThird) {
241 if (acs->playHammerSounds) {
243 }
244 }
245 } else if (acs->stateTimer < oneThird * 3) {
247 battleStatus->actionProgress = 2;
248 if (acs->stateTimer == oneThird * 2) {
249 if (acs->playHammerSounds) {
251 }
252 }
253 }
254
255 if (acs->stateTimer == (-(inputWindow + 1) + acs->duration)) {
256 battleStatus->actionProgress = 3;
259 if (acs->playHammerSounds) {
261 }
262 if (acs->autoSucceed != 0 && acs->autoSucceed != 2) {
263 acs->autoSucceed = 2;
264 acs->stateTimer = acs->duration - 4;
265 }
266 }
267 inputWindow = battleStatus->actionCmdDifficultyTable[acs->difficulty] - (acs->duration - acs->stateTimer) + 3;
268 if (inputWindow < 0) {
269 inputWindow = 0;
270 }
271
272 // has the stick been release too early?
273 if (!(battleStatus->curButtonsDown & BUTTON_STICK_LEFT)
274 && inputWindow == 0
275 && acs->autoSucceed == 0
276 && battleStatus->actionCommandMode < AC_MODE_TUTORIAL
277 ) {
278 battleStatus->actionQuality = AC_QUALITY_FAILED;
279 battleStatus->actionResult = ACTION_RESULT_EARLY;
281 return;
282 }
283
284 // step back several frames in the input buffer
285 bufferPos = battleStatus->inputBufferPos;
287 if (bufferPos < 0) {
288 bufferPos += ARRAY_COUNT(battleStatus->holdInputBuffer);
289 }
290
291 // has the stick been released within the window?
292 if (battleStatus->actionQuality == 0) {
293 for (i = 0; i < inputWindow; i++) {
294 if (bufferPos >= ARRAY_COUNT(battleStatus->holdInputBuffer)) {
295 bufferPos -= ARRAY_COUNT(battleStatus->holdInputBuffer);
296 }
297
298 if (!(battleStatus->holdInputBuffer[bufferPos] & BUTTON_STICK_LEFT) || acs->autoSucceed != 0) {
299 battleStatus->actionQuality = 1;
300 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
302 }
303 bufferPos++;
304 }
305 }
306
307 if (battleStatus->actionCommandMode < AC_MODE_TUTORIAL || acs->stateTimer != acs->duration) {
308 acs->stateTimer++;
309 if (acs->duration < acs->stateTimer) {
310 if (battleStatus->actionQuality == 0) {
311 battleStatus->actionQuality = AC_QUALITY_FAILED;
312 }
313
314 if (battleStatus->actionQuality == 1) {
316 }
317
319 acs->stateTimer = 5;
320 acs->state = AC_STATE_DISPOSE;
321 }
322 }
323 break;
324 case AC_STATE_DISPOSE:
325 if (acs->stateTimer != 0) {
326 acs->stateTimer--;
327 return;
328 }
330 break;
331 }
332}
333
343
BSS s32 PopupMenu_SelectedIndex
BSS ActionCommandStatus gActionCommandStatus
Definition action_cmd.c:91
void action_command_free(void)
Definition action_cmd.c:446
void increment_action_command_attempt_count(void)
Definition action_cmd.c:640
s32 adjust_action_command_difficulty(s32 difficultyLevel)
Definition action_cmd.c:101
void increment_action_command_success_count(void)
Definition action_cmd.c:654
void action_command_init_status(void)
Definition action_cmd.c:256
HudScript HES_TimingCharge3
#define AC_QUALITY_FAILED
Definition action_cmd.h:66
HudElemID hudElemIDs[16]
Definition action_cmd.h:83
HudScript HES_TimingReady
@ AC_STATE_APPEAR
Definition action_cmd.h:35
@ AC_STATE_DISPOSE
Definition action_cmd.h:38
@ AC_STATE_INIT
Definition action_cmd.h:34
@ AC_STATE_ACTIVE
Definition action_cmd.h:37
@ AC_STATE_START
Definition action_cmd.h:36
HudScript HES_StickTapNeutral
HudScript HES_TimingCharge4b
HudScript HES_TimingWait
HudScript HES_TimingCharge4a
HudScript HES_TimingCharge4c
HudScript HES_RightOn
HudScript HES_StickHoldLeft
HudScript HES_TimingCharge2
HudScript HES_TimingCharge1
@ AC_MODE_TUTORIAL_BLOCK
Definition action_cmd.h:59
@ AC_MODE_TUTORIAL
Definition action_cmd.h:62
@ AC_MODE_NOT_LEARNED
Definition action_cmd.h:60
HudScript HES_TimingBar1Chance
s32 actionCmdTableHammer[]
Definition action_cmd.c:29
void N free(void)
Definition hammer.c:344
void N update(void)
Definition hammer.c:122
void N draw(void)
Definition hammer.c:334
@ HIDX_CHARGE_C
Definition hammer.c:14
@ HIDX_STICK
Definition hammer.c:15
@ HIDX_FRAME
Definition hammer.c:10
@ HIDX_CHARGE_A
Definition hammer.c:12
@ HIDX_RIGHT_ON
Definition hammer.c:16
@ HIDX_WAIT
Definition hammer.c:11
@ HIDX_CHARGE_B
Definition hammer.c:13
s32 HudElemID
@ ACTION_COMMAND_SMASH
Definition enums.h:3508
@ BUTTON_STICK_LEFT
Definition enums.h:2779
@ BS_FLAGS1_2000
Definition enums.h:3615
@ SOUND_TIMING_BAR_TICK
Definition enums.h:955
@ SOUND_TIMING_BAR_GO
Definition enums.h:956
@ ACTION_RESULT_EARLY
Definition enums.h:1992
@ ACTION_RESULT_SUCCESS
Definition enums.h:1994
@ ACTION_RESULT_FAIL
Definition enums.h:1993
#define ApiStatus_DONE2
Definition evt.h:119
s32 Bytecode
Definition evt.h:7
void btl_set_popup_duration(s32 duration)
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1730
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)
HudElemID hud_element_create(HudScript *anim)
Creates a new HUD element and returns its ID.
void hud_element_set_render_pos(s32 id, s32 x, s32 y)
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:72
@ HUD_ELEMENT_FLAG_MANUAL_RENDER
Definition hud_element.h:78
void sfx_play_sound(s32 soundID)
#define ARRAY_COUNT(arr)
Definition macros.h:39
#define POPUP_MSG_OFF
Definition battle.h:280
#define POPUP_MSG_ON
Definition battle.h:279
BattleStatus gBattleStatus
Definition battle.cpp:14
void N init(Npc *bombette)
Definition bombette.c:66