Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
spook.c
Go to the documentation of this file.
1#include "common.h"
2#include "audio/public.h"
3#include "battle/action_cmd.h"
4
5#define NAMESPACE action_command_spook
6
7s32 D_802A9920_430940[8] = { 0, 25, 50, 75, 75, 0, 0, 0 };
8
9extern s32 actionCmdTableSpook[];
10
11API_CALLABLE(N(init)) {
12 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
13 BattleStatus* battleStatus = &gBattleStatus;
14 s32 id;
15
16 battleStatus->unk_82 = 100;
18 battleStatus->actionResult = ACTION_RESULT_NONE;
20 battleStatus->actionSuccess = 0;
21 return ApiStatus_DONE2;
22 }
24 actionCommandStatus->actionCommandID = ACTION_COMMAND_SPOOK;
25 actionCommandStatus->showHud = TRUE;
26 actionCommandStatus->hudPrepareTime = 30;
27 actionCommandStatus->state = 0;
28 actionCommandStatus->wrongButtonPressed = FALSE;
29 actionCommandStatus->barFillLevel = 0;
30 actionCommandStatus->barFillWidth = 0;
31 actionCommandStatus->isBarFilled = FALSE;
32 battleStatus->actionSuccess = 0;
33 battleStatus->actionQuality = 0;
34 actionCommandStatus->hudPosX = -48;
35 actionCommandStatus->hudPosY = 80;
36
38 actionCommandStatus->hudElements[0] = id;
39 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
42
44 actionCommandStatus->hudElements[1] = id;
45 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
48
50 actionCommandStatus->hudElements[2] = id;
51 hud_element_set_render_pos(id, actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
54
55 return ApiStatus_DONE2;
56}
57
59
60void N(update)(void) {
61 ActionCommandStatus* actionCommandStatus = &gActionCommandStatus;
62 BattleStatus* battleStatus = &gBattleStatus;
63 s32 id;
64 s32 cutoff;
65 s32 fillLevel;
66
67 switch (actionCommandStatus->state) {
68 case 0:
70
71 id = actionCommandStatus->hudElements[0];
72 hud_element_set_alpha(id, 255);
73 if (actionCommandStatus->showHud) {
75 }
76
77 id = actionCommandStatus->hudElements[1];
78 hud_element_set_alpha(id, 255);
79 if (actionCommandStatus->showHud) {
81 }
82
83 actionCommandStatus->state = 1;
84 break;
85 case 1:
87 actionCommandStatus->hudPosX += 20;
88 if (actionCommandStatus->hudPosX > 50) {
89 actionCommandStatus->hudPosX = 50;
90 }
91 hud_element_set_render_pos(actionCommandStatus->hudElements[0], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY);
92 hud_element_set_render_pos(actionCommandStatus->hudElements[1], actionCommandStatus->hudPosX, actionCommandStatus->hudPosY + 28);
93 break;
94 case 10:
96 if (actionCommandStatus->prepareTime != 0) {
97 actionCommandStatus->prepareTime--;
98 return;
99 }
100 hud_element_set_script(actionCommandStatus->hudElements[0], &HES_StickMashLeft);
101 actionCommandStatus->barFillLevel = 0;
102 battleStatus->actionQuality = 0;
103 actionCommandStatus->unk_5C = 0;
104 actionCommandStatus->frameCounter = actionCommandStatus->duration;
106 actionCommandStatus->state = 11;
107 case 11:
109 if (!actionCommandStatus->isBarFilled) {
110 if (actionCommandStatus->targetWeakness != 0) {
111 cutoff = actionCommandStatus->mashMeterCutoffs[actionCommandStatus->mashMeterIntervals];
112
113 actionCommandStatus->barFillLevel -= D_802A9920_430940[actionCommandStatus->barFillLevel / cutoff / 20];
114 if (actionCommandStatus->barFillLevel < 0) {
115 actionCommandStatus->barFillLevel = 0;
116 }
117 } else {
118 actionCommandStatus->barFillLevel -= 10;
119 if (actionCommandStatus->barFillLevel < 0) {
120 actionCommandStatus->barFillLevel = 0;
121 }
122 }
123
124 if (!actionCommandStatus->isBarFilled) {
125 if (actionCommandStatus->targetWeakness != 0) {
126
127 if (battleStatus->curButtonsDown & BUTTON_STICK_LEFT) {
128 actionCommandStatus->unk_5C = TRUE;
129 }
130
131 if (!(battleStatus->curButtonsDown & BUTTON_STICK_LEFT) && actionCommandStatus->unk_5C) {
132 s32 a = battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty];
133 s32 b = actionCommandStatus->targetWeakness * 850;
134
135 actionCommandStatus->barFillLevel += (a * b) / 10000;
136 actionCommandStatus->unk_5C = 0;
137 }
138
139 if (battleStatus->curButtonsPressed & BUTTON_STICK_RIGHT) {
140 s32 a = battleStatus->actionCmdDifficultyTable[actionCommandStatus->difficulty];
141 s32 b = actionCommandStatus->targetWeakness * 850;
142
143 actionCommandStatus->barFillLevel -= (a * b) / 10000;
144 }
145 } else {
146 if (battleStatus->curButtonsDown & BUTTON_STICK_LEFT) {
147 actionCommandStatus->unk_5C = TRUE;
148 }
149
150 if (!(battleStatus->curButtonsDown & BUTTON_STICK_LEFT) && actionCommandStatus->unk_5C) {
151 actionCommandStatus->barFillLevel += 100;
152 if (actionCommandStatus->barFillLevel >= 500) {
153 actionCommandStatus->barFillLevel = 500;
154 }
155 actionCommandStatus->unk_5C = 0;
156 }
157
158 if (battleStatus->curButtonsPressed & BUTTON_STICK_RIGHT) {
159 actionCommandStatus->barFillLevel -= 100;
160 }
161 }
162 }
163 }
164
165 if (actionCommandStatus->barFillLevel < 0) {
166 actionCommandStatus->barFillLevel = 0;
167 }
168 if (actionCommandStatus->barFillLevel > 10000) {
169 id = actionCommandStatus->hudElements[2];
170 actionCommandStatus->barFillLevel = 10000;
171 actionCommandStatus->isBarFilled = TRUE;
172 hud_element_set_render_pos(id, actionCommandStatus->hudPosX + 50, actionCommandStatus->hudPosY + 28);
174 }
175
176 battleStatus->actionQuality = actionCommandStatus->barFillLevel / 100;
178
179 if (actionCommandStatus->frameCounter != 0) {
180 actionCommandStatus->frameCounter--;
181 return;
182 }
183
184 fillLevel = actionCommandStatus->barFillLevel;
185 if (actionCommandStatus->targetWeakness == 0) {
186 fillLevel = 0;
187 }
188
189 if (fillLevel == 0) {
190 battleStatus->actionSuccess = -1;
191 } else {
192 battleStatus->actionSuccess = fillLevel / 100;
193
194 }
195
196 cutoff = actionCommandStatus->mashMeterCutoffs[actionCommandStatus->mashMeterIntervals - 1];
197 if (battleStatus->actionSuccess > cutoff) {
198 battleStatus->actionResult = ACTION_RESULT_SUCCESS;
199 } else {
200 battleStatus->actionResult = ACTION_RESULT_MINUS_2;
201 }
202
203 if (battleStatus->actionSuccess == 100) {
205 }
208 actionCommandStatus->frameCounter = 5;
209 actionCommandStatus->state = 12;
210 break;
211 case 12:
212 if (actionCommandStatus->targetWeakness == 0) {
213 actionCommandStatus->barFillLevel -= 100;
214 if (actionCommandStatus->barFillLevel < 0) {
215 actionCommandStatus->barFillLevel = 0;
216 }
217 }
218
219 if (actionCommandStatus->frameCounter != 0) {
220 actionCommandStatus->frameCounter--;
221 return;
222 }
224 break;
225 }
226}
227
229
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 action_command_init_status(void)
Definition action_cmd.c:256
HudScript HES_StickNeutral
HudScript HES_BlueMeter
HudScript HES_StickMashLeft
HudScript HES_100pct
@ ACTION_COMMAND_MODE_NOT_LEARNED
Definition action_cmd.h:38
@ ACTION_COMMAND_SPOOK
Definition enums.h:3493
@ BUTTON_STICK_LEFT
Definition enums.h:2793
@ BUTTON_STICK_RIGHT
Definition enums.h:2794
@ 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
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_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: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
void N update(void)
Definition spook.c:60
s32 actionCmdTableSpook[]
Definition action_cmd.c:48
s32 D_802A9920_430940[8]
Definition spook.c:7
s32 * actionCmdDifficultyTable
BattleStatus gBattleStatus
Definition battle.c:11
void N init(Npc *bombette)
Definition bombette.c:66