sm64

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

elevator.inc.c (3611B)


      1 // elevator.inc.c
      2 
      3 static s16 sElevatorHeights[] = {
      4       -51,    0, 0,
      5      -461,    0, 0,
      6      -512,    0, 0,
      7     -2611,    0, 0,
      8     -2360,    0, 0,
      9       214,    0, 0,
     10       -50, 1945, 1,
     11 };
     12 
     13 void elevator_starting_shake(void) {
     14     cur_obj_play_sound_2(SOUND_GENERAL_QUIET_POUND1);
     15     cur_obj_shake_screen(SHAKE_POS_SMALL);
     16 }
     17 
     18 void elevator_act_0(void) {
     19     o->oVelY = 0;
     20     if (o->oElevatorUnk100 == 2) {
     21         if (gMarioObject->platform == o) {
     22             if (o->oPosY > o->oElevatorUnkFC) {
     23                 o->oAction = 2;
     24             } else {
     25                 o->oAction = 1;
     26             }
     27         }
     28     } else if (gMarioObject->oPosY > o->oElevatorUnkFC || o->oElevatorUnk100 == 1) {
     29         o->oPosY = o->oElevatorUnkF8;
     30         if (gMarioObject->platform == o) {
     31             o->oAction = 2;
     32         }
     33     } else {
     34         o->oPosY = o->oElevatorUnkF4;
     35         if (gMarioObject->platform == o) {
     36             o->oAction = 1;
     37         }
     38     }
     39 }
     40 
     41 void elevator_act_1(void) {
     42     cur_obj_play_sound_1(SOUND_ENV_ELEVATOR1);
     43     if (o->oTimer == 0 && cur_obj_is_mario_on_platform()) {
     44         elevator_starting_shake();
     45     }
     46     approach_f32_signed(&o->oVelY, 10.0f, 2.0f);
     47     o->oPosY += o->oVelY;
     48     if (o->oPosY > o->oElevatorUnkF8) {
     49         o->oPosY = o->oElevatorUnkF8;
     50         if (o->oElevatorUnk100 == 2 || o->oElevatorUnk100 == 1) {
     51             o->oAction = 3;
     52         } else if (gMarioObject->oPosY < o->oElevatorUnkFC) {
     53             o->oAction = 2;
     54         } else {
     55             o->oAction = 3;
     56         }
     57     }
     58 }
     59 
     60 void elevator_act_2(void) {
     61     cur_obj_play_sound_1(SOUND_ENV_ELEVATOR1);
     62     if (o->oTimer == 0 && cur_obj_is_mario_on_platform()) {
     63         elevator_starting_shake();
     64     }
     65     approach_f32_signed(&o->oVelY, -10.0f, -2.0f);
     66     o->oPosY += o->oVelY;
     67     if (o->oPosY < o->oElevatorUnkF4) {
     68         o->oPosY = o->oElevatorUnkF4;
     69         if (o->oElevatorUnk100 == 1) {
     70             o->oAction = 4;
     71         } else if (o->oElevatorUnk100 == 2) {
     72             o->oAction = 3;
     73         } else if (gMarioObject->oPosY > o->oElevatorUnkFC) {
     74             o->oAction = 1;
     75         } else {
     76             o->oAction = 3;
     77         }
     78     }
     79 }
     80 
     81 void elevator_act_4(void) {
     82     o->oVelY = 0;
     83     if (o->oTimer == 0) {
     84         cur_obj_shake_screen(SHAKE_POS_SMALL);
     85         cur_obj_play_sound_2(SOUND_GENERAL_METAL_POUND);
     86     }
     87     if (!mario_is_in_air_action() && !cur_obj_is_mario_on_platform()) {
     88         o->oAction = 1;
     89     }
     90 }
     91 
     92 void elevator_act_3(void) {
     93     o->oVelY = 0;
     94     if (o->oTimer == 0) {
     95         cur_obj_shake_screen(SHAKE_POS_SMALL);
     96         cur_obj_play_sound_2(SOUND_GENERAL_METAL_POUND);
     97     }
     98     if (!mario_is_in_air_action() && !cur_obj_is_mario_on_platform()) {
     99         o->oAction = 0;
    100     }
    101 }
    102 
    103 void bhv_elevator_init(void) {
    104     s32 sp1C = sElevatorHeights[o->oBhvParams2ndByte * 3 + 2];
    105     if (sp1C == 0) {
    106         o->oElevatorUnkF4 = sElevatorHeights[o->oBhvParams2ndByte * 3];
    107         o->oElevatorUnkF8 = o->oHomeY;
    108         o->oElevatorUnkFC = (o->oElevatorUnkF4 + o->oElevatorUnkF8) / 2;
    109         o->oElevatorUnk100 = cur_obj_has_behavior(bhvRRElevatorPlatform);
    110     } else {
    111         o->oElevatorUnkF4 = sElevatorHeights[o->oBhvParams2ndByte * 3];
    112         o->oElevatorUnkF8 = sElevatorHeights[o->oBhvParams2ndByte * 3 + 1];
    113         o->oElevatorUnkFC = (o->oElevatorUnkF4 + o->oElevatorUnkF8) / 2;
    114         o->oElevatorUnk100 = 2;
    115     }
    116 }
    117 
    118 void (*sElevatorActions[])(void) = {
    119     elevator_act_0,
    120     elevator_act_1,
    121     elevator_act_2,
    122     elevator_act_3,
    123     elevator_act_4,
    124 };
    125 
    126 void bhv_elevator_loop(void) {
    127     cur_obj_call_action_function(sElevatorActions);
    128 }