fork/training-mode-ce
git clone https://git.julia.blue/fork/training-mode-ce
a385936
nix
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 { 15OPT_FIRE_SPEED , 16OPT_FIRE_DELAY_RANDOM_MIN , 17OPT_FIRE_DELAY_RANDOM_MAX , 18OPT_LASER_HEIGHT , 19OPT_DIRECTION , 20}; 21 22enum fire_speed { 23FIRE_SPEED_RANDOM , 24FIRE_SPEED_SLOW , 25FIRE_SPEED_MEDIUM , 26FIRE_SPEED_FAST , 27}; 28 29enum laser_height { 30LASER_HEIGHT_RANDOM , 31LASER_HEIGHT_VERY_LOW , 32LASER_HEIGHT_LOW , 33LASER_HEIGHT_MID , 34LASER_HEIGHT_HIGH , 35}; 36 37enum falco_direction { 38DIRECTION_RIGHT , 39DIRECTION_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 ) { 109GOBJ * player = Fighter_GetGObj (0 ); 110FighterData * player_data = player -> userdata ; 111GOBJ * falco = Fighter_GetGObj (1 ); 112FighterData * falco_data = falco -> userdata ; 113 114Fighter_ZeroCPUInputs (falco_data ); 115falco_data -> flags .no_reaction_always = true; 116falco_data -> grab .vuln = 0x1FF ; 117player_data -> shield .health = 60 ; 118 119int new_direction = -1 ; 120if (player_data -> input .down & HSD_BUTTON_DPAD_LEFT ) { 121new_direction = DIRECTION_RIGHT ; 122 }else if (player_data -> input .down & HSD_BUTTON_DPAD_RIGHT ) { 123new_direction = DIRECTION_LEFT ; 124 } 125if (new_direction != -1 ) { 126Options_Main [OPT_DIRECTION ].val = new_direction ; 127ChangeDirection (menu ,new_direction ); 128 } 129 130int state = falco_data -> state_id ; 131int state_frame = falco_data -> TM .state_frame ; 132 133bool ground_actionable = (state == ASID_LANDING && state_frame > 4 )|| state == ASID_WAIT ; 134bool air_actionable = state == ASID_JUMPF || state == ASID_JUMPB || (state == ASID_KNEEBEND && state_frame == 5 ); 135bool can_fastfall = falco_data -> phys .air_state == 1 && falco_data -> phys .self_vel .Y <=0.f ; 136 137if (ground_actionable && falco_wait_delay > 0 ) 138falco_wait_delay -- ; 139 140if (air_actionable && falco_shoot_delay > 0 ) 141falco_shoot_delay -- ; 142 143if (can_fastfall && falco_fastfall_delay > 0 ) 144falco_fastfall_delay -- ; 145 146 147if (ground_actionable && falco_wait_delay == -1 ) { 148// set wait timer 149 150int delay_option = Options_Main [OPT_FIRE_SPEED ].val ; 151 152if (delay_option == FIRE_SPEED_RANDOM ) 153falco_wait_delay = GetRandomLaserDelay (); 154else if (delay_option == FIRE_SPEED_SLOW ) 155falco_wait_delay = 20 ; 156else if (delay_option == FIRE_SPEED_MEDIUM ) 157falco_wait_delay = 10 ; 158else if (delay_option == FIRE_SPEED_FAST ) 159falco_wait_delay = 0 ; 160 } 161 162if (ground_actionable && falco_wait_delay == 0 ) { 163// start jump 164 165falco_wait_delay = -1 ; 166falco_data -> cpu .held |=PAD_BUTTON_Y ; 167 } 168 169if (air_actionable && falco_shoot_delay == -1 ) { 170// set shoot timer 171 172int delay_option = Options_Main [OPT_LASER_HEIGHT ].val ; 173 174if (delay_option == LASER_HEIGHT_RANDOM ) { 175falco_shoot_delay = HSD_Randi (4 )+ 2 ; 176falco_fastfall_delay = 1 ; 177 }else if (delay_option == LASER_HEIGHT_VERY_LOW ) { 178falco_shoot_delay = 11 ; 179falco_fastfall_delay = 8 ; 180 }else if (delay_option == LASER_HEIGHT_LOW ) { 181falco_shoot_delay = 5 ; 182falco_fastfall_delay = 1 ; 183 }else if (delay_option == LASER_HEIGHT_MID ) { 184falco_shoot_delay = 4 ; 185falco_fastfall_delay = 1 ; 186 }else if (delay_option == LASER_HEIGHT_HIGH ) { 187falco_shoot_delay = 2 ; 188falco_fastfall_delay = 0 ; 189 } 190 } 191 192if (air_actionable && falco_shoot_delay == 0 ) { 193// start laser 194 195falco_shoot_delay = -1 ; 196falco_data -> cpu .held |=PAD_BUTTON_B ; 197 } 198 199if (can_fastfall && falco_fastfall_delay == 0 ) { 200falco_data -> cpu .lstickY = -127 ; 201falco_fastfall_delay = -1 ; 202 } 203} 204 205void Exit (GOBJ * menu ) { 206stc_match -> state = 3 ; 207Match_EndVS (); 208} 209 210void ChangeFireSpeedOption (GOBJ * event_menu ,int value ) { 211bool disable_random_bounds = value != FIRE_SPEED_RANDOM ; 212Options_Main [OPT_FIRE_DELAY_RANDOM_MIN ].disable = disable_random_bounds ; 213Options_Main [OPT_FIRE_DELAY_RANDOM_MAX ].disable = disable_random_bounds ; 214} 215 216void ChangeDirection (GOBJ * event_menu ,int value ) { 217GOBJ * falco = Fighter_GetGObj (1 ); 218FighterData * falco_data = falco -> userdata ; 219 220if (value == DIRECTION_LEFT ) { 221falco_data -> facing_direction = CPU_LEFT_DIRECTION ; 222falco_data -> phys .pos .X = CPU_LEFT_STAGE_POS_X ; 223 }else { 224falco_data -> facing_direction = - CPU_LEFT_DIRECTION ; 225falco_data -> phys .pos .X = - CPU_LEFT_STAGE_POS_X ; 226 } 227} 228 229void ChangeRandomFireDelayMin (GOBJ * event_menu ,int value ) { 230int random_fire_delay_min = Options_Main [OPT_FIRE_DELAY_RANDOM_MIN ].val ; 231int random_fire_delay_max = Options_Main [OPT_FIRE_DELAY_RANDOM_MAX ].val ; 232 233// Ensure the min is never greater than the max 234if (random_fire_delay_min > random_fire_delay_max ) { 235Options_Main [OPT_FIRE_DELAY_RANDOM_MAX ].val = random_fire_delay_min ; 236 } 237} 238 239void ChangeRandomFireDelayMax (GOBJ * event_menu ,int value ) { 240int random_fire_delay_min = Options_Main [OPT_FIRE_DELAY_RANDOM_MIN ].val ; 241int random_fire_delay_max = Options_Main [OPT_FIRE_DELAY_RANDOM_MAX ].val ; 242 243// Ensure the max is never less than the min 244if (random_fire_delay_max < random_fire_delay_min ) { 245Options_Main [OPT_FIRE_DELAY_RANDOM_MIN ].val = random_fire_delay_max ; 246 } 247} 248 249int GetRandomLaserDelay (void ) { 250int random_fire_delay_min = Options_Main [OPT_FIRE_DELAY_RANDOM_MIN ].val ; 251int random_fire_delay_max = Options_Main [OPT_FIRE_DELAY_RANDOM_MAX ].val ; 252 253return HSD_Randi (random_fire_delay_max - random_fire_delay_min )+ random_fire_delay_min ; 254} 255 256EventMenu * Event_Menu = & Menu_Main ;