summaryrefslogtreecommitdiff
path: root/src/object/trapdoor.c
blob: 1704c770809fd52c46a0cf37c68635d83f8740c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
 * @file trapdoor.c
 * @ingroup Objects
 *
 * @brief Trapdoor object
 */
#include "item.h"
#include "object.h"
#include "asm.h"
#include "flags.h"
#include "physics.h"
#include "player.h"

void sub_08099ECC(Entity*);
void Trapdoor_Init(Entity*);
void Trapdoor_Action1(Entity*);
void Trapdoor_Action2(Entity*);
void Trapdoor_Action3(Entity*);
void Trapdoor_Action4(Entity*);
extern void CreateHoleManager(u32);

void Trapdoor(Entity* this) {
    static void (*const Trapdoor_Actions[])(Entity*) = {
        Trapdoor_Init, Trapdoor_Action1, Trapdoor_Action2, Trapdoor_Action3, Trapdoor_Action4,
    };
    Trapdoor_Actions[this->action](this);
}

void Trapdoor_Init(Entity* this) {
    this->collisionLayer = 1;
    this->spriteRendering.b3 = 3;
    this->spritePriority.b0 = 7;
    this->subAction = 0;
    if (GetInventoryValue(ITEM_FLIPPERS)) {
        this->action = 4;
        this->frameIndex = 0;
    } else {
        this->action = 1;
        InitializeAnimation(this, 0);
    }
}

void Trapdoor_Action1(Entity* this) {
    if (CheckLocalFlag(MIZUKAKI_STAIR)) {
        GetNextFrame(this);
        if ((this->frame == 1) && (this->subAction == 0)) {
            this->frame = 0;
            sub_08099ECC(this);
        }
        if (this->frame & ANIM_DONE) {
            this->action = 2;
            InitializeAnimation(this, 1);
        }
    }
}

void Trapdoor_Action2(Entity* this) {
    GetNextFrame(this);
    if (this->frame & ANIM_DONE) {
        this->frame &= ~0x80;
        this->timer++;
        if (this->timer == 3) {
            this->action = 3;
            this->frameIndex = 4;
        }
    }
}

void Trapdoor_Action3(Entity* this) {
    if (EntityInRectRadius(this, &gPlayerEntity.base, 0xc, 0xc)) {
        if (this->subAction == 0) {
            sub_08099ECC(this);
            RequestPriorityDuration(this, 30);
        }
        if (CheckLocalFlag(MIZUKAKI_STAIR_WARP_OK)) {
            CreateHoleManager(0x7);
        }
    }
}

void Trapdoor_Action4(Entity* this) {
}

void sub_08099ECC(Entity* this) {
    this->subAction = 1;
    CopyPosition(this, &gPlayerEntity.base);
    gPlayerState.queued_action = PLAYER_FALL;
    gPlayerState.field_0x38 = 0;
    gPlayerState.flags |= PL_PIT_IS_EXIT;
}