summaryrefslogtreecommitdiff
path: root/src/enemy/chaser.c
blob: 93a042b8f61de4c01be0fc2bab8fa2fcdd0a6fc8 (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
/**
 * @file chaser.c
 * @ingroup Enemies
 *
 * @brief Chaser enemy
 */
#include "enemy.h"
#include "sound.h"
#include "effects.h"
#include "functions.h"
#include "player.h"
#include "physics.h"

extern void (*const Chaser_Functions[])(Entity*);
extern void (*const gUnk_080CD298[])(Entity*);

void Chaser(Entity* this) {
    u32 idx = sub_080012DC(this);
    if (idx) {
        gUnk_080012C8[idx](this);
    } else {
        Chaser_Functions[GetNextFunction(this)](this);
    }
}

void Chaser_OnTick(Entity* this) {
    gUnk_080CD298[this->action](this);
}

void sub_0802B530(Entity* this) {
    this->action = 1;
    InitializeAnimation(this, 0);
}

void sub_0802B540(Entity* this) {
    if (this->timer != 0) {
        this->timer--;
    } else {
        u32 direction = sub_0804A024(this, 1, 0xc);
        if (direction != DIR_NONE) {
            this->action = 2;
            this->speed = 0x40;
            this->direction = direction;
        }
    }
}

void sub_0802B56C(Entity* this) {
    GetNextFrame(this);
    if (this->contactFlags & CONTACT_NOW) {
        this->speed = 0x40;
    }

    if (ProcessMovement12(this)) {
        if (this->animIndex != 1) {
            InitializeAnimation(this, 1);
        }
        if (this->speed < 0x220) {
            this->speed += 4;
        }
    } else {
        this->action = 3;
        InitializeAnimation(this, 2);
    }
}

void sub_0802B5C8(Entity* this) {
    GetNextFrame(this);
    if (this->frame & ANIM_DONE) {
        this->action = 1;
        this->timer = 30;
        InitializeAnimation(this, 0);
    }
}

// clang-format off
void (*const Chaser_Functions[])(Entity*) = {
    Chaser_OnTick,
    Chaser_OnTick,
    GenericKnockback,
    GenericDeath,
    GenericConfused,
    Chaser_OnTick,
    Chaser_OnTick,
};

void (*const gUnk_080CD298[])(Entity*) = {
    sub_0802B530,
    sub_0802B540,
    sub_0802B56C,
    sub_0802B5C8,
};
// clang-format on