sm64

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

switch_hidden_objects.inc.c (3772B)


      1 // switch_hidden_objects.inc.c
      2 
      3 struct ObjectHitbox sBreakableBoxHitbox = {
      4     /* interactType:      */ INTERACT_BREAKABLE,
      5     /* downOffset:        */ 20,
      6     /* damageOrCoinValue: */ 0,
      7     /* health:            */ 1,
      8     /* numLootCoins:      */ 0,
      9     /* radius:            */ 150,
     10     /* height:            */ 200,
     11     /* hurtboxRadius:     */ 150,
     12     /* hurtboxHeight:     */ 200,
     13 };
     14 
     15 void breakable_box_init(void) {
     16     o->oHiddenObjectPurpleSwitch = NULL;
     17     o->oAnimState = 1;
     18 
     19     switch (o->oBhvParams2ndByte) {
     20         case BREAKABLE_BOX_BP_NO_COINS:
     21             o->oNumLootCoins = 0;
     22             break;
     23         case BREAKABLE_BOX_BP_3_COINS:
     24             o->oNumLootCoins = 3;
     25             break;
     26         case BREAKABLE_BOX_BP_5_COINS:
     27             o->oNumLootCoins = 5;
     28             break;
     29         case BREAKABLE_BOX_BP_GIANT:
     30             cur_obj_scale(1.5f);
     31             break;
     32     }
     33 }
     34 
     35 void hidden_breakable_box_actions(void) {
     36     struct Object *purpleSwitch;
     37 
     38     obj_set_hitbox(o, &sBreakableBoxHitbox);
     39     cur_obj_set_model(MODEL_BREAKABLE_BOX_SMALL);
     40 
     41     if (o->oAction == HIDDEN_OBJECT_ACT_INACTIVE) {
     42         cur_obj_disable_rendering();
     43         cur_obj_become_intangible();
     44         if (o->oTimer == 0) {
     45             breakable_box_init();
     46         }
     47         if (o->oHiddenObjectPurpleSwitch == NULL) {
     48             o->oHiddenObjectPurpleSwitch =
     49                 cur_obj_nearest_object_with_behavior(bhvFloorSwitchHiddenObjects);
     50         }
     51         if ((purpleSwitch = o->oHiddenObjectPurpleSwitch) != NULL) {
     52             if (purpleSwitch->oAction == PURPLE_SWITCH_ACT_TICKING) {
     53                 o->oAction++;
     54                 cur_obj_enable_rendering();
     55                 cur_obj_unhide();
     56             }
     57         }
     58     } else if (o->oAction == HIDDEN_OBJECT_ACT_ACTIVE) {
     59         cur_obj_become_tangible();
     60         if (cur_obj_wait_then_blink(360, 20)) {
     61             o->oAction = HIDDEN_OBJECT_ACT_INACTIVE;
     62         }
     63         if (cur_obj_was_attacked_or_ground_pounded()) {
     64             spawn_mist_particles();
     65             spawn_triangle_break_particles(30, MODEL_DIRT_ANIMATION, 3.0f, 4);
     66             o->oAction++;
     67             cur_obj_play_sound_2(SOUND_GENERAL_BREAK_BOX);
     68         }
     69         load_object_collision_model();
     70     } else { // HIDDEN_OBJECT_ACT_BROKEN
     71         cur_obj_become_intangible();
     72         cur_obj_disable_rendering();
     73         o->oInteractStatus = 0;
     74         if ((purpleSwitch = o->oHiddenObjectPurpleSwitch) != NULL) {
     75             if (purpleSwitch->oAction == PURPLE_SWITCH_ACT_IDLE) {
     76                 o->oAction = HIDDEN_OBJECT_ACT_INACTIVE;
     77             }
     78         }
     79     }
     80 }
     81 
     82 void hidden_wdw_platform_actions(void) {
     83     struct Object *purpleSwitch;
     84 
     85     obj_set_collision_data(o, wdw_seg7_collision_07018528);
     86 
     87     if (o->oAction == HIDDEN_OBJECT_ACT_INACTIVE) {
     88         cur_obj_disable_rendering();
     89         cur_obj_become_intangible();
     90         if (o->oHiddenObjectPurpleSwitch == NULL) {
     91             o->oHiddenObjectPurpleSwitch =
     92                 cur_obj_nearest_object_with_behavior(bhvFloorSwitchHiddenObjects);
     93         }
     94         if ((purpleSwitch = o->oHiddenObjectPurpleSwitch) != NULL) {
     95             if (purpleSwitch->oAction == PURPLE_SWITCH_ACT_TICKING) {
     96                 o->oAction++;
     97                 cur_obj_enable_rendering();
     98                 cur_obj_unhide();
     99             }
    100         }
    101     } else { // HIDDEN_OBJECT_ACT_ACTIVE
    102         cur_obj_become_tangible();
    103         if (cur_obj_wait_then_blink(360, 20)) {
    104             o->oAction = HIDDEN_OBJECT_ACT_INACTIVE;
    105         }
    106         load_object_collision_model();
    107     }
    108 }
    109 
    110 void bhv_hidden_object_loop(void) {
    111     if (o->oBhvParams2ndByte == HIDDEN_OBJECT_BP_BREAKABLE_BOX) {
    112         hidden_breakable_box_actions();
    113     } else {
    114         hidden_wdw_platform_actions();
    115     }
    116 }