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

Go to the source code of this file.

Macros

#define METER_FILL_RATE   100
 

Enumerations

enum  { HIDX_BUTTON = 0 , HIDX_METER = 1 , HIDX_RUN_AWAY = 2 , HIDX_OK = 3 }
 

Functions

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

Variables

s32 actionCmdTableBreakFree []
 

Macro Definition Documentation

◆ METER_FILL_RATE

#define METER_FILL_RATE   100

Definition at line 17 of file break_free.c.

Referenced by update().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
HIDX_BUTTON 
HIDX_METER 
HIDX_RUN_AWAY 
HIDX_OK 

Definition at line 9 of file break_free.c.

9 {
10 HIDX_BUTTON = 0,
11 HIDX_METER = 1,
12 HIDX_RUN_AWAY = 2,
13 HIDX_OK = 3,
14};
@ HIDX_RUN_AWAY
Definition break_free.c:12
@ HIDX_METER
Definition break_free.c:11
@ HIDX_BUTTON
Definition break_free.c:10
@ HIDX_OK
Definition break_free.c:13

Function Documentation

◆ update()

void N update ( void )

Definition at line 108 of file break_free.c.

108 {
110 BattleStatus* battleStatus = &gBattleStatus;
111 HudElemID hid;
112
113 switch (acs->state) {
114 case AC_STATE_INIT:
116
117 hid = acs->hudElemIDs[HIDX_BUTTON];
118 hud_element_set_alpha(hid, 255);
119 if (acs->showHud) {
121 }
122
123 hid = acs->hudElemIDs[HIDX_METER];
124 hud_element_set_alpha(hid, 255);
125 if (acs->showHud) {
127 }
128
129 hid = acs->hudElemIDs[HIDX_RUN_AWAY];
130 hud_element_set_alpha(hid, 255);
131 if (acs->showHud) {
133 }
134
135 hid = acs->hudElemIDs[HIDX_OK];
136 hud_element_set_alpha(hid, 255);
137 if (acs->showHud) {
139 }
140
141 acs->state = AC_STATE_APPEAR;
142 break;
143 case AC_STATE_APPEAR:
145 acs->hudPosX += 20;
146 if (acs->hudPosX > 50) {
147 acs->hudPosX = 50;
148 }
152 hud_element_set_render_pos(acs->hudElemIDs[HIDX_OK], acs->hudPosX + 31, acs->hudPosY + 17);
153 break;
154 case AC_STATE_START:
156 if (acs->prepareTime != 0) {
157 acs->prepareTime--;
158 return;
159 }
161 acs->state = AC_STATE_ACTIVE;
162 acs->stateTimer = acs->duration;
163
164 // fallthrough
165 case AC_STATE_ACTIVE:
167
168 // update the position of the 'OK' tick
169 if (acs->breakFree.dir == 0) {
170 acs->escapeThreshold++;
171 if (acs->escapeThreshold >= acs->escapeChance) {
172 acs->escapeThreshold = acs->escapeChance;
173 acs->breakFree.dir = 1;
174 }
175 } else {
176 acs->escapeThreshold--;
177 if (acs->escapeThreshold <= 0) {
178 acs->escapeThreshold = 0;
179 acs->breakFree.dir = 0;
180 }
181 }
182
183 // unlike most other mash inputs, this command doesn't just increment meterFillLevel with inputs
184 // instead we sum the total number of inputs during the last N frames of the input buffer
185 if (!acs->berserkerEnabled) {
186 s32 inputBufPos = battleStatus->inputBufferPos;
187 s32 windowLen = acs->duration - acs->stateTimer;
188 s32 i;
189
190 acs->meterFillLevel = 0;
191
192 inputBufPos -= windowLen;
193 if (inputBufPos < 0) {
194 inputBufPos += ARRAY_COUNT(battleStatus->pushInputBuffer);
195 }
196
197 for (i = 0; i < windowLen; i++, inputBufPos++) {
198 if (inputBufPos >= ARRAY_COUNT(battleStatus->pushInputBuffer)) {
199 inputBufPos -= ARRAY_COUNT(battleStatus->pushInputBuffer);
200 }
201 if (battleStatus->pushInputBuffer[inputBufPos] & BUTTON_A) {
203 }
204 }
205 } else {
206 acs->meterFillLevel += SCALE_BY_PCT(25, battleStatus->actionCmdDifficultyTable[acs->difficulty]);
208 }
209
210 battleStatus->actionQuality = acs->meterFillLevel / ONE_PCT_MASH;
211 if (acs->stateTimer != 0) {
212 acs->stateTimer--;
213 break;
214 }
215
216 if (battleStatus->actionQuality >= acs->mashMeterCutoffs[acs->mashMeterNumIntervals] - acs->escapeThreshold) {
217 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
218 battleStatus->actionQuality = 1;
219 } else {
221 battleStatus->actionQuality = AC_QUALITY_FAILED;
222 }
223
225 acs->stateTimer = 20;
226 acs->state = AC_STATE_DISPOSE;
227 break;
228 case AC_STATE_DISPOSE:
229 if (acs->stateTimer != 0) {
230 acs->stateTimer--;
231 break;
232 }
234 break;
235 }
236}
BSS ActionCommandStatus gActionCommandStatus
Definition action_cmd.c:91
void action_command_free(void)
Definition action_cmd.c:446
#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
#define ONE_PCT_MASH
Definition action_cmd.h:69
#define SCALE_BY_PCT(x, pct)
Definition action_cmd.h:77
HudScript HES_MashAButton
#define METER_FILL_RATE
Definition break_free.c:17
s32 HudElemID
#define rand_int
@ BUTTON_A
Definition enums.h:2790
@ ACTION_RESULT_METER_NOT_ENOUGH
Definition enums.h:1965
@ ACTION_RESULT_SUCCESS
Definition enums.h:1968
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:72
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define POPUP_MSG_OFF
Definition battle.h:270
#define POPUP_MSG_ON
Definition battle.h:269
s32 * actionCmdDifficultyTable
s32 pushInputBuffer[64]
BattleStatus gBattleStatus
Definition battle.c:11

◆ draw()

void N draw ( void )

Definition at line 238 of file break_free.c.

238 {
240 s32* hudElements = acs->hudElemIDs;
241 s32 hudX, hudY;
242 HudElemID hid;
243 s16 maxMeterValue;
244
245 // equivalent to 60 * acs->escapeThreshold / maxMeterValue
246 maxMeterValue = acs->mashMeterCutoffs[acs->mashMeterNumIntervals];
247 hudX = 60 - ((maxMeterValue - acs->escapeThreshold) * 60 / maxMeterValue);
248
249 hud_element_set_render_pos(hudElements[HIDX_OK], acs->hudPosX + 31 - hudX, acs->hudPosY + 17);
250 hud_element_set_render_pos(hudElements[HIDX_RUN_AWAY], acs->hudPosX + 31 - hudX, acs->hudPosY - 1);
251
252 if (!acs->berserkerEnabled) {
254 }
255
256 hid = hudElements[HIDX_METER];
258 hud_element_get_render_pos(hid, &hudX, &hudY);
259
262 hud_element_draw_clipped(hudElements[HIDX_OK]);
263}
void draw_mash_meter_multicolor(s32 posX, s32 posY, s32 fillValue)
Definition action_cmd.c:226
void hud_element_get_render_pos(s32 id, s32 *x, s32 *y)
void hud_element_draw_clipped(s32 id)

◆ free()

Variable Documentation

◆ actionCmdTableBreakFree

s32 actionCmdTableBreakFree[]
extern

Definition at line 31 of file action_cmd.c.

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