summaryrefslogtreecommitdiff
path: root/src/object/specialFx.c
blob: bfe1a5e50b27630db5cc2d96578702cf5817b54e (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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/**
 * @file specialFx.c
 * @ingroup Objects
 *
 * @brief Special FX object
 */
#include "entity.h"
#include "functions.h"
#include "object.h"

typedef struct {
    Entity base;
    u32 unk_68;
    u8 unk_6c[0x1C];
} SpecialFxObject;

typedef struct {
    u8 unk_00 : 4;
    u8 unk_00_4 : 4;
    u8 unk_01;
    u16 sfx;
} struct_0811F960;

// way more legible like this than if clang-format were to put multiple elements on each line
// clang-format off
const struct_0811F960 gUnk_0811F960[] = {
    {0x1, 0x0, 0x00, SFX_12D},
    {0x0, 0x0, 0x00, SFX_ITEM_BOMB_EXPLODE},
    {0x0, 0x0, 0x00, SFX_124},
    {0x0, 0x1, 0x11, SFX_123},
    {0x0, 0x1, 0x12, SFX_164},
    {0x0, 0x1, 0x13, SFX_10D},
    {0x0, 0x0, 0x00, SFX_FF},
    {0x5, 0x1, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x2, 0x1, 0x00, SFX_WATER_SPLASH},
    {0x2, 0x1, 0x00, SFX_WATER_SPLASH},
    {0x0, 0x0, 0x00, SFX_195},
    {0x0, 0x0, 0x00, SFX_164},
    {0x0, 0x0, 0x00, SFX_10D},
    {0x0, 0x1, 0x00, SFX_METAL_CLINK},
    {0x0, 0x0, 0x00, SFX_BUTTON_PRESS},
    {0x5, 0x0, 0x00, SFX_NONE},
    {0x0, 0x0, 0x10, SFX_123},
    {0x5, 0x1, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_164},
    {0x0, 0x1, 0x14, SFX_1A8},
    {0x0, 0x1, 0x10, SFX_GRAB},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x3, 0x0, 0x00, SFX_197},
    {0x3, 0x0, 0x00, SFX_NONE},
    {0x6, 0x1, 0x00, SFX_METAL_CLINK},
    {0x3, 0x0, 0x00, SFX_METAL_CLINK},
    {0x0, 0x0, 0x00, SFX_METAL_CLINK},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x7, 0x0, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x3, 0x1, 0x00, SFX_NONE},
    {0x8, 0x1, 0x00, SFX_NONE},
    {0x9, 0x1, 0x00, SFX_15F},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x2, 0x1, 0x00, SFX_WATER_SPLASH},
    {0x0, 0x0, 0x00, SFX_METAL_CLINK},
    {0x0, 0x0, 0x00, SFX_164},
    {0xA, 0x1, 0x00, SFX_NONE},
    {0xA, 0x1, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x9, 0x1, 0x00, SFX_15F},
    {0x9, 0x1, 0x00, SFX_15F},
    {0x9, 0x1, 0x00, SFX_15F},
    {0x0, 0x0, 0x00, SFX_NONE},
    {0x2, 0x0, 0x00, SFX_LAVA_TILE_LAND},
    {0x0, 0x1, 0x11, SFX_123},
    {0x0, 0x1, 0x11, SFX_123},
    {0x0, 0x1, 0x11, SFX_123},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_1B4},
    {0x0, 0x1, 0x13, SFX_164},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x10, SFX_GRAB},
    {0x0, 0x1, 0x10, SFX_GRAB},
    {0x0, 0x1, 0x10, SFX_GRAB},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_11D},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x0, 0x00, SFX_164},
    {0x0, 0x0, 0x00, SFX_ITEM_BOMB_EXPLODE},
    {0x0, 0x0, 0x00, SFX_ITEM_BOMB_EXPLODE},
    {0x0, 0x0, 0x00, SFX_ITEM_BOMB_EXPLODE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0xB, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_NONE},
    {0x0, 0x1, 0x00, SFX_ITEM_BOMB_EXPLODE},
    {0x2, 0x1, 0x00, SFX_WATER_SPLASH},
#ifndef EU
    {0x0, 0x0, 0x18, SFX_124},
#else
    {0x0, 0x0, 0x16, SFX_124},
#endif
    {0xC, 0x0, 0x00, SFX_124},
    {0x0, 0x0, 0x00, SFX_ITEM_BOMB_EXPLODE},
    {0xD, 0x1, 0x00, SFX_NONE},
    {0xD, 0x1, 0x00, SFX_NONE},
};
// clang-format on

void SpecialFx(Entity*);
void SpecialFx_Init(SpecialFxObject*);
void SpecialFx_Action1(SpecialFxObject*);
void sub_080845DC(SpecialFxObject*);
void sub_080845F8(SpecialFxObject*);
void sub_08084630(SpecialFxObject*);
void sub_08084680(SpecialFxObject*);
void sub_08084694(SpecialFxObject*);
void sub_080846B0(SpecialFxObject*);
void sub_0808471C(SpecialFxObject*);
void sub_08084770(SpecialFxObject*);
void sub_08084784(SpecialFxObject*);
void sub_08084798(SpecialFxObject*);
void sub_080847BC(SpecialFxObject*);
void sub_080847D0(SpecialFxObject*);
void sub_080847E0(SpecialFxObject*);

void SpecialFx(Entity* this) {
    static void (*const SpecialFx_Actions[])(SpecialFxObject*) = {
        SpecialFx_Init,
        SpecialFx_Action1,
    };
    SpecialFx_Actions[this->action]((SpecialFxObject*)this);
}

