fork/training-mode-ce
git clone https://git.julia.blue/fork/training-mode-ce
8a9536d
master
1#include "lcancel.h" 2 3// Main Menu 4enum lcancel_option 5{ 6OPTLC_BARREL , 7OPTLC_BARREL_INTANGIBILITY_RATE , 8OPTLC_HUD , 9OPTLC_TIPS , 10OPTLC_HELP , 11OPTLC_EXIT , 12 13OPTLC_COUNT 14}; 15static const char * LcOptions_Barrel []= {"Off" ,"Stationary" ,"Move" }; 16static const char * LcOptions_Barrel_Intangibility []= {"Off" ,"Rare" ,"Medium" ,"Often" }; 17static EventOption LcOptions_Main [OPTLC_COUNT ]= { 18// Target 19 { 20 .kind = OPTKIND_STRING , 21 .value_num = sizeof (LcOptions_Barrel ) /4 , 22 .name = "Target" , 23 .desc = {"Enable a target to attack. Use DPad down to" , 24"manually move it." }, 25 .values = LcOptions_Barrel , 26 .OnChange = LCancel_ChangeBarrel , 27 }, 28// Target Intangibility 29 { 30 .kind = OPTKIND_STRING , 31 .value_num = sizeof (LcOptions_Barrel_Intangibility ) /4 , 32 .name = "Target Intangibility" , 33 .desc = {"Target cycles intangibility to practice" , 34"L-cancel timing on both hit and whiff" }, 35 .values = LcOptions_Barrel_Intangibility , 36 }, 37// HUD 38 { 39 .kind = OPTKIND_TOGGLE , 40 .val = 1 , 41 .name = "HUD" , 42 .desc = {"Toggle visibility of the HUD." }, 43 .OnChange = LCancel_ChangeShowHUD , 44 }, 45// Tips 46 { 47 .kind = OPTKIND_TOGGLE , 48 .val = 1 , 49 .name = "Tips" , 50 .desc = {"Toggle the onscreen display of tips." }, 51 .OnChange = Tips_Toggle , 52 }, 53// Help 54 { 55 .kind = OPTKIND_INFO , 56 .name = "Help" ,// pointer to a string 57 .desc = {"L-canceling is performed by pressing L, R, or Z up to " , 58"7 frames before landing from a non-special aerial" , 59"attack. This will cut the landing lag in half, allowing " , 60"you to act sooner after attacking." }, 61 }, 62// Exit 63 { 64 .kind = OPTKIND_FUNC , 65 .name = "Exit" , 66 .desc = {"Return to the Event Selection Screen." }, 67 .OnSelect = Event_Exit , 68 }, 69}; 70static EventMenu LabMenu_Main = { 71 .name = "L-Cancel Training" , 72 .option_num = sizeof (LcOptions_Main ) /sizeof (EventOption ), 73 .options = LcOptions_Main , 74}; 75 76// Init Function 77void Event_Init (GOBJ * gobj ) 78{ 79LCancelData * event_data = gobj -> userdata ; 80 81// get l-cancel assets 82event_data -> lcancel_assets = Archive_GetPublicAddress (event_vars -> event_archive ,"lcancel" ); 83 84// create HUD 85LCancel_Init (event_data ); 86 87// initialize barrel intangible timer 88event_data -> barrel_intangible_timer = 0 ; 89 90// set CPU AI to no_act 15 91//cpu_data->cpu.ai = 0; 92} 93// Think Function 94void Event_Think (GOBJ * event ) 95{ 96LCancelData * event_data = event -> userdata ; 97 98// get fighter data 99GOBJ * hmn = Fighter_GetGObj (0 ); 100FighterData * hmn_data = hmn -> userdata ; 101 102// set infinite shields 103hmn_data -> shield .health = 60 ; 104 105LcOptions_Main [OPTLC_BARREL_INTANGIBILITY_RATE ].disable = (LcOptions_Main [OPTLC_BARREL ].val == 0 ) ?1 :0 ; 106 107LCancel_Think (event_data ,hmn_data ); 108Barrel_Think (event_data ); 109} 110void Event_Exit (GOBJ * menu ) 111{ 112// end game 113stc_match -> state = 3 ; 114 115// cleanup 116Match_EndVS (); 117} 118 119// L-Cancel functions 120void LCancel_Init (LCancelData * event_data ) 121{ 122GOBJ * hud_gobj = GObj_Create (0 ,0 ,0 ); 123event_data -> hud .gobj = hud_gobj ; 124// Load jobj 125JOBJ * hud_jobj = JOBJ_LoadJoint (event_data -> lcancel_assets -> hud ); 126GObj_AddObject (hud_gobj ,3 ,hud_jobj ); 127GObj_AddGXLink (hud_gobj ,GXLink_Common ,GXLINK_HUD ,80 ); 128 129// create text canvas 130int canvas = Text_CreateCanvas (2 ,hud_gobj ,14 ,15 ,0 ,GXLINK_HUD ,81 ,19 ); 131event_data -> hud .canvas = canvas ; 132 133// init text 134Text ** text_arr = & event_data -> hud .text_time ; 135for (int i = 0 ;i < 3 ;i ++ ) 136 { 137 138// Create text object 139Text * hud_text = Text_CreateText (2 ,canvas ); 140text_arr [i ]= hud_text ; 141hud_text -> kerning = 1 ; 142hud_text -> align = 1 ; 143hud_text -> use_aspect = 1 ; 144 145// Get position 146Vec3 text_pos ; 147JOBJ * text_jobj ; 148JOBJ_GetChild (hud_jobj ,& text_jobj ,2 + i ,-1 ); 149JOBJ_GetWorldPosition (text_jobj ,0 ,& text_pos ); 150 151// adjust scale 152Vec3 * scale = & hud_jobj -> scale ; 153// text scale 154hud_text -> viewport_scale .X = (scale -> X * 0.01 )* LCLTEXT_SCALE ; 155hud_text -> viewport_scale .Y = (scale -> Y * 0.01 )* LCLTEXT_SCALE ; 156hud_text -> aspect .X = 165 ; 157 158// text position 159hud_text -> trans .X = text_pos .X + (scale -> X /4.0 ); 160hud_text -> trans .Y = (text_pos .Y * -1 )+ (scale -> Y /4.0 ); 161 162// dummy text 163Text_AddSubtext (hud_text ,0 ,0 ,"-" ); 164 } 165 166// save initial arrow position 167JOBJ * arrow_jobj ; 168JOBJ_GetChild (hud_jobj ,& arrow_jobj ,LCLARROW_JOBJ ,-1 ); 169event_data -> hud .arrow_base_x = arrow_jobj -> trans .X ; 170event_data -> hud .arrow_timer = 0 ; 171event_data -> is_current_aerial_counted = false; 172arrow_jobj -> trans .X = 0 ; 173JOBJ_SetFlags (arrow_jobj ,JOBJ_HIDDEN ); 174} 175void LCancel_ChangeBarrel (GOBJ * menu_gobj ,int value ) { 176LcOptions_Main [OPTLC_BARREL_INTANGIBILITY_RATE ].disable = (value == 0 ) ?1 :0 ; 177} 178void LCancel_ChangeShowHUD (GOBJ * menu_gobj ,int show ) { 179HUDCamData * cam = event_vars -> hudcam_gobj -> userdata ; 180cam -> hide = !show ; 181} 182void LCancel_Think (LCancelData * event_data ,FighterData * hmn_data ) 183{ 184 185// run tip logic 186if (LcOptions_Main [OPTLC_TIPS ].val ) 187Tips_Think (event_data ,hmn_data ); 188 189JOBJ * hud_jobj = event_data -> hud .gobj -> hsd_object ; 190 191bool should_update_fastfall_hud = false; 192bool can_fastfall = hmn_data -> phys .self_vel .Y < 0 ; 193 194// log fastfall frame 195int state = hmn_data -> state_id ; 196if (can_fastfall ) 197 { 198// did i fastfall yet? 199if (hmn_data -> flags .is_fastfall ) 200event_data -> is_fastfall = true;// set as fastfall this session 201else 202event_data -> fastfall_frame ++ ;// increment frames 203 } 204 205if (IsAerialLandingState (hmn_data -> state_id )&& hmn_data -> state .frame == 0 ) { 206// Record L input timing on the first frame of aerial landing 207event_data -> current_l_input_timing = hmn_data -> input .timer_trigger_any_ignore_hitlag ; 208 } 209 210bool has_horizontal_velocity = hmn_data -> phys .self_vel .X != 0 ; 211bool is_success_l_input = event_data -> current_l_input_timing < 7 ; 212bool was_previous_state_aerial_landing = IsAerialLandingState (hmn_data -> TM .state_prev [0 ]); 213 214bool is_success_l_cancel = IsAerialLandingState (hmn_data -> state_id )&& is_success_l_input ; 215 216bool is_missed_l_cancel = IsAerialLandingState (hmn_data -> state_id ) 217&& !is_success_l_input 218// If there's no horizontal velocity then it's not possible to edge cancel and a miss is confirmed 219// OR if the number of landing frames has exceeded the number of frames of the l-cancelled animation then it's considered a miss (even if an edge cancel can still occur) 220&& (!has_horizontal_velocity || ((hmn_data -> state .frame + 1 )> (hmn_data -> figatree_curr -> frame_num /2 ))); 221 222bool is_edge_cancel = IsEdgeCancelState (hmn_data -> state_id ) 223&& was_previous_state_aerial_landing ; 224 225if (!event_data -> is_current_aerial_counted && (is_success_l_cancel || is_missed_l_cancel || is_edge_cancel )) 226 { 227event_data -> is_current_aerial_counted = true; 228 229// increment total lcls 230event_data -> hud .lcl_total ++ ; 231 232// determine succession 233bool is_fail = true; 234if (is_success_l_cancel || is_edge_cancel ) 235 { 236is_fail = false; 237event_data -> hud .lcl_success ++ ; 238 } 239event_data -> is_fail = is_fail ;// save l-cancel bool 240 241// Play appropriate sfx 242if (is_fail ) 243SFX_PlayCommon (3 ); 244else 245SFX_PlayRaw (303 ,255 ,128 ,20 ,3 ); 246 247// update timing text 248if (is_edge_cancel ) 249 { 250Text_SetText (event_data -> hud .text_time ,0 ,"EC %df" ,hmn_data -> TM .state_prev_frames [0 ]); 251 } 252else if (event_data -> current_l_input_timing > MAX_L_PRESS_TIMING ) 253 { 254Text_SetText (event_data -> hud .text_time ,0 ,"No Press" ); 255 } 256else 257 { 258Text_SetText (event_data -> hud .text_time ,0 ,"%df/7f" ,event_data -> current_l_input_timing + 1 ); 259 } 260int frame_box_id = min (event_data -> current_l_input_timing ,MAX_L_PRESS_TIMING ); 261 262// update arrow 263JOBJ * arrow_jobj ; 264JOBJ_GetChild (hud_jobj ,& arrow_jobj ,LCLARROW_JOBJ ,-1 ); 265event_data -> hud .arrow_prevpos = arrow_jobj -> trans .X ; 266event_data -> hud .arrow_nextpos = event_data -> hud .arrow_base_x - (frame_box_id * LCLARROW_OFFSET ); 267JOBJ_ClearFlags (arrow_jobj ,JOBJ_HIDDEN ); 268event_data -> hud .arrow_timer = LCLARROW_ANIMFRAMES ; 269 270should_update_fastfall_hud = true; 271 272// Print succession 273int successful = event_data -> hud .lcl_success ; 274float succession = ((float )event_data -> hud .lcl_success / (float )event_data -> hud .lcl_total )* 100.0 ; 275Text_SetText (event_data -> hud .text_scs ,0 ,"%d (%.2f%)" ,successful ,succession ); 276 277// Play HUD anim 278JOBJ_RemoveAnimAll (hud_jobj ); 279JOBJ_AddAnimAll (hud_jobj ,0 ,event_data -> lcancel_assets -> hudmatanim [is_fail ],0 ); 280JOBJ_ReqAnimAll (hud_jobj ,0 ); 281 } 282else if (!IsAerialLandingState (hmn_data -> state_id )&& !IsEdgeCancelState (hmn_data -> state_id )) 283 { 284event_data -> is_current_aerial_counted = false; 285 } 286 287if (IsAutoCancelLanding (hmn_data )) 288 { 289// state as autocancelled 290Text_SetText (event_data -> hud .text_time ,0 ,"Auto-canceled" ); 291 292should_update_fastfall_hud = true; 293 294// Play HUD anim 295JOBJ_RemoveAnimAll (hud_jobj ); 296JOBJ_AddAnimAll (hud_jobj ,0 ,event_data -> lcancel_assets -> hudmatanim [2 ],0 ); 297JOBJ_ReqAnimAll (hud_jobj ,0 ); 298 } 299 300// update arrow animation 301if (event_data -> hud .arrow_timer > 0 ) 302 { 303// decrement timer 304event_data -> hud .arrow_timer -- ; 305 306// get this frames position 307float time = 1 - ((float )event_data -> hud .arrow_timer / (float )LCLARROW_ANIMFRAMES ); 308float xpos = smooth_lerp (time ,event_data -> hud .arrow_prevpos ,event_data -> hud .arrow_nextpos ); 309 310// update position 311JOBJ * arrow_jobj ; 312JOBJ_GetChild (hud_jobj ,& arrow_jobj ,LCLARROW_JOBJ ,-1 );// get timing bar jobj 313arrow_jobj -> trans .X = xpos ; 314JOBJ_SetMtxDirtySub (arrow_jobj ); 315 } 316 317if (should_update_fastfall_hud ) { 318// Print airborne frames 319if (event_data -> is_fastfall ) 320Text_SetText (event_data -> hud .text_air ,0 ,"%df" ,event_data -> fastfall_frame - 1 ); 321else 322Text_SetText (event_data -> hud .text_air ,0 ,"-" ); 323 } 324 325if (!can_fastfall && !IsAerialLandingState (state ))// cant fastfall, reset frames 326 { 327event_data -> fastfall_frame = 0 ; 328event_data -> is_fastfall = false; 329 } 330 331// update HUD anim 332JOBJ_AnimAll (hud_jobj ); 333} 334void LCancel_HUDCamThink (GOBJ * gobj ) 335{ 336 337// if HUD enabled and not paused 338if ((LcOptions_Main [OPTLC_HUD ].val )&& (Pause_CheckStatus (1 )!= 2 )) 339 { 340CObjThink_Common (gobj ); 341 } 342} 343 344// Tips Functions 345void Tips_Toggle (GOBJ * menu_gobj ,int value ) 346{ 347// destroy existing tips when disabling 348if (value == 1 ) 349event_vars -> Tip_Destroy (); 350} 351void Tips_Think (LCancelData * event_data ,FighterData * hmn_data ) 352{ 353 354// shield tip 355if (event_data -> tip .shield_isdisp == 0 )// if not shown 356 { 357// look for a freshly buffered guard off 358if (((hmn_data -> state_id == ASID_GUARDOFF )&& (hmn_data -> TM .state_frame == 0 ))&& // currently in guardoff first frame 359 (hmn_data -> TM .state_prev [0 ]== ASID_GUARD )&& // was just in wait 360 ((hmn_data -> TM .state_prev [3 ] >=ASID_LANDINGAIRN )&& (hmn_data -> TM .state_prev [3 ] <=ASID_LANDINGAIRLW )))// was in aerial landing a few frames ago 361 { 362// increment condition count 363event_data -> tip .shield_num ++ ; 364 365// if condition met X times, show tip 366if (event_data -> tip .shield_num >=3 ) 367 { 368// display tip 369char * shield_string = "Tip:\nDon't hold the trigger! Quickly \npress and release to prevent \nshielding after landing." ; 370if (event_vars -> Tip_Display (5 * 60 ,shield_string )) 371 { 372// set as shown 373//event_data->tip.shield_isdisp = 1; 374event_data -> tip .shield_num = 0 ; 375 } 376 } 377 } 378 } 379 380// hitbox tip 381if (event_data -> tip .hitbox_isdisp == 0 )// if not shown 382 { 383// update hitbox active bool 384if ((hmn_data -> state_id >=ASID_ATTACKAIRN )&& (hmn_data -> state_id <=ASID_ATTACKAIRLW ))// check if currently in aerial attack) // check if in first frame of aerial attack 385 { 386 387// reset hitbox bool on first frame of aerial attack 388if (hmn_data -> TM .state_frame == 0 ) 389event_data -> tip .hitbox_active = 0 ; 390 391// check if hitbox active 392for (u32 i = 0 ;i < countof (hmn_data -> hitbox );i ++ ) 393 { 394if (hmn_data -> hitbox [i ].active != 0 ) 395 { 396event_data -> tip .hitbox_active = 1 ; 397break ; 398 } 399 } 400 } 401 402// update tip conditions 403if ((hmn_data -> state_id >=ASID_LANDINGAIRN )&& (hmn_data -> state_id <=ASID_LANDINGAIRLW )&& (hmn_data -> TM .state_frame == 0 )&& // is in aerial landing 404 (!event_data -> is_fail )&& 405 (event_data -> tip .hitbox_active == 0 ))// succeeded the last aerial landing 406 { 407// increment condition count 408event_data -> tip .hitbox_num ++ ; 409 410// if condition met X times, show tip 411if (event_data -> tip .hitbox_num >=3 ) 412 { 413// display tip 414char * hitbox_string = "Tip:\nDon't land too quickly! Make \nsure you land after the \nattack becomes active." ; 415if (event_vars -> Tip_Display (5 * 60 ,hitbox_string )) 416 { 417 418// set as shown 419//event_data->tip.hitbox_isdisp = 1; 420event_data -> tip .hitbox_num = 0 ; 421 } 422 } 423 } 424 } 425 426// fastfall tip 427if (event_data -> tip .fastfall_isdisp == 0 )// if not shown 428 { 429// update fastfell bool 430if ((hmn_data -> state_id >=ASID_ATTACKAIRN )&& (hmn_data -> state_id <=ASID_ATTACKAIRLW ))// check if currently in aerial attack) // check if in first frame of aerial attack 431 { 432 433// reset hitbox bool on first frame of aerial attack 434if (hmn_data -> TM .state_frame == 0 ) 435event_data -> tip .fastfall_active = 0 ; 436 437// check if fastfalling 438if (hmn_data -> flags .is_fastfall ) 439event_data -> tip .fastfall_active = 1 ; 440 } 441 442// update tip conditions 443if (IsAerialLandingState (hmn_data -> state_id )&& (hmn_data -> TM .state_frame == 0 )&& // is in aerial landing 444 ((event_data -> current_l_input_timing >=7 )&& (event_data -> current_l_input_timing <=15 ))&& // was early for an l-cancel 445 (event_data -> tip .fastfall_active == 0 ))// succeeded the last aerial landing 446 { 447// increment condition count 448event_data -> tip .fastfall_num ++ ; 449 450// if condition met X times, show tip 451if (event_data -> tip .fastfall_num >=3 ) 452 { 453// display tip 454char * fastfall_string = "Tip:\nDon't forget to fastfall!\nIt will let you act sooner \nand help with your \ntiming." ; 455if (event_vars -> Tip_Display (5 * 60 ,fastfall_string )) 456 { 457 458// set as shown 459//event_data->tip.hitbox_isdisp = 1; 460event_data -> tip .fastfall_num = 0 ; 461 } 462 } 463 } 464 } 465 466// late tip 467if (event_data -> tip .late_isdisp == 0 )// if not shown 468 { 469if ((hmn_data -> state_id >=ASID_LANDINGAIRN )&& (hmn_data -> state_id <=ASID_LANDINGAIRLW )&& // is in aerial landing 470 (event_data -> is_fail )&& // failed the l-cancel 471 (hmn_data -> input .down & (HSD_TRIGGER_L |HSD_TRIGGER_R |HSD_TRIGGER_Z )))// was late for an l-cancel by pressing it just now 472 { 473// increment condition count 474event_data -> tip .late_num ++ ; 475 476// if condition met X times, show tip 477if (event_data -> tip .late_num >=3 ) 478 { 479// display tip 480char * late_string = "Tip:\nTry pressing the trigger a\nbit earlier, before the\nfighter lands." ; 481if (event_vars -> Tip_Display (5 * 60 ,late_string )) 482 { 483// set as shown 484//event_data->tip.hitbox_isdisp = 1; 485event_data -> tip .late_num = 0 ; 486 } 487 } 488 } 489 } 490} 491 492// Barrel Functions 493static void UpdateBarrelIntangibility (LCancelData * event_data ,GOBJ * barrel_gobj ) 494{ 495if (LcOptions_Main [OPTLC_BARREL_INTANGIBILITY_RATE ].val != 0 ) 496 { 497int timer_cycle = 120 ; 498event_data -> barrel_intangible_timer ++ ; 499if (event_data -> barrel_intangible_timer >=timer_cycle ) 500event_data -> barrel_intangible_timer = 0 ; 501 502// determine intangibility duration based on option value 503int intangibility_duration ; 504if (LcOptions_Main [OPTLC_BARREL_INTANGIBILITY_RATE ].val == 1 )// rare 505intangibility_duration = 40 ; 506else if (LcOptions_Main [OPTLC_BARREL_INTANGIBILITY_RATE ].val == 2 )// medium 507intangibility_duration = 60 ; 508else if (LcOptions_Main [OPTLC_BARREL_INTANGIBILITY_RATE ].val == 3 )// often 509intangibility_duration = 80 ; 510else 511intangibility_duration = 0 ; 512 513// the timer is lower than intangibility_duration = intangible(2), rest = tangible(0) 514int tangibility = (event_data -> barrel_intangible_timer < intangibility_duration ) ?2 :0 ; 515Item_SetHurtboxTangibility (barrel_gobj ,tangibility ); 516 } 517else 518 { 519Item_SetHurtboxTangibility (barrel_gobj ,0 ); 520 } 521} 522void Barrel_Think (LCancelData * event_data ) 523{ 524GOBJ * barrel_gobj = event_data -> barrel_gobj ; 525 526switch (LcOptions_Main [OPTLC_BARREL ].val ) 527 { 528case (0 ):// off 529 { 530// if spawned, remove 531if (barrel_gobj != 0 ) 532 { 533Item_Destroy (barrel_gobj ); 534event_data -> barrel_gobj = 0 ; 535 } 536 537// reset intangible timer when target is off 538event_data -> barrel_intangible_timer = 0 ; 539 540break ; 541 } 542case (1 ):// stationary 543 { 544// if not spawned, spawn 545if (barrel_gobj == 0 ) 546 { 547// spawn barrel at center stage 548barrel_gobj = Barrel_Spawn (0 ); 549event_data -> barrel_gobj = barrel_gobj ; 550 } 551 552ItemData * barrel_data = barrel_gobj -> userdata ; 553barrel_data -> can_hold = 0 ; 554 555UpdateBarrelIntangibility (event_data ,barrel_gobj ); 556 557// check to move barrel 558// get fighter data 559GOBJ * hmn = Fighter_GetGObj (0 ); 560FighterData * hmn_data = hmn -> userdata ; 561if (hmn_data -> input .down & PAD_BUTTON_DPAD_DOWN ) 562 { 563// ensure player is grounded 564int isGround = 0 ; 565if (hmn_data -> phys .air_state == 0 ) 566 { 567 568// check for ground in front of player 569Vec3 coll_pos ; 570int line_index ; 571int line_kind ; 572Vec3 line_unk ; 573float fromX = (hmn_data -> phys .pos .X )+ (hmn_data -> facing_direction * 16 ); 574float toX = fromX ; 575float fromY = (hmn_data -> phys .pos .Y + 5 ); 576float toY = fromY - 10 ; 577isGround = GrColl_RaycastGround (& coll_pos ,& line_index ,& line_kind ,& line_unk ,-1 ,-1 ,-1 ,0 ,fromX ,fromY ,toX ,toY ,0 ); 578if (isGround == 1 ) 579 { 580 581// update last pos 582event_data -> barrel_lastpos = coll_pos ; 583 584// place barrel here 585barrel_data -> pos = coll_pos ; 586barrel_data -> coll_data .ground_index = line_index ; 587 588// update ECB 589barrel_data -> coll_data .topN_Curr = barrel_data -> pos ;// move current ECB location to new position 590Coll_ECBCurrToPrev (& barrel_data -> coll_data ); 591barrel_data -> cb .coll (barrel_gobj ); 592 593SFX_Play (221 ); 594 } 595else 596 { 597// play SFX 598SFX_PlayCommon (3 ); 599 } 600 } 601 } 602break ; 603 } 604case (2 ):// move 605 { 606// if not spawned, spawn 607if (barrel_gobj == 0 ) 608 { 609// spawn barrel at center stage 610barrel_gobj = Barrel_Spawn (1 ); 611event_data -> barrel_gobj = barrel_gobj ; 612 } 613 614ItemData * barrel_data = barrel_gobj -> userdata ; 615barrel_data -> can_hold = 0 ; 616barrel_data -> can_nudge = 0 ; 617 618UpdateBarrelIntangibility (event_data ,barrel_gobj ); 619 620break ; 621 } 622 } 623} 624GOBJ * Barrel_Spawn (int pos_kind ) 625{ 626 627LCancelData * event_data = event_vars -> event_gobj -> userdata ; 628Vec3 * barrel_lastpos = & event_data -> barrel_lastpos ; 629 630// determine position to spawn 631Vec3 pos ; 632pos .Z = 0 ; 633switch (pos_kind ) 634 { 635case (0 ):// center stage 636 { 637// get position 638int line_index ; 639int line_kind ; 640Vec3 line_angle ; 641float from_x = 0 ; 642float to_x = from_x ; 643float from_y = 6 ; 644float to_y = from_y - 1000 ; 645int is_ground = GrColl_RaycastGround (& pos ,& line_index ,& line_kind ,& line_angle ,-1 ,-1 ,-1 ,0 ,from_x ,from_y ,to_x ,to_y ,0 ); 646if (is_ground == 0 ) 647 gotoBARREL_RANDPOS ; 648break ; 649 } 650case (1 ):// random pos 651 { 652BARREL_RANDPOS : 653 { 654 655// get position 656int line_index ; 657int line_kind ; 658Vec3 line_angle ; 659float from_x = Stage_GetCameraLeft ()+ (HSD_Randi (Stage_GetCameraRight ()- Stage_GetCameraLeft ()))+ HSD_Randf (); 660float to_x = from_x ; 661float from_y = Stage_GetCameraBottom ()+ (HSD_Randi (Stage_GetCameraTop ()- Stage_GetCameraBottom ()))+ HSD_Randf (); 662float to_y = from_y - 1000 ; 663int is_ground = GrColl_RaycastGround (& pos ,& line_index ,& line_kind ,& line_angle ,-1 ,-1 ,-1 ,0 ,from_x ,from_y ,to_x ,to_y ,0 ); 664if (is_ground == 0 ) 665 gotoBARREL_RANDPOS ; 666 667// ensure it isnt too close to the previous 668float distance = Math_Vec3Distance (& pos ,barrel_lastpos ); 669if (distance < 25.f ) 670 gotoBARREL_RANDPOS ; 671 672// ensure left and right have ground 673Vec3 near_pos ; 674float near_fromX = pos .X + 8 ; 675float near_fromY = pos .Y + 4 ; 676to_y = near_fromY - 4 ; 677is_ground = GrColl_RaycastGround (& near_pos ,& line_index ,& line_kind ,& line_angle ,-1 ,-1 ,-1 ,0 ,near_fromX ,near_fromY ,near_fromX ,to_y ,0 ); 678if (is_ground == 0 ) 679 gotoBARREL_RANDPOS ; 680near_fromX = pos .X - 8 ; 681is_ground = GrColl_RaycastGround (& near_pos ,& line_index ,& line_kind ,& line_angle ,-1 ,-1 ,-1 ,0 ,near_fromX ,near_fromY ,near_fromX ,to_y ,0 ); 682if (is_ground == 0 ) 683 gotoBARREL_RANDPOS ; 684 685break ; 686 } 687 } 688 } 689 690// spawn item 691SpawnItem spawnItem ; 692spawnItem .parent_gobj = 0 ; 693spawnItem .parent_gobj2 = 0 ; 694spawnItem .it_kind = ITEM_BARREL ; 695spawnItem .hold_kind = 0 ; 696spawnItem .unk2 = 0 ; 697spawnItem .pos = pos ; 698spawnItem .pos2 = pos ; 699spawnItem .vel .X = 0 ; 700spawnItem .vel .Y = 0 ; 701spawnItem .vel .Z = 0 ; 702spawnItem .facing_direction = 1 ; 703spawnItem .damage = 0 ; 704spawnItem .unk5 = 0 ; 705spawnItem .unk6 = 0 ; 706spawnItem .is_raycast_below = 1 ; 707spawnItem .is_spin = 0 ; 708GOBJ * barrel_gobj = Item_CreateItem2 (& spawnItem ); 709Item_CollAir_Bounce (barrel_gobj ,Barrel_Null ); 710 711static const void * item_callbacks []= { 712 (void * )0x803f58e0 , 713 (void * )0x80287458 , 714Barrel_OnDestroy ,// onDestroy 715 (void * )0x80287e68 , 716 (void * )0x80287ea8 , 717 (void * )0x80287ec8 , 718 (void * )0x80288818 , 719Barrel_OnHurt ,// onhurt 720 (void * )0x802889f8 , 721 (void * )0x802888b8 , 722 (void * )0x00000000 , 723 (void * )0x00000000 , 724 (void * )0x80288958 , 725 (void * )0x80288c68 , 726 (void * )0x803f5988 , 727 }; 728 729// replace collision callback 730ItemData * barrel_data = barrel_gobj -> userdata ; 731memcpy (barrel_data -> it_func ,item_callbacks ,sizeof (item_callbacks )); 732barrel_data -> camera_subject -> kind = 0 ; 733 734// update last barrel pos 735event_data -> barrel_lastpos = pos ; 736 737return barrel_gobj ; 738} 739void Barrel_Null (void ) 740{ 741return ;// Do nothing on purpose 742} 743void Barrel_Break (GOBJ * barrel_gobj ) 744{ 745ItemData * barrel_data = barrel_gobj -> userdata ; 746Effect_SpawnSync (1063 ,barrel_gobj ,& barrel_data -> pos ); 747SFX_Play (251 ); 748ScreenRumble_Execute (2 ,& barrel_data -> pos ); 749JOBJ * barrel_jobj = barrel_gobj -> hsd_object ; 750JOBJ_SetFlagsAll (barrel_jobj ,JOBJ_HIDDEN ); 751barrel_data -> xd0c = 2 ; 752barrel_data -> self_vel .X = 0 ; 753barrel_data -> self_vel .Y = 0 ; 754barrel_data -> item_var .var1 = 1 ; 755barrel_data -> item_var .var2 = 40 ; 756barrel_data -> xdcf3 = 1 ; 757ItemStateChange (barrel_gobj ,7 ,2 ); 758} 759int Barrel_OnHurt (GOBJ * barrel_gobj ) 760{ 761if (LcOptions_Main [OPTLC_BARREL ].val != 2 )// move 762return 0 ; 763 764LCancelData * event_data = event_vars -> event_gobj -> userdata ; 765Barrel_Break (event_data -> barrel_gobj ); 766 767// spawn new barrel at a random position 768barrel_gobj = Barrel_Spawn (1 ); 769event_data -> barrel_gobj = barrel_gobj ; 770 771return 0 ; 772} 773int Barrel_OnDestroy (GOBJ * barrel_gobj ) 774{ 775LCancelData * event_data = event_vars -> event_gobj -> userdata ; 776 777// if this barrel is still the current barrel 778if (barrel_gobj == event_data -> barrel_gobj ) 779event_data -> barrel_gobj = 0 ; 780 781return 0 ; 782} 783 784bool IsAerialLandingState (int state_id ) { 785return ASID_LANDINGAIRN <=state_id && state_id <=ASID_LANDINGAIRLW ; 786} 787 788bool IsEdgeCancelState (int state_id ) { 789return state_id == ASID_FALL || state_id == ASID_OTTOTTO ; 790} 791 792bool IsAutoCancelLanding (FighterData * hmn_data ) { 793return hmn_data -> state_id == ASID_LANDING 794&& hmn_data -> TM .state_frame == 0 // if first frame of landing 795&& hmn_data -> TM .state_prev [0 ] >=ASID_ATTACKAIRN 796&& hmn_data -> TM .state_prev [0 ] <=ASID_ATTACKAIRLW ;// came from aerial attack 797} 798 799// Initial Menu 800EventMenu * Event_Menu = & LabMenu_Main ;