summaryrefslogtreecommitdiff
path: root/src/enemy/wisp.c
blob: 247cf0a01ff27804417b970143c6eb7c811fd15f (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
#include "global.h"
#include "entity.h"
#include "enemy.h"
#include "player.h"
#include "save.h"
#include "random.h"
#include "createObject.h"
#include "functions.h"

extern void (*const gUnk_080CEB74[])(Entity*);
extern void (*const gUnk_080CEB8C[])(Entity*);
extern void (*const gUnk_080CEB98[])(Entity*);

extern u8 gUnk_080CEBA4[];

void Wisp(Entity* this) {
    EnemyFunctionHandler(this, gUnk_080CEB74);
}

void sub_0803354C(Entity* this) {
    gUnk_080CEB8C[this->action](this);
}

void sub_08033564(Entity* this) {
    u32 bits;
    Entity* ent;

    bits = this->bitfield;
    if ((bits & 0x80) == 0) {
        return;
    }

    switch ((s32)bits & 0x3f) {
        case 0:
            this->action = 2;
            this->spriteSettings.b.draw = FALSE;
            this->flags &= 0x7f;
            this->field_0x7c.HALF.LO = 0x27c;
            gPlayerState.flags.all |= 0x4000;
            gSave.stats.effect = this->type + 1;
            gSave.stats.effectTimer = 600;
            if (this->type == 0) {
                break;
            }
            DeleteThisEntity();
            break;
        case 0xe:
        case 0x15:
            this->currentHealth = 0;
            break;
        case 0x14:
            this->flags &= 0x7f;
            this->iframes = 0;
            this->spriteSettings.b.draw = FALSE;
            ent = CreateFx(this, 2, 0);
            if (ent != NULL) {
                this->attachedEntity = ent;
                this->actionDelay = 0xe;
                CopyPosition(this, ent);
            }
            DeleteThisEntity();
            break;
    }
}

void sub_0803362C(Entity* this) {
    if (sub_0806F520() != 0) {
        gUnk_080CEB98[this->subAction](this);
    }
}

void sub_08033650(Entity* this) {
    this->subAction = 2;
}

void sub_08033658(Entity* this) {
    sub_0806F4E8(this);
}

void sub_08033660(Entity* this) {
    if (sub_0806F3E4(this)) {
        sub_0804A7D4(this);
    }
}

void sub_08033674(Entity* this) {
    sub_0804A720(this);
    this->actionDelay = 0;
    this->action = 1;
    this->field_0x1c = 1;
    this->field_0x80.HWORD = this->x.HALF.HI;
    this->field_0x82.HWORD = this->y.HALF.HI;
    sub_08033744(this);
    InitializeAnimation(this, this->type2);
}

void sub_080336A8(Entity* this) {
    if (--this->actionDelay == 0) {
        sub_08033744(this);
    } else if (this->collisions != 0) {
        sub_0800417E(this, this->collisions);
    }
    ProcessMovement(this);
    GetNextFrame(this);
}

void sub_080336DC(Entity* this) {
    switch ((u16)-- this->field_0x7c.HALF.LO) {
        case 0x24:
            this->x.HALF.HI = this->field_0x80.HWORD;
            this->y.HALF.HI = this->field_0x82.HWORD;
            break;
        case 0x18:
            CreateDust(this);
            break;
        case 0xc:
            this->spriteSettings.b.draw = TRUE;
            break;
        case 0x0:
            this->action = 1;
            this->flags |= 0x80;
            sub_08033744(this);
            break;
    }
}

void sub_08033744(Entity* this) {
    u32 temp;
    u32 rand = (u32)Random() % 256;

    // 8 potential options
    this->actionDelay = gUnk_080CEBA4[(rand & 0x70) >> 4];

    // 4 potential options
    temp = ((rand & 0xc) * 2);

    // 75% chance to pass
    if ((sub_08049FA0(this) == 0) && ((rand % 4) != 0)) {
        temp = sub_08049EE4(this);

        // 50% chance to pass
        if ((rand & 0x80) != 0) {
            temp += 0x4;
            temp &= 0x18;
        } else {
            temp += 0x1c;
            temp &= 0x18;
        }
    }
    this->direction = temp;
}