Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
break_free.c
Go to the documentation of this file.
1#include "common.h"
2#include "battle/action_cmd.h"
3
4#define NAMESPACE action_command_break_free
5
6extern s32 actionCmdTableBreakFree[];
7
8API_CALLABLE(N(init)) {
9 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
10 BattleStatus* battleStatus = &gBattleStatus;
11 s32 id;
12
13 battleStatus->unk_82 = 0;
15 battleStatus->actionResult = ACTION_RESULT_NONE;
16
18 battleStatus->actionSuccess = 0;
19 return ApiStatus_DONE2;
20 }
21
23 actionCommandStatus->actionCommandID = ACTION_COMMAND_BREAK_FREE;
24 actionCommandStatus->showHud = TRUE;
25 actionCommandStatus->state = 0;
26 actionCommandStatus->wrongButtonPressed = FALSE;
27 actionCommandStatus->barFillLevel = 0;
28 actionCommandStatus->thresholdLevel = 0;
29 actionCommandStatus->barFillWidth = 0;
30 battleStatus->actionSuccess = 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);
39
41 actionCommandStatus->hudElements[1] = id;
42 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
45
47 actionCommandStatus->hudElements[2] = id;
48 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
51
53 actionCommandStatus->hudElements[3] = id;
54 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
57
58 return ApiStatus_DONE2;
59}
60
61API_CALLABLE(N(start)) {
62 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
63 BattleStatus* battleStatus = &gBattleStatus;
64 Bytecode* args = script->ptrReadPos;
65
67 battleStatus->actionSuccess = 0;
68 return ApiStatus_DONE2;
69 }
70
72
73 actionCommandStatus->prepareTime = evt_get_variable(script, *args++);
74 actionCommandStatus->duration = evt_get_variable(script, *args++);
75 actionCommandStatus->unk_5A = evt_get_variable(script, *args++);
76 actionCommandStatus->difficulty = evt_get_variable(script, *args++);
77 actionCommandStatus->difficulty = adjust_action_command_difficulty(actionCommandStatus->difficulty);
78
79 actionCommandStatus->wrongButtonPressed = FALSE;
80 actionCommandStatus->barFillLevel = 0;
81 actionCommandStatus->thresholdLevel = 0;
82 actionCommandStatus->barFillWidth = 0;
83
84 battleStatus->actionSuccess = 0;
85 battleStatus->actionResult = ACTION_RESULT_NONE;
86 battleStatus->unk_82 = actionCommandStatus->mashMeterCutoffs[actionCommandStatus->mashMeterIntervals - 1];
87
88 actionCommandStatus->thresholdLevel = rand_int(actionCommandStatus->unk_5A);
89 actionCommandStatus->unk_5C = 0;
90 actionCommandStatus->state = 10;
91 battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
92
93 return ApiStatus_DONE2;
94}
95
96void N(update)(void) {
97 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
98 BattleStatus* battleStatus = &gBattleStatus;
99 s32 id;
100
101 switch (actionCommandStatus->state) {
102 case 0:
104
105 id = actionCommandStatus->hudElements[0];
106 hud_element_set_alpha(id, 255);
107 if (actionCommandStatus->showHud) {
109 }
110
111 id = actionCommandStatus->hudElements[1];
112 hud_element_set_alpha(id, 255);
113 if (actionCommandStatus->showHud) {
115 }
116
117 id = actionCommandStatus->hudElements[2];
118 hud_element_set_alpha(id, 255);
119 if (actionCommandStatus->showHud) {
121 }
122
123 id = actionCommandStatus->hudElements[3];
124 hud_element_set_alpha(id, 255);
125 if (actionCommandStatus->showHud) {
127 }
128
129 actionCommandStatus->state = 1;
130 break;
131 case 1:
133 actionCommandStatus->hudPosX += 20;
134 if (actionCommandStatus->hudPosX > 50) {
135 actionCommandStatus->hudPosX = 50;
136 }
137 hud_element_set_render_pos(actionCommandStatus->hudElements[0], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
138 hud_element_set_render_pos(actionCommandStatus->hudElements[1], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
139 hud_element_set_render_pos(actionCommandStatus->hudElements[2], actionCommandStatus->hudPosX + 31, actionCommandStatus->hudPosY - 1);
140 hud_element_set_render_pos(actionCommandStatus->hudElements[3], actionCommandStatus->hudPosX + 31, actionCommandStatus->hudPosY + 17);
141 break;
142 case 10:
144 if (actionCommandStatus->prepareTime != 0) {
145 actionCommandStatus->prepareTime--;
146 return;
147 }
148 hud_element_set_script(actionCommandStatus->hudElements[0], &HES_MashAButton);
149 actionCommandStatus->state = 11;
150 actionCommandStatus->frameCounter = actionCommandStatus->duration;
151 case 11:
153 if (actionCommandStatus->unk_5C == 0) {
154 actionCommandStatus->thresholdLevel++;
155 if (actionCommandStatus->thresholdLevel >= actionCommandStatus->unk_5A) {
156 actionCommandStatus->thresholdLevel = actionCommandStatus->unk_5A;
157 actionCommandStatus->unk_5C = 1;
158 }
159 } else {
160 actionCommandStatus->thresholdLevel--;
161 if (actionCommandStatus->thresholdLevel <= 0) {
162 actionCommandStatus->thresholdLevel = 0;
163 actionCommandStatus->unk_5C = 0;
164 }
165 }
166
167 if (!actionCommandStatus->berserkerEnabled) {
168 s32 inputBufPos = battleStatus->inputBufferPos;
169 s32 temp_a2 = actionCommandStatus->duration - actionCommandStatus->frameCounter;
170 s32 i;
171
172 actionCommandStatus->barFillLevel = 0;
173
174 inputBufPos -= temp_a2;
175 if (inputBufPos < 0) {
176 inputBufPos += ARRAY_COUNT(battleStatus->pushInputBuffer);
177 }
178
179 for (i = 0; i < temp_a2; i++, inputBufPos++) {
180 if (inputBufPos >= ARRAY_COUNT(battleStatus->pushInputBuffer)) {
181 inputBufPos -= ARRAY_COUNT(battleStatus->pushInputBuffer);
182 }
183 if (battleStatus->pushInputBuffer[inputBufPos] & BUTTON_A) {
184 actionCommandStatus->barFillLevel += battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty];
185 }
186 }
187 } else {
188 actionCommandStatus->barFillLevel += (battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty]) / 4;
189 actionCommandStatus->barFillLevel += rand_int(battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty] / 4);
190 }
191
192 battleStatus->actionSuccess = actionCommandStatus->barFillLevel / 100;
193 if (actionCommandStatus->frameCounter != 0) {
194 actionCommandStatus->frameCounter--;
195 return;
196 }
197
198 if (battleStatus->actionSuccess >= actionCommandStatus->mashMeterCutoffs[actionCommandStatus->mashMeterIntervals] - actionCommandStatus->thresholdLevel) {
199 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
200 battleStatus->actionSuccess = 1;
201 } else {
202 battleStatus->actionResult = ACTION_RESULT_MINUS_2;
203 battleStatus->actionSuccess = -1;
204 }
205
207 actionCommandStatus->frameCounter = 20;
208 actionCommandStatus->state = 12;
209 break;
210 case 12:
211 if (actionCommandStatus->frameCounter != 0) {
212 actionCommandStatus->frameCounter--;
213 return;
214 }
216 break;
217 }
218}
219
220void N(draw)(void) {
221 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
222 s32* hudElements = actionCommandStatus->hudElements;
223 s32 hudX;
224 s32 hudY;
225 s32 id;
226 s16 mashMeterCutoff;
227 s32 thirtyOne;
228
229 mashMeterCutoff = actionCommandStatus->mashMeterCutoffs[actionCommandStatus->mashMeterIntervals];
230 hudX = 60 - ((mashMeterCutoff - actionCommandStatus->thresholdLevel) * 60 / mashMeterCutoff);
231
232 // Putting 31 into a variable manually fixes regalloc, so perhaps this was a constant defined somewhere?
233 thirtyOne = 31;
234 hud_element_set_render_pos(hudElements[3], actionCommandStatus->hudPosX - (hudX - thirtyOne),
235 actionCommandStatus->hudPosY + 17);
236 hud_element_set_render_pos(hudElements[2], actionCommandStatus->hudPosX - (hudX - thirtyOne),
237 actionCommandStatus->hudPosY - 1);
238
239 if (!actionCommandStatus->berserkerEnabled) {
240 hud_element_draw_clipped(hudElements[0]);
241 }
242
243 id = hudElements[1];
245 hud_element_get_render_pos(id, &hudX, &hudY);
246
247 draw_mash_meter_multicolor(hudX, hudY, actionCommandStatus->barFillLevel / 100);
248 hud_element_draw_clipped(hudElements[2]);
249 hud_element_draw_clipped(hudElements[3]);
250}
251
BSS ActionCommandStatus gActionCommandStatus
Definition action_cmd.c:91
void draw_mash_meter_multicolor(s32 posX, s32 posY, s32 fillValue)
Definition action_cmd.c:226
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
HudScript HES_AButton
HudScript HES_BlueMeter
HudScript HES_RunAwayOK
HudScript HES_MashAButton
@ ACTION_COMMAND_MODE_NOT_LEARNED
Definition action_cmd.h:38
HudScript HES_RunningAway
void N free(void)
Definition break_free.c:252
s32 actionCmdTableBreakFree[]
Definition action_cmd.c:31
void N update(void)
Definition break_free.c:96
void N draw(void)
Definition break_free.c:220
#define rand_int
@ ACTION_COMMAND_BREAK_FREE
Definition enums.h:3476
@ BUTTON_A
Definition enums.h:2790
@ ACTION_RESULT_NONE
Definition enums.h:1963
@ ACTION_RESULT_SUCCESS
Definition enums.h:1968
@ ACTION_RESULT_MINUS_2
Definition enums.h:1965
#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_get_render_pos(s32 id, s32 *x, s32 *y)
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
#define ARRAY_COUNT(arr)
Definition macros.h:40
s32 * actionCmdDifficultyTable
s32 pushInputBuffer[64]
BattleStatus gBattleStatus
Definition battle.c:11
void N init(Npc *bombette)
Definition bombette.c:66