summaryrefslogtreecommitdiff
path: root/src/enemy/enemy4D.c
blob: 4fe0acfa0165ace0e2f0694b3c839cc6a73a89ab (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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/**
 * @file enemy4D.c
 * @ingroup Enemies
 *
 * @brief Enemy4D enemy
 */
#include "enemy.h"
#include "entity.h"
#include "functions.h"

typedef struct {
    /*0x00*/ Entity base;
    /*0x68*/ u8 unk_68[0x5];
    /*0x6d*/ u8 unk_6d;
    /*0x6e*/ u8 unk_6e;
    /*0x6f*/ u8 unk_6f;
    /*0x70*/ u16 unk_70;
    /*0x72*/ u16 unk_72;
    /*0x74*/ u8 unk_74[0x4];
    /*0x78*/ u16 unk_78;
    /*0x7a*/ u8 unk_7a;
    /*0x7b*/ u8 unk_7b;
    /*0x7c*/ u8 unk_7c;
    /*0x7d*/ u8 unk_7d;
    /*0x7e*/ u8 unk_7e;
    /*0x7f*/ u8 unk_7f;
    /*0x80*/ u16 unk_80;
    /*0x82*/ u16 unk_82;
    /*0x84*/ u16 unk_84;
    /*0x86*/ u16 unk_86;
} Enemy4DEntity;

extern void sub_0803E9A4(Entity*);      // ballChainSoldier
extern void sub_0803E94C(Entity*, u32); // ballChainSoldier

extern Entity* gUnk_020000B0;

void sub_0803EE8C(Enemy4DEntity*);
bool32 sub_0803EF20(Enemy4DEntity*);
bool32 sub_0803EEA4(Enemy4DEntity*);
bool32 sub_0803EF04(Enemy4DEntity*, u32);
void Enemy4D_OnTick(Enemy4DEntity*);
void Enemy4D_OnCollision(Enemy4DEntity*);
void Enemy4D_OnKnockback(Enemy4DEntity*);
void Enemy4D_OnDeath(Enemy4DEntity*);
void Enemy4D_OnGrabbed(Enemy4DEntity*);
void Enemy4D_Init(Enemy4DEntity*);
void Enemy4D_Action1(Enemy4DEntity*);
void Enemy4D_Action2(Enemy4DEntity*);
void Enemy4D_Action3(Enemy4DEntity*);
void Enemy4D_Action4(Enemy4DEntity*);
void Enemy4D_Action5(Enemy4DEntity*);
void Enemy4D_Action6(Enemy4DEntity*);
void Enemy4D_Action7(Enemy4DEntity*);
void Enemy4D_Action8(Enemy4DEntity*);
void Enemy4D_Action9(Enemy4DEntity*);
void Enemy4D_Action10(Enemy4DEntity*);
bool32 sub_0803EF70(Entity*, Entity*);
bool32 sub_0803EF74(Entity*, Entity*);
bool32 sub_0803EFAC(Entity*, Entity*);

void (*const Enemy4D_Functions[])(Enemy4DEntity*) = {
    Enemy4D_OnTick,
    Enemy4D_OnCollision,
    Enemy4D_OnKnockback,
    Enemy4D_OnDeath,
    (void (*)(Enemy4DEntity*))GenericConfused,
    Enemy4D_OnGrabbed,
};

void Enemy4D(Enemy4DEntity* this) {
    EnemyFunctionHandler(super, (EntityActionArray)Enemy4D_Functions);
}

void Enemy4D_OnTick(Enemy4DEntity* this) {
    static void (*const Enemy4D_Actions[])(Enemy4DEntity*) = {
        Enemy4D_Init,    Enemy4D_Action1, Enemy4D_Action2, Enemy4D_Action3, Enemy4D_Action4,  Enemy4D_Action5,
        Enemy4D_Action6, Enemy4D_Action7, Enemy4D_Action8, Enemy4D_Action9, Enemy4D_Action10,
    };
    Enemy4D_Actions[super->action](this);
}

void Enemy4D_OnCollision(Enemy4DEntity* this) {
    EnemyFunctionHandlerAfterCollision(super, Enemy4D_Functions);
}

void Enemy4D_OnKnockback(Enemy4DEntity* this) {
    GenericKnockback(super);
    Enemy4D_OnTick(this);
}

void Enemy4D_OnDeath(Enemy4DEntity* this) {
    EnemyCreateDeathFX((Enemy*)super, 0xff, 0x57);
}

void Enemy4D_OnGrabbed(Enemy4DEntity* this) {
}

void Enemy4D_Init(Enemy4DEntity* this) {
    Entity* projectile;

    sub_0804A720(super);
    projectile = EnemyCreateProjectile(super, BALL_AND_CHAIN, 0);
    if (projectile != NULL) {
        projectile->parent = super;
        super->child = projectile;
        COLLISION_ON(super);
        super->spriteSettings.draw = TRUE;
        super->animationState = IdleEast;
        this->unk_7b = 0;
        this->unk_7c = 0;
        this->unk_7e = 0x28;
        this->unk_7f = 0xfe;
        this->unk_80 = super->x.HALF.HI;
        this->unk_82 = super->y.HALF.HI;
        InitAnimationForceUpdate(super, super->animationState << 2);
        sub_0803EE8C(this);
    }
}
void Enemy4D_Action1(Enemy4DEntity* this) {
    this->unk_7c -= 0xa;
    if (sub_08049DF4(1)) {
        super->direction = DirectionRoundUp(GetFacingDirection(super, gUnk_020000B0));
        sub_0803E94C(super, 0);
    }
    sub_0803E9A4(super);
    if (EntityWithinDistance(super, this->unk_80, this->unk_82, 2) == FALSE) {
        super->action = 4;
        sub_0803E94C(super, 0x10);
    } else {
        if (sub_0803EF20(this) == FALSE) {
            sub_0803EEA4(this);
        }
    }
}

void Enemy4D_Action2(Enemy4DEntity* this) {
    this->unk_7c -= 0x10;
    sub_0803E9A4(super);
    if (this->unk_7e > 0x1c) {
        this->unk_7e--;
    }
    if (--this->unk_78 == 0) {
        super->action = 3;
        this->unk_7b = 0;
    }
}

void Enemy4D_Action3(Enemy4DEntity* this) {
    this->unk_7c -= 0xa;
    sub_0803E9A4(super);
    if (this->unk_7e < 0x28) {
        this->unk_7e++;
    } else {
        sub_0803EE8C(this);
    }
}

void Enemy4D_Action4(Enemy4DEntity* this) {
    this->unk_7c -= 0xa;
    sub_0803E9A4(super);
    if (EntityWithinDistance(super, this->unk_80, this->unk_82, 1)) {
        super->x.HALF.HI = this->unk_80;
        super->y.HALF.HI = this->unk_82;
        sub_0803EE8C(this);
        sub_0803E94C(super, 0);
    } else {
        if (super->knockbackDuration == 0) {
            super->direction = CalculateDirectionTo(super->x.HALF.HI, super->y.HALF.HI, this->unk_80, this->unk_82);
            sub_0803E94C(super, 0x10);
            ProcessMovement0(super);
        }
    }
}

void Enemy4D_Action5(Enemy4DEntity* this) {
    s32 tmp;
    this->unk_7c -= 0xc;
    sub_0803E9A4(super);
    tmp = this->unk_7e - 4;
    this->unk_7e = tmp;
    if ((tmp * 0x1000000) < 1) {
        this->unk_7e = 0;
        super->action = 6;
        super->timer = 15;
        InitAnimationForceUpdate(super, super->animationState + 0x20);
    }
}

void Enemy4D_Action6(Enemy4DEntity* this) {

    static const u8 gUnk_080D08C4[] = {
        0,
        68,
        128,
        188,
    };
    if (--super->timer == 0) {
        super->action = 7;
        super->timer = 1;
        this->unk_7c = gUnk_080D08C4[super->animationState];
        this->unk_7f = 0xf6;
        EnqueueSFX(SFX_15B);
    }
}

void Enemy4D_Action7(Enemy4DEntity* this) {
    if ((super->frame & ANIM_DONE) == 0) {
        UpdateAnimationSingleFrame(super);
    } else {
        if (--super->timer == 0) {
            super->timer = 2;
            this->unk_7f++;
        }
        if (this->unk_7f != 0) {
            this->unk_7e += 5;
        } else {
            super->action = 8;
            super->timer = 30;
            InitScreenShake(8, 0);
        }
    }
}

void Enemy4D_Action8(Enemy4DEntity* this) {
    if (--super->timer == 0) {
        super->action = 9;
    }
}

void Enemy4D_Action9(Enemy4DEntity* this) {
    u8 tmp;
    tmp = this->unk_7e = this->unk_7e - 2;
    if (tmp < 0xb) {
        super->action = 0xa;
        super->timer = 60;
        super->direction = super->animationState << 3;
        this->unk_7c = 0;
        this->unk_7f = 0xfe;
        sub_0803E94C(super, 0x10);
    } else if (tmp < 0x13) {
        super->child->flags &= ~ENT_COLLIDE;
    }
}

void Enemy4D_Action10(Enemy4DEntity* this) {
    if (super->timer != 0) {
        if (--super->timer == 0) {
            super->child->flags |= ENT_COLLIDE;
            sub_0803E94C(super, 0);
        }
    } else {
        this->unk_7c -= 0xa;
        sub_0803E9A4(super);
        if (++this->unk_7e > 0x27) {
            sub_0803EE8C(this);
        }
    }
}

void sub_0803EE8C(Enemy4DEntity* this) {
    super->action = 1;
    this->unk_7a = 0x1e;
    sub_0803E94C(super, 0);
}

bool32 sub_0803EEA4(Enemy4DEntity* this) {
    s32 tmp;
    if (sub_08049FDC(super, 1)) {
        if (sub_0803EF04(this, 0x4e) != 0) {
            tmp = sub_0804A044(super, gUnk_020000B0, 0x12);
            if (tmp != 0xff) {
                if (--this->unk_7a == 0) {
                    super->action = 5;
                    super->direction = tmp;
                    sub_0803E94C(super, 0);
                    return TRUE;
                }
                return FALSE;
            }
        }
    }
    this->unk_7a = 0x1e;
    return FALSE;
}

bool32 sub_0803EF04(Enemy4DEntity* this, u32 distance) {
    return EntityWithinDistance(super, gUnk_020000B0->x.HALF.HI, gUnk_020000B0->y.HALF.HI - 4, distance);
}

bool32 sub_0803EF20(Enemy4DEntity* this) {
    static bool32 (*const gUnk_080D08C8[])(Entity*, Entity*) = {
        sub_0803EF70, sub_0803EF70, sub_0803EF70, sub_0803EF74, sub_0803EFAC, sub_0803EF70, sub_0803EF70, sub_0803EF70,
        sub_0803EF70, sub_0803EF70, sub_0803EF70, sub_0803EF70, sub_0803EF70, sub_0803EF70, sub_0803EF70, sub_0803EFAC,
        sub_0803EF70, sub_0803EFAC, sub_0803EFAC, sub_0803EFAC, sub_0803EF70, sub_0803EF70, sub_0803EFAC,
    };
    Entity* it;
    LinkedList* list = &gEntityLists[2];

    for (it = list->first; it != (Entity*)list; it = it->next) {
        if ((it->kind == 8) && gUnk_080D08C8[it->id](super, it)) {
            super->action = 2;
            this->unk_78 = 0xb4;
            this->unk_7b = 1;
            return TRUE;
        }
    }
    return FALSE;
}

bool32 sub_0803EF70(Entity* param_1, Entity* param_2) {
    return FALSE;
}

bool32 sub_0803EF74(Entity* param_1, Entity* param_2) {
    if (EntityWithinDistance(param_1, param_2->x.HALF.HI, param_2->y.HALF.HI, 0x50)) {
        if (4 >= (((param_2->direction - GetFacingDirection(param_2, param_1)) + 2) & 0x1f)) {
            return TRUE;
        }
    }
    return FALSE;
}

bool32 sub_0803EFAC(Entity* param_1, Entity* param_2) {
    if (EntityInRectRadius(param_1, param_2, 0x50, 0x50)) {
        u32 tmp = sub_0804A044(param_2, param_1, 0x1c);
        if (tmp != 0xff) {
            if (tmp == param_2->direction) {
                return TRUE;
            }
        }
    }
    return FALSE;
}