Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
flee.c
Go to the documentation of this file.
1#include "common.h"
2#include "battle/action_cmd.h"
3
4#define NAMESPACE action_command_flee
5
7
8extern s32 actionCmdTableFlee[];
9
10API_CALLABLE(N(init)) {
11 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
12 BattleStatus* battleStatus = &gBattleStatus;
13 Bytecode* args = script->ptrReadPos;
14 s32 xOffset;
15 s32 hudElement;
16
17 battleStatus->unk_82 = 0;
19 battleStatus->actionResult = ACTION_RESULT_NONE;
21 actionCommandStatus->unk_5A = evt_get_variable(script, *args++);
22 actionCommandStatus->actionCommandID = ACTION_COMMAND_FLEE;
23 actionCommandStatus->state = 0;
24 actionCommandStatus->wrongButtonPressed = FALSE;
25 actionCommandStatus->barFillLevel = actionCommandStatus->unk_5A * 100;
26 actionCommandStatus->thresholdLevel = rand_int(50);
27 actionCommandStatus->barFillWidth = 0;
28 actionCommandStatus->unk_5C = 1;
29 actionCommandStatus->unk_5A = rand_int(1);
30 actionCommandStatus->isBarFilled = FALSE;
31 battleStatus->actionSuccess = 0;
32 actionCommandStatus->hudPosX = -48;
33 D_802A9920 = 0;
34 actionCommandStatus->hudPosY = 80;
35
36 hudElement = hud_element_create(&HES_AButton);
37 actionCommandStatus->hudElements[0] = hudElement;
38 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
39 hud_element_set_render_depth(hudElement, 0);
41
42 hudElement = hud_element_create(&HES_BlueMeter);
43 actionCommandStatus->hudElements[1] = hudElement;
44 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
45 hud_element_set_render_depth(hudElement, 0);
47
49 actionCommandStatus->hudElements[2] = hudElement;
50 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
51 hud_element_set_render_depth(hudElement, 0);
53
54 hudElement = hud_element_create(&HES_RunAwayOK);
55 actionCommandStatus->hudElements[3] = hudElement;
56 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
57 hud_element_set_render_depth(hudElement, 0);
59
60 xOffset = 29 - ((100 - actionCommandStatus->thresholdLevel) * 60) / 100;
61 hud_element_set_render_pos(actionCommandStatus->hudElements[3], actionCommandStatus->hudPosX - xOffset, actionCommandStatus->hudPosY + 17);
62 hud_element_set_render_pos(actionCommandStatus->hudElements[2], actionCommandStatus->hudPosX - xOffset, actionCommandStatus->hudPosY - 1);
63
64 hudElement = hud_element_create(&HES_100pct);
65 actionCommandStatus->hudElements[4] = hudElement;
66 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
67 hud_element_set_render_depth(hudElement, 0);
69
70 return ApiStatus_DONE2;
71}
72
73API_CALLABLE(N(start)) {
74 Bytecode* args = script->ptrReadPos;
75 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
76 BattleStatus* battleStatus = &gBattleStatus;
77
79 actionCommandStatus->prepareTime = evt_get_variable(script, *args++);
80 actionCommandStatus->duration = evt_get_variable(script, *args++);
81 actionCommandStatus->difficulty = evt_get_variable(script, *args++);
82 actionCommandStatus->difficulty = adjust_action_command_difficulty(actionCommandStatus->difficulty);
83 actionCommandStatus->wrongButtonPressed = FALSE;
84 battleStatus->actionSuccess = 0;
85 battleStatus->actionResult = ACTION_RESULT_NONE;
86 battleStatus->unk_82 = actionCommandStatus->mashMeterCutoffs[actionCommandStatus->mashMeterIntervals - 1];
87 battleStatus->flags1 &= ~BS_FLAGS1_FREE_ACTION_COMMAND;
88 actionCommandStatus->state = 10;
89 return ApiStatus_DONE2;
90}
91
92void N(update)(void) {
93 s32 temp;
94 s32 hudElement;
95 BattleStatus* battleStatus = &gBattleStatus;
96 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
97
98 switch (actionCommandStatus->state) {
99 case 0:
100 hudElement = actionCommandStatus->hudElements[0];
101 hud_element_set_alpha(hudElement, 0xFF);
102 if (actionCommandStatus->showHud) {
104 }
105
106 hudElement = actionCommandStatus->hudElements[1];
107 hud_element_set_alpha(hudElement, 0xFF);
108 if (actionCommandStatus->showHud) {
110 }
111
112 hudElement = actionCommandStatus->hudElements[2];
113 hud_element_set_alpha(hudElement, 0xFF);
114 if (actionCommandStatus->showHud) {
116 }
117
118 hudElement = actionCommandStatus->hudElements[3];
119 hud_element_set_alpha(hudElement, 0xFF);
120 if (actionCommandStatus->showHud) {
122 }
123
124 actionCommandStatus->state = 1;
125 break;
126 case 1:
127 actionCommandStatus->hudPosX += 20;
128 if (actionCommandStatus->hudPosX > 50) {
129 actionCommandStatus->hudPosX = 50;
130 }
131 hud_element_set_render_pos(actionCommandStatus->hudElements[0], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
132 hud_element_set_render_pos(actionCommandStatus->hudElements[1], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
133 break;
134 case 10:
135 if (actionCommandStatus->prepareTime != 0) {
136 actionCommandStatus->prepareTime--;
137 break;
138 }
139
140 hud_element_set_script(actionCommandStatus->hudElements[0], &HES_MashAButton);
141 D_802A9920 = 1;
142 actionCommandStatus->state = 11;
143 actionCommandStatus->frameCounter = actionCommandStatus->duration;
144 case 11:
145 if (battleStatus->actionCommandMode != ACTION_COMMAND_MODE_NOT_LEARNED && (battleStatus->curButtonsPressed & BUTTON_A)) {
146 actionCommandStatus->barFillLevel += (battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty] * 180 / 100);
147 }
148 if (actionCommandStatus->barFillLevel >= 10000) {
149 hudElement = actionCommandStatus->hudElements[4];
150 actionCommandStatus->barFillLevel = 10000;
151 actionCommandStatus->isBarFilled = TRUE;
152 hud_element_set_render_pos(hudElement, actionCommandStatus->hudPosX + 50, actionCommandStatus->hudPosY + 28);
154 }
155
156 battleStatus->actionSuccess = actionCommandStatus->barFillLevel / 100;
157 if (actionCommandStatus->frameCounter == 0) {
158 if (battleStatus->actionSuccess >= (100 - actionCommandStatus->thresholdLevel)) {
159 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
160 battleStatus->actionSuccess = 1;
161 } else {
162 battleStatus->actionResult = ACTION_RESULT_MINUS_2;
163 battleStatus->actionSuccess = -1;
164 }
165 actionCommandStatus->frameCounter = 20;
166 actionCommandStatus->state = 12;
167 } else {
168 actionCommandStatus->frameCounter--;
169 }
170 break;
171 case 12:
172 if (actionCommandStatus->frameCounter != 0) {
173 actionCommandStatus->frameCounter--;
174 break;
175 }
177 break;
178 }
179
180 switch (actionCommandStatus->state) {
181 case 1:
182 case 10:
183 case 11:
184 temp = actionCommandStatus->unk_5A == 0 ? 7 : 8;
185 if (actionCommandStatus->unk_5C == 0) {
186 actionCommandStatus->thresholdLevel += temp;
187 if (actionCommandStatus->thresholdLevel >= 100) {
188 actionCommandStatus->thresholdLevel = 100;
189 actionCommandStatus->unk_5C = 1;
190 }
191 break;
192 }
193 actionCommandStatus->thresholdLevel -= temp;
194 if (actionCommandStatus->thresholdLevel <= 0) {
195 actionCommandStatus->thresholdLevel = 0;
196 actionCommandStatus->unk_5C = 0;
197 }
198 }
199}
200
201void N(draw)(void) {
202 s32 y;
203 s32 x;
204 s32 temp_a1;
205 s32 hudElement;
206 s32 temp_v1;
207
208 BattleStatus* battleStatus = &gBattleStatus;
209 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
210
211 temp_v1 = (100 - actionCommandStatus->thresholdLevel) * 60;
212 x = 60 - temp_v1 / 100;
213 temp_a1 = x - 31;
214
215 hud_element_set_render_pos(actionCommandStatus->hudElements[3], actionCommandStatus->hudPosX - temp_a1, actionCommandStatus->hudPosY + 17);
216 hud_element_set_render_pos(actionCommandStatus->hudElements[2], actionCommandStatus->hudPosX + 31 - x, actionCommandStatus->hudPosY - 1);
217
219 hud_element_draw_clipped(actionCommandStatus->hudElements[0]);
220 }
221
222 hudElement = actionCommandStatus->hudElements[1];
223 hud_element_draw_clipped(hudElement);
224 hud_element_get_render_pos(hudElement, &x, &y);
225
226 if (D_802A9920 == 0) {
227 draw_mash_meter_multicolor_with_divisor(x, y, actionCommandStatus->barFillLevel / 100, 1);
228 } else {
229 if (!actionCommandStatus->isBarFilled) {
230 draw_mash_meter_multicolor_with_divisor(x, y, actionCommandStatus->barFillLevel / 100, 4);
231 } else {
232 draw_mash_meter_blink(x, y, actionCommandStatus->barFillLevel / 100);
233 }
234 }
235
236 hud_element_draw_clipped(actionCommandStatus->hudElements[2]);
237 hud_element_draw_clipped(actionCommandStatus->hudElements[3]);
238 hud_element_draw_clipped(actionCommandStatus->hudElements[4]);
239}
240
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
void draw_mash_meter_blink(s32 posX, s32 posY, s32 fillValue)
Definition action_cmd.c:246
void action_command_init_status(void)
Definition action_cmd.c:256
HudScript HES_AButton
HudScript HES_BlueMeter
HudScript HES_RunAwayOK
HudScript HES_MashAButton
HudScript HES_100pct
@ ACTION_COMMAND_MODE_NOT_LEARNED
Definition action_cmd.h:38
HudScript HES_RunningAway
#define rand_int
@ ACTION_COMMAND_FLEE
Definition enums.h:3475
@ BUTTON_A
Definition enums.h:2790
@ 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
BSS s32 D_802A9920
Definition flee.c:6
s32 actionCmdTableFlee[]
Definition action_cmd.c:30
void N free(void)
Definition flee.c:241
void N update(void)
Definition flee.c:92
void N draw(void)
Definition flee.c:201
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)
void hud_element_free(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