Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
air_raid.c
Go to the documentation of this file.
1#include "battle/battle.h"
2#include "battle/action_cmd.h"
3
4#define NAMESPACE action_command_air_raid
5
6extern s32 actionCmdTableAirRaid[];
7
8// indices into ActionCommandStatus::hudElements for this action command
9enum {
13};
14
15// how much to add to the meter per input if all modifiers are neutral
16#define METER_FILL_RATE 850
17
18s32 N(DrainRateTable)[] = { 0, 25, 50, 75, 75 };
19
20#define GET_DRAIN_RATE(pct) PCT_TO_TABLE_RATE(N(DrainRateTable), pct)
21
22// threshold meter values; not used for anything
23// these correspond to values provided via SetupMashMeter
24s32 N(BasicThresholds)[] = { 40, 70, 99, 200 };
25s32 N(SuperThresholds)[] = { 35, 60, 80, 99, 200 };
26s32 N(UltraThresholds)[] = { 35, 35, 60, 80, 99, 200 };
27
28API_CALLABLE(N(init)) {
30 BattleStatus* battleStatus = &gBattleStatus;
31 HudElemID hid;
32
33 battleStatus->maxActionQuality = 100;
35 battleStatus->actionResult = ACTION_RESULT_NONE;
36
37 if (battleStatus->actionCommandMode == AC_MODE_NOT_LEARNED) {
38 battleStatus->actionQuality = 0;
39 return ApiStatus_DONE2;
40 }
41
43
45 acs->showHud = TRUE;
46 acs->hudPrepareTime = 30;
47 acs->state = AC_STATE_INIT;
48 acs->wrongButtonPressed = FALSE;
49 acs->meterFillLevel = 0;
50 acs->meterFillWidth = 0;
51 acs->isMeterFilled = FALSE;
52 battleStatus->actionQuality = 0;
53 acs->hudPosX = -48;
54 acs->hudPosY = 80;
55
57 acs->hudElemIDs[HIDX_STICK] = hid;
61
63 acs->hudElemIDs[HIDX_METER] = hid;
64 hud_element_set_render_pos(hid, acs->hudPosX, acs->hudPosY + 28);
67
69 acs->hudElemIDs[HIDX_100_PCT] = hid;
70 hud_element_set_render_pos(hid, acs->hudPosX, acs->hudPosY + 28);
73
74 return ApiStatus_DONE2;
75}
76
77API_CALLABLE(N(start)) {
79 BattleStatus* battleStatus = &gBattleStatus;
80 Bytecode* args = script->ptrReadPos;
81
82 if (battleStatus->actionCommandMode == AC_MODE_NOT_LEARNED) {
83 battleStatus->actionQuality = 0;
84 return ApiStatus_DONE2;
85 }
86
88
89 acs->prepareTime = evt_get_variable(script, *args++);
90 acs->duration = evt_get_variable(script, *args++);
91 acs->difficulty = evt_get_variable(script, *args++);
93 acs->statusChance = evt_get_variable(script, *args++); // unused
94
95 acs->wrongButtonPressed = FALSE;
96 acs->meterFillLevel = 0;
97 acs->meterFillWidth = 0;
98 battleStatus->actionQuality = 0;
99 battleStatus->actionResult = ACTION_RESULT_NONE;
100 battleStatus->maxActionQuality = acs->mashMeterCutoffs[(acs->mashMeterNumIntervals - 1)];
101 battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
102 acs->state = AC_STATE_START;
103
105
106 return ApiStatus_DONE2;
107}
108
109void N(update)(void) {
111 BattleStatus* battleStatus = &gBattleStatus;
112 Actor* partner = battleStatus->partnerActor;
113 HudElemID hid;
114 s32 cutoff;
115
116 switch (acs->state) {
117 case AC_STATE_INIT:
119
120 hid = acs->hudElemIDs[HIDX_STICK];
121 hud_element_set_alpha(hid, 255);
122 if (acs->showHud) {
124 }
125
126 hid = acs->hudElemIDs[HIDX_METER];
127 hud_element_set_alpha(hid, 255);
128 if (acs->showHud) {
130 }
131
132 acs->state = AC_STATE_APPEAR;
133 break;
134 case AC_STATE_APPEAR:
136
137 if (acs->hudPrepareTime != 0) {
138 acs->hudPrepareTime--;
139 return;
140 }
141
142 acs->hudPosX += 20;
143 if (acs->hudPosX > 50) {
144 acs->hudPosX = 50;
145 }
146
149 break;
150 case AC_STATE_START:
152
153 if (acs->prepareTime != 0) {
154 acs->prepareTime--;
155 return;
156 }
157
159 acs->meterFillLevel = 0;
160 battleStatus->resultTier = 0;
161 acs->airRaid.holdingLeft = FALSE;
162 acs->stateTimer = acs->duration;
164 acs->state = AC_STATE_ACTIVE;
165
166 // fallthrough
167 case AC_STATE_ACTIVE:
169
170 // meter can drain if it hasn't been fully filled
171 if (!acs->isMeterFilled) {
172 cutoff = acs->mashMeterCutoffs[acs->mashMeterNumIntervals];
173 acs->meterFillLevel -= GET_DRAIN_RATE(acs->meterFillLevel / cutoff);
174 if (acs->meterFillLevel < 0) {
175 acs->meterFillLevel = 0;
176 }
177 }
178
179 // check for meter-filling input
180 if (!acs->isMeterFilled) {
181 if (battleStatus->curButtonsDown & BUTTON_STICK_LEFT) {
182 acs->airRaid.holdingLeft = TRUE;
183 }
184
185 if (!(battleStatus->curButtonsDown & BUTTON_STICK_LEFT)) {
186 if (acs->airRaid.holdingLeft) {
188 acs->airRaid.holdingLeft = FALSE;
189 }
190 }
191
192 // right stick inputs actively drain the meter
193 if (battleStatus->curButtonsPressed & BUTTON_STICK_RIGHT) {
195 }
196 }
197
198
199 if (acs->meterFillLevel < 0) {
200 acs->meterFillLevel = 0;
201 }
202
203 // handle meter reaching 100%
204 if (acs->meterFillLevel > MAX_MASH_UNITS) {
206 acs->isMeterFilled = TRUE;
207 hid = acs->hudElemIDs[HIDX_100_PCT];
208 hud_element_set_render_pos(hid, acs->hudPosX + 50, acs->hudPosY + 28);
210 }
211
212 battleStatus->actionProgress = acs->meterFillLevel / ONE_PCT_MASH;
214
215 // resultTier is not used by this move; uses actionProgress instead via the move script
216 switch (partner->actorBlueprint->level) {
218 if (battleStatus->actionProgress >= N(BasicThresholds)[battleStatus->resultTier]) {
219 battleStatus->resultTier++;
220 }
221
222 if (battleStatus->resultTier > 0 && battleStatus->actionProgress < N(BasicThresholds)[battleStatus->resultTier - 1]) {
223 battleStatus->resultTier--;
224 }
225 break;
227 if (battleStatus->actionProgress >= N(SuperThresholds)[battleStatus->resultTier]) {
228 battleStatus->resultTier++;
229 }
230 if (battleStatus->resultTier > 0 && battleStatus->actionProgress < N(SuperThresholds)[battleStatus->resultTier - 1]) {
231 battleStatus->resultTier--;
232 }
233 break;
235 if (battleStatus->actionProgress >= N(UltraThresholds)[battleStatus->resultTier]) {
236 battleStatus->resultTier++;
237 }
238 if (battleStatus->resultTier > 0 && battleStatus->actionProgress < N(UltraThresholds)[battleStatus->resultTier - 1]) {
239 battleStatus->resultTier--;
240 }
241 break;
242 }
243
244 if (acs->stateTimer != 0) {
245 acs->stateTimer--;
246 break;
247 }
248
249 if (acs->meterFillLevel == 0) {
250 battleStatus->actionQuality = AC_QUALITY_FAILED;
251 } else {
252 battleStatus->actionQuality = acs->meterFillLevel / ONE_PCT_MASH;
253 }
254
255 cutoff = acs->mashMeterCutoffs[acs->mashMeterNumIntervals - 1];
256 if (battleStatus->actionQuality > cutoff) {
257 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
258 } else {
260 }
261
262 if (battleStatus->actionQuality == 100) {
263 // only count 100% fill as success for this action command
265 }
266
269 acs->stateTimer = 5;
270 acs->state = AC_STATE_DISPOSE;
271 break;
272 case AC_STATE_DISPOSE:
273 if (acs->stateTimer != 0) {
274 acs->stateTimer--;
275 break;
276 }
278 break;
279 }
280}
281
283
BSS ActionCommandStatus gActionCommandStatus
Definition action_cmd.c:91
void action_command_free(void)
Definition action_cmd.c:446
void increment_action_command_attempt_count(void)
Definition action_cmd.c:641
s32 adjust_action_command_difficulty(s32 difficultyLevel)
Definition action_cmd.c:101
void increment_action_command_success_count(void)
Definition action_cmd.c:655
void action_command_init_status(void)
Definition action_cmd.c:256
#define AC_QUALITY_FAILED
Definition action_cmd.h:66
HudElemID hudElemIDs[16]
Definition action_cmd.h:83
@ AC_STATE_APPEAR
Definition action_cmd.h:35
@ AC_STATE_DISPOSE
Definition action_cmd.h:38
@ AC_STATE_INIT
Definition action_cmd.h:34
@ AC_STATE_ACTIVE
Definition action_cmd.h:37
@ AC_STATE_START
Definition action_cmd.h:36
HudScript HES_StickNeutral
#define ONE_PCT_MASH
Definition action_cmd.h:69
#define SCALE_BY_PCT(x, pct)
Definition action_cmd.h:77
HudScript HES_BlueMeter
HudScript HES_StickMashLeft
HudScript HES_100pct
@ AC_MODE_NOT_LEARNED
Definition action_cmd.h:60
#define MAX_MASH_UNITS
Definition action_cmd.h:75
#define GET_DRAIN_RATE(pct)
Definition air_raid.c:20
#define METER_FILL_RATE
Definition air_raid.c:16
@ HIDX_METER
Definition air_raid.c:11
@ HIDX_STICK
Definition air_raid.c:10
@ HIDX_100_PCT
Definition air_raid.c:12
void N update(void)
Definition air_raid.c:109
s32 actionCmdTableAirRaid[]
Definition action_cmd.c:41
struct ActorBlueprint * actorBlueprint
s32 HudElemID
@ ACTION_COMMAND_AIR_RAID
Definition enums.h:3486
@ BUTTON_STICK_LEFT
Definition enums.h:2793
@ BUTTON_STICK_RIGHT
Definition enums.h:2794
@ PARTNER_RANK_NORMAL
Definition enums.h:2018
@ PARTNER_RANK_SUPER
Definition enums.h:2019
@ PARTNER_RANK_ULTRA
Definition enums.h:2020
@ SOUND_LOOP_CHARGE_METER
Definition enums.h:1646
@ ACTION_RESULT_NONE
Definition enums.h:1963
@ ACTION_RESULT_METER_NOT_ENOUGH
Definition enums.h:1965
@ ACTION_RESULT_SUCCESS
Definition enums.h:1968
#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:1689
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.
@ HUD_ELEMENT_FLAG_DISABLED
Definition hud_element.h:72
@ HUD_ELEMENT_FLAG_80
Definition hud_element.h:78
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 POPUP_MSG_OFF
Definition battle.h:270
#define POPUP_MSG_ON
Definition battle.h:269
struct Actor * partnerActor
s32 * actionCmdDifficultyTable
BattleStatus gBattleStatus
Definition battle.c:11
void N init(Npc *bombette)
Definition bombette.c:66