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
6extern s32 actionCmdTableHammer[];
7
8// indices into ActionCommandStatus::hudElements for this action command
9enum {
17};
18
19API_CALLABLE(N(init)) {
21 BattleStatus* battleStatus = &gBattleStatus;
22 HudElemID hid;
23
24 battleStatus->maxActionQuality = 1;
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
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;
46
48 acs->hudElemIDs[HIDX_WAIT] = hid;
52
54 acs->hudElemIDs[HIDX_CHARGE_A] = hid;
58
60 acs->hudElemIDs[HIDX_CHARGE_B] = hid;
64
66 acs->hudElemIDs[HIDX_CHARGE_C] = hid;
70
72 acs->hudElemIDs[HIDX_STICK] = hid;
76
78 acs->hudElemIDs[HIDX_RIGHT_ON] = hid;
82 hud_element_set_alpha(hid, 255);
83
84 return ApiStatus_DONE2;
85}
86
87API_CALLABLE(N(start)) {
89 BattleStatus* battleStatus = &gBattleStatus;
90 Bytecode* args = script->ptrReadPos;
91
92 if (battleStatus->actionCommandMode == AC_MODE_NOT_LEARNED) {
93 battleStatus->actionQuality = 0;
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++);
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;
115 battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
116
118
119 return ApiStatus_DONE2;
120}
121
122void N(update)(void) {
124 BattleStatus* battleStatus = &gBattleStatus;
125 Actor* partner = battleStatus->partnerActor;
126 HudElemID hid;
127 f32 oneThird;
128 s32 inputWindow;
129 s32 bufferPos;
130 s32 i;
131 s32 new_var;
132
133 switch (acs->state) {
134 case AC_STATE_INIT:
136
137 hid = acs->hudElemIDs[HIDX_FRAME];
138 if (acs->showHud) {
140 }
141 hud_element_set_alpha(hid, 255);
142
143 hid = acs->hudElemIDs[HIDX_WAIT];
144 if (acs->showHud) {
146 }
147 hud_element_set_alpha(hid, 255);
148
149 hid = acs->hudElemIDs[HIDX_CHARGE_A];
150 if (acs->showHud) {
152 }
153 hud_element_set_alpha(hid, 255);
154
155 hid = acs->hudElemIDs[HIDX_CHARGE_B];
156 if (acs->showHud) {
158 }
159 hud_element_set_alpha(hid, 255);
160
161 hid = acs->hudElemIDs[HIDX_CHARGE_C];
162 if (acs->showHud) {
164 }
165 hud_element_set_alpha(hid, 255);
166
167 hid = acs->hudElemIDs[HIDX_STICK];
168 if (acs->showHud) {
170 }
171 hud_element_set_alpha(hid, 255);
172
173 acs->state = AC_STATE_APPEAR;
174 break;
175 case AC_STATE_APPEAR:
177 acs->hudPosX += 20;
178 if (acs->hudPosX > 50) {
179 acs->hudPosX = 50;
180 }
187 if (acs->autoSucceed != 0) {
188 hid = acs->hudElemIDs[HIDX_RIGHT_ON];
189 hud_element_set_render_pos(hid, acs->hudPosX + 50, acs->hudPosY);
190 if (acs->showHud) {
192 break;
193 }
194 }
195 break;
196 case AC_STATE_START:
198 if (acs->prepareTime < 15) {
205 }
206
207 if (acs->prepareTime != 0) {
208 acs->prepareTime--;
209 return;
210 }
211
212 acs->stateTimer = 0;
213 if (!(battleStatus->curButtonsDown & BUTTON_STICK_LEFT) && battleStatus->actionCommandMode < AC_MODE_TUTORIAL) {
214 acs->hammerMissedStart = TRUE;
215 }
216 acs->state = AC_STATE_ACTIVE;
217
218 // fallthrough
219 case AC_STATE_ACTIVE:
221
222 if (battleStatus->actionCommandMode <= AC_MODE_TUTORIAL_BLOCK) {
223 return;
224 }
225
226 inputWindow = battleStatus->actionCmdDifficultyTable[acs->difficulty];
227 new_var = inputWindow + 2;
228 oneThird = (acs->duration - new_var) / 3;
229
230 if (acs->stateTimer < oneThird) {
232 battleStatus->actionProgress = 0;
233 if (acs->stateTimer == 0) {
234 if (acs->playHammerSounds) {
236 }
237 }
238 } else if (acs->stateTimer < oneThird * 2) {
240 battleStatus->actionProgress = 1;
241 if (acs->stateTimer == oneThird) {
242 if (acs->playHammerSounds) {
244 }
245 }
246 } else if (acs->stateTimer < oneThird * 3) {
248 battleStatus->actionProgress = 2;
249 if (acs->stateTimer == oneThird * 2) {
250 if (acs->playHammerSounds) {
252 }
253 }
254 }
255
256 if (acs->stateTimer == (-(inputWindow + 1) + acs->duration)) {
257 battleStatus->actionProgress = 3;
260 if (acs->playHammerSounds) {
262 }
263 if (acs->autoSucceed != 0 && acs->autoSucceed != 2) {
264 acs->autoSucceed = 2;
265 acs->stateTimer = acs->duration - 4;
266 }
267 }
268 inputWindow = battleStatus->actionCmdDifficultyTable[acs->difficulty] - (acs->duration - acs->stateTimer) + 3;
269 if (inputWindow < 0) {
270 inputWindow = 0;
271 }
272
273 // has the stick been release too early?
274 if (!(battleStatus->curButtonsDown & BUTTON_STICK_LEFT)
275 && inputWindow == 0
276 && acs->autoSucceed == 0
277 && battleStatus->actionCommandMode < AC_MODE_TUTORIAL
278 ) {
279 battleStatus->actionQuality = AC_QUALITY_FAILED;
280 battleStatus->actionResult = ACTION_RESULT_EARLY;
282 return;
283 }
284
285 // step back several frames in the input buffer
286 bufferPos = battleStatus->inputBufferPos;
287 bufferPos -= inputWindow;
288 if (bufferPos < 0) {
289 bufferPos += ARRAY_COUNT(battleStatus->holdInputBuffer);
290 }
291
292 // has the stick been released within the window?
293 if (battleStatus->actionQuality == 0) {
294 for (i = 0; i < inputWindow; i++) {
295 if (bufferPos >= ARRAY_COUNT(battleStatus->holdInputBuffer)) {
296 bufferPos -= ARRAY_COUNT(battleStatus->holdInputBuffer);
297 }
298
299 if (!(battleStatus->holdInputBuffer[bufferPos] & BUTTON_STICK_LEFT) || acs->autoSucceed != 0) {
300 battleStatus->actionQuality = 1;
301 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
303 }
304 bufferPos++;
305 }
306 }
307
308 if (battleStatus->actionCommandMode < AC_MODE_TUTORIAL || acs->stateTimer != acs->duration) {
309 acs->stateTimer++;
310 if (acs->duration < acs->stateTimer) {
311 if (battleStatus->actionQuality == 0) {
312 battleStatus->actionQuality = AC_QUALITY_FAILED;
313 }
314
315 if (battleStatus->actionQuality == 1) {
317 }
318
320 acs->stateTimer = 5;
321 acs->state = AC_STATE_DISPOSE;
322 }
323 }
324 break;
325 case AC_STATE_DISPOSE:
326 if (acs->stateTimer != 0) {
327 acs->stateTimer--;
328 return;
329 }
331 break;
332 }
333}
334
344
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:641
s32 adjust_action_command_difficulty(s32 difficultyLevel)
Definition action_cmd.c:101
void increment_action_command_success_count(void)
Definition action_cmd.c:655
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
@ 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 actionCmdTableHammer[]
Definition action_cmd.c:29
void N free(void)
Definition hammer.c:345
void N update(void)
Definition hammer.c:122
void N draw(void)
Definition hammer.c:335
s32 HudElemID
@ ACTION_COMMAND_SMASH
Definition enums.h:3474
@ BUTTON_STICK_LEFT
Definition enums.h:2793
@ BS_FLAGS1_2000
Definition enums.h:3581
@ SOUND_TIMING_BAR_TICK
Definition enums.h:952
@ SOUND_TIMING_BAR_GO
Definition enums.h:953
@ ACTION_RESULT_EARLY
Definition enums.h:1966
@ 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:1689
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:72
@ HUD_ELEMENT_FLAG_80
Definition hud_element.h:78
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 holdInputBuffer[64]
struct Actor * partnerActor
s32 * actionCmdDifficultyTable
BattleStatus gBattleStatus
Definition battle.c:11
void N init(Npc *bombette)
Definition bombette.c:66