sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

chuckya.inc.c (7431B)


      1 // chuckya.inc.c
      2 
      3 struct UnusedChuckyaData {
      4     u8 unk0;
      5     f32 unk4;
      6     f32 unk8;
      7 };
      8 
      9 struct UnusedChuckyaData sUnusedChuckyaData[] = {
     10     { 2, 0.f,  1.f },
     11     { 2, 10.f, 1.f },
     12     { 2, 20.f, 1.f },
     13     { 2, 20.f, 1.f },
     14     { 8, 10.f, 1.f },
     15 };
     16 
     17 void common_anchor_mario_behavior(f32 sp28, f32 sp2C, s32 sp30) {
     18     switch (o->parentObj->oChuckyaUnk88) {
     19         case 0:
     20             break;
     21 
     22         case 1:
     23             obj_set_gfx_pos_at_obj_pos(gMarioObject, o);
     24             break;
     25 
     26         case 2:
     27             gMarioObject->oInteractStatus |= (INT_STATUS_MARIO_UNK2 + sp30);
     28             gMarioStates[0].forwardVel = sp28;
     29             gMarioStates[0].vel[1] = sp2C;
     30             o->parentObj->oChuckyaUnk88 = 0;
     31             break;
     32 
     33         case 3:
     34             gMarioObject->oInteractStatus |= (INT_STATUS_MARIO_UNK2 | INT_STATUS_MARIO_UNK6);
     35             gMarioStates[0].forwardVel = 10.0f;
     36             gMarioStates[0].vel[1] = 10.0f;
     37             o->parentObj->oChuckyaUnk88 = 0;
     38             break;
     39     }
     40 
     41     o->oMoveAngleYaw = o->parentObj->oMoveAngleYaw;
     42 
     43     if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) {
     44         obj_mark_for_deletion(o);
     45     }
     46 }
     47 
     48 void bhv_chuckya_anchor_mario_loop(void) {
     49     common_anchor_mario_behavior(40.0f, 40.0f, INT_STATUS_MARIO_UNK6);
     50 }
     51 
     52 s32 unknown_chuckya_function(s32 sp20, f32 sp24, f32 sp28, s16 sp2C) {
     53     s32 sp1C = 0;
     54 
     55     if (o->oChuckyaUnkF8 != 4) {
     56         if (sp24 < cur_obj_lateral_dist_from_mario_to_home()) {
     57             if (cur_obj_lateral_dist_to_home() < 200.0f) {
     58                 sp1C = 0;
     59             } else {
     60                 sp1C = 1;
     61                 o->oAngleToMario = cur_obj_angle_to_home();
     62             }
     63         } else if (o->oDistanceToMario > sp28) {
     64             if (gGlobalTimer % sp2C == 0) {
     65                 o->oAngleToMario = obj_angle_to_object(o, gMarioObject);
     66             }
     67             sp1C = 2;
     68         } else {
     69             sp1C = 3;
     70         }
     71 
     72         if (sp20 && update_angle_from_move_flags(&o->oAngleToMario)) {
     73             sp1C = 4;
     74             o->oChuckyaUnkF8 = 4;
     75         }
     76     } else {
     77         sp1C = 4;
     78     }
     79 
     80     return sp1C;
     81 }
     82 
     83 s32 approach_forward_vel(f32 *forwardVel, f32 spC, f32 sp10) {
     84     s32 sp4 = 0;
     85 
     86     if (*forwardVel > spC) {
     87         *forwardVel -= sp10;
     88         if (*forwardVel < spC) {
     89             *forwardVel = spC;
     90         }
     91     } else if (*forwardVel < spC) {
     92         *forwardVel += sp10;
     93         if (*forwardVel > spC) {
     94             *forwardVel = spC;
     95         }
     96     } else {
     97         sp4 = 1;
     98     }
     99 
    100     return sp4;
    101 }
    102 
    103 void chuckya_act_0(void) {
    104     s32 sp3C;
    105     UNUSED u8 filler[16];
    106     s32 sp28;
    107 #ifdef AVOID_UB
    108     sp3C = 0;
    109 #endif
    110 
    111     if (o->oTimer == 0) {
    112         o->oChuckyaUnkFC = 0;
    113     }
    114 
    115     o->oAngleToMario = obj_angle_to_object(o, gMarioObject);
    116 
    117     switch (sp28 = o->oSubAction) {
    118         case 0:
    119             o->oForwardVel = 0.0f;
    120             if (cur_obj_lateral_dist_from_mario_to_home() < 2000.0f) {
    121                 cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x400);
    122                 if (o->oChuckyaUnkFC > 40
    123                     || abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario) < 0x1000) {
    124                     o->oSubAction = 1;
    125                 }
    126             } else {
    127                 o->oSubAction = 3;
    128             }
    129             break;
    130 
    131         case 1:
    132             approach_forward_vel(&o->oForwardVel, 30.0f, 4.0f);
    133             if (abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario) > 0x4000) {
    134                 o->oSubAction = 2;
    135             }
    136             if (cur_obj_lateral_dist_from_mario_to_home() > 2000.0f) {
    137                 o->oSubAction = 3;
    138             }
    139             break;
    140 
    141         case 2:
    142             approach_forward_vel(&o->oForwardVel, 0, 4.0f);
    143             if (o->oChuckyaUnkFC > 48) {
    144                 o->oSubAction = 0;
    145             }
    146             break;
    147 
    148         case 3:
    149             if (cur_obj_lateral_dist_to_home() < 500.0f) {
    150                 o->oForwardVel = 0.0f;
    151             } else {
    152                 approach_forward_vel(&o->oForwardVel, 10.0f, 4.0f);
    153                 o->oAngleToMario = cur_obj_angle_to_home();
    154                 cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x800);
    155             }
    156             if (cur_obj_lateral_dist_from_mario_to_home() < 1900.0f) {
    157                 o->oSubAction = 0;
    158             }
    159             break;
    160     }
    161 
    162     if (o->oSubAction != sp28) {
    163         o->oChuckyaUnkFC = 0;
    164     } else {
    165         o->oChuckyaUnkFC++;
    166     }
    167 
    168     cur_obj_init_animation_with_sound(4);
    169 
    170     if (o->oForwardVel > 1.0f) {
    171         cur_obj_play_sound_1(SOUND_AIR_CHUCKYA_MOVE);
    172     }
    173 
    174     print_debug_bottom_up("fg %d", sp3C);
    175     print_debug_bottom_up("sp %d", o->oForwardVel);
    176 }
    177 
    178 void chuckya_act_1(void) {
    179     if (o->oSubAction == 0) {
    180         if (cur_obj_init_animation_and_check_if_near_end(0)) {
    181             o->oSubAction++;
    182         }
    183         o->oChuckyaUnkFC = random_float() * 30.0f + 10.0f;
    184         o->oChuckyaUnk100 = 0;
    185         o->oForwardVel = 0.0f;
    186     } else {
    187         if (o->oSubAction == 1) {
    188             o->oChuckyaUnk100 += player_performed_grab_escape_action();
    189             print_debug_bottom_up("%d", o->oChuckyaUnk100);
    190             if (o->oChuckyaUnk100 > 10) {
    191                 o->oChuckyaUnk88 = 3;
    192                 o->oAction = 3;
    193                 o->oInteractStatus &= ~INT_STATUS_GRABBED_MARIO;
    194             } else {
    195                 cur_obj_init_animation_with_sound(1);
    196                 o->oMoveAngleYaw += INT_STATUS_GRABBED_MARIO;
    197                 if (o->oChuckyaUnkFC-- < 0
    198                     && (check_if_moving_over_floor(50.0f, 150.0f) || o->oChuckyaUnkFC < -16)) {
    199                     o->oSubAction++;
    200                 }
    201             }
    202         } else {
    203             cur_obj_init_animation_with_sound(3);
    204             if (cur_obj_check_anim_frame(18)) {
    205                 cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN4);
    206                 o->oChuckyaUnk88 = 2;
    207                 o->oAction = 3;
    208                 o->oInteractStatus &= ~INT_STATUS_GRABBED_MARIO;
    209             }
    210         }
    211     }
    212 }
    213 
    214 void chuckya_act_3(void) {
    215     o->oForwardVel = 0.0f;
    216     o->oVelY = 0.0f;
    217     cur_obj_init_animation_with_sound(4);
    218     if (o->oTimer > 100) {
    219         o->oAction = 0;
    220     }
    221 }
    222 
    223 void chuckya_act_2(void) {
    224     if (o->oMoveFlags & (OBJ_MOVE_HIT_WALL | OBJ_MOVE_MASK_IN_WATER | OBJ_MOVE_LANDED)) {
    225         obj_mark_for_deletion(o);
    226         obj_spawn_loot_yellow_coins(o, 5, 20.0f);
    227         spawn_mist_particles_with_sound(SOUND_OBJ_CHUCKYA_DEATH);
    228     }
    229 }
    230 
    231 void (*sChuckyaActions[])(void) = {
    232     chuckya_act_0,
    233     chuckya_act_1,
    234     chuckya_act_2,
    235     chuckya_act_3,
    236 };
    237 
    238 void chuckya_move(void) {
    239     cur_obj_update_floor_and_walls();
    240     cur_obj_call_action_function(sChuckyaActions);
    241     cur_obj_move_standard(-30);
    242     if (o->oInteractStatus & INT_STATUS_GRABBED_MARIO) {
    243         o->oAction = 1;
    244         o->oChuckyaUnk88 = 1;
    245         cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN3);
    246     }
    247 }
    248 
    249 void bhv_chuckya_loop(void) {
    250     f32 sp2C = 20.0f;
    251     f32 sp28 = 50.0f;
    252 
    253     cur_obj_scale(2.0f);
    254     o->oInteractionSubtype |= INT_SUBTYPE_GRABS_MARIO;
    255 
    256     switch (o->oHeldState) {
    257         case HELD_FREE:
    258             chuckya_move();
    259             break;
    260         case HELD_HELD:
    261             cur_obj_unrender_set_action_and_anim(2, 0);
    262             break;
    263         case HELD_THROWN:
    264         case HELD_DROPPED:
    265             cur_obj_get_thrown_or_placed(sp2C, sp28, 2);
    266             break;
    267     }
    268 
    269     o->oInteractStatus = 0;
    270 
    271     print_debug_bottom_up("md %d", o->oAction);
    272 }