fork/training-mode-ce

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

Alex Harrisonadd barrel to fc event569ae8b

nix
5.9 KiB227 linesraw
1#include "../MexTK/mex.h"
2#include "events.h"
3
4void Exit(GOBJ *menu);
5
6enum options_main {
7    OPT_BARREL,
8    OPT_EXIT,
9
10    OPT_COUNT
11};
12
13static EventOption Options_Main[OPT_COUNT] = {
14    {
15        .kind = OPTKIND_TOGGLE,
16        .name = "Target",
17        .desc = {"Enable a target to attack"},
18    },
19    {
20        .kind = OPTKIND_FUNC,
21        .name = "Exit",
22        .desc = { "Return to the Event Select Screen." },
23        .OnSelect = Exit,
24    },
25};
26
27static EventMenu Menu_Main = {
28    .name = "Float Cancel Training",
29    .option_num = countof(Options_Main),
30    .options = Options_Main,
31};
32
33enum PeachActionStates {
34    ASID_FLOAT = 341,
35    ASID_FLOATENDF,
36    ASID_FLOATENDB,
37    ASID_FLOATATTACKN,
38    ASID_FLOATATTACKF,
39    ASID_FLOATATTACKB,
40    ASID_FLOATATTACKU,
41    ASID_FLOATATTACKD,
42};
43
44enum Action {
45    Action_None,
46    Action_Wait,
47    Action_Float,
48    Action_FloatNeutral,
49    Action_FloatAttack,
50    Action_Hitlag,
51    Action_FloatAttackFall,
52    Action_FloatAttackFastFall,
53    Action_Landing,
54    
55    Action_Count
56};
57static char *action_names[] = {
58    "None",
59    "Wait",
60    "Float",
61    "Deadzone",
62    "Attack",
63    "Hitlag",
64    "Fall",
65    "Fastfall",
66    "Landing",
67};
68
69static u32 action_log_cur;
70static u8 action_log[30];
71
72static GXColor action_colors[Action_Count] = {
73    {40, 40, 40, 180},  // dark gray - none
74    {80, 80, 80, 180},  // light gray - wait
75    {255, 128, 128, 180}, // red - float
76    {230, 22, 198, 180}, // magenta - deadzone
77    {52, 202, 228, 180}, // cyan - attack
78    {70, 40, 60, 180}, // hitlag
79    {128, 128, 255, 180}, // blue - fall
80    {128, 255, 128, 180}, // green - fastfall
81    {220, 220, 70, 180}, // yellow - landing
82};
83
84void GX(GOBJ *gobj, int pass) {
85    // hitbox GX
86    if (pass == 1) {
87        GOBJ *ft = Fighter_GetGObj(0);
88        FighterData *ft_data = ft->userdata;
89        
90        static GXColor diffuse = {255, 0, 0, 100};
91        static GXColor ambient = {255, 255, 255, 255};
92        for (u32 i = 0; i < countof(ft_data->hitbox); ++i) {
93            ftHit *hit = &ft_data->hitbox[i];
94            if (hit->active)
95                Develop_DrawSphere(hit->size, &hit->pos, &hit->pos_prev, &diffuse, &ambient);
96        }
97    }
98    
99    // action log gx
100    if (pass == 2) {
101        event_vars->HUD_DrawActionLogBar(
102            action_log,
103            action_colors,
104            countof(action_log)
105        );
106        
107        // skip none and wait states
108        event_vars->HUD_DrawActionLogKey(
109            &action_names[2],
110            &action_colors[2],
111            countof(action_names) - 2
112        );
113    }
114}
115
116void Exit(GOBJ *menu) {
117    stc_match->state = 3;
118    Match_EndVS();
119}
120
121void Event_Init(GOBJ *menu) {
122    // init display gobj
123    GOBJ *gobj = GObj_Create(0, 0, 0);
124    GObj_AddGXLink(gobj, GX, 5, 0);
125}
126
127// prevent action log from filling until first jump.
128static bool started = false;
129
130static GOBJ *barrel;
131
132void Barrel_Spawn(void) {
133    Vec3 pos = { 0 };
134    SpawnItem spawn = {
135        .it_kind = ITEM_BARREL,
136        .pos = pos,
137        .pos2 = pos,
138        .facing_direction = 1,
139        .is_raycast_below = 1,
140    };
141    barrel = Item_CreateItem2(&spawn);
142}
143
144int Barrel_OnTakeDamage(GOBJ *_) {
145    GOBJ *ft = Fighter_GetGObj(0);
146    FighterData *ft_data = ft->userdata;
147    int state = ft_data->state_id;
148    
149    if (ASID_FLOATATTACKN <= state && state <= ASID_FLOATATTACKD) {
150        ItemData *data = barrel->userdata;
151        Effect_SpawnSync(1063, barrel, &data->pos);
152    }
153    return false;
154}
155void Barrel_OnDestroy(GOBJ *_) {
156    if (Options_Main[OPT_BARREL].val)
157        Barrel_Spawn();
158}
159
160void Event_Think(GOBJ *menu) {
161    // barrel ------------------------------------------------------------------
162    
163    if (Options_Main[OPT_BARREL].val) {
164        if (barrel == 0)
165            Barrel_Spawn();
166        
167        // Some internal functions adjust these in think functions,
168        // so we need to set it every frame.
169        ItemData *data = barrel->userdata;
170        data->it_func->OnTakeDamage = Barrel_OnTakeDamage;
171        data->it_func->OnDestroy = Barrel_OnDestroy;
172        data->can_hold = false;
173    }
174    
175    if (!Options_Main[OPT_BARREL].val && barrel != 0) {
176        GObj_Destroy(barrel);
177        barrel = 0;
178    }
179
180    // action log --------------------------------------------------------------
181    
182    {
183        GOBJ *ft = Fighter_GetGObj(0);
184        FighterData *ft_data = ft->userdata;
185        
186        int state = ft_data->state_id;
187        int is_fastfall = ft_data->flags.is_fastfall;
188        
189        // determine current action
190        int cur_action;
191        bool reset = false;
192        if (ft_data->flags.hitlag) {
193            cur_action = Action_Hitlag;
194        } else if (state == ASID_JUMPF || state == ASID_JUMPB) {
195            started = true;
196            cur_action = Action_None;
197            
198            // reset action log on the final frame of jumpsquat
199            reset = ft_data->TM.state_frame == 2;
200        } else if (state == ASID_FLOAT) {
201            if (ft_data->input.lstick.X == 0.f && ft_data->input.lstick.Y == 0.f)
202                cur_action = Action_FloatNeutral;
203            else
204                cur_action = Action_Float;
205        } else if (state >= ASID_FLOATATTACKN && state <= ASID_FLOATATTACKD) {
206            if (ft_data->phys.self_vel.Y == 0.f)
207                cur_action = Action_FloatAttack;
208            else
209                cur_action = is_fastfall ? Action_FloatAttackFastFall : Action_FloatAttackFall;
210        } else if (state == ASID_LANDING || state == ASID_SQUAT || state == ASID_SQUATWAIT || state == ASID_SQUATRV) {
211            cur_action = Action_Landing;
212        } else {
213            cur_action = Action_Wait;
214        }
215            
216        if (!started) return;
217        
218        if (reset) {
219            memset(action_log, Action_None, sizeof(action_log));
220            action_log_cur = 0;
221        } else if (action_log_cur < countof(action_log)) {
222            action_log[action_log_cur++] = cur_action;
223        }
224    }
225}
226
227EventMenu *Event_Menu = &Menu_Main;