Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
07.c
Go to the documentation of this file.
1#include "common.h"
2#include "battle/action_cmd.h"
3
4#define NAMESPACE action_command_07
5
7
9
10extern s32 actionCmdTable07[];
11
12API_CALLABLE(N(init)) {
13 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
14 BattleStatus* battleStatus = &gBattleStatus;
15 Bytecode* args = script->ptrReadPos;
16 s32 hudElement;
17 s32 hudElementTemp;
18
19 battleStatus->unk_82 = 5;
21
22 actionCommandStatus->autoSucceed = 0;
23 actionCommandStatus->actionCommandID = ACTION_COMMAND_07;
24 actionCommandStatus->state = 0;
25 actionCommandStatus->wrongButtonPressed = FALSE;
26 actionCommandStatus->barFillLevel = evt_get_variable(script, *args);
27 actionCommandStatus->hudPosX = -48;
28 actionCommandStatus->barFillWidth = 0;
29 D_802A9620 = 0;
30 actionCommandStatus->hudPosY = 80;
31
32 hudElement = hud_element_create(&HES_AButton);
33 actionCommandStatus->hudElements[0] = hudElement;
35 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
36 hud_element_set_render_depth(hudElement, 0);
37
38 // Weird use of an extra temp settles regalloc here.
39 hudElementTemp = hud_element_create(&HES_BlueMeter);
40 hudElement = hudElementTemp;
41 actionCommandStatus->hudElements[1] = hudElement;
42 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
43 hud_element_set_render_depth(hudElement, 0);
45
46 hudElement = hud_element_create(&HES_RunAwayOK);
47 actionCommandStatus->hudElements[2] = hudElement;
48 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
49 hud_element_set_render_depth(hudElement, 0);
51
52 battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
53
54 return ApiStatus_DONE2;
55}
56
57API_CALLABLE(N(start)) {
58 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
59 BattleStatus* battleStatus = &gBattleStatus;
60 s32* args = script->ptrReadPos;
61 s32 mask;
62
63 actionCommandStatus->autoSucceed = 0;
64 actionCommandStatus->prepareTime = evt_get_variable(script, *args++);
65 actionCommandStatus->duration = evt_get_variable(script, *args++);
66 actionCommandStatus->difficulty = evt_get_variable(script, *args++);
67 actionCommandStatus->difficulty = adjust_action_command_difficulty(actionCommandStatus->difficulty);
68
69 actionCommandStatus->wrongButtonPressed = FALSE;
70 battleStatus->actionSuccess = 0;
71 battleStatus->actionResult = ACTION_RESULT_FAIL;
72
73 battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
75 actionCommandStatus->state = 10;
76
77 return ApiStatus_DONE2;
78}
79
80void N(update)(void) {
81 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
82 BattleStatus* battleStatus = &gBattleStatus;
83 s32 id;
84
85 switch (actionCommandStatus->state) {
86 case 0:
88
89 id = actionCommandStatus->hudElements[0];
90 if (actionCommandStatus->showHud) {
92 }
93 hud_element_set_alpha(id, 255);
94
95 id = actionCommandStatus->hudElements[1];
96 hud_element_set_alpha(id, 255);
97 if (actionCommandStatus->showHud) {
99 }
100
101 id = actionCommandStatus->hudElements[2];
102 hud_element_set_alpha(id, 255);
103 if (actionCommandStatus->showHud) {
105 }
106
107 actionCommandStatus->state = 1;
108 break;
109 case 1:
111
112 actionCommandStatus->hudPosX += 20;
113 if (actionCommandStatus->hudPosX > 50) {
114 actionCommandStatus->hudPosX = 50;
115 }
116
117 hud_element_set_render_pos(actionCommandStatus->hudElements[0], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
118 hud_element_set_render_pos(actionCommandStatus->hudElements[1], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
119 hud_element_set_render_pos(actionCommandStatus->hudElements[2], actionCommandStatus->hudPosX + 31, actionCommandStatus->hudPosY + 14);
120 break;
121 case 10:
123
124 if (actionCommandStatus->prepareTime != 0) {
125 actionCommandStatus->prepareTime--;
126 return;
127 }
128
129 hud_element_set_script(actionCommandStatus->hudElements[0], &HES_MashAButton);
130 battleStatus->actionSuccess = 0;
131 D_802A9620 = 1;
132 actionCommandStatus->unk_5D = 0;
133 actionCommandStatus->state = 11;
134 actionCommandStatus->frameCounter = actionCommandStatus->duration;
135 // fallthrough
136 case 11:
138
139 if (battleStatus->curButtonsPressed & BUTTON_A) {
140 s32 fillAmt = battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty] * 6;
141
142 if (actionCommandStatus->unk_5D == 0) {
143 actionCommandStatus->barFillLevel += fillAmt;
144 }
145 }
146
147 if (actionCommandStatus->barFillLevel > 10000) {
148 actionCommandStatus->barFillLevel = 10000;
149 actionCommandStatus->unk_5D = 3;
150 }
151
152 if (actionCommandStatus->unk_5D != 0) {
153 actionCommandStatus->unk_5D--;
154 if (actionCommandStatus->unk_5D == 0) {
155 actionCommandStatus->barFillLevel = 0;
156 battleStatus->actionSuccess++;
157 }
158 }
159
160 battleStatus->actionQuality = actionCommandStatus->barFillLevel / 100;
161
162 if (actionCommandStatus->frameCounter != 0) {
163 actionCommandStatus->frameCounter--;
164 return;
165 }
167 actionCommandStatus->frameCounter = 5;
168 actionCommandStatus->state = 12;
169 break;
170 case 12:
171 if (actionCommandStatus->frameCounter != 0) {
172 actionCommandStatus->frameCounter--;
173 return;
174 }
176 break;
177 }
178}
179
180void N(draw)(void) {
181 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
182 s32 hudX;
183 s32 hudY;
184 s32 hudElement1;
185
186 hud_element_draw_clipped(actionCommandStatus->hudElements[0]);
187 hudElement1 = actionCommandStatus->hudElements[1];
188 hud_element_draw_clipped(hudElement1);
189 hud_element_get_render_pos(hudElement1, &hudX, &hudY);
190
191 if (D_802A9620 == 0) {
192 draw_mash_meter_multicolor_with_divisor(hudX, hudY, actionCommandStatus->barFillLevel / 100, 1);
193 } else {
194 draw_mash_meter_multicolor_with_divisor(hudX, hudY, actionCommandStatus->barFillLevel / 100, 2);
195 }
196
197 hud_element_draw_clipped(actionCommandStatus->hudElements[2]);
198}
199
BSS ActionCommandStatus gActionCommandStatus
Definition action_cmd.c:91
void action_command_free(void)
Definition action_cmd.c:446
void draw_mash_meter_multicolor_with_divisor(s32 posX, s32 posY, s32 fillValue, s32 divisor)
Definition action_cmd.c:231
s32 adjust_action_command_difficulty(s32 arg0)
Definition action_cmd.c:101
HudScript HES_AButton
HudScript HES_BlueMeter
HudScript HES_RunAwayOK
HudScript HES_MashAButton
s32 actionCmdTable07[]
Definition action_cmd.c:34
BSS s32 D_802A9620
Definition 07.c:8
void btl_message_unlock_box_pos(void)
void N update(void)
Definition 07.c:80
void N draw(void)
Definition 07.c:180
@ ACTION_COMMAND_07
Definition enums.h:3479
@ BUTTON_A
Definition enums.h:2790
@ 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_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)
@ HUD_ELEMENT_FLAG_DISABLED
Definition hud_element.h:74
@ HUD_ELEMENT_FLAG_80
Definition hud_element.h:80
#define BSS
Definition macros.h:7
s32 * actionCmdDifficultyTable
BattleStatus gBattleStatus
Definition battle.c:11
void N init(Npc *bombette)
Definition bombette.c:66