summaryrefslogtreecommitdiff
path: root/src/object/ladderHoleInBookshelf.c
blob: 0082e9d3fb7b3e1312b40c801edb6a73a5bcb51f (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
/**
 * @file ladderHoleInBookshelf.c
 * @ingroup Objects
 *
 * @brief Ladder Hole In Bookshelf object
 */
#include "entity.h"
#include "player.h"

void LadderHoleInBookshelf_Init(Entity* this);
void LadderHoleInBookshelf_Action1(Entity* this);
bool32 sub_08094064(Entity* this);

void LadderHoleInBookshelf(Entity* this) {
    static void (*const LadderHoleInBookshelf_Actions[])(Entity*) = {
        LadderHoleInBookshelf_Init,
        LadderHoleInBookshelf_Action1,
    };

    LadderHoleInBookshelf_Actions[this->action](this);
}

void LadderHoleInBookshelf_Init(Entity* this) {
    this->action = 1;
    this->collisionLayer = 2;
    UpdateSpriteForCollisionLayer(this);
}

void LadderHoleInBookshelf_Action1(Entity* this) {
    if (sub_08094064(this)) {
        if (this->collisionLayer == 2) {
            switch (gPlayerEntity.base.action) {
                case PLAYER_CLIMB:
                case PLAYER_USEENTRANCE:
                    return;
            }
            this->collisionLayer = 1;
            UpdateSpriteForCollisionLayer(this);
            this->spritePriority.b0 = 5;
        } else {
            switch (gPlayerEntity.base.action) {
                case PLAYER_CLIMB:
                case PLAYER_USEENTRANCE:
                    this->collisionLayer = 2;
                    UpdateSpriteForCollisionLayer(this);
                    this->spritePriority.b0 = 1;
                    break;
                default:
                    if ((gPlayerEntity.base.collisionLayer & 2) == 0) {
                        break;
                    }
                    gPlayerEntity.base.collisionLayer = 1;
                    break;
            }
        }
    }
}

bool32 sub_08094064(Entity* this) {
    bool32 rv = 1;
    if (gPlayerEntity.base.x.HALF.HI - this->x.HALF.HI + 0x1cU >= 0x39) {
        rv = 0;
    }

    return rv;
}