summaryrefslogtreecommitdiff
path: root/src/enemy/vaatiWrathEye.c
blob: 7f398d4f6e64ce64e79b5b47a791f67d9a6af5d4 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
 * @file vaatiWrathEye.c
 * @ingroup Enemies
 *
 * @brief Vaati Wrath Eye enemy
 */
#include "enemy/vaatiWrath.h"
#include "room.h"
#include "physics.h"
#include "asm.h"

void sub_080485D8(Entity*);
void sub_080485FC(Entity*);
void VaatiWrathEyeAction0(Entity*);
void VaatiWrathEyeAction1(Entity*);
void VaatiWrathEyeAction2(Entity*);
void VaatiWrathEyeAction3(Entity*);
void VaatiWrathEyeAction4(Entity*);
void VaatiWrathEyeAction5(Entity*);
void VaatiWrathEyeAction6(Entity*);
void VaatiWrathEyeAction7(Entity*);
void VaatiWrathEyeAction8(Entity*);
void VaatiWrathEyeAction9(Entity*);

void (*const vaatiWrathEyeActions[])(Entity*) = {
    VaatiWrathEyeAction0, VaatiWrathEyeAction1, VaatiWrathEyeAction2, VaatiWrathEyeAction3, VaatiWrathEyeAction4,
    VaatiWrathEyeAction5, VaatiWrathEyeAction6, VaatiWrathEyeAction7, VaatiWrathEyeAction8, VaatiWrathEyeAction9,
};

const s8 gUnk_080D1D70[] = { 0xee, 0x01, 0xfa, 0x04, 0x06, 0x04, 0x13, 0x01 };

const s8 gUnk_080D1D78[] = { 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xfa, 0xfb, 0xfc, 0xfc, 0xfd, 0xfc,
                             0xfb, 0xfa, 0xf9, 0xfa, 0xfb, 0xfb, 0xfc, 0xfd, 0xfc, 0xfb, 0xfa,
                             0xf9, 0xfa, 0xfa, 0xfb, 0xfc, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9 };

const s8 gUnk_080D1D98[] = { 0xe8, 0x04, 0xf8, 0x08, 0x08, 0x08, 0x18, 0x04 };

void VaatiWrathEye(Entity* this) {
    if (this->parent->next == NULL) {
        DeleteThisEntity();
    }
    vaatiWrathEyeActions[this->action](this);
}

void VaatiWrathEyeAction0(Entity* this) {
    if ((gRoomTransition.field_0x38 & 1) != 0) {
        this->action = 2;
        InitializeAnimation(this, 1);
    } else {
        this->action = 1;
        InitializeAnimation(this, 0);
        SoundReq(SFX_166);
    }
    sub_080485D8(this);
}

void VaatiWrathEyeAction1(Entity* this) {
    sub_080485D8(this);
    GetNextFrame(this);
    if ((this->frame & ANIM_DONE) != 0) {
        this->action = 2;
        InitializeAnimation(this, 1);
    }
}

void VaatiWrathEyeAction2(Entity* this) {
    sub_080485D8(this);
    if ((gRoomTransition.field_0x39 & 3) == 0) {
        this->action = 3;
        COLLISION_ON(this);
        this->speed = 0x80;
    }
}

void VaatiWrathEyeAction3(Entity* this) {
    u32 direction;
    Entity* parent;
    u32 x;
    u32 y;

    const s8* ptr;

    parent = this->parent;
    if (((VaatiWrathEntity*)parent)->unk_79 != 0) {
        sub_080485D8(this);
    } else {
        ptr = &gUnk_080D1D98[this->type * 2];
        x = parent->x.HALF.HI + ptr[0];
        y = parent->y.HALF.HI + ptr[1];
        direction = CalculateDirectionTo(this->x.HALF.HI, this->y.HALF.HI, x, y);
        this->direction = direction;
        LinearMoveUpdate(this);
        this->z.HALF.HI = this->parent->z.HALF.HI;
        if ((this->x.HALF.HI == x) && (this->y.HALF.HI == y)) {
            this->action = 4;
            this->timer = 60;
        }
    }
}

void VaatiWrathEyeAction4(Entity* this) {
    sub_080485FC(this);
    if (this->timer != 0) {
        if (--this->timer == 0) {
            InitializeAnimation(this, 3);
        }
    } else {
        GetNextFrame(this);
        if ((this->frame & ANIM_DONE) != 0) {
            this->action = 5;
            this->timer = 0;
        }
    }
}

void VaatiWrathEyeAction5(Entity* this) {
    if (this->timer != 0) {
        this->action = 6;
        if (this->parent->health >= 0x15) {
            this->timer = 120;
        } else {
            this->timer = 60;
        }
        this->child = NULL;
        InitializeAnimation(this, 5);
        SoundReq(SFX_19B);
    }
    sub_080485FC(this);
}

void VaatiWrathEyeAction6(Entity* this) {
    Entity* pEVar3;

    sub_080485FC(this);
    GetNextFrame(this);
    if (this->timer != 0) {
        if (--this->timer == 0) {
            InitializeAnimation(this, 6);
        }
    } else {
        if (this->frame & ANIM_DONE) {
            this->action = 7;
            this->timer = 120;
            this->subtimer = 0;
        } else {
            if (this->frame & 1) {
                this->frame &= 0xfe;
                pEVar3 = CreateProjectile(V3_TENNIS_BALL_PROJECTILE);
                if (pEVar3 != NULL) {
                    pEVar3->parent = this;
                    this->child = pEVar3;
                    PositionRelative(this, pEVar3, 0, Q_16_16(12.0));
                }
            }
        }
    }
}

void VaatiWrathEyeAction7(Entity* this) {
    sub_080485FC(this);
    GetNextFrame(this);
    if (this->subtimer != 0) {
        this->action = 8;
        this->timer = 60;
        COLLISION_OFF(this);
        this->spriteSettings.draw = 0;
        CreateFx(this, FX_REFLECT2, 0x40);
        ((VaatiWrathEntity*)this->parent)->unk_7b |= 0x10 << this->type;
    } else {
        if (--this->timer != 0) {
            return;
        }
        this->action = 5;
        this->timer = 0;
        ((VaatiWrathEntity*)this->parent)->unk_7b |= 1 << this->type;
    }
}

void VaatiWrathEyeAction8(Entity* this) {
    if (this->parent->action == 0xb) {
        this->timer = 60;
    } else {
        if (--this->timer == 0) {
            this->action = 9;
            COLLISION_ON(this);
            this->spriteSettings.draw = 1;
            InitializeAnimation(this, 0);
            sub_080485FC(this);
            SoundReq(SFX_166);
        }
    }
}

void VaatiWrathEyeAction9(Entity* this) {
    sub_080485FC(this);
    GetNextFrame(this);
    if ((this->frame & ANIM_DONE) != 0) {
        this->action = 4;
        this->timer = 1;
        ((VaatiWrathEntity*)this->parent)->unk_7b =
            (((VaatiWrathEntity*)this->parent)->unk_7b & 0xf) | (1 << this->type);
    }
}

void sub_080485D8(Entity* this) {
    const s8* ptr;

    ptr = &gUnk_080D1D70[this->type * 2];
    sub_0806FA90(this->parent, this, ptr[0], ptr[1]);
}

void sub_080485FC(Entity* this) {
    const s8* ptr;

    ptr = &gUnk_080D1D98[this->type * 2];
    sub_0806FA90(this->parent, this, ptr[0], ptr[1]);
    this->z.HALF.HI = gUnk_080D1D78[this->type * 8 + (((VaatiWrathEntity*)this->parent)->unk_78 >> 4 & 7)];
}