Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
hurricane.c File Reference

Go to the source code of this file.

Functions

void N update (void)
 
void N draw (void)
 
void N free (void)
 

Variables

s32 D_802A98E0_42FFC0 [8] = { 0, 25, 50, 75, 75, 0, 0, 0 }
 
s32 actionCmdTableHurricane []
 

Function Documentation

◆ update()

void N update ( void )

Definition at line 93 of file hurricane.c.

93 {
94 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
95 BattleStatus* battleStatus = &gBattleStatus;
96
97 s32 buttonsPushed;
98 s32 frameCount;
99 s32 buttonsAB;
100 s32 bufferPos;
101 s32 hudElement;
102 s32 mashMeterIndex;
103 s32 mashMeterCutoff;
104 s8 adjustedFillLevel;
105
106 switch (actionCommandStatus->state) {
107 case 0:
109
110 hudElement = actionCommandStatus->hudElements[0];
111 if (actionCommandStatus->showHud) {
113 }
114 hud_element_set_alpha(hudElement, 255);
115
116 hudElement = actionCommandStatus->hudElements[2];
117 if (actionCommandStatus->showHud) {
119 }
120 hud_element_set_alpha(hudElement, 255);
121
122 hudElement = actionCommandStatus->hudElements[1];
123 hud_element_set_alpha(hudElement, 255);
124 if (actionCommandStatus->showHud) {
126 }
127
128 actionCommandStatus->state = 1;
129 break;
130 case 1:
132 if (actionCommandStatus->hudPrepareTime != 0) {
133 actionCommandStatus->hudPrepareTime--;
134 break;
135 }
136
137 actionCommandStatus->hudPosX += 20;
138 if (actionCommandStatus->hudPosX > 50) {
139 actionCommandStatus->hudPosX = 50;
140 }
141
142 hud_element_set_render_pos(actionCommandStatus->hudElements[0], actionCommandStatus->hudPosX - 17,
143 actionCommandStatus->hudPosY);
144 hud_element_set_render_pos(actionCommandStatus->hudElements[2], actionCommandStatus->hudPosX + 23,
145 actionCommandStatus->hudPosY);
146 hud_element_set_render_pos(actionCommandStatus->hudElements[1], actionCommandStatus->hudPosX,
147 actionCommandStatus->hudPosY + 28);
148 break;
149 case 10:
151 if (actionCommandStatus->prepareTime != 0) {
152 actionCommandStatus->prepareTime--;
153 break;
154 }
155 hud_element_set_script(actionCommandStatus->hudElements[0], &HES_MashAButton);
156 hud_element_set_script(actionCommandStatus->hudElements[2], &HES_MashBButton1);
157 actionCommandStatus->barFillLevel = 0;
158 actionCommandStatus->unk_5C = 0;
159 actionCommandStatus->frameCounter = actionCommandStatus->duration;
160 actionCommandStatus->state = 11;
161 // fallthrough
162 case 11:
164 if (!actionCommandStatus->isBarFilled) {
165 s16 newFillLevel;
166
167 if (actionCommandStatus->targetWeakness != 0) {
168 s8 mashMeterIntervals = actionCommandStatus->mashMeterIntervals;
169 s16* mashMeterCutoffs = actionCommandStatus->mashMeterCutoffs;
170 s32 index;
171
172 mashMeterCutoff = mashMeterCutoffs[mashMeterIntervals];
173 index = actionCommandStatus->barFillLevel / mashMeterCutoff / 20;
174 newFillLevel = actionCommandStatus->barFillLevel - D_802A98E0_42FFC0[index];
175 } else {
176 newFillLevel = actionCommandStatus->barFillLevel - 10;
177 }
178
179 actionCommandStatus->barFillLevel = newFillLevel;
180 if (actionCommandStatus->barFillLevel < 0) {
181 actionCommandStatus->barFillLevel = 0;
182 }
183 }
184
185 bufferPos = battleStatus->inputBufferPos;
186 bufferPos -= 2;
187 if (bufferPos < 0) {
188 bufferPos += ARRAY_COUNT(battleStatus->pushInputBuffer);
189 }
190
191 buttonsPushed = 0;
192 frameCount = 1;
193
194 while (frameCount >= 0) {
195 if (bufferPos >= ARRAY_COUNT(battleStatus->pushInputBuffer)) {
196 bufferPos -= ARRAY_COUNT(battleStatus->pushInputBuffer);
197 }
198
199 buttonsPushed |= battleStatus->pushInputBuffer[bufferPos++];
200 frameCount--;
201 }
202
203 buttonsAB = BUTTON_A | BUTTON_B;
204 if ((buttonsPushed & buttonsAB) == buttonsAB) {
205 if (actionCommandStatus->targetWeakness != 0) {
206 s32 fillLevel;
207
208 fillLevel = actionCommandStatus->targetWeakness * 650;
209 fillLevel = fillLevel / 100 * battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty];
210
211 // Perplexing reuse of buttonsPushed here, but it fixes register allocation. Likely another
212 // subexpression from above can be put into a variable and reused instead.
213 //
214 // TODO: Find a way to avoid reusing buttonsPushed.
215 buttonsPushed = fillLevel / 100;
216
217 actionCommandStatus->barFillLevel += buttonsPushed;
218 } else {
219 actionCommandStatus->barFillLevel += 100;
220
221 if (actionCommandStatus->barFillLevel >= 500) {
222 actionCommandStatus->barFillLevel = 500;
223 }
224 }
225
226 bufferPos = battleStatus->inputBufferPos;
227 bufferPos -= 2;
228 if (bufferPos < 0) {
229 bufferPos += ARRAY_COUNT(battleStatus->pushInputBuffer);
230 }
231
232 frameCount = 1;
233 while (frameCount >= 0) {
234 if (bufferPos >= ARRAY_COUNT(battleStatus->pushInputBuffer)) {
235 bufferPos -= ARRAY_COUNT(battleStatus->pushInputBuffer);
236 }
237
238 battleStatus->pushInputBuffer[bufferPos++] = 0;
239 frameCount--;
240 }
241 }
242
243 if (actionCommandStatus->barFillLevel > 10000) {
244 hudElement = actionCommandStatus->hudElements[4];
245 actionCommandStatus->barFillLevel = 10000;
246 actionCommandStatus->isBarFilled = TRUE;
247 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX + 50,
248 actionCommandStatus->hudPosY + 28);
250 }
251
252 adjustedFillLevel = actionCommandStatus->barFillLevel / 100;
253
254 battleStatus->actionQuality = adjustedFillLevel;
255
256 if (actionCommandStatus->frameCounter == 0) {
257 s16 threshold;
258
259 // Again, reusing buttonsPushed specifically for reg-alloc. See above.
260 //
261 // TODO: Find a way to avoid reusing buttonsPushed.
262 buttonsPushed = actionCommandStatus->barFillLevel;
263 if (actionCommandStatus->targetWeakness == 0) {
264 buttonsPushed = 0;
265 }
266
267 if (buttonsPushed == 0) {
268 battleStatus->actionSuccess = -1;
269 } else {
270 battleStatus->actionSuccess = buttonsPushed / 100;
271 }
272
273 mashMeterIndex = actionCommandStatus->mashMeterIntervals - 1;
274 mashMeterCutoff = actionCommandStatus->mashMeterCutoffs[mashMeterIndex];
275 threshold = mashMeterCutoff / 2;
276
277 if (battleStatus->actionQuality <= threshold) {
278 battleStatus->actionResult = ACTION_RESULT_MINUS_4;
279 } else {
280 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
281 }
282
283 if (battleStatus->actionSuccess == 100) {
285 }
286
288 actionCommandStatus->frameCounter = 5;
289 actionCommandStatus->state = 12;
290 } else {
291 actionCommandStatus->frameCounter -= 1;
292 }
293 break;
294 case 12:
295 if (actionCommandStatus->targetWeakness == 0) {
296 actionCommandStatus->barFillLevel -= 100;
297 if (actionCommandStatus->barFillLevel < 0) {
298 actionCommandStatus->barFillLevel = 0;
299 }
300 }
301
302 if (actionCommandStatus->frameCounter != 0) {
303 actionCommandStatus->frameCounter -= 1;
304 } else {
306 }
307 break;
308 }
309}
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
HudScript HES_MashBButton1
HudScript HES_MashAButton
@ BUTTON_A
Definition enums.h:2790
@ BUTTON_B
Definition enums.h:2789
@ ACTION_RESULT_SUCCESS
Definition enums.h:1968
@ ACTION_RESULT_MINUS_4
Definition enums.h:1964
void btl_set_popup_duration(s32 duration)
void hud_element_set_alpha(s32 id, s32 opacity)
void hud_element_set_script(s32 id, HudScript *anim)
void hud_element_set_render_pos(s32 id, s32 x, s32 y)
void hud_element_clear_flags(s32 id, s32 flags)
Turns off the given flags.
@ HUD_ELEMENT_FLAG_DISABLED
Definition hud_element.h:74
s32 D_802A98E0_42FFC0[8]
Definition hurricane.c:6
#define ARRAY_COUNT(arr)
Definition macros.h:40
s32 * actionCmdDifficultyTable
s32 pushInputBuffer[64]
BattleStatus gBattleStatus
Definition battle.c:11

