fork/training-mode-ce
git clone https://git.julia.blue/fork/training-mode-ce
deecee7
nix
1#include "../MexTK/mex.h" 2#include "events.h" 3 4static EventMenu Menu_Main ; 5static EventMenu Menu_Chances ; 6 7static void Exit (GOBJ * menu ); 8static void StartMoveCPU (GOBJ * menu ); 9static void FinishMoveCPU (GOBJ * menu ); 10static void StartMoveHMN (GOBJ * menu ); 11static void FinishMoveHMN (GOBJ * menu ); 12static void ChangeTechInPlaceChance (GOBJ * menu_gobj ,int _new_val ); 13static void ChangeTechAwayChance (GOBJ * menu_gobj ,int _new_val ); 14static void ChangeTechTowardChance (GOBJ * menu_gobj ,int _new_val ); 15static void ChangeMissTechChance (GOBJ * menu_gobj ,int _new_val ); 16static void ChangeStandChance (GOBJ * menu_gobj ,int _new_val ); 17static void ChangeRollAwayChance (GOBJ * menu_gobj ,int _new_val ); 18static void ChangeRollTowardChance (GOBJ * menu_gobj ,int _new_val ); 19static void ChangeGetupAttackChance (GOBJ * menu_gobj ,int _new_val ); 20 21static const char * Options_Invis []= {"None" ,"After Reaction" ,"Flash Reaction" }; 22enum { 23OPTINVIS_NONE , 24OPTINVIS_POST_REACTION , 25OPTINVIS_FLASH , 26 27OPTINVIS_COUNT 28}; 29 30static const EventOption Option_MoveCPU = { 31 .kind = OPTKIND_FUNC , 32 .name = "Move CPU" , 33 .desc = {"Manually set the CPU's position." ,"Press A to change direction." }, 34 .OnSelect = StartMoveCPU , 35}; 36 37static const EventOption Option_FinishMoveCPU = { 38 .kind = OPTKIND_FUNC , 39 .name = "Finish Moving CPU" , 40 .desc = {"Finish setting the CPU's position." }, 41 .OnSelect = FinishMoveCPU , 42}; 43 44static const EventOption Option_MoveHMN = { 45 .kind = OPTKIND_FUNC , 46 .name = "Move HMN" , 47 .desc = {"Manually set the HMN's position." ,"Press A to change direction." }, 48 .OnSelect = StartMoveHMN , 49}; 50 51static const EventOption Option_FinishMoveHMN = { 52 .kind = OPTKIND_FUNC , 53 .name = "Finish Moving HMN" , 54 .desc = {"Finish setting the HMN's position." }, 55 .OnSelect = FinishMoveHMN , 56}; 57 58static float GameSpeeds []= {1.f ,5.f /6.f ,2.f /3.f ,1.f /2.f ,1.f /4.f }; 59static const char * Options_GameSpeedText []= {"1" ,"5/6" ,"2/3" ,"1/2" ,"1/4" }; 60 61static const char * Options_Reset []= {"Fast" ,"Slow" ,"None" }; 62static int ResetDurations []= {30 ,60 ,2147483647 }; 63 64enum { 65OPT_CHANCE_MENU , 66OPT_REACTION_OSD , 67OPT_TIMING_OSD , 68OPT_RESET , 69OPT_INVIS , 70OPT_SPEED , 71OPT_MOVE_CPU , 72OPT_MOVE_HMN , 73OPT_EXIT , 74 75OPT_COUNT 76}; 77 78static EventOption Options_Main []= { 79 { 80 .kind = OPTKIND_MENU , 81 .menu = & Menu_Chances , 82 .name = "Tech Chances" , 83 .desc = {"Adjust tech and getup option chances." }, 84 }, 85 { 86 .kind = OPTKIND_TOGGLE , 87 .name = "Reaction Frame OSD" , 88 .desc = {"Check which frame you reacted on." }, 89 }, 90 { 91 .kind = OPTKIND_TOGGLE , 92 .name = "Timing OSD" , 93 .desc = {"Check how early or late you were." }, 94 .val = true, 95 }, 96 { 97 .kind = OPTKIND_STRING , 98 .name = "Reset" , 99 .desc = {"Change how quickly the event resets." }, 100 .values = Options_Reset , 101 .value_num = countof (Options_Reset ), 102 }, 103 { 104 .kind = OPTKIND_STRING , 105 .name = "Tech Invisibility" , 106 .desc = {"Toggle the CPU turning invisible during tech" ,"animations." }, 107 .values = Options_Invis , 108 .value_num = countof (Options_Invis ), 109 }, 110 { 111 .kind = OPTKIND_STRING , 112 .value_num = countof (Options_GameSpeedText ), 113 .name = "Game Speed" , 114 .desc = {"Change how fast the game engine runs." }, 115 .values = Options_GameSpeedText , 116 }, 117Option_MoveCPU , 118Option_MoveHMN , 119 { 120 .kind = OPTKIND_FUNC , 121 .name = "Exit" , 122 .desc = {"Return to the Event Select Screen." }, 123 .OnSelect = Exit , 124 }, 125}; 126 127static EventMenu Menu_Main = { 128 .name = "Techchase Training" , 129 .option_num = countof (Options_Main ), 130 .options = Options_Main , 131}; 132 133EventMenu * Event_Menu = & Menu_Main ; 134 135enum { 136OPTCHANCE_TECHINPLACE , 137OPTCHANCE_TECHAWAY , 138OPTCHANCE_TECHTOWARD , 139OPTCHANCE_MISSTECH , 140OPTCHANCE_GETUPWAIT , 141OPTCHANCE_GETUPSTAND , 142OPTCHANCE_GETUPAWAY , 143OPTCHANCE_GETUPTOWARD , 144OPTCHANCE_GETUPATTACK , 145 146OPTCHANCE_COUNT 147}; 148 149static EventOption Options_Chances []= { 150 { 151 .kind = OPTKIND_INT , 152 .value_num = 101 , 153 .val = 40 , 154 .name = "Tech in Place Chance" , 155 .desc = {"Adjust the chance the CPU will tech in place." }, 156 .format = "%d%%" , 157 .OnChange = ChangeTechInPlaceChance , 158 }, 159 { 160 .kind = OPTKIND_INT , 161 .value_num = 101 , 162 .val = 30 , 163 .name = "Tech Away Chance" , 164 .desc = {"Adjust the chance the CPU will tech away." }, 165 .format = "%d%%" , 166 .OnChange = ChangeTechAwayChance , 167 }, 168 { 169 .kind = OPTKIND_INT , 170 .value_num = 101 , 171 .val = 30 , 172 .name = "Tech Toward Chance" , 173 .desc = {"Adjust the chance the CPU will tech toward." }, 174 .format = "%d%%" , 175 .OnChange = ChangeTechTowardChance , 176 }, 177 { 178 .kind = OPTKIND_INT , 179 .value_num = 101 , 180 .val = 0 , 181 .name = "Miss Tech Chance" , 182 .desc = {"Adjust the chance the CPU will miss tech." }, 183 .format = "%d%%" , 184 .OnChange = ChangeMissTechChance , 185 }, 186 { 187 .kind = OPTKIND_INT , 188 .value_num = 101 , 189 .val = 0 , 190 .name = "Miss Tech Wait Chance" , 191 .desc = {"Adjust the chance the CPU will wait 15 frames" , 192"after a missed tech." }, 193 .format = "%d%%" , 194 }, 195 { 196 .kind = OPTKIND_INT , 197 .value_num = 101 , 198 .val = 25 , 199 .name = "Stand Chance" , 200 .desc = {"Adjust the chance the CPU will stand." }, 201 .format = "%d%%" , 202 .OnChange = ChangeStandChance , 203 }, 204 { 205 .kind = OPTKIND_INT , 206 .value_num = 101 , 207 .val = 25 , 208 .name = "Roll Away Chance" , 209 .desc = {"Adjust the chance the CPU will roll away." }, 210 .format = "%d%%" , 211 .OnChange = ChangeRollAwayChance , 212 }, 213 { 214 .kind = OPTKIND_INT , 215 .value_num = 101 , 216 .val = 25 , 217 .name = "Roll Toward Chance" , 218 .desc = {"Adjust the chance the CPU will roll toward." }, 219 .format = "%d%%" , 220 .OnChange = ChangeRollTowardChance , 221 }, 222 { 223 .kind = OPTKIND_INT , 224 .value_num = 101 , 225 .val = 25 , 226 .name = "Getup Attack Chance" , 227 .desc = {"Adjust the chance the CPU will getup attack." }, 228 .format = "%d%%" , 229 .OnChange = ChangeGetupAttackChance , 230 }, 231}; 232 233static EventMenu Menu_Chances = { 234 .name = "Option Chances" , 235 .option_num = countof (Options_Chances ), 236 .options = Options_Chances , 237}; 238 239static void UpdatePosition (GOBJ * fighter ) { 240FighterData * data = fighter -> userdata ; 241 242Vec3 pos = data -> phys .pos ; 243data -> coll_data .topN_Curr = pos ; 244data -> coll_data .topN_CurrCorrect = pos ; 245data -> coll_data .topN_Prev = pos ; 246data -> coll_data .topN_Proj = pos ; 247data -> coll_data .coll_test = * stc_colltest ; 248 249JOBJ * jobj = fighter -> hsd_object ; 250jobj -> trans = data -> phys .pos ; 251JOBJ_SetMtxDirtySub (jobj ); 252 253// Update static hmn block coords 254Fighter_SetPosition (data -> ply ,data -> flags .ms ,& data -> phys .pos ); 255} 256 257static bool FindGroundNearPlayer (GOBJ * fighter ,Vec3 * pos ,int * line_idx ) { 258FighterData * data = fighter -> userdata ; 259float x = data -> phys .pos .X ; 260float y1 = data -> phys .pos .Y + 4 ; 261float y2 = data -> phys .pos .Y - 4 ; 262 263Vec3 _line_unk ; 264int _line_kind ; 265 266return GrColl_RaycastGround (pos ,line_idx ,& _line_kind ,& _line_unk , 267-1 ,-1 ,-1 ,0 ,x ,y1 ,x ,y2 ,0 ); 268} 269 270static void UpdateCameraBox (GOBJ * fighter ) { 271Fighter_UpdateCameraBox (fighter ); 272 273FighterData * data = fighter -> userdata ; 274CmSubject * subject = data -> camera_subject ; 275subject -> boundleft_curr = subject -> boundleft_proj ; 276subject -> boundright_curr = subject -> boundright_proj ; 277} 278 279static int reset_timer = -1 ; 280static int missed_tech_getup_timer = -1 ; 281static int first_action_frame = -1 ; 282static bool put_out_hitbox = false; 283 284// figatree_curr->frame_num for last getup animation. 285// We can't easily request this on demand so we store it here pre-emptively. 286static int getup_option_length = 0 ; 287 288static int hmn_pad_index ; 289static int null_pad_index ; 290 291static Vec3 cpu_pos = {5 ,27 ,0 }; 292static Vec3 hmn_pos = {-5 ,0 ,0 }; 293static float cpu_facing_direction = -1 ; 294static float hmn_facing_direction = 1 ; 295 296static void Reset (void ) { 297event_vars -> Savestate_Load_v1 (event_vars -> savestate ,Savestate_Silent ); 298 299GOBJ * hmn = Fighter_GetGObj (0 ); 300GOBJ * cpu = Fighter_GetGObj (1 ); 301FighterData * hmn_data = hmn -> userdata ; 302FighterData * cpu_data = cpu -> userdata ; 303 304hmn_data -> facing_direction = hmn_facing_direction ; 305cpu_data -> facing_direction = cpu_facing_direction ; 306 307hmn_data -> phys .pos = hmn_pos ; 308cpu_data -> phys .pos = cpu_pos ; 309 310UpdatePosition (hmn ); 311UpdatePosition (cpu ); 312 313Vec3 grounded_hmn_pos ; 314int ground_index ; 315if (FindGroundNearPlayer (hmn ,& grounded_hmn_pos ,& ground_index )) { 316hmn_data -> phys .pos = grounded_hmn_pos ; 317hmn_data -> coll_data .ground_index = ground_index ; 318UpdatePosition (hmn ); 319EnvironmentCollision_WaitLanding (hmn ); 320Fighter_SetGrounded (hmn_data ); 321Fighter_EnterWait (hmn ); 322 }else { 323Fighter_EnterFall (hmn ); 324 } 325 326Fighter_EnterDamageFall (cpu ); 327 328UpdateCameraBox (hmn ); 329UpdateCameraBox (cpu ); 330 331Match_CorrectCamera (); 332 333reset_timer = -1 ; 334missed_tech_getup_timer = -1 ; 335first_action_frame = -1 ; 336put_out_hitbox = false; 337} 338 339static int tech_frame_distinguishable [27 ]= { 3408 ,// Mario 3414 ,// Fox 3426 ,// Captain Falcon 3439 ,// Donkey Kong 3443 ,// Kirby 3451 ,// Bowser 3466 ,// Link 3478 ,// Sheik 3488 ,// Ness 3493 ,// Peach 3509 ,// Popo (Ice Climbers) 3519 ,// Nana (Ice Climbers) 3527 ,// Pikachu 3536 ,// Samus 3549 ,// Yoshi 3553 ,// Jigglypuff 35616 ,// Mewtwo 3578 ,// Luigi 3587 ,// Marth 3596 ,// Zelda 3606 ,// Young Link 3618 ,// Dr. Mario 3624 ,// Falco 3638 ,// Pichu 3643 ,// Game & Watch 3656 ,// Ganondorf 3667 ,// Roy 367}; 368 369void Event_Update (GOBJ * menu ) { 370if (Pause_CheckStatus (1 )!= 2 ) { 371float speed = GameSpeeds [Options_Main [OPT_SPEED ].val ]; 372HSD_SetSpeedEasy (speed ); 373 }else { 374HSD_SetSpeedEasy (1.0 ); 375 } 376 377} 378 379void MoveFighter (GOBJ * ft ,Vec3 * pos ,float * facing_direction ) { 380HSD_Pad * pad = PadGetMaster (hmn_pad_index ); 381FighterData * ft_data = ft -> userdata ; 382 383if (pad -> down & HSD_BUTTON_A ) 384* facing_direction = -* facing_direction ; 385ft_data -> facing_direction = * facing_direction ; 386ft_data -> facing_direction_prev = * facing_direction ; 387 388float x = pad -> fstickX ; 389float y = pad -> fstickY ; 390float deadzone = 0.2750f ; 391if (fabs (x )< deadzone )x = 0.f ; 392if (fabs (y )< deadzone )y = 0.f ; 393pos -> X += x * 1.5f ; 394pos -> Y += y * 1.5f ; 395ft_data -> phys .pos = * pos ; 396UpdatePosition (ft ); 397} 398 399void Event_Think (GOBJ * menu ) { 400if (event_vars -> game_timer == 1 ) { 401event_vars -> Savestate_Save_v1 (event_vars -> savestate ,Savestate_Silent ); 402Reset (); 403 } 404 405HSD_Pad * pad = PadGetMaster (hmn_pad_index ); 406GOBJ * hmn = Fighter_GetGObj (0 ); 407GOBJ * cpu = Fighter_GetGObj (1 ); 408FighterData * hmn_data = hmn -> userdata ; 409FighterData * cpu_data = cpu -> userdata ; 410 411// move CPU 412if (Options_Main [OPT_MOVE_CPU ].name == Option_FinishMoveCPU .name ) { 413MoveFighter (cpu ,& cpu_pos ,& cpu_facing_direction ); 414Fighter_EnterDamageFall (cpu ); 415return ; 416 } 417 418// move HMN 419else if (Options_Main [OPT_MOVE_HMN ].name == Option_FinishMoveHMN .name ) { 420MoveFighter (hmn ,& hmn_pos ,& hmn_facing_direction ); 421 422Vec3 grounded_hmn_pos ; 423int ground_index ; 424if (FindGroundNearPlayer (hmn ,& grounded_hmn_pos ,& ground_index )) { 425hmn_data -> phys .pos = grounded_hmn_pos ; 426hmn_data -> coll_data .ground_index = ground_index ; 427 } 428Fighter_EnterFall (hmn ); 429 430return ; 431 } 432 433cpu_data -> cpu .ai = 15 ; 434cpu_data -> cpu .held = 0 ; 435cpu_data -> cpu .lstickX = 0 ; 436cpu_data -> cpu .lstickY = 0 ; 437cpu_data -> cpu .cstickX = 0 ; 438cpu_data -> cpu .cstickY = 0 ; 439 440int state_id = cpu_data -> state_id ; 441 442// cache getup_option_length 443if (ASID_DOWNSPOTD <=state_id && state_id <=ASID_PASSIVESTANDB ) 444getup_option_length = cpu_data -> figatree_curr -> frame_num ; 445 446// check for action 447if ( 448Options_Main [OPT_REACTION_OSD ].val 449&& ASID_DOWNSPOTD <=state_id && state_id <=ASID_PASSIVESTANDB 450&& first_action_frame == -1 451 ) { 452HSD_Pad * engine_pad = PadGetEngine (hmn_data -> pad_index ); 453 454int input = engine_pad -> held |engine_pad -> stickX |engine_pad -> stickY |engine_pad -> substickX |engine_pad -> substickY ; 455if (input != 0 ) { 456first_action_frame = cpu_data -> TM .state_frame ; 457int frame_distinguishable = tech_frame_distinguishable [cpu_data -> kind ]; 458 459event_vars -> Message_Display ( 46015 ,hmn_data -> ply ,MSGCOLOR_WHITE , 461"Reaction: %if\n" ,first_action_frame - frame_distinguishable 462 ); 463 } 464 } 465 466// set intangibility 467if ( 468 ( 469// make invincible on last frame of getup/tech option 470ASID_DOWNSPOTD <=state_id && state_id <=ASID_PASSIVESTANDB 471&& cpu_data -> state .frame + 1 == cpu_data -> figatree_curr -> frame_num 472 ) 473|| state_id == ASID_WAIT 474|| state_id == ASID_DAMAGEFALL 475 ) { 476cpu_data -> hurt .intang_frames .ledge = 1 ; 477cpu_data -> hurt .kind_game = 1 ; 478 }else { 479cpu_data -> hurt .intang_frames .ledge = 0 ; 480cpu_data -> hurt .kind_game = 0 ; 481 } 482 483// Check for late attack and show Timing OSD 484if ( 485Options_Main [OPT_TIMING_OSD ].val 486&& state_id == ASID_WAIT 487&& hmn_data -> flags .hitbox_active 488&& !put_out_hitbox 489 ) { 490put_out_hitbox = true; 491event_vars -> Message_Display ( 49216 ,hmn_data -> ply ,MSGCOLOR_RED , 493"%if Late\n" ,cpu_data -> TM .state_frame 494 ); 495 } 496 497if (reset_timer == -1 ) { 498// tech if airborne 499if (cpu_data -> phys .air_state == 1 ) { 500cpu_data -> input .timer_LR = 0 ; 501 502int rng = HSD_Randi (100 ); 503s8 x = 0 ; 504char LR = 0 ; 505if ((rng -= Options_Chances [OPTCHANCE_TECHINPLACE ].val )< 0 ) { 506 507 }else if ((rng -= Options_Chances [OPTCHANCE_TECHAWAY ].val )< 0 ) { 508x = 40 * (int )sign (cpu_data -> phys .pos .X - hmn_data -> phys .pos .X ); 509 }else if ((rng -= Options_Chances [OPTCHANCE_TECHTOWARD ].val )< 0 ) { 510x = 40 * (int )sign (hmn_data -> phys .pos .X - cpu_data -> phys .pos .X ); 511 }else { 512LR = -1 ; 513 } 514cpu_data -> cpu .lstickX = x ; 515cpu_data -> input .timer_LR = LR ; 516 } 517 518// missed tech getup 519if (missed_tech_getup_timer == -1 ) { 520if (state_id == ASID_DOWNWAITU || state_id == ASID_DOWNWAITD ) { 521int rng = HSD_Randi (100 ); 522if (rng < Options_Chances [OPTCHANCE_GETUPWAIT ].val ) { 523missed_tech_getup_timer = 15 ; 524 }else { 525rng = HSD_Randi (100 ); 526s8 x = 0 ; 527s8 y = 0 ; 528int held = 0 ; 529if ((rng -= Options_Chances [OPTCHANCE_GETUPSTAND ].val )< 0 ) { 530y = 127 ; 531 }else if ((rng -= Options_Chances [OPTCHANCE_GETUPAWAY ].val )< 0 ) { 532x = 40 * (int )sign (cpu_data -> phys .pos .X - hmn_data -> phys .pos .X ); 533 }else if ((rng -= Options_Chances [OPTCHANCE_GETUPTOWARD ].val )< 0 ) { 534x = 40 * (int )sign (hmn_data -> phys .pos .X - cpu_data -> phys .pos .X ); 535 }else { 536held = PAD_BUTTON_A ; 537 } 538cpu_data -> cpu .lstickX = x ; 539cpu_data -> cpu .lstickY = y ; 540cpu_data -> cpu .held = held ; 541 } 542 } 543 }else { 544missed_tech_getup_timer -- ; 545 } 546 547// fail if finished tech 548if (state_id == ASID_WAIT ) { 549// SFX_Play(0xAF); 550reset_timer = ResetDurations [Options_Main [OPT_RESET ].val ]; 551 } 552// succeed if grabbed or hit 553else if ( 554 (ASID_CAPTUREPULLEDHI <=state_id && state_id <=ASID_CAPTUREFOOT ) 555|| (ASID_DAMAGEHI1 <=state_id && state_id <=ASID_DAMAGEFLYROLL ) 556|| (cpu_data -> dmg .hitlag_frames > 0 && cpu_data -> flags .hitlag_victim ) 557 ) { 558// Show Timing OSD 559if (Options_Main [OPT_TIMING_OSD ].val && !put_out_hitbox ) { 560put_out_hitbox = true; 561 562int frames_taken = -1 ; 563int prev_state_id = -1 ; 564for (int i = 0 ;i < 6 ;++ i ) { 565prev_state_id = cpu_data -> TM .state_prev [i ]; 566if (ASID_DOWNSPOTD <=prev_state_id && prev_state_id <=ASID_PASSIVESTANDB ) { 567frames_taken = cpu_data -> TM .state_prev_frames [i ]; 568break ; 569 } 570 } 571 572if (prev_state_id != -1 ) { 573event_vars -> Message_Display ( 57416 ,hmn_data -> ply ,MSGCOLOR_GREEN , 575"%if Early\n" ,getup_option_length - frames_taken - 2 576 ); 577 } 578 } 579 580SFX_Play (0xAD ); 581reset_timer = ResetDurations [Options_Main [OPT_RESET ].val ]; 582 } 583 } 584 585if (pad -> down & HSD_BUTTON_DPAD_LEFT ) 586Reset (); 587 588if (reset_timer >=0 && reset_timer -- == 0 ) 589Reset (); 590} 591 592static void Event_PostThink (GOBJ * menu ) { 593GOBJ * cpu = Fighter_GetGObj (1 ); 594FighterData * cpu_data = cpu -> userdata ; 595int state_id = cpu_data -> state_id ; 596 597int frame_distinguishable = tech_frame_distinguishable [cpu_data -> kind ]; 598switch (Options_Main [OPT_INVIS ].val ) { 599case OPTINVIS_NONE : { 600cpu_data -> flags .invisible = false; 601 }break ; 602case OPTINVIS_POST_REACTION : { 603bool post_reaction = 604ASID_PASSIVE <=state_id && state_id <=ASID_PASSIVESTANDB 605&& frame_distinguishable < cpu_data -> TM .state_frame && cpu_data -> TM .state_frame < 20 ; 606cpu_data -> flags .invisible = post_reaction ; 607 }break ; 608case OPTINVIS_FLASH : { 609bool on_reaction = ( 610ASID_PASSIVE <=state_id && state_id <=ASID_PASSIVESTANDB 611&& cpu_data -> TM .state_frame + 1 != frame_distinguishable 612&& cpu_data -> TM .state_frame < 20 613 ) 614|| state_id == ASID_DAMAGEFALL ; 615cpu_data -> flags .invisible = on_reaction ; 616 }break ; 617 } 618 619memset (& cpu_data -> color [1 ],0 ,sizeof (ColorOverlay )); 620memset (& cpu_data -> color [0 ],0 ,sizeof (ColorOverlay )); 621if (state_id == ASID_WAIT ) { 622cpu_data -> color [1 ].hex = (GXColor ) {0xF0 ,0xF0 ,0xF0 ,0xA0 }; 623cpu_data -> color [1 ].color_enable = 1 ; 624 } 625} 626 627void Event_Init (GOBJ * gobj ) { 628GObj_AddProc (gobj ,Event_PostThink ,20 ); 629 630GOBJ * hmn = Fighter_GetGObj (0 ); 631FighterData * hmn_data = hmn -> userdata ; 632hmn_pad_index = hmn_data -> pad_index ; 633null_pad_index = (hmn_pad_index + 1 ) %4 ; 634} 635 636static void Exit (GOBJ * menu ) { 637stc_match -> state = 3 ; 638Match_EndVS (); 639} 640 641// Clean up percentages so the total is always 100. 642// The next percentage is modified. 643static void ReboundChances (s16 * chances [],unsigned int chance_count ,int just_changed_option ) { 644if (chance_count == 0 )return ; 645 646int sum = 0 ; 647for (u32 t = 0 ;t < chance_count ;++ t ) 648sum += * chances [t ]; 649 650int delta = 100 - sum ; 651// keep adding/removing from next option chance until all needed change to revert to 100% is applied 652while (delta ) 653 { 654int rebound_option = (just_changed_option + 1 ) %chance_count ; 655 656s16 * opt_val = chances [rebound_option ]; 657int prev_chance = (int )* opt_val ; 658 659int new_chance = prev_chance + delta ; 660if (new_chance < 0 ) { 661* opt_val = 0 ; 662delta = new_chance ; 663 }else if (new_chance > 100 ) { 664* opt_val = 100 ; 665delta = new_chance - 100 ; 666 }else { 667* opt_val = (u16 )new_chance ; 668delta = 0 ; 669 } 670 671just_changed_option = rebound_option ; 672 } 673} 674 675static void ReboundTechChances (EventOption * tech_menu ,int slot_idx_changed ) { 676s16 * chances [4 ]; 677int enabled_slots = 0 ; 678 679for (int i = 0 ;i < 4 ;i ++ ) { 680chances [enabled_slots ]= & tech_menu [i ].val ; 681enabled_slots ++ ; 682 } 683 684ReboundChances (chances ,4 ,slot_idx_changed ); 685} 686 687static void ChangeTechInPlaceChance (GOBJ * menu_gobj ,int _new_val ) {ReboundTechChances (& Options_Chances [OPTCHANCE_TECHINPLACE ],0 ); } 688static void ChangeTechAwayChance (GOBJ * menu_gobj ,int _new_val ) {ReboundTechChances (& Options_Chances [OPTCHANCE_TECHINPLACE ],1 ); } 689static void ChangeTechTowardChance (GOBJ * menu_gobj ,int _new_val ) {ReboundTechChances (& Options_Chances [OPTCHANCE_TECHINPLACE ],2 ); } 690static void ChangeMissTechChance (GOBJ * menu_gobj ,int _new_val ) {ReboundTechChances (& Options_Chances [OPTCHANCE_TECHINPLACE ],3 ); } 691 692static void ChangeStandChance (GOBJ * menu_gobj ,int _new_val ) {ReboundTechChances (& Options_Chances [OPTCHANCE_GETUPSTAND ],0 ); } 693static void ChangeRollAwayChance (GOBJ * menu_gobj ,int _new_val ) {ReboundTechChances (& Options_Chances [OPTCHANCE_GETUPSTAND ],1 ); } 694static void ChangeRollTowardChance (GOBJ * menu_gobj ,int _new_val ) {ReboundTechChances (& Options_Chances [OPTCHANCE_GETUPSTAND ],2 ); } 695static void ChangeGetupAttackChance (GOBJ * menu_gobj ,int _new_val ) {ReboundTechChances (& Options_Chances [OPTCHANCE_GETUPSTAND ],3 ); } 696 697static void DisableHmnControl (void ) { 698GOBJ * hmn = Fighter_GetGObj (0 ); 699FighterData * hmn_data = hmn -> userdata ; 700hmn_data -> pad_index = null_pad_index ; 701} 702 703static void EnableHmnControl (void ) { 704GOBJ * hmn = Fighter_GetGObj (0 ); 705FighterData * hmn_data = hmn -> userdata ; 706hmn_data -> pad_index = hmn_pad_index ; 707} 708 709static void StartMoveCPU (GOBJ * menu ) { 710DisableHmnControl (); 711Reset (); 712Options_Main [OPT_MOVE_CPU ]= Option_FinishMoveCPU ; 713Options_Main [OPT_MOVE_HMN ].disable = true; 714} 715 716static void FinishMoveCPU (GOBJ * menu ) { 717EnableHmnControl (); 718Reset (); 719Options_Main [OPT_MOVE_CPU ]= Option_MoveCPU ; 720Options_Main [OPT_MOVE_HMN ].disable = false; 721} 722 723static void StartMoveHMN (GOBJ * menu ) { 724DisableHmnControl (); 725Reset (); 726Options_Main [OPT_MOVE_HMN ]= Option_FinishMoveHMN ; 727Options_Main [OPT_MOVE_CPU ].disable = true; 728} 729 730static void FinishMoveHMN (GOBJ * menu ) { 731EnableHmnControl (); 732Reset (); 733Options_Main [OPT_MOVE_HMN ]= Option_MoveHMN ; 734Options_Main [OPT_MOVE_CPU ].disable = false; 735}