Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
air_lift.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects.h"
3#include "battle/action_cmd.h"
4
5#define NAMESPACE action_command_air_lift
6
7s32 D_802A9852_4292C0[] = { 0, 25, 50, 75, 75, 0, 0, 0 };
8
10
11extern s32 actionCmdTableAirLift[];
12
13API_CALLABLE(N(init)) {
14 s32 *args = script->ptrReadPos;
15 BattleStatus* battleStatus = &gBattleStatus;
16 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
17 s32 hudElement;
18
20 battleStatus->unk_82 = 0;
21 battleStatus->actionResult = ACTION_RESULT_NONE;
23 actionCommandStatus->unk_5A = evt_get_variable(script, *args++);
24 actionCommandStatus->actionCommandID = ACTION_COMMAND_AIR_LIFT;
25 actionCommandStatus->showHud = TRUE;
26 actionCommandStatus->state = 0;
27 actionCommandStatus->wrongButtonPressed = FALSE;
28 actionCommandStatus->barFillLevel = 0;
29 actionCommandStatus->barFillWidth = 0;
30 actionCommandStatus->isBarFilled = FALSE;
31 battleStatus->actionSuccess = 0;
32 battleStatus->actionQuality = 0;
33 actionCommandStatus->hudPrepareTime = 30;
34 actionCommandStatus->hudPosX = -48;
36 actionCommandStatus->hudPosY = 80;
37
38 hudElement = hud_element_create(&HES_AButton);
39 actionCommandStatus->hudElements[0] = hudElement;
40 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
41 hud_element_set_render_depth(hudElement, 0);
43
44 hudElement = hud_element_create(&HES_BlueMeter);
45 actionCommandStatus->hudElements[1] = hudElement;
46 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
47 hud_element_set_render_depth(hudElement, 0);
49
50 hudElement = hud_element_create(&HES_100pct);
51 actionCommandStatus->hudElements[2] = hudElement;
52 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
53 hud_element_set_render_depth(hudElement, 0);
55
56 return ApiStatus_DONE2;
57}
58
59API_CALLABLE(N(start)) {
60 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
61 BattleStatus* battleStatus = &gBattleStatus;
62 Bytecode* args = script->ptrReadPos;
63 u8 mashMeterCutoff;
64
66
67 actionCommandStatus->prepareTime = evt_get_variable(script, *args++);
68 actionCommandStatus->duration = evt_get_variable(script, *args++);
69 actionCommandStatus->difficulty = evt_get_variable(script, *args++);
70 actionCommandStatus->difficulty = adjust_action_command_difficulty(actionCommandStatus->difficulty);
71 actionCommandStatus->targetWeakness = evt_get_variable(script, *args++);
72
73 actionCommandStatus->wrongButtonPressed = FALSE;
74 battleStatus->actionSuccess = 0;
75 battleStatus->actionResult = ACTION_RESULT_NONE;
76
77 mashMeterCutoff = actionCommandStatus->mashMeterCutoffs[actionCommandStatus->mashMeterIntervals - 1];
78 actionCommandStatus->unk_5C = 0;
79
80 battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
81 actionCommandStatus->state = 10;
82 battleStatus->unk_82 = mashMeterCutoff;
83
85
86 return ApiStatus_DONE2;
87}
88
89void N(update)(void) {
90 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
91 BattleStatus* battleStatus = &gBattleStatus;
92 s32 id;
93
94 switch (actionCommandStatus->state) {
95 case 0:
97
98 id = actionCommandStatus->hudElements[0];
99 hud_element_set_alpha(id, 255);
100 if (actionCommandStatus->showHud) {
102 }
103
104 id = actionCommandStatus->hudElements[1];
105 hud_element_set_alpha(id, 255);
106 if (actionCommandStatus->showHud) {
108 }
109
110 actionCommandStatus->state = 1;
111 break;
112 case 1:
114
115 if (actionCommandStatus->hudPrepareTime != 0) {
116 actionCommandStatus->hudPrepareTime--;
117 return;
118 }
119
120 actionCommandStatus->hudPosX += 20;
121 if (actionCommandStatus->hudPosX > 50) {
122 actionCommandStatus->hudPosX = 50;
123 }
124
125 hud_element_set_render_pos(actionCommandStatus->hudElements[0], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
126 hud_element_set_render_pos(actionCommandStatus->hudElements[1], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
127 break;
128 case 10:
130
131 if (actionCommandStatus->prepareTime != 0) {
132 actionCommandStatus->prepareTime--;
133 return;
134 }
135
136 hud_element_set_script(actionCommandStatus->hudElements[0], &HES_MashAButton);
137 air_lift_bss_0 = 1;
138 actionCommandStatus->frameCounter = actionCommandStatus->duration;
140 actionCommandStatus->state = 11;
141 // fallthrough
142 case 11:
144 if (!actionCommandStatus->isBarFilled) {
145 if (actionCommandStatus->unk_5A != 0) {
146 s32 a = actionCommandStatus->mashMeterCutoffs[actionCommandStatus->mashMeterIntervals];
147
148 actionCommandStatus->barFillLevel -= D_802A9852_4292C0[actionCommandStatus->barFillLevel / a / 20];
149 if (actionCommandStatus->barFillLevel < 0) {
150 actionCommandStatus->barFillLevel = 0;
151 }
152 } else {
153 actionCommandStatus->barFillLevel -= 10;
154 if (actionCommandStatus->barFillLevel < 0) {
155 actionCommandStatus->barFillLevel = 0;
156 }
157 }
158 }
159
160 if (battleStatus->actionCommandMode != ACTION_COMMAND_MODE_NOT_LEARNED && (battleStatus->curButtonsPressed & BUTTON_A)) {
161 if (actionCommandStatus->unk_5A != 0) {
162 s32 a = battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty];
163 s32 b = actionCommandStatus->unk_5A * 820;
164
165 actionCommandStatus->barFillLevel += (a * b) / 10000;
166 } else {
167 actionCommandStatus->barFillLevel += 100;
168 if (actionCommandStatus->barFillLevel >= 500) {
169 actionCommandStatus->barFillLevel = 500;
170 }
171 }
172
173 }
174
175 if (actionCommandStatus->barFillLevel > 10000) {
176 actionCommandStatus->barFillLevel = 10000;
177 actionCommandStatus->isBarFilled = TRUE;
178 id = actionCommandStatus->hudElements[2];
179 hud_element_set_render_pos(id, actionCommandStatus->hudPosX + 50, actionCommandStatus->hudPosY + 28);
181 }
182
183 battleStatus->actionSuccess = actionCommandStatus->barFillLevel / 100;
184 if (battleStatus->actionQuality < battleStatus->actionSuccess) {
185 battleStatus->actionQuality = battleStatus->actionSuccess;
186 }
188
189 if (actionCommandStatus->frameCounter != 0) {
190 actionCommandStatus->frameCounter--;
191 return;
192 }
193
194 if (actionCommandStatus->unk_5A == 0) {
195 battleStatus->actionQuality = 0;
196 }
197
198 battleStatus->actionSuccess = battleStatus->actionQuality;
199 if (rand_int(99) < battleStatus->actionSuccess) {
200 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
201 battleStatus->actionSuccess = 1;
202 } else {
203 battleStatus->actionResult = ACTION_RESULT_MINUS_2;
204 battleStatus->actionSuccess = -1;
205 }
206
207 if (battleStatus->actionSuccess == 1) {
209 }
212 actionCommandStatus->frameCounter = 20;
213 actionCommandStatus->state = 12;
214 break;
215 case 12:
216 if (actionCommandStatus->unk_5A == 0) {
217 actionCommandStatus->barFillLevel -= 100;
218 if (actionCommandStatus->barFillLevel < 0) {
219 actionCommandStatus->barFillLevel = 0;
220 }
221 }
222 if (actionCommandStatus->frameCounter != 0) {
223 actionCommandStatus->frameCounter--;
224 return;
225 }
227 break;
228 }
229}
230
231void N(draw)(void) {
232 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
233 s32 hudX;
234 s32 hudY;
235 s32 hudElement1;
236
238 hud_element_draw_clipped(actionCommandStatus->hudElements[0]);
239 }
240
241 hudElement1 = actionCommandStatus->hudElements[1];
242 hud_element_draw_clipped(hudElement1);
243 hud_element_get_render_pos(hudElement1, &hudX, &hudY);
244
245 if (air_lift_bss_0 == 0) {
246 draw_mash_meter_multicolor_with_divisor(hudX, hudY, actionCommandStatus->barFillLevel / 100, 1);
247 } else if (!actionCommandStatus->isBarFilled) {
248 draw_mash_meter_multicolor_with_divisor(hudX, hudY, actionCommandStatus->barFillLevel / 100, 4);
249 } else {
250 draw_mash_meter_blink_with_divisor(hudX, hudY, actionCommandStatus->barFillLevel / 100, 4);
251 }
252
253 hud_element_draw_clipped(actionCommandStatus->hudElements[2]);
254}
255
void draw_mash_meter_blink_with_divisor(s32 posX, s32 posY, s32 fillValue, s32 divisor)
Definition action_cmd.c:251
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
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
void action_command_init_status(void)
Definition action_cmd.c:256
void func_80269118(void)
Definition action_cmd.c:641
HudScript HES_AButton
HudScript HES_BlueMeter
HudScript HES_MashAButton
HudScript HES_100pct
@ ACTION_COMMAND_MODE_NOT_LEARNED
Definition action_cmd.h:38
BSS s32 air_lift_bss_0
Definition air_lift.c:9
void N update(void)
Definition air_lift.c:89
void N draw(void)
Definition air_lift.c:231
s32 actionCmdTableAirLift[]
Definition action_cmd.c:40
s32 D_802A9852_4292C0[]
Definition air_lift.c:7
#define rand_int
@ ACTION_COMMAND_AIR_LIFT
Definition enums.h:3485
@ BUTTON_A
Definition enums.h:2790
@ SOUND_LOOP_CHARGE_BAR
Definition enums.h:1646
@ 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)
@ HUD_ELEMENT_FLAG_DISABLED
Definition hud_element.h:74
@ HUD_ELEMENT_FLAG_80
Definition hud_element.h:80
void sfx_stop_sound(s32 soundID)
Definition sfx.c:507
void sfx_adjust_env_sound_params(s32 soundID, u8 volume, u8 pan, s16 pitchShift)
Definition sfx.c:492
void sfx_play_sound_with_params(s32 soundID, u8 volume, u8 pan, s16 pitchShift)
Definition sfx.c:458
#define BSS
Definition macros.h:7
s32 * actionCmdDifficultyTable
BattleStatus gBattleStatus
Definition battle.c:11
void N init(Npc *bombette)
Definition bombette.c:66