summaryrefslogtreecommitdiff
path: root/src/object/lightableSwitch.c
blob: cbeafdd700cbc5e313725b485810277dfed21c39 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "global.h"
#include "entity.h"
#include "room.h"
#include "flags.h"
#include "functions.h"

extern void sub_0809EB30(Entity*);
extern void sub_0809EAD8(Entity*);
extern void sub_0809EABC(Entity*);
extern void sub_080A2CC0(Entity*, Entity**, u16*);

extern void (*const gUnk_081243B4[])(Entity*);
extern void (*const gUnk_081243BC[])(Entity*);
extern void (*const gUnk_081243C4[])(Entity*);

extern Hitbox gUnk_080FD150;

void LightableSwitch(Entity* this) {
    gUnk_081243B4[this->type](this);
    sub_0809EB30(this);
}

void sub_0809EA1C(Entity* this) {
    gUnk_081243BC[this->action](this);
}

void sub_0809EA34(Entity* this) {
    this->action = 1;
    this->flags = this->flags | 0x80;
    this->frameIndex = 0;
    this->field_0x3c = 7;
    this->field_0x40 = 0x48;
    this->damageType = 0x28;
    this->flags2 = 10;
    this->hitbox = &gUnk_080FD150;
    sub_0809EAD8(this);
    UpdateSpriteForCollisionLayer(this);
    sub_0809EABC(this);
}

void sub_0809EA80(Entity* this) {

    if ((this->bitfield & 0x80) != 0) {
        if (CheckFlags(this->field_0x86.HWORD) != 0) {
            ClearFlag(this->field_0x86.HWORD);
        } else {
            SetFlag(this->field_0x86.HWORD);
        }
        EnqueueSFX(0x110);
    }
    sub_0809EABC(this);
}

void sub_0809EABC(Entity* this) {
    bool32 anySet;
    u32 f;

    f = CheckFlags(this->field_0x86.HWORD);
    anySet = BOOLCAST(f);
    if (this->frameIndex != anySet) {
        this->frameIndex = anySet;
    }
}

void sub_0809EAD8(Entity* this) {
    u8 bVar1;
    Entity* pEVar2;

    if (this->type2 != 0) {

        this->attachedEntity = GetCurrentRoomProperty(this->type2);
        sub_080A2CC0(this, &this->attachedEntity, &this->field_0x74.HWORD);

    } else {
        SetTile(0x4050, COORD_TO_TILE(this), this->collisionLayer);
    }
}

void sub_0809EB30(Entity* this) {
    u16 uVar1;
    u16* puVar2;

    if (this->type2 != 0) {
        if ((this->direction & 0x80) == 0) {
            sub_0806F69C(this);
        }
        puVar2 = &this->field_0x74.HWORD;
        if (!--*puVar2) {
            sub_080A2CC0(this, &this->attachedEntity, puVar2);
        }
    }
}

void sub_0809EB68(Entity* this) {
    gUnk_081243C4[this->action](this);
}

void sub_0809EB80(Entity* this) {

    this->action = 1;
    this->flags = this->flags | 0x80;
    this->frameIndex = 3;
    this->field_0x3c = 7;
    this->field_0x40 = 0x48;
    this->damageType = 0x28;
    this->flags2 = 10;
    this->hitbox = &gUnk_080FD150;
    sub_0809EAD8(this);
    UpdateSpriteForCollisionLayer(this);
    if (CheckFlags(this->cutsceneBeh.HWORD) != 0) {
        this->action = 3;
        this->frameIndex = 2;
    }
}

void sub_0809EBD8(Entity* this) {
    if ((this->bitfield & 0x80) != 0) {
        this->action = 2;
        this->actionDelay = 0x10;
        this->frameIndex = 2;
        SetFlag(this->field_0x86.HWORD);
        EnqueueSFX(0x110);
    }
}

void sub_0809EC08(Entity* this) {

    if (CheckFlags(this->cutsceneBeh.HWORD) != 0) {
        this->action = 3;

    } else {
        if (--this->actionDelay == 0) {
            this->action = 1;
            this->frameIndex = 3;
            ClearFlag(this->field_0x86.HWORD);
            EnqueueSFX(0x110);
        }
    }
}

void nullsub_126(Entity* this) {
}