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
8API_CALLABLE(N(init)) {
9 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
10 BattleStatus* battleStatus = &gBattleStatus;
11 s32 id;
12
13 battleStatus->unk_82 = 1;
15 battleStatus->actionResult = ACTION_RESULT_FAIL;
16
18 battleStatus->actionSuccess = 0;
19 battleStatus->actionQuality = 0;
20 return ApiStatus_DONE2;
21 }
22
24 actionCommandStatus->actionCommandID = ACTION_COMMAND_SMASH;
25 actionCommandStatus->hudPosX = -48;
26 actionCommandStatus->state = 0;
27 actionCommandStatus->wrongButtonPressed = FALSE;
28 actionCommandStatus->hudPosY = 96;
29
31 actionCommandStatus->hudElements[0] = id;
33 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
35
37 actionCommandStatus->hudElements[1] = id;
39 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
41
43 actionCommandStatus->hudElements[2] = id;
45 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
47
49 actionCommandStatus->hudElements[3] = id;
51 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
53
55 actionCommandStatus->hudElements[4] = id;
57 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
59
61 actionCommandStatus->hudElements[5] = id;
63 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
65
67 actionCommandStatus->hudElements[6] = id;
69 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
71 hud_element_set_alpha(id, 255);
72
73 return ApiStatus_DONE2;
74}
75
76API_CALLABLE(N(start)) {
77 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
78 BattleStatus* battleStatus = &gBattleStatus;
79 Bytecode* args = script->ptrReadPos;
80
82 battleStatus->actionSuccess = 0;
83 battleStatus->actionQuality = 0;
84 return ApiStatus_DONE2;
85 }
86
88 actionCommandStatus->prepareTime = evt_get_variable(script, *args++);
89 actionCommandStatus->duration = evt_get_variable(script, *args++);
90 actionCommandStatus->difficulty = evt_get_variable(script, *args);
91 actionCommandStatus->difficulty = adjust_action_command_difficulty(actionCommandStatus->difficulty);
92 actionCommandStatus->wrongButtonPressed = FALSE;
93 actionCommandStatus->playHammerSounds = TRUE;
94 if (actionCommandStatus->prepareTime < 0) {
95 actionCommandStatus->prepareTime = 0;
96 actionCommandStatus->playHammerSounds = FALSE;
97 }
98
99 actionCommandStatus->hammerMissedStart = FALSE;
100 battleStatus->actionSuccess = 0;
101 battleStatus->actionQuality = 0;
102 battleStatus->actionResult = ACTION_RESULT_FAIL;
103 actionCommandStatus->state = 10;
104 battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
106 return ApiStatus_DONE2;
107}
108
109void N(update)(void) {
110 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
111 BattleStatus* battleStatus = &gBattleStatus;
112 Actor* partner = battleStatus->partnerActor;
113 s32 id;
114 f32 temp_f20;
115 s32 phi_s0;
116 s32 new_var;
117 s32 a;
118
119 switch (actionCommandStatus->state) {
120 case 0:
122
123 id = actionCommandStatus->hudElements[0];
124 if (actionCommandStatus->showHud) {
126 }
127 hud_element_set_alpha(id, 255);
128
129 id = actionCommandStatus->hudElements[1];
130 if (actionCommandStatus->showHud) {
132 }
133 hud_element_set_alpha(id, 255);
134
135 id = actionCommandStatus->hudElements[2];
136 if (actionCommandStatus->showHud) {
138 }
139 hud_element_set_alpha(id, 255);
140
141 id = actionCommandStatus->hudElements[3];
142 if (actionCommandStatus->showHud) {
144 }
145 hud_element_set_alpha(id, 255);
146
147 id = actionCommandStatus->hudElements[4];
148 if (actionCommandStatus->showHud) {
150 }
151 hud_element_set_alpha(id, 255);
152
153 id = actionCommandStatus->hudElements[5];
154 if (actionCommandStatus->showHud) {
156 }
157 hud_element_set_alpha(id, 255);
158
159 actionCommandStatus->state = 1;
160 break;
161 case 1:
163 actionCommandStatus->hudPosX += 20;
164 if (actionCommandStatus->hudPosX > 50) {
165 actionCommandStatus->hudPosX = 50;
166 }
167 hud_element_set_render_pos(actionCommandStatus->hudElements[0], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
168 hud_element_set_render_pos(actionCommandStatus->hudElements[1], actionCommandStatus->hudPosX + 21, actionCommandStatus->hudPosY - 3);
169 hud_element_set_render_pos(actionCommandStatus->hudElements[2], actionCommandStatus->hudPosX + 5, actionCommandStatus->hudPosY + 1);
170 hud_element_set_render_pos(actionCommandStatus->hudElements[3], actionCommandStatus->hudPosX - 7, actionCommandStatus->hudPosY + 1);
171 hud_element_set_render_pos(actionCommandStatus->hudElements[4], actionCommandStatus->hudPosX - 19, actionCommandStatus->hudPosY + 1);
172 hud_element_set_render_pos(actionCommandStatus->hudElements[5], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY - 23);
173 if (actionCommandStatus->autoSucceed != 0) {
174 id = actionCommandStatus->hudElements[6];
175 hud_element_set_render_pos(id, actionCommandStatus->hudPosX + 50, actionCommandStatus->hudPosY);
176 if (actionCommandStatus->showHud) {
178 break;
179 }
180 }
181 break;
182 case 10:
184 if (actionCommandStatus->prepareTime < 15) {
185 hud_element_set_alpha(actionCommandStatus->hudElements[0], 255);
186 hud_element_set_alpha(actionCommandStatus->hudElements[1], 255);
187 hud_element_set_alpha(actionCommandStatus->hudElements[2], 255);
188 hud_element_set_alpha(actionCommandStatus->hudElements[3], 255);
189 hud_element_set_alpha(actionCommandStatus->hudElements[4], 255);
190 hud_element_set_alpha(actionCommandStatus->hudElements[5], 255);
191 }
192
193 if (actionCommandStatus->prepareTime != 0) {
194 actionCommandStatus->prepareTime--;
195 return;
196 }
197
198 actionCommandStatus->frameCounter = 0;
199 if (!(battleStatus->curButtonsDown & BUTTON_STICK_LEFT) && battleStatus->actionCommandMode < ACTION_COMMAND_MODE_TUTORIAL) {
200 actionCommandStatus->hammerMissedStart = TRUE;
201 }
202 actionCommandStatus->state = 11;
203 case 11:
205
207 return;
208 }
209
210 phi_s0 = battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty];
211 new_var = phi_s0 + 2;
212 temp_f20 = (actionCommandStatus->duration - new_var) / 3;
213
214 if (actionCommandStatus->frameCounter < temp_f20) {
215 hud_element_set_script(actionCommandStatus->hudElements[4], &HES_TimingCharge3);
216 battleStatus->actionQuality = 0;
217 if (actionCommandStatus->frameCounter == 0 && actionCommandStatus->playHammerSounds) {
219 }
220 } else if (actionCommandStatus->frameCounter < temp_f20 * 2) {
221 hud_element_set_script(actionCommandStatus->hudElements[3], &HES_TimingCharge2);
222 battleStatus->actionQuality = 1;
223 if (actionCommandStatus->frameCounter == temp_f20) {
224 if (actionCommandStatus->playHammerSounds) {
226 }
227 }
228 } else if (actionCommandStatus->frameCounter < temp_f20 * 3.0f) {
229 hud_element_set_script(actionCommandStatus->hudElements[2], &HES_TimingCharge1);
230 battleStatus->actionQuality = 2;
231 if (actionCommandStatus->frameCounter == temp_f20 * 2) {
232 if (actionCommandStatus->playHammerSounds) {
234 }
235 }
236 }
237
238 if (actionCommandStatus->frameCounter == (~phi_s0 + actionCommandStatus->duration)) {
239 battleStatus->actionQuality = 3;
240 hud_element_set_script(actionCommandStatus->hudElements[1], &HES_TimingReady);
241 hud_element_set_script(actionCommandStatus->hudElements[5], &HES_StickTapNeutral);
242 if (actionCommandStatus->playHammerSounds) {
244 }
245 if (actionCommandStatus->autoSucceed != 0 && actionCommandStatus->autoSucceed != 2) {
246 actionCommandStatus->autoSucceed = 2;
247 actionCommandStatus->frameCounter = actionCommandStatus->duration - 4;
248 }
249 }
250
251 a = actionCommandStatus->duration - actionCommandStatus->frameCounter;
252 phi_s0 = battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty] - a + 3;
253 if (phi_s0 < 0) {
254 phi_s0 = 0;
255 }
256
257 if (!(battleStatus->curButtonsDown & BUTTON_STICK_LEFT) &&
258 phi_s0 == 0 &&
259 actionCommandStatus->autoSucceed == 0 &&
261 {
262 battleStatus->actionSuccess = -1;
263 battleStatus->actionResult = ACTION_RESULT_EARLY;
265 } else {
266 s32 i;
267 s32 bufferPos;
268
269 bufferPos = battleStatus->inputBufferPos;
270 bufferPos -= phi_s0;
271 if (bufferPos < 0) {
272 bufferPos += ARRAY_COUNT(battleStatus->holdInputBuffer);
273 }
274
275 if (battleStatus->actionSuccess == 0) {
276 for (i = 0; i < phi_s0; i++, bufferPos++) {
277 if (bufferPos >= ARRAY_COUNT(battleStatus->holdInputBuffer)) {
278 bufferPos -= ARRAY_COUNT(battleStatus->holdInputBuffer);
279 }
280
281 if (!(battleStatus->holdInputBuffer[bufferPos] & BUTTON_STICK_LEFT) ||
282 actionCommandStatus->autoSucceed != 0)
283 {
284 battleStatus->actionSuccess = 1;
285 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
287 }
288 }
289 }
290
291 if (battleStatus->actionCommandMode < ACTION_COMMAND_MODE_TUTORIAL || actionCommandStatus->frameCounter != actionCommandStatus->duration) {
292 actionCommandStatus->frameCounter++;
293 if (actionCommandStatus->duration < actionCommandStatus->frameCounter) {
294 if (battleStatus->actionSuccess == 0) {
295 battleStatus->actionSuccess = -1;
296 }
297
298 if (battleStatus->actionSuccess == 1) {
300 }
301
303 actionCommandStatus->frameCounter = 5;
304 actionCommandStatus->state = 12;
305 }
306 }
307 }
308 break;
309 case 12:
310 if (actionCommandStatus->frameCounter != 0) {
311 actionCommandStatus->frameCounter--;
312 return;
313 }
315 break;
316 }
317}
318
328
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_TimingCharge3
HudScript HES_TimingReady
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
@ ACTION_COMMAND_MODE_TUTORIAL
Definition action_cmd.h:40
@ ACTION_COMMAND_MODE_TUTORIAL_BLOCK
Definition action_cmd.h:37
@ ACTION_COMMAND_MODE_NOT_LEARNED
Definition action_cmd.h:38
HudScript HES_TimingBar1Chance
s32 actionCmdTableHammer[]
Definition action_cmd.c:29
void N free(void)
Definition hammer.c:329
void N update(void)
Definition hammer.c:109
void N draw(void)
Definition hammer.c:319
@ ACTION_COMMAND_SMASH
Definition enums.h:3474
@ BUTTON_STICK_LEFT
Definition enums.h:2793
@ BS_FLAGS1_2000
Definition enums.h:3582
@ 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:1690
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
void sfx_play_sound(s32 soundID)
Definition sfx.c:517
#define ARRAY_COUNT(arr)
Definition macros.h:40
s32 holdInputBuffer[64]
struct Actor * partnerActor
s32 * actionCmdDifficultyTable
BattleStatus gBattleStatus
Definition battle.c:11
void N init(Npc *bombette)
Definition bombette.c:66