fork/training-mode-ce

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

Alex Harrisonadjust barrel intangibility names and descriptions8a9536d

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