void SpecialFx_Init(SpecialFxObject* this) {
    static const u8 gUnk_0811FAC8[] = { 0x03, 0x37, 0x38, 0x39 };
    static const u8 gUnk_0811FACC[] = { 0x17, 0x3e, 0x3f, 0x40 };
    const struct_0811F960* ptr;

    super->action = 1;
    super->flags &= ~0x80;
    super->spriteSettings.draw = 1;
    SetEntityPriority(super, 6);
    if (super->collisionLayer == 0) {
        ResolveCollisionLayer(super);
    }
    if (super->type == 0x20) {
        super->flags |= 0x20;
    }
    if (super->type == 0x3) {
        super->type = gUnk_0811FAC8[Random() & 3];
    }
    if (super->type == 0x17) {
        super->type = gUnk_0811FACC[Random() & 3];
    }
    InitializeAnimation(super, super->type);
    ptr = &gUnk_0811F960[super->type];
    if (ptr->unk_00 == 6) {
        super->speed = 0x40;
    }
    if (ptr->sfx != SFX_NONE && !(super->type2 & 0x40)) {
        EnqueueSFX(ptr->sfx);
    }
    if (super->type2 & 0x80) {
        CreateRandomItemDrop(super, ptr->unk_01);
    }
    if (super->type2 & 0x20) {
        super->spriteRendering.b3 = 1;
    }
}

void SpecialFx_Action1(SpecialFxObject* this) {
    static void (*const gUnk_0811FAD0[])(SpecialFxObject*) = {
        sub_080845DC, sub_080845F8, sub_08084630, sub_08084694, (void (*)(SpecialFxObject*))DeleteEntity,
        sub_08084680, sub_080846B0, sub_0808471C, sub_08084770, sub_08084798,
        sub_080847BC, sub_08084784, sub_080847D0, sub_080847E0,
    };
    gUnk_0811FAD0[gUnk_0811F960[super->type].unk_00](this);
}

void sub_080845DC(SpecialFxObject* this) {
    GetNextFrame(super);
    if (super->frame & ANIM_DONE) {
        DeleteThisEntity();
    }
}

void sub_080845F8(SpecialFxObject* this) {
    if (((8 - (super->x.HALF.HI & 0xF)) | (8 - (super->y.HALF.HI & 0xF))) != 0) {
        super->direction = sub_080045DA((8 - (super->x.HALF.HI & 0xF)), (8 - (super->y.HALF.HI & 0xF))) >> 3;
        LinearMoveUpdate(super);
    }
    sub_08084630(this);
}

void sub_08084630(SpecialFxObject* this) {
    GetNextFrame(super);
    if (super->frame & ANIM_DONE) {
        if ((super->type2 & 1) && (super->child != 0)) {
            ((GenericEntity*)super->child)->field_0x6a.HWORD--;
            if (this->unk_68 != 0) {
                ((GenericEntity*)super->child)->field_0x6c.HWORD &= ~(1 << ((this->unk_68 - 1) & 0x1F));
            }
        }
        DeleteThisEntity();
    }
}

void sub_08084680(SpecialFxObject* this) {
    super->z.WORD += Q_16_16(0.25);
    sub_080845DC(this);
}

void sub_08084694(SpecialFxObject* this) {
    if ((super->parent == NULL) || (super->parent->next == NULL)) {
        DeleteThisEntity();
    }
    GetNextFrame(super);
}

void sub_080846B0(SpecialFxObject* this) {
    s32 tmp;
    if (super->timer != 0) {
        if (super->speed != 0) {
            super->speed -= 0x10;
        }
        LinearMoveUpdate(super);
        sub_080845DC(this);
    } else {
        super->timer = 1;
        if ((super->animationState | 2) == 2) {
            super->direction = 0x1e;
        } else {
            super->direction = 2;
        }
        if (super->subtimer != 0) {
            super->spriteVramOffset++;
            tmp = (super->direction > 0x17 ? -1 : 1);
            super->direction += tmp;
            super->speed = 0x280;
        } else {
            super->speed = 0x300;
        }
    }
}

void sub_0808471C(SpecialFxObject* this) {
    static const s8 gUnk_0811FB08[] = { -8, -8, 8, -8, -8, 8, 8, 8 };

    GetNextFrame(super);
    if (super->frame & ANIM_DONE) {
        u32 i;

        for (i = 0; i < 4; i++) {
            Entity* fx = CreateFx(super, 0x24, 0);

            if (fx != NULL) {
                const s8* ptr = &gUnk_0811FB08[2 * i];
                fx->x.HALF.HI += ptr[0];
                fx->y.HALF.HI += ptr[1];
            }
        }
        DeleteThisEntity();
    }
}

void sub_08084770(SpecialFxObject* this) {
    super->z.WORD -= Q_16_16(0.25);
    sub_080845DC(this);
}

void sub_08084784(SpecialFxObject* this) {
    super->z.WORD += Q_16_16(0.25);
    sub_080845DC(this);
}

void sub_08084798(SpecialFxObject* this) {
    GetNextFrame(super);
    if ((super->frame & ANIM_DONE) || (super->child->next == NULL)) {
        DeleteThisEntity();
    }
}

void sub_080847BC(SpecialFxObject* this) {
    super->z.WORD -= Q_16_16(0.125);
    sub_080845DC(this);
}

void sub_080847D0(SpecialFxObject* this) {
    LinearMoveUpdate(super);
    sub_080845DC(this);
}

void sub_080847E0(SpecialFxObject* this) {
    if (gRoomControls.reload_flags == 1) {
        DeleteThisEntity();
    }
    PositionRelative(&gPlayerEntity.base, super, 0, -0x30000);
    super->z.HALF.HI = -3;
    SortEntityAbove(&gPlayerEntity.base, super);
    sub_080845DC(this);
}