fork/training-mode-ce

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

Alex Harrisonfix initial facing direction in techchase trainingdeecee7

master
22.4 KiB735 linesraw
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 {
23    OPTINVIS_NONE,
24    OPTINVIS_POST_REACTION,
25    OPTINVIS_FLASH,
26
27    OPTINVIS_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 {
65    OPT_CHANCE_MENU,
66    OPT_REACTION_OSD,
67    OPT_TIMING_OSD,
68    OPT_RESET,
69    OPT_INVIS,
70    OPT_SPEED,
71    OPT_MOVE_CPU,
72    OPT_MOVE_HMN,
73    OPT_EXIT,
74
75    OPT_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    },
117    Option_MoveCPU,
118    Option_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 {
136    OPTCHANCE_TECHINPLACE,
137    OPTCHANCE_TECHAWAY,
138    OPTCHANCE_TECHTOWARD,
139    OPTCHANCE_MISSTECH,
140    OPTCHANCE_GETUPWAIT,
141    OPTCHANCE_GETUPSTAND,
142    OPTCHANCE_GETUPAWAY,
143    OPTCHANCE_GETUPTOWARD,
144    OPTCHANCE_GETUPATTACK,
145
146    OPTCHANCE_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) {
240    FighterData *data = fighter->userdata;
241
242    Vec3 pos = data->phys.pos;
243    data->coll_data.topN_Curr = pos;
244    data->coll_data.topN_CurrCorrect = pos;
245    data->coll_data.topN_Prev = pos;
246    data->coll_data.topN_Proj = pos;
247    data->coll_data.coll_test = *stc_colltest;
248
249    JOBJ *jobj = fighter->hsd_object;
250    jobj->trans = data->phys.pos;
251    JOBJ_SetMtxDirtySub(jobj);
252
253    // Update static hmn block coords
254    Fighter_SetPosition(data->ply, data->flags.ms, &data->phys.pos);
255}
256
257static bool FindGroundNearPlayer(GOBJ *fighter, Vec3 *pos, int *line_idx) {
258    FighterData *data = fighter->userdata;
259    float x = data->phys.pos.X;
260    float y1 = data->phys.pos.Y + 4;
261    float y2 = data->phys.pos.Y - 4;
262
263    Vec3 _line_unk;
264    int _line_kind;
265
266    return 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) {
271    Fighter_UpdateCameraBox(fighter);
272
273    FighterData *data = fighter->userdata;
274    CmSubject *subject = data->camera_subject;
275    subject->boundleft_curr = subject->boundleft_proj;
276    subject->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) {
297    event_vars->Savestate_Load_v1(event_vars->savestate, Savestate_Silent);
298
299    GOBJ *hmn = Fighter_GetGObj(0);
300    GOBJ *cpu = Fighter_GetGObj(1);
301    FighterData *hmn_data = hmn->userdata;
302    FighterData *cpu_data = cpu->userdata;
303
304    hmn_data->facing_direction = hmn_facing_direction;
305    cpu_data->facing_direction = cpu_facing_direction;
306
307    hmn_data->phys.pos = hmn_pos;
308    cpu_data->phys.pos = cpu_pos;
309
310    UpdatePosition(hmn);
311    UpdatePosition(cpu);
312    
313    Vec3 grounded_hmn_pos;
314    int ground_index;
315    if (FindGroundNearPlayer(hmn, &grounded_hmn_pos, &ground_index)) {
316        hmn_data->phys.pos = grounded_hmn_pos;
317        hmn_data->coll_data.ground_index = ground_index;
318        UpdatePosition(hmn);
319        EnvironmentCollision_WaitLanding(hmn);
320        Fighter_SetGrounded(hmn_data);
321        Fighter_EnterWait(hmn);
322    } else {
323        Fighter_EnterFall(hmn);
324    }
325
326    Fighter_EnterDamageFall(cpu);
327
328    UpdateCameraBox(hmn);
329    UpdateCameraBox(cpu);
330
331    Match_CorrectCamera();
332
333    reset_timer = -1;
334    missed_tech_getup_timer = -1;
335    first_action_frame = -1;
336    put_out_hitbox = false;
337}
338
339static int tech_frame_distinguishable[27] = {
340     8, // Mario
341     4, // Fox
342     6, // Captain Falcon
343     9, // Donkey Kong
344     3, // Kirby
345     1, // Bowser
346     6, // Link
347     8, // Sheik
348     8, // Ness
349     3, // Peach
350     9, // Popo (Ice Climbers)
351     9, // Nana (Ice Climbers)
352     7, // Pikachu
353     6, // Samus
354     9, // Yoshi
355     3, // Jigglypuff
356    16, // Mewtwo
357     8, // Luigi
358     7, // Marth
359     6, // Zelda
360     6, // Young Link
361     8, // Dr. Mario
362     4, // Falco
363     8, // Pichu
364     3, // Game & Watch
365     6, // Ganondorf
366     7, // Roy
367};
368
369void Event_Update(GOBJ *menu) {
370    if (Pause_CheckStatus(1) != 2) {
371        float speed = GameSpeeds[Options_Main[OPT_SPEED].val];
372        HSD_SetSpeedEasy(speed);
373    } else {
374        HSD_SetSpeedEasy(1.0);
375    }
376
377}
378
379void MoveFighter(GOBJ *ft, Vec3 *pos, float *facing_direction) {
380    HSD_Pad *pad = PadGetMaster(hmn_pad_index);
381    FighterData *ft_data = ft->userdata;
382    
383    if (pad->down & HSD_BUTTON_A)
384        *facing_direction = -*facing_direction;
385    ft_data->facing_direction = *facing_direction;
386    ft_data->facing_direction_prev = *facing_direction;
387        
388    float x = pad->fstickX;
389    float y = pad->fstickY;
390    float deadzone = 0.2750f;
391    if (fabs(x) < deadzone) x = 0.f;
392    if (fabs(y) < deadzone) y = 0.f;
393    pos->X += x * 1.5f;
394    pos->Y += y * 1.5f;
395    ft_data->phys.pos = *pos;
396    UpdatePosition(ft);
397}
398
399void Event_Think(GOBJ *menu) {
400    if (event_vars->game_timer == 1) {
401        event_vars->Savestate_Save_v1(event_vars->savestate, Savestate_Silent);
402        Reset();
403    }
404
405    HSD_Pad *pad = PadGetMaster(hmn_pad_index);
406    GOBJ *hmn = Fighter_GetGObj(0);
407    GOBJ *cpu = Fighter_GetGObj(1);
408    FighterData *hmn_data = hmn->userdata;
409    FighterData *cpu_data = cpu->userdata;
410    
411    // move CPU
412    if (Options_Main[OPT_MOVE_CPU].name == Option_FinishMoveCPU.name) {
413        MoveFighter(cpu, &cpu_pos, &cpu_facing_direction);
414        Fighter_EnterDamageFall(cpu);
415        return;
416    }
417    
418    // move HMN
419    else if (Options_Main[OPT_MOVE_HMN].name == Option_FinishMoveHMN.name) {
420        MoveFighter(hmn, &hmn_pos, &hmn_facing_direction);
421
422        Vec3 grounded_hmn_pos;
423        int ground_index;
424        if (FindGroundNearPlayer(hmn, &grounded_hmn_pos, &ground_index)) {
425            hmn_data->phys.pos = grounded_hmn_pos;
426            hmn_data->coll_data.ground_index = ground_index;
427        }
428        Fighter_EnterFall(hmn);
429    
430        return;
431    }
432    
433    cpu_data->cpu.ai = 15;
434    cpu_data->cpu.held = 0;
435    cpu_data->cpu.lstickX = 0;
436    cpu_data->cpu.lstickY = 0;
437    cpu_data->cpu.cstickX = 0;
438    cpu_data->cpu.cstickY = 0;
439
440    int state_id = cpu_data->state_id;
441    
442    // cache getup_option_length
443    if (ASID_DOWNSPOTD <= state_id && state_id <= ASID_PASSIVESTANDB)
444        getup_option_length = cpu_data->figatree_curr->frame_num;
445
446    // check for action
447    if (
448        Options_Main[OPT_REACTION_OSD].val
449        && ASID_DOWNSPOTD <= state_id && state_id <= ASID_PASSIVESTANDB
450        && first_action_frame == -1
451    ) {
452        HSD_Pad *engine_pad = PadGetEngine(hmn_data->pad_index);
453        
454        int input = engine_pad->held | engine_pad->stickX | engine_pad->stickY | engine_pad->substickX | engine_pad->substickY;
455        if (input != 0) {
456            first_action_frame = cpu_data->TM.state_frame;
457            int frame_distinguishable = tech_frame_distinguishable[cpu_data->kind];
458
459            event_vars->Message_Display(
460                15, hmn_data->ply, MSGCOLOR_WHITE, 
461                "Reaction: %if\n", first_action_frame - frame_distinguishable
462            );
463        }
464    }
465
466    // set intangibility
467    if (
468        (
469            // make invincible on last frame of getup/tech option
470            ASID_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    ) {
476        cpu_data->hurt.intang_frames.ledge = 1;
477        cpu_data->hurt.kind_game = 1;
478    } else {
479        cpu_data->hurt.intang_frames.ledge = 0;
480        cpu_data->hurt.kind_game = 0;
481    }
482    
483    // Check for late attack and show Timing OSD
484    if (
485        Options_Main[OPT_TIMING_OSD].val
486        && state_id == ASID_WAIT 
487        && hmn_data->flags.hitbox_active
488        && !put_out_hitbox
489    ) { 
490        put_out_hitbox = true;
491        event_vars->Message_Display(
492            16, hmn_data->ply, MSGCOLOR_RED, 
493            "%if Late\n", cpu_data->TM.state_frame
494        );
495    }
496
497    if (reset_timer == -1) {
498        // tech if airborne
499        if (cpu_data->phys.air_state == 1) {
500            cpu_data->input.timer_LR = 0;
501            
502            int rng = HSD_Randi(100);
503            s8 x = 0;
504            char LR = 0;
505            if ((rng -= Options_Chances[OPTCHANCE_TECHINPLACE].val) < 0) {
506
507            } else if ((rng -= Options_Chances[OPTCHANCE_TECHAWAY].val) < 0) {
508                x = 40 * (int)sign(cpu_data->phys.pos.X - hmn_data->phys.pos.X);
509            } else if ((rng -= Options_Chances[OPTCHANCE_TECHTOWARD].val) < 0) {
510                x = 40 * (int)sign(hmn_data->phys.pos.X - cpu_data->phys.pos.X);
511            } else {
512                LR = -1;
513            }
514            cpu_data->cpu.lstickX = x;
515            cpu_data->input.timer_LR = LR;
516        }
517        
518        // missed tech getup
519        if (missed_tech_getup_timer == -1) {
520            if (state_id == ASID_DOWNWAITU || state_id == ASID_DOWNWAITD) {
521                int rng = HSD_Randi(100);
522                if (rng < Options_Chances[OPTCHANCE_GETUPWAIT].val) {
523                    missed_tech_getup_timer = 15;
524                } else {
525                    rng = HSD_Randi(100);
526                    s8 x = 0;
527                    s8 y = 0;
528                    int held = 0;
529                    if ((rng -= Options_Chances[OPTCHANCE_GETUPSTAND].val) < 0) {
530                        y = 127;
531                    } else if ((rng -= Options_Chances[OPTCHANCE_GETUPAWAY].val) < 0) {
532                        x = 40 * (int)sign(cpu_data->phys.pos.X - hmn_data->phys.pos.X);
533                    } else if ((rng -= Options_Chances[OPTCHANCE_GETUPTOWARD].val) < 0) {
534                        x = 40 * (int)sign(hmn_data->phys.pos.X - cpu_data->phys.pos.X);
535                    } else {
536                        held = PAD_BUTTON_A;
537                    }
538                    cpu_data->cpu.lstickX = x;
539                    cpu_data->cpu.lstickY = y;
540                    cpu_data->cpu.held = held;
541                }
542            }
543        } else {
544            missed_tech_getup_timer--;
545        }
546
547        // fail if finished tech 
548        if (state_id == ASID_WAIT) {
549            // SFX_Play(0xAF);
550            reset_timer = ResetDurations[Options_Main[OPT_RESET].val];
551        }
552        // succeed if grabbed or hit 
553        else 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
559            if (Options_Main[OPT_TIMING_OSD].val && !put_out_hitbox) { 
560                put_out_hitbox = true;
561                
562                int frames_taken = -1;
563                int prev_state_id = -1;
564                for (int i = 0; i < 6; ++i) {
565                    prev_state_id = cpu_data->TM.state_prev[i];
566                    if (ASID_DOWNSPOTD <= prev_state_id && prev_state_id <= ASID_PASSIVESTANDB) {
567                        frames_taken = cpu_data->TM.state_prev_frames[i];
568                        break;
569                    }
570                }
571
572                if (prev_state_id != -1) {
573                    event_vars->Message_Display(
574                        16, hmn_data->ply, MSGCOLOR_GREEN, 
575                        "%if Early\n", getup_option_length - frames_taken - 2
576                    );
577                }
578            }
579        
580            SFX_Play(0xAD);
581            reset_timer = ResetDurations[Options_Main[OPT_RESET].val];
582        }
583    }
584
585    if (pad->down & HSD_BUTTON_DPAD_LEFT)
586        Reset();
587
588    if (reset_timer >= 0 && reset_timer-- == 0)
589        Reset();
590}
591
592static void Event_PostThink(GOBJ *menu) {
593    GOBJ *cpu = Fighter_GetGObj(1);
594    FighterData *cpu_data = cpu->userdata;
595    int state_id = cpu_data->state_id;
596
597    int frame_distinguishable = tech_frame_distinguishable[cpu_data->kind];
598    switch (Options_Main[OPT_INVIS].val) {
599        case OPTINVIS_NONE: {
600            cpu_data->flags.invisible = false;
601        } break;
602        case OPTINVIS_POST_REACTION: {
603            bool post_reaction =
604                ASID_PASSIVE <= state_id && state_id <= ASID_PASSIVESTANDB
605                && frame_distinguishable < cpu_data->TM.state_frame && cpu_data->TM.state_frame < 20;
606            cpu_data->flags.invisible = post_reaction;
607        } break;
608        case OPTINVIS_FLASH: {
609            bool on_reaction = (
610                    ASID_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;
615            cpu_data->flags.invisible = on_reaction;
616        } break;
617    }
618
619    memset(&cpu_data->color[1], 0, sizeof(ColorOverlay));
620    memset(&cpu_data->color[0], 0, sizeof(ColorOverlay));
621    if (state_id == ASID_WAIT) {
622        cpu_data->color[1].hex = (GXColor) {0xF0, 0xF0, 0xF0, 0xA0};
623        cpu_data->color[1].color_enable = 1;
624    }
625}
626
627void Event_Init(GOBJ *gobj) {
628    GObj_AddProc(gobj, Event_PostThink, 20);
629    
630    GOBJ *hmn = Fighter_GetGObj(0);
631    FighterData *hmn_data = hmn->userdata;
632    hmn_pad_index = hmn_data->pad_index;
633    null_pad_index = (hmn_pad_index + 1) % 4;
634}
635
636static void Exit(GOBJ *menu) {
637    stc_match->state = 3;
638    Match_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) {
644    if (chance_count == 0) return;
645
646    int sum = 0;
647    for (u32 t = 0; t < chance_count; ++t)
648        sum += *chances[t];
649
650    int delta = 100 - sum;
651    // keep adding/removing from next option chance until all needed change to revert to 100% is applied
652    while (delta)
653    {
654        int rebound_option = (just_changed_option + 1) % chance_count;
655
656        s16 *opt_val = chances[rebound_option];
657        int prev_chance = (int)*opt_val;
658
659        int new_chance = prev_chance + delta;
660        if (new_chance < 0) {
661            *opt_val = 0;
662            delta = new_chance;
663        } else if (new_chance > 100) {
664            *opt_val = 100;
665            delta = new_chance - 100;
666        } else {
667            *opt_val = (u16)new_chance;
668            delta = 0;
669        }
670
671        just_changed_option = rebound_option;
672    }
673}
674
675static void ReboundTechChances(EventOption *tech_menu, int slot_idx_changed) {
676    s16 *chances[4];
677    int enabled_slots = 0;
678
679    for (int i = 0; i < 4; i++) {
680        chances[enabled_slots] = &tech_menu[i].val;
681        enabled_slots++;
682    }
683
684    ReboundChances(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) {
698    GOBJ *hmn = Fighter_GetGObj(0);
699    FighterData *hmn_data = hmn->userdata;
700    hmn_data->pad_index = null_pad_index;
701}
702
703static void EnableHmnControl(void) {
704    GOBJ *hmn = Fighter_GetGObj(0);
705    FighterData *hmn_data = hmn->userdata;
706    hmn_data->pad_index = hmn_pad_index;
707}
708
709static void StartMoveCPU(GOBJ *menu) {
710    DisableHmnControl();
711    Reset();
712    Options_Main[OPT_MOVE_CPU] = Option_FinishMoveCPU; 
713    Options_Main[OPT_MOVE_HMN].disable = true;
714}
715
716static void FinishMoveCPU(GOBJ *menu) {
717    EnableHmnControl();
718    Reset();
719    Options_Main[OPT_MOVE_CPU] = Option_MoveCPU; 
720    Options_Main[OPT_MOVE_HMN].disable = false;
721}
722
723static void StartMoveHMN(GOBJ *menu) {
724    DisableHmnControl();
725    Reset();
726    Options_Main[OPT_MOVE_HMN] = Option_FinishMoveHMN; 
727    Options_Main[OPT_MOVE_CPU].disable = true;
728}
729
730static void FinishMoveHMN(GOBJ *menu) {
731    EnableHmnControl();
732    Reset();
733    Options_Main[OPT_MOVE_HMN] = Option_MoveHMN; 
734    Options_Main[OPT_MOVE_CPU].disable = false;
735}