◆ draw()

void N draw ( void )

Definition at line 311 of file hurricane.c.

311 {
312 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
313 s32 hudY;
314 s32 hudX;
315 s32 id;
316
317 hud_element_draw_clipped(actionCommandStatus->hudElements[0]);
318 hud_element_draw_clipped(actionCommandStatus->hudElements[2]);
319
320 id = actionCommandStatus->hudElements[1];
322 hud_element_get_render_pos(id, &hudX, &hudY);
323
324 if (!actionCommandStatus->isBarFilled) {
325 draw_mash_meter_multicolor(hudX, hudY, actionCommandStatus->barFillLevel / 100);
326 } else {
327 draw_mash_meter_blink(hudX, hudY, actionCommandStatus->barFillLevel / 100);
328 }
329
330 hud_element_draw_clipped(actionCommandStatus->hudElements[4]);
331}
void draw_mash_meter_multicolor(s32 posX, s32 posY, s32 fillValue)
Definition action_cmd.c:226
void draw_mash_meter_blink(s32 posX, s32 posY, s32 fillValue)
Definition action_cmd.c:246
void hud_element_get_render_pos(s32 id, s32 *x, s32 *y)
void hud_element_draw_clipped(s32 id)

◆ free()

Variable Documentation

◆ D_802A98E0_42FFC0

s32 D_802A98E0_42FFC0[8] = { 0, 25, 50, 75, 75, 0, 0, 0 }

Definition at line 6 of file hurricane.c.

6{ 0, 25, 50, 75, 75, 0, 0, 0 };

Referenced by update().

◆ actionCmdTableHurricane

s32 actionCmdTableHurricane[]
extern

Definition at line 47 of file action_cmd.c.

47{ 130, 120, 110, 100, 90, 80, 70, 60 };