fork/training-mode-ce

git clone https://git.julia.blue/fork/training-mode-ce

Nick CondronMenu overhaul (#298)a385936

nix
7.8 KiB256 linesraw
1#include "../MexTK/mex.h"
2#include "events.h"
3
4#define CPU_LEFT_STAGE_POS_X 70.f
5#define CPU_LEFT_DIRECTION -1.f
6
7void Exit(GOBJ *menu);
8void ChangeFireSpeedOption(GOBJ *event_menu, int value);
9void ChangeDirection(GOBJ *event_menu, int value);
10void ChangeRandomFireDelayMin(GOBJ *event_menu, int value);
11void ChangeRandomFireDelayMax(GOBJ *event_menu, int value);
12int GetRandomLaserDelay(void);
13
14enum menu_options {
15    OPT_FIRE_SPEED,
16    OPT_FIRE_DELAY_RANDOM_MIN,
17    OPT_FIRE_DELAY_RANDOM_MAX,
18    OPT_LASER_HEIGHT,
19    OPT_DIRECTION,
20};
21
22enum fire_speed {
23    FIRE_SPEED_RANDOM,
24    FIRE_SPEED_SLOW,
25    FIRE_SPEED_MEDIUM,
26    FIRE_SPEED_FAST,
27};
28
29enum laser_height {
30    LASER_HEIGHT_RANDOM,
31    LASER_HEIGHT_VERY_LOW,
32    LASER_HEIGHT_LOW,
33    LASER_HEIGHT_MID,
34    LASER_HEIGHT_HIGH,
35};
36
37enum falco_direction {
38    DIRECTION_RIGHT,
39    DIRECTION_LEFT,
40};
41
42static const char *Options_FireSpeed[] = { "Random", "Slow", "Medium", "Fast" };
43static const char *Options_LaserHeight[] = { "Random", "Very Low", "Low", "Mid", "High" };
44static const char *Options_Direction[] = { "Right", "Left" };
45
46static EventOption Options_Main[] = {
47    {
48        .kind = OPTKIND_STRING,
49        .value_num = sizeof(Options_FireSpeed) / 4,
50        .name = "Fire Speed",
51        .desc = {"Change the rate of fire."},
52        .values = Options_FireSpeed,
53        .OnChange = ChangeFireSpeedOption,
54    },
55    {
56        .kind = OPTKIND_INT,
57        .value_num = 61,
58        .val = 0,
59        .name = "Min Fire Delay",
60        .desc = {"Adjust the minimum number of frames between lasers"},
61        .format = "%d",
62        .OnChange = ChangeRandomFireDelayMin,
63        .disable = false,
64    },
65    {
66        .kind = OPTKIND_INT,
67        .value_num = 61,
68        .val = 20,
69        .name = "Max Fire Delay",
70        .desc = {"Adjust the maximum number of frames between lasers"},
71        .format = "%d",
72        .OnChange = ChangeRandomFireDelayMax,
73        .disable = false,
74    },
75    {
76        .kind = OPTKIND_STRING,
77        .value_num = sizeof(Options_LaserHeight) / 4,
78        .name = "Laser Height",
79        .desc = {"Change the laser height."},
80        .values = Options_LaserHeight,
81    },
82    {
83        .kind = OPTKIND_STRING,
84        .value_num = sizeof(Options_Direction) / 4,
85        .name = "Direction",
86        .desc = {"Change which way falco shoots a laser."},
87        .values = Options_Direction,
88        .OnChange = ChangeDirection,
89    },
90    {
91        .kind = OPTKIND_FUNC,
92        .name = "Exit",
93        .desc = {"Return to the Event Select Screen."},
94        .OnSelect = Exit,
95    },
96};
97
98static EventMenu Menu_Main = {
99    .name = "Powershield Training",
100    .option_num = sizeof(Options_Main) / sizeof(EventOption),
101    .options = Options_Main,
102};
103
104static int falco_wait_delay = -1;
105static int falco_shoot_delay = -1;
106static int falco_fastfall_delay = -1;
107
108void Event_Think(GOBJ *menu) {
109    GOBJ *player = Fighter_GetGObj(0);
110    FighterData *player_data = player->userdata;
111    GOBJ *falco = Fighter_GetGObj(1);
112    FighterData *falco_data = falco->userdata;
113
114    Fighter_ZeroCPUInputs(falco_data);
115    falco_data->flags.no_reaction_always = true;
116    falco_data->grab.vuln = 0x1FF;
117    player_data->shield.health = 60;
118
119    int new_direction = -1;
120    if (player_data->input.down & HSD_BUTTON_DPAD_LEFT) {
121        new_direction = DIRECTION_RIGHT;
122    } else if (player_data->input.down & HSD_BUTTON_DPAD_RIGHT) {
123        new_direction = DIRECTION_LEFT;
124    }
125    if (new_direction != -1) {
126        Options_Main[OPT_DIRECTION].val = new_direction;
127        ChangeDirection(menu, new_direction);
128    }
129
130    int state = falco_data->state_id;
131    int state_frame = falco_data->TM.state_frame;
132
133    bool ground_actionable = (state == ASID_LANDING && state_frame > 4) || state == ASID_WAIT;
134    bool air_actionable = state == ASID_JUMPF || state == ASID_JUMPB || (state == ASID_KNEEBEND && state_frame == 5);
135    bool can_fastfall = falco_data->phys.air_state == 1 && falco_data->phys.self_vel.Y <= 0.f;
136
137    if (ground_actionable && falco_wait_delay > 0)
138        falco_wait_delay--;
139
140    if (air_actionable && falco_shoot_delay > 0)
141        falco_shoot_delay--;
142
143    if (can_fastfall && falco_fastfall_delay > 0)
144        falco_fastfall_delay--;
145
146
147    if (ground_actionable && falco_wait_delay == -1) {
148        // set wait timer
149
150        int delay_option = Options_Main[OPT_FIRE_SPEED].val;
151
152        if (delay_option == FIRE_SPEED_RANDOM)
153            falco_wait_delay = GetRandomLaserDelay();
154        else if (delay_option == FIRE_SPEED_SLOW)
155            falco_wait_delay = 20;
156        else if (delay_option == FIRE_SPEED_MEDIUM)
157            falco_wait_delay = 10;
158        else if (delay_option == FIRE_SPEED_FAST)
159            falco_wait_delay = 0;
160    }
161
162    if (ground_actionable && falco_wait_delay == 0) {
163        // start jump
164
165        falco_wait_delay = -1;
166        falco_data->cpu.held |= PAD_BUTTON_Y;
167    }
168
169    if (air_actionable && falco_shoot_delay == -1) {
170        // set shoot timer
171
172        int delay_option = Options_Main[OPT_LASER_HEIGHT].val;
173
174        if (delay_option == LASER_HEIGHT_RANDOM) {
175            falco_shoot_delay = HSD_Randi(4) + 2;
176            falco_fastfall_delay = 1;
177        } else if (delay_option == LASER_HEIGHT_VERY_LOW) {
178            falco_shoot_delay = 11;
179            falco_fastfall_delay = 8;
180        } else if (delay_option == LASER_HEIGHT_LOW) {
181            falco_shoot_delay = 5;
182            falco_fastfall_delay = 1;
183        } else if (delay_option == LASER_HEIGHT_MID) {
184            falco_shoot_delay = 4;
185            falco_fastfall_delay = 1;
186        } else if (delay_option == LASER_HEIGHT_HIGH) {
187            falco_shoot_delay = 2;
188            falco_fastfall_delay = 0;
189        }
190    }
191
192    if (air_actionable && falco_shoot_delay == 0) {
193        // start laser
194
195        falco_shoot_delay = -1;
196        falco_data->cpu.held |= PAD_BUTTON_B;
197    }
198
199    if (can_fastfall && falco_fastfall_delay == 0) {
200        falco_data->cpu.lstickY = -127;
201        falco_fastfall_delay = -1;
202    }
203}
204
205void Exit(GOBJ *menu) {
206    stc_match->state = 3;
207    Match_EndVS();
208}
209
210void ChangeFireSpeedOption(GOBJ *event_menu, int value) {
211    bool disable_random_bounds = value != FIRE_SPEED_RANDOM;
212    Options_Main[OPT_FIRE_DELAY_RANDOM_MIN].disable = disable_random_bounds;
213    Options_Main[OPT_FIRE_DELAY_RANDOM_MAX].disable = disable_random_bounds;
214}
215
216void ChangeDirection(GOBJ *event_menu, int value) {
217    GOBJ *falco = Fighter_GetGObj(1);
218    FighterData *falco_data = falco->userdata;
219
220    if (value == DIRECTION_LEFT) {
221        falco_data->facing_direction = CPU_LEFT_DIRECTION;
222        falco_data->phys.pos.X = CPU_LEFT_STAGE_POS_X;
223    } else {
224        falco_data->facing_direction = -CPU_LEFT_DIRECTION;
225        falco_data->phys.pos.X = -CPU_LEFT_STAGE_POS_X;    
226    }
227}
228
229void ChangeRandomFireDelayMin(GOBJ *event_menu, int value) {
230    int random_fire_delay_min = Options_Main[OPT_FIRE_DELAY_RANDOM_MIN].val;
231    int random_fire_delay_max = Options_Main[OPT_FIRE_DELAY_RANDOM_MAX].val;
232
233    // Ensure the min is never greater than the max
234    if (random_fire_delay_min > random_fire_delay_max) {
235        Options_Main[OPT_FIRE_DELAY_RANDOM_MAX].val = random_fire_delay_min;
236    }
237}
238
239void ChangeRandomFireDelayMax(GOBJ *event_menu, int value) {
240    int random_fire_delay_min = Options_Main[OPT_FIRE_DELAY_RANDOM_MIN].val;
241    int random_fire_delay_max = Options_Main[OPT_FIRE_DELAY_RANDOM_MAX].val;
242
243    // Ensure the max is never less than the min
244    if (random_fire_delay_max < random_fire_delay_min) {
245        Options_Main[OPT_FIRE_DELAY_RANDOM_MIN].val = random_fire_delay_max;
246    }
247}
248
249int GetRandomLaserDelay(void) {
250    int random_fire_delay_min = Options_Main[OPT_FIRE_DELAY_RANDOM_MIN].val;
251    int random_fire_delay_max = Options_Main[OPT_FIRE_DELAY_RANDOM_MAX].val;
252
253    return HSD_Randi(random_fire_delay_max - random_fire_delay_min) + random_fire_delay_min;
254}
255
256EventMenu *Event_Menu = &Menu_Main;