summaryrefslogtreecommitdiff
path: root/src/object/object49.c
blob: b281815211d0f9b0a7469ef17557d1377592c9af (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
#include "global.h"
#include "entity.h"
#include "functions.h"
#include "position.h"
#include "random.h"
#include "structures.h"

static void sub_0808F2B0(Entity*);
static void sub_0808F14C(Entity*);
static void sub_0808F244(Entity*);

extern void sub_0806FCF4(Entity*, u32, u32, u32);
extern void sub_0808F5EC(Entity*);
extern bool32 sub_0806F3E4(Entity*);

extern void (*const gUnk_08121E5C[])(Entity*);
extern void (*const gUnk_08121E88[])(Entity*);
extern void (*const gUnk_08121E98[])(Entity*);
extern const u16 gUnk_08121EA0[];

void Object49(Entity* this) {
    gUnk_08121E5C[this->entityType.form](this);
}

void sub_0808F0B8(Entity* this) {
    gUnk_08121E88[this->action](this);
}

void sub_0808F0D0(Entity* this) {
    u32 offsetX;
    u32 offsetY;
    Entity* ent;
    u32 uVar3;

    ent = CreateObjectWithParent(this, 0x49, 2, 0);
    this->attachedEntity = ent;
    if (ent == NULL) {
        DeleteThisEntity();
    }
    this->action = 1;
    this->height.HALF.HI = -0xc0;
    offsetX = Random() % 64;
    if ((Random() & 1) != 0) {
        offsetX = -offsetX;
    }
    this->x.HALF.HI = this->parent->x.HALF.HI + offsetX;
    offsetY = Random() % 32;
    if ((Random() & 1) != 0) {
        offsetY = -offsetY;
    }
    this->y.HALF.HI = this->parent->y.HALF.HI + offsetY;
    *(u32*)&this->field_0x74 = 0x240;
    *(u32*)&this->field_0x78 = 0x140;
    InitializeAnimation(this, 3);
    sub_0808F14C(this);
}

static void sub_0808F14C(Entity* this) {
    sub_0808F2B0(this);
    if (sub_08003FC4(this, 0x2000) == 0) {
        this->action++;
        PlaySFX(0x84);
    }
}

void sub_0808F170(Entity* this) {
    *(u32*)&this->field_0x74 -= 0x20;
    *(u32*)&this->field_0x78 += 0x20;
    sub_0806FCF4(this, *(u32*)&this->field_0x78, 8, 2);
    if (*(u32*)&this->field_0x78 > 0x1ff) {
        this->action++;
    }
    sub_0808F2B0(this);
}

void sub_0808F1A4(Entity* this) {
    *(u32*)&this->field_0x78 += 0x10;
    *(u32*)&this->field_0x74 += 0x10;
    sub_0806FCF4(this, *(u32*)&this->field_0x78, 8, 2);
    if (*(u32*)&this->field_0x78 > 0x3ff) {
        this->attachedEntity->action = 0xff;
        DeleteThisEntity();
    } else {
        sub_0808F2B0(this);
    }
}

void sub_0808F1E0(Entity* this) {
    gUnk_08121E98[this->action](this);
}

void sub_0808F1F8(Entity* this) {
    u8 bVar1;

    this->spriteRendering.b0 = 3;
    this->action++;
    this->spriteRendering.b3 = this->parent->spriteRendering.b3;
    this->spriteOrientation.flipY = this->parent->spriteOrientation.flipY;
    this->spritePriority.b0 = 7;
    InitializeAnimation(this, 1);
    sub_0808F244(this);
}

static void sub_0808F244(Entity* this) {

    this->spriteSettings.b.draw = this->parent->spriteSettings.b.draw;
    this->y.HALF.HI = this->parent->y.HALF.HI + 3;
    this->x.HALF.HI = (*(s8*)&this->attachedEntity->spriteOffsetX + this->attachedEntity->x.HALF.HI);
    this->height.WORD = 0;
    *(u32*)&this->field_0x74 = 0x80 - this->parent->height.HALF.HI;
    *(u32*)&this->field_0x78 = 0x100 - this->parent->height.HALF.HI;
    *(u32*)&this->field_0x70.WORD = *((u8*)&this->parent->field_0x7c + 3);
    sub_0808F2B0(this);
    if ((this->parent->field_0x6c.HALF.HI & 2) != 0) {
        DeleteThisEntity();
    }
}

static void sub_0808F2B0(Entity* this) {
    sub_0805EC9C(this, *(u32*)&this->field_0x74, *(u32*)&this->field_0x78, this->field_0x70.WORD);
}

void sub_0808F2C0(Entity* this) {
    if (this->action == 0) {
        this->action++;
        this->spriteRendering.b3 = this->parent->spriteRendering.b3;
        this->spriteOrientation.flipY = this->parent->spriteOrientation.flipY;
        this->spriteSettings.b.draw = 1;
        this->spritePriority.b0 = 7;
        this->height.WORD = 0;

        this->y.HALF.HI = this->parent->y.HALF.HI + 3;
        this->x.HALF.HI = this->parent->x.HALF.HI;
        InitializeAnimation(this, 3);
    }
    if (this->parent->height.HALF.HI == 0) {
        *(u32*)&this->field_0x74 = *(u32*)&this->parent->field_0x74;
        *(u32*)&this->field_0x78 = *(u32*)&this->parent->field_0x78;
    } else {
        *(u32*)&this->field_0x74 = 0x200 - this->parent->height.HALF.HI;
        *(u32*)&this->field_0x78 = this->parent->height.HALF.HI * -2 + 0x300;
    }
    *(u32*)&this->field_0x70 = 0;
    sub_0808F2B0(this);
    sub_0806FCF4(this, *(u32*)&this->field_0x78, 8, 2);
    if (this->action == 0xff) {
        DeleteThisEntity();
    }
}

void sub_0808F370(Entity* this) {
    if (this->action == 0) {
        if (this->parent->previousActionFlag == 1) {
            this->action = 1;
            this->field_0x70.WORD = 0;
            sub_0808F5EC(this);
        }
    } else {
        u8 flag = this->parent->previousActionFlag - 1;
        if (flag < 5) {
            if (this->field_0x70.WORD == 0) {
                if (--(*(u32*)&this->field_0x74) == -1) {
                    this->field_0x70.WORD = gUnk_08121EA0[Random() & 1];
                }
            } else {
                if (--this->field_0x70.WORD == 0) {
                    sub_0808F5EC(this);
                }
            }
        } else {
            this->action = 0;
            *(u32*)&this->field_0x74 = 0;
        }
    }
}

void sub_0808F3DC(Entity* this) {
    if (this->action == 0) {
        this->spriteSettings.b.draw = 1;
        this->action = 1;
        this->actionDelay = 120;
        InitializeAnimation(this, this->entityType.form + 1);
        // TODO: This block of code might supposed to be a switch statement.
        if (this->entityType.form != 8) {
            if (this->entityType.form == 7) {
                sub_0806FAD8(this->attachedEntity, this);
                return;
            }
        } else {
            this->damageType = this->attachedEntity->damageType;
            this->attachedEntity->damageType = 0x7E;
        }
        ResolveEntityOnTop(this->attachedEntity, this);
    } else {
        if (*(u32*)&this->parent->field_0x74 == 0) {
            if (this->entityType.form == 8) {
                this->attachedEntity->damageType = this->damageType;
            }
            DeleteThisEntity();
        }

        if (this->entityType.form == 5 && this->frames.b.f0) {
            Entity* entity = CreateObjectWithParent(this->attachedEntity, 0x49, 8, 0);
            if (entity) {
                entity->parent = this->parent;
                entity->attachedEntity = this->parent->parent;
            }
        }

        GetNextFrame(this);
        CopyPositionAndSpriteOffset(this->attachedEntity, this);
    }
}

void sub_0808F498(Entity* this) {
    u32 var0;

    if (this->action != 0) {
        if (sub_0806F3E4(this)) {
            if (gScreenTransition.frameCount % 16 == 0) {
                PlaySFX(0xEF);
            }
            DeleteThisEntity();
        }

        if (--this->actionDelay == 0xFF) {
            DeleteThisEntity();
        }

        if (gPlayerState.field_0x1c != 1) {
            DeleteThisEntity();
        }
    } else {
        this->action = 1;
        this->actionDelay = 64;
        var0 = this->entityType.parameter != 0 ? 44 : 43;
        this->x.HALF.HI -= this->parent->boundingBox->width;
        this->x.HALF.HI += (s32)Random() % (this->parent->boundingBox->width * 2);
        this->y.HALF.HI -= this->parent->boundingBox->height;
        this->y.HALF.HI += (s32)Random() % (this->parent->boundingBox->height * 2);
        sub_0801D2B4(this, var0);
        InitializeAnimation(this, 4);
    }
}

void sub_0808F554(Entity* this) {
    CopyPositionAndSpriteOffset(this->parent, this);
    this->spriteOffsetY -= 24;
    if ((s8)this->parent->spriteOffsetX != 0) {
        this->spriteOffsetX += (s8)this->parent->spriteOffsetX / 2;
    }

    if (this->action != 0) {
        if (*(u32*)&this->cutsceneBeh) {
            if (--(*(u32*)&this->cutsceneBeh) == 0) {
                DeleteThisEntity();
            }
        }
        GetNextFrame(this);
    } else {
        this->action = 1;
        this->spriteRendering.b3 = this->parent->spriteRendering.b3;
        this->spriteOrientation.flipY = this->parent->spriteOrientation.flipY;
        this->spritePriority.b0 = 0;
        InitializeAnimation(this, 3);
    }
}

void sub_0808F5EC(Entity* this) {
    Entity* entity = CreateObjectWithParent(this->attachedEntity, 0x49, 5, 0);
    if (entity) {
        entity->parent = this;
        entity->attachedEntity = this->attachedEntity;
    }

    entity = CreateObjectWithParent(this->attachedEntity, 0x49, 6, 0);
    if (entity) {
        entity->parent = this;
        entity->attachedEntity = this->attachedEntity;
    }

    entity = CreateObjectWithParent(this->attachedEntity, 0x49, 7, 0);
    if (entity) {
        entity->parent = this;
        entity->attachedEntity = this->attachedEntity;
    }

    *(u32*)&this->field_0x74 = 600;
}