sm64

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

mushroom_1up.inc.c (9135B)


      1 // mushroom_1up.inc.c
      2 
      3 void bhv_1up_interact(void) {
      4     UNUSED u8 filler[4];
      5 
      6     if (obj_check_if_collided_with_object(o, gMarioObject) == TRUE) {
      7         play_sound(SOUND_GENERAL_COLLECT_1UP, gGlobalSoundSource);
      8         gMarioState->numLives++;
      9         o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
     10 #if ENABLE_RUMBLE
     11         queue_rumble_data(5, 80);
     12 #endif
     13     }
     14 }
     15 
     16 void bhv_1up_common_init(void) {
     17     o->oMoveAnglePitch = -0x4000;
     18     o->oGravity = 3.0f;
     19     o->oFriction = 1.0f;
     20     o->oBuoyancy = 1.0f;
     21 }
     22 
     23 void bhv_1up_init(void) {
     24     bhv_1up_common_init();
     25     if (o->oBhvParams2ndByte == ONE_UP_BP_BEAT_BITDW_BOWSER) {
     26         if (!(save_file_get_flags() & (SAVE_FLAG_HAVE_KEY_1 | SAVE_FLAG_UNLOCKED_BASEMENT_DOOR))) {
     27             o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
     28         }
     29     } else if (o->oBhvParams2ndByte == ONE_UP_BP_BEAT_BITFS_BOWSER) {
     30         if (!(save_file_get_flags() & (SAVE_FLAG_HAVE_KEY_2 | SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR))) {
     31             o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
     32         }
     33     }
     34 }
     35 
     36 void one_up_loop_in_air(void) {
     37     if (o->oTimer < 5) {
     38         o->oVelY = 40.0f;
     39     } else {
     40         o->oAngleVelPitch = -0x1000;
     41         o->oMoveAnglePitch += o->oAngleVelPitch;
     42         o->oVelY = coss(o->oMoveAnglePitch) * 30.0f + 2.0f;
     43         o->oForwardVel = -sins(o->oMoveAnglePitch) * 30.0f;
     44     }
     45 }
     46 
     47 void pole_1up_move_towards_mario(void) {
     48     f32 sp34 = gMarioObject->header.gfx.pos[0] - o->oPosX;
     49     f32 sp30 = gMarioObject->header.gfx.pos[1] + 120.0f - o->oPosY;
     50     f32 sp2C = gMarioObject->header.gfx.pos[2] - o->oPosZ;
     51     s16 sp2A = atan2s(sqrtf(sqr(sp34) + sqr(sp2C)), sp30);
     52 
     53     obj_turn_toward_object(o, gMarioObject, 16, 0x1000);
     54 
     55     o->oMoveAnglePitch = approach_s16_symmetric(o->oMoveAnglePitch, sp2A, 0x1000);
     56     o->oVelY = sins(o->oMoveAnglePitch) * 30.0f;
     57     o->oForwardVel = coss(o->oMoveAnglePitch) * 30.0f;
     58 
     59     bhv_1up_interact();
     60 }
     61 
     62 void one_up_move_away_from_mario(s16 collisionFlags) {
     63     o->oForwardVel = 8.0f;
     64     o->oMoveAngleYaw = o->oAngleToMario + 0x8000;
     65 
     66     bhv_1up_interact();
     67 
     68     if (collisionFlags & OBJ_COL_FLAG_HIT_WALL) {
     69         o->oAction = 2;
     70     }
     71 
     72     if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 3000)) {
     73         o->oAction = 2;
     74     }
     75 }
     76 
     77 void bhv_1up_walking_loop(void) {
     78     object_step();
     79 
     80     switch (o->oAction) {
     81         case 0:
     82             if (o->oTimer > 17) {
     83                 spawn_object(o, MODEL_NONE, bhvSparkleSpawn);
     84             }
     85 
     86             if (o->oTimer == 0) {
     87                 play_sound(SOUND_GENERAL2_1UP_APPEAR, gGlobalSoundSource);
     88             }
     89 
     90             one_up_loop_in_air();
     91 
     92             if (o->oTimer == 37) {
     93                 cur_obj_become_tangible();
     94                 o->oAction = 1;
     95                 o->oForwardVel = 2.0f;
     96             }
     97             break;
     98 
     99         case 1:
    100             if (o->oTimer > 300) {
    101                 o->oAction = 2;
    102             }
    103 
    104             bhv_1up_interact();
    105             break;
    106 
    107         case 2:
    108             obj_flicker_and_disappear(o, 30);
    109             bhv_1up_interact();
    110             break;
    111     }
    112 
    113     set_object_visibility(o, 3000);
    114 }
    115 
    116 void bhv_1up_running_away_loop(void) {
    117     s16 collisionFlags = object_step();
    118 
    119     switch (o->oAction) {
    120         case 0:
    121             if (o->oTimer > 17) {
    122                 spawn_object(o, MODEL_NONE, bhvSparkleSpawn);
    123             }
    124 
    125             if (o->oTimer == 0) {
    126                 play_sound(SOUND_GENERAL2_1UP_APPEAR, gGlobalSoundSource);
    127             }
    128 
    129             one_up_loop_in_air();
    130 
    131             if (o->oTimer == 37) {
    132                 cur_obj_become_tangible();
    133                 o->oAction = 1;
    134                 o->oForwardVel = 8.0f;
    135             }
    136             break;
    137 
    138         case 1:
    139             spawn_object(o, MODEL_NONE, bhvSparkleSpawn);
    140             one_up_move_away_from_mario(collisionFlags);
    141             break;
    142 
    143         case 2:
    144             obj_flicker_and_disappear(o, 30);
    145             bhv_1up_interact();
    146             break;
    147     }
    148 
    149     set_object_visibility(o, 3000);
    150 }
    151 
    152 void sliding_1up_move(void) {
    153     s16 collisionFlags = object_step();
    154 
    155     if (collisionFlags & OBJ_COL_FLAG_GROUNDED) {
    156         o->oForwardVel += 25.0f;
    157         o->oVelY = 0.0f;
    158     } else {
    159         o->oForwardVel *= 0.98;
    160     }
    161 
    162     if (o->oForwardVel > 40.0) {
    163         o->oForwardVel = 40.0f;
    164     }
    165 
    166     if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 5000)) {
    167         o->oAction = 2;
    168     }
    169 }
    170 
    171 void bhv_1up_sliding_loop(void) {
    172     switch (o->oAction) {
    173         case 0:
    174             set_object_visibility(o, 3000);
    175             if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1000)) {
    176                 o->oAction = 1;
    177             }
    178             break;
    179 
    180         case 1:
    181             sliding_1up_move();
    182             break;
    183 
    184         case 2:
    185             obj_flicker_and_disappear(o, 30);
    186             bhv_1up_interact();
    187             break;
    188     }
    189 
    190     bhv_1up_interact();
    191     spawn_object(o, MODEL_NONE, bhvSparkleSpawn);
    192 }
    193 
    194 void bhv_1up_loop(void) {
    195     bhv_1up_interact();
    196     set_object_visibility(o, 3000);
    197 }
    198 
    199 void bhv_1up_jump_on_approach_loop(void) {
    200     s16 collisionFlags;
    201 
    202     switch (o->oAction) {
    203         case 0:
    204             if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1000)) {
    205                 o->oVelY = 40.0f;
    206                 o->oAction = 1;
    207             }
    208             break;
    209 
    210         case 1:
    211             collisionFlags = object_step();
    212             one_up_move_away_from_mario(collisionFlags);
    213             spawn_object(o, MODEL_NONE, bhvSparkleSpawn);
    214             break;
    215 
    216         case 2:
    217             collisionFlags = object_step();
    218             bhv_1up_interact();
    219             obj_flicker_and_disappear(o, 30);
    220             break;
    221     }
    222 
    223     set_object_visibility(o, 3000);
    224 }
    225 
    226 void bhv_1up_hidden_loop(void) {
    227     s16 collisionFlags;
    228 
    229     switch (o->oAction) {
    230         case 0:
    231             o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE;
    232             if (o->oHidden1UpNumTouchedTriggers == o->oBhvParams2ndByte) {
    233                 o->oVelY = 40.0f;
    234                 o->oAction = 3;
    235                 o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
    236                 play_sound(SOUND_GENERAL2_1UP_APPEAR, gGlobalSoundSource);
    237             }
    238             break;
    239 
    240         case 1:
    241             collisionFlags = object_step();
    242             one_up_move_away_from_mario(collisionFlags);
    243             spawn_object(o, MODEL_NONE, bhvSparkleSpawn);
    244             break;
    245 
    246         case 2:
    247             collisionFlags = object_step();
    248             bhv_1up_interact();
    249             obj_flicker_and_disappear(o, 30);
    250             break;
    251 
    252         case 3:
    253             collisionFlags = object_step();
    254             if (o->oTimer > 17) {
    255                 spawn_object(o, MODEL_NONE, bhvSparkleSpawn);
    256             }
    257 
    258             one_up_loop_in_air();
    259 
    260             if (o->oTimer == 37) {
    261                 cur_obj_become_tangible();
    262                 o->oAction = 1;
    263                 o->oForwardVel = 8.0f;
    264             }
    265             break;
    266     }
    267 }
    268 
    269 void bhv_1up_hidden_trigger_loop(void) {
    270     if (obj_check_if_collided_with_object(o, gMarioObject) == TRUE) {
    271         struct Object *hidden1Up = cur_obj_nearest_object_with_behavior(bhvHidden1Up);
    272         if (hidden1Up != NULL) {
    273             hidden1Up->oHidden1UpNumTouchedTriggers++;
    274         }
    275 
    276         o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
    277     }
    278 }
    279 
    280 void bhv_1up_hidden_in_pole_loop(void) {
    281     UNUSED s16 collisionFlags;
    282 
    283     switch (o->oAction) {
    284         case 0:
    285             o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE;
    286             if (o->oHidden1UpNumTouchedTriggers == o->oBhvParams2ndByte) {
    287                 o->oVelY = 40.0f;
    288                 o->oAction = 3;
    289                 o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
    290                 play_sound(SOUND_GENERAL2_1UP_APPEAR, gGlobalSoundSource);
    291             }
    292             break;
    293 
    294         case 1:
    295             pole_1up_move_towards_mario();
    296             collisionFlags = object_step();
    297             break;
    298 
    299         case 3:
    300             collisionFlags = object_step();
    301             if (o->oTimer > 17) {
    302                 spawn_object(o, MODEL_NONE, bhvSparkleSpawn);
    303             }
    304 
    305             one_up_loop_in_air();
    306 
    307             if (o->oTimer == 37) {
    308                 cur_obj_become_tangible();
    309                 o->oAction = 1;
    310                 o->oForwardVel = 10.0f;
    311             }
    312             break;
    313     }
    314 }
    315 
    316 void bhv_1up_hidden_in_pole_trigger_loop(void) {
    317     if (obj_check_if_collided_with_object(o, gMarioObject) == TRUE) {
    318         struct Object *hidden1Up = cur_obj_nearest_object_with_behavior(bhvHidden1UpInPole);
    319         if (hidden1Up != NULL) {
    320             hidden1Up->oHidden1UpNumTouchedTriggers++;
    321         }
    322 
    323         o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
    324     }
    325 }
    326 
    327 void bhv_1up_hidden_in_pole_spawner_loop(void) {
    328     if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 700)) {
    329         s8 i;
    330         spawn_object_relative(2, 0, 50, 0, o, MODEL_1UP, bhvHidden1UpInPole);
    331         for (i = 0; i <= 1; i++) {
    332             spawn_object_relative(0, 0, i * -200, 0, o, MODEL_NONE, bhvHidden1UpInPoleTrigger);
    333         }
    334 
    335         o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
    336     }
    337 }