sm64

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

whomp.inc.c (8415B)


      1 // whomp.inc.c
      2 
      3 void whomp_play_sfx_from_pound_animation(void) {
      4     UNUSED s32 animFrame = o->header.gfx.animInfo.animFrame;
      5     s32 playSound = FALSE;
      6 
      7     if (o->oForwardVel < 5.0f) {
      8         playSound = cur_obj_check_anim_frame(0);
      9         playSound |= cur_obj_check_anim_frame(23);
     10     } else {
     11         playSound = cur_obj_check_anim_frame_in_range(0, 3);
     12         playSound |= cur_obj_check_anim_frame_in_range(23, 3);
     13     }
     14 
     15     if (playSound) {
     16         cur_obj_play_sound_2(SOUND_OBJ_POUNDING1);
     17     }
     18 }
     19 
     20 void whomp_init(void) {
     21     cur_obj_init_animation_with_accel_and_sound(0, 1.0f);
     22     cur_obj_set_pos_to_home();
     23 
     24     if (o->oBhvParams2ndByte != WHOMP_BP_SMALL) {
     25         gSecondCameraFocus = o;
     26         cur_obj_scale(2.0f);
     27         if (o->oSubAction == 0) {
     28             if (o->oDistanceToMario < 600.0f) {
     29                 o->oSubAction++;
     30                 seq_player_lower_volume(SEQ_PLAYER_LEVEL, 60, 40);
     31             } else {
     32                 cur_obj_set_pos_to_home();
     33                 o->oHealth = 3;
     34             }
     35         } else if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP,
     36             DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, DIALOG_114)) {
     37             o->oAction = 2;
     38         }
     39     } else if (o->oDistanceToMario < 500.0f) {
     40         o->oAction = 1;
     41     }
     42 
     43     whomp_play_sfx_from_pound_animation();
     44 }
     45 
     46 void whomp_turn(void) {
     47     if (o->oSubAction == 0) {
     48         o->oForwardVel = 0.0f;
     49         cur_obj_init_animation_with_accel_and_sound(0, 1.0f);
     50         if (o->oTimer > 31) {
     51             o->oSubAction++;
     52         } else {
     53             o->oMoveAngleYaw += 0x400;
     54         }
     55     } else {
     56         o->oForwardVel = 3.0f;
     57         if (o->oTimer > 42) {
     58             o->oAction = 1;
     59         }
     60     }
     61 
     62     whomp_play_sfx_from_pound_animation();
     63 }
     64 
     65 void whomp_patrol(void) {
     66     s16 marioAngle = abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw);
     67     f32 distWalked = cur_obj_lateral_dist_to_home();
     68     f32 patrolDist;
     69 
     70     if (gCurrLevelNum == LEVEL_BITS) {
     71         patrolDist = 200.0f;
     72     } else {
     73         patrolDist = 700.0f;
     74     }
     75 
     76     cur_obj_init_animation_with_accel_and_sound(0, 1.0f);
     77     o->oForwardVel = 3.0f;
     78 
     79     if (distWalked > patrolDist) {
     80         o->oAction = 7;
     81     } else if (marioAngle < 0x2000) {
     82         if (o->oDistanceToMario < 1500.0f) {
     83             o->oForwardVel = 9.0f;
     84             cur_obj_init_animation_with_accel_and_sound(0, 3.0f);
     85         }
     86         if (o->oDistanceToMario < 300.0f) {
     87             o->oAction = 3;
     88         }
     89     }
     90 
     91     whomp_play_sfx_from_pound_animation();
     92 }
     93 
     94 void king_whomp_chase(void) {
     95     cur_obj_init_animation_with_accel_and_sound(0, 1.0f);
     96     o->oForwardVel = 3.0f;
     97     cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x200);
     98 
     99     if (o->oTimer > 30) {
    100         s16 marioAngle = abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw);
    101         if (marioAngle < 0x2000) {
    102             if (o->oDistanceToMario < 1500.0f) {
    103                 o->oForwardVel = 9.0f;
    104                 cur_obj_init_animation_with_accel_and_sound(0, 3.0f);
    105             }
    106             if (o->oDistanceToMario < 300.0f) {
    107                 o->oAction = 3;
    108             }
    109         }
    110     }
    111 
    112     whomp_play_sfx_from_pound_animation();
    113 
    114     if (mario_is_far_below_object(1000.0f)) {
    115         o->oAction = 0;
    116         stop_background_music(SEQUENCE_ARGS(4, SEQ_EVENT_BOSS));
    117     }
    118 }
    119 
    120 void whomp_prepare_jump(void) {
    121     o->oForwardVel = 0.0f;
    122     cur_obj_init_animation_with_accel_and_sound(1, 1.0f);
    123     if (cur_obj_check_if_near_animation_end()) {
    124         o->oAction = 4;
    125     }
    126 }
    127 
    128 void whomp_jump(void) {
    129     if (o->oTimer == 0) {
    130         o->oVelY = 40.0f;
    131     }
    132 
    133     if (o->oTimer < 8) {
    134     } else {
    135         o->oAngleVelPitch += 0x100;
    136         o->oFaceAnglePitch += o->oAngleVelPitch;
    137         if (o->oFaceAnglePitch > 0x4000) {
    138             o->oAngleVelPitch = 0;
    139             o->oFaceAnglePitch = 0x4000;
    140             o->oAction = 5;
    141         }
    142     }
    143 }
    144 
    145 void whomp_land(void) {
    146     if (o->oSubAction == 0 && o->oMoveFlags & OBJ_MOVE_LANDED) {
    147         cur_obj_play_sound_2(SOUND_OBJ_WHOMP);
    148         cur_obj_shake_screen(SHAKE_POS_SMALL);
    149         o->oVelY = 0.0f;
    150         o->oSubAction++;
    151     }
    152 
    153     if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) {
    154         o->oAction = 6;
    155     }
    156 }
    157 
    158 void king_whomp_on_ground(void) {
    159     if (o->oSubAction == 0) {
    160         if (cur_obj_is_mario_ground_pounding_platform()) {
    161             Vec3f pos;
    162             o->oHealth--;
    163             cur_obj_play_sound_2(SOUND_OBJ2_WHOMP_SOUND_SHORT);
    164             cur_obj_play_sound_2(SOUND_OBJ_KING_WHOMP_DEATH);
    165             if (o->oHealth == 0) {
    166                 o->oAction = 8;
    167             } else {
    168                 vec3f_copy_2(pos, &o->oPosX);
    169                 vec3f_copy_2(&o->oPosX, &gMarioObject->oPosX);
    170                 spawn_mist_particles_variable(0, 0, 100.0f);
    171                 spawn_triangle_break_particles(20, MODEL_DIRT_ANIMATION, 3.0f, 4);
    172                 cur_obj_shake_screen(SHAKE_POS_SMALL);
    173                 vec3f_copy_2(&o->oPosX, pos);
    174             }
    175             o->oSubAction++;
    176         }
    177         o->oWhompShakeVal = 0;
    178     } else {
    179         if (o->oWhompShakeVal < 10) {
    180             if (o->oWhompShakeVal % 2) {
    181                 o->oPosY += 8.0f;
    182             } else {
    183                 o->oPosY -= 8.0f;
    184             }
    185         } else {
    186             o->oSubAction = 10;
    187         }
    188         o->oWhompShakeVal++;
    189     }
    190 }
    191 
    192 void whomp_on_ground(void) {
    193     if (o->oSubAction == 0) {
    194         if (gMarioObject->platform == o) {
    195             if (cur_obj_is_mario_ground_pounding_platform()) {
    196                 o->oNumLootCoins = 5;
    197                 obj_spawn_loot_yellow_coins(o, 5, 20.0f);
    198                 o->oAction = 8;
    199             } else {
    200                 cur_obj_spawn_loot_coin_at_mario_pos();
    201                 o->oSubAction++;
    202             }
    203         }
    204     } else if (!cur_obj_is_mario_on_platform()) {
    205         o->oSubAction = 0;
    206     }
    207 }
    208 
    209 void whomp_on_ground_general(void) {
    210     if (o->oSubAction != 10) {
    211         o->oForwardVel = 0.0f;
    212         o->oAngleVelPitch = 0;
    213         o->oAngleVelYaw = 0;
    214         o->oAngleVelRoll = 0;
    215 
    216         if (o->oBhvParams2ndByte != WHOMP_BP_SMALL) {
    217             king_whomp_on_ground();
    218         } else {
    219             whomp_on_ground();
    220         }
    221         if (o->oTimer > 100 || (gMarioState->action == ACT_SQUISHED && o->oTimer > 30)) {
    222             o->oSubAction = 10;
    223         }
    224     } else if (o->oFaceAnglePitch > 0) {
    225         o->oAngleVelPitch = -0x200;
    226         o->oFaceAnglePitch += o->oAngleVelPitch;
    227     } else {
    228         o->oAngleVelPitch = 0;
    229         o->oFaceAnglePitch = 0;
    230         if (o->oBhvParams2ndByte != WHOMP_BP_SMALL) {
    231             o->oAction = 2;
    232         } else {
    233             o->oAction = 1;
    234         }
    235     }
    236 }
    237 
    238 void whomp_die(void) {
    239     if (o->oBhvParams2ndByte != WHOMP_BP_SMALL) {
    240         if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP,
    241             DIALOG_FLAG_TEXT_DEFAULT, CUTSCENE_DIALOG, DIALOG_115)) {
    242             obj_set_angle(o, 0, 0, 0);
    243             cur_obj_hide();
    244             cur_obj_become_intangible();
    245             spawn_mist_particles_variable(0, 0, 200.0f);
    246             spawn_triangle_break_particles(20, MODEL_DIRT_ANIMATION, 3.0f, 4);
    247             cur_obj_shake_screen(SHAKE_POS_SMALL);
    248             o->oPosY += 100.0f;
    249             spawn_default_star(180.0f, 3880.0f, 340.0f);
    250             cur_obj_play_sound_2(SOUND_OBJ_KING_WHOMP_DEATH);
    251             o->oAction = 9;
    252         }
    253     } else {
    254         spawn_mist_particles_variable(0, 0, 100.0f);
    255         spawn_triangle_break_particles(20, MODEL_DIRT_ANIMATION, 3.0f, 4);
    256         cur_obj_shake_screen(SHAKE_POS_SMALL);
    257         create_sound_spawner(SOUND_OBJ_THWOMP);
    258         obj_mark_for_deletion(o);
    259     }
    260 }
    261 
    262 void king_whomp_stop_music(void) {
    263     if (o->oTimer == 60) {
    264         stop_background_music(SEQUENCE_ARGS(4, SEQ_EVENT_BOSS));
    265     }
    266 }
    267 
    268 void (*sWhompActions[])(void) = {
    269     whomp_init,
    270     whomp_patrol,
    271     king_whomp_chase,
    272     whomp_prepare_jump,
    273     whomp_jump,
    274     whomp_land,
    275     whomp_on_ground_general,
    276     whomp_turn, whomp_die,
    277     king_whomp_stop_music,
    278 };
    279 
    280 void bhv_whomp_loop(void) {
    281     cur_obj_update_floor_and_walls();
    282     cur_obj_call_action_function(sWhompActions);
    283     cur_obj_move_standard(-20);
    284     if (o->oAction != 9) {
    285         if (o->oBhvParams2ndByte != WHOMP_BP_SMALL) {
    286             cur_obj_hide_if_mario_far_away_y(2000.0f);
    287         } else {
    288             cur_obj_hide_if_mario_far_away_y(1000.0f);
    289         }
    290         load_object_collision_model();
    291     }
    292 }