summaryrefslogtreecommitdiff
path: root/src/object/mask.c
blob: b6d06206e3908a4dcf26cde4de02f90dba76a22e (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "global.h"
#include "entity.h"
#include "room.h"
#include "random.h"
#include "structures.h"
#include "player.h"
#include "flags.h"
#include "functions.h"

extern void (*MaskActionFuncs[])(Entity*);

extern void sub_08000148(u16, u16, u32);
extern s16 sub_080001DA(u16, u32);
extern u16 sub_080002E0(u16, u32);

extern void sub_0805457C(Entity*, s32);

void Mask(Entity* this) {
    MaskActionFuncs[this->action](this);
}

void sub_080929A4(Entity* this) {
    if (this->type2 & 0xC0) {
        if (CheckFlags(this->field_0x86.HWORD)) {
            s32 field_0x0a;

            switch (this->type2 & 0xC0) {
                case 0x40:
                    field_0x0a = gScreenTransition.field_0xa;

                    switch (field_0x0a) {
                        case 0x44D ... 0x44F:
                        case 0x182:
                            DeleteThisEntity();
                            goto switchEnd;
                    }

                    ClearFlag(this->field_0x86.HWORD);
                    break;
                case 0x80:
                    DeleteThisEntity();
                    break;
            }
        switchEnd:
        }
    }

    this->action = 1;
    this->field_0x20 = 0x18000;

    this->field_0x78.HWORD = ((Random() & 7) << 10) | 0x2000;

    this->field_0xf = this->actionDelay >> 1;
    this->actionDelay = 0;

    this->frameIndex = this->type2 & 0x3f;

    this->field_0x7c.HALF.HI = COORD_TO_TILE(this);
    this->field_0x7c.HALF.LO = sub_080001DA(this->field_0x7c.HALF.HI, 1);

    this->field_0x7a.HWORD = sub_080002E0(this->field_0x7c.HALF.HI, 1);

    SetTile(0x4022, this->field_0x7c.HALF_U.HI, 1);
}

// Probably related to knocking it down
void sub_08092A94(Entity* this) {
    // Check for the first frame of bonking animation
    if (gPlayerEntity.action != 6) {
        return;
    }

    if (gPlayerEntity.animationState != 0) {
        return;
    }

    // Check if link is close enough to the mask
    if (this->y.HALF.HI + 40 < gPlayerEntity.y.HALF.HI) {
        return;
    }

    if (this->x.HALF.HI - gPlayerEntity.x.HALF.HI >= this->field_0xf ||
        this->x.HALF.HI - gPlayerEntity.x.HALF.HI <= -this->field_0xf) {
        return;
    }

    // Presumably, make the mask fall
    SetTile(this->field_0x7c.HALF_U.LO, this->field_0x7c.HALF_U.HI, 1);

    sub_08000148(this->field_0x7a.HWORD, this->field_0x7c.HALF.HI, 1);

    this->action = 2;

    this->height.HALF.HI -= 0x20;
    this->y.HALF.HI += 0x20;

    this->spriteRendering.b3 = 2;
}

// Probably falling down
void sub_08092B0C(Entity* this) {
    if (this->actionDelay == 1) {
        this->action = 3;

        this->actionDelay = 0;
        switch (this->type2 & 0xC0) {
            case 0x80:
                EnqueueSFX(0x72);
            case 0x40:
                SetFlag(this->field_0x86.HWORD);
                break;
        }

        CreateFx(this, 5, 0);

        sub_0805457C(this, 3);
    } else {
        sub_080044EC(this, this->field_0x78.HWORD);

        if (this->height.HALF.HI == 0) {
            this->actionDelay++;
        }
    }
}

void Mask_Delete(Entity* this) {
    DeleteThisEntity();
}