summaryrefslogtreecommitdiff
path: root/src/object/objectA2.c
blob: 2cc132fe7f96f247045653d6cb5d47f5f51750a5 (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
#include "global.h"
#include "object.h"
#include "menu.h"
#include "random.h"
#include "audio.h"
#include "structures.h"
#include "functions.h"

void sub_0809F318(Entity*);
void sub_0809F374(Entity*);
void sub_0809F3E8(Entity*);
void sub_0809F408(Entity*);
void sub_0809F448(Entity*);

void (*const gUnk_081246F4[])(Entity*) = { sub_0809F318, sub_0809F374, sub_0809F3E8, sub_0809F408 };

const u8 gUnk_08124704[] = { 0, 1, 2, 4 };

typedef struct {
    u8 unk_0;
    u8 unk_1;
} PACKED struct_08124708;

const struct_08124708 gUnk_08124708[5] = { { 0, 0x2F }, { 1, 0x20 }, { 1, 0x16 }, { 2, 0x10 }, { 3, 0x01 } };

void ObjectA2(Entity* this) {
    gUnk_081246F4[this->action](this);
    GetNextFrame(this);
}

void sub_0809F318(Entity* this) {
    InitializeAnimation(this, 0);
    if (Random() & 0x10) {
        this->spriteSettings.b.flipX = 1;
    }
    this->x.HALF.HI = 0x28;
    this->y.HALF.HI = 0x48;
    this->height.HALF.HI = 0xFFB0;
    this->spriteOrientation.flipY = 2;
    this->action = 1;
    sub_0801D2B4(this, gUnk_08124704[this->type]);
    sub_0805E3A0(this, 7);
}

void sub_0809F374(Entity* this) {
    sub_0806F69C(this);
#ifndef EU
    if (gUnk_02000000->gameLanguage < 2) {
        if (sub_080044EC(this, 0x2000) < 2) {
            this->height.WORD = 0;
            this->action = 2;
            InitializeAnimation(this, 1);
            SoundReq(SFX_186);
        } else {
            this->actionDelay++;
        }
    } else {
#endif
        switch (sub_080044EC(this, 0x2000)) {
            default:
                this->actionDelay++;
                break;
            case 0:
                this->action = 2;
                InitializeAnimation(this, 1);
                // fall through
            case 1:
                this->actionDelay = 0;
                sub_0809F448(this);
                SoundReq(SFX_186);
        }
#ifndef EU
    }
#endif
}

void sub_0809F3E8(Entity* this) {
    if (this->frames.b.f3) {
        this->action = 3;
        InitializeAnimation(this, 2);
    }
}

void sub_0809F408(Entity* this) {
    switch (this->frames.all) {
        case 9:
            this->frames.all = 0;
            CreateFx(this, 0x43, 0);
            gMenu.field_0x0 = 1;
            break;
        case 0x80:
            gMenu.field_0x4 = 1;
            DeleteThisEntity();
    }
}

void sub_0809F448(Entity* this) {
    s32 tmp;
    int rand = Random();
    const struct_08124708* tmp2 = &gUnk_08124708[this->field_0xf];
    this->field_0xf++;
    tmp = 0x280000 - this->x.WORD;
    switch (tmp2->unk_0) {
        case 0:
            tmp = rand % 0x180000;
            if (rand & 0x1000000) {
                tmp = -tmp;
            }
            break;
        case 1:
            tmp += -0x80000 + (rand & 0xFFFFF);
            break;
    }
    this->speed = (tmp > 0 ? tmp : -tmp) / (tmp2->unk_1 << 8);
    this->direction = sub_080045DA(tmp, 0) >> 3;